Zone guardian MAI: add optional station_x,station_y= keys

This commit is contained in:
mattsc 2013-06-06 19:24:13 -07:00
parent 3fadf4cc31
commit 2139c84188
3 changed files with 20 additions and 9 deletions

View file

@ -231,14 +231,24 @@ return {
-- If no enemy around or within the zone, move toward "random" position which are mainy the borders
else
--print "Move toward newpos"
local width, height = wesnoth.get_map_size()
local locs = wesnoth.get_locations {
x = '1-' .. width,
y = '1-' .. height,
{ "and", cfg.filter_location }
}
local newpos = math.random(#locs)
local nh = AH.next_hop(unit, locs[newpos][1], locs[newpos][2])
local newpos
-- If cfg.station_x/y are given, move toward that location
if cfg.station_x and cfg.station_y then
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 = wesnoth.get_locations {
x = '1-' .. width,
y = '1-' .. height,
{ "and", cfg.filter_location }
}
local newind = math.random(#locs)
newpos = {locs[newind][1], locs[newind][2]}
end
-- Next hop toward that position
local nh = AH.next_hop(unit, newpos[1], newpos[2])
if nh then
AH.movefull_stopunit(ai, unit, nh)
end

View file

@ -423,7 +423,7 @@ function wesnoth.wml_actions.micro_ai(cfg)
optional_keys["stationed_guardian"] = {}
required_keys["zone_guardian"] = { "id", "filter_location" }
optional_keys["zone_guardian"] = { "filter_location_enemy" }
optional_keys["zone_guardian"] = { "filter_location_enemy", "station_x", "station_y" }
required_keys["coward"] = { "id", "distance" }
optional_keys["coward"] = { "seek_x", "seek_y","avoid_x","avoid_y" }

View file

@ -406,6 +406,7 @@ separate attack Zone"
x,y=22-31,4-11 # This is intentionally chosen to extend past the lake
terrain=W*
[/filter_location]
station_x,station_y=32,8
[/micro_ai]
{SET_LABEL 3 13 _"Guarded Location"}