mirror of
https://github.com/vcmi/vcmi.git
synced 2026-06-19 22:57:37 +02:00
Fix crash on AI evaluating hero pool after retreating from combat
This commit is contained in:
@@ -59,11 +59,12 @@ void TavernHeroesPool::setHeroForPlayer(PlayerColor player, TavernHeroSlot slot,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
auto h = owner->getMap().tryGetFromHeroPool(hero);
|
auto h = owner->getMap().tryGetFromHeroPool(hero);
|
||||||
|
assert(h != nullptr);
|
||||||
|
|
||||||
if (h && army)
|
if (army)
|
||||||
h->setToArmy(army);
|
h->setToArmy(army);
|
||||||
|
|
||||||
if (h && replenishPoints)
|
if (replenishPoints)
|
||||||
{
|
{
|
||||||
h->setMovementPoints(h->movementPointsLimit(true));
|
h->setMovementPoints(h->movementPointsLimit(true));
|
||||||
h->mana = h->manaLimit();
|
h->mana = h->manaLimit();
|
||||||
@@ -100,6 +101,7 @@ std::vector<const CGHeroInstance *> TavernHeroesPool::getHeroesFor(PlayerColor c
|
|||||||
|
|
||||||
for(const auto & slot : currentTavern)
|
for(const auto & slot : currentTavern)
|
||||||
{
|
{
|
||||||
|
assert(slot.hero != nullptr);
|
||||||
if (slot.player == color)
|
if (slot.player == color)
|
||||||
result.push_back(owner->getMap().tryGetFromHeroPool(slot.hero));
|
result.push_back(owner->getMap().tryGetFromHeroPool(slot.hero));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -497,18 +497,6 @@ void BattleResultProcessor::battleFinalize(const BattleID & battleID, const Batt
|
|||||||
//handle victory/loss of engaged players
|
//handle victory/loss of engaged players
|
||||||
gameHandler->checkVictoryLossConditions({finishingBattle->loser, finishingBattle->victor});
|
gameHandler->checkVictoryLossConditions({finishingBattle->loser, finishingBattle->victor});
|
||||||
|
|
||||||
if (result.result == EBattleResult::SURRENDER)
|
|
||||||
{
|
|
||||||
gameHandler->gameState().statistic.accumulatedValues[finishingBattle->loser].numHeroSurrendered++;
|
|
||||||
gameHandler->heroPool->onHeroSurrendered(finishingBattle->loser, loserHero);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.result == EBattleResult::ESCAPE)
|
|
||||||
{
|
|
||||||
gameHandler->gameState().statistic.accumulatedValues[finishingBattle->loser].numHeroEscaped++;
|
|
||||||
gameHandler->heroPool->onHeroEscaped(finishingBattle->loser, loserHero);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove beaten hero
|
// Remove beaten hero
|
||||||
if(loserHero)
|
if(loserHero)
|
||||||
{
|
{
|
||||||
@@ -524,6 +512,18 @@ void BattleResultProcessor::battleFinalize(const BattleID & battleID, const Batt
|
|||||||
gameHandler->heroPool->onHeroEscaped(finishingBattle->victor, winnerHero);
|
gameHandler->heroPool->onHeroEscaped(finishingBattle->victor, winnerHero);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.result == EBattleResult::SURRENDER)
|
||||||
|
{
|
||||||
|
gameHandler->gameState().statistic.accumulatedValues[finishingBattle->loser].numHeroSurrendered++;
|
||||||
|
gameHandler->heroPool->onHeroSurrendered(finishingBattle->loser, loserHero);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.result == EBattleResult::ESCAPE)
|
||||||
|
{
|
||||||
|
gameHandler->gameState().statistic.accumulatedValues[finishingBattle->loser].numHeroEscaped++;
|
||||||
|
gameHandler->heroPool->onHeroEscaped(finishingBattle->loser, loserHero);
|
||||||
|
}
|
||||||
|
|
||||||
finishingBattles.erase(battleID);
|
finishingBattles.erase(battleID);
|
||||||
battleResults.erase(battleID);
|
battleResults.erase(battleID);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user