forked from itslunaranyo/copper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monsters.qc
775 lines (652 loc) · 17.9 KB
/
monsters.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
/*
==============================================================================
MONSTERS
All things spawning and initializing
==============================================================================
*/
/*FGD
@baseclass base(Angle, Appearflags, Target, Targetname, Deathtype) color(220 0 0) = Monster
[
spawnflags(Flags) =
[
1 : "Ambush" : 0
16 : "Triggered Spawn" : 0
32 : "No Teleflash on Spawn" : 0
64 : "Don't Spawn If Would Telefrag" : 0
128 : "Spawn Angry" : 0
]
movedir(string) : "Auto jump velocity on spawn/awaken (x y z, in worldspace)"
rmovedir(string) : "Angle-relative auto jump velocity on spawn/awaken (forward right up)"
count(integer) : "If triggered: Number of times a spawn can be triggered before stopping. -1 for infinite spawns, -4 to auto-scale the count to the number of clients in coop."
wait(string) : "If triggered: Pause before spawning" : "0"
rand(string) : "If triggered: Random extra time before spawning" : "0"
netname(string) : "If triggered: Spawned monster(s) will have this targetname"
]
*/
// at map start, anything that is a monster calls this and adds itself to various
// balance debugging totals, to take some of the guesswork out of ammo placement
void() TallyHitpoints =
{
if (!cvar("developer")) return;
//dprint5("tally hitpoints for ",self.classname," adding ",ftos(self.health),"\n");
if (self.classname == "monster_boss" || self.classname == "monster_oldone")
return;
local float num;
num = 1;
if (self.spawnflags & SPAWN_TRIGGERED)
{
if (self.count > 1)
num = self.count;
}
if (self.type == "zombie")
{
if ( !( self.spawnflags & SPAWN_CRUCIFIED ) )
num_zombies += num;
}
else
monster_health += self.health * num;
if (self.classname == "monster_army")
ammo_total += 5 * DEBUG_DMG_PER_SHELL;
//if (self.classname == "monster_enforcer")
// ammo_total += 5 * DEBUG_DMG_PER_CELL;
if (self.classname == "monster_ogre")
num_rockets += 1;
}
/*
================================================================
SPAWNING
all monster_* entities can be used as triggerable monster teleport spawns,
which is way better than building a big teleport setup in a hidden room
for each one.
setting 'count' on any monster allows the same entity to be triggered more than
once to spawn monsters repeatedly. 'count' monsters are added to the kill total
when the map starts.
setting count to a negative number makes the spawner unlimited use, and monsters
are added to the kill total as they're spawned.
FIXME: their bodies and head gibs WILL stick around forever
================================================================
*/
/*
================
monster_spawnsetup_go
sanity check for trigger-spawned monsters with no existing targeters
fix by iw
================
*/
void() monster_spawnsetup_go =
{
self.think = SUB_Null; // just to tidy up after ourselves
if (self.targetname == string_null)
{
dprint5("WARNING: removed triggered-spawn ", self.classname,
" with no targetname at ", vtos(self.origin), "\n");
remove(self);
return;
}
if (cvar("developer"))
{
if (!SUB_VerifyTriggerable())
{
dprint4("WARNING: triggered-spawn ", self.classname,
" with unmatched targetname '", self.targetname);
dprint3("' at ", vtos(self.origin), "\n");
//remove(self);
return;
}
}
self.customflags |= CFL_SPAWNER;
self.use = self.think1;
self.think1 = SUB_Null; // just to tidy up after ourselves
if (!self.count)
self.count = 1;
if (self.count == -1)
self.count = 0;
if (self.count != -4)
addmonster(self.count); // this count gets added late
};
/*
================
monster_spawnsetup
Checks if this monster is in some way a spawner of monsters, and returns
TRUE if so, after scheduling appropriate setup. A return of TRUE should
signal the calling spawnfunc that the monster shouldn't continue to be
spawned right now.
'spawnthink' is the function that should be used as the triggering action
if this monster is a spawner.
================
*/
float( void() spawnthink ) monster_spawnsetup =
{
TallyHitpoints();
if (!(self.spawnflags & SPAWN_TRIGGERED))
return FALSE;
// if we're not in coop mode, count -4 will always evaluate to 1, so go ahead and default
// this field back to 0 so the kill count doesn't change during play if it doesn't have to
if (self.count == -4 && !cvar("coop"))
self.count = 0;
// wait for all potential targeters to finish spawning
self.think1 = spawnthink;
self.think = monster_spawnsetup_go;
self.nextthink = time + 0.1 + random() * 0.05; // spread thinks to not ram quake to death with sub_verifytriggerable checks
return TRUE;
}
void(float num) addmonster =
{
if (!self.th_checkattack)
self.th_checkattack = CheckAttack;
if (!num) return;
total_monsters = total_monsters + num;
WriteByte (MSG_ALL, SVC_UPDATESTAT);
WriteByte (MSG_ALL, STAT_TOTALMONSTERS);
WriteLong (MSG_ALL, total_monsters);
}
float(entity me) monster_check_enemy_activator =
{
if ((activator.flags & (FL_CLIENT|FL_MONSTER)) && activator.health <= 0)
return FALSE;
return TRUE;
}
float(entity me) monster_check_enemy_inheritance =
{
if (!(activator.flags & FL_MONSTER))
return FALSE;
if (!(activator.enemy.health > 0 || activator.oldenemy.health > 0))
return FALSE;
if (!(activator.enemy.classname == "player" || activator.oldenemy.classname == "player"))
return FALSE;
return TRUE;
}
entity(float onlymonsters) find_touching =
{
entity head = findradius(BoundsCenter(self), self.size_z + 64);
while (head != world)
{
if (head.health <= 0 ||
(head.solid == SOLID_NOT || head.solid == SOLID_TRIGGER) ||
!BoundsTouching(self.absmin, self.absmax, head.absmin, head.absmax, 2) ||
(onlymonsters && !(head.flags & FL_MONSTER)) )
{
head = head.chain;
}
else return head;
}
return world;
}
void() mon_spawner_tryspawn
{
if (find_touching(TRUE))
{
self.nextthink = time + 0.25;
return;
}
if (!(self.spawnflags & SPAWN_NO_TFOG))
teleport_flash();
self.think1();
}
entity( void() spawnthink ) mon_spawner_use =
{
//playercount_convert(count);
if (self.count == -4)
{
self.count = clients;
addmonster(clients);
}
entity mon;
float pause;
mon = spawn();
mon.flags |= FL_MONSTER;
setorigin(mon, self.origin);
mon.angles = self.angles;
pause = self.wait + random() * self.rand;
mon.nextthink = time + pause;
mon.spawnflags = self.spawnflags;
mon.movedir = self.movedir;
mon.rmovedir = self.rmovedir;
mon.lip = self.lip;
mon.state = self.state;
mon.alpha = self.alpha;
mon.skin = self.skin;
mon.effects = self.effects;
mon.armortype = self.armortype;
mon.armorvalue = self.armorvalue;
mon.items = self.items;
mon.gravity = self.gravity;
mon.invincible_finished = self.invincible_finished;
mon.invisible_finished = self.invisible_finished;
mon.super_damage_finished = self.super_damage_finished;
mon.radsuit_finished = self.radsuit_finished;
mon.health = self.health;
mon.delay = self.delay;
mon.message = self.message;
mon.deathtype = self.deathtype;
SUB_CopyTargets(mon);
mon.targetname = self.netname;
// don't spawnfrag monsters if the mapper expects us to be spawning into chaos
if ( (self.spawnflags & SPAWN_NO_TFRAG) )
{
// set monster's size now so we can check the landing zone for other monsters
setsize(mon,self.mins,self.maxs);
mon.think = mon_spawner_tryspawn;
mon.think1 = spawnthink;
}
else
{
mon.think = spawnthink;
if (!(self.spawnflags & SPAWN_NO_TFOG))
teleport_flash_delay(pause);
}
// set .enemy before monster_start thinks, because 'activator' will be different by then
if ( !self.enemy && (self.spawnflags & SPAWN_INSTAWAKE) && monster_check_enemy_activator(mon) )
{
// theSolipsist fix: monsters triggered or awakened by other monsters inherit their enemies
if (monster_check_enemy_inheritance(mon))
{
mon.enemy = activator.enemy;
mon.oldenemy = activator.oldenemy;
}
else
mon.enemy = activator;
}
if (self.count > 0)
{
self.count = self.count - 1;
if (self.count == 0)
{
SUB_Remove();
}
}
else
{
addmonster(1); // add them one at a time if this is an unlimited spawner
}
return mon;
}
void(entity m) monster_kill =
{
T_Damage(m, self, self, m.health + 100);
}
/*
================
monster_use
Using a monster makes it angry at the current activator, because
nobody likes to be used
================
*/
void() monster_use =
{
if (self.health <= 0)
return;
if (self.enemy)
return;
if (has_invis(activator))
return;
if (activator.flags & FL_NOTARGET)
return;
if (!monster_check_enemy_activator(self)) return;
// theSolipsist fix: monsters triggered or awakened by other monsters inherit their enemies
if (monster_check_enemy_inheritance(self))
{
self.enemy = activator.enemy;
self.oldenemy = activator.oldenemy;
}
else
self.enemy = activator;
// delay reaction so the monster is still heard if it's teleported
self.nextthink = time + 0.1;
self.think = FoundTarget;
}
/*
================
monster_death_use
When a monster dies, it fires all of its targets with the current
enemy as activator.
================
*/
void() monster_death_use =
{
// fall to ground
if (self.flags & FL_FLY)
self.flags = self.flags - FL_FLY;
if (self.flags & FL_SWIM)
self.flags = self.flags - FL_SWIM;
if (!self.target && !self.target2 && !self.target3 && !self.target4 && !self.killtarget)
return;
// make a player activator even if the monster was killed while infighting
if (self.enemy.classname != "player")
{
if (self.oldenemy.classname == "player")
activator = self.oldenemy;
else
activator = get_closest_client();
}
else activator = self.enemy;
SUB_UseTargets ();
}
//============================================================================
/*
================
Common monster starts
================
*/
void() monster_start =
{
//if (self.oldorigin == VEC_ORIGIN)
// self.oldorigin = self.origin;
if (self.rmovedir != VEC_ORIGIN)
{
makevectors(self.angles);
self.movedir = v_forward * self.rmovedir_x + v_right * self.rmovedir_y + v_up * self.rmovedir_z;
}
// moved from mon_spawner_use because it was too early to catch the monster's mins and maxs
if ((self.type != "zombie" || !(self.spawnflags & SPAWN_LYING))) // lying zombies are nonsolid
{
entity tdeath = spawn_tdeath(self.origin, self);
if (tdeath && self.spawnflags & SPAWN_NO_TFRAG)
{
// we still need to spawn a tdeath so players counter-telefrag these monsters if
// they're in the way
tdeath.nextthink = time + 0.05;
// we make the tdeath remove itself before the minimum time for the spawned
// monster's nextthink, or else monsters can graze the telefrag trigger and
// explode even if they weren't truly blocking the spawn
}
}
// wait a few frames to make sure doors have spawned before doing droptofloor
self.nextthink = 1.15;
// why 1.15 is a magic number:
// - quake starts 'time' at 1.0 seconds.
// - doors and movers and stuff reposition themselves at 1.1 seconds.
// - items drop themselves into place at 1.2 seconds, after movers, so that they fall on them
// in their final positions.
// - we want monsters to do this too, but before items do, because they were always before
// items originally and altering the drop order too much could cause items that didn't
// fall out of the world before to do so erroneously in Copper.
// - we don't use 'time + 0.15' because this could be running on a late spawn. a constant
// 1.15 will always be when we want at map start but in the past upon late spawn.
if (self.type == string_null)
self.type = self.classname;
// needed for monsters to be healed by a target_heal
self.max_health = self.health;
}
void() monster_start_go =
{
local entity pathgoal;
self.takedamage = DAMAGE_AIM;
self.ideal_yaw = self.angles * '0 1 0';
self.use = monster_use;
self.flags = self.flags | FL_MONSTER;
// check if the mapper placed them touching a killer liquid and grant them immunity to it
vector wtt;
wtt = WaterTest();
if (wtt_x)
{
if (wtt_y == CONTENT_LAVA || wtt_y == CONTENT_SLIME)
{
self.customflags |= CFL_LIQUID_IMMUNE;
}
}
// ai_nav
//self.radius = (self.maxs_x - self.mins_x) * 0.7;
if (self.enemy.flags & FL_NOTARGET || self.enemy.movetype == MOVETYPE_NOCLIP)
self.enemy = world;
if (self.enemy)
{
self.th_stand();
self.think = FoundTarget;
}
else if (self.target)
{
pathgoal = find(world, targetname, self.target);
if (!pathgoal)
{
dprint (self.classname);
dprint (" at ");
dprint (vtos(self.origin));
dprint (" can't find target\n");
}
if (pathgoal.classname == "path_corner")
{
self.goalentity = pathgoal;
self.ideal_yaw = vectoyaw(self.goalentity.origin - self.origin);
self.th_walk ();
}
else
{
self.pausetime = time + A_SHITLOAD;
self.th_stand ();
}
}
else
{
self.pausetime = time + A_SHITLOAD;
self.th_stand ();
}
// spread think times so they don't all happen at same time
// add tiny minimum in case random() ever returns exactly 0 (rare but possible)
self.nextthink = time + random()*0.1 + 0.05;
}
/*
================
Walkmonster starts
================
*/
void() walkmonster_start_go =
{
self.movetype = MOVETYPE_STEP;
// fix monsters being stuck in floor because of QSS fix
//if (self.oldorigin != VEC_ORIGIN)
// setorigin(self,self.oldorigin);
if (self.rmovedir != VEC_ORIGIN)
{
makevectors(self.angles);
self.movedir = v_forward * self.rmovedir_x + v_right * self.rmovedir_y + v_up * self.rmovedir_z;
self.rmovedir = VEC_ORIGIN;
}
if (self.movedir == VEC_ORIGIN && !(self.spawnflags & SPAWN_TRIGGERED) ) // always put telespawned monsters where the mapper wants
{
self.origin_z = self.origin_z + 1; // raise off floor a bit
droptofloor(0,0);
}
if (!walkmove(0,0))
{
dprint ("walkmonster in wall at: ");
dprint (vtos(self.origin));
dprint ("\n");
}
if (!self.yaw_speed)
self.yaw_speed = 20;
self.view_ofs = '0 0 25';
if (self.spawnflags & SPAWN_TRIGGERED && self.movedir != VEC_ORIGIN)
{
self.velocity = self.movedir;
self.movedir = VEC_ORIGIN;
}
monster_start_go();
}
void() walkmonster_start =
{
monster_start();
self.think = walkmonster_start_go;
}
/*
================
Flymonster starts
================
*/
void() flymonster_start_go =
{
self.movetype = MOVETYPE_FLY;
// fix monsters dropping to floor because of QSS fix
if (self.oldorigin != VEC_ORIGIN)
setorigin(self,self.oldorigin);
if (!self.yaw_speed)
self.yaw_speed = 10;
self.view_ofs = '0 0 25';
if (!walkmove(0,0))
{
dprint ("flymonster in wall at: ");
dprint (vtos(self.origin));
dprint ("\n");
}
monster_start_go();
}
void() flymonster_start =
{
monster_start();
// iw -- move these here so fish don't fall for a frame and a half
self.flags = self.flags | FL_FLY;
self.think = flymonster_start_go;
}
/*
================
Swimmonster starts
================
*/
void() swimmonster_start_go =
{
self.movetype = MOVETYPE_FLY;
// fix monsters dropping to floor because of QSS fix
if (self.oldorigin != VEC_ORIGIN)
setorigin(self,self.oldorigin);
if (!self.yaw_speed)
self.yaw_speed = 20;//10
self.view_ofs = '0 0 10';
// FIXME: why don't fish do a walkmove test?
monster_start_go();
// yes besides the fact that they don't have feet dickhead
}
void() swimmonster_start =
{
monster_start();
// iw -- move these here so fish don't fall for a frame and a half
self.flags = self.flags | FL_SWIM;
self.think = swimmonster_start_go;
}
/*
================
stuff for nomonsters 1
monsters which fire targets on death can't just not be spawned or the map
will break, so they become invisible eyes that fire their targets on sight
================
*/
float() nomonster_findtarget =
{
local entity client;
local float r;
if ( sight_entity_time >= time - 0.1 && ( !(self.spawnflags & SPAWN_AMBUSH ) ) )
{
client = sight_entity;
if (client.enemy == self.enemy)
return FALSE;
}
else
{
client = checkclient();
if (!client)
return FALSE; // no check entities in PVS
}
if (!FilterTarget(client))
return FALSE;
if (!visible (client))
return FALSE;
r = range(client);
if (r == RANGE_TOOFAR)
{
return FALSE;
}
return TRUE;
}
void() nomonster_sleep =
{
if (nomonster_findtarget())
{
sight_entity = self;
sight_entity_time = time;
self.show_hostile = time + 1;
SUB_UseTargets();
self.think = SUB_Remove;
//self.think = BecomeExplosion;
}
self.nextthink = time + 0.2;
//particle(self.origin, '0 0 0', 64, 16);
}
void() nomonster_find =
{
self.think = nomonster_sleep;
self.nextthink = time + 0.2;
entity e;
if (self.target != string_null)
{
e = find(world, targetname, self.target);
while(e)
{
if (e.classname != "path_corner")
return;
e = find(e, targetname, self.target);
}
}
if (self.target2 != string_null)
{
e = find(world, targetname, self.target2);
while(e)
{
if (e.classname != "path_corner")
return;
e = find(e, targetname, self.target2);
}
}
if (self.target3 != string_null)
{
e = find(world, targetname, self.target3);
while(e)
{
if (e.classname != "path_corner")
return;
e = find(e, targetname, self.target3);
}
}
if (self.target4 != string_null)
{
e = find(world, targetname, self.target4);
while(e)
{
if (e.classname != "path_corner")
return;
e = find(e, targetname, self.target4);
}
}
remove(self);
}
void() nomonster_go =
{
// a nomonster still has to be a solid so that it can be teleported out of teleboxes
self.solid = SOLID_SLIDEBOX;
self.movetype = MOVETYPE_FLY;
setsize(self, VEC_HULL_MIN, VEC_HULL_MAX);
self.think = nomonster_find;
self.view_ofs = '0 0 25';
self.nextthink = time + 0.2 + random();
}
float() nomonster =
{
if (cvar("nomonsters") == 0)
return FALSE;
if (self.target == string_null &&
self.target2 == string_null &&
self.target3 == string_null &&
self.target4 == string_null &&
self.killtarget == string_null)
{
remove(self);
return TRUE;
}
// make teleports work:
self.health = 1;
self.flags += FL_MONSTER;
if (self.targetname != string_null && self.spawnflags & SPAWN_TRIGGERED)
self.use = nomonster_go;
else
nomonster_go();
//self.classname = "nomonster";
return TRUE;
}