-
Notifications
You must be signed in to change notification settings - Fork 14
/
wordwarvi.c
14406 lines (12872 loc) · 390 KB
/
wordwarvi.c
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
/*
(C) Copyright 2007,2008, Stephen M. Cameron.
This file is part of wordwarvi.
wordwarvi 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 2 of the License, or
(at your option) any later version.
wordwarvi 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 wordwarvi; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifndef __WIN32__
#include <arpa/inet.h> /* for htonl, etc. */
#else
#include <winsock2.h> /* htonl */
#endif /* __WIN32__ */
#include <gdk/gdkkeysyms.h>
#ifdef DO_INHIBIT_SCREENSAVER
#include <gdk/gdkx.h> /* for GDK_WINDOW_XWINDOW, for inhibiting screensaver. */
#endif
#include <stdint.h>
#include <math.h>
#define GNU_SOURCE
#include <getopt.h>
#include "compat.h"
#include "wwviaudio.h"
#include "joystick.h"
#include "rumble.h"
#include "my_point.h"
#include "wwvi_font.h"
#include "version.h"
#include "stamp.h"
#ifdef OPENLASE
#include "libol.h"
#endif
#ifndef DATADIR
#define DATADIR ""
#endif
#ifdef OPENLASE
/* openlase related defines */
#define LASERTOP 0.03
#define LASERBOTTOM 0.97
#define LASERLEFT 0.03
#define LASERRIGHT 0.97
#define LASERWIDTH (LASERRIGHT - LASERLEFT)
#define LASERHEIGHT (LASERBOTTOM - LASERTOP)
#define LASERFRAMERATE (1000)
#define LASERMAXLINES 300
#endif
#ifndef M_PI
#define M_PI (3.14159265)
#endif
#define TWOPI (M_PI * 2.0)
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define DEBUG_HITZONE 0
/* #define DEBUG_TARGET_LIST */
#define MAX_CONCURRENT_SOUNDS (26)
#define NCLIPS 59
/* define sound clip constants */
#define PLAYER_LASER_SOUND 0
#define BOMB_IMPACT_SOUND 1
#define ROCKET_LAUNCH_SOUND 2
#define FLAK_FIRE_SOUND 3
#define LARGE_EXPLOSION_SOUND 4
#define ROCKET_EXPLOSION_SOUND 5
#define LASER_EXPLOSION_SOUND 6
#define GROUND_SMACK_SOUND 7
#define INSERT_COIN_SOUND 8
#define MUSIC_SOUND 9
#define SAM_LAUNCH_SOUND 10
#define THUNDER_SOUND 11
#define INTERMISSION_MUSIC_SOUND 12
#define MISSILE_LOCK_SIREN_SOUND 13
#define CARDOOR_SOUND 14
#define OWMYSPINE_SOUND 15
#define WOOHOO_SOUND 16
#define HELPDOWNHERE_SOUND 17
#define CRONSHOT 18
#define HELPUPHERE_SOUND 19
#define ABDUCTED_SOUND 20
#define CLANG_SOUND 21
#define SCREAM_SOUND 22
#define BODYSLAM_SOUND 23
#define USETHESOURCE_SOUND 24
#define OOF_SOUND 25
#define METALBANG1 26
#define METALBANG2 27
#define METALBANG3 28
#define METALBANG4 29
#define METALBANG5 30
#define METALBANG6 31
#define METALBANG7 32
#define METALBANG8 33
#define STONEBANG1 34
#define STONEBANG2 35
#define STONEBANG3 36
#define STONEBANG4 37
#define STONEBANG5 38
#define STONEBANG6 39
#define STONEBANG7 40
#define STONEBANG8 41
#define CORROSIVE_SOUND 42
#define VOLCANO_ERUPTION 43
#define IT_BURNS 44
#define ZZZT_SOUND 45
#define GRAVITYBOMB_SOUND 46
#define DESTINY_FACEDOWN 47
#define HIGH_SCORE_MUSIC 48
#define JETWASH_SOUND 49
#define TIMPANI_BOING 50
#define NICE_BANK_SHOT 51
#define HOHOHO 52
#define HOHOHO_MERRY_XMAS 53
#define YAY_SANTA 54
#define RADAR_FAIL 55
#define RADAR_READY 56
#define GUNWHEEL 57
#define TESLA_FIRE 58
/* ...End of audio stuff */
#define NHUMANOIDS 4 /* number of vi .swp files, initially */
#define MAXHUMANS 10 /* maxiumum number possible of vi .swp files */
#define RADAR_HEIGHT 60 /* height, in pixels, of radar screen */
#define RADAR_LEFT_MARGIN 10 /* space to leave, in pixels left/right of radar screen to window edge. */
#define RADAR_RIGHT_MARGIN 160 /* space to leave, in pixels left/right of radar screen to window edge. */
#define RADAR_YMARGIN 10 /* space to leave, in pixels from bottom edge of radar to bottom of window */
#define MAX_RADAR_NOISE 2000 /* maximum number of noise pixels placed by radar jammers, increasing */
/* this may adversely affect performance, as this number of x's are */
/* drawn EVERY FRAME when in close proximity to jammer. */
#ifdef OPENLASE
#define FRAME_RATE_HZ 20 /* target frame rate at which gtk callback fires by default */
#else
#define FRAME_RATE_HZ 30 /* target frame rate at which gtk callback fires by default */
#endif
int frame_rate_hz = FRAME_RATE_HZ; /* Actual frame rate, user adjustable. */
#define TERRAIN_LENGTH 1000 /* length, in number of line segments, of terrain */
#define SCREEN_WIDTH 800 /* window width, in pixels */
#define SCREEN_HEIGHT 600 /* window height, in pixels */
#define WORLDWIDTH (SCREEN_WIDTH * 40) /* width of world, 40 screens wide. */
#define KERNEL_Y_BOUNDARY (-1000) /* basically, an arbitrary altitude limit on movement of player. */
#define VOLCANO_XFRACTION (15) /* volcano x pos is 1/VOLCANO_XFRACTION of the way across the world. */
#define LARGE_SCALE_ROUGHNESS (0.04) /* limits roughness, on large scale, of fractal terrain algorithm */
#define SMALL_SCALE_ROUGHNESS (0.09) /* limits roughtness, on small scale, of fractal terrain algorithm */
#define MAXOBJS 8500 /* arbitrary, maximum number of objects in game, ~4000 are commonly seen. */
/* object allocation algorithm uses a bit per object to indicate */
/* free/allocated... how many 32 bit blocks do we need? NBITBLOCKS. */
#define NBITBLOCKS ((MAXOBJS >> 5) + 1) /* 5, 2^5 = 32, 32 bits per int. */
#define LASER_BOLT_DAMAGE 5 /* damage done by flak guns to player */
#define PLAYER_LASER_DAMAGE 20 /* damage done by player's laser (to blimps, clipper ships */
#define NFLAK 10 /* Number of flak guns (laser turrets) */
#define NKGUNS 30 /* Number of Kernel defense guns (laser turrets) */
#define KGUN_INIT_HEALTH 1 /* number of hits it takes to kill kgun. */
#define MAX_KGUN_HEALTH 1 /* An interesting idea, but >1 makes the game too hard. */
#define NROCKETS 20 /* Number of rockets sprinkled into the terrain */
#define NBIGROCKETS 15
#define NJETS 15 /* Number of jets sprinkled into the terrain */
#define LAUNCH_DIST 1200 /* How close player can get in x dimension before rocket launches */
#define BIG_ROCKET_LAUNCH_DIST 200 /* How close player can get in x dimension before rocket launches */
#define MAX_ROCKET_SPEED -32 /* max vertical speed of rocket */
#define SAM_LAUNCH_DIST 400 /* How close player can get in x deminsion before SAM might launch */
#define GDB_LAUNCH_DIST 700 /* How close player can get in x deminsion before GDB might launch */
#define SAM_LAUNCH_CHANCE 15 /* chances out of 100 if in ranch, missile will be launched */
#define PLAYER_SPEED 8 /* max X player speed, in pixels per frame */
#define MAX_VX 15 /* Hmm... another max X player speed? a bug, I think. */
#define MAX_VY 25 /* Max player y speed, pixels per frame. */
#define LASERLEAD (11) /* How many pixels left/right to lead the player in aiming flak guns */
#define LASERLEADX (11) /* How many pixels left/right to lead the player in aiming flak guns */
#define LASERLEADY (0) /* How many pixels up/down to lead the player in aiming flak guns */
#define LASER_SPEED 50 /* Speed of player's laser beams, pixels/frame */
#define LASER_PROXIMITY 300
#define LASER_Y_PROXIMITY 8
#define BOMB_PROXIMITY 10000 /* square root of 30000, how close bomb has to be to be considered a "hit", squared. */
#define BOMB_X_PROXIMITY 100 /* X proximity to hit, for bombs which impact the ground. */
#define CRON_SHOT_CHANCE 40 /* chance out of 100 that cron jobs take a shot if in range, and timer % 10 == 0 */
#define CRON_SHOT_DIST_SQR (300*300) /* 300 pixels dist for cron to consider player "in range" */
#define CRON_DX_THRESHOLD 14 /* dist must be <= this many pixels for cron to consider himself to have */
#define CRON_DY_THRESHOLD 14 /* reached his destination. */
#define CRON_MAX_VX 8 /* max x and y velocities of cron jobs */
#define CRON_MAX_VY 5
#define GDB_DX_THRESHOLD 25 /* dist must be <= this many pixels for gdb to consider himself to have */
#define GDB_DY_THRESHOLD 25 /* reached it's destination. It's large, so they won't just sit on the */
/* player's face. */
#define GDB_MAX_VX 13 /* max x and y velocities of GDBs. */
#define GDB_MAX_VY 13
#define JETPILOT_BIG_DY_THRESHOLD 40
#define JETPILOT_SMALL_DY_THRESHOLD 20
#define JETPILOT_MAX_VX 5
#define JETPILOT_MAX_VY 13
#define NBUILDINGS 15 /* initial number of buildings on the terrain */
#define MAXBUILDING_WIDTH 9 /* max building width, in terrain line segments */
#define NFUELTANKS 20 /* Initial number of fuel tanks sprinkled around the terrain */
/* How many hit points a fuel tank contains */
#define FUELTANK_CAPACITY (game_state.max_player_health / 3)
/* #define REFUEL_RATE 1 */ /* lower numbers = faster, used as modulo of timer */
/* lower numbers = faster, used as modulo of timer */
#define REFUEL_RATE (game_state.max_player_health >= 100 ? 1 : 100/game_state.max_player_health)
/* lower numbers == faster, used as modulo of timer */
#define REFILL_RATE (FUELTANK_CAPACITY <= 30 ? 30/FUELTANK_CAPACITY * frame_rate_hz * 3 : frame_rate_hz * 3)
#define NJAMMERS 1 /* Initial number of radar jammers sprinkled through the terrain */
#define NCRON 15 /* Initial number of cron jobs sprinkeled through the terrain */
#define NSHIPS 1 /* Initial number of clipper ships sprinkeled through the terrain */
#define NGDBS 3 /* Initial number of gdbs sprinkeled through the terrain */
#define NOCTOPI 0 /* Initial number of octopi sprinkled through the terrain */
#define NTENTACLES 2 /* Initial number of tentacles sprinkled through the terrain */
#define NSAMS 3 /* Initial number of SAM stations sprinkled through the terrain */
#define BOMB_SPEED 10 /* differential x velocity of bomb as it leaves player's ship */
#define MAX_ALT 100 /* for "attract mode", max altitude above ground player flies. */
#define MIN_ALT 50 /* for "attract mode", min altitude above ground player flies. */
#define EASY_MAXHEALTH 150 /* Max, and initial health value of player */
#define MEDIUM_MAXHEALTH 100 /* Max, and initial health value of player */
#define HARD_MAXHEALTH 32 /* Max, and initial health value of player */
#define INSANE_MAXHEALTH 10 /* Max, and initial health value of player */
#define BATSHIT_INSANE_MAXHEALTH 3 /* Max, and initial health value of player */
/* If player's health drops below this, the radar goes on the fritz */
#define RADAR_FRITZ_HEALTH (game_state.max_player_health / 4)
#define NAIRSHIPS 1 /* Initial number of blimps sprinkled through the terrain */
#define NBALLOONS 2 /* Initial number of balloons sprinkled through the terrain */
#define NWORMS 2 /* Initial number of worms sprinkled through the terrain */
#define MAX_WORM_VX 8
#define MAX_WORM_VY MAX_WORM_VX
#define MAX_BALLOON_HEIGHT 300 /* these two control blimps, balloons, and clipper ships */
#define MIN_BALLOON_HEIGHT 50 /* limiting their altitude to a range above the ground (pixels) */
#define MAX_MISSILE_VELOCITY 19 /* Max x and y missile/harpoon velocities */
#define MISSILE_DAMAGE 20 /* amount of damage missile/harpoon inflict on player */
#define MISSILE_PROXIMITY 10 /* x and y proximity for missiles to be considered a hit (pixels) */
#define MISSILE_FIRE_PERIOD (frame_rate_hz * 1) /* time which must elapse between firings of missiles */
#define WORM_DAMAGE 5
#define BULLET_SPEED 25 /* max x/y velocities of bullets (cron jobs shoot) */
#define BULLET_DAMAGE 20 /* amount of damage bullets inflict on player */
#define BULLET_PROXIMITY 10 /* x and y proximity for bullet to be considered a hit (pixels) */
#define BULLET_LEAD_TIME 15 /* pixels per unit of velocity to lead player while aiming bullets */
#define HUMANOID_DIST 15 /* proximity to pick up a .swp file */
#define MAX_TENTACLE_SEGS 40 /* max number of segments of a tentacle */
#define MAX_SEG_ANGLE 60 /* max angle a tentacle may bend with the one next to it */
/* macro to compute initial tentacle angles */
#define TENTACLE_RANGE(t) (randomn(t.upper_angle - t.lower_angle) + t.lower_angle)
/* Scoring stuff */
#define DELIVER_PRESENTS_SCORE 1000 /* score for delivering presents (xmas mode) */
#define GROUND_OOPS 64000 /* There are some functions which, given an x value, */
/* return the corresponding y value for the terrain */
/* at that x value. For some values of x, there is */
/* no y. The value returned in that case is GROUND_OOPS */
/* The functions are: find_ground_level() and */
/* approximate_horizon() */
/* some globals... maybe should be in game_state */
int game_pause = 0; /* is game paused? */
int game_pause_help = 0; /* is game in help-pause mode? */
int in_the_process_of_quitting = 0;
int current_quit_selection = 0;
int final_quit_selection = 0;
int attract_mode = 0; /* is game in attract mode */
int credits = 0; /* how many quarters have been put in, but not played? */
int no_colors_any_more = 0;
/* int toggle = 0;
*/
int total_radar_noise; /* count of how much radar noise has been drawn in a given frame */
/* This is to limit things, so if there are 10 radar jammers in */
/* close range, we don't draw 10x the amount of noise necessary */
/* to obscure things. If the radar is totally obscured, obscuring */
/* it 10 more times is wasting cpu. */
int timer = 0; /* monotonically increases by 1 with every frame */
int next_timer = 0; /* when timer reaches this value, timer_expired() is called */
int timer_event = 0; /* timer_expired() switches on this value... */
int sound_device = -1;
/* timer_event values. */
#define BLINK_EVENT 1
#define READY_EVENT 2
#define SET_EVENT 3
#define GO_EVENT 4
#define BLANK_EVENT 5
#define GAME_OVER_EVENT 6
#define BLANK_GAME_OVER_1_EVENT 7
#define INSERT_COIN_EVENT 8
#define BLANK_GAME_OVER_2_EVENT 9
#define GAME_ENDED_EVENT 10
#define GAME_ENDED_EVENT_2 11
#define CREDITS1_EVENT 12
#define CREDITS2_EVENT 13
#define INTRO1_EVENT 14
#define INTRO2_EVENT 15
#define START_INTERMISSION_EVENT 16
#define END_INTERMISSION_EVENT 17
#define KEYS1_EVENT 18
#define KEYS2_EVENT 19
#define START_HIGHSCORES_EVENT 20
#define END_HIGHSCORES_EVENT 21
#define NEW_HIGH_SCORE_PRE_EVENT 22
#define NEW_HIGH_SCORE_PRE2_EVENT 23
#define NEW_HIGH_SCORE_EVENT 24
int nomusic = 0;
int sound_working = 0;
int round_explosions = 0;
int spherical_explosions = 1;
int explosion_factor = 1;
int brightsparks = 0; /* controls preference for how to draw sparks */
int xmas_mode = 0;
int thicklines = 0; /* controls preference for how to draw lines. */
int nframes = 0; /* count of total frames drawn, used for calculating actual frame rate */
struct timeval start_time, end_time; /* start and end time of game, for calc'ing frame rate */
unsigned int free_obj_bitmap[NBITBLOCKS] = {0}; /* bitmaps for object allocater free/allocated status */
int jsfd = -1;
#define NCOLORS 10 /* number of "cardinal" colors */
#define NSPARKCOLORS 25 /* 25 shades from yellow to red for the sparks */
#define NRAINBOWSTEPS (16)
#define NRAINBOWCOLORS (NRAINBOWSTEPS*3)
GdkColor huex[NCOLORS + NSPARKCOLORS + NRAINBOWCOLORS]; /* all the colors we have to work with are in here */
GdkColor *sparkcolor; /* a pointer into the huex[] array where the spark colors begin */
GdkColor *rainbow_color; /* a pointer into the huex[] array where the rainbow colors begin */
/* cardinal color indexes into huex array */
#define WHITE 0
#define BLUE 1
#define BLACK 2
#define GREEN 3
#define YELLOW 4
#define RED 5
#define ORANGE 6
#define CYAN 7
#define MAGENTA 8
#define DARKGREEN 9
int planet_color[] = {
RED, GREEN, YELLOW, ORANGE, MAGENTA, CYAN, WHITE
};
#include "levels.h"
int score_table[256]; /* table of scores for each object type. */
int kill_tally[256]; /* tally of various things killed */
void init_score_table(void)
{
memset(score_table, 0, sizeof(score_table));
score_table[OBJ_TYPE_AIRSHIP] = -5000;
score_table[OBJ_TYPE_JET] = 2000;
score_table[OBJ_TYPE_BALLOON] = 3000;
score_table[OBJ_TYPE_CRON] = 400;
score_table[OBJ_TYPE_FUEL] = 0;
score_table[OBJ_TYPE_SHIP] = 10000;
score_table[OBJ_TYPE_GUN] = 400;
score_table[OBJ_TYPE_HUMAN] = 1000;
score_table[OBJ_TYPE_MISSILE] = 50;
score_table[OBJ_TYPE_HARPOON] = 50;
score_table[OBJ_TYPE_ROCKET] = 100;
score_table[OBJ_TYPE_BIG_ROCKET] = 400;
score_table[OBJ_TYPE_SAM_STATION] = 400;
score_table[OBJ_TYPE_BRIDGE] = 10;
score_table[OBJ_TYPE_GDB] = 400;
score_table[OBJ_TYPE_OCTOPUS] = 880;
score_table[OBJ_TYPE_TENTACLE] = 100;
score_table[OBJ_TYPE_JAMMER] = 100;
score_table[OBJ_TYPE_WORM] = 30;
score_table[OBJ_TYPE_KGUN] = 400;
score_table[OBJ_TYPE_JETPILOT] = 300;
}
void init_kill_tally(void)
{
memset(kill_tally, 0, sizeof(kill_tally));
}
int current_level = 0; /* current level of the game, starts at zero */
struct level_parameters_t {
int random_seed; /* so the games always have the same terrain, setup, etc. */
int level_number;
/* numbers of various objects on a given level */
int nhumanoids;
int nbridges;
int nbuildings;
int nrockets;
int nbigrockets;
int njets;
int nflak;
int nfueltanks;
int njammers;
int ncron;
int nships;
int ngdbs;
int noctopi;
int ntentacles;
int nballoons;
int nsams;
/* int nbombs; */
/* int ngbombs; */
int nairships;
int nworms;
int nkguns;
int kgun_health;
/* how often flak guns (laser turrets) fire. */
int laser_fire_chance;
/* how the terrain looks. Starts out smooth, later levels more mountainous */
double large_scale_roughness;
double small_scale_roughness;
int ground_color;
int jetpilot_firechance;
} level = {
/* initial values */
31415927, /* This value is not used */
0,
NHUMANOIDS,
NBRIDGES,
NBUILDINGS,
NROCKETS,
NBIGROCKETS,
NJETS,
NFLAK,
NFUELTANKS,
NJAMMERS,
NCRON,
NSHIPS,
NGDBS,
NOCTOPI,
NTENTACLES,
NBALLOONS,
NSAMS,
/* NBOMBS, */
/* NGBOMBS, */
NAIRSHIPS,
NWORMS,
NKGUNS,
KGUN_INIT_HEALTH,
AVERAGE_LASER,
LARGE_SCALE_ROUGHNESS,
SMALL_SCALE_ROUGHNESS,
0,
AGGRESSIVE_LASER,
};
/* vxy_2_dxy is a 2d array which translates a vx and vy velocity vextor
* into an x,y vector in the same direction but a fixed magnitude. The array
* caches precomputed values. This is used for drawing the missiles. If the
* missiles are travelling at vx, vy, then this array allows us to compute x,y
* offsets to draw the missile pointing in the right direction with just a
* table lookup. See init_vxy_2_dxy() function, below. */
#define MAX_VELOCITY_TO_COMPUTE 31
#define V_MAGNITUDE (20.0)
struct my_point_t vxy_2_dxy[MAX_VELOCITY_TO_COMPUTE+1][MAX_VELOCITY_TO_COMPUTE+1];
/* these hold cached values of sine and cosine functions for 0-360 degress */
double sine[361];
double cosine[361];
/* Below, arrays of points telling how to draw the various objects in */
/* the game. */
struct my_point_t kgun_points[] = {
{ -10, -25 },
{ -10, -5 },
{ 10, -5 },
{ 10, -25 },
{ -10, -5 },
{ -7, 5 },
{ 7, 5 },
{ 10, -5 },
{ -10, -25 },
};
struct my_point_t inverted_kgun_points[] = {
{ -10, 25 },
{ -10, 5 },
{ 10, 5 },
{ 10, 25 },
{ -10, 5 },
{ -7, -5 },
{ 7, -5 },
{ 10, 5 },
{ -10, 25 },
};
struct my_point_t tesla_points[] = {
{ -10, -25 },
{ -10, -5 },
{ 10, -5 },
{ 10, -25 },
{ -10, -5 },
{ -7, 5 },
{ 7, 5 },
{ 10, -5 },
{ -10, -25 },
{ LINE_BREAK, LINE_BREAK },
{ -7, 5 },
{ -2, 40 },
{ -5, 42 },
{ -2, 44 },
{ 2, 44 },
{ 5, 42 },
{ 2, 40 },
{ 7, 5 },
};
struct my_point_t octopus_points[] = {
{ 7, 0 },
{ 10, -5 },
{ 15, -25 },
{ 10, -30 },
{ -10, -30 },
{ -15, -25 },
{ -10, -5 },
{ -7, 0 },
{ LINE_BREAK, LINE_BREAK },
{ -8, -10 },
{ -4, -7 },
{ LINE_BREAK, LINE_BREAK },
{ 8, -10 },
{ 4, -7 }
};
struct my_point_t bullet_points[] = {
{ -4, 0 },
{ 0, -4 },
{ 4, 0 },
{ 0, 4 },
{ -4, 0 },
{ 4, 0 },
{ LINE_BREAK, LINE_BREAK },
{ 0, -4 },
{ 0, 4},
};
struct my_point_t gdb_points_left[] = {
{ 10, 0 },
{ 5, 0 },
{ -15, 5 },
{ -20, 0 },
{ -20, -5 },
{ 0, -15, },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, GREEN },
{ -20, -5 },
{ -18, -12 },
{ -10, -16 },
{ -3, -15 },
{ 0, -15, },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, CYAN },
{ 0, -15, },
{ 0, 15 },
{ -5, 20 },
{ -10, 20 },
{ LINE_BREAK, LINE_BREAK },
{ 15, -22 },
{ 0, -15 },
{ 0, 0 },
{ 15, 0 },
{ 15, -22 },
{ 15, -45 },
{ 18, -45 },
{ 18, -22 },
{ 18, 0 },
{ 33, 0 },
{ 33, -15 },
{ 18, -22 },
};
struct my_point_t gdb_points_right[] = {
{ 10, 0 },
{ 5, 0 },
{ -15, 5 },
{ -20, 0 },
{ -20, -5 },
{ 0, -15, },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, GREEN },
{ -20, -5 },
{ -18, -12 },
{ -10, -16 },
{ -3, -15 },
{ 0, -15, },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, CYAN },
{ 0, -15, },
{ 0, 15 },
{ -5, 20 },
{ -10, 20 },
{ LINE_BREAK, LINE_BREAK },
{ 15, -22 },
{ 0, -15 },
{ 0, 0 },
{ 15, 0 },
{ 15, -22 },
{ 15, -45 },
{ 18, -45 },
{ 18, -22 },
{ 18, 0 },
{ 33, 0 },
{ 33, -15 },
{ 18, -22 },
};
struct my_point_t humanoid_points[] = {
{ -1, 0 }, /* waist */
{ 1, 0 },
{ 4, -6 }, /* shoulders */
{ -4, -6 },
{ -1, 0 },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, CYAN },
{ -1, 0 }, /* left leg */
{ -3, 4 },
{ -3, 7 },
{ LINE_BREAK, LINE_BREAK },
{ 1, 0 }, /* right leg */
{ 3, 4 },
{ 3, 7 },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, MAGENTA },
{ 4, -6, }, /* right arm */
{ 6, -3 },
{ 6, 1 },
{ LINE_BREAK, LINE_BREAK },
{ -4, -6, }, /* left arm */
{ -6, -3 },
{ -6, 1 },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, ORANGE },
{ -1, -7 }, /* head */
{ -1, -9 },
{ 1, -9, },
{ 1, -7 },
};
struct my_point_t jetpilot_points_left[] = {
{ COLOR_CHANGE, GREEN },
{ 0, -8 },
{ 0, 0 },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, CYAN },
{ 0, 0 },
{ -2, 5 },
{ 0, 9 },
{ LINE_BREAK, LINE_BREAK },
{ 2, 0 },
{ 0, 5 },
{ 2, 9 },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, GREEN },
/* { 0, 9 }, */
/* { -2, 11 }, */
{ 2, 9 },
{ -1, 11 },
{ 0, 9 },
{ 2, 9 },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, WHITE },
{ -2, -1 }, /* gun */
{ -5, -1 },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, YELLOW },
{ 0, -8, },
{ 2, -8, },
{ 2, -5, },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, ORANGE },
{ 2, -5, },
{ 0, -5, },
{ 0, -8, },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, WHITE },
{ 2, -5, }, /* jetpack */
{ 4, -5, },
{ 4, -0, },
{ 4, -0, },
{ 2, -0, },
{ 2, -5, },
{ LINE_BREAK, LINE_BREAK },
{ 3, 0 }, /* nozzle */
{ 2, 2 },
{ 4, 2},
{ 3, 0},
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, GREEN },
{ 1, -5 }, /* arm */
{ 3, -1 },
{ -2, 0 },
};
struct my_point_t jetpilot_points_right[ARRAY_SIZE(jetpilot_points_left)];
struct my_point_t SAM_station_points[] = {
{ -5, 0 }, /* Bottom base */
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, RED },
{ -5, 0 }, /* Bottom base */
{ -5, -10 },
{ 5, 0 },
{ 5, -10 },
{ -5, 0 },
{ 5, 0 },
{ LINE_BREAK, LINE_BREAK },
{ -5, -10 }, /* middle base */
{ -5, -20 },
{ 5, -10 },
{ 5, -20 },
{ -5, -10 },
{ 5, -10 },
{ LINE_BREAK, LINE_BREAK },
{ -5, -20 }, /* Top base */
{ -5, -30 },
{ 5, -20 },
{ 5, -30 },
{ -5, -20 },
{ 5, -20 },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, WHITE },
{ -5, -30 },
{ 5, -30 },
{ LINE_BREAK, LINE_BREAK },
{ -3, -30 }, /* Base of radar */
{ 0, -35, },
{ 3, -30 },
{ LINE_BREAK, LINE_BREAK },
{ 0, -35, }, /* Radar dish */
{ 10, -45 },
{ 13, -59 },
{ LINE_BREAK, LINE_BREAK },
{ 0, -35, }, /* Radar dish */
{ -10, -25, },
{ -25, -22, },
{ 13, -59 },
{ LINE_BREAK, LINE_BREAK },
{ 0, -35, }, /* Radar dish */
{ -15, -50, }, /* Radar dish */
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, WHITE },
{ 20, 0 }, /* Little building */
{ 20, -50 },
{ 30, -50 },
{ 30, 0 },
};
struct my_point_t SAM_station_debris_points[] = {
{ -5, 0 }, /* Bottom base */
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, RED },
{ -5, 0 }, /* Bottom base */
{ -5, -10 },
{ 5, 0 },
{ 5, -10 },
{ -5, 0 },
{ 5, 0 },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, WHITE },
{ 20, 0 }, /* Little building */
{ 20, -10 },
{ 30, -13 },
{ 30, 0 },
};
struct my_point_t airship_points[] = {
{ -70, -50 }, /* tip of nose */
{ -60, -60 },
{ -50, -65 },
{ -40, -67 },
{ -30, -70 }, /* top left */
{ 30, -70 }, /* top right */
{ 40, -67 },
{ 50, -65 },
{ 60, -60 },
{ 70, -50 },
{ LINE_BREAK, LINE_BREAK },
/* Now the same shape, but with y displacement to make bottom of blimp */
{ -70, -50 }, /* tip of nose */
{ -60, -40 },
{ -50, -35 },
{ -40, -33 },
{ -30, -30 }, /* bottom left */
{ 30, -30 }, /* bottom right */
{ 40, -33 },
{ 50, -35 },
{ 60, -40 },
{ 70, -50 }, /* back point */
{ LINE_BREAK, LINE_BREAK },
{ 60, -60 }, /* top tail */
{ 70, -70 },
{ 90, -70 },
{ 90, -60 },
{ 70, -50 }, /* back point */
{ 90, -40 },
{ 90, -30 },
{ 70, -30 },
{ 60, -40 },
{ LINE_BREAK, LINE_BREAK }, /* central tail fin */
{ 60, -50 } ,
{ 90, -50 },
{ LINE_BREAK, LINE_BREAK }, /* Gondola */
{ -10, -30 },
{ -5, -20 },
{ 10, -20 },
{ 10, -30 },
};
struct my_point_t balloon_points[] = {
{ 0, -100 },
{ -20, -98 },
{ -35, -90 },
{ -45, -80 },
{ -47, -70 },
{ -47, -60 },
{ -40, -50 },
{ -8, -20 },
{ -8, -10 },
{ 8, -10 },
{ 8, -20 },
{ 40, -50 },
{ 47, -60 },
{ 47, -70 },
{ 45, -80 },
{ 35, -90 },
{ 20, -98 },
{ 0, -100 },
{ LINE_BREAK, LINE_BREAK }, /* Gondola strings */
{ -8, -10 },
{ -5, 5, },
{ 5, 5, },
{ 8, -10 },
{ LINE_BREAK, LINE_BREAK }, /* Gondola */
{ -5, 5,},
{ -5, 0,},
{ 5, 0,},
{ 5, 5,},
};
struct my_point_t spark_points[] = {
{ -1,-1 },
{ -1, 1},
{ 1, 1 },
{ 1, -1 },
{ -1, -1 },
#if 0
{ 0, 0 },
{ 0, 10 },
{ 10, 10 },
{ 10, 0 },
{ 0, 0 },
#endif
};
struct my_point_t cron_points[] = {
{ -10, -15 },
{ 10, -15 },
{ 15, -8 },
{ 10, 0 },
{ -10, 0 },
{ -15, -8 },
{ -10, -15 },
{ LINE_BREAK, LINE_BREAK },
{ 0, 10 },
{ 7, 5 },
{ 7, 17 },
{ 10, 30 },
{ 7, 37 },
{ LINE_BREAK, LINE_BREAK },
{ 0, 10 },
{ -7, 5 },
{ -7, 17 },
{ -10, 30 },
{ -7, 37 },
{ LINE_BREAK, LINE_BREAK },
{ 0, 0 },
{ 0, 30 },
{ LINE_BREAK, LINE_BREAK },
{ 7, -15 },
{ 7, -25 },
{ LINE_BREAK, LINE_BREAK },
{ 9, -15 },
{ 9, -35 },
};
struct my_point_t jammer_points[] = {
{ -10, 0 },
{ 10, 0 },
{ 10, -10 },
{ 5, -10 },
{ 3, -15 },
{ -3, -15 },
{ -5, -10 },
{ -10, -10 },
{ -10, 0 },
};
struct my_point_t jammer_debris_points[] = {
{ -10, 0 },
{ 10, 0 },
{ 10, -6 },
{ 5, -2 },
{ 3, -7 },
{ -3, -0 },
{ -7, -3 },
{ -10, -4 },
{ -10, 0 },
};
struct my_point_t present_points[] = {
{ -10, -5 },
{ -10, 5 },
{ 0, 10 },
{ 10, 5 },
{ 10, -5 },
{ 0, -10 },
{ -10, -5 },
{ 0, 0 },
{ 10, -5 },
{ LINE_BREAK, LINE_BREAK },
{ 0, 0 },
{ 0, 10 },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, RED },
{ -5, 7 },
{ -5, -3 },
{ 5, -7 },
{ LINE_BREAK, LINE_BREAK },
{ COLOR_CHANGE, RED },
{ 5, 7 },
{ 5, -3 },
{ -5, -7 },
};
struct my_point_t house_points[] = {
{ -30, -10 },
{ -30, 25 },
{ 30, 25 },
{ 30, -10},
{ LINE_BREAK, LINE_BREAK },
{ -5, 25 }, /* door */