Changeset b73bc28 in network-game for server/server.cpp
- Timestamp:
- Dec 21, 2013, 2:35:19 AM (11 years ago)
- Branches:
- master
- Children:
- d3efa1a
- Parents:
- ce2bb87
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
rce2bb87 rb73bc28 224 224 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 225 225 { 226 if (it->second->currentGame == NULL) 226 Player* p = it->second; 227 if (p->currentGame == NULL) 227 228 continue; 228 229 … … 231 232 232 233 // move player and perform associated tasks 233 oldPos = it->second->pos;234 if ( it->second->move(it->second->currentGame->getMap())) {234 oldPos = p->pos; 235 if (p->move(p->currentGame->getMap())) { 235 236 236 237 cout << "player moved" << endl; 237 if ( it->second->currentGame->processPlayerMovement(it->second, oldPos))238 if (p->currentGame->processPlayerMovement(p, oldPos)) 238 239 broadcastMove = true; 239 240 cout << "player move processed" << endl; 240 241 241 /* 242 map<unsigned int, Player*>& playersInGame = p->currentGame->getPlayers(); 243 242 244 WorldMap::ObjectType flagType; 243 245 POSITION pos; … … 245 247 bool flagReturned = false; 246 248 bool ownFlagAtBase = false; 247 248 switch(gameMap->getStructure(it->second->pos.x/25, it->second->pos.y/25)) 249 250 // need to figure out how to move this to a different file 251 // while still sending back flag type and position 252 WorldMap* playerMap = p->currentGame->getMap(); 253 switch(playerMap->getStructure(p->pos.x/25, p->pos.y/25)) 249 254 { 250 255 case WorldMap::STRUCTURE_BLUE_FLAG: 251 256 { 252 if ( it->second->team == 0 && it->second->hasRedFlag)257 if (p->team == 0 && p->hasRedFlag) 253 258 { 254 259 // check that your flag is at your base 255 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);260 pos = playerMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG); 256 261 257 vector<WorldMap::Object>* vctObjects = gameMap->getObjects();262 vector<WorldMap::Object>* vctObjects = playerMap->getObjects(); 258 263 vector<WorldMap::Object>::iterator itObjects; 259 264 … … 272 277 if (ownFlagAtBase) 273 278 { 274 it->second->hasRedFlag = false;279 p->hasRedFlag = false; 275 280 flagType = WorldMap::OBJECT_RED_FLAG; 276 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);281 pos = playerMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG); 277 282 flagTurnedIn = true; 278 283 scoreBlue++; … … 284 289 case WorldMap::STRUCTURE_RED_FLAG: 285 290 { 286 if ( it->second->team == 1 && it->second->hasBlueFlag)291 if (p->team == 1 && p->hasBlueFlag) 287 292 { 288 293 // check that your flag is at your base 289 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);294 pos = playerMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG); 290 295 291 vector<WorldMap::Object>* vctObjects = gameMap->getObjects();296 vector<WorldMap::Object>* vctObjects = playerMap->getObjects(); 292 297 vector<WorldMap::Object>::iterator itObjects; 293 298 … … 306 311 if (ownFlagAtBase) 307 312 { 308 it->second->hasBlueFlag = false;313 p->hasBlueFlag = false; 309 314 flagType = WorldMap::OBJECT_BLUE_FLAG; 310 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);315 pos = playerMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG); 311 316 flagTurnedIn = true; 312 317 scoreRed++; … … 323 328 pos.x = pos.x*25+12; 324 329 pos.y = pos.y*25+12; 325 gameMap->addObject(flagType, pos.x, pos.y);330 playerMap->addObject(flagType, pos.x, pos.y); 326 331 327 332 serverMsg.type = MSG_TYPE_OBJECT; 328 gameMap->getObjects()->back().serialize(serverMsg.buffer);333 playerMap->getObjects()->back().serialize(serverMsg.buffer); 329 334 330 335 map<unsigned int, Player*>::iterator it2; 331 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 336 337 for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++) 332 338 { 333 339 if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 ) … … 339 345 memcpy(serverMsg.buffer+4, &scoreRed, 4); 340 346 341 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)347 for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++) 342 348 { 343 349 if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 ) … … 350 356 351 357 // go through all objects and check if the player is close to one and if its their flag 352 vector<WorldMap::Object>* vctObjects = gameMap->getObjects();358 vector<WorldMap::Object>* vctObjects = playerMap->getObjects(); 353 359 vector<WorldMap::Object>::iterator itObjects; 354 360 POSITION structPos; … … 358 364 POSITION pos = itObjects->pos; 359 365 360 if (posDistance( it->second->pos, pos.toFloat()) < 10)366 if (posDistance(p->pos, pos.toFloat()) < 10) 361 367 { 362 if ( it->second->team == 0 &&368 if (p->team == 0 && 363 369 itObjects->type == WorldMap::OBJECT_BLUE_FLAG) 364 370 { 365 structPos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);371 structPos = playerMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG); 366 372 flagReturned = true; 367 373 break; 368 374 } 369 else if ( it->second->team == 1 &&375 else if (p->team == 1 && 370 376 itObjects->type == WorldMap::OBJECT_RED_FLAG) 371 377 { 372 structPos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);378 structPos = playerMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG); 373 379 flagReturned = true; 374 380 break; … … 386 392 387 393 map<unsigned int, Player*>::iterator it2; 388 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)394 for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++) 389 395 { 390 396 if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 ) … … 392 398 } 393 399 } 394 */395 400 396 401 if (broadcastMove) … … 398 403 cout << "broadcasting player move" << endl; 399 404 serverMsg.type = MSG_TYPE_PLAYER; 400 it->second->serialize(serverMsg.buffer);405 p->serialize(serverMsg.buffer); 401 406 402 407 // only broadcast message to other players in the same game 403 408 cout << "about to broadcast move" << endl; 404 409 405 map<unsigned int, Player*> playersInGame = it->second->currentGame->getPlayers();406 410 map<unsigned int, Player*>::iterator it2; 407 411 for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++) … … 895 899 flagType = WorldMap::OBJECT_RED_FLAG; 896 900 897 addObjectToMap(flagType, p->pos.x, p->pos.y, gameMap, mapPlayers, msgProcessor, sock, outputLog);901 addObjectToMap(flagType, p->pos.x, p->pos.y, p->currentGame->getMap(), p->currentGame->getPlayers(), msgProcessor, sock, outputLog); 898 902 899 903 p->hasBlueFlag = false;
Note:
See TracChangeset
for help on using the changeset viewer.