1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Do not allow rising of corpses below alive stack

This commit is contained in:
Ivan Savenko 2023-04-13 19:08:08 +03:00
parent beb9069f78
commit 1fab2e2e34

View File

@ -89,20 +89,32 @@ void DemonSummon::apply(ServerCallback * server, const Mechanics * m, const Effe
server->apply(&pack);
}
bool DemonSummon::isValidTarget(const Mechanics * m, const battle::Unit * s) const
bool DemonSummon::isValidTarget(const Mechanics * m, const battle::Unit * unit) const
{
if(!s->isDead())
return false;
if(!unit->isDead())
{
//check if alive unit blocks rising
for(const BattleHex & hex : battle::Unit::getHexes(unit->getPosition(), unit->doubleWide(), unit->unitSide()))
{
auto blocking = m->battle()->battleGetUnitsIf([hex, unit](const battle::Unit * other)
{
return other->isValidTarget(false) && other->coversPos(hex) && other != unit;
});
if (s->isGhost())
if(!blocking.empty())
return false;
}
}
if (unit->isGhost())
return false;
const auto *creatureType = creature.toCreature(m->creatures());
if (s->getTotalHealth() < creatureType->getMaxHealth())
if (unit->getTotalHealth() < creatureType->getMaxHealth())
return false;
return m->isReceptive(s);
return m->isReceptive(unit);
}
void DemonSummon::serializeJsonUnitEffect(JsonSerializeFormat & handler)