From 716c324695a942772047a370fb15b66d0af5ab4b Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Sat, 24 Oct 2015 16:21:30 +0200 Subject: [PATCH] Don't give a turn to player who is about to lose (days without town). --- lib/NetPacks.h | 3 ++- lib/NetPacksLib.cpp | 12 +----------- server/CGameHandler.cpp | 33 ++++++++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 843a3d713..bf82db99c 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -167,10 +167,11 @@ struct YourTurn : public CPackForClient //100 DLL_LINKAGE void applyGs(CGameState *gs); PlayerColor player; + ui8 daysWithoutCastle; template void serialize(Handler &h, const int version) { - h & player; + h & player & daysWithoutCastle; } }; diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 88bdac197..ede41bd8b 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -1623,18 +1623,8 @@ DLL_LINKAGE void YourTurn::applyGs( CGameState *gs ) { gs->currentPlayer = player; - //count days without town auto & playerState = gs->players[player]; - if(playerState.towns.empty()) - { - if(playerState.daysWithoutCastle) - ++(*playerState.daysWithoutCastle); - else playerState.daysWithoutCastle = 0; - } - else - { - playerState.daysWithoutCastle = boost::none; - } + playerState.daysWithoutCastle = daysWithoutCastle; } DLL_LINKAGE Component::Component(const CStackBasicDescriptor &stack) diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index ee5f5f436..3253f378b 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1583,19 +1583,42 @@ void CGameHandler::run(bool resume) } resume = false; - for(; it != playerTurnOrder.end(); it++) + for (; it != playerTurnOrder.end(); it++) { auto playerColor = *it; - if(gs->players[playerColor].status == EPlayerStatus::INGAME) + + auto playerState = gs->players[playerColor]; + if (playerState.status == EPlayerStatus::INGAME) { - states.setFlag(playerColor, &PlayerStatus::makingTurn, true); + states.setFlag (playerColor, &PlayerStatus::makingTurn, true); + + //count days without town + if (playerState.towns.empty()) + { + if (playerState.daysWithoutCastle) + ++(*playerState.daysWithoutCastle); + else playerState.daysWithoutCastle = 0; + } + else + { + playerState.daysWithoutCastle = boost::none; //TODO: reset this immediatelly when player conquers any castle + } + + //if player runs out of time, he shouldn't get the turn (especially AI) + checkVictoryLossConditionsForAll(); + + if (gs->players[playerColor].status != EPlayerStatus::INGAME) + { //player lost at the beginning of his turn + continue; + } YourTurn yt; yt.player = playerColor; + //Change local daysWithoutCastle counter for local interface message //TODO: needed? + if (playerState.daysWithoutCastle) + yt.daysWithoutCastle = playerState.daysWithoutCastle.get(); applyAndSend(&yt); - checkVictoryLossConditionsForAll(); - //wait till turn is done boost::unique_lock lock(states.mx); while(states.players.at(playerColor).makingTurn && !end2)