Lua AIs: use ai_helper.get_locations_no_borders()

(cherry-picked from commit dcadab91a4)
This commit is contained in:
mattsc 2018-09-06 07:25:37 -07:00
parent 319c98d616
commit 56934ad576
8 changed files with 9 additions and 41 deletions

View file

@ -713,12 +713,7 @@ function ai_helper.get_passable_locations(location_filter, unit)
-- excluding border hexes are returned
-- All hexes that are not on the map border
local width, height = wesnoth.get_map_size()
local all_locs = wesnoth.get_locations{
x = '1-' .. width,
y = '1-' .. height,
{ "and", location_filter }
}
local all_locs = ai_helper.get_locations_no_borders(location_filter)
-- If @unit is provided, exclude terrain that's impassable for the unit
if unit then

View file

@ -58,11 +58,8 @@ function ca_castle_switch:evaluation(cfg, data)
end
end
local width,height,border = wesnoth.get_map_size()
local keeps = wesnoth.get_locations {
local keeps = AH.get_locations_no_borders {
terrain = 'K*,K*^*,*^K*', -- Keeps
x = '1-'..width,
y = '1-'..height,
{ "not", { {"filter", {}} }}, -- That have no unit
{ "not", { radius = 6, {"filter", { canrecruit = 'yes',
{ "filter_side", { { "enemy_of", {side = wesnoth.current.side} } } }
@ -163,8 +160,7 @@ function ca_castle_switch:evaluation(cfg, data)
-- if we're on a keep, wait until there are no movable units on the castle before moving off
CS_leader_score = 195000
if wesnoth.get_terrain_info(wesnoth.get_terrain(leader.x, leader.y)).keep then
local castle = wesnoth.get_locations {
x = "1-"..width, y = "1-"..height,
local castle = AH.get_locations_no_borders {
{ "and", {
x = leader.x, y = leader.y, radius = 200,
{ "filter_radius", { terrain = 'C*,K*,C*^*,K*^*,*^K*,*^C*' } }

View file

@ -591,11 +591,9 @@ return {
function get_current_castle(leader, data)
if (not data.castle) or (data.castle.x ~= leader.x) or (data.castle.y ~= leader.y) then
data.castle = {}
local width,height,border = wesnoth.get_map_size()
data.castle = {
locs = wesnoth.get_locations {
x = "1-"..width, y = "1-"..height,
locs = AH.get_locations_no_borders {
{ "filter_vision", { side = wesnoth.current.side, visible = 'yes' } },
{ "and", {
x = leader.x, y = leader.y, radius = 200,

View file

@ -73,12 +73,7 @@ function ca_forest_animals_move:execution(cfg)
local wander_terrain = wml.get_child(cfg, "filter_location") or {}
if (not close_enemies[1]) then
local reach = AH.get_reachable_unocc(unit)
local width, height = wesnoth.get_map_size()
local wander_locs = wesnoth.get_locations {
x = '1-' .. width,
y = '1-' .. height,
{ "and", wander_terrain }
}
local wander_locs = AH.get_locations_no_borders(wander_terrain)
local locs_map = LS.of_pairs(wander_locs)
local reachable_wander_terrain = {}

View file

@ -45,12 +45,7 @@ function ca_goto:evaluation(cfg, data)
-- 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()
local all_locs = wesnoth.get_locations {
x = '1-' .. width,
y = '1-' .. height,
{ "and", wml.get_child(cfg, "filter_location") }
}
local all_locs = AH.get_locations_no_borders(wml.get_child(cfg, "filter_location"))
if (#all_locs == 0) then return 0 end
-- If 'unique_goals' is set, check whether there are locations left to go to.

View file

@ -49,12 +49,7 @@ function ca_hang_out:execution(cfg)
{ "filter", { side = wesnoth.current.side, canrecruit = "yes" } }
}
local width, height = wesnoth.get_map_size()
local locs = wesnoth.get_locations {
x = '1-' .. width,
y = '1-' .. height,
{ "and", filter_location }
}
local locs = AH.get_locations_no_borders(filter_location)
-- Get map of locations to be avoided.
-- Use [micro_ai][avoid] tag with priority over [ai][avoid].

View file

@ -43,8 +43,7 @@ function ca_wolves_multipacks_wander:execution(cfg)
-- Pack gets a new goal if none exist or on any move with 10% random chance
local rand = math.random(10)
if (not goal[1]) or (rand == 1) then
local width, height = wesnoth.get_map_size()
local locs = wesnoth.get_locations { x = '1-'..width, y = '1-'..height }
local locs = AH.get_locations_no_borders {}
-- Need to find reachable terrain for this to be a viable goal
-- We only check whether the first wolf can get there

View file

@ -90,12 +90,7 @@ function ca_zone_guardian:execution(cfg)
newpos = { cfg.station_x, cfg.station_y }
-- Otherwise choose one randomly from those given in filter_location
else
local width, height = wesnoth.get_map_size()
local locs_map = LS.of_pairs(wesnoth.get_locations {
x = '1-' .. width,
y = '1-' .. height,
{ "and", zone }
})
local locs_map = LS.of_pairs(AH.get_locations_no_borders(zone))
-- Check out which of those hexes the guardian can reach
local reach_map = LS.of_pairs(wesnoth.find_reach(guardian))