Skip to content

Commit

Permalink
Goto Micro AI: change order of SLF and SUF evaluation
Browse files Browse the repository at this point in the history
This is for efficiency reasons, as location filters do not necessarily
change throughout a side’s turn, while fewer and fewer units have moves
left.

(cherry-picked from commit 0dcbe1d)
  • Loading branch information
mattsc committed Oct 7, 2018
1 parent 674a39a commit 6a64e6e
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions data/ai/micro_ais/cas/ca_goto.lua
Expand Up @@ -25,6 +25,24 @@ function ca_goto:evaluation(cfg, data)
return 0
end

local all_units = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", wml.get_child(cfg, "filter") }
}

local units = {}
if cfg.release_unit_at_goal then
for _,unit in ipairs(all_units) do
if (not MAIUV.get_mai_unit_variables(unit, cfg.ai_id, "release")) then
table.insert(units, unit)
end
end
else
units = all_units
end

if (not units[1]) then return 0 end

-- For convenience, we check for locations here, and just pass that to the exec function
-- This is mostly to make the unique_goals option easier
local width, height = wesnoth.get_map_size()
Expand Down Expand Up @@ -60,23 +78,6 @@ function ca_goto:evaluation(cfg, data)
end
if (not locs[1]) then return 0 end

local all_units = AH.get_units_with_moves {
side = wesnoth.current.side,
{ "and", wml.get_child(cfg, "filter") }
}

local units = {}
if cfg.release_unit_at_goal then
for _,unit in ipairs(all_units) do
if (not MAIUV.get_mai_unit_variables(unit, cfg.ai_id, "release")) then
table.insert(units, unit)
end
end
else
units = all_units
end
if (not units[1]) then return 0 end

-- Now store units and locs, so that we don't need to duplicate this in the exec function
GO_units, GO_locs = units, locs

Expand Down

0 comments on commit 6a64e6e

Please sign in to comment.