MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / startNewTurn

Method startNewTurn

source/network/ODServer.cpp:304–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

302}
303
304void ODServer::startNewTurn(double timeSinceLastTurn)
305{
306 GameMap* gameMap = mGameMap;
307 int64_t turn = gameMap->getTurnNumber();
308
309 // We wait until every client acknowledge the turn to start the next one. This way, we ensure
310 // synchronisation is not too bad
311 for (ODSocketClient* client : mSockClients)
312 {
313 if(client->getLastTurnAck() != turn)
314 return;
315 }
316
317 gameMap->setTurnNumber(++turn);
318
319 ServerNotification* serverNotification = new ServerNotification(
320 ServerNotificationType::turnStarted, nullptr);
321 serverNotification->mPacket << turn;
322 queueServerNotification(serverNotification);
323
324 if(mServerMode == ServerMode::ModeEditor)
325 gameMap->updateVisibleEntities();
326
327 gameMap->updateAnimations(timeSinceLastTurn);
328
329 // We notify the clients about what they got
330 for (ODSocketClient* sock : mSockClients)
331 {
332 Player* player = sock->getPlayer();
333 // For now, only the player whose seat changed is notified. If we need it, we could send the event to every player
334 // so that they can see how far from the goals the other players are
335 ServerNotification *serverNotification = new ServerNotification(
336 ServerNotificationType::refreshPlayerSeat, player);
337 std::string goals = gameMap->getGoalsStringForPlayer(player);
338 Seat* seat = player->getSeat();
339 seat->exportToPacketForUpdate(serverNotification->mPacket);
340 serverNotification->mPacket << goals;
341 ODServer::getSingleton().queueServerNotification(serverNotification);
342
343 // Here, the creature list is pulled. It could be possible that the creature dies before the stat window is
344 // closed. So, if we cannot find the creature, we just erase it.
345 std::vector<std::string>& creatures = mCreaturesInfoWanted[sock];
346 std::vector<std::string>::iterator itCreatures = creatures.begin();
347 while(itCreatures != creatures.end())
348 {
349 std::string& name = *itCreatures;
350 Creature* creature = gameMap->getCreature(name);
351 if(creature == nullptr)
352 itCreatures = creatures.erase(itCreatures);
353 else
354 {
355 std::string creatureInfos = creature->getStatsText();
356
357 ServerNotification *serverNotification = new ServerNotification(
358 ServerNotificationType::notifyCreatureInfo, player);
359 serverNotification->mPacket << name << creatureInfos;
360 ODServer::getSingleton().queueServerNotification(serverNotification);
361

Callers

nothing calls this directly

Calls 15

getTurnNumberMethod · 0.80
getLastTurnAckMethod · 0.80
setTurnNumberMethod · 0.80
updateVisibleEntitiesMethod · 0.80
getStatsTextMethod · 0.80
doPlayerAITurnMethod · 0.80
fireRefreshEntitiesMethod · 0.80
processDeletionQueuesMethod · 0.80
updateAnimationsMethod · 0.45
getPlayerMethod · 0.45

Tested by

no test coverage detected