Changeset 9ba9b96 in network-game


Ignore:
Timestamp:
Jan 20, 2014, 4:59:34 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
949cf70
Parents:
d998572
Message:

All ids should now be unsigned ints

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • common/Player.cpp

    rd998572 r9ba9b96  
    100100}
    101101
    102 void Player::setId(int id)
     102void Player::setId(unsigned int id)
    103103{
    104104   this->id = id;
  • common/Player.h

    rd998572 r9ba9b96  
    4141   ~Player();
    4242
    43    void setId(int id);
     43   void setId(unsigned int id);
    4444   void setAddr(sockaddr_in addr);
    4545   void setClass(PlayerClass c);
     
    5252   void takeDamage(int damage);
    5353
    54    void takeFlag(int flag, WorldMap* map);
    55    void dropFlag(int flag, WorldMap* map);
     54   void takeFlag(unsigned int flag, WorldMap* map);
     55   void dropFlag(unsigned int flag, WorldMap* map);
    5656
    57    int id;
     57   unsigned int id;
    5858   string name;
    5959   string password;
     
    6666   bool isChasing;
    6767   bool isAttacking;
    68    int targetPlayer;
     68   unsigned int targetPlayer;
    6969   bool isDead;
    7070
  • common/Projectile.cpp

    rd998572 r9ba9b96  
    4545}
    4646
    47 void Projectile::setId(int id)
     47void Projectile::setId(unsigned int id)
    4848{
    4949   this->id = id;
  • common/Projectile.h

    rd998572 r9ba9b96  
    1313class Projectile {
    1414public:
     15   unsigned int id;
     16   POSITION pos;
     17   unsigned int target;
     18   int speed;
     19   int damage;
     20   unsigned long long timeLastUpdated;
    1521
    1622   Projectile();
     
    2026   ~Projectile();
    2127
    22    void setId(int id);
     28   void setId(unsigned int id);
    2329
    2430   void serialize(char* buffer);
    2531   void deserialize(char* buffer);
    2632
    27    // returns true if it reached the target and should be deleted
     33   // returns true if the projectile reached the target and should be deleted
    2834   bool move(map<unsigned int, Player*>& mapPlayers);
    29 
    30    /*
    31     * target should become a Player*. When this object gets serialized, the player's id should be sent.
    32     * Deserialization in this case might be tricky since it will require a playerMap to turn the id into a Plauyer*
    33     */
    34 
    35    int id;
    36    POSITION pos;
    37    int target;
    38    int speed;
    39    int damage;
    40    unsigned long long timeLastUpdated;
    4135};
    4236
  • common/WorldMap.cpp

    rd998572 r9ba9b96  
    102102// used by the server to create new objects
    103103void WorldMap::addObject(WorldMap::ObjectType t, int x, int y) {
    104    int id;
     104   unsigned int id;
    105105   vector<WorldMap::Object>::iterator it;
    106106
     
    111111      }
    112112
    113       if (it == vctObjects->end())  // if no objects with this id exists
     113      if (it == vctObjects->end())  // if no objects with this id exist
    114114         break;
    115115   }
     
    120120
    121121// used by the client to update object positions or create objects it has not seen before
    122 void WorldMap::updateObject(int id, WorldMap::ObjectType t, int x, int y) {
     122void WorldMap::updateObject(unsigned int id, WorldMap::ObjectType t, int x, int y) {
    123123   vector<WorldMap::Object>::iterator it;
    124124   bool foundObject = false;
     
    157157}
    158158
    159 bool WorldMap::removeObject(int id) {
     159bool WorldMap::removeObject(unsigned int id) {
    160160   vector<WorldMap::Object>::iterator it;
    161161
     
    316316/*** Functions for Object ***/
    317317
    318 WorldMap::Object::Object(int id, ObjectType type, int x, int y) {
     318WorldMap::Object::Object(unsigned int id, ObjectType type, int x, int y) {
    319319   this->type = type;
    320320   this->id = id;
     
    323323}
    324324
    325 WorldMap::Object::Object(int id, ObjectType type, POSITION pos) {
     325WorldMap::Object::Object(unsigned int id, ObjectType type, POSITION pos) {
    326326   this->type = type;
    327327   this->id = id;
  • common/WorldMap.h

    rd998572 r9ba9b96  
    3232   class Object {
    3333   public:
    34       int id;
     34      unsigned int id;
    3535      ObjectType type;
    3636      POSITION pos;
    3737
    38       Object(int id, ObjectType type, int x, int y);
    39       Object(int id, ObjectType type, POSITION pos);
     38      Object(unsigned int id, ObjectType type, int x, int y);
     39      Object(unsigned int id, ObjectType type, POSITION pos);
    4040
    4141      ~Object();
     
    6565
    6666   void addObject(ObjectType type, int x, int y);
    67    void updateObject(int id, WorldMap::ObjectType t, int x, int y);
    68    bool removeObject(int id);
     67   void updateObject(unsigned int id, WorldMap::ObjectType t, int x, int y);
     68   bool removeObject(unsigned int id);
    6969
    7070   static WorldMap* createDefaultMap();
  • server/server.cpp

    rd998572 r9ba9b96  
    450450         cout << "PLAYER_MOVE" << endl;
    451451
    452          int id, x, y;
     452         unsigned int id;
     453         int x, y;
    453454
    454455         memcpy(&id, clientMsg.buffer, 4);
     
    493494         cout << "PICKUP_FLAG" << endl;
    494495
    495          int id;
     496         unsigned int id;
    496497
    497498         memcpy(&id, clientMsg.buffer, 4);
     
    499500
    500501         Player* p = mapPlayers[id];
    501          int objectId = p->currentGame->processFlagPickupRequest(p);
     502         unsigned int objectId = p->currentGame->processFlagPickupRequest(p);
    502503
    503504         if (objectId >= 0) {
     
    520521         cout << "DROP_FLAG" << endl;
    521522
    522          int id;
     523         unsigned int id;
    523524
    524525         memcpy(&id, clientMsg.buffer, 4);
     
    550551         cout << "Received a START_ATTACK message" << endl;
    551552
    552          int id, targetId;
     553         unsigned int id, targetId;
    553554
    554555         memcpy(&id, clientMsg.buffer, 4);
     
    726727         serverMsg.type = MSG_TYPE_SCORE;
    727728
    728          int blueScore = g->getBlueScore();
    729          int redScore = g->getRedScore();
     729         unsigned int blueScore = g->getBlueScore();
     730         unsigned int redScore = g->getRedScore();
    730731         memcpy(serverMsg.buffer, &blueScore, 4);
    731732         memcpy(serverMsg.buffer+4, &redScore, 4);
Note: See TracChangeset for help on using the changeset viewer.