Changeset 45734ff in network-game for server


Ignore:
Timestamp:
Dec 22, 2013, 10:14:43 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
58ca135
Parents:
1d96513
Message:

The Game class stores a list of projectiles present in that game

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    r1d96513 r45734ff  
    4848
    4949void updateUnusedPlayerId(unsigned int& id, map<unsigned int, Player*>& mapPlayers);
    50 void updateUnusedProjectileId(unsigned int& id, map<unsigned int, Projectile>& mapProjectiles);
    5150Player *findPlayerByName(map<unsigned int, Player*> &m, string name);
    5251Player *findPlayerByAddr(map<unsigned int, Player*> &m, const sockaddr_in &addr);
     
    476475
    477476                  Projectile proj(p->pos.x, p->pos.y, p->targetPlayer, p->damage);
    478                   proj.id = unusedProjectileId;
    479                   updateUnusedProjectileId(unusedProjectileId, mapProjectiles);
    480                   mapProjectiles[proj.id] = proj;
    481 
    482                   int x = it->second->pos.x;
    483                   int y = it->second->pos.y;
     477                  p->currentGame->assignProjectileId(&proj);
     478                 
     479                  p->currentGame->addProjectile(proj);
     480
     481                  int x = p->pos.x;
     482                  int y = p->pos.y;
    484483
    485484                  serverMsg.type = MSG_TYPE_PROJECTILE;
     
    487486                  memcpy(serverMsg.buffer+4, &x, 4);
    488487                  memcpy(serverMsg.buffer+8, &y, 4);
    489                   memcpy(serverMsg.buffer+12, &it->second->targetPlayer, 4);
     488                  memcpy(serverMsg.buffer+12, &p->targetPlayer, 4);
    490489               }
    491490               else
     
    507506         // move all projectiles
    508507         // see if this can be moved inside the game class
     508         // this method can be moved when I add a MessageProcessor to the Game class
    509509         map<unsigned int, Projectile>::iterator itProj;
    510510         for (itProj = mapProjectiles.begin(); itProj != mapProjectiles.end(); itProj++)
     
    11981198}
    11991199
    1200 void updateUnusedProjectileId(unsigned int& id, map<unsigned int, Projectile>& mapProjectiles)
    1201 {
    1202    while (mapProjectiles.find(id) != mapProjectiles.end())
    1203       id++;
    1204 }
    1205 
    12061200Player *findPlayerByName(map<unsigned int, Player*> &m, string name)
    12071201{
Note: See TracChangeset for help on using the changeset viewer.