BattleResultProcessor.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /*
  2. * BattleResultProcessor.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "BattleResultProcessor.h"
  12. #include "../CGameHandler.h"
  13. #include "../processors/HeroPoolProcessor.h"
  14. #include "../queries/QueriesProcessor.h"
  15. #include "../queries/BattleQueries.h"
  16. #include "../../lib/ArtifactUtils.h"
  17. #include "../../lib/CStack.h"
  18. #include "../../lib/GameSettings.h"
  19. #include "../../lib/battle/BattleInfo.h"
  20. #include "../../lib/gameState/CGameState.h"
  21. #include "../../lib/mapObjects/CGTownInstance.h"
  22. #include "../../lib/serializer/Cast.h"
  23. #include "../../lib/spells/CSpellHandler.h"
  24. BattleResultProcessor::BattleResultProcessor(BattleProcessor * owner)
  25. // : owner(owner)
  26. : gameHandler(nullptr)
  27. {
  28. }
  29. void BattleResultProcessor::setGameHandler(CGameHandler * newGameHandler)
  30. {
  31. gameHandler = newGameHandler;
  32. }
  33. CasualtiesAfterBattle::CasualtiesAfterBattle(const SideInBattle & battleSide, const BattleInfo * bat):
  34. army(battleSide.armyObject)
  35. {
  36. heroWithDeadCommander = ObjectInstanceID();
  37. PlayerColor color = battleSide.color;
  38. for(CStack * st : bat->stacks)
  39. {
  40. if(st->summoned) //don't take into account temporary summoned stacks
  41. continue;
  42. if(st->unitOwner() != color) //remove only our stacks
  43. continue;
  44. logGlobal->debug("Calculating casualties for %s", st->nodeName());
  45. st->health.takeResurrected();
  46. if(st->unitSlot() == SlotID::ARROW_TOWERS_SLOT)
  47. {
  48. logGlobal->debug("Ignored arrow towers stack.");
  49. }
  50. else if(st->unitSlot() == SlotID::WAR_MACHINES_SLOT)
  51. {
  52. auto warMachine = st->unitType()->warMachine;
  53. if(warMachine == ArtifactID::NONE)
  54. {
  55. logGlobal->error("Invalid creature in war machine virtual slot. Stack: %s", st->nodeName());
  56. }
  57. //catapult artifact remain even if "creature" killed in siege
  58. else if(warMachine != ArtifactID::CATAPULT && st->getCount() <= 0)
  59. {
  60. logGlobal->debug("War machine has been destroyed");
  61. auto hero = dynamic_ptr_cast<CGHeroInstance> (army);
  62. if (hero)
  63. removedWarMachines.push_back (ArtifactLocation(hero, hero->getArtPos(warMachine, true)));
  64. else
  65. logGlobal->error("War machine in army without hero");
  66. }
  67. }
  68. else if(st->unitSlot() == SlotID::SUMMONED_SLOT_PLACEHOLDER)
  69. {
  70. if(st->alive() && st->getCount() > 0)
  71. {
  72. logGlobal->debug("Permanently summoned %d units.", st->getCount());
  73. const CreatureID summonedType = st->creatureId();
  74. summoned[summonedType] += st->getCount();
  75. }
  76. }
  77. else if(st->unitSlot() == SlotID::COMMANDER_SLOT_PLACEHOLDER)
  78. {
  79. if (nullptr == st->base)
  80. {
  81. logGlobal->error("Stack with no base in commander slot. Stack: %s", st->nodeName());
  82. }
  83. else
  84. {
  85. auto c = dynamic_cast <const CCommanderInstance *>(st->base);
  86. if(c)
  87. {
  88. auto h = dynamic_cast <const CGHeroInstance *>(army);
  89. if(h && h->commander == c && (st->getCount() == 0 || !st->alive()))
  90. {
  91. logGlobal->debug("Commander is dead.");
  92. heroWithDeadCommander = army->id; //TODO: unify commander handling
  93. }
  94. }
  95. else
  96. logGlobal->error("Stack with invalid instance in commander slot. Stack: %s", st->nodeName());
  97. }
  98. }
  99. else if(st->base && !army->slotEmpty(st->unitSlot()))
  100. {
  101. logGlobal->debug("Count: %d; base count: %d", st->getCount(), army->getStackCount(st->unitSlot()));
  102. if(st->getCount() == 0 || !st->alive())
  103. {
  104. logGlobal->debug("Stack has been destroyed.");
  105. StackLocation sl(army, st->unitSlot());
  106. newStackCounts.push_back(TStackAndItsNewCount(sl, 0));
  107. }
  108. else if(st->getCount() < army->getStackCount(st->unitSlot()))
  109. {
  110. logGlobal->debug("Stack lost %d units.", army->getStackCount(st->unitSlot()) - st->getCount());
  111. StackLocation sl(army, st->unitSlot());
  112. newStackCounts.push_back(TStackAndItsNewCount(sl, st->getCount()));
  113. }
  114. else if(st->getCount() > army->getStackCount(st->unitSlot()))
  115. {
  116. logGlobal->debug("Stack gained %d units.", st->getCount() - army->getStackCount(st->unitSlot()));
  117. StackLocation sl(army, st->unitSlot());
  118. newStackCounts.push_back(TStackAndItsNewCount(sl, st->getCount()));
  119. }
  120. }
  121. else
  122. {
  123. logGlobal->warn("Unable to process stack: %s", st->nodeName());
  124. }
  125. }
  126. }
  127. void CasualtiesAfterBattle::updateArmy(CGameHandler *gh)
  128. {
  129. for (TStackAndItsNewCount &ncount : newStackCounts)
  130. {
  131. if (ncount.second > 0)
  132. gh->changeStackCount(ncount.first, ncount.second, true);
  133. else
  134. gh->eraseStack(ncount.first, true);
  135. }
  136. for (auto summoned_iter : summoned)
  137. {
  138. SlotID slot = army->getSlotFor(summoned_iter.first);
  139. if (slot.validSlot())
  140. {
  141. StackLocation location(army, slot);
  142. gh->addToSlot(location, summoned_iter.first.toCreature(), summoned_iter.second);
  143. }
  144. else
  145. {
  146. //even if it will be possible to summon anything permanently it should be checked for free slot
  147. //necromancy is handled separately
  148. gh->complain("No free slot to put summoned creature");
  149. }
  150. }
  151. for (auto al : removedWarMachines)
  152. {
  153. gh->removeArtifact(al);
  154. }
  155. if (heroWithDeadCommander != ObjectInstanceID())
  156. {
  157. SetCommanderProperty scp;
  158. scp.heroid = heroWithDeadCommander;
  159. scp.which = SetCommanderProperty::ALIVE;
  160. scp.amount = 0;
  161. gh->sendAndApply(&scp);
  162. }
  163. }
  164. FinishingBattleHelper::FinishingBattleHelper(std::shared_ptr<const CBattleQuery> Query, int remainingBattleQueriesCount)
  165. {
  166. assert(Query->result);
  167. assert(Query->bi);
  168. auto &result = *Query->result;
  169. auto &info = *Query->bi;
  170. winnerHero = result.winner != 0 ? info.sides[1].hero : info.sides[0].hero;
  171. loserHero = result.winner != 0 ? info.sides[0].hero : info.sides[1].hero;
  172. victor = info.sides[result.winner].color;
  173. loser = info.sides[!result.winner].color;
  174. winnerSide = result.winner;
  175. this->remainingBattleQueriesCount = remainingBattleQueriesCount;
  176. }
  177. FinishingBattleHelper::FinishingBattleHelper()
  178. {
  179. winnerHero = loserHero = nullptr;
  180. winnerSide = 0;
  181. remainingBattleQueriesCount = 0;
  182. }
  183. void BattleResultProcessor::endBattle(int3 tile, const CGHeroInstance * heroAttacker, const CGHeroInstance * heroDefender)
  184. {
  185. auto const & giveExp = [](BattleResult &r)
  186. {
  187. if (r.winner > 1)
  188. {
  189. // draw
  190. return;
  191. }
  192. r.exp[0] = 0;
  193. r.exp[1] = 0;
  194. for (auto i = r.casualties[!r.winner].begin(); i!=r.casualties[!r.winner].end(); i++)
  195. {
  196. r.exp[r.winner] += VLC->creh->objects.at(i->first)->valOfBonuses(BonusType::STACK_HEALTH) * i->second;
  197. }
  198. };
  199. LOG_TRACE(logGlobal);
  200. //Fill BattleResult structure with exp info
  201. giveExp(*battleResult);
  202. if (battleResult->result == EBattleResult::NORMAL) // give 500 exp for defeating hero, unless he escaped
  203. {
  204. if(heroAttacker)
  205. battleResult->exp[1] += 500;
  206. if(heroDefender)
  207. battleResult->exp[0] += 500;
  208. }
  209. if(heroAttacker)
  210. battleResult->exp[0] = heroAttacker->calculateXp(battleResult->exp[0]);//scholar skill
  211. if(heroDefender)
  212. battleResult->exp[1] = heroDefender->calculateXp(battleResult->exp[1]);
  213. auto battleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(gameHandler->gameState()->curB->sides[0].color));
  214. if (!battleQuery)
  215. {
  216. logGlobal->error("Cannot find battle query!");
  217. gameHandler->complain("Player " + boost::lexical_cast<std::string>(gameHandler->gameState()->curB->sides[0].color) + " has no battle query at the top!");
  218. return;
  219. }
  220. battleQuery->result = std::make_optional(*battleResult);
  221. //Check how many battle gameHandler->queries were created (number of players blocked by battle)
  222. const int queriedPlayers = battleQuery ? (int)boost::count(gameHandler->queries->allQueries(), battleQuery) : 0;
  223. finishingBattle = std::make_unique<FinishingBattleHelper>(battleQuery, queriedPlayers);
  224. // in battles against neutrals, 1st player can ask to replay battle manually
  225. if (!gameHandler->gameState()->curB->sides[1].color.isValidPlayer())
  226. {
  227. auto battleDialogQuery = std::make_shared<CBattleDialogQuery>(gameHandler, gameHandler->gameState()->curB);
  228. battleResult->queryID = battleDialogQuery->queryID;
  229. gameHandler->queries->addQuery(battleDialogQuery);
  230. }
  231. else
  232. battleResult->queryID = -1;
  233. //set same battle result for all gameHandler->queries
  234. for(auto q : gameHandler->queries->allQueries())
  235. {
  236. auto otherBattleQuery = std::dynamic_pointer_cast<CBattleQuery>(q);
  237. if(otherBattleQuery)
  238. otherBattleQuery->result = battleQuery->result;
  239. }
  240. gameHandler->sendAndApply(battleResult.get()); //after this point casualties objects are destroyed
  241. if (battleResult->queryID == -1)
  242. endBattleConfirm(gameHandler->gameState()->curB);
  243. }
  244. void BattleResultProcessor::endBattleConfirm(const BattleInfo * battleInfo)
  245. {
  246. auto battleQuery = std::dynamic_pointer_cast<CBattleQuery>(gameHandler->queries->topQuery(battleInfo->sides.at(0).color));
  247. if(!battleQuery)
  248. {
  249. logGlobal->trace("No battle query, battle end was confirmed by another player");
  250. return;
  251. }
  252. const EBattleResult result = battleResult.get()->result;
  253. CasualtiesAfterBattle cab1(battleInfo->sides.at(0), battleInfo), cab2(battleInfo->sides.at(1), battleInfo); //calculate casualties before deleting battle
  254. ChangeSpells cs; //for Eagle Eye
  255. if(!finishingBattle->isDraw() && finishingBattle->winnerHero)
  256. {
  257. if (int eagleEyeLevel = finishingBattle->winnerHero->valOfBonuses(BonusType::LEARN_BATTLE_SPELL_LEVEL_LIMIT, -1))
  258. {
  259. double eagleEyeChance = finishingBattle->winnerHero->valOfBonuses(BonusType::LEARN_BATTLE_SPELL_CHANCE, 0);
  260. for(auto & spellId : battleInfo->sides.at(!battleResult->winner).usedSpellsHistory)
  261. {
  262. auto spell = spellId.toSpell(VLC->spells());
  263. if(spell && spell->getLevel() <= eagleEyeLevel && !finishingBattle->winnerHero->spellbookContainsSpell(spell->getId()) && gameHandler->getRandomGenerator().nextInt(99) < eagleEyeChance)
  264. cs.spells.insert(spell->getId());
  265. }
  266. }
  267. }
  268. std::vector<const CArtifactInstance *> arts; //display them in window
  269. if(result == EBattleResult::NORMAL && !finishingBattle->isDraw() && finishingBattle->winnerHero)
  270. {
  271. auto sendMoveArtifact = [&](const CArtifactInstance *art, MoveArtifact *ma)
  272. {
  273. const auto slot = ArtifactUtils::getArtAnyPosition(finishingBattle->winnerHero, art->getTypeId());
  274. if(slot != ArtifactPosition::PRE_FIRST)
  275. {
  276. arts.push_back(art);
  277. ma->dst = ArtifactLocation(finishingBattle->winnerHero, slot);
  278. if(ArtifactUtils::isSlotBackpack(slot))
  279. ma->askAssemble = false;
  280. gameHandler->sendAndApply(ma);
  281. }
  282. };
  283. if (finishingBattle->loserHero)
  284. {
  285. //TODO: wrap it into a function, somehow (std::variant -_-)
  286. auto artifactsWorn = finishingBattle->loserHero->artifactsWorn;
  287. for (auto artSlot : artifactsWorn)
  288. {
  289. MoveArtifact ma;
  290. ma.src = ArtifactLocation(finishingBattle->loserHero, artSlot.first);
  291. const CArtifactInstance * art = ma.src.getArt();
  292. if (art && !art->artType->isBig() &&
  293. art->artType->getId() != ArtifactID::SPELLBOOK)
  294. // don't move war machines or locked arts (spellbook)
  295. {
  296. sendMoveArtifact(art, &ma);
  297. }
  298. }
  299. for(int slotNumber = finishingBattle->loserHero->artifactsInBackpack.size() - 1; slotNumber >= 0; slotNumber--)
  300. {
  301. //we assume that no big artifacts can be found
  302. MoveArtifact ma;
  303. ma.src = ArtifactLocation(finishingBattle->loserHero,
  304. ArtifactPosition(GameConstants::BACKPACK_START + slotNumber)); //backpack automatically shifts arts to beginning
  305. const CArtifactInstance * art = ma.src.getArt();
  306. if (art->artType->getId() != ArtifactID::GRAIL) //grail may not be won
  307. {
  308. sendMoveArtifact(art, &ma);
  309. }
  310. }
  311. if (finishingBattle->loserHero->commander) //TODO: what if commanders belong to no hero?
  312. {
  313. artifactsWorn = finishingBattle->loserHero->commander->artifactsWorn;
  314. for (auto artSlot : artifactsWorn)
  315. {
  316. MoveArtifact ma;
  317. ma.src = ArtifactLocation(finishingBattle->loserHero->commander.get(), artSlot.first);
  318. const CArtifactInstance * art = ma.src.getArt();
  319. if (art && !art->artType->isBig())
  320. {
  321. sendMoveArtifact(art, &ma);
  322. }
  323. }
  324. }
  325. }
  326. for (auto armySlot : battleInfo->sides.at(!battleResult->winner).armyObject->stacks)
  327. {
  328. auto artifactsWorn = armySlot.second->artifactsWorn;
  329. for (auto artSlot : artifactsWorn)
  330. {
  331. MoveArtifact ma;
  332. ma.src = ArtifactLocation(armySlot.second, artSlot.first);
  333. const CArtifactInstance * art = ma.src.getArt();
  334. if (art && !art->artType->isBig())
  335. {
  336. sendMoveArtifact(art, &ma);
  337. }
  338. }
  339. }
  340. }
  341. if (arts.size()) //display loot
  342. {
  343. InfoWindow iw;
  344. iw.player = finishingBattle->winnerHero->tempOwner;
  345. iw.text.appendLocalString (EMetaText::GENERAL_TXT, 30); //You have captured enemy artifact
  346. for (auto art : arts) //TODO; separate function to display loot for various ojects?
  347. {
  348. iw.components.emplace_back(
  349. Component::EComponentType::ARTIFACT, art->artType->getId(),
  350. art->artType->getId() == ArtifactID::SPELL_SCROLL? art->getScrollSpellID() : 0, 0);
  351. if (iw.components.size() >= 14)
  352. {
  353. gameHandler->sendAndApply(&iw);
  354. iw.components.clear();
  355. }
  356. }
  357. if (iw.components.size())
  358. {
  359. gameHandler->sendAndApply(&iw);
  360. }
  361. }
  362. //Eagle Eye secondary skill handling
  363. if (!cs.spells.empty())
  364. {
  365. cs.learn = 1;
  366. cs.hid = finishingBattle->winnerHero->id;
  367. InfoWindow iw;
  368. iw.player = finishingBattle->winnerHero->tempOwner;
  369. iw.text.appendLocalString(EMetaText::GENERAL_TXT, 221); //Through eagle-eyed observation, %s is able to learn %s
  370. iw.text.replaceRawString(finishingBattle->winnerHero->getNameTranslated());
  371. std::ostringstream names;
  372. for (int i = 0; i < cs.spells.size(); i++)
  373. {
  374. names << "%s";
  375. if (i < cs.spells.size() - 2)
  376. names << ", ";
  377. else if (i < cs.spells.size() - 1)
  378. names << "%s";
  379. }
  380. names << ".";
  381. iw.text.replaceRawString(names.str());
  382. auto it = cs.spells.begin();
  383. for (int i = 0; i < cs.spells.size(); i++, it++)
  384. {
  385. iw.text.replaceLocalString(EMetaText::SPELL_NAME, it->toEnum());
  386. if (i == cs.spells.size() - 2) //we just added pre-last name
  387. iw.text.replaceLocalString(EMetaText::GENERAL_TXT, 141); // " and "
  388. iw.components.emplace_back(Component::EComponentType::SPELL, *it, 0, 0);
  389. }
  390. gameHandler->sendAndApply(&iw);
  391. gameHandler->sendAndApply(&cs);
  392. }
  393. cab1.updateArmy(gameHandler);
  394. cab2.updateArmy(gameHandler); //take casualties after battle is deleted
  395. if(finishingBattle->loserHero) //remove beaten hero
  396. {
  397. RemoveObject ro(finishingBattle->loserHero->id);
  398. gameHandler->sendAndApply(&ro);
  399. }
  400. if(finishingBattle->isDraw() && finishingBattle->winnerHero) //for draw case both heroes should be removed
  401. {
  402. RemoveObject ro(finishingBattle->winnerHero->id);
  403. gameHandler->sendAndApply(&ro);
  404. }
  405. if(battleResult->winner == BattleSide::DEFENDER
  406. && finishingBattle->winnerHero
  407. && finishingBattle->winnerHero->visitedTown
  408. && !finishingBattle->winnerHero->inTownGarrison
  409. && finishingBattle->winnerHero->visitedTown->garrisonHero == finishingBattle->winnerHero)
  410. {
  411. gameHandler->swapGarrisonOnSiege(finishingBattle->winnerHero->visitedTown->id); //return defending visitor from garrison to its rightful place
  412. }
  413. //give exp
  414. if(!finishingBattle->isDraw() && battleResult->exp[finishingBattle->winnerSide] && finishingBattle->winnerHero)
  415. gameHandler->changePrimSkill(finishingBattle->winnerHero, PrimarySkill::EXPERIENCE, battleResult->exp[finishingBattle->winnerSide]);
  416. BattleResultAccepted raccepted;
  417. raccepted.heroResult[0].army = const_cast<CArmedInstance*>(battleInfo->sides.at(0).armyObject);
  418. raccepted.heroResult[1].army = const_cast<CArmedInstance*>(battleInfo->sides.at(1).armyObject);
  419. raccepted.heroResult[0].hero = const_cast<CGHeroInstance*>(battleInfo->sides.at(0).hero);
  420. raccepted.heroResult[1].hero = const_cast<CGHeroInstance*>(battleInfo->sides.at(1).hero);
  421. raccepted.heroResult[0].exp = battleResult->exp[0];
  422. raccepted.heroResult[1].exp = battleResult->exp[1];
  423. raccepted.winnerSide = finishingBattle->winnerSide;
  424. gameHandler->sendAndApply(&raccepted);
  425. gameHandler->queries->popIfTop(battleQuery);
  426. //--> continuation (battleAfterLevelUp) occurs after level-up gameHandler->queries are handled or on removing query
  427. }
  428. void BattleResultProcessor::battleAfterLevelUp(const BattleResult &result)
  429. {
  430. LOG_TRACE(logGlobal);
  431. if(!finishingBattle)
  432. return;
  433. finishingBattle->remainingBattleQueriesCount--;
  434. logGlobal->trace("Decremented gameHandler->queries count to %d", finishingBattle->remainingBattleQueriesCount);
  435. if (finishingBattle->remainingBattleQueriesCount > 0)
  436. //Battle results will be handled when all battle gameHandler->queries are closed
  437. return;
  438. //TODO consider if we really want it to work like above. ATM each player as unblocked as soon as possible
  439. // but the battle consequences are applied after final player is unblocked. Hard to abuse...
  440. // Still, it looks like a hole.
  441. // Necromancy if applicable.
  442. const CStackBasicDescriptor raisedStack = finishingBattle->winnerHero ? finishingBattle->winnerHero->calculateNecromancy(*battleResult) : CStackBasicDescriptor();
  443. // Give raised units to winner and show dialog, if any were raised,
  444. // units will be given after casualties are taken
  445. const SlotID necroSlot = raisedStack.type ? finishingBattle->winnerHero->getSlotFor(raisedStack.type) : SlotID();
  446. if (necroSlot != SlotID())
  447. {
  448. finishingBattle->winnerHero->showNecromancyDialog(raisedStack, gameHandler->getRandomGenerator());
  449. gameHandler->addToSlot(StackLocation(finishingBattle->winnerHero, necroSlot), raisedStack.type, raisedStack.count);
  450. }
  451. BattleResultsApplied resultsApplied;
  452. resultsApplied.player1 = finishingBattle->victor;
  453. resultsApplied.player2 = finishingBattle->loser;
  454. gameHandler->sendAndApply(&resultsApplied);
  455. gameHandler->setBattle(nullptr);
  456. //handle victory/loss of engaged players
  457. std::set<PlayerColor> playerColors = {finishingBattle->loser, finishingBattle->victor};
  458. gameHandler->checkVictoryLossConditions(playerColors);
  459. if (result.result == EBattleResult::SURRENDER)
  460. gameHandler->heroPool->onHeroSurrendered(finishingBattle->loser, finishingBattle->loserHero);
  461. if (result.result == EBattleResult::ESCAPE)
  462. gameHandler->heroPool->onHeroEscaped(finishingBattle->loser, finishingBattle->loserHero);
  463. if (result.winner != 2 && finishingBattle->winnerHero && finishingBattle->winnerHero->stacks.empty()
  464. && (!finishingBattle->winnerHero->commander || !finishingBattle->winnerHero->commander->alive))
  465. {
  466. RemoveObject ro(finishingBattle->winnerHero->id);
  467. gameHandler->sendAndApply(&ro);
  468. if (VLC->settings()->getBoolean(EGameSettings::HEROES_RETREAT_ON_WIN_WITHOUT_TROOPS))
  469. gameHandler->heroPool->onHeroEscaped(finishingBattle->victor, finishingBattle->winnerHero);
  470. }
  471. finishingBattle.reset();
  472. battleResult.reset();
  473. }
  474. void BattleResultProcessor::setBattleResult(EBattleResult resultType, int victoriusSide)
  475. {
  476. battleResult = std::make_unique<BattleResult>();
  477. battleResult->result = resultType;
  478. battleResult->winner = victoriusSide; //surrendering side loses
  479. gameHandler->gameState()->curB->calculateCasualties(battleResult->casualties);
  480. }
  481. bool BattleResultProcessor::battleIsEnding() const
  482. {
  483. return battleResult != nullptr;
  484. }