-
Notifications
You must be signed in to change notification settings - Fork 1
/
cgl.h
314 lines (306 loc) · 6.1 KB
/
cgl.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
/* cgl.h - data structures representing a single CGL level file and the tile
* structure - the main data structure of the game simulation and graphics
* Copyright (C) 2010 Michal Trybus.
*
* This file is part of FreeCG.
*
* FreeCG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* FreeCG is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FreeCG. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CGL_H
#define CGL_H
#include "mathgeom.h"
#include "gfx.h"
#include <stdio.h>
#include <stdint.h>
#define CGL_MAGIC "\xe1\xd2\xc3\xb4"
enum cgl_sizes {
/* side length in pixels of the smallest game unit */
UNIT = 4,
CGL_BLOCK_SIZE = (8 * UNIT),
BLOCK_SIZE = 32,
/* size of section headers */
CGL_SHDR_SIZE = 4,
CGL_MAGIC_SIZE = 4,
SOBS_TILE_SIZE = 4,
VENT_NUM_SHORTS = 18,
VENT_HDR_SIZE = 2,
MAGN_NUM_SHORTS = 18,
MAGN_HDR_SIZE = 2,
DIST_NUM_SHORTS = 18,
DIST_HDR_SIZE = 2,
CANO_NUM_SHORTS = 22,
CANO_HDR_SIZE = 3,
PIPE_NUM_SHORTS = 4,
PIPE_HDR_SIZE = 16,
ONEW_HDR_SIZE = 1,
ONEW_NUM_SHORTS = 32,
LPTS_HDR_SIZE = 1,
LPTS_NUM_SHORTS = 6,
LPTS_NUM_STUFF = 10
};
/* All dynamic tiles (not in SOBS) are placed above the rest */
#define DYN_TILES_Z 0.1
/* Some dynamic tiles consist of 2 layers. Second layer's Z */
#define DYN_TILES_OVERLAY_Z 0.2
enum error_codes {
EBADHDR = 1,
EBADSHDR,
EBADSIZE,
EBADSOIN,
EBADSOBS,
EBADVENT,
EBADMAGN,
EBADDIST,
EBADCANO,
EBADPIPE,
EBADONEW,
EBADBARR,
EBADLPTS,
/* ... */
EBADSHORT,
EBADINT
};
/* The main tile data structure. Used to represent all objects in the game. */
struct tile {
/* origin */
short x, y;
/* dimensions */
unsigned short w, h;
/* texture position - assume the same dimensions of texture */
short tex_x, tex_y;
/* z-value - from 0 (lowest) to 1 (highest) */
double z;
enum type {
/* drawn normally */
Simple = 0,
/* not drawn */
Transparent,
/* Blinking (for gate lights) */
Blink
} type;
/* This is the type of collision test to be performed on a tile */
enum collision_test {
/* The whole rectangular area defined by points (x, y) and
* (x + w, y + h) is used to detect collisions */
Rect = 0,
/* As above, but check whether the center of ship intersects,
* not the whole ship */
RectPoint,
/* A rectangular part of collision map defined by points
* (img_x, img_y), (img_x + w, img_y + h) is used to detect
* collisions in a rectabgular tile */
Bitmap,
/* For transparent or special tiles */
NoCollision,
/* Collisions are detected using a special function */
Cannon
} collision_test;
/* What to do if there's a collision */
enum collision_type {
Kaboom = 0,
AirgenAction,
GateAction,
LGateAction,
AirportAction,
FanAction,
MagnetAction
} collision_type;
/* necessary for renderer, the number of the most recent frame in
* which the tile was rendered */
unsigned int lframe;
/* additional data necessary for collision detection */
void *data;
};
struct fan {
enum {
Hi = 0,
Low
} power;
enum dir dir;
struct tile *base,
*pipes,
*act;
/* x position of the primary texture */
int tex_x;
double modifier;
};
struct magnet {
enum dir dir;
struct tile *base,
*magn,
*act;
/* x position of the primary texture */
int tex_x;
double modifier;
};
struct airgen {
enum {
CCW = 0,
CW
} spin;
enum dir dir;
struct tile *base,
*pipes,
*act;
/* x position of the primary texture */
int tex_x;
int active;
};
struct cannon {
enum dir dir;
int fire_rate;
int speed_x, speed_y;
struct tile *beg_base,
*beg_cano,
*end_base,
*end_catch;
vector beg,
end;
};
enum orientation {
Vertical = 0,
Horizontal
};
struct bar {
enum {
Constant = 0,
Variable
} gap_type;
enum orientation orientation;
double flen, slen;
double fspeed, sspeed;
double fnext_change, snext_change;
int len;
int gap;
int min_s, max_s;
int freq;
struct tile *beg,
*end,
*fbar,
*sbar;
int btex_x, etex_x;
};
enum gate_type{
GateLeft = 0,
GateTop,
GateRight,
GateBottom
};
struct gate {
struct tile *base[5],
*bar,
*arrow,
*act;
enum gate_type type;
enum orientation orient;
int dir;
int has_end;
double max_len, len;
int active;
};
struct lgate {
struct tile *base[5],
*bar,
*light[4],
*act;
enum gate_type type;
enum orientation orient;
int keys[4];
int has_end;
double max_len, len;
int active;
int open;
};
struct freight {
enum {
Freight1 = 0,
Freight2,
Freight3,
Freight4
} f;
struct airport *ap;
};
struct airport {
struct tile *base,
*stripe[2],
*arrow[2],
*cargo[10];
struct rect lbbox;
enum {
Homebase = 1,
Key,
Fuel,
Freight,
Extras,
} type;
int has_left_arrow,
has_right_arrow;
size_t num_cargo;
double transfer_time;
int sched_cargo_transfer;
int ship_touched;
union {
int key;
struct freight freight[10];
enum {
Turbo = 0,
Life,
Cargo
} extras[10];
} c /* common */;
};
typedef struct tile **block;
/* cgl level contents */
enum game_status {
Alive = 0,
Lost,
Victory
};
struct cgl {
enum {
Full,
Demo
} type;
size_t num_all_freight;
size_t num_1ups;
size_t width, height;
size_t ntiles;
struct tile *tiles;
size_t nfans;
struct fan *fans;
size_t nmagnets;
struct magnet *magnets;
size_t nairgens;
struct airgen *airgens;
size_t ncannons;
struct cannon *cannons;
size_t nbars;
struct bar *bars;
size_t ngates;
struct gate *gates;
size_t nlgates;
struct lgate *lgates;
size_t nairports;
struct airport *airports;
struct airport *hb;
block **blocks;
double time;
struct ship *ship;
double kaboom_end;
enum game_status status;
};
struct cgl *read_cgl(const char*, uint8_t**);
void cgl_preprocess(struct cgl*);
void free_cgl(struct cgl*);
#endif