forked from triplane-classic/triplane
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtriplane.cpp
More file actions
3838 lines (2792 loc) · 102 KB
/
Copy pathtriplane.cpp
File metadata and controls
3838 lines (2792 loc) · 102 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Triplane Classic - a side-scrolling dogfighting game.
* Copyright (C) 1996,1997,2009 Dodekaedron Software Creations Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* tjt@users.sourceforge.net
*/
#define MAIN_VERSION 1
#define SUB_VERSION 3
//\\\\ Includes
#include "triplane.h"
#include "io/joystick.h"
#include "gfx/gfx.h"
#include "menus/tripmenu.h"
#include "world/terrain.h"
#include "world/fobjects.h"
#include "world/tmexept.h"
#include "world/plane.h"
#include "world/tripaudio.h"
#include <stdint.h>
#include <SDL.h>
#include <SDL_endian.h>
#include "util/wutil.h"
#include <time.h>
#include <string.h>
#include "io/trip_io.h"
#include "io/sdl_compat.h"
#include "settings.h"
//\\\\ Variables
//\ Picturedata
Bitmap *board;
Bitmap *board2;
Bitmap *pwon;
Bitmap *pwoff;
Bitmap *picons[4];
Bitmap *plane1;
Bitmap *planes[16][61][4][2];
Bitmap *bomb[61];
Bitmap *boards[4];
Bitmap *closed;
Bitmap *bomb_icon;
Bitmap *gas_icon;
Bitmap *small_ammo_icon;
Bitmap *big_ammo_icon;
Bitmap *plane_crash[6];
Bitmap *smoke[SMOKE_FRAMES];
Bitmap *wave1[WAVE1_FRAMES];
Bitmap *wave2[WAVE2_FRAMES];
Bitmap *explox[4][EXPLOX_FRAMES];
Bitmap *maisema;
Bitmap *bites[NUMBER_OF_BITES];
Bitmap *menu1;
Bitmap *structures[MAX_STRUCTURES][2];
Bitmap *temp_bitti;
Bitmap *cursor;
Bitmap *kkbase[2][3][7];
Bitmap *infantry_walking[4][2][12];
Bitmap *infantry_dying[4][2][7];
Bitmap *infantry_aiming[4][2][6];
Bitmap *infantry_wavedeath[4][2][10];
Bitmap *infantry_shooting[4][2][6];
Bitmap *infantry_bdying[4][2][10];
Bitmap *infantry_dropping[4][2];
Bitmap *infantry_after_drop[4][2];
Bitmap *itexplosion[ITEXPLOSION_FRAMES];
Bitmap *flames[6];
Bitmap *status_icons[2][2];
Bitmap *hangarmenu;
Bitmap *hangaractive, *hangarinactive;
Bitmap *radar[4][8];
Bitmap *rifle[12];
Bitmap *hruks;
Bitmap *ssmoke[17];
Bitmap *ovi[13];
Bitmap *mekan_running[14][2];
Bitmap *mekan_pushing[2][14][2];
int hangar_x[4];
int hangar_y[4];
int hangar_door_frame[4];
int mekan_x[4];
int mekan_y[4];
int mekan_frame[4];
int mekan_status[4];
int mekan_target[4];
int mekan_subtarget[4];
int mekan_direction[4];
int hangar_door_opening[4];
int hangar_door_closing[4];
int mekan_mission[4];
int plane_wants_in[16];
int plane_wants_out[16];
int player_exists[16] = { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int plane_present[16] = { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int player_sides[16] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 };
int player_tsides[16] = { 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 };
int plane_coming[16];
extern int number_of_planes[16];
extern int miss_plane_direction[16];
extern int miss_pl_x[16];
extern int miss_pl_y[16];
extern int fighter[16];
unsigned char *level_bitmap;
int playing_solo;
int solo_country = 0;
int solo_mission;
int solo_failed;
int solo_success;
int solo_dest_remaining;
//\ struct_information:
int struct_state[MAX_STRUCTURES];
int struct_width[MAX_STRUCTURES];
int struct_heigth[MAX_STRUCTURES];
//\ Fonts
Font *fontti;
Font *frost;
Font *grid2;
//\ Parameter control
char parametrit[40][40];
int parametri_kpl;
//\ Shots control
int pohja = 0;
int play_shot[16];
int shots_flying_x[MAX_SHOTS];
int shots_flying_y[MAX_SHOTS];
int shots_flying_x_speed[MAX_SHOTS];
int shots_flying_y_speed[MAX_SHOTS];
int shots_flying_owner[MAX_SHOTS];
int shots_flying_age[MAX_SHOTS];
int shots_flying_infan[MAX_SHOTS];
//\ Player planes
int in_closing[16];
int player_shown_x[16];
int player_shown_y[16];
unsigned char *plane_p[16][61][4][2];
int hangarmenu_active[16];
int hangarmenu_position[16];
int hangarmenu_gas[16];
int hangarmenu_ammo[16];
int hangarmenu_bombs[16];
int hangarmenu_max_gas[16];
int hangarmenu_max_ammo[16];
int hangarmenu_max_bombs[16];
/* Timing */
short int viimeiset_framet = 0;
short int frame_laskuri = 0;
/* Timing*/
//\ Graphics locating
int x_muutos[4] = { 0, 160, 0, 160 };
int y_muutos[4] = { 0, 0, 100, 100 };
int x1_raja[4] = { 2, 162, 2, 162 };
int y1_raja[4] = { 2, 2, 102, 102 };
int x2_raja[4] = { 157, 317, 157, 317 };
int y2_raja[4] = { 89, 89, 187, 187 };
//\ Airfields
int player_on_airfield[16];
//\ General
int collision_detect = 1;
int part_collision_detect = 1;
int power_reverse = 0;
int power_on_off = 0;
int loading_texts = 0;
int solo_mode = -1;
int aftermath;
int level_loaded;
//\ Flying objects control
struct flying_objects_data fobjects[MAX_FLYING_OBJECTS];
//\ Scoring data
int player_fired[16];
int player_hits[16];
int player_shots_down[16][16];
int player_bombed[16];
int player_bomb_hits[16];
//\ Leveldata
char levelname[80];
struct level_struct leveldata;
//\ Bombs
int bomb_x[MAX_BOMBS];
int bomb_y[MAX_BOMBS];
int bomb_speed[MAX_BOMBS];
int bomb_angle[MAX_BOMBS];
int bomb_owner[MAX_BOMBS];
int bomb_x_speed[MAX_BOMBS];
int bomb_y_speed[MAX_BOMBS];
int roll_key_down[16];
int bomb_key_down[16];
int hangarkey_up_down[16];
int hangarkey_down_down[16];
int hangarkey_right_down[16];
int hangarkey_left_down[16];
int plane_tire_y;
int flags_state[MAX_FLAGS];
int flags_frame[MAX_FLAGS];
int flags_x[MAX_FLAGS];
int flags_y[MAX_FLAGS];
int flags_owner[MAX_FLAGS];
Bitmap *flags[4][12];
//\\ AA-MG && AA-Gun
int kkbase_x[MAX_AA_GUNS];
int kkbase_y[MAX_AA_GUNS];
int kkbase_last_shot[MAX_AA_GUNS];
int kkbase_shot_number[MAX_AA_GUNS];
int kkbase_frame[MAX_AA_GUNS];
int kkbase_status[MAX_AA_GUNS];
int kkbase_country[MAX_AA_GUNS];
int kkbase_type[MAX_AA_GUNS];
int kkbase_mission[MAX_AA_GUNS];
int kkbase_number[MAX_AA_GUNS];
//\\ Infantry
extern int infan_x[MAX_INFANTRY];
extern int infan_y[MAX_INFANTRY];
extern int infan_direction[MAX_INFANTRY];
extern int infan_last_shot[MAX_INFANTRY];
extern int infan_state[MAX_INFANTRY];
extern int infan_country[MAX_INFANTRY];
extern int infan_frame[MAX_INFANTRY];
extern int infan_x_speed[MAX_INFANTRY];
extern int infan_stop[8];
//\\ Computer players
int computer_active[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int going_left;
int going_up;
int terrain_level[2400];
int wide_terrain_level[2400];
int current_mission[16];
int mission_phase[16];
int mission_target[16];
int distances[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
int angles[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int bombs_going[100];
//\\ Configuration
short joystick_exists;
int modem_com_port = 2;
int modem_com_speed = 9600;
// Solo mode success/failure text blinking variables
int status_frames = 0;
int status_state = 0;
int mission_duration;
int mission_interrupted;
int mission_re_fly = -1;
FILE *record_file = NULL;
char *record_data = NULL;
int *record_random = NULL;
int record_counter = 0;
int main_engine_random_seed;
int quit_flag = 0;
int mc_up[16];
int mc_down[16];
int mc_bomb[16];
int mc_roll[16];
int mc_guns[16];
int mc_power[16];
int new_mc_up[16];
int new_mc_down[16];
int new_mc_bomb[16];
int new_mc_roll[16];
int new_mc_guns[16];
int new_mc_power[16];
int main_version;
int sub_version;
#include "gfx/extra.h"
//\\\\ Externs
extern int current_mode;
extern int dirty_area;
extern int isa_counter;
extern int dirty_x[100];
extern int dirty_y[100];
extern int dirty_yl[100];
extern int dirty_xl[100];
extern unsigned char *dirty_marker;
extern int itgun_shot_x[MAX_ITGUN_SHOTS];
extern int itgun_shot_y[MAX_ITGUN_SHOTS];
extern char mission_names[24][30];
//\\\\ Prototypes
void hangarmenu_handle(void);
int findparameter(const char *jono);
void controls(void);
void detect_collision(void);
void main_engine(void);
void load_up(void);
void clean_memory(void);
void init_data(void);
void do_aftermath(int show_it_all);
void airfield_checks(void);
void handle_parameters(void);
void load_level(void);
void clear_level(void);
void do_flags(void);
sb_sample *sample_load(const char *name);
void kkbase_sound(int type, int kkbase_x);
void itgun_sound(int itgun_x);
void rotate_water_palet(void);
void cause_damage(int amount, int plane);
int small_warning(const char *message);
int big_warning(const char *message);
void load_all_samples(void);
void init_sologame(void);
void write_files(void);
void load_sfx(void);
void load_music(void);
void clear_sfx(void);
void clear_music(void);
void init_sounds(void);
void uninit_sounds(void);
extern void do_infan(void);
extern void do_kkbase(void);
extern void start_it_shot(int x, int y, int angle);
extern void do_it_shots(void);
extern void init_mission(int country, int number);
extern void do_mekan(void);
extern void do_ai(int number);
extern void ai_turn_down(int number);
extern void ai_turn_up(int number);
extern void ai_evade_terrain(int number);
extern void ai_turnplus(int number);
extern void ai_turnminus(int number);
extern "C" {
extern void init_alkucallback(void);
}
#define NUMBER_OF_STRUCT_NAMES 35
#define DESCRIPTION_LENGHT
char struct_names[NUMBER_OF_STRUCT_NAMES * 2][7] = {
"TOWER", "DTOWER",
"FAC1", "DFAC1",
"FAC2", "DFAC2",
"BIRCH1", "DBIR1",
"BIRCH2", "DBIR2",
"BIRCH3", "DBIR3",
"TENT2", "DTENT2",
"OAK1", "DOAK1",
"OAK2", "DOAK2",
"OAK3", "DOAK3",
"PALM1", "DPALM1",
"PALM2", "DPALM2",
"PALM3", "DPALM3",
"HOU1", "DHOU1",
"HOU2", "DHOU2",
"HOU3", "DHOU3",
"HOU4", "DHOU4",
"HOU5", "DHOU5",
"WATERT", "DWAT",
"CHOU1", "DCHOU1",
"BARR2", "DBARR2",
"BARRA", "DBARRA",
"CBARR2", "DCBAR2",
"CBARRA", "DCBARR",
"CHOU5", "DCHOU5",
"WOAK1", "DOAK1",
"WOAK2", "DOAK2",
"WOAK3", "DOAK3",
"STORE1", "DSTORE",
"IGLU1", "DIGLU1",
"VEC1", "DVEC1",
"VEC2", "DVEC2",
"AUT1", "DBIR1",
"AUT2", "DBIR2",
"AUT3", "DBIR3"
};
//\\\\ Special
#if defined(WIN32) && defined(NDEBUG)
// Hide console for Release builds
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#endif
//\\\\ Functions
static void record_random_swap_endianess(void) {
int i;
for (i = 0; i < 24 * 1280; i++) {
record_random[i] = SDL_SwapLE32(record_random[i]);
}
}
void hangarmenu_handle(void) {
int l;
for (l = 0; l < 8; l++) {
if (!hangarmenu_active[l])
continue;
if (mc_guns[l]) {
if (!hangarkey_right_down[l]) {
hangarkey_right_down[l] = 1;
hangarmenu_position[l]++;
if (hangarmenu_position[l] > 2)
hangarmenu_position[l] = 2;
}
} else
hangarkey_right_down[l] = 0;
if (mc_bomb[l]) {
if (!hangarkey_left_down[l]) {
hangarkey_left_down[l] = 1;
hangarmenu_position[l]--;
if (hangarmenu_position[l] < 0)
hangarmenu_position[l] = 0;
}
} else
hangarkey_left_down[l] = 0;
if (mc_down[l]) {
if (!hangarkey_up_down[l]) {
hangarkey_up_down[l] = 1;
switch (hangarmenu_position[l]) {
case 0:
if (++hangarmenu_bombs[l] > hangarmenu_max_bombs[l])
hangarmenu_bombs[l] = hangarmenu_max_bombs[l];
break;
case 1:
hangarmenu_ammo[l] += 16;
if (hangarmenu_ammo[l] > hangarmenu_max_ammo[l])
hangarmenu_ammo[l] = hangarmenu_max_ammo[l];
break;
case 2:
hangarmenu_gas[l] += 256;
if (hangarmenu_gas[l] > hangarmenu_max_gas[l])
hangarmenu_gas[l] = hangarmenu_max_gas[l];
break;
}
}
} else
hangarkey_up_down[l] = 0;
if (mc_up[l]) {
if (!hangarkey_down_down[l]) {
hangarkey_down_down[l] = 1;
switch (hangarmenu_position[l]) {
case 0:
if (--hangarmenu_bombs[l] < 0)
hangarmenu_bombs[l] = 0;
break;
case 1:
if (!playing_solo && config.unlimited_ammo)
break;
hangarmenu_ammo[l] -= 16;
if (hangarmenu_ammo[l] < 0)
hangarmenu_ammo[l] = 0;
break;
case 2:
if (!playing_solo && config.unlimited_gas)
break;
hangarmenu_gas[l] -= 256;
if (hangarmenu_gas[l] < 2)
hangarmenu_gas[l] = 2;
break;
}
}
} else
hangarkey_down_down[l] = 0;
if (mc_roll[l] || mc_power[l]) {
plane_wants_out[l] = 1;
player_rolling[l] = 0;
player_spinning[l] = 0;
spinning_remaining[l] = 0;
player_last_shot[l] = 0;
hangarmenu_active[l] = 0;
}
if (leveldata.plane_direction[player_tsides[l]]) {
player_x[l] = (hangar_x[player_tsides[l]] + 38) << 8;
player_angle[l] = TAIL_HIT_ANGLE << 8;
player_upsidedown[l] = 0;
} else {
player_x[l] = (hangar_x[player_tsides[l]] + 38) << 8;
player_angle[l] = (180 + 6 - TAIL_HIT_ANGLE) << 8;
player_upsidedown[l] = 1;
}
player_y[l] = (leveldata.airfield_y[player_tsides[l]] - PLANE_MODIFICATION) << 8;
player_on_airfield[l] = player_tsides[l] + 1;
player_was_on_airfield[l] = player_tsides[l] + 1;
controls_power[l] = 0;
player_speed[l] = 0;
player_x_8[l] = player_x[l] >> 8;
player_y_8[l] = player_y[l] >> 8;
controls_up[l] = 0;
controls_down[l] = 0;
player_gas[l] = hangarmenu_gas[l];
player_ammo[l] = hangarmenu_ammo[l];
player_bombs[l] = hangarmenu_bombs[l];
player_endurance[l] = plane_mass[l] >> 3; //4
}
}
void init_sologame(void) {
init_mission(solo_country, solo_mission);
}
int small_warning(const char *message) {
Bitmap *warnkuva;
int flag = 1;
int x, y, n1, n2;
int response = 0;
warnkuva = new Bitmap("WARN2");
while (flag) {
koords(&x, &y, &n1, &n2);
tyhjaa_vircr();
warnkuva->blit(87, 59);
frost->printf(91, 77, message);
cursor->blit(x - 10, y - 10);
do_all();
if (n1 || n2) {
if (x >= 92 && x <= 131 && y >= 115 && y <= 134) {
flag = 0;
response = 1;
}
if (x >= 187 && x <= 226 && y >= 115 && y <= 134) {
flag = 0;
response = 0;
}
}
}
while (n1 || n2) {
koords(&x, &y, &n1, &n2);
nopeuskontrolli();
}
delete warnkuva;
return response;
}
int big_warning(const char *message) {
if (message == NULL)
return 0;
else
return 0;
}
void cause_damage(int amount, int plane) {
player_endurance[plane] -= amount;
if (player_endurance[plane] < 1) {
if (!player_spinning[plane] && !in_closing[plane]) {
if (wrandom(2) == 1 && (!player_on_airfield[plane]))
player_spinning[plane] = 1;
else {
in_closing[plane] = 2;
plane_present[plane] = 0;
start_parts(plane);
if (config.sound_on && config.sfx_on)
play_2d_sample(sample_crash[wrandom(2)], player_x_8[solo_country], player_x_8[plane]);
}
}
}
}
void rotate_water_palet(void) {
int l, l2;
int seivi;
static int nytko = 0;
if (++nytko == 2) {
nytko = 0;
} else
for (l2 = 0; l2 < 3; l2++) {
seivi = ruutu.normaalipaletti[224][l2];
for (l = 0; l < 7; l++) {
ruutu.normaalipaletti[l + 224][l2] = ruutu.normaalipaletti[l + 225][l2];
}
ruutu.normaalipaletti[l + 224][l2] = seivi;
}
setpal_range(&ruutu.normaalipaletti[224], 224, 8, 1);
}
void do_flags(void) {
int l;
for (l = 0; l < MAX_FLAGS; l++)
if (flags_x[l])
if ((++flags_state[l]) >= FLAGS_SPEED) {
flags_state[l] = 0;
flags_frame[l]++;
if (flags_frame[l] > 11)
flags_frame[l] = 0;
}
}
void airfield_checks(void) {
int l, l2;
int yyy, xxx;
for (l = 0; l < 16; l++) {
if (!plane_present[l])
continue;
player_was_on_airfield[l] = 0;
if (!player_upsidedown[l]) {
yyy = 5;
xxx = 5;
} else {
yyy = -5;
xxx = 5;
}
plane_tire_y = ((player_y[l]) + (((-xxx * sinit[player_angle[l] >> 8] + yyy * cosinit[player_angle[l] >> 8] + 128) >> 8) << 8) + 256) >> 8;
player_on_airfield[l] = 0;
for (l2 = 0; l2 < 4; l2++)
if (leveldata.airfield_x[l2] && ((player_x_8[l]) >= leveldata.airfield_x[l2])
&& ((player_x_8[l]) <= (leveldata.airfield_x[l2] + leveldata.airfield_lenght[l2])) && (plane_tire_y >= (leveldata.airfield_y[l2] - 1))) {
if (((player_angle[l] >> 8) <= TAIL_HIT_ANGLE) || ((player_angle[l] >> 8) >= (360 - HIT_ANGLE))) {
if (!player_upsidedown[l]) {
if ((plane_tire_y >= (leveldata.airfield_y[l2]))) {
player_on_airfield[l] = l2 + 1;
player_was_on_airfield[l] = l2 + 1;
} else
player_was_on_airfield[l] = l2 + 1;
}
}
if (((player_angle[l] >> 8) <= (180 + 6 + HIT_ANGLE)) && ((player_angle[l] >> 8) >= (180 + 6 - TAIL_HIT_ANGLE))) {
if (player_upsidedown[l]) {
if ((plane_tire_y >= (leveldata.airfield_y[l2]))) {
player_on_airfield[l] = l2 + 1;
player_was_on_airfield[l] = l2 + 1;
} else
player_was_on_airfield[l] = l2 + 1;
}
}
}
}
}
void init_player(int l, int pommit) {
if (!player_exists[l])
return;
if (playing_solo) {
if (in_closing[l]) {
number_of_planes[l]--;
if (number_of_planes[l] < 0) {
if (l != solo_country) {
in_closing[l] = 0;
plane_present[l] = 0;
player_exists[l] = 0;
return;
}
}
}
}
in_closing[l] = 0;
plane_coming[l] = 0;
plane_present[l] = 0;
plane_wants_in[l] = 0;
player_x_speed[l] = 0;
player_y_speed[l] = 0;
if ((!computer_active[l]) && !(playing_solo && miss_pl_x[l])) {
plane_coming[l] = 1;
hangarmenu_active[l] = 1;
} else {
if (playing_solo && miss_pl_x[l]) {
plane_coming[l] = 0;
plane_present[l] = 1;
if (miss_plane_direction[l]) {
player_x[l] = miss_pl_x[l] << 8;
player_angle[l] = 0;
player_upsidedown[l] = 0;
} else {
player_x[l] = miss_pl_x[l] << 8;
player_angle[l] = 180 << 8;
player_upsidedown[l] = 1;
}
player_y[l] = miss_pl_y[l] << 8;
player_on_airfield[l] = 0;
player_was_on_airfield[l] = 0;
controls_power[l] = 1;
player_speed[l] = 1500;
if (computer_active[l]) {
current_mission[l] = AIM_NOMISSION;
mission_phase[l] = 0;
mission_target[l] = 0;
}
} else {
plane_coming[l] = 1;
plane_wants_out[l] = 1;
if (leveldata.plane_direction[player_tsides[l]]) {
player_x[l] = (hangar_x[player_tsides[l]] + 38) << 8;
player_angle[l] = TAIL_HIT_ANGLE << 8;
player_upsidedown[l] = 0;
} else {
player_x[l] = (hangar_x[player_tsides[l]] + 38) << 8;
player_angle[l] = (180 + 6 - TAIL_HIT_ANGLE) << 8;
player_upsidedown[l] = 1;
}
player_y[l] = (leveldata.airfield_y[player_tsides[l]] - PLANE_MODIFICATION) << 8;
player_on_airfield[l] = player_tsides[l] + 1;
player_was_on_airfield[l] = player_tsides[l] + 1;
controls_power[l] = 0;
player_speed[l] = 0;
if (computer_active[l]) {
current_mission[l] = AIM_TAKEOFF;
mission_phase[l] = 0;
mission_target[l] = 0;
}
}
player_x_8[l] = player_x[l] >> 8;
player_y_8[l] = player_y[l] >> 8;
controls_up[l] = 0;
controls_down[l] = 0;
if (playing_solo) {
switch (fighter[l]) {
case 0:
player_ammo[l] = 0;
player_bombs[l] = plane_bombs[l];
break;
case 1:
player_ammo[l] = plane_ammo[l];
player_bombs[l] = (pommit ? plane_bombs[l] : 0);
break;
case 2:
player_ammo[l] = plane_ammo[l];
player_bombs[l] = 0;
break;
}
} else {
player_ammo[l] = plane_ammo[l];
player_bombs[l] = computer_active[l] ? ((wrandom(mission_duration + 1) < 1440) ? plane_bombs[l] : 0) : (pommit ? plane_bombs[l] : 0);
}
player_gas[l] = plane_gas[l];
player_rolling[l] = 0;
player_spinning[l] = 0;
spinning_remaining[l] = 0;
player_last_shot[l] = 0;
player_endurance[l] = plane_mass[l] >> 3; //4
}
}
int findparameter(const char *jono) {
int laskuri;
for (laskuri = 1; laskuri < parametri_kpl; laskuri++)
if (!strncmp(parametrit[laskuri], jono, strlen(jono)))
return (laskuri);
return (0);
}
void controls(void) {
int l;
for (l = 0; l < 16; l++) {
mc_up[l] = new_mc_up[l];
mc_down[l] = new_mc_down[l];
mc_roll[l] = new_mc_roll[l];
mc_power[l] = new_mc_power[l];
mc_bomb[l] = new_mc_bomb[l];
mc_guns[l] = new_mc_guns[l];
}
//// Recorder
unsigned char rbyte;
int rcount;
if (findparameter("-record")) {
for (rcount = 0; rcount < 16; rcount++) {
rbyte = 0;
rbyte += mc_up[rcount];
rbyte += mc_down[rcount] << 1;
rbyte += mc_roll[rcount] << 2;
rbyte += mc_power[rcount] << 3;
rbyte += mc_bomb[rcount] << 4;
rbyte += mc_guns[rcount] << 5;
record_data[record_counter++] = rbyte;
}
record_random[record_counter >> 4] = wrandom(2147483647);
}
if (findparameter("-playback")) {
for (rcount = 0; rcount < 16; rcount++) {
rbyte = record_data[record_counter++];
mc_up[rcount] = rbyte & 1;
mc_down[rcount] = rbyte & 2;
mc_roll[rcount] = rbyte & 4;
mc_power[rcount] = rbyte & 8;
mc_bomb[rcount] = rbyte & 16;
mc_guns[rcount] = rbyte & 32;
}
if (record_random[record_counter >> 4] != wrandom(2147483647)) {
printf("Random failure at %d\n", record_counter >> 4);
}
}
//// Recorder
if (!(playing_solo && hangarmenu_active[solo_country])) {
for (l = 0; l < 16; l++) {