MAIs: test for unit equality directly, not via coordinates

This commit is contained in:
mattsc 2014-03-28 12:15:53 -07:00
parent f03c6052d0
commit 0fd45763a9
2 changed files with 2 additions and 2 deletions

View file

@ -157,7 +157,7 @@ function ca_goto:execution(ai, cfg, self)
-- Add a small penalty for occupied hexes
-- (this mean occupied by an allied unit, as enemies make the hex unreachable)
local unit_in_way = wesnoth.get_unit(l[1], l[2])
if unit_in_way and ((unit_in_way.x ~= u.x) or (unit_in_way.y ~= u.y)) then
if unit_in_way and (unit_in_way ~= u) then
rating = rating - 0.01
end

View file

@ -87,7 +87,7 @@ function ca_healer_move:evaluation(ai, cfg, self)
-- Also, hex must be unoccupied by another unit, of course
local unit_in_way = wesnoth.get_unit(r[1], r[2])
if (not avoid_map:get(r[1], r[2])) then
if (not unit_in_way) or ((unit_in_way.x == h.x) and (unit_in_way.y == h.y)) then
if (not unit_in_way) or (unit_in_way == h) then
for k,u in ipairs(healees) do
if (H.distance_between(u.x, u.y, r[1], r[2]) == 1) then
-- !!!!!!! These ratings have to be positive or the method doesn't work !!!!!!!!!