This is a first draft of the patrolling system.

At the moment everything manually, the system lacks normal evaluation
of the move and the patrolling unit will not stop until its moves run
out. Also, at the moment, it is possible to patrol between two
waypoints only.

Further work will be carried out to transform the creation of
patrolling units to one line syntax.
This commit is contained in:
Dmitry Kovalenko 2011-06-17 10:07:41 +00:00
parent 2e0b1f7853
commit bf8300c064

View file

@ -164,7 +164,7 @@ Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd
[unit]
x,y=16,5
type="Wolf Rider"
generate_name=yes
name="Rark"
[/unit]
[unit]
@ -296,26 +296,60 @@ function my_ai:stage_hello()
end
function my_ai:candidate_action_evaluation_hello()
wesnoth.message('hello from candidate action evaluation!')
--wesnoth.message('hello from candidate action evaluation!')
return 42, {test=123}
end
function my_ai:candidate_action_execution_hello(cfg)
wesnoth.message('hello from candidate action execution!')
wesnoth.message('test value is ') -- .. cfg.test) -- ERROR: cfg.test is nil here
-- wesnoth.message('hello from candidate action execution!')
--wesnoth.message('test value is ') -- .. cfg.test) -- ERROR: cfg.test is nil here
self:do_moves()
end
function my_ai:candidate_action_evaluation_hello2()
wesnoth.message('hello from second candidate action evaluation!')
--wesnoth.message('hello from second candidate action evaluation!')
return 99
end
function my_ai:candidate_action_execution_hello2()
wesnoth.message('hello from second candidate action execution!')
--wesnoth.message('hello from second candidate action execution!')
self:do_moves()
end
function my_ai:patrol_eval()
wesnoth.message('Considering to patrol, checking, whether everything is ok')
return 10000
end
function my_ai:patrol_gen(ai, n, w1, w2) -- n is the name of the unit, like Kiressh
-- w1, w2 -- waypoint tables of form {x,y}
wesnoth.message("Creation of the patrol func")
local unit = wesnoth.get_units({name=n})[1]
local x, y = unit.x, unit.y
local wpn = 1 --WayPoint Number - we have to remember which waypoint we are heading to
if (x == w1.x and y == w1.y) then
w1, w2 = w2, w2 -- if we are standing on the first waypoint, swap them
end
local waypoints = {w1, w2} -- this form might be just received from the args
wesnoth.message ("Eof creation")
return
function()
--wesnoth.message(tostring(waypoints[1].x).." YES")
wesnoth.message("Entering patrol execution code")
x, y = unit.x, unit.y
if (x == waypoints[wpn].x and y == waypoints[wpn].y) then
wpn = 3 - wpn -- hardcoded for two waypoints
end
ai.move(unit, waypoints[wpn].x, waypoints[wpn].y)
end
end
my_ai.patrol_exec = my_ai:patrol_gen(ai, "Rark", {x=16, y=15}, {x=16, y=5})
function my_ai:do_moves()
--wesnoth.message('Passive leader: ', tostring(ai.get_passive_leader()))
@ -335,11 +369,11 @@ function my_ai:do_moves()
--wesnoth.message('Leader goal' .. ai.get_leader_goal().x .. ' ' .. ai.get_leader_goal().y) -- fixed
--wesnoth.message('Avoid ex. ' .. #ai.get_avoid() .. ' ' ..ai.get_avoid()[1]["x"] .. " " .. ai.get_avoid()[1]["y"]) -- fixed?
--we wesnoth.message('DSTSRC fun: ' .. #ai.get_dstsrc())
for k,v in pairs(ai.get_enemy_dstsrc()) do
for i,l in ipairs(v) do
wesnoth.message("->" .. l.x .. " " .. l.y)
end
end
--for k,v in pairs(ai.get_enemy_dstsrc()) do
--- for i,l in ipairs(v) do
-- wesnoth.message("->" .. l.x .. " " .. l.y)
-- end
--end
my_leader = wesnoth.get_units({side = 1, can_recruit=yes})[1].name
@ -371,6 +405,12 @@ return my_ai
[/engine]
[stage]
name=testing_ai_default::candidate_action_evaluation_loop
[candidate_action]
engine=lua
name=patrol
evaluation="return (...):patrol_eval()"
execution="(...):patrol_exec()"
[/candidate_action]
[candidate_action]
engine=lua
name=first