- Timestamp:
- May 26, 2013, 3:34:27 PM (12 years ago)
- Branches:
- master
- Children:
- 07c73fa
- Parents:
- 15efb4e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
r15efb4e r446dc65 170 170 POSITION pos; 171 171 bool flagTurnedIn = false; 172 172 bool flagReturned = false; 173 bool ownFlagAtBase = false; 174 173 175 switch(gameMap->getStructure(it->second.pos.x/25, it->second.pos.y/25)) { 174 176 case WorldMap::STRUCTURE_BLUE_FLAG: … … 176 178 if (it->second.team == 0 && it->second.hasRedFlag) 177 179 { 178 it->second.hasRedFlag = false; 179 flagType = WorldMap::OBJECT_RED_FLAG; 180 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG); 181 flagTurnedIn = true; 182 scoreBlue++; 180 // check that your flag is at your base 181 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG); 182 183 vector<WorldMap::Object>* vctObjects = gameMap->getObjects(); 184 vector<WorldMap::Object>::iterator itObjects; 185 186 for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) { 187 if (itObjects->type == WorldMap::OBJECT_BLUE_FLAG) { 188 if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12) { 189 ownFlagAtBase = true; 190 break; 191 } 192 } 193 } 194 195 if (ownFlagAtBase) { 196 it->second.hasRedFlag = false; 197 flagType = WorldMap::OBJECT_RED_FLAG; 198 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG); 199 flagTurnedIn = true; 200 scoreBlue++; 201 } 183 202 } 184 203 … … 189 208 if (it->second.team == 1 && it->second.hasBlueFlag) 190 209 { 191 it->second.hasBlueFlag = false; 192 flagType = WorldMap::OBJECT_BLUE_FLAG; 193 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG); 194 flagTurnedIn = true; 195 scoreRed++; 210 // check that your flag is at your base 211 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG); 212 213 vector<WorldMap::Object>* vctObjects = gameMap->getObjects(); 214 vector<WorldMap::Object>::iterator itObjects; 215 216 for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) { 217 if (itObjects->type == WorldMap::OBJECT_RED_FLAG) { 218 if (itObjects->pos.x == pos.x*25+12 && itObjects->pos.y == pos.y*25+12) { 219 ownFlagAtBase = true; 220 break; 221 } 222 } 223 } 224 225 if (ownFlagAtBase) { 226 it->second.hasBlueFlag = false; 227 flagType = WorldMap::OBJECT_BLUE_FLAG; 228 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG); 229 flagTurnedIn = true; 230 scoreRed++; 231 } 196 232 } 197 233 … … 228 264 // this means a PLAYER message will be sent 229 265 broadcastMove = true; 266 } 267 268 // go through all objects and check if the player is close to one and if its their flag 269 vector<WorldMap::Object>* vctObjects = gameMap->getObjects(); 270 vector<WorldMap::Object>::iterator itObjects; 271 POSITION structPos; 272 273 for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) { 274 POSITION pos = itObjects->pos; 275 276 if (posDistance(it->second.pos, pos.toFloat()) < 10) { 277 if (it->second.team == 0 && 278 itObjects->type == WorldMap::OBJECT_BLUE_FLAG) { 279 structPos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG); 280 flagReturned = true; 281 break; 282 } else if (it->second.team == 1 && 283 itObjects->type == WorldMap::OBJECT_RED_FLAG) { 284 structPos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG); 285 flagReturned = true; 286 break; 287 } 288 } 289 } 290 291 if (flagReturned) { 292 itObjects->pos.x = structPos.x*25+12; 293 itObjects->pos.y = structPos.y*25+12; 294 295 serverMsg.type = MSG_TYPE_OBJECT; 296 itObjects->serialize(serverMsg.buffer); 297 298 map<unsigned int, Player>::iterator it2; 299 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 300 { 301 if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 ) 302 error("sendMessage"); 303 } 230 304 } 231 305
Note:
See TracChangeset
for help on using the changeset viewer.