This repository has been archived by the owner on Jan 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
g_newai.c
1868 lines (1621 loc) · 43.6 KB
/
g_newai.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
#include "g_local.h"
//===============================
// BLOCKED Logic
//===============================
/*
gi.WriteByte (svc_temp_entity);
gi.WriteByte (TE_DEBUGTRAIL);
gi.WritePosition (pt1);
gi.WritePosition (pt2);
gi.multicast (pt1, MULTICAST_PVS);
self->nextthink = level.time + 10;
*/
// plat states, copied from g_func.c
#define STATE_TOP 0
#define STATE_BOTTOM 1
#define STATE_UP 2
#define STATE_DOWN 3
qboolean face_wall (edict_t *self);
void HuntTarget (edict_t *self);
// PMM
qboolean parasite_drain_attack_ok (vec3_t start, vec3_t end);
// blocked_checkshot
// shotchance: 0-1, chance they'll take the shot if it's clear.
qboolean blocked_checkshot (edict_t *self, float shotChance)
{
qboolean playerVisible;
if(!self->enemy)
return false;
// blocked checkshot is only against players. this will
// filter out player sounds and other shit they should
// not be firing at.
if(!(self->enemy->client))
return false;
if (random() < shotChance)
return false;
// PMM - special handling for the parasite
if (!strcmp(self->classname, "monster_parasite"))
{
vec3_t f, r, offset, start, end;
trace_t tr;
AngleVectors (self->s.angles, f, r, NULL);
VectorSet (offset, 24, 0, 6);
G_ProjectSource (self->s.origin, offset, f, r, start);
VectorCopy (self->enemy->s.origin, end);
if (!parasite_drain_attack_ok(start, end))
{
end[2] = self->enemy->s.origin[2] + self->enemy->maxs[2] - 8;
if (!parasite_drain_attack_ok(start, end))
{
end[2] = self->enemy->s.origin[2] + self->enemy->mins[2] + 8;
if (!parasite_drain_attack_ok(start, end))
return false;
}
}
VectorCopy (self->enemy->s.origin, end);
tr = gi.trace (start, NULL, NULL, end, self, MASK_SHOT);
if (tr.ent != self->enemy)
{
self->monsterinfo.aiflags |= AI_BLOCKED;
if(self->monsterinfo.attack)
self->monsterinfo.attack(self);
self->monsterinfo.aiflags &= ~AI_BLOCKED;
return true;
}
}
playerVisible = visible (self, self->enemy);
// always shoot at teslas
if(playerVisible)
{
if (!strcmp(self->enemy->classname, "tesla"))
{
// if(g_showlogic && g_showlogic->value)
// gi.dprintf("blocked: taking a shot\n");
// turn on AI_BLOCKED to let the monster know the attack is being called
// by the blocked functions...
self->monsterinfo.aiflags |= AI_BLOCKED;
if(self->monsterinfo.attack)
self->monsterinfo.attack(self);
self->monsterinfo.aiflags &= ~AI_BLOCKED;
return true;
}
}
return false;
}
// blocked_checkplat
// dist: how far they are trying to walk.
qboolean blocked_checkplat (edict_t *self, float dist)
{
int playerPosition;
trace_t trace;
vec3_t pt1, pt2;
vec3_t forward;
edict_t *plat;
if(!self->enemy)
return false;
// check player's relative altitude
if(self->enemy->absmin[2] >= self->absmax[2])
playerPosition = 1;
else if(self->enemy->absmax[2] <= self->absmin[2])
playerPosition = -1;
else
playerPosition = 0;
// if we're close to the same position, don't bother trying plats.
if(playerPosition == 0)
return false;
plat = NULL;
// see if we're already standing on a plat.
if(self->groundentity && self->groundentity != world)
{
if(!strncmp(self->groundentity->classname, "func_plat", 8))
plat = self->groundentity;
}
// if we're not, check to see if we'll step onto one with this move
if(!plat)
{
AngleVectors (self->s.angles, forward, NULL, NULL);
VectorMA(self->s.origin, dist, forward, pt1);
VectorCopy (pt1, pt2);
pt2[2] -= 384;
trace = gi.trace(pt1, vec3_origin, vec3_origin, pt2, self, MASK_MONSTERSOLID);
if(trace.fraction < 1 && !trace.allsolid && !trace.startsolid)
{
if(!strncmp(trace.ent->classname, "func_plat", 8))
{
plat = trace.ent;
}
}
}
// if we've found a plat, trigger it.
if(plat && plat->use)
{
if (playerPosition == 1)
{
if((self->groundentity == plat && plat->moveinfo.state == STATE_BOTTOM) ||
(self->groundentity != plat && plat->moveinfo.state == STATE_TOP))
{
// if(g_showlogic && g_showlogic->value)
// gi.dprintf("player above, and plat will raise. using!\n");
plat->use (plat, self, self);
return true;
}
}
else if(playerPosition == -1)
{
if((self->groundentity == plat && plat->moveinfo.state == STATE_TOP) ||
(self->groundentity != plat && plat->moveinfo.state == STATE_BOTTOM))
{
// if(g_showlogic && g_showlogic->value)
// gi.dprintf("player below, and plat will lower. using!\n");
plat->use (plat, self, self);
return true;
}
}
// if(g_showlogic && g_showlogic->value)
// gi.dprintf("hit a plat, not using. ppos: %d plat: %d\n", playerPosition, plat->moveinfo.state);
}
return false;
}
// blocked_checkjump
// dist: how far they are trying to walk.
// maxDown/maxUp: how far they'll ok a jump for. set to 0 to disable that direction.
qboolean blocked_checkjump (edict_t *self, float dist, float maxDown, float maxUp)
{
int playerPosition;
trace_t trace;
vec3_t pt1, pt2;
vec3_t forward, up;
vec_t d0, d1;
edict_t *target;
// Lazarus: Rogue only did this for enemies. We do it for enemies or
// movetargets
if(!self->monsterinfo.jump)
return false;
if(!self->enemy)
return false;
if(self->enemy)
target = self->enemy;
else if(self->movetarget)
target = self->movetarget;
else
return false;
VectorSubtract(target->s.origin,self->s.origin,pt1);
d0 = VectorLength(pt1);
AngleVectors (self->s.angles, forward, NULL, up);
VectorMA(self->s.origin, 48, forward, pt1);
if(target->absmin[2] > (self->absmin[2] + 16))
playerPosition = 1;
else if(target->absmin[2] < (self->absmin[2] - 16))
playerPosition = -1;
else
playerPosition = 0;
if(playerPosition == -1 && maxDown)
{
// check to make sure we can even get to the spot we're going to "fall" from
trace = gi.trace(self->s.origin, self->mins, self->maxs, pt1, self, MASK_MONSTERSOLID);
if(trace.fraction < 1)
return false;
VectorCopy (pt1, pt2);
pt2[2] = self->mins[2] - maxDown - 1;
trace = gi.trace(pt1, vec3_origin, vec3_origin, pt2, self, MASK_MONSTERSOLID | MASK_WATER);
if(trace.fraction < 1 && !trace.allsolid && !trace.startsolid)
{
if((self->absmin[2] - trace.endpos[2]) >= 24 && trace.contents & MASK_SOLID)
{
if( (target->absmin[2] - trace.endpos[2]) > 32)
return false;
if(trace.plane.normal[2] < 0.9)
return false;
VectorSubtract(target->s.origin,trace.endpos,pt1);
d1 = VectorLength(pt1);
if(d0 < d1)
return false;
self->velocity[0] = forward[0]*dist*10;
self->velocity[1] = forward[1]*dist*10;
self->velocity[2] = max(self->velocity[2],100);
gi.linkentity(self);
return true;
}
}
}
else if(playerPosition == 1 && maxUp)
{
VectorCopy(pt1, pt2);
pt1[2] = self->absmax[2] + maxUp;
trace = gi.trace(pt1, vec3_origin, vec3_origin, pt2, self, MASK_MONSTERSOLID | MASK_WATER);
if(trace.fraction < 1 && !trace.allsolid && !trace.startsolid)
{
if((trace.endpos[2] - self->absmin[2]) <= maxUp && trace.contents & MASK_SOLID)
{
VectorSubtract(target->s.origin,trace.endpos,pt1);
d1 = VectorLength(pt1);
if(d0 < d1)
return false;
face_wall(self);
self->monsterinfo.jump(self);
self->velocity[0] = forward[0]*dist*10;
self->velocity[1] = forward[1]*dist*10;
self->velocity[2] = max(self->velocity[2],200);
gi.linkentity(self);
return true;
}
// else if(g_showlogic && g_showlogic->value)
// gi.dprintf("Too high to jump %0.1f\n", (trace.endpos[2] - self->absmin[2]));
}
// else if(g_showlogic && g_showlogic->value)
// gi.dprintf("Not something I could jump onto\n");
}
// else if(g_showlogic && g_showlogic->value)
// gi.dprintf("Player at similar level. No need to jump up?\n");
return false;
}
// checks to see if another coop player is nearby, and will switch.
qboolean blocked_checknewenemy (edict_t *self)
{
/*
int player;
edict_t *ent;
if (!(coop->value))
return false;
for (player = 1; player <= game.maxclients; player++)
{
ent = &g_edicts[player];
if (!ent->inuse)
continue;
if (!ent->client)
continue;
if (ent == self->enemy)
continue;
if (visible (self, ent))
{
if (g_showlogic && g_showlogic->value)
gi.dprintf ("B_CNE: %s acquired new enemy %s\n", self->classname, ent->client->pers.netname);
self->enemy = ent;
FoundTarget (self);
return true;
}
}
return false;
*/
return false;
}
// *************************
// HINT PATHS
// *************************
#define HINT_ENDPOINT 0x0001
#define MAX_HINT_CHAINS 100
int hint_paths_present;
edict_t *hint_path_start[MAX_HINT_CHAINS];
int num_hint_paths;
//
// AI code
//
// =============
// hintpath_findstart - given any hintpath node, finds the start node
// =============
edict_t *hintpath_findstart(edict_t *ent)
{
edict_t *e;
edict_t *last;
int field;
if(ent->target) // starting point
{
last = world;
field = FOFS(targetname);
e = G_Find(NULL, field, ent->target);
while(e)
{
last = e;
if(!e->target)
break;
e = G_Find(NULL, field, e->target);
}
}
else // end point
{
last = world;
field = FOFS(target);
e = G_Find(NULL, field, ent->targetname);
while(e)
{
last = e;
if(!e->targetname)
break;
e = G_Find(NULL, field, e->targetname);
}
}
if(!(last->spawnflags & HINT_ENDPOINT))
{
// gi.dprintf ("end of chain is not HINT_ENDPOINT\n");
return NULL;
}
if(last == world)
last = NULL;
return last;
}
// =============
// hintpath_other_end - given one endpoint of a hintpath, returns the other end.
// =============
edict_t *hintpath_other_end(edict_t *ent)
{
edict_t *e;
edict_t *last;
int field;
if(ent->target) // starting point
{
last = world;
field = FOFS(targetname);
e = G_Find(NULL, field, ent->target);
while(e)
{
last = e;
if(!e->target)
break;
e = G_Find(NULL, field, e->target);
}
}
else // end point
{
last = world;
field = FOFS(target);
e = G_Find(NULL, field, ent->targetname);
while(e)
{
last = e;
if(!e->targetname)
break;
e = G_Find(NULL, field, e->targetname);
}
}
if(!(last->spawnflags & HINT_ENDPOINT))
{
// gi.dprintf ("end of chain is not HINT_ENDPOINT\n");
return NULL;
}
if(last == world)
last = NULL;
return last;
}
// =============
// hintpath_go - starts a monster (self) moving towards the hintpath (point)
// disables all contrary AI flags.
// =============
void hintpath_go (edict_t *self, edict_t *point)
{
vec3_t dir;
vec3_t angles;
VectorSubtract(point->s.origin, self->s.origin, dir);
vectoangles2(dir, angles);
self->ideal_yaw = angles[YAW];
self->goalentity = self->movetarget = point;
self->monsterinfo.pausetime = 0;
self->monsterinfo.aiflags |= AI_HINT_PATH;
self->monsterinfo.aiflags &= ~(AI_SOUND_TARGET | AI_PURSUIT_LAST_SEEN | AI_PURSUE_NEXT | AI_PURSUE_TEMP);
// run for it
self->monsterinfo.search_time = level.time;
self->monsterinfo.run (self);
}
// =============
// hintpath_stop - bails a monster out of following hint paths
// =============
void hintpath_stop (edict_t *self)
{
self->goalentity = NULL;
self->movetarget = NULL;
// self->monsterinfo.last_hint = NULL;
self->monsterinfo.last_hint_time = level.time;
self->monsterinfo.goal_hint = NULL;
self->monsterinfo.aiflags &= ~AI_HINT_PATH;
if (has_valid_enemy(self))
{
// if we can see our target, go nuts
if (visible(self, self->enemy))
{
FoundTarget (self);
return;
}
// otherwise, keep chasing
HuntTarget (self);
return;
}
// if our enemy is no longer valid, forget about our enemy and go into stand
self->enemy = NULL;
// 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);
}
// =============
// monsterlost_checkhint - the monster (self) will check around for valid hintpaths.
// a valid hintpath is one where the two endpoints can see both the monster
// and the monster's enemy. if only one person is visible from the endpoints,
// it will not go for it.
// =============
qboolean monsterlost_checkhint2 (edict_t *self);
qboolean monsterlost_checkhint (edict_t *self)
{
edict_t *e, *monster_pathchain, *target_pathchain, *checkpoint;
edict_t *closest;
float closest_range = 1000000;
edict_t *start, *destination;
int field;
int count1=0, count2=0, count3=0, count4=0, count5=0;
float r;
int i;
qboolean hint_path_represented[MAX_HINT_CHAINS];
// if there are no hint paths on this map, exit immediately.
if(!hint_paths_present)
return false;
if(!self->enemy)
return false;
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
return false;
if (!strcmp(self->classname, "monster_turret"))
return false;
monster_pathchain = NULL;
field = FOFS(classname);
// find all the hint_paths.
// FIXME - can we not do this every time?
for (i=0; i < num_hint_paths; i++)
{
e = hint_path_start[i];
while(e)
{
count1++;
if (e->monster_hint_chain)
e->monster_hint_chain = NULL;
if (monster_pathchain)
{
checkpoint->monster_hint_chain = e;
checkpoint = e;
}
else
{
monster_pathchain = e;
checkpoint = e;
}
e = e->hint_chain;
}
}
// filter them by distance and visibility to the monster
e = monster_pathchain;
checkpoint = NULL;
while (e)
{
r = realrange (self, e);
// if (r > 512)
// count3++;
if (r > 512)
{
count2++;
if (checkpoint)
{
checkpoint->monster_hint_chain = e->monster_hint_chain;
e->monster_hint_chain = NULL;
e = checkpoint->monster_hint_chain;
continue;
}
else
{
// use checkpoint as temp pointer
checkpoint = e;
e = e->monster_hint_chain;
checkpoint->monster_hint_chain = NULL;
// and clear it again
checkpoint = NULL;
// since we have yet to find a valid one (or else checkpoint would be set) move the
// start of monster_pathchain
monster_pathchain = e;
continue;
}
}
if (!visible(self, e))
{
count4++;
if (checkpoint)
{
checkpoint->monster_hint_chain = e->monster_hint_chain;
e->monster_hint_chain = NULL;
e = checkpoint->monster_hint_chain;
continue;
}
else
{
// use checkpoint as temp pointer
checkpoint = e;
e = e->monster_hint_chain;
checkpoint->monster_hint_chain = NULL;
// and clear it again
checkpoint = NULL;
// since we have yet to find a valid one (or else checkpoint would be set) move the
// start of monster_pathchain
monster_pathchain = e;
continue;
}
}
count5++;
checkpoint = e;
e = e->monster_hint_chain;
}
// at this point, we have a list of all of the eligible hint nodes for the monster
// we now take them, figure out what hint chains they're on, and traverse down those chains,
// seeing whether any can see the player
//
// first, we figure out which hint chains we have represented in monster_pathchain
if (count5 == 0)
return false;
for (i=0; i < num_hint_paths; i++)
{
hint_path_represented[i] = false;
}
e = monster_pathchain;
checkpoint = NULL;
while (e)
{
if ((e->hint_chain_id < 0) || (e->hint_chain_id > num_hint_paths))
return false;
hint_path_represented[e->hint_chain_id] = true;
e = e->monster_hint_chain;
}
count1 = 0;
count2 = 0;
count3 = 0;
count4 = 0;
count5 = 0;
// now, build the target_pathchain which contains all of the hint_path nodes we need to check for
// validity (within range, visibility)
target_pathchain = NULL;
checkpoint = NULL;
for (i=0; i < num_hint_paths; i++)
{
// if this hint chain is represented in the monster_hint_chain, add all of it's nodes to the target_pathchain
// for validity checking
if (hint_path_represented[i])
{
e = hint_path_start[i];
while (e)
{
if (target_pathchain)
{
checkpoint->target_hint_chain = e;
checkpoint = e;
}
else
{
target_pathchain = e;
checkpoint = e;
}
e = e->hint_chain;
}
}
}
// target_pathchain is a list of all of the hint_path nodes we need to check for validity relative to the target
e = target_pathchain;
checkpoint = NULL;
while (e)
{
r = realrange (self->enemy, e);
if (r > 512)
{
count2++;
if (checkpoint)
{
checkpoint->target_hint_chain = e->target_hint_chain;
e->target_hint_chain = NULL;
e = checkpoint->target_hint_chain;
continue;
}
else
{
// use checkpoint as temp pointer
checkpoint = e;
e = e->target_hint_chain;
checkpoint->target_hint_chain = NULL;
// and clear it again
checkpoint = NULL;
target_pathchain = e;
continue;
}
}
if (!visible(self->enemy, e))
{
count4++;
if (checkpoint)
{
checkpoint->target_hint_chain = e->target_hint_chain;
e->target_hint_chain = NULL;
e = checkpoint->target_hint_chain;
continue;
}
else
{
// use checkpoint as temp pointer
checkpoint = e;
e = e->target_hint_chain;
checkpoint->target_hint_chain = NULL;
// and clear it again
checkpoint = NULL;
target_pathchain = e;
continue;
}
}
// if it passes all the tests, it's a keeper
count5++;
checkpoint = e;
e = e->target_hint_chain;
}
// at this point we should have:
// monster_pathchain - a list of "monster valid" hint_path nodes linked together by monster_hint_chain
// target_pathcain - a list of "target valid" hint_path nodes linked together by target_hint_chain. these
// are filtered such that only nodes which are on the same chain as "monster valid" nodes
//
// Now, we figure out which "monster valid" node we want to use
//
// To do this, we first off make sure we have some target nodes. If we don't, there are no valid hint_path nodes
// for us to take
//
// If we have some, we filter all of our "monster valid" nodes by which ones have "target valid" nodes on them
//
// Once this filter is finished, we select the closest "monster valid" node, and go to it.
if (count5 == 0)
return false;
// reuse the hint_chain_represented array, this time to see which chains are represented by the target
for (i=0; i < num_hint_paths; i++)
{
hint_path_represented[i] = false;
}
e = target_pathchain;
checkpoint = NULL;
while (e)
{
if ((e->hint_chain_id < 0) || (e->hint_chain_id > num_hint_paths))
return false;
hint_path_represented[e->hint_chain_id] = true;
e = e->target_hint_chain;
}
// traverse the monster_pathchain - if the hint_node isn't represented in the "target valid" chain list,
// remove it
// if it is on the list, check it for range from the monster. If the range is the closest, keep it
//
closest = NULL;
e = monster_pathchain;
while (e)
{
if (!(hint_path_represented[e->hint_chain_id]))
{
checkpoint = e->monster_hint_chain;
e->monster_hint_chain = NULL;
e = checkpoint;
continue;
}
r = realrange(self, e);
if (r < closest_range)
{
closest = e;
closest_range = r; // Lazarus: This was left out, ya doofuses
}
e = e->monster_hint_chain;
}
if (!closest)
return false;
start = closest;
// now we know which one is the closest to the monster .. this is the one the monster will go to
// we need to finally determine what the DESTINATION node is for the monster .. walk down the hint_chain,
// and find the closest one to the player
closest = NULL;
closest_range = 10000000;
e = target_pathchain;
while (e)
{
if (start->hint_chain_id == e->hint_chain_id)
{
r = realrange(self->enemy, e); // Lazarus: This WAS realrange(self, e)... that can't be right
if (r < closest_range)
{
closest = e;
closest_range = r; // Lazarus: again, you idjits left this out
}
}
e = e->target_hint_chain;
}
if (!closest)
return false;
destination = closest;
self->monsterinfo.goal_hint = destination;
// self->monsterinfo.last_hint = NULL;
hintpath_go(self, start);
return true;
}
/*
qboolean monsterlost_checkhint2 (edict_t *self)
{
edict_t *e, *e2, *goPoint;
int field;
int playerVisible, selfVisible;
// if there are no hint paths on this map, exit immediately.
if(!hint_paths_present)
return false;
if(!self->enemy)
return false;
goPoint = NULL;
field = FOFS(classname);
// check all the hint_paths.
e = G_Find(NULL, field, "hint_path");
while(e)
{
// if it's an endpoint, check for "validity"
if(e->spawnflags & HINT_ENDPOINT)
{
// check visibility from this spot
selfVisible = visible(e, self);
playerVisible = visible(e, self->enemy);
// gi.dprintf("checking endpoint at %s %d %d\n", vtos(e->s.origin),selfVisible,playerVisible);
// at least one of us is visible from this endpoint.
// now check the other one if needed.
if(selfVisible || playerVisible)
{
// if endpoint 1 saw me, set my destination to it.
if(selfVisible)
goPoint = e;
// if both aren't visible, try the other endpoint
if(!selfVisible || !playerVisible)
{
e2 = hintpath_other_end(e);
if(!e2) // could not connect to the other endpoint
{
gi.dprintf("Unlinked hint paths!\n");
return false;
}
// if endpoint 1 saw the enemy, see if endpoint 2 sees me
if(!selfVisible)
selfVisible = visible(e2, self);
// if endpoint 1 saw me, see if endpoint 2 sees the enemy
else if(!playerVisible)
playerVisible = visible(e2, self->enemy);
// if endpoint 2 saw me, set my destination to it.
if(!goPoint && selfVisible)
goPoint = e2;
// gi.dprintf("checking other endpoint at %s %d %d\n", vtos(e2->s.origin),selfVisible,playerVisible);
}
// if both are visible from at least one endpoint,
// go for it.
if(selfVisible && playerVisible)
{
// set me to go to goPoint
if(g_showlogic && g_showlogic->value)
gi.dprintf("found path. proceed to %s\n", vtos(goPoint->s.origin));
// since this is a new hint path trip, set last_hint to NULL
self->monsterinfo.last_hint = NULL;
hintpath_go(self, goPoint);
return true;
}
}
}
e = G_Find(e, field, "hint_path");
}
// if we got here, we didn't find a valid path
if(g_showlogic && g_showlogic->value)
gi.dprintf("blocked_checkhint: found no paths\n");
return false;
}
*/
//
// Path code
//
// =============
// hint_path_touch - someone's touched the hint_path
// =============
void hint_path_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
edict_t *e, *goal, *next = NULL;
// int chain; // direction - (-1) = upstream, (1) = downstream, (0) = done
qboolean goalFound = false;
if(other->monsterinfo.aiflags & AI_MEDIC_PATROL)
{
if(other->movetarget == self)
medic_NextPatrolPoint(other,self);
return;
}
// make sure we're the target of it's obsession
if(other->movetarget == self)
{
goal = other->monsterinfo.goal_hint;
// if the monster is where he wants to be
if (goal == self)
{
hintpath_stop (other);
return;
}
else
{
// if we aren't, figure out which way we want to go
e = hint_path_start[self->hint_chain_id];
while (e)
{
// if we get up to ourselves on the hint chain, we're going down it
if (e == self)
{
next = e->hint_chain;
break;
}
if (e == goal)
goalFound = true;
// if we get to where the next link on the chain is this hint_path and have found the goal on the way
// we're going upstream, so remember who the previous link is
if ((e->hint_chain == self) && goalFound)
{
next = e;
break;
}
e = e->hint_chain;
}
}
// if we couldn't find it, have the monster go back to normal hunting.
if(!next)
{
hintpath_stop(other);
return;
}
// set the last_hint entry to this hint_path, and
// send him on his way
hintpath_go(other, next);
// have the monster freeze if the hint path we just touched has a wait time
// on it, for example, when riding a plat.
if(self->wait)
other->nextthink = level.time + self->wait;
}
}
/*
void hint_path_touch2 (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
edict_t *next, *last;
int chain;
// make sure we're the target of it's obsession
if(other->movetarget == self)
{
chain = 0; // direction the monster is going in the chain
next = NULL; // next hint_path
// gi.dprintf("hint_path %s\n", vtos(self->s.origin));
// is this the first hintpath targeted? if so, we can do this easily.
if(other->monsterinfo.last_hint == NULL)
{