- Timestamp:
- May 25, 2013, 11:35:00 PM (12 years ago)
- Branches:
- master
- Children:
- b8601ee
- Parents:
- 4926168
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
r4926168 r5c84d54 214 214 } 215 215 216 vector<WorldMap::Object>* vctObjects = gameMap->getObjects();217 vector<WorldMap::Object>::iterator itObjects;218 219 for (itObjects = vctObjects->begin(); itObjects != vctObjects->end();) {220 POSITION pos = itObjects->pos;221 bool gotFlag = false;222 223 if (posDistance(it->second.pos, pos.toFloat()) < 10) {224 switch (itObjects->type) {225 case WorldMap::OBJECT_BLUE_FLAG:226 if (it->second.team == 1) {227 gotFlag = true;228 it->second.hasBlueFlag = true;229 broadcastMove = true;230 }231 break;232 case WorldMap::OBJECT_RED_FLAG:233 if (it->second.team == 0) {234 gotFlag = true;235 it->second.hasRedFlag = true;236 broadcastMove = true;237 }238 break;239 }240 241 if (gotFlag) {242 serverMsg.type = MSG_TYPE_REMOVE_OBJECT;243 memcpy(serverMsg.buffer, &itObjects->id, 4);244 245 map<unsigned int, Player>::iterator it2;246 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)247 {248 if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )249 error("sendMessage");250 }251 252 // remove the object from the server-side map253 cout << "size before: " << gameMap->getObjects()->size() << endl;254 itObjects = vctObjects->erase(itObjects);255 cout << "size after: " << gameMap->getObjects()->size() << endl;256 }257 }258 259 if (!gotFlag)260 itObjects++;261 }262 263 216 if (broadcastMove) { 264 217 serverMsg.type = MSG_TYPE_PLAYER; … … 526 479 cout << "id: " << id << endl; 527 480 481 vector<WorldMap::Object>* vctObjects = gameMap->getObjects(); 482 vector<WorldMap::Object>::iterator itObjects; 483 484 for (itObjects = vctObjects->begin(); itObjects != vctObjects->end();) { 485 POSITION pos = itObjects->pos; 486 bool gotFlag = false; 487 488 if (posDistance(mapPlayers[id].pos, pos.toFloat()) < 10) { 489 switch (itObjects->type) { 490 case WorldMap::OBJECT_BLUE_FLAG: 491 if (mapPlayers[id].team == 1) { 492 gotFlag = true; 493 mapPlayers[id].hasBlueFlag = true; 494 broadcastResponse = true; 495 } 496 break; 497 case WorldMap::OBJECT_RED_FLAG: 498 if (mapPlayers[id].team == 0) { 499 gotFlag = true; 500 mapPlayers[id].hasRedFlag = true; 501 broadcastResponse = true; 502 } 503 break; 504 } 505 506 if (gotFlag) { 507 serverMsg.type = MSG_TYPE_REMOVE_OBJECT; 508 memcpy(serverMsg.buffer, &itObjects->id, 4); 509 510 map<unsigned int, Player>::iterator it; 511 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 512 { 513 if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 ) 514 error("sendMessage"); 515 } 516 517 // remove the object from the server-side map 518 cout << "size before: " << gameMap->getObjects()->size() << endl; 519 itObjects = vctObjects->erase(itObjects); 520 cout << "size after: " << gameMap->getObjects()->size() << endl; 521 } 522 } 523 524 if (!gotFlag) 525 itObjects++; 526 } 527 528 serverMsg.type = MSG_TYPE_PLAYER; 529 mapPlayers[id].serialize(serverMsg.buffer); 530 528 531 break; 529 532 }
Note:
See TracChangeset
for help on using the changeset viewer.