1
0
mirror of https://github.com/vcmi/vcmi.git synced 2026-05-22 09:55:17 +02:00

vcmi: add getTrigger method to obstacles

Fixes advanced remove obstacle spell
This commit is contained in:
Konstantin
2023-03-31 00:49:51 +03:00
parent 82a6d94fd0
commit d8a237ba46
8 changed files with 25 additions and 33 deletions
+5 -6
View File
@@ -312,23 +312,22 @@ BattleAction CBattleAI::goTowardsNearest(const CStack * stack, std::vector<Battl
{
std::set<BattleHex> obstacleHexes;
auto insertAffected = [](const CObstacleInstance* spellObst, std::set<BattleHex> obstacleHexes) {
auto affectedHexes = spellObst->getAffectedTiles();
auto insertAffected = [](const CObstacleInstance & spellObst, std::set<BattleHex> obstacleHexes) {
auto affectedHexes = spellObst.getAffectedTiles();
obstacleHexes.insert(affectedHexes.cbegin(), affectedHexes.cend());
};
const auto & obstacles = hb.battleGetAllObstacles();
for (const auto & obst: obstacles) {
const auto * spellObst = dynamic_cast<const SpellCreatedObstacle*>(obst.get());
if(spellObst && spellObst->trigger)
if(obst->triggersEffects())
{
auto triggerAbility = VLC->spells()->getById(SpellID(spellObst->ID));
auto triggerAbility = VLC->spells()->getById(obst->getTrigger());
auto triggerIsNegative = triggerAbility->isNegative() || triggerAbility->isDamage();
if(triggerIsNegative)
insertAffected(spellObst, obstacleHexes);
insertAffected(*obst, obstacleHexes);
}
}
// Flying stack doesn't go hex by hex, so we can't backtrack using predecessors.