Changeset 7511a2b in network-game


Ignore:
Timestamp:
May 25, 2013, 6:49:14 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
b8cb03f
Parents:
e487381
Message:

Resolved a bug where objects with duplicate ids were getting created

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    re487381 r7511a2b  
    453453            case MSG_TYPE_PLAYER:   // kind of hacky to put this here
    454454            {
    455                cout << "Got MSG_TYPE_PLAYER message in Start" << endl;
     455               cout << "Got MSG_TYPE_PLAYER message in STATE_START" << endl;
    456456
    457457               Player p("", "");
     
    467467            case MSG_TYPE_OBJECT:
    468468            {
    469                cout << "Received object message. Baller Biller!" << endl;
     469               cout << "Received OBJECT message in STATE_START." << endl;
    470470
    471471               WorldMap::Object o(0, WorldMap::OBJECT_NONE, 0, 0);
    472472               o.deserialize(msg.buffer);
     473               cout << "object id: " << o.id << endl;
    473474               gameMap->updateObject(o.id, o.type, o.pos.x, o.pos.y);
    474475
     
    511512            case MSG_TYPE_PLAYER:
    512513            {
    513                cout << "Got MSG_TYPE_PLAYER message in Login" << endl;
     514               cout << "Got MSG_TYPE_PLAYER message in STATE_LOGIN" << endl;
    514515
    515516               Player p("", "");
     
    544545            case MSG_TYPE_OBJECT:
    545546            {
    546                cout << "Received object message. Baller Biller!" << endl;
     547               cout << "Received object message in STATE_LOGIN." << endl;
    547548
    548549               WorldMap::Object o(0, WorldMap::OBJECT_NONE, 0, 0);
     
    554555            case MSG_TYPE_REMOVE_OBJECT:
    555556            {
     557               cout << "Received REMOVE_OBJECT message!" << endl;
     558
    556559               int id;
    557560               memcpy(&id, msg.buffer, 4);
     561
     562               cout << "Removing object with id " << id << endl;
     563
    558564               if (!gameMap->removeObject(id))
    559565                  cout << "Did not remove the object" << endl;
     566
     567               break;
    560568            }
    561569            default:
  • common/WorldMap.cpp

    re487381 r7511a2b  
    6868   return vctObjects;
    6969}
     70
    7071vector<WorldMap::Object> WorldMap::getObjects(int x, int y) {
    7172   vector<WorldMap::Object> vctObjectsInRegion;
    7273
    7374   vector<WorldMap::Object>::iterator it;
    74    for(it = vctObjects->begin(); it != vctObjects->end(); it++) {
     75   for (it = vctObjects->begin(); it != vctObjects->end(); it++) {
    7576      if (it->pos.x/25 == x && it->pos.y/25 == y)
    7677         vctObjectsInRegion.push_back(*it);
     
    8283// used by the server to create new objects
    8384void WorldMap::addObject(WorldMap::ObjectType t, int x, int y) {
    84    WorldMap::Object o(vctObjects->size(), t, x, y);
     85   int id;
     86   vector<WorldMap::Object>::iterator it;
     87
     88   for (id = 0; id < vctObjects->size(); id++) {
     89      for (it = vctObjects->begin(); it != vctObjects->end(); it++) {
     90         if (id == it->id)
     91            break;
     92      }
     93
     94      if (it == vctObjects->end())  // if no objects with this id exists
     95         break;
     96   }
     97
     98   WorldMap::Object o(id, t, x, y);
    8599   vctObjects->push_back(o);
    86100}
     
    91105   bool foundObject = false;
    92106
     107   cout << "Searching for obbject to update" << endl;
     108   switch (t) {
     109   case WorldMap::OBJECT_BLUE_FLAG:
     110      cout << "BLUE_FLAG" << endl;
     111      break;
     112   case WorldMap::OBJECT_RED_FLAG:
     113      cout << "RED_FLAG" << endl;
     114      break;
     115   }
     116
    93117   for (it = vctObjects->begin(); it != vctObjects->end(); it++) {
    94118      if (it->id == id) {
    95119         foundObject = true;
     120         cout << "Found object with id " << id << endl;
     121         switch (it->type) {
     122         case WorldMap::OBJECT_BLUE_FLAG:
     123            cout << "BLUE_FLAG" << endl;
     124            break;
     125         case WorldMap::OBJECT_RED_FLAG:
     126            cout << "RED_FLAG" << endl;
     127            break;
     128         }
    96129         it->pos.x = x;
    97130         it->pos.y = y;
Note: See TracChangeset for help on using the changeset viewer.