1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Fix battle ending

This commit is contained in:
Ivan Savenko 2023-08-17 15:18:16 +03:00
parent a1d3181a98
commit a1092e0f3f
3 changed files with 15 additions and 5 deletions

View File

@ -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;
}

View File

@ -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()

View File

@ -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);