Changeset 411c1ae in network-game
- Timestamp:
- Jul 23, 2013, 11:31:40 PM (11 years ago)
- Branches:
- master
- Children:
- 46d6469
- Parents:
- eab83af
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
reab83af r411c1ae 44 44 void updateUnusedProjectileId(unsigned int& id, map<unsigned int, Projectile>& mapProjectiles); 45 45 void damagePlayer(Player *p, int damage); 46 47 void addObjectToMap(WorldMap::ObjectType objectType, int x, int y, WorldMap* gameMap, map<unsigned int, Player>& mapPlayers, MessageProcessor &msgProcessor, int sock); 46 48 47 49 // this should probably go somewhere in the common folder … … 412 414 damagePlayer(target, it->second.damage); 413 415 416 if (target->isDead) { 417 WorldMap::ObjectType flagType = WorldMap::OBJECT_NONE; 418 if (target->hasBlueFlag) 419 flagType = WorldMap::OBJECT_BLUE_FLAG; 420 else if (target->hasRedFlag) 421 flagType = WorldMap::OBJECT_RED_FLAG; 422 423 if (flagType != WorldMap::OBJECT_NONE) { 424 addObjectToMap(flagType, target->pos.x, target->pos.y, gameMap, mapPlayers, msgProcessor, sock); 425 } 426 } 427 414 428 serverMsg.type = MSG_TYPE_PLAYER; 415 429 target->serialize(serverMsg.buffer); … … 469 483 470 484 damagePlayer(target, itProj->second.damage); 485 486 if (target->isDead) { 487 WorldMap::ObjectType flagType = WorldMap::OBJECT_NONE; 488 if (target->hasBlueFlag) 489 flagType = WorldMap::OBJECT_BLUE_FLAG; 490 else if (target->hasRedFlag) 491 flagType = WorldMap::OBJECT_RED_FLAG; 492 493 if (flagType != WorldMap::OBJECT_NONE) { 494 addObjectToMap(flagType, target->pos.x, target->pos.y, gameMap, mapPlayers, msgProcessor, sock); 495 } 496 } 471 497 472 498 serverMsg.type = MSG_TYPE_PLAYER; … … 664 690 else 665 691 { 692 if (!p->isDead) { 693 WorldMap::ObjectType flagType = WorldMap::OBJECT_NONE; 694 if (p->hasBlueFlag) 695 flagType = WorldMap::OBJECT_BLUE_FLAG; 696 else if (p->hasRedFlag) 697 flagType = WorldMap::OBJECT_RED_FLAG; 698 699 if (flagType != WorldMap::OBJECT_NONE) { 700 addObjectToMap(flagType, p->pos.x, p->pos.y, gameMap, mapPlayers, msgProcessor, sock); 701 } 702 } 703 666 704 if (p->id < unusedPlayerId) 667 705 unusedPlayerId = p->id; … … 821 859 flagType = WorldMap::OBJECT_RED_FLAG; 822 860 823 gameMap->addObject(flagType, mapPlayers[id].pos.x, mapPlayers[id].pos.y); 824 825 // need to send the OBJECT message too 826 serverMsg.type = MSG_TYPE_OBJECT; 827 gameMap->getObjects()->back().serialize(serverMsg.buffer); 828 829 map<unsigned int, Player>::iterator it; 830 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 831 { 832 if ( msgProcessor.sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 ) 833 error("sendMessage"); 834 } 861 addObjectToMap(flagType, mapPlayers[id].pos.x, mapPlayers[id].pos.y, gameMap, mapPlayers, msgProcessor, sock); 835 862 836 863 mapPlayers[id].hasBlueFlag = false; … … 911 938 } 912 939 } 940 941 void addObjectToMap(WorldMap::ObjectType objectType, int x, int y, WorldMap* gameMap, map<unsigned int, Player>& mapPlayers, MessageProcessor &msgProcessor, int sock) { 942 NETWORK_MSG serverMsg; 943 944 gameMap->addObject(objectType, x, y); 945 946 // need to send the OBJECT message too 947 serverMsg.type = MSG_TYPE_OBJECT; 948 gameMap->getObjects()->back().serialize(serverMsg.buffer); 949 950 map<unsigned int, Player>::iterator it; 951 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 952 { 953 if ( msgProcessor.sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 ) 954 error("sendMessage"); 955 } 956 }
Note:
See TracChangeset
for help on using the changeset viewer.