2
0
Эх сурвалжийг харах

Do not remove hero if left only with commander

Andrii Danylchenko 3 жил өмнө
parent
commit
0d15089dd4

+ 1 - 1
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<const CGHeroInstance*>(selectedObj))
+				&& selectedObj->needsLastStack())
 			{
 				lastHeroStackSelected = true;
 			}

+ 9 - 3
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));

+ 2 - 1
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);