Tweaked the patrol_gen function to return a pair of function: execution and evaluation
This commit is contained in:
parent
3c51dda69a
commit
de73faad91
2 changed files with 19 additions and 13 deletions
|
@ -14,13 +14,20 @@ function patrol_gen(n, wp) -- n is the name of the unit, like Kiressh
|
|||
--local waypoints = {w1, w2} -- this form might be just received from the args
|
||||
local wpcount = # wp
|
||||
|
||||
return
|
||||
function()
|
||||
x, y = unit.x, unit.y
|
||||
if (x == wp[wpn].x and y == wp[wpn].y) then
|
||||
wpn = wpn % wpcount + 1 -- advance by one waypoint(this construct loops in range [1, wpcount])
|
||||
end
|
||||
ai.move_full(unit, wp[wpn].x, wp[wpn].y) -- @note: should we change this to ai.move()?
|
||||
|
||||
local patrol = {}
|
||||
|
||||
patrol.exec = function()
|
||||
x, y = unit.x, unit.y
|
||||
if (x == wp[wpn].x and y == wp[wpn].y) then
|
||||
wpn = wpn % wpcount + 1 -- advance by one waypoint(this construct loops in range [1, wpcount])
|
||||
end
|
||||
ai.move_full(unit, wp[wpn].x, wp[wpn].y) -- @note: should we change this to ai.move()?
|
||||
end
|
||||
|
||||
patrol.eval = function()
|
||||
return 300000
|
||||
end
|
||||
|
||||
return patrol
|
||||
end
|
||||
|
|
|
@ -98,12 +98,11 @@ Gs^Fp , Gs^Fp , Wwf , Wwf , Mm , Rd
|
|||
|
||||
wesnoth.require("ai/lua/patrol.lua")
|
||||
|
||||
patrol_rark = patrol_gen("Rark", {{x=14, y=7}, {x=15, y=7}, {x=15, y=8}, {x=14, y=8}}) -- need to find a solution for this
|
||||
patrol_bilbo = patrol_gen("Bilbo", {{x=2, y=3}, {x=3, y=2}})
|
||||
patrol_sally = patrol_gen("Sally", {{x=5, y=7}, {x=7, y=5}})
|
||||
function patrol_eval_rark()
|
||||
return 1001
|
||||
end
|
||||
local ptrl = patrol_gen("Rark", {{x=14, y=7}, {x=15, y=7}, {x=15, y=8}, {x=14, y=8}}) -- need to find a solution for this
|
||||
patrol_rark = ptrl.exec
|
||||
patrol_bilbo = patrol_gen("Bilbo", {{x=2, y=3}, {x=3, y=2}}).exec
|
||||
patrol_sally = patrol_gen("Sally", {{x=5, y=7}, {x=7, y=5}}).exec
|
||||
patrol_eval_rark = ptrl.eval
|
||||
-- End of patrol function // patrol_gen(ai, "Rark", {{x=14, y=7}, {x=15, y=7}, {x=15, y=8}, {x=14, y=8}})
|
||||
>>
|
||||
[/lua]
|
||||
|
|
Loading…
Add table
Reference in a new issue