1 /*
2 BStone: A Source port of
3 Blake Stone: Aliens of Gold and Blake Stone: Planet Strike
4 
5 Copyright (c) 1992-2013 Apogee Entertainment, LLC
6 Copyright (c) 2013-2015 Boris I. Bendovsky (bibendovsky@hotmail.com)
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the
20 Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23 
24 
25 #include <functional>
26 #include <unordered_map>
27 #include "3d_def.h"
28 #include "jm_lzh.h"
29 #include "bstone_binary_reader.h"
30 #include "bstone_binary_writer.h"
31 #include "bstone_memory_stream.h"
32 #include "bstone_ps_fizzle_fx.h"
33 #include "bstone_string_helper.h"
34 #include "bstone_text_reader.h"
35 #include "bstone_text_writer.h"
36 
37 
38 void VL_LatchToScreen(
39     int source,
40     int width,
41     int height,
42     int x,
43     int y);
44 
45 /*
46 =============================================================================
47 
48  BLAKE STONE
49  (C)opyright 1993, JAM Productions, Inc.
50 
51  3D engine licensed by ID Software, Inc.
52  Shareware distribution by Apogee Software, Inc.
53 
54 =============================================================================
55 */
56 
57 
58 void ConnectBarriers();
59 void FreeMusic();
60 void ClearMemory();
61 
62 void CA_CacheScreen(
63     int16_t chunk);
64 
65 void VH_UpdateScreen();
66 void DrawHighScores();
67 void freed_main();
68 
69 void PreloadUpdate(
70     uint16_t current,
71     uint16_t total);
72 
73 void OpenAudioFile();
74 
75 
76 bstone::ClArgs g_args;
77 
78 
79 #define FOCALLENGTH (0x5700L) // in global coordinates
80 #define VIEWGLOBAL 0x10000 // globals visable flush to wall
81 
82 #define VIEWWIDTH (256) // size of view window
83 #define VIEWHEIGHT (144)
84 
85 
86 #define MAX_DEST_PATH_LEN (30)
87 
88 
89 /*
90 =============================================================================
91 
92  GLOBAL VARIABLES
93 
94 =============================================================================
95 */
96 
97 extern int16_t pickquick;
98 
99 
100 void DrawCreditsPage();
101 void unfreed_main();
102 void ShowPromo();
103 
104 int16_t starting_episode;
105 int16_t starting_level;
106 int16_t starting_difficulty;
107 
108 std::string data_dir;
109 
110 void InitPlaytemp();
111 
112 
113 uint16_t TopColor;
114 uint16_t BottomColor;
115 
116 bool nospr;
117 
118 int16_t dirangle[9] = {
119     0 * ANGLES / 8,
120     1 * ANGLES / 8,
121     2 * ANGLES / 8,
122     3 * ANGLES / 8,
123     4 * ANGLES / 8,
124     5 * ANGLES / 8,
125     6 * ANGLES / 8,
126     7 * ANGLES / 8,
127     8 * ANGLES / 8,
128 }; // dirangle
129 
130 //
131 // proejection variables
132 //
133 int focallength;
134 int screenofs;
135 int viewwidth;
136 int viewheight;
137 int centerx;
138 int shootdelta; // pixels away from centerx a target can be
139 int scale;
140 int maxslope;
141 int heightnumerator;
142 int minheightdiv;
143 
144 
145 bool startgame;
146 bool loadedgame;
147 int mouseadjustment;
148 
149 const std::string binary_config_file_name = "bstone_config";
150 const std::string text_config_file_name = "bstone_config.txt";
151 
152 // FIXME Unused
153 #if 0
154 int16_t view_xl;
155 int16_t view_xh;
156 int16_t view_yl;
157 int16_t view_yh;
158 #endif // 0
159 
160 static const bool default_no_wall_hit_sound = true;
161 bool g_no_wall_hit_sound = default_no_wall_hit_sound;
162 
163 static const bool default_always_run = true;
164 bool g_always_run = default_always_run;
165 
166 // BBi AOG only options
167 static const bool default_heart_beat_sound = false;
168 bool g_heart_beat_sound = default_heart_beat_sound;
169 
170 static const bool default_rotated_automap = false;
171 bool g_rotated_automap = default_rotated_automap;
172 
173 GameType g_game_type;
174 
175 
176 bool no_screens = false;
177 
178 
179 // ==========================================================================
180 // Sprites
181 
182 int16_t SPR_DEMO = 0;
183 
184 int16_t SPR_STAT_0 = 0;
185 int16_t SPR_STAT_1 = 0;
186 int16_t SPR_STAT_2 = 0;
187 int16_t SPR_STAT_3 = 0;
188 int16_t SPR_STAT_4 = 0;
189 int16_t SPR_STAT_5 = 0;
190 int16_t SPR_STAT_6 = 0;
191 int16_t SPR_STAT_7 = 0;
192 int16_t SPR_STAT_8 = 0;
193 int16_t SPR_STAT_9 = 0;
194 int16_t SPR_STAT_10 = 0;
195 int16_t SPR_STAT_11 = 0;
196 int16_t SPR_STAT_12 = 0;
197 int16_t SPR_STAT_13 = 0;
198 int16_t SPR_STAT_14 = 0;
199 int16_t SPR_STAT_15 = 0;
200 int16_t SPR_STAT_16 = 0;
201 int16_t SPR_STAT_17 = 0;
202 int16_t SPR_STAT_18 = 0;
203 int16_t SPR_STAT_19 = 0;
204 int16_t SPR_STAT_20 = 0;
205 int16_t SPR_STAT_21 = 0;
206 int16_t SPR_STAT_22 = 0;
207 int16_t SPR_STAT_23 = 0;
208 int16_t SPR_STAT_24 = 0;
209 int16_t SPR_STAT_25 = 0;
210 int16_t SPR_STAT_26 = 0;
211 int16_t SPR_STAT_27 = 0;
212 int16_t SPR_STAT_28 = 0;
213 int16_t SPR_STAT_29 = 0;
214 int16_t SPR_STAT_30 = 0;
215 int16_t SPR_STAT_31 = 0;
216 int16_t SPR_STAT_32 = 0;
217 int16_t SPR_STAT_33 = 0;
218 int16_t SPR_STAT_34 = 0;
219 int16_t SPR_STAT_35 = 0;
220 int16_t SPR_STAT_36 = 0;
221 int16_t SPR_STAT_37 = 0;
222 int16_t SPR_STAT_38 = 0;
223 int16_t SPR_STAT_39 = 0;
224 int16_t SPR_STAT_40 = 0;
225 int16_t SPR_STAT_41 = 0;
226 int16_t SPR_STAT_42 = 0;
227 int16_t SPR_STAT_43 = 0;
228 int16_t SPR_STAT_44 = 0;
229 int16_t SPR_STAT_45 = 0;
230 int16_t SPR_STAT_46 = 0;
231 int16_t SPR_STAT_47 = 0;
232 int16_t SPR_STAT_48 = 0;
233 int16_t SPR_STAT_49 = 0;
234 int16_t SPR_STAT_50 = 0;
235 int16_t SPR_STAT_51 = 0;
236 int16_t SPR_STAT_52 = 0;
237 int16_t SPR_STAT_53 = 0;
238 int16_t SPR_STAT_54 = 0;
239 int16_t SPR_STAT_55 = 0;
240 int16_t SPR_STAT_56 = 0;
241 
242 int16_t SPR_CRATE_1 = 0;
243 int16_t SPR_CRATE_2 = 0;
244 int16_t SPR_CRATE_3 = 0;
245 
246 int16_t SPR_STAT_57 = 0;
247 int16_t SPR_STAT_58 = 0;
248 int16_t SPR_STAT_59 = 0;
249 int16_t SPR_STAT_60 = 0;
250 int16_t SPR_STAT_61 = 0;
251 int16_t SPR_STAT_62 = 0;
252 int16_t SPR_STAT_63 = 0;
253 int16_t SPR_STAT_64 = 0;
254 int16_t SPR_STAT_65 = 0;
255 int16_t SPR_STAT_66 = 0;
256 int16_t SPR_STAT_67 = 0;
257 int16_t SPR_STAT_68 = 0;
258 int16_t SPR_STAT_69 = 0;
259 int16_t SPR_STAT_70 = 0;
260 int16_t SPR_STAT_71 = 0;
261 int16_t SPR_STAT_72 = 0;
262 int16_t SPR_STAT_73 = 0;
263 int16_t SPR_STAT_74 = 0;
264 int16_t SPR_STAT_75 = 0;
265 int16_t SPR_STAT_76 = 0;
266 int16_t SPR_STAT_77 = 0;
267 int16_t SPR_STAT_78 = 0;
268 int16_t SPR_STAT_79 = 0;
269 
270 int16_t SPR_DOORBOMB = 0;
271 int16_t SPR_ALT_DOORBOMB = 0;
272 int16_t SPR_RUBBLE = 0;
273 int16_t SPR_BONZI_TREE = 0;
274 int16_t SPR_AUTOMAPPER = 0;
275 int16_t SPR_POT_PLANT = 0;
276 int16_t SPR_TUBE_PLANT = 0;
277 int16_t SPR_HITECH_CHAIR = 0;
278 
279 int16_t SPR_AIR_VENT = 0;
280 int16_t SPR_BLOOD_DRIP1 = 0;
281 int16_t SPR_BLOOD_DRIP2 = 0;
282 int16_t SPR_BLOOD_DRIP3 = 0;
283 int16_t SPR_BLOOD_DRIP4 = 0;
284 int16_t SPR_WATER_DRIP1 = 0;
285 int16_t SPR_WATER_DRIP2 = 0;
286 int16_t SPR_WATER_DRIP3 = 0;
287 int16_t SPR_WATER_DRIP4 = 0;
288 
289 int16_t SPR_DECO_ARC_1 = 0;
290 int16_t SPR_DECO_ARC_2 = 0;
291 int16_t SPR_DECO_ARC_3 = 0;
292 
293 int16_t SPR_GRATE = 0;
294 int16_t SPR_STEAM_1 = 0;
295 int16_t SPR_STEAM_2 = 0;
296 int16_t SPR_STEAM_3 = 0;
297 int16_t SPR_STEAM_4 = 0;
298 
299 int16_t SPR_STEAM_PIPE = 0;
300 int16_t SPR_PIPE_STEAM_1 = 0;
301 int16_t SPR_PIPE_STEAM_2 = 0;
302 int16_t SPR_PIPE_STEAM_3 = 0;
303 int16_t SPR_PIPE_STEAM_4 = 0;
304 
305 int16_t SPR_DEAD_RENT = 0;
306 int16_t SPR_DEAD_PRO = 0;
307 int16_t SPR_DEAD_SWAT = 0;
308 
309 int16_t SPR_RENT_S_1 = 0;
310 int16_t SPR_RENT_S_2 = 0;
311 int16_t SPR_RENT_S_3 = 0;
312 int16_t SPR_RENT_S_4 = 0;
313 int16_t SPR_RENT_S_5 = 0;
314 int16_t SPR_RENT_S_6 = 0;
315 int16_t SPR_RENT_S_7 = 0;
316 int16_t SPR_RENT_S_8 = 0;
317 
318 int16_t SPR_RENT_W1_1 = 0;
319 int16_t SPR_RENT_W1_2 = 0;
320 int16_t SPR_RENT_W1_3 = 0;
321 int16_t SPR_RENT_W1_4 = 0;
322 int16_t SPR_RENT_W1_5 = 0;
323 int16_t SPR_RENT_W1_6 = 0;
324 int16_t SPR_RENT_W1_7 = 0;
325 int16_t SPR_RENT_W1_8 = 0;
326 
327 int16_t SPR_RENT_W2_1 = 0;
328 int16_t SPR_RENT_W2_2 = 0;
329 int16_t SPR_RENT_W2_3 = 0;
330 int16_t SPR_RENT_W2_4 = 0;
331 int16_t SPR_RENT_W2_5 = 0;
332 int16_t SPR_RENT_W2_6 = 0;
333 int16_t SPR_RENT_W2_7 = 0;
334 int16_t SPR_RENT_W2_8 = 0;
335 
336 int16_t SPR_RENT_W3_1 = 0;
337 int16_t SPR_RENT_W3_2 = 0;
338 int16_t SPR_RENT_W3_3 = 0;
339 int16_t SPR_RENT_W3_4 = 0;
340 int16_t SPR_RENT_W3_5 = 0;
341 int16_t SPR_RENT_W3_6 = 0;
342 int16_t SPR_RENT_W3_7 = 0;
343 int16_t SPR_RENT_W3_8 = 0;
344 
345 int16_t SPR_RENT_W4_1 = 0;
346 int16_t SPR_RENT_W4_2 = 0;
347 int16_t SPR_RENT_W4_3 = 0;
348 int16_t SPR_RENT_W4_4 = 0;
349 int16_t SPR_RENT_W4_5 = 0;
350 int16_t SPR_RENT_W4_6 = 0;
351 int16_t SPR_RENT_W4_7 = 0;
352 int16_t SPR_RENT_W4_8 = 0;
353 
354 int16_t SPR_RENT_DIE_1 = 0;
355 int16_t SPR_RENT_DIE_2 = 0;
356 int16_t SPR_RENT_DIE_3 = 0;
357 int16_t SPR_RENT_DIE_4 = 0;
358 int16_t SPR_RENT_PAIN_1 = 0;
359 int16_t SPR_RENT_DEAD = 0;
360 
361 int16_t SPR_RENT_SHOOT1 = 0;
362 int16_t SPR_RENT_SHOOT2 = 0;
363 int16_t SPR_RENT_SHOOT3 = 0;
364 
365 int16_t SPR_PRO_S_1 = 0;
366 int16_t SPR_PRO_S_2 = 0;
367 int16_t SPR_PRO_S_3 = 0;
368 int16_t SPR_PRO_S_4 = 0;
369 int16_t SPR_PRO_S_5 = 0;
370 int16_t SPR_PRO_S_6 = 0;
371 int16_t SPR_PRO_S_7 = 0;
372 int16_t SPR_PRO_S_8 = 0;
373 
374 int16_t SPR_PRO_W1_1 = 0;
375 int16_t SPR_PRO_W1_2 = 0;
376 int16_t SPR_PRO_W1_3 = 0;
377 int16_t SPR_PRO_W1_4 = 0;
378 int16_t SPR_PRO_W1_5 = 0;
379 int16_t SPR_PRO_W1_6 = 0;
380 int16_t SPR_PRO_W1_7 = 0;
381 int16_t SPR_PRO_W1_8 = 0;
382 
383 int16_t SPR_PRO_W2_1 = 0;
384 int16_t SPR_PRO_W2_2 = 0;
385 int16_t SPR_PRO_W2_3 = 0;
386 int16_t SPR_PRO_W2_4 = 0;
387 int16_t SPR_PRO_W2_5 = 0;
388 int16_t SPR_PRO_W2_6 = 0;
389 int16_t SPR_PRO_W2_7 = 0;
390 int16_t SPR_PRO_W2_8 = 0;
391 
392 int16_t SPR_PRO_W3_1 = 0;
393 int16_t SPR_PRO_W3_2 = 0;
394 int16_t SPR_PRO_W3_3 = 0;
395 int16_t SPR_PRO_W3_4 = 0;
396 int16_t SPR_PRO_W3_5 = 0;
397 int16_t SPR_PRO_W3_6 = 0;
398 int16_t SPR_PRO_W3_7 = 0;
399 int16_t SPR_PRO_W3_8 = 0;
400 
401 int16_t SPR_PRO_W4_1 = 0;
402 int16_t SPR_PRO_W4_2 = 0;
403 int16_t SPR_PRO_W4_3 = 0;
404 int16_t SPR_PRO_W4_4 = 0;
405 int16_t SPR_PRO_W4_5 = 0;
406 int16_t SPR_PRO_W4_6 = 0;
407 int16_t SPR_PRO_W4_7 = 0;
408 int16_t SPR_PRO_W4_8 = 0;
409 
410 int16_t SPR_PRO_PAIN_1 = 0;
411 int16_t SPR_PRO_DIE_1 = 0;
412 int16_t SPR_PRO_DIE_2 = 0;
413 int16_t SPR_PRO_DIE_3 = 0;
414 int16_t SPR_PRO_PAIN_2 = 0;
415 int16_t SPR_PRO_DIE_4 = 0;
416 int16_t SPR_PRO_DEAD = 0;
417 
418 int16_t SPR_PRO_SHOOT1 = 0;
419 int16_t SPR_PRO_SHOOT2 = 0;
420 int16_t SPR_PRO_SHOOT3 = 0;
421 
422 int16_t SPR_SWAT_S_1 = 0;
423 int16_t SPR_SWAT_S_2 = 0;
424 int16_t SPR_SWAT_S_3 = 0;
425 int16_t SPR_SWAT_S_4 = 0;
426 int16_t SPR_SWAT_S_5 = 0;
427 int16_t SPR_SWAT_S_6 = 0;
428 int16_t SPR_SWAT_S_7 = 0;
429 int16_t SPR_SWAT_S_8 = 0;
430 
431 int16_t SPR_SWAT_W1_1 = 0;
432 int16_t SPR_SWAT_W1_2 = 0;
433 int16_t SPR_SWAT_W1_3 = 0;
434 int16_t SPR_SWAT_W1_4 = 0;
435 int16_t SPR_SWAT_W1_5 = 0;
436 int16_t SPR_SWAT_W1_6 = 0;
437 int16_t SPR_SWAT_W1_7 = 0;
438 int16_t SPR_SWAT_W1_8 = 0;
439 
440 int16_t SPR_SWAT_W2_1 = 0;
441 int16_t SPR_SWAT_W2_2 = 0;
442 int16_t SPR_SWAT_W2_3 = 0;
443 int16_t SPR_SWAT_W2_4 = 0;
444 int16_t SPR_SWAT_W2_5 = 0;
445 int16_t SPR_SWAT_W2_6 = 0;
446 int16_t SPR_SWAT_W2_7 = 0;
447 int16_t SPR_SWAT_W2_8 = 0;
448 
449 int16_t SPR_SWAT_W3_1 = 0;
450 int16_t SPR_SWAT_W3_2 = 0;
451 int16_t SPR_SWAT_W3_3 = 0;
452 int16_t SPR_SWAT_W3_4 = 0;
453 int16_t SPR_SWAT_W3_5 = 0;
454 int16_t SPR_SWAT_W3_6 = 0;
455 int16_t SPR_SWAT_W3_7 = 0;
456 int16_t SPR_SWAT_W3_8 = 0;
457 
458 int16_t SPR_SWAT_W4_1 = 0;
459 int16_t SPR_SWAT_W4_2 = 0;
460 int16_t SPR_SWAT_W4_3 = 0;
461 int16_t SPR_SWAT_W4_4 = 0;
462 int16_t SPR_SWAT_W4_5 = 0;
463 int16_t SPR_SWAT_W4_6 = 0;
464 int16_t SPR_SWAT_W4_7 = 0;
465 int16_t SPR_SWAT_W4_8 = 0;
466 
467 int16_t SPR_SWAT_PAIN_1 = 0;
468 int16_t SPR_SWAT_DIE_1 = 0;
469 int16_t SPR_SWAT_DIE_2 = 0;
470 int16_t SPR_SWAT_DIE_3 = 0;
471 int16_t SPR_SWAT_PAIN_2 = 0;
472 int16_t SPR_SWAT_DIE_4 = 0;
473 int16_t SPR_SWAT_DEAD = 0;
474 
475 int16_t SPR_SWAT_SHOOT1 = 0;
476 int16_t SPR_SWAT_SHOOT2 = 0;
477 int16_t SPR_SWAT_SHOOT3 = 0;
478 
479 int16_t SPR_SWAT_WOUNDED1 = 0;
480 int16_t SPR_SWAT_WOUNDED2 = 0;
481 int16_t SPR_SWAT_WOUNDED3 = 0;
482 int16_t SPR_SWAT_WOUNDED4 = 0;
483 
484 int16_t SPR_OFC_S_1 = 0;
485 int16_t SPR_OFC_S_2 = 0;
486 int16_t SPR_OFC_S_3 = 0;
487 int16_t SPR_OFC_S_4 = 0;
488 int16_t SPR_OFC_S_5 = 0;
489 int16_t SPR_OFC_S_6 = 0;
490 int16_t SPR_OFC_S_7 = 0;
491 int16_t SPR_OFC_S_8 = 0;
492 
493 int16_t SPR_OFC_W1_1 = 0;
494 int16_t SPR_OFC_W1_2 = 0;
495 int16_t SPR_OFC_W1_3 = 0;
496 int16_t SPR_OFC_W1_4 = 0;
497 int16_t SPR_OFC_W1_5 = 0;
498 int16_t SPR_OFC_W1_6 = 0;
499 int16_t SPR_OFC_W1_7 = 0;
500 int16_t SPR_OFC_W1_8 = 0;
501 
502 int16_t SPR_OFC_W2_1 = 0;
503 int16_t SPR_OFC_W2_2 = 0;
504 int16_t SPR_OFC_W2_3 = 0;
505 int16_t SPR_OFC_W2_4 = 0;
506 int16_t SPR_OFC_W2_5 = 0;
507 int16_t SPR_OFC_W2_6 = 0;
508 int16_t SPR_OFC_W2_7 = 0;
509 int16_t SPR_OFC_W2_8 = 0;
510 
511 int16_t SPR_OFC_W3_1 = 0;
512 int16_t SPR_OFC_W3_2 = 0;
513 int16_t SPR_OFC_W3_3 = 0;
514 int16_t SPR_OFC_W3_4 = 0;
515 int16_t SPR_OFC_W3_5 = 0;
516 int16_t SPR_OFC_W3_6 = 0;
517 int16_t SPR_OFC_W3_7 = 0;
518 int16_t SPR_OFC_W3_8 = 0;
519 
520 int16_t SPR_OFC_W4_1 = 0;
521 int16_t SPR_OFC_W4_2 = 0;
522 int16_t SPR_OFC_W4_3 = 0;
523 int16_t SPR_OFC_W4_4 = 0;
524 int16_t SPR_OFC_W4_5 = 0;
525 int16_t SPR_OFC_W4_6 = 0;
526 int16_t SPR_OFC_W4_7 = 0;
527 int16_t SPR_OFC_W4_8 = 0;
528 
529 int16_t SPR_OFC_PAIN_1 = 0;
530 int16_t SPR_OFC_DIE_1 = 0;
531 int16_t SPR_OFC_DIE_2 = 0;
532 int16_t SPR_OFC_DIE_3 = 0;
533 int16_t SPR_OFC_PAIN_2 = 0;
534 int16_t SPR_OFC_DIE_4 = 0;
535 int16_t SPR_OFC_DEAD = 0;
536 
537 int16_t SPR_OFC_SHOOT1 = 0;
538 int16_t SPR_OFC_SHOOT2 = 0;
539 int16_t SPR_OFC_SHOOT3 = 0;
540 
541 int16_t SPR_GOLD_S_1 = 0;
542 int16_t SPR_GOLD_S_2 = 0;
543 int16_t SPR_GOLD_S_3 = 0;
544 int16_t SPR_GOLD_S_4 = 0;
545 int16_t SPR_GOLD_S_5 = 0;
546 int16_t SPR_GOLD_S_6 = 0;
547 int16_t SPR_GOLD_S_7 = 0;
548 int16_t SPR_GOLD_S_8 = 0;
549 
550 int16_t SPR_GOLD_W1_1 = 0;
551 int16_t SPR_GOLD_W1_2 = 0;
552 int16_t SPR_GOLD_W1_3 = 0;
553 int16_t SPR_GOLD_W1_4 = 0;
554 int16_t SPR_GOLD_W1_5 = 0;
555 int16_t SPR_GOLD_W1_6 = 0;
556 int16_t SPR_GOLD_W1_7 = 0;
557 int16_t SPR_GOLD_W1_8 = 0;
558 
559 int16_t SPR_GOLD_W2_1 = 0;
560 int16_t SPR_GOLD_W2_2 = 0;
561 int16_t SPR_GOLD_W2_3 = 0;
562 int16_t SPR_GOLD_W2_4 = 0;
563 int16_t SPR_GOLD_W2_5 = 0;
564 int16_t SPR_GOLD_W2_6 = 0;
565 int16_t SPR_GOLD_W2_7 = 0;
566 int16_t SPR_GOLD_W2_8 = 0;
567 
568 int16_t SPR_GOLD_W3_1 = 0;
569 int16_t SPR_GOLD_W3_2 = 0;
570 int16_t SPR_GOLD_W3_3 = 0;
571 int16_t SPR_GOLD_W3_4 = 0;
572 int16_t SPR_GOLD_W3_5 = 0;
573 int16_t SPR_GOLD_W3_6 = 0;
574 int16_t SPR_GOLD_W3_7 = 0;
575 int16_t SPR_GOLD_W3_8 = 0;
576 
577 int16_t SPR_GOLD_W4_1 = 0;
578 int16_t SPR_GOLD_W4_2 = 0;
579 int16_t SPR_GOLD_W4_3 = 0;
580 int16_t SPR_GOLD_W4_4 = 0;
581 int16_t SPR_GOLD_W4_5 = 0;
582 int16_t SPR_GOLD_W4_6 = 0;
583 int16_t SPR_GOLD_W4_7 = 0;
584 int16_t SPR_GOLD_W4_8 = 0;
585 
586 int16_t SPR_GOLD_PAIN_1 = 0;
587 
588 int16_t SPR_GOLD_WRIST_1 = 0;
589 int16_t SPR_GOLD_WRIST_2 = 0;
590 
591 int16_t SPR_GOLD_SHOOT1 = 0;
592 int16_t SPR_GOLD_SHOOT2 = 0;
593 int16_t SPR_GOLD_SHOOT3 = 0;
594 
595 int16_t SPR_GOLD_WARP1 = 0;
596 int16_t SPR_GOLD_WARP2 = 0;
597 int16_t SPR_GOLD_WARP3 = 0;
598 int16_t SPR_GOLD_WARP4 = 0;
599 int16_t SPR_GOLD_WARP5 = 0;
600 
601 int16_t SPR_GOLD_DEATH1 = 0;
602 int16_t SPR_GOLD_DEATH2 = 0;
603 int16_t SPR_GOLD_DEATH3 = 0;
604 int16_t SPR_GOLD_DEATH4 = 0;
605 int16_t SPR_GOLD_DEATH5 = 0;
606 int16_t SPR_MGOLD_OUCH = 0;
607 
608 int16_t SPR_GOLD_MORPH1 = 0;
609 int16_t SPR_GOLD_MORPH2 = 0;
610 int16_t SPR_GOLD_MORPH3 = 0;
611 int16_t SPR_GOLD_MORPH4 = 0;
612 int16_t SPR_GOLD_MORPH5 = 0;
613 int16_t SPR_GOLD_MORPH6 = 0;
614 int16_t SPR_GOLD_MORPH7 = 0;
615 int16_t SPR_GOLD_MORPH8 = 0;
616 
617 int16_t SPR_MGOLD_WALK1 = 0;
618 int16_t SPR_MGOLD_WALK2 = 0;
619 int16_t SPR_MGOLD_WALK3 = 0;
620 int16_t SPR_MGOLD_WALK4 = 0;
621 int16_t SPR_MGOLD_ATTACK1 = 0;
622 int16_t SPR_MGOLD_ATTACK2 = 0;
623 int16_t SPR_MGOLD_ATTACK3 = 0;
624 int16_t SPR_MGOLD_ATTACK4 = 0;
625 
626 int16_t SPR_MGOLD_SHOT1 = 0;
627 int16_t SPR_MGOLD_SHOT2 = 0;
628 int16_t SPR_MGOLD_SHOT3 = 0;
629 int16_t SPR_MGOLD_SHOT_EXP1 = 0;
630 int16_t SPR_MGOLD_SHOT_EXP2 = 0;
631 int16_t SPR_MGOLD_SHOT_EXP3 = 0;
632 
633 int16_t SPR_GSCOUT_W1_1 = 0;
634 int16_t SPR_GSCOUT_W1_2 = 0;
635 int16_t SPR_GSCOUT_W1_3 = 0;
636 int16_t SPR_GSCOUT_W1_4 = 0;
637 int16_t SPR_GSCOUT_W1_5 = 0;
638 int16_t SPR_GSCOUT_W1_6 = 0;
639 int16_t SPR_GSCOUT_W1_7 = 0;
640 int16_t SPR_GSCOUT_W1_8 = 0;
641 
642 int16_t SPR_GSCOUT_W2_1 = 0;
643 int16_t SPR_GSCOUT_W2_2 = 0;
644 int16_t SPR_GSCOUT_W2_3 = 0;
645 int16_t SPR_GSCOUT_W2_4 = 0;
646 int16_t SPR_GSCOUT_W2_5 = 0;
647 int16_t SPR_GSCOUT_W2_6 = 0;
648 int16_t SPR_GSCOUT_W2_7 = 0;
649 int16_t SPR_GSCOUT_W2_8 = 0;
650 
651 int16_t SPR_GSCOUT_W3_1 = 0;
652 int16_t SPR_GSCOUT_W3_2 = 0;
653 int16_t SPR_GSCOUT_W3_3 = 0;
654 int16_t SPR_GSCOUT_W3_4 = 0;
655 int16_t SPR_GSCOUT_W3_5 = 0;
656 int16_t SPR_GSCOUT_W3_6 = 0;
657 int16_t SPR_GSCOUT_W3_7 = 0;
658 int16_t SPR_GSCOUT_W3_8 = 0;
659 
660 int16_t SPR_GSCOUT_W4_1 = 0;
661 int16_t SPR_GSCOUT_W4_2 = 0;
662 int16_t SPR_GSCOUT_W4_3 = 0;
663 int16_t SPR_GSCOUT_W4_4 = 0;
664 int16_t SPR_GSCOUT_W4_5 = 0;
665 int16_t SPR_GSCOUT_W4_6 = 0;
666 int16_t SPR_GSCOUT_W4_7 = 0;
667 int16_t SPR_GSCOUT_W4_8 = 0;
668 
669 int16_t SPR_GSCOUT_DIE1 = 0;
670 int16_t SPR_GSCOUT_DIE2 = 0;
671 int16_t SPR_GSCOUT_DIE3 = 0;
672 int16_t SPR_GSCOUT_DIE4 = 0;
673 int16_t SPR_GSCOUT_DIE5 = 0;
674 int16_t SPR_GSCOUT_DIE6 = 0;
675 int16_t SPR_GSCOUT_DIE7 = 0;
676 int16_t SPR_GSCOUT_DIE8 = 0;
677 
678 int16_t SPR_GSCOUT_DEAD = 0;
679 
680 int16_t SPR_FSCOUT_W1_1 = 0;
681 int16_t SPR_FSCOUT_W1_2 = 0;
682 int16_t SPR_FSCOUT_W1_3 = 0;
683 int16_t SPR_FSCOUT_W1_4 = 0;
684 int16_t SPR_FSCOUT_W1_5 = 0;
685 int16_t SPR_FSCOUT_W1_6 = 0;
686 int16_t SPR_FSCOUT_W1_7 = 0;
687 int16_t SPR_FSCOUT_W1_8 = 0;
688 
689 int16_t SPR_FSCOUT_W2_1 = 0;
690 int16_t SPR_FSCOUT_W2_2 = 0;
691 int16_t SPR_FSCOUT_W2_3 = 0;
692 int16_t SPR_FSCOUT_W2_4 = 0;
693 int16_t SPR_FSCOUT_W2_5 = 0;
694 int16_t SPR_FSCOUT_W2_6 = 0;
695 int16_t SPR_FSCOUT_W2_7 = 0;
696 int16_t SPR_FSCOUT_W2_8 = 0;
697 
698 int16_t SPR_FSCOUT_W3_1 = 0;
699 int16_t SPR_FSCOUT_W3_2 = 0;
700 int16_t SPR_FSCOUT_W3_3 = 0;
701 int16_t SPR_FSCOUT_W3_4 = 0;
702 int16_t SPR_FSCOUT_W3_5 = 0;
703 int16_t SPR_FSCOUT_W3_6 = 0;
704 int16_t SPR_FSCOUT_W3_7 = 0;
705 int16_t SPR_FSCOUT_W3_8 = 0;
706 
707 int16_t SPR_FSCOUT_W4_1 = 0;
708 int16_t SPR_FSCOUT_W4_2 = 0;
709 int16_t SPR_FSCOUT_W4_3 = 0;
710 int16_t SPR_FSCOUT_W4_4 = 0;
711 int16_t SPR_FSCOUT_W4_5 = 0;
712 int16_t SPR_FSCOUT_W4_6 = 0;
713 int16_t SPR_FSCOUT_W4_7 = 0;
714 int16_t SPR_FSCOUT_W4_8 = 0;
715 
716 int16_t SPR_FSCOUT_DIE1 = 0;
717 int16_t SPR_FSCOUT_DIE2 = 0;
718 int16_t SPR_FSCOUT_DIE3 = 0;
719 int16_t SPR_FSCOUT_DIE4 = 0;
720 int16_t SPR_FSCOUT_DIE5 = 0;
721 int16_t SPR_FSCOUT_DIE6 = 0;
722 int16_t SPR_FSCOUT_DIE7 = 0;
723 int16_t SPR_FSCOUT_DEAD = 0;
724 
725 int16_t SPR_EXPLOSION_1 = 0;
726 int16_t SPR_EXPLOSION_2 = 0;
727 int16_t SPR_EXPLOSION_3 = 0;
728 int16_t SPR_EXPLOSION_4 = 0;
729 int16_t SPR_EXPLOSION_5 = 0;
730 
731 int16_t SPR_VITAL_STAND = 0;
732 int16_t SPR_VITAL_DIE_1 = 0;
733 int16_t SPR_VITAL_DIE_2 = 0;
734 int16_t SPR_VITAL_DIE_3 = 0;
735 int16_t SPR_VITAL_DIE_4 = 0;
736 int16_t SPR_VITAL_DIE_5 = 0;
737 int16_t SPR_VITAL_DIE_6 = 0;
738 int16_t SPR_VITAL_DIE_7 = 0;
739 int16_t SPR_VITAL_DIE_8 = 0;
740 int16_t SPR_VITAL_DEAD_1 = 0;
741 int16_t SPR_VITAL_DEAD_2 = 0;
742 int16_t SPR_VITAL_DEAD_3 = 0;
743 int16_t SPR_VITAL_OUCH = 0;
744 
745 int16_t SPR_CUBE1 = 0;
746 int16_t SPR_CUBE2 = 0;
747 int16_t SPR_CUBE3 = 0;
748 int16_t SPR_CUBE4 = 0;
749 int16_t SPR_CUBE5 = 0;
750 int16_t SPR_CUBE6 = 0;
751 int16_t SPR_CUBE7 = 0;
752 int16_t SPR_CUBE8 = 0;
753 int16_t SPR_CUBE9 = 0;
754 int16_t SPR_CUBE10 = 0;
755 int16_t SPR_CUBE_EXP1 = 0;
756 int16_t SPR_CUBE_EXP2 = 0;
757 int16_t SPR_CUBE_EXP3 = 0;
758 int16_t SPR_CUBE_EXP4 = 0;
759 int16_t SPR_CUBE_EXP5 = 0;
760 int16_t SPR_CUBE_EXP6 = 0;
761 int16_t SPR_CUBE_EXP7 = 0;
762 int16_t SPR_CUBE_EXP8 = 0;
763 int16_t SPR_DEAD_CUBE = 0;
764 
765 int16_t SPR_SECURITY_NORMAL = 0;
766 int16_t SPR_SECURITY_ALERT = 0;
767 
768 int16_t SPR_POD_EGG = 0;
769 int16_t SPR_POD_HATCH1 = 0;
770 int16_t SPR_POD_HATCH2 = 0;
771 int16_t SPR_POD_HATCH3 = 0;
772 int16_t SPR_POD_WALK1 = 0;
773 int16_t SPR_POD_WALK2 = 0;
774 int16_t SPR_POD_WALK3 = 0;
775 int16_t SPR_POD_WALK4 = 0;
776 int16_t SPR_POD_ATTACK1 = 0;
777 int16_t SPR_POD_ATTACK2 = 0;
778 int16_t SPR_POD_ATTACK3 = 0;
779 int16_t SPR_POD_OUCH = 0;
780 int16_t SPR_POD_DIE1 = 0;
781 int16_t SPR_POD_DIE2 = 0;
782 int16_t SPR_POD_DIE3 = 0;
783 int16_t SPR_POD_SPIT1 = 0;
784 int16_t SPR_POD_SPIT2 = 0;
785 int16_t SPR_POD_SPIT3 = 0;
786 
787 int16_t SPR_ELEC_APPEAR1 = 0;
788 int16_t SPR_ELEC_APPEAR2 = 0;
789 int16_t SPR_ELEC_APPEAR3 = 0;
790 int16_t SPR_ELEC_WALK1 = 0;
791 int16_t SPR_ELEC_WALK2 = 0;
792 int16_t SPR_ELEC_WALK3 = 0;
793 int16_t SPR_ELEC_WALK4 = 0;
794 int16_t SPR_ELEC_OUCH = 0;
795 int16_t SPR_ELEC_SHOOT1 = 0;
796 int16_t SPR_ELEC_SHOOT2 = 0;
797 int16_t SPR_ELEC_SHOOT3 = 0;
798 int16_t SPR_ELEC_DIE1 = 0;
799 int16_t SPR_ELEC_DIE2 = 0;
800 int16_t SPR_ELEC_DIE3 = 0;
801 int16_t SPR_ELEC_SHOT1 = 0;
802 int16_t SPR_ELEC_SHOT2 = 0;
803 int16_t SPR_ELEC_SHOT_EXP1 = 0;
804 int16_t SPR_ELEC_SHOT_EXP2 = 0;
805 
806 int16_t SPR_ELECTRO_SPHERE_ROAM1 = 0;
807 int16_t SPR_ELECTRO_SPHERE_ROAM2 = 0;
808 int16_t SPR_ELECTRO_SPHERE_ROAM3 = 0;
809 int16_t SPR_ELECTRO_SPHERE_OUCH = 0;
810 int16_t SPR_ELECTRO_SPHERE_DIE1 = 0;
811 int16_t SPR_ELECTRO_SPHERE_DIE2 = 0;
812 int16_t SPR_ELECTRO_SPHERE_DIE3 = 0;
813 int16_t SPR_ELECTRO_SPHERE_DIE4 = 0;
814 
815 int16_t SPR_GENETIC_W1 = 0;
816 int16_t SPR_GENETIC_W2 = 0;
817 int16_t SPR_GENETIC_W3 = 0;
818 int16_t SPR_GENETIC_W4 = 0;
819 int16_t SPR_GENETIC_SWING1 = 0;
820 int16_t SPR_GENETIC_SWING2 = 0;
821 int16_t SPR_GENETIC_SWING3 = 0;
822 int16_t SPR_GENETIC_DEAD = 0;
823 int16_t SPR_GENETIC_DIE1 = 0;
824 int16_t SPR_GENETIC_DIE2 = 0;
825 int16_t SPR_GENETIC_DIE3 = 0;
826 int16_t SPR_GENETIC_DIE4 = 0;
827 int16_t SPR_GENETIC_OUCH = 0;
828 int16_t SPR_GENETIC_SHOOT1 = 0;
829 int16_t SPR_GENETIC_SHOOT2 = 0;
830 int16_t SPR_GENETIC_SHOOT3 = 0;
831 
832 int16_t SPR_MUTHUM1_W1 = 0;
833 int16_t SPR_MUTHUM1_W2 = 0;
834 int16_t SPR_MUTHUM1_W3 = 0;
835 int16_t SPR_MUTHUM1_W4 = 0;
836 int16_t SPR_MUTHUM1_SWING1 = 0;
837 int16_t SPR_MUTHUM1_SWING2 = 0;
838 int16_t SPR_MUTHUM1_SWING3 = 0;
839 int16_t SPR_MUTHUM1_DEAD = 0;
840 int16_t SPR_MUTHUM1_DIE1 = 0;
841 int16_t SPR_MUTHUM1_DIE2 = 0;
842 int16_t SPR_MUTHUM1_DIE3 = 0;
843 int16_t SPR_MUTHUM1_DIE4 = 0;
844 int16_t SPR_MUTHUM1_OUCH = 0;
845 int16_t SPR_MUTHUM1_SPIT1 = 0;
846 int16_t SPR_MUTHUM1_SPIT2 = 0;
847 int16_t SPR_MUTHUM1_SPIT3 = 0;
848 
849 int16_t SPR_MUTHUM2_W1 = 0;
850 int16_t SPR_MUTHUM2_W2 = 0;
851 int16_t SPR_MUTHUM2_W3 = 0;
852 int16_t SPR_MUTHUM2_W4 = 0;
853 int16_t SPR_MUTHUM2_SWING1 = 0;
854 int16_t SPR_MUTHUM2_SWING2 = 0;
855 int16_t SPR_MUTHUM2_SWING3 = 0;
856 int16_t SPR_MUTHUM2_DEAD = 0;
857 int16_t SPR_MUTHUM2_DIE1 = 0;
858 int16_t SPR_MUTHUM2_DIE2 = 0;
859 int16_t SPR_MUTHUM2_DIE3 = 0;
860 int16_t SPR_MUTHUM2_DIE4 = 0;
861 int16_t SPR_MUTHUM2_OUCH = 0;
862 int16_t SPR_MUTHUM2_SPIT1 = 0;
863 int16_t SPR_MUTHUM2_SPIT2 = 0;
864 int16_t SPR_MUTHUM2_SPIT3 = 0;
865 
866 int16_t SPR_MUTHUM2_MORPH1 = 0;
867 int16_t SPR_MUTHUM2_MORPH2 = 0;
868 int16_t SPR_MUTHUM2_MORPH3 = 0;
869 int16_t SPR_MUTHUM2_MORPH4 = 0;
870 int16_t SPR_MUTHUM2_MORPH5 = 0;
871 int16_t SPR_MUTHUM2_MORPH6 = 0;
872 int16_t SPR_MUTHUM2_MORPH7 = 0;
873 int16_t SPR_MUTHUM2_MORPH8 = 0;
874 int16_t SPR_MUTHUM2_MORPH9 = 0;
875 
876 int16_t SPR_LCAN_ALIEN_READY = 0;
877 int16_t SPR_LCAN_ALIEN_B1 = 0;
878 int16_t SPR_LCAN_ALIEN_B2 = 0;
879 int16_t SPR_LCAN_ALIEN_B3 = 0;
880 int16_t SPR_LCAN_ALIEN_EMPTY = 0;
881 
882 int16_t SPR_LCAN_ALIEN_W1 = 0;
883 int16_t SPR_LCAN_ALIEN_W2 = 0;
884 int16_t SPR_LCAN_ALIEN_W3 = 0;
885 int16_t SPR_LCAN_ALIEN_W4 = 0;
886 int16_t SPR_LCAN_ALIEN_SWING1 = 0;
887 int16_t SPR_LCAN_ALIEN_SWING2 = 0;
888 int16_t SPR_LCAN_ALIEN_SWING3 = 0;
889 int16_t SPR_LCAN_ALIEN_DEAD = 0;
890 int16_t SPR_LCAN_ALIEN_DIE1 = 0;
891 int16_t SPR_LCAN_ALIEN_DIE2 = 0;
892 int16_t SPR_LCAN_ALIEN_DIE3 = 0;
893 int16_t SPR_LCAN_ALIEN_DIE4 = 0;
894 int16_t SPR_LCAN_ALIEN_OUCH = 0;
895 int16_t SPR_LCAN_ALIEN_SPIT1 = 0;
896 int16_t SPR_LCAN_ALIEN_SPIT2 = 0;
897 int16_t SPR_LCAN_ALIEN_SPIT3 = 0;
898 
899 int16_t SPR_SCAN_ALIEN_READY = 0;
900 int16_t SPR_SCAN_ALIEN_B1 = 0;
901 int16_t SPR_SCAN_ALIEN_B2 = 0;
902 int16_t SPR_SCAN_ALIEN_B3 = 0;
903 int16_t SPR_SCAN_ALIEN_EMPTY = 0;
904 
905 int16_t SPR_SCAN_ALIEN_W1 = 0;
906 int16_t SPR_SCAN_ALIEN_W2 = 0;
907 int16_t SPR_SCAN_ALIEN_W3 = 0;
908 int16_t SPR_SCAN_ALIEN_W4 = 0;
909 int16_t SPR_SCAN_ALIEN_SWING1 = 0;
910 int16_t SPR_SCAN_ALIEN_SWING2 = 0;
911 int16_t SPR_SCAN_ALIEN_SWING3 = 0;
912 int16_t SPR_SCAN_ALIEN_DEAD = 0;
913 int16_t SPR_SCAN_ALIEN_DIE1 = 0;
914 int16_t SPR_SCAN_ALIEN_DIE2 = 0;
915 int16_t SPR_SCAN_ALIEN_DIE3 = 0;
916 int16_t SPR_SCAN_ALIEN_DIE4 = 0;
917 int16_t SPR_SCAN_ALIEN_OUCH = 0;
918 
919 int16_t SPR_SCAN_ALIEN_SPIT1 = 0;
920 int16_t SPR_SCAN_ALIEN_SPIT2 = 0;
921 int16_t SPR_SCAN_ALIEN_SPIT3 = 0;
922 
923 int16_t SPR_GURNEY_MUT_READY = 0;
924 int16_t SPR_GURNEY_MUT_B1 = 0;
925 int16_t SPR_GURNEY_MUT_B2 = 0;
926 int16_t SPR_GURNEY_MUT_B3 = 0;
927 int16_t SPR_GURNEY_MUT_EMPTY = 0;
928 
929 int16_t SPR_GURNEY_MUT_W1 = 0;
930 int16_t SPR_GURNEY_MUT_W2 = 0;
931 int16_t SPR_GURNEY_MUT_W3 = 0;
932 int16_t SPR_GURNEY_MUT_W4 = 0;
933 int16_t SPR_GURNEY_MUT_SWING1 = 0;
934 int16_t SPR_GURNEY_MUT_SWING2 = 0;
935 int16_t SPR_GURNEY_MUT_SWING3 = 0;
936 int16_t SPR_GURNEY_MUT_DEAD = 0;
937 int16_t SPR_GURNEY_MUT_DIE1 = 0;
938 int16_t SPR_GURNEY_MUT_DIE2 = 0;
939 int16_t SPR_GURNEY_MUT_DIE3 = 0;
940 int16_t SPR_GURNEY_MUT_DIE4 = 0;
941 int16_t SPR_GURNEY_MUT_OUCH = 0;
942 
943 int16_t SPR_LIQUID_M1 = 0;
944 int16_t SPR_LIQUID_M2 = 0;
945 int16_t SPR_LIQUID_M3 = 0;
946 int16_t SPR_LIQUID_R1 = 0;
947 int16_t SPR_LIQUID_R2 = 0;
948 int16_t SPR_LIQUID_R3 = 0;
949 int16_t SPR_LIQUID_R4 = 0;
950 int16_t SPR_LIQUID_S1 = 0;
951 int16_t SPR_LIQUID_S2 = 0;
952 int16_t SPR_LIQUID_S3 = 0;
953 int16_t SPR_LIQUID_OUCH = 0;
954 int16_t SPR_LIQUID_DIE_1 = 0;
955 int16_t SPR_LIQUID_DIE_2 = 0;
956 int16_t SPR_LIQUID_DIE_3 = 0;
957 int16_t SPR_LIQUID_DIE_4 = 0;
958 int16_t SPR_LIQUID_DEAD = 0;
959 int16_t SPR_LIQUID_SHOT_FLY_1 = 0;
960 int16_t SPR_LIQUID_SHOT_FLY_2 = 0;
961 int16_t SPR_LIQUID_SHOT_FLY_3 = 0;
962 int16_t SPR_LIQUID_SHOT_BURST_1 = 0;
963 int16_t SPR_LIQUID_SHOT_BURST_2 = 0;
964 int16_t SPR_LIQUID_SHOT_BURST_3 = 0;
965 
966 int16_t SPR_SPIT1_1 = 0;
967 int16_t SPR_SPIT1_2 = 0;
968 int16_t SPR_SPIT1_3 = 0;
969 int16_t SPR_SPIT_EXP1_1 = 0;
970 int16_t SPR_SPIT_EXP1_2 = 0;
971 int16_t SPR_SPIT_EXP1_3 = 0;
972 
973 int16_t SPR_SPIT2_1 = 0;
974 int16_t SPR_SPIT2_2 = 0;
975 int16_t SPR_SPIT2_3 = 0;
976 int16_t SPR_SPIT_EXP2_1 = 0;
977 int16_t SPR_SPIT_EXP2_2 = 0;
978 int16_t SPR_SPIT_EXP2_3 = 0;
979 
980 int16_t SPR_SPIT3_1 = 0;
981 int16_t SPR_SPIT3_2 = 0;
982 int16_t SPR_SPIT3_3 = 0;
983 int16_t SPR_SPIT_EXP3_1 = 0;
984 int16_t SPR_SPIT_EXP3_2 = 0;
985 int16_t SPR_SPIT_EXP3_3 = 0;
986 
987 int16_t SPR_TERROT_1 = 0;
988 int16_t SPR_TERROT_2 = 0;
989 int16_t SPR_TERROT_3 = 0;
990 int16_t SPR_TERROT_4 = 0;
991 int16_t SPR_TERROT_5 = 0;
992 int16_t SPR_TERROT_6 = 0;
993 int16_t SPR_TERROT_7 = 0;
994 int16_t SPR_TERROT_8 = 0;
995 
996 int16_t SPR_TERROT_FIRE_1 = 0;
997 int16_t SPR_TERROT_FIRE_2 = 0;
998 int16_t SPR_TERROT_DIE_1 = 0;
999 int16_t SPR_TERROT_DIE_2 = 0;
1000 int16_t SPR_TERROT_DIE_3 = 0;
1001 int16_t SPR_TERROT_DIE_4 = 0;
1002 int16_t SPR_TERROT_DEAD = 0;
1003 
1004 int16_t SPR_KNIFEREADY = 0;
1005 int16_t SPR_KNIFEATK1 = 0;
1006 int16_t SPR_KNIFEATK2 = 0;
1007 int16_t SPR_KNIFEATK3 = 0;
1008 int16_t SPR_KNIFEATK4 = 0;
1009 
1010 int16_t SPR_PISTOLREADY = 0;
1011 int16_t SPR_PISTOLATK1 = 0;
1012 int16_t SPR_PISTOLATK2 = 0;
1013 int16_t SPR_PISTOLATK3 = 0;
1014 int16_t SPR_PISTOLATK4 = 0;
1015 
1016 int16_t SPR_MACHINEGUNREADY = 0;
1017 int16_t SPR_MACHINEGUNATK1 = 0;
1018 int16_t SPR_MACHINEGUNATK2 = 0;
1019 int16_t SPR_MACHINEGUNATK3 = 0;
1020 int16_t SPR_MACHINEGUNATK4 = 0;
1021 
1022 int16_t SPR_CHAINREADY = 0;
1023 int16_t SPR_CHAINATK1 = 0;
1024 int16_t SPR_CHAINATK2 = 0;
1025 int16_t SPR_CHAINATK3 = 0;
1026 int16_t SPR_CHAINATK4 = 0;
1027 
1028 int16_t SPR_GRENADEREADY = 0;
1029 int16_t SPR_GRENADEATK1 = 0;
1030 int16_t SPR_GRENADEATK2 = 0;
1031 int16_t SPR_GRENADEATK3 = 0;
1032 int16_t SPR_GRENADEATK4 = 0;
1033 
1034 int16_t SPR_GRENADE_FLY1 = 0;
1035 int16_t SPR_GRENADE_FLY2 = 0;
1036 int16_t SPR_GRENADE_FLY3 = 0;
1037 int16_t SPR_GRENADE_FLY4 = 0;
1038 int16_t SPR_GRENADE_EXPLODE1 = 0;
1039 int16_t SPR_GRENADE_EXPLODE2 = 0;
1040 int16_t SPR_GRENADE_EXPLODE3 = 0;
1041 int16_t SPR_GRENADE_EXPLODE4 = 0;
1042 int16_t SPR_GRENADE_EXPLODE5 = 0;
1043 
1044 int16_t SPR_ELEC_ARC1 = 0;
1045 int16_t SPR_ELEC_ARC2 = 0;
1046 int16_t SPR_ELEC_ARC3 = 0;
1047 int16_t SPR_ELEC_ARC4 = 0;
1048 int16_t SPR_ELEC_POST1 = 0;
1049 int16_t SPR_ELEC_POST2 = 0;
1050 int16_t SPR_ELEC_POST3 = 0;
1051 int16_t SPR_ELEC_POST4 = 0;
1052 
1053 int16_t SPR_VPOST1 = 0;
1054 int16_t SPR_VPOST2 = 0;
1055 int16_t SPR_VPOST3 = 0;
1056 int16_t SPR_VPOST4 = 0;
1057 int16_t SPR_VPOST5 = 0;
1058 int16_t SPR_VPOST6 = 0;
1059 int16_t SPR_VPOST7 = 0;
1060 int16_t SPR_VPOST8 = 0;
1061 
1062 int16_t SPR_VSPIKE1 = 0;
1063 int16_t SPR_VSPIKE2 = 0;
1064 int16_t SPR_VSPIKE3 = 0;
1065 int16_t SPR_VSPIKE4 = 0;
1066 int16_t SPR_VSPIKE5 = 0;
1067 int16_t SPR_VSPIKE6 = 0;
1068 int16_t SPR_VSPIKE7 = 0;
1069 int16_t SPR_VSPIKE8 = 0;
1070 
1071 int16_t SPR_GREEN_OOZE1 = 0;
1072 int16_t SPR_GREEN_OOZE2 = 0;
1073 int16_t SPR_GREEN_OOZE3 = 0;
1074 int16_t SPR_BLACK_OOZE1 = 0;
1075 int16_t SPR_BLACK_OOZE2 = 0;
1076 int16_t SPR_BLACK_OOZE3 = 0;
1077 
1078 int16_t SPR_GREEN2_OOZE1 = 0;
1079 int16_t SPR_GREEN2_OOZE2 = 0;
1080 int16_t SPR_GREEN2_OOZE3 = 0;
1081 int16_t SPR_BLACK2_OOZE1 = 0;
1082 int16_t SPR_BLACK2_OOZE2 = 0;
1083 int16_t SPR_BLACK2_OOZE3 = 0;
1084 
1085 int16_t SPR_CANDY_BAR = 0;
1086 int16_t SPR_CANDY_WRAPER = 0;
1087 int16_t SPR_SANDWICH = 0;
1088 int16_t SPR_SANDWICH_WRAPER = 0;
1089 
1090 int16_t SPR_BLAKE_W1 = 0;
1091 int16_t SPR_BLAKE_W2 = 0;
1092 int16_t SPR_BLAKE_W3 = 0;
1093 int16_t SPR_BLAKE_W4 = 0;
1094 
1095 int16_t SPR_BOSS1_W1 = 0;
1096 int16_t SPR_BOSS1_W2 = 0;
1097 int16_t SPR_BOSS1_W3 = 0;
1098 int16_t SPR_BOSS1_W4 = 0;
1099 int16_t SPR_BOSS1_SWING1 = 0;
1100 int16_t SPR_BOSS1_SWING2 = 0;
1101 int16_t SPR_BOSS1_SWING3 = 0;
1102 int16_t SPR_BOSS1_DEAD = 0;
1103 int16_t SPR_BOSS1_DIE1 = 0;
1104 int16_t SPR_BOSS1_DIE2 = 0;
1105 int16_t SPR_BOSS1_DIE3 = 0;
1106 int16_t SPR_BOSS1_DIE4 = 0;
1107 int16_t SPR_BOSS1_OUCH = 0;
1108 int16_t SPR_BOSS1_PROJ1 = 0;
1109 int16_t SPR_BOSS1_PROJ2 = 0;
1110 int16_t SPR_BOSS1_PROJ3 = 0;
1111 int16_t SPR_BOSS1_EXP1 = 0;
1112 int16_t SPR_BOSS1_EXP2 = 0;
1113 int16_t SPR_BOSS1_EXP3 = 0;
1114 int16_t SPR_BOSS1_MORPH1 = 0;
1115 int16_t SPR_BOSS1_MORPH2 = 0;
1116 int16_t SPR_BOSS1_MORPH3 = 0;
1117 int16_t SPR_BOSS1_MORPH4 = 0;
1118 int16_t SPR_BOSS1_MORPH5 = 0;
1119 int16_t SPR_BOSS1_MORPH6 = 0;
1120 int16_t SPR_BOSS1_MORPH7 = 0;
1121 int16_t SPR_BOSS1_MORPH8 = 0;
1122 int16_t SPR_BOSS1_MORPH9 = 0;
1123 
1124 int16_t SPR_BOSS2_W1 = 0;
1125 int16_t SPR_BOSS2_W2 = 0;
1126 int16_t SPR_BOSS2_W3 = 0;
1127 int16_t SPR_BOSS2_W4 = 0;
1128 int16_t SPR_BOSS2_SWING1 = 0;
1129 int16_t SPR_BOSS2_SWING2 = 0;
1130 int16_t SPR_BOSS2_SWING3 = 0;
1131 int16_t SPR_BOSS2_DEAD = 0;
1132 int16_t SPR_BOSS2_DIE1 = 0;
1133 int16_t SPR_BOSS2_DIE2 = 0;
1134 int16_t SPR_BOSS2_DIE3 = 0;
1135 int16_t SPR_BOSS2_DIE4 = 0;
1136 int16_t SPR_BOSS2_OUCH = 0;
1137 
1138 int16_t SPR_BOSS3_W1 = 0;
1139 int16_t SPR_BOSS3_W2 = 0;
1140 int16_t SPR_BOSS3_W3 = 0;
1141 int16_t SPR_BOSS3_W4 = 0;
1142 int16_t SPR_BOSS3_SWING1 = 0;
1143 int16_t SPR_BOSS3_SWING2 = 0;
1144 int16_t SPR_BOSS3_SWING3 = 0;
1145 int16_t SPR_BOSS3_DEAD = 0;
1146 int16_t SPR_BOSS3_DIE1 = 0;
1147 int16_t SPR_BOSS3_DIE2 = 0;
1148 int16_t SPR_BOSS3_DIE3 = 0;
1149 int16_t SPR_BOSS3_DIE4 = 0;
1150 int16_t SPR_BOSS3_OUCH = 0;
1151 
1152 int16_t SPR_BOSS4_W1 = 0;
1153 int16_t SPR_BOSS4_W2 = 0;
1154 int16_t SPR_BOSS4_W3 = 0;
1155 int16_t SPR_BOSS4_W4 = 0;
1156 int16_t SPR_BOSS4_SWING1 = 0;
1157 int16_t SPR_BOSS4_SWING2 = 0;
1158 int16_t SPR_BOSS4_SWING3 = 0;
1159 int16_t SPR_BOSS4_DEAD = 0;
1160 int16_t SPR_BOSS4_DIE1 = 0;
1161 int16_t SPR_BOSS4_DIE2 = 0;
1162 int16_t SPR_BOSS4_DIE3 = 0;
1163 int16_t SPR_BOSS4_DIE4 = 0;
1164 int16_t SPR_BOSS4_OUCH = 0;
1165 int16_t SPR_BOSS4_MORPH1 = 0;
1166 int16_t SPR_BOSS4_MORPH2 = 0;
1167 int16_t SPR_BOSS4_MORPH3 = 0;
1168 int16_t SPR_BOSS4_MORPH4 = 0;
1169 int16_t SPR_BOSS4_MORPH5 = 0;
1170 int16_t SPR_BOSS4_MORPH6 = 0;
1171 int16_t SPR_BOSS4_MORPH7 = 0;
1172 int16_t SPR_BOSS4_MORPH8 = 0;
1173 int16_t SPR_BOSS4_MORPH9 = 0;
1174 
1175 int16_t SPR_BOSS5_W1 = 0;
1176 int16_t SPR_BOSS5_W2 = 0;
1177 int16_t SPR_BOSS5_W3 = 0;
1178 int16_t SPR_BOSS5_W4 = 0;
1179 int16_t SPR_BOSS5_SWING1 = 0;
1180 int16_t SPR_BOSS5_SWING2 = 0;
1181 int16_t SPR_BOSS5_SWING3 = 0;
1182 int16_t SPR_BOSS5_DEAD = 0;
1183 int16_t SPR_BOSS5_DIE1 = 0;
1184 int16_t SPR_BOSS5_DIE2 = 0;
1185 int16_t SPR_BOSS5_DIE3 = 0;
1186 int16_t SPR_BOSS5_DIE4 = 0;
1187 int16_t SPR_BOSS5_OUCH = 0;
1188 int16_t SPR_BOSS5_PROJ1 = 0;
1189 int16_t SPR_BOSS5_PROJ2 = 0;
1190 int16_t SPR_BOSS5_PROJ3 = 0;
1191 int16_t SPR_BOSS5_EXP1 = 0;
1192 int16_t SPR_BOSS5_EXP2 = 0;
1193 int16_t SPR_BOSS5_EXP3 = 0;
1194 
1195 int16_t SPR_BOSS6_W1 = 0;
1196 int16_t SPR_BOSS6_W2 = 0;
1197 int16_t SPR_BOSS6_W3 = 0;
1198 int16_t SPR_BOSS6_W4 = 0;
1199 int16_t SPR_BOSS6_SWING1 = 0;
1200 int16_t SPR_BOSS6_SWING2 = 0;
1201 int16_t SPR_BOSS6_SWING3 = 0;
1202 int16_t SPR_BOSS6_DEAD = 0;
1203 int16_t SPR_BOSS6_DIE1 = 0;
1204 int16_t SPR_BOSS6_DIE2 = 0;
1205 int16_t SPR_BOSS6_DIE3 = 0;
1206 int16_t SPR_BOSS6_DIE4 = 0;
1207 int16_t SPR_BOSS6_OUCH = 0;
1208 
1209 int16_t SPR_BOSS7_W1 = 0;
1210 int16_t SPR_BOSS7_W2 = 0;
1211 int16_t SPR_BOSS7_W3 = 0;
1212 int16_t SPR_BOSS7_W4 = 0;
1213 int16_t SPR_BOSS7_SHOOT1 = 0;
1214 int16_t SPR_BOSS7_SHOOT2 = 0;
1215 int16_t SPR_BOSS7_SHOOT3 = 0;
1216 int16_t SPR_BOSS7_DEAD = 0;
1217 int16_t SPR_BOSS7_DIE1 = 0;
1218 int16_t SPR_BOSS7_DIE2 = 0;
1219 int16_t SPR_BOSS7_DIE3 = 0;
1220 int16_t SPR_BOSS7_DIE4 = 0;
1221 int16_t SPR_BOSS7_OUCH = 0;
1222 
1223 int16_t SPR_BOSS8_W1 = 0;
1224 int16_t SPR_BOSS8_W2 = 0;
1225 int16_t SPR_BOSS8_W3 = 0;
1226 int16_t SPR_BOSS8_W4 = 0;
1227 int16_t SPR_BOSS8_SHOOT1 = 0;
1228 int16_t SPR_BOSS8_SHOOT2 = 0;
1229 int16_t SPR_BOSS8_SHOOT3 = 0;
1230 int16_t SPR_BOSS8_DIE1 = 0;
1231 int16_t SPR_BOSS8_DIE2 = 0;
1232 int16_t SPR_BOSS8_DIE3 = 0;
1233 int16_t SPR_BOSS8_DIE4 = 0;
1234 int16_t SPR_BOSS8_DEAD = 0;
1235 int16_t SPR_BOSS8_OUCH = 0;
1236 
1237 int16_t SPR_BOSS9_W1 = 0;
1238 int16_t SPR_BOSS9_W2 = 0;
1239 int16_t SPR_BOSS9_W3 = 0;
1240 int16_t SPR_BOSS9_W4 = 0;
1241 int16_t SPR_BOSS9_SHOOT1 = 0;
1242 int16_t SPR_BOSS9_SHOOT2 = 0;
1243 int16_t SPR_BOSS9_SHOOT3 = 0;
1244 int16_t SPR_BOSS9_DIE1 = 0;
1245 int16_t SPR_BOSS9_DIE2 = 0;
1246 int16_t SPR_BOSS9_DIE3 = 0;
1247 int16_t SPR_BOSS9_DIE4 = 0;
1248 int16_t SPR_BOSS9_DEAD = 0;
1249 int16_t SPR_BOSS9_OUCH = 0;
1250 
1251 int16_t SPR_BOSS10_W1 = 0;
1252 int16_t SPR_BOSS10_W2 = 0;
1253 int16_t SPR_BOSS10_W3 = 0;
1254 int16_t SPR_BOSS10_W4 = 0;
1255 int16_t SPR_BOSS10_SHOOT1 = 0;
1256 int16_t SPR_BOSS10_SHOOT2 = 0;
1257 int16_t SPR_BOSS10_SHOOT3 = 0;
1258 int16_t SPR_BOSS10_DEAD = 0;
1259 int16_t SPR_BOSS10_DIE1 = 0;
1260 int16_t SPR_BOSS10_DIE2 = 0;
1261 int16_t SPR_BOSS10_DIE3 = 0;
1262 int16_t SPR_BOSS10_DIE4 = 0;
1263 int16_t SPR_BOSS10_OUCH = 0;
1264 
1265 int16_t SPR_BOSS10_SPIT1 = 0;
1266 int16_t SPR_BOSS10_SPIT2 = 0;
1267 int16_t SPR_BOSS10_SPIT3 = 0;
1268 int16_t SPR_BOSS10_SPIT_EXP1 = 0;
1269 int16_t SPR_BOSS10_SPIT_EXP2 = 0;
1270 int16_t SPR_BOSS10_SPIT_EXP3 = 0;
1271 
1272 int16_t SPR_DETONATOR_EXP1 = 0;
1273 int16_t SPR_DETONATOR_EXP2 = 0;
1274 int16_t SPR_DETONATOR_EXP3 = 0;
1275 int16_t SPR_DETONATOR_EXP4 = 0;
1276 int16_t SPR_DETONATOR_EXP5 = 0;
1277 int16_t SPR_DETONATOR_EXP6 = 0;
1278 int16_t SPR_DETONATOR_EXP7 = 0;
1279 int16_t SPR_DETONATOR_EXP8 = 0;
1280 
1281 int16_t SPR_CLIP_EXP1 = 0;
1282 int16_t SPR_CLIP_EXP2 = 0;
1283 int16_t SPR_CLIP_EXP3 = 0;
1284 int16_t SPR_CLIP_EXP4 = 0;
1285 int16_t SPR_CLIP_EXP5 = 0;
1286 int16_t SPR_CLIP_EXP6 = 0;
1287 int16_t SPR_CLIP_EXP7 = 0;
1288 int16_t SPR_CLIP_EXP8 = 0;
1289 
1290 int16_t SPR_BFG_WEAPON1 = 0;
1291 int16_t SPR_BFG_WEAPON2 = 0;
1292 int16_t SPR_BFG_WEAPON3 = 0;
1293 int16_t SPR_BFG_WEAPON4 = 0;
1294 int16_t SPR_BFG_WEAPON5 = 0;
1295 
1296 int16_t SPR_BFG_WEAPON_SHOT1 = 0;
1297 int16_t SPR_BFG_WEAPON_SHOT2 = 0;
1298 int16_t SPR_BFG_WEAPON_SHOT3 = 0;
1299 
1300 int16_t SPR_BFG_EXP1 = 0;
1301 int16_t SPR_BFG_EXP2 = 0;
1302 int16_t SPR_BFG_EXP3 = 0;
1303 int16_t SPR_BFG_EXP4 = 0;
1304 int16_t SPR_BFG_EXP5 = 0;
1305 int16_t SPR_BFG_EXP6 = 0;
1306 int16_t SPR_BFG_EXP7 = 0;
1307 int16_t SPR_BFG_EXP8 = 0;
1308 
1309 
initialize_sprites()1310 void initialize_sprites()
1311 {
1312     if (::is_aog_sw()) {
1313         SPR_STAT_0 = 1;
1314         SPR_STAT_2 = 2;
1315         SPR_STAT_8 = 3;
1316         SPR_STAT_9 = 4;
1317         SPR_STAT_10 = 5;
1318         SPR_STAT_11 = 6;
1319         SPR_STAT_12 = 7;
1320         SPR_STAT_13 = 8;
1321         SPR_STAT_14 = 9;
1322         SPR_STAT_15 = 10;
1323         SPR_STAT_18 = 11;
1324         SPR_STAT_24 = 12;
1325         SPR_STAT_26 = 13;
1326         SPR_STAT_27 = 14;
1327         SPR_STAT_28 = 15;
1328         SPR_STAT_29 = 16;
1329         SPR_STAT_31 = 17;
1330         SPR_STAT_32 = 18;
1331         SPR_STAT_33 = 19;
1332         SPR_STAT_34 = 20;
1333         SPR_STAT_35 = 21;
1334         SPR_STAT_36 = 22;
1335         SPR_STAT_38 = 23;
1336         SPR_STAT_40 = 24;
1337         SPR_STAT_41 = 25;
1338         SPR_STAT_42 = 26;
1339         SPR_STAT_43 = 27;
1340         SPR_STAT_44 = 28;
1341         SPR_STAT_45 = 29;
1342         SPR_STAT_46 = 30;
1343         SPR_STAT_47 = 31;
1344         SPR_STAT_48 = 32;
1345         SPR_STAT_49 = 33;
1346         SPR_STAT_50 = 34;
1347         SPR_STAT_51 = 35;
1348         SPR_STAT_52 = 36;
1349         SPR_STAT_53 = 37;
1350         SPR_STAT_54 = 38;
1351         SPR_STAT_55 = 39;
1352         SPR_STAT_56 = 40;
1353         SPR_CRATE_1 = 41;
1354         SPR_STAT_57 = 42;
1355         SPR_STAT_60 = 43;
1356         SPR_STAT_61 = 44;
1357         SPR_STAT_62 = 45;
1358         SPR_STAT_63 = 46;
1359         SPR_STAT_65 = 47;
1360         SPR_STAT_66 = 48;
1361         SPR_STAT_67 = 49;
1362         SPR_STAT_68 = 50;
1363         SPR_STAT_69 = 51;
1364         SPR_STAT_77 = 52;
1365         SPR_STAT_78 = 53;
1366         SPR_STAT_79 = 54;
1367 
1368         SPR_AIR_VENT = 55;
1369 
1370         SPR_BLOOD_DRIP1 = 56;
1371         SPR_BLOOD_DRIP2 = 57;
1372         SPR_BLOOD_DRIP3 = 58;
1373         SPR_BLOOD_DRIP4 = 59;
1374 
1375         SPR_WATER_DRIP1 = 60;
1376         SPR_WATER_DRIP2 = 61;
1377         SPR_WATER_DRIP3 = 62;
1378         SPR_WATER_DRIP4 = 63;
1379 
1380         SPR_DECO_ARC_1 = 64;
1381         SPR_DECO_ARC_2 = 65;
1382         SPR_DECO_ARC_3 = 66;
1383 
1384         SPR_GRATE = 67;
1385 
1386         SPR_STEAM_1 = 68;
1387         SPR_STEAM_2 = 69;
1388         SPR_STEAM_3 = 70;
1389         SPR_STEAM_4 = 71;
1390         SPR_STEAM_PIPE = 72;
1391         SPR_PIPE_STEAM_1 = 73;
1392         SPR_PIPE_STEAM_2 = 74;
1393         SPR_PIPE_STEAM_3 = 75;
1394         SPR_PIPE_STEAM_4 = 76;
1395 
1396         SPR_RENT_S_1 = 77;
1397         SPR_RENT_S_2 = 78;
1398         SPR_RENT_S_3 = 79;
1399         SPR_RENT_S_4 = 80;
1400         SPR_RENT_S_5 = 81;
1401         SPR_RENT_S_6 = 82;
1402         SPR_RENT_S_7 = 83;
1403         SPR_RENT_S_8 = 84;
1404         SPR_RENT_W1_1 = 85;
1405         SPR_RENT_W1_2 = 86;
1406         SPR_RENT_W1_3 = 87;
1407         SPR_RENT_W1_4 = 88;
1408         SPR_RENT_W1_5 = 89;
1409         SPR_RENT_W1_6 = 90;
1410         SPR_RENT_W1_7 = 91;
1411         SPR_RENT_W1_8 = 92;
1412         SPR_RENT_W2_1 = 93;
1413         SPR_RENT_W2_2 = 94;
1414         SPR_RENT_W2_3 = 95;
1415         SPR_RENT_W2_4 = 96;
1416         SPR_RENT_W2_5 = 97;
1417         SPR_RENT_W2_6 = 98;
1418         SPR_RENT_W2_7 = 99;
1419         SPR_RENT_W2_8 = 100;
1420         SPR_RENT_W3_1 = 101;
1421         SPR_RENT_W3_2 = 102;
1422         SPR_RENT_W3_3 = 103;
1423         SPR_RENT_W3_4 = 104;
1424         SPR_RENT_W3_5 = 105;
1425         SPR_RENT_W3_6 = 106;
1426         SPR_RENT_W3_7 = 107;
1427         SPR_RENT_W3_8 = 108;
1428         SPR_RENT_W4_1 = 109;
1429         SPR_RENT_W4_2 = 110;
1430         SPR_RENT_W4_3 = 111;
1431         SPR_RENT_W4_4 = 112;
1432         SPR_RENT_W4_5 = 113;
1433         SPR_RENT_W4_6 = 114;
1434         SPR_RENT_W4_7 = 115;
1435         SPR_RENT_W4_8 = 116;
1436         SPR_RENT_DIE_1 = 117;
1437         SPR_RENT_DIE_2 = 118;
1438         SPR_RENT_DIE_3 = 119;
1439         SPR_RENT_DIE_4 = 120;
1440         SPR_RENT_PAIN_1 = 121;
1441         SPR_RENT_DEAD = 122;
1442         SPR_RENT_SHOOT1 = 123;
1443         SPR_RENT_SHOOT2 = 124;
1444         SPR_RENT_SHOOT3 = 125;
1445 
1446         SPR_PRO_S_1 = 126;
1447         SPR_PRO_S_2 = 127;
1448         SPR_PRO_S_3 = 128;
1449         SPR_PRO_S_4 = 129;
1450         SPR_PRO_S_5 = 130;
1451         SPR_PRO_S_6 = 131;
1452         SPR_PRO_S_7 = 132;
1453         SPR_PRO_S_8 = 133;
1454         SPR_PRO_W1_1 = 134;
1455         SPR_PRO_W1_2 = 135;
1456         SPR_PRO_W1_3 = 136;
1457         SPR_PRO_W1_4 = 137;
1458         SPR_PRO_W1_5 = 138;
1459         SPR_PRO_W1_6 = 139;
1460         SPR_PRO_W1_7 = 140;
1461         SPR_PRO_W1_8 = 141;
1462         SPR_PRO_W2_1 = 142;
1463         SPR_PRO_W2_2 = 143;
1464         SPR_PRO_W2_3 = 144;
1465         SPR_PRO_W2_4 = 145;
1466         SPR_PRO_W2_5 = 146;
1467         SPR_PRO_W2_6 = 147;
1468         SPR_PRO_W2_7 = 148;
1469         SPR_PRO_W2_8 = 149;
1470         SPR_PRO_W3_1 = 150;
1471         SPR_PRO_W3_2 = 151;
1472         SPR_PRO_W3_3 = 152;
1473         SPR_PRO_W3_4 = 153;
1474         SPR_PRO_W3_5 = 154;
1475         SPR_PRO_W3_6 = 155;
1476         SPR_PRO_W3_7 = 156;
1477         SPR_PRO_W3_8 = 157;
1478         SPR_PRO_W4_1 = 158;
1479         SPR_PRO_W4_2 = 159;
1480         SPR_PRO_W4_3 = 160;
1481         SPR_PRO_W4_4 = 161;
1482         SPR_PRO_W4_5 = 162;
1483         SPR_PRO_W4_6 = 163;
1484         SPR_PRO_W4_7 = 164;
1485         SPR_PRO_W4_8 = 165;
1486         SPR_PRO_PAIN_1 = 166;
1487         SPR_PRO_DIE_1 = 167;
1488         SPR_PRO_DIE_2 = 168;
1489         SPR_PRO_DIE_3 = 169;
1490         SPR_PRO_PAIN_2 = 170;
1491         SPR_PRO_DIE_4 = 171;
1492         SPR_PRO_DEAD = 172;
1493         SPR_PRO_SHOOT1 = 173;
1494         SPR_PRO_SHOOT2 = 174;
1495         SPR_PRO_SHOOT3 = 175;
1496 
1497         SPR_SWAT_S_1 = 176;
1498         SPR_SWAT_S_2 = 177;
1499         SPR_SWAT_S_3 = 178;
1500         SPR_SWAT_S_4 = 179;
1501         SPR_SWAT_S_5 = 180;
1502         SPR_SWAT_S_6 = 181;
1503         SPR_SWAT_S_7 = 182;
1504         SPR_SWAT_S_8 = 183;
1505         SPR_SWAT_W1_1 = 184;
1506         SPR_SWAT_W1_2 = 185;
1507         SPR_SWAT_W1_3 = 186;
1508         SPR_SWAT_W1_4 = 187;
1509         SPR_SWAT_W1_5 = 188;
1510         SPR_SWAT_W1_6 = 189;
1511         SPR_SWAT_W1_7 = 190;
1512         SPR_SWAT_W1_8 = 191;
1513         SPR_SWAT_W2_1 = 192;
1514         SPR_SWAT_W2_2 = 193;
1515         SPR_SWAT_W2_3 = 194;
1516         SPR_SWAT_W2_4 = 195;
1517         SPR_SWAT_W2_5 = 196;
1518         SPR_SWAT_W2_6 = 197;
1519         SPR_SWAT_W2_7 = 198;
1520         SPR_SWAT_W2_8 = 199;
1521         SPR_SWAT_W3_1 = 200;
1522         SPR_SWAT_W3_2 = 201;
1523         SPR_SWAT_W3_3 = 202;
1524         SPR_SWAT_W3_4 = 203;
1525         SPR_SWAT_W3_5 = 204;
1526         SPR_SWAT_W3_6 = 205;
1527         SPR_SWAT_W3_7 = 206;
1528         SPR_SWAT_W3_8 = 207;
1529         SPR_SWAT_W4_1 = 208;
1530         SPR_SWAT_W4_2 = 209;
1531         SPR_SWAT_W4_3 = 210;
1532         SPR_SWAT_W4_4 = 211;
1533         SPR_SWAT_W4_5 = 212;
1534         SPR_SWAT_W4_6 = 213;
1535         SPR_SWAT_W4_7 = 214;
1536         SPR_SWAT_W4_8 = 215;
1537         SPR_SWAT_PAIN_1 = 216;
1538         SPR_SWAT_DIE_1 = 217;
1539         SPR_SWAT_DIE_2 = 218;
1540         SPR_SWAT_DIE_3 = 219;
1541         SPR_SWAT_PAIN_2 = 220;
1542         SPR_SWAT_DIE_4 = 221;
1543         SPR_SWAT_DEAD = 222;
1544         SPR_SWAT_SHOOT1 = 223;
1545         SPR_SWAT_SHOOT2 = 224;
1546         SPR_SWAT_SHOOT3 = 225;
1547         SPR_SWAT_WOUNDED1 = 226;
1548         SPR_SWAT_WOUNDED2 = 227;
1549         SPR_SWAT_WOUNDED3 = 228;
1550         SPR_SWAT_WOUNDED4 = 229;
1551 
1552         SPR_OFC_S_1 = 230;
1553         SPR_OFC_S_2 = 231;
1554         SPR_OFC_S_3 = 232;
1555         SPR_OFC_S_4 = 233;
1556         SPR_OFC_S_5 = 234;
1557         SPR_OFC_S_6 = 235;
1558         SPR_OFC_S_7 = 236;
1559         SPR_OFC_S_8 = 237;
1560         SPR_OFC_W1_1 = 238;
1561         SPR_OFC_W1_2 = 239;
1562         SPR_OFC_W1_3 = 240;
1563         SPR_OFC_W1_4 = 241;
1564         SPR_OFC_W1_5 = 242;
1565         SPR_OFC_W1_6 = 243;
1566         SPR_OFC_W1_7 = 244;
1567         SPR_OFC_W1_8 = 245;
1568         SPR_OFC_W2_1 = 246;
1569         SPR_OFC_W2_2 = 247;
1570         SPR_OFC_W2_3 = 248;
1571         SPR_OFC_W2_4 = 249;
1572         SPR_OFC_W2_5 = 250;
1573         SPR_OFC_W2_6 = 251;
1574         SPR_OFC_W2_7 = 252;
1575         SPR_OFC_W2_8 = 253;
1576         SPR_OFC_W3_1 = 254;
1577         SPR_OFC_W3_2 = 255;
1578         SPR_OFC_W3_3 = 256;
1579         SPR_OFC_W3_4 = 257;
1580         SPR_OFC_W3_5 = 258;
1581         SPR_OFC_W3_6 = 259;
1582         SPR_OFC_W3_7 = 260;
1583         SPR_OFC_W3_8 = 261;
1584         SPR_OFC_W4_1 = 262;
1585         SPR_OFC_W4_2 = 263;
1586         SPR_OFC_W4_3 = 264;
1587         SPR_OFC_W4_4 = 265;
1588         SPR_OFC_W4_5 = 266;
1589         SPR_OFC_W4_6 = 267;
1590         SPR_OFC_W4_7 = 268;
1591         SPR_OFC_W4_8 = 269;
1592         SPR_OFC_PAIN_1 = 270;
1593         SPR_OFC_DIE_1 = 271;
1594         SPR_OFC_DIE_2 = 272;
1595         SPR_OFC_DIE_3 = 273;
1596         SPR_OFC_PAIN_2 = 274;
1597         SPR_OFC_DIE_4 = 275;
1598         SPR_OFC_DEAD = 276;
1599         SPR_OFC_SHOOT1 = 277;
1600         SPR_OFC_SHOOT2 = 278;
1601         SPR_OFC_SHOOT3 = 279;
1602 
1603         SPR_GOLD_S_1 = 280;
1604         SPR_GOLD_S_2 = 281;
1605         SPR_GOLD_S_3 = 282;
1606         SPR_GOLD_S_4 = 283;
1607         SPR_GOLD_S_5 = 284;
1608         SPR_GOLD_S_6 = 285;
1609         SPR_GOLD_S_7 = 286;
1610         SPR_GOLD_S_8 = 287;
1611         SPR_GOLD_W1_1 = 288;
1612         SPR_GOLD_W1_2 = 289;
1613         SPR_GOLD_W1_3 = 290;
1614         SPR_GOLD_W1_4 = 291;
1615         SPR_GOLD_W1_5 = 292;
1616         SPR_GOLD_W1_6 = 293;
1617         SPR_GOLD_W1_7 = 294;
1618         SPR_GOLD_W1_8 = 295;
1619         SPR_GOLD_W2_1 = 296;
1620         SPR_GOLD_W2_2 = 297;
1621         SPR_GOLD_W2_3 = 298;
1622         SPR_GOLD_W2_4 = 299;
1623         SPR_GOLD_W2_5 = 300;
1624         SPR_GOLD_W2_6 = 301;
1625         SPR_GOLD_W2_7 = 302;
1626         SPR_GOLD_W2_8 = 303;
1627         SPR_GOLD_W3_1 = 304;
1628         SPR_GOLD_W3_2 = 305;
1629         SPR_GOLD_W3_3 = 306;
1630         SPR_GOLD_W3_4 = 307;
1631         SPR_GOLD_W3_5 = 308;
1632         SPR_GOLD_W3_6 = 309;
1633         SPR_GOLD_W3_7 = 310;
1634         SPR_GOLD_W3_8 = 311;
1635         SPR_GOLD_W4_1 = 312;
1636         SPR_GOLD_W4_2 = 313;
1637         SPR_GOLD_W4_3 = 314;
1638         SPR_GOLD_W4_4 = 315;
1639         SPR_GOLD_W4_5 = 316;
1640         SPR_GOLD_W4_6 = 317;
1641         SPR_GOLD_W4_7 = 318;
1642         SPR_GOLD_W4_8 = 319;
1643         SPR_GOLD_PAIN_1 = 320;
1644         SPR_GOLD_WRIST_1 = 321;
1645         SPR_GOLD_WRIST_2 = 322;
1646         SPR_GOLD_SHOOT1 = 323;
1647         SPR_GOLD_SHOOT2 = 324;
1648         SPR_GOLD_SHOOT3 = 325;
1649         SPR_GOLD_WARP1 = 326;
1650         SPR_GOLD_WARP2 = 327;
1651         SPR_GOLD_WARP3 = 328;
1652         SPR_GOLD_WARP4 = 329;
1653         SPR_GOLD_WARP5 = 330;
1654 
1655         SPR_FSCOUT_W1_1 = 331;
1656         SPR_FSCOUT_W1_2 = 332;
1657         SPR_FSCOUT_W1_3 = 333;
1658         SPR_FSCOUT_W1_4 = 334;
1659         SPR_FSCOUT_W1_5 = 335;
1660         SPR_FSCOUT_W1_6 = 336;
1661         SPR_FSCOUT_W1_7 = 337;
1662         SPR_FSCOUT_W1_8 = 338;
1663         SPR_FSCOUT_DIE1 = 339;
1664         SPR_FSCOUT_DIE2 = 340;
1665         SPR_FSCOUT_DIE3 = 341;
1666         SPR_FSCOUT_DIE4 = 342;
1667         SPR_FSCOUT_DIE5 = 343;
1668         SPR_FSCOUT_DIE6 = 344;
1669         SPR_FSCOUT_DIE7 = 345;
1670         SPR_FSCOUT_DEAD = 346;
1671 
1672         SPR_EXPLOSION_1 = 347;
1673         SPR_EXPLOSION_2 = 348;
1674         SPR_EXPLOSION_3 = 349;
1675         SPR_EXPLOSION_4 = 350;
1676         SPR_EXPLOSION_5 = 351;
1677 
1678         SPR_SECURITY_NORMAL = 352;
1679         SPR_SECURITY_ALERT = 353;
1680 
1681         SPR_POD_EGG = 354;
1682         SPR_POD_HATCH1 = 355;
1683         SPR_POD_HATCH2 = 356;
1684         SPR_POD_HATCH3 = 357;
1685         SPR_POD_WALK1 = 358;
1686         SPR_POD_WALK2 = 359;
1687         SPR_POD_WALK3 = 360;
1688         SPR_POD_WALK4 = 361;
1689         SPR_POD_ATTACK1 = 362;
1690         SPR_POD_ATTACK2 = 363;
1691         SPR_POD_ATTACK3 = 364;
1692         SPR_POD_OUCH = 365;
1693         SPR_POD_DIE1 = 366;
1694         SPR_POD_DIE2 = 367;
1695         SPR_POD_DIE3 = 368;
1696         SPR_POD_SPIT1 = 369;
1697         SPR_POD_SPIT2 = 370;
1698         SPR_POD_SPIT3 = 371;
1699 
1700         SPR_ELEC_APPEAR1 = 372;
1701         SPR_ELEC_APPEAR2 = 373;
1702         SPR_ELEC_APPEAR3 = 374;
1703         SPR_ELEC_WALK1 = 375;
1704         SPR_ELEC_WALK2 = 376;
1705         SPR_ELEC_WALK3 = 377;
1706         SPR_ELEC_WALK4 = 378;
1707         SPR_ELEC_OUCH = 379;
1708         SPR_ELEC_SHOOT1 = 380;
1709         SPR_ELEC_SHOOT2 = 381;
1710         SPR_ELEC_SHOOT3 = 382;
1711         SPR_ELEC_DIE1 = 383;
1712         SPR_ELEC_DIE2 = 384;
1713         SPR_ELEC_DIE3 = 385;
1714         SPR_ELEC_SHOT1 = 386;
1715         SPR_ELEC_SHOT2 = 387;
1716         SPR_ELEC_SHOT_EXP1 = 388;
1717         SPR_ELEC_SHOT_EXP2 = 389;
1718 
1719         SPR_ELECTRO_SPHERE_ROAM1 = 390;
1720         SPR_ELECTRO_SPHERE_ROAM2 = 391;
1721         SPR_ELECTRO_SPHERE_ROAM3 = 392;
1722         SPR_ELECTRO_SPHERE_OUCH = 393;
1723         SPR_ELECTRO_SPHERE_DIE1 = 394;
1724         SPR_ELECTRO_SPHERE_DIE2 = 395;
1725         SPR_ELECTRO_SPHERE_DIE3 = 396;
1726         SPR_ELECTRO_SPHERE_DIE4 = 397;
1727 
1728         SPR_GENETIC_W1 = 398;
1729         SPR_GENETIC_W2 = 399;
1730         SPR_GENETIC_W3 = 400;
1731         SPR_GENETIC_W4 = 401;
1732         SPR_GENETIC_SWING1 = 402;
1733         SPR_GENETIC_SWING2 = 403;
1734         SPR_GENETIC_SWING3 = 404;
1735         SPR_GENETIC_DEAD = 405;
1736         SPR_GENETIC_DIE1 = 406;
1737         SPR_GENETIC_DIE2 = 407;
1738         SPR_GENETIC_DIE3 = 408;
1739         SPR_GENETIC_DIE4 = 409;
1740         SPR_GENETIC_OUCH = 410;
1741         SPR_GENETIC_SHOOT1 = 411;
1742         SPR_GENETIC_SHOOT2 = 412;
1743         SPR_GENETIC_SHOOT3 = 413;
1744 
1745         SPR_MUTHUM1_W1 = 414;
1746         SPR_MUTHUM1_W2 = 415;
1747         SPR_MUTHUM1_W3 = 416;
1748         SPR_MUTHUM1_W4 = 417;
1749         SPR_MUTHUM1_SWING1 = 418;
1750         SPR_MUTHUM1_SWING2 = 419;
1751         SPR_MUTHUM1_SWING3 = 420;
1752         SPR_MUTHUM1_DEAD = 421;
1753         SPR_MUTHUM1_DIE1 = 422;
1754         SPR_MUTHUM1_DIE2 = 423;
1755         SPR_MUTHUM1_DIE3 = 424;
1756         SPR_MUTHUM1_DIE4 = 425;
1757         SPR_MUTHUM1_OUCH = 426;
1758         SPR_MUTHUM1_SPIT1 = 427;
1759         SPR_MUTHUM1_SPIT2 = 428;
1760         SPR_MUTHUM1_SPIT3 = 429;
1761 
1762         SPR_SCAN_ALIEN_READY = 430;
1763         SPR_SCAN_ALIEN_B1 = 431;
1764         SPR_SCAN_ALIEN_B2 = 432;
1765         SPR_SCAN_ALIEN_B3 = 433;
1766         SPR_SCAN_ALIEN_EMPTY = 434;
1767         SPR_SCAN_ALIEN_W1 = 435;
1768         SPR_SCAN_ALIEN_W2 = 436;
1769         SPR_SCAN_ALIEN_W3 = 437;
1770         SPR_SCAN_ALIEN_W4 = 438;
1771         SPR_SCAN_ALIEN_SWING1 = 439;
1772         SPR_SCAN_ALIEN_SWING2 = 440;
1773         SPR_SCAN_ALIEN_SWING3 = 441;
1774         SPR_SCAN_ALIEN_DEAD = 442;
1775         SPR_SCAN_ALIEN_DIE1 = 443;
1776         SPR_SCAN_ALIEN_DIE2 = 444;
1777         SPR_SCAN_ALIEN_DIE3 = 445;
1778         SPR_SCAN_ALIEN_DIE4 = 446;
1779         SPR_SCAN_ALIEN_OUCH = 447;
1780         SPR_SCAN_ALIEN_SPIT1 = 448;
1781         SPR_SCAN_ALIEN_SPIT2 = 449;
1782         SPR_SCAN_ALIEN_SPIT3 = 450;
1783 
1784         SPR_SPIT1_1 = 451;
1785         SPR_SPIT1_2 = 452;
1786         SPR_SPIT1_3 = 453;
1787         SPR_SPIT_EXP1_1 = 454;
1788         SPR_SPIT_EXP1_2 = 455;
1789         SPR_SPIT_EXP1_3 = 456;
1790 
1791         SPR_SPIT2_1 = 457;
1792         SPR_SPIT2_2 = 458;
1793         SPR_SPIT2_3 = 459;
1794         SPR_SPIT_EXP2_1 = 460;
1795         SPR_SPIT_EXP2_2 = 461;
1796         SPR_SPIT_EXP2_3 = 462;
1797 
1798         SPR_SPIT3_1 = 463;
1799         SPR_SPIT3_2 = 464;
1800         SPR_SPIT3_3 = 465;
1801         SPR_SPIT_EXP3_1 = 466;
1802         SPR_SPIT_EXP3_2 = 467;
1803         SPR_SPIT_EXP3_3 = 468;
1804 
1805         SPR_TERROT_1 = 469;
1806         SPR_TERROT_2 = 470;
1807         SPR_TERROT_3 = 471;
1808         SPR_TERROT_4 = 472;
1809         SPR_TERROT_5 = 473;
1810         SPR_TERROT_6 = 474;
1811         SPR_TERROT_7 = 475;
1812         SPR_TERROT_8 = 476;
1813         SPR_TERROT_FIRE_1 = 477;
1814         SPR_TERROT_FIRE_2 = 478;
1815         SPR_TERROT_DIE_1 = 479;
1816         SPR_TERROT_DIE_2 = 480;
1817         SPR_TERROT_DIE_3 = 481;
1818         SPR_TERROT_DIE_4 = 482;
1819         SPR_TERROT_DEAD = 483;
1820 
1821         SPR_KNIFEREADY = 484;
1822         SPR_KNIFEATK1 = 485;
1823         SPR_KNIFEATK2 = 486;
1824         SPR_KNIFEATK3 = 487;
1825         SPR_KNIFEATK4 = 488;
1826 
1827         SPR_PISTOLREADY = 489;
1828         SPR_PISTOLATK1 = 490;
1829         SPR_PISTOLATK2 = 491;
1830         SPR_PISTOLATK3 = 492;
1831         SPR_PISTOLATK4 = 493;
1832 
1833         SPR_MACHINEGUNREADY = 494;
1834         SPR_MACHINEGUNATK1 = 495;
1835         SPR_MACHINEGUNATK2 = 496;
1836         SPR_MACHINEGUNATK3 = 497;
1837         SPR_MACHINEGUNATK4 = 498;
1838 
1839         SPR_CHAINREADY = 499;
1840         SPR_CHAINATK1 = 500;
1841         SPR_CHAINATK2 = 501;
1842         SPR_CHAINATK3 = 502;
1843         SPR_CHAINATK4 = 503;
1844 
1845         SPR_GRENADEREADY = 504;
1846         SPR_GRENADEATK1 = 505;
1847         SPR_GRENADEATK2 = 506;
1848         SPR_GRENADEATK3 = 507;
1849         SPR_GRENADEATK4 = 508;
1850         SPR_GRENADE_FLY1 = 509;
1851         SPR_GRENADE_FLY2 = 510;
1852         SPR_GRENADE_FLY3 = 511;
1853         SPR_GRENADE_FLY4 = 512;
1854         SPR_GRENADE_EXPLODE1 = 513;
1855         SPR_GRENADE_EXPLODE2 = 514;
1856         SPR_GRENADE_EXPLODE3 = 515;
1857         SPR_GRENADE_EXPLODE4 = 516;
1858         SPR_GRENADE_EXPLODE5 = 517;
1859 
1860         SPR_ELEC_ARC1 = 518;
1861         SPR_ELEC_ARC2 = 519;
1862         SPR_ELEC_ARC3 = 520;
1863         SPR_ELEC_ARC4 = 521;
1864         SPR_ELEC_POST1 = 522;
1865         SPR_ELEC_POST2 = 523;
1866         SPR_ELEC_POST3 = 524;
1867         SPR_ELEC_POST4 = 525;
1868 
1869         SPR_CANDY_BAR = 526;
1870         SPR_CANDY_WRAPER = 527;
1871 
1872         SPR_SANDWICH = 528;
1873         SPR_SANDWICH_WRAPER = 529;
1874 
1875         SPR_BLAKE_W1 = 530;
1876         SPR_BLAKE_W2 = 531;
1877         SPR_BLAKE_W3 = 532;
1878         SPR_BLAKE_W4 = 533;
1879 
1880         SPR_BOSS1_W1 = 534;
1881         SPR_BOSS1_W2 = 535;
1882         SPR_BOSS1_W3 = 536;
1883         SPR_BOSS1_W4 = 537;
1884         SPR_BOSS1_SWING1 = 538;
1885         SPR_BOSS1_SWING2 = 539;
1886         SPR_BOSS1_SWING3 = 540;
1887         SPR_BOSS1_DEAD = 541;
1888         SPR_BOSS1_DIE1 = 542;
1889         SPR_BOSS1_DIE2 = 543;
1890         SPR_BOSS1_DIE3 = 544;
1891         SPR_BOSS1_DIE4 = 545;
1892         SPR_BOSS1_OUCH = 546;
1893         SPR_BOSS1_PROJ1 = 547;
1894         SPR_BOSS1_PROJ2 = 548;
1895         SPR_BOSS1_PROJ3 = 549;
1896         SPR_BOSS1_EXP1 = 550;
1897         SPR_BOSS1_EXP2 = 551;
1898         SPR_BOSS1_EXP3 = 552;
1899     } else if (::is_aog_full()) {
1900         SPR_STAT_0 = 1;
1901         SPR_STAT_1 = 2;
1902         SPR_STAT_2 = 3;
1903         SPR_STAT_3 = 4;
1904         SPR_STAT_4 = 5;
1905         SPR_STAT_5 = 6;
1906         SPR_STAT_6 = 7;
1907         SPR_STAT_7 = 8;
1908         SPR_STAT_8 = 9;
1909         SPR_STAT_9 = 10;
1910         SPR_STAT_10 = 11;
1911         SPR_STAT_11 = 12;
1912         SPR_STAT_12 = 13;
1913         SPR_STAT_13 = 14;
1914         SPR_STAT_14 = 15;
1915         SPR_STAT_15 = 16;
1916         SPR_STAT_16 = 17;
1917         SPR_STAT_17 = 18;
1918         SPR_STAT_18 = 19;
1919         SPR_STAT_19 = 20;
1920         SPR_STAT_20 = 21;
1921         SPR_STAT_21 = 22;
1922         SPR_STAT_22 = 23;
1923         SPR_STAT_23 = 24;
1924         SPR_STAT_24 = 25;
1925         SPR_STAT_25 = 26;
1926         SPR_STAT_26 = 27;
1927         SPR_STAT_27 = 28;
1928         SPR_STAT_28 = 29;
1929         SPR_STAT_29 = 30;
1930         SPR_STAT_30 = 31;
1931         SPR_STAT_31 = 32;
1932         SPR_STAT_32 = 33;
1933         SPR_STAT_33 = 34;
1934         SPR_STAT_34 = 35;
1935         SPR_STAT_35 = 36;
1936         SPR_STAT_36 = 37;
1937         SPR_STAT_37 = 38;
1938         SPR_STAT_38 = 39;
1939         SPR_STAT_39 = 40;
1940         SPR_STAT_40 = 41;
1941         SPR_STAT_41 = 42;
1942         SPR_STAT_42 = 43;
1943         SPR_STAT_43 = 44;
1944         SPR_STAT_44 = 45;
1945         SPR_STAT_45 = 46;
1946         SPR_STAT_46 = 47;
1947         SPR_STAT_47 = 48;
1948         SPR_STAT_48 = 49;
1949         SPR_STAT_49 = 50;
1950         SPR_STAT_50 = 51;
1951         SPR_STAT_51 = 52;
1952         SPR_STAT_52 = 53;
1953         SPR_STAT_53 = 54;
1954         SPR_STAT_54 = 55;
1955         SPR_STAT_55 = 56;
1956         SPR_STAT_56 = 57;
1957 
1958         SPR_CRATE_1 = 58;
1959         SPR_CRATE_2 = 59;
1960         SPR_CRATE_3 = 60;
1961 
1962         SPR_STAT_57 = 61;
1963         SPR_STAT_58 = 62;
1964         SPR_STAT_59 = 63;
1965         SPR_STAT_60 = 64;
1966         SPR_STAT_61 = 65;
1967         SPR_STAT_62 = 66;
1968         SPR_STAT_63 = 67;
1969         SPR_STAT_64 = 68;
1970         SPR_STAT_65 = 69;
1971         SPR_STAT_66 = 70;
1972         SPR_STAT_67 = 71;
1973         SPR_STAT_68 = 72;
1974         SPR_STAT_69 = 73;
1975         SPR_STAT_70 = 74;
1976         SPR_STAT_71 = 75;
1977         SPR_STAT_72 = 76;
1978         SPR_STAT_73 = 77;
1979         SPR_STAT_74 = 78;
1980         SPR_STAT_75 = 79;
1981         SPR_STAT_76 = 80;
1982         SPR_STAT_77 = 81;
1983         SPR_STAT_78 = 82;
1984         SPR_STAT_79 = 83;
1985 
1986         SPR_AIR_VENT = 84;
1987 
1988         SPR_BLOOD_DRIP1 = 85;
1989         SPR_BLOOD_DRIP2 = 86;
1990         SPR_BLOOD_DRIP3 = 87;
1991         SPR_BLOOD_DRIP4 = 88;
1992 
1993         SPR_WATER_DRIP1 = 89;
1994         SPR_WATER_DRIP2 = 90;
1995         SPR_WATER_DRIP3 = 91;
1996         SPR_WATER_DRIP4 = 92;
1997 
1998         SPR_DECO_ARC_1 = 93;
1999         SPR_DECO_ARC_2 = 94;
2000         SPR_DECO_ARC_3 = 95;
2001 
2002         SPR_GRATE = 96;
2003 
2004         SPR_STEAM_1 = 97;
2005         SPR_STEAM_2 = 98;
2006         SPR_STEAM_3 = 99;
2007         SPR_STEAM_4 = 100;
2008         SPR_STEAM_PIPE = 101;
2009         SPR_PIPE_STEAM_1 = 102;
2010         SPR_PIPE_STEAM_2 = 103;
2011         SPR_PIPE_STEAM_3 = 104;
2012         SPR_PIPE_STEAM_4 = 105;
2013 
2014         SPR_RENT_S_1 = 106;
2015         SPR_RENT_S_2 = 107;
2016         SPR_RENT_S_3 = 108;
2017         SPR_RENT_S_4 = 109;
2018         SPR_RENT_S_5 = 110;
2019         SPR_RENT_S_6 = 111;
2020         SPR_RENT_S_7 = 112;
2021         SPR_RENT_S_8 = 113;
2022         SPR_RENT_W1_1 = 114;
2023         SPR_RENT_W1_2 = 115;
2024         SPR_RENT_W1_3 = 116;
2025         SPR_RENT_W1_4 = 117;
2026         SPR_RENT_W1_5 = 118;
2027         SPR_RENT_W1_6 = 119;
2028         SPR_RENT_W1_7 = 120;
2029         SPR_RENT_W1_8 = 121;
2030         SPR_RENT_W2_1 = 122;
2031         SPR_RENT_W2_2 = 123;
2032         SPR_RENT_W2_3 = 124;
2033         SPR_RENT_W2_4 = 125;
2034         SPR_RENT_W2_5 = 126;
2035         SPR_RENT_W2_6 = 127;
2036         SPR_RENT_W2_7 = 128;
2037         SPR_RENT_W2_8 = 129;
2038         SPR_RENT_W3_1 = 130;
2039         SPR_RENT_W3_2 = 131;
2040         SPR_RENT_W3_3 = 132;
2041         SPR_RENT_W3_4 = 133;
2042         SPR_RENT_W3_5 = 134;
2043         SPR_RENT_W3_6 = 135;
2044         SPR_RENT_W3_7 = 136;
2045         SPR_RENT_W3_8 = 137;
2046         SPR_RENT_W4_1 = 138;
2047         SPR_RENT_W4_2 = 139;
2048         SPR_RENT_W4_3 = 140;
2049         SPR_RENT_W4_4 = 141;
2050         SPR_RENT_W4_5 = 142;
2051         SPR_RENT_W4_6 = 143;
2052         SPR_RENT_W4_7 = 144;
2053         SPR_RENT_W4_8 = 145;
2054         SPR_RENT_DIE_1 = 146;
2055         SPR_RENT_DIE_2 = 147;
2056         SPR_RENT_DIE_3 = 148;
2057         SPR_RENT_DIE_4 = 149;
2058         SPR_RENT_PAIN_1 = 150;
2059         SPR_RENT_DEAD = 151;
2060         SPR_RENT_SHOOT1 = 152;
2061         SPR_RENT_SHOOT2 = 153;
2062         SPR_RENT_SHOOT3 = 154;
2063 
2064         SPR_PRO_S_1 = 155;
2065         SPR_PRO_S_2 = 156;
2066         SPR_PRO_S_3 = 157;
2067         SPR_PRO_S_4 = 158;
2068         SPR_PRO_S_5 = 159;
2069         SPR_PRO_S_6 = 160;
2070         SPR_PRO_S_7 = 161;
2071         SPR_PRO_S_8 = 162;
2072         SPR_PRO_W1_1 = 163;
2073         SPR_PRO_W1_2 = 164;
2074         SPR_PRO_W1_3 = 165;
2075         SPR_PRO_W1_4 = 166;
2076         SPR_PRO_W1_5 = 167;
2077         SPR_PRO_W1_6 = 168;
2078         SPR_PRO_W1_7 = 169;
2079         SPR_PRO_W1_8 = 170;
2080         SPR_PRO_W2_1 = 171;
2081         SPR_PRO_W2_2 = 172;
2082         SPR_PRO_W2_3 = 173;
2083         SPR_PRO_W2_4 = 174;
2084         SPR_PRO_W2_5 = 175;
2085         SPR_PRO_W2_6 = 176;
2086         SPR_PRO_W2_7 = 177;
2087         SPR_PRO_W2_8 = 178;
2088         SPR_PRO_W3_1 = 179;
2089         SPR_PRO_W3_2 = 180;
2090         SPR_PRO_W3_3 = 181;
2091         SPR_PRO_W3_4 = 182;
2092         SPR_PRO_W3_5 = 183;
2093         SPR_PRO_W3_6 = 184;
2094         SPR_PRO_W3_7 = 185;
2095         SPR_PRO_W3_8 = 186;
2096         SPR_PRO_W4_1 = 187;
2097         SPR_PRO_W4_2 = 188;
2098         SPR_PRO_W4_3 = 189;
2099         SPR_PRO_W4_4 = 190;
2100         SPR_PRO_W4_5 = 191;
2101         SPR_PRO_W4_6 = 192;
2102         SPR_PRO_W4_7 = 193;
2103         SPR_PRO_W4_8 = 194;
2104         SPR_PRO_PAIN_1 = 195;
2105         SPR_PRO_DIE_1 = 196;
2106         SPR_PRO_DIE_2 = 197;
2107         SPR_PRO_DIE_3 = 198;
2108         SPR_PRO_PAIN_2 = 199;
2109         SPR_PRO_DIE_4 = 200;
2110         SPR_PRO_DEAD = 201;
2111         SPR_PRO_SHOOT1 = 202;
2112         SPR_PRO_SHOOT2 = 203;
2113         SPR_PRO_SHOOT3 = 204;
2114 
2115         SPR_SWAT_S_1 = 205;
2116         SPR_SWAT_S_2 = 206;
2117         SPR_SWAT_S_3 = 207;
2118         SPR_SWAT_S_4 = 208;
2119         SPR_SWAT_S_5 = 209;
2120         SPR_SWAT_S_6 = 210;
2121         SPR_SWAT_S_7 = 211;
2122         SPR_SWAT_S_8 = 212;
2123         SPR_SWAT_W1_1 = 213;
2124         SPR_SWAT_W1_2 = 214;
2125         SPR_SWAT_W1_3 = 215;
2126         SPR_SWAT_W1_4 = 216;
2127         SPR_SWAT_W1_5 = 217;
2128         SPR_SWAT_W1_6 = 218;
2129         SPR_SWAT_W1_7 = 219;
2130         SPR_SWAT_W1_8 = 220;
2131         SPR_SWAT_W2_1 = 221;
2132         SPR_SWAT_W2_2 = 222;
2133         SPR_SWAT_W2_3 = 223;
2134         SPR_SWAT_W2_4 = 224;
2135         SPR_SWAT_W2_5 = 225;
2136         SPR_SWAT_W2_6 = 226;
2137         SPR_SWAT_W2_7 = 227;
2138         SPR_SWAT_W2_8 = 228;
2139         SPR_SWAT_W3_1 = 229;
2140         SPR_SWAT_W3_2 = 230;
2141         SPR_SWAT_W3_3 = 231;
2142         SPR_SWAT_W3_4 = 232;
2143         SPR_SWAT_W3_5 = 233;
2144         SPR_SWAT_W3_6 = 234;
2145         SPR_SWAT_W3_7 = 235;
2146         SPR_SWAT_W3_8 = 236;
2147         SPR_SWAT_W4_1 = 237;
2148         SPR_SWAT_W4_2 = 238;
2149         SPR_SWAT_W4_3 = 239;
2150         SPR_SWAT_W4_4 = 240;
2151         SPR_SWAT_W4_5 = 241;
2152         SPR_SWAT_W4_6 = 242;
2153         SPR_SWAT_W4_7 = 243;
2154         SPR_SWAT_W4_8 = 244;
2155         SPR_SWAT_PAIN_1 = 245;
2156         SPR_SWAT_DIE_1 = 246;
2157         SPR_SWAT_DIE_2 = 247;
2158         SPR_SWAT_DIE_3 = 248;
2159         SPR_SWAT_PAIN_2 = 249;
2160         SPR_SWAT_DIE_4 = 250;
2161         SPR_SWAT_DEAD = 251;
2162         SPR_SWAT_SHOOT1 = 252;
2163         SPR_SWAT_SHOOT2 = 253;
2164         SPR_SWAT_SHOOT3 = 254;
2165         SPR_SWAT_WOUNDED1 = 255;
2166         SPR_SWAT_WOUNDED2 = 256;
2167         SPR_SWAT_WOUNDED3 = 257;
2168         SPR_SWAT_WOUNDED4 = 258;
2169 
2170         SPR_OFC_S_1 = 259;
2171         SPR_OFC_S_2 = 260;
2172         SPR_OFC_S_3 = 261;
2173         SPR_OFC_S_4 = 262;
2174         SPR_OFC_S_5 = 263;
2175         SPR_OFC_S_6 = 264;
2176         SPR_OFC_S_7 = 265;
2177         SPR_OFC_S_8 = 266;
2178         SPR_OFC_W1_1 = 267;
2179         SPR_OFC_W1_2 = 268;
2180         SPR_OFC_W1_3 = 269;
2181         SPR_OFC_W1_4 = 270;
2182         SPR_OFC_W1_5 = 271;
2183         SPR_OFC_W1_6 = 272;
2184         SPR_OFC_W1_7 = 273;
2185         SPR_OFC_W1_8 = 274;
2186         SPR_OFC_W2_1 = 275;
2187         SPR_OFC_W2_2 = 276;
2188         SPR_OFC_W2_3 = 277;
2189         SPR_OFC_W2_4 = 278;
2190         SPR_OFC_W2_5 = 279;
2191         SPR_OFC_W2_6 = 280;
2192         SPR_OFC_W2_7 = 281;
2193         SPR_OFC_W2_8 = 282;
2194         SPR_OFC_W3_1 = 283;
2195         SPR_OFC_W3_2 = 284;
2196         SPR_OFC_W3_3 = 285;
2197         SPR_OFC_W3_4 = 286;
2198         SPR_OFC_W3_5 = 287;
2199         SPR_OFC_W3_6 = 288;
2200         SPR_OFC_W3_7 = 289;
2201         SPR_OFC_W3_8 = 290;
2202         SPR_OFC_W4_1 = 291;
2203         SPR_OFC_W4_2 = 292;
2204         SPR_OFC_W4_3 = 293;
2205         SPR_OFC_W4_4 = 294;
2206         SPR_OFC_W4_5 = 295;
2207         SPR_OFC_W4_6 = 296;
2208         SPR_OFC_W4_7 = 297;
2209         SPR_OFC_W4_8 = 298;
2210         SPR_OFC_PAIN_1 = 299;
2211         SPR_OFC_DIE_1 = 300;
2212         SPR_OFC_DIE_2 = 301;
2213         SPR_OFC_DIE_3 = 302;
2214         SPR_OFC_PAIN_2 = 303;
2215         SPR_OFC_DIE_4 = 304;
2216         SPR_OFC_DEAD = 305;
2217         SPR_OFC_SHOOT1 = 306;
2218         SPR_OFC_SHOOT2 = 307;
2219         SPR_OFC_SHOOT3 = 308;
2220 
2221         SPR_GOLD_S_1 = 309;
2222         SPR_GOLD_S_2 = 310;
2223         SPR_GOLD_S_3 = 311;
2224         SPR_GOLD_S_4 = 312;
2225         SPR_GOLD_S_5 = 313;
2226         SPR_GOLD_S_6 = 314;
2227         SPR_GOLD_S_7 = 315;
2228         SPR_GOLD_S_8 = 316;
2229         SPR_GOLD_W1_1 = 317;
2230         SPR_GOLD_W1_2 = 318;
2231         SPR_GOLD_W1_3 = 319;
2232         SPR_GOLD_W1_4 = 320;
2233         SPR_GOLD_W1_5 = 321;
2234         SPR_GOLD_W1_6 = 322;
2235         SPR_GOLD_W1_7 = 323;
2236         SPR_GOLD_W1_8 = 324;
2237         SPR_GOLD_W2_1 = 325;
2238         SPR_GOLD_W2_2 = 326;
2239         SPR_GOLD_W2_3 = 327;
2240         SPR_GOLD_W2_4 = 328;
2241         SPR_GOLD_W2_5 = 329;
2242         SPR_GOLD_W2_6 = 330;
2243         SPR_GOLD_W2_7 = 331;
2244         SPR_GOLD_W2_8 = 332;
2245         SPR_GOLD_W3_1 = 333;
2246         SPR_GOLD_W3_2 = 334;
2247         SPR_GOLD_W3_3 = 335;
2248         SPR_GOLD_W3_4 = 336;
2249         SPR_GOLD_W3_5 = 337;
2250         SPR_GOLD_W3_6 = 338;
2251         SPR_GOLD_W3_7 = 339;
2252         SPR_GOLD_W3_8 = 340;
2253         SPR_GOLD_W4_1 = 341;
2254         SPR_GOLD_W4_2 = 342;
2255         SPR_GOLD_W4_3 = 343;
2256         SPR_GOLD_W4_4 = 344;
2257         SPR_GOLD_W4_5 = 345;
2258         SPR_GOLD_W4_6 = 346;
2259         SPR_GOLD_W4_7 = 347;
2260         SPR_GOLD_W4_8 = 348;
2261         SPR_GOLD_PAIN_1 = 349;
2262         SPR_GOLD_WRIST_1 = 350;
2263         SPR_GOLD_WRIST_2 = 351;
2264         SPR_GOLD_SHOOT1 = 352;
2265         SPR_GOLD_SHOOT2 = 353;
2266         SPR_GOLD_SHOOT3 = 354;
2267         SPR_GOLD_WARP1 = 355;
2268         SPR_GOLD_WARP2 = 356;
2269         SPR_GOLD_WARP3 = 357;
2270         SPR_GOLD_WARP4 = 358;
2271         SPR_GOLD_WARP5 = 359;
2272 
2273         SPR_GSCOUT_W1_1 = 360;
2274         SPR_GSCOUT_W1_2 = 361;
2275         SPR_GSCOUT_W1_3 = 362;
2276         SPR_GSCOUT_W1_4 = 363;
2277         SPR_GSCOUT_W1_5 = 364;
2278         SPR_GSCOUT_W1_6 = 365;
2279         SPR_GSCOUT_W1_7 = 366;
2280         SPR_GSCOUT_W1_8 = 367;
2281         SPR_GSCOUT_W2_1 = 368;
2282         SPR_GSCOUT_W2_2 = 369;
2283         SPR_GSCOUT_W2_3 = 370;
2284         SPR_GSCOUT_W2_4 = 371;
2285         SPR_GSCOUT_W2_5 = 372;
2286         SPR_GSCOUT_W2_6 = 373;
2287         SPR_GSCOUT_W2_7 = 374;
2288         SPR_GSCOUT_W2_8 = 375;
2289         SPR_GSCOUT_W3_1 = 376;
2290         SPR_GSCOUT_W3_2 = 377;
2291         SPR_GSCOUT_W3_3 = 378;
2292         SPR_GSCOUT_W3_4 = 379;
2293         SPR_GSCOUT_W3_5 = 380;
2294         SPR_GSCOUT_W3_6 = 381;
2295         SPR_GSCOUT_W3_7 = 382;
2296         SPR_GSCOUT_W3_8 = 383;
2297         SPR_GSCOUT_W4_1 = 384;
2298         SPR_GSCOUT_W4_2 = 385;
2299         SPR_GSCOUT_W4_3 = 386;
2300         SPR_GSCOUT_W4_4 = 387;
2301         SPR_GSCOUT_W4_5 = 388;
2302         SPR_GSCOUT_W4_6 = 389;
2303         SPR_GSCOUT_W4_7 = 390;
2304         SPR_GSCOUT_W4_8 = 391;
2305         SPR_GSCOUT_DIE1 = 392;
2306         SPR_GSCOUT_DIE2 = 393;
2307         SPR_GSCOUT_DIE3 = 394;
2308         SPR_GSCOUT_DIE4 = 395;
2309         SPR_GSCOUT_DIE5 = 396;
2310         SPR_GSCOUT_DIE6 = 397;
2311         SPR_GSCOUT_DIE7 = 398;
2312         SPR_GSCOUT_DIE8 = 399;
2313         SPR_GSCOUT_DEAD = 400;
2314 
2315         SPR_FSCOUT_W1_1 = 401;
2316         SPR_FSCOUT_W1_2 = 402;
2317         SPR_FSCOUT_W1_3 = 403;
2318         SPR_FSCOUT_W1_4 = 404;
2319         SPR_FSCOUT_W1_5 = 405;
2320         SPR_FSCOUT_W1_6 = 406;
2321         SPR_FSCOUT_W1_7 = 407;
2322         SPR_FSCOUT_W1_8 = 408;
2323         SPR_FSCOUT_W2_1 = 409;
2324         SPR_FSCOUT_W2_2 = 410;
2325         SPR_FSCOUT_W2_3 = 411;
2326         SPR_FSCOUT_W2_4 = 412;
2327         SPR_FSCOUT_W2_5 = 413;
2328         SPR_FSCOUT_W2_6 = 414;
2329         SPR_FSCOUT_W2_7 = 415;
2330         SPR_FSCOUT_W2_8 = 416;
2331         SPR_FSCOUT_W3_1 = 417;
2332         SPR_FSCOUT_W3_2 = 418;
2333         SPR_FSCOUT_W3_3 = 419;
2334         SPR_FSCOUT_W3_4 = 420;
2335         SPR_FSCOUT_W3_5 = 421;
2336         SPR_FSCOUT_W3_6 = 422;
2337         SPR_FSCOUT_W3_7 = 423;
2338         SPR_FSCOUT_W3_8 = 424;
2339         SPR_FSCOUT_W4_1 = 425;
2340         SPR_FSCOUT_W4_2 = 426;
2341         SPR_FSCOUT_W4_3 = 427;
2342         SPR_FSCOUT_W4_4 = 428;
2343         SPR_FSCOUT_W4_5 = 429;
2344         SPR_FSCOUT_W4_6 = 430;
2345         SPR_FSCOUT_W4_7 = 431;
2346         SPR_FSCOUT_W4_8 = 432;
2347         SPR_FSCOUT_DIE1 = 433;
2348         SPR_FSCOUT_DIE2 = 434;
2349         SPR_FSCOUT_DIE3 = 435;
2350         SPR_FSCOUT_DIE4 = 436;
2351         SPR_FSCOUT_DIE5 = 437;
2352         SPR_FSCOUT_DIE6 = 438;
2353         SPR_FSCOUT_DIE7 = 439;
2354         SPR_FSCOUT_DEAD = 440;
2355 
2356         SPR_EXPLOSION_1 = 441;
2357         SPR_EXPLOSION_2 = 442;
2358         SPR_EXPLOSION_3 = 443;
2359         SPR_EXPLOSION_4 = 444;
2360         SPR_EXPLOSION_5 = 445;
2361 
2362         SPR_VITAL_STAND = 446;
2363         SPR_VITAL_DIE_1 = 447;
2364         SPR_VITAL_DIE_2 = 448;
2365         SPR_VITAL_DIE_3 = 449;
2366         SPR_VITAL_DIE_4 = 450;
2367         SPR_VITAL_DIE_5 = 451;
2368         SPR_VITAL_DIE_6 = 452;
2369         SPR_VITAL_DIE_7 = 453;
2370         SPR_VITAL_DIE_8 = 454;
2371         SPR_VITAL_DEAD_1 = 455;
2372         SPR_VITAL_DEAD_2 = 456;
2373         SPR_VITAL_DEAD_3 = 457;
2374         SPR_VITAL_OUCH = 458;
2375 
2376         SPR_SECURITY_NORMAL = 459;
2377         SPR_SECURITY_ALERT = 460;
2378 
2379         SPR_POD_EGG = 461;
2380         SPR_POD_HATCH1 = 462;
2381         SPR_POD_HATCH2 = 463;
2382         SPR_POD_HATCH3 = 464;
2383         SPR_POD_WALK1 = 465;
2384         SPR_POD_WALK2 = 466;
2385         SPR_POD_WALK3 = 467;
2386         SPR_POD_WALK4 = 468;
2387         SPR_POD_ATTACK1 = 469;
2388         SPR_POD_ATTACK2 = 470;
2389         SPR_POD_ATTACK3 = 471;
2390         SPR_POD_OUCH = 472;
2391         SPR_POD_DIE1 = 473;
2392         SPR_POD_DIE2 = 474;
2393         SPR_POD_DIE3 = 475;
2394         SPR_POD_SPIT1 = 476;
2395         SPR_POD_SPIT2 = 477;
2396         SPR_POD_SPIT3 = 478;
2397 
2398         SPR_ELEC_APPEAR1 = 479;
2399         SPR_ELEC_APPEAR2 = 480;
2400         SPR_ELEC_APPEAR3 = 481;
2401         SPR_ELEC_WALK1 = 482;
2402         SPR_ELEC_WALK2 = 483;
2403         SPR_ELEC_WALK3 = 484;
2404         SPR_ELEC_WALK4 = 485;
2405         SPR_ELEC_OUCH = 486;
2406         SPR_ELEC_SHOOT1 = 487;
2407         SPR_ELEC_SHOOT2 = 488;
2408         SPR_ELEC_SHOOT3 = 489;
2409         SPR_ELEC_DIE1 = 490;
2410         SPR_ELEC_DIE2 = 491;
2411         SPR_ELEC_DIE3 = 492;
2412         SPR_ELEC_SHOT1 = 493;
2413         SPR_ELEC_SHOT2 = 494;
2414         SPR_ELEC_SHOT_EXP1 = 495;
2415         SPR_ELEC_SHOT_EXP2 = 496;
2416 
2417         SPR_ELECTRO_SPHERE_ROAM1 = 497;
2418         SPR_ELECTRO_SPHERE_ROAM2 = 498;
2419         SPR_ELECTRO_SPHERE_ROAM3 = 499;
2420         SPR_ELECTRO_SPHERE_OUCH = 500;
2421         SPR_ELECTRO_SPHERE_DIE1 = 501;
2422         SPR_ELECTRO_SPHERE_DIE2 = 502;
2423         SPR_ELECTRO_SPHERE_DIE3 = 503;
2424         SPR_ELECTRO_SPHERE_DIE4 = 504;
2425 
2426         SPR_GENETIC_W1 = 505;
2427         SPR_GENETIC_W2 = 506;
2428         SPR_GENETIC_W3 = 507;
2429         SPR_GENETIC_W4 = 508;
2430         SPR_GENETIC_SWING1 = 509;
2431         SPR_GENETIC_SWING2 = 510;
2432         SPR_GENETIC_SWING3 = 511;
2433         SPR_GENETIC_DEAD = 512;
2434         SPR_GENETIC_DIE1 = 513;
2435         SPR_GENETIC_DIE2 = 514;
2436         SPR_GENETIC_DIE3 = 515;
2437         SPR_GENETIC_DIE4 = 516;
2438         SPR_GENETIC_OUCH = 517;
2439         SPR_GENETIC_SHOOT1 = 518;
2440         SPR_GENETIC_SHOOT2 = 519;
2441         SPR_GENETIC_SHOOT3 = 520;
2442 
2443         SPR_MUTHUM1_W1 = 521;
2444         SPR_MUTHUM1_W2 = 522;
2445         SPR_MUTHUM1_W3 = 523;
2446         SPR_MUTHUM1_W4 = 524;
2447         SPR_MUTHUM1_SWING1 = 525;
2448         SPR_MUTHUM1_SWING2 = 526;
2449         SPR_MUTHUM1_SWING3 = 527;
2450         SPR_MUTHUM1_DEAD = 528;
2451         SPR_MUTHUM1_DIE1 = 529;
2452         SPR_MUTHUM1_DIE2 = 530;
2453         SPR_MUTHUM1_DIE3 = 531;
2454         SPR_MUTHUM1_DIE4 = 532;
2455         SPR_MUTHUM1_OUCH = 533;
2456         SPR_MUTHUM1_SPIT1 = 534;
2457         SPR_MUTHUM1_SPIT2 = 535;
2458         SPR_MUTHUM1_SPIT3 = 536;
2459 
2460         SPR_MUTHUM2_W1 = 537;
2461         SPR_MUTHUM2_W2 = 538;
2462         SPR_MUTHUM2_W3 = 539;
2463         SPR_MUTHUM2_W4 = 540;
2464         SPR_MUTHUM2_SWING1 = 541;
2465         SPR_MUTHUM2_SWING2 = 542;
2466         SPR_MUTHUM2_SWING3 = 543;
2467         SPR_MUTHUM2_DEAD = 544;
2468         SPR_MUTHUM2_DIE1 = 545;
2469         SPR_MUTHUM2_DIE2 = 546;
2470         SPR_MUTHUM2_DIE3 = 547;
2471         SPR_MUTHUM2_DIE4 = 548;
2472         SPR_MUTHUM2_OUCH = 549;
2473         SPR_MUTHUM2_SPIT1 = 550;
2474         SPR_MUTHUM2_SPIT2 = 551;
2475         SPR_MUTHUM2_SPIT3 = 552;
2476 
2477         SPR_LCAN_ALIEN_READY = 553;
2478         SPR_LCAN_ALIEN_B1 = 554;
2479         SPR_LCAN_ALIEN_B2 = 555;
2480         SPR_LCAN_ALIEN_B3 = 556;
2481         SPR_LCAN_ALIEN_EMPTY = 557;
2482         SPR_LCAN_ALIEN_W1 = 558;
2483         SPR_LCAN_ALIEN_W2 = 559;
2484         SPR_LCAN_ALIEN_W3 = 560;
2485         SPR_LCAN_ALIEN_W4 = 561;
2486         SPR_LCAN_ALIEN_SWING1 = 562;
2487         SPR_LCAN_ALIEN_SWING2 = 563;
2488         SPR_LCAN_ALIEN_SWING3 = 564;
2489         SPR_LCAN_ALIEN_DEAD = 565;
2490         SPR_LCAN_ALIEN_DIE1 = 566;
2491         SPR_LCAN_ALIEN_DIE2 = 567;
2492         SPR_LCAN_ALIEN_DIE3 = 568;
2493         SPR_LCAN_ALIEN_DIE4 = 569;
2494         SPR_LCAN_ALIEN_OUCH = 570;
2495         SPR_LCAN_ALIEN_SPIT1 = 571;
2496         SPR_LCAN_ALIEN_SPIT2 = 572;
2497         SPR_LCAN_ALIEN_SPIT3 = 573;
2498 
2499         SPR_SCAN_ALIEN_READY = 574;
2500         SPR_SCAN_ALIEN_B1 = 575;
2501         SPR_SCAN_ALIEN_B2 = 576;
2502         SPR_SCAN_ALIEN_B3 = 577;
2503         SPR_SCAN_ALIEN_EMPTY = 578;
2504         SPR_SCAN_ALIEN_W1 = 579;
2505         SPR_SCAN_ALIEN_W2 = 580;
2506         SPR_SCAN_ALIEN_W3 = 581;
2507         SPR_SCAN_ALIEN_W4 = 582;
2508         SPR_SCAN_ALIEN_SWING1 = 583;
2509         SPR_SCAN_ALIEN_SWING2 = 584;
2510         SPR_SCAN_ALIEN_SWING3 = 585;
2511         SPR_SCAN_ALIEN_DEAD = 586;
2512         SPR_SCAN_ALIEN_DIE1 = 587;
2513         SPR_SCAN_ALIEN_DIE2 = 588;
2514         SPR_SCAN_ALIEN_DIE3 = 589;
2515         SPR_SCAN_ALIEN_DIE4 = 590;
2516         SPR_SCAN_ALIEN_OUCH = 591;
2517         SPR_SCAN_ALIEN_SPIT1 = 592;
2518         SPR_SCAN_ALIEN_SPIT2 = 593;
2519         SPR_SCAN_ALIEN_SPIT3 = 594;
2520 
2521         SPR_GURNEY_MUT_READY = 595;
2522         SPR_GURNEY_MUT_B1 = 596;
2523         SPR_GURNEY_MUT_B2 = 597;
2524         SPR_GURNEY_MUT_B3 = 598;
2525         SPR_GURNEY_MUT_EMPTY = 599;
2526         SPR_GURNEY_MUT_W1 = 600;
2527         SPR_GURNEY_MUT_W2 = 601;
2528         SPR_GURNEY_MUT_W3 = 602;
2529         SPR_GURNEY_MUT_W4 = 603;
2530         SPR_GURNEY_MUT_SWING1 = 604;
2531         SPR_GURNEY_MUT_SWING2 = 605;
2532         SPR_GURNEY_MUT_SWING3 = 606;
2533         SPR_GURNEY_MUT_DEAD = 607;
2534         SPR_GURNEY_MUT_DIE1 = 608;
2535         SPR_GURNEY_MUT_DIE2 = 609;
2536         SPR_GURNEY_MUT_DIE3 = 610;
2537         SPR_GURNEY_MUT_DIE4 = 611;
2538         SPR_GURNEY_MUT_OUCH = 612;
2539 
2540         SPR_LIQUID_M1 = 613;
2541         SPR_LIQUID_M2 = 614;
2542         SPR_LIQUID_M3 = 615;
2543         SPR_LIQUID_R1 = 616;
2544         SPR_LIQUID_R2 = 617;
2545         SPR_LIQUID_R3 = 618;
2546         SPR_LIQUID_R4 = 619;
2547         SPR_LIQUID_S1 = 620;
2548         SPR_LIQUID_S2 = 621;
2549         SPR_LIQUID_S3 = 622;
2550         SPR_LIQUID_OUCH = 623;
2551         SPR_LIQUID_DIE_1 = 624;
2552         SPR_LIQUID_DIE_2 = 625;
2553         SPR_LIQUID_DIE_3 = 626;
2554         SPR_LIQUID_DIE_4 = 627;
2555         SPR_LIQUID_DEAD = 628;
2556         SPR_LIQUID_SHOT_FLY_1 = 629;
2557         SPR_LIQUID_SHOT_FLY_2 = 630;
2558         SPR_LIQUID_SHOT_FLY_3 = 631;
2559         SPR_LIQUID_SHOT_BURST_1 = 632;
2560         SPR_LIQUID_SHOT_BURST_2 = 633;
2561         SPR_LIQUID_SHOT_BURST_3 = 634;
2562 
2563         SPR_SPIT1_1 = 635;
2564         SPR_SPIT1_2 = 636;
2565         SPR_SPIT1_3 = 637;
2566         SPR_SPIT_EXP1_1 = 638;
2567         SPR_SPIT_EXP1_2 = 639;
2568         SPR_SPIT_EXP1_3 = 640;
2569 
2570         SPR_SPIT2_1 = 641;
2571         SPR_SPIT2_2 = 642;
2572         SPR_SPIT2_3 = 643;
2573         SPR_SPIT_EXP2_1 = 644;
2574         SPR_SPIT_EXP2_2 = 645;
2575         SPR_SPIT_EXP2_3 = 646;
2576 
2577         SPR_SPIT3_1 = 647;
2578         SPR_SPIT3_2 = 648;
2579         SPR_SPIT3_3 = 649;
2580         SPR_SPIT_EXP3_1 = 650;
2581         SPR_SPIT_EXP3_2 = 651;
2582         SPR_SPIT_EXP3_3 = 652;
2583 
2584         SPR_TERROT_1 = 653;
2585         SPR_TERROT_2 = 654;
2586         SPR_TERROT_3 = 655;
2587         SPR_TERROT_4 = 656;
2588         SPR_TERROT_5 = 657;
2589         SPR_TERROT_6 = 658;
2590         SPR_TERROT_7 = 659;
2591         SPR_TERROT_8 = 660;
2592         SPR_TERROT_FIRE_1 = 661;
2593         SPR_TERROT_FIRE_2 = 662;
2594         SPR_TERROT_DIE_1 = 663;
2595         SPR_TERROT_DIE_2 = 664;
2596         SPR_TERROT_DIE_3 = 665;
2597         SPR_TERROT_DIE_4 = 666;
2598         SPR_TERROT_DEAD = 667;
2599 
2600         SPR_KNIFEREADY = 668;
2601         SPR_KNIFEATK1 = 669;
2602         SPR_KNIFEATK2 = 670;
2603         SPR_KNIFEATK3 = 671;
2604         SPR_KNIFEATK4 = 672;
2605 
2606         SPR_PISTOLREADY = 673;
2607         SPR_PISTOLATK1 = 674;
2608         SPR_PISTOLATK2 = 675;
2609         SPR_PISTOLATK3 = 676;
2610         SPR_PISTOLATK4 = 677;
2611 
2612         SPR_MACHINEGUNREADY = 678;
2613         SPR_MACHINEGUNATK1 = 679;
2614         SPR_MACHINEGUNATK2 = 680;
2615         SPR_MACHINEGUNATK3 = 681;
2616         SPR_MACHINEGUNATK4 = 682;
2617 
2618         SPR_CHAINREADY = 683;
2619         SPR_CHAINATK1 = 684;
2620         SPR_CHAINATK2 = 685;
2621         SPR_CHAINATK3 = 686;
2622         SPR_CHAINATK4 = 687;
2623 
2624         SPR_GRENADEREADY = 688;
2625         SPR_GRENADEATK1 = 689;
2626         SPR_GRENADEATK2 = 690;
2627         SPR_GRENADEATK3 = 691;
2628         SPR_GRENADEATK4 = 692;
2629         SPR_GRENADE_FLY1 = 693;
2630         SPR_GRENADE_FLY2 = 694;
2631         SPR_GRENADE_FLY3 = 695;
2632         SPR_GRENADE_FLY4 = 696;
2633         SPR_GRENADE_EXPLODE1 = 697;
2634         SPR_GRENADE_EXPLODE2 = 698;
2635         SPR_GRENADE_EXPLODE3 = 699;
2636         SPR_GRENADE_EXPLODE4 = 700;
2637         SPR_GRENADE_EXPLODE5 = 701;
2638 
2639         SPR_ELEC_ARC1 = 702;
2640         SPR_ELEC_ARC2 = 703;
2641         SPR_ELEC_ARC3 = 704;
2642         SPR_ELEC_ARC4 = 705;
2643         SPR_ELEC_POST1 = 706;
2644         SPR_ELEC_POST2 = 707;
2645         SPR_ELEC_POST3 = 708;
2646         SPR_ELEC_POST4 = 709;
2647 
2648         SPR_GREEN_OOZE1 = 710;
2649         SPR_GREEN_OOZE2 = 711;
2650         SPR_GREEN_OOZE3 = 712;
2651 
2652         SPR_BLACK_OOZE1 = 713;
2653         SPR_BLACK_OOZE2 = 714;
2654         SPR_BLACK_OOZE3 = 715;
2655 
2656         SPR_CANDY_BAR = 716;
2657         SPR_CANDY_WRAPER = 717;
2658 
2659         SPR_SANDWICH = 718;
2660         SPR_SANDWICH_WRAPER = 719;
2661 
2662         SPR_BLAKE_W1 = 720;
2663         SPR_BLAKE_W2 = 721;
2664         SPR_BLAKE_W3 = 722;
2665         SPR_BLAKE_W4 = 723;
2666 
2667         SPR_BOSS1_W1 = 724;
2668         SPR_BOSS1_W2 = 725;
2669         SPR_BOSS1_W3 = 726;
2670         SPR_BOSS1_W4 = 727;
2671         SPR_BOSS1_SWING1 = 728;
2672         SPR_BOSS1_SWING2 = 729;
2673         SPR_BOSS1_SWING3 = 730;
2674         SPR_BOSS1_DEAD = 731;
2675         SPR_BOSS1_DIE1 = 732;
2676         SPR_BOSS1_DIE2 = 733;
2677         SPR_BOSS1_DIE3 = 734;
2678         SPR_BOSS1_DIE4 = 735;
2679         SPR_BOSS1_OUCH = 736;
2680         SPR_BOSS1_PROJ1 = 737;
2681         SPR_BOSS1_PROJ2 = 738;
2682         SPR_BOSS1_PROJ3 = 739;
2683         SPR_BOSS1_EXP1 = 740;
2684         SPR_BOSS1_EXP2 = 741;
2685         SPR_BOSS1_EXP3 = 742;
2686 
2687         SPR_BOSS2_W1 = 743;
2688         SPR_BOSS2_W2 = 744;
2689         SPR_BOSS2_W3 = 745;
2690         SPR_BOSS2_W4 = 746;
2691         SPR_BOSS2_SWING1 = 747;
2692         SPR_BOSS2_SWING2 = 748;
2693         SPR_BOSS2_SWING3 = 749;
2694         SPR_BOSS2_DEAD = 750;
2695         SPR_BOSS2_DIE1 = 751;
2696         SPR_BOSS2_DIE2 = 752;
2697         SPR_BOSS2_DIE3 = 753;
2698         SPR_BOSS2_DIE4 = 754;
2699         SPR_BOSS2_OUCH = 755;
2700 
2701         SPR_BOSS3_W1 = 756;
2702         SPR_BOSS3_W2 = 757;
2703         SPR_BOSS3_W3 = 758;
2704         SPR_BOSS3_W4 = 759;
2705         SPR_BOSS3_SWING1 = 760;
2706         SPR_BOSS3_SWING2 = 761;
2707         SPR_BOSS3_SWING3 = 762;
2708         SPR_BOSS3_DEAD = 763;
2709         SPR_BOSS3_DIE1 = 764;
2710         SPR_BOSS3_DIE2 = 765;
2711         SPR_BOSS3_DIE3 = 766;
2712         SPR_BOSS3_DIE4 = 767;
2713         SPR_BOSS3_OUCH = 768;
2714 
2715         SPR_BOSS4_W1 = 769;
2716         SPR_BOSS4_W2 = 770;
2717         SPR_BOSS4_W3 = 771;
2718         SPR_BOSS4_W4 = 772;
2719         SPR_BOSS4_SWING1 = 773;
2720         SPR_BOSS4_SWING2 = 774;
2721         SPR_BOSS4_SWING3 = 775;
2722         SPR_BOSS4_DEAD = 776;
2723         SPR_BOSS4_DIE1 = 777;
2724         SPR_BOSS4_DIE2 = 778;
2725         SPR_BOSS4_DIE3 = 779;
2726         SPR_BOSS4_DIE4 = 780;
2727         SPR_BOSS4_OUCH = 781;
2728 
2729         SPR_BOSS5_W1 = 782;
2730         SPR_BOSS5_W2 = 783;
2731         SPR_BOSS5_W3 = 784;
2732         SPR_BOSS5_W4 = 785;
2733         SPR_BOSS5_SWING1 = 786;
2734         SPR_BOSS5_SWING2 = 787;
2735         SPR_BOSS5_SWING3 = 788;
2736         SPR_BOSS5_DEAD = 789;
2737         SPR_BOSS5_DIE1 = 790;
2738         SPR_BOSS5_DIE2 = 791;
2739         SPR_BOSS5_DIE3 = 792;
2740         SPR_BOSS5_DIE4 = 793;
2741         SPR_BOSS5_OUCH = 794;
2742         SPR_BOSS5_PROJ1 = 795;
2743         SPR_BOSS5_PROJ2 = 796;
2744         SPR_BOSS5_PROJ3 = 797;
2745         SPR_BOSS5_EXP1 = 798;
2746         SPR_BOSS5_EXP2 = 799;
2747         SPR_BOSS5_EXP3 = 800;
2748 
2749         SPR_BOSS6_W1 = 801;
2750         SPR_BOSS6_W2 = 802;
2751         SPR_BOSS6_W3 = 803;
2752         SPR_BOSS6_W4 = 804;
2753         SPR_BOSS6_SWING1 = 805;
2754         SPR_BOSS6_SWING2 = 806;
2755         SPR_BOSS6_SWING3 = 807;
2756         SPR_BOSS6_DEAD = 808;
2757         SPR_BOSS6_DIE1 = 809;
2758         SPR_BOSS6_DIE2 = 810;
2759         SPR_BOSS6_DIE3 = 811;
2760         SPR_BOSS6_DIE4 = 812;
2761         SPR_BOSS6_OUCH = 813;
2762     } else if (::is_ps()) {
2763         SPR_STAT_0 = 1;
2764         SPR_STAT_1 = 2;
2765         SPR_STAT_2 = 3;
2766         SPR_STAT_3 = 4;
2767         SPR_STAT_4 = 5;
2768         SPR_STAT_5 = 6;
2769         SPR_STAT_6 = 7;
2770         SPR_STAT_7 = 8;
2771         SPR_STAT_8 = 9;
2772         SPR_STAT_9 = 10;
2773         SPR_STAT_10 = 11;
2774         SPR_STAT_11 = 12;
2775         SPR_STAT_12 = 13;
2776         SPR_STAT_13 = 14;
2777         SPR_STAT_14 = 15;
2778         SPR_STAT_15 = 16;
2779         SPR_STAT_16 = 17;
2780         SPR_STAT_17 = 18;
2781         SPR_STAT_18 = 19;
2782         SPR_STAT_19 = 20;
2783         SPR_STAT_20 = 21;
2784         SPR_STAT_21 = 22;
2785         SPR_STAT_22 = 23;
2786         SPR_STAT_23 = 24;
2787         SPR_STAT_24 = 25;
2788         SPR_STAT_25 = 26;
2789         SPR_STAT_26 = 27;
2790         SPR_STAT_27 = 28;
2791         SPR_STAT_28 = 29;
2792         SPR_STAT_29 = 30;
2793         SPR_STAT_30 = 31;
2794         SPR_STAT_31 = 32;
2795         SPR_STAT_32 = 33;
2796         SPR_STAT_33 = 34;
2797         SPR_STAT_34 = 35;
2798         SPR_STAT_35 = 36;
2799         SPR_STAT_36 = 37;
2800         SPR_STAT_37 = 38;
2801         SPR_STAT_38 = 39;
2802         SPR_STAT_39 = 40;
2803         SPR_STAT_40 = 41;
2804         SPR_STAT_41 = 42;
2805         SPR_STAT_42 = 43;
2806         SPR_STAT_43 = 44;
2807         SPR_STAT_44 = 45;
2808         SPR_STAT_45 = 46;
2809         SPR_STAT_46 = 47;
2810         SPR_STAT_47 = 48;
2811         SPR_STAT_48 = 49;
2812         SPR_STAT_49 = 50;
2813         SPR_STAT_50 = 51;
2814         SPR_STAT_51 = 52;
2815         SPR_STAT_52 = 53;
2816         SPR_STAT_53 = 54;
2817         SPR_STAT_54 = 55;
2818         SPR_STAT_55 = 56;
2819         SPR_STAT_56 = 57;
2820 
2821         SPR_CRATE_1 = 58;
2822         SPR_CRATE_2 = 59;
2823         SPR_CRATE_3 = 60;
2824 
2825         SPR_STAT_57 = 61;
2826         SPR_STAT_58 = 62;
2827         SPR_STAT_59 = 63;
2828         SPR_STAT_60 = 64;
2829         SPR_STAT_61 = 65;
2830         SPR_STAT_62 = 66;
2831         SPR_STAT_63 = 67;
2832         SPR_STAT_64 = 68;
2833         SPR_STAT_65 = 69;
2834         SPR_STAT_66 = 70;
2835         SPR_STAT_67 = 71;
2836         SPR_STAT_68 = 72;
2837         SPR_STAT_69 = 73;
2838         SPR_STAT_70 = 74;
2839         SPR_STAT_71 = 75;
2840         SPR_STAT_72 = 76;
2841         SPR_STAT_73 = 77;
2842         SPR_STAT_74 = 78;
2843         SPR_STAT_75 = 79;
2844         SPR_STAT_76 = 80;
2845         SPR_STAT_77 = 81;
2846         SPR_STAT_78 = 82;
2847         SPR_STAT_79 = 83;
2848 
2849         SPR_DOORBOMB = 84;
2850         SPR_ALT_DOORBOMB = 85;
2851 
2852         SPR_RUBBLE = 86;
2853         SPR_BONZI_TREE = 87;
2854         SPR_AUTOMAPPER = 88;
2855         SPR_POT_PLANT = 89;
2856         SPR_TUBE_PLANT = 90;
2857         SPR_HITECH_CHAIR = 91;
2858 
2859         SPR_AIR_VENT = 92;
2860 
2861         SPR_BLOOD_DRIP1 = 93;
2862         SPR_BLOOD_DRIP2 = 94;
2863         SPR_BLOOD_DRIP3 = 95;
2864         SPR_BLOOD_DRIP4 = 96;
2865         SPR_WATER_DRIP1 = 97;
2866         SPR_WATER_DRIP2 = 98;
2867         SPR_WATER_DRIP3 = 99;
2868         SPR_WATER_DRIP4 = 100;
2869 
2870         SPR_DECO_ARC_1 = 101;
2871         SPR_DECO_ARC_2 = 102;
2872         SPR_DECO_ARC_3 = 103;
2873 
2874         SPR_GRATE = 104;
2875         SPR_STEAM_1 = 105;
2876         SPR_STEAM_2 = 106;
2877         SPR_STEAM_3 = 107;
2878         SPR_STEAM_4 = 108;
2879         SPR_STEAM_PIPE = 109;
2880         SPR_PIPE_STEAM_1 = 110;
2881         SPR_PIPE_STEAM_2 = 111;
2882         SPR_PIPE_STEAM_3 = 112;
2883         SPR_PIPE_STEAM_4 = 113;
2884 
2885         SPR_DEAD_RENT = 114;
2886         SPR_DEAD_PRO = 115;
2887         SPR_DEAD_SWAT = 116;
2888 
2889         SPR_RENT_S_1 = 117;
2890         SPR_RENT_S_2 = 118;
2891         SPR_RENT_S_3 = 119;
2892         SPR_RENT_S_4 = 120;
2893         SPR_RENT_S_5 = 121;
2894         SPR_RENT_S_6 = 122;
2895         SPR_RENT_S_7 = 123;
2896         SPR_RENT_S_8 = 124;
2897         SPR_RENT_W1_1 = 125;
2898         SPR_RENT_W1_2 = 126;
2899         SPR_RENT_W1_3 = 127;
2900         SPR_RENT_W1_4 = 128;
2901         SPR_RENT_W1_5 = 129;
2902         SPR_RENT_W1_6 = 130;
2903         SPR_RENT_W1_7 = 131;
2904         SPR_RENT_W1_8 = 132;
2905         SPR_RENT_W2_1 = 133;
2906         SPR_RENT_W2_2 = 134;
2907         SPR_RENT_W2_3 = 135;
2908         SPR_RENT_W2_4 = 136;
2909         SPR_RENT_W2_5 = 137;
2910         SPR_RENT_W2_6 = 138;
2911         SPR_RENT_W2_7 = 139;
2912         SPR_RENT_W2_8 = 140;
2913         SPR_RENT_W3_1 = 141;
2914         SPR_RENT_W3_2 = 142;
2915         SPR_RENT_W3_3 = 143;
2916         SPR_RENT_W3_4 = 144;
2917         SPR_RENT_W3_5 = 145;
2918         SPR_RENT_W3_6 = 146;
2919         SPR_RENT_W3_7 = 147;
2920         SPR_RENT_W3_8 = 148;
2921         SPR_RENT_W4_1 = 149;
2922         SPR_RENT_W4_2 = 150;
2923         SPR_RENT_W4_3 = 151;
2924         SPR_RENT_W4_4 = 152;
2925         SPR_RENT_W4_5 = 153;
2926         SPR_RENT_W4_6 = 154;
2927         SPR_RENT_W4_7 = 155;
2928         SPR_RENT_W4_8 = 156;
2929         SPR_RENT_DIE_1 = 157;
2930         SPR_RENT_DIE_2 = 158;
2931         SPR_RENT_DIE_3 = 159;
2932         SPR_RENT_DIE_4 = 160;
2933         SPR_RENT_PAIN_1 = 161;
2934         SPR_RENT_DEAD = 162;
2935         SPR_RENT_SHOOT1 = 163;
2936         SPR_RENT_SHOOT2 = 164;
2937         SPR_RENT_SHOOT3 = 165;
2938 
2939         SPR_PRO_S_1 = 166;
2940         SPR_PRO_S_2 = 167;
2941         SPR_PRO_S_3 = 168;
2942         SPR_PRO_S_4 = 169;
2943         SPR_PRO_S_5 = 170;
2944         SPR_PRO_S_6 = 171;
2945         SPR_PRO_S_7 = 172;
2946         SPR_PRO_S_8 = 173;
2947         SPR_PRO_W1_1 = 174;
2948         SPR_PRO_W1_2 = 175;
2949         SPR_PRO_W1_3 = 176;
2950         SPR_PRO_W1_4 = 177;
2951         SPR_PRO_W1_5 = 178;
2952         SPR_PRO_W1_6 = 179;
2953         SPR_PRO_W1_7 = 180;
2954         SPR_PRO_W1_8 = 181;
2955         SPR_PRO_W2_1 = 182;
2956         SPR_PRO_W2_2 = 183;
2957         SPR_PRO_W2_3 = 184;
2958         SPR_PRO_W2_4 = 185;
2959         SPR_PRO_W2_5 = 186;
2960         SPR_PRO_W2_6 = 187;
2961         SPR_PRO_W2_7 = 188;
2962         SPR_PRO_W2_8 = 189;
2963         SPR_PRO_W3_1 = 190;
2964         SPR_PRO_W3_2 = 191;
2965         SPR_PRO_W3_3 = 192;
2966         SPR_PRO_W3_4 = 193;
2967         SPR_PRO_W3_5 = 194;
2968         SPR_PRO_W3_6 = 195;
2969         SPR_PRO_W3_7 = 196;
2970         SPR_PRO_W3_8 = 197;
2971         SPR_PRO_W4_1 = 198;
2972         SPR_PRO_W4_2 = 199;
2973         SPR_PRO_W4_3 = 200;
2974         SPR_PRO_W4_4 = 201;
2975         SPR_PRO_W4_5 = 202;
2976         SPR_PRO_W4_6 = 203;
2977         SPR_PRO_W4_7 = 204;
2978         SPR_PRO_W4_8 = 205;
2979         SPR_PRO_PAIN_1 = 206;
2980         SPR_PRO_DIE_1 = 207;
2981         SPR_PRO_DIE_2 = 208;
2982         SPR_PRO_DIE_3 = 209;
2983         SPR_PRO_PAIN_2 = 210;
2984         SPR_PRO_DIE_4 = 211;
2985         SPR_PRO_DEAD = 212;
2986         SPR_PRO_SHOOT1 = 213;
2987         SPR_PRO_SHOOT2 = 214;
2988         SPR_PRO_SHOOT3 = 215;
2989 
2990         SPR_SWAT_S_1 = 216;
2991         SPR_SWAT_S_2 = 217;
2992         SPR_SWAT_S_3 = 218;
2993         SPR_SWAT_S_4 = 219;
2994         SPR_SWAT_S_5 = 220;
2995         SPR_SWAT_S_6 = 221;
2996         SPR_SWAT_S_7 = 222;
2997         SPR_SWAT_S_8 = 223;
2998         SPR_SWAT_W1_1 = 224;
2999         SPR_SWAT_W1_2 = 225;
3000         SPR_SWAT_W1_3 = 226;
3001         SPR_SWAT_W1_4 = 227;
3002         SPR_SWAT_W1_5 = 228;
3003         SPR_SWAT_W1_6 = 229;
3004         SPR_SWAT_W1_7 = 230;
3005         SPR_SWAT_W1_8 = 231;
3006         SPR_SWAT_W2_1 = 232;
3007         SPR_SWAT_W2_2 = 233;
3008         SPR_SWAT_W2_3 = 234;
3009         SPR_SWAT_W2_4 = 235;
3010         SPR_SWAT_W2_5 = 236;
3011         SPR_SWAT_W2_6 = 237;
3012         SPR_SWAT_W2_7 = 238;
3013         SPR_SWAT_W2_8 = 239;
3014         SPR_SWAT_W3_1 = 240;
3015         SPR_SWAT_W3_2 = 241;
3016         SPR_SWAT_W3_3 = 242;
3017         SPR_SWAT_W3_4 = 243;
3018         SPR_SWAT_W3_5 = 244;
3019         SPR_SWAT_W3_6 = 245;
3020         SPR_SWAT_W3_7 = 246;
3021         SPR_SWAT_W3_8 = 247;
3022         SPR_SWAT_W4_1 = 248;
3023         SPR_SWAT_W4_2 = 249;
3024         SPR_SWAT_W4_3 = 250;
3025         SPR_SWAT_W4_4 = 251;
3026         SPR_SWAT_W4_5 = 252;
3027         SPR_SWAT_W4_6 = 253;
3028         SPR_SWAT_W4_7 = 254;
3029         SPR_SWAT_W4_8 = 255;
3030         SPR_SWAT_PAIN_1 = 256;
3031         SPR_SWAT_DIE_1 = 257;
3032         SPR_SWAT_DIE_2 = 258;
3033         SPR_SWAT_DIE_3 = 259;
3034         SPR_SWAT_PAIN_2 = 260;
3035         SPR_SWAT_DIE_4 = 261;
3036         SPR_SWAT_DEAD = 262;
3037         SPR_SWAT_SHOOT1 = 263;
3038         SPR_SWAT_SHOOT2 = 264;
3039         SPR_SWAT_SHOOT3 = 265;
3040         SPR_SWAT_WOUNDED1 = 266;
3041         SPR_SWAT_WOUNDED2 = 267;
3042         SPR_SWAT_WOUNDED3 = 268;
3043         SPR_SWAT_WOUNDED4 = 269;
3044 
3045         SPR_OFC_S_1 = 270;
3046         SPR_OFC_S_2 = 271;
3047         SPR_OFC_S_3 = 272;
3048         SPR_OFC_S_4 = 273;
3049         SPR_OFC_S_5 = 274;
3050         SPR_OFC_S_6 = 275;
3051         SPR_OFC_S_7 = 276;
3052         SPR_OFC_S_8 = 277;
3053         SPR_OFC_W1_1 = 278;
3054         SPR_OFC_W1_2 = 279;
3055         SPR_OFC_W1_3 = 280;
3056         SPR_OFC_W1_4 = 281;
3057         SPR_OFC_W1_5 = 282;
3058         SPR_OFC_W1_6 = 283;
3059         SPR_OFC_W1_7 = 284;
3060         SPR_OFC_W1_8 = 285;
3061         SPR_OFC_W2_1 = 286;
3062         SPR_OFC_W2_2 = 287;
3063         SPR_OFC_W2_3 = 288;
3064         SPR_OFC_W2_4 = 289;
3065         SPR_OFC_W2_5 = 290;
3066         SPR_OFC_W2_6 = 291;
3067         SPR_OFC_W2_7 = 292;
3068         SPR_OFC_W2_8 = 293;
3069         SPR_OFC_W3_1 = 294;
3070         SPR_OFC_W3_2 = 295;
3071         SPR_OFC_W3_3 = 296;
3072         SPR_OFC_W3_4 = 297;
3073         SPR_OFC_W3_5 = 298;
3074         SPR_OFC_W3_6 = 299;
3075         SPR_OFC_W3_7 = 300;
3076         SPR_OFC_W3_8 = 301;
3077         SPR_OFC_W4_1 = 302;
3078         SPR_OFC_W4_2 = 303;
3079         SPR_OFC_W4_3 = 304;
3080         SPR_OFC_W4_4 = 305;
3081         SPR_OFC_W4_5 = 306;
3082         SPR_OFC_W4_6 = 307;
3083         SPR_OFC_W4_7 = 308;
3084         SPR_OFC_W4_8 = 309;
3085         SPR_OFC_PAIN_1 = 310;
3086         SPR_OFC_DIE_1 = 311;
3087         SPR_OFC_DIE_2 = 312;
3088         SPR_OFC_DIE_3 = 313;
3089         SPR_OFC_PAIN_2 = 314;
3090         SPR_OFC_DIE_4 = 315;
3091         SPR_OFC_DEAD = 316;
3092         SPR_OFC_SHOOT1 = 317;
3093         SPR_OFC_SHOOT2 = 318;
3094         SPR_OFC_SHOOT3 = 319;
3095 
3096         SPR_GOLD_S_1 = 320;
3097         SPR_GOLD_S_2 = 321;
3098         SPR_GOLD_S_3 = 322;
3099         SPR_GOLD_S_4 = 323;
3100         SPR_GOLD_S_5 = 324;
3101         SPR_GOLD_S_6 = 325;
3102         SPR_GOLD_S_7 = 326;
3103         SPR_GOLD_S_8 = 327;
3104         SPR_GOLD_W1_1 = 328;
3105         SPR_GOLD_W1_2 = 329;
3106         SPR_GOLD_W1_3 = 330;
3107         SPR_GOLD_W1_4 = 331;
3108         SPR_GOLD_W1_5 = 332;
3109         SPR_GOLD_W1_6 = 333;
3110         SPR_GOLD_W1_7 = 334;
3111         SPR_GOLD_W1_8 = 335;
3112         SPR_GOLD_W2_1 = 336;
3113         SPR_GOLD_W2_2 = 337;
3114         SPR_GOLD_W2_3 = 338;
3115         SPR_GOLD_W2_4 = 339;
3116         SPR_GOLD_W2_5 = 340;
3117         SPR_GOLD_W2_6 = 341;
3118         SPR_GOLD_W2_7 = 342;
3119         SPR_GOLD_W2_8 = 343;
3120         SPR_GOLD_W3_1 = 344;
3121         SPR_GOLD_W3_2 = 345;
3122         SPR_GOLD_W3_3 = 346;
3123         SPR_GOLD_W3_4 = 347;
3124         SPR_GOLD_W3_5 = 348;
3125         SPR_GOLD_W3_6 = 349;
3126         SPR_GOLD_W3_7 = 350;
3127         SPR_GOLD_W3_8 = 351;
3128         SPR_GOLD_W4_1 = 352;
3129         SPR_GOLD_W4_2 = 353;
3130         SPR_GOLD_W4_3 = 354;
3131         SPR_GOLD_W4_4 = 355;
3132         SPR_GOLD_W4_5 = 356;
3133         SPR_GOLD_W4_6 = 357;
3134         SPR_GOLD_W4_7 = 358;
3135         SPR_GOLD_W4_8 = 359;
3136         SPR_GOLD_PAIN_1 = 360;
3137         SPR_GOLD_WRIST_1 = 361;
3138         SPR_GOLD_WRIST_2 = 362;
3139         SPR_GOLD_SHOOT1 = 363;
3140         SPR_GOLD_SHOOT2 = 364;
3141         SPR_GOLD_SHOOT3 = 365;
3142         SPR_GOLD_WARP1 = 366;
3143         SPR_GOLD_WARP2 = 367;
3144         SPR_GOLD_WARP3 = 368;
3145         SPR_GOLD_WARP4 = 369;
3146         SPR_GOLD_WARP5 = 370;
3147         SPR_GOLD_DEATH1 = 371;
3148         SPR_GOLD_DEATH2 = 372;
3149         SPR_GOLD_DEATH3 = 373;
3150         SPR_GOLD_DEATH4 = 374;
3151         SPR_GOLD_DEATH5 = 375;
3152         SPR_MGOLD_OUCH = 376;
3153         SPR_GOLD_MORPH1 = 377;
3154         SPR_GOLD_MORPH2 = 378;
3155         SPR_GOLD_MORPH3 = 379;
3156         SPR_GOLD_MORPH4 = 380;
3157         SPR_GOLD_MORPH5 = 381;
3158         SPR_GOLD_MORPH6 = 382;
3159         SPR_GOLD_MORPH7 = 383;
3160         SPR_GOLD_MORPH8 = 384;
3161 
3162         SPR_MGOLD_WALK1 = 385;
3163         SPR_MGOLD_WALK2 = 386;
3164         SPR_MGOLD_WALK3 = 387;
3165         SPR_MGOLD_WALK4 = 388;
3166         SPR_MGOLD_ATTACK1 = 389;
3167         SPR_MGOLD_ATTACK2 = 390;
3168         SPR_MGOLD_ATTACK3 = 391;
3169         SPR_MGOLD_ATTACK4 = 392;
3170         SPR_MGOLD_SHOT1 = 393;
3171         SPR_MGOLD_SHOT2 = 394;
3172         SPR_MGOLD_SHOT3 = 395;
3173         SPR_MGOLD_SHOT_EXP1 = 396;
3174         SPR_MGOLD_SHOT_EXP2 = 397;
3175         SPR_MGOLD_SHOT_EXP3 = 398;
3176 
3177         SPR_GSCOUT_W1_1 = 399;
3178         SPR_GSCOUT_W1_2 = 400;
3179         SPR_GSCOUT_W1_3 = 401;
3180         SPR_GSCOUT_W1_4 = 402;
3181         SPR_GSCOUT_W1_5 = 403;
3182         SPR_GSCOUT_W1_6 = 404;
3183         SPR_GSCOUT_W1_7 = 405;
3184         SPR_GSCOUT_W1_8 = 406;
3185         SPR_GSCOUT_W2_1 = 407;
3186         SPR_GSCOUT_W2_2 = 408;
3187         SPR_GSCOUT_W2_3 = 409;
3188         SPR_GSCOUT_W2_4 = 410;
3189         SPR_GSCOUT_W2_5 = 411;
3190         SPR_GSCOUT_W2_6 = 412;
3191         SPR_GSCOUT_W2_7 = 413;
3192         SPR_GSCOUT_W2_8 = 414;
3193         SPR_GSCOUT_W3_1 = 415;
3194         SPR_GSCOUT_W3_2 = 416;
3195         SPR_GSCOUT_W3_3 = 417;
3196         SPR_GSCOUT_W3_4 = 418;
3197         SPR_GSCOUT_W3_5 = 419;
3198         SPR_GSCOUT_W3_6 = 420;
3199         SPR_GSCOUT_W3_7 = 421;
3200         SPR_GSCOUT_W3_8 = 422;
3201         SPR_GSCOUT_W4_1 = 423;
3202         SPR_GSCOUT_W4_2 = 424;
3203         SPR_GSCOUT_W4_3 = 425;
3204         SPR_GSCOUT_W4_4 = 426;
3205         SPR_GSCOUT_W4_5 = 427;
3206         SPR_GSCOUT_W4_6 = 428;
3207         SPR_GSCOUT_W4_7 = 429;
3208         SPR_GSCOUT_W4_8 = 430;
3209         SPR_GSCOUT_DIE1 = 431;
3210         SPR_GSCOUT_DIE2 = 432;
3211         SPR_GSCOUT_DIE3 = 433;
3212         SPR_GSCOUT_DIE4 = 434;
3213         SPR_GSCOUT_DIE5 = 435;
3214         SPR_GSCOUT_DIE6 = 436;
3215         SPR_GSCOUT_DIE7 = 437;
3216         SPR_GSCOUT_DIE8 = 438;
3217         SPR_GSCOUT_DEAD = 439;
3218 
3219         SPR_FSCOUT_W1_1 = 440;
3220         SPR_FSCOUT_W1_2 = 441;
3221         SPR_FSCOUT_W1_3 = 442;
3222         SPR_FSCOUT_W1_4 = 443;
3223         SPR_FSCOUT_W1_5 = 444;
3224         SPR_FSCOUT_W1_6 = 445;
3225         SPR_FSCOUT_W1_7 = 446;
3226         SPR_FSCOUT_W1_8 = 447;
3227         SPR_FSCOUT_W2_1 = 448;
3228         SPR_FSCOUT_W2_2 = 449;
3229         SPR_FSCOUT_W2_3 = 450;
3230         SPR_FSCOUT_W2_4 = 451;
3231         SPR_FSCOUT_W2_5 = 452;
3232         SPR_FSCOUT_W2_6 = 453;
3233         SPR_FSCOUT_W2_7 = 454;
3234         SPR_FSCOUT_W2_8 = 455;
3235         SPR_FSCOUT_W3_1 = 456;
3236         SPR_FSCOUT_W3_2 = 457;
3237         SPR_FSCOUT_W3_3 = 458;
3238         SPR_FSCOUT_W3_4 = 459;
3239         SPR_FSCOUT_W3_5 = 460;
3240         SPR_FSCOUT_W3_6 = 461;
3241         SPR_FSCOUT_W3_7 = 462;
3242         SPR_FSCOUT_W3_8 = 463;
3243         SPR_FSCOUT_W4_1 = 464;
3244         SPR_FSCOUT_W4_2 = 465;
3245         SPR_FSCOUT_W4_3 = 466;
3246         SPR_FSCOUT_W4_4 = 467;
3247         SPR_FSCOUT_W4_5 = 468;
3248         SPR_FSCOUT_W4_6 = 469;
3249         SPR_FSCOUT_W4_7 = 470;
3250         SPR_FSCOUT_W4_8 = 471;
3251         SPR_FSCOUT_DIE1 = 472;
3252         SPR_FSCOUT_DIE2 = 473;
3253         SPR_FSCOUT_DIE3 = 474;
3254         SPR_FSCOUT_DIE4 = 475;
3255         SPR_FSCOUT_DIE5 = 476;
3256         SPR_FSCOUT_DIE6 = 477;
3257         SPR_FSCOUT_DIE7 = 478;
3258         SPR_FSCOUT_DEAD = 479;
3259 
3260         SPR_EXPLOSION_1 = 480;
3261         SPR_EXPLOSION_2 = 481;
3262         SPR_EXPLOSION_3 = 482;
3263         SPR_EXPLOSION_4 = 483;
3264         SPR_EXPLOSION_5 = 484;
3265 
3266         SPR_CUBE1 = 485;
3267         SPR_CUBE2 = 486;
3268         SPR_CUBE3 = 487;
3269         SPR_CUBE4 = 488;
3270         SPR_CUBE5 = 489;
3271         SPR_CUBE6 = 490;
3272         SPR_CUBE7 = 491;
3273         SPR_CUBE8 = 492;
3274         SPR_CUBE9 = 493;
3275         SPR_CUBE10 = 494;
3276         SPR_CUBE_EXP1 = 495;
3277         SPR_CUBE_EXP2 = 496;
3278         SPR_CUBE_EXP3 = 497;
3279         SPR_CUBE_EXP4 = 498;
3280         SPR_CUBE_EXP5 = 499;
3281         SPR_CUBE_EXP6 = 500;
3282         SPR_CUBE_EXP7 = 501;
3283         SPR_CUBE_EXP8 = 502;
3284         SPR_DEAD_CUBE = 503;
3285 
3286         SPR_SECURITY_NORMAL = 504;
3287         SPR_SECURITY_ALERT = 505;
3288 
3289         SPR_POD_EGG = 506;
3290         SPR_POD_HATCH1 = 507;
3291         SPR_POD_HATCH2 = 508;
3292         SPR_POD_HATCH3 = 509;
3293         SPR_POD_WALK1 = 510;
3294         SPR_POD_WALK2 = 511;
3295         SPR_POD_WALK3 = 512;
3296         SPR_POD_WALK4 = 513;
3297         SPR_POD_ATTACK1 = 514;
3298         SPR_POD_ATTACK2 = 515;
3299         SPR_POD_ATTACK3 = 516;
3300         SPR_POD_OUCH = 517;
3301         SPR_POD_DIE1 = 518;
3302         SPR_POD_DIE2 = 519;
3303         SPR_POD_DIE3 = 520;
3304         SPR_POD_SPIT1 = 521;
3305         SPR_POD_SPIT2 = 522;
3306         SPR_POD_SPIT3 = 523;
3307 
3308         SPR_ELEC_APPEAR1 = 524;
3309         SPR_ELEC_APPEAR2 = 525;
3310         SPR_ELEC_APPEAR3 = 526;
3311         SPR_ELEC_WALK1 = 527;
3312         SPR_ELEC_WALK2 = 528;
3313         SPR_ELEC_WALK3 = 529;
3314         SPR_ELEC_WALK4 = 530;
3315         SPR_ELEC_OUCH = 531;
3316         SPR_ELEC_SHOOT1 = 532;
3317         SPR_ELEC_SHOOT2 = 533;
3318         SPR_ELEC_SHOOT3 = 534;
3319         SPR_ELEC_DIE1 = 535;
3320         SPR_ELEC_DIE2 = 536;
3321         SPR_ELEC_DIE3 = 537;
3322         SPR_ELEC_SHOT1 = 538;
3323         SPR_ELEC_SHOT2 = 539;
3324         SPR_ELEC_SHOT_EXP1 = 540;
3325         SPR_ELEC_SHOT_EXP2 = 541;
3326 
3327         SPR_ELECTRO_SPHERE_ROAM1 = 542;
3328         SPR_ELECTRO_SPHERE_ROAM2 = 543;
3329         SPR_ELECTRO_SPHERE_ROAM3 = 544;
3330         SPR_ELECTRO_SPHERE_OUCH = 545;
3331         SPR_ELECTRO_SPHERE_DIE1 = 546;
3332         SPR_ELECTRO_SPHERE_DIE2 = 547;
3333         SPR_ELECTRO_SPHERE_DIE3 = 548;
3334         SPR_ELECTRO_SPHERE_DIE4 = 549;
3335 
3336         SPR_GENETIC_W1 = 550;
3337         SPR_GENETIC_W2 = 551;
3338         SPR_GENETIC_W3 = 552;
3339         SPR_GENETIC_W4 = 553;
3340         SPR_GENETIC_SWING1 = 554;
3341         SPR_GENETIC_SWING2 = 555;
3342         SPR_GENETIC_SWING3 = 556;
3343         SPR_GENETIC_DEAD = 557;
3344         SPR_GENETIC_DIE1 = 558;
3345         SPR_GENETIC_DIE2 = 559;
3346         SPR_GENETIC_DIE3 = 560;
3347         SPR_GENETIC_DIE4 = 561;
3348         SPR_GENETIC_OUCH = 562;
3349         SPR_GENETIC_SHOOT1 = 563;
3350         SPR_GENETIC_SHOOT2 = 564;
3351         SPR_GENETIC_SHOOT3 = 565;
3352 
3353         SPR_MUTHUM1_W1 = 566;
3354         SPR_MUTHUM1_W2 = 567;
3355         SPR_MUTHUM1_W3 = 568;
3356         SPR_MUTHUM1_W4 = 569;
3357         SPR_MUTHUM1_SWING1 = 570;
3358         SPR_MUTHUM1_SWING2 = 571;
3359         SPR_MUTHUM1_SWING3 = 572;
3360         SPR_MUTHUM1_DEAD = 573;
3361         SPR_MUTHUM1_DIE1 = 574;
3362         SPR_MUTHUM1_DIE2 = 575;
3363         SPR_MUTHUM1_DIE3 = 576;
3364         SPR_MUTHUM1_DIE4 = 577;
3365         SPR_MUTHUM1_OUCH = 578;
3366         SPR_MUTHUM1_SPIT1 = 579;
3367         SPR_MUTHUM1_SPIT2 = 580;
3368         SPR_MUTHUM1_SPIT3 = 581;
3369 
3370         SPR_MUTHUM2_W1 = 582;
3371         SPR_MUTHUM2_W2 = 583;
3372         SPR_MUTHUM2_W3 = 584;
3373         SPR_MUTHUM2_W4 = 585;
3374         SPR_MUTHUM2_SWING1 = 586;
3375         SPR_MUTHUM2_SWING2 = 587;
3376         SPR_MUTHUM2_SWING3 = 588;
3377         SPR_MUTHUM2_DEAD = 589;
3378         SPR_MUTHUM2_DIE1 = 590;
3379         SPR_MUTHUM2_DIE2 = 591;
3380         SPR_MUTHUM2_DIE3 = 592;
3381         SPR_MUTHUM2_DIE4 = 593;
3382         SPR_MUTHUM2_OUCH = 594;
3383         SPR_MUTHUM2_SPIT1 = 595;
3384         SPR_MUTHUM2_SPIT2 = 596;
3385         SPR_MUTHUM2_SPIT3 = 597;
3386         SPR_MUTHUM2_MORPH1 = 598;
3387         SPR_MUTHUM2_MORPH2 = 599;
3388         SPR_MUTHUM2_MORPH3 = 600;
3389         SPR_MUTHUM2_MORPH4 = 601;
3390         SPR_MUTHUM2_MORPH5 = 602;
3391         SPR_MUTHUM2_MORPH6 = 603;
3392         SPR_MUTHUM2_MORPH7 = 604;
3393         SPR_MUTHUM2_MORPH8 = 605;
3394         SPR_MUTHUM2_MORPH9 = 606;
3395 
3396         SPR_LCAN_ALIEN_READY = 607;
3397         SPR_LCAN_ALIEN_B1 = 608;
3398         SPR_LCAN_ALIEN_B2 = 609;
3399         SPR_LCAN_ALIEN_B3 = 610;
3400         SPR_LCAN_ALIEN_EMPTY = 611;
3401         SPR_LCAN_ALIEN_W1 = 612;
3402         SPR_LCAN_ALIEN_W2 = 613;
3403         SPR_LCAN_ALIEN_W3 = 614;
3404         SPR_LCAN_ALIEN_W4 = 615;
3405         SPR_LCAN_ALIEN_SWING1 = 616;
3406         SPR_LCAN_ALIEN_SWING2 = 617;
3407         SPR_LCAN_ALIEN_SWING3 = 618;
3408         SPR_LCAN_ALIEN_DEAD = 619;
3409         SPR_LCAN_ALIEN_DIE1 = 620;
3410         SPR_LCAN_ALIEN_DIE2 = 621;
3411         SPR_LCAN_ALIEN_DIE3 = 622;
3412         SPR_LCAN_ALIEN_DIE4 = 623;
3413         SPR_LCAN_ALIEN_OUCH = 624;
3414         SPR_LCAN_ALIEN_SPIT1 = 625;
3415         SPR_LCAN_ALIEN_SPIT2 = 626;
3416         SPR_LCAN_ALIEN_SPIT3 = 627;
3417 
3418         SPR_SCAN_ALIEN_READY = 628;
3419         SPR_SCAN_ALIEN_B1 = 629;
3420         SPR_SCAN_ALIEN_B2 = 630;
3421         SPR_SCAN_ALIEN_B3 = 631;
3422         SPR_SCAN_ALIEN_EMPTY = 632;
3423         SPR_SCAN_ALIEN_W1 = 633;
3424         SPR_SCAN_ALIEN_W2 = 634;
3425         SPR_SCAN_ALIEN_W3 = 635;
3426         SPR_SCAN_ALIEN_W4 = 636;
3427         SPR_SCAN_ALIEN_SWING1 = 637;
3428         SPR_SCAN_ALIEN_SWING2 = 638;
3429         SPR_SCAN_ALIEN_SWING3 = 639;
3430         SPR_SCAN_ALIEN_DEAD = 640;
3431         SPR_SCAN_ALIEN_DIE1 = 641;
3432         SPR_SCAN_ALIEN_DIE2 = 642;
3433         SPR_SCAN_ALIEN_DIE3 = 643;
3434         SPR_SCAN_ALIEN_DIE4 = 644;
3435         SPR_SCAN_ALIEN_OUCH = 645;
3436         SPR_SCAN_ALIEN_SPIT1 = 646;
3437         SPR_SCAN_ALIEN_SPIT2 = 647;
3438         SPR_SCAN_ALIEN_SPIT3 = 648;
3439 
3440         SPR_GURNEY_MUT_READY = 649;
3441         SPR_GURNEY_MUT_B1 = 650;
3442         SPR_GURNEY_MUT_B2 = 651;
3443         SPR_GURNEY_MUT_B3 = 652;
3444         SPR_GURNEY_MUT_EMPTY = 653;
3445         SPR_GURNEY_MUT_W1 = 654;
3446         SPR_GURNEY_MUT_W2 = 655;
3447         SPR_GURNEY_MUT_W3 = 656;
3448         SPR_GURNEY_MUT_W4 = 657;
3449         SPR_GURNEY_MUT_SWING1 = 658;
3450         SPR_GURNEY_MUT_SWING2 = 659;
3451         SPR_GURNEY_MUT_SWING3 = 660;
3452         SPR_GURNEY_MUT_DEAD = 661;
3453         SPR_GURNEY_MUT_DIE1 = 662;
3454         SPR_GURNEY_MUT_DIE2 = 663;
3455         SPR_GURNEY_MUT_DIE3 = 664;
3456         SPR_GURNEY_MUT_DIE4 = 665;
3457         SPR_GURNEY_MUT_OUCH = 666;
3458 
3459         SPR_LIQUID_M1 = 667;
3460         SPR_LIQUID_M2 = 668;
3461         SPR_LIQUID_M3 = 669;
3462         SPR_LIQUID_R1 = 670;
3463         SPR_LIQUID_R2 = 671;
3464         SPR_LIQUID_R3 = 672;
3465         SPR_LIQUID_R4 = 673;
3466         SPR_LIQUID_S1 = 674;
3467         SPR_LIQUID_S2 = 675;
3468         SPR_LIQUID_S3 = 676;
3469         SPR_LIQUID_OUCH = 677;
3470         SPR_LIQUID_DIE_1 = 678;
3471         SPR_LIQUID_DIE_2 = 679;
3472         SPR_LIQUID_DIE_3 = 680;
3473         SPR_LIQUID_DIE_4 = 681;
3474         SPR_LIQUID_DEAD = 682;
3475         SPR_LIQUID_SHOT_FLY_1 = 683;
3476         SPR_LIQUID_SHOT_FLY_2 = 684;
3477         SPR_LIQUID_SHOT_FLY_3 = 685;
3478         SPR_LIQUID_SHOT_BURST_1 = 686;
3479         SPR_LIQUID_SHOT_BURST_2 = 687;
3480         SPR_LIQUID_SHOT_BURST_3 = 688;
3481 
3482         SPR_SPIT1_1 = 689;
3483         SPR_SPIT1_2 = 690;
3484         SPR_SPIT1_3 = 691;
3485         SPR_SPIT_EXP1_1 = 692;
3486         SPR_SPIT_EXP1_2 = 693;
3487         SPR_SPIT_EXP1_3 = 694;
3488 
3489         SPR_SPIT2_1 = 695;
3490         SPR_SPIT2_2 = 696;
3491         SPR_SPIT2_3 = 697;
3492         SPR_SPIT_EXP2_1 = 698;
3493         SPR_SPIT_EXP2_2 = 699;
3494         SPR_SPIT_EXP2_3 = 700;
3495 
3496         SPR_SPIT3_1 = 701;
3497         SPR_SPIT3_2 = 702;
3498         SPR_SPIT3_3 = 703;
3499         SPR_SPIT_EXP3_1 = 704;
3500         SPR_SPIT_EXP3_2 = 705;
3501         SPR_SPIT_EXP3_3 = 706;
3502 
3503         SPR_TERROT_1 = 707;
3504         SPR_TERROT_2 = 708;
3505         SPR_TERROT_3 = 709;
3506         SPR_TERROT_4 = 710;
3507         SPR_TERROT_5 = 711;
3508         SPR_TERROT_6 = 712;
3509         SPR_TERROT_7 = 713;
3510         SPR_TERROT_8 = 714;
3511         SPR_TERROT_FIRE_1 = 715;
3512         SPR_TERROT_FIRE_2 = 716;
3513         SPR_TERROT_DIE_1 = 717;
3514         SPR_TERROT_DIE_2 = 718;
3515         SPR_TERROT_DIE_3 = 719;
3516         SPR_TERROT_DIE_4 = 720;
3517         SPR_TERROT_DEAD = 721;
3518 
3519         SPR_KNIFEREADY = 722;
3520         SPR_KNIFEATK1 = 723;
3521         SPR_KNIFEATK2 = 724;
3522         SPR_KNIFEATK3 = 725;
3523         SPR_KNIFEATK4 = 726;
3524 
3525         SPR_PISTOLREADY = 727;
3526         SPR_PISTOLATK1 = 728;
3527         SPR_PISTOLATK2 = 729;
3528         SPR_PISTOLATK3 = 730;
3529         SPR_PISTOLATK4 = 731;
3530 
3531         SPR_MACHINEGUNREADY = 732;
3532         SPR_MACHINEGUNATK1 = 733;
3533         SPR_MACHINEGUNATK2 = 734;
3534         SPR_MACHINEGUNATK3 = 735;
3535         SPR_MACHINEGUNATK4 = 736;
3536 
3537         SPR_CHAINREADY = 737;
3538         SPR_CHAINATK1 = 738;
3539         SPR_CHAINATK2 = 739;
3540         SPR_CHAINATK3 = 740;
3541         SPR_CHAINATK4 = 741;
3542 
3543         SPR_GRENADEREADY = 742;
3544         SPR_GRENADEATK1 = 743;
3545         SPR_GRENADEATK2 = 744;
3546         SPR_GRENADEATK3 = 745;
3547         SPR_GRENADEATK4 = 746;
3548         SPR_GRENADE_FLY1 = 747;
3549         SPR_GRENADE_FLY2 = 748;
3550         SPR_GRENADE_FLY3 = 749;
3551         SPR_GRENADE_FLY4 = 750;
3552         SPR_GRENADE_EXPLODE1 = 751;
3553         SPR_GRENADE_EXPLODE2 = 752;
3554         SPR_GRENADE_EXPLODE3 = 753;
3555         SPR_GRENADE_EXPLODE4 = 754;
3556         SPR_GRENADE_EXPLODE5 = 755;
3557 
3558         SPR_ELEC_ARC1 = 756;
3559         SPR_ELEC_ARC2 = 757;
3560         SPR_ELEC_ARC3 = 758;
3561         SPR_ELEC_ARC4 = 759;
3562         SPR_ELEC_POST1 = 760;
3563         SPR_ELEC_POST2 = 761;
3564         SPR_ELEC_POST3 = 762;
3565         SPR_ELEC_POST4 = 763;
3566 
3567         SPR_VPOST1 = 764;
3568         SPR_VPOST2 = 765;
3569         SPR_VPOST3 = 766;
3570         SPR_VPOST4 = 767;
3571         SPR_VPOST5 = 768;
3572         SPR_VPOST6 = 769;
3573         SPR_VPOST7 = 770;
3574         SPR_VPOST8 = 771;
3575 
3576         SPR_VSPIKE1 = 772;
3577         SPR_VSPIKE2 = 773;
3578         SPR_VSPIKE3 = 774;
3579         SPR_VSPIKE4 = 775;
3580         SPR_VSPIKE5 = 776;
3581         SPR_VSPIKE6 = 777;
3582         SPR_VSPIKE7 = 778;
3583         SPR_VSPIKE8 = 779;
3584 
3585         SPR_GREEN_OOZE1 = 780;
3586         SPR_GREEN_OOZE2 = 781;
3587         SPR_GREEN_OOZE3 = 782;
3588 
3589         SPR_BLACK_OOZE1 = 783;
3590         SPR_BLACK_OOZE2 = 784;
3591         SPR_BLACK_OOZE3 = 785;
3592 
3593         SPR_GREEN2_OOZE1 = 786;
3594         SPR_GREEN2_OOZE2 = 787;
3595         SPR_GREEN2_OOZE3 = 788;
3596 
3597         SPR_BLACK2_OOZE1 = 789;
3598         SPR_BLACK2_OOZE2 = 790;
3599         SPR_BLACK2_OOZE3 = 791;
3600 
3601         SPR_CANDY_BAR = 792;
3602         SPR_CANDY_WRAPER = 793;
3603 
3604         SPR_SANDWICH = 794;
3605         SPR_SANDWICH_WRAPER = 795;
3606 
3607         SPR_BLAKE_W1 = 796;
3608         SPR_BLAKE_W2 = 797;
3609         SPR_BLAKE_W3 = 798;
3610         SPR_BLAKE_W4 = 799;
3611 
3612         SPR_BOSS1_W1 = 800;
3613         SPR_BOSS1_W2 = 801;
3614         SPR_BOSS1_W3 = 802;
3615         SPR_BOSS1_W4 = 803;
3616         SPR_BOSS1_SWING1 = 804;
3617         SPR_BOSS1_SWING2 = 805;
3618         SPR_BOSS1_SWING3 = 806;
3619         SPR_BOSS1_DEAD = 807;
3620         SPR_BOSS1_DIE1 = 808;
3621         SPR_BOSS1_DIE2 = 809;
3622         SPR_BOSS1_DIE3 = 810;
3623         SPR_BOSS1_DIE4 = 811;
3624         SPR_BOSS1_OUCH = 812;
3625         SPR_BOSS1_PROJ1 = 813;
3626         SPR_BOSS1_PROJ2 = 814;
3627         SPR_BOSS1_PROJ3 = 815;
3628         SPR_BOSS1_EXP1 = 816;
3629         SPR_BOSS1_EXP2 = 817;
3630         SPR_BOSS1_EXP3 = 818;
3631         SPR_BOSS1_MORPH1 = 819;
3632         SPR_BOSS1_MORPH2 = 820;
3633         SPR_BOSS1_MORPH3 = 821;
3634         SPR_BOSS1_MORPH4 = 822;
3635         SPR_BOSS1_MORPH5 = 823;
3636         SPR_BOSS1_MORPH6 = 824;
3637         SPR_BOSS1_MORPH7 = 825;
3638         SPR_BOSS1_MORPH8 = 826;
3639         SPR_BOSS1_MORPH9 = 827;
3640 
3641         SPR_BOSS2_W1 = 828;
3642         SPR_BOSS2_W2 = 829;
3643         SPR_BOSS2_W3 = 830;
3644         SPR_BOSS2_W4 = 831;
3645         SPR_BOSS2_SWING1 = 832;
3646         SPR_BOSS2_SWING2 = 833;
3647         SPR_BOSS2_SWING3 = 834;
3648         SPR_BOSS2_DEAD = 835;
3649         SPR_BOSS2_DIE1 = 836;
3650         SPR_BOSS2_DIE2 = 837;
3651         SPR_BOSS2_DIE3 = 838;
3652         SPR_BOSS2_DIE4 = 839;
3653         SPR_BOSS2_OUCH = 840;
3654 
3655         SPR_BOSS3_W1 = 841;
3656         SPR_BOSS3_W2 = 842;
3657         SPR_BOSS3_W3 = 843;
3658         SPR_BOSS3_W4 = 844;
3659         SPR_BOSS3_SWING1 = 845;
3660         SPR_BOSS3_SWING2 = 846;
3661         SPR_BOSS3_SWING3 = 847;
3662         SPR_BOSS3_DEAD = 848;
3663         SPR_BOSS3_DIE1 = 849;
3664         SPR_BOSS3_DIE2 = 850;
3665         SPR_BOSS3_DIE3 = 851;
3666         SPR_BOSS3_DIE4 = 852;
3667         SPR_BOSS3_OUCH = 853;
3668 
3669         SPR_BOSS4_W1 = 854;
3670         SPR_BOSS4_W2 = 855;
3671         SPR_BOSS4_W3 = 856;
3672         SPR_BOSS4_W4 = 857;
3673         SPR_BOSS4_SWING1 = 858;
3674         SPR_BOSS4_SWING2 = 859;
3675         SPR_BOSS4_SWING3 = 860;
3676         SPR_BOSS4_DEAD = 861;
3677         SPR_BOSS4_DIE1 = 862;
3678         SPR_BOSS4_DIE2 = 863;
3679         SPR_BOSS4_DIE3 = 864;
3680         SPR_BOSS4_DIE4 = 865;
3681         SPR_BOSS4_OUCH = 866;
3682         SPR_BOSS4_MORPH1 = 867;
3683         SPR_BOSS4_MORPH2 = 868;
3684         SPR_BOSS4_MORPH3 = 869;
3685         SPR_BOSS4_MORPH4 = 870;
3686         SPR_BOSS4_MORPH5 = 871;
3687         SPR_BOSS4_MORPH6 = 872;
3688         SPR_BOSS4_MORPH7 = 873;
3689         SPR_BOSS4_MORPH8 = 874;
3690         SPR_BOSS4_MORPH9 = 875;
3691 
3692         SPR_BOSS5_W1 = 876;
3693         SPR_BOSS5_W2 = 877;
3694         SPR_BOSS5_W3 = 878;
3695         SPR_BOSS5_W4 = 879;
3696         SPR_BOSS5_SWING1 = 880;
3697         SPR_BOSS5_SWING2 = 881;
3698         SPR_BOSS5_SWING3 = 882;
3699         SPR_BOSS5_DEAD = 883;
3700         SPR_BOSS5_DIE1 = 884;
3701         SPR_BOSS5_DIE2 = 885;
3702         SPR_BOSS5_DIE3 = 886;
3703         SPR_BOSS5_DIE4 = 887;
3704         SPR_BOSS5_OUCH = 888;
3705         SPR_BOSS5_PROJ1 = 889;
3706         SPR_BOSS5_PROJ2 = 890;
3707         SPR_BOSS5_PROJ3 = 891;
3708         SPR_BOSS5_EXP1 = 892;
3709         SPR_BOSS5_EXP2 = 893;
3710         SPR_BOSS5_EXP3 = 894;
3711 
3712         SPR_BOSS6_W1 = 895;
3713         SPR_BOSS6_W2 = 896;
3714         SPR_BOSS6_W3 = 897;
3715         SPR_BOSS6_W4 = 898;
3716         SPR_BOSS6_SWING1 = 899;
3717         SPR_BOSS6_SWING2 = 900;
3718         SPR_BOSS6_SWING3 = 901;
3719         SPR_BOSS6_DEAD = 902;
3720         SPR_BOSS6_DIE1 = 903;
3721         SPR_BOSS6_DIE2 = 904;
3722         SPR_BOSS6_DIE3 = 905;
3723         SPR_BOSS6_DIE4 = 906;
3724         SPR_BOSS6_OUCH = 907;
3725 
3726         SPR_BOSS7_W1 = 908;
3727         SPR_BOSS7_W2 = 909;
3728         SPR_BOSS7_W3 = 910;
3729         SPR_BOSS7_W4 = 911;
3730         SPR_BOSS7_SHOOT1 = 912;
3731         SPR_BOSS7_SHOOT2 = 913;
3732         SPR_BOSS7_SHOOT3 = 914;
3733         SPR_BOSS7_DEAD = 915;
3734         SPR_BOSS7_DIE1 = 916;
3735         SPR_BOSS7_DIE2 = 917;
3736         SPR_BOSS7_DIE3 = 918;
3737         SPR_BOSS7_DIE4 = 919;
3738         SPR_BOSS7_OUCH = 920;
3739 
3740         SPR_BOSS8_W1 = 921;
3741         SPR_BOSS8_W2 = 922;
3742         SPR_BOSS8_W3 = 923;
3743         SPR_BOSS8_W4 = 924;
3744         SPR_BOSS8_SHOOT1 = 925;
3745         SPR_BOSS8_SHOOT2 = 926;
3746         SPR_BOSS8_SHOOT3 = 927;
3747         SPR_BOSS8_DIE1 = 928;
3748         SPR_BOSS8_DIE2 = 929;
3749         SPR_BOSS8_DIE3 = 930;
3750         SPR_BOSS8_DIE4 = 931;
3751         SPR_BOSS8_DEAD = 932;
3752         SPR_BOSS8_OUCH = 933;
3753 
3754         SPR_BOSS9_W1 = 934;
3755         SPR_BOSS9_W2 = 935;
3756         SPR_BOSS9_W3 = 936;
3757         SPR_BOSS9_W4 = 937;
3758         SPR_BOSS9_SHOOT1 = 938;
3759         SPR_BOSS9_SHOOT2 = 939;
3760         SPR_BOSS9_SHOOT3 = 940;
3761         SPR_BOSS9_DIE1 = 941;
3762         SPR_BOSS9_DIE2 = 942;
3763         SPR_BOSS9_DIE3 = 943;
3764         SPR_BOSS9_DIE4 = 944;
3765         SPR_BOSS9_DEAD = 945;
3766         SPR_BOSS9_OUCH = 946;
3767 
3768         SPR_BOSS10_W1 = 947;
3769         SPR_BOSS10_W2 = 948;
3770         SPR_BOSS10_W3 = 949;
3771         SPR_BOSS10_W4 = 950;
3772         SPR_BOSS10_SHOOT1 = 951;
3773         SPR_BOSS10_SHOOT2 = 952;
3774         SPR_BOSS10_SHOOT3 = 953;
3775         SPR_BOSS10_DEAD = 954;
3776         SPR_BOSS10_DIE1 = 955;
3777         SPR_BOSS10_DIE2 = 956;
3778         SPR_BOSS10_DIE3 = 957;
3779         SPR_BOSS10_DIE4 = 958;
3780         SPR_BOSS10_OUCH = 959;
3781         SPR_BOSS10_SPIT1 = 960;
3782         SPR_BOSS10_SPIT2 = 961;
3783         SPR_BOSS10_SPIT3 = 962;
3784         SPR_BOSS10_SPIT_EXP1 = 963;
3785         SPR_BOSS10_SPIT_EXP2 = 964;
3786         SPR_BOSS10_SPIT_EXP3 = 965;
3787 
3788         SPR_DETONATOR_EXP1 = 966;
3789         SPR_DETONATOR_EXP2 = 967;
3790         SPR_DETONATOR_EXP3 = 968;
3791         SPR_DETONATOR_EXP4 = 969;
3792         SPR_DETONATOR_EXP5 = 970;
3793         SPR_DETONATOR_EXP6 = 971;
3794         SPR_DETONATOR_EXP7 = 972;
3795         SPR_DETONATOR_EXP8 = 973;
3796 
3797         SPR_CLIP_EXP1 = 974;
3798         SPR_CLIP_EXP2 = 975;
3799         SPR_CLIP_EXP3 = 976;
3800         SPR_CLIP_EXP4 = 977;
3801         SPR_CLIP_EXP5 = 978;
3802         SPR_CLIP_EXP6 = 979;
3803         SPR_CLIP_EXP7 = 980;
3804         SPR_CLIP_EXP8 = 981;
3805 
3806         SPR_BFG_WEAPON1 = 982;
3807         SPR_BFG_WEAPON2 = 983;
3808         SPR_BFG_WEAPON3 = 984;
3809         SPR_BFG_WEAPON4 = 985;
3810         SPR_BFG_WEAPON5 = 986;
3811         SPR_BFG_WEAPON_SHOT1 = 987;
3812         SPR_BFG_WEAPON_SHOT2 = 988;
3813         SPR_BFG_WEAPON_SHOT3 = 989;
3814 
3815         SPR_BFG_EXP1 = 990;
3816         SPR_BFG_EXP2 = 991;
3817         SPR_BFG_EXP3 = 992;
3818         SPR_BFG_EXP4 = 993;
3819         SPR_BFG_EXP5 = 994;
3820         SPR_BFG_EXP6 = 995;
3821         SPR_BFG_EXP7 = 996;
3822         SPR_BFG_EXP8 = 997;
3823     }
3824 }
3825 
3826 
3827 // Sprites
3828 // ==========================================================================
3829 
3830 
3831 /*
3832 =============================================================================
3833 
3834  LOCAL VARIABLES
3835 
3836 =============================================================================
3837 */
3838 
3839 #if 0
3840 
3841 unsigned mspeed;
3842 
3843 void CalcSpeedRating()
3844 {
3845     int16_t loop;
3846 
3847     for (loop = 0; loop < 10; loop++) {
3848         ThreeDRefresh();
3849         mspeed += tics;
3850     }
3851 }
3852 
3853 #endif
3854 
3855 
3856 // BBi
3857 extern statetype s_ofs_stand;
3858 extern statetype s_ofs_chase1;
3859 extern statetype s_ofs_chase1s;
3860 extern statetype s_ofs_chase2;
3861 extern statetype s_ofs_chase3;
3862 extern statetype s_ofs_chase3s;
3863 extern statetype s_ofs_chase4;
3864 extern statetype s_ofs_pain;
3865 extern statetype s_ofs_die1;
3866 extern statetype s_ofs_die1s;
3867 extern statetype s_ofs_die2;
3868 extern statetype s_ofs_die3;
3869 extern statetype s_ofs_die4;
3870 extern statetype s_ofs_die5;
3871 extern statetype s_ofs_attack1;
3872 extern statetype s_ofs_attack2;
3873 extern statetype s_ofs_attack3;
3874 extern statetype s_ofs_spit1;
3875 extern statetype s_ofs_spit2;
3876 extern statetype s_ofs_spit3;
3877 extern statetype s_ofs_shoot1;
3878 extern statetype s_ofs_shoot2;
3879 extern statetype s_ofs_shoot3;
3880 extern statetype s_ofs_pod_attack1;
3881 extern statetype s_ofs_pod_attack1a;
3882 extern statetype s_ofs_pod_attack2;
3883 extern statetype s_ofs_pod_spit1;
3884 extern statetype s_ofs_pod_spit2;
3885 extern statetype s_ofs_pod_spit3;
3886 extern statetype s_ofs_pod_death1;
3887 extern statetype s_ofs_pod_death2;
3888 extern statetype s_ofs_pod_death3;
3889 extern statetype s_ofs_pod_ouch;
3890 extern statetype s_ofs_bounce;
3891 extern statetype s_ofs_ouch;
3892 extern statetype s_ofs_esphere_death1;
3893 extern statetype s_ofs_esphere_death2;
3894 extern statetype s_ofs_esphere_death3;
3895 extern statetype s_ofs_random;
3896 extern statetype s_ofs_static;
3897 extern statetype s_hold;
3898 extern statetype s_ofs_smart_anim;
3899 extern statetype s_ofs_smart_anim2;
3900 extern statetype s_barrier_transition;
3901 extern statetype s_vpost_barrier;
3902 extern statetype s_spike_barrier;
3903 extern statetype s_barrier_shutdown;
3904 extern statetype s_rent_stand;
3905 extern statetype s_rent_path1;
3906 extern statetype s_rent_path1s;
3907 extern statetype s_rent_path2;
3908 extern statetype s_rent_path3;
3909 extern statetype s_rent_path3s;
3910 extern statetype s_rent_path4;
3911 extern statetype s_rent_pain;
3912 extern statetype s_rent_shoot1;
3913 extern statetype s_rent_shoot2;
3914 extern statetype s_rent_shoot3;
3915 extern statetype s_rent_chase1;
3916 extern statetype s_rent_chase1s;
3917 extern statetype s_rent_chase2;
3918 extern statetype s_rent_chase3;
3919 extern statetype s_rent_chase3s;
3920 extern statetype s_rent_chase4;
3921 extern statetype s_rent_die1;
3922 extern statetype s_rent_die2;
3923 extern statetype s_rent_die3;
3924 extern statetype s_rent_die3s;
3925 extern statetype s_rent_die4;
3926 extern statetype s_ofcstand;
3927 extern statetype s_ofcpath1;
3928 extern statetype s_ofcpath1s;
3929 extern statetype s_ofcpath2;
3930 extern statetype s_ofcpath3;
3931 extern statetype s_ofcpath3s;
3932 extern statetype s_ofcpath4;
3933 extern statetype s_ofcpain;
3934 extern statetype s_ofcshoot1;
3935 extern statetype s_ofcshoot2;
3936 extern statetype s_ofcshoot3;
3937 extern statetype s_ofcchase1;
3938 extern statetype s_ofcchase1s;
3939 extern statetype s_ofcchase2;
3940 extern statetype s_ofcchase3;
3941 extern statetype s_ofcchase3s;
3942 extern statetype s_ofcchase4;
3943 extern statetype s_ofcdie1;
3944 extern statetype s_ofcdie2;
3945 extern statetype s_ofcdie3;
3946 extern statetype s_ofcdie4;
3947 extern statetype s_ofcdie5;
3948 extern statetype s_swatstand;
3949 extern statetype s_swatpath1;
3950 extern statetype s_swatpath1s;
3951 extern statetype s_swatpath2;
3952 extern statetype s_swatpath3;
3953 extern statetype s_swatpath3s;
3954 extern statetype s_swatpath4;
3955 extern statetype s_swatpain;
3956 extern statetype s_swatshoot1;
3957 extern statetype s_swatshoot2;
3958 extern statetype s_swatshoot3;
3959 extern statetype s_swatshoot4;
3960 extern statetype s_swatshoot5;
3961 extern statetype s_swatshoot6;
3962 extern statetype s_swatshoot7;
3963 extern statetype s_swatchase1;
3964 extern statetype s_swatchase1s;
3965 extern statetype s_swatchase2;
3966 extern statetype s_swatchase3;
3967 extern statetype s_swatchase3s;
3968 extern statetype s_swatchase4;
3969 extern statetype s_swatwounded1;
3970 extern statetype s_swatwounded2;
3971 extern statetype s_swatwounded3;
3972 extern statetype s_swatwounded4;
3973 extern statetype s_swatunwounded1;
3974 extern statetype s_swatunwounded2;
3975 extern statetype s_swatunwounded3;
3976 extern statetype s_swatunwounded4;
3977 extern statetype s_swatdie1;
3978 extern statetype s_swatdie2;
3979 extern statetype s_swatdie3;
3980 extern statetype s_swatdie4;
3981 extern statetype s_swatdie5;
3982 extern statetype s_prostand;
3983 extern statetype s_propath1;
3984 extern statetype s_propath1s;
3985 extern statetype s_propath2;
3986 extern statetype s_propath3;
3987 extern statetype s_propath3s;
3988 extern statetype s_propath4;
3989 extern statetype s_propain;
3990 extern statetype s_proshoot1;
3991 extern statetype s_proshoot2;
3992 extern statetype s_proshoot3;
3993 extern statetype s_proshoot4;
3994 extern statetype s_proshoot5;
3995 extern statetype s_proshoot6;
3996 extern statetype s_proshoot6a;
3997 extern statetype s_prochase1;
3998 extern statetype s_prochase1s;
3999 extern statetype s_prochase2;
4000 extern statetype s_prochase3;
4001 extern statetype s_prochase3s;
4002 extern statetype s_prochase4;
4003 extern statetype s_prodie1;
4004 extern statetype s_prodie2;
4005 extern statetype s_prodie3;
4006 extern statetype s_prodie3a;
4007 extern statetype s_prodie4;
4008 extern statetype s_electro_appear1;
4009 extern statetype s_electro_appear2;
4010 extern statetype s_electro_appear3;
4011 extern statetype s_electro_chase1;
4012 extern statetype s_electro_chase2;
4013 extern statetype s_electro_chase3;
4014 extern statetype s_electro_chase4;
4015 extern statetype s_electro_ouch;
4016 extern statetype s_electro_shoot1;
4017 extern statetype s_electro_shoot2;
4018 extern statetype s_electro_shoot3;
4019 extern statetype s_electro_shot1;
4020 extern statetype s_electro_shot2;
4021 extern statetype s_ofs_shot1;
4022 extern statetype s_ofs_shot2;
4023 extern statetype s_electro_die1;
4024 extern statetype s_electro_die2;
4025 extern statetype s_electro_die3;
4026 extern statetype s_liquid_wait;
4027 extern statetype s_liquid_move;
4028 extern statetype s_liquid_rise1;
4029 extern statetype s_liquid_rise2;
4030 extern statetype s_liquid_rise3;
4031 extern statetype s_liquid_stand;
4032 extern statetype s_liquid_fall1;
4033 extern statetype s_liquid_fall2;
4034 extern statetype s_liquid_fall3;
4035 extern statetype s_liquid_shoot1;
4036 extern statetype s_liquid_shoot2;
4037 extern statetype s_liquid_shoot3;
4038 extern statetype s_liquid_ouch;
4039 extern statetype s_liquid_die1;
4040 extern statetype s_liquid_die2;
4041 extern statetype s_liquid_die3;
4042 extern statetype s_liquid_die4;
4043 extern statetype s_liquid_dead;
4044 extern statetype s_liquid_shot;
4045 extern statetype s_blake1;
4046 extern statetype s_blake2;
4047 extern statetype s_blake3;
4048 extern statetype s_blake4;
4049 extern statetype s_goldstand;
4050 extern statetype s_goldpath1;
4051 extern statetype s_goldpath1s;
4052 extern statetype s_goldpath2;
4053 extern statetype s_goldpath3;
4054 extern statetype s_goldpath3s;
4055 extern statetype s_goldpath4;
4056 extern statetype s_goldpain;
4057 extern statetype s_goldshoot1;
4058 extern statetype s_goldshoot2;
4059 extern statetype s_goldshoot3;
4060 extern statetype s_goldshoot4;
4061 extern statetype s_goldshoot5;
4062 extern statetype s_goldshoot6;
4063 extern statetype s_goldshoot7;
4064 extern statetype s_goldchase1;
4065 extern statetype s_goldchase1s;
4066 extern statetype s_goldchase2;
4067 extern statetype s_goldchase3;
4068 extern statetype s_goldchase3s;
4069 extern statetype s_goldchase4;
4070 extern statetype s_goldwarp_it;
4071 extern statetype s_goldwarp_it1;
4072 extern statetype s_goldwarp_it2;
4073 extern statetype s_goldwarp_it3;
4074 extern statetype s_goldwarp_it4;
4075 extern statetype s_goldwarp_it5;
4076 extern statetype s_goldwarp_out1;
4077 extern statetype s_goldwarp_out2;
4078 extern statetype s_goldwarp_out3;
4079 extern statetype s_goldwarp_out4;
4080 extern statetype s_goldwarp_out5;
4081 extern statetype s_goldwarp_in1;
4082 extern statetype s_goldwarp_in2;
4083 extern statetype s_goldwarp_in3;
4084 extern statetype s_goldwarp_in4;
4085 extern statetype s_goldwarp_in5;
4086 extern statetype s_goldmorphwait1;
4087 extern statetype s_goldmorph1;
4088 extern statetype s_goldmorph2;
4089 extern statetype s_goldmorph3;
4090 extern statetype s_goldmorph4;
4091 extern statetype s_goldmorph5;
4092 extern statetype s_goldmorph6;
4093 extern statetype s_goldmorph7;
4094 extern statetype s_goldmorph8;
4095 extern statetype s_mgold_chase1;
4096 extern statetype s_mgold_chase2;
4097 extern statetype s_mgold_chase3;
4098 extern statetype s_mgold_chase4;
4099 extern statetype s_mgold_shoot1;
4100 extern statetype s_mgold_shoot2;
4101 extern statetype s_mgold_shoot3;
4102 extern statetype s_mgold_shoot4;
4103 extern statetype s_mgold_pain;
4104 extern statetype s_security_light;
4105 extern statetype s_scout_stand;
4106 extern statetype s_scout_path1;
4107 extern statetype s_scout_path2;
4108 extern statetype s_scout_path3;
4109 extern statetype s_scout_path4;
4110 extern statetype s_scout_run;
4111 extern statetype s_scout_run2;
4112 extern statetype s_scout_run3;
4113 extern statetype s_scout_run4;
4114 extern statetype s_scout_dead;
4115 extern statetype s_steamgrate;
4116 extern statetype s_steamrelease1;
4117 extern statetype s_steamrelease2;
4118 extern statetype s_steamrelease3;
4119 extern statetype s_steamrelease4;
4120 extern statetype s_steamrelease5;
4121 extern statetype s_steamrelease6;
4122 extern statetype s_terrot_wait;
4123 extern statetype s_terrot_found;
4124 extern statetype s_terrot_shoot1;
4125 extern statetype s_terrot_shoot2;
4126 extern statetype s_terrot_shoot3;
4127 extern statetype s_terrot_shoot4;
4128 extern statetype s_terrot_seek1;
4129 extern statetype s_terrot_seek1s;
4130 extern statetype s_terrot_die1;
4131 extern statetype s_terrot_die2;
4132 extern statetype s_terrot_die3;
4133 extern statetype s_terrot_die4;
4134 extern statetype s_terrot_die5;
4135 extern statetype s_player;
4136 extern statetype s_attack;
4137 
4138 
4139 statetype* states_list[] = {
4140     nullptr,
4141     &s_ofs_stand,
4142     &s_ofs_chase1,
4143     &s_ofs_chase1s,
4144     &s_ofs_chase2,
4145     &s_ofs_chase3,
4146     &s_ofs_chase3s,
4147     &s_ofs_chase4,
4148     &s_ofs_pain,
4149     &s_ofs_die1,
4150     &s_ofs_die1s,
4151     &s_ofs_die2,
4152     &s_ofs_die3,
4153     &s_ofs_die4,
4154     &s_ofs_die5,
4155     &s_ofs_attack1,
4156     &s_ofs_attack2,
4157     &s_ofs_attack3,
4158     &s_ofs_spit1,
4159     &s_ofs_spit2,
4160     &s_ofs_spit3,
4161     &s_ofs_shoot1,
4162     &s_ofs_shoot2,
4163     &s_ofs_shoot3,
4164     &s_ofs_pod_attack1,
4165     &s_ofs_pod_attack1a,
4166     &s_ofs_pod_attack2,
4167     &s_ofs_pod_spit1,
4168     &s_ofs_pod_spit2,
4169     &s_ofs_pod_spit3,
4170     &s_ofs_pod_death1,
4171     &s_ofs_pod_death2,
4172     &s_ofs_pod_death3,
4173     &s_ofs_pod_ouch,
4174     &s_ofs_bounce,
4175     &s_ofs_ouch,
4176     &s_ofs_esphere_death1,
4177     &s_ofs_esphere_death2,
4178     &s_ofs_esphere_death3,
4179     &s_ofs_random,
4180     &s_ofs_static,
4181     &s_hold,
4182     &s_ofs_smart_anim,
4183     &s_ofs_smart_anim2,
4184     &s_barrier_transition,
4185     &s_vpost_barrier,
4186     &s_spike_barrier,
4187     &s_barrier_shutdown,
4188     &s_rent_stand,
4189     &s_rent_path1,
4190     &s_rent_path1s,
4191     &s_rent_path2,
4192     &s_rent_path3,
4193     &s_rent_path3s,
4194     &s_rent_path4,
4195     &s_rent_pain,
4196     &s_rent_shoot1,
4197     &s_rent_shoot2,
4198     &s_rent_shoot3,
4199     &s_rent_chase1,
4200     &s_rent_chase1s,
4201     &s_rent_chase2,
4202     &s_rent_chase3,
4203     &s_rent_chase3s,
4204     &s_rent_chase4,
4205     &s_rent_die1,
4206     &s_rent_die2,
4207     &s_rent_die3,
4208     &s_rent_die3s,
4209     &s_rent_die4,
4210     &s_ofcstand,
4211     &s_ofcpath1,
4212     &s_ofcpath1s,
4213     &s_ofcpath2,
4214     &s_ofcpath3,
4215     &s_ofcpath3s,
4216     &s_ofcpath4,
4217     &s_ofcpain,
4218     &s_ofcshoot1,
4219     &s_ofcshoot2,
4220     &s_ofcshoot3,
4221     &s_ofcchase1,
4222     &s_ofcchase1s,
4223     &s_ofcchase2,
4224     &s_ofcchase3,
4225     &s_ofcchase3s,
4226     &s_ofcchase4,
4227     &s_ofcdie1,
4228     &s_ofcdie2,
4229     &s_ofcdie3,
4230     &s_ofcdie4,
4231     &s_ofcdie5,
4232     &s_swatstand,
4233     &s_swatpath1,
4234     &s_swatpath1s,
4235     &s_swatpath2,
4236     &s_swatpath3,
4237     &s_swatpath3s,
4238     &s_swatpath4,
4239     &s_swatpain,
4240     &s_swatshoot1,
4241     &s_swatshoot2,
4242     &s_swatshoot3,
4243     &s_swatshoot4,
4244     &s_swatshoot5,
4245     &s_swatshoot6,
4246     &s_swatshoot7,
4247     &s_swatchase1,
4248     &s_swatchase1s,
4249     &s_swatchase2,
4250     &s_swatchase3,
4251     &s_swatchase3s,
4252     &s_swatchase4,
4253     &s_swatwounded1,
4254     &s_swatwounded2,
4255     &s_swatwounded3,
4256     &s_swatwounded4,
4257     &s_swatunwounded1,
4258     &s_swatunwounded2,
4259     &s_swatunwounded3,
4260     &s_swatunwounded4,
4261     &s_swatdie1,
4262     &s_swatdie2,
4263     &s_swatdie3,
4264     &s_swatdie4,
4265     &s_swatdie5,
4266     &s_prostand,
4267     &s_propath1,
4268     &s_propath1s,
4269     &s_propath2,
4270     &s_propath3,
4271     &s_propath3s,
4272     &s_propath4,
4273     &s_propain,
4274     &s_proshoot1,
4275     &s_proshoot2,
4276     &s_proshoot3,
4277     &s_proshoot4,
4278     &s_proshoot5,
4279     &s_proshoot6,
4280     &s_proshoot6a,
4281     &s_prochase1,
4282     &s_prochase1s,
4283     &s_prochase2,
4284     &s_prochase3,
4285     &s_prochase3s,
4286     &s_prochase4,
4287     &s_prodie1,
4288     &s_prodie2,
4289     &s_prodie3,
4290     &s_prodie3a,
4291     &s_prodie4,
4292     &s_electro_appear1,
4293     &s_electro_appear2,
4294     &s_electro_appear3,
4295     &s_electro_chase1,
4296     &s_electro_chase2,
4297     &s_electro_chase3,
4298     &s_electro_chase4,
4299     &s_electro_ouch,
4300     &s_electro_shoot1,
4301     &s_electro_shoot2,
4302     &s_electro_shoot3,
4303     &s_electro_shot1,
4304     &s_electro_shot2,
4305     &s_ofs_shot1,
4306     &s_ofs_shot2,
4307     &s_electro_die1,
4308     &s_electro_die2,
4309     &s_electro_die3,
4310     &s_liquid_wait,
4311     &s_liquid_move,
4312     &s_liquid_rise1,
4313     &s_liquid_rise2,
4314     &s_liquid_rise3,
4315     &s_liquid_stand,
4316     &s_liquid_fall1,
4317     &s_liquid_fall2,
4318     &s_liquid_fall3,
4319     &s_liquid_shoot1,
4320     &s_liquid_shoot2,
4321     &s_liquid_shoot3,
4322     &s_liquid_ouch,
4323     &s_liquid_die1,
4324     &s_liquid_die2,
4325     &s_liquid_die3,
4326     &s_liquid_die4,
4327     &s_liquid_dead,
4328     &s_liquid_shot,
4329     &s_blake1,
4330     &s_blake2,
4331     &s_blake3,
4332     &s_blake4,
4333     &s_goldstand,
4334     &s_goldpath1,
4335     &s_goldpath1s,
4336     &s_goldpath2,
4337     &s_goldpath3,
4338     &s_goldpath3s,
4339     &s_goldpath4,
4340     &s_goldpain,
4341     &s_goldshoot1,
4342     &s_goldshoot2,
4343     &s_goldshoot3,
4344     &s_goldshoot4,
4345     &s_goldshoot5,
4346     &s_goldshoot6,
4347     &s_goldshoot7,
4348     &s_goldchase1,
4349     &s_goldchase1s,
4350     &s_goldchase2,
4351     &s_goldchase3,
4352     &s_goldchase3s,
4353     &s_goldchase4,
4354     &s_goldwarp_it,
4355     &s_goldwarp_it1,
4356     &s_goldwarp_it2,
4357     &s_goldwarp_it3,
4358     &s_goldwarp_it4,
4359     &s_goldwarp_it5,
4360     &s_goldwarp_out1,
4361     &s_goldwarp_out2,
4362     &s_goldwarp_out3,
4363     &s_goldwarp_out4,
4364     &s_goldwarp_out5,
4365     &s_goldwarp_in1,
4366     &s_goldwarp_in2,
4367     &s_goldwarp_in3,
4368     &s_goldwarp_in4,
4369     &s_goldwarp_in5,
4370     &s_goldmorphwait1,
4371     &s_goldmorph1,
4372     &s_goldmorph2,
4373     &s_goldmorph3,
4374     &s_goldmorph4,
4375     &s_goldmorph5,
4376     &s_goldmorph6,
4377     &s_goldmorph7,
4378     &s_goldmorph8,
4379     &s_mgold_chase1,
4380     &s_mgold_chase2,
4381     &s_mgold_chase3,
4382     &s_mgold_chase4,
4383     &s_mgold_shoot1,
4384     &s_mgold_shoot2,
4385     &s_mgold_shoot3,
4386     &s_mgold_shoot4,
4387     &s_mgold_pain,
4388     &s_security_light,
4389     &s_scout_stand,
4390     &s_scout_path1,
4391     &s_scout_path2,
4392     &s_scout_path3,
4393     &s_scout_path4,
4394     &s_scout_run,
4395     &s_scout_run2,
4396     &s_scout_run3,
4397     &s_scout_run4,
4398     &s_scout_dead,
4399     &s_steamgrate,
4400     &s_steamrelease1,
4401     &s_steamrelease2,
4402     &s_steamrelease3,
4403     &s_steamrelease4,
4404     &s_steamrelease5,
4405     &s_steamrelease6,
4406     &s_terrot_wait,
4407     &s_terrot_found,
4408     &s_terrot_shoot1,
4409     &s_terrot_shoot2,
4410     &s_terrot_shoot3,
4411     &s_terrot_shoot4,
4412     &s_terrot_seek1,
4413     &s_terrot_seek1s,
4414     &s_terrot_die1,
4415     &s_terrot_die2,
4416     &s_terrot_die3,
4417     &s_terrot_die4,
4418     &s_terrot_die5,
4419     &s_player,
4420     &s_attack,
4421     nullptr,
4422 };
4423 
get_state_index(statetype * state)4424 static int get_state_index(
4425     statetype* state)
4426 {
4427     if (!state) {
4428         return 0;
4429     }
4430 
4431     for (int i = 1; states_list[i]; ++i) {
4432         if (states_list[i] == state) {
4433             return i;
4434         }
4435     }
4436 
4437     return -1;
4438 }
4439 
initialize_states()4440 void initialize_states()
4441 {
4442     s_ofs_stand.shapenum = SPR_GENETIC_W1 - SPR_GENETIC_W1;
4443     s_ofs_chase1.shapenum = SPR_GENETIC_W1 - SPR_GENETIC_W1;
4444     s_ofs_chase1s.shapenum = SPR_GENETIC_W1 - SPR_GENETIC_W1;
4445     s_ofs_chase2.shapenum = SPR_GENETIC_W2 - SPR_GENETIC_W1;
4446     s_ofs_chase3.shapenum = SPR_GENETIC_W3 - SPR_GENETIC_W1;
4447     s_ofs_chase3s.shapenum = SPR_GENETIC_W3 - SPR_GENETIC_W1;
4448     s_ofs_chase4.shapenum = SPR_GENETIC_W4 - SPR_GENETIC_W1;
4449     s_ofs_pain.shapenum = SPR_GENETIC_OUCH - SPR_GENETIC_W1;
4450     s_ofs_die1.shapenum = SPR_GENETIC_OUCH - SPR_GENETIC_W1;
4451     s_ofs_die1s.shapenum = SPR_GENETIC_DIE1 - SPR_GENETIC_W1;
4452     s_ofs_die2.shapenum = SPR_GENETIC_DIE2 - SPR_GENETIC_W1;
4453     s_ofs_die3.shapenum = SPR_GENETIC_DIE3 - SPR_GENETIC_W1;
4454     s_ofs_die4.shapenum = SPR_GENETIC_DIE4 - SPR_GENETIC_W1;
4455     s_ofs_die5.shapenum = SPR_GENETIC_DEAD - SPR_GENETIC_W1;
4456     s_ofs_attack1.shapenum = SPR_GENETIC_SWING1 - SPR_GENETIC_W1;
4457     s_ofs_attack2.shapenum = SPR_GENETIC_SWING2 - SPR_GENETIC_W1;
4458     s_ofs_attack3.shapenum = SPR_GENETIC_SWING3 - SPR_GENETIC_W1;
4459     s_ofs_spit1.shapenum = SPR_GENETIC_SHOOT1 - SPR_GENETIC_W1;
4460     s_ofs_spit2.shapenum = SPR_GENETIC_SHOOT2 - SPR_GENETIC_W1;
4461     s_ofs_spit3.shapenum = SPR_GENETIC_SHOOT3 - SPR_GENETIC_W1;
4462     s_ofs_shoot1.shapenum = SPR_GENETIC_SWING1 - SPR_GENETIC_W1;
4463     s_ofs_shoot2.shapenum = SPR_GENETIC_SWING2 - SPR_GENETIC_W1;
4464     s_ofs_shoot3.shapenum = SPR_GENETIC_SWING3 - SPR_GENETIC_W1;
4465     s_ofs_pod_attack1.shapenum = SPR_POD_ATTACK1 - SPR_POD_WALK1;
4466     s_ofs_pod_attack1a.shapenum = SPR_POD_ATTACK2 - SPR_POD_WALK1;
4467     s_ofs_pod_attack2.shapenum = SPR_POD_ATTACK3 - SPR_POD_WALK1;
4468     s_ofs_pod_spit1.shapenum = SPR_POD_SPIT1 - SPR_POD_WALK1;
4469     s_ofs_pod_spit2.shapenum = SPR_POD_SPIT2 - SPR_POD_WALK1;
4470     s_ofs_pod_spit3.shapenum = SPR_POD_SPIT3 - SPR_POD_WALK1;
4471     s_ofs_pod_ouch.shapenum = SPR_POD_OUCH - SPR_POD_WALK1;
4472     s_vpost_barrier.shapenum = SPR_VPOST1;
4473     s_spike_barrier.shapenum = SPR_VSPIKE1;
4474     s_rent_stand.shapenum = SPR_RENT_S_1;
4475     s_rent_path1.shapenum = SPR_RENT_W1_1;
4476     s_rent_path1s.shapenum = SPR_RENT_W2_1;
4477     s_rent_path2.shapenum = SPR_RENT_W2_1;
4478     s_rent_path3.shapenum = SPR_RENT_W3_1;
4479     s_rent_path3s.shapenum = SPR_RENT_W3_1;
4480     s_rent_path4.shapenum = SPR_RENT_W4_1;
4481     s_rent_pain.shapenum = SPR_RENT_PAIN_1;
4482     s_rent_shoot1.shapenum = SPR_RENT_SHOOT1;
4483     s_rent_shoot2.shapenum = SPR_RENT_SHOOT2;
4484     s_rent_shoot3.shapenum = SPR_RENT_SHOOT3;
4485     s_rent_chase1.shapenum = SPR_RENT_W1_1;
4486     s_rent_chase1s.shapenum = SPR_RENT_W1_1;
4487     s_rent_chase2.shapenum = SPR_RENT_W2_1;
4488     s_rent_chase3.shapenum = SPR_RENT_W3_1;
4489     s_rent_chase3s.shapenum = SPR_RENT_W3_1;
4490     s_rent_chase4.shapenum = SPR_RENT_W4_1;
4491     s_rent_die1.shapenum = SPR_RENT_DIE_1;
4492     s_rent_die2.shapenum = SPR_RENT_DIE_2;
4493     s_rent_die3.shapenum = SPR_RENT_DIE_3;
4494     s_rent_die3s.shapenum = SPR_RENT_DIE_4;
4495     s_rent_die4.shapenum = SPR_RENT_DEAD;
4496     s_ofcstand.shapenum = SPR_OFC_S_1;
4497     s_ofcpath1.shapenum = SPR_OFC_W1_1;
4498     s_ofcpath1s.shapenum = SPR_OFC_W1_1;
4499     s_ofcpath2.shapenum = SPR_OFC_W2_1;
4500     s_ofcpath3.shapenum = SPR_OFC_W3_1;
4501     s_ofcpath3s.shapenum = SPR_OFC_W3_1;
4502     s_ofcpath4.shapenum = SPR_OFC_W4_1;
4503     s_ofcpain.shapenum = SPR_OFC_PAIN_1;
4504     s_ofcshoot1.shapenum = SPR_OFC_SHOOT1;
4505     s_ofcshoot2.shapenum = SPR_OFC_SHOOT2;
4506     s_ofcshoot3.shapenum = SPR_OFC_SHOOT3;
4507     s_ofcchase1.shapenum = SPR_OFC_W1_1;
4508     s_ofcchase1s.shapenum = SPR_OFC_W1_1;
4509     s_ofcchase2.shapenum = SPR_OFC_W2_1;
4510     s_ofcchase3.shapenum = SPR_OFC_W3_1;
4511     s_ofcchase3s.shapenum = SPR_OFC_W3_1;
4512     s_ofcchase4.shapenum = SPR_OFC_W4_1;
4513     s_ofcdie1.shapenum = SPR_OFC_DIE_1;
4514     s_ofcdie2.shapenum = SPR_OFC_DIE_2;
4515     s_ofcdie3.shapenum = SPR_OFC_DIE_3;
4516     s_ofcdie4.shapenum = SPR_OFC_DIE_4;
4517     s_ofcdie5.shapenum = SPR_OFC_DEAD;
4518     s_swatstand.shapenum = SPR_SWAT_S_1;
4519     s_swatpath1.shapenum = SPR_SWAT_W1_1;
4520     s_swatpath1s.shapenum = SPR_SWAT_W1_1;
4521     s_swatpath2.shapenum = SPR_SWAT_W2_1;
4522     s_swatpath3.shapenum = SPR_SWAT_W3_1;
4523     s_swatpath3s.shapenum = SPR_SWAT_W3_1;
4524     s_swatpath4.shapenum = SPR_SWAT_W4_1;
4525     s_swatpain.shapenum = SPR_SWAT_PAIN_1;
4526     s_swatshoot1.shapenum = SPR_SWAT_SHOOT1;
4527     s_swatshoot2.shapenum = SPR_SWAT_SHOOT2;
4528     s_swatshoot3.shapenum = SPR_SWAT_SHOOT3;
4529     s_swatshoot4.shapenum = SPR_SWAT_SHOOT2;
4530     s_swatshoot5.shapenum = SPR_SWAT_SHOOT3;
4531     s_swatshoot6.shapenum = SPR_SWAT_SHOOT2;
4532     s_swatshoot7.shapenum = SPR_SWAT_SHOOT3;
4533     s_swatchase1.shapenum = SPR_SWAT_W1_1;
4534     s_swatchase1s.shapenum = SPR_SWAT_W1_1;
4535     s_swatchase2.shapenum = SPR_SWAT_W2_1;
4536     s_swatchase3.shapenum = SPR_SWAT_W3_1;
4537     s_swatchase3s.shapenum = SPR_SWAT_W3_1;
4538     s_swatchase4.shapenum = SPR_SWAT_W4_1;
4539     s_swatwounded1.shapenum = SPR_SWAT_WOUNDED1;
4540     s_swatwounded2.shapenum = SPR_SWAT_WOUNDED2;
4541     s_swatwounded3.shapenum = SPR_SWAT_WOUNDED3;
4542     s_swatwounded4.shapenum = SPR_SWAT_WOUNDED4;
4543     s_swatunwounded1.shapenum = SPR_SWAT_WOUNDED4;
4544     s_swatunwounded2.shapenum = SPR_SWAT_WOUNDED3;
4545     s_swatunwounded3.shapenum = SPR_SWAT_WOUNDED2;
4546     s_swatunwounded4.shapenum = SPR_SWAT_WOUNDED1;
4547     s_swatdie1.shapenum = SPR_SWAT_DIE_1;
4548     s_swatdie2.shapenum = SPR_SWAT_DIE_2;
4549     s_swatdie3.shapenum = SPR_SWAT_DIE_3;
4550     s_swatdie4.shapenum = SPR_SWAT_DIE_4;
4551     s_swatdie5.shapenum = SPR_SWAT_DEAD;
4552     s_prostand.shapenum = SPR_PRO_S_1;
4553     s_propath1.shapenum = SPR_PRO_W1_1;
4554     s_propath1s.shapenum = SPR_PRO_W1_1;
4555     s_propath2.shapenum = SPR_PRO_W2_1;
4556     s_propath3.shapenum = SPR_PRO_W3_1;
4557     s_propath3s.shapenum = SPR_PRO_W3_1;
4558     s_propath4.shapenum = SPR_PRO_W4_1;
4559     s_propain.shapenum = SPR_PRO_PAIN_1;
4560     s_proshoot1.shapenum = SPR_PRO_SHOOT1;
4561     s_proshoot2.shapenum = SPR_PRO_SHOOT2;
4562     s_proshoot3.shapenum = SPR_PRO_SHOOT3;
4563     s_proshoot4.shapenum = SPR_PRO_SHOOT2;
4564     s_proshoot5.shapenum = SPR_PRO_SHOOT3;
4565     s_proshoot6.shapenum = SPR_PRO_SHOOT2;
4566     s_proshoot6a.shapenum = SPR_PRO_SHOOT3;
4567     s_prochase1.shapenum = SPR_PRO_W1_1;
4568     s_prochase1s.shapenum = SPR_PRO_W1_1;
4569     s_prochase2.shapenum = SPR_PRO_W2_1;
4570     s_prochase3.shapenum = SPR_PRO_W3_1;
4571     s_prochase3s.shapenum = SPR_PRO_W3_1;
4572     s_prochase4.shapenum = SPR_PRO_W4_1;
4573     s_prodie1.shapenum = SPR_PRO_DIE_1;
4574     s_prodie2.shapenum = SPR_PRO_DIE_2;
4575     s_prodie3.shapenum = SPR_PRO_DIE_3;
4576     s_prodie3a.shapenum = SPR_PRO_DIE_4;
4577     s_prodie4.shapenum = SPR_PRO_DEAD;
4578     s_electro_appear1.shapenum = SPR_ELEC_APPEAR1;
4579     s_electro_appear2.shapenum = SPR_ELEC_APPEAR2;
4580     s_electro_appear3.shapenum = SPR_ELEC_APPEAR3;
4581     s_electro_chase1.shapenum = SPR_ELEC_WALK1;
4582     s_electro_chase2.shapenum = SPR_ELEC_WALK2;
4583     s_electro_chase3.shapenum = SPR_ELEC_WALK3;
4584     s_electro_chase4.shapenum = SPR_ELEC_WALK4;
4585     s_electro_ouch.shapenum = SPR_ELEC_OUCH;
4586     s_electro_shoot1.shapenum = SPR_ELEC_SHOOT1;
4587     s_electro_shoot2.shapenum = SPR_ELEC_SHOOT2;
4588     s_electro_shoot3.shapenum = SPR_ELEC_SHOOT3;
4589     s_electro_shot1.shapenum = SPR_ELEC_SHOT1;
4590     s_electro_shot2.shapenum = SPR_ELEC_SHOT2;
4591     s_electro_die1.shapenum = SPR_ELEC_DIE1;
4592     s_electro_die2.shapenum = SPR_ELEC_DIE2;
4593     s_electro_die3.shapenum = SPR_ELEC_DIE3;
4594     s_liquid_wait.shapenum = SPR_LIQUID_M1;
4595     s_liquid_move.shapenum = SPR_LIQUID_M1;
4596     s_liquid_rise1.shapenum = SPR_LIQUID_R1;
4597     s_liquid_rise2.shapenum = SPR_LIQUID_R2;
4598     s_liquid_rise3.shapenum = SPR_LIQUID_R3;
4599     s_liquid_stand.shapenum = SPR_LIQUID_R4;
4600     s_liquid_fall1.shapenum = SPR_LIQUID_R3;
4601     s_liquid_fall2.shapenum = SPR_LIQUID_R2;
4602     s_liquid_fall3.shapenum = SPR_LIQUID_R1;
4603     s_liquid_shoot1.shapenum = SPR_LIQUID_S1;
4604     s_liquid_shoot2.shapenum = SPR_LIQUID_S2;
4605     s_liquid_shoot3.shapenum = SPR_LIQUID_S3;
4606     s_liquid_ouch.shapenum = SPR_LIQUID_OUCH;
4607     s_liquid_die1.shapenum = SPR_LIQUID_DIE_1;
4608     s_liquid_die2.shapenum = SPR_LIQUID_DIE_2;
4609     s_liquid_die3.shapenum = SPR_LIQUID_DIE_3;
4610     s_liquid_die4.shapenum = SPR_LIQUID_DIE_4;
4611     s_liquid_dead.shapenum = SPR_LIQUID_DEAD;
4612     s_blake1.shapenum = SPR_BLAKE_W1;
4613     s_blake2.shapenum = SPR_BLAKE_W2;
4614     s_blake3.shapenum = SPR_BLAKE_W3;
4615     s_blake4.shapenum = SPR_BLAKE_W4;
4616     s_goldstand.shapenum = SPR_GOLD_S_1;
4617     s_goldpath1.shapenum = SPR_GOLD_W1_1;
4618     s_goldpath1s.shapenum = SPR_GOLD_W1_1;
4619     s_goldpath2.shapenum = SPR_GOLD_W2_1;
4620     s_goldpath3.shapenum = SPR_GOLD_W3_1;
4621     s_goldpath3s.shapenum = SPR_GOLD_W3_1;
4622     s_goldpath4.shapenum = SPR_GOLD_W4_1;
4623     s_goldpain.shapenum = SPR_GOLD_PAIN_1;
4624     s_goldshoot1.shapenum = SPR_GOLD_SHOOT1;
4625     s_goldshoot2.shapenum = SPR_GOLD_SHOOT2;
4626     s_goldshoot3.shapenum = SPR_GOLD_SHOOT3;
4627     s_goldshoot4.shapenum = SPR_GOLD_SHOOT2;
4628     s_goldshoot5.shapenum = SPR_GOLD_SHOOT3;
4629     s_goldshoot6.shapenum = SPR_GOLD_SHOOT2;
4630     s_goldshoot7.shapenum = SPR_GOLD_SHOOT3;
4631     s_goldchase1.shapenum = SPR_GOLD_W1_1;
4632     s_goldchase1s.shapenum = SPR_GOLD_W1_1;
4633     s_goldchase2.shapenum = SPR_GOLD_W2_1;
4634     s_goldchase3.shapenum = SPR_GOLD_W3_1;
4635     s_goldchase3s.shapenum = SPR_GOLD_W3_1;
4636     s_goldchase4.shapenum = SPR_GOLD_W4_1;
4637     s_goldwarp_it.shapenum = SPR_GOLD_S_1;
4638     s_goldwarp_it1.shapenum = SPR_GOLD_WRIST_1;
4639     s_goldwarp_it2.shapenum = SPR_GOLD_WRIST_2;
4640     s_goldwarp_it3.shapenum = SPR_GOLD_WRIST_1;
4641     s_goldwarp_it4.shapenum = SPR_GOLD_WRIST_2;
4642     s_goldwarp_it5.shapenum = SPR_GOLD_S_1;
4643     s_goldwarp_out1.shapenum = SPR_GOLD_WARP1;
4644     s_goldwarp_out2.shapenum = SPR_GOLD_WARP2;
4645     s_goldwarp_out3.shapenum = SPR_GOLD_WARP3;
4646     s_goldwarp_out4.shapenum = SPR_GOLD_WARP4;
4647     s_goldwarp_out5.shapenum = SPR_GOLD_WARP5;
4648     s_goldwarp_in1.shapenum = SPR_GOLD_WARP5;
4649     s_goldwarp_in2.shapenum = SPR_GOLD_WARP4;
4650     s_goldwarp_in3.shapenum = SPR_GOLD_WARP3;
4651     s_goldwarp_in4.shapenum = SPR_GOLD_WARP2;
4652     s_goldwarp_in5.shapenum = SPR_GOLD_WARP1;
4653     s_goldmorphwait1.shapenum = SPR_GOLD_WRIST_1;
4654     s_goldmorph1.shapenum = SPR_GOLD_MORPH1;
4655     s_goldmorph2.shapenum = SPR_GOLD_MORPH2;
4656     s_goldmorph3.shapenum = SPR_GOLD_MORPH3;
4657     s_goldmorph4.shapenum = SPR_GOLD_MORPH4;
4658     s_goldmorph5.shapenum = SPR_GOLD_MORPH5;
4659     s_goldmorph6.shapenum = SPR_GOLD_MORPH6;
4660     s_goldmorph7.shapenum = SPR_GOLD_MORPH7;
4661     s_goldmorph8.shapenum = SPR_GOLD_MORPH8;
4662     s_mgold_chase1.shapenum = SPR_MGOLD_WALK1;
4663     s_mgold_chase2.shapenum = SPR_MGOLD_WALK2;
4664     s_mgold_chase3.shapenum = SPR_MGOLD_WALK3;
4665     s_mgold_chase4.shapenum = SPR_MGOLD_WALK4;
4666     s_mgold_shoot1.shapenum = SPR_MGOLD_ATTACK1;
4667     s_mgold_shoot2.shapenum = SPR_MGOLD_ATTACK2;
4668     s_mgold_shoot3.shapenum = SPR_MGOLD_ATTACK3;
4669     s_mgold_shoot4.shapenum = SPR_MGOLD_ATTACK4;
4670     s_mgold_pain.shapenum = SPR_MGOLD_OUCH;
4671     s_security_light.shapenum = SPR_SECURITY_NORMAL;
4672     s_scout_stand.shapenum = SPR_GSCOUT_W1_1 - SPR_GSCOUT_W1_1;
4673     s_scout_path1.shapenum = SPR_GSCOUT_W1_1 - SPR_GSCOUT_W1_1;
4674     s_scout_path2.shapenum = SPR_GSCOUT_W2_1 - SPR_GSCOUT_W2_1;
4675     s_scout_path3.shapenum = SPR_GSCOUT_W3_1 - SPR_GSCOUT_W3_1;
4676     s_scout_path4.shapenum = SPR_GSCOUT_W4_1 - SPR_GSCOUT_W4_1;
4677     s_scout_run.shapenum = SPR_GSCOUT_W1_1 - SPR_GSCOUT_W1_1;
4678     s_scout_run2.shapenum = SPR_GSCOUT_W2_1 - SPR_GSCOUT_W2_1;
4679     s_scout_run3.shapenum = SPR_GSCOUT_W3_1 - SPR_GSCOUT_W3_1;
4680     s_scout_run4.shapenum = SPR_GSCOUT_W4_1 - SPR_GSCOUT_W4_1;
4681     s_scout_dead.shapenum = SPR_GSCOUT_W1_1 - SPR_GSCOUT_W1_1;
4682     s_terrot_wait.shapenum = SPR_TERROT_1;
4683     s_terrot_found.shapenum = SPR_TERROT_1;
4684     s_terrot_shoot1.shapenum = SPR_TERROT_FIRE_1;
4685     s_terrot_shoot2.shapenum = SPR_TERROT_FIRE_2;
4686     s_terrot_shoot3.shapenum = SPR_TERROT_FIRE_1;
4687     s_terrot_shoot4.shapenum = SPR_TERROT_FIRE_2;
4688     s_terrot_seek1.shapenum = SPR_TERROT_1;
4689     s_terrot_seek1s.shapenum = SPR_TERROT_1;
4690     s_terrot_die1.shapenum = SPR_TERROT_DIE_1;
4691     s_terrot_die2.shapenum = SPR_TERROT_DIE_2;
4692     s_terrot_die3.shapenum = SPR_TERROT_DIE_3;
4693     s_terrot_die4.shapenum = SPR_TERROT_DIE_4;
4694     s_terrot_die5.shapenum = SPR_TERROT_DEAD;
4695 }
4696 
4697 
4698 int16_t NUMSNDCHUNKS = 0;
4699 
4700 int16_t S2100A_MUS = 0;
4701 int16_t GOLDA_MUS = 0;
4702 int16_t DRKHALLA_MUS = 0;
4703 int16_t FREEDOMA_MUS = 0;
4704 int16_t GENEFUNK_MUS = 0;
4705 int16_t TIMEA_MUS = 0;
4706 int16_t HIDINGA_MUS = 0;
4707 int16_t INCNRATN_MUS = 0;
4708 int16_t JUNGLEA_MUS = 0;
4709 int16_t LEVELA_MUS = 0;
4710 int16_t MEETINGA_MUS = 0;
4711 int16_t STRUTA_MUS = 0;
4712 int16_t RACSHUFL_MUS = 0;
4713 int16_t RUMBAA_MUS = 0;
4714 int16_t SEARCHNA_MUS = 0;
4715 int16_t THEWAYA_MUS = 0;
4716 int16_t INTRIGEA_MUS = 0;
4717 
4718 int16_t CATACOMB_MUS = 0;
4719 int16_t STICKS_MUS = 0;
4720 int16_t PLOT_MUS = 0;
4721 int16_t CIRCLES_MUS = 0;
4722 int16_t LASTLAFF_MUS = 0;
4723 int16_t TOHELL_MUS = 0;
4724 int16_t FORTRESS_MUS = 0;
4725 int16_t GIVING_MUS = 0;
4726 int16_t HARTBEAT_MUS = 0;
4727 int16_t LURKING_MUS = 0;
4728 int16_t MAJMIN_MUS = 0;
4729 int16_t VACCINAP_MUS = 0;
4730 int16_t DARKNESS_MUS = 0;
4731 int16_t MONASTRY_MUS = 0;
4732 int16_t TOMBP_MUS = 0;
4733 int16_t TIME_MUS = 0;
4734 int16_t MOURNING_MUS = 0;
4735 int16_t SERPENT_MUS = 0;
4736 int16_t HISCORE_MUS = 0;
4737 
4738 int16_t APOGFNFM_MUS = 0;
4739 int16_t THEME_MUS = 0;
4740 int16_t LASTMUSIC = 0;
4741 int16_t TITLE_LOOP_MUSIC = 0;
4742 
4743 
initialize_audio_constants()4744 void initialize_audio_constants()
4745 {
4746     if (::is_aog()) {
4747         NUMSNDCHUNKS = 319;
4748 
4749         THEME_MUS = 16;
4750         LASTMUSIC = 19;
4751     } else {
4752         NUMSNDCHUNKS = 321;
4753 
4754         THEME_MUS = 20;
4755         LASTMUSIC = 21;
4756     }
4757 
4758     APOGFNFM_MUS = 2;
4759 
4760     S2100A_MUS = 0;
4761     GOLDA_MUS = 1;
4762     APOGFNFM_MUS = 2;
4763     DRKHALLA_MUS = 3;
4764     FREEDOMA_MUS = 4;
4765     GENEFUNK_MUS = 5;
4766     TIMEA_MUS = 6;
4767     HIDINGA_MUS = 7;
4768     INCNRATN_MUS = 8;
4769     JUNGLEA_MUS = 9;
4770     LEVELA_MUS = 10;
4771     MEETINGA_MUS = 11;
4772     STRUTA_MUS = 12;
4773     RACSHUFL_MUS = 13;
4774     RUMBAA_MUS = 14;
4775     SEARCHNA_MUS = 15;
4776     THEWAYA_MUS = 17;
4777     INTRIGEA_MUS = 18;
4778 
4779     CATACOMB_MUS = 0;
4780     STICKS_MUS = 1;
4781     PLOT_MUS = 3;
4782     CIRCLES_MUS = 4;
4783     LASTLAFF_MUS = 5;
4784     TOHELL_MUS = 6;
4785     FORTRESS_MUS = 7;
4786     GIVING_MUS = 8;
4787     HARTBEAT_MUS = 9;
4788     LURKING_MUS = 10;
4789     MAJMIN_MUS = 11;
4790     VACCINAP_MUS = 12;
4791     DARKNESS_MUS = 13;
4792     MONASTRY_MUS = 14;
4793     TOMBP_MUS = 15;
4794     TIME_MUS = 16;
4795     MOURNING_MUS = 17;
4796     SERPENT_MUS = 18;
4797     HISCORE_MUS = 19;
4798 
4799     audiosegs.resize(NUMSNDCHUNKS);
4800 
4801     if (::is_ps()) {
4802         MENUSONG = LASTLAFF_MUS;
4803         ROSTER_MUS = HISCORE_MUS;
4804         TEXTSONG = TOHELL_MUS;
4805         TITLE_LOOP_MUSIC = PLOT_MUS;
4806     } else {
4807         MENUSONG = MEETINGA_MUS;
4808         ROSTER_MUS = LEVELA_MUS;
4809         TEXTSONG = RUMBAA_MUS;
4810         TITLE_LOOP_MUSIC = GOLDA_MUS;
4811     }
4812 }
4813 
4814 
4815 int16_t TELEPORT_LUMP_START = 0;
4816 int16_t TELEPORT_LUMP_END = 0;
4817 
4818 int16_t README_LUMP_START = 0;
4819 int16_t README_LUMP_END = 0;
4820 
4821 int16_t CONTROLS_LUMP_START = 0;
4822 int16_t CONTROLS_LUMP_END = 0;
4823 
4824 int16_t LATCHPICS_LUMP_START = 0;
4825 int16_t LATCHPICS_LUMP_END = 0;
4826 
4827 
4828 //
4829 // Amount of each data item
4830 //
4831 int16_t NUMCHUNKS = 0;
4832 int16_t NUMFONT = 0;
4833 int16_t NUMFONTM = 0;
4834 int16_t NUMPICS = 0;
4835 int16_t NUMPICM = 0;
4836 int16_t NUMSPRITES = 0;
4837 int16_t NUMTILE8 = 0;
4838 int16_t NUMTILE8M = 0;
4839 int16_t NUMTILE16 = 0;
4840 int16_t NUMTILE16M = 0;
4841 int16_t NUMTILE32 = 0;
4842 int16_t NUMTILE32M = 0;
4843 int16_t NUMEXTERNS = 0;
4844 
4845 //
4846 // File offsets for data items
4847 //
4848 int16_t STRUCTPIC = 0;
4849 
4850 int16_t STARTFONT = 0;
4851 int16_t STARTFONTM = 0;
4852 int16_t STARTPICS = 0;
4853 int16_t STARTPICM = 0;
4854 int16_t STARTSPRITES = 0;
4855 int16_t STARTTILE8 = 0;
4856 int16_t STARTTILE8M = 0;
4857 int16_t STARTTILE16 = 0;
4858 int16_t STARTTILE16M = 0;
4859 int16_t STARTTILE32 = 0;
4860 int16_t STARTTILE32M = 0;
4861 int16_t STARTEXTERNS = 0;
4862 
4863 
4864 int16_t TELEPORTBACKPIC = 0;
4865 int16_t TELEPORT1OFFPIC = 0;
4866 int16_t TELEPORT2OFFPIC = 0;
4867 int16_t TELEPORT3OFFPIC = 0;
4868 int16_t TELEPORT4OFFPIC = 0;
4869 int16_t TELEPORT5OFFPIC = 0;
4870 int16_t TELEPORT6OFFPIC = 0;
4871 int16_t TELEPORT7OFFPIC = 0;
4872 int16_t TELEPORT8OFFPIC = 0;
4873 int16_t TELEPORT9OFFPIC = 0;
4874 int16_t TELEPORT10OFFPIC = 0;
4875 int16_t TELEPORT1ONPIC = 0;
4876 int16_t TELEPORT2ONPIC = 0;
4877 int16_t TELEPORT3ONPIC = 0;
4878 int16_t TELEPORT4ONPIC = 0;
4879 int16_t TELEPORT5ONPIC = 0;
4880 int16_t TELEPORT6ONPIC = 0;
4881 int16_t TELEPORT7ONPIC = 0;
4882 int16_t TELEPORT8ONPIC = 0;
4883 int16_t TELEPORT9ONPIC = 0;
4884 int16_t TELEPORT10ONPIC = 0;
4885 int16_t TELEPORT_TEXT_BG = 0;
4886 int16_t BACKGROUND_SCREENPIC = 0;
4887 int16_t APOGEEPIC = 0;
4888 int16_t PIRACYPIC = 0;
4889 int16_t PC13PIC = 0;
4890 int16_t LOSEPIC = 0;
4891 int16_t AUTOMAPPIC = 0;
4892 int16_t PSPROMO1PIC = 0;
4893 int16_t PSPROMO2PIC = 0;
4894 int16_t PSPROMO3PIC = 0;
4895 int16_t H_ALTPIC = 0;
4896 int16_t H_CTRLPIC = 0;
4897 int16_t H_SPACEPIC = 0;
4898 int16_t H_PAUSEPIC = 0;
4899 int16_t H_ESCPIC = 0;
4900 int16_t H_LTARROWPIC = 0;
4901 int16_t H_UPARROWPIC = 0;
4902 int16_t H_DNARROWPIC = 0;
4903 int16_t H_RTARROWPIC = 0;
4904 int16_t H_ENTERPIC = 0;
4905 int16_t H_QPIC = 0;
4906 int16_t H_WPIC = 0;
4907 int16_t H_EPIC = 0;
4908 int16_t H_IPIC = 0;
4909 int16_t H_HPIC = 0;
4910 int16_t H_1PIC = 0;
4911 int16_t H_2PIC = 0;
4912 int16_t H_3PIC = 0;
4913 int16_t H_4PIC = 0;
4914 int16_t H_5PIC = 0;
4915 int16_t H_F1PIC = 0;
4916 int16_t H_F2PIC = 0;
4917 int16_t H_F3PIC = 0;
4918 int16_t H_F4PIC = 0;
4919 int16_t H_F5PIC = 0;
4920 int16_t H_F6PIC = 0;
4921 int16_t H_F7PIC = 0;
4922 int16_t H_F8PIC = 0;
4923 int16_t H_F9PIC = 0;
4924 int16_t H_F10PIC = 0;
4925 int16_t H_TABPIC = 0;
4926 int16_t H_CPIC = 0;
4927 int16_t H_FPIC = 0;
4928 int16_t H_PPIC = 0;
4929 int16_t H_MPIC = 0;
4930 int16_t H_LPIC = 0;
4931 int16_t H_SHIFTPIC = 0;
4932 int16_t APOGEE_LOGOPIC = 0;
4933 int16_t VISAPIC = 0;
4934 int16_t MCPIC = 0;
4935 int16_t FAXPIC = 0;
4936 int16_t H_TOPWINDOWPIC = 0;
4937 int16_t H_LEFTWINDOWPIC = 0;
4938 int16_t H_RIGHTWINDOWPIC = 0;
4939 int16_t H_BOTTOMINFOPIC = 0;
4940 int16_t C_NOTSELECTEDPIC = 0;
4941 int16_t C_SELECTEDPIC = 0;
4942 int16_t C_NOTSELECTED_HIPIC = 0;
4943 int16_t C_SELECTED_HIPIC = 0;
4944 int16_t C_BABYMODEPIC = 0;
4945 int16_t C_EASYPIC = 0;
4946 int16_t C_NORMALPIC = 0;
4947 int16_t C_HARDPIC = 0;
4948 int16_t C_EPISODE1PIC = 0;
4949 int16_t C_EPISODE2PIC = 0;
4950 int16_t C_EPISODE3PIC = 0;
4951 int16_t C_EPISODE4PIC = 0;
4952 int16_t C_EPISODE5PIC = 0;
4953 int16_t C_EPISODE6PIC = 0;
4954 int16_t BIGGOLDSTERNPIC = 0;
4955 int16_t STARLOGOPIC = 0;
4956 int16_t BLAKEWITHGUNPIC = 0;
4957 int16_t STARINSTITUTEPIC = 0;
4958 int16_t MEDALOFHONORPIC = 0;
4959 int16_t SMALLGOLDSTERNPIC = 0;
4960 int16_t BLAKEWINPIC = 0;
4961 int16_t SHUTTLEEXPPIC = 0;
4962 int16_t PLANETSPIC = 0;
4963 int16_t MOUSEPIC = 0;
4964 int16_t JOYSTICKPIC = 0;
4965 int16_t GRAVISPADPIC = 0;
4966 int16_t TITLEPIC = 0;
4967 int16_t PROMO1PIC = 0;
4968 int16_t PROMO2PIC = 0;
4969 int16_t WEAPON1PIC = 0;
4970 int16_t WEAPON2PIC = 0;
4971 int16_t WEAPON3PIC = 0;
4972 int16_t WEAPON4PIC = 0;
4973 int16_t WEAPON5PIC = 0;
4974 int16_t WAITPIC = 0;
4975 int16_t READYPIC = 0;
4976 int16_t N_BLANKPIC = 0;
4977 int16_t N_0PIC = 0;
4978 int16_t N_1PIC = 0;
4979 int16_t N_2PIC = 0;
4980 int16_t N_3PIC = 0;
4981 int16_t N_4PIC = 0;
4982 int16_t N_5PIC = 0;
4983 int16_t N_6PIC = 0;
4984 int16_t N_7PIC = 0;
4985 int16_t N_8PIC = 0;
4986 int16_t N_9PIC = 0;
4987 int16_t N_RPIC = 0;
4988 int16_t N_OPIC = 0;
4989 int16_t N_LPIC = 0;
4990 int16_t N_DASHPIC = 0;
4991 int16_t DIM_LIGHTPIC = 0;
4992 int16_t BRI_LIGHTPIC = 0;
4993 int16_t ECG_HEART_GOOD = 0;
4994 int16_t ECG_HEART_BAD = 0;
4995 int16_t ECG_GRID_PIECE = 0;
4996 int16_t ECG_HEARTBEAT_00 = 0;
4997 int16_t ECG_HEARTBEAT_01 = 0;
4998 int16_t ECG_HEARTBEAT_02 = 0;
4999 int16_t ECG_HEARTBEAT_03 = 0;
5000 int16_t ECG_HEARTBEAT_04 = 0;
5001 int16_t ECG_HEARTBEAT_05 = 0;
5002 int16_t ECG_HEARTBEAT_06 = 0;
5003 int16_t ECG_HEARTBEAT_07 = 0;
5004 int16_t ECG_HEARTBEAT_08 = 0;
5005 int16_t ECG_HEARTBEAT_09 = 0;
5006 int16_t ECG_HEARTBEAT_10 = 0;
5007 int16_t ECG_HEARTBEAT_11 = 0;
5008 int16_t ECG_HEARTBEAT_12 = 0;
5009 int16_t ECG_HEARTBEAT_13 = 0;
5010 int16_t ECG_HEARTBEAT_14 = 0;
5011 int16_t ECG_HEARTBEAT_15 = 0;
5012 int16_t ECG_HEARTBEAT_16 = 0;
5013 int16_t ECG_HEARTBEAT_17 = 0;
5014 int16_t ECG_HEARTBEAT_18 = 0;
5015 int16_t ECG_HEARTBEAT_19 = 0;
5016 int16_t ECG_HEARTBEAT_20 = 0;
5017 int16_t ECG_HEARTBEAT_21 = 0;
5018 int16_t ECG_HEARTBEAT_22 = 0;
5019 int16_t ECG_HEARTBEAT_23 = 0;
5020 int16_t ECG_HEARTBEAT_24 = 0;
5021 int16_t ECG_HEARTBEAT_25 = 0;
5022 int16_t ECG_HEARTBEAT_26 = 0;
5023 int16_t ECG_HEARTBEAT_27 = 0;
5024 int16_t INFOAREAPIC = 0;
5025 int16_t TOP_STATUSBARPIC = 0;
5026 int16_t STATUSBARPIC = 0;
5027 int16_t PIRACYPALETTE = 0;
5028 int16_t APOGEEPALETTE = 0;
5029 int16_t TITLEPALETTE = 0;
5030 int16_t ORDERSCREEN = 0;
5031 int16_t ERRORSCREEN = 0;
5032 int16_t INFORMANT_HINTS = 0;
5033 int16_t NICE_SCIE_HINTS = 0;
5034 int16_t MEAN_SCIE_HINTS = 0;
5035 int16_t BRIEF_W1 = 0;
5036 int16_t BRIEF_I1 = 0;
5037 int16_t BRIEF_W2 = 0;
5038 int16_t BRIEF_I2 = 0;
5039 int16_t BRIEF_W3 = 0;
5040 int16_t BRIEF_I3 = 0;
5041 int16_t BRIEF_W4 = 0;
5042 int16_t BRIEF_I4 = 0;
5043 int16_t BRIEF_W5 = 0;
5044 int16_t BRIEF_I5 = 0;
5045 int16_t BRIEF_W6 = 0;
5046 int16_t BRIEF_I6 = 0;
5047 int16_t LEVEL_DESCS = 0;
5048 int16_t POWERBALLTEXT = 0;
5049 int16_t TICSTEXT = 0;
5050 int16_t MUSICTEXT = 0;
5051 int16_t RADARTEXT = 0;
5052 int16_t HELPTEXT = 0;
5053 int16_t SAGATEXT = 0;
5054 int16_t LOSETEXT = 0;
5055 int16_t ORDERTEXT = 0;
5056 int16_t CREDITSTEXT = 0;
5057 int16_t MUSTBE386TEXT = 0;
5058 int16_t QUICK_INFO1_TEXT = 0;
5059 int16_t QUICK_INFO2_TEXT = 0;
5060 int16_t BADINFO_TEXT = 0;
5061 int16_t CALJOY1_TEXT = 0;
5062 int16_t CALJOY2_TEXT = 0;
5063 int16_t READTHIS_TEXT = 0;
5064 int16_t ELEVMSG0_TEXT = 0;
5065 int16_t ELEVMSG1_TEXT = 0;
5066 int16_t ELEVMSG4_TEXT = 0;
5067 int16_t ELEVMSG5_TEXT = 0;
5068 int16_t FLOORMSG_TEXT = 0;
5069 int16_t YOUWIN_TEXT = 0;
5070 int16_t CHANGEVIEW_TEXT = 0;
5071 int16_t DIZ_ERR_TEXT = 0;
5072 int16_t BADLEVELSTEXT = 0;
5073 int16_t BADSAVEGAME_TEXT = 0;
5074 
5075 int16_t TELEPORTBACKTOPPIC = 0;
5076 int16_t TELEPORTBACKBOTPIC = 0;
5077 int16_t TELEPORT11ONPIC = 0;
5078 int16_t TELEPORT12ONPIC = 0;
5079 int16_t TELEPORT13ONPIC = 0;
5080 int16_t TELEPORT14ONPIC = 0;
5081 int16_t TELEPORT15ONPIC = 0;
5082 int16_t TELEPORT16ONPIC = 0;
5083 int16_t TELEPORT17ONPIC = 0;
5084 int16_t TELEPORT18ONPIC = 0;
5085 int16_t TELEPORT19ONPIC = 0;
5086 int16_t TELEPORT20ONPIC = 0;
5087 int16_t TELEUPONPIC = 0;
5088 int16_t TELEDNONPIC = 0;
5089 int16_t TELEUPOFFPIC = 0;
5090 int16_t TELEDNOFFPIC = 0;
5091 int16_t TELEPORT11OFFPIC = 0;
5092 int16_t TELEPORT12OFFPIC = 0;
5093 int16_t TELEPORT13OFFPIC = 0;
5094 int16_t TELEPORT14OFFPIC = 0;
5095 int16_t TELEPORT15OFFPIC = 0;
5096 int16_t TELEPORT16OFFPIC = 0;
5097 int16_t TELEPORT17OFFPIC = 0;
5098 int16_t TELEPORT18OFFPIC = 0;
5099 int16_t TELEPORT19OFFPIC = 0;
5100 int16_t TELEPORT20OFFPIC = 0;
5101 int16_t AUTOMAP_MAG1PIC = 0;
5102 int16_t AUTOMAP_MAG2PIC = 0;
5103 int16_t AUTOMAP_MAG4PIC = 0;
5104 int16_t H_6PIC = 0;
5105 int16_t H_TILDEPIC = 0;
5106 int16_t H_PLUSPIC = 0;
5107 int16_t H_MINUSPIC = 0;
5108 int16_t STARPORTPIC = 0;
5109 int16_t BOSSPIC = 0;
5110 int16_t THREEPLANETSPIC = 0;
5111 int16_t SOLARSYSTEMPIC = 0;
5112 int16_t AOGENDINGPIC = 0;
5113 int16_t GFLOGOSPIC = 0;
5114 int16_t BLAKEHEADPIC = 0;
5115 int16_t PROJECTFOLDERPIC = 0;
5116 int16_t TITLE1PIC = 0;
5117 int16_t TITLE2PIC = 0;
5118 int16_t WEAPON6PIC = 0;
5119 int16_t WEAPON7PIC = 0;
5120 int16_t W1_CORNERPIC = 0;
5121 int16_t W2_CORNERPIC = 0;
5122 int16_t W3_CORNERPIC = 0;
5123 int16_t W4_CORNERPIC = 0;
5124 int16_t W5_CORNERPIC = 0;
5125 int16_t W6_CORNERPIC = 0;
5126 int16_t NG_BLANKPIC = 0;
5127 int16_t NG_0PIC = 0;
5128 int16_t NG_1PIC = 0;
5129 int16_t NG_2PIC = 0;
5130 int16_t NG_3PIC = 0;
5131 int16_t NG_4PIC = 0;
5132 int16_t NG_5PIC = 0;
5133 int16_t NG_6PIC = 0;
5134 int16_t NG_7PIC = 0;
5135 int16_t NG_8PIC = 0;
5136 int16_t NG_9PIC = 0;
5137 int16_t ONEXZOOMPIC = 0;
5138 int16_t TWOXZOOMPIC = 0;
5139 int16_t FOURXZOOMPIC = 0;
5140 int16_t NO_KEYPIC = 0;
5141 int16_t RED_KEYPIC = 0;
5142 int16_t YEL_KEYPIC = 0;
5143 int16_t BLU_KEYPIC = 0;
5144 int16_t ENDINGPALETTE = 0;
5145 int16_t NO386SCREEN = 0;
5146 int16_t T_DEMO0 = 0;
5147 int16_t T_DEMO1 = 0;
5148 int16_t T_DEMO2 = 0;
5149 int16_t T_DEMO3 = 0;
5150 int16_t T_DEMO4 = 0;
5151 int16_t T_DEMO5 = 0;
5152 int16_t DECOY = 0;
5153 int16_t DECOY2 = 0;
5154 int16_t DECOY3 = 0;
5155 int16_t DECOY4 = 0;
5156 
5157 
initialize_gfxv_contants()5158 void initialize_gfxv_contants()
5159 {
5160     if (::is_aog_sw()) {
5161         TELEPORTBACKPIC = 6;
5162         TELEPORT1OFFPIC = 7;
5163         TELEPORT2OFFPIC = 8;
5164         TELEPORT3OFFPIC = 9;
5165         TELEPORT4OFFPIC = 10;
5166         TELEPORT5OFFPIC = 11;
5167         TELEPORT6OFFPIC = 12;
5168         TELEPORT7OFFPIC = 13;
5169         TELEPORT8OFFPIC = 14;
5170         TELEPORT9OFFPIC = 15;
5171         TELEPORT10OFFPIC = 16;
5172         TELEPORT1ONPIC = 17;
5173         TELEPORT2ONPIC = 18;
5174         TELEPORT3ONPIC = 19;
5175         TELEPORT4ONPIC = 20;
5176         TELEPORT5ONPIC = 21;
5177         TELEPORT6ONPIC = 22;
5178         TELEPORT7ONPIC = 23;
5179         TELEPORT8ONPIC = 24;
5180         TELEPORT9ONPIC = 25;
5181         TELEPORT10ONPIC = 26;
5182         TELEPORT_TEXT_BG = 27;
5183         BACKGROUND_SCREENPIC = 28;
5184         APOGEEPIC = 29;
5185         PC13PIC = 30;
5186         LOSEPIC = 31;
5187         PSPROMO1PIC = 32;
5188         PSPROMO2PIC = 33;
5189         PSPROMO3PIC = 34;
5190         AUTOMAPPIC = 35;
5191         H_ALTPIC = 36;
5192         H_CTRLPIC = 37;
5193         H_SPACEPIC = 38;
5194         H_PAUSEPIC = 39;
5195         H_ESCPIC = 40;
5196         H_LTARROWPIC = 41;
5197         H_UPARROWPIC = 42;
5198         H_DNARROWPIC = 43;
5199         H_RTARROWPIC = 44;
5200         H_ENTERPIC = 45;
5201         H_QPIC = 46;
5202         H_WPIC = 47;
5203         H_EPIC = 48;
5204         H_IPIC = 49;
5205         H_HPIC = 50;
5206         H_1PIC = 51;
5207         H_2PIC = 52;
5208         H_3PIC = 53;
5209         H_4PIC = 54;
5210         H_5PIC = 55;
5211         H_F1PIC = 56;
5212         H_F2PIC = 57;
5213         H_F3PIC = 58;
5214         H_F4PIC = 59;
5215         H_F5PIC = 60;
5216         H_F6PIC = 61;
5217         H_F7PIC = 62;
5218         H_F8PIC = 63;
5219         H_F9PIC = 64;
5220         H_F10PIC = 65;
5221         H_TABPIC = 66;
5222         H_CPIC = 67;
5223         H_FPIC = 68;
5224         H_PPIC = 69;
5225         H_MPIC = 70;
5226         H_LPIC = 71;
5227         H_SHIFTPIC = 72;
5228         APOGEE_LOGOPIC = 73;
5229         VISAPIC = 74;
5230         MCPIC = 75;
5231         FAXPIC = 76;
5232         H_TOPWINDOWPIC = 77;
5233         H_LEFTWINDOWPIC = 78;
5234         H_RIGHTWINDOWPIC = 79;
5235         H_BOTTOMINFOPIC = 80;
5236         C_NOTSELECTEDPIC = 81;
5237         C_SELECTEDPIC = 82;
5238         C_NOTSELECTED_HIPIC = 83;
5239         C_SELECTED_HIPIC = 84;
5240         C_BABYMODEPIC = 85;
5241         C_EASYPIC = 86;
5242         C_NORMALPIC = 87;
5243         C_HARDPIC = 88;
5244         C_EPISODE1PIC = 89;
5245         C_EPISODE2PIC = 90;
5246         C_EPISODE3PIC = 91;
5247         C_EPISODE4PIC = 92;
5248         C_EPISODE5PIC = 93;
5249         C_EPISODE6PIC = 94;
5250         BIGGOLDSTERNPIC = 95;
5251         STARLOGOPIC = 96;
5252         BLAKEWITHGUNPIC = 97;
5253         STARINSTITUTEPIC = 98;
5254         MEDALOFHONORPIC = 99;
5255         SMALLGOLDSTERNPIC = 100;
5256         BLAKEWINPIC = 101;
5257         SHUTTLEEXPPIC = 102;
5258         PLANETSPIC = 103;
5259         MOUSEPIC = 104;
5260         JOYSTICKPIC = 105;
5261         GRAVISPADPIC = 106;
5262         TITLEPIC = 107;
5263         PROMO1PIC = 108;
5264         PROMO2PIC = 109;
5265         WEAPON1PIC = 110;
5266         WEAPON2PIC = 111;
5267         WEAPON3PIC = 112;
5268         WEAPON4PIC = 113;
5269         WEAPON5PIC = 114;
5270         WAITPIC = 115;
5271         READYPIC = 116;
5272         N_BLANKPIC = 117;
5273         N_0PIC = 118;
5274         N_1PIC = 119;
5275         N_2PIC = 120;
5276         N_3PIC = 121;
5277         N_4PIC = 122;
5278         N_5PIC = 123;
5279         N_6PIC = 124;
5280         N_7PIC = 125;
5281         N_8PIC = 126;
5282         N_9PIC = 127;
5283         N_RPIC = 128;
5284         N_OPIC = 129;
5285         N_LPIC = 130;
5286         N_DASHPIC = 131;
5287         DIM_LIGHTPIC = 132;
5288         BRI_LIGHTPIC = 133;
5289         ECG_HEART_GOOD = 134;
5290         ECG_HEART_BAD = 135;
5291         ECG_GRID_PIECE = 136;
5292         // ??? = 137
5293         ECG_HEARTBEAT_00 = 138;
5294         ECG_HEARTBEAT_01 = 139;
5295         ECG_HEARTBEAT_02 = 140;
5296         ECG_HEARTBEAT_03 = 141;
5297         ECG_HEARTBEAT_04 = 142;
5298         ECG_HEARTBEAT_05 = 143;
5299         ECG_HEARTBEAT_06 = 144;
5300         ECG_HEARTBEAT_07 = 145;
5301         ECG_HEARTBEAT_08 = 146;
5302         ECG_HEARTBEAT_09 = 147;
5303         ECG_HEARTBEAT_10 = 148;
5304         ECG_HEARTBEAT_11 = 149;
5305         ECG_HEARTBEAT_12 = 150;
5306         ECG_HEARTBEAT_13 = 151;
5307         ECG_HEARTBEAT_14 = 152;
5308         ECG_HEARTBEAT_15 = 153;
5309         ECG_HEARTBEAT_16 = 154;
5310         ECG_HEARTBEAT_17 = 155;
5311         ECG_HEARTBEAT_18 = 156;
5312         ECG_HEARTBEAT_19 = 157;
5313         ECG_HEARTBEAT_20 = 158;
5314         ECG_HEARTBEAT_21 = 159;
5315         ECG_HEARTBEAT_22 = 160;
5316         ECG_HEARTBEAT_23 = 161;
5317         ECG_HEARTBEAT_24 = 162;
5318         ECG_HEARTBEAT_25 = 163;
5319         ECG_HEARTBEAT_26 = 164;
5320         ECG_HEARTBEAT_27 = 165;
5321         INFOAREAPIC = 166;
5322         TOP_STATUSBARPIC = 167;
5323         STATUSBARPIC = 168;
5324         APOGEEPALETTE = 171;
5325         TITLEPALETTE = 175;
5326         ORDERSCREEN = 176;
5327         ERRORSCREEN = 177;
5328         INFORMANT_HINTS = 181;
5329         NICE_SCIE_HINTS = 182;
5330         MEAN_SCIE_HINTS = 183;
5331         BRIEF_W1 = 184;
5332         BRIEF_I1 = 185;
5333         LEVEL_DESCS = 186;
5334         POWERBALLTEXT = 187;
5335         TICSTEXT = 188;
5336         MUSICTEXT = 189;
5337         RADARTEXT = 190;
5338         HELPTEXT = 191;
5339         SAGATEXT = 192;
5340         LOSETEXT = 193;
5341         ORDERTEXT = 194;
5342         CREDITSTEXT = 195;
5343         MUSTBE386TEXT = 196;
5344         QUICK_INFO1_TEXT = 197;
5345         QUICK_INFO2_TEXT = 198;
5346         BADINFO_TEXT = 199;
5347         CALJOY1_TEXT = 200;
5348         CALJOY2_TEXT = 201;
5349         READTHIS_TEXT = 202;
5350         ELEVMSG0_TEXT = 203;
5351         ELEVMSG1_TEXT = 204;
5352         ELEVMSG4_TEXT = 205;
5353         ELEVMSG5_TEXT = 206;
5354         FLOORMSG_TEXT = 207;
5355         YOUWIN_TEXT = 208;
5356         CHANGEVIEW_TEXT = 209;
5357         BADLEVELSTEXT = 210;
5358         BADSAVEGAME_TEXT = 211;
5359 
5360 
5361         STRUCTPIC = 0;
5362 
5363         STARTFONT = 1;
5364         STARTFONTM = 6;
5365         STARTPICS = 6;
5366         STARTPICM = STATUSBARPIC + 1;
5367         STARTSPRITES = STATUSBARPIC + 1;
5368         STARTTILE8 = STATUSBARPIC + 1;
5369         STARTTILE8M = STATUSBARPIC + 2;
5370         STARTTILE16 = STATUSBARPIC + 2;
5371         STARTTILE16M = STATUSBARPIC + 2;
5372         STARTTILE32 = STATUSBARPIC + 2;
5373         STARTTILE32M = STATUSBARPIC + 2;
5374         STARTEXTERNS = STATUSBARPIC + 2;
5375 
5376         TELEPORT_LUMP_START = TELEPORTBACKPIC;
5377         TELEPORT_LUMP_END = TELEPORT_TEXT_BG;
5378 
5379         README_LUMP_START = H_ALTPIC;
5380         README_LUMP_END = H_BOTTOMINFOPIC;
5381 
5382         CONTROLS_LUMP_START = C_NOTSELECTEDPIC;
5383         CONTROLS_LUMP_END = C_EPISODE6PIC;
5384 
5385         LATCHPICS_LUMP_START = WEAPON1PIC;
5386         LATCHPICS_LUMP_END = STATUSBARPIC;
5387 
5388         NUMCHUNKS = 212;
5389         NUMFONT = 5;
5390         NUMFONTM = 0;
5391         NUMPICS = 163;
5392         NUMPICM = 0;
5393         NUMSPRITES = 0;
5394         NUMTILE8 = 72;
5395         NUMTILE8M = 0;
5396         NUMTILE16 = 0;
5397         NUMTILE16M = 0;
5398         NUMTILE32 = 0;
5399         NUMTILE32M = 0;
5400         NUMEXTERNS = NUMCHUNKS - (STATUSBARPIC + 2);
5401     } else if (::is_aog_full_v1_0()) {
5402         TELEPORTBACKPIC = 6;
5403         TELEPORT1OFFPIC = 7;
5404         TELEPORT2OFFPIC = 8;
5405         TELEPORT3OFFPIC = 9;
5406         TELEPORT4OFFPIC = 10;
5407         TELEPORT5OFFPIC = 11;
5408         TELEPORT6OFFPIC = 12;
5409         TELEPORT7OFFPIC = 13;
5410         TELEPORT8OFFPIC = 14;
5411         TELEPORT9OFFPIC = 15;
5412         TELEPORT10OFFPIC = 16;
5413         TELEPORT1ONPIC = 17;
5414         TELEPORT2ONPIC = 18;
5415         TELEPORT3ONPIC = 19;
5416         TELEPORT4ONPIC = 20;
5417         TELEPORT5ONPIC = 21;
5418         TELEPORT6ONPIC = 22;
5419         TELEPORT7ONPIC = 23;
5420         TELEPORT8ONPIC = 24;
5421         TELEPORT9ONPIC = 25;
5422         TELEPORT10ONPIC = 26;
5423         TELEPORT_TEXT_BG = 27;
5424         BACKGROUND_SCREENPIC = 28;
5425         APOGEEPIC = 29;
5426         PIRACYPIC = 30;
5427         PC13PIC = 31;
5428         LOSEPIC = 32;
5429         AUTOMAPPIC = 33;
5430         H_ALTPIC = 34;
5431         H_CTRLPIC = 35;
5432         H_SPACEPIC = 36;
5433         H_PAUSEPIC = 37;
5434         H_ESCPIC = 38;
5435         H_LTARROWPIC = 39;
5436         H_UPARROWPIC = 40;
5437         H_DNARROWPIC = 41;
5438         H_RTARROWPIC = 42;
5439         H_ENTERPIC = 43;
5440         H_QPIC = 44;
5441         H_WPIC = 45;
5442         H_EPIC = 46;
5443         H_IPIC = 47;
5444         H_HPIC = 48;
5445         H_1PIC = 49;
5446         H_2PIC = 50;
5447         H_3PIC = 51;
5448         H_4PIC = 52;
5449         H_5PIC = 53;
5450         H_F1PIC = 54;
5451         H_F2PIC = 55;
5452         H_F3PIC = 56;
5453         H_F4PIC = 57;
5454         H_F5PIC = 58;
5455         H_F6PIC = 59;
5456         H_F7PIC = 60;
5457         H_F8PIC = 61;
5458         H_F9PIC = 62;
5459         H_F10PIC = 63;
5460         H_TABPIC = 64;
5461         H_CPIC = 65;
5462         H_FPIC = 66;
5463         H_PPIC = 67;
5464         H_MPIC = 68;
5465         APOGEE_LOGOPIC = 69;
5466         VISAPIC = 70;
5467         MCPIC = 71;
5468         FAXPIC = 72;
5469         H_TOPWINDOWPIC = 73;
5470         H_LEFTWINDOWPIC = 74;
5471         H_RIGHTWINDOWPIC = 75;
5472         H_BOTTOMINFOPIC = 76;
5473         C_NOTSELECTEDPIC = 77;
5474         C_SELECTEDPIC = 78;
5475         C_NOTSELECTED_HIPIC = 79;
5476         C_SELECTED_HIPIC = 80;
5477         C_BABYMODEPIC = 81;
5478         C_EASYPIC = 82;
5479         C_NORMALPIC = 83;
5480         C_HARDPIC = 84;
5481         C_EPISODE1PIC = 85;
5482         C_EPISODE2PIC = 86;
5483         C_EPISODE3PIC = 87;
5484         C_EPISODE4PIC = 88;
5485         C_EPISODE5PIC = 89;
5486         C_EPISODE6PIC = 90;
5487         BIGGOLDSTERNPIC = 91;
5488         STARLOGOPIC = 92;
5489         BLAKEWITHGUNPIC = 93;
5490         STARINSTITUTEPIC = 94;
5491         MEDALOFHONORPIC = 95;
5492         SMALLGOLDSTERNPIC = 96;
5493         BLAKEWINPIC = 97;
5494         SHUTTLEEXPPIC = 98;
5495         PLANETSPIC = 99;
5496         MOUSEPIC = 100;
5497         JOYSTICKPIC = 101;
5498         GRAVISPADPIC = 102;
5499         TITLEPIC = 103;
5500         WEAPON1PIC = 104;
5501         WEAPON2PIC = 105;
5502         WEAPON3PIC = 106;
5503         WEAPON4PIC = 107;
5504         WEAPON5PIC = 108;
5505         WAITPIC = 109;
5506         READYPIC = 110;
5507         N_BLANKPIC = 111;
5508         N_0PIC = 112;
5509         N_1PIC = 113;
5510         N_2PIC = 114;
5511         N_3PIC = 115;
5512         N_4PIC = 116;
5513         N_5PIC = 117;
5514         N_6PIC = 118;
5515         N_7PIC = 119;
5516         N_8PIC = 120;
5517         N_9PIC = 121;
5518         N_RPIC = 122;
5519         N_OPIC = 123;
5520         N_LPIC = 124;
5521         N_DASHPIC = 125;
5522         DIM_LIGHTPIC = 126;
5523         BRI_LIGHTPIC = 127;
5524         ECG_HEART_GOOD = 128;
5525         ECG_HEART_BAD = 129;
5526         ECG_GRID_PIECE = 130;
5527         ECG_HEARTBEAT_00 = 132;
5528         ECG_HEARTBEAT_01 = 133;
5529         ECG_HEARTBEAT_02 = 134;
5530         ECG_HEARTBEAT_03 = 135;
5531         ECG_HEARTBEAT_04 = 136;
5532         ECG_HEARTBEAT_05 = 137;
5533         ECG_HEARTBEAT_06 = 138;
5534         ECG_HEARTBEAT_07 = 139;
5535         ECG_HEARTBEAT_08 = 140;
5536         ECG_HEARTBEAT_09 = 141;
5537         ECG_HEARTBEAT_10 = 142;
5538         ECG_HEARTBEAT_11 = 143;
5539         ECG_HEARTBEAT_12 = 144;
5540         ECG_HEARTBEAT_13 = 145;
5541         ECG_HEARTBEAT_14 = 146;
5542         ECG_HEARTBEAT_15 = 147;
5543         ECG_HEARTBEAT_16 = 148;
5544         ECG_HEARTBEAT_17 = 149;
5545         ECG_HEARTBEAT_18 = 150;
5546         ECG_HEARTBEAT_19 = 151;
5547         ECG_HEARTBEAT_20 = 152;
5548         ECG_HEARTBEAT_21 = 153;
5549         ECG_HEARTBEAT_22 = 154;
5550         ECG_HEARTBEAT_23 = 155;
5551         ECG_HEARTBEAT_24 = 156;
5552         ECG_HEARTBEAT_25 = 157;
5553         ECG_HEARTBEAT_26 = 158;
5554         ECG_HEARTBEAT_27 = 159;
5555         INFOAREAPIC = 160;
5556         TOP_STATUSBARPIC = 161;
5557         STATUSBARPIC = 162;
5558         PIRACYPALETTE = 164;
5559         APOGEEPALETTE = 165;
5560         TITLEPALETTE = 166;
5561         ORDERSCREEN = 167;
5562         ERRORSCREEN = 168;
5563         INFORMANT_HINTS = 175;
5564         NICE_SCIE_HINTS = 176;
5565         MEAN_SCIE_HINTS = 177;
5566         BRIEF_W1 = 178;
5567         BRIEF_I1 = 179;
5568         BRIEF_W2 = 180;
5569         BRIEF_I2 = 181;
5570         BRIEF_W3 = 182;
5571         BRIEF_I3 = 183;
5572         BRIEF_W4 = 184;
5573         BRIEF_I4 = 185;
5574         BRIEF_W5 = 186;
5575         BRIEF_I5 = 187;
5576         BRIEF_W6 = 188;
5577         BRIEF_I6 = 189;
5578         LEVEL_DESCS = 190;
5579         HELPTEXT = 191;
5580         SAGATEXT = 192;
5581         LOSETEXT = 193;
5582         ORDERTEXT = 194;
5583         CREDITSTEXT = 195;
5584         MUSTBE386TEXT = 196;
5585         QUICK_INFO1_TEXT = 197;
5586         QUICK_INFO2_TEXT = 198;
5587         BADINFO_TEXT = 199;
5588         CALJOY1_TEXT = 200;
5589         CALJOY2_TEXT = 201;
5590         READTHIS_TEXT = 202;
5591         ELEVMSG0_TEXT = 203;
5592         ELEVMSG1_TEXT = 204;
5593         ELEVMSG4_TEXT = 205;
5594         ELEVMSG5_TEXT = 206;
5595         FLOORMSG_TEXT = 207;
5596         YOUWIN_TEXT = 208;
5597         CHANGEVIEW_TEXT = 209;
5598         DIZ_ERR_TEXT = 210;
5599         BADLEVELSTEXT = 211;
5600 
5601 
5602         STRUCTPIC = 0;
5603 
5604         STARTFONT = 1;
5605         STARTFONTM = 6;
5606         STARTPICS = 6;
5607         STARTPICM = STATUSBARPIC + 1;
5608         STARTSPRITES = STATUSBARPIC + 1;
5609         STARTTILE8 = STATUSBARPIC + 1;
5610         STARTTILE8M = STATUSBARPIC + 2;
5611         STARTTILE16 = STATUSBARPIC + 2;
5612         STARTTILE16M = STATUSBARPIC + 2;
5613         STARTTILE32 = STATUSBARPIC + 2;
5614         STARTTILE32M = STATUSBARPIC + 2;
5615         STARTEXTERNS = STATUSBARPIC + 2;
5616 
5617         TELEPORT_LUMP_START = TELEPORTBACKPIC;
5618         TELEPORT_LUMP_END = TELEPORT_TEXT_BG;
5619 
5620         README_LUMP_START = H_ALTPIC;
5621         README_LUMP_END = H_BOTTOMINFOPIC;
5622 
5623         CONTROLS_LUMP_START = C_NOTSELECTEDPIC;
5624         CONTROLS_LUMP_END = C_EPISODE6PIC;
5625 
5626         LATCHPICS_LUMP_START = WEAPON1PIC;
5627         LATCHPICS_LUMP_END = STATUSBARPIC;
5628 
5629         NUMCHUNKS = 212;
5630         NUMFONT = 5;
5631         NUMFONTM = 0;
5632         NUMPICS = 157;
5633         NUMPICM = 0;
5634         NUMSPRITES = 0;
5635         NUMTILE8 = 72;
5636         NUMTILE8M = 0;
5637         NUMTILE16 = 0;
5638         NUMTILE16M = 0;
5639         NUMTILE32 = 0;
5640         NUMTILE32M = 0;
5641         NUMEXTERNS = NUMCHUNKS - (STARTEXTERNS + 2);
5642     } else if (::is_aog_full_v2_x()) {
5643         TELEPORTBACKPIC = 6;
5644         TELEPORT1OFFPIC = 7;
5645         TELEPORT2OFFPIC = 8;
5646         TELEPORT3OFFPIC = 9;
5647         TELEPORT4OFFPIC = 10;
5648         TELEPORT5OFFPIC = 11;
5649         TELEPORT6OFFPIC = 12;
5650         TELEPORT7OFFPIC = 13;
5651         TELEPORT8OFFPIC = 14;
5652         TELEPORT9OFFPIC = 15;
5653         TELEPORT10OFFPIC = 16;
5654         TELEPORT1ONPIC = 17;
5655         TELEPORT2ONPIC = 18;
5656         TELEPORT3ONPIC = 19;
5657         TELEPORT4ONPIC = 20;
5658         TELEPORT5ONPIC = 21;
5659         TELEPORT6ONPIC = 22;
5660         TELEPORT7ONPIC = 23;
5661         TELEPORT8ONPIC = 24;
5662         TELEPORT9ONPIC = 25;
5663         TELEPORT10ONPIC = 26;
5664         TELEPORT_TEXT_BG = 27;
5665         BACKGROUND_SCREENPIC = 28;
5666         APOGEEPIC = 29;
5667         PIRACYPIC = 30;
5668         PC13PIC = 31;
5669         LOSEPIC = 32;
5670         AUTOMAPPIC = 33;
5671         H_ALTPIC = 34;
5672         H_CTRLPIC = 35;
5673         H_SPACEPIC = 36;
5674         H_PAUSEPIC = 37;
5675         H_ESCPIC = 38;
5676         H_LTARROWPIC = 39;
5677         H_UPARROWPIC = 40;
5678         H_DNARROWPIC = 41;
5679         H_RTARROWPIC = 42;
5680         H_ENTERPIC = 43;
5681         H_QPIC = 44;
5682         H_WPIC = 45;
5683         H_EPIC = 46;
5684         H_IPIC = 47;
5685         H_HPIC = 48;
5686         H_1PIC = 49;
5687         H_2PIC = 50;
5688         H_3PIC = 51;
5689         H_4PIC = 52;
5690         H_5PIC = 53;
5691         H_F1PIC = 54;
5692         H_F2PIC = 55;
5693         H_F3PIC = 56;
5694         H_F4PIC = 57;
5695         H_F5PIC = 58;
5696         H_F6PIC = 59;
5697         H_F7PIC = 60;
5698         H_F8PIC = 61;
5699         H_F9PIC = 62;
5700         H_F10PIC = 63;
5701         H_TABPIC = 64;
5702         H_CPIC = 65;
5703         H_FPIC = 66;
5704         H_PPIC = 67;
5705         H_MPIC = 68;
5706         H_LPIC = 69;
5707         H_SHIFTPIC = 70;
5708         APOGEE_LOGOPIC = 71;
5709         VISAPIC = 72;
5710         MCPIC = 73;
5711         FAXPIC = 74;
5712         H_TOPWINDOWPIC = 75;
5713         H_LEFTWINDOWPIC = 76;
5714         H_RIGHTWINDOWPIC = 77;
5715         H_BOTTOMINFOPIC = 78;
5716         C_NOTSELECTEDPIC = 79;
5717         C_SELECTEDPIC = 80;
5718         C_NOTSELECTED_HIPIC = 81;
5719         C_SELECTED_HIPIC = 82;
5720         C_BABYMODEPIC = 83;
5721         C_EASYPIC = 84;
5722         C_NORMALPIC = 85;
5723         C_HARDPIC = 86;
5724         C_EPISODE1PIC = 87;
5725         C_EPISODE2PIC = 88;
5726         C_EPISODE3PIC = 89;
5727         C_EPISODE4PIC = 90;
5728         C_EPISODE5PIC = 91;
5729         C_EPISODE6PIC = 92;
5730         BIGGOLDSTERNPIC = 93;
5731         STARLOGOPIC = 94;
5732         BLAKEWITHGUNPIC = 95;
5733         STARINSTITUTEPIC = 96;
5734         MEDALOFHONORPIC = 97;
5735         SMALLGOLDSTERNPIC = 98;
5736         BLAKEWINPIC = 99;
5737         SHUTTLEEXPPIC = 100;
5738         PLANETSPIC = 101;
5739         MOUSEPIC = 102;
5740         JOYSTICKPIC = 103;
5741         GRAVISPADPIC = 104;
5742         TITLEPIC = 105;
5743         WEAPON1PIC = 106;
5744         WEAPON2PIC = 107;
5745         WEAPON3PIC = 108;
5746         WEAPON4PIC = 109;
5747         WEAPON5PIC = 110;
5748         WAITPIC = 111;
5749         READYPIC = 112;
5750         N_BLANKPIC = 113;
5751         N_0PIC = 114;
5752         N_1PIC = 115;
5753         N_2PIC = 116;
5754         N_3PIC = 117;
5755         N_4PIC = 118;
5756         N_5PIC = 119;
5757         N_6PIC = 120;
5758         N_7PIC = 121;
5759         N_8PIC = 122;
5760         N_9PIC = 123;
5761         N_RPIC = 124;
5762         N_OPIC = 125;
5763         N_LPIC = 126;
5764         N_DASHPIC = 127;
5765         DIM_LIGHTPIC = 128;
5766         BRI_LIGHTPIC = 129;
5767         ECG_HEART_GOOD = 130;
5768         ECG_HEART_BAD = 131;
5769         ECG_GRID_PIECE = 132;
5770         ECG_HEARTBEAT_00 = 134;
5771         ECG_HEARTBEAT_01 = 135;
5772         ECG_HEARTBEAT_02 = 136;
5773         ECG_HEARTBEAT_03 = 137;
5774         ECG_HEARTBEAT_04 = 138;
5775         ECG_HEARTBEAT_05 = 139;
5776         ECG_HEARTBEAT_06 = 140;
5777         ECG_HEARTBEAT_07 = 141;
5778         ECG_HEARTBEAT_08 = 142;
5779         ECG_HEARTBEAT_09 = 143;
5780         ECG_HEARTBEAT_10 = 144;
5781         ECG_HEARTBEAT_11 = 145;
5782         ECG_HEARTBEAT_12 = 146;
5783         ECG_HEARTBEAT_13 = 147;
5784         ECG_HEARTBEAT_14 = 148;
5785         ECG_HEARTBEAT_15 = 149;
5786         ECG_HEARTBEAT_16 = 150;
5787         ECG_HEARTBEAT_17 = 151;
5788         ECG_HEARTBEAT_18 = 152;
5789         ECG_HEARTBEAT_19 = 153;
5790         ECG_HEARTBEAT_20 = 154;
5791         ECG_HEARTBEAT_21 = 155;
5792         ECG_HEARTBEAT_22 = 156;
5793         ECG_HEARTBEAT_23 = 157;
5794         ECG_HEARTBEAT_24 = 158;
5795         ECG_HEARTBEAT_25 = 159;
5796         ECG_HEARTBEAT_26 = 160;
5797         ECG_HEARTBEAT_27 = 161;
5798         INFOAREAPIC = 162;
5799         TOP_STATUSBARPIC = 163;
5800         STATUSBARPIC = 164;
5801         PIRACYPALETTE = 167;
5802         APOGEEPALETTE = 168;
5803         TITLEPALETTE = 169;
5804         ORDERSCREEN = 170;
5805         ERRORSCREEN = 171;
5806         INFORMANT_HINTS = 181;
5807         NICE_SCIE_HINTS = 182;
5808         MEAN_SCIE_HINTS = 183;
5809         BRIEF_W1 = 184;
5810         BRIEF_I1 = 185;
5811         BRIEF_W2 = 186;
5812         BRIEF_I2 = 187;
5813         BRIEF_W3 = 188;
5814         BRIEF_I3 = 189;
5815         BRIEF_W4 = 190;
5816         BRIEF_I4 = 191;
5817         BRIEF_W5 = 192;
5818         BRIEF_I5 = 193;
5819         BRIEF_W6 = 194;
5820         BRIEF_I6 = 195;
5821         LEVEL_DESCS = 196;
5822         POWERBALLTEXT = 197;
5823         TICSTEXT = 198;
5824         MUSICTEXT = 199;
5825         RADARTEXT = 200;
5826         HELPTEXT = 201;
5827         SAGATEXT = 202;
5828         LOSETEXT = 203;
5829         ORDERTEXT = 204;
5830         CREDITSTEXT = 205;
5831         MUSTBE386TEXT = 206;
5832         QUICK_INFO1_TEXT = 207;
5833         QUICK_INFO2_TEXT = 208;
5834         BADINFO_TEXT = 209;
5835         CALJOY1_TEXT = 210;
5836         CALJOY2_TEXT = 211;
5837         READTHIS_TEXT = 212;
5838         ELEVMSG0_TEXT = 213;
5839         ELEVMSG1_TEXT = 214;
5840         ELEVMSG4_TEXT = 215;
5841         ELEVMSG5_TEXT = 216;
5842         FLOORMSG_TEXT = 217;
5843         YOUWIN_TEXT = 218;
5844         CHANGEVIEW_TEXT = 219;
5845         DIZ_ERR_TEXT = 220;
5846         BADLEVELSTEXT = 221;
5847         BADSAVEGAME_TEXT = 222;
5848 
5849 
5850         STRUCTPIC = 0;
5851 
5852         STARTFONT = 1;
5853         STARTFONTM = 6;
5854         STARTPICS = 6;
5855         STARTPICM = STATUSBARPIC + 1;
5856         STARTSPRITES = STATUSBARPIC + 1;
5857         STARTTILE8 = STATUSBARPIC + 1;
5858         STARTTILE8M = STATUSBARPIC + 2;
5859         STARTTILE16 = STATUSBARPIC + 2;
5860         STARTTILE16M = STATUSBARPIC + 2;
5861         STARTTILE32 = STATUSBARPIC + 2;
5862         STARTTILE32M = STATUSBARPIC + 2;
5863         STARTEXTERNS = STATUSBARPIC + 2;
5864 
5865         TELEPORT_LUMP_START = TELEPORTBACKPIC;
5866         TELEPORT_LUMP_END = TELEPORT_TEXT_BG;
5867 
5868         README_LUMP_START = H_ALTPIC;
5869         README_LUMP_END = H_BOTTOMINFOPIC;
5870 
5871         CONTROLS_LUMP_START = C_NOTSELECTEDPIC;
5872         CONTROLS_LUMP_END = C_EPISODE6PIC;
5873 
5874         LATCHPICS_LUMP_START = WEAPON1PIC;
5875         LATCHPICS_LUMP_END = STATUSBARPIC;
5876 
5877         NUMCHUNKS = 223;
5878         NUMFONT = 5;
5879         NUMFONTM = 0;
5880         NUMPICS = 159;
5881         NUMPICM = 0;
5882         NUMSPRITES = 0;
5883         NUMTILE8 = 72;
5884         NUMTILE8M = 0;
5885         NUMTILE16 = 0;
5886         NUMTILE16M = 0;
5887         NUMTILE32 = 0;
5888         NUMTILE32M = 0;
5889         NUMEXTERNS = NUMCHUNKS - (STARTEXTERNS + 2);
5890     } else if (::is_aog_full_v3_0()) {
5891         TELEPORTBACKPIC = 6;
5892         TELEPORT1OFFPIC = 7;
5893         TELEPORT2OFFPIC = 8;
5894         TELEPORT3OFFPIC = 9;
5895         TELEPORT4OFFPIC = 10;
5896         TELEPORT5OFFPIC = 11;
5897         TELEPORT6OFFPIC = 12;
5898         TELEPORT7OFFPIC = 13;
5899         TELEPORT8OFFPIC = 14;
5900         TELEPORT9OFFPIC = 15;
5901         TELEPORT10OFFPIC = 16;
5902         TELEPORT1ONPIC = 17;
5903         TELEPORT2ONPIC = 18;
5904         TELEPORT3ONPIC = 19;
5905         TELEPORT4ONPIC = 20;
5906         TELEPORT5ONPIC = 21;
5907         TELEPORT6ONPIC = 22;
5908         TELEPORT7ONPIC = 23;
5909         TELEPORT8ONPIC = 24;
5910         TELEPORT9ONPIC = 25;
5911         TELEPORT10ONPIC = 26;
5912         TELEPORT_TEXT_BG = 27;
5913         BACKGROUND_SCREENPIC = 28;
5914         APOGEEPIC = 29;
5915         PIRACYPIC = 30;
5916         PC13PIC = 31;
5917         LOSEPIC = 32;
5918         PSPROMO1PIC = 33;
5919         PSPROMO2PIC = 34;
5920         PSPROMO3PIC = 35;
5921 
5922         AUTOMAPPIC = 36;
5923         H_ALTPIC = 37;
5924         H_CTRLPIC = 38;
5925         H_SPACEPIC = 39;
5926         H_PAUSEPIC = 40;
5927         H_ESCPIC = 41;
5928         H_LTARROWPIC = 42;
5929         H_UPARROWPIC = 43;
5930         H_DNARROWPIC = 44;
5931         H_RTARROWPIC = 45;
5932         H_ENTERPIC = 46;
5933         H_QPIC = 47;
5934         H_WPIC = 48;
5935         H_EPIC = 49;
5936         H_IPIC = 50;
5937         H_HPIC = 51;
5938         H_1PIC = 52;
5939         H_2PIC = 53;
5940         H_3PIC = 54;
5941         H_4PIC = 55;
5942         H_5PIC = 56;
5943         H_F1PIC = 57;
5944         H_F2PIC = 58;
5945         H_F3PIC = 59;
5946         H_F4PIC = 60;
5947         H_F5PIC = 61;
5948         H_F6PIC = 62;
5949         H_F7PIC = 63;
5950         H_F8PIC = 64;
5951         H_F9PIC = 65;
5952         H_F10PIC = 66;
5953         H_TABPIC = 67;
5954         H_CPIC = 68;
5955         H_FPIC = 69;
5956         H_PPIC = 70;
5957         H_MPIC = 71;
5958         H_LPIC = 72;
5959         H_SHIFTPIC = 73;
5960         APOGEE_LOGOPIC = 74;
5961         VISAPIC = 75;
5962         MCPIC = 76;
5963         FAXPIC = 77;
5964         H_TOPWINDOWPIC = 78;
5965         H_LEFTWINDOWPIC = 79;
5966         H_RIGHTWINDOWPIC = 80;
5967         H_BOTTOMINFOPIC = 81;
5968         C_NOTSELECTEDPIC = 82;
5969         C_SELECTEDPIC = 83;
5970         C_NOTSELECTED_HIPIC = 84;
5971         C_SELECTED_HIPIC = 85;
5972         C_BABYMODEPIC = 86;
5973         C_EASYPIC = 87;
5974         C_NORMALPIC = 88;
5975         C_HARDPIC = 89;
5976         C_EPISODE1PIC = 90;
5977         C_EPISODE2PIC = 91;
5978         C_EPISODE3PIC = 92;
5979         C_EPISODE4PIC = 93;
5980         C_EPISODE5PIC = 94;
5981         C_EPISODE6PIC = 95;
5982         BIGGOLDSTERNPIC = 96;
5983         STARLOGOPIC = 97;
5984         BLAKEWITHGUNPIC = 98;
5985         STARINSTITUTEPIC = 99;
5986         MEDALOFHONORPIC = 100;
5987         SMALLGOLDSTERNPIC = 101;
5988         BLAKEWINPIC = 102;
5989         SHUTTLEEXPPIC = 103;
5990         PLANETSPIC = 104;
5991         MOUSEPIC = 105;
5992         JOYSTICKPIC = 106;
5993         GRAVISPADPIC = 107;
5994         TITLEPIC = 108;
5995         WEAPON1PIC = 109;
5996         WEAPON2PIC = 110;
5997         WEAPON3PIC = 111;
5998         WEAPON4PIC = 112;
5999         WEAPON5PIC = 113;
6000         WAITPIC = 114;
6001         READYPIC = 115;
6002         N_BLANKPIC = 116;
6003         N_0PIC = 117;
6004         N_1PIC = 118;
6005         N_2PIC = 119;
6006         N_3PIC = 120;
6007         N_4PIC = 121;
6008         N_5PIC = 122;
6009         N_6PIC = 123;
6010         N_7PIC = 124;
6011         N_8PIC = 125;
6012         N_9PIC = 126;
6013         N_RPIC = 127;
6014         N_OPIC = 128;
6015         N_LPIC = 129;
6016         N_DASHPIC = 130;
6017         DIM_LIGHTPIC = 131;
6018         BRI_LIGHTPIC = 132;
6019         ECG_HEART_GOOD = 133;
6020         ECG_HEART_BAD = 134;
6021         ECG_GRID_PIECE = 135;
6022         ECG_HEARTBEAT_00 = 137;
6023         ECG_HEARTBEAT_01 = 138;
6024         ECG_HEARTBEAT_02 = 139;
6025         ECG_HEARTBEAT_03 = 140;
6026         ECG_HEARTBEAT_04 = 141;
6027         ECG_HEARTBEAT_05 = 142;
6028         ECG_HEARTBEAT_06 = 143;
6029         ECG_HEARTBEAT_07 = 144;
6030         ECG_HEARTBEAT_08 = 145;
6031         ECG_HEARTBEAT_09 = 146;
6032         ECG_HEARTBEAT_10 = 147;
6033         ECG_HEARTBEAT_11 = 148;
6034         ECG_HEARTBEAT_12 = 149;
6035         ECG_HEARTBEAT_13 = 150;
6036         ECG_HEARTBEAT_14 = 151;
6037         ECG_HEARTBEAT_15 = 152;
6038         ECG_HEARTBEAT_16 = 153;
6039         ECG_HEARTBEAT_17 = 154;
6040         ECG_HEARTBEAT_18 = 155;
6041         ECG_HEARTBEAT_19 = 156;
6042         ECG_HEARTBEAT_20 = 157;
6043         ECG_HEARTBEAT_21 = 158;
6044         ECG_HEARTBEAT_22 = 159;
6045         ECG_HEARTBEAT_23 = 160;
6046         ECG_HEARTBEAT_24 = 161;
6047         ECG_HEARTBEAT_25 = 162;
6048         ECG_HEARTBEAT_26 = 163;
6049         ECG_HEARTBEAT_27 = 164;
6050         INFOAREAPIC = 165;
6051         TOP_STATUSBARPIC = 166;
6052         STATUSBARPIC = 167;
6053         PIRACYPALETTE = 170;
6054         APOGEEPALETTE = 171;
6055         TITLEPALETTE = 172;
6056         ORDERSCREEN = 173;
6057         ERRORSCREEN = 174;
6058         INFORMANT_HINTS = 183;
6059         NICE_SCIE_HINTS = 184;
6060         MEAN_SCIE_HINTS = 185;
6061         BRIEF_W1 = 186;
6062         BRIEF_I1 = 187;
6063         BRIEF_W2 = 188;
6064         BRIEF_I2 = 189;
6065         BRIEF_W3 = 190;
6066         BRIEF_I3 = 191;
6067         BRIEF_W4 = 192;
6068         BRIEF_I4 = 193;
6069         BRIEF_W5 = 194;
6070         BRIEF_I5 = 195;
6071         BRIEF_W6 = 196;
6072         BRIEF_I6 = 197;
6073         LEVEL_DESCS = 198;
6074         POWERBALLTEXT = 199;
6075         TICSTEXT = 200;
6076         MUSICTEXT = 201;
6077         RADARTEXT = 202;
6078         HELPTEXT = 203;
6079         SAGATEXT = 204;
6080         LOSETEXT = 205;
6081         ORDERTEXT = 206;
6082         CREDITSTEXT = 207;
6083         MUSTBE386TEXT = 208;
6084         QUICK_INFO1_TEXT = 209;
6085         QUICK_INFO2_TEXT = 210;
6086         BADINFO_TEXT = 211;
6087         CALJOY1_TEXT = 212;
6088         CALJOY2_TEXT = 213;
6089         READTHIS_TEXT = 214;
6090         ELEVMSG0_TEXT = 215;
6091         ELEVMSG1_TEXT = 216;
6092         ELEVMSG4_TEXT = 217;
6093         ELEVMSG5_TEXT = 218;
6094         FLOORMSG_TEXT = 219;
6095         YOUWIN_TEXT = 220;
6096         CHANGEVIEW_TEXT = 221;
6097         DIZ_ERR_TEXT = 222;
6098         BADLEVELSTEXT = 223;
6099         BADSAVEGAME_TEXT = 224;
6100 
6101 
6102         STRUCTPIC = 0;
6103 
6104         STARTFONT = 1;
6105         STARTFONTM = 6;
6106         STARTPICS = 6;
6107         STARTPICM = STATUSBARPIC + 1;
6108         STARTSPRITES = STATUSBARPIC + 1;
6109         STARTTILE8 = STATUSBARPIC + 1;
6110         STARTTILE8M = STATUSBARPIC + 2;
6111         STARTTILE16 = STATUSBARPIC + 2;
6112         STARTTILE16M = STATUSBARPIC + 2;
6113         STARTTILE32 = STATUSBARPIC + 2;
6114         STARTTILE32M = STATUSBARPIC + 2;
6115         STARTEXTERNS = STATUSBARPIC + 2;
6116 
6117         TELEPORT_LUMP_START = TELEPORTBACKPIC;
6118         TELEPORT_LUMP_END = TELEPORT_TEXT_BG;
6119 
6120         README_LUMP_START = H_ALTPIC;
6121         README_LUMP_END = H_BOTTOMINFOPIC;
6122 
6123         CONTROLS_LUMP_START = C_NOTSELECTEDPIC;
6124         CONTROLS_LUMP_END = C_EPISODE6PIC;
6125 
6126         LATCHPICS_LUMP_START = WEAPON1PIC;
6127         LATCHPICS_LUMP_END = STATUSBARPIC;
6128 
6129         NUMCHUNKS = 225;
6130         NUMFONT = 5;
6131         NUMFONTM = 0;
6132         NUMPICS = 162;
6133         NUMPICM = 0;
6134         NUMSPRITES = 0;
6135         NUMTILE8 = 72;
6136         NUMTILE8M = 0;
6137         NUMTILE16 = 0;
6138         NUMTILE16M = 0;
6139         NUMTILE32 = 0;
6140         NUMTILE32M = 0;
6141         NUMEXTERNS = NUMCHUNKS - (STARTEXTERNS + 2);
6142     } else if (::is_ps()) {
6143         TELEPORTBACKTOPPIC = 6;
6144         TELEPORTBACKBOTPIC = 7;
6145         TELEPORT1ONPIC = 8;
6146         TELEPORT2ONPIC = 9;
6147         TELEPORT3ONPIC = 10;
6148         TELEPORT4ONPIC = 11;
6149         TELEPORT5ONPIC = 12;
6150         TELEPORT6ONPIC = 13;
6151         TELEPORT7ONPIC = 14;
6152         TELEPORT8ONPIC = 15;
6153         TELEPORT9ONPIC = 16;
6154         TELEPORT10ONPIC = 17;
6155         TELEPORT11ONPIC = 18;
6156         TELEPORT12ONPIC = 19;
6157         TELEPORT13ONPIC = 20;
6158         TELEPORT14ONPIC = 21;
6159         TELEPORT15ONPIC = 22;
6160         TELEPORT16ONPIC = 23;
6161         TELEPORT17ONPIC = 24;
6162         TELEPORT18ONPIC = 25;
6163         TELEPORT19ONPIC = 26;
6164         TELEPORT20ONPIC = 27;
6165         TELEUPONPIC = 28;
6166         TELEDNONPIC = 29;
6167         TELEUPOFFPIC = 30;
6168         TELEDNOFFPIC = 31;
6169         TELEPORT1OFFPIC = 32;
6170         TELEPORT2OFFPIC = 33;
6171         TELEPORT3OFFPIC = 34;
6172         TELEPORT4OFFPIC = 35;
6173         TELEPORT5OFFPIC = 36;
6174         TELEPORT6OFFPIC = 37;
6175         TELEPORT7OFFPIC = 38;
6176         TELEPORT8OFFPIC = 39;
6177         TELEPORT9OFFPIC = 40;
6178         TELEPORT10OFFPIC = 41;
6179         TELEPORT11OFFPIC = 42;
6180         TELEPORT12OFFPIC = 43;
6181         TELEPORT13OFFPIC = 44;
6182         TELEPORT14OFFPIC = 45;
6183         TELEPORT15OFFPIC = 46;
6184         TELEPORT16OFFPIC = 47;
6185         TELEPORT17OFFPIC = 48;
6186         TELEPORT18OFFPIC = 49;
6187         TELEPORT19OFFPIC = 50;
6188         TELEPORT20OFFPIC = 51;
6189         BACKGROUND_SCREENPIC = 52;
6190         APOGEEPIC = 53;
6191         PC13PIC = 54;
6192         LOSEPIC = 55;
6193         AUTOMAPPIC = 56;
6194         AUTOMAP_MAG1PIC = 57;
6195         AUTOMAP_MAG2PIC = 58;
6196         AUTOMAP_MAG4PIC = 59;
6197         H_ALTPIC = 60;
6198         H_CTRLPIC = 61;
6199         H_SPACEPIC = 62;
6200         H_PAUSEPIC = 63;
6201         H_ESCPIC = 64;
6202         H_LTARROWPIC = 65;
6203         H_UPARROWPIC = 66;
6204         H_DNARROWPIC = 67;
6205         H_RTARROWPIC = 68;
6206         H_ENTERPIC = 69;
6207         H_QPIC = 70;
6208         H_WPIC = 71;
6209         H_EPIC = 72;
6210         H_IPIC = 73;
6211         H_HPIC = 74;
6212         H_1PIC = 75;
6213         H_2PIC = 76;
6214         H_3PIC = 77;
6215         H_4PIC = 78;
6216         H_5PIC = 79;
6217         H_F1PIC = 80;
6218         H_F2PIC = 81;
6219         H_F3PIC = 82;
6220         H_F4PIC = 83;
6221         H_F5PIC = 84;
6222         H_F6PIC = 85;
6223         H_F7PIC = 86;
6224         H_F8PIC = 87;
6225         H_F9PIC = 88;
6226         H_F10PIC = 89;
6227         H_TABPIC = 90;
6228         H_CPIC = 91;
6229         H_FPIC = 92;
6230         H_PPIC = 93;
6231         H_MPIC = 94;
6232         H_LPIC = 95;
6233         H_SHIFTPIC = 96;
6234         H_6PIC = 97;
6235         H_TILDEPIC = 98;
6236         H_PLUSPIC = 99;
6237         H_MINUSPIC = 100;
6238         APOGEE_LOGOPIC = 101;
6239         VISAPIC = 102;
6240         MCPIC = 103;
6241         FAXPIC = 104;
6242         H_TOPWINDOWPIC = 105;
6243         H_LEFTWINDOWPIC = 106;
6244         H_RIGHTWINDOWPIC = 107;
6245         H_BOTTOMINFOPIC = 108;
6246         C_NOTSELECTEDPIC = 109;
6247         C_SELECTEDPIC = 110;
6248         C_NOTSELECTED_HIPIC = 111;
6249         C_SELECTED_HIPIC = 112;
6250         C_BABYMODEPIC = 113;
6251         C_EASYPIC = 114;
6252         C_NORMALPIC = 115;
6253         C_HARDPIC = 116;
6254         C_EPISODE1PIC = 117;
6255         C_EPISODE2PIC = 118;
6256         C_EPISODE3PIC = 119;
6257         C_EPISODE4PIC = 120;
6258         C_EPISODE5PIC = 121;
6259         C_EPISODE6PIC = 122;
6260         BIGGOLDSTERNPIC = 123;
6261         STARLOGOPIC = 124;
6262         BLAKEWITHGUNPIC = 125;
6263         STARINSTITUTEPIC = 126;
6264         MEDALOFHONORPIC = 127;
6265         SMALLGOLDSTERNPIC = 128;
6266         BLAKEWINPIC = 129;
6267         SHUTTLEEXPPIC = 130;
6268         PLANETSPIC = 131;
6269         MOUSEPIC = 132;
6270         JOYSTICKPIC = 133;
6271         GRAVISPADPIC = 134;
6272         STARPORTPIC = 135;
6273         BOSSPIC = 136;
6274         THREEPLANETSPIC = 137;
6275         SOLARSYSTEMPIC = 138;
6276         AOGENDINGPIC = 139;
6277         GFLOGOSPIC = 140;
6278         BLAKEHEADPIC = 141;
6279         PROJECTFOLDERPIC = 142;
6280         TITLE1PIC = 143;
6281         TITLE2PIC = 144;
6282         WEAPON1PIC = 145;
6283         WEAPON2PIC = 146;
6284         WEAPON3PIC = 147;
6285         WEAPON4PIC = 148;
6286         WEAPON5PIC = 149;
6287         WEAPON6PIC = 150;
6288         WEAPON7PIC = 151;
6289         W1_CORNERPIC = 152;
6290         W2_CORNERPIC = 153;
6291         W3_CORNERPIC = 154;
6292         W4_CORNERPIC = 155;
6293         W5_CORNERPIC = 156;
6294         W6_CORNERPIC = 157;
6295         WAITPIC = 158;
6296         READYPIC = 159;
6297         N_BLANKPIC = 160;
6298         N_0PIC = 161;
6299         N_1PIC = 162;
6300         N_2PIC = 163;
6301         N_3PIC = 164;
6302         N_4PIC = 165;
6303         N_5PIC = 166;
6304         N_6PIC = 167;
6305         N_7PIC = 168;
6306         N_8PIC = 169;
6307         N_9PIC = 170;
6308         N_RPIC = 171;
6309         N_OPIC = 172;
6310         N_LPIC = 173;
6311         N_DASHPIC = 174;
6312         NG_BLANKPIC = 175;
6313         NG_0PIC = 176;
6314         NG_1PIC = 177;
6315         NG_2PIC = 178;
6316         NG_3PIC = 179;
6317         NG_4PIC = 180;
6318         NG_5PIC = 181;
6319         NG_6PIC = 182;
6320         NG_7PIC = 183;
6321         NG_8PIC = 184;
6322         NG_9PIC = 185;
6323         DIM_LIGHTPIC = 186;
6324         BRI_LIGHTPIC = 187;
6325         INFOAREAPIC = 188;
6326         TOP_STATUSBARPIC = 189;
6327         STATUSBARPIC = 190;
6328         ONEXZOOMPIC = 191;
6329         TWOXZOOMPIC = 192;
6330         FOURXZOOMPIC = 193;
6331         NO_KEYPIC = 194;
6332         RED_KEYPIC = 195;
6333         YEL_KEYPIC = 196;
6334         BLU_KEYPIC = 197;
6335         POWERBALLTEXT = 199;
6336         PIRACYPALETTE = 200;
6337         APOGEEPALETTE = 201;
6338         ENDINGPALETTE = 202;
6339         TITLEPALETTE = 203;
6340         ORDERSCREEN = 204;
6341         ERRORSCREEN = 205;
6342         NO386SCREEN = 206;
6343         MUSICTEXT = 207;
6344         RADARTEXT = 208;
6345         TICSTEXT = 209;
6346         T_DEMO0 = 210;
6347         T_DEMO1 = 211;
6348         T_DEMO2 = 212;
6349         T_DEMO3 = 213;
6350         T_DEMO4 = 214;
6351         T_DEMO5 = 215;
6352         INFORMANT_HINTS = 216;
6353         NICE_SCIE_HINTS = 217;
6354         MEAN_SCIE_HINTS = 218;
6355         BRIEF_W1 = 219;
6356         BRIEF_I1 = 220;
6357         LEVEL_DESCS = 221;
6358         DECOY = 222;
6359         DECOY2 = 223;
6360         DECOY3 = 224;
6361         DECOY4 = 225;
6362         HELPTEXT = 226;
6363         SAGATEXT = 227;
6364         LOSETEXT = 228;
6365         ORDERTEXT = 229;
6366         CREDITSTEXT = 230;
6367         MUSTBE386TEXT = 231;
6368         QUICK_INFO1_TEXT = 232;
6369         QUICK_INFO2_TEXT = 233;
6370         BADINFO_TEXT = 234;
6371         CALJOY1_TEXT = 235;
6372         CALJOY2_TEXT = 236;
6373         READTHIS_TEXT = 237;
6374         ELEVMSG0_TEXT = 238;
6375         ELEVMSG1_TEXT = 239;
6376         ELEVMSG4_TEXT = 240;
6377         ELEVMSG5_TEXT = 241;
6378         FLOORMSG_TEXT = 242;
6379         YOUWIN_TEXT = 243;
6380         CHANGEVIEW_TEXT = 244;
6381         DIZ_ERR_TEXT = 245;
6382         BADLEVELSTEXT = 246;
6383         BADSAVEGAME_TEXT = 247;
6384 
6385 
6386         STARTFONT = 1;
6387         STARTFONTM = 6;
6388         STARTPICS = 6;
6389         STARTPICM = POWERBALLTEXT - 1;
6390         STARTSPRITES = POWERBALLTEXT - 1;
6391         STARTTILE8 = POWERBALLTEXT - 1;
6392         STARTTILE8M = POWERBALLTEXT;
6393         STARTTILE16 = POWERBALLTEXT;
6394         STARTTILE16M = POWERBALLTEXT;
6395         STARTTILE32 = POWERBALLTEXT;
6396         STARTTILE32M = POWERBALLTEXT;
6397         STARTEXTERNS = POWERBALLTEXT;
6398 
6399         TELEPORT_LUMP_START = TELEPORT1ONPIC;
6400         TELEPORT_LUMP_END = TELEPORT20OFFPIC;
6401 
6402         README_LUMP_START = H_ALTPIC;
6403         README_LUMP_END = H_BOTTOMINFOPIC;
6404 
6405         CONTROLS_LUMP_START = C_NOTSELECTEDPIC;
6406         CONTROLS_LUMP_END = C_EPISODE6PIC;
6407 
6408         LATCHPICS_LUMP_START = WEAPON1PIC;
6409         LATCHPICS_LUMP_END = BLU_KEYPIC;
6410 
6411 
6412         NUMCHUNKS = 248;
6413         NUMFONT = 5;
6414         NUMFONTM = 0;
6415         NUMPICS = 192;
6416         NUMPICM = 0;
6417         NUMSPRITES = 0;
6418         NUMTILE8 = 72;
6419         NUMTILE8M = 0;
6420         NUMTILE16 = 0;
6421         NUMTILE16M = 0;
6422         NUMTILE32 = 0;
6423         NUMTILE32M = 0;
6424         NUMEXTERNS = NUMCHUNKS - STARTEXTERNS;
6425 
6426         STRUCTPIC = 0;
6427     }
6428 
6429     grsegs.resize(NUMCHUNKS);
6430     grneeded.resize(NUMCHUNKS);
6431 }
6432 
6433 
InitSmartSpeedAnim(objtype * obj,uint16_t ShapeNum,uint8_t StartOfs,uint8_t MaxOfs,animtype_t AnimType,animdir_t AnimDir,uint16_t Delay)6434 void InitSmartSpeedAnim(
6435     objtype* obj,
6436     uint16_t ShapeNum,
6437     uint8_t StartOfs,
6438     uint8_t MaxOfs,
6439     animtype_t AnimType,
6440     animdir_t AnimDir,
6441     uint16_t Delay)
6442 {
6443     ::InitAnim(
6444         obj,
6445         ShapeNum,
6446         StartOfs,
6447         MaxOfs,
6448         AnimType,
6449         AnimDir,
6450         Delay,
6451         Delay);
6452 }
6453 
InitSmartAnim(objtype * obj,uint16_t ShapeNum,uint8_t StartOfs,uint8_t MaxOfs,animtype_t AnimType,animdir_t AnimDir)6454 void InitSmartAnim(
6455     objtype* obj,
6456     uint16_t ShapeNum,
6457     uint8_t StartOfs,
6458     uint8_t MaxOfs,
6459     animtype_t AnimType,
6460     animdir_t AnimDir)
6461 {
6462     ::InitSmartSpeedAnim(
6463         obj,
6464         ShapeNum,
6465         StartOfs,
6466         MaxOfs,
6467         AnimType,
6468         AnimDir,
6469         ::is_ps() ? 7 : 21);
6470 }
6471 
6472 // ========================================================================
6473 // ArchiveException
6474 
ArchiveException(const char * message)6475 ArchiveException::ArchiveException(
6476     const char* message) throw () :
6477         message_(message)
6478 {
6479 }
6480 
ArchiveException(const ArchiveException & that)6481 ArchiveException::ArchiveException(
6482     const ArchiveException& that) throw () :
6483         message_(that.message_)
6484 {
6485 }
6486 
6487 // (virtual)
~ArchiveException()6488 ArchiveException::~ArchiveException() throw ()
6489 {
6490 }
6491 
operator =(const ArchiveException & that)6492 ArchiveException& ArchiveException::operator=(
6493     const ArchiveException& that) throw ()
6494 {
6495     if (&that != this) {
6496         message_ = that.message_;
6497     }
6498 
6499     return *this;
6500 }
6501 
6502 // (virtual)
what() const6503 const char* ArchiveException::what() const throw ()
6504 {
6505     return message_;
6506 }
6507 
6508 // ArchiveException
6509 // ========================================================================
6510 
6511 bstone::MemoryStream g_playtemp;
6512 
6513 static bool is_config_loaded = false;
6514 
get_score_file_name()6515 static const std::string& get_score_file_name()
6516 {
6517     static std::string file_name;
6518     static bool is_initialized = false;
6519 
6520     if (!is_initialized) {
6521         is_initialized = true;
6522 
6523         std::string game_type_string;
6524 
6525         switch (::g_game_type) {
6526         case GameType::aog_sw:
6527             game_type_string = "aog_sw";
6528             break;
6529 
6530         case GameType::aog_full_v1_0:
6531         case GameType::aog_full_v2_x:
6532         case GameType::aog_full_v3_0:
6533             game_type_string = "aog_full";
6534             break;
6535 
6536         case GameType::ps:
6537             game_type_string = "ps";
6538             break;
6539 
6540         default:
6541             throw std::runtime_error("Invalid game type.");
6542         }
6543 
6544         file_name = "bstone_" + game_type_string + "_high_scores";
6545     }
6546 
6547     return file_name;
6548 }
6549 
set_default_high_scores()6550 static void set_default_high_scores()
6551 {
6552     Scores = {
6553         HighScore { "JAM PRODUCTIONS INC.", 10000, 1, 0, 0, },
6554         HighScore { "", 10000, 1, 0, 0, },
6555         HighScore { "JERRY JONES", 10000, 1, 0, 0, },
6556         HighScore { "MICHAEL MAYNARD", 10000, 1, 0, 0, },
6557         HighScore { "JAMES T. ROW", 10000, 1, 0, 0, },
6558         HighScore { "", 10000, 1, 0, 0, },
6559         HighScore { "", 10000, 1, 0, 0, },
6560         HighScore { "TO REGISTER CALL", 10000, 1, 0, 0, },
6561         HighScore { " 1-800-GAME123", 10000, 1, 0, 0, },
6562         HighScore { "", 10000, 1, 0, 0, },
6563     }; // Scores
6564 }
6565 
read_high_scores()6566 void read_high_scores()
6567 {
6568     auto is_succeed = true;
6569 
6570     auto scores_path = ::get_profile_dir() + ::get_score_file_name();
6571 
6572     HighScores scores(MaxScores);
6573     bstone::FileStream stream(scores_path);
6574 
6575     if (stream.is_open()) {
6576         bstone::Crc32 check_sum;
6577         bstone::BinaryReader reader(&stream);
6578 
6579         try {
6580             for (auto& score : scores) {
6581                 ::deserialize_field(score.name, reader, check_sum);
6582                 ::deserialize_field(score.score, reader, check_sum);
6583                 ::deserialize_field(score.completed, reader, check_sum);
6584                 ::deserialize_field(score.episode, reader, check_sum);
6585                 ::deserialize_field(score.ratio, reader, check_sum);
6586             }
6587         } catch (const ArchiveException&) {
6588             is_succeed = false;
6589         }
6590 
6591         if (is_succeed) {
6592             uint32_t saved_checksum = 0;
6593             reader.read(saved_checksum);
6594             bstone::Endian::lei(saved_checksum);
6595 
6596             is_succeed = (saved_checksum == check_sum.get_value());
6597         }
6598     } else {
6599         is_succeed = false;
6600     }
6601 
6602     if (is_succeed) {
6603         ::Scores = scores;
6604     } else {
6605         ::set_default_high_scores();
6606     }
6607 }
6608 
write_high_scores()6609 static void write_high_scores()
6610 {
6611     if (::g_game_type == GameType::none) {
6612         return;
6613     }
6614 
6615     auto scores_path = ::get_profile_dir() + ::get_score_file_name();
6616 
6617     bstone::FileStream stream(scores_path, bstone::StreamOpenMode::write);
6618 
6619     if (!stream.is_open()) {
6620         bstone::Log::write_error(
6621             "Failed to open a high scores file for writing: {}.",
6622             scores_path);
6623 
6624         return;
6625     }
6626 
6627     bstone::Crc32 checksum;
6628     bstone::BinaryWriter writer(&stream);
6629 
6630     for (const auto& score : Scores) {
6631         ::serialize_field(score.name, writer, checksum);
6632         ::serialize_field(score.score, writer, checksum);
6633         ::serialize_field(score.completed, writer, checksum);
6634         ::serialize_field(score.episode, writer, checksum);
6635         ::serialize_field(score.ratio, writer, checksum);
6636     }
6637 
6638     writer.write(bstone::Endian::le(checksum.get_value()));
6639 }
6640 
set_vanilla_controls()6641 static void set_vanilla_controls()
6642 {
6643     dirscan = {
6644         ScanCode::sc_up_arrow,
6645         ScanCode::sc_right_arrow,
6646         ScanCode::sc_down_arrow,
6647         ScanCode::sc_left_arrow,
6648     }; // dirscan
6649 
6650     buttonscan = {
6651         ScanCode::sc_control,
6652         ScanCode::sc_alt,
6653         ScanCode::sc_right_shift,
6654         ScanCode::sc_space,
6655         ScanCode::sc_1,
6656         ScanCode::sc_2,
6657         ScanCode::sc_3,
6658         ScanCode::sc_4,
6659         ScanCode::sc_5,
6660         ScanCode::sc_6,
6661         ScanCode::sc_7,
6662         ScanCode::sc_none,
6663     }; // buttonscan
6664 
6665     buttonmouse = {
6666         bt_attack,
6667         bt_strafe,
6668         bt_use,
6669         bt_nobutton,
6670     }; // buttonmouse
6671 
6672     buttonjoy = {
6673         bt_attack,
6674         bt_strafe,
6675         bt_use,
6676         bt_run,
6677     }; // buttonjoy
6678 }
6679 // BBi
6680 
6681 
6682 namespace
6683 {
6684 
6685 
6686 const auto vid_is_widescreen_name = "vid_is_widescreen";
6687 const auto snd_is_sfx_enabled_name = "snd_is_sfx_enabled";
6688 const auto snd_is_music_enabled_name = "snd_is_music_enabled";
6689 const auto snd_sfx_volume_name = "snd_sfx_volume";
6690 const auto snd_music_volume_name = "snd_music_volume";
6691 const auto in_use_modern_bindings_name = "in_use_modern_bindings";
6692 const auto in_mouse_sensitivity_name = "in_mouse_sensitivity";
6693 const auto in_is_mouse_enabled_name = "in_is_mouse_enabled";
6694 const auto in_is_joystick_enabled_name = "in_is_joystick_enabled";
6695 const auto in_is_joystick_pad_enabled_name = "in_is_joystick_pad_enabled";
6696 const auto in_is_joystick_progressive_name = "in_is_joystick_progressive";
6697 const auto in_joystick_port_name = "in_joystick_port";
6698 const auto in_mouse_binding_name = "in_mouse_binding";
6699 const auto in_kb_binding_name = "in_kb_binding";
6700 const auto in_mouse_button_name = "in_mouse_button";
6701 const auto in_js_button_name = "in_js_button";
6702 const auto in_binding_name = "in_binding";
6703 const auto gp_flags_name = "gp_flags";
6704 const auto gp_no_wall_hit_sfx_name = "gp_no_wall_hit_sfx";
6705 const auto gp_is_always_run_name = "gp_is_always_run";
6706 const auto gp_use_heart_beat_sfx_name = "gp_use_heart_beat_sfx";
6707 const auto am_is_rotated_name = "am_is_rotated";
6708 
6709 
6710 class ScanCodeHash
6711 {
6712 public:
operator ()(const ScanCode scan_code) const6713     std::size_t operator()(
6714         const ScanCode scan_code) const
6715     {
6716         return (std::hash<int>{})(static_cast<int>(scan_code));
6717     }
6718 }; // ScanCodeHash
6719 
6720 const auto scan_code_name_map = std::unordered_map<ScanCode, std::string, ScanCodeHash>{
6721     {ScanCode::sc_return, "return",},
6722     {ScanCode::sc_escape, "escape",},
6723     {ScanCode::sc_space, "space",},
6724     {ScanCode::sc_minus, "minus",},
6725     {ScanCode::sc_equals, "equals",},
6726     {ScanCode::sc_backspace, "backspace",},
6727     {ScanCode::sc_tab, "tab",},
6728     {ScanCode::sc_alt, "alt",},
6729     {ScanCode::sc_left_bracket, "left_bracket",},
6730     {ScanCode::sc_right_bracket, "right_bracket",},
6731     {ScanCode::sc_control, "control",},
6732     {ScanCode::sc_caps_lock, "caps_lock",},
6733     {ScanCode::sc_num_lock, "num_lock",},
6734     {ScanCode::sc_scroll_lock, "scroll_lock",},
6735     {ScanCode::sc_left_shift, "left_shift",},
6736     {ScanCode::sc_right_shift, "right_shift",},
6737     {ScanCode::sc_up_arrow, "up_arrow",},
6738     {ScanCode::sc_down_arrow, "down_arrow",},
6739     {ScanCode::sc_left_arrow, "left_arrow",},
6740     {ScanCode::sc_right_arrow, "right_arrow",},
6741     {ScanCode::sc_insert, "insert",},
6742     {ScanCode::sc_delete, "delete",},
6743     {ScanCode::sc_home, "home",},
6744     {ScanCode::sc_end, "end",},
6745     {ScanCode::sc_page_up, "page_up",},
6746     {ScanCode::sc_page_down, "page_down",},
6747     {ScanCode::sc_slash, "slash",},
6748     {ScanCode::sc_f1, "f1",},
6749     {ScanCode::sc_f2, "f2",},
6750     {ScanCode::sc_f3, "f3",},
6751     {ScanCode::sc_f4, "f4",},
6752     {ScanCode::sc_f5, "f5",},
6753     {ScanCode::sc_f6, "f6",},
6754     {ScanCode::sc_f7, "f7",},
6755     {ScanCode::sc_f8, "f8",},
6756     {ScanCode::sc_f9, "f9",},
6757     {ScanCode::sc_f10, "f10",},
6758     {ScanCode::sc_f11, "f11",},
6759     {ScanCode::sc_f12, "f12",},
6760     {ScanCode::sc_print_screen, "print_screen",},
6761     {ScanCode::sc_pause, "pause",},
6762     {ScanCode::sc_back_quote, "back_quote",},
6763     {ScanCode::sc_semicolon, "semicolon",},
6764     {ScanCode::sc_quote, "quote",},
6765     {ScanCode::sc_backslash, "backslash",},
6766     {ScanCode::sc_comma, "comma",},
6767     {ScanCode::sc_period, "period",},
6768     {ScanCode::sc_1, "1",},
6769     {ScanCode::sc_2, "2",},
6770     {ScanCode::sc_3, "3",},
6771     {ScanCode::sc_4, "4",},
6772     {ScanCode::sc_5, "5",},
6773     {ScanCode::sc_6, "6",},
6774     {ScanCode::sc_7, "7",},
6775     {ScanCode::sc_8, "8",},
6776     {ScanCode::sc_9, "9",},
6777     {ScanCode::sc_0, "0",},
6778     {ScanCode::sc_a, "a",},
6779     {ScanCode::sc_b, "b",},
6780     {ScanCode::sc_c, "c",},
6781     {ScanCode::sc_d, "d",},
6782     {ScanCode::sc_e, "e",},
6783     {ScanCode::sc_f, "f",},
6784     {ScanCode::sc_g, "g",},
6785     {ScanCode::sc_h, "h",},
6786     {ScanCode::sc_i, "i",},
6787     {ScanCode::sc_j, "j",},
6788     {ScanCode::sc_k, "k",},
6789     {ScanCode::sc_l, "l",},
6790     {ScanCode::sc_m, "m",},
6791     {ScanCode::sc_n, "n",},
6792     {ScanCode::sc_o, "o",},
6793     {ScanCode::sc_p, "p",},
6794     {ScanCode::sc_q, "q",},
6795     {ScanCode::sc_r, "r",},
6796     {ScanCode::sc_s, "s",},
6797     {ScanCode::sc_t, "t",},
6798     {ScanCode::sc_u, "u",},
6799     {ScanCode::sc_v, "v",},
6800     {ScanCode::sc_w, "w",},
6801     {ScanCode::sc_x, "x",},
6802     {ScanCode::sc_y, "y",},
6803     {ScanCode::sc_z, "z",},
6804     {ScanCode::sc_kp_minus, "kp_minus",},
6805     {ScanCode::sc_kp_plus, "kp_plus",},
6806     {ScanCode::sc_mouse_left, "mouse_left",},
6807     {ScanCode::sc_mouse_middle, "mouse_middle",},
6808     {ScanCode::sc_mouse_right, "mouse_right",},
6809     {ScanCode::sc_mouse_x1, "mouse_x1",},
6810     {ScanCode::sc_mouse_x2, "mouse_x2",},
6811 };
6812 
6813 
parse_config_line(const std::string & line,std::string & name,int & index0,int & index1,std::string & value)6814 bool parse_config_line(
6815     const std::string& line,
6816     std::string& name,
6817     int& index0,
6818     int& index1,
6819     std::string& value)
6820 {
6821     if (line.empty())
6822     {
6823         return false;
6824     }
6825 
6826     const auto comment_position = line.find("//");
6827 
6828     if (comment_position != line.npos)
6829     {
6830         return false;
6831     }
6832 
6833 
6834     const auto name_end_space = line.find(' ');
6835 
6836     if (name_end_space == line.npos)
6837     {
6838         return false;
6839     }
6840 
6841 
6842     const auto value_begin_quotes = line.find('\"', name_end_space);
6843 
6844     if (value_begin_quotes == line.npos)
6845     {
6846         return false;
6847     }
6848 
6849 
6850     const auto value_end_quotes = line.find('\"', value_begin_quotes + 1);
6851 
6852     if (value_end_quotes == line.npos)
6853     {
6854         return false;
6855     }
6856 
6857 
6858     const auto full_name = line.substr(0, name_end_space);
6859 
6860     if (full_name.empty())
6861     {
6862         return false;
6863     }
6864 
6865     if (value_end_quotes > value_begin_quotes)
6866     {
6867         value = line.substr(value_begin_quotes + 1, value_end_quotes - value_begin_quotes - 1);
6868     }
6869     else
6870     {
6871         value.clear();
6872     }
6873 
6874 
6875     index0 = -1;
6876     index1 = -1;
6877     const auto index0_begin_bracket = full_name.find('[');
6878     const auto index0_end_bracket = full_name.find(']');
6879     const auto has_index0 = (index0_begin_bracket != full_name.npos && index0_end_bracket != full_name.npos);
6880 
6881     if (has_index0)
6882     {
6883         name = full_name.substr(0, index0_begin_bracket);
6884     }
6885     else
6886     {
6887         name = full_name;
6888     }
6889 
6890     if (has_index0)
6891     {
6892         const auto index0_string = full_name.substr(index0_begin_bracket + 1, index0_end_bracket - index0_begin_bracket);
6893 
6894         if (!bstone::StringHelper::lexical_cast(index0_string, index0))
6895         {
6896             return false;
6897         }
6898     }
6899 
6900     if (has_index0)
6901     {
6902         const auto index1_begin_bracket = full_name.find('[', index0_end_bracket + 1);
6903         const auto index1_end_bracket = full_name.find(']', index0_end_bracket + 1);
6904         const auto has_index1 = (index1_begin_bracket != full_name.npos && index1_end_bracket != full_name.npos);
6905 
6906         const auto index1_string = full_name.substr(index1_begin_bracket + 1, index1_end_bracket - index1_begin_bracket);
6907 
6908         if (!bstone::StringHelper::lexical_cast(index1_string, index1))
6909         {
6910             return false;
6911         }
6912     }
6913 
6914     return true;
6915 }
6916 
set_config_defaults()6917 void set_config_defaults()
6918 {
6919     ::mouseenabled = true;
6920 
6921     ::joystickenabled = false;
6922     ::joypadenabled = false;
6923     ::joystickport = 0;
6924     ::joystickprogressive = false;
6925 
6926     ::set_vanilla_controls();
6927     ::in_set_default_bindings();
6928 
6929     ::mouseadjustment = ::default_mouse_sensitivity;
6930 
6931     ::gamestate.flags |= GS_HEARTB_SOUND | GS_ATTACK_INFOAREA;
6932     ::gamestate.flags |= GS_DRAW_CEILING | GS_DRAW_FLOOR | GS_LIGHTING;
6933 
6934     ::sd_sfx_volume = ::sd_default_sfx_volume;
6935     ::sd_music_volume = ::sd_default_music_volume;
6936 
6937     ::g_no_wall_hit_sound = default_no_wall_hit_sound;
6938     ::in_use_modern_bindings = default_in_use_modern_bindings;
6939     ::g_always_run = default_always_run;
6940 
6941     ::g_heart_beat_sound = ::default_heart_beat_sound;
6942     ::g_rotated_automap = ::default_rotated_automap;
6943 
6944     ::vid_widescreen = ::default_vid_widescreen;
6945 }
6946 
get_scan_code_by_name(const std::string & name)6947 ScanCode get_scan_code_by_name(
6948     const std::string& name)
6949 {
6950     const auto it = std::find_if(
6951         scan_code_name_map.cbegin(),
6952         scan_code_name_map.cend(),
6953         [&](const std::pair<ScanCode, std::string>& item)
6954         {
6955             return item.second == name;
6956         }
6957     );
6958 
6959     if (it == scan_code_name_map.cend())
6960     {
6961         return ScanCode::sc_none;
6962     }
6963 
6964     return it->first;
6965 }
6966 
read_text_config()6967 void read_text_config()
6968 {
6969     ::is_config_loaded = true;
6970 
6971 
6972     const auto default_game_state_flags = uint16_t{
6973         GS_HEARTB_SOUND |
6974         GS_ATTACK_INFOAREA |
6975         GS_LIGHTING |
6976         GS_DRAW_CEILING |
6977         GS_DRAW_FLOOR
6978     };
6979 
6980     auto is_sound_enabled = true;
6981     auto is_music_enabled = true;
6982     auto game_state_flags = default_game_state_flags;
6983 
6984 
6985     set_config_defaults();
6986 
6987     const auto config_path = ::get_profile_dir() + ::text_config_file_name;
6988 
6989     bstone::FileStream stream{config_path};
6990 
6991     if (stream.is_open())
6992     {
6993         bstone::TextReader reader{&stream};
6994 
6995         if (reader.is_open())
6996         {
6997             while (!reader.is_eos())
6998             {
6999                 const auto line = reader.read_line();
7000 
7001                 auto name = std::string{};
7002                 auto index0 = int{};
7003                 auto index1 = int{};
7004                 auto value_string = std::string{};
7005 
7006                 if (parse_config_line(line, name, index0, index1, value_string))
7007                 {
7008                     if (name == vid_is_widescreen_name)
7009                     {
7010                         auto value = int{};
7011 
7012                         if (bstone::StringHelper::lexical_cast(value_string, value))
7013                         {
7014                             ::vid_widescreen = (value != 0);
7015                         }
7016                     }
7017                     else if (name == snd_is_sfx_enabled_name)
7018                     {
7019                         auto value = int{};
7020 
7021                         if (bstone::StringHelper::lexical_cast(value_string, value))
7022                         {
7023                             is_sound_enabled = (value != 0);
7024                         }
7025                     }
7026                     else if (name == snd_is_music_enabled_name)
7027                     {
7028                         auto value = int{};
7029 
7030                         if (bstone::StringHelper::lexical_cast(value_string, value))
7031                         {
7032                             is_music_enabled = (value != 0);
7033                         }
7034                     }
7035                     else if (name == snd_sfx_volume_name)
7036                     {
7037                         auto value = int{};
7038 
7039                         if (bstone::StringHelper::lexical_cast(value_string, value))
7040                         {
7041                             ::sd_sfx_volume = value;
7042                         }
7043 
7044                         if (::sd_sfx_volume < ::sd_min_volume)
7045                         {
7046                             ::sd_sfx_volume = ::sd_min_volume;
7047                         }
7048 
7049                         if (::sd_sfx_volume > ::sd_max_volume)
7050                         {
7051                             ::sd_sfx_volume = ::sd_max_volume;
7052                         }
7053                     }
7054                     else if (name == snd_music_volume_name)
7055                     {
7056                         auto value = int{};
7057 
7058                         if (bstone::StringHelper::lexical_cast(value_string, value))
7059                         {
7060                             ::sd_music_volume = value;
7061                         }
7062 
7063                         if (::sd_music_volume < ::sd_min_volume)
7064                         {
7065                             ::sd_music_volume = ::sd_min_volume;
7066                         }
7067 
7068                         if (::sd_music_volume > ::sd_max_volume)
7069                         {
7070                             ::sd_music_volume = ::sd_max_volume;
7071                         }
7072                     }
7073                     else if (name == in_use_modern_bindings_name)
7074                     {
7075                         auto value = int{};
7076 
7077                         if (bstone::StringHelper::lexical_cast(value_string, value))
7078                         {
7079                             ::in_use_modern_bindings = (value != 0);
7080                         }
7081                     }
7082                     else if (name == in_mouse_sensitivity_name)
7083                     {
7084                         auto value = int{};
7085 
7086                         if (bstone::StringHelper::lexical_cast(value_string, value))
7087                         {
7088                             ::mouseadjustment = value;
7089                         }
7090 
7091                         if (::mouseadjustment < min_mouse_sensitivity)
7092                         {
7093                             ::mouseadjustment = min_mouse_sensitivity;
7094                         }
7095 
7096                         if (::mouseadjustment > max_mouse_sensitivity)
7097                         {
7098                             ::mouseadjustment = max_mouse_sensitivity;
7099                         }
7100                     }
7101                     else if (name == in_is_mouse_enabled_name)
7102                     {
7103                         auto value = int{};
7104 
7105                         if (bstone::StringHelper::lexical_cast(value_string, value))
7106                         {
7107                             ::mouseenabled = (value != 0);
7108                         }
7109                     }
7110                     else if (name == in_is_joystick_enabled_name)
7111                     {
7112                         auto value = int{};
7113 
7114                         if (bstone::StringHelper::lexical_cast(value_string, value))
7115                         {
7116                             ::joystickenabled = (value != 0);
7117                         }
7118                     }
7119                     else if (name == in_is_joystick_pad_enabled_name)
7120                     {
7121                         auto value = int{};
7122 
7123                         if (bstone::StringHelper::lexical_cast(value_string, value))
7124                         {
7125                             ::joypadenabled = (value != 0);
7126                         }
7127                     }
7128                     else if (name == in_is_joystick_progressive_name)
7129                     {
7130                         auto value = int{};
7131 
7132                         if (bstone::StringHelper::lexical_cast(value_string, value))
7133                         {
7134                             ::joystickprogressive = (value != 0);
7135                         }
7136                     }
7137                     else if (name == in_joystick_port_name)
7138                     {
7139                         auto value = int16_t{};
7140 
7141                         if (bstone::StringHelper::lexical_cast(value_string, value))
7142                         {
7143                             ::joystickport = value;
7144                         }
7145 
7146                         if (::joystickport < 0)
7147                         {
7148                             ::joystickport = 0;
7149                         }
7150                     }
7151                     else if (name == in_mouse_binding_name)
7152                     {
7153                         if (index1 < 0)
7154                         {
7155                             if (index0 >= 0 && index0 < static_cast<int>(::dirscan.size()))
7156                             {
7157                                 ::dirscan[index0] = get_scan_code_by_name(value_string);
7158                             }
7159                         }
7160                     }
7161                     else if (name == in_kb_binding_name)
7162                     {
7163                         if (index1 < 0)
7164                         {
7165                             if (index0 >= 0 && index0 < static_cast<int>(::buttonscan.size()))
7166                             {
7167                                 ::buttonscan[index0] = get_scan_code_by_name(value_string);
7168                             }
7169                         }
7170                     }
7171                     else if (name == in_mouse_button_name)
7172                     {
7173                         if (index1 < 0)
7174                         {
7175                             if (index0 >= 0 && index0 < static_cast<int>(::buttonmouse.size()))
7176                             {
7177                                 auto value = int16_t{};
7178 
7179                                 if (bstone::StringHelper::lexical_cast(value_string, value))
7180                                 {
7181                                     ::buttonmouse[index0] = value;
7182                                 }
7183 
7184                                 if (::buttonmouse[index0] < 0)
7185                                 {
7186                                     ::buttonmouse[index0] = 0;
7187                                 }
7188                             }
7189                         }
7190                     }
7191                     else if (name == in_js_button_name)
7192                     {
7193                         if (index1 < 0)
7194                         {
7195                             if (index0 >= 0 && index0 < static_cast<int>(::buttonjoy.size()))
7196                             {
7197                                 auto value = int16_t{};
7198 
7199                                 if (bstone::StringHelper::lexical_cast(value_string, value))
7200                                 {
7201                                     ::buttonjoy[index0] = value;
7202                                 }
7203 
7204                                 if (::buttonjoy[index0] < 0)
7205                                 {
7206                                     ::buttonjoy[index0] = 0;
7207                                 }
7208                             }
7209                         }
7210                     }
7211                     else if (name == in_binding_name)
7212                     {
7213                         static_assert(std::is_array<Bindings>::value, "Expected C-array type.");
7214 
7215                         constexpr auto bindings_count = static_cast<int>(std::extent<Bindings, 0>::value);
7216 
7217                         if (index0 >= 0 && index0 < bindings_count && index1 >= 0 && index1 < bindings_count)
7218                         {
7219                             ::in_bindings[index0][index1] = get_scan_code_by_name(value_string);
7220                         }
7221                     }
7222                     else if (name == gp_flags_name)
7223                     {
7224                         auto value = uint16_t{};
7225 
7226                         if (bstone::StringHelper::lexical_cast(value_string, value))
7227                         {
7228                             game_state_flags = value;
7229                         }
7230                     }
7231                     else if (name == gp_no_wall_hit_sfx_name)
7232                     {
7233                         auto value = int{};
7234 
7235                         if (bstone::StringHelper::lexical_cast(value_string, value))
7236                         {
7237                             ::g_no_wall_hit_sound = (value != 0);
7238                         }
7239                     }
7240                     else if (name == gp_is_always_run_name)
7241                     {
7242                         auto value = int{};
7243 
7244                         if (bstone::StringHelper::lexical_cast(value_string, value))
7245                         {
7246                             ::g_always_run = (value != 0);
7247                         }
7248                     }
7249                     else if (name == gp_use_heart_beat_sfx_name)
7250                     {
7251                         auto value = int{};
7252 
7253                         if (bstone::StringHelper::lexical_cast(value_string, value))
7254                         {
7255                             ::g_heart_beat_sound = (value != 0);
7256                         }
7257                     }
7258                     else if (name == am_is_rotated_name)
7259                     {
7260                         auto value = int{};
7261 
7262                         if (bstone::StringHelper::lexical_cast(value_string, value))
7263                         {
7264                             ::g_rotated_automap = (value != 0);
7265                         }
7266                     }
7267                 }
7268             }
7269         }
7270     }
7271 
7272 
7273     ::gamestate.flags &= ~default_game_state_flags;
7274     ::gamestate.flags |= game_state_flags;
7275 
7276     ::SD_EnableSound(is_sound_enabled);
7277     ::SD_EnableMusic(is_music_enabled);
7278 
7279     ::sd_set_sfx_volume(sd_sfx_volume);
7280     ::sd_set_music_volume(sd_music_volume);
7281 
7282     ::vl_update_widescreen();
7283 }
7284 
7285 
7286 } // namespace
7287 
7288 
ReadConfig()7289 void ReadConfig()
7290 {
7291     read_text_config();
7292 }
7293 
7294 
7295 namespace
7296 {
7297 
7298 
7299 template<typename T>
7300 class ToString
7301 {
7302 public:
convert(T && src_value,std::string & dst_value)7303     static bool convert(
7304         T&& src_value,
7305         std::string& dst_value)
7306     {
7307         return bstone::StringHelper::lexical_cast(src_value, dst_value);
7308     }
7309 };
7310 
7311 template<>
7312 class ToString<bool>
7313 {
7314 public:
convert(const bool src_value,std::string & dst_value)7315     static bool convert(
7316         const bool src_value,
7317         std::string& dst_value)
7318     {
7319         dst_value = (src_value ? "1" : "0");
7320 
7321         return true;
7322     }
7323 };
7324 
7325 
7326 template<typename T>
write_config_entry(bstone::TextWriter & writer,const std::string & name,T && value)7327 void write_config_entry(
7328     bstone::TextWriter& writer,
7329     const std::string& name,
7330     T&& value)
7331 {
7332     auto value_string = std::string{};
7333 
7334     if (!ToString<T>::convert(value, value_string))
7335     {
7336         bstone::Log::write_warning("Failed to convert value for setting \"{}\".", name);
7337     }
7338 
7339     const auto string = name + " \"" + value_string + "\"\n";
7340 
7341     if (!writer.write(string))
7342     {
7343         bstone::Log::write_warning("Failed to write setting \"{}\".", name);
7344     }
7345 }
7346 
get_scan_code_name(ScanCode scan_code)7347 const std::string& get_scan_code_name(
7348     ScanCode scan_code)
7349 {
7350     static const auto empty_name = std::string{};
7351 
7352     const auto it = scan_code_name_map.find(scan_code);
7353 
7354     if (it == scan_code_name_map.cend())
7355     {
7356         return empty_name;
7357     }
7358 
7359     return it->second;
7360 }
7361 
write_x_scan_config(const ScanCodes & scan_codes,const std::string & name_prefix,bstone::TextWriter & writer)7362 void write_x_scan_config(
7363     const ScanCodes& scan_codes,
7364     const std::string& name_prefix,
7365     bstone::TextWriter& writer)
7366 {
7367     auto line = std::string{};
7368 
7369     auto counter = 0;
7370 
7371     for (const auto scan_code : scan_codes)
7372     {
7373         const auto scan_code_name = get_scan_code_name(scan_code);
7374 
7375         line = name_prefix + "[" + std::to_string(counter) + "] \"" + scan_code_name + "\"\n";
7376         writer.write(line);
7377 
7378         counter += 1;
7379     }
7380 }
7381 
write_buttons_config(const Buttons & buttons,const std::string & name_prefix,bstone::TextWriter & writer)7382 void write_buttons_config(
7383     const Buttons& buttons,
7384     const std::string& name_prefix,
7385     bstone::TextWriter& writer)
7386 {
7387     auto line = std::string{};
7388 
7389     auto counter = 0;
7390 
7391     for (const auto button : buttons)
7392     {
7393         line = name_prefix + "[" + std::to_string(counter) + "] \"" + std::to_string(button) + "\"\n";
7394         writer.write(line);
7395 
7396         counter += 1;
7397     }
7398 }
7399 
write_bindings_config(const std::string & name_prefix,bstone::TextWriter & writer)7400 void write_bindings_config(
7401     const std::string& name_prefix,
7402     bstone::TextWriter& writer)
7403 {
7404     auto line = std::string{};
7405 
7406     auto counter0 = 0;
7407 
7408     for (const auto& binding : in_bindings)
7409     {
7410         const auto& counter0_string = std::to_string(counter0);
7411 
7412         auto counter1 = 0;
7413 
7414         for (const auto scan_code : binding)
7415         {
7416             const auto& scan_code_name = get_scan_code_name(scan_code);
7417             const auto& counter1_string = std::to_string(counter1);
7418 
7419             line = name_prefix +
7420                 "[" + counter0_string + "][" + counter1_string + "] \"" +
7421                 scan_code_name + "\"\n";
7422 
7423             writer.write(line);
7424 
7425             counter1 += 1;
7426         }
7427 
7428         counter0 += 1;
7429     }
7430 }
7431 
write_text_config()7432 void write_text_config()
7433 {
7434     constexpr auto memory_stream_initial_size = 4096;
7435 
7436     bstone::MemoryStream memory_stream{memory_stream_initial_size, bstone::StreamOpenMode::write};
7437     bstone::TextWriter writer{&memory_stream};
7438 
7439 
7440     writer.write("// BStone configuration file\n");
7441     writer.write("// WARNING! This is auto-generated file.\n");
7442     writer.write("\n");
7443 
7444     writer.write("\n// Video\n");
7445     write_config_entry(writer, vid_is_widescreen_name, ::vid_widescreen);
7446 
7447     writer.write("\n// Audio\n");
7448     write_config_entry(writer, snd_is_sfx_enabled_name, ::sd_is_sound_enabled);
7449     write_config_entry(writer, snd_is_music_enabled_name, ::sd_is_music_enabled);
7450     write_config_entry(writer, snd_sfx_volume_name, ::sd_sfx_volume);
7451     write_config_entry(writer, snd_music_volume_name, ::sd_music_volume);
7452 
7453     writer.write("\n// Input\n");
7454     write_config_entry(writer, in_use_modern_bindings_name, ::in_use_modern_bindings);
7455     write_config_entry(writer, in_mouse_sensitivity_name, ::mouseadjustment);
7456     write_config_entry(writer, in_is_mouse_enabled_name, ::mouseenabled);
7457     write_config_entry(writer, in_is_joystick_enabled_name, ::joystickenabled);
7458     write_config_entry(writer, in_is_joystick_pad_enabled_name, ::joypadenabled);
7459     write_config_entry(writer, in_is_joystick_progressive_name, ::joystickprogressive);
7460     write_config_entry(writer, in_joystick_port_name, ::joystickport);
7461 
7462     writer.write("\n// Input bindings\n");
7463     write_x_scan_config(::dirscan, in_mouse_binding_name, writer);
7464     write_x_scan_config(::buttonscan, in_kb_binding_name, writer);
7465     write_buttons_config(::buttonmouse, in_mouse_button_name, writer);
7466     write_buttons_config(::buttonjoy, in_js_button_name, writer);
7467     write_bindings_config(::in_binding_name, writer);
7468 
7469     writer.write("\n// Gameplay\n");
7470     write_config_entry(writer, gp_flags_name, ::gamestate.flags);
7471     write_config_entry(writer, gp_no_wall_hit_sfx_name, ::g_no_wall_hit_sound);
7472     write_config_entry(writer, gp_is_always_run_name, ::g_always_run);
7473     write_config_entry(writer, gp_use_heart_beat_sfx_name, ::g_heart_beat_sound);
7474 
7475     writer.write("\n// Auto-map\n");
7476     write_config_entry(writer, am_is_rotated_name, ::g_rotated_automap);
7477 
7478 
7479     static_cast<void>(memory_stream.flush());
7480 
7481     const auto stream_size = static_cast<int>(memory_stream.get_size());
7482     const auto stream_data = memory_stream.get_data();
7483 
7484     const auto config_path = ::get_profile_dir() + ::text_config_file_name;
7485 
7486     bstone::FileStream stream{config_path, bstone::StreamOpenMode::write};
7487 
7488     if (!stream.write(stream_data, stream_size))
7489     {
7490         bstone::Log::write_warning("Failed to write a configuration.");
7491     }
7492 }
7493 
7494 
7495 } // namespace
7496 
7497 
WriteConfig()7498 void WriteConfig()
7499 {
7500     write_text_config();
7501 }
7502 
7503 
7504 bool ShowQuickMsg;
7505 
7506 /*
7507 =====================
7508 =
7509 = NewGame
7510 =
7511 = Set up new game to start from the beginning
7512 =
7513 =====================
7514 */
NewGame(int16_t difficulty,int16_t episode)7515 void NewGame(
7516     int16_t difficulty,
7517     int16_t episode)
7518 {
7519     uint16_t oldf = gamestate.flags, loop;
7520 
7521     InitPlaytemp();
7522     playstate = ex_stillplaying;
7523 
7524     ShowQuickMsg = true;
7525     ::gamestuff.clear();
7526     memset(&gamestate, 0, sizeof(gamestate));
7527 
7528     ::gamestate.initialize_cross_barriers();
7529     ::gamestate.initialize_local_barriers();
7530     ::gamestate.flags = oldf & ~(GS_KILL_INF_WARN);
7531 
7532     ::gamestate.difficulty = difficulty;
7533 
7534     ::gamestate.weapons = 1 << wp_autocharge; // |1<<wp_plasma_detonators;
7535     ::gamestate.weapon = wp_autocharge;
7536     ::gamestate.chosenweapon = wp_autocharge;
7537     ::gamestate.old_weapons[0] = ::gamestate.weapons;
7538     ::gamestate.old_weapons[1] = ::gamestate.weapon;
7539     ::gamestate.old_weapons[2] = ::gamestate.chosenweapon;
7540 
7541     ::gamestate.health = 100;
7542     ::gamestate.old_ammo = STARTAMMO;
7543     ::gamestate.ammo = STARTAMMO;
7544     ::gamestate.lives = 3;
7545     ::gamestate.nextextra = EXTRAPOINTS;
7546     ::gamestate.episode = episode;
7547     ::gamestate.flags |= (GS_CLIP_WALLS | GS_ATTACK_INFOAREA); // |GS_DRAW_CEILING|GS_DRAW_FLOOR);
7548     ::gamestate.mapon = (::is_ps() ? 0 : 1);
7549 
7550     ::startgame = true;
7551 
7552     for (loop = 0; loop < MAPS_WITH_STATS; loop++) {
7553         ::gamestuff.old_levelinfo[loop].stats.overall_floor = 100;
7554         if (loop) {
7555             ::gamestuff.old_levelinfo[loop].locked = true;
7556         }
7557     }
7558 
7559     ::ExtraRadarFlags = 0;
7560     ::InstantWin = 0;
7561     ::InstantQuit = 0;
7562 
7563     ::pickquick = 0;
7564 
7565     // BBi
7566     ::g_playtemp.set_position(0);
7567     ::g_playtemp.set_size(0);
7568     // BBi
7569 }
7570 
7571 // ===========================================================================
7572 
7573 
7574 bool LevelInPlaytemp(
7575     int level_index);
7576 
7577 #define LZH_WORK_BUFFER_SIZE (8192)
7578 
7579 void* lzh_work_buffer;
7580 
InitPlaytemp()7581 void InitPlaytemp()
7582 {
7583     g_playtemp.open(1 * 1024 * 1024);
7584     g_playtemp.set_size(0);
7585     g_playtemp.set_position(0);
7586 }
7587 
FindChunk(bstone::IStream * stream,const std::string & dst_chunk_name)7588 int FindChunk(
7589     bstone::IStream* stream,
7590     const std::string& dst_chunk_name)
7591 {
7592     std::string src_chunk_name;
7593     char src_chunk_name_buffer[4];
7594 
7595     stream->set_position(0);
7596 
7597     for (bool quit = false; !quit; ) {
7598         if (stream->read(src_chunk_name_buffer, 4) == 4) {
7599             int32_t chunk_size = 0;
7600 
7601             if (stream->read(&chunk_size, 4) == 4) {
7602                 bstone::Endian::lei(chunk_size);
7603 
7604                 src_chunk_name.assign(src_chunk_name_buffer, 4);
7605 
7606                 if (src_chunk_name == dst_chunk_name) {
7607                     return chunk_size;
7608                 }
7609 
7610                 stream->skip(chunk_size);
7611             } else {
7612                 quit = true;
7613             }
7614         } else {
7615             quit = true;
7616         }
7617     }
7618 
7619     stream->seek(0, bstone::StreamSeekOrigin::end);
7620 
7621     return 0;
7622 }
7623 
NextChunk(bstone::IStream * stream)7624 int NextChunk(
7625     bstone::IStream* stream)
7626 {
7627     bool is_succeed = true;
7628 
7629     if (is_succeed) {
7630         char name_buffer[4];
7631         is_succeed = (stream->read(name_buffer, 4) == 4);
7632     }
7633 
7634     int32_t chunk_size = 0;
7635 
7636     if (is_succeed) {
7637         is_succeed = (stream->read(&chunk_size, 4) == 4);
7638     }
7639 
7640     if (is_succeed) {
7641         return chunk_size;
7642     }
7643 
7644     stream->seek(0, bstone::StreamSeekOrigin::end);
7645     return 0;
7646 }
7647 
7648 int8_t LS_current = -1;
7649 int8_t LS_total = -1;
7650 
LoadLevel(int level_index)7651 bool LoadLevel(
7652     int level_index)
7653 {
7654     extern bool ForceLoadDefault;
7655 
7656     bool oldloaded = loadedgame;
7657 
7658     extern int16_t nsd_table[];
7659     extern int16_t sm_table[];
7660 
7661     WindowY = 181;
7662 
7663     int real_level_index =
7664         level_index != 0xFF ? level_index : gamestate.mapon;
7665 
7666     gamestuff.level[real_level_index].locked = false;
7667     int mod = real_level_index % 6;
7668     normalshade_div = nsd_table[mod];
7669     shade_max = sm_table[mod];
7670     normalshade = (3 * (maxscale >> 2)) / normalshade_div;
7671 
7672     std::string chunk_name = "LV" + (
7673         bstone::FormatString() << std::setw(2) << std::setfill('0') <<
7674         std::hex << std::uppercase << level_index).to_string();
7675 
7676     g_playtemp.set_position(0);
7677 
7678     if ((::FindChunk(&g_playtemp, chunk_name) == 0) || ForceLoadDefault) {
7679         ::SetupGameLevel();
7680 
7681         gamestate.flags |= GS_VIRGIN_LEVEL;
7682         gamestate.turn_around = 0;
7683 
7684         ::PreloadUpdate(1, 1);
7685         ForceLoadDefault = false;
7686         return true;
7687     }
7688 
7689     gamestate.flags &= ~GS_VIRGIN_LEVEL;
7690 
7691     // Read all sorts of stuff...
7692     //
7693 
7694     bool is_succeed = true;
7695     bstone::Crc32 checksum;
7696 
7697     loadedgame = true;
7698     ::SetupGameLevel();
7699     loadedgame = oldloaded;
7700 
7701     bstone::BinaryReader reader(&g_playtemp);
7702 
7703     try {
7704         ::deserialize_field(tilemap, reader, checksum);
7705 
7706         for (int i = 0; i < MAPSIZE; ++i) {
7707             for (int j = 0; j < MAPSIZE; ++j) {
7708                 int32_t value = 0;
7709                 ::deserialize_field(value, reader, checksum);
7710 
7711                 if (value < 0) {
7712                     actorat[i][j] = &objlist[-value];
7713                 } else {
7714                     actorat[i][j] = reinterpret_cast<objtype*>(static_cast<size_t>(value));
7715                 }
7716             }
7717         }
7718 
7719         ::deserialize_field(areaconnect, reader, checksum);
7720         ::deserialize_field(areabyplayer, reader, checksum);
7721 
7722         // Restore 'save game' actors
7723         //
7724 
7725         int32_t actor_count = 0;
7726         ::deserialize_field(actor_count, reader, checksum);
7727 
7728         if (actor_count < 1 || actor_count >= MAXACTORS) {
7729             throw ArchiveException("actor_count");
7730         }
7731 
7732         ::InitActorList();
7733 
7734         // First actor is always player
7735         new_actor->deserialize(reader, checksum);
7736 
7737         for (int32_t i = 1; i < actor_count; ++i) {
7738             ::GetNewActor();
7739             new_actor->deserialize(reader, checksum);
7740             actorat[new_actor->tilex][new_actor->tiley] = new_actor;
7741 
7742 #if LOOK_FOR_DEAD_GUYS
7743             if ((new_actor->flags & FL_DEADGUY) != 0) {
7744                 DeadGuys[NumDeadGuys++] = new_actor;
7745             }
7746 #endif
7747         }
7748 
7749         //
7750         //  Re-Establish links to barrier switches
7751         //
7752 
7753         for (objtype* actor = objlist; actor; actor = actor->next) {
7754             switch (actor->obclass) {
7755             case arc_barrierobj:
7756             case post_barrierobj:
7757             case vspike_barrierobj:
7758             case vpost_barrierobj:
7759                 actor->temp2 = ::ScanBarrierTable(
7760                     actor->tilex, actor->tiley);
7761                 break;
7762 
7763             default:
7764                 break;
7765             }
7766         }
7767 
7768         ::ConnectBarriers();
7769 
7770         // Read all sorts of stuff...
7771         //
7772 
7773         int32_t laststatobj_index = 0;
7774         ::deserialize_field(laststatobj_index, reader, checksum);
7775 
7776         if (laststatobj_index < 0) {
7777             laststatobj = nullptr;
7778         } else {
7779             laststatobj = &statobjlist[laststatobj_index];
7780         }
7781 
7782         for (int i = 0; i < MAXSTATS; ++i) {
7783             statobjlist[i].deserialize(reader, checksum);
7784         }
7785 
7786         ::deserialize_field(doorposition, reader, checksum);
7787 
7788         for (int i = 0; i < MAXDOORS; ++i) {
7789             doorobjlist[i].deserialize(reader, checksum);
7790         }
7791 
7792         ::deserialize_field(pwallstate, reader, checksum);
7793         ::deserialize_field(pwallx, reader, checksum);
7794         ::deserialize_field(pwally, reader, checksum);
7795         ::deserialize_field(pwalldir, reader, checksum);
7796         ::deserialize_field(pwallpos, reader, checksum);
7797         ::deserialize_field(pwalldist, reader, checksum);
7798         ::deserialize_field(TravelTable, reader, checksum);
7799         ConHintList.deserialize(reader, checksum);
7800 
7801         for (int i = 0; i < MAXEAWALLS; ++i) {
7802             eaList[i].deserialize(reader, checksum);
7803         }
7804 
7805         GoldsternInfo.deserialize(reader, checksum);
7806 
7807         for (int i = 0; i < GOLDIE_MAX_SPAWNS; ++i) {
7808             GoldieList[i].deserialize(reader, checksum);
7809         }
7810 
7811         for (int i = 0; i < MAX_BARRIER_SWITCHES; ++i) {
7812             ::gamestate.barrier_table[i].deserialize(reader, checksum);
7813         }
7814 
7815         // BBi
7816         ::apply_cross_barriers();
7817         // BBi
7818 
7819         ::deserialize_field(gamestate.plasma_detonators, reader, checksum);
7820     } catch (const ArchiveException&) {
7821         is_succeed = false;
7822     }
7823 
7824     // Read and evaluate checksum
7825     //
7826     if (is_succeed) {
7827         uint32_t saved_checksum = 0;
7828         reader.read(saved_checksum);
7829         bstone::Endian::lei(saved_checksum);
7830 
7831         is_succeed = (saved_checksum == checksum.get_value());
7832     }
7833 
7834     if (!is_succeed) {
7835         int16_t old_wx = WindowX;
7836         int16_t old_wy = WindowY;
7837         int16_t old_ww = WindowW;
7838         int16_t old_wh = WindowH;
7839         int16_t old_px = px;
7840         int16_t old_py = py;
7841 
7842         WindowX = 0;
7843         WindowY = 16;
7844         WindowW = 320;
7845         WindowH = 168;
7846 
7847         ::CacheMessage(BADINFO_TEXT);
7848 
7849         WindowX = old_wx;
7850         WindowY = old_wy;
7851         WindowW = old_ww;
7852         WindowH = old_wh;
7853 
7854         px = old_px;
7855         py = old_py;
7856 
7857         ::IN_ClearKeysDown();
7858         ::IN_Ack();
7859 
7860         gamestate.score = 0;
7861         gamestate.nextextra = EXTRAPOINTS;
7862         gamestate.lives = 1;
7863 
7864         gamestate.weapon = gamestate.chosenweapon = wp_autocharge;
7865         gamestate.weapons = 1 << wp_autocharge;
7866 
7867         gamestate.ammo = 8;
7868     }
7869 
7870     ::NewViewSize();
7871 
7872     // Check for Strange Door and Actor combos
7873     //
7874     if (is_succeed) {
7875         ::CleanUpDoors_N_Actors();
7876     }
7877 
7878     return is_succeed;
7879 }
7880 
SaveLevel(int level_index)7881 bool SaveLevel(
7882     int level_index)
7883 {
7884     WindowY = 181;
7885 
7886     // Make sure floor stats are saved!
7887     //
7888     int16_t oldmapon = gamestate.mapon;
7889     gamestate.mapon = gamestate.lastmapon;
7890     ::ShowStats(0, 0, ss_justcalc,
7891                 &gamestuff.level[gamestate.mapon].stats);
7892     gamestate.mapon = oldmapon;
7893 
7894     // Yeah! We're no longer a virgin!
7895     //
7896     gamestate.flags &= ~GS_VIRGIN_LEVEL;
7897 
7898     // Remove level chunk from file
7899     //
7900     std::string chunk_name = "LV" + (
7901         bstone::FormatString() << std::setw(2) << std::setfill('0') <<
7902         std::hex << std::uppercase << level_index).to_string();
7903 
7904     ::DeleteChunk(g_playtemp, chunk_name);
7905 
7906     g_playtemp.seek(0, bstone::StreamSeekOrigin::end);
7907 
7908     // Write level chunk id
7909     //
7910     g_playtemp.write(chunk_name.c_str(), 4);
7911 
7912     // leave four bytes for chunk size
7913     g_playtemp.skip(4);
7914 
7915     bstone::Crc32 checksum;
7916     int64_t beg_offset = g_playtemp.get_position();
7917 
7918     bstone::BinaryWriter writer(&g_playtemp);
7919 
7920     ::serialize_field(tilemap, writer, checksum);
7921 
7922     //
7923     // actorat
7924     //
7925 
7926     for (int i = 0; i < MAPSIZE; ++i) {
7927         for (int j = 0; j < MAPSIZE; ++j) {
7928             int32_t s_value;
7929 
7930             if (actorat[i][j] >= objlist) {
7931                 s_value = -static_cast<int32_t>(
7932                     actorat[i][j] - objlist);
7933             } else {
7934                 s_value = static_cast<int32_t>(
7935                     reinterpret_cast<size_t>(actorat[i][j]));
7936             }
7937 
7938             ::serialize_field(s_value, writer, checksum);
7939         }
7940     }
7941 
7942     ::serialize_field(areaconnect, writer, checksum);
7943     ::serialize_field(areabyplayer, writer, checksum);
7944 
7945     //
7946     // objlist
7947     //
7948 
7949     int32_t actor_count = 0;
7950     const objtype* actor = nullptr;
7951 
7952     for (actor = player; actor; actor = actor->next) {
7953         ++actor_count;
7954     }
7955 
7956     ::serialize_field(actor_count, writer, checksum);
7957 
7958     for (actor = player; actor; actor = actor->next) {
7959         actor->serialize(writer, checksum);
7960     }
7961 
7962     //
7963     // laststatobj
7964     //
7965 
7966     int32_t laststatobj_index =
7967         static_cast<int32_t>(laststatobj - statobjlist);
7968 
7969     ::serialize_field(laststatobj_index, writer, checksum);
7970 
7971 
7972     //
7973     // statobjlist
7974     //
7975     for (int i = 0; i < MAXSTATS; ++i) {
7976         statobjlist[i].serialize(writer, checksum);
7977     }
7978 
7979     //
7980 
7981     ::serialize_field(doorposition, writer, checksum);
7982 
7983     for (int i = 0; i < MAXDOORS; ++i) {
7984         doorobjlist[i].serialize(writer, checksum);
7985     }
7986 
7987     ::serialize_field(pwallstate, writer, checksum);
7988     ::serialize_field(pwallx, writer, checksum);
7989     ::serialize_field(pwally, writer, checksum);
7990     ::serialize_field(pwalldir, writer, checksum);
7991     ::serialize_field(pwallpos, writer, checksum);
7992     ::serialize_field(pwalldist, writer, checksum);
7993     ::serialize_field(TravelTable, writer, checksum);
7994     ConHintList.serialize(writer, checksum);
7995 
7996     for (int i = 0; i < MAXEAWALLS; ++i) {
7997         eaList[i].serialize(writer, checksum);
7998     }
7999 
8000     GoldsternInfo.serialize(writer, checksum);
8001 
8002     for (int i = 0; i < GOLDIE_MAX_SPAWNS; ++i) {
8003         GoldieList[i].serialize(writer, checksum);
8004     }
8005 
8006     for (int i = 0; i < MAX_BARRIER_SWITCHES; ++i) {
8007         ::gamestate.barrier_table[i].serialize(writer, checksum);
8008     }
8009 
8010     ::serialize_field(::gamestate.plasma_detonators, writer, checksum);
8011 
8012     // Write checksum and determine size of file
8013     //
8014     writer.write(bstone::Endian::le(checksum.get_value()));
8015 
8016     int64_t end_offset = g_playtemp.get_position();
8017     int32_t chunk_size = static_cast<int32_t>(end_offset - beg_offset);
8018 
8019     // Write chunk size, set file size, and close file
8020     //
8021     g_playtemp.seek(-(chunk_size + 4), bstone::StreamSeekOrigin::current);
8022     writer.write(bstone::Endian::le(chunk_size));
8023     g_playtemp.set_size(end_offset);
8024 
8025     ::NewViewSize();
8026 
8027     return true;
8028 }
8029 
DeleteChunk(bstone::MemoryStream & stream,const std::string & chunk_name)8030 int DeleteChunk(
8031     bstone::MemoryStream& stream,
8032     const std::string& chunk_name)
8033 {
8034     stream.set_position(0);
8035 
8036     int chunk_size = ::FindChunk(&stream, chunk_name);
8037 
8038     if (chunk_size > 0) {
8039         int64_t offset = stream.get_position() - 8;
8040         int count = chunk_size + 8;
8041 
8042         stream.remove_block(offset, count);
8043     }
8044 
8045     return chunk_size;
8046 }
8047 
get_saved_game_version_string()8048 static const std::string& get_saved_game_version_string()
8049 {
8050     static auto version_string = std::string();
8051     static auto is_initialized = false;
8052 
8053     if (!is_initialized) {
8054         is_initialized = true;
8055 
8056         version_string = "bstone: ";
8057 
8058         if (::is_aog_sw()) {
8059             version_string += "aliens of gold (shareware)";
8060         } else if (::is_aog_full()) {
8061             version_string += "aliens of gold (full)";
8062         } else if (::is_ps()) {
8063             version_string += "planet strike";
8064         } else {
8065             throw std::runtime_error("Invalid game type.");
8066         }
8067 
8068         version_string +=
8069             " saved game (v" +
8070             std::to_string(BS_SAVE_VERSION) +
8071             ")"
8072         ;
8073     }
8074 
8075     return version_string;
8076 }
8077 
LoadCompressedChunk(const std::string & chunk_name,bstone::IStream * stream,Buffer & buffer)8078 static bool LoadCompressedChunk(
8079     const std::string& chunk_name,
8080     bstone::IStream* stream,
8081     Buffer& buffer)
8082 {
8083     auto stream_size = stream->get_size();
8084 
8085     bstone::BinaryReader reader(stream);
8086 
8087 
8088     if (::FindChunk(stream, chunk_name) == 0) {
8089         bstone::Log::write_error(
8090             "LOAD: Failed to locate {} chunk.",
8091             chunk_name);
8092 
8093         return false;
8094     }
8095 
8096     reader.skip(-4);
8097 
8098     auto total_size = bstone::Endian::le(reader.read_s32());
8099 
8100     if (total_size <= 0 || total_size > stream_size) {
8101         bstone::Log::write_error(
8102             "LOAD: Invalid {} size.",
8103             chunk_name);
8104 
8105         return false;
8106     }
8107 
8108     auto size = total_size - 4;
8109     auto src_size = bstone::Endian::le(reader.read_s32());
8110 
8111     Buffer src_buffer(size);
8112 
8113     if (!reader.read(src_buffer.data(), size)) {
8114         bstone::Log::write_error(
8115             "LOAD: Unexpected end of {} data.",
8116             chunk_name);
8117     }
8118 
8119 
8120     buffer.resize(src_size);
8121 
8122     static_cast<void>(::LZH_Startup());
8123 
8124     auto decoded_size = ::LZH_Decompress(
8125         src_buffer.data(),
8126         buffer.data(),
8127         src_size,
8128         size);
8129 
8130     ::LZH_Shutdown();
8131 
8132     if (decoded_size != src_size) {
8133         bstone::Log::write_error(
8134             "LOAD: Failed to decompress {} data.",
8135             chunk_name);
8136 
8137         return false;
8138     }
8139 
8140     return true;
8141 }
8142 
LoadTheGame(const std::string & file_name)8143 bool LoadTheGame(
8144     const std::string& file_name)
8145 {
8146     bool is_succeed = true;
8147 
8148     bstone::FileStream file_stream(file_name);
8149 
8150     if (!file_stream.is_open()) {
8151         is_succeed = false;
8152 
8153         bstone::Log::write_error(
8154             "LOAD: Failed to open file \"{}\".",
8155             file_name);
8156     }
8157 
8158     bstone::BinaryReader file_reader(&file_stream);
8159 
8160     if (is_succeed) {
8161         is_succeed &= g_playtemp.set_size(0);
8162         is_succeed &= g_playtemp.set_position(0);
8163     }
8164 
8165 
8166     // Read in VERS chunk
8167     //
8168     if (is_succeed) {
8169         if (::FindChunk(&file_stream, "VERS") == 0) {
8170             is_succeed = false;
8171 
8172             bstone::Log::write_error(
8173                 "LOAD: Failed to locate VERS chunk.");
8174         }
8175     }
8176 
8177     if (is_succeed) {
8178         const int max_length = 128;
8179 
8180         const auto& version_string = ::get_saved_game_version_string();
8181 
8182         file_reader.skip(-4);
8183 
8184         const auto saved_version_string = file_reader.read_string(
8185             max_length);
8186 
8187         if (saved_version_string != version_string) {
8188             is_succeed = false;
8189 
8190             bstone::Log::write_error(
8191                 "LOAD: Invalid version.");
8192         }
8193     }
8194 
8195 
8196     // Read in HEAD chunk
8197     //
8198     Buffer head_buffer;
8199 
8200     if (is_succeed) {
8201         if (!::LoadCompressedChunk("HEAD", &file_stream, head_buffer)) {
8202             is_succeed = false;
8203         }
8204     }
8205 
8206     // Read in LVXX chunk
8207     //
8208     Buffer lvxx_buffer;
8209 
8210     if (is_succeed) {
8211         if (!::LoadCompressedChunk("LVXX", &file_stream, lvxx_buffer)) {
8212             is_succeed = false;
8213         }
8214     }
8215 
8216 
8217     bstone::Crc32 checksum;
8218 
8219     // Deserialize HEAD chunk
8220     //
8221     if (is_succeed) {
8222         try {
8223             bstone::MemoryStream head_stream(
8224                 static_cast<int>(head_buffer.size()),
8225                 0,
8226                 head_buffer.data());
8227 
8228             bstone::BinaryReader head_reader(&head_stream);
8229 
8230             gamestate.deserialize(head_reader, checksum);
8231             gamestuff.deserialize(head_reader, checksum);
8232         } catch (const ArchiveException&) {
8233             is_succeed = false;
8234 
8235             bstone::Log::write_error(
8236                 "LOAD: Failed to deserialize HEAD data.");
8237         }
8238     }
8239 
8240     // Deserialize LVXX chunk
8241     //
8242     if (is_succeed) {
8243         is_succeed &= ::g_playtemp.set_position(0);
8244         is_succeed &= ::g_playtemp.set_size(0);
8245 
8246         if (is_succeed) {
8247             bstone::MemoryStream lvxx_stream(
8248                 static_cast<int>(lvxx_buffer.size()),
8249                 0,
8250                 lvxx_buffer.data());
8251 
8252             if (!lvxx_stream.copy_to(&::g_playtemp)) {
8253                 is_succeed = false;
8254 
8255                 bstone::Log::write_error(
8256                     "LOAD: Failed to deserialize LVXX data.");
8257             }
8258         }
8259     }
8260 
8261 
8262     // Finish loading
8263     //
8264     ::NewViewSize();
8265 
8266     bool show_error_message = true;
8267 
8268     if (is_succeed) {
8269         // Start music for the starting level in this loaded game.
8270         //
8271         ::FreeMusic();
8272         ::StartMusic(false);
8273 
8274         is_succeed = ::LoadLevel(0xFF);
8275 
8276         // Already shown in LoadLevel
8277         show_error_message = false;
8278     }
8279 
8280     if (is_succeed) {
8281         ::ShowQuickMsg = false;
8282     } else {
8283         static_cast<void>(::g_playtemp.set_position(0));
8284         static_cast<void>(::g_playtemp.set_size(0));
8285 
8286         if (show_error_message) {
8287             const char* const message =
8288                 "The selected saved game is\n"
8289                 "from an unsupported version of\n"
8290                 "the game and can not be loaded.\n"
8291                 "\n"
8292                 "           Press a key."
8293             ;
8294 
8295             auto old_wx = ::WindowX;
8296             auto old_wy = ::WindowY;
8297             auto old_ww = ::WindowW;
8298             auto old_wh = ::WindowH;
8299             auto old_px = ::px;
8300             auto old_py = ::py;
8301 
8302             ::WindowX = 0;
8303             ::WindowY = 16;
8304             ::WindowW = 320;
8305             ::WindowH = 168;
8306 
8307             ::Message(message);
8308 
8309             ::sd_play_player_sound(::NOWAYSND, bstone::AC_NO_WAY);
8310 
8311             ::WindowX = old_wx;
8312             ::WindowY = old_wy;
8313             ::WindowW = old_ww;
8314             ::WindowH = old_wh;
8315 
8316             ::px = old_px;
8317             ::py = old_py;
8318 
8319             ::IN_ClearKeysDown();
8320             ::IN_Ack();
8321 
8322             ::VW_FadeOut();
8323             ::screenfaded = true;
8324         }
8325     }
8326 
8327     return is_succeed;
8328 }
8329 
SaveTheGame(const std::string & file_name,const std::string & description)8330 bool SaveTheGame(
8331     const std::string& file_name,
8332     const std::string& description)
8333 {
8334     bstone::FileStream file_stream(
8335         file_name,
8336         bstone::StreamOpenMode::write);
8337 
8338     if (!file_stream.is_open()) {
8339         bstone::Log::write_error(
8340             "SAVE: Failed to open file \"{}\".",
8341             file_name);
8342 
8343         return false;
8344     }
8345 
8346 
8347     // Store current level
8348     //
8349     static_cast<void>(::SaveLevel(0xFF));
8350 
8351 
8352     // Compose HEAD data
8353     //
8354     bstone::Crc32 head_checksum;
8355     bstone::MemoryStream head_stream;
8356     bstone::BinaryWriter head_writer(&head_stream);
8357 
8358     try {
8359         gamestate.serialize(head_writer, head_checksum);
8360         gamestuff.serialize(head_writer, head_checksum);
8361         head_writer.set_position(0);
8362     } catch (const ArchiveException&) {
8363         bstone::Log::write_error(
8364             "SAVE: Failed to serialize HEAD chunk.");
8365 
8366         return false;
8367     }
8368 
8369 
8370     auto head_src_size = static_cast<int32_t>(head_stream.get_size());
8371     const int32_t head_desire_dst_size = 2 * head_src_size;
8372 
8373     Buffer head_buffer(head_desire_dst_size);
8374 
8375     static_cast<void>(::LZH_Startup());
8376 
8377     int32_t head_dst_size = ::LZH_Compress(
8378         head_stream.get_data(),
8379         head_buffer.data(),
8380         head_src_size);
8381 
8382     ::LZH_Shutdown();
8383 
8384     if (head_dst_size > head_desire_dst_size) {
8385         bstone::Log::write_error(
8386             "SAVE: Failed to compress HEAD data.");
8387 
8388         return false;
8389     }
8390 
8391 
8392     // Compose LVXX data
8393     //
8394     ::g_playtemp.set_position(0);
8395 
8396     auto lvxx_src_size = static_cast<int32_t>(::g_playtemp.get_size());
8397 
8398     const int32_t lvxx_desire_dst_size = (2 * lvxx_src_size);
8399 
8400     Buffer lvxx_buffer(lvxx_desire_dst_size);
8401 
8402     static_cast<void>(::LZH_Startup());
8403 
8404     int32_t lvxx_dst_size = ::LZH_Compress(
8405         ::g_playtemp.get_data(),
8406         lvxx_buffer.data(),
8407         lvxx_src_size);
8408 
8409     ::LZH_Shutdown();
8410 
8411     if (lvxx_dst_size > lvxx_desire_dst_size) {
8412         bstone::Log::write_error(
8413             "SAVE: Failed to compress LVXX data.");
8414 
8415         return false;
8416     }
8417 
8418 
8419     // Write to file
8420     //
8421     bool is_succeed = true;
8422 
8423     bstone::BinaryWriter file_writer(&file_stream);
8424 
8425     // Write VERS chunk
8426     //
8427     is_succeed &= file_writer.write("VERS", 4);
8428     is_succeed &= file_writer.write(::get_saved_game_version_string());
8429 
8430     // Write DESC chunk
8431     //
8432     is_succeed &= file_writer.write("DESC", 4);
8433     is_succeed &= file_writer.write(description);
8434 
8435     // Write HEAD chunk
8436     //
8437     is_succeed &= file_writer.write("HEAD", 4);
8438     is_succeed &= file_writer.write(bstone::Endian::le(head_dst_size + 4));
8439     is_succeed &= file_writer.write(bstone::Endian::le(head_src_size));
8440     is_succeed &= file_stream.write(head_buffer.data(), head_dst_size);
8441 
8442     // Write LVXX chunk
8443     //
8444     is_succeed &= file_writer.write("LVXX", 4);
8445     is_succeed &= file_writer.write(
8446         bstone::Endian::le(lvxx_dst_size + 4));
8447     is_succeed &= file_writer.write(
8448         bstone::Endian::le(lvxx_src_size));
8449     is_succeed &= file_stream.write(lvxx_buffer.data(), lvxx_dst_size);
8450 
8451     //
8452     ::NewViewSize();
8453 
8454     if (!is_succeed) {
8455         bstone::Log::write_error(
8456             "SAVE: Failed to write data.");
8457     }
8458 
8459     return is_succeed;
8460 }
8461 
LevelInPlaytemp(int level_index)8462 bool LevelInPlaytemp(
8463     int level_index)
8464 {
8465     bstone::FormatString format;
8466     format << "LV" << std::uppercase << std::hex <<
8467         std::setfill('0') << std::setw(2) << level_index;
8468 
8469     return ::FindChunk(&g_playtemp, format.to_string()) != 0;
8470 }
8471 
CheckDiskSpace(int32_t needed,const char * text,cds_io_type io_type)8472 bool CheckDiskSpace(
8473     int32_t needed,
8474     const char* text,
8475     cds_io_type io_type)
8476 {
8477     static_cast<void>(needed);
8478     static_cast<void>(text);
8479     static_cast<void>(io_type);
8480     return true;
8481 }
8482 
CleanUpDoors_N_Actors()8483 void CleanUpDoors_N_Actors()
8484 {
8485     int x;
8486     int y;
8487     objtype* actor;
8488     uint8_t tile;
8489     uint16_t door;
8490 
8491     for (y = 0; y < mapheight; ++y) {
8492         for (x = 0; x < mapwidth; ++x) {
8493             tile = tilemap[y][x];
8494 
8495             if ((tile & 0x80) != 0) {
8496                 // Found a door
8497 
8498                 actor = actorat[y][x];
8499                 uint16_t actor_u16 = static_cast<uint16_t>(
8500                     reinterpret_cast<size_t>(actor));
8501 
8502                 if (ui16_to_actor(actor_u16)) {
8503                     // Found an actor
8504 
8505                     door = tile & 0x3F;
8506 
8507                     if ((actor->flags & (FL_SOLID | FL_DEADGUY)) == (FL_SOLID | FL_DEADGUY)) {
8508                         actor->flags &= ~(FL_SHOOTABLE | FL_SOLID | FL_FAKE_STATIC);
8509                     }
8510 
8511                     // Make sure door is open
8512 
8513                     doorobjlist[door].ticcount = 0;
8514                     doorobjlist[door].action = dr_open;
8515                     doorposition[door] = 0xFFFF;
8516                 }
8517             }
8518         }
8519     }
8520 }
8521 
8522 // --------------------------------------------------------------------------
8523 // ClearNClose() - Use when changing levels via standard elevator.
8524 //
8525 // - This code doesn't CLEAR the elevator door as originally
8526 // planned because, actors were coded to stay out of the
8527 // elevator doorway.
8528 //
8529 // --------------------------------------------------------------------------
ClearNClose()8530 void ClearNClose()
8531 {
8532     int tx = 0;
8533     int ty = 0;
8534     int p_x = (::player->x >> TILESHIFT) & 0xFF;
8535     int p_y = (::player->y >> TILESHIFT) & 0xFF;
8536 
8537     // Locate the door.
8538     //
8539     for (int x = -1; x < 2 && tx == 0; x += 2) {
8540         for (int y = -1; y < 2; y += 2) {
8541             if ((::tilemap[p_x + x][p_y + y] & 0x80) != 0) {
8542                 tx = p_x + x;
8543                 ty = p_y + y;
8544                 break;
8545             }
8546         }
8547     }
8548 
8549     // Close the door!
8550     //
8551     if (tx != 0) {
8552         int door_index = ::tilemap[tx][ty] & 63;
8553 
8554         ::doorobjlist[door_index].action = dr_closed; // this door is closed!
8555         ::doorposition[door_index] = 0; // draw it closed!
8556 
8557         // make it solid!
8558         ::actorat[tx][ty] = reinterpret_cast<objtype*>(static_cast<size_t>(door_index | 0x80));
8559     }
8560 }
8561 
CycleColors()8562 void CycleColors()
8563 {
8564     const int NUM_RANGES = 5;
8565     const uint8_t CRNG_LOW = 0xF0;
8566     const uint8_t CRNG_HIGH = 0xFE;
8567     const int CRNG_SIZE = CRNG_HIGH - CRNG_LOW + 1;
8568 
8569     static CycleInfo crng[NUM_RANGES] = {
8570         { 7, 0, 0xF0, 0xF1 },
8571         { 15, 0, 0xF2, 0xF3 },
8572         { 30, 0, 0xF4, 0xF5 },
8573         { 10, 0, 0xF6, 0xF9 },
8574         { 12, 0, 0xFA, 0xFE },
8575     };
8576 
8577     uint8_t loop;
8578     uint8_t cbuffer[CRNG_SIZE][3];
8579     bool changes = false;
8580 
8581     for (loop = 0; loop < NUM_RANGES; loop++) {
8582         CycleInfo* c = &crng[loop];
8583 
8584         if (tics >= c->delay_count) {
8585             uint8_t temp[3], first, last, numregs;
8586 
8587             if (!changes) {
8588                 VL_GetPalette(CRNG_LOW, CRNG_SIZE, (uint8_t*)cbuffer);
8589                 changes = true;
8590             }
8591 
8592             first = c->firstreg - CRNG_LOW;
8593             numregs = c->lastreg - c->firstreg;                 // is one less than in range
8594             last = first + numregs;
8595 
8596             memcpy(temp, cbuffer[last], 3);
8597             memmove(cbuffer[first + 1], cbuffer[first], numregs * 3);
8598             memcpy(cbuffer[first], temp, 3);
8599 
8600             c->delay_count = c->init_delay;
8601         } else {
8602             c->delay_count -= static_cast<uint8_t>(tics);
8603         }
8604     }
8605 
8606     bool use_delay = false;
8607 
8608     if (changes) {
8609         ::VL_SetPalette(CRNG_LOW, CRNG_SIZE, (uint8_t*)cbuffer);
8610         ::VL_RefreshScreen();
8611 
8612         use_delay = !::vid_has_vsync;
8613     } else {
8614         use_delay = true;
8615     }
8616 
8617     if (use_delay)
8618     {
8619         VW_WaitVBL(1);
8620     }
8621 }
8622 
8623 /*
8624 ==========================
8625 =
8626 = ShutdownId
8627 =
8628 = Shuts down all ID_?? managers
8629 =
8630 ==========================
8631 */
ShutdownId()8632 void ShutdownId()
8633 {
8634     US_Shutdown();
8635     SD_Shutdown();
8636     PM_Shutdown();
8637     IN_Shutdown();
8638     VW_Shutdown();
8639     CA_Shutdown();
8640 }
8641 
8642 /*
8643 ====================
8644 =
8645 = CalcProjection
8646 =
8647 = Uses focallength
8648 =
8649 ====================
8650 */
CalcProjection(int32_t focal)8651 void CalcProjection(
8652     int32_t focal)
8653 {
8654     ::focallength = focal;
8655     const double facedist = focal + MINDIST;
8656     const auto halfview = ::viewwidth / 2; // half view in pixels
8657 
8658     //
8659     // calculate scale value for vertical height calculations
8660     // and sprite x calculations
8661     //
8662     ::scale = static_cast<int>(halfview * facedist / (VIEWGLOBAL / 2));
8663 
8664     //
8665     // divide heightnumerator by a posts distance to get the posts height for
8666     // the heightbuffer.  The pixel height is height>>2
8667     //
8668     ::heightnumerator = (TILEGLOBAL * ::scale) / 64;
8669     ::minheightdiv = (::heightnumerator / 0x7FFF) + 1;
8670 
8671     //
8672     // calculate the angle offset from view angle of each pixel's ray
8673     //
8674 
8675     ::pixelangle.clear();
8676     ::pixelangle.resize(::vga_width);
8677 
8678     for (int i = 0; i < halfview; i++)
8679     {
8680         // start 1/2 pixel over, so viewangle bisects two middle pixels
8681         const double tang = i * VIEWGLOBAL / ::viewwidth / facedist;
8682         const auto angle = static_cast<float>(::atan(tang));
8683         const auto intang = static_cast<int>(angle * radtoint);
8684         ::pixelangle[halfview - 1 - i] = intang;
8685         ::pixelangle[halfview + i] = -intang;
8686     }
8687 
8688     //
8689     // if a point's abs(y/x) is greater than maxslope, the point is outside
8690     // the view area
8691     //
8692     ::maxslope = ::finetangent[::pixelangle[0]];
8693     ::maxslope /= 256;
8694 }
8695 
DoMovie(movie_t movie,void * palette)8696 bool DoMovie(
8697     movie_t movie,
8698     void* palette)
8699 {
8700     bool ReturnVal;
8701     SD_StopSound();
8702 
8703     ClearMemory();
8704     UnCacheLump(STARTFONT, STARTFONT + NUMFONT);
8705     CA_LoadAllSounds();
8706 
8707     if (palette) {
8708         movies[movie].palette = palette;
8709     } else {
8710         movies[movie].palette = vgapal;
8711     }
8712 
8713     ReturnVal = MOVIE_Play(&movies[movie]);
8714 
8715     SD_StopSound();
8716     ClearMemory();
8717     LoadFonts();
8718 
8719     return ReturnVal;
8720 }
8721 
LoadFonts()8722 void LoadFonts()
8723 {
8724     CA_CacheGrChunk(STARTFONT + 4);
8725     CA_CacheGrChunk(STARTFONT + 2);
8726 }
8727 
SetViewSize()8728 void SetViewSize()
8729 {
8730     ::viewwidth = ::vga_width;
8731     ::viewheight = (ref_3d_view_height * ::vga_height) / ::vga_ref_height;
8732     ::centerx = (::viewwidth / 2) - 1;
8733     ::shootdelta = ::viewwidth / 10;
8734 
8735     ::vga_3d_view_top = (::ref_3d_view_top * ::vga_height) / ::vga_ref_height;
8736     ::vga_3d_view_bottom = (::ref_3d_view_bottom * ::vga_height) / ::vga_ref_height;
8737 
8738     ::screenofs = ::vga_3d_view_top * ::viewwidth;
8739 
8740     // calculate trace angles and projection constants
8741     ::CalcProjection(FOCALLENGTH);
8742 
8743     // build all needed compiled scalers
8744     ::SetupScaling((3 * ::viewwidth) / 2);
8745 }
8746 
NewViewSize()8747 void NewViewSize()
8748 {
8749     CA_UpLevel();
8750     ::SetViewSize();
8751     CA_DownLevel();
8752 }
8753 
pre_quit()8754 void pre_quit()
8755 {
8756     if (::is_config_loaded) {
8757         ::WriteConfig();
8758         ::write_high_scores();
8759     }
8760 
8761     ::ShutdownId();
8762 }
8763 
Quit()8764 void Quit()
8765 {
8766     ::pre_quit();
8767 
8768     ::exit(1);
8769 }
8770 
DemoLoop()8771 void DemoLoop()
8772 {
8773     bool breakit;
8774 
8775     while (true) {
8776         playstate = ex_title;
8777         if (!screenfaded) {
8778             VW_FadeOut();
8779         }
8780         VL_SetPaletteIntensity(0, 255, vgapal, 0);
8781 
8782         if (!::no_screens) {
8783             while (!(gamestate.flags & GS_NOWAIT)) {
8784                 extern bool sqActive;
8785 
8786                 // Start music when coming from menu...
8787                 //
8788                 if (!sqActive) {
8789                     // Load and start music
8790                     //
8791                     if (::is_aog()) {
8792                         CA_CacheAudioChunk(STARTMUSIC + MEETINGA_MUS);
8793                         ::SD_StartMusic(MEETINGA_MUS);
8794                     } else {
8795                         CA_CacheAudioChunk(STARTMUSIC + TITLE_LOOP_MUSIC);
8796                         ::SD_StartMusic(TITLE_LOOP_MUSIC);
8797                     }
8798                 }
8799 
8800 
8801                 //
8802                 // title page
8803                 //
8804                 breakit = false;
8805 
8806                 if (::is_aog()) {
8807                     ::CA_CacheScreen(TITLEPIC);
8808                 } else {
8809                     ::CA_CacheScreen(TITLE1PIC);
8810                 }
8811 
8812                 ::CA_CacheGrChunk(TITLEPALETTE);
8813 
8814                 ::VL_SetPalette(
8815                     0,
8816                     256,
8817                     reinterpret_cast<const uint8_t*>(::grsegs[TITLEPALETTE]));
8818 
8819                 ::VL_SetPaletteIntensity(
8820                     0,
8821                     255,
8822                     reinterpret_cast<const uint8_t*>(::grsegs[TITLEPALETTE]),
8823                     0);
8824 
8825                 auto version_text_width = 0;
8826                 auto version_text_height = 0;
8827                 const auto version_padding = 1;
8828                 const auto version_margin = 4;
8829                 const auto ps_fizzle_height = 15;
8830                 auto& version_string = ::get_version_string();
8831 
8832                 ::fontnumber = 2;
8833 
8834                 ::USL_MeasureString(
8835                     version_string.c_str(),
8836                     &version_text_width,
8837                     &version_text_height);
8838 
8839                 const auto version_bar_width =
8840                     version_text_width + (2 * version_padding);
8841 
8842                 const auto version_bar_height =
8843                     version_text_height + (2 * version_padding);
8844 
8845                 const auto version_bar_x =
8846                     ::vga_ref_width - (version_margin + version_bar_width);
8847 
8848                 const auto version_bar_y = (
8849                     ::is_aog() ?
8850                         version_margin :
8851                         ::vga_ref_height -
8852                             (version_bar_height + ps_fizzle_height));
8853 
8854                 ::WindowX = static_cast<uint16_t>(version_bar_x);
8855                 ::WindowY = static_cast<uint16_t>(version_bar_y);
8856                 ::PrintX = ::WindowX + version_padding;
8857                 ::PrintY = ::WindowY + version_padding;
8858                 ::WindowW = static_cast<uint16_t>(version_bar_width);
8859                 ::WindowH = static_cast<uint16_t>(version_bar_height);
8860 
8861                 ::VWB_Bar(
8862                     ::WindowX,
8863                     ::WindowY,
8864                     ::WindowW,
8865                     ::WindowH,
8866                     VERSION_TEXT_BKCOLOR);
8867 
8868                 SETFONTCOLOR(VERSION_TEXT_COLOR, VERSION_TEXT_BKCOLOR);
8869                 ::US_Print(::get_version_string().c_str());
8870 
8871                 VW_UpdateScreen();
8872                 ::VL_FadeIn(0, 255, reinterpret_cast<uint8_t*>(::grsegs[TITLEPALETTE]), 30);
8873                 ::UNCACHEGRCHUNK(TITLEPALETTE);
8874 
8875                 if (::is_ps()) {
8876                     bstone::PSFizzleFX fizzle;
8877 
8878                     fizzle.initialize();
8879 
8880                     breakit |= fizzle.present();
8881                 }
8882 
8883                 if (breakit || ::IN_UserInput(TickBase * 6)) {
8884                     break;
8885                 }
8886 
8887                 VW_FadeOut();
8888 
8889                 //
8890                 // credits page
8891                 //
8892                 DrawCreditsPage();
8893                 VW_UpdateScreen();
8894                 VW_FadeIn();
8895                 if (IN_UserInput(TickBase * 6)) {
8896                     break;
8897                 }
8898                 VW_FadeOut();
8899 
8900 
8901                 //
8902                 // high scores
8903                 //
8904                 CA_CacheScreen(BACKGROUND_SCREENPIC);
8905                 DrawHighScores();
8906                 VW_UpdateScreen();
8907                 VW_FadeIn();
8908 
8909                 if (IN_UserInput(TickBase * 9)) {
8910                     break;
8911                 }
8912                 VW_FadeOut();
8913             }
8914         } else {
8915             // Start music when coming from menu...
8916             if (!sqActive) {
8917                 // Load and start music
8918                 //
8919                 if (!::is_aog()) {
8920                     CA_CacheAudioChunk(STARTMUSIC + MENUSONG);
8921                     ::SD_StartMusic(MENUSONG);
8922                 } else {
8923                     CA_CacheAudioChunk(STARTMUSIC + TITLE_LOOP_MUSIC);
8924                     ::SD_StartMusic(TITLE_LOOP_MUSIC);
8925                 }
8926             }
8927         }
8928 
8929         if (!screenfaded) {
8930             VW_FadeOut();
8931         }
8932 
8933         while (true) {
8934             US_ControlPanel(ScanCode::sc_none);
8935 
8936             if (startgame || loadedgame) {
8937                 GameLoop();
8938             }
8939         }
8940     }
8941 }
8942 
DrawCreditsPage()8943 void DrawCreditsPage()
8944 {
8945     PresenterInfo pi;
8946 
8947     CA_CacheScreen(BACKGROUND_SCREENPIC);
8948 
8949     memset(&pi, 0, sizeof(pi));
8950     pi.flags = TPF_CACHE_NO_GFX;
8951     pi.xl = 38;
8952     pi.yl = 28;
8953     pi.xh = 281;
8954     pi.yh = 170;
8955     pi.bgcolor = 2;
8956     pi.ltcolor = BORDER_HI_COLOR;
8957     fontcolor = BORDER_TEXT_COLOR;
8958     pi.shcolor = pi.dkcolor = 0;
8959     pi.fontnumber = static_cast<int8_t>(fontnumber);
8960 
8961     TP_LoadScript(nullptr, &pi, CREDITSTEXT);
8962     TP_Presenter(&pi);
8963 }
8964 
8965 
8966 int16_t debug_value = 0;
8967 
main(int argc,char * argv[])8968 int main(
8969     int argc,
8970     char* argv[])
8971 {
8972     int sdl_result = 0;
8973 
8974     uint32_t init_flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
8975 
8976     sdl_result = ::SDL_Init(init_flags);
8977 
8978     if (sdl_result != 0) {
8979         ::Quit(::SDL_GetError());
8980     }
8981 
8982     ::g_args.initialize(argc, argv);
8983 
8984     freed_main();
8985 
8986     DemoLoop();
8987 
8988     Quit();
8989 
8990     return 0;
8991 }
8992 
InitDestPath()8993 void InitDestPath()
8994 {
8995     auto default_data_dir = ::get_default_data_dir();
8996     auto requested_data_dir = ::g_args.get_option_value("data_dir");
8997 
8998     if (requested_data_dir.empty()) {
8999         data_dir = ::get_default_data_dir();
9000     } else {
9001         const auto separator =
9002 #ifdef _WIN32
9003             '\\'
9004 #else
9005             '/'
9006 #endif
9007         ;
9008 
9009         data_dir = requested_data_dir;
9010 
9011         if (data_dir.back() != separator) {
9012             data_dir += separator;
9013         }
9014     }
9015 }
9016 
9017 // BBi
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9018 void objtype::serialize(
9019     bstone::BinaryWriter& writer,
9020     bstone::Crc32& checksum) const
9021 {
9022     ::serialize_field(tilex, writer, checksum);
9023     ::serialize_field(tiley, writer, checksum);
9024     ::serialize_field(areanumber, writer, checksum);
9025     ::serialize_field(active, writer, checksum);
9026     ::serialize_field(ticcount, writer, checksum);
9027     ::serialize_field(obclass, writer, checksum);
9028 
9029     int32_t state_index = static_cast<int32_t>(::get_state_index(state));
9030     ::serialize_field(state_index, writer, checksum);
9031 
9032     ::serialize_field(flags, writer, checksum);
9033     ::serialize_field(flags2, writer, checksum);
9034     ::serialize_field(distance, writer, checksum);
9035     ::serialize_field(dir, writer, checksum);
9036     ::serialize_field(trydir, writer, checksum);
9037     ::serialize_field(x, writer, checksum);
9038     ::serialize_field(y, writer, checksum);
9039     ::serialize_field(s_tilex, writer, checksum);
9040     ::serialize_field(s_tiley, writer, checksum);
9041     ::serialize_field(viewx, writer, checksum);
9042     ::serialize_field(viewheight, writer, checksum);
9043     ::serialize_field(transx, writer, checksum);
9044     ::serialize_field(transy, writer, checksum);
9045     ::serialize_field(hitpoints, writer, checksum);
9046     ::serialize_field(ammo, writer, checksum);
9047     ::serialize_field(lighting, writer, checksum);
9048     ::serialize_field(linc, writer, checksum);
9049     ::serialize_field(angle, writer, checksum);
9050     ::serialize_field(speed, writer, checksum);
9051     ::serialize_field(temp1, writer, checksum);
9052     ::serialize_field(temp2, writer, checksum);
9053     ::serialize_field(temp3, writer, checksum);
9054 }
9055 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9056 void objtype::deserialize(
9057     bstone::BinaryReader& reader,
9058     bstone::Crc32& checksum)
9059 {
9060     ::deserialize_field(tilex, reader, checksum);
9061     ::deserialize_field(tiley, reader, checksum);
9062     ::deserialize_field(areanumber, reader, checksum);
9063     ::deserialize_field(active, reader, checksum);
9064     ::deserialize_field(ticcount, reader, checksum);
9065     ::deserialize_field(obclass, reader, checksum);
9066 
9067     int32_t state_index = 0;
9068     ::deserialize_field(state_index, reader, checksum);
9069     state = states_list[state_index];
9070 
9071     ::deserialize_field(flags, reader, checksum);
9072     ::deserialize_field(flags2, reader, checksum);
9073     ::deserialize_field(distance, reader, checksum);
9074     ::deserialize_field(dir, reader, checksum);
9075     ::deserialize_field(trydir, reader, checksum);
9076     ::deserialize_field(x, reader, checksum);
9077     ::deserialize_field(y, reader, checksum);
9078     ::deserialize_field(s_tilex, reader, checksum);
9079     ::deserialize_field(s_tiley, reader, checksum);
9080     ::deserialize_field(viewx, reader, checksum);
9081     ::deserialize_field(viewheight, reader, checksum);
9082     ::deserialize_field(transx, reader, checksum);
9083     ::deserialize_field(transy, reader, checksum);
9084     ::deserialize_field(hitpoints, reader, checksum);
9085     ::deserialize_field(ammo, reader, checksum);
9086     ::deserialize_field(lighting, reader, checksum);
9087     ::deserialize_field(linc, reader, checksum);
9088     ::deserialize_field(angle, reader, checksum);
9089     ::deserialize_field(speed, reader, checksum);
9090     ::deserialize_field(temp1, reader, checksum);
9091     ::deserialize_field(temp2, reader, checksum);
9092     ::deserialize_field(temp3, reader, checksum);
9093 }
9094 
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9095 void statobj_t::serialize(
9096     bstone::BinaryWriter& writer,
9097     bstone::Crc32& checksum) const
9098 {
9099     ::serialize_field(tilex, writer, checksum);
9100     ::serialize_field(tiley, writer, checksum);
9101     ::serialize_field(areanumber, writer, checksum);
9102 
9103     int32_t vis_index = static_cast<int32_t>(visspot - &spotvis[0][0]);
9104     ::serialize_field(vis_index, writer, checksum);
9105 
9106     ::serialize_field(shapenum, writer, checksum);
9107     ::serialize_field(flags, writer, checksum);
9108     ::serialize_field(itemnumber, writer, checksum);
9109     ::serialize_field(lighting, writer, checksum);
9110 }
9111 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9112 void statobj_t::deserialize(
9113     bstone::BinaryReader& reader,
9114     bstone::Crc32& checksum)
9115 {
9116     ::deserialize_field(tilex, reader, checksum);
9117     ::deserialize_field(tiley, reader, checksum);
9118     ::deserialize_field(areanumber, reader, checksum);
9119 
9120     int32_t vis_index = 0;
9121     ::deserialize_field(vis_index, reader, checksum);
9122 
9123     if (vis_index < 0) {
9124         visspot = nullptr;
9125     } else {
9126         visspot = &(&spotvis[0][0])[vis_index];
9127     }
9128 
9129     ::deserialize_field(shapenum, reader, checksum);
9130     ::deserialize_field(flags, reader, checksum);
9131     ::deserialize_field(itemnumber, reader, checksum);
9132     ::deserialize_field(lighting, reader, checksum);
9133 }
9134 
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9135 void doorobj_t::serialize(
9136     bstone::BinaryWriter& writer,
9137     bstone::Crc32& checksum) const
9138 {
9139     ::serialize_field(tilex, writer, checksum);
9140     ::serialize_field(tiley, writer, checksum);
9141     ::serialize_field(vertical, writer, checksum);
9142     ::serialize_field(flags, writer, checksum);
9143     ::serialize_field(lock, writer, checksum);
9144     ::serialize_field(type, writer, checksum);
9145     ::serialize_field(action, writer, checksum);
9146     ::serialize_field(ticcount, writer, checksum);
9147     ::serialize_field(areanumber, writer, checksum);
9148 }
9149 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9150 void doorobj_t::deserialize(
9151     bstone::BinaryReader& reader,
9152     bstone::Crc32& checksum)
9153 {
9154     ::deserialize_field(tilex, reader, checksum);
9155     ::deserialize_field(tiley, reader, checksum);
9156     ::deserialize_field(vertical, reader, checksum);
9157     ::deserialize_field(flags, reader, checksum);
9158     ::deserialize_field(lock, reader, checksum);
9159     ::deserialize_field(type, reader, checksum);
9160     ::deserialize_field(action, reader, checksum);
9161     ::deserialize_field(ticcount, reader, checksum);
9162     ::deserialize_field(areanumber, reader, checksum);
9163 }
9164 
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9165 void mCacheInfo::serialize(
9166     bstone::BinaryWriter& writer,
9167     bstone::Crc32& checksum) const
9168 {
9169     ::serialize_field(local_val, writer, checksum);
9170     ::serialize_field(global_val, writer, checksum);
9171 }
9172 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9173 void mCacheInfo::deserialize(
9174     bstone::BinaryReader& reader,
9175     bstone::Crc32& checksum)
9176 {
9177     ::deserialize_field(local_val, reader, checksum);
9178     ::deserialize_field(global_val, reader, checksum);
9179     mSeg = nullptr;
9180 }
9181 
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9182 void con_mCacheInfo::serialize(
9183     bstone::BinaryWriter& writer,
9184     bstone::Crc32& checksum) const
9185 {
9186     mInfo.serialize(writer, checksum);
9187     ::serialize_field(type, writer, checksum);
9188     ::serialize_field(operate_cnt, writer, checksum);
9189 }
9190 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9191 void con_mCacheInfo::deserialize(
9192     bstone::BinaryReader& reader,
9193     bstone::Crc32& checksum)
9194 {
9195     mInfo.deserialize(reader, checksum);
9196     ::deserialize_field(type, reader, checksum);
9197     ::deserialize_field(operate_cnt, reader, checksum);
9198 }
9199 
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9200 void concession_t::serialize(
9201     bstone::BinaryWriter& writer,
9202     bstone::Crc32& checksum) const
9203 {
9204     ::serialize_field(NumMsgs, writer, checksum);
9205 
9206     for (int i = 0; i < NumMsgs; ++i) {
9207         cmInfo[i].serialize(writer, checksum);
9208     }
9209 }
9210 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9211 void concession_t::deserialize(
9212     bstone::BinaryReader& reader,
9213     bstone::Crc32& checksum)
9214 {
9215     ::deserialize_field(NumMsgs, reader, checksum);
9216 
9217     for (int i = 0; i < NumMsgs; ++i) {
9218         cmInfo[i].deserialize(reader, checksum);
9219     }
9220 }
9221 
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9222 void eaWallInfo::serialize(
9223     bstone::BinaryWriter& writer,
9224     bstone::Crc32& checksum) const
9225 {
9226     ::serialize_field(tilex, writer, checksum);
9227     ::serialize_field(tiley, writer, checksum);
9228     ::serialize_field(aliens_out, writer, checksum);
9229     ::serialize_field(delay, writer, checksum);
9230 }
9231 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9232 void eaWallInfo::deserialize(
9233     bstone::BinaryReader& reader,
9234     bstone::Crc32& checksum)
9235 {
9236     ::deserialize_field(tilex, reader, checksum);
9237     ::deserialize_field(tiley, reader, checksum);
9238     ::deserialize_field(aliens_out, reader, checksum);
9239     ::deserialize_field(delay, reader, checksum);
9240 }
9241 
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9242 void GoldsternInfo_t::serialize(
9243     bstone::BinaryWriter& writer,
9244     bstone::Crc32& checksum) const
9245 {
9246     ::serialize_field(LastIndex, writer, checksum);
9247     ::serialize_field(SpawnCnt, writer, checksum);
9248     ::serialize_field(flags, writer, checksum);
9249     ::serialize_field(WaitTime, writer, checksum);
9250     ::serialize_field(GoldSpawned, writer, checksum);
9251 }
9252 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9253 void GoldsternInfo_t::deserialize(
9254     bstone::BinaryReader& reader,
9255     bstone::Crc32& checksum)
9256 {
9257     ::deserialize_field(LastIndex, reader, checksum);
9258     ::deserialize_field(SpawnCnt, reader, checksum);
9259     ::deserialize_field(flags, reader, checksum);
9260     ::deserialize_field(WaitTime, reader, checksum);
9261     ::deserialize_field(GoldSpawned, reader, checksum);
9262 }
9263 
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9264 void tilecoord_t::serialize(
9265     bstone::BinaryWriter& writer,
9266     bstone::Crc32& checksum) const
9267 {
9268     ::serialize_field(tilex, writer, checksum);
9269     ::serialize_field(tiley, writer, checksum);
9270 }
9271 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9272 void tilecoord_t::deserialize(
9273     bstone::BinaryReader& reader,
9274     bstone::Crc32& checksum)
9275 {
9276     ::deserialize_field(tilex, reader, checksum);
9277     ::deserialize_field(tiley, reader, checksum);
9278 }
9279 
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9280 void barrier_type::serialize(
9281     bstone::BinaryWriter& writer,
9282     bstone::Crc32& checksum) const
9283 {
9284     ::serialize_field(level, writer, checksum);
9285     coord.serialize(writer, checksum);
9286     ::serialize_field(on, writer, checksum);
9287 }
9288 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9289 void barrier_type::deserialize(
9290     bstone::BinaryReader& reader,
9291     bstone::Crc32& checksum)
9292 {
9293     ::deserialize_field(level, reader, checksum);
9294     coord.deserialize(reader, checksum);
9295     ::deserialize_field(on, reader, checksum);
9296 }
9297 
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9298 void statsInfoType::serialize(
9299     bstone::BinaryWriter& writer,
9300     bstone::Crc32& checksum) const
9301 {
9302     ::serialize_field(total_points, writer, checksum);
9303     ::serialize_field(accum_points, writer, checksum);
9304     ::serialize_field(total_enemy, writer, checksum);
9305     ::serialize_field(accum_enemy, writer, checksum);
9306     ::serialize_field(total_inf, writer, checksum);
9307     ::serialize_field(accum_inf, writer, checksum);
9308     ::serialize_field(overall_floor, writer, checksum);
9309 }
9310 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9311 void statsInfoType::deserialize(
9312     bstone::BinaryReader& reader,
9313     bstone::Crc32& checksum)
9314 {
9315     ::deserialize_field(total_points, reader, checksum);
9316     ::deserialize_field(accum_points, reader, checksum);
9317     ::deserialize_field(total_enemy, reader, checksum);
9318     ::deserialize_field(accum_enemy, reader, checksum);
9319     ::deserialize_field(total_inf, reader, checksum);
9320     ::deserialize_field(accum_inf, reader, checksum);
9321     ::deserialize_field(overall_floor, reader, checksum);
9322 }
9323 
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9324 void levelinfo::serialize(
9325     bstone::BinaryWriter& writer,
9326     bstone::Crc32& checksum) const
9327 {
9328     ::serialize_field(bonus_queue, writer, checksum);
9329     ::serialize_field(bonus_shown, writer, checksum);
9330     ::serialize_field(locked, writer, checksum);
9331     stats.serialize(writer, checksum);
9332     ::serialize_field(ptilex, writer, checksum);
9333     ::serialize_field(ptiley, writer, checksum);
9334     ::serialize_field(pangle, writer, checksum);
9335 }
9336 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9337 void levelinfo::deserialize(
9338     bstone::BinaryReader& reader,
9339     bstone::Crc32& checksum)
9340 {
9341     ::deserialize_field(bonus_queue, reader, checksum);
9342     ::deserialize_field(bonus_shown, reader, checksum);
9343     ::deserialize_field(locked, reader, checksum);
9344     stats.deserialize(reader, checksum);
9345     ::deserialize_field(ptilex, reader, checksum);
9346     ::deserialize_field(ptiley, reader, checksum);
9347     ::deserialize_field(pangle, reader, checksum);
9348 }
9349 
fargametype()9350 fargametype::fargametype() :
9351     old_levelinfo(),
9352     level()
9353 {
9354 }
9355 
initialize()9356 void fargametype::initialize()
9357 {
9358     old_levelinfo.resize(MAPS_PER_EPISODE);
9359     level.resize(MAPS_PER_EPISODE);
9360 }
9361 
clear()9362 void fargametype::clear()
9363 {
9364     old_levelinfo.clear();
9365     level.clear();
9366 
9367     initialize();
9368 }
9369 
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9370 void fargametype::serialize(
9371     bstone::BinaryWriter& writer,
9372     bstone::Crc32& checksum) const
9373 {
9374     for (int i = 0; i < MAPS_PER_EPISODE; ++i) {
9375         old_levelinfo[i].serialize(writer, checksum);
9376     }
9377 
9378     for (int i = 0; i < MAPS_PER_EPISODE; ++i) {
9379         level[i].serialize(writer, checksum);
9380     }
9381 }
9382 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9383 void fargametype::deserialize(
9384     bstone::BinaryReader& reader,
9385     bstone::Crc32& checksum)
9386 {
9387     for (int i = 0; i < MAPS_PER_EPISODE; ++i) {
9388         old_levelinfo[i].deserialize(reader, checksum);
9389     }
9390 
9391     for (int i = 0; i < MAPS_PER_EPISODE; ++i) {
9392         level[i].deserialize(reader, checksum);
9393     }
9394 }
9395 
serialize(bstone::BinaryWriter & writer,bstone::Crc32 & checksum) const9396 void gametype::serialize(
9397     bstone::BinaryWriter& writer,
9398     bstone::Crc32& checksum) const
9399 {
9400     ::serialize_field(turn_around, writer, checksum);
9401     ::serialize_field(turn_angle, writer, checksum);
9402     ::serialize_field(flags, writer, checksum);
9403     ::serialize_field(lastmapon, writer, checksum);
9404     ::serialize_field(difficulty, writer, checksum);
9405     ::serialize_field(mapon, writer, checksum);
9406     ::serialize_field(oldscore, writer, checksum);
9407     ::serialize_field(tic_score, writer, checksum);
9408     ::serialize_field(score, writer, checksum);
9409     ::serialize_field(nextextra, writer, checksum);
9410     ::serialize_field(score_roll_wait, writer, checksum);
9411     ::serialize_field(lives, writer, checksum);
9412     ::serialize_field(health, writer, checksum);
9413     ::serialize_field(health_str, writer, checksum);
9414     ::serialize_field(rpower, writer, checksum);
9415     ::serialize_field(old_rpower, writer, checksum);
9416     ::serialize_field(rzoom, writer, checksum);
9417     ::serialize_field(radar_leds, writer, checksum);
9418     ::serialize_field(lastradar_leds, writer, checksum);
9419     ::serialize_field(lastammo_leds, writer, checksum);
9420     ::serialize_field(ammo_leds, writer, checksum);
9421     ::serialize_field(ammo, writer, checksum);
9422     ::serialize_field(old_ammo, writer, checksum);
9423     ::serialize_field(plasma_detonators, writer, checksum);
9424     ::serialize_field(old_plasma_detonators, writer, checksum);
9425     ::serialize_field(useable_weapons, writer, checksum);
9426     ::serialize_field(weapons, writer, checksum);
9427     ::serialize_field(weapon, writer, checksum);
9428     ::serialize_field(chosenweapon, writer, checksum);
9429     ::serialize_field(old_weapons, writer, checksum);
9430     ::serialize_field(weapon_wait, writer, checksum);
9431     ::serialize_field(attackframe, writer, checksum);
9432     ::serialize_field(attackcount, writer, checksum);
9433     ::serialize_field(weaponframe, writer, checksum);
9434     ::serialize_field(episode, writer, checksum);
9435 
9436     auto time_count = TimeCount;
9437     ::serialize_field(time_count, writer, checksum);
9438 
9439     // Skip "msg"
9440     ::serialize_field(numkeys, writer, checksum);
9441     ::serialize_field(old_numkeys, writer, checksum);
9442 
9443     for (int i = 0; i < MAX_BARRIER_SWITCHES; ++i) {
9444         cross_barriers[i].serialize(writer, checksum);
9445     }
9446 
9447     for (int i = 0; i < MAX_BARRIER_SWITCHES; ++i) {
9448         barrier_table[i].serialize(writer, checksum);
9449     }
9450 
9451     for (int i = 0; i < MAX_BARRIER_SWITCHES; ++i) {
9452         old_barrier_table[i].serialize(writer, checksum);
9453     }
9454 
9455     ::serialize_field(tokens, writer, checksum);
9456     ::serialize_field(old_tokens, writer, checksum);
9457     ::serialize_field(boss_key_dropped, writer, checksum);
9458     ::serialize_field(old_boss_key_dropped, writer, checksum);
9459     ::serialize_field(wintilex, writer, checksum);
9460     ::serialize_field(wintiley, writer, checksum);
9461 }
9462 
deserialize(bstone::BinaryReader & reader,bstone::Crc32 & checksum)9463 void gametype::deserialize(
9464     bstone::BinaryReader& reader,
9465     bstone::Crc32& checksum)
9466 {
9467     ::deserialize_field(turn_around, reader, checksum);
9468     ::deserialize_field(turn_angle, reader, checksum);
9469     ::deserialize_field(flags, reader, checksum);
9470     ::deserialize_field(lastmapon, reader, checksum);
9471     ::deserialize_field(difficulty, reader, checksum);
9472     ::deserialize_field(mapon, reader, checksum);
9473     ::deserialize_field(oldscore, reader, checksum);
9474     ::deserialize_field(tic_score, reader, checksum);
9475     ::deserialize_field(score, reader, checksum);
9476     ::deserialize_field(nextextra, reader, checksum);
9477     ::deserialize_field(score_roll_wait, reader, checksum);
9478     ::deserialize_field(lives, reader, checksum);
9479     ::deserialize_field(health, reader, checksum);
9480     ::deserialize_field(health_str, reader, checksum);
9481     ::deserialize_field(rpower, reader, checksum);
9482     ::deserialize_field(old_rpower, reader, checksum);
9483     ::deserialize_field(rzoom, reader, checksum);
9484     ::deserialize_field(radar_leds, reader, checksum);
9485     ::deserialize_field(lastradar_leds, reader, checksum);
9486     ::deserialize_field(lastammo_leds, reader, checksum);
9487     ::deserialize_field(ammo_leds, reader, checksum);
9488     ::deserialize_field(ammo, reader, checksum);
9489     ::deserialize_field(old_ammo, reader, checksum);
9490     ::deserialize_field(plasma_detonators, reader, checksum);
9491     ::deserialize_field(old_plasma_detonators, reader, checksum);
9492     ::deserialize_field(useable_weapons, reader, checksum);
9493     ::deserialize_field(weapons, reader, checksum);
9494     ::deserialize_field(weapon, reader, checksum);
9495     ::deserialize_field(chosenweapon, reader, checksum);
9496     ::deserialize_field(old_weapons, reader, checksum);
9497     ::deserialize_field(weapon_wait, reader, checksum);
9498     ::deserialize_field(attackframe, reader, checksum);
9499     ::deserialize_field(attackcount, reader, checksum);
9500     ::deserialize_field(weaponframe, reader, checksum);
9501     ::deserialize_field(episode, reader, checksum);
9502 
9503     uint32_t time_count = 0;
9504     ::deserialize_field(time_count, reader, checksum);
9505 
9506     msg = nullptr;
9507     ::deserialize_field(numkeys, reader, checksum);
9508     ::deserialize_field(old_numkeys, reader, checksum);
9509 
9510     for (int i = 0; i < MAX_BARRIER_SWITCHES; ++i) {
9511         cross_barriers[i].deserialize(reader, checksum);
9512     }
9513 
9514     for (int i = 0; i < MAX_BARRIER_SWITCHES; ++i) {
9515         barrier_table[i].deserialize(reader, checksum);
9516     }
9517 
9518     for (int i = 0; i < MAX_BARRIER_SWITCHES; ++i) {
9519         old_barrier_table[i].deserialize(reader, checksum);
9520     }
9521 
9522     ::deserialize_field(tokens, reader, checksum);
9523     ::deserialize_field(old_tokens, reader, checksum);
9524     ::deserialize_field(boss_key_dropped, reader, checksum);
9525     ::deserialize_field(old_boss_key_dropped, reader, checksum);
9526     ::deserialize_field(wintilex, reader, checksum);
9527     ::deserialize_field(wintiley, reader, checksum);
9528 
9529     TimeCount = time_count;
9530 }
9531 
initialize_cross_barriers()9532 void gametype::initialize_cross_barriers()
9533 {
9534     for (int i = 0; i < MAX_BARRIER_SWITCHES; ++i) {
9535         cross_barriers[i].level = 0xFF;
9536         cross_barriers[i].coord.tilex = 0xFF;
9537         cross_barriers[i].coord.tiley = 0xFF;
9538         cross_barriers[i].on = 0xFF;
9539     }
9540 }
9541 
initialize_local_barriers()9542 void gametype::initialize_local_barriers()
9543 {
9544     for (int i = 0; i < MAX_BARRIER_SWITCHES; ++i) {
9545         barrier_table[i].level = 0xFF;
9546         barrier_table[i].coord.tilex = 0xFF;
9547         barrier_table[i].coord.tiley = 0xFF;
9548         barrier_table[i].on = 0xFF;
9549 
9550         old_barrier_table[i].level = 0xFF;
9551         old_barrier_table[i].coord.tilex = 0xFF;
9552         old_barrier_table[i].coord.tiley = 0xFF;
9553         old_barrier_table[i].on = 0xFF;
9554     }
9555 }
9556 
store_local_barriers()9557 void gametype::store_local_barriers()
9558 {
9559     for (int i = 0; i < MAX_BARRIER_SWITCHES; ++i) {
9560         old_barrier_table[i] = barrier_table[i];
9561     }
9562 }
9563 
restore_local_barriers()9564 void gametype::restore_local_barriers()
9565 {
9566     for (int i = 0; i < MAX_BARRIER_SWITCHES; ++i) {
9567         barrier_table[i] = old_barrier_table[i];
9568     }
9569 }
9570 
is_aog_full_v1_0()9571 bool is_aog_full_v1_0()
9572 {
9573     return ::g_game_type == GameType::aog_full_v1_0;
9574 }
9575 
is_aog_full_v2_x()9576 bool is_aog_full_v2_x()
9577 {
9578     return ::g_game_type == GameType::aog_full_v2_x;
9579 }
9580 
is_aog_full_v3_0()9581 bool is_aog_full_v3_0()
9582 {
9583     return ::g_game_type == GameType::aog_full_v3_0;
9584 }
9585 
is_aog_full()9586 bool is_aog_full()
9587 {
9588     return
9589         ::is_aog_full_v1_0() ||
9590         ::is_aog_full_v2_x() ||
9591         ::is_aog_full_v3_0();
9592 }
9593 
is_aog_sw()9594 bool is_aog_sw()
9595 {
9596     return ::g_game_type == GameType::aog_sw;
9597 }
9598 
is_aog()9599 bool is_aog()
9600 {
9601     return ::is_aog_sw() || ::is_aog_full();
9602 }
9603 
is_ps()9604 bool is_ps()
9605 {
9606     return ::g_game_type == GameType::ps;
9607 }
9608 
sys_sleep_for(int milliseconds)9609 void sys_sleep_for(
9610     int milliseconds)
9611 {
9612     std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
9613 }
9614 
sys_default_sleep_for()9615 void sys_default_sleep_for()
9616 {
9617     ::sys_sleep_for(10);
9618 }
9619 
get_version_string()9620 const std::string& get_version_string()
9621 {
9622     static const std::string version = "1.1.9";
9623     return version;
9624 }
9625 
get_profile_dir()9626 const std::string& get_profile_dir()
9627 {
9628     static std::string profile_dir;
9629     static auto is_initialized = false;
9630 
9631     if (!is_initialized) {
9632         is_initialized = true;
9633 
9634         profile_dir = ::g_args.get_option_value("profile_dir");
9635 
9636         if (!profile_dir.empty()) {
9637             profile_dir +=
9638 #ifdef _WIN32
9639                 '\\'
9640 #else
9641                 '/'
9642 #endif
9643             ;
9644         }
9645 
9646         if (profile_dir.empty()) {
9647             auto sdl_dir = ::SDL_GetPrefPath("bibendovsky", "bstone");
9648 
9649             if (sdl_dir) {
9650                 profile_dir = sdl_dir;
9651                 ::SDL_free(sdl_dir);
9652             }
9653         }
9654     }
9655 
9656     return profile_dir;
9657 }
9658 
get_default_data_dir()9659 const std::string& get_default_data_dir()
9660 {
9661     static std::string result;
9662     static auto is_initialized = false;
9663 
9664     if (!is_initialized) {
9665         is_initialized = true;
9666 
9667         auto sdl_dir = ::SDL_GetBasePath();
9668 
9669         if (sdl_dir) {
9670             result = sdl_dir;
9671             ::SDL_free(sdl_dir);
9672         }
9673     }
9674 
9675     return result;
9676 }
9677 // BBi
9678