Changeset 402cf86 in network-game for server/server.cpp
- Timestamp:
- Dec 20, 2013, 1:41:49 AM (11 years ago)
- Branches:
- master
- Children:
- 6c9bcdd
- Parents:
- fef7c69
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
rfef7c69 r402cf86 138 138 while (!done) 139 139 { 140 141 140 usleep(5000); 142 141 … … 217 216 } 218 217 219 // move all players 220 // maybe put this in a separate method 218 // process players currently in a game 221 219 FLOAT_POSITION oldPos; 222 bool broadcastMove = false;223 220 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 224 221 { 222 bool broadcastMove = false; 223 224 // move player and perform associated tasks 225 225 oldPos = it->second->pos; 226 if (it->second->move(gameMap)) { 227 228 // check if the move needs to be canceled 229 switch(gameMap->getElement(it->second->pos.x/25, it->second->pos.y/25)) 230 { 231 case WorldMap::TERRAIN_NONE: 232 case WorldMap::TERRAIN_OCEAN: 233 case WorldMap::TERRAIN_ROCK: 234 { 235 it->second->pos = oldPos; 236 it->second->target.x = it->second->pos.x; 237 it->second->target.y = it->second->pos.y; 238 it->second->isChasing = false; 239 broadcastMove = true; 240 break; 241 } 242 default: 243 // if there are no obstacles, do nothing 244 break; 245 } 246 226 if (it->second->move(it->second->currentGame->getMap())) { 227 228 if (it->second->currentGame->processPlayerMovement(it->second, oldPos)) 229 broadcastMove = true; 230 231 /* 247 232 WorldMap::ObjectType flagType; 248 233 POSITION pos; … … 397 382 } 398 383 } 384 */ 399 385 400 386 if (broadcastMove) … … 403 389 it->second->serialize(serverMsg.buffer); 404 390 391 // only broadcast message to other players in the same game 405 392 cout << "about to broadcast move" << endl; 393 394 map<unsigned int, Player*> playersInGame = it->second->currentGame->getPlayers(); 406 395 map<unsigned int, Player*>::iterator it2; 407 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)396 for (it2 = playersInGame.begin(); it2 != playersInGamePlayers.end(); it2++) 408 397 { 409 398 if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
Note:
See TracChangeset
for help on using the changeset viewer.