-
Notifications
You must be signed in to change notification settings - Fork 0
/
yama_ai_patrols.lua
93 lines (75 loc) · 1.68 KB
/
yama_ai_patrols.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
patrols = {}
function patrols.new()
local public = {}
local private = {}
-- Public
public.goal = nil
public.speed = 0
-- Private
private.current = nil
private.k, private.v = nil, nil
private.loop = true
private.radius = 32
private.order = nil
-- Public Functions
function public.set(name, map)
if map.patrols[name] then
private.current = map.patrols[name]
private.k = 0
public.next()
end
end
function public.setLoop(loop)
private.loop = loop
end
function public.setRadius(radius)
private.radius = radius
end
function public.update(x, y)
if private.v then
if yama.g.getDistance(x, y, private.v.x, private.v.y) < private.radius then
public.next()
end
if private.v then
public.goal = {private.v.x, private.v.y}
public.speed = 1
else
public.goal = nil
public.speed = 0
end
end
end
function public.next()
if private.order == "random" then
private.k = math.random(1, #private.current.points)
private.v = private.current.points[private.k]
elseif private.order == "reverse" then
private.k = private.k - 1
else
private.k = private.k + 1
end
if private.current.points[private.k] then
private.v = private.current.points[private.k]
elseif private.loop and private.order == "reverse" then
private.k = #private.current.points
private.v = private.current.points[private.k]
elseif private.loop then
private.k = 1
private.v = private.current.points[private.k]
else
private.v = nil
end
end
function public.getPoint()
return private.v.x, private.v.y
end
function public.isActive()
if private.v then
return truepatrol
else
return false
end
end
return public
end
return patrols