forked from itslunaranyo/copper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai.qc
1589 lines (1321 loc) · 34.3 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
/*
==============================================================================
AI
Moving, animating, and decision making
==============================================================================
*/
/*
=============
eyeline
=============
*/
vector(entity targ) eyeline =
{
vector spot1, spot2;
spot1 = self.origin + self.view_ofs;
spot2 = targ.origin + targ.view_ofs;
return (spot2 - spot1);
}
/*
=============
range
returns the range categorization of an entity relative to self
=============
*/
float(entity targ) range =
{
vector d;
float r;
if (EntitiesTouching(self, targ)) // always melee someone standing on your head
return RANGE_MELEE;
d = eyeline(targ);
//d_z *= 2; // don't melee guys way above or below you
r = vlen(d);
if (r < 120)
return RANGE_MELEE;
if (r < 500)
return RANGE_NEAR;
if (r < 900)
return RANGE_MID;
if (r < 1250)
return RANGE_FAR;
return RANGE_TOOFAR;
}
/*
=============
visible
returns 1 if the entity is visible to self, even if not infront()
uses enemy's real position, NOT the potentially ring-of-shadows-offset BS position!
=============
*/
float (entity targ) visible =
{
local vector spot1, spot2;
spot1 = self.origin + self.view_ofs;
spot2 = targ.origin + targ.view_ofs;
traceline2(spot1, spot2, self, TRACE_NOMONSTERS|TRACE_WATER); // see through other monsters
if (trace_inopen && trace_inwater)
return FALSE; // sight line crossed contents
if (trace_fraction == 1)
return TRUE;
return FALSE;
}
/*
=============
infront
returns 1 if the entity is in front (in sight) of self
=============
*/
float(entity targ) infront =
{
vector vec;
float dot;
makevectors (self.angles);
vec = normalize (targ.origin - self.origin);
dot = vec * v_forward;
if ( dot > 0.3)
{
return TRUE;
}
return FALSE;
}
/*
=============
z_overlaps
returns 1 if the entity's bounds on z overlap those of self
for checking if melee attacks are worthwhile
=============
*/
float(entity targ) z_overlap =
{
return (self.absmin_z < targ.absmax_z && targ.absmin_z < self.absmax_z);
}
/*
=============
enemy_vispos
Run every monster's aiming routine against this func instead of self.enemy.origin, so they
can be confused by a ring of shadows and fire in wrong directions
=============
*/
vector() enemy_vispos =
{
// dogs can still smell the player
if (!has_invis(self.enemy) || self.classname == "monster_dog" )
return self.enemy.origin;
if ( time < self.dmgtime + 1 ) // shooting right at a monster gives you away for a moment
return self.enemy.origin;
vector dir, visOrg;
float hadjust;
dir = self.enemy.origin - self.origin;
// pick random offset based on time, salted with monster's position for variety
visOrg = SinCos(time * 121 - self.origin_x - self.origin_y) * (vlen(dir) * 0.8 - 64);// * 0.4 + 64);
hadjust = normalize(dir) * normalize(visOrg);
visOrg_z = dir_z * hadjust * 0.5;
visOrg += self.enemy.origin;
return visOrg;
}
/*
===========
enemy_alive
Verify if enemy can still be attacked
Returns FALSE if enemy should be permanently forgotten
============
*/
float() enemy_alive =
{
if (self.enemy.health <= 0) return FALSE;
// also consider a downed zombie to be dead, instead of waving a chainsaw over its body forever
if (self.enemy.customflags & (CFL_KNOCKEDDOWN)) return FALSE;
// coop spectating is a deadflag without being out of health
if (self.enemy.deadflag) return FALSE;
return TRUE;
}
/*
=============
enemy_yaw
=============
*/
float() enemy_yaw =
{
if (!self.enemy)
return self.ideal_yaw;
return vectoyaw(enemy_vispos() - self.origin);
}
/*
============
FacingIdeal
============
*/
float() FacingIdeal =
{
return (angledif(self.angles_y,self.ideal_yaw) < 45);
}
/*
============
enemy_aim_vertical
raise aim point a bit when target is up high to try and clear ledges
============
*/
vector() enemy_aim_vertical =
{
float up = self.enemy.maxs_z * 1.6;
vector dir = normalize(self.enemy.origin - self.origin);
up *= max(0, dir_z);
return Vector(0,0,up);
}
/*
============
LeadTarget
returns a relative position to aim at to lead a shot at a moving target
(not a normalized firing vector, so monsters can modify the result further first)
source: where the projectile will originate from
misvel: speed of projectile
degree: amount to lead target, < 1 will still lag behind target a bit
============
*/
vector(vector source, float misvel, float degree) LeadTarget =
{
local vector vel, lead_offset, evel;
vel = enemy_vispos() - source;
// don't lead if you can't see the target
if (has_invis(self.enemy))
return vel;
evel = self.enemy.velocity;
if( !(self.enemy.flags & FL_ONGROUND) && fabs(evel_z) < 275 )
evel_z = 0; // ignore if the player is jumping around
lead_offset = (vlen(vel) / misvel) * evel * degree;
return vel + lead_offset;
}
vector(vector source, float misvel) LeadTargetBySkill =
{
// in normal combat, leading above ~50% makes for worse accuracy, not better, because
// the player is always changing speed and direction
return LeadTarget(source, misvel, min(0.5, skill * 0.25));
}
/*
==============================================================================
ATTACK CHECKS
==============================================================================
*/
/*
=============
enemy_priority
for switching targets with a semblance of intelligence in coop
a monster will switch to another player if that player is
- closer to the monster than its enemy
- more in front of it than its enemy
- more visible than its enemy
higher return value = higher priority
=============
*/
float(entity targ) enemy_priority =
{
vector vec;
float r, d, p;
r = RANGE_TOOFAR - range(targ); // melee = 4, near = 3 ...
makevectors (self.angles);
vec = targ.origin - self.origin;
vec_z *= 2;
vec = normalize(vec);
d = (vec * v_forward + 2) / 2; // 0.5=behind, 1.5=dead ahead
p = r * d;
if (!visible(targ))
p *= 0.5; // no LOS
if (has_invis(targ))
p *= 0.25; // under the radar
if (has_quad(targ))
p *= 4; // way over the radar
/*
bprint(targ.netname);
bprint2(": r ", ftos(r));
bprint2(" d ", ftos(d));
bprint3(" -> p ", ftos(p), "\n");
*/
return p;
}
/*
===========
ReprioritizeEnemy
in coop, monsters always immediately switched targets when harmed, so players
could easily nullify threats by juggling aggro.
I've abandoned the infight-based aggro-pulling model, rather than overloading the
definition of "when harmed" with more logic. now, if a monster is angry at any one
player, it treats all players in view as potential targets, attacking whichever
player is most convenient at the moment.
.search_time: a monster will not switch to another player in coop until after
this time - set when angered by a player and after switching targets
============
*/
float() ReprioritizeEnemy =
{
if (self.enemy.classname != "player") return FALSE;
entity pl, best;
float priority, bestp;
bestp = -1;
best = world;
pl = nextent(world);
while (pl.flags & FL_CLIENT)
{
if (FilterTarget(pl))
{
priority = enemy_priority(pl);
if (priority > bestp)
{
bestp = priority;
best = pl;
}
}
pl = nextent(pl);
}
if (best && best != self.enemy)
{
self.oldenemy = self.enemy;
self.enemy = best;
self.goalentity = best;
self.search_time = time + 1;
sight_entity = self;
sight_entity_time = time;
self.show_hostile = time + 1;
// don't switch targets the instant before firing or lightning comes out of your ass
ai_attack_finished(1);
return TRUE;
}
return FALSE;
}
/*
===========
CheckClearAttack
Ensure the line of fire to the enemy isn't blocked by another creature
============
*/
float() CheckClearAttack =
{
vector spot1, spot2;
if (self.enemy.customflags & (CFL_PLUNGE|CFL_LIMBO) || self.enemy.deadflag == DEAD_SPECTATING)
return FALSE;
if (has_invis(self.enemy))
return TRUE;
spot1 = self.origin + self.view_ofs;
spot2 = enemy_vispos() + self.enemy.view_ofs;
traceline2(spot1, spot2, self, TRACE_WATER);
if (trace_inopen && trace_inwater)
return FALSE; // sight line crossed contents
if (trace_ent != self.enemy)
{
if (trace_ent.classname == "player")
return TRUE; // go ahead and hit a player
return FALSE; // don't have a clear shot
}
return TRUE;
}
/*
===========
ai_attack_finished
lunaran: nightmare is no longer made harder by all monsters always firing. they looked
really stupid when they'd automatically become turrets, and it made combat much less
mobile and dynamic (shamblers were particularly 'cheesable')
monster attack frequency is no longer used as a means to artificially inflate or
scale difficulty. a theoretical player who begins learning Quake on Easy would gain
skills and reflexive instincts which can be guaranteed to carry over to higher skills
as that player improves to higher challenges.
============
*/
void(float t) ai_attack_finished =
{
self.attack_finished = time + t;
}
/*
===========
ai_check_refire
these monsters DO fire more than once on nightmare, but not infinitely over and
over - making it random makes it uncertain and thus not cheesable
============
*/
void (void() th, float minf) ai_check_refire_min =
{
if (!enemy_alive())
return;
if (!CheckClearAttack())
return;
if (self.cnt < minf)
{
self.cnt += 1;
self.think = th;
return;
}
// no further refire unless nightmare
if (skill < 3)
{
self.cnt = 0;
return;
}
// diminish chances of refire with each extra shot
self.cnt = max(1, (self.cnt-minf) * 2);
if ( random() * self.cnt > 0.5 )
{
self.cnt = 0;
return;
}
self.cnt += minf;
self.think = th;
}
void (void() th) ai_check_refire =
{
ai_check_refire_min(th, 0);
}
/*
===========
CheckAttack
The player is in view, so decide to move or launch an attack
Returns FALSE if movement should continue
============
*/
float() CheckAttack =
{
local float chance;
if (!CheckClearAttack()) return FALSE;
// always melee immediately when close enough
if ((enemy_range == RANGE_MELEE && z_overlap(self.enemy)) ||
(has_invis(self.enemy) && random() < 0.1) ) // wave arms randomly now and then if target is invisible
{
if (self.th_melee)
{
self.th_melee();
return TRUE;
}
}
if (!self.th_missile) return FALSE;
if (enemy_range >= RANGE_FAR) return FALSE;
if (enemy_range == RANGE_MELEE)
{
chance = 0.9;
self.attack_finished = 0;
}
if (time < self.attack_finished) return FALSE; // after melee check
if (enemy_range == RANGE_NEAR)
{
if (self.th_melee)
chance = 0.2;
else
chance = 0.4;
}
else if (enemy_range == RANGE_MID)
{
if (self.th_melee)
chance = 0.05;
else
chance = 0.1;
}
else if (enemy_range >= RANGE_FAR)
chance = 0;
if (random() < chance)
{
self.th_missile();
ai_attack_finished (2*random());
return TRUE;
}
return FALSE;
}
/*
==============================================================================
WAKING UP
==============================================================================
*/
void() HuntTarget =
{
self.goalentity = self.enemy;
self.ideal_yaw = enemy_yaw();
self.think = self.th_run;
self.nextthink = time + 0.1;
ai_attack_finished (1); // wait a while before first attack
}
void() SightSound =
{
if (self.classname == "monster_ogre" )
sound (self, CHAN_VOICE, "ogre/ogwake.wav", 1, ATTN_NORM);
else if (self.classname == "monster_knight" || self.classname == "monster_axegrunt")
sound (self, CHAN_VOICE, "knight/ksight.wav", 1, ATTN_NORM);
else if (self.classname == "monster_shambler")
sound (self, CHAN_VOICE, "shambler/ssight.wav", 1, ATTN_NORM);
else if (self.classname == "monster_demon1")
sound (self, CHAN_VOICE, "demon/sight2.wav", 1, ATTN_NORM);
else if (self.classname == "monster_wizard")
sound (self, CHAN_VOICE, "wizard/wsight.wav", 1, ATTN_NORM);
else if (self.classname == "monster_zombie")
sound (self, CHAN_VOICE, "zombie/z_idle.wav", 1, ATTN_NORM);
else if (self.classname == "monster_dog")
sound (self, CHAN_VOICE, "dog/dsight.wav", 1, ATTN_NORM);
else if (self.classname == "monster_hell_knight" )
sound (self, CHAN_VOICE, "hknight/sight1.wav", 1, ATTN_NORM);
else if (self.classname == "monster_tarbaby")
sound (self, CHAN_VOICE, "blob/sight1.wav", 1, ATTN_NORM);
else if (self.classname == "monster_enforcer")
{
local float rsnd;
rsnd = random();
if (rsnd < 0.25)
sound (self, CHAN_VOICE, "enforcer/sight1.wav", 1, ATTN_NORM);
else if (rsnd < 0.5)
sound (self, CHAN_VOICE, "enforcer/sight2.wav", 1, ATTN_NORM);
else if (rsnd < 0.75)
sound (self, CHAN_VOICE, "enforcer/sight3.wav", 1, ATTN_NORM);
else
sound (self, CHAN_VOICE, "enforcer/sight4.wav", 1, ATTN_NORM);
}
else if (self.classname == "monster_army")
sound (self, CHAN_VOICE, "soldier/sight1.wav", 1, ATTN_NORM);
else if (self.classname == "monster_shalrath")
sound (self, CHAN_VOICE, "shalrath/sight.wav", 1, ATTN_NORM);
}
void() FoundTarget =
{
while(!enemy_alive())
{
if (self.oldenemy)
{
self.enemy = self.oldenemy;
self.oldenemy = world;
}
else
{
self.enemy = world;
self.th_stand();
return;
}
}
if (self.enemy.classname == "player")
{ // let other monsters see this monster for a while
sight_entity = self;
sight_entity_time = time;
}
self.show_hostile = time + 1; // wake up other monsters
self.dmgtime = time + 1; // aggro timer
self.search_time = time + 3; // aggro timer
SightSound ();
// for awakening with velocity
if (self.movetype == MOVETYPE_STEP && self.movedir != '0 0 0')
{
self.velocity = self.movedir;
self.flags = not(self.flags, FL_ONGROUND);
self.movedir = '0 0 0'; // don't leap again if an infight starts
}
HuntTarget ();
}
float(entity client) FilterTarget =
{
if (client.flags & FL_NOTARGET || client.movetype == MOVETYPE_NOCLIP)
return FALSE;
if (client.health <= 0 || client.deadflag)
return FALSE;
if (client.customflags & (CFL_PLUNGE|CFL_LIMBO))
return FALSE;
if (range(client) == RANGE_TOOFAR)
return FALSE;
return TRUE;
}
/*
===========
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.
============
*/
float() FindTarget =
{
local entity client;
local float r;
//dprint("in findtarget\n");
// (spawnflags & 3) unhacked by lunaran since I actually want to use spawnflag 2 for something
// apparently all the mega-enforcers in lunsp1 were ambush because of this ... oops
if ( sight_entity_time >= time - 0.1 && ( !(self.spawnflags & SPAWN_AMBUSH ) ) )
{
client = sight_entity;
if (client.enemy == self.enemy)
return FALSE;
}
else
{
// to avoid spending too much time, only check a single client (or fakeclient)
// this means multiplayer games have slightly slower noticing monsters
client = checkclient();
if (!client)
return FALSE; // no check entities in PVS
}
if (client == self.enemy)
return FALSE;
if (!FilterTarget(client))
return FALSE;
if (client.classname != "player" && !FilterTarget(client.enemy))
return FALSE; // don't wake up other monsters in notarget mode
if (!visible (client))
return FALSE;
r = range(client);
if (r == RANGE_NEAR)
{
if (client.show_hostile < time && !infront(client))
return FALSE;
}
else if (r == RANGE_MID || r == RANGE_FAR)
{
if ( !infront(client) )
return FALSE;
}
// the only two things that alert monsters when invisible besides damage:
// - firing a weapon
// - bumping into a dog
if (has_invis(client))
{
if (self.classname == "monster_dog" && client.classname == "player")
{
if (r != RANGE_MELEE)
return FALSE;
}
else if (client.show_hostile < time)
{
return FALSE;
}
}
// got one
self.enemy = client;
if (self.enemy.classname != "player")
{
self.enemy = self.enemy.enemy; // angered by a monster angering, use its enemy
if (self.enemy.classname != "player")
{
self.enemy = world;
return FALSE;
}
}
FoundTarget();
return TRUE;
}
void(entity m) ai_freeze_monster =
{
if (m == world)
error("tried to freeze the world");
if (m.nextthink > time + 0.11 || m.nextthink < time)
return; // don't mess with what isn't active anyway
m.nextthink = time + A_SHITLOAD;
m.button0 = m.movetype;
m.button1 = m.solid;
m.button2 = m.takedamage;
m.oldorigin = m.velocity;
m.movetype = MOVETYPE_NONE;
m.solid = SOLID_NOT;
m.takedamage = DAMAGE_NO;
m.velocity = VEC_ORIGIN;
}
void(entity m) ai_unfreeze_monster =
{
if (m == world)
error("tried to unfreeze the world");
if (!m.button0 && !m.button1 && !m.button2)
return; // never frozen
m.nextthink = time + random() * 0.1 + 0.01;
m.movetype = m.button0;
m.solid = m.button1;
m.takedamage = m.button2;
m.velocity = m.oldorigin;
m.button0 = m.button1 = m.button2 = 0;
}
/*
==============================================================================
PATH PATROL CODE
The angle of the pathcorner effects standing and bowing direction, but has
no effect on movement, which always heads to the next target.
==============================================================================
*/
void() path_corner_touch =
{
if (other.goalentity != self) return;
if (other.enemy) return; // fighting, not following a path
//bprint("valid pathcorner touch\n");
if (self.target != string_null)
{
other.goalentity = findunlocked(world, targetname, self.target);
}
else
{
other.goalentity = world;
}
if (!other.goalentity)
{
//bprint("dude stopped without a goalentity\n");
other.pausetime = time + A_SHITLOAD;
other.think = other.th_stand;
// other.th_stand ();
if (self.angles_y)
other.ideal_yaw = self.angles_y;
return;
}
if (other.classname == "monster_ogre")
sound (other, CHAN_VOICE, "ogre/ogdrag.wav", 1, ATTN_IDLE);// play chainsaw drag sound
if (self.wait)
{
other.pausetime = time + self.wait;
other.think = other.th_stand;
// other.th_stand ();
if (self.angles_y)
other.ideal_yaw = self.angles_y;
return;
}
other.ideal_yaw = vectoyaw(other.goalentity.origin - other.origin);
}
/*QUAKED path_corner (0.5 0.3 0) (-8 -8 -8) (8 8 8) - - - - BEZIER
Waypoint for platforms and monsters. Will stop here for good if no path_corner is targeted by this entity.
Monsters who wait here will turn to face 'angle'.
Keys:
"targetname" must be present. The name of this pathcorner.
"target" the next spot to move to. If not present, stop here for good.
"wait" The number of seconds to spend standing here
"angle" direction to face while standing here
"speed" tell a visiting func_train to change its speed. If a path_corner's speed is -1, the func_train's move when LEAVING that corner will be to snap instantly to the next corner.
Spawnflags:
BEZIER Act as a bilinear control point between the previous and next pathcorner in the chain (train only, no monster patrols)
"count" change number of steps of interpolation along the curve the train will make (default 10)
*/
/*FGD
@PointClass base(Appearflags, Targetname, Target, Angle) size(16 16 16) color(128 80 0) =
path_corner :
"Waypoint for platforms and monsters. Will stop here for good if no path_corner is targeted by this entity.
Monsters who wait here will turn to face 'angle'.
Checking the Bezier spawnflag will make this pathcorner act as a bilinear control point - meaning curved motion - between the previous and next pathcorner in the chain (train only, no monster patrols).
"count" change number of steps of interpolation along the curve the train will make (default 10)"
[
spawnflags(Flags) = [
16 : "Bezier point" : 0
]
wait(string) : "Wait time (seconds)" : "0"
speed(string) : "A visiting func_train to change its speed to this. If 'speed' is -1, the func_train's move when LEAVING that corner will be to snap instantly to the next corner." : "0"
count(integer) : "steps of interpolation along this bezier curve segment" : 10
]
*/
void() path_corner =
{
if (!SUB_ShouldSpawn()) return;
if (self.targetname == string_null)
{
dprint3("path_corner with no targetname at ", vtos(self.origin), "\n");
remove(self);
return;
}
if (!self.wait)
{
if (self.pausetime)
self.wait = self.pausetime;
//else if (!self.target)
// self.wait = -1;
}
if ((self.spawnflags & 16) && self.count <= 0)
self.count = 10;
self.solid = SOLID_TRIGGER;
self.touch = path_corner_touch;
setsize (self, '-8 -8 -8', '8 8 8');
}
/*
=============
victim_path_expand
keep expanding the victim-approach trigger so monsters don't keep
trying to approach a dead victim if it's getting crowded
=============
*/
void() victim_path_expand =
{
self.cnt += 1;
if (self.cnt > 4)
{
// try to catch anyone left and then stop being such a bigass trigger
setsize(self, self.mins - '512 512 0', self.maxs + '512 512 0');
self.think = SUB_Remove;
self.nextthink = time + 0.2;
force_retouch = 2;
return;
}
setsize(self, self.mins - '64 64 0' * self.cnt, self.maxs + '64 64 0' * self.cnt);
self.nextthink = time + 2 * (5-self.cnt);
}
/*
=============
ai_approach_victim
monsters walk towards a vanquished player and stop when close enough to admire their handiwork
=============
*/
void(entity vic) ai_approach_victim =
{
entity targ;
// bind the trigger to the dead player and reuse it so we don't make a
// bazillion of them when the player dies to a bazillion monsters
if (vic.enemy && vic.enemy.classname == "victim_path")
{
targ = vic.enemy;
}
else
{
targ = spawn();
targ.classname = "victim_path";
targ.solid = SOLID_TRIGGER;
setorigin(targ, self.goalentity.origin);
setsize (targ, '-64 -64 -512', '64 64 1024');
//targ.angles = self.angles;
targ.touch = path_corner_touch;
targ.think = victim_path_expand;
targ.nextthink = time + 5;
targ.lifetime_finished = time + 10;
vic.enemy = targ;
}
self.goalentity = targ;
self.th_walk ();
}
/*
=============
ai_check_liquid
take damage from slime and lava. returns FALSE if monster died from it.
=============
*/
float() ai_check_liquid =
{
// there are hacked takedamage cthons out there, and they're all in the lava
if (self.type == "boss" || self.classname == "monster_rotfish")
return TRUE;
vector wtt;
wtt = WaterTest();
float wl, wt;
wl = wtt_x;
wt = wtt_y;
// never do liquid damage for some mild wading, since lots of ep3 has lava
// the monsters can step into and out of
if (wl < 3)
return TRUE;
// monsters that spawn in slime/lava were clearly intended to be there by the
// mapper, so give them special dispensation to not quietly die before the
// player ever finds them. also, revoke their liquid rights once they leave, so
// they just die instead of staying lost if they fall back in
if (!wl)
{
self.customflags = not(self.customflags, CFL_LIQUID_IMMUNE);
return TRUE;
}
if (self.customflags & CFL_LIQUID_IMMUNE)
return TRUE;
if (self.type == "zombie")
{
// zombies immune to slime (or else they just keep falling and getting up)
if (wt == CONTENT_LAVA) // but always gib if touching lava
T_Damage(self, world, world, self.health + 10);
}
else
{
if (wt == CONTENT_LAVA)
T_Damage(self, world, world, wl * 10);
if (wt == CONTENT_SLIME && self.classname != "monster_wizard")
// scrags will happily fly down into slime, and they do spit green shit anyway
T_Damage(self, world, world, wl * 5);
}
return self.health > 0;
}
/*
==============================================================================
ANIMATION
==============================================================================
*/
/*
=============
ai_face
Stay facing the enemy
=============
*/
void() ai_face =
{
if (self.flags & (FL_FLY|FL_SWIM))
self.velocity = '0 0 0';
self.ideal_yaw = enemy_yaw();
ChangeYaw ();
}