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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
-module(btl_action).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-record
(
move,
{
actor_ix :: non_neg_integer(),
path :: list(shr_direction:enum()),
movement_points :: (non_neg_integer() | -1)
}
).
-record
(
switch_weapon,
{
actor_ix :: non_neg_integer()
}
).
-record
(
attack,
{
actor_ix :: non_neg_integer(),
target_ix :: non_neg_integer(),
is_opportunistic :: boolean()
}
).
-type category() ::
(
'move'
| 'switch_weapon'
| 'attack'
| 'nothing'
).
-opaque type() ::
(
#move{}
| #switch_weapon{}
| #attack{}
).
-export_type([category/0, type/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-export
(
[
from_map_marker/3,
maybe_decode_move/2,
maybe_decode_weapon_switch/2,
maybe_decode_attack/2,
can_follow/2
]
).
-export
(
[
new_move/3,
new_attack_of_opportunity/2
]
).
-export
(
[
get_is_opportunistic/1,
get_path/1,
get_movement_points/1,
get_target_index/1,
get_actor_index/1,
get_category/1
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec maybe_decode_move
(
non_neg_integer(),
list(shr_direction:type())
)
-> list(type()).
maybe_decode_move (_CharacterIX, []) -> [];
maybe_decode_move (CharacterIX, PathInBinary) ->
Path = lists:map(fun shr_direction:decode/1, PathInBinary),
[
#move
{
actor_ix = CharacterIX,
path = Path,
movement_points = -1
}
].
-spec maybe_decode_attack
(
non_neg_integer(),
integer()
)
-> list(type()).
maybe_decode_attack (_CharacterIX, TargetIX) when (TargetIX < 0) -> [];
maybe_decode_attack (CharacterIX, TargetIX) ->
[
#attack
{
actor_ix = CharacterIX,
target_ix = TargetIX,
is_opportunistic = false
}
].
-spec maybe_decode_weapon_switch
(
non_neg_integer(),
boolean()
)
-> list(type()).
maybe_decode_weapon_switch (_CharacterIX, false) -> [];
maybe_decode_weapon_switch (CharacterIX, true) ->
[#switch_weapon{ actor_ix = CharacterIX }].
-spec can_follow (category(), category()) -> boolean().
can_follow (nothing, attack) -> true;
can_follow (nothing, switch_weapon) -> true;
can_follow (nothing, move) -> true;
can_follow (move, switch_weapon) -> true;
can_follow (move, attack) -> true;
can_follow (_, _) -> false.
-spec get_path (type()) -> list(shr_direction:type()).
get_path (Action) when is_record(Action, move) -> Action#move.path;
get_path (_) ->
[].
-spec get_movement_points (type()) -> (non_neg_integer() | -1).
get_movement_points (Action) when is_record(Action, move) ->
Action#move.movement_points;
get_movement_points (_) -> -1.
-spec get_target_index (type()) -> (non_neg_integer() | -1).
get_target_index (Action) when is_record(Action, attack) ->
Action#attack.target_ix;
get_target_index (_) -> -1.
-spec get_actor_index (type()) -> (non_neg_integer() | -1).
get_actor_index (Action) when is_record(Action, attack) ->
Action#attack.actor_ix;
get_actor_index (Action) when is_record(Action, move) ->
Action#move.actor_ix;
get_actor_index (Action) when is_record(Action, switch_weapon) ->
Action#switch_weapon.actor_ix;
get_actor_index (_) ->
-1.
-spec get_is_opportunistic (type()) -> boolean().
get_is_opportunistic (Action) when is_record(Action, attack) ->
Action#attack.is_opportunistic;
get_is_opportunistic (_) -> false.
-spec new_move
(
non_neg_integer(),
list(shr_direction:type()),
(non_neg_integer() | -1)
)
-> type().
new_move (ActorIX, Path, MovementPoints) ->
#move
{
actor_ix = ActorIX,
path = Path,
movement_points = MovementPoints
}.
-spec new_attack_of_opportunity
(
non_neg_integer(),
non_neg_integer()
)
-> type().
new_attack_of_opportunity (ActorIX, TargetIX) ->
#attack
{
actor_ix = ActorIX,
target_ix = TargetIX,
is_opportunistic = true
}.
-spec get_category (type()) -> category().
get_category (Action) when is_record(Action, attack) -> attack;
get_category (Action) when is_record(Action, move) -> move;
get_category (Action) when is_record(Action, switch_weapon) -> switch_weapon.
-spec from_map_marker
(
non_neg_integer(),
btl_character:type(),
shr_map_marker:type()
)
-> list(type()).
from_map_marker (CharacterIX, _Character, Marker) ->
case shr_map_marker:get_category(Marker) of
matk ->
[
#attack
{
target_ix = CharacterIX,
actor_ix = shr_map_marker:get_character_index(Marker),
is_opportunistic = true
}
];
_ -> []
end.
|