mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Add turn timer allowed option
This commit is contained in:
@@ -36,6 +36,7 @@ void TurnTimerHandler::onGameplayStart(PlayerColor player)
|
|||||||
timers[player].isActive = true;
|
timers[player].isActive = true;
|
||||||
timers[player].isBattle = false;
|
timers[player].isBattle = false;
|
||||||
lastUpdate[player] = std::numeric_limits<int>::max();
|
lastUpdate[player] = std::numeric_limits<int>::max();
|
||||||
|
endTurnAllowed[player] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,6 +48,13 @@ void TurnTimerHandler::setTimerEnabled(PlayerColor player, bool enabled)
|
|||||||
sendTimerUpdate(player);
|
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)
|
void TurnTimerHandler::sendTimerUpdate(PlayerColor player)
|
||||||
{
|
{
|
||||||
TurnTimeUpdate ttu;
|
TurnTimeUpdate ttu;
|
||||||
@@ -63,6 +71,7 @@ void TurnTimerHandler::onPlayerGetTurn(PlayerColor player)
|
|||||||
{
|
{
|
||||||
if(si->turnTimerInfo.isEnabled())
|
if(si->turnTimerInfo.isEnabled())
|
||||||
{
|
{
|
||||||
|
endTurnAllowed[player] = true;
|
||||||
auto & timer = timers[player];
|
auto & timer = timers[player];
|
||||||
if(si->turnTimerInfo.baseTimer > 0)
|
if(si->turnTimerInfo.baseTimer > 0)
|
||||||
timer.baseTimer += timer.turnTimer;
|
timer.baseTimer += timer.turnTimer;
|
||||||
@@ -125,7 +134,7 @@ void TurnTimerHandler::onPlayerMakingTurn(PlayerColor player, int waitTime)
|
|||||||
timer.baseTimer = 0;
|
timer.baseTimer = 0;
|
||||||
onPlayerMakingTurn(player, 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);
|
gameHandler.turnOrder->onPlayerEndsTurn(state->color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class TurnTimerHandler
|
|||||||
const int turnTimePropagateThreshold = 3000;
|
const int turnTimePropagateThreshold = 3000;
|
||||||
std::map<PlayerColor, TurnTimerInfo> timers;
|
std::map<PlayerColor, TurnTimerInfo> timers;
|
||||||
std::map<PlayerColor, int> lastUpdate;
|
std::map<PlayerColor, int> lastUpdate;
|
||||||
|
std::map<PlayerColor, bool> endTurnAllowed;
|
||||||
std::recursive_mutex mx;
|
std::recursive_mutex mx;
|
||||||
|
|
||||||
void onPlayerMakingTurn(PlayerColor player, int waitTime);
|
void onPlayerMakingTurn(PlayerColor player, int waitTime);
|
||||||
@@ -48,4 +49,5 @@ public:
|
|||||||
void onBattleEnd();
|
void onBattleEnd();
|
||||||
void update(int waitTime);
|
void update(int waitTime);
|
||||||
void setTimerEnabled(PlayerColor player, bool enabled);
|
void setTimerEnabled(PlayerColor player, bool enabled);
|
||||||
|
void setEndTurnAllowed(PlayerColor player, bool enabled);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user