ai_helper.has_ability: restore previous functionality

Before the recent change, the ability type (tag name) was checked. It then got changed to ability id. This commit changes it back to the old behavior.

For the record, there are situation when either the id or the type is needed. In addition, one sometimes wants to check wheter the ability is active (or will be active). Thus, no matter how this is done, neither will serve all purposes and sometimes other functions/functionality should be used. This commit does, however, restore the previous behavior and thus preserves backward compatibilty.
This commit is contained in:
mattsc 2020-01-01 20:33:59 -08:00
parent a7aa08c90a
commit 800c943221

View file

@ -1273,27 +1273,8 @@ function ai_helper.get_closest_enemy(loc, side, cfg)
end
function ai_helper.has_ability(unit, ability, exact_match)
-- Returns true/false depending on whether unit has the given ability
-- OPTIONAL INPUT:
-- - exact_match=true: (boolean) If set to true (the default), the ability id
-- has to match @ability exactly, otherwise it is sufficient if @ability appears
-- in the id. This is done so that, for example, regeneration abilities with
-- ids 'regenerates' and 'regenerates_4' can be matched simultaneously.
if (exact_match == nil) then exact_match = true end
for _,ability_id in ipairs(unit.abilities) do
if exact_match then
if (ability == ability_id) then
return true
end
else
if string.find(ability_id, ability) then
return true
end
end
end
return false
-- Returns true/false depending on whether unit has the given ability type (tag name)
return unit:matches { ability_type = ability }
end
function ai_helper.has_weapon_special(unit, special)