- Timestamp:
- Dec 20, 2013, 3:42:30 AM (11 years ago)
- Branches:
- master
- Children:
- b73bc28
- Parents:
- 6c9bcdd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
r6c9bcdd rce2bb87 153 153 154 154 map<unsigned int, Player*>::iterator it; 155 156 cout << "Updating player targets and respawning dead players" << endl; 155 157 156 158 // set targets for all chasing players (or make them attack if they're close enough) … … 216 218 } 217 219 220 cout << "Processing players in a game" << endl; 221 218 222 // process players currently in a game 219 223 FLOAT_POSITION oldPos; 220 224 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 221 225 { 226 if (it->second->currentGame == NULL) 227 continue; 228 229 cout << "moving player" << endl; 222 230 bool broadcastMove = false; 223 231 … … 226 234 if (it->second->move(it->second->currentGame->getMap())) { 227 235 236 cout << "player moved" << endl; 228 237 if (it->second->currentGame->processPlayerMovement(it->second, oldPos)) 229 238 broadcastMove = true; 239 cout << "player move processed" << endl; 230 240 231 241 /* … … 386 396 if (broadcastMove) 387 397 { 398 cout << "broadcasting player move" << endl; 388 399 serverMsg.type = MSG_TYPE_PLAYER; 389 400 it->second->serialize(serverMsg.buffer); … … 394 405 map<unsigned int, Player*> playersInGame = it->second->currentGame->getPlayers(); 395 406 map<unsigned int, Player*>::iterator it2; 396 for (it2 = playersInGame.begin(); it2 != playersInGame Players.end(); it2++)407 for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++) 397 408 { 398 409 if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 ) 399 410 error("sendMessage"); 400 411 } 401 } 402 } 412 cout << "done broadcasting player move" << endl; 413 } 414 } 415 416 cout << "processing player attack" << endl; 403 417 404 418 // check if the player's attack animation is complete … … 476 490 } 477 491 } 492 493 cout << "Processing projectiles" << endl; 478 494 479 495 // move all projectiles … … 540 556 cout << "Should be broadcasting the message" << endl; 541 557 558 // needs to be updated to use the players from the game 542 559 map<unsigned int, Player*>::iterator it; 543 560 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) … … 555 572 error("sendMessage"); 556 573 } 574 575 cout << "Finished processing the message" << endl; 557 576 } 558 577 } … … 651 670 cout << "new player id: " << p->id << endl; 652 671 p->setAddr(from); 672 p->currentGame = NULL; 653 673 654 674 // choose a random team (either 0 or 1) … … 835 855 836 856 Player* p = mapPlayers[id]; 837 838 vector<WorldMap::Object>* vctObjects = gameMap->getObjects(); 839 vector<WorldMap::Object>::iterator itObjects; 840 841 for (itObjects = vctObjects->begin(); itObjects != vctObjects->end();) { 842 POSITION pos = itObjects->pos; 843 bool gotFlag = false; 844 845 if (posDistance(p->pos, pos.toFloat()) < 10) { 846 switch (itObjects->type) { 847 case WorldMap::OBJECT_BLUE_FLAG: 848 if (p->team == 1) { 849 gotFlag = true; 850 p->hasBlueFlag = true; 851 broadcastResponse = true; 852 } 853 break; 854 case WorldMap::OBJECT_RED_FLAG: 855 if (p->team == 0) { 856 gotFlag = true; 857 p->hasRedFlag = true; 858 broadcastResponse = true; 859 } 860 break; 861 } 862 863 if (gotFlag) { 864 serverMsg.type = MSG_TYPE_REMOVE_OBJECT; 865 memcpy(serverMsg.buffer, &itObjects->id, 4); 866 867 map<unsigned int, Player*>::iterator it; 868 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 869 { 870 if ( msgProcessor.sendMessage(&serverMsg, sock, &(it->second->addr), &outputLog) < 0 ) 871 error("sendMessage"); 872 } 873 874 // remove the object from the server-side map 875 cout << "size before: " << gameMap->getObjects()->size() << endl; 876 itObjects = vctObjects->erase(itObjects); 877 cout << "size after: " << gameMap->getObjects()->size() << endl; 878 } 879 } 880 881 if (!gotFlag) 882 itObjects++; 883 } 884 857 int objectId = p->currentGame->processFlagPickupRequest(p); 858 859 if (objectId >= 0) { 860 serverMsg.type = MSG_TYPE_REMOVE_OBJECT; 861 memcpy(serverMsg.buffer, &objectId, 4); 862 863 map<unsigned int, Player*> players = p->currentGame->getPlayers(); 864 map<unsigned int, Player*>::iterator it; 865 for (it = players.begin(); it != players.end(); it++) 866 { 867 if ( msgProcessor.sendMessage(&serverMsg, sock, &(it->second->addr), &outputLog) < 0 ) 868 error("sendMessage"); 869 } 870 871 } 872 873 // if there was no flag to pickup, we really don't need to send a message 885 874 serverMsg.type = MSG_TYPE_PLAYER; 886 875 p->serialize(serverMsg.buffer);
Note:
See TracChangeset
for help on using the changeset viewer.