-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemy.c
6744 lines (5997 loc) · 200 KB
/
enemy.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
/*
Lacewing
Copyright (C) 2003 Linley Henzell & Captain Pork
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public Licence as published by
the Free Software Foundation; either version 2 of the Licence, 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 Licence for more details.
You should have received a copy of the GNU General Public Licence
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The GPL version 2 is included in this distribution in a file called
LICENCE.TXT. Use any text editor or the TYPE command to read it.
You should be able to reach us by sending an email to
File: enemy.c
History:
6/10/2003 - Version 1.0 finalised
This file contains:
- most functions relating to enemies
This is a really badly written file. There's no excuse at all for large
parts of it, in particular all of those move_<whatever> functions. I'm
reasonably pleased with most of the Lacewing code (at least, compared to
some of my earlier crimes against C), but for some reason I can't be
bothered fixing up this tangled, redundancy-filled mess. Oh well.
*/
#define ALLEGRO_NO_CLEAR_BITMAP_ALIAS
#define ALLEGRO_NO_VHLINE_ALIAS
#include "allegro.h"
#include <math.h>
#include "config.h"
#include "globvars.h"
#include "stuff.h"
#include "cloud.h"
#include "palette.h"
#include "bullet.h"
#include "pickup.h"
#include "sound.h"
#include "actor.h"
#include "levels.h"
#define HIVE_MIN_RANGE 200000
#define HIVE_MAX_RANGE 500000
/*
NOTE:
Firebases & Hives should always be enemy[0], so that they never overwrite
another enemy on the screen
*/
// int add_enemy - adds an appropriate enemy
int create_enemy(int type, int subtype, int x, int y,
int x_speed, int y_speed, int angle, int carrying_pickup, int special [10],
int target);
int create_turret(int type, int base, int turret_counter);
void manage_enemy(int e);
int move_enemy(int e);
int detect_collision(int e);//, int things [2]);
void enemy_explodes(int e);
void register_destroyed(int e, int cause);
void destroy_enemy(int e);
int move_crawler(int e);
int move_faller(int e);
int move_bouncers(int e);
int move_stinger(int e);
int move_stinger2(int e);
int move_stinger3(int e);
int move_stinger4(int e);
int move_hurler(int e);
int move_hurler2(int e);
int move_hurler3(int e);
int move_swerver(int e);
int move_swerver3(int e);
int move_drifter(int e);
int move_hive(int e);
int move_bee(int e);
int move_curver(int e);
int move_wanderer(int e);
int move_minethrower(int e);
int move_minethrower2(int e);
int move_dead_wanderer(int e);
int move_dead_fighter(int e);
int move_jelly(int e);
int move_cloaker(int e);
int move_superjelly(int e);
int move_flakker(int e);
int move_bolter(int e);
int move_torper(int e);
int move_fighter(int e);
int move_fighter4(int e);
int move_fighter4_turret(int e);
int move_torper2(int e);
int move_firebase(int e);
int move_firebase_turret(int e);
int move_firebase2(int e);
int move_firebase2_turret1(int e);
int move_firebase2_turret2(int e);
int move_firebase3(int e);
int move_firebase3_turret(int e);
int move_blaster_turret(int e);
int move_blaster(int e);
int move_boss1(int e);
int move_boss1_turret(int e); // turret1 & 2
int move_boss2(int e);
int move_boss2_turret(int e);
int move_boss3(int e);
int move_boss3_turret(int e);
int move_boss4(int e);
int move_boss4_turret(int e);
int metamorphosis(int e);
//int turn_towards_angle(int angle, int tangle, int turning);
//int turn_towards_xy(int x1, int y1, int x2, int y2, int angle, int turning);
void accelerate_enemy(int e, int angle, int impulse);
void drag_enemy(int e, float drag_amount);
int track_target(int e, int attacking, int turning);
void standard_attack(int e, int angle);
int near_angle(int angle1, int angle2);
void find_firebase_start_point(int location [2]);
void find_crawly_start_point(int location [2]);
void find_target_start_point(int location [2]);
int spawn_enemy(int type, int subtype, int carrying_pickup, int target);
void move_sun(int e);
int hurt_enemy(int e, int hurty, int source, char pulse);
void score_kill(int etype, int subtype, int p);
int check_for_targets(void);
enum
{
ESOUND_NONE,
ESOUND_EXPLODE1,
ESOUND_EXPLODE2,
ESOUND_WOBBLE,
ESOUND_LONG_WOBBLE,
ESOUND_WARP_IN,
ESOUND_STING,
ESOUND_HARD_ZAP,
ESOUND_BOSS2,
ESOUND_BLORT,
ESOUND_STING4,
ESOUND_BLAST,
ESOUND_ZAPNOTE1,
ESOUND_ZAPNOTE2,
ESOUND_MINE,
ESOUND_SHORTZAP,
ESOUND_SHORTZAP2,
ESOUND_BLAT,
ESOUND_SUN,
ESOUND_BOSS1,
ESOUND_CROAK,
ESOUND_GREENSEEKER1,
ESOUND_GREENSEEKER2,
ESOUND_TORPEDO,
ESOUND_BOSS3_1,
ESOUND_BOSS3_2,
ESOUND_BOSS3_3,
ESOUND_PLASMA,
ESOUND_SEEKMINE,
ESOUND_ORBITAL,
ESOUND_MISSILE,
ESOUND_MINEBANG,
ESOUND_MUTATE
};
void enemy_sound(int e, int sound);
void enemy_soundf(int e, int sound, int freq);
void init_enemies(void)
{
int e;
for (e = 0; e < NO_ENEMIES; e++)
{
enemy[e].type = ENEMY_NONE;
enemy[e].target = TARGET_NO;
}
}
int create_enemy(int type, int subtype, int x, int y,
int x_speed, int y_speed, int angle, int carrying_pickup, int special [10],
int target)
{
int e = 0;
for (e = 0; e < NO_ENEMIES; e++)
{
if (e == NO_ENEMIES - 1) return -1;
if (enemy[e].type == ENEMY_NONE) break;
}
enemy[e].type = type;
enemy[e].x = x;
enemy[e].y = y;
enemy[e].x_speed = x_speed;
enemy[e].y_speed = y_speed;
enemy[e].angle = grand(ANGLE_FULL); //angle;
enemy[e].moving_angle = angle;
enemy[e].armour = eclass[type].max_armour;
enemy[e].hurt_pulse = 0;
enemy[e].radius = eclass[type].radius;
enemy[e].edge_radius = eclass[type].edge_radius;
enemy[e].shield = eclass[type].max_shield;
enemy[e].mass = eclass[type].mass;
enemy[e].drag_amount = 0;
enemy[e].subtype = subtype;
enemy[e].attacking = ATTACK_NONE;
enemy[e].counter = 256 - counter;
enemy[e].recycle = 50;
// enemy[e].attacking = 0;
enemy[e].just_collided = 0;
enemy[e].carrying_pickup = carrying_pickup;
enemy[e].target = target;
enemy[e].burst_fire = 0;
// REMEMBER: enemies are also created in create_turret()
switch(subtype)
{
case SUBTYPE_NONE:
switch(type)
{
default:
case ENEMY_STINGER:
case ENEMY_BOSS1:
enemy[e].colours [0] = COLOUR_GREEN6;
enemy[e].colours [1] = COLOUR_GREEN1;
break;
case ENEMY_MINETHROWER:
case ENEMY_SUN:
case ENEMY_FIGHTER3:
case ENEMY_DEAD_FIGHTER3:
case ENEMY_FIREBASE2:
case ENEMY_DRIFTER2:
case ENEMY_FLAKKER:
case ENEMY_FLAKKER2:
case ENEMY_BOLTER:
case ENEMY_HURLER3:
enemy[e].colours [0] = COLOUR_RED6;
enemy[e].colours [1] = COLOUR_RED1;
break;
case ENEMY_SUN_GREEN:
case ENEMY_FIGHTER:
case ENEMY_DEAD_FIGHTER:
enemy[e].colours [0] = COLOUR_GREEN6;
enemy[e].colours [1] = COLOUR_GREEN1;
break;
case ENEMY_MINETHROWER2:
case ENEMY_SUN_BLUE:
case ENEMY_CURVER:
case ENEMY_STINGER3:
case ENEMY_FIGHTER4:
case ENEMY_BOLTER2:
case ENEMY_BOSS3:
case ENEMY_BOSS3_TURRET1:
case ENEMY_BOSS3_TURRET2:
case ENEMY_TORPER2:
enemy[e].colours [0] = COLOUR_BLUE6;
enemy[e].colours [1] = COLOUR_BLUE2;
break;
case ENEMY_WANDERER:
case ENEMY_DRIFTER:
case ENEMY_JELLY:
case ENEMY_STINGER2:
case ENEMY_FIREBASE:
case ENEMY_BEE:
case ENEMY_HIVE:
case ENEMY_TORPER:
case ENEMY_HURLER:
enemy[e].colours [0] = COLOUR_YELLOW6;
enemy[e].colours [1] = COLOUR_YELLOW1;
break;
case ENEMY_CLOAKER:
enemy[e].colours [0] = COLOUR_YELLOW1;
enemy[e].colours [1] = COLOUR_YELLOW1;
break;
case ENEMY_CLOAKER2:
enemy[e].colours [0] = COLOUR_PURPLE1;
enemy[e].colours [1] = COLOUR_PURPLE1;
break;
case ENEMY_STINGER4:
enemy[e].colours [0] = COLOUR_PURPLE6;
enemy[e].colours [1] = COLOUR_PURPLE1;
break;
case ENEMY_BLASTER:
case ENEMY_FIREBASE3:
case ENEMY_FIREBASE3_TURRET:
case ENEMY_SUPERJELLY:
case ENEMY_BOSS4:
case ENEMY_BOSS4_TURRET:
enemy[e].colours [0] = COLOUR_GREY6;
enemy[e].colours [1] = COLOUR_GREY2;
break;
/* case ENEMY_DEAD_FIGHTER:
enemy[e].colours [0] = COLOUR_GREY4;
enemy[e].colours [1] = COLOUR_GREY1;
break;*/
case ENEMY_FIGHTER2:
case ENEMY_DEAD_FIGHTER2:
case ENEMY_BOSS2:
case ENEMY_BOSS2_TURRET:
case ENEMY_HURLER2:
enemy[e].colours [0] = COLOUR_ORANGE6;
enemy[e].colours [1] = COLOUR_ORANGE1;
break;
case ENEMY_DRIFTER3:
enemy[e].colours [0] = COLOUR_PURPLE6;
enemy[e].colours [1] = COLOUR_PURPLE1;
break;
}
break;
case SUBTYPE_GREEN:
enemy[e].colours [0] = COLOUR_GREEN6;
enemy[e].colours [1] = COLOUR_GREEN1;
break;
case SUBTYPE_YELLOW:
enemy[e].colours [0] = COLOUR_YELLOW6;
enemy[e].colours [1] = COLOUR_YELLOW1;
enemy[e].armour *= 15; enemy[e].armour /= 10;
break;
case SUBTYPE_ORANGE:
enemy[e].colours [0] = COLOUR_ORANGE6;
enemy[e].colours [1] = COLOUR_ORANGE1;
enemy[e].armour *= 25; enemy[e].armour /= 10;
break;
case SUBTYPE_RED:
enemy[e].colours [0] = COLOUR_RED6;
enemy[e].colours [1] = COLOUR_RED1;
enemy[e].armour *= 30; enemy[e].armour /= 10;
break;
case SUBTYPE_BLUE:
enemy[e].colours [0] = COLOUR_BLUE6;
enemy[e].colours [1] = COLOUR_BLUE1;
enemy[e].armour *= 35; enemy[e].armour /= 10;
break;
case SUBTYPE_PURPLE:
enemy[e].colours [0] = COLOUR_PURPLE6;
enemy[e].colours [1] = COLOUR_PURPLE1;
enemy[e].armour *= 40; enemy[e].armour /= 10;
break;
case SUBTYPE_WHITE:
enemy[e].colours [0] = COLOUR_GREY6;
enemy[e].colours [1] = COLOUR_GREY2;
enemy[e].armour *= 50; enemy[e].armour /= 10;
break;
}
enemy[e].hurt_pulse_colour1 = enemy[e].colours [0];
enemy[e].hurt_pulse_colour2 = enemy[e].colours [1];
int i, j;
for (i = 0; i < NO_ENEMY_ATTRIBUTES; i ++)
{
enemy[e].attribute [i] = eclass[type].default_attributes [i];
}
switch(enemy[e].type)
{
case ENEMY_CRAWLER:
case ENEMY_CRAWLER2:
case ENEMY_CRAWLER3:
case ENEMY_CRAWLER4:
enemy[e].attribute [ATTRIB_CRAWLER_AXIS] = 1;
enemy[e].attribute [ATTRIB_CRAWLER_SPEED] = 805 + subtype * 250;
// crawler speed shouldn't be a multiple of GRAIN
if (enemy[e].attribute [ATTRIB_CRAWLER_SPEED] % GRAIN == 0)
enemy[e].attribute [ATTRIB_CRAWLER_SPEED] += 5;
break;
case ENEMY_FALLER:
enemy[e].attribute [ATTRIB_FALLER_SPEED] = 1105 + subtype * 200;
// enemy[e].attribute [ATTRIB_FALLER_SECTIONS] = 4; //grand(4);
enemy[e].attribute [ATTRIB_FALLER_SECTIONS] = grand(arena.level / 2); //grand(4);
if (game.type == GAME_DUEL)
enemy[e].attribute [ATTRIB_FALLER_SECTIONS] = grand(arena.crawlies_created) / 5;
if (enemy[e].attribute [ATTRIB_FALLER_SECTIONS] > 4)
enemy[e].attribute [ATTRIB_FALLER_SECTIONS] = 4;
enemy[e].attribute [ATTRIB_FALLER_ARMOUR] = 300 + subtype * 150;
break;
case ENEMY_SWERVER:
enemy[e].attribute [ATTRIB_SWERVER_ANGLE] = ANGLE_QUARTER; // MUST be divisible into ANGLE_FULL
enemy[e].attribute [ATTRIB_SWERVER_TURN] = 16; // MUST be divisible into ANGLE_FULL AND whatever SWERVER_ANGLE defaults to
enemy[e].attribute [ATTRIB_SWERVER_SPEED] = 1600 + subtype * 350;
break;
case ENEMY_SWERVER2:
enemy[e].attribute [ATTRIB_SWERVER_ANGLE] = ANGLE_QUARTER; // MUST be divisible into ANGLE_FULL
enemy[e].attribute [ATTRIB_SWERVER_TURN] = 16; // MUST be divisible into ANGLE_FULL AND whatever SWERVER_ANGLE defaults to
enemy[e].attribute [ATTRIB_SWERVER_SPEED] = 1800 + subtype * 350;
break;
case ENEMY_SWERVER3:
enemy[e].attribute [ATTRIB_SWERVER_ANGLE] = ANGLE_QUARTER; // MUST be divisible into ANGLE_FULL
enemy[e].attribute [ATTRIB_SWERVER_TURN] = 16; // MUST be divisible into ANGLE_FULL AND whatever SWERVER_ANGLE defaults to
enemy[e].attribute [ATTRIB_SWERVER_SPEED] = 1800 + subtype * 350;
enemy[e].attribute [ATTRIB_SWERVER3_ANGLE2] = 0;
enemy[e].attribute [ATTRIB_SWERVER3_ATTACKING] = ATTACK_NONE;
break;
case ENEMY_SUN:
enemy[e].hurt_pulse_colour1 = COLOUR_YELLOW6;
enemy[e].hurt_pulse_colour2 = COLOUR_YELLOW3;
enemy[e].attribute [ATTRIB_SUN_COUNTER] = 6000;
enemy[e].attribute [ATTRIB_SUN_COUNT_SPEED] = 0;
enemy[e].attribute [ATTRIB_SUN_COUNT_START] = 6000;
break;
case ENEMY_SUN_GREEN:
enemy[e].hurt_pulse_colour1 = COLOUR_YELLOW6;
enemy[e].hurt_pulse_colour2 = COLOUR_YELLOW3;
enemy[e].attribute [ATTRIB_SUN_COUNTER] = 5000;
enemy[e].attribute [ATTRIB_SUN_COUNT_SPEED] = 0;
enemy[e].attribute [ATTRIB_SUN_COUNT_START] = 5000;
break;
case ENEMY_SUN_BLUE:
enemy[e].hurt_pulse_colour1 = COLOUR_GREY6;
enemy[e].hurt_pulse_colour2 = COLOUR_GREY3;
enemy[e].attribute [ATTRIB_SUN_COUNTER] = 4000;
enemy[e].attribute [ATTRIB_SUN_COUNT_SPEED] = 0;
enemy[e].attribute [ATTRIB_SUN_COUNT_START] = 4000;
break;
case ENEMY_WANDERER:
enemy[e].attribute [ATTRIB_WANDERER_NEXT_MINE] = 250;
enemy[e].attribute [ATTRIB_WANDERER_X_DEST] = grand(arena.max_x - 40000) + 20000;
enemy[e].attribute [ATTRIB_WANDERER_Y_DEST] = grand(arena.max_y - 40000) + 20000;
enemy[e].burst_fire = 3 + grand(4);
enemy[e].angle = grand(ANGLE_FULL);
break;
case ENEMY_FIGHTER:
enemy[e].attribute [ATTRIB_FIGHTER_THRUST] = 100;
enemy[e].attribute [ATTRIB_FIGHTER_MODE] = FIGHTER_MOVE;
enemy[e].attribute [ATTRIB_FIGHTER_TURN] = 16;
enemy[e].attribute [ATTRIB_FIGHTER_X_DEST] = grand(arena.max_x - 40000) + 20000;
enemy[e].attribute [ATTRIB_FIGHTER_Y_DEST] = grand(arena.max_y - 40000) + 20000;
enemy[e].burst_fire = 0;
enemy[e].angle = grand(ANGLE_FULL);
break;
case ENEMY_FIGHTER2:
enemy[e].attribute [ATTRIB_FIGHTER_THRUST] = 150;
enemy[e].attribute [ATTRIB_FIGHTER_MODE] = FIGHTER_MOVE;
enemy[e].attribute [ATTRIB_FIGHTER_TURN] = 20;
enemy[e].attribute [ATTRIB_FIGHTER_X_DEST] = grand(arena.max_x - 40000) + 20000;
enemy[e].attribute [ATTRIB_FIGHTER_Y_DEST] = grand(arena.max_y - 40000) + 20000;
enemy[e].burst_fire = 3 + grand(4);
enemy[e].angle = grand(ANGLE_FULL);
break;
case ENEMY_FIGHTER3:
enemy[e].attribute [ATTRIB_FIGHTER_THRUST] = 200;
enemy[e].attribute [ATTRIB_FIGHTER_MODE] = FIGHTER_MOVE;
enemy[e].attribute [ATTRIB_FIGHTER_TURN] = 24;
enemy[e].attribute [ATTRIB_FIGHTER_X_DEST] = grand(arena.max_x - 40000) + 20000;
enemy[e].attribute [ATTRIB_FIGHTER_Y_DEST] = grand(arena.max_y - 40000) + 20000;
enemy[e].burst_fire = 0;
enemy[e].angle = grand(ANGLE_FULL);
break;
case ENEMY_BLASTER:
j = create_turret(ENEMY_BLASTER_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_BLASTER_TURRET1] = j;
if (j != -1) // sanity check
{
enemy[j].x = enemy[e].x - 15*GRAIN;
enemy[j].y = enemy[e].y - 10*GRAIN;
}
j = create_turret(ENEMY_BLASTER_TURRET, e, 256 - counter - 50);
enemy[e].attribute [ATTRIB_BLASTER_TURRET2] = j;
if (j != -1) // sanity check
{
enemy[j].x = enemy[e].x - 15*GRAIN;
enemy[j].y = enemy[e].y - 10*GRAIN;
}
enemy[e].angle = grand(ANGLE_FULL);
break;
case ENEMY_FIGHTER4:
enemy[e].attribute [ATTRIB_FIGHTER_THRUST] = 80;
enemy[e].attribute [ATTRIB_FIGHTER_MODE] = FIGHTER_MOVE;
enemy[e].attribute [ATTRIB_FIGHTER_TURN] = 8;
enemy[e].attribute [ATTRIB_FIGHTER_X_DEST] = grand(arena.max_x - 40000) + 20000;
enemy[e].attribute [ATTRIB_FIGHTER_Y_DEST] = grand(arena.max_y - 40000) + 20000;
j = create_turret(ENEMY_FIGHTER4_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_FIGHTER4_TURRET1] = j;
if (j != -1) // sanity check
{
enemy[j].x = enemy[e].x - 15*GRAIN;
enemy[j].y = enemy[e].y - 10*GRAIN;
}
j = create_turret(ENEMY_FIGHTER4_TURRET, e, 256 - counter - 50);
enemy[e].attribute [ATTRIB_FIGHTER4_TURRET2] = j;
if (j != -1) // sanity check
{
enemy[j].x = enemy[e].x - 15*GRAIN;
enemy[j].y = enemy[e].y - 10*GRAIN;
}
enemy[e].angle = grand(ANGLE_FULL);
break;
case ENEMY_FIREBASE:
j = create_turret(ENEMY_FIREBASE_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_FIREBASE_TURRET1] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 51*GRAIN;
enemy[j].y = enemy[e].y - 0*GRAIN;
}
j = create_turret(ENEMY_FIREBASE_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_FIREBASE_TURRET2] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x + 51*GRAIN;
enemy[j].y = enemy[e].y - 0*GRAIN;
}
j = create_turret(ENEMY_FIREBASE_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_FIREBASE_TURRET3] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 0*GRAIN;
enemy[j].y = enemy[e].y - 51*GRAIN;
}
j = create_turret(ENEMY_FIREBASE_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_FIREBASE_TURRET4] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 0*GRAIN;
enemy[j].y = enemy[e].y + 51*GRAIN;
}
enemy[e].angle = grand(ANGLE_FULL);
break;
case ENEMY_BOSS1:
j = create_turret(ENEMY_BOSS1_TURRET2, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS1_TURRET3] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 35*GRAIN;
enemy[j].y = enemy[e].y - 35*GRAIN;
}
/* j = create_turret(ENEMY_BOSS1_TURRET1, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS1_TURRET4] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x + 35*GRAIN;
enemy[j].y = enemy[e].y - 35*GRAIN;
}*/
j = create_turret(ENEMY_BOSS1_TURRET2, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS1_TURRET1] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 51*GRAIN;
enemy[j].y = enemy[e].y + 50*GRAIN;
}
j = create_turret(ENEMY_BOSS1_TURRET2, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS1_TURRET2] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x + 51*GRAIN;
enemy[j].y = enemy[e].y + 50*GRAIN;
}
enemy[e].angle = grand(ANGLE_FULL);
enemy[e].attribute [ATTRIB_BOSS1_X_DEST] = grand(arena.max_x - 300000) + 150000;
enemy[e].attribute [ATTRIB_BOSS1_Y_DEST] = grand(arena.max_y - 300000) + 150000;
break;
case ENEMY_BOSS2:
j = create_turret(ENEMY_BOSS2_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS2_TURRET1] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 51*GRAIN;
enemy[j].y = enemy[e].y + 50*GRAIN;
}
j = create_turret(ENEMY_BOSS2_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS2_TURRET2] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x + 51*GRAIN;
enemy[j].y = enemy[e].y + 50*GRAIN;
}
j = create_turret(ENEMY_BOSS2_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS2_TURRET3] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 35*GRAIN;
enemy[j].y = enemy[e].y - 35*GRAIN;
}
j = create_turret(ENEMY_BOSS2_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS2_TURRET4] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x + 35*GRAIN;
enemy[j].y = enemy[e].y - 35*GRAIN;
}
enemy[e].angle = grand(ANGLE_FULL);
enemy[e].attribute [ATTRIB_BOSS2_DELTA_SPIN] = 1;
enemy[e].attribute [ATTRIB_BOSS2_TURRETS_LEFT] = 4;
enemy[e].attribute [ATTRIB_BOSS2_X_DEST] = grand(arena.max_x - 300000) + 150000;
enemy[e].attribute [ATTRIB_BOSS2_Y_DEST] = grand(arena.max_y - 300000) + 150000;
break;
case ENEMY_BOSS3:
j = create_turret(ENEMY_BOSS3_TURRET1, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS3_TURRET1] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 51*GRAIN;
enemy[j].y = enemy[e].y + 50*GRAIN;
}
j = create_turret(ENEMY_BOSS3_TURRET1, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS3_TURRET2] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x + 51*GRAIN;
enemy[j].y = enemy[e].y + 50*GRAIN;
}
j = create_turret(ENEMY_BOSS3_TURRET1, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS3_TURRET3] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 35*GRAIN;
enemy[j].y = enemy[e].y - 35*GRAIN;
}
j = create_turret(ENEMY_BOSS3_TURRET2, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS3_TURRET4] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x + 35*GRAIN;
enemy[j].y = enemy[e].y - 35*GRAIN;
}
j = create_turret(ENEMY_BOSS3_TURRET2, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS3_TURRET5] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x + 35*GRAIN;
enemy[j].y = enemy[e].y - 35*GRAIN;
}
enemy[e].angle = grand(ANGLE_FULL);
// enemy[e].attribute [ATTRIB_BOSS2_DELTA_SPIN] = 1;
// enemy[e].attribute [ATTRIB_BOSS2_TURRETS_LEFT] = 4;
// enemy[e].attribute [ATTRIB_BOSS2_X_DEST] = grand(arena.max_x - 300000) + 150000;
// enemy[e].attribute [ATTRIB_BOSS2_Y_DEST] = grand(arena.max_y - 300000) + 150000;
break;
case ENEMY_BOSS4:
j = create_turret(ENEMY_BOSS4_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS4_TURRET1] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 51*GRAIN;
enemy[j].y = enemy[e].y + 50*GRAIN;
}
j = create_turret(ENEMY_BOSS4_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS4_TURRET2] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x + 51*GRAIN;
enemy[j].y = enemy[e].y + 50*GRAIN;
}
j = create_turret(ENEMY_BOSS4_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS4_TURRET3] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 35*GRAIN;
enemy[j].y = enemy[e].y - 35*GRAIN;
}
j = create_turret(ENEMY_BOSS4_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_BOSS4_TURRET4] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x + 35*GRAIN;
enemy[j].y = enemy[e].y - 35*GRAIN;
}
enemy[e].angle = grand(ANGLE_FULL);
enemy[e].attribute [ATTRIB_BOSS4_X_DEST] = grand(arena.max_x - 300000) + 150000;
enemy[e].attribute [ATTRIB_BOSS4_Y_DEST] = grand(arena.max_y - 300000) + 150000;
// enemy[e].attribute [ATTRIB_BOSS2_DELTA_SPIN] = 1;
// enemy[e].attribute [ATTRIB_BOSS2_TURRETS_LEFT] = 4;
// enemy[e].attribute [ATTRIB_BOSS2_X_DEST] = grand(arena.max_x - 300000) + 150000;
// enemy[e].attribute [ATTRIB_BOSS2_Y_DEST] = grand(arena.max_y - 300000) + 150000;
break;
case ENEMY_FIREBASE3:
j = create_turret(ENEMY_FIREBASE3_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_FIREBASE3_TURRET1] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 35*GRAIN;
enemy[j].y = enemy[e].y - 36*GRAIN;
}
j = create_turret(ENEMY_FIREBASE3_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_FIREBASE3_TURRET2] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x + 35*GRAIN;
enemy[j].y = enemy[e].y - 36*GRAIN;
}
j = create_turret(ENEMY_FIREBASE3_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_FIREBASE3_TURRET3] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x + 35*GRAIN;
enemy[j].y = enemy[e].y + 36*GRAIN;
}
j = create_turret(ENEMY_FIREBASE3_TURRET, e, 256 - counter);
enemy[e].attribute [ATTRIB_FIREBASE3_TURRET4] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 35*GRAIN;
enemy[j].y = enemy[e].y + 36*GRAIN;
}
enemy[e].angle = grand(ANGLE_FULL);
break;
case ENEMY_FIREBASE2:
j = create_turret(ENEMY_FIREBASE2_TURRET1, e, 256 - counter);
enemy[e].attribute [ATTRIB_FIREBASE2_TURRET1] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x - 0*GRAIN;
enemy[j].y = enemy[e].y - 25*GRAIN;
}
j = create_turret(ENEMY_FIREBASE2_TURRET2, e, 256 - counter);
enemy[e].attribute [ATTRIB_FIREBASE2_TURRET2] = j;
if (j != -1)
{
enemy[j].x = enemy[e].x + 0*GRAIN;
enemy[j].y = enemy[e].y + 25*GRAIN;
}
enemy[e].angle = grand(ANGLE_FULL);
break;
case ENEMY_DRIFTER:
enemy[e].attribute [ATTRIB_DRIFTER_RANGE] = 100000;
enemy[e].attribute [ATTRIB_DRIFTER_ACCEL] = 180;
enemy[e].angle = grand(ANGLE_FULL);
enemy[e].attribute [ATTRIB_DRIFTER_X_DEST] = grand(arena.max_x - 300000) + 150000;
enemy[e].attribute [ATTRIB_DRIFTER_Y_DEST] = grand(arena.max_y - 300000) + 150000;
break;
case ENEMY_HIVE:
enemy[e].attribute [ATTRIB_HIVE_ATTACK13] = ATTACK_NONE;
enemy[e].attribute [ATTRIB_HIVE_ATTACK24] = ATTACK_NONE;
/* enemy[e].attribute [ATTRIB_HIVE_BEE1] = -1;
enemy[e].attribute [ATTRIB_HIVE_BEE2] = -1;
enemy[e].attribute [ATTRIB_HIVE_BEE3] = -1;
enemy[e].attribute [ATTRIB_HIVE_BEE4] = -1;
enemy[e].angle = grand(ANGLE_FULL);*/
break;
case ENEMY_BEE:
enemy[e].attribute [ATTRIB_BEE_HIVE] = special [0];
enemy[e].attribute [ATTRIB_BEE_MODE] = BEE_RESTING;
enemy[e].attribute [ATTRIB_BEE_NUMBER] = special [1];
enemy[e].attribute [ATTRIB_BEE_RANGE] = 200;
break;
case ENEMY_DRIFTER2:
enemy[e].attribute [ATTRIB_DRIFTER_RANGE] = 125000;
enemy[e].attribute [ATTRIB_DRIFTER_ACCEL] = 185;
enemy[e].angle = grand(ANGLE_FULL);
enemy[e].attribute [ATTRIB_DRIFTER_X_DEST] = grand(arena.max_x - 300000) + 150000;
enemy[e].attribute [ATTRIB_DRIFTER_Y_DEST] = grand(arena.max_y - 300000) + 150000;
break;
case ENEMY_DRIFTER3:
enemy[e].attribute [ATTRIB_DRIFTER_RANGE] = 150000;
enemy[e].attribute [ATTRIB_DRIFTER_ACCEL] = 190;
enemy[e].attribute [ATTRIB_DRIFTER3_ORBITAL_DIR] = 32;
if (grand(2) == 0)
enemy[e].attribute [ATTRIB_DRIFTER3_ORBITAL_DIR] = -32;
enemy[e].angle = grand(ANGLE_FULL);
enemy[e].attribute [ATTRIB_DRIFTER_X_DEST] = grand(arena.max_x - 300000) + 150000;
enemy[e].attribute [ATTRIB_DRIFTER_Y_DEST] = grand(arena.max_y - 300000) + 150000;
break;
case ENEMY_CLOAKER:
enemy[e].attribute [ATTRIB_CLOAKER_ACCEL] = 150;
enemy[e].angle = grand(ANGLE_FULL);
enemy[e].attribute [ATTRIB_CLOAKER_X_DEST] = grand(arena.max_x - 300000) + 150000;
enemy[e].attribute [ATTRIB_CLOAKER_Y_DEST] = grand(arena.max_y - 300000) + 150000;
break;
case ENEMY_CLOAKER2:
enemy[e].attribute [ATTRIB_CLOAKER_ACCEL] = 210;
enemy[e].angle = grand(ANGLE_FULL);
enemy[e].attribute [ATTRIB_CLOAKER_X_DEST] = grand(arena.max_x - 300000) + 150000;
enemy[e].attribute [ATTRIB_CLOAKER_Y_DEST] = grand(arena.max_y - 300000) + 150000;
break;
case ENEMY_BOLTER:
case ENEMY_BOLTER2:
enemy[e].attribute [ATTRIB_BOLTER_SPIN] = 1;
enemy[e].attribute [ATTRIB_BOLTER_DELTA_SPIN] = 1;
break;
case ENEMY_TORPER2:
enemy[e].attribute [ATTRIB_TORPER2_X_DEST] = grand(arena.max_x - 300000) + 150000;
enemy[e].attribute [ATTRIB_TORPER2_Y_DEST] = grand(arena.max_y - 300000) + 150000;
break;
default:
// enemy[e].angle = grand(ANGLE_FULL);
break;
/* case ENEMY_BOUNCER2:
case ENEMY_BOUNCER3:
case ENEMY_BOUNCER4:
break;*/
}
return e;
}
int create_turret(int type, int base, int turret_counter)
{
int e = 0;
for (e = 0; e < NO_ENEMIES; e++)
{
if (e == NO_ENEMIES - 1) return -1;
if (enemy[e].type == ENEMY_NONE) break;
}
enemy[e].type = type;
enemy[e].x = enemy[base].x;
enemy[e].y = enemy[base].y;
enemy[e].x_speed = enemy[base].x_speed;
enemy[e].y_speed = enemy[base].y_speed;
enemy[e].angle = enemy[base].angle;
enemy[e].moving_angle = enemy[base].angle;
enemy[e].armour = eclass[type].max_armour;
enemy[e].hurt_pulse = 0;
enemy[e].radius = eclass[type].radius;
enemy[e].edge_radius = eclass[type].edge_radius;
enemy[e].shield = eclass[type].max_shield;
enemy[e].mass = eclass[type].mass;
enemy[e].drag_amount = 0;
enemy[e].subtype = 0;
enemy[e].attacking = ATTACK_NONE;
enemy[e].counter = 256 - counter + turret_counter;
enemy[e].recycle = enemy[e].counter;
// enemy[e].attacking = 0;
enemy[e].just_collided = 0;
enemy[e].carrying_pickup = 0;
enemy[e].target = TARGET_NO;
enemy[e].burst_fire = 0;
int i;
for (i = 0; i < NO_ENEMY_ATTRIBUTES; i ++)
{
enemy[e].attribute [i] = eclass[type].default_attributes [i];
}
switch(type)
{
default:
case ENEMY_FIGHTER4_TURRET:
enemy[e].colours [0] = COLOUR_BLUE6;
enemy[e].colours [1] = COLOUR_BLUE1;
enemy[e].attribute [ATTRIB_FI4TURRET_MAIN] = base;
enemy[e].attribute [ATTRIB_FI4TURRET_MAIN_DEAD] = 0;
break;
case ENEMY_BLASTER_TURRET:
enemy[e].colours [0] = COLOUR_BLUE6;
enemy[e].colours [1] = COLOUR_BLUE1;
enemy[e].attribute [ATTRIB_BTURRET_MAIN] = base;
enemy[e].attribute [ATTRIB_BTURRET_MAIN_DEAD] = 0;
break;
case ENEMY_FIREBASE_TURRET:
enemy[e].colours [0] = COLOUR_YELLOW6;
enemy[e].colours [1] = COLOUR_YELLOW1;
enemy[e].attribute [ATTRIB_FBTURRET_MAIN] = base;
enemy[e].attribute [ATTRIB_FBTURRET_MAIN_DEAD] = 0;
break;
case ENEMY_BOSS2_TURRET:
enemy[e].colours [0] = COLOUR_YELLOW6;
enemy[e].colours [1] = COLOUR_YELLOW1;
enemy[e].attribute [ATTRIB_BO2TURRET_MAIN] = base;
enemy[e].attribute [ATTRIB_BO2TURRET_MAIN_DEAD] = 0;
break;
case ENEMY_BOSS3_TURRET1:
case ENEMY_BOSS3_TURRET2:
enemy[e].colours [0] = COLOUR_BLUE6;
enemy[e].colours [1] = COLOUR_BLUE1;
enemy[e].attribute [ATTRIB_BO3TURRET_MAIN] = base;
enemy[e].attribute [ATTRIB_BO3TURRET_MAIN_DEAD] = 0;
break;
case ENEMY_BOSS4_TURRET:
enemy[e].colours [0] = COLOUR_GREY6;
enemy[e].colours [1] = COLOUR_GREY1;
enemy[e].attribute [ATTRIB_BO4TURRET_MAIN] = base;
enemy[e].attribute [ATTRIB_BO4TURRET_MAIN_DEAD] = 0;
break;
case ENEMY_FIREBASE2_TURRET1:
case ENEMY_FIREBASE2_TURRET2:
enemy[e].colours [0] = COLOUR_RED6;
enemy[e].colours [1] = COLOUR_RED1;
enemy[e].attribute [ATTRIB_FB2TURRET_MAIN] = base;
enemy[e].attribute [ATTRIB_FB2TURRET_MAIN_DEAD] = 0;
break;
case ENEMY_FIREBASE3_TURRET:
enemy[e].colours [0] = COLOUR_GREY6;
enemy[e].colours [1] = COLOUR_GREY1;
enemy[e].attribute [ATTRIB_FB3TURRET_MAIN] = base;
enemy[e].attribute [ATTRIB_FB3TURRET_MAIN_DEAD] = 0;
break;
case ENEMY_BOSS1_TURRET1:
case ENEMY_BOSS1_TURRET2:
enemy[e].colours [0] = COLOUR_GREEN6;
enemy[e].colours [1] = COLOUR_GREEN1;
enemy[e].attribute [ATTRIB_BO1TURRET_MAIN] = base;
enemy[e].attribute [ATTRIB_BO1TURRET_MAIN_DEAD] = 0;
break;
}
enemy[e].hurt_pulse_colour1 = enemy[e].colours [0];
enemy[e].hurt_pulse_colour2 = enemy[e].colours [1];
enemy[e].angle = grand(ANGLE_FULL);
return e;
}
void run_enemies(void)
{
int e;
for (e = 0; e < NO_ENEMIES; e++)
{
if (enemy[e].type != ENEMY_NONE)
manage_enemy(e);
}
}
void manage_enemy(int e)
{
if (enemy[e].hurt_pulse > 0)
enemy[e].hurt_pulse --;
if (enemy[e].recycle > 0)
enemy[e].recycle --;
if (enemy[e].just_collided > 0)
enemy[e].just_collided --;
enemy[e].counter ++; // assumed: this wraps at 256 (unsigned char)
char need_move_enemy = 1;
switch(enemy[e].type)
{
case ENEMY_CRAWLER:
case ENEMY_CRAWLER2:
case ENEMY_CRAWLER3:
case ENEMY_CRAWLER4:
move_crawler(e);
need_move_enemy = 0;
break;
case ENEMY_FALLER:
move_faller(e);
need_move_enemy = 0;
break;
case ENEMY_STINGER:
move_stinger(e);
break;
case ENEMY_STINGER2:
move_stinger2(e);
break;
case ENEMY_STINGER3:
move_stinger3(e);
break;
case ENEMY_STINGER4:
move_stinger4(e);
break;
case ENEMY_HURLER:
case ENEMY_HURLER2:
move_hurler(e);
break;
case ENEMY_HURLER3:
move_hurler3(e);
break;
case ENEMY_SWERVER:
case ENEMY_SWERVER2:
move_swerver(e);
need_move_enemy = 0;
break;
case ENEMY_SWERVER3:
move_swerver3(e);