1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Add turn timer allowed option

This commit is contained in:
nordsoft 2023-09-02 03:17:32 +04:00
parent cab2bddf7e
commit 9cd3b537ad
2 changed files with 12 additions and 1 deletions

View File

@ -36,6 +36,7 @@ void TurnTimerHandler::onGameplayStart(PlayerColor player)
timers[player].isActive = true;
timers[player].isBattle = false;
lastUpdate[player] = std::numeric_limits<int>::max();
endTurnAllowed[player] = true;
}
}
@ -47,6 +48,13 @@ void TurnTimerHandler::setTimerEnabled(PlayerColor player, bool enabled)
sendTimerUpdate(player);
}
void TurnTimerHandler::setEndTurnAllowed(PlayerColor player, bool enabled)
{
std::lock_guard<std::recursive_mutex> guard(mx);
assert(player.isValidPlayer());
endTurnAllowed[player] = enabled;
}
void TurnTimerHandler::sendTimerUpdate(PlayerColor player)
{
TurnTimeUpdate ttu;
@ -63,6 +71,7 @@ void TurnTimerHandler::onPlayerGetTurn(PlayerColor player)
{
if(si->turnTimerInfo.isEnabled())
{
endTurnAllowed[player] = true;
auto & timer = timers[player];
if(si->turnTimerInfo.baseTimer > 0)
timer.baseTimer += timer.turnTimer;
@ -125,7 +134,7 @@ void TurnTimerHandler::onPlayerMakingTurn(PlayerColor player, int waitTime)
timer.baseTimer = 0;
onPlayerMakingTurn(player, 0);
}
else if(!gameHandler.queries->topQuery(state->color)) //wait for replies to avoid pending queries
else if(endTurnAllowed[state->color] && !gameHandler.queries->topQuery(state->color)) //wait for replies to avoid pending queries
gameHandler.turnOrder->onPlayerEndsTurn(state->color);
}
}

View File

@ -29,6 +29,7 @@ class TurnTimerHandler
const int turnTimePropagateThreshold = 3000;
std::map<PlayerColor, TurnTimerInfo> timers;
std::map<PlayerColor, int> lastUpdate;
std::map<PlayerColor, bool> endTurnAllowed;
std::recursive_mutex mx;
void onPlayerMakingTurn(PlayerColor player, int waitTime);
@ -48,4 +49,5 @@ public:
void onBattleEnd();
void update(int waitTime);
void setTimerEnabled(PlayerColor player, bool enabled);
void setEndTurnAllowed(PlayerColor player, bool enabled);
};