Changeset b73bc28 in network-game


Ignore:
Timestamp:
Dec 21, 2013, 2:35:19 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
d3efa1a
Parents:
ce2bb87
Message:

Turning in the opposing team's flag now works in individual games and returning your own should as well, but hasn't been tested

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    rce2bb87 rb73bc28  
    224224         for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
    225225         {
    226             if (it->second->currentGame == NULL)
     226            Player* p = it->second;
     227            if (p->currentGame == NULL)
    227228               continue;
    228229
     
    231232
    232233            // 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())) {
    235236
    236237               cout << "player moved" << endl;
    237                if (it->second->currentGame->processPlayerMovement(it->second, oldPos))
     238               if (p->currentGame->processPlayerMovement(p, oldPos))
    238239                   broadcastMove = true;
    239240               cout << "player move processed" << endl;
    240241
    241                /*
     242               map<unsigned int, Player*>& playersInGame = p->currentGame->getPlayers();
     243
    242244               WorldMap::ObjectType flagType;
    243245               POSITION pos;
     
    245247               bool flagReturned = false;
    246248               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))
    249254               {
    250255                  case WorldMap::STRUCTURE_BLUE_FLAG:
    251256                  {
    252                      if (it->second->team == 0 && it->second->hasRedFlag)
     257                     if (p->team == 0 && p->hasRedFlag)
    253258                     {
    254259                        // check that your flag is at your base
    255                         pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
     260                        pos = playerMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
    256261                       
    257                         vector<WorldMap::Object>* vctObjects = gameMap->getObjects();
     262                        vector<WorldMap::Object>* vctObjects = playerMap->getObjects();
    258263                        vector<WorldMap::Object>::iterator itObjects;
    259264
     
    272277                        if (ownFlagAtBase)
    273278                        {
    274                            it->second->hasRedFlag = false;
     279                           p->hasRedFlag = false;
    275280                           flagType = WorldMap::OBJECT_RED_FLAG;
    276                            pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
     281                           pos = playerMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
    277282                           flagTurnedIn = true;
    278283                           scoreBlue++;
     
    284289                  case WorldMap::STRUCTURE_RED_FLAG:
    285290                  {
    286                      if (it->second->team == 1 && it->second->hasBlueFlag)
     291                     if (p->team == 1 && p->hasBlueFlag)
    287292                     {
    288293                        // check that your flag is at your base
    289                         pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
     294                        pos = playerMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
    290295                       
    291                         vector<WorldMap::Object>* vctObjects = gameMap->getObjects();
     296                        vector<WorldMap::Object>* vctObjects = playerMap->getObjects();
    292297                        vector<WorldMap::Object>::iterator itObjects;
    293298
     
    306311                        if (ownFlagAtBase)
    307312                        {
    308                            it->second->hasBlueFlag = false;
     313                           p->hasBlueFlag = false;
    309314                           flagType = WorldMap::OBJECT_BLUE_FLAG;
    310                            pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
     315                           pos = playerMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
    311316                           flagTurnedIn = true;
    312317                           scoreRed++;
     
    323328                  pos.x = pos.x*25+12;
    324329                  pos.y = pos.y*25+12;
    325                   gameMap->addObject(flagType, pos.x, pos.y);
     330                  playerMap->addObject(flagType, pos.x, pos.y);
    326331
    327332                  serverMsg.type = MSG_TYPE_OBJECT;
    328                   gameMap->getObjects()->back().serialize(serverMsg.buffer);
     333                  playerMap->getObjects()->back().serialize(serverMsg.buffer);
    329334
    330335                  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++)
    332338                  {
    333339                     if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
     
    339345                  memcpy(serverMsg.buffer+4, &scoreRed, 4);
    340346
    341                   for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
     347                  for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++)
    342348                  {
    343349                     if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
     
    350356
    351357               // 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();
    353359               vector<WorldMap::Object>::iterator itObjects;
    354360               POSITION structPos;
     
    358364                  POSITION pos = itObjects->pos;
    359365
    360                   if (posDistance(it->second->pos, pos.toFloat()) < 10)
     366                  if (posDistance(p->pos, pos.toFloat()) < 10)
    361367                  {
    362                      if (it->second->team == 0 &&
     368                     if (p->team == 0 &&
    363369                         itObjects->type == WorldMap::OBJECT_BLUE_FLAG)
    364370                     {
    365                         structPos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
     371                        structPos = playerMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG);
    366372                        flagReturned = true;
    367373                        break;
    368374                     }
    369                      else if (it->second->team == 1 &&
     375                     else if (p->team == 1 &&
    370376                              itObjects->type == WorldMap::OBJECT_RED_FLAG)
    371377                     {
    372                         structPos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
     378                        structPos = playerMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG);
    373379                        flagReturned = true;
    374380                        break;
     
    386392
    387393                  map<unsigned int, Player*>::iterator it2;
    388                   for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
     394                  for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++)
    389395                  {
    390396                     if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
     
    392398                  }
    393399               }
    394                */
    395400
    396401               if (broadcastMove)
     
    398403                  cout << "broadcasting player move" << endl;
    399404                  serverMsg.type = MSG_TYPE_PLAYER;
    400                   it->second->serialize(serverMsg.buffer);
     405                  p->serialize(serverMsg.buffer);
    401406
    402407                  // only broadcast message to other players in the same game
    403408                  cout << "about to broadcast move" << endl;
    404409
    405                   map<unsigned int, Player*> playersInGame = it->second->currentGame->getPlayers();
    406410                  map<unsigned int, Player*>::iterator it2;
    407411                  for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++)
     
    895899            flagType = WorldMap::OBJECT_RED_FLAG;
    896900
    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);
    898902
    899903         p->hasBlueFlag = false;
Note: See TracChangeset for help on using the changeset viewer.