Changeset 402cf86 in network-game for server/server.cpp


Ignore:
Timestamp:
Dec 20, 2013, 1:41:49 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
6c9bcdd
Parents:
fef7c69
Message:

The server checks player movement in individual games and stops players who hit obstacles

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    rfef7c69 r402cf86  
    138138   while (!done)
    139139   {
    140 
    141140      usleep(5000);
    142141
     
    217216         }
    218217
    219          // move all players
    220          // maybe put this in a separate method
     218         // process players currently in a game
    221219         FLOAT_POSITION oldPos;
    222          bool broadcastMove = false;
    223220         for (it = mapPlayers.begin(); it != mapPlayers.end(); it++)
    224221         {
     222            bool broadcastMove = false;
     223
     224            // move player and perform associated tasks
    225225            oldPos = it->second->pos;
    226             if (it->second->move(gameMap)) {
    227 
    228                // check if the move needs to be canceled
    229                switch(gameMap->getElement(it->second->pos.x/25, it->second->pos.y/25))
    230                {
    231                   case WorldMap::TERRAIN_NONE:
    232                   case WorldMap::TERRAIN_OCEAN:
    233                   case WorldMap::TERRAIN_ROCK:
    234                   {
    235                      it->second->pos = oldPos;
    236                      it->second->target.x = it->second->pos.x;
    237                      it->second->target.y = it->second->pos.y;
    238                      it->second->isChasing = false;
    239                      broadcastMove = true;
    240                      break;
    241                   }
    242                   default:
    243                      // if there are no obstacles, do nothing
    244                      break;
    245                }
    246 
     226            if (it->second->move(it->second->currentGame->getMap())) {
     227
     228               if (it->second->currentGame->processPlayerMovement(it->second, oldPos))
     229                   broadcastMove = true;
     230
     231               /*
    247232               WorldMap::ObjectType flagType;
    248233               POSITION pos;
     
    397382                  }
    398383               }
     384               */
    399385
    400386               if (broadcastMove)
     
    403389                  it->second->serialize(serverMsg.buffer);
    404390
     391                  // only broadcast message to other players in the same game
    405392                  cout << "about to broadcast move" << endl;
     393
     394                  map<unsigned int, Player*> playersInGame = it->second->currentGame->getPlayers();
    406395                  map<unsigned int, Player*>::iterator it2;
    407                   for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
     396                  for (it2 = playersInGame.begin(); it2 != playersInGamePlayers.end(); it2++)
    408397                  {
    409398                     if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
Note: See TracChangeset for help on using the changeset viewer.