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

Timers fixes

This commit is contained in:
nordsoft 2023-08-30 03:33:59 +04:00
parent 9a42abe2a7
commit cc3ca9a41e
5 changed files with 64 additions and 56 deletions

View File

@ -97,27 +97,9 @@ void TurnTimerWidget::setTime(PlayerColor player, int time)
}
}
void TurnTimerWidget::tick(uint32_t msPassed)
void TurnTimerWidget::updateTimer(PlayerColor player, uint32_t msPassed)
{
if(!LOCPLINT || !LOCPLINT->cb)
return;
for(PlayerColor p(0); p < PlayerColor::PLAYER_LIMIT; ++p)
{
auto player = p;
if(LOCPLINT->battleInt)
{
if(auto * stack = LOCPLINT->battleInt->stacksController->getActiveStack())
player = stack->getOwner();
else
continue;
if(p != player)
continue;
}
else if(!LOCPLINT->cb->isPlayerMakingTurn(player))
continue;
auto time = LOCPLINT->cb->getPlayerTurnTime(player);
const auto & time = LOCPLINT->cb->getPlayerTurnTime(player);
if(time.isActive)
cachedTurnTime -= msPassed;
@ -153,4 +135,25 @@ void TurnTimerWidget::tick(uint32_t msPassed)
else
timeCheckAndUpdate(0);
}
void TurnTimerWidget::tick(uint32_t msPassed)
{
if(!LOCPLINT || !LOCPLINT->cb)
return;
if(LOCPLINT->battleInt)
{
if(auto * stack = LOCPLINT->battleInt->stacksController->getActiveStack())
updateTimer(stack->getOwner(), msPassed);
else
updateTimer(PlayerColor::NEUTRAL, msPassed);
}
else
{
for(PlayerColor p(0); p < PlayerColor::PLAYER_LIMIT; ++p)
{
if(LOCPLINT->cb->isPlayerMakingTurn(p))
updateTimer(p, msPassed);
}
}
}

View File

@ -47,6 +47,8 @@ private:
std::shared_ptr<DrawRect> buildDrawRect(const JsonNode & config) const;
void updateTimer(PlayerColor player, uint32_t msPassed);
public:
void show(Canvas & to) override;

View File

@ -19,7 +19,7 @@ struct DLL_LINKAGE TurnTimerInfo
int battleTimer = 0; //in ms, counts down during battles when creature timer runs out
int creatureTimer = 0; //in ms, counts down when player is choosing action in battle
bool isActive = true; //should be paused if set to false
bool isActive = false; //is being counting down
bool isBattle = false; //indicator for current timer mode
bool isEnabled() const;

View File

@ -187,14 +187,18 @@ void TurnTimerHandler::onBattleEnd()
for(auto i : {attacker, defender})
{
if(i.isValidPlayer() && !pvpBattle)
if(i.isValidPlayer())
{
auto & timer = timers[i];
timer.isBattle = false;
if(!pvpBattle)
{
if(si->turnTimerInfo.baseTimer && timer.baseTimer == 0)
timer.baseTimer = timer.creatureTimer;
else if(si->turnTimerInfo.turnTimer && timer.turnTimer == 0)
timer.turnTimer = timer.creatureTimer;
}
sendTimerUpdate(i);
}

View File

@ -263,9 +263,8 @@ void BattleResultProcessor::endBattle(int3 tile, const CGHeroInstance * heroAtta
otherBattleQuery->result = battleQuery->result;
}
gameHandler->sendAndApply(battleResult.get()); //after this point casualties objects are destroyed
gameHandler->turnTimerHandler.onBattleEnd();
gameHandler->sendAndApply(battleResult.get()); //after this point casualties objects are destroyed
if (battleResult->queryID == QueryID::NONE)
endBattleConfirm(gameHandler->gameState()->curB);