From a1092e0f3f63849ec8eb2fd983a3a077bfc94087 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Thu, 17 Aug 2023 15:18:16 +0300 Subject: [PATCH] Fix battle ending --- server/battles/BattleFlowProcessor.cpp | 13 ++++++++++--- server/battles/BattleProcessor.cpp | 5 ++++- server/battles/BattleProcessor.h | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/server/battles/BattleFlowProcessor.cpp b/server/battles/BattleFlowProcessor.cpp index be38cf39d..73adaa533 100644 --- a/server/battles/BattleFlowProcessor.cpp +++ b/server/battles/BattleFlowProcessor.cpp @@ -227,7 +227,8 @@ void BattleFlowProcessor::onTacticsEnded() castOpeningSpells(); // it is possible that due to opening spells one side was eliminated -> check for end of battle - owner->checkBattleStateChanges(); + if (owner->checkBattleStateChanges()) + return; startNextRound(true); activateNextStack(); @@ -301,6 +302,10 @@ void BattleFlowProcessor::activateNextStack() // Find next stack that requires manual control for (;;) { + // battle has ended + if (owner->checkBattleStateChanges()) + return; + const CStack * next = getNextStack(); if (!next) @@ -520,7 +525,10 @@ void BattleFlowProcessor::onActionMade(const BattleAction &ba) assert(activeStack != nullptr); //we're after action, all results applied - owner->checkBattleStateChanges(); //check if this action ended the battle + + // check whether action has ended the battle + if(owner->checkBattleStateChanges()) + return; bool heroAction = ba.actionType == EActionType::HERO_SPELL || ba.actionType ==EActionType::SURRENDER || ba.actionType ==EActionType::RETREAT || ba.actionType ==EActionType::END_TACTIC_PHASE; @@ -571,7 +579,6 @@ bool BattleFlowProcessor::makeAutomaticAction(const CStack *stack, BattleAction gameHandler->sendAndApply(&bsa); bool ret = owner->makeBattleAction(ba); - owner->checkBattleStateChanges(); return ret; } diff --git a/server/battles/BattleProcessor.cpp b/server/battles/BattleProcessor.cpp index b1b854aa6..9b9a13770 100644 --- a/server/battles/BattleProcessor.cpp +++ b/server/battles/BattleProcessor.cpp @@ -165,7 +165,7 @@ void BattleProcessor::setupBattle(int3 tile, const CArmedInstance *armies[2], co gameHandler->sendAndApply(&bs); } -void BattleProcessor::checkBattleStateChanges() +bool BattleProcessor::checkBattleStateChanges() { //check if drawbridge state need to be changes if (gameHandler->battleGetSiegeLevel() > 0) @@ -175,7 +175,10 @@ void BattleProcessor::checkBattleStateChanges() if (auto result = gameHandler->battleIsFinished()) { setBattleResult(EBattleResult::NORMAL, *result); + return true; } + + return false; } void BattleProcessor::updateGateState() diff --git a/server/battles/BattleProcessor.h b/server/battles/BattleProcessor.h index 038e10bca..07d437b6e 100644 --- a/server/battles/BattleProcessor.h +++ b/server/battles/BattleProcessor.h @@ -42,7 +42,7 @@ class BattleProcessor : boost::noncopyable void updateGateState(); void engageIntoBattle(PlayerColor player); - void checkBattleStateChanges(); + bool checkBattleStateChanges(); void setupBattle(int3 tile, const CArmedInstance *armies[2], const CGHeroInstance *heroes[2], bool creatureBank, const CGTownInstance *town); bool makeBattleAction(const BattleAction & ba);