TeamColor PlayerIdToTeam(PlayerId id) { if (id >= 244 && id <= 250) return TeamColor(250 - id); else return NoTeam; }
void RadarRenderer::makeList( SceneRenderer&) { // draw walls. walls are flat so a line will do. const std::vector<WallObstacle>& walls = world.getWalls(); int count = walls.size(); glColor3f(0.25f, 0.5f, 0.5f); glBegin(GL_LINES); int i; for (i = 0; i < count; i++) { const WallObstacle& wall = walls[i]; const float w = wall.getBreadth(); const float c = w * cosf(wall.getRotation()); const float s = w * sinf(wall.getRotation()); const float* pos = wall.getPosition(); glVertex2f(pos[0] - s, pos[1] + c); glVertex2f(pos[0] + s, pos[1] - c); } glEnd(); // draw box buildings. const std::vector<BoxBuilding>& boxes = world.getBoxes(); count = boxes.size(); glBegin(GL_QUADS); for (i = 0; i < count; i++) { const BoxBuilding& box = boxes[i]; if (box.isInvisible()) continue; const float cs = colorScale(box.getPosition()[2], box.getHeight(), BZDBCache::enhancedRadar); glColor4f(0.25f * cs, 0.5f * cs, 0.5f * cs, transScale(box)); const float c = cosf(box.getRotation()); const float s = sinf(box.getRotation()); const float wx = c * box.getWidth(), wy = s * box.getWidth(); const float hx = -s * box.getBreadth(), hy = c * box.getBreadth(); const float* pos = box.getPosition(); glVertex2f(pos[0] - wx - hx, pos[1] - wy - hy); glVertex2f(pos[0] + wx - hx, pos[1] + wy - hy); glVertex2f(pos[0] + wx + hx, pos[1] + wy + hy); glVertex2f(pos[0] - wx + hx, pos[1] - wy + hy); } glEnd(); // draw pyramid buildings const std::vector<PyramidBuilding>& pyramids = world.getPyramids(); count = pyramids.size(); glBegin(GL_QUADS); for (i = 0; i < count; i++) { const PyramidBuilding& pyr = pyramids[i]; const float cs = colorScale(pyr.getPosition()[2], pyr.getHeight(), BZDBCache::enhancedRadar); glColor4f(0.25f * cs, 0.5f * cs, 0.5f * cs, transScale(pyr)); const float c = cosf(pyr.getRotation()); const float s = sinf(pyr.getRotation()); const float wx = c * pyr.getWidth(), wy = s * pyr.getWidth(); const float hx = -s * pyr.getBreadth(), hy = c * pyr.getBreadth(); const float* pos = pyr.getPosition(); glVertex2f(pos[0] - wx - hx, pos[1] - wy - hy); glVertex2f(pos[0] + wx - hx, pos[1] + wy - hy); glVertex2f(pos[0] + wx + hx, pos[1] + wy + hy); glVertex2f(pos[0] - wx + hx, pos[1] - wy + hy); } glEnd(); // now draw antialiased outlines around the polygons count = boxes.size(); for (i = 0; i < count; i++) { const BoxBuilding& box = boxes[i]; if (box.isInvisible()) continue; const float cs = colorScale(box.getPosition()[2], box.getHeight(), BZDBCache::enhancedRadar); glColor4f(0.25f * cs, 0.5f * cs, 0.5f * cs, transScale(box)); const float c = cosf(box.getRotation()); const float s = sinf(box.getRotation()); const float wx = c * box.getWidth(), wy = s * box.getWidth(); const float hx = -s * box.getBreadth(), hy = c * box.getBreadth(); const float* pos = box.getPosition(); glBegin(GL_LINE_LOOP); glVertex2f(pos[0] - wx - hx, pos[1] - wy - hy); glVertex2f(pos[0] + wx - hx, pos[1] + wy - hy); glVertex2f(pos[0] + wx + hx, pos[1] + wy + hy); glVertex2f(pos[0] - wx + hx, pos[1] - wy + hy); glEnd(); } count = pyramids.size(); for (i = 0; i < count; i++) { const PyramidBuilding& pyr = pyramids[i]; const float cs = colorScale(pyr.getPosition()[2], pyr.getHeight(), BZDBCache::enhancedRadar); glColor4f(0.25f * cs, 0.5f * cs, 0.5f * cs, transScale(pyr)); const float c = cosf(pyr.getRotation()); const float s = sinf(pyr.getRotation()); const float wx = c * pyr.getWidth(), wy = s * pyr.getWidth(); const float hx = -s * pyr.getBreadth(), hy = c * pyr.getBreadth(); const float* pos = pyr.getPosition(); glBegin(GL_LINE_LOOP); glVertex2f(pos[0] - wx - hx, pos[1] - wy - hy); glVertex2f(pos[0] + wx - hx, pos[1] + wy - hy); glVertex2f(pos[0] + wx + hx, pos[1] + wy + hy); glVertex2f(pos[0] - wx + hx, pos[1] - wy + hy); glEnd(); } // draw team bases if(world.allowTeamFlags()) { for(i = 1; i < NumTeams; i++) { for (int j = 0;;j++) { const float *base = world.getBase(i, j); if (base == NULL) break; glColor3fv(Team::getRadarColor(TeamColor(i))); glBegin(GL_LINE_LOOP); const float beta = atan2f(base[5], base[4]); const float r = hypotf(base[4], base[5]); glVertex2f(base[0] + r * cosf(base[3] + beta), base[1] + r * sinf(base[3] + beta)); glVertex2f(base[0] + r * cosf(base[3] - beta + M_PI), base[1] + r * sinf(base[3] - beta + M_PI)); glVertex2f(base[0] + r * cosf(base[3] + beta + M_PI), base[1] + r * sinf(base[3] + beta + M_PI)); glVertex2f(base[0] + r * cosf(base[3] - beta), base[1] + r * sinf(base[3] - beta)); glEnd(); } } } // draw teleporters. teleporters are pretty thin so use lines // (which, if longer than a pixel, are guaranteed to draw something; // not so for a polygon). just in case the system doesn't correctly // filter the ends of line segments, we'll draw the line in each // direction (which degrades the antialiasing). Newport graphics // is one system that doesn't do correct filtering. const std::vector<Teleporter>& teleporters = world.getTeleporters(); count = teleporters.size(); glColor3f(1.0f, 1.0f, 0.25f); glBegin(GL_LINES); for (i = 0; i < count; i++) { const Teleporter& tele = teleporters[i]; const float cs = colorScale(tele.getPosition()[2], tele.getHeight(), BZDBCache::enhancedRadar); glColor4f(1.0f * cs, 1.0f * cs, 0.25f * cs, transScale(tele)); const float w = tele.getBreadth(); const float c = w * cosf(tele.getRotation()); const float s = w * sinf(tele.getRotation()); const float* pos = tele.getPosition(); glVertex2f(pos[0] - s, pos[1] + c); glVertex2f(pos[0] + s, pos[1] - c); glVertex2f(pos[0] + s, pos[1] - c); glVertex2f(pos[0] - s, pos[1] + c); } glEnd(); }
Settings::Settings() { static_assert(TEAM_BLUE == blue && TEAM_RED == red && TEAM_YELLOW == yellow && TEAM_BLACK == black && TEAM_WHITE == white && TEAM_GREEN == green && TEAM_ORANGE == orange && TEAM_PURPLE == purple && TEAM_BROWN == brown && TEAM_GRAY == gray, "These macros and enums have to match!"); if(!loaded) { VERIFY(settings.load()); loaded = true; } *this = settings; #ifdef TARGET_SIM if(SystemCall::getMode() == SystemCall::simulatedRobot) { int index = atoi(RoboCupCtrl::controller->getRobotName().c_str() + 5) - 1; teamNumber = index < 6 ? 1 : 2; teamPort = 10000 + teamNumber; teamColor = index < 6 ? TeamColor(RoboCupCtrl::controller->gameController.teamInfos[0].teamColor) : TeamColor(RoboCupCtrl::controller->gameController.teamInfos[1].teamColor); playerNumber = index % 6 + 1; } headName = bodyName = "Nao"; ConsoleRoboCupCtrl* ctrl = dynamic_cast<ConsoleRoboCupCtrl*>(RoboCupCtrl::controller); if(ctrl) { std::string logFileName = ctrl->getLogFile(); if(logFileName != "") { QRegExp re1("([A-Za-z]*)_([A-Za-z]*)__", Qt::CaseSensitive, QRegExp::RegExp2); QRegExp re2("([A-Za-z]*)_([A-Za-z]*)_([A-Za-z0-9]*)_([A-Za-z0-9]*)__"); QRegExp re3("_([0-9][0-9]*)(_\\([0-9][0-9]*\\)){0,1}\\."); int pos1 = re1.indexIn(logFileName.c_str()); int pos2 = re2.indexIn(logFileName.c_str()); int pos3 = re3.indexIn(logFileName.c_str()); if(pos2 != -1) { headName = re2.capturedTexts()[1].toUtf8().constData(); bodyName = re2.capturedTexts()[2].toUtf8().constData(); scenario = re2.capturedTexts()[3].toUtf8().constData(); location = re2.capturedTexts()[4].toUtf8().constData(); } else if(pos1 != -1) { headName = re1.capturedTexts()[1].toUtf8().constData(); bodyName = re1.capturedTexts()[2].toUtf8().constData(); } else bodyName = headName = "Default"; if(pos3 != -1) playerNumber = re3.capturedTexts()[1].toUtf8().constData()[0] - '0'; } } #endif }
void* WorldBuilder::unpack(void* buf) { // unpack world database from network transfer // read style header uint16_t code, len; buf = nboUnpackUShort(buf, len); buf = nboUnpackUShort(buf, code); if (code != WorldCodeHeader) return NULL; // read style uint16_t gameStyle, maxPlayers, maxShots, maxFlags,serverMapVersion; buf = nboUnpackUShort(buf, serverMapVersion); if (serverMapVersion != mapVersion) return NULL; float worldSize; buf = nboUnpackFloat(buf, worldSize); BZDB.set(StateDatabase::BZDB_WORLDSIZE, string_util::format("%f", worldSize)); buf = nboUnpackUShort(buf, gameStyle); setGameStyle(short(gameStyle)); buf = nboUnpackUShort(buf, maxPlayers); setMaxPlayers(int(maxPlayers)); buf = nboUnpackUShort(buf, maxShots); setMaxShots(int(maxShots)); buf = nboUnpackUShort(buf, maxFlags); setMaxFlags(int(maxFlags)); buf = nboUnpackFloat(buf, world->linearAcceleration); buf = nboUnpackFloat(buf, world->angularAcceleration); uint16_t shakeTimeout = 0, shakeWins; buf = nboUnpackUShort(buf, shakeTimeout); setShakeTimeout(0.1f * float(shakeTimeout)); buf = nboUnpackUShort(buf, shakeWins); setShakeWins(shakeWins); uint32_t epochOffset; buf = nboUnpackUInt(buf, epochOffset); setEpochOffset(epochOffset); // read geometry buf = nboUnpackUShort(buf, len); buf = nboUnpackUShort(buf, code); while (code != WorldCodeEnd) { switch (code) { case WorldCodeBox: { float data[7]; unsigned char tempflags; if (len != WorldCodeBoxSize) return NULL; memset(data, 0, sizeof(float) * 7); buf = nboUnpackFloat(buf, data[0]); buf = nboUnpackFloat(buf, data[1]); buf = nboUnpackFloat(buf, data[2]); buf = nboUnpackFloat(buf, data[3]); buf = nboUnpackFloat(buf, data[4]); buf = nboUnpackFloat(buf, data[5]); buf = nboUnpackFloat(buf, data[6]); buf = nboUnpackUByte(buf, tempflags); BoxBuilding box(data, data[3], data[4], data[5], data[6], (tempflags & _DRIVE_THRU)!=0, (tempflags & _SHOOT_THRU)!=0); append(box); break; } case WorldCodePyramid: { float data[7]; unsigned char tempflags; if (len != WorldCodePyramidSize) return NULL; buf = nboUnpackFloat(buf, data[0]); buf = nboUnpackFloat(buf, data[1]); buf = nboUnpackFloat(buf, data[2]); buf = nboUnpackFloat(buf, data[3]); buf = nboUnpackFloat(buf, data[4]); buf = nboUnpackFloat(buf, data[5]); buf = nboUnpackFloat(buf, data[6]); buf = nboUnpackUByte(buf, tempflags); PyramidBuilding pyr(data, data[3], data[4], data[5], data[6], (tempflags & _DRIVE_THRU)!=0, (tempflags & _SHOOT_THRU)!=0); if (tempflags & _FLIP_Z) pyr.setZFlip(); append(pyr); break; } case WorldCodeTeleporter: { float data[8]; unsigned char tempflags; if (len != WorldCodeTeleporterSize) return NULL; buf = nboUnpackFloat(buf, data[0]); buf = nboUnpackFloat(buf, data[1]); buf = nboUnpackFloat(buf, data[2]); buf = nboUnpackFloat(buf, data[3]); buf = nboUnpackFloat(buf, data[4]); buf = nboUnpackFloat(buf, data[5]); buf = nboUnpackFloat(buf, data[6]); buf = nboUnpackFloat(buf, data[7]); buf = nboUnpackUByte(buf, tempflags); Teleporter tele(data, data[3], data[4], data[5], data[6],data[7], (tempflags & _DRIVE_THRU)!=0, (tempflags & _SHOOT_THRU)!=0); append(tele); break; } case WorldCodeLink: { uint16_t data[2]; if (len != WorldCodeLinkSize) return NULL; buf = nboUnpackUShort(buf, data[0]); buf = nboUnpackUShort(buf, data[1]); setTeleporterTarget(int(data[0]), int(data[1])); break; } case WorldCodeWall: { float data[6]; if (len != WorldCodeWallSize) return NULL; buf = nboUnpackFloat(buf, data[0]); buf = nboUnpackFloat(buf, data[1]); buf = nboUnpackFloat(buf, data[2]); buf = nboUnpackFloat(buf, data[3]); buf = nboUnpackFloat(buf, data[4]); buf = nboUnpackFloat(buf, data[5]); WallObstacle wall(data, data[3], data[4], data[5]); append(wall); break; } case WorldCodeBase: { uint16_t team; float data[10]; if (len != WorldCodeBaseSize) return NULL; buf = nboUnpackUShort(buf, team); buf = nboUnpackFloat(buf, data[0]); buf = nboUnpackFloat(buf, data[1]); buf = nboUnpackFloat(buf, data[2]); buf = nboUnpackFloat(buf, data[3]); buf = nboUnpackFloat(buf, data[4]); buf = nboUnpackFloat(buf, data[5]); buf = nboUnpackFloat(buf, data[6]); buf = nboUnpackFloat(buf, data[7]); buf = nboUnpackFloat(buf, data[8]); buf = nboUnpackFloat(buf, data[9]); BaseBuilding base(data, data[3], data +4, team); append(base); setBase(TeamColor(team), data, data[3], data[4], data[5], data[6]); break; } case WorldCodeWeapon: { Weapon weapon; uint16_t delays; buf = FlagType::unpack(buf, weapon.type); buf = nboUnpackFloat(buf, weapon.pos[0]); buf = nboUnpackFloat(buf, weapon.pos[1]); buf = nboUnpackFloat(buf, weapon.pos[2]); buf = nboUnpackFloat(buf, weapon.dir); buf = nboUnpackFloat(buf, weapon.initDelay); buf = nboUnpackUShort(buf, delays); uint16_t weapon_len = WorldCodeWeaponSize + (delays * sizeof(float)); if (len != weapon_len) { return NULL; } int i; for (i = 0; i < delays; i++) { float delay; buf = nboUnpackFloat(buf, delay); weapon.delay.push_back(delay); } append(weapon); break; } case WorldCodeZone: { EntryZone zone; uint16_t flags, teams, safety; buf = nboUnpackFloat(buf, zone.pos[0]); buf = nboUnpackFloat(buf, zone.pos[1]); buf = nboUnpackFloat(buf, zone.pos[2]); buf = nboUnpackFloat(buf, zone.size[0]); buf = nboUnpackFloat(buf, zone.size[1]); buf = nboUnpackFloat(buf, zone.size[2]); buf = nboUnpackFloat(buf, zone.rot); buf = nboUnpackUShort(buf, flags); buf = nboUnpackUShort(buf, teams); buf = nboUnpackUShort(buf, safety); uint16_t zone_len = WorldCodeZoneSize; zone_len += FlagType::packSize * flags; zone_len += sizeof(uint16_t) * teams; zone_len += sizeof(uint16_t) * safety; if (len != zone_len) { return NULL; } int i; for (i = 0; i < flags; i++) { FlagType *type; buf = FlagType::unpack (buf, type); zone.flags.push_back(type); } for (i = 0; i < teams; i++) { uint16_t team; buf = nboUnpackUShort(buf, team); zone.teams.push_back((TeamColor)team); } for (i = 0; i < safety; i++) { uint16_t safety; buf = nboUnpackUShort(buf, safety); zone.safety.push_back((TeamColor)safety); } append(zone); break; } default: return NULL; } buf = nboUnpackUShort(buf, len); buf = nboUnpackUShort(buf, code); } return buf; }