Changeset 411c1ae in network-game


Ignore:
Timestamp:
Jul 23, 2013, 11:31:40 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
46d6469
Parents:
eab83af
Message:

When a player dies or logs off, he drops any flag he might be carrying

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    reab83af r411c1ae  
    4444void updateUnusedProjectileId(unsigned int& id, map<unsigned int, Projectile>& mapProjectiles);
    4545void damagePlayer(Player *p, int damage);
     46
     47void addObjectToMap(WorldMap::ObjectType objectType, int x, int y, WorldMap* gameMap, map<unsigned int, Player>& mapPlayers, MessageProcessor &msgProcessor, int sock);
    4648
    4749// this should probably go somewhere in the common folder
     
    412414                  damagePlayer(target, it->second.damage);
    413415
     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
    414428                  serverMsg.type = MSG_TYPE_PLAYER;
    415429                  target->serialize(serverMsg.buffer);
     
    469483
    470484               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               }
    471497
    472498               serverMsg.type = MSG_TYPE_PLAYER;
     
    664690         else
    665691         {
     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
    666704            if (p->id < unusedPlayerId)
    667705               unusedPlayerId = p->id;
     
    821859            flagType = WorldMap::OBJECT_RED_FLAG;
    822860
    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);
    835862
    836863         mapPlayers[id].hasBlueFlag = false;
     
    911938   }
    912939}
     940
     941void 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.