Skip to content

Commit

Permalink
Bottleneck MAI: bug fix for when allied units are present
Browse files Browse the repository at this point in the history
Hexes occupied by allied units were previously not excluded properly by
the AI, which could lead to error messages and the candidate action to
be blacklisted.
  • Loading branch information
mattsc authored and mattsc committed Apr 2, 2015
1 parent 3595927 commit 775a0b0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions data/ai/micro_ais/cas/ca_bottleneck_move.lua
Expand Up @@ -327,6 +327,18 @@ function ca_bottleneck_move:evaluation(ai, cfg, self)
end
end

-- Get a map of the allies, as hexes occupied by allied units count as
-- reachable, but must be excluded. This could also be done below by
-- using bottleneck_move_out_of_way(), but this is much faster
local allies = AH.get_live_units {
{ "filter_side", { { "allied_with", { side = wesnoth.current.side } } } },
{ "not", { side = wesnoth.current.side } }
}
local allies_map = LS.create()
for _,ally in ipairs(allies) do
allies_map:insert(ally.x, ally.y)
end

local max_rating, best_unit, best_hex = 0
for _,unit in ipairs(units) do
local is_healer = (unit.__cfg.usage == "healer")
Expand All @@ -351,6 +363,9 @@ function ca_bottleneck_move:evaluation(ai, cfg, self)
-- If the target hex is occupied, give it a small penalty
if current_rating_map:get(loc[1], loc[2]) then rating = rating - 0.001 end

-- Also need to exclude hexes occupied by an allied unit
if allies_map:get(loc[1], loc[2]) then rating = 0 end

-- Now only valid and possible moves should have a rating > 0
if (rating > max_rating) then
max_rating, best_unit, best_hex = rating, unit, { loc[1], loc[2] }
Expand Down

0 comments on commit 775a0b0

Please sign in to comment.