-
-
Notifications
You must be signed in to change notification settings - Fork 991
/
patrol.fai
73 lines (62 loc) · 1.23 KB
/
patrol.fai
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
fai 'patrol.fai'
def closest_unit(ai*, me)
choose(
enemy_units, 'unit',
-distance_between(me.loc, unit.loc)
);
def step_move(me)
if( unit_at( desired_path[0] ),
if( desired_path.size > 1,
move_partial(
me.loc,
desired_path[1]
),
end
),
move_partial(
me.loc,
desired_path[0]
)
)
where desired_path = shortest_path( me.loc, me.vars.next_step );
def move_ahead(ai*, me)
if( enemy_units,
if( distance_between( closest_unit(ai, me).loc, me.loc ) > me.moves-1,
move_partial(
me.loc,
me.vars.next_step
),
step_move(me)
),
move_partial(
me.loc,
me.vars.next_step
)
);
def patrol_move(ai*, me)
if( me.vars.next_step = me.loc,
set_unit_var('next_step',
me.vars.waypoints[ me.vars.next_step ],
me.loc
),
move_ahead(ai,me)
);
if( me.moves = 0,
end,
if(attack,
attack,
patrol_move(self, me)
)
)
where attack = if( path_to,
if(path_to.size <= me.vars.guard_radius,
attack( me.loc, path_to.last, closest_unit(self, me).loc ),
0
),
0
)
where path_to = if( enemy_units,
shortest_path( me.loc, closest_unit(self, me).loc ),
[]
)
faiend