diff --git a/lib/serializer/ESerializationVersion.h b/lib/serializer/ESerializationVersion.h index 4ccc431e1..368d5786c 100644 --- a/lib/serializer/ESerializationVersion.h +++ b/lib/serializer/ESerializationVersion.h @@ -39,6 +39,7 @@ enum class ESerializationVersion : int32_t JSON_FLAGS, // 836 json uses new format for flags MANA_LIMIT, // 837 change MANA_PER_KNOWLEGDE to percentage BONUS_META_STRING, // 838 bonuses use MetaString instead of std::string for descriptions + TURN_TIMERS_STATE, // 839 current state of turn timers is serialized - CURRENT = BONUS_META_STRING + CURRENT = TURN_TIMERS_STATE }; diff --git a/server/CGameHandler.h b/server/CGameHandler.h index dffb78584..dc91d6370 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -230,6 +230,9 @@ public: h & *playerMessages; h & *turnOrder; + if (h.version >= Handler::Version::TURN_TIMERS_STATE) + h & *turnTimerHandler; + #if SCRIPTING_ENABLED JsonNode scriptsState; if(h.saving) diff --git a/server/TurnTimerHandler.h b/server/TurnTimerHandler.h index 8f6fae5a6..8def338f5 100644 --- a/server/TurnTimerHandler.h +++ b/server/TurnTimerHandler.h @@ -25,7 +25,7 @@ class CGameHandler; class TurnTimerHandler { CGameHandler & gameHandler; - const int turnTimePropagateFrequency = 1000; + static constexpr int turnTimePropagateFrequency = 1000; std::map timers; std::map lastUpdate; std::map endTurnAllowed; @@ -48,4 +48,11 @@ public: void update(int waitTime); void setTimerEnabled(PlayerColor player, bool enabled); void setEndTurnAllowed(PlayerColor player, bool enabled); + + template + void serialize(Handler & h) + { + h & timers; + h & endTurnAllowed; + } }; diff --git a/server/processors/TurnOrderProcessor.cpp b/server/processors/TurnOrderProcessor.cpp index 2266036a5..695abce63 100644 --- a/server/processors/TurnOrderProcessor.cpp +++ b/server/processors/TurnOrderProcessor.cpp @@ -249,10 +249,12 @@ void TurnOrderProcessor::doStartPlayerTurn(PlayerColor which) assert(gameHandler->getPlayerState(which)); assert(gameHandler->getPlayerState(which)->status == EPlayerStatus::INGAME); - //Note: on game load, "actingPlayer" might already contain list of players + // Only if player is actually starting his turn (and not loading from save) + if (!actingPlayers.count(which)) + gameHandler->onPlayerTurnStarted(which); + actingPlayers.insert(which); awaitingPlayers.erase(which); - gameHandler->onPlayerTurnStarted(which); auto turnQuery = std::make_shared(gameHandler, which); gameHandler->queries->addQuery(turnQuery);