-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhist_record.h
329 lines (289 loc) · 6.12 KB
/
hist_record.h
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*
harris - a strategy game
Copyright (C) 2012-2015 Edward Cree
licensed under GPLv3+ - see top of harris.c for details
hist_record: parse history events from a game event log (for stats purposes)
*/
#include "types.h"
#include "date.h"
/* Event classes start here */
/* Aircraft events */
// <ct-ev> ::= CT <mark:int> # older saves may be missing <mark>, in which case assume 0
struct creat_record
{
unsigned int mark;
};
// <nav-ev> ::= NA <navaid:int> # installation of a navaid (or, for fighters, radar)
struct nav_record
{
unsigned int navaid;
};
// <pff-ev> ::= PF # assignment to PFF - not reversible
// no data to store
// <raid-ev>::= RA <targ-id:int> <ra-crew>
// <ra-crew>::= <cm-uid> [<ra-crew>]
struct raid_record
{
unsigned int targ;
unsigned int ncrew; // if 0, then the crew just weren't stored (there must have been _someone_ flying it...)
cmid crew[MAX_CREW];
};
// <hit-ev> ::= HI <targ-id:int> <bmb:int> # bmb is either lb of bombs, lb of mines, or # of leaflets. Need targ-id as we might have hit a different target to the one we were aiming for
struct hit_record
{
unsigned int targ;
unsigned int bmb;
};
// <dmg-ev> ::= DM <delta-dmg:float> <current-dmg:float> (AC <from:ac-uid> | FK <flak-id:int> | TF <targ-d:int>)
struct dmg_record
{
double delta, current;
/* For DS_FIGHTER we store the acid in src.idx, whereas a dmgsrc in the game stores
* the index into game.fighters. Similarly, for DS_BOMBER, we store the acid, but
* the game stores the index into game.bombers.
*/
dmgsrc src;
};
// <fail-ev>::= FA <failstate:int> # is really a bool
struct fail_record
{
bool state;
};
// <crsh-ev>::= CR
// <scrp-ev>::= SC
// <obs-ev> ::= OB
enum crob_type
{
CROB_CR,
CROB_SC,
CROB_OB,
};
struct crob_record
{
enum crob_type ty;
};
/* <data> ::= A <ac-uid> <b-or-f><type:int> <a-event> | ...
* <a-event>::= <ct-ev> | <nav-ev> | <pff-ev> | <raid-ev> | <hit-ev> | <dmg-ev> | <fail-ev> | <crsh-ev> | <obs-ev>
*/
enum acev_type
{
AE_CT,
AE_NAV,
AE_PFF,
AE_RAID,
AE_HIT,
AE_DMG,
AE_FAIL,
AE_CROB,
ACEV_TYPES
};
struct ac_record
{
acid id;
bool fighter;
unsigned int ac_type;
enum acev_type type;
union
{
struct creat_record creat;
struct nav_record nav;
/* no data for PF */
struct raid_record raid;
struct hit_record hit;
struct dmg_record dmg;
struct fail_record fail;
struct crob_record crob;
};
};
/* Target events */
// <t-dmg> ::= DM <delta-dmg:float> <current-dmg:float>
struct tdm_record
{
double delta, current;
};
// <t-flk> ::= FK <delta-flk:float> <current-flk:float>
struct tfk_record
{
double delta, current;
};
// <t-ship> ::= SH
// no data to store
/* <data> ::= ... | T <targ-id:int> <t-event>
* <t-event>::= <t-dmg> | <t-flk> | <t-ship>
*/
enum targev_type
{
TE_DMG,
TE_FLAK,
TE_SHIP,
TARGEV_TYPES
};
struct targ_record
{
unsigned int id;
enum targev_type type;
union
{
struct tdm_record tdm;
struct tfk_record tfk;
/* no data for T SH */
};
};
/* Misc. events */
// <cash-ev>::= CA <delta-cash:int> <current-cash:int> # Only for Budget payments, as CT costs are known
struct cash_record
{
int delta, current;
};
// <conf-ev>::= CO <confid:float>
struct confid_record
{
double confid;
};
// <mora-ev>::= MO <morale:float>
struct morale_record
{
double morale;
};
// <gprd-ev>::= GP <iclass:int> <gprod:float> <dprod:float> # dprod is _not_ the difference from the previous gprod!
struct gprod_record
{
enum i_class iclass;
double gprod, dprod;
};
// <tpri-ev>::= TP <tclass:int> <ignore:int> # really a bool
struct tprio_record
{
enum t_class tclass;
bool ignore;
};
// <ipri-ev>::= IP <iclass:int> <ignore:int> # really a bool
struct iprio_record
{
enum i_class iclass;
bool ignore;
};
// <prop-ev>::= PG <event:int>
struct prop_record
{
int event;
};
/* <data> ::= ... | M <misc-ev>
* <misc-ev>::= <cash-ev> | <conf-ev> | <mora-ev> | <gprd-ev> | <prio-ev> | <prop-ev>
* <prio-ev>::= <tpri-ev> | <ipri-ev>
*/
enum miscev_type
{
ME_CASH,
ME_CONFID,
ME_MORALE,
ME_GPROD,
ME_TPRIO,
ME_IPRIO,
ME_PROP,
MISCEV_TYPES
};
struct misc_record
{
enum miscev_type type;
union
{
struct cash_record cash;
struct confid_record confid;
struct morale_record morale;
struct gprod_record gprod;
struct tprio_record tprio;
struct iprio_record iprio;
struct prop_record prop;
};
};
/* Crew events */
// <gen-ev> ::= GE <lrate:int> # generation of a new (student) crewman
struct gen_record
{
unsigned int lrate;
};
// <ski-ev> ::= SK <skill:int> # reached a new integer-part of skill
struct skill_record
{
unsigned int skill;
};
/* <csta-ev>::= ST <cstatus> # status change (see also EX)
* <cstatus>::= C | S | I # never have E as that's an <escp-ev> rather than a <csta-ev>
*/
struct csta_record
{
enum cstatus status;
};
// <op-ev> ::= OP <tops:int> # completed an op (*not* generated daily for instructors!)
struct op_record
{
unsigned int tops;
};
// <deth-ev>::= DE | PW
struct death_record
{
bool pw;
};
// <escp-ev>::= EX <rtime:int> # number of days until return
struct esc_record
{
int rtime;
};
/* <data> ::= ... | C <cm-uid> <cclass> <crew-ev>
* <crew-ev>::= <gen-ev> | <ski-ev> | <csta-ev> | <op-ev> | <deth-ev> | <escp-ev>
*/
enum crewev_type
{
CE_GEN,
CE_SKILL,
CE_STATUS,
CE_OP,
CE_DEATH, // Includes PW
CE_ESC,
CREWEV_TYPES
};
struct crew_record
{
cmid id;
enum cclass cclass;
enum crewev_type type;
union
{
struct gen_record gen;
struct skill_record skill;
struct csta_record csta;
struct op_record op;
struct death_record death;
struct esc_record esc;
};
};
/* Overall event container */
/* <record> ::= <date> <time> <data>
* <data> ::= A <ac-uid> <b-or-f><type:int> <a-event> | T <targ-id:int> <t-event> | I <init-ev> | M <misc-ev> | C <cm-uid> <cclass> <crew-ev>
* <init-ev>::= INIT <filename:str> # Never generated, but should appear in all startpoints (*.sav.in)
*/
enum hist_type
{
HT_INIT,
HT_AC,
HT_TARG,
HT_MISC,
HT_CREW,
HIST_TYPES
};
struct hist_record
{
date date;
harris_time time;
enum hist_type type;
union
{
char *init; // filename
struct ac_record ac;
struct targ_record targ;
struct misc_record misc;
struct crew_record crew;
};
};
int parse_event(struct hist_record *rec, char *line);