From 2c48c95c8d6f28858477dd22b010541c03a8586a Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Tue, 1 Mar 2016 04:06:32 +0300 Subject: [PATCH] Fix casualties calculation for commander --- server/CGameHandler.cpp | 54 +++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 254407a63..cdf45cb6f 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -6079,21 +6079,6 @@ CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance * _army, Battl if(color == PlayerColor::UNFLAGGABLE) color = PlayerColor::NEUTRAL; - auto killStack = [&, this](const SlotID slot, const CStackInstance * instance) - { - StackLocation sl(army, slot); - newStackCounts.push_back(TStackAndItsNewCount(sl, 0)); - if(nullptr == instance) - return; - auto c = dynamic_cast (instance); - if (c) //switch commander status to dead - { - auto h = dynamic_cast (army); - if (h && h->commander == c) - heroWithDeadCommander = army->id; //TODO: unify commander handling - } - }; - for(CStack *st : bat->stacks) { if(vstd::contains(st->state, EBattleStackState::SUMMONED)) //don't take into account temporary summoned stacks @@ -6109,7 +6094,7 @@ CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance * _army, Battl if(st->slot == SlotID::ARROW_TOWERS_SLOT) { //do nothing - logGlobal->debugStream() << "Ignored arrow towers stack"; + logGlobal->debug("Ignored arrow towers stack."); } else if(st->slot == SlotID::WAR_MACHINES_SLOT) { @@ -6122,40 +6107,63 @@ CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance * _army, Battl //catapult artifact remain even if "creature" killed in siege else if(warMachine != ArtifactID::CATAPULT && !st->count) { - logGlobal->debugStream() << "War machine has been destroyed"; + logGlobal->debug("War machine has been destroyed"); auto hero = dynamic_ptr_cast (army); if (hero) removedWarMachines.push_back (ArtifactLocation(hero, hero->getArtPos(warMachine, true))); else - logGlobal->errorStream() << "War machine in army without hero"; + logGlobal->error("War machine in army without hero"); } } else if(st->slot == SlotID::SUMMONED_SLOT_PLACEHOLDER) { if(st->alive() && st->count > 0) { - logGlobal->debugStream() << "Stack has been permanently summoned"; - //this stack was permanently summoned + logGlobal->debugStream() << "Permanently summoned " + st->count << " units."; const CreatureID summonedType = st->type->idNumber; summoned[summonedType] += st->count; } } + else if(st->slot == SlotID::COMMANDER_SLOT_PLACEHOLDER) + { + if(nullptr == st->base) + { + logGlobal->error("Stack with no base in commander slot."); + } + else + { + auto c = dynamic_cast (st->base); + if(c) + { + auto h = dynamic_cast (army); + if (h && h->commander == c) + { + logGlobal->debug("Commander is dead."); + heroWithDeadCommander = army->id; //TODO: unify commander handling + } + } + else + logGlobal->error("Stack with invalid instance in commander slot."); + } + } else if(st->base && !army->slotEmpty(st->slot)) { if(st->count == 0 || !st->alive()) { - killStack(st->slot, st->base); - logGlobal->debugStream() << "Stack has been destroyed"; + logGlobal->debug("Stack has been destroyed."); + StackLocation sl(army, st->slot); + newStackCounts.push_back(TStackAndItsNewCount(sl, 0)); } else if(st->count < army->getStackCount(st->slot)) { + logGlobal->debugStream() << "Stack lost " << (army->getStackCount(st->slot) - st->count) << " units."; StackLocation sl(army, st->slot); newStackCounts.push_back(TStackAndItsNewCount(sl, st->count)); } } else { - logGlobal->warnStream() << "Unhandled stack " << st->nodeName(); + logGlobal->warnStream() << "Unable to process stack: " << st->nodeName(); } } }