1 /*
2 * Triplane Classic - a side-scrolling dogfighting game.
3 * Copyright (C) 1996,1997,2009 Dodekaedron Software Creations Oy
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * tjt@users.sourceforge.net
19 */
20
21 #define MAIN_VERSION 1
22 #define SUB_VERSION 3
23
24
25 //\\\\ Includes
26
27 #include "triplane.h"
28 #include "io/joystick.h"
29 #include "gfx/gfx.h"
30 #include "menus/tripmenu.h"
31 #include "world/terrain.h"
32 #include "world/fobjects.h"
33 #include "world/tmexept.h"
34 #include "world/plane.h"
35 #include "world/tripaudio.h"
36 #include <stdint.h>
37 #include <SDL.h>
38 #include <SDL_endian.h>
39 #include "util/wutil.h"
40 #include <time.h>
41 #include <string.h>
42 #include "io/trip_io.h"
43 #include "io/sdl_compat.h"
44 #include "settings.h"
45
46 //\\\\ Variables
47
48 //\ Picturedata
49
50 Bitmap *board;
51 Bitmap *board2;
52 Bitmap *pwon;
53 Bitmap *pwoff;
54 Bitmap *picons[4];
55 Bitmap *plane1;
56 Bitmap *planes[16][61][4][2];
57 Bitmap *bomb[61];
58 Bitmap *boards[4];
59 Bitmap *closed;
60 Bitmap *bomb_icon;
61 Bitmap *gas_icon;
62 Bitmap *small_ammo_icon;
63 Bitmap *big_ammo_icon;
64 Bitmap *plane_crash[6];
65 Bitmap *smoke[SMOKE_FRAMES];
66 Bitmap *wave1[WAVE1_FRAMES];
67 Bitmap *wave2[WAVE2_FRAMES];
68 Bitmap *explox[4][EXPLOX_FRAMES];
69 Bitmap *maisema;
70 Bitmap *bites[NUMBER_OF_BITES];
71 Bitmap *menu1;
72 Bitmap *structures[MAX_STRUCTURES][2];
73 Bitmap *temp_bitti;
74 Bitmap *cursor;
75 Bitmap *kkbase[2][3][7];
76 Bitmap *infantry_walking[4][2][12];
77 Bitmap *infantry_dying[4][2][7];
78 Bitmap *infantry_aiming[4][2][6];
79 Bitmap *infantry_wavedeath[4][2][10];
80 Bitmap *infantry_shooting[4][2][6];
81 Bitmap *infantry_bdying[4][2][10];
82 Bitmap *infantry_dropping[4][2];
83 Bitmap *infantry_after_drop[4][2];
84 Bitmap *itexplosion[ITEXPLOSION_FRAMES];
85 Bitmap *flames[6];
86 Bitmap *status_icons[2][2];
87 Bitmap *hangarmenu;
88 Bitmap *hangaractive, *hangarinactive;
89 Bitmap *radar[4][8];
90 Bitmap *rifle[12];
91 Bitmap *hruks;
92 Bitmap *ssmoke[17];
93 Bitmap *ovi[13];
94 Bitmap *mekan_running[14][2];
95 Bitmap *mekan_pushing[2][14][2];
96
97 int hangar_x[4];
98 int hangar_y[4];
99 int hangar_door_frame[4];
100 int mekan_x[4];
101 int mekan_y[4];
102 int mekan_frame[4];
103 int mekan_status[4];
104 int mekan_target[4];
105 int mekan_subtarget[4];
106 int mekan_direction[4];
107 int hangar_door_opening[4];
108 int hangar_door_closing[4];
109 int mekan_mission[4];
110 int plane_wants_in[16];
111 int plane_wants_out[16];
112
113 int player_exists[16] = { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
114 int plane_present[16] = { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
115 int player_sides[16] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 };
116 int player_tsides[16] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 };
117
118 int plane_coming[16];
119 extern int number_of_planes[16];
120 extern int miss_plane_direction[16];
121 extern int miss_pl_x[16];
122 extern int miss_pl_y[16];
123 extern int fighter[16];
124
125 unsigned char *level_bitmap;
126
127 int playing_solo;
128 int solo_country = 0;
129 int solo_mission;
130
131 int solo_failed;
132 int solo_success;
133 int solo_dest_remaining;
134
135 //\ struct_information:
136
137 int struct_state[MAX_STRUCTURES];
138 int struct_width[MAX_STRUCTURES];
139 int struct_heigth[MAX_STRUCTURES];
140
141 //\ Fonts
142
143 Font *fontti;
144 Font *frost;
145 Font *grid2;
146
147 //\ Parameter control
148
149 char parametrit[40][40];
150 int parametri_kpl;
151
152 //\ Shots control
153
154 int pohja = 0;
155 int play_shot[16];
156 int shots_flying_x[MAX_SHOTS];
157 int shots_flying_y[MAX_SHOTS];
158 int shots_flying_x_speed[MAX_SHOTS];
159 int shots_flying_y_speed[MAX_SHOTS];
160 int shots_flying_owner[MAX_SHOTS];
161 int shots_flying_age[MAX_SHOTS];
162 int shots_flying_infan[MAX_SHOTS];
163
164 //\ Player planes
165
166 int in_closing[16];
167 int player_shown_x[16];
168 int player_shown_y[16];
169 unsigned char *plane_p[16][61][4][2];
170 int hangarmenu_active[16];
171 int hangarmenu_position[16];
172 int hangarmenu_gas[16];
173 int hangarmenu_ammo[16];
174 int hangarmenu_bombs[16];
175
176 int hangarmenu_max_gas[16];
177 int hangarmenu_max_ammo[16];
178 int hangarmenu_max_bombs[16];
179
180
181 /* Timing */
182 short int viimeiset_framet = 0;
183 short int frame_laskuri = 0;
184 /* Timing*/
185
186
187 //\ Graphics locating
188
189 int x_muutos[4] = { 0, 160, 0, 160 };
190 int y_muutos[4] = { 0, 0, 100, 100 };
191 int x1_raja[4] = { 2, 162, 2, 162 };
192 int y1_raja[4] = { 2, 2, 102, 102 };
193 int x2_raja[4] = { 157, 317, 157, 317 };
194 int y2_raja[4] = { 89, 89, 187, 187 };
195
196 //\ Airfields
197
198
199 int player_on_airfield[16];
200
201 //\ General
202
203 int collision_detect = 1;
204 int part_collision_detect = 1;
205 int power_reverse = 0;
206 int power_on_off = 0;
207 int loading_texts = 0;
208 int solo_mode = -1;
209 int aftermath;
210 int level_loaded;
211
212 //\ Flying objects control
213
214 struct flying_objects_data fobjects[MAX_FLYING_OBJECTS];
215
216 //\ Scoring data
217
218 int player_fired[16];
219 int player_hits[16];
220 int player_shots_down[16][16];
221
222 int player_bombed[16];
223 int player_bomb_hits[16];
224
225 //\ Leveldata
226
227 char levelname[80];
228
229 struct level_struct leveldata;
230
231 //\ Bombs
232
233 int bomb_x[MAX_BOMBS];
234 int bomb_y[MAX_BOMBS];
235 int bomb_speed[MAX_BOMBS];
236 int bomb_angle[MAX_BOMBS];
237 int bomb_owner[MAX_BOMBS];
238 int bomb_x_speed[MAX_BOMBS];
239 int bomb_y_speed[MAX_BOMBS];
240
241 int roll_key_down[16];
242 int bomb_key_down[16];
243 int hangarkey_up_down[16];
244 int hangarkey_down_down[16];
245 int hangarkey_right_down[16];
246 int hangarkey_left_down[16];
247
248
249
250 int plane_tire_y;
251
252 int flags_state[MAX_FLAGS];
253 int flags_frame[MAX_FLAGS];
254 int flags_x[MAX_FLAGS];
255 int flags_y[MAX_FLAGS];
256 int flags_owner[MAX_FLAGS];
257 Bitmap *flags[4][12];
258
259 //\\ AA-MG && AA-Gun
260
261 int kkbase_x[MAX_AA_GUNS];
262 int kkbase_y[MAX_AA_GUNS];
263 int kkbase_last_shot[MAX_AA_GUNS];
264 int kkbase_shot_number[MAX_AA_GUNS];
265 int kkbase_frame[MAX_AA_GUNS];
266 int kkbase_status[MAX_AA_GUNS];
267 int kkbase_country[MAX_AA_GUNS];
268 int kkbase_type[MAX_AA_GUNS];
269 int kkbase_mission[MAX_AA_GUNS];
270 int kkbase_number[MAX_AA_GUNS];
271
272 //\\ Infantry
273
274 extern int infan_x[MAX_INFANTRY];
275 extern int infan_y[MAX_INFANTRY];
276 extern int infan_direction[MAX_INFANTRY];
277 extern int infan_last_shot[MAX_INFANTRY];
278 extern int infan_state[MAX_INFANTRY];
279 extern int infan_country[MAX_INFANTRY];
280 extern int infan_frame[MAX_INFANTRY];
281 extern int infan_x_speed[MAX_INFANTRY];
282 extern int infan_stop[8];
283
284 //\\ Computer players
285
286 int computer_active[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
287
288 int going_left;
289 int going_up;
290 int terrain_level[2400];
291 int wide_terrain_level[2400];
292 int current_mission[16];
293 int mission_phase[16];
294 int mission_target[16];
295
296 int distances[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
297 int angles[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
298
299 int bombs_going[100];
300
301 //\\ Configuration
302
303 short joystick_exists;
304
305 int modem_com_port = 2;
306 int modem_com_speed = 9600;
307
308 // Solo mode success/failure text blinking variables
309 int status_frames = 0;
310 int status_state = 0;
311
312 int mission_duration;
313 int mission_interrupted;
314 int mission_re_fly = -1;
315
316 FILE *record_file = NULL;
317 char *record_data = NULL;
318 int *record_random = NULL;
319 int record_counter = 0;
320
321 int main_engine_random_seed;
322
323
324 int quit_flag = 0;
325
326 int mc_up[16];
327 int mc_down[16];
328 int mc_bomb[16];
329 int mc_roll[16];
330 int mc_guns[16];
331 int mc_power[16];
332
333 int new_mc_up[16];
334 int new_mc_down[16];
335 int new_mc_bomb[16];
336 int new_mc_roll[16];
337 int new_mc_guns[16];
338 int new_mc_power[16];
339
340 int main_version;
341 int sub_version;
342
343 #include "gfx/extra.h"
344
345 //\\\\ Externs
346
347 extern int current_mode;
348
349 extern int dirty_area;
350 extern int isa_counter;
351 extern int dirty_x[100];
352 extern int dirty_y[100];
353 extern int dirty_yl[100];
354 extern int dirty_xl[100];
355 extern unsigned char *dirty_marker;
356
357 extern int itgun_shot_x[MAX_ITGUN_SHOTS];
358 extern int itgun_shot_y[MAX_ITGUN_SHOTS];
359
360 extern char mission_names[24][30];
361
362 //\\\\ Prototypes
363
364 void hangarmenu_handle(void);
365 int findparameter(const char *jono);
366 void controls(void);
367 void detect_collision(void);
368 void main_engine(void);
369 void load_up(void);
370 void clean_memory(void);
371 void init_data(void);
372 void do_aftermath(int show_it_all);
373 void airfield_checks(void);
374 void handle_parameters(void);
375 void load_level(void);
376 void clear_level(void);
377 void do_flags(void);
378 sb_sample *sample_load(const char *name);
379 void kkbase_sound(int type, int kkbase_x);
380 void itgun_sound(int itgun_x);
381 void rotate_water_palet(void);
382 void cause_damage(int amount, int plane);
383 int small_warning(const char *message);
384 int big_warning(const char *message);
385 void load_all_samples(void);
386 void init_sologame(void);
387 void write_files(void);
388
389 void load_sfx(void);
390 void load_music(void);
391 void clear_sfx(void);
392 void clear_music(void);
393 void init_sounds(void);
394 void uninit_sounds(void);
395
396
397 extern void do_infan(void);
398 extern void do_kkbase(void);
399 extern void start_it_shot(int x, int y, int angle);
400 extern void do_it_shots(void);
401 extern void init_mission(int country, int number);
402 extern void do_mekan(void);
403
404 extern void do_ai(int number);
405 extern void ai_turn_down(int number);
406 extern void ai_turn_up(int number);
407 extern void ai_evade_terrain(int number);
408 extern void ai_turnplus(int number);
409 extern void ai_turnminus(int number);
410
411 extern "C" {
412 extern void init_alkucallback(void);
413 }
414
415 #define NUMBER_OF_STRUCT_NAMES 35
416 #define DESCRIPTION_LENGHT
417
418 char struct_names[NUMBER_OF_STRUCT_NAMES * 2][7] = {
419 "TOWER", "DTOWER",
420 "FAC1", "DFAC1",
421 "FAC2", "DFAC2",
422 "BIRCH1", "DBIR1",
423 "BIRCH2", "DBIR2",
424 "BIRCH3", "DBIR3",
425 "TENT2", "DTENT2",
426 "OAK1", "DOAK1",
427 "OAK2", "DOAK2",
428 "OAK3", "DOAK3",
429 "PALM1", "DPALM1",
430 "PALM2", "DPALM2",
431 "PALM3", "DPALM3",
432 "HOU1", "DHOU1",
433 "HOU2", "DHOU2",
434 "HOU3", "DHOU3",
435 "HOU4", "DHOU4",
436 "HOU5", "DHOU5",
437 "WATERT", "DWAT",
438 "CHOU1", "DCHOU1",
439 "BARR2", "DBARR2",
440 "BARRA", "DBARRA",
441 "CBARR2", "DCBAR2",
442 "CBARRA", "DCBARR",
443 "CHOU5", "DCHOU5",
444 "WOAK1", "DOAK1",
445 "WOAK2", "DOAK2",
446 "WOAK3", "DOAK3",
447 "STORE1", "DSTORE",
448 "IGLU1", "DIGLU1",
449 "VEC1", "DVEC1",
450 "VEC2", "DVEC2",
451 "AUT1", "DBIR1",
452 "AUT2", "DBIR2",
453 "AUT3", "DBIR3"
454 };
455
456 //\\\\ Functions
457
record_random_swap_endianess(void)458 static void record_random_swap_endianess(void) {
459 int i;
460 for (i = 0; i < 24 * 1280; i++) {
461 record_random[i] = SDL_SwapLE32(record_random[i]);
462 }
463 }
464
465
hangarmenu_handle(void)466 void hangarmenu_handle(void) {
467
468 int l;
469
470 for (l = 0; l < 8; l++) {
471 if (!hangarmenu_active[l])
472 continue;
473
474
475
476
477 if (mc_guns[l]) {
478 if (!hangarkey_right_down[l]) {
479 hangarkey_right_down[l] = 1;
480 hangarmenu_position[l]++;
481 if (hangarmenu_position[l] > 2)
482 hangarmenu_position[l] = 2;
483 }
484 } else
485 hangarkey_right_down[l] = 0;
486
487 if (mc_bomb[l]) {
488 if (!hangarkey_left_down[l]) {
489 hangarkey_left_down[l] = 1;
490 hangarmenu_position[l]--;
491 if (hangarmenu_position[l] < 0)
492 hangarmenu_position[l] = 0;
493 }
494 } else
495 hangarkey_left_down[l] = 0;
496
497 if (mc_down[l]) {
498 if (!hangarkey_up_down[l]) {
499 hangarkey_up_down[l] = 1;
500
501 switch (hangarmenu_position[l]) {
502 case 0:
503 if (++hangarmenu_bombs[l] > hangarmenu_max_bombs[l])
504 hangarmenu_bombs[l] = hangarmenu_max_bombs[l];
505 break;
506
507 case 1:
508 hangarmenu_ammo[l] += 16;
509 if (hangarmenu_ammo[l] > hangarmenu_max_ammo[l])
510 hangarmenu_ammo[l] = hangarmenu_max_ammo[l];
511 break;
512
513 case 2:
514 hangarmenu_gas[l] += 256;
515 if (hangarmenu_gas[l] > hangarmenu_max_gas[l])
516 hangarmenu_gas[l] = hangarmenu_max_gas[l];
517 break;
518
519
520 }
521
522 }
523
524
525 } else
526 hangarkey_up_down[l] = 0;
527
528 if (mc_up[l]) {
529 if (!hangarkey_down_down[l]) {
530 hangarkey_down_down[l] = 1;
531
532 switch (hangarmenu_position[l]) {
533 case 0:
534 if (--hangarmenu_bombs[l] < 0)
535 hangarmenu_bombs[l] = 0;
536 break;
537
538 case 1:
539 if (!playing_solo && config.unlimited_ammo)
540 break;
541 hangarmenu_ammo[l] -= 16;
542 if (hangarmenu_ammo[l] < 0)
543 hangarmenu_ammo[l] = 0;
544 break;
545
546 case 2:
547 if (!playing_solo && config.unlimited_gas)
548 break;
549 hangarmenu_gas[l] -= 256;
550 if (hangarmenu_gas[l] < 2)
551 hangarmenu_gas[l] = 2;
552 break;
553
554
555 }
556
557 }
558
559
560 } else
561 hangarkey_down_down[l] = 0;
562
563 if (mc_roll[l] || mc_power[l]) {
564 plane_wants_out[l] = 1;
565
566 player_rolling[l] = 0;
567 player_spinning[l] = 0;
568 spinning_remaining[l] = 0;
569 player_last_shot[l] = 0;
570
571 hangarmenu_active[l] = 0;
572 }
573
574
575
576 if (leveldata.plane_direction[player_tsides[l]]) {
577 player_x[l] = (hangar_x[player_tsides[l]] + 38) << 8;
578 player_angle[l] = TAIL_HIT_ANGLE << 8;
579 player_upsidedown[l] = 0;
580 } else {
581 player_x[l] = (hangar_x[player_tsides[l]] + 38) << 8;
582 player_angle[l] = (180 + 6 - TAIL_HIT_ANGLE) << 8;
583 player_upsidedown[l] = 1;
584 }
585
586 player_y[l] = (leveldata.airfield_y[player_tsides[l]] - PLANE_MODIFICATION) << 8;
587 player_on_airfield[l] = player_tsides[l] + 1;
588 player_was_on_airfield[l] = player_tsides[l] + 1;
589 controls_power[l] = 0;
590 player_speed[l] = 0;
591
592 player_x_8[l] = player_x[l] >> 8;
593 player_y_8[l] = player_y[l] >> 8;
594 controls_up[l] = 0;
595 controls_down[l] = 0;
596
597 player_gas[l] = hangarmenu_gas[l];
598 player_ammo[l] = hangarmenu_ammo[l];
599 player_bombs[l] = hangarmenu_bombs[l];
600
601 player_endurance[l] = plane_mass[l] >> 3; //4
602
603 }
604 }
605
init_sologame(void)606 void init_sologame(void) {
607 init_mission(solo_country, solo_mission);
608 }
609
610
small_warning(const char * message)611 int small_warning(const char *message) {
612 Bitmap *warnkuva;
613 int flag = 1;
614 int x, y, n1, n2;
615 int response = 0;
616
617 warnkuva = new Bitmap("WARN2");
618
619 while (flag) {
620 koords(&x, &y, &n1, &n2);
621
622 tyhjaa_vircr();
623 warnkuva->blit(87, 59);
624 frost->printf(91, 77, message);
625 cursor->blit(x - 10, y - 10);
626
627 do_all();
628
629 if (n1 || n2) {
630 if (x >= 92 && x <= 131 && y >= 115 && y <= 134) {
631 flag = 0;
632 response = 1;
633
634 }
635
636 if (x >= 187 && x <= 226 && y >= 115 && y <= 134) {
637 flag = 0;
638 response = 0;
639
640 }
641
642
643 }
644 }
645
646 while (n1 || n2)
647 koords(&x, &y, &n1, &n2);
648
649 delete warnkuva;
650
651 return response;
652 }
653
big_warning(const char * message)654 int big_warning(const char *message) {
655 if (message == NULL)
656 return 0;
657 else
658 return 0;
659 }
660
cause_damage(int amount,int plane)661 void cause_damage(int amount, int plane) {
662
663 player_endurance[plane] -= amount;
664
665 if (player_endurance[plane] < 1) {
666 if (!player_spinning[plane] && !in_closing[plane]) {
667
668 if (wrandom(2) == 1 && (!player_on_airfield[plane]))
669 player_spinning[plane] = 1;
670 else {
671 in_closing[plane] = 2;
672 plane_present[plane] = 0;
673 start_parts(plane);
674 if (config.sound_on && config.sfx_on)
675 play_2d_sample(sample_crash[wrandom(2)], player_x_8[solo_country], player_x_8[plane]);
676 }
677 }
678 }
679
680
681 }
682
rotate_water_palet(void)683 void rotate_water_palet(void) {
684 int l, l2;
685 int seivi;
686 static int nytko = 0;
687
688 if (++nytko == 2) {
689 nytko = 0;
690 } else
691 for (l2 = 0; l2 < 3; l2++) {
692 seivi = ruutu.normaalipaletti[224][l2];
693 for (l = 0; l < 7; l++) {
694
695 ruutu.normaalipaletti[l + 224][l2] = ruutu.normaalipaletti[l + 225][l2];
696 }
697 ruutu.normaalipaletti[l + 224][l2] = seivi;
698
699 }
700
701 setpal_range(&ruutu.normaalipaletti[224], 224, 8, 1);
702 }
703
do_flags(void)704 void do_flags(void) {
705 int l;
706
707 for (l = 0; l < MAX_FLAGS; l++)
708 if (flags_x[l])
709 if ((++flags_state[l]) >= FLAGS_SPEED) {
710 flags_state[l] = 0;
711 flags_frame[l]++;
712 if (flags_frame[l] > 11)
713 flags_frame[l] = 0;
714 }
715 }
716
717
718
719
airfield_checks(void)720 void airfield_checks(void) {
721 int l, l2;
722 int yyy, xxx;
723
724 for (l = 0; l < 16; l++) {
725 if (!plane_present[l])
726 continue;
727
728 player_was_on_airfield[l] = 0;
729
730 if (!player_upsidedown[l]) {
731 yyy = 5;
732 xxx = 5;
733
734 } else {
735 yyy = -5;
736 xxx = 5;
737 }
738
739 plane_tire_y = ((player_y[l]) + (((-xxx * sinit[player_angle[l] >> 8] + yyy * cosinit[player_angle[l] >> 8] + 128) >> 8) << 8) + 256) >> 8;
740
741 player_on_airfield[l] = 0;
742 for (l2 = 0; l2 < 4; l2++)
743 if (leveldata.airfield_x[l2] && ((player_x_8[l]) >= leveldata.airfield_x[l2])
744 && ((player_x_8[l]) <= (leveldata.airfield_x[l2] + leveldata.airfield_lenght[l2])) && (plane_tire_y >= (leveldata.airfield_y[l2] - 1))) {
745
746
747 if (((player_angle[l] >> 8) <= TAIL_HIT_ANGLE) || ((player_angle[l] >> 8) >= (360 - HIT_ANGLE))) {
748 if (!player_upsidedown[l]) {
749 if ((plane_tire_y >= (leveldata.airfield_y[l2]))) {
750 player_on_airfield[l] = l2 + 1;
751 player_was_on_airfield[l] = l2 + 1;
752 } else
753 player_was_on_airfield[l] = l2 + 1;
754 }
755 }
756
757 if (((player_angle[l] >> 8) <= (180 + 6 + HIT_ANGLE)) && ((player_angle[l] >> 8) >= (180 + 6 - TAIL_HIT_ANGLE))) {
758 if (player_upsidedown[l]) {
759 if ((plane_tire_y >= (leveldata.airfield_y[l2]))) {
760 player_on_airfield[l] = l2 + 1;
761 player_was_on_airfield[l] = l2 + 1;
762 } else
763 player_was_on_airfield[l] = l2 + 1;
764 }
765 }
766 }
767
768 }
769 }
770
init_player(int l,int pommit)771 void init_player(int l, int pommit) {
772 if (!player_exists[l])
773 return;
774
775 if (playing_solo) {
776
777 if (in_closing[l]) {
778
779 number_of_planes[l]--;
780
781 if (number_of_planes[l] < 0) {
782 if (l != solo_country) {
783 in_closing[l] = 0;
784 plane_present[l] = 0;
785 player_exists[l] = 0;
786 return;
787
788 }
789
790 }
791 }
792
793
794 }
795
796 in_closing[l] = 0;
797 plane_coming[l] = 0;
798 plane_present[l] = 0;
799 plane_wants_in[l] = 0;
800 player_x_speed[l] = 0;
801 player_y_speed[l] = 0;
802
803
804
805 if ((!computer_active[l]) && !(playing_solo && miss_pl_x[l])) {
806 plane_coming[l] = 1;
807
808 hangarmenu_active[l] = 1;
809
810 } else {
811 if (playing_solo && miss_pl_x[l]) {
812 plane_coming[l] = 0;
813 plane_present[l] = 1;
814 if (miss_plane_direction[l]) {
815 player_x[l] = miss_pl_x[l] << 8;
816 player_angle[l] = 0;
817 player_upsidedown[l] = 0;
818 } else {
819 player_x[l] = miss_pl_x[l] << 8;
820 player_angle[l] = 180 << 8;
821 player_upsidedown[l] = 1;
822 }
823
824 player_y[l] = miss_pl_y[l] << 8;
825 player_on_airfield[l] = 0;
826 player_was_on_airfield[l] = 0;
827 controls_power[l] = 1;
828 player_speed[l] = 1500;
829
830 if (computer_active[l]) {
831 current_mission[l] = AIM_NOMISSION;
832 mission_phase[l] = 0;
833 mission_target[l] = 0;
834 }
835
836
837 } else {
838 plane_coming[l] = 1;
839 plane_wants_out[l] = 1;
840 if (leveldata.plane_direction[player_tsides[l]]) {
841 player_x[l] = (hangar_x[player_tsides[l]] + 38) << 8;
842 player_angle[l] = TAIL_HIT_ANGLE << 8;
843 player_upsidedown[l] = 0;
844 } else {
845 player_x[l] = (hangar_x[player_tsides[l]] + 38) << 8;
846 player_angle[l] = (180 + 6 - TAIL_HIT_ANGLE) << 8;
847 player_upsidedown[l] = 1;
848 }
849
850 player_y[l] = (leveldata.airfield_y[player_tsides[l]] - PLANE_MODIFICATION) << 8;
851 player_on_airfield[l] = player_tsides[l] + 1;
852 player_was_on_airfield[l] = player_tsides[l] + 1;
853 controls_power[l] = 0;
854 player_speed[l] = 0;
855
856 if (computer_active[l]) {
857 current_mission[l] = AIM_TAKEOFF;
858 mission_phase[l] = 0;
859 mission_target[l] = 0;
860 }
861 }
862
863
864 player_x_8[l] = player_x[l] >> 8;
865 player_y_8[l] = player_y[l] >> 8;
866 controls_up[l] = 0;
867 controls_down[l] = 0;
868
869 if (playing_solo) {
870 switch (fighter[l]) {
871 case 0:
872 player_ammo[l] = 0;
873 player_bombs[l] = plane_bombs[l];
874 break;
875
876 case 1:
877 player_ammo[l] = plane_ammo[l];
878 player_bombs[l] = (pommit ? plane_bombs[l] : 0);
879 break;
880 case 2:
881 player_ammo[l] = plane_ammo[l];
882 player_bombs[l] = 0;
883 break;
884
885 }
886
887 } else {
888 player_ammo[l] = plane_ammo[l];
889 player_bombs[l] = computer_active[l] ? ((wrandom(mission_duration + 1) < 1440) ? plane_bombs[l] : 0) : (pommit ? plane_bombs[l] : 0);
890 }
891
892
893 player_gas[l] = plane_gas[l];
894 player_rolling[l] = 0;
895 player_spinning[l] = 0;
896 spinning_remaining[l] = 0;
897 player_last_shot[l] = 0;
898 player_endurance[l] = plane_mass[l] >> 3; //4
899
900
901
902
903 }
904 }
905
findparameter(const char * jono)906 int findparameter(const char *jono) {
907 int laskuri;
908
909 for (laskuri = 1; laskuri < parametri_kpl; laskuri++)
910 if (!strncmp(parametrit[laskuri], jono, strlen(jono)))
911 return (laskuri);
912
913 return (0);
914 }
915
916
917
controls(void)918 void controls(void) {
919 int l;
920
921
922
923
924
925 for (l = 0; l < 16; l++) {
926 mc_up[l] = new_mc_up[l];
927 mc_down[l] = new_mc_down[l];
928 mc_roll[l] = new_mc_roll[l];
929 mc_power[l] = new_mc_power[l];
930 mc_bomb[l] = new_mc_bomb[l];
931 mc_guns[l] = new_mc_guns[l];
932
933
934
935
936
937 }
938
939 //// Recorder
940
941 unsigned char rbyte;
942 int rcount;
943
944 if (findparameter("-record")) {
945 for (rcount = 0; rcount < 16; rcount++) {
946
947 rbyte = 0;
948 rbyte += mc_up[rcount];
949 rbyte += mc_down[rcount] << 1;
950 rbyte += mc_roll[rcount] << 2;
951 rbyte += mc_power[rcount] << 3;
952 rbyte += mc_bomb[rcount] << 4;
953 rbyte += mc_guns[rcount] << 5;
954
955 record_data[record_counter++] = rbyte;
956
957 }
958
959
960 record_random[record_counter >> 4] = wrandom(2147483647);
961
962 }
963
964 if (findparameter("-playback")) {
965 for (rcount = 0; rcount < 16; rcount++) {
966 rbyte = record_data[record_counter++];
967
968 mc_up[rcount] = rbyte & 1;
969 mc_down[rcount] = rbyte & 2;
970 mc_roll[rcount] = rbyte & 4;
971 mc_power[rcount] = rbyte & 8;
972 mc_bomb[rcount] = rbyte & 16;
973 mc_guns[rcount] = rbyte & 32;
974
975
976
977 }
978
979 if (record_random[record_counter >> 4] != wrandom(2147483647)) {
980 printf("Random failure at %d\n", record_counter >> 4);
981 }
982
983
984
985 }
986 //// Recorder
987
988
989 if (!(playing_solo && hangarmenu_active[solo_country])) {
990 for (l = 0; l < 16; l++) {
991
992 if (!player_exists[l])
993 continue;
994
995 if (hangarmenu_active[l])
996 continue;
997
998 if (computer_active[l]) {
999 do_ai(l);
1000 continue;
1001 }
1002
1003 if (l > 7)
1004 continue;
1005
1006
1007 if (mc_down[l])
1008 controls_down[l] = 1;
1009 else
1010 controls_down[l] = 0;
1011
1012 if (mc_up[l])
1013 controls_up[l] = 1;
1014 else
1015 controls_up[l] = 0;
1016
1017 controls_power[l] = mc_power[l];
1018
1019
1020
1021 if (mc_bomb[l]) {
1022 if (!bomb_key_down[l]) {
1023 if (!player_on_airfield[l]) {
1024 if (player_bombs[l] && !in_closing[l]) {
1025
1026 player_bombs[l]--;
1027 drop_bomb(l);
1028 }
1029 } else if (player_speed[l] == 0 && (player_on_airfield[l] - 1) == l && !in_closing[l] && !player_spinning[l]) {
1030 if (!plane_wants_out[l])
1031 plane_wants_in[l] = 1;
1032 }
1033
1034 bomb_key_down[l] = 1;
1035 }
1036
1037 } else
1038 bomb_key_down[l] = 0;
1039
1040
1041
1042 if (mc_roll[l]) {
1043 if (!roll_key_down[l]) {
1044
1045
1046 roll_key_down[l] = 1;
1047 if (!player_on_airfield[l]) {
1048
1049 if (!player_rolling[l])
1050 player_rolling[l] = 1;
1051
1052
1053 } else {
1054 if (!player_speed[l] && !in_closing[l] && !player_spinning[l] && (player_on_airfield[l] - 1) == l) {
1055 if (!plane_wants_out[l])
1056 plane_wants_in[l] = 1;
1057 }
1058
1059 }
1060 }
1061
1062 } else
1063 roll_key_down[l] = 0;
1064
1065
1066
1067
1068 if (mc_guns[l] && (player_last_shot[l] > SHOTS_RATE) && player_ammo[l]) {
1069
1070 start_shot(l);
1071 }
1072
1073
1074 } // control
1075
1076 for (l = 0; l < 16; l++)
1077 if (player_rolling[l])
1078 player_rolling[l]++;
1079
1080
1081 for (l = 0; l < 16; l++)
1082 if (player_rolling[l] == 4) {
1083 player_rolling[l] = 0;
1084 if (player_upsidedown[l])
1085 player_upsidedown[l] = 0;
1086 else
1087 player_upsidedown[l] = 1;
1088
1089 }
1090 }
1091
1092 for (l = 0; l < 16; l++) {
1093 if (!player_exists[l])
1094 continue;
1095
1096 if (l > 3)
1097 continue;
1098
1099
1100 if (!playing_solo && config.joystick[0] == l) {
1101 get_joystick_action(0, (hangarmenu_active[l] || in_closing[l]),
1102 &new_mc_down[l], &new_mc_up[l], &new_mc_power[l], &new_mc_roll[l], &new_mc_guns[l], &new_mc_bomb[l]);
1103 if (!joystick_has_roll_button(0) && !(hangarmenu_active[l] || in_closing[l])) {
1104 // Autoroll code
1105 new_mc_roll[l] = 0;
1106 if (new_mc_down[l] == new_mc_up[l]) /* not turning up/down */
1107 if ((player_upsidedown[l] && (player_angle[l] < 23040 || player_angle[l] > 69120)) ||
1108 (!player_upsidedown[l] && (player_angle[l] < 69120 && player_angle[l] > 23040)))
1109 if (!player_rolling[l])
1110 new_mc_roll[l] = 1;
1111 }
1112 } else {
1113 if (!playing_solo && config.joystick[1] == l) {
1114 get_joystick_action(1, (hangarmenu_active[l] || in_closing[l]),
1115 &new_mc_down[l], &new_mc_up[l], &new_mc_power[l], &new_mc_roll[l], &new_mc_guns[l], &new_mc_bomb[l]);
1116 if (!joystick_has_roll_button(1) && !(hangarmenu_active[l] || in_closing[l])) {
1117 // Autoroll code
1118 new_mc_roll[l] = 0;
1119 if (new_mc_down[l] == new_mc_up[l]) /* not turning up/down */
1120 if ((player_upsidedown[l] && (player_angle[l] < 23040 || player_angle[l] > 69120)) ||
1121 (!player_upsidedown[l] && (player_angle[l] < 69120 && player_angle[l] > 23040)))
1122 if (!player_rolling[l])
1123 new_mc_roll[l] = 1;
1124 }
1125 } else {
1126 if ((playing_solo ? key[roster[config.player_number[solo_country]].down] : key[player_keys[l].down]))
1127 new_mc_down[l] = 1;
1128 else
1129 new_mc_down[l] = 0;
1130
1131 if ((playing_solo ? key[roster[config.player_number[solo_country]].up] : key[player_keys[l].up]))
1132 new_mc_up[l] = 1;
1133 else
1134 new_mc_up[l] = 0;
1135
1136 if (!power_on_off) {
1137 if (!power_reverse) {
1138 if ((playing_solo ? key[roster[config.player_number[solo_country]].power] : key[player_keys[l].power]))
1139 new_mc_power[l] = 1;
1140 else
1141 new_mc_power[l] = 0;
1142 } else {
1143 if ((playing_solo ? key[roster[config.player_number[solo_country]].power] : key[player_keys[l].power]))
1144 new_mc_power[l] = 0;
1145 else
1146 new_mc_power[l] = 1;
1147 }
1148 } else {
1149 if ((playing_solo ? key[roster[config.player_number[solo_country]].power] : key[player_keys[l].power])) {
1150 if (!controls_power2[l]) {
1151 if (new_mc_power[l])
1152 new_mc_power[l] = 0;
1153 else
1154 new_mc_power[l] = 1;
1155 }
1156 controls_power2[l] = 1;
1157
1158 } else
1159 controls_power2[l] = 0;
1160
1161 if (in_closing[l])
1162 new_mc_power[l] = 0;
1163
1164 }
1165
1166 new_mc_bomb[l] = 0;
1167
1168 if ((playing_solo ? key[roster[config.player_number[solo_country]].bombs] : key[player_keys[l].bombs])) {
1169 new_mc_bomb[l] = 1;
1170
1171 }
1172
1173 new_mc_roll[l] = 0;
1174 if ((playing_solo ? key[roster[config.player_number[solo_country]].roll] : key[player_keys[l].roll])) {
1175
1176 new_mc_roll[l] = 1;
1177
1178
1179 }
1180
1181
1182 new_mc_guns[l] = 0;
1183
1184 if ((playing_solo ? key[roster[config.player_number[solo_country]].guns] : key[player_keys[l].guns])) {
1185 new_mc_guns[l] = 1;
1186
1187 }
1188 }
1189 }
1190
1191
1192
1193 if (player_spinning[l]) {
1194 if (!player_rolling[l])
1195 player_rolling[l] = 1;
1196 }
1197
1198 if (spinning_remaining[l]) {
1199 spinning_remaining[l]--;
1200
1201 if (!player_rolling[l])
1202 player_rolling[l] = 1;
1203
1204 }
1205
1206 }
1207 }
1208
1209
1210
1211
detect_collision(void)1212 void detect_collision(void) {
1213 int xl, yl, xa, ya, sx, sy;
1214 int l, l2;
1215 int laskx, lasky;
1216 int px[16], py[16];
1217 int temp;
1218 int nx, ny;
1219 int yyy, xxx;
1220
1221 for (l = 0; l < 16; l++) {
1222 if (!plane_present[l])
1223 continue;
1224
1225 px[l] = (player_x_8[l]) - 10;
1226 py[l] = (player_y_8[l]) - 10;
1227
1228 }
1229
1230
1231 for (l = 0; l < 16; l++) {
1232 if (!plane_present[l])
1233 continue;
1234
1235 temp = (player_angle[l] >> 8) / 6;
1236 for (l2 = 0; l2 < 16; l2++) {
1237 if (l2 == l)
1238 continue;
1239
1240 if (!plane_present[l2])
1241 continue;
1242
1243
1244 if ((px[l] + 19) >= px[l2] && px[l] <= (px[l2] + 19) && (py[l] + 19) >= py[l2] && py[l] <= (py[l2] + 19)) {
1245 sx = px[l2] - px[l];
1246 sy = py[l2] - py[l];
1247
1248 xa = sx;
1249 if (xa < 0) {
1250 xl = 19 + xa;
1251 xa = 0;
1252
1253 } else {
1254 xl = 19;
1255 }
1256
1257 ya = sy;
1258 if (ya < 0) {
1259 yl = 19 + ya;
1260 ya = 0;
1261 } else {
1262 yl = 19;
1263 }
1264
1265 for (lasky = ya; lasky <= yl; lasky++)
1266 for (laskx = xa; laskx <= xl; laskx++) {
1267 if (plane_p[l][temp][player_rolling[l]][player_upsidedown[l]][lasky * 20 + laskx] != 255)
1268 if (plane_p[l2][(player_angle[l2] >> 8) / 6][player_rolling[l2]][player_upsidedown[l2]][(lasky - sy) * 20 + (laskx - sx)] != 255) {
1269 if (collision_detect) {
1270 if (!in_closing[l]) {
1271
1272 in_closing[l] = 2;
1273 plane_present[l] = 0;
1274 start_parts(l);
1275 player_shots_down[l][l]++;
1276 player_points[l]--;
1277 if (config.sound_on && config.sfx_on)
1278 play_2d_sample(sample_crash[wrandom(2)], player_x_8[solo_country], player_x_8[l]);
1279 }
1280 if (!in_closing[l2]) {
1281 in_closing[l2] = 2;
1282 plane_present[l2] = 0;
1283 start_parts(l2);
1284 player_shots_down[l2][l2]++;
1285 player_points[l2]--;
1286 if (config.sound_on && config.sfx_on)
1287 play_2d_sample(sample_crash[wrandom(2)], player_x_8[solo_country], player_x_8[l]);
1288
1289 }
1290 }
1291 }
1292 }
1293
1294 }
1295
1296
1297 }
1298 nx = (player_x[l] + 12 * cosinit[player_angle[l] >> 8]) >> 8;
1299 ny = (player_y[l] - 12 * sinit[player_angle[l] >> 8]) >> 8;
1300
1301 if (nx < 0 || nx >= 2400 || ny >= 200) {
1302 nx = 0;
1303 ny = 199;
1304 }
1305
1306 if (ny < 0)
1307 ny = 0;
1308
1309 if (((level_bitmap[nx + ny * 2400]) < 112 || ((level_bitmap[nx + ny * 2400])) > 119) && !in_closing[l] && !player_on_airfield[l]) {
1310 if (!player_spinning[l]) {
1311 player_shots_down[l][l]++;
1312 player_points[l]--;
1313 }
1314
1315 in_closing[l] = 2;
1316 plane_present[l] = 0;
1317 start_parts(l);
1318
1319 if (config.sound_on && config.sfx_on) {
1320 if (level_bitmap[nx + ny * 2400] < 231 && level_bitmap[nx + ny * 2400] > 224)
1321 play_2d_sample(sample_spcrash, player_x_8[solo_country], player_x_8[l]);
1322 else
1323 play_2d_sample(sample_crash[wrandom(2)], player_x_8[solo_country], player_x_8[l]);
1324 }
1325
1326 continue;
1327 }
1328
1329
1330 if (!player_upsidedown[l]) {
1331 yyy = 5;
1332 xxx = 5;
1333
1334 } else {
1335 yyy = -5;
1336 xxx = 5;
1337 }
1338
1339 nx = (player_x[l] >> 8) + ((+xxx * cosinit[player_angle[l] >> 8] + yyy * sinit[player_angle[l] >> 8] + 128) >> 8);
1340 ny = (player_y[l] >> 8) + ((-xxx * sinit[player_angle[l] >> 8] + yyy * cosinit[player_angle[l] >> 8] + 128) >> 8);
1341
1342 if (nx < 0 || nx >= 2400 || ny >= 200) {
1343 nx = 0;
1344 ny = 199;
1345 }
1346
1347 if (ny < 0)
1348 ny = 0;
1349
1350 if (((level_bitmap[nx + ny * 2400]) < 112 || ((level_bitmap[nx + ny * 2400])) > 119) && !in_closing[l] && !player_on_airfield[l]) {
1351 if (!player_spinning[l]) {
1352 player_shots_down[l][l]++;
1353 player_points[l]--;
1354 }
1355
1356 in_closing[l] = 2;
1357 plane_present[l] = 0;
1358 start_parts(l);
1359
1360 if (config.sound_on && config.sfx_on) {
1361 if (level_bitmap[nx + ny * 2400] < 231 && level_bitmap[nx + ny * 2400] > 224)
1362 play_2d_sample(sample_spcrash, player_x_8[solo_country], player_x_8[l]);
1363 else
1364 play_2d_sample(sample_crash[wrandom(2)], player_x_8[solo_country], player_x_8[l]);
1365 }
1366 continue;
1367 }
1368 }
1369 }
1370
solo_do_all(void)1371 static void solo_do_all(void) {
1372 int x_offset = 160;
1373
1374 // Compute player's plane location on screen and corresponding
1375 // offset of the background bitmap
1376
1377 if (((player_x_8[solo_country]) - x_offset + 320) > NUMBER_OF_SCENES * 160)
1378 x_offset -= NUMBER_OF_SCENES * 160 - ((player_x_8[solo_country]) - x_offset + 320);
1379
1380 if (((player_x_8[solo_country]) - x_offset) < 0)
1381 x_offset += player_x_8[solo_country] - x_offset;
1382
1383 x_offset -= player_x_8[solo_country];
1384 x_offset = -x_offset;
1385
1386 // draw double bufffer to screen
1387 do_all();
1388
1389 // initialize double buffer back to background image
1390 // background image 2400x200 (2400 == NUMBER_OF_SCENES*160)
1391 // surface 320x200
1392 maisema->blit(-x_offset, 0);
1393 }
1394
1395 /*
1396 * The following function has been adapted from
1397 * linux-2.6.18/storage/multipath-tools/kpartx/crc32.c with the
1398 * following disclamer:
1399 *
1400 * This code is in the public domain; copyright abandoned.
1401 * Liability for non-performance of this code is limited to the amount
1402 * you paid for it. Since it is distributed for free, your refund will
1403 * be very very small. If it breaks, you get to keep both pieces.
1404 */
1405 #define CRCPOLY_LE 0xedb88320
crc32_le(uint32_t crc,unsigned char const * p,size_t len)1406 static uint32_t crc32_le(uint32_t crc, unsigned char const *p, size_t len) {
1407 int i;
1408
1409 while (len--) {
1410 crc ^= *p++;
1411 for (i = 0; i < 8; i++)
1412 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
1413 }
1414 return crc;
1415 }
1416
do_debug_trace(void)1417 void do_debug_trace(void) {
1418 static int first_call = 1;
1419 static int enabled = 0;
1420
1421 if (first_call) {
1422 if (findparameter("-debugtrace")) {
1423 enabled = 1;
1424 }
1425 first_call = 0;
1426 }
1427
1428 if (enabled) {
1429 int len;
1430 uint32_t vircr_checksum;
1431
1432 if (current_mode == VGA_MODE) {
1433 len = 320 * 200;
1434 } else {
1435 len = 800 * 600;
1436 }
1437
1438 vircr_checksum = crc32_le(~0, vircr, len);
1439
1440 printf("%d %08x\n", frame_laskuri, vircr_checksum);
1441
1442 }
1443 }
1444
main_engine(void)1445 void main_engine(void) {
1446 int preview_mode = 0;
1447 int l, l2, flag = 1;
1448 int xx, yy;
1449
1450 quit_flag = 0;
1451
1452 if (playing_solo) {
1453 collision_detect = 0;
1454 part_collision_detect = 1;
1455 } else {
1456 collision_detect = config.nocollision;
1457 part_collision_detect = config.partcollision;
1458 }
1459
1460 power_on_off = config.poweronoff;
1461 power_reverse = config.powerrev;
1462
1463 for (l = 0; l < 16; l++) {
1464 player_sides[l] = player_tsides[l];
1465
1466 }
1467
1468 if (playing_solo) {
1469
1470 if (!(preview_mode = solo_player_menu())) {
1471 aftermath = 0;
1472 return;
1473 }
1474
1475 if (preview_mode == 2)
1476 preview_mode = 0;
1477
1478 }
1479 aftermath = 1;
1480
1481 setwrandom(7);
1482
1483 load_level();
1484 level_loaded = 1;
1485
1486 if (playing_solo) {
1487 init_sologame();
1488
1489 }
1490
1491
1492
1493 init_data();
1494
1495
1496
1497 for (l = 0; l < 16; l++) {
1498 in_closing[l] = 1;
1499 init_player(l);
1500 player_points[l] = 0;
1501 }
1502
1503 for (l = 0; l < MAX_STRUCTURES; l++) {
1504 if (!leveldata.struct_hit[l])
1505 continue;
1506
1507 if (structures[l][0] == NULL)
1508 continue;
1509
1510 structures[l][0]->blit_to_bitmap(maisema, leveldata.struct_x[l], leveldata.struct_y[l]);
1511
1512 }
1513
1514 if (config.flags)
1515 do_flags();
1516 do_kkbase();
1517
1518 if (preview_mode) {
1519 if (!kangas_menu()) {
1520 aftermath = 0;
1521 return;
1522
1523 }
1524 }
1525
1526 if (playing_solo) {
1527 solo_failed = 0;
1528 solo_success = 0;
1529 solo_dest_remaining = 0;
1530
1531 for (l = 0; l < MAX_STRUCTURES; l++) {
1532 if (!leveldata.struct_x[l])
1533 continue;
1534
1535 if (leveldata.struct_type[l] == 1)
1536 solo_dest_remaining++;
1537
1538 }
1539
1540 }
1541
1542 if (current_mode == SVGA_MODE) {
1543
1544 tyhjaa_vircr();
1545 maisema->blit(-1600, 388, 0, 0, 799, 599);
1546 maisema->blit(-800, 192, 0, 0, 799, 599);
1547 maisema->blit(0, -4, 0, 0, 799, 599);
1548
1549 for (l = 0; l < MAX_STRUCTURES; l++) {
1550 if (structures[l][0] != NULL) {
1551 if (leveldata.struct_hit[l])
1552 continue;
1553
1554 structures[l][0]->blit(leveldata.struct_x[l] - (leveldata.struct_x[l] / 800) * 800,
1555 leveldata.struct_y[l] + (leveldata.struct_x[l] / 800) * 196 - 4);
1556
1557 structures[l][0]->info(&xx, &yy);
1558
1559 if ((leveldata.struct_x[l] - (leveldata.struct_x[l] / 800) * 800) + xx > 800)
1560 structures[l][0]->blit(leveldata.struct_x[l] - (leveldata.struct_x[l] / 800) * 800 - 800,
1561 leveldata.struct_y[l] + (leveldata.struct_x[l] / 800 + 1) * 196 - 4);
1562
1563 }
1564
1565 }
1566
1567 standard_background = new Bitmap(0, 0, 800, 600);
1568 standard_background->blit(0, 0, 0, 0, 799, 599);
1569
1570
1571 } else {
1572 board->blit(0, 0);
1573 }
1574
1575 for (l = 0; l < 2400; l++) {
1576 terrain_level[l] = 0;
1577
1578 for (l2 = 0; l2 < 200; l2++)
1579 if (level_bitmap[l + l2 * 2400] < 112 || level_bitmap[l + l2 * 2400] > 119) {
1580 terrain_level[l] = l2 - 1;
1581 if (terrain_level[l] < 0)
1582 terrain_level[l] = 0;
1583 break;
1584 }
1585
1586
1587 }
1588
1589 for (l = 0; l < 2400; l++) {
1590 wide_terrain_level[l] = 200;
1591
1592 for (l2 = 0; l2 < 25; l2++) {
1593 if (l + l2 >= 2400)
1594 break;
1595
1596 if (terrain_level[l + l2] < wide_terrain_level[l])
1597 wide_terrain_level[l] = terrain_level[l + l2];
1598
1599 }
1600
1601 for (l2 = 0; l2 < 25; l2++) {
1602 if (l - l2 < 0)
1603 break;
1604
1605 if (terrain_level[l - l2] < wide_terrain_level[l])
1606 wide_terrain_level[l] = terrain_level[l - l2];
1607
1608 }
1609
1610
1611 }
1612
1613
1614 for (l = 0; l < 100; l++) {
1615 if (!infan_x[l])
1616 continue;
1617
1618 infan_y[l] = terrain_level[infan_x[l]] - 13;
1619
1620 }
1621
1622 if (findparameter("-pixelhunt"))
1623 setpal_range(NULL, 112, 8);
1624
1625 mission_duration = 0;
1626 mission_interrupted = 0;
1627
1628 if (playing_solo) {
1629 init_exeptions(solo_country, solo_mission);
1630 tyhjaa_vircr();
1631 }
1632 //// Open joysticks
1633 if (!playing_solo) {
1634 open_close_joysticks(config.joystick[0] != -1, config.joystick[1] != -1);
1635 }
1636 //// Record
1637
1638
1639 if (findparameter("-record") || findparameter("-playback")) {
1640 record_data = (char *) walloc(16 * 24 * 1280);
1641 record_random = (int *) walloc(4 * 24 * 1280);
1642 }
1643
1644 if (findparameter("-playback")) {
1645 record_file = settings_open("record.dta", "rb");
1646 fread(record_data, 24 * 1280, 16, record_file);
1647 fclose(record_file);
1648
1649 record_file = settings_open("record.000", "rb");
1650 fread(record_random, 24 * 1280, 4, record_file);
1651 record_random_swap_endianess();
1652 fclose(record_file);
1653
1654 }
1655 //// Record
1656 setwrandom(7);
1657
1658 if (!draw_with_vircr_mode)
1659 update_vircr_mode = 0;
1660
1661 while (flag) {
1662 update_key_state();
1663
1664 if (key[SDLK_PAUSE]) {
1665 // wait until pause key is released, then pressed and released again
1666 while (key[SDLK_PAUSE]) { // still pressed
1667 nopeuskontrolli();
1668 update_key_state();
1669 }
1670 while (!key[SDLK_PAUSE]) { // released
1671 nopeuskontrolli();
1672 update_key_state();
1673 }
1674 while (key[SDLK_PAUSE]) { // pressed again
1675 nopeuskontrolli();
1676 update_key_state();
1677 }
1678 }
1679 // use F4 as an alias for the Pause key
1680 // because Pause does not always work reliably
1681 // (and is not present on all keyboards)
1682 if (key[SDLK_F4]) {
1683 // wait until F4 is released, then pressed and released again
1684 while (key[SDLK_F4]) { // still pressed
1685 nopeuskontrolli();
1686 update_key_state();
1687 }
1688 while (!key[SDLK_F4]) { // released
1689 nopeuskontrolli();
1690 update_key_state();
1691 }
1692 while (key[SDLK_F4]) { // pressed again
1693 nopeuskontrolli();
1694 update_key_state();
1695 }
1696 }
1697
1698 if (key[SDLK_ESCAPE]) {
1699 flag = 0;
1700 mission_interrupted = 1;
1701 }
1702
1703 if (quit_flag) {
1704 quit_flag = 0;
1705 flag = 0;
1706 mission_interrupted = 1;
1707
1708 }
1709
1710 if (playing_solo && hangarmenu_active[solo_country]) {
1711
1712 } else {
1713 do_shots();
1714 do_shots();
1715
1716 do_it_shots();
1717
1718 airfield_checks();
1719
1720 for (l = 0; l < 16; l++) {
1721 if (!computer_active[l]) {
1722 if (plane_wants_in[l]) {
1723 if (mekan_target[player_tsides[l]] == l)
1724 if (mekan_subtarget[player_tsides[l]] == 2) {
1725 controls_power[l] = 0;
1726 controls_up[l] = 0;
1727 controls_down[l] = 0;
1728
1729
1730 }
1731
1732 }
1733
1734 if (plane_wants_out[l]) {
1735 if (mekan_target[player_tsides[l]] == l) {
1736 if (mekan_subtarget[player_tsides[l]] == 0) {
1737 controls_power[l] = 0;
1738
1739 }
1740
1741 } else {
1742 controls_power[l] = 0;
1743
1744
1745 }
1746
1747
1748 }
1749 } else {
1750 if (plane_wants_out[l] || plane_wants_in[l]) {
1751 controls_power[l] = 0;
1752
1753 }
1754
1755 }
1756
1757 }
1758
1759 model_planes();
1760 do_bombs();
1761 do_bombs();
1762 detect_collision();
1763
1764 detect_damage();
1765
1766 if (config.flames)
1767 do_flames();
1768 do_fobjects();
1769
1770 if (config.flags)
1771 do_flags();
1772 do_infan();
1773 do_kkbase();
1774 do_mekan();
1775 }
1776
1777 if (solo_mode == -1)
1778 terrain_to_screen();
1779 else {
1780 solo_do_all();
1781 solo_terrain_to_screen();
1782 }
1783
1784 hangarmenu_handle();
1785
1786 if (playing_solo && hangarmenu_active[solo_country]) {
1787
1788 } else {
1789 for (l = 0; l < 16; l++) {
1790 if (!player_exists[l])
1791 continue;
1792
1793 player_last_shot[l]++;
1794 if (!playing_solo && config.stop)
1795 if (player_points[l] >= config.stop)
1796 flag = 0;
1797
1798 if (in_closing[l])
1799 plane_present[l] = 0;
1800 }
1801
1802 if (playing_solo)
1803 game_exeptions(solo_country, solo_mission);
1804 }
1805
1806 if (playing_solo) {
1807 for (l = 0; l < 12; l++) {
1808 if (player_exists[l] && player_sides[l] == 1)
1809 break;
1810 }
1811
1812 if (l == 12) {
1813 if (!solo_dest_remaining)
1814 solo_success = 1;
1815 }
1816
1817 if (key[SDLK_F1] && key[SDLK_F2] && key[SDLK_F3]) {
1818 frost->printf(40, 40, "SoloDestRemaining: %d. l=%d\n", solo_dest_remaining, l);
1819
1820 }
1821
1822 if (number_of_planes[solo_country] < 0)
1823 solo_failed = 1;
1824
1825
1826 endgame_exeptions(solo_country, solo_mission);
1827
1828
1829 if ((solo_success || solo_failed) && player_on_airfield[solo_country] && !player_speed[solo_country])
1830 flag = 0;
1831
1832 if (miss_pl_x[solo_country] && solo_failed)
1833 flag = 0;
1834
1835
1836 }
1837
1838
1839 do_debug_trace();
1840
1841 if (current_mode == SVGA_MODE) {
1842 do_all_clear(0); ///
1843
1844 }
1845
1846
1847 rotate_water_palet();
1848
1849 if (current_mode == VGA_MODE) {
1850 if (solo_mode == -1)
1851 do_all(1);
1852 }
1853
1854
1855 if (playing_solo && hangarmenu_active[solo_country]) {
1856 controls();
1857 nopeuskontrolli();
1858 } else {
1859 controls();
1860 nopeuskontrolli();
1861 frame_laskuri++;
1862 mission_duration++;
1863 }
1864 }
1865
1866 if (!draw_with_vircr_mode)
1867 update_vircr_mode = 1;
1868
1869 wait_relase();
1870 mission_re_fly = -1;
1871
1872 //// Close joysticks
1873 open_close_joysticks(0, 0);
1874
1875 //// Record
1876
1877 if (findparameter("-record")) {
1878 record_file = settings_open("record.dta", "wb");
1879 fwrite(record_data, 24 * 1280, 16, record_file);
1880 fclose(record_file);
1881
1882 record_file = settings_open("record.000", "wb");
1883 record_random_swap_endianess();
1884 fwrite(record_random, 24 * 1280, 4, record_file);
1885 fclose(record_file);
1886
1887 }
1888
1889 if (findparameter("-record") || findparameter("-playback")) {
1890 free(record_data);
1891 free(record_random);
1892 }
1893 //// Record
1894
1895 if (current_mode == SVGA_MODE) {
1896
1897 delete standard_background;
1898 standard_background = NULL;
1899 }
1900
1901
1902 }
1903
1904
1905
do_aftermath(int show_it_all)1906 void do_aftermath(int show_it_all) {
1907 Bitmap *temp;
1908 Bitmap *temp2;
1909 int l, l2;
1910 int tempt;
1911 int firedi;
1912 int infantry_score = 0;
1913 int struct_score = 0;
1914 int some_score;
1915 int aaa_score = 0;
1916 int x, y, n1, n2;
1917 int need_for_letter = 0;
1918 char ch;
1919 Bitmap *fly, *exit;
1920 int x_coord;
1921 int best_in_record = 0;
1922 int sisennys;
1923 int mission_success = 0;
1924
1925 fly = new Bitmap("FLY");
1926 exit = new Bitmap("EXIT");
1927
1928 random_fade_out();
1929
1930 mission_re_fly = -1;
1931
1932 if (show_it_all && (!playing_solo)) {
1933 if (!findparameter("-debugnographics"))
1934 init_vga("PALET5");
1935
1936 temp = new Bitmap("SCORE");
1937 temp->blit(0, 0);
1938 delete temp;
1939
1940
1941 for (l = 0; l < 4; l++) {
1942 for (l2 = 0; l2 < 4; l2++) {
1943 fontti->printf(69 + l2 * 30, 80 + l * 21, "%4d", player_shots_down[l][l2]);
1944 }
1945 fontti->printf(194, 80 + l * 21, "%3d", abs(player_points[l]));
1946 if (player_points[l] < 0)
1947 fontti->printf(194, 80 + l * 21, "-");
1948
1949 fontti->printf(224, 80 + l * 21, "%5d", player_fired[l]);
1950
1951 if (player_fired[l] == 0)
1952 firedi = 1;
1953 else
1954 firedi = player_fired[l];
1955
1956 fontti->printf(254, 80 + l * 21, "%4d%%", (player_hits[l] * 1000) / (firedi));
1957 }
1958
1959 do_all();
1960 }
1961
1962 if (playing_solo) {
1963 init_vga("PALET3");
1964
1965 sisennys = grid2->printf(0, 0, "%s", mission_names[solo_mission + solo_country * 6]);
1966 sisennys = (320 - sisennys) >> 1;
1967
1968 temp = new Bitmap("KANGAS", 0);
1969 temp->blit_fullscreen();
1970 temp2 = new Bitmap(260, 188, 37, 10, temp);
1971 temp2->blit(0, 190);
1972 delete temp2;
1973 delete temp;
1974
1975 tempt = 0;
1976
1977 l2 = 0;
1978 for (l = 0; l < MAX_STRUCTURES; l++) {
1979 if (!leveldata.struct_x[l])
1980 continue;
1981
1982
1983 if (!strcmp(leveldata.pd_name[l], "INFAN")) {
1984
1985 if (leveldata.struct_type[l] == 1) {
1986 if (infan_x[l] && (infan_state[l] != 3) && (infan_state[l] != 4) && (infan_state[l] != 5))
1987 l2 = 1;
1988 else {
1989 tempt += 1;
1990 infantry_score += 1;
1991 }
1992
1993 }
1994
1995 if (leveldata.struct_type[l] == 2) {
1996 if (!infan_x[l] || (infan_state[l] == 3) || (infan_state[l] == 4) || (infan_state[l] == 5))
1997 l2 = 1;
1998
1999 }
2000
2001 if (player_sides[leveldata.struct_owner[l]] == 0) {
2002 if (!infan_x[l] || (infan_state[l] == 3) || (infan_state[l] == 4) || (infan_state[l] == 5)) {
2003 tempt -= 2;
2004 infantry_score -= 2;
2005 }
2006
2007 }
2008
2009 if (player_sides[leveldata.struct_owner[l]] == 1) {
2010 if (!infan_x[l] || (infan_state[l] == 3) || (infan_state[l] == 4) || (infan_state[l] == 5)) {
2011 tempt += 4;
2012 infantry_score += 4;
2013 }
2014
2015 }
2016
2017 } else {
2018 if (structures[l][1] == NULL)
2019 continue;
2020
2021 if (leveldata.struct_type[l] == 1) {
2022 if (!struct_state[l])
2023 l2 = 1;
2024 else {
2025 tempt += 5;
2026 struct_score += 5;
2027 }
2028
2029 }
2030
2031 if (leveldata.struct_type[l] == 2) {
2032 if (struct_state[l])
2033 l2 = 1;
2034
2035 }
2036
2037 if (leveldata.struct_owner[l] != 4 && player_sides[leveldata.struct_owner[l]] == 0) {
2038 if (struct_state[l]) {
2039 tempt -= 20;
2040 struct_score -= 20;
2041 }
2042
2043 }
2044
2045 if (player_sides[leveldata.struct_owner[l]] == 1) {
2046 if (struct_state[l]) {
2047 tempt += 7;
2048 struct_score += 7;
2049 }
2050
2051 }
2052
2053 }
2054
2055 }
2056
2057 for (l = 0; l < MAX_AA_GUNS; l++) {
2058 if (!kkbase_x[l])
2059 continue;
2060
2061 if (kkbase_mission[l] == 1) {
2062 if (kkbase_status[l] != 2) {
2063 l2 = 1;
2064 } else {
2065 tempt += 5;
2066 aaa_score += 5;
2067 }
2068
2069 }
2070
2071 if (kkbase_mission[l] == 2) {
2072 if (kkbase_status[l] == 2)
2073 l2 = 1;
2074
2075 }
2076
2077 if (player_sides[leveldata.struct_owner[kkbase_number[l]]] == 0) {
2078 if (kkbase_status[l] == 2) {
2079 tempt -= 10;
2080 aaa_score -= 10;
2081 }
2082 }
2083
2084 if (player_sides[leveldata.struct_owner[kkbase_number[l]]] == 1) {
2085 if (kkbase_status[l] == 2) {
2086 tempt += 6;
2087 aaa_score += 6;
2088 }
2089
2090 }
2091
2092 }
2093
2094 grid2->printf(sisennys, 25, "%s", mission_names[solo_mission + solo_country * 6]);
2095
2096 frost->printf(110, 60, "AAA score :");
2097 frost->printf(210, 60, "%-6d", aaa_score);
2098
2099 frost->printf(110, 70, "Infantry score :");
2100 frost->printf(210, 70, "%-6d", infantry_score);
2101
2102 frost->printf(110, 80, "Structure score :");
2103 frost->printf(210, 80, "%-6d", struct_score);
2104
2105 some_score = player_points[solo_country] * 25 + number_of_planes[solo_country] * 20;
2106 tempt += some_score;
2107
2108 frost->printf(110, 90, "Plane score :");
2109 frost->printf(210, 90, "%-6d", some_score);
2110
2111 some_score = 110 - mission_duration / 42;
2112 tempt += some_score;
2113
2114 frost->printf(110, 100, "Time score :");
2115 frost->printf(210, 100, "%-6d", some_score);
2116
2117 some_score = -(player_fired[solo_country] >> 5);
2118 some_score -= player_bombed[solo_country] >> 1;
2119 tempt += some_score;
2120
2121 frost->printf(110, 110, "Ammunition score :");
2122 frost->printf(210, 110, "%-6d", some_score);
2123
2124 some_score = solo_mission * 25;
2125 tempt += some_score;
2126
2127 frost->printf(110, 120, "Difficulty bonus :");
2128 frost->printf(210, 120, "%-6d", some_score);
2129
2130
2131 if (((l2 == 0) && (number_of_planes[solo_country] >= 0)) && (!mission_interrupted))
2132 {
2133 if (tempt < 1)
2134 tempt = 1;
2135
2136 for (l = 0; l < MAX_PLAYERS_IN_ROSTER; l++) {
2137 if (!roster[l].pilotname[0])
2138 break;
2139
2140 if (roster[l].solo_mis_scores[solo_country][solo_mission] > best_in_record)
2141 best_in_record = roster[l].solo_mis_scores[solo_country][solo_mission];
2142
2143 }
2144
2145 roster[config.player_number[solo_country]].solo_mis_success++;
2146 if (tempt > 0 && solo_mission == 5 && !roster[config.player_number[solo_country]].solo_mis_scores[solo_country][solo_mission]) {
2147 need_for_letter = 1;
2148 }
2149
2150 if (tempt > roster[config.player_number[solo_country]].solo_mis_scores[solo_country][solo_mission])
2151 roster[config.player_number[solo_country]].solo_mis_scores[solo_country][solo_mission] = tempt;
2152 x_coord = grid2->printf(35, 160, "Mission Successful. Total score: %d.", tempt);
2153
2154
2155 if (best_in_record < tempt) {
2156 grid2->printf(x_coord + 10, 160, "(New Record) (Old %d)", best_in_record);
2157
2158 } else {
2159 if (best_in_record == tempt)
2160 grid2->printf(x_coord + 10, 160, "(Same as old record)");
2161 else
2162 grid2->printf(x_coord + 10, 160, "(Record is %d)", best_in_record);
2163
2164 }
2165
2166 mission_success = 1;
2167 } else {
2168 tempt = 0;
2169 grid2->printf(35, 160, "Mission failed. Total score: 0.");
2170
2171 }
2172
2173 do_all();
2174
2175
2176 if (tempt < 0)
2177 tempt = 0;
2178
2179 roster[config.player_number[solo_country]].solo_mis_totals += tempt;
2180
2181 if (tempt > 0) {
2182 hiiri_to(62, 195);
2183
2184 } else {
2185 hiiri_to(80, 195);
2186
2187 }
2188
2189 tempt = 0;
2190
2191 }
2192
2193 if (show_it_all) {
2194 standard_background = new Bitmap(0, 0, 320, 200);
2195 do_all_clear();
2196 }
2197
2198 for (l = 0; l < 4; l++) {
2199 if (config.player_type[l] == 1 && config.player_number[l] != -1) {
2200
2201 roster[config.player_number[l]].solo_mis_flown++;
2202
2203 tempt = 0;
2204 for (l2 = 0; l2 < 16; l2++) {
2205 if (player_sides[l2] == player_sides[l])
2206 continue;
2207
2208 tempt += player_shots_down[l][l2];
2209 }
2210
2211 roster[config.player_number[l]].solo_mis_drops += tempt;
2212
2213 tempt = 0;
2214 for (l2 = 0; l2 < 16; l2++) {
2215
2216 tempt += player_shots_down[l2][l];
2217 }
2218
2219
2220 roster[config.player_number[l]].solo_mis_dropped += tempt;
2221
2222 roster[config.player_number[l]].solo_mis_shotsf += player_fired[l];
2223 roster[config.player_number[l]].solo_mis_shotshit += player_hits[l];
2224
2225 roster[config.player_number[l]].solo_mis_bombs += player_bombed[l];
2226 roster[config.player_number[l]].solo_mis_bombshit += player_bomb_hits[l];
2227
2228
2229 }
2230
2231 if (config.player_type[l] == 3 && config.player_number[l] != -1) {
2232 roster[config.player_number[l]].multi_mis_flown++;
2233
2234 tempt = 0;
2235 for (l2 = 0; l2 < 4; l2++) {
2236 if (l2 == l)
2237 continue;
2238
2239 tempt += player_shots_down[l][l2];
2240 }
2241
2242 roster[config.player_number[l]].multi_mis_drops += tempt;
2243
2244 tempt = 0;
2245 for (l2 = 0; l2 < 4; l2++) {
2246
2247 tempt += player_shots_down[l2][l];
2248 }
2249
2250 for (l2 = 0; l2 < 4; l2++) {
2251 if (player_points[l2] > player_points[l])
2252 break;
2253
2254 }
2255 if (l2 == 4)
2256 roster[config.player_number[l]].multi_mis_success++;
2257
2258 roster[config.player_number[l]].multi_mis_dropped += tempt;
2259
2260 roster[config.player_number[l]].multi_mis_shotsf += player_fired[l];
2261 roster[config.player_number[l]].multi_mis_shotshit += player_hits[l];
2262
2263 roster[config.player_number[l]].multi_mis_bombs += player_bombed[l];
2264 roster[config.player_number[l]].multi_mis_bombshit += player_bomb_hits[l];
2265
2266
2267 }
2268
2269
2270
2271
2272 }
2273
2274 //// Bug up ^^^^
2275
2276 if (show_it_all) {
2277 l = 1;
2278
2279 while (l == 1) {
2280 if (kbhit()) {
2281 if ((ch = getch()) == 27) {
2282 l = 0;
2283
2284 }
2285
2286 if (ch == 13) {
2287 l = 2;
2288 if (!need_for_letter) {
2289 if (!mission_success)
2290 mission_re_fly = solo_mission;
2291 else
2292 mission_re_fly = 999;
2293 }
2294 }
2295
2296 }
2297
2298
2299 koords(&x, &y, &n1, &n2);
2300
2301
2302 if (n1 || n2) {
2303 if (playing_solo) {
2304 if (x >= 72 && y >= 191 && x <= 88 && y <= 199) {
2305
2306 fly->blit(72, 191);
2307
2308 if (n1)
2309 l = 0;
2310 else
2311 l = 2;
2312
2313
2314 if (!need_for_letter) {
2315 if (!mission_success)
2316 mission_re_fly = solo_mission;
2317 else
2318 mission_re_fly = 999;
2319 }
2320
2321 }
2322
2323 if (x >= 54 && y >= 191 && x <= 70 && y <= 199) {
2324 exit->blit(54, 191);
2325
2326 if (n1)
2327 l = 0;
2328 else
2329 l = 2;
2330
2331 }
2332
2333
2334 } else {
2335
2336 l = 2;
2337 }
2338 cursor->blit(x - 10, y - 10);
2339 do_all_clear();
2340 wait_mouse_relase();
2341 } else {
2342 cursor->blit(x - 10, y - 10);
2343 do_all_clear();
2344 }
2345 }
2346
2347 delete standard_background;
2348 standard_background = NULL;
2349
2350 if (!findparameter("-debugnoaftermathfadeout") && l == 0)
2351 random_fade_out();
2352 }
2353 save_roster();
2354 init_vga("PALET5");
2355 delete fly;
2356 delete exit;
2357 if (need_for_letter)
2358 letter_menu();
2359 }
2360
load_up(void)2361 void load_up(void) {
2362 int l, l1, l2, l3;
2363 int xxx, yyy;
2364 unsigned char *point1, *point2;
2365
2366 loading_text("DKS-file directory structure loaded.");
2367 loading_text("Loading Trigonometric functions.");
2368
2369 init_trigs();
2370
2371 if (!findparameter("-debugnofonts")) {
2372
2373 loading_text("Loading fonts.");
2374 frost = new Font("GRFONT");
2375 frost->scale();
2376 fontti = new Font("FONTT");
2377 grid2 = new Font("G2FONT");
2378 grid2->scale();
2379 }
2380
2381 loading_text("Loading and initializing board-graphics.");
2382 board = new Bitmap("BOARD", 0);
2383 boards[0] = new Bitmap(2, 90, 159, 12, board);
2384 boards[1] = new Bitmap(162, 90, 158, 12, board);
2385 boards[2] = new Bitmap(2, 188, 159, 12, board);
2386 boards[3] = new Bitmap(162, 188, 158, 12, board);
2387
2388 closed = new Bitmap("CLOSED", 0);
2389 board2 = new Bitmap("BOARD2", 0);
2390
2391 loading_text("Loading status icons.");
2392 plane1 = new Bitmap("STATUS");
2393
2394 status_icons[0][0] = new Bitmap(1, 1, 31, 11, plane1);
2395 status_icons[0][1] = new Bitmap(1, 13, 31, 11, plane1);
2396 status_icons[1][0] = new Bitmap(33, 1, 31, 11, plane1);
2397 status_icons[1][1] = new Bitmap(33, 13, 31, 11, plane1);
2398
2399 delete plane1;
2400
2401 loading_text("Loading smoke.");
2402
2403 plane1 = new Bitmap("SMOKE");
2404 for (l = 0; l < SMOKE_FRAMES; l++)
2405 smoke[l] = new Bitmap(1 + l * 21, 1, 20, 20, plane1);
2406
2407 delete plane1;
2408
2409 plane1 = new Bitmap("SSMOKE");
2410 for (l = 0; l < 17; l++)
2411 ssmoke[l] = new Bitmap(1 + l * 10, 1, 9, 9, plane1);
2412
2413 delete plane1;
2414
2415 loading_text("Loading hangar.");
2416
2417 hangarmenu = new Bitmap("HMENU", 0);
2418 hangaractive = new Bitmap("HACTIV");
2419 hangarinactive = new Bitmap("HINACT");
2420 hruks = new Bitmap("HRUKS");
2421
2422 loading_text("Loading radaricons.");
2423
2424 plane1 = new Bitmap("RADAR");
2425
2426 for (l = 0; l < 4; l++)
2427 for (l2 = 0; l2 < 8; l2++) {
2428 radar[l][l2] = new Bitmap(1 + l2 * 4, 1 + l * 4, 3, 3, plane1);
2429
2430 }
2431
2432 delete plane1;
2433
2434 loading_text("Loading waves.");
2435
2436 plane1 = new Bitmap("WAVE1");
2437 for (l = 0; l < WAVE1_FRAMES; l++)
2438 wave1[l] = new Bitmap(1 + l * 24, 1, 23, 23, plane1);
2439
2440 delete plane1;
2441
2442 plane1 = new Bitmap("WAVE2");
2443 for (l = 0; l < WAVE2_FRAMES; l++)
2444 wave2[l] = new Bitmap(1 + l * 4, 1, 3, 5, plane1);
2445
2446 delete plane1;
2447
2448 loading_text("Loading flames");
2449
2450 plane1 = new Bitmap("FLAME");
2451 for (l = 0; l < NUMBER_OF_FLAMES; l++)
2452 flames[l] = new Bitmap(1 + l * 8, 1, 7, 14, plane1);
2453
2454 delete plane1;
2455
2456 loading_text("Loading AAA Explosion.");
2457
2458 plane1 = new Bitmap("ITEXP1");
2459 for (l = 0; l < ITEXPLOSION_FRAMES; l++)
2460 itexplosion[l] = new Bitmap(1 + l * 24, 1, 23, 14, plane1);
2461
2462 delete plane1;
2463
2464 loading_text("Loading explosion frames.");
2465
2466 point1 = (unsigned char *) walloc(61 * 41);
2467 for (l = 0; l < 2501; l++)
2468 point1[l] = converted_explosion[l];
2469
2470 plane1 = new Bitmap(61, 41, point1, "explosion");
2471
2472 for (l = 0; l < 4; l++)
2473 for (l2 = 0; l2 < EXPLOX_FRAMES; l2++)
2474 explox[l][l2] = new Bitmap(1 + l2 * 10, 1 + l * 10, 9, 9, plane1);
2475
2476 delete plane1;
2477
2478 loading_text("Loading AA-MG animations");
2479
2480 plane1 = new Bitmap("KKPESA");
2481 for (l = 0; l < 2; l++)
2482 for (l2 = 0; l2 < 7; l2++) {
2483 kkbase[0][l][l2] = new Bitmap(1 + l2 * 27, 1 + l * 22, 26, 21, plane1);
2484
2485 }
2486
2487 for (l2 = 0; l2 < 5; l2++)
2488 kkbase[0][2][l2] = new Bitmap(1 + l2 * 27, 1 + l * 22, 26, 21, plane1);
2489
2490 delete plane1;
2491
2492 loading_text("Loading AA-GUN animations");
2493
2494 plane1 = new Bitmap("ITGUNS");
2495 for (l = 0; l < 2; l++)
2496 for (l2 = 0; l2 < 7; l2++) {
2497 kkbase[1][l][l2] = new Bitmap(1 + l2 * 27, 1 + l * 22, 26, 21, plane1);
2498
2499 }
2500
2501 for (l2 = 0; l2 < 5; l2++)
2502 kkbase[1][2][l2] = new Bitmap(1 + l2 * 27, 1 + l * 22, 26, 21, plane1);
2503
2504 delete plane1;
2505
2506 loading_text("Loading hangar doors");
2507
2508 plane1 = new Bitmap("OVI");
2509
2510 for (l = 0; l < 13; l++)
2511 ovi[l] = new Bitmap(1 + l * 26, 1, 25, 13, plane1);
2512
2513 delete plane1;
2514
2515 loading_text("Loading mechanic");
2516
2517 plane1 = new Bitmap("MEKAN1");
2518 for (l = 0; l < 14; l++) {
2519 mekan_running[l][0] = new Bitmap(1 + 14 * l, 1, 13, 11, plane1);
2520
2521 point1 = (unsigned char *) walloc(13 * 11);
2522
2523 point2 = mekan_running[l][0]->info(&xxx, &yyy);
2524 mekan_running[l][1] = new Bitmap(13, 11, point1, "mekan1");
2525
2526 for (xxx = 0; xxx < 13; xxx++)
2527 for (yyy = 0; yyy < 11; yyy++)
2528 point1[xxx + yyy * 13] = point2[12 - xxx + yyy * 13];
2529
2530 }
2531 delete plane1;
2532
2533 plane1 = new Bitmap("MEKAN2");
2534 for (l = 0; l < 14; l++) {
2535 mekan_pushing[0][l][0] = new Bitmap(1 + 14 * l, 1, 13, 11, plane1);
2536
2537 point1 = (unsigned char *) walloc(13 * 11);
2538 point2 = mekan_pushing[0][l][0]->info(&xxx, &yyy);
2539 mekan_pushing[0][l][1] = new Bitmap(13, 11, point1, "mekan2");
2540
2541 for (xxx = 0; xxx < 13; xxx++)
2542 for (yyy = 0; yyy < 11; yyy++)
2543 point1[xxx + yyy * 13] = point2[12 - xxx + yyy * 13];
2544
2545 }
2546 delete plane1;
2547
2548 plane1 = new Bitmap("MEKAN3");
2549 for (l = 0; l < 9; l++) {
2550 mekan_pushing[1][l][1] = new Bitmap(1 + 14 * l, 1, 13, 11, plane1);
2551
2552 point1 = (unsigned char *) walloc(13 * 11);
2553
2554 point2 = mekan_pushing[1][l][1]->info(&xxx, &yyy);
2555 mekan_pushing[1][l][0] = new Bitmap(13, 11, point1, "mekan3");
2556
2557 for (xxx = 0; xxx < 13; xxx++)
2558 for (yyy = 0; yyy < 11; yyy++)
2559 point1[xxx + yyy * 13] = point2[12 - xxx + yyy * 13];
2560
2561 }
2562 delete plane1;
2563
2564
2565 loading_text("Loading Infantry");
2566
2567 if (!findparameter("-debugnoinfantry")) {
2568
2569 plane1 = new Bitmap("INFANT");
2570
2571 for (l = 0; l < 4; l++) // Down X
2572 {
2573 infantry_dropping[l][0] = new Bitmap(257, 16 + l * 45, 15, 14, plane1);
2574 infantry_after_drop[l][0] = new Bitmap(257, 31 + l * 45, 15, 14, plane1);
2575
2576 for (l2 = 0; l2 < 12; l2++)
2577 infantry_walking[l][0][l2] = new Bitmap(1 + l2 * 16, 1 + l * 45, 15, 14, plane1);
2578
2579 for (l2 = 0; l2 < 7; l2++)
2580 infantry_dying[l][0][l2] = new Bitmap(193 + l2 * 16, 1 + l * 45, 15, 14, plane1);
2581
2582 for (l2 = 0; l2 < 6; l2++) {
2583 infantry_aiming[l][0][l2] = new Bitmap(1 + l2 * 16, 16 + l * 45, 15, 14, plane1);
2584
2585 infantry_shooting[l][0][l2] = new Bitmap(1 + l2 * 16, 31 + l * 45, 15, 14, plane1);
2586
2587 }
2588
2589 for (l2 = 0; l2 < 10; l2++) {
2590 infantry_wavedeath[l][0][l2] = new Bitmap(97 + l2 * 16, 16 + l * 45, 15, 14, plane1);
2591
2592 infantry_bdying[l][0][l2] = new Bitmap(97 + l2 * 16, 31 + l * 45, 15, 14, plane1);
2593
2594 }
2595
2596 }
2597 delete plane1; // Up X
2598
2599 loading_text("Mirroring infantry.");
2600
2601 for (l = 0; l < 4; l++) {
2602 point1 = (unsigned char *) walloc(15 * 14);
2603
2604 point2 = infantry_dropping[l][0]->info(&xxx, &yyy);
2605 infantry_dropping[l][1] = new Bitmap(15, 14, point1, "mirr_inf_dropping");
2606
2607 for (xxx = 0; xxx < 15; xxx++)
2608 for (yyy = 0; yyy < 14; yyy++)
2609 point1[xxx + yyy * 15] = point2[14 - xxx + yyy * 15];
2610
2611 point1 = (unsigned char *) walloc(15 * 14);
2612
2613 point2 = infantry_after_drop[l][0]->info(&xxx, &yyy);
2614 infantry_after_drop[l][1] = new Bitmap(15, 14, point1, "mirr_inf_after_drop");
2615
2616 for (xxx = 0; xxx < 15; xxx++)
2617 for (yyy = 0; yyy < 14; yyy++)
2618 point1[xxx + yyy * 15] = point2[14 - xxx + yyy * 15];
2619
2620
2621
2622 for (l2 = 0; l2 < 12; l2++) {
2623 point1 = (unsigned char *) walloc(15 * 14);
2624
2625 point2 = infantry_walking[l][0][l2]->info(&xxx, &yyy);
2626 infantry_walking[l][1][l2] = new Bitmap(15, 14, point1, "mirr_inf_walking");
2627
2628 for (xxx = 0; xxx < 15; xxx++)
2629 for (yyy = 0; yyy < 14; yyy++)
2630 point1[xxx + yyy * 15] = point2[14 - xxx + yyy * 15];
2631
2632 }
2633
2634 for (l2 = 0; l2 < 7; l2++) {
2635 point1 = (unsigned char *) walloc(15 * 14);
2636
2637 point2 = infantry_dying[l][0][l2]->info(&xxx, &yyy);
2638 infantry_dying[l][1][l2] = new Bitmap(15, 14, point1, "mirr_inf_dying");
2639
2640 for (xxx = 0; xxx < 15; xxx++)
2641 for (yyy = 0; yyy < 14; yyy++)
2642 point1[xxx + yyy * 15] = point2[14 - xxx + yyy * 15];
2643
2644 }
2645
2646 for (l2 = 0; l2 < 6; l2++) {
2647 point1 = (unsigned char *) walloc(15 * 14);
2648
2649 point2 = infantry_aiming[l][0][l2]->info(&xxx, &yyy);
2650 infantry_aiming[l][1][l2] = new Bitmap(15, 14, point1, "mirr_inf_aiming");
2651
2652 for (xxx = 0; xxx < 15; xxx++)
2653 for (yyy = 0; yyy < 14; yyy++)
2654 point1[xxx + yyy * 15] = point2[14 - xxx + yyy * 15];
2655
2656
2657 point1 = (unsigned char *) walloc(15 * 14);
2658 point2 = infantry_shooting[l][0][l2]->info(&xxx, &yyy);
2659 infantry_shooting[l][1][l2] = new Bitmap(15, 14, point1, "mirr_inf_shooting");
2660
2661 for (xxx = 0; xxx < 15; xxx++)
2662 for (yyy = 0; yyy < 14; yyy++)
2663 point1[xxx + yyy * 15] = point2[14 - xxx + yyy * 15];
2664
2665 }
2666
2667 for (l2 = 0; l2 < 10; l2++) {
2668 point1 = (unsigned char *) walloc(15 * 14);
2669 point2 = infantry_wavedeath[l][0][l2]->info(&xxx, &yyy);
2670 infantry_wavedeath[l][1][l2] = new Bitmap(15, 14, point1, "mirr_inf_wavedeath");
2671
2672 for (xxx = 0; xxx < 15; xxx++)
2673 for (yyy = 0; yyy < 14; yyy++)
2674 point1[xxx + yyy * 15] = point2[14 - xxx + yyy * 15];
2675
2676
2677
2678 point1 = (unsigned char *) walloc(15 * 14);
2679
2680 point2 = infantry_bdying[l][0][l2]->info(&xxx, &yyy);
2681 infantry_bdying[l][1][l2] = new Bitmap(15, 14, point1, "mirr_inf_bdying");
2682
2683 for (xxx = 0; xxx < 15; xxx++)
2684 for (yyy = 0; yyy < 14; yyy++)
2685 point1[xxx + yyy * 15] = point2[14 - xxx + yyy * 15];
2686
2687 }
2688
2689 }
2690 } // debug
2691
2692 if (!findparameter("-debugnorotate")) {
2693
2694 loading_text("Loading and rotating bomb.");
2695 bomb[0] = new Bitmap("BOMB");
2696
2697 for (l = 1; l < 61; l++) {
2698 bomb[l] = rotate_bitmap(bomb[0], l * 6);
2699 }
2700
2701 loading_text("Loading main planepicture.");
2702 plane1 = new Bitmap("PLANES");
2703
2704 loading_text("Generating rotated pictures.");
2705 for (l3 = 0; l3 < 4; l3++)
2706 for (l2 = 0; l2 < 4; l2++) {
2707 planes[l2][0][l3][0] = new Bitmap(1 + l3 * 21, 1 + l2 * 21, 20, 20, plane1);
2708 plane_p[l2][0][l3][0] = planes[l2][0][l3][0]->info(&xxx, &yyy);
2709 for (l = 1; l < 16; l++) {
2710 planes[l2][l][l3][0] = rotate_bitmap(planes[l2][0][l3][0], l * 6);
2711 plane_p[l2][l][l3][0] = planes[l2][l][l3][0]->info(&xxx, &yyy);
2712
2713 }
2714 }
2715
2716 for (l3 = 0; l3 < 4; l3++)
2717 for (l2 = 0; l2 < 4; l2++) {
2718 planes[l2][0][l3][0] = new Bitmap(1 + l3 * 21, 1 + l2 * 21, 20, 20, plane1);
2719 plane_p[l2][0][l3][0] = planes[l2][0][l3][0]->info(&xxx, &yyy);
2720 for (l = 45; l < 60; l++) {
2721 planes[l2][l][l3][0] = rotate_bitmap(planes[l2][0][l3][0], l * 6);
2722 plane_p[l2][l][l3][0] = planes[l2][l][l3][0]->info(&xxx, &yyy);
2723
2724 }
2725 }
2726
2727 for (l3 = 0; l3 < 4; l3++)
2728 for (l2 = 0; l2 < 16; l2++)
2729 for (l1 = 0; l1 < 4; l1++) {
2730 point1 = planes[l1][l2][l3][0]->info(&xxx, &yyy);
2731 point2 = (unsigned char *) walloc(400);
2732 if (!l2) {
2733 planes[l1][30][l3][1] = new Bitmap(20, 20, point2, "mirr_plane_1");
2734 plane_p[l1][30][l3][1] = point2;
2735 } else {
2736 planes[l1][30 - l2][l3][1] = new Bitmap(20, 20, point2, "mirr_plane_2");
2737 plane_p[l1][30 - l2][l3][1] = point2;
2738 }
2739 for (xxx = 0; xxx < 20; xxx++)
2740 for (yyy = 0; yyy < 20; yyy++)
2741 point2[(19 - xxx) + yyy * 20] = point1[xxx + yyy * 20];
2742 }
2743
2744 for (l3 = 0; l3 < 4; l3++)
2745 for (l2 = 45; l2 < 60; l2++)
2746 for (l1 = 0; l1 < 4; l1++) {
2747 point1 = planes[l1][l2][l3][0]->info(&xxx, &yyy);
2748 point2 = (unsigned char *) walloc(400);
2749
2750 planes[l1][90 - l2][l3][1] = new Bitmap(20, 20, point2, "mirr_plane_3");
2751 plane_p[l1][90 - l2][l3][1] = point2;
2752
2753 for (xxx = 0; xxx < 20; xxx++)
2754 for (yyy = 0; yyy < 20; yyy++)
2755 point2[(19 - xxx) + yyy * 20] = point1[xxx + yyy * 20];
2756 }
2757
2758
2759
2760 for (l3 = 0; l3 < 4; l3++)
2761 for (l2 = 0; l2 < 16; l2++)
2762 for (l1 = 0; l1 < 4; l1++) {
2763 point1 = planes[l1][l2][l3][0]->info(&xxx, &yyy);
2764 point2 = (unsigned char *) walloc(400);
2765 if (!l2) {
2766 planes[l1][0][l3][1] = new Bitmap(20, 20, point2, "mirr_plane_4");
2767 plane_p[l1][0][l3][1] = point2;
2768 } else {
2769 planes[l1][60 - l2][l3][1] = new Bitmap(20, 20, point2, "mirr_plane_5");
2770 plane_p[l1][60 - l2][l3][1] = point2;
2771 }
2772 for (xxx = 0; xxx < 20; xxx++)
2773 for (yyy = 0; yyy < 20; yyy++)
2774 point2[xxx + (19 - yyy) * 20] = point1[xxx + yyy * 20];
2775 }
2776
2777 for (l3 = 0; l3 < 4; l3++)
2778 for (l2 = 45; l2 < 60; l2++)
2779 for (l1 = 0; l1 < 4; l1++) {
2780 point1 = planes[l1][l2][l3][0]->info(&xxx, &yyy);
2781 point2 = (unsigned char *) walloc(400);
2782 if (!l2) {
2783 planes[l1][0][l3][1] = new Bitmap(20, 20, point2, "mirr_plane_6");
2784 plane_p[l1][0][l3][1] = point2;
2785 } else {
2786 planes[l1][60 - l2][l3][1] = new Bitmap(20, 20, point2, "mirr_plane_7");
2787 plane_p[l1][60 - l2][l3][1] = point2;
2788 }
2789 for (xxx = 0; xxx < 20; xxx++)
2790 for (yyy = 0; yyy < 20; yyy++)
2791 point2[xxx + (19 - yyy) * 20] = point1[xxx + yyy * 20];
2792 }
2793
2794 for (l3 = 0; l3 < 4; l3++)
2795 for (l2 = 16; l2 < 45; l2++)
2796 for (l1 = 0; l1 < 4; l1++) {
2797 point1 = planes[l1][l2][l3][1]->info(&xxx, &yyy);
2798 point2 = (unsigned char *) walloc(400);
2799
2800 planes[l1][60 - l2][l3][0] = new Bitmap(20, 20, point2, "mirr_plane_8");
2801 plane_p[l1][60 - l2][l3][0] = point2;
2802
2803 for (xxx = 0; xxx < 20; xxx++)
2804 for (yyy = 0; yyy < 20; yyy++)
2805 point2[xxx + (19 - yyy) * 20] = point1[xxx + yyy * 20];
2806 }
2807
2808 delete plane1;
2809
2810
2811 for (l = 0; l < 61; l++)
2812 for (l2 = 0; l2 < 4; l2++)
2813 for (l3 = 0; l3 < 2; l3++) {
2814 plane_p[4][l][l2][l3] = plane_p[0][l][l2][l3];
2815 plane_p[5][l][l2][l3] = plane_p[1][l][l2][l3];
2816 plane_p[6][l][l2][l3] = plane_p[2][l][l2][l3];
2817 plane_p[7][l][l2][l3] = plane_p[3][l][l2][l3];
2818 plane_p[8][l][l2][l3] = plane_p[0][l][l2][l3];
2819 plane_p[9][l][l2][l3] = plane_p[1][l][l2][l3];
2820 plane_p[10][l][l2][l3] = plane_p[2][l][l2][l3];
2821 plane_p[11][l][l2][l3] = plane_p[3][l][l2][l3];
2822 plane_p[12][l][l2][l3] = plane_p[1][l][l2][l3];
2823 plane_p[13][l][l2][l3] = plane_p[2][l][l2][l3];
2824 plane_p[14][l][l2][l3] = plane_p[3][l][l2][l3];
2825 plane_p[15][l][l2][l3] = plane_p[0][l][l2][l3];
2826
2827 planes[4][l][l2][l3] = planes[0][l][l2][l3];
2828 planes[5][l][l2][l3] = planes[1][l][l2][l3];
2829 planes[6][l][l2][l3] = planes[2][l][l2][l3];
2830 planes[7][l][l2][l3] = planes[3][l][l2][l3];
2831 planes[8][l][l2][l3] = planes[0][l][l2][l3];
2832 planes[9][l][l2][l3] = planes[1][l][l2][l3];
2833 planes[10][l][l2][l3] = planes[2][l][l2][l3];
2834 planes[11][l][l2][l3] = planes[3][l][l2][l3];
2835 planes[12][l][l2][l3] = planes[1][l][l2][l3];
2836 planes[13][l][l2][l3] = planes[2][l][l2][l3];
2837 planes[14][l][l2][l3] = planes[3][l][l2][l3];
2838 planes[15][l][l2][l3] = planes[0][l][l2][l3];
2839
2840
2841 }
2842
2843 } // debug
2844
2845 loading_text("Loading explosions.");
2846
2847 plane1 = new Bitmap("CRASH");
2848 for (l = 0; l < 6; l++)
2849 plane_crash[l] = new Bitmap(1 + 21 * l, 1, 20, 20, plane1);
2850 delete plane1;
2851
2852 loading_text("Loading icons.");
2853
2854 bomb_icon = new Bitmap("ASE1", 0);
2855 gas_icon = new Bitmap("ASE2", 0);
2856 small_ammo_icon = new Bitmap("ASE4", 0);
2857 big_ammo_icon = new Bitmap("ASE3", 0);
2858
2859 plane1 = new Bitmap("PICONS", 0);
2860 for (l = 0; l < 4; l++)
2861 picons[l] = new Bitmap(9 * l, 0, 9, 9, plane1);
2862
2863 delete plane1;
2864
2865 pwon = new Bitmap("PWON");
2866 pwoff = new Bitmap("PWOFF");
2867
2868 loading_text("Loading small parts.");
2869
2870 plane1 = new Bitmap("BITES");
2871 for (l = 0; l < NUMBER_OF_BITES; l++)
2872 bites[l] = new Bitmap(1 + 11 * l, 1, 10, 10, plane1);
2873 delete plane1;
2874
2875 plane1 = new Bitmap("RIFLE");
2876 for (l = 0; l < 12; l++)
2877 rifle[l] = new Bitmap(1 + 9 * l, 1, 8, 8, plane1);
2878 delete plane1;
2879
2880
2881 loading_text("Loading menu graphics.");
2882
2883 menu1 = new Bitmap("MENU01");
2884
2885 loading_text("Loading flags.");
2886
2887 temp_bitti = new Bitmap("FLAGS");
2888
2889 for (l = 0; l < 4; l++) {
2890 for (l2 = 0; l2 < 12; l2++) {
2891 flags[l][l2] = new Bitmap(1 + l2 * 14, 1 + l * 10, 13, 9, temp_bitti);
2892
2893 }
2894 }
2895
2896 delete temp_bitti;
2897
2898 loading_text("Loading mouse cursor.");
2899 cursor = new Bitmap("CURSOR");
2900
2901 }
2902
2903
2904
clean_memory(void)2905 void clean_memory(void) {
2906 int l, l2, l3, l4;
2907
2908 for (l = 0; l < 13; l++)
2909 delete ovi[l];
2910
2911 for (l = 0; l < 14; l++)
2912 for (l2 = 0; l2 < 2; l2++) {
2913 delete mekan_running[l][l2];
2914 delete mekan_pushing[0][l][l2];
2915 delete mekan_pushing[1][l][l2];
2916
2917
2918 }
2919
2920 for (l = 0; l < 17; l++)
2921 delete ssmoke[l];
2922
2923 delete hangarmenu;
2924 delete hangaractive;
2925 delete hangarinactive;
2926 delete hruks;
2927
2928 for (l = 0; l < 12; l++)
2929 delete rifle[l];
2930
2931 for (l = 0; l < 4; l++)
2932 for (l2 = 0; l2 < 8; l2++)
2933 delete radar[l][l2];
2934
2935 delete board;
2936 delete board2;
2937
2938 delete status_icons[0][0];
2939 delete status_icons[0][1];
2940 delete status_icons[1][0];
2941 delete status_icons[1][1];
2942
2943 for (l = 0; l < SMOKE_FRAMES; l++)
2944 delete smoke[l];
2945
2946 for (l = 0; l < WAVE1_FRAMES; l++)
2947 delete wave1[l];
2948
2949 for (l = 0; l < WAVE2_FRAMES; l++)
2950 delete wave2[l];
2951
2952 for (l = 0; l < NUMBER_OF_FLAMES; l++)
2953 delete flames[l];
2954
2955 for (l = 0; l < ITEXPLOSION_FRAMES; l++)
2956 delete itexplosion[l];
2957
2958 for (l = 0; l < 4; l++)
2959 for (l2 = 0; l2 < EXPLOX_FRAMES; l2++)
2960 delete explox[l][l2];
2961
2962 for (l3 = 0; l3 < 2; l3++)
2963 for (l = 0; l < 2; l++)
2964 for (l2 = 0; l2 < 7; l2++) {
2965 delete kkbase[l3][l][l2];
2966
2967 }
2968
2969 for (l3 = 0; l3 < 2; l3++)
2970 for (l2 = 0; l2 < 5; l2++)
2971 delete kkbase[l3][l][l2];
2972
2973 for (l3 = 0; l3 < 2; l3++)
2974 for (l = 0; l < 4; l++) {
2975 delete infantry_dropping[l][l3];
2976 delete infantry_after_drop[l][l3];
2977
2978
2979 for (l2 = 0; l2 < 12; l2++)
2980 delete infantry_walking[l][l3][l2];
2981
2982 for (l2 = 0; l2 < 7; l2++)
2983 delete infantry_dying[l][l3][l2];
2984
2985 for (l2 = 0; l2 < 6; l2++) {
2986 delete infantry_aiming[l][l3][l2];
2987
2988 delete infantry_shooting[l][l3][l2];
2989
2990 }
2991
2992 for (l2 = 0; l2 < 10; l2++) {
2993 delete infantry_wavedeath[l][l3][l2];
2994
2995 delete infantry_bdying[l][l3][l2];
2996
2997 }
2998
2999 }
3000
3001 for (l2 = 0; l2 < 4; l2++) {
3002 delete picons[l2];
3003 delete boards[l2];
3004 for (l = 0; l < 60; l++)
3005 for (l3 = 0; l3 < 4; l3++)
3006 for (l4 = 0; l4 < 2; l4++)
3007 delete planes[l2][l][l3][l4];
3008 }
3009
3010 for (l2 = 0; l2 < 6; l2++)
3011 delete plane_crash[l2];
3012
3013 for (l = 0; l < NUMBER_OF_BITES; l++)
3014 delete bites[l];
3015
3016
3017 delete closed;
3018 delete bomb_icon;
3019 delete gas_icon;
3020 delete small_ammo_icon;
3021 delete big_ammo_icon;
3022 delete pwon;
3023 delete pwoff;
3024
3025 delete fontti;
3026 delete frost;
3027 delete menu1;
3028
3029 for (l = 0; l < 4; l++)
3030 for (l2 = 0; l2 < 12; l2++)
3031 delete flags[l][l2];
3032 delete cursor;
3033
3034 }
3035
load_level(void)3036 void load_level(void) {
3037 int l, l2, i;
3038 int xx, yy;
3039 int c_flag;
3040 Bitmap *temppic;
3041
3042 loading_text("Loading levelinfo.");
3043
3044 if (!findparameter("-level")) {
3045 if (!playing_solo) {
3046 sprintf(levelname, "level%d", config.current_multilevel + 1);
3047 } else {
3048 sprintf(levelname, "%d-%d", solo_country, solo_mission);
3049
3050 }
3051 } else {
3052 sprintf(levelname, parametrit[findparameter("-level")] + 6);
3053
3054 }
3055
3056
3057 if (!dksopen(levelname)) {
3058 loading_text("Loading external level.");
3059 } else {
3060 dksclose();
3061
3062 }
3063
3064 if (!extdksopen(levelname)) {
3065 printf("\nError locating leveldata %s.\n\n", levelname);
3066 exit(1);
3067
3068
3069 }
3070
3071 dksread(&leveldata, sizeof(leveldata));
3072 dksclose();
3073
3074 // Byte order conversion
3075
3076 for (i = 0; i < MAX_STRUCTURES; i++) {
3077 leveldata.struct_x[i] = SDL_SwapLE32(leveldata.struct_x[i]);
3078 leveldata.struct_y[i] = SDL_SwapLE32(leveldata.struct_y[i]);
3079 leveldata.struct_hit[i] = SDL_SwapLE32(leveldata.struct_hit[i]);
3080 leveldata.struct_owner[i] = SDL_SwapLE32(leveldata.struct_owner[i]);
3081 leveldata.struct_type[i] = SDL_SwapLE32(leveldata.struct_type[i]);
3082 }
3083
3084 for (i = 0; i < 4; i++) {
3085 leveldata.airfield_x[i] = SDL_SwapLE32(leveldata.airfield_x[i]);
3086 leveldata.airfield_y[i] = SDL_SwapLE32(leveldata.airfield_y[i]);
3087 leveldata.airfield_lenght[i] = SDL_SwapLE32(leveldata.airfield_lenght[i]);
3088 leveldata.plane_direction[i] = SDL_SwapLE32(leveldata.plane_direction[i]);
3089 }
3090
3091
3092 for (l = 0; l < 4; l++) {
3093 if (!leveldata.airfield_x[l])
3094 continue;
3095 leveldata.airfield_x[l] += 4;
3096 leveldata.airfield_lenght[l] -= 8;
3097 }
3098
3099 for (l = 0; l < 4; l++) {
3100 if (leveldata.airfield_x[l] && config.player_type[l]) {
3101 plane_present[l] = 0;
3102
3103 } else {
3104 plane_present[l] = 0;
3105
3106 }
3107
3108 }
3109
3110 loading_text("Loading scenery.");
3111
3112 maisema = new Bitmap(leveldata.pb_name, 0);
3113
3114 loading_text("Loading structures.");
3115
3116 for (l = 0; l < MAX_FLAGS; l++)
3117 flags_x[l] = 0;
3118
3119 for (l = 0; l < MAX_INFANTRY; l++) {
3120 infan_x[l] = 0;
3121 }
3122
3123 for (l = 0; l < MAX_AA_GUNS; l++) {
3124 kkbase_x[l] = 0;
3125
3126 }
3127
3128 for (l = 0; l < 8; l++)
3129 infan_stop[l] = 0;
3130
3131
3132
3133 for (l = 0; l < MAX_STRUCTURES; l++) {
3134 struct_state[l] = 0;
3135 structures[l][1] = NULL;
3136 structures[l][0] = NULL;
3137
3138 if (leveldata.struct_x[l]) {
3139 if (!strncmp(leveldata.pd_name[l], "FLAGS", 5)) {
3140
3141 c_flag = atoi(leveldata.pd_name[l] + 5);
3142
3143 for (l2 = 0; l2 < MAX_FLAGS; l2++)
3144 if (!flags_x[l2])
3145 break;
3146
3147 if (l2 == MAX_FLAGS)
3148 continue;
3149
3150 flags_x[l2] = leveldata.struct_x[l];
3151 flags_y[l2] = leveldata.struct_y[l];
3152 flags_owner[l2] = c_flag;
3153 continue;
3154 }
3155
3156 if (!strncmp(leveldata.pd_name[l], "INFAN", 5)) {
3157 if (!playing_solo && !config.infantry)
3158 continue;
3159
3160
3161 infan_x[l] = leveldata.struct_x[l];
3162 infan_y[l] = leveldata.struct_y[l];
3163 infan_direction[l] = leveldata.struct_hit[l];
3164 infan_last_shot[l] = 0;
3165 infan_state[l] = 0;
3166 infan_country[l] = leveldata.struct_owner[l];
3167 infan_frame[l] = wrandom(12);
3168 continue;
3169 }
3170
3171 if (!strncmp(leveldata.pd_name[l], "INSTOP", 6)) {
3172
3173 for (l2 = 0; l2 < 8; l2++)
3174 if (!infan_stop[l2])
3175 break;
3176
3177 if (l2 != 8) {
3178 infan_stop[l2] = leveldata.struct_x[l];
3179
3180 }
3181
3182 continue;
3183 }
3184
3185 if (!strncmp(leveldata.pd_name[l], "KKBASE", 6)) {
3186 if (!playing_solo && !config.aa_mgs)
3187 continue;
3188
3189
3190 for (l2 = 0; l2 < MAX_AA_GUNS; l2++)
3191 if (!kkbase_x[l2])
3192 break;
3193
3194 if (l2 == MAX_AA_GUNS)
3195 continue;
3196
3197 kkbase_x[l2] = leveldata.struct_x[l];
3198 kkbase_y[l2] = leveldata.struct_y[l];
3199 kkbase_last_shot[l2] = 0;
3200 kkbase_status[l2] = 0;
3201 kkbase_country[l2] = leveldata.struct_owner[l];
3202 kkbase_frame[l2] = 3;
3203 kkbase_shot_number[l2] = 0;
3204 kkbase_type[l2] = 0;
3205 kkbase_mission[l2] = leveldata.struct_type[l];
3206 kkbase_number[l2] = l;
3207 continue;
3208 }
3209
3210 if (!strncmp(leveldata.pd_name[l], "ITGUN", 5)) {
3211 if (!playing_solo && !config.it_guns)
3212 continue;
3213
3214
3215 for (l2 = 0; l2 < MAX_AA_GUNS; l2++)
3216 if (!kkbase_x[l2])
3217 break;
3218
3219 if (l2 == MAX_AA_GUNS)
3220 continue;
3221
3222 kkbase_x[l2] = leveldata.struct_x[l];
3223 kkbase_y[l2] = leveldata.struct_y[l];
3224 kkbase_last_shot[l2] = 0;
3225 kkbase_status[l2] = 0;
3226 kkbase_country[l2] = leveldata.struct_owner[l];
3227 kkbase_frame[l2] = 3;
3228 kkbase_shot_number[l2] = 0;
3229 kkbase_type[l2] = 1;
3230 kkbase_mission[l2] = leveldata.struct_type[l];
3231 kkbase_number[l2] = l;
3232 continue;
3233 }
3234
3235 if (leveldata.struct_hit[l]) {
3236 structures[l][0] = new Bitmap(leveldata.pd_name[l]);
3237
3238 } else {
3239 temppic = new Bitmap(leveldata.pd_name[l]);
3240 temppic->info(&struct_width[l], &struct_heigth[l]);
3241
3242 structures[l][0] = new Bitmap(leveldata.struct_x[l], leveldata.struct_y[l], struct_width[l], struct_heigth[l], maisema);
3243
3244 temppic->blit_to_bitmap(structures[l][0], 0, 0);
3245 delete temppic;
3246
3247 for (l2 = 0; l2 < NUMBER_OF_STRUCT_NAMES; l2++) {
3248 if (!strcmp(struct_names[l2 * 2], leveldata.pd_name[l])) {
3249 temppic = new Bitmap(struct_names[l2 * 2 + 1]);
3250
3251 structures[l][1] = new Bitmap(leveldata.struct_x[l], leveldata.struct_y[l], struct_width[l], struct_heigth[l], maisema);
3252
3253 temppic->blit_to_bitmap(structures[l][1], 0, 0);
3254 delete temppic;
3255
3256 break;
3257 }
3258 }
3259
3260 if (l2 == NUMBER_OF_STRUCT_NAMES) {
3261 delete structures[l][0];
3262 structures[l][0] = new Bitmap(leveldata.pd_name[l]);
3263 structures[l][0]->info(&struct_width[l], &struct_heigth[l]);
3264
3265 }
3266 }
3267 }
3268 }
3269
3270 for (l = 0; l < 4; l++) {
3271 if (!leveldata.airfield_x[l]) {
3272 hangar_x[l] = 0;
3273 hangar_y[l] = 0;
3274
3275 } else {
3276 for (l2 = 0; l2 < 100; l2++) {
3277 if (!strcmp(leveldata.pd_name[l2], "HANGAR")) {
3278 if (leveldata.struct_x[l2] + 4 >= leveldata.airfield_x[l])
3279 if (leveldata.struct_x[l2] <= (leveldata.airfield_x[l] + leveldata.airfield_lenght[l]))
3280 break;
3281
3282 }
3283 }
3284
3285 if (l2 == 100) {
3286 hangar_x[l] = 0;
3287 hangar_y[l] = 0;
3288
3289
3290 } else {
3291 hangar_x[l] = leveldata.struct_x[l2];
3292 hangar_y[l] = leveldata.struct_y[l2];
3293
3294 }
3295 }
3296 }
3297
3298
3299 loading_text("Updating terrainpointer.");
3300
3301 level_bitmap = maisema->info(&xx, &yy);
3302
3303 for (l = 0; l < 2400; l++) {
3304 terrain_level[l] = 0;
3305
3306 for (l2 = 199; l2 >= 0; l2--)
3307 if (level_bitmap[l + l2 * 2400] >= 112 && level_bitmap[l + l2 * 2400] <= 119) {
3308 terrain_level[l] = l2;
3309 break;
3310 }
3311
3312
3313 }
3314
3315 if (current_mode == VGA_MODE && !findparameter("-debugnographics")) {
3316 loading_text("Initializing screen.");
3317 if (!findparameter("-black"))
3318 init_vga("PALET5");
3319 else
3320 init_vga("PALET3");
3321 }
3322
3323 }
3324
clear_level(void)3325 void clear_level(void) {
3326 int l, l2;
3327
3328
3329 for (l2 = 0; l2 < 2; l2++)
3330 for (l = 0; l < MAX_STRUCTURES; l++) {
3331 if (structures[l][l2] != NULL)
3332 delete structures[l][l2];
3333 }
3334
3335 delete maisema;
3336
3337 }
3338
3339
init_data(void)3340 void init_data(void) {
3341 int l, l2;
3342
3343 record_counter = 0;
3344
3345
3346 for (l = 0; l < 4; l++) {
3347 hangar_door_frame[l] = 0;
3348 hangar_door_closing[l] = 0;
3349 hangar_door_opening[l] = 0;
3350 mekan_x[l] = 0;
3351 mekan_y[l] = leveldata.airfield_y[l] - 11;
3352 mekan_frame[l] = 0;
3353 mekan_status[l] = 0;
3354 mekan_target[l] = 0;
3355 mekan_subtarget[l] = 0;
3356 mekan_direction[l] = 0;
3357 mekan_mission[l] = 0;
3358
3359
3360 }
3361
3362 for (l = 0; l < 16; l++) {
3363 mc_up[l] = 0;
3364 mc_down[l] = 0;
3365 mc_bomb[l] = 0;
3366 mc_roll[l] = 0;
3367 mc_guns[l] = 0;
3368 mc_power[l] = 0;
3369
3370 new_mc_up[l] = 0;
3371 new_mc_down[l] = 0;
3372 new_mc_bomb[l] = 0;
3373 new_mc_roll[l] = 0;
3374 new_mc_guns[l] = 0;
3375 new_mc_power[l] = 0;
3376
3377
3378 roll_key_down[l] = 0;
3379 bomb_key_down[l] = 0;
3380 hangarkey_up_down[l] = 0;
3381 hangarkey_down_down[l] = 0;
3382 hangarkey_right_down[l] = 0;
3383 hangarkey_left_down[l] = 0;
3384
3385 player_was_on_airfield[l] = 0;
3386 plane_wants_in[l] = 0;
3387 plane_wants_out[l] = 0;
3388
3389 }
3390
3391 for (l = 0; l < 100; l++)
3392 bombs_going[l] = -1;
3393
3394 for (l = 0; l < MAX_FLAMES; l++)
3395 flame_x[l] = 0;
3396
3397 for (l = 0; l < MAX_FLAGS; l++) {
3398 flags_state[l] = 0;
3399 flags_frame[l] = wrandom(10);
3400 }
3401
3402 for (l = 0; l < MAX_ITGUN_SHOTS; l++)
3403 itgun_shot_x[l] = 0;
3404
3405 for (l = 0; l < MAX_BOMBS; l++)
3406 bomb_x[l] = 0;
3407
3408 for (l = 0; l < MAX_SHOTS; l++)
3409 shots_flying_x[l] = 0;
3410
3411 for (l = 0; l < MAX_FLYING_OBJECTS; l++)
3412 fobjects[l].x = 0;
3413
3414 if (playing_solo) {
3415 for (l = 0; l < 12; l++) {
3416 player_exists[l] = 0;
3417 computer_active[l] = 0;
3418 if (number_of_planes[l]) {
3419 player_exists[l] = 1;
3420 if (l != solo_country) {
3421 computer_active[l] = 1;
3422
3423 } else {
3424 computer_active[l] = 0;
3425 }
3426
3427 }
3428 }
3429
3430 for (l = 0; l < 4; l++) {
3431 plane_power[l] = t_plane_power[l];
3432 plane_manover[l] = t_plane_manover[l];
3433 plane_mass[l] = t_plane_mass[l];
3434 plane_bombs[l] = t_plane_bombs[l];
3435 plane_gas[l] = t_plane_gas[l];
3436 plane_ammo[l] = t_plane_ammo[l];
3437 }
3438 } else {
3439 if (config.all_planes_are) {
3440 for (l = 0; l < 4; l++) {
3441 plane_power[l] = t_plane_power[config.all_planes_are - 1];
3442 plane_manover[l] = t_plane_manover[config.all_planes_are - 1];
3443 plane_mass[l] = t_plane_mass[config.all_planes_are - 1];
3444 plane_bombs[l] = t_plane_bombs[config.all_planes_are - 1];
3445 plane_gas[l] = t_plane_gas[config.all_planes_are - 1];
3446 plane_ammo[l] = t_plane_ammo[config.all_planes_are - 1];
3447 }
3448
3449
3450 } else {
3451 for (l = 0; l < 4; l++) {
3452 plane_power[l] = t_plane_power[l];
3453 plane_manover[l] = t_plane_manover[l];
3454 plane_mass[l] = t_plane_mass[l];
3455 plane_bombs[l] = t_plane_bombs[l];
3456 plane_gas[l] = t_plane_gas[l];
3457 plane_ammo[l] = t_plane_ammo[l];
3458 }
3459
3460 }
3461
3462 if (config.alliance) {
3463 switch (config.alliance) {
3464 case 1:
3465 player_sides[0] = 0;
3466 player_sides[1] = 0;
3467 player_sides[2] = 1;
3468 player_sides[3] = 1;
3469 break;
3470
3471 case 2:
3472 player_sides[0] = 0;
3473 player_sides[1] = 1;
3474 player_sides[2] = 0;
3475 player_sides[3] = 1;
3476 break;
3477
3478 case 3:
3479 player_sides[0] = 0;
3480 player_sides[1] = 1;
3481 player_sides[2] = 1;
3482 player_sides[3] = 0;
3483 break;
3484
3485
3486
3487 }
3488
3489 }
3490
3491 }
3492
3493 for (l = 0; l < 16; l++) {
3494 player_x_8[l] = 25000;
3495 player_y_8[l] = 1000;
3496 player_x[l] = 2500000;
3497 player_y[l] = 250000;
3498 plane_present[l] = 0;
3499 plane_coming[l] = 0;
3500 player_on_airfield[l] = 0;
3501 player_fired[l] = 0;
3502 player_hits[l] = 0;
3503 player_bombed[l] = 0;
3504 player_bomb_hits[l] = 0;
3505
3506 player_speed[l] = 0;
3507 player_angle[l] = 0;
3508 player_upsidedown[l] = 0;
3509 player_rolling[l] = 0;
3510 player_spinning[l] = 0;
3511 spinning_remaining[l] = 0;
3512 player_x_speed[l] = 0;
3513 player_y_speed[l] = 0;
3514 player_last_shot[l] = 0;
3515
3516
3517 hangarmenu_active[l] = 0;
3518 hangarmenu_position[l] = 0;
3519
3520 if (playing_solo)
3521 switch (fighter[l]) {
3522 case 0:
3523 hangarmenu_ammo[l] = hangarmenu_max_ammo[l] = 0;
3524 hangarmenu_bombs[l] = hangarmenu_max_bombs[l] = plane_bombs[l];
3525 break;
3526
3527 case 1:
3528 hangarmenu_ammo[l] = hangarmenu_max_ammo[l] = plane_ammo[l];
3529 hangarmenu_bombs[l] = hangarmenu_max_bombs[l] = plane_bombs[l];
3530 break;
3531 case 2:
3532 hangarmenu_ammo[l] = hangarmenu_max_ammo[l] = plane_ammo[l];
3533 hangarmenu_bombs[l] = hangarmenu_max_bombs[l] = 0;
3534 break;
3535
3536 } else {
3537 hangarmenu_ammo[l] = hangarmenu_max_ammo[l] = plane_ammo[l];
3538 hangarmenu_bombs[l] = hangarmenu_max_bombs[l] = plane_bombs[l];
3539
3540 }
3541
3542 hangarmenu_gas[l] = hangarmenu_max_gas[l] = plane_gas[l];
3543
3544 for (l2 = 0; l2 < 16; l2++)
3545 player_shots_down[l][l2] = 0;
3546
3547 }
3548
3549 }
3550
handle_parameters(void)3551 void handle_parameters(void) {
3552 if (findparameter("-reverse"))
3553 reverbed_channels = 1;
3554
3555 if (findparameter("-nosound")) {
3556 is_there_sound = 0;
3557 config.sound_on = 0;
3558 loading_text("Sounds disabled.");
3559 }
3560
3561 if (findparameter("-2")) {
3562 pixel_multiplier_vga = 2;
3563 }
3564
3565 if (findparameter("-3")) {
3566 pixel_multiplier_vga = 3;
3567 }
3568
3569 if (findparameter("-4")) {
3570 pixel_multiplier_vga = 4;
3571 }
3572
3573 if (findparameter("-2svga")) {
3574 pixel_multiplier_svga = 2;
3575 }
3576
3577 if (findparameter("-fullscreen")) {
3578 wantfullscreen = 1;
3579 }
3580
3581 if (findparameter("-nofullscreen")) {
3582 wantfullscreen = 0;
3583 }
3584
3585 if (findparameter("-sdldraw")) {
3586 draw_with_vircr_mode = 0;
3587 }
3588 }
3589
main(int argc,char * argv[])3590 int main(int argc, char *argv[]) {
3591 int x, y, n1, n2;
3592 int laskuri;
3593 FILE *faili;
3594 Bitmap *lakuva1;
3595
3596 for (laskuri = 0; laskuri < argc; laskuri++)
3597 strcpy(parametrit[laskuri], argv[laskuri]);
3598
3599 parametri_kpl = argc;
3600
3601
3602 if (findparameter("-?") || findparameter("-h") || findparameter("--help") || findparameter("-help")) {
3603 printf("Triplane Classic " TRIPLANE_VERSION " - a side-scrolling dogfighting game.\n");
3604 printf("Copyright (C) 1996,1997,2009 Dodekaedron Software Creations Oy\n");
3605 printf("This program is free software; you may redistribute it under the terms of\n");
3606 printf("the GNU General Public License version 3 or (at your option) a later version.\n");
3607 printf("This program has absolutely no warranty.\n\n");
3608 printf("-help Help on options\n");
3609 printf("-fullscreen Start game in fullscreen mode (default)\n");
3610 printf("-nofullscreen Start game in windowed mode\n");
3611 printf("-nosound Start game without sounds\n");
3612 printf("-2, -3, -4 Zoom the 320x200-pixel game window 2x, 3x or 4x\n");
3613 printf("-2svga Zoom the 800x600-pixel window 2x to produce 1600x1200-pixel window\n");
3614 printf("\n");
3615 exit(0);
3616 }
3617
3618 if (findparameter("-loadtexts"))
3619 loading_texts = 1;
3620
3621 if (!dksinit(DKS_FILENAME)) {
3622 printf("\n\nError locating main datafile\n");
3623 exit(1);
3624 }
3625
3626 main_engine_random_seed = time(0);
3627 wrandom_sanity_check();
3628
3629 main_version = MAIN_VERSION;
3630 sub_version = SUB_VERSION;
3631
3632 load_config();
3633
3634 loading_text("Starting parameter handling.");
3635 handle_parameters();
3636
3637 /* needed to find joysticks */
3638 /* needs draw_with_vircr_mode parameter from handle_parameters() */
3639 init_video();
3640
3641 loading_text("Looking for joystick");
3642 if (!(joystick_exists = init_joysticks())) {
3643 loading_text("Joystick(s) not detected and thus not calibrated.");
3644 }
3645
3646 if (config.joystick_calibrated[1] || config.joystick_calibrated[0]) {
3647 if (!load_joysticks_data(CALIBRATION_FILENAME)) {
3648 config.joystick_calibrated[0] = 0;
3649 config.joystick[0] = -1;
3650 config.joystick_calibrated[1] = 0;
3651 config.joystick[1] = -1;
3652 loading_text("Unable to load calibration data.");
3653
3654 }
3655
3656 }
3657
3658 loading_text("\nLoading keyset.");
3659
3660 if (!findparameter("-debugnokeyset"))
3661 load_keyset();
3662
3663 if (findparameter("-speed")) {
3664 nopeuskontrolli_enable(0);
3665 }
3666
3667 if (is_there_sound) {
3668 loading_text("Initializing sounds.");
3669 init_sounds(); /* can zero is_there_sound */
3670 }
3671
3672 if (is_there_sound) {
3673 if (config.music_on) {
3674 loading_text("Loading music.");
3675 load_music();
3676 }
3677
3678 if (config.sfx_on) {
3679 loading_text("Loading samples.");
3680 load_sfx();
3681
3682 }
3683
3684 loading_text("Soundsystem initialized correctly.\n\n");
3685 }
3686
3687
3688 init_vga("PALETD");
3689 lakuva1 = new Bitmap("STARTD", 0);
3690
3691 lakuva1->blit(0, 0);
3692 do_all();
3693
3694 delete lakuva1;
3695
3696
3697 if (sfx_loaded && config.sound_on) {
3698 play_sample(sample_alku);
3699 }
3700
3701 loading_text("\nData loading started.");
3702 load_up();
3703
3704
3705
3706 if (loading_texts) {
3707 printf("\nLoading complete. Press a key to continue.");
3708 fflush(stdout);
3709 }
3710
3711 n1 = 0;
3712 while (!n1 && !findparameter("-autostart")) {
3713 if (kbhit())
3714 break;
3715
3716 koords(&x, &y, &n1, &n2);
3717
3718 if (n1 || n2) {
3719 wait_mouse_relase();
3720 break;
3721 }
3722
3723 }
3724
3725 while (kbhit() && !findparameter("-autostart"))
3726 getch();
3727
3728
3729 if (sfx_loaded) {
3730 sample_alku->right_volume = 0;
3731 sample_alku->left_volume = 0;
3732
3733 }
3734
3735 #ifdef NO_TRADEMARK_PROBLEMS
3736 lakuva1 = new Bitmap("START1", 0);
3737 init_vga("PALETA");
3738
3739 lakuva1->blit(0, 0);
3740 do_all();
3741
3742 delete lakuva1;
3743
3744
3745 while (!kbhit() && !findparameter("-autostart")) {
3746 koords(&x, &y, &n1, &n2);
3747
3748 if (n1 || n2) {
3749 wait_mouse_relase();
3750 break;
3751 }
3752
3753 }
3754 #endif
3755
3756 while (kbhit() && !findparameter("-autostart"))
3757 getch();
3758
3759
3760 loading_text("Loading roster.");
3761 load_roster();
3762
3763 loading_text("\nInitializing VGA and starting game.");
3764 if (!findparameter("-debugnographics"))
3765 init_vga("PALET5");
3766
3767 while (kbhit())
3768 getch();
3769
3770 main_menu();
3771 save_roster();
3772
3773 if (music_loaded) {
3774 sdl_stop_music();
3775 clear_music();
3776 }
3777
3778 if (sfx_loaded) {
3779 clear_sfx();
3780
3781 }
3782
3783 if (is_there_sound) {
3784 uninit_sounds();
3785 }
3786
3787 if (findparameter("-writehsfile")) {
3788 faili = settings_open("higsscor.txt", "wt");
3789
3790 fprintf(faili, "Triplane Classic Acelist. Total highscores in Sologame\n\n");
3791
3792 for (laskuri = 0; laskuri < MAX_PLAYERS_IN_ROSTER; laskuri++) {
3793
3794 if (!roster[laskuri].pilotname[0])
3795 break;
3796
3797 x = 0;
3798
3799 fprintf(faili, "Scores for %s :\n", roster[laskuri].pilotname);
3800
3801 for (n1 = 0; n1 < 4; n1++)
3802 for (n2 = 0; n2 < 6; n2++) {
3803 x += roster[laskuri].solo_mis_scores[n1][n2];
3804 fprintf(faili, "%d/%d : %d\n", n1, n2, roster[laskuri].solo_mis_scores[n1][n2]);
3805 }
3806
3807 fprintf(faili, "-------------------------------\nTotal : %d\n\n", x);
3808 }
3809
3810 fclose(faili);
3811
3812 }
3813
3814 save_config();
3815
3816 clean_memory();
3817
3818 return 0;
3819 }
3820
loading_text(const char * teksti)3821 void loading_text(const char *teksti) {
3822 if (loading_texts) {
3823 printf("%s\n", teksti);
3824
3825 }
3826 }
3827