mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Fix casualties calculation for commander
This commit is contained in:
parent
94770e7598
commit
2c48c95c8d
@ -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 <const CCommanderInstance *>(instance);
|
||||
if (c) //switch commander status to dead
|
||||
{
|
||||
auto h = dynamic_cast <const CGHeroInstance *>(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<CGHeroInstance> (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 <const CCommanderInstance *>(st->base);
|
||||
if(c)
|
||||
{
|
||||
auto h = dynamic_cast <const CGHeroInstance *>(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user