From bb0b8acc06506084e20f6c69890d21e6515255a3 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 12 Nov 2012 12:11:08 +0100 Subject: [PATCH] In SelectTargetUnitsOfAutoCast, compute inCombat only when needed. change InCombat condition to be true also when enemy can hit the caster. --- src/spell/spells.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/spell/spells.cpp b/src/spell/spells.cpp index a8852c85d..49f86ecba 100644 --- a/src/spell/spells.cpp +++ b/src/spell/spells.cpp @@ -208,22 +208,23 @@ static Target *SelectTargetUnitsOfAutoCast(CUnit &caster, const SpellType &spell int range = autocast->Range; // Select all units aroung the caster - std::vector table; SelectAroundUnit(caster, range, table); - // Check every unit if it is hostile - bool inCombat = false; - for (size_t i = 0; i < table.size(); ++i) { - if (table[i]->IsVisibleAsGoal(*caster.Player) && caster.IsEnemy(*table[i]) - && CanTarget(*caster.Type, *table[i]->Type)) { - inCombat = true; - break; - } - } - // Check generic conditions. FIXME: a better way to do this? if (autocast->Combat != CONDITION_TRUE) { + // Check each unit if it is hostile. + bool inCombat = false; + for (size_t i = 0; i < table.size(); ++i) { + const CUnit &target = *table[i]; + + // Note that CanTarget doesn't take into account (offensive) spells... + if (target.IsVisibleAsGoal(*caster.Player) && caster.IsEnemy(target) + && (CanTarget(*caster.Type, *target.Type) || CanTarget(*target.Type, *caster.Type))) { + inCombat = true; + break; + } + } if ((autocast->Combat == CONDITION_ONLY) ^ (inCombat)) { return NULL; }