-
Notifications
You must be signed in to change notification settings - Fork 1
/
g_ai.c
1201 lines (991 loc) · 27.2 KB
/
g_ai.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
/*
Copyright (C) 1997-2001 Id Software, Inc.
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 2
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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// g_ai.c
#include "g_local.h"
//SWB - KOTS Includes
#include "kots_monster.h"
qboolean FindTarget (edict_t *self);
extern cvar_t *maxclients;
qboolean ai_checkattack (edict_t *self, float dist);
qboolean enemy_vis;
qboolean enemy_infront;
int enemy_range;
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 (void)
{
edict_t *ent;
int start, check;
if (level.sight_client == NULL)
start = 1;
else
start = level.sight_client - g_edicts;
check = start;
while (1)
{
check++;
if (check > game.maxclients)
check = 1;
ent = &g_edicts[check];
if (ent->inuse
&& ent->health > 0
&& !(ent->flags & FL_NOTARGET)
//SWB - can't sight chars not logged in or cloaked
&& ent->character->is_loggedin
&& !ent->character->is_cloaked
)
{
level.sight_client = ent;
return; // got one
}
if (check == start)
{
level.sight_client = NULL;
return; // nobody to see
}
}
}
//============================================================================
/*
=============
ai_move
Move the specified distance at current facing.
This replaces the QC functions: ai_forward, ai_back, ai_pain, and ai_painforward
==============
*/
void ai_move (edict_t *self, float dist)
{
M_walkmove (self, self->s.angles[YAW], dist);
}
/*
=============
ai_stand
Used for standing around and looking for players
Distance is for slight position adjustments needed by the animations
==============
*/
void ai_stand (edict_t *self, float dist)
{
vec3_t v;
if (dist)
M_walkmove (self, self->s.angles[YAW], dist);
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
{
if (self->enemy)
{
VectorSubtract (self->enemy->s.origin, self->s.origin, v);
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);
}
M_ChangeYaw (self);
ai_checkattack (self, 0);
}
else
FindTarget (self);
return;
}
if (FindTarget (self))
return;
//SWB - find a new goal
if (Kots_MonsterFindGoal(self))
return;
//SWB - Keep the monster moving
if (level.time > self->monsterinfo.pausetime)
{
self->monsterinfo.walk (self);
return;
}
if (!(self->spawnflags & 1) && (self->monsterinfo.idle) && (level.time > self->monsterinfo.idle_time))
{
if (self->monsterinfo.idle_time)
{
self->monsterinfo.idle (self);
self->monsterinfo.idle_time = level.time + 15 + random() * 15;
}
else
{
self->monsterinfo.idle_time = level.time + random() * 15;
}
}
}
/*
=============
ai_walk
The monster is walking it's beat
=============
*/
void ai_walk (edict_t *self, float dist)
{
M_MoveToGoal (self, dist);
// check for noticing a player
if (FindTarget (self))
return;
if ((self->monsterinfo.search) && (level.time > self->monsterinfo.idle_time))
{
if (self->monsterinfo.idle_time)
{
self->monsterinfo.search (self);
self->monsterinfo.idle_time = level.time + 15 + random() * 15;
}
else
{
self->monsterinfo.idle_time = level.time + random() * 15;
}
}
}
/*
=============
ai_charge
Turns towards target and advances
Use this call with a distnace of 0 to replace ai_face
==============
*/
void ai_charge (edict_t *self, float dist)
{
vec3_t v;
VectorSubtract (self->enemy->s.origin, self->s.origin, v);
self->ideal_yaw = vectoyaw(v);
M_ChangeYaw (self);
if (dist)
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 ai_turn (edict_t *self, float dist)
{
if (dist)
M_walkmove (self, self->s.angles[YAW], dist);
if (FindTarget (self))
return;
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
*/
/*
=============
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
=============
*/
int range (edict_t *self, edict_t *other)
{
vec3_t v;
float len;
VectorSubtract (self->s.origin, other->s.origin, v);
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;
}
/*
=============
visible
returns 1 if the entity is visible to self, even if not infront ()
=============
*/
qboolean visible (edict_t *self, edict_t *other)
{
vec3_t spot1;
vec3_t spot2;
trace_t trace;
//SWB - monsters can't see logged out or cloaked players
if (other->character && (!other->character->is_loggedin || other->character->is_cloaked))
return false;
VectorCopy (self->s.origin, spot1);
spot1[2] += self->viewheight;
VectorCopy (other->s.origin, spot2);
spot2[2] += other->viewheight;
trace = gi.trace (spot1, vec3_origin, vec3_origin, spot2, self, MASK_OPAQUE | MASK_WATER);
//SWB - don't see through opaque water
if (trace.contents == CONTENTS_WATER && trace.surface->flags & (SURF_TRANS33 | SURF_TRANS66))
gi.trace(trace.endpos, vec3_origin, vec3_origin, spot2, trace.ent, MASK_OPAQUE);
if (trace.fraction == 1.0)
{
//SWB - now make sure we can trace back without hitting opaque water
trace = gi.trace (spot2, vec3_origin, vec3_origin, spot1, other, MASK_OPAQUE | MASK_WATER);
if (trace.contents == CONTENTS_WATER && trace.surface->flags & (SURF_TRANS33 | SURF_TRANS66))
gi.trace(trace.endpos, vec3_origin, vec3_origin, spot1, trace.ent, MASK_OPAQUE);
if (trace.fraction == 1.0)
return true;
}
return false;
}
/*
=============
infront
returns 1 if the entity is in front (in sight) of self
=============
*/
qboolean infront (edict_t *self, edict_t *other)
{
vec3_t vec;
float dot;
vec3_t forward;
//SWB - monsters can't see logged out or cloaked players
if (other->character && (!other->character->is_loggedin || other->character->is_cloaked))
return false;
AngleVectors (self->s.angles, forward, NULL, NULL);
VectorSubtract (other->s.origin, self->s.origin, vec);
VectorNormalize (vec);
dot = DotProduct (vec, forward);
if (dot > 0.3)
return true;
return false;
}
//============================================================================
void HuntTarget (edict_t *self)
{
vec3_t vec;
self->goalentity = self->enemy;
//SWB - ensure the functions exist before calling them
if (self->monsterinfo.aiflags & AI_STAND_GROUND && self->monsterinfo.stand)
self->monsterinfo.stand (self);
else if (self->monsterinfo.run)
self->monsterinfo.run (self);
VectorSubtract (self->enemy->s.origin, self->s.origin, vec);
self->ideal_yaw = vectoyaw(vec);
// wait a while before first attack
if (!(self->monsterinfo.aiflags & AI_STAND_GROUND))
AttackFinished (self, 1);
}
void FoundTarget (edict_t *self)
{
// let other monsters see this monster for a while
if (self->enemy->client)
{
level.sight_entity = self;
level.sight_entity_framenum = level.framenum;
level.sight_entity->light_level = 128;
}
self->show_hostile = level.time + 1; // wake up other monsters
VectorCopy(self->enemy->s.origin, self->monsterinfo.last_sighting);
self->monsterinfo.trail_time = level.time;
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 = NULL;
self->monsterinfo.aiflags |= AI_COMBAT_POINT;
// clear the targetname, that point is ours!
self->movetarget->targetname = NULL;
self->monsterinfo.pausetime = 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.
============
*/
qboolean FindTarget (edict_t *self)
{
edict_t *client;
qboolean heardit;
int r;
if (self->monsterinfo.aiflags & AI_GOOD_GUY)
{
if (self->goalentity && self->goalentity->inuse && self->goalentity->classname)
{
if (strcmp(self->goalentity->classname, "target_actor") == 0)
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) )
{
client = level.sight_entity;
if (client->enemy == self->enemy)
{
return false;
}
}
else if (level.sound_entity_framenum >= (level.framenum - 1))
{
client = level.sound_entity;
heardit = true;
}
else if (!(self->enemy) && (level.sound2_entity_framenum >= (level.framenum - 1)) && !(self->spawnflags & 1) )
{
client = level.sound2_entity;
heardit = true;
}
else
{
client = level.sight_client;
if (!client)
return false; // no clients to get mad at
}
// if the entity went away, forget it
if (!client->inuse)
return false;
if (client == self->enemy)
return true; // JDC false;
if (client->client)
{
if (client->flags & FL_NOTARGET)
return false;
}
else if (client->svflags & SVF_MONSTER)
{
if (!client->enemy)
return false;
if (client->enemy->flags & FL_NOTARGET)
return false;
}
else if (heardit)
{
//SWB - ensure that the item we heard still has an owner
if (!client->owner || !client->owner->inuse || client->owner->flags & FL_NOTARGET)
return false;
}
else
return false;
if (!heardit)
{
//SWB - verify that the character is still logged in
if (!client->character || !client->character->is_loggedin)
return false;
//SWB - need to improve this for flashlight, but good enough for now
if (client->character->is_cloaked)
return false;
r = range (self, client);
//SWB - must be in front of them when far away
if (r == RANGE_FAR)
if (!infront (self, client))
{
return false;
}
// this is where we would check invisibility
//SWB - allow monsters to see in all light levels (fix for high gl_modulate values)
// is client in an spot too dark to be seen?
//if (client->light_level <= 5)
// return false;
if (!visible (self, client))
{
return false;
}
//SWB - made monsters more alert, only have to be in front of them when far away now
/*
if (r == RANGE_NEAR)
{
// Aldarn - makes monsters more alert by commenting this out
//if (client->show_hostile < level.time && !infront (self, client))
//{
// return false;
//}
}
else if (r == RANGE_MID)
{
if (!infront (self, client))
{
return false;
}
}
*/
self->enemy = client;
if (strcmp(self->enemy->classname, "player_noise") != 0)
{
self->monsterinfo.aiflags &= ~AI_SOUND_TARGET;
if (!self->enemy->client)
{
self->enemy = self->enemy->enemy;
if (!self->enemy->client)
{
self->enemy = NULL;
return false;
}
}
}
}
else // heardit
{
vec3_t temp;
if (self->spawnflags & 1)
{
if (!visible (self, client))
return false;
}
else
{
if (!gi.inPHS(self->s.origin, client->s.origin))
return false;
}
VectorSubtract (client->s.origin, self->s.origin, temp);
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 (client->areanum != self->areanum)
if (!gi.AreasConnected(self->areanum, client->areanum))
return false;
self->ideal_yaw = vectoyaw(temp);
M_ChangeYaw (self);
// hunt the sound for a bit; hopefully find the real player
self->monsterinfo.aiflags |= AI_SOUND_TARGET;
self->enemy = client;
}
//
// got one
//
FoundTarget (self);
if (!(self->monsterinfo.aiflags & AI_SOUND_TARGET) && (self->monsterinfo.sight))
self->monsterinfo.sight (self, self->enemy);
return true;
}
//=============================================================================
/*
============
FacingIdeal
============
*/
qboolean FacingIdeal(edict_t *self)
{
float delta;
delta = anglemod(self->s.angles[YAW] - self->ideal_yaw);
if (delta > 45 && delta < 315)
return false;
return true;
}
//=============================================================================
qboolean M_CheckAttack (edict_t *self)
{
vec3_t spot1, spot2;
float chance;
trace_t tr;
//SWB - how did we get in here with no enemy?
if (!self->enemy || !self->enemy->inuse)
return false;
//SWB - don't attack logged out or cloaked chars
if (self->enemy->character && (!self->enemy->character->is_loggedin || self->enemy->character->is_cloaked))
return false;
if (self->enemy->health > 0)
{
// see if any entities are in the way of the shot
VectorCopy (self->s.origin, spot1);
spot1[2] += self->viewheight;
VectorCopy (self->enemy->s.origin, spot2);
spot2[2] += self->enemy->viewheight;
tr = gi.trace (spot1, NULL, NULL, spot2, self, CONTENTS_SOLID|CONTENTS_MONSTER|CONTENTS_SLIME|CONTENTS_LAVA|CONTENTS_WINDOW);
// do we have a clear shot?
if (tr.ent != self->enemy)
return false;
}
// melee attack
if (enemy_range == RANGE_MELEE)
{
// don't always melee in easy mode
if (skill->value == 0 && (rand()&3) )
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)
return false;
if (level.time < self->monsterinfo.attack_finished)
return false;
if (enemy_range == RANGE_FAR)
return false;
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
{
chance = 0.4;
}
else if (enemy_range == RANGE_MELEE)
{
chance = 0.2;
}
else if (enemy_range == RANGE_NEAR)
{
chance = 0.1;
}
else if (enemy_range == RANGE_MID)
{
chance = 0.02;
}
else
{
return false;
}
if (skill->value == 0)
chance *= 0.5;
else if (skill->value >= 2)
chance *= 2;
if (random () < chance)
{
self->monsterinfo.attack_state = AS_MISSILE;
self->monsterinfo.attack_finished = level.time + 2*random();
return true;
}
if (self->flags & FL_FLY)
{
if (random() < 0.3)
self->monsterinfo.attack_state = AS_SLIDING;
else
self->monsterinfo.attack_state = AS_STRAIGHT;
}
return false;
}
/*
=============
ai_run_melee
Turn and close until within an angle to launch a melee attack
=============
*/
void ai_run_melee(edict_t *self)
{
self->ideal_yaw = enemy_yaw;
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
=============
*/
void ai_run_missile(edict_t *self)
{
self->ideal_yaw = enemy_yaw;
M_ChangeYaw (self);
if (FacingIdeal(self))
{
self->monsterinfo.attack (self);
self->monsterinfo.attack_state = AS_STRAIGHT;
}
};
/*
=============
ai_run_slide
Strafe sideways, but stay at aproximately the same range
=============
*/
void ai_run_slide(edict_t *self, float distance)
{
float ofs;
self->ideal_yaw = enemy_yaw;
M_ChangeYaw (self);
if (self->monsterinfo.lefty)
ofs = 90;
else
ofs = -90;
if (M_walkmove (self, self->ideal_yaw + ofs, distance))
return;
self->monsterinfo.lefty = 1 - self->monsterinfo.lefty;
M_walkmove (self, self->ideal_yaw - ofs, distance);
}
/*
=============
ai_checkattack
Decides if we're going to attack or do something else
used by ai_run and ai_stand
=============
*/
qboolean ai_checkattack (edict_t *self, float dist)
{
vec3_t temp;
qboolean 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.time - self->enemy->teleport_time) > 5.0)
{
if (self->goalentity == self->enemy)
{
if (self->movetarget)
self->goalentity = self->movetarget;
else
self->goalentity = NULL;
}
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.time + 1;
return false;
}
}
}
enemy_vis = false;
// see if the enemy is dead
hesDeadJim = false;
//SWB - check if logged in also
if ((!self->enemy) || (!self->enemy->inuse) || (self->enemy->character && !self->enemy->character->is_loggedin))
{
hesDeadJim = true;
}
else if (self->monsterinfo.aiflags & AI_MEDIC)
{
if (self->enemy->health > 0)
{
hesDeadJim = true;
self->monsterinfo.aiflags &= ~AI_MEDIC;
}
}
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->enemy = NULL;
// FIXME: look all around for other targets
if (self->oldenemy && self->oldenemy->health > 0)
{
self->enemy = self->oldenemy;
self->oldenemy = NULL;
HuntTarget (self);
}
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.pausetime = level.time + 100000000;
//self->monsterinfo.stand (self);
Kots_MonsterFindGoal(self);
}
return true;
}
}
self->show_hostile = level.time + 1; // wake up other monsters
// check knowledge of enemy
enemy_vis = visible(self, self->enemy);
if (enemy_vis)
{
self->monsterinfo.search_time = level.time + 5;
VectorCopy (self->enemy->s.origin, self->monsterinfo.last_sighting);
}
// look for other coop players here
// if (coop && self->monsterinfo.search_time < level.time)
// {
// if (FindTarget (self))
// return true;
// }
enemy_infront = infront(self, self->enemy);
enemy_range = range(self, self->enemy);
VectorSubtract (self->enemy->s.origin, self->s.origin, temp);
enemy_yaw = vectoyaw(temp);
// JDC self->ideal_yaw = enemy_yaw;
if (self->monsterinfo.attack_state == AS_MISSILE)
{
ai_run_missile (self);
return true;
}
if (self->monsterinfo.attack_state == AS_MELEE)
{
ai_run_melee (self);
return true;
}
// if enemy is not currently visible, we will never attack
if (!enemy_vis)
return false;
return self->monsterinfo.checkattack (self);
}
/*
=============
ai_run
The monster has an enemy it is trying to kill
=============
*/
void ai_run (edict_t *self, float dist)
{
vec3_t v;
edict_t *tempgoal;
edict_t *save;
qboolean new;
edict_t *marker;
float d1, d2;
trace_t tr;
vec3_t v_forward, v_right;
float left, center, right;
vec3_t left_target, right_target;
// if we're going to a combat point, just proceed
if (self->monsterinfo.aiflags & AI_COMBAT_POINT)
{
M_MoveToGoal (self, dist);