-
Notifications
You must be signed in to change notification settings - Fork 2
/
ai.qc
1388 lines (1169 loc) · 32.4 KB
/
ai.qc
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
#ifdef SINGLE_PLAYER
// from ai.qc
bool(entity self) FindTarget;
bool(entity self, float dist) ai_checkattack;
//range
typedef enum : int
{
RANGE_MELEE,
RANGE_NEAR,
RANGE_MID,
RANGE_FAR
} range_t;
PROGS_LOCAL bool enemy_vis;
PROGS_LOCAL range_t enemy_range;
PROGS_LOCAL float enemy_yaw;
//============================================================================
/*
=================
AI_SetSightClient
Called once each frame to set level.sight_client to the
player to be checked for in findtarget.
If all clients are either dead or in notarget, sight_client
will be null.
In coop games, sight_client will cycle between the clients.
=================
*/
void() AI_SetSightClient =
{
entity ent;
int start, check;
if (level.sight_client == world)
start = 1;
else
start = level.sight_client.s.number;
check = start;
while (1)
{
check++;
if (check > game.maxclients)
check = 1;
ent = itoe(check);
if (ent.inuse && ent.health > 0 && !(ent.flags & FL_VISIBLE_MASK))
{
level.sight_client = ent;
return; // got one
}
if (check == start)
{
level.sight_client = world;
return; // nobody to see
}
}
}
//============================================================================
// from move.qc
bool(entity ent, float yaw, float dist) M_walkmove;
/*
=============
ai_move
Move the specified distance at current facing.
This replaces the QC functions: ai_forward, ai_back, ai_pain, and ai_painforward
==============
*/
void(entity self, float dist) ai_move =
{
M_walkmove(self, self.s.angles[YAW], dist);
}
// from move.qc
void(entity ent) M_ChangeYaw;
void(entity ent, float dist) M_MoveToGoal;
/*
=============
ai_stand
Used for standing around and looking for players
Distance is for slight position adjustments needed by the animations
==============
*/
void(entity self, float dist) ai_stand =
{
if (dist)
M_walkmove(self, self.s.angles[YAW], dist);
if (self.monsterinfo.aiflags & AI_STAND_GROUND)
{
if (self.enemy)
{
vector v = self.enemy.s.origin - self.s.origin;
self.ideal_yaw = vectoyaw(v);
if (self.s.angles[YAW] != self.ideal_yaw && self.monsterinfo.aiflags & AI_TEMP_STAND_GROUND)
{
self.monsterinfo.aiflags &= ~(AI_STAND_GROUND | AI_TEMP_STAND_GROUND);
self.monsterinfo.run(self);
}
#ifdef GROUND_ZERO
if (!(self.monsterinfo.aiflags & AI_MANUAL_STEERING))
M_ChangeYaw (self);
// find out if we're going to be shooting
bool retval = ai_checkattack (self, 0);
// record sightings of player
if (self.enemy && self.enemy.inuse && visible(self, self.enemy))
{
self.monsterinfo.aiflags &= ~AI_LOST_SIGHT;
self.monsterinfo.last_sighting = self.enemy.s.origin;
self.monsterinfo.blind_fire_target = self.enemy.s.origin;
self.monsterinfo.trail_framenum = level.framenum;
self.monsterinfo.blind_fire_framedelay = 0;
}
// check retval to make sure we're not blindfiring
else if (!retval)
{
FindTarget (self);
return;
}
#else
M_ChangeYaw(self);
ai_checkattack(self, 0);
#endif
}
else
FindTarget(self);
return;
}
if (FindTarget(self))
return;
if (level.framenum > self.monsterinfo.pause_framenum)
{
self.monsterinfo.walk(self);
return;
}
if (!(self.spawnflags & 1) && (self.monsterinfo.idle) && (level.framenum > self.monsterinfo.idle_framenum))
{
if (self.monsterinfo.idle_framenum)
{
self.monsterinfo.idle(self);
self.monsterinfo.idle_framenum = level.framenum + (int)random(15f * BASE_FRAMERATE, 30f * BASE_FRAMERATE);
}
else
self.monsterinfo.idle_framenum = level.framenum + (int)random(15f * BASE_FRAMERATE);
}
}
/*
=============
ai_walk
The monster is walking it's beat
=============
*/
void(entity self, float dist) ai_walk =
{
M_MoveToGoal(self, dist);
// check for noticing a player
if (FindTarget(self))
return;
if ((self.monsterinfo.search) && (level.framenum > self.monsterinfo.idle_framenum)) {
if (self.monsterinfo.idle_framenum) {
self.monsterinfo.search(self);
self.monsterinfo.idle_framenum = level.framenum + (int)random(15f * BASE_FRAMERATE, 30f * BASE_FRAMERATE);
} else {
self.monsterinfo.idle_framenum = level.framenum + (int)random(15f * BASE_FRAMERATE);
}
}
}
/*
=============
ai_charge
Turns towards target and advances
Use this call with a distnace of 0 to replace ai_face
==============
*/
void(entity self, float dist) ai_charge =
{
vector v;
#ifdef GROUND_ZERO
float ofs;
// PMM - made AI_MANUAL_STEERING affect things differently here .. they turn, but
// don't set the ideal_yaw
// This is put in there so monsters won't move towards the origin after killing
// a tesla. This could be problematic, so keep an eye on it.
if(!self.enemy || !self.enemy.inuse)
return;
// save blindfire target
if (visible(self, self.enemy))
self.monsterinfo.blind_fire_target = self.enemy.s.origin;
if (!(self.monsterinfo.aiflags & AI_MANUAL_STEERING))
{
#endif
v = self.enemy.s.origin - self.s.origin;
self.ideal_yaw = vectoyaw(v);
#ifdef GROUND_ZERO
}
#endif
M_ChangeYaw(self);
if (dist)
{
#ifdef GROUND_ZERO
if (self.monsterinfo.aiflags & AI_CHARGING)
{
M_MoveToGoal (self, dist);
return;
}
// circle strafe support
if (self.monsterinfo.attack_state == AS_SLIDING)
{
// if we're fighting a tesla, NEVER circle strafe
if ((self.enemy) && (self.enemy.classname) && (self.enemy.classname == "tesla"))
ofs = 0;
else if (self.monsterinfo.lefty)
ofs = 90f;
else
ofs = -90f;
if (M_walkmove (self, self.ideal_yaw + ofs, dist))
return;
self.monsterinfo.lefty = !self.monsterinfo.lefty;
M_walkmove (self, self.ideal_yaw - ofs, dist);
}
else
#endif
M_walkmove(self, self.s.angles[YAW], dist);
}
}
/*
=============
ai_turn
don't move, but turn towards ideal_yaw
Distance is for slight position adjustments needed by the animations
=============
*/
void(entity self, float dist) ai_turn =
{
if (dist)
M_walkmove(self, self.s.angles[YAW], dist);
if (FindTarget(self))
return;
#ifdef GROUND_ZERO
if (!(self.monsterinfo.aiflags & AI_MANUAL_STEERING))
#endif
M_ChangeYaw(self);
}
/*
.enemy
Will be world if not currently angry at anyone.
.movetarget
The next path spot to walk toward. If .enemy, ignore .movetarget.
When an enemy is killed, the monster will try to return to it's path.
.hunt_time
Set to time + something when the player is in sight, but movement straight for
him is blocked. This causes the monster to use wall following code for
movement direction instead of sighting on the player.
.ideal_yaw
A yaw angle of the intended direction, which will be turned towards at up
to 45 deg / state. If the enemy is in view and hunt_time is not active,
this will be the exact line towards the enemy.
.pausetime
A monster will leave it's stand state and head towards it's .movetarget when
time > .pausetime.
walkmove(angle, speed) primitive is all or nothing
*/
const float MELEE_DISTANCE = 80f;
/*
=============
range
returns the range catagorization of an entity reletive to self
0 melee range, will become hostile even if back is turned
1 visibility and infront, or visibility and show hostile
2 infront and show hostile
3 only triggered by damage
=============
*/
range_t(entity self, entity other) range =
{
vector v;
float len;
v = self.s.origin - other.s.origin;
len = VectorLength(v);
if (len < MELEE_DISTANCE)
return RANGE_MELEE;
if (len < 500)
return RANGE_NEAR;
if (len < 1000)
return RANGE_MID;
return RANGE_FAR;
}
//============================================================================
inline void(entity self, float time) AttackFinished =
{
self.monsterinfo.attack_finished = level.framenum + (int)(time * BASE_FRAMERATE);
}
void(entity self) HuntTarget =
{
vector vec;
self.goalentity = self.enemy;
if (self.monsterinfo.aiflags & AI_STAND_GROUND)
self.monsterinfo.stand(self);
else
self.monsterinfo.run(self);
vec = self.enemy.s.origin - self.s.origin;
self.ideal_yaw = vectoyaw(vec);
// wait a while before first attack
if (!(self.monsterinfo.aiflags & AI_STAND_GROUND))
AttackFinished(self, 1);
}
void(entity self) FoundTarget =
{
// let other monsters see this monster for a while
if (self.enemy.is_client)
{
#ifdef GROUND_ZERO
if (self.enemy.flags & FL_DISGUISED)
self.enemy.flags &= ~FL_DISGUISED;
#endif
level.sight_entity = self;
level.sight_entity_framenum = level.framenum;
level.sight_entity.light_level = 128;
}
self.show_hostile = level.framenum + 1 * BASE_FRAMERATE; // wake up other monsters
self.monsterinfo.last_sighting = self.enemy.s.origin;
self.monsterinfo.trail_framenum = level.framenum;
#ifdef GROUND_ZERO
self.monsterinfo.blind_fire_target = self.enemy.s.origin;
self.monsterinfo.blind_fire_framedelay = 0;
#endif
if (!self.combattarget)
{
HuntTarget(self);
return;
}
self.goalentity = self.movetarget = G_PickTarget(self.combattarget);
if (!self.movetarget)
{
self.goalentity = self.movetarget = self.enemy;
HuntTarget(self);
gi.dprintf("%s at %s, combattarget %s not found\n", self.classname, vtos(self.s.origin), self.combattarget);
return;
}
// clear out our combattarget, these are a one shot deal
self.combattarget = 0;
self.monsterinfo.aiflags |= AI_COMBAT_POINT;
// clear the targetname, that point is ours!
self.movetarget.targetname = 0;
self.monsterinfo.pause_framenum = 0;
// run for it
self.monsterinfo.run(self);
}
/*
===========
FindTarget
Self is currently not attacking anything, so try to find a target
Returns TRUE if an enemy was sighted
When a player fires a missile, the point of impact becomes a fakeplayer so
that monsters that see the impact will respond as if they had seen the
player.
To avoid spending too much time, only a single client (or fakeclient) is
checked each frame. This means multi player games will have slightly
slower noticing monsters.
============
*/
bool(entity self) FindTarget =
{
entity cl;
bool heardit;
int r;
if (self.monsterinfo.aiflags & AI_GOOD_GUY) {
if (self.goalentity && self.goalentity.inuse && self.goalentity.classname) {
if (self.goalentity.classname == "target_actor")
return false;
}
//FIXME look for monsters?
return false;
}
// if we're going to a combat point, just proceed
if (self.monsterinfo.aiflags & AI_COMBAT_POINT)
return false;
// if the first spawnflag bit is set, the monster will only wake up on
// really seeing the player, not another monster getting angry or hearing
// something
// revised behavior so they will wake up if they "see" a player make a noise
// but not weapon impact/explosion noises
heardit = false;
if ((level.sight_entity_framenum >= (level.framenum - 1)) && !(self.spawnflags & 1))
{
cl = level.sight_entity;
if (cl.enemy == self.enemy)
return false;
}
#ifdef GROUND_ZERO
else if (level.disguise_violation_framenum > level.framenum)
cl = level.disguise_violator;
#endif
else if (level.sound_entity_framenum >= (level.framenum - 1)) {
cl = level.sound_entity;
heardit = true;
} else if (!(self.enemy) && (level.sound2_entity_framenum >= (level.framenum - 1)) && !(self.spawnflags & 1)) {
cl = level.sound2_entity;
heardit = true;
} else {
cl = level.sight_client;
if (!cl)
return false; // no clients to get mad at
}
// if the entity went away, forget it
if (!cl.inuse)
return false;
if (cl == self.enemy)
return true; // JDC false;
#ifdef GROUND_ZERO
if ((self.monsterinfo.aiflags & AI_HINT_PATH) && coop.intVal)
heardit = false;
#endif
if (cl.is_client) {
if (cl.flags & FL_NOTARGET)
return false;
} else if (cl.svflags & SVF_MONSTER) {
if (!cl.enemy)
return false;
if (cl.enemy.flags & FL_NOTARGET)
return false;
} else if (heardit) {
if (cl.owner && cl.owner.flags & FL_NOTARGET)
return false;
} else
return false;
if (!heardit) {
r = range(self, cl);
if (r == RANGE_FAR)
return false;
// this is where we would check invisibility
// is client in an spot too dark to be seen?
if (cl.light_level <= 5)
return false;
if (!visible(self, cl)) {
return false;
}
if (r == RANGE_NEAR) {
if (cl.show_hostile < level.framenum && !infront(self, cl)) {
return false;
}
} else if (r == RANGE_MID) {
if (!infront(self, cl)) {
return false;
}
}
self.enemy = cl;
if (self.enemy.classname != "player_noise") {
self.monsterinfo.aiflags &= ~AI_SOUND_TARGET;
if (!self.enemy.is_client) {
self.enemy = self.enemy.enemy;
if (!self.enemy.is_client) {
self.enemy = 0;
return false;
}
}
}
} else { // heardit
vector temp;
if (self.spawnflags & 1) {
if (!visible(self, cl))
return false;
} else {
if (!gi.inPHS(self.s.origin, cl.s.origin))
return false;
}
temp = cl.s.origin - self.s.origin;
if (VectorLength(temp) > 1000) { // too far to hear
return false;
}
// check area portals - if they are different and not connected then we can't hear it
if (cl.areanum != self.areanum)
if (!gi.AreasConnected(self.areanum, cl.areanum))
return false;
self.ideal_yaw = vectoyaw(temp);
#ifdef GROUND_ZERO
if (!(self.monsterinfo.aiflags & AI_MANUAL_STEERING))
#endif
M_ChangeYaw(self);
// hunt the sound for a bit; hopefully find the real player
self.monsterinfo.aiflags |= AI_SOUND_TARGET;
self.enemy = cl;
}
//
// got one
//
#ifdef GROUND_ZERO
// PMM - if we got an enemy, we need to bail out of hint paths, so take over here
if (self.monsterinfo.aiflags & AI_HINT_PATH)
// this calls foundtarget for us
hintpath_stop (self);
else
#endif
FoundTarget(self);
if (!(self.monsterinfo.aiflags & AI_SOUND_TARGET) && (self.monsterinfo.sight))
self.monsterinfo.sight(self, self.enemy);
return true;
}
//=============================================================================
/*
============
FacingIdeal
============
*/
static bool(entity self) FacingIdeal =
{
float delta;
delta = anglemod(self.s.angles[YAW] - self.ideal_yaw);
if (delta > 45 && delta < 315)
return false;
return true;
}
//=============================================================================
bool(entity self) M_CheckAttack =
{
vector spot1, spot2;
float chance;
trace_t tr;
if (self.enemy.health > 0) {
// see if any entities are in the way of the shot
spot1 = self.s.origin;
spot1.z += self.viewheight;
spot2 = self.enemy.s.origin;
spot2.z += self.enemy.viewheight;
gi.traceline(&tr, spot1, spot2, self, CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_SLIME | CONTENTS_LAVA | CONTENTS_WINDOW);
// do we have a clear shot?
if (tr.ent != self.enemy)
{
#ifdef GROUND_ZERO
// PGM - we want them to go ahead and shoot at info_notnulls if they can.
if(self.enemy.solid != SOLID_NOT || tr.fraction < 1.0)
{
// PMM - if we can't see our target, and we're not blocked by a monster, go into blind fire if available
if (!(tr.ent.svflags & SVF_MONSTER) && !visible(self, self.enemy))
{
if ((self.monsterinfo.blindfire) && (self.monsterinfo.blind_fire_framedelay <= (20.0 * BASE_FRAMERATE)))
{
if (level.framenum < self.monsterinfo.attack_finished)
{
return false;
}
if (level.framenum < (self.monsterinfo.trail_framenum + self.monsterinfo.blind_fire_framedelay))
{
// wait for our time
return false;
}
else
{
// make sure we're not going to shoot a monster
gi.traceline(&tr, spot1, self.monsterinfo.blind_fire_target, self, CONTENTS_MONSTER);
if (tr.allsolid || tr.startsolid || ((tr.fraction < 1.0) && (tr.ent != self.enemy)))
return false;
self.monsterinfo.attack_state = AS_BLIND;
return true;
}
}
}
// pmm
#endif
return false;
#ifdef GROUND_ZERO
}
#endif
}
}
// melee attack
if (enemy_range == RANGE_MELEE) {
// don't always melee in easy mode
if (skill.intVal == 0 && (Q_rand() & 3))
{
#ifdef GROUND_ZERO
self.monsterinfo.attack_state = AS_STRAIGHT;
#endif
return false;
}
if (self.monsterinfo.melee)
self.monsterinfo.attack_state = AS_MELEE;
else
self.monsterinfo.attack_state = AS_MISSILE;
return true;
}
// missile attack
if (!self.monsterinfo.attack)
{
#ifdef GROUND_ZERO
self.monsterinfo.attack_state = AS_STRAIGHT;
#endif
return false;
}
if (level.framenum < self.monsterinfo.attack_finished)
return false;
if (enemy_range == RANGE_FAR)
return false;
if (self.monsterinfo.aiflags & AI_STAND_GROUND) {
chance = 0.4f;
} else if (enemy_range == RANGE_MELEE) {
chance = 0.2f;
} else if (enemy_range == RANGE_NEAR) {
chance = 0.1f;
} else if (enemy_range == RANGE_MID) {
chance = 0.02f;
} else {
return false;
}
if (skill.intVal == 0)
chance *= 0.5f;
else if (skill.intVal >= 2)
chance *= 2;
if (random() < chance || self.enemy.solid == SOLID_NOT)
{
self.monsterinfo.attack_state = AS_MISSILE;
self.monsterinfo.attack_finished = level.framenum + (int)random(2f * BASE_FRAMERATE);
return true;
}
if (self.flags & FL_FLY) {
#ifdef GROUND_ZERO
// originally, just 0.3
float strafe_chance;
// if enemy is tesla, never strafe
if (self.enemy && self.enemy.classname == "tesla")
strafe_chance = 0;
else if (self.classname != "monster_daedalus")
strafe_chance = 0.8;
else
strafe_chance = 0.6;
if (random() < strafe_chance)
#else
if (random() < 0.3f)
#endif
self.monsterinfo.attack_state = AS_SLIDING;
else
self.monsterinfo.attack_state = AS_STRAIGHT;
}
#ifdef GROUND_ZERO
else
{
if (random() < 0.4)
self.monsterinfo.attack_state = AS_SLIDING;
else
self.monsterinfo.attack_state = AS_STRAIGHT;
}
#endif
return false;
}
/*
=============
ai_run_melee
Turn and close until within an angle to launch a melee attack
=============
*/
static void(entity self) ai_run_melee =
{
self.ideal_yaw = enemy_yaw;
#ifdef GROUND_ZERO
if (!(self.monsterinfo.aiflags & AI_MANUAL_STEERING))
#endif
M_ChangeYaw(self);
if (FacingIdeal(self)) {
self.monsterinfo.melee(self);
self.monsterinfo.attack_state = AS_STRAIGHT;
}
}
/*
=============
ai_run_missile
Turn in place until within an angle to launch a missile attack
=============
*/
static void(entity self) ai_run_missile =
{
self.ideal_yaw = enemy_yaw;
#ifdef GROUND_ZERO
if (!(self.monsterinfo.aiflags & AI_MANUAL_STEERING))
#endif
M_ChangeYaw(self);
if (FacingIdeal(self)) {
self.monsterinfo.attack(self);
#ifdef GROUND_ZERO
if (self.monsterinfo.attack_state == AS_MISSILE || self.monsterinfo.attack_state == AS_BLIND)
#endif
self.monsterinfo.attack_state = AS_STRAIGHT;
}
}
// temp
#ifdef GROUND_ZERO
const float MAX_SIDESTEP = 8.0;
#endif
/*
=============
ai_run_slide
Strafe sideways, but stay at aproximately the same range
=============
*/
static void(entity self, float distance) ai_run_slide =
{
float ofs;
self.ideal_yaw = enemy_yaw;
#ifdef GROUND_ZERO
if (!(self.monsterinfo.aiflags & AI_MANUAL_STEERING))
M_ChangeYaw(self);
if (!(self.flags & FL_FLY))
distance = minf(distance, MAX_SIDESTEP);
#endif
if (self.monsterinfo.lefty)
ofs = 90f;
else
ofs = -90f;
if (M_walkmove(self, self.ideal_yaw + ofs, distance))
return;
#ifdef GROUND_ZERO
// PMM - if we're dodging, give up on it and go straight
if (self.monsterinfo.aiflags & AI_DODGING)
{
monster_done_dodge (self);
// by setting as_straight, caller will know to try straight move
self.monsterinfo.attack_state = AS_STRAIGHT;
return;
}
#endif
self.monsterinfo.lefty = !self.monsterinfo.lefty;
#ifdef GROUND_ZERO
if (M_walkmove (self, self.ideal_yaw - ofs, distance))
return;
// if we're dodging, give up on it and go straight
if (self.monsterinfo.aiflags & AI_DODGING)
monster_done_dodge (self);
// the move failed, so signal the caller (ai_run) to try going straight
self.monsterinfo.attack_state = AS_STRAIGHT;
#else
M_walkmove(self, self.ideal_yaw - ofs, distance);
#endif
}
/*
=============
ai_checkattack
Decides if we're going to attack or do something else
used by ai_run and ai_stand
=============
*/
bool(entity self, float dist) ai_checkattack =
{
vector temp;
bool hesDeadJim;
// this causes monsters to run blindly to the combat point w/o firing
if (self.goalentity) {
if (self.monsterinfo.aiflags & AI_COMBAT_POINT)
return false;
if (self.monsterinfo.aiflags & AI_SOUND_TARGET) {
if ((level.framenum - self.enemy.last_sound_framenum) > 5.0f * BASE_FRAMERATE) {
if (self.goalentity == self.enemy) {
if (self.movetarget)
self.goalentity = self.movetarget;
else
self.goalentity = null_entity;
}
self.monsterinfo.aiflags &= ~AI_SOUND_TARGET;
if (self.monsterinfo.aiflags & AI_TEMP_STAND_GROUND)
self.monsterinfo.aiflags &= ~(AI_STAND_GROUND | AI_TEMP_STAND_GROUND);
} else {
self.show_hostile = level.framenum + 1 * BASE_FRAMERATE;
return false;
}
}
}
enemy_vis = false;
// see if the enemy is dead
hesDeadJim = false;
if ((!self.enemy) || (!self.enemy.inuse)) {
hesDeadJim = true;
} else if (self.monsterinfo.aiflags & AI_MEDIC) {
if (!(self.enemy.inuse) || self.enemy.health > 0) {
hesDeadJim = true;
}
} else {
if (self.monsterinfo.aiflags & AI_BRUTAL) {
if (self.enemy.health <= -80)
hesDeadJim = true;
} else {
if (self.enemy.health <= 0)
hesDeadJim = true;
}
}
if (hesDeadJim) {
self.monsterinfo.aiflags &= ~AI_MEDIC;
self.enemy = 0;
// FIXME: look all around for other targets
if (self.oldenemy && self.oldenemy.health > 0)
{
self.enemy = self.oldenemy;
self.oldenemy = 0;
HuntTarget(self);
}
#ifdef GROUND_ZERO
// multiple teslas make monsters lose track of the player.
else if (self.monsterinfo.last_player_enemy && self.monsterinfo.last_player_enemy.health > 0)
{
self.enemy = self.monsterinfo.last_player_enemy;
self.oldenemy = 0;
self.monsterinfo.last_player_enemy = 0;
HuntTarget (self);
}
#endif
else
{
if (self.movetarget) {
self.goalentity = self.movetarget;
self.monsterinfo.walk(self);
} else {
// we need the pausetime otherwise the stand code
// will just revert to walking with no target and
// the monsters will wonder around aimlessly trying
// to hunt the world entity
self.monsterinfo.pause_framenum = INT_MAX;
self.monsterinfo.stand(self);
}
return true;
}
}
self.show_hostile = level.framenum + 1 * BASE_FRAMERATE; // wake up other monsters
// check knowledge of enemy
enemy_vis = visible(self, self.enemy);
if (enemy_vis) {
self.monsterinfo.search_framenum = level.framenum + 5 * BASE_FRAMERATE;
self.monsterinfo.last_sighting = self.enemy.s.origin;
#ifdef GROUND_ZERO
// PMM
self.monsterinfo.aiflags &= ~AI_LOST_SIGHT;
self.monsterinfo.trail_framenum = level.framenum;
self.monsterinfo.blind_fire_target = self.enemy.s.origin;
self.monsterinfo.blind_fire_framedelay = 0;
// pmm
#endif
}
enemy_range = range(self, self.enemy);
temp = self.enemy.s.origin - self.s.origin;
enemy_yaw = vectoyaw(temp);
#ifdef GROUND_ZERO
// PMM -- reordered so the monster specific checkattack is called before the run_missle/melee/checkvis