-
Notifications
You must be signed in to change notification settings - Fork 41
/
actions.py
245 lines (216 loc) · 5.14 KB
/
actions.py
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
from construct import *
from aoc.mgz.body.achievements import *
from aoc.mgz.enums import *
"""Not all actions are defined, not all actions are complete"""
attack = Struct("attack",
Byte("player_id"),
Magic("\x00\x00"),
ULInt32("target_id"),
ULInt32("selected"),
LFloat32("x"),
LFloat32("y"),
If(lambda ctx: ctx.selected < 0xff,
Array(lambda ctx: ctx.selected, ULInt32("unit_ids")),
)
)
move = Struct("move",
Byte("player_id"),
Magic("\x00\x00"),
Padding(4),
ULInt32("selected"),
LFloat32("x"),
LFloat32("y"),
If(lambda ctx: ctx.selected < 0xff,
Array(lambda ctx: ctx.selected, ULInt32("unit_ids")),
)
)
resign = Struct("resign",
Byte("player_id"),
Byte("player_num"),
Flag("disconnected")
)
train = Struct("train",
Padding(3),
ULInt32("building_id"),
ULInt16("unit_type"),
ULInt16("number"),
)
research = Struct("research",
Padding(3),
ULInt32("building_id"),
ULInt16("player_id"),
ULInt16("technology_type"),
Padding(4),
)
sell = Struct("sell",
Byte("player_id"),
ResourceEnum(Byte("resource_type")),
Byte("amount"),
Padding(4)
)
buy = Struct("buy",
Byte("player_id"),
ResourceEnum(Byte("resource_type")),
Byte("amount"),
Padding(4)
)
stop = Struct("stop",
Byte("selected"),
Array(lambda ctx: ctx.selected, ULInt32("object_ids"))
)
stance = Struct("stance",
Byte("selected"),
Byte("stance_type"),
Array(lambda ctx: ctx.selected, ULInt32("unit_ids"))
)
guard = Struct("guard",
Byte("selected"),
Padding(2),
ULInt32("guarded_unit_id"),
Array(lambda ctx: ctx.selected, ULInt32("unit_ids"))
)
follow = Struct("follow",
Byte("selected"),
Padding(2),
ULInt32("followed_unit_id"),
Array(lambda ctx: ctx.selected, ULInt32("unit_ids"))
)
formation = Struct("formation",
Byte("selected"),
ULInt16("player_id"),
ULInt32("formation_type"),
Array(lambda ctx: ctx.selected, ULInt32("unit_ids"))
)
multiplayersave = Struct("multiplayersave",
ULInt16("player_id"),
Padding(5),
CString("filename")
)
build = Struct("build",
Byte("selected"),
ULInt16("player_id"),
LFloat32("x"),
LFloat32("y"),
BuildingEnum(ULInt32("building_type")),
Padding(8),
Array(lambda ctx: ctx.selected, ULInt32("unit_ids"))
)
gamespeed = Struct("gamespeed",
Padding(15),
)
wall = Struct("wall",
Byte("selected"),
Byte("player_id"),
Padding(4),
Padding(1),
ULInt32("building_id"),
Padding(4),
Array(lambda ctx: ctx.selected, ULInt32("unit_ids")),
)
delete = Struct("delete",
Padding(3),
ULInt32("object_id"),
ULInt32("player_id")
)
attackground = Struct("attackground",
Byte("selected"),
Padding(2),
LFloat32("x"),
LFloat32("y"),
Array(lambda ctx: ctx.selected, ULInt32("unit_ids"))
)
tribute = Struct("tribute",
Byte("player_id"),
Byte("player_id_to"),
ResourceEnum(Byte("resource_type")),
LFloat32("amount"),
LFloat32("fee")
)
unload = Struct("unload",
ULInt16("selected"),
Padding(1),
LFloat32("x"), # -1 if none
LFloat32("y"), # -1 if none
Padding(4),
Padding(4), # 0xffffffff
Array(lambda ctx: ctx.selected, ULInt32("unit_ids"))
)
flare = Struct("flare",
Padding(7),
Array(9, Byte("player_ids")),
Padding(3),
LFloat32("x"),
LFloat32("y"),
Byte("player_id"),
Byte("player_number"),
Padding(2)
)
garrison = Struct("garrison",
Byte("selected"),
Padding(2),
SLInt32("building_id"), # -1 cancels production queue
ULInt32("u0"),
LFloat32("x"),
LFloat32("y"),
Padding(4), # const
Array(lambda ctx: ctx.selected, ULInt32("unit_ids")),
)
gatherpoint = Struct("gatherpoint",
Byte("selected"),
Padding(2),
ULInt32("target_id"),
ULInt32("target_type"),
LFloat32("x"),
LFloat32("y"),
Array(lambda ctx: ctx.selected, ULInt32("unit_ids"))
)
townbell = Struct("townbell",
Padding(3),
ULInt32("towncenter_id"),
ULInt32("active")
)
"""Patrol
10 X-coordinates followed by 10 Y-coordinates
First of each is popped off for consistency with other actions
"""
patrol = Struct("patrol",
Byte("selected"),
ULInt16("waypoints"),
LFloat32("x"),
Array(9, LFloat32("x_more")),
LFloat32("y"),
Array(9, LFloat32("y_more")),
Array(lambda ctx: ctx.selected, ULInt32("unit_ids")),
)
backtowork = Struct("backtowork",
Padding(3),
ULInt32("towncenter_id")
)
postgame = Struct("achievements",
Padding(3),
String("scenario_filename", 32, padchar = '\x00', trimdir = 'right'),
Byte("player_num"),
Byte("computer_num"),
Padding(2),
TimeSecAdapter(ULInt32("duration")),
Flag("cheats"),
Flag("complete"),
Padding(14),
Byte("map_size"),
Byte("map_id"),
Byte("population"),
Padding(1),
VictoryEnum(Byte("victory_type")),
StartingAgeEnum(Byte("starting_age")),
ResourceLevelEnum(Byte("resource_level")),
Flag("all_techs"),
Flag("team_together", truth = 0, falsehood = 1),
RevealMapEnum(Byte("reveal_map")),
Padding(3),
Flag("lock_teams"),
Flag("lock_speed"),
Padding(1),
Array(lambda ctx: ctx.player_num, achievements),
Padding(4),
Array(lambda ctx: (8 - (ctx.player_num + ctx.computer_num)) * 63, Padding(4)),
)