Changeset 5ae8dca in network-game for server


Ignore:
Timestamp:
Dec 22, 2013, 10:59:13 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
35f6097
Parents:
58ca135
Message:

Server moves projectiles in all individual games and damages players and sends correct messages when a projectile hits in individual games

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    r58ca135 r5ae8dca  
    507507         // see if this can be moved inside the game class
    508508         // this method can be moved when I add a MessageProcessor to the Game class
     509         map<string, Game*>::iterator itGames;
     510         Game* game;
    509511         map<unsigned int, Projectile>::iterator itProj;
    510          for (itProj = mapProjectiles.begin(); itProj != mapProjectiles.end(); itProj++)
    511          {
    512             cout << "About to call projectile move" << endl;
    513             if (itProj->second.move(mapPlayers))
     512         for (itGames = mapGames.begin(); itGames != mapGames.end(); itGames++) {
     513            game = itGames->second;
     514            for (itProj = game->getProjectiles().begin(); itProj != game->getProjectiles().end(); itProj++)
    514515            {
    515                // send a REMOVE_PROJECTILE message
    516                cout << "send a REMOVE_PROJECTILE message" << endl;
    517                serverMsg.type = MSG_TYPE_REMOVE_PROJECTILE;
    518                memcpy(serverMsg.buffer, &itProj->second.id, 4);
    519                mapProjectiles.erase(itProj->second.id);
    520 
    521                map<unsigned int, Player*>::iterator it2;
    522                cout << "Broadcasting REMOVE_PROJECTILE" << endl;
    523                for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
     516               cout << "About to call projectile move" << endl;
     517               if (itProj->second.move(game->getPlayers()))
    524518               {
    525                   if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
    526                      error("sendMessage");
    527                }
    528 
    529                cout << "send a PLAYER message after dealing damage" << endl;
    530                // send a PLAYER message after dealing damage
    531                Player* target = mapPlayers[itProj->second.target];
    532 
    533                damagePlayer(target, itProj->second.damage);
    534 
    535                if (target->isDead)
    536                {
    537                   WorldMap::ObjectType flagType = WorldMap::OBJECT_NONE;
    538                   if (target->hasBlueFlag)
    539                      flagType = WorldMap::OBJECT_BLUE_FLAG;
    540                   else if (target->hasRedFlag)
    541                      flagType = WorldMap::OBJECT_RED_FLAG;
    542 
    543                   if (flagType != WorldMap::OBJECT_NONE)
    544                      addObjectToMap(flagType, target->pos.x, target->pos.y, gameMap, mapPlayers, msgProcessor, sock, outputLog);
    545                }
    546 
    547                serverMsg.type = MSG_TYPE_PLAYER;
    548                target->serialize(serverMsg.buffer);
    549 
    550                cout << "Sending a PLAYER message" << endl;
    551                for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
    552                {
    553                   if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
    554                      error("sendMessage");
    555                }
    556             }
    557             cout << "Projectile was not moved" << endl;
     519                  // send a REMOVE_PROJECTILE message
     520                  cout << "send a REMOVE_PROJECTILE message" << endl;
     521                  serverMsg.type = MSG_TYPE_REMOVE_PROJECTILE;
     522                  memcpy(serverMsg.buffer, &itProj->second.id, 4);
     523                  game->removeProjectile(itProj->second.id);
     524
     525                  map<unsigned int, Player*>::iterator it2;
     526                  cout << "Broadcasting REMOVE_PROJECTILE" << endl;
     527                  for (it2 = game->getPlayers().begin(); it2 != game->getPlayers().end(); it2++)
     528                  {
     529                     if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
     530                        error("sendMessage");
     531                  }
     532
     533                  cout << "send a PLAYER message after dealing damage" << endl;
     534                  // send a PLAYER message after dealing damage
     535                  Player* target = game->getPlayers()[itProj->second.target];
     536
     537                  damagePlayer(target, itProj->second.damage);
     538
     539                  if (target->isDead)
     540                  {
     541                     WorldMap::ObjectType flagType = WorldMap::OBJECT_NONE;
     542                     if (target->hasBlueFlag)
     543                        flagType = WorldMap::OBJECT_BLUE_FLAG;
     544                     else if (target->hasRedFlag)
     545                        flagType = WorldMap::OBJECT_RED_FLAG;
     546
     547                     if (flagType != WorldMap::OBJECT_NONE)
     548                        addObjectToMap(flagType, target->pos.x, target->pos.y, game->getMap(), game->getPlayers(), msgProcessor, sock, outputLog);
     549                  }
     550
     551                  serverMsg.type = MSG_TYPE_PLAYER;
     552                  target->serialize(serverMsg.buffer);
     553
     554                  cout << "Sending a PLAYER message" << endl;
     555                  for (it2 = game->getPlayers().begin(); it2 != game->getPlayers().end(); it2++)
     556                  {
     557                     if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
     558                        error("sendMessage");
     559                  }
     560               }
     561               cout << "Projectile was not moved" << endl;
     562            }
    558563         }
    559564      }
Note: See TracChangeset for help on using the changeset viewer.