From 0d15089dd454305665de0a1c01d2008c2bbe421a Mon Sep 17 00:00:00 2001 From: Andrii Danylchenko Date: Sat, 23 Apr 2022 16:45:38 +0300 Subject: [PATCH] Do not remove hero if left only with commander --- client/widgets/CGarrisonInt.cpp | 2 +- lib/mapObjects/CGHeroInstance.cpp | 12 +++++++++--- server/CGameHandler.cpp | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/client/widgets/CGarrisonInt.cpp b/client/widgets/CGarrisonInt.cpp index 22e3ce96a..2078429b8 100644 --- a/client/widgets/CGarrisonInt.cpp +++ b/client/widgets/CGarrisonInt.cpp @@ -328,7 +328,7 @@ void CGarrisonSlot::clickLeft(tribool down, bool previousState) bool lastHeroStackSelected = false; if(selectedObj->stacksCount() == 1 && owner->getSelection()->upg != upg - && dynamic_cast(selectedObj)) + && selectedObj->needsLastStack()) { lastHeroStackSelected = true; } diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index f27ffd496..59ebdd789 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -51,17 +51,23 @@ static void showInfoDialog(const CGHeroInstance* h, const ui32 txtID, const ui16 static int lowestSpeed(const CGHeroInstance * chi) { + static const CSelector selectorSTACKS_SPEED = Selector::type()(Bonus::STACKS_SPEED); + static const std::string keySTACKS_SPEED = "type_" + std::to_string((si32)Bonus::STACKS_SPEED); + if(!chi->stacksCount()) { + if(chi->commander && chi->commander->alive) + { + return chi->commander->valOfBonuses(selectorSTACKS_SPEED, keySTACKS_SPEED); + } + logGlobal->error("Hero %d (%s) has no army!", chi->id.getNum(), chi->name); return 20; } + auto i = chi->Slots().begin(); //TODO? should speed modifiers (eg from artifacts) affect hero movement? - static const CSelector selectorSTACKS_SPEED = Selector::type()(Bonus::STACKS_SPEED); - static const std::string keySTACKS_SPEED = "type_"+std::to_string((si32)Bonus::STACKS_SPEED); - int ret = (i++)->second->valOfBonuses(selectorSTACKS_SPEED, keySTACKS_SPEED); for(; i != chi->Slots().end(); i++) ret = std::min(ret, i->second->valOfBonuses(selectorSTACKS_SPEED, keySTACKS_SPEED)); diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index b0667cc73..dcb46375a 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -974,7 +974,8 @@ void CGameHandler::battleAfterLevelUp(const BattleResult &result) sendAndApply(&sah); } - if (result.winner != 2 && finishingBattle->winnerHero && finishingBattle->winnerHero->stacks.empty()) + if (result.winner != 2 && finishingBattle->winnerHero && finishingBattle->winnerHero->stacks.empty() + && (!finishingBattle->winnerHero->commander || !finishingBattle->winnerHero->commander->alive)) { RemoveObject ro(finishingBattle->winnerHero->id); sendAndApply(&ro);