-
Notifications
You must be signed in to change notification settings - Fork 2
/
misc.qc
1770 lines (1492 loc) · 40.4 KB
/
misc.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
/*QUAKED func_group (0 0 0) ?
Used to group brushes together just for editor convenience.
*/
//=====================================================
static void(entity ent, entity other, entity activator) Use_Areaportal =
{
ent.count ^= 1; // toggle state
gi.SetAreaPortalState(ent.style, ent.count);
}
/*QUAKED func_areaportal (0 0 0) ?
This is a non-visible object that divides the world into
areas that are seperated when this portal is not activated.
Usually enclosed in the middle of a door.
*/
API_FUNC static void(entity ent) SP_func_areaportal =
{
ent.use = Use_Areaportal;
ent.count = 0; // always start closed;
}
//=====================================================
/*
=================
Misc functions
=================
*/
PROGS_LOCAL INLINE vector(int damage) VelocityForDamage =
{
return randomv('-100 -100 200', '100 100 300') * ((damage < 50) ? 0.7f : 1.2f);
}
PROGS_LOCAL void(entity ent) ClipGibVelocity =
{
if (ent.velocity.x < -300)
ent.velocity.x = -300f;
else if (ent.velocity.x > 300)
ent.velocity.x = 300f;
if (ent.velocity.y < -300)
ent.velocity.y = -300f;
else if (ent.velocity.y > 300)
ent.velocity.y = 300f;
if (ent.velocity.z < 200)
ent.velocity.z = 200f; // always some upwards
else if (ent.velocity.z > 500)
ent.velocity.z = 500f;
}
/*
=================
gibs
=================
*/
static void(entity self) gib_think =
{
self.s.frame++;
self.nextthink = level.framenum + 1;
if (self.s.frame == 10) {
self.think = G_FreeEdict;
self.nextthink = level.framenum + (int)(random(8f, 18f) * BASE_FRAMERATE);
}
}
void(entity self, entity other, vector normal, csurface_t surf) gib_touch =
{
vector normal_angles, right;
if (self.groundentity == null_entity)
return;
self.touch = 0;
if (normal) {
gi.sound(self, CHAN_VOICE, gi.soundindex("misc/fhit3.wav"), 1, ATTN_NORM, 0);
normal_angles = vectoangles(normal);
AngleVectors(normal_angles, 0, &right, 0);
self.s.angles = vectoangles(right);
if (self.s.modelindex == sm_meat_index) {
self.s.frame++;
self.think = gib_think;
self.nextthink = level.framenum + 1;
}
}
}
void(entity self, entity inflictor, entity attacker, int damage, vector point) gib_die =
{
G_FreeEdict(self);
}
void(entity self, string gibname, int damage, gib_type_t type) ThrowGib =
{
entity gib = G_Spawn();
vector sz = self.size * 0.5f;
vector origin = self.absmin + sz;
gib.s.origin = origin + randomv(-sz, sz);
gi.setmodel(gib, gibname);
gib.solid = SOLID_NOT;
gib.s.effects |= EF_GIB;
gib.flags |= FL_NO_KNOCKBACK;
gib.takedamage = true;
gib.die = gib_die;
float vscale;
if (type == GIB_ORGANIC)
{
gib.movetype = MOVETYPE_TOSS;
gib.touch = gib_touch;
vscale = 0.5f;
}
else
{
gib.movetype = MOVETYPE_BOUNCE;
vscale = 1.0f;
}
gib.velocity = self.velocity + (vscale * VelocityForDamage(damage));
ClipGibVelocity(gib);
gib.avelocity = randomv('600 600 600');
gib.think = G_FreeEdict;
gib.nextthink = level.framenum + (int)(random(10f, 20f) * BASE_FRAMERATE);
gi.linkentity(gib);
}
void(entity self, string gibname, int damage, gib_type_t type) ThrowHead =
{
self.s.skinnum = 0;
self.s.frame = 0;
self.mins = vec3_origin;
self.maxs = vec3_origin;
self.s.modelindex2 = 0;
gi.setmodel(self, gibname);
self.solid = SOLID_NOT;
self.s.effects |= EF_GIB;
self.s.effects &= ~EF_FLIES;
self.s.sound = 0;
self.flags |= FL_NO_KNOCKBACK;
self.svflags &= ~SVF_MONSTER;
self.takedamage = true;
self.die = gib_die;
float vscale;
if (type == GIB_ORGANIC)
{
self.movetype = MOVETYPE_TOSS;
self.touch = gib_touch;
vscale = 0.5f;
}
else
{
self.movetype = MOVETYPE_BOUNCE;
vscale = 1.0f;
}
self.velocity += (vscale * VelocityForDamage(damage));
ClipGibVelocity(self);
self.avelocity[YAW] = random(-600f, 600f);
self.think = G_FreeEdict;
self.nextthink = level.framenum + (int)(random(10f, 20f) * BASE_FRAMERATE);
gi.linkentity(self);
}
void(entity self, int damage) ThrowClientHead =
{
string gibname;
if (Q_rand() & 1)
{
gibname = "models/objects/gibs/head2/tris.md2";
self.s.skinnum = 1; // second skin is player
}
else
{
gibname = "models/objects/gibs/skull/tris.md2";
self.s.skinnum = 0;
}
self.s.origin[2] += 32;
self.s.frame = 0;
gi.setmodel(self, gibname);
self.mins = '-16 -16 0';
self.maxs = '16 16 16';
self.takedamage = false;
self.solid = SOLID_NOT;
self.s.effects = EF_GIB;
self.s.sound = 0;
self.flags |= FL_NO_KNOCKBACK;
self.movetype = MOVETYPE_BOUNCE;
self.velocity += VelocityForDamage(damage);
if (self.is_client)
{ // bodies in the queue don't have a client anymore
self.client.anim_priority = ANIM_DEATH;
self.client.anim_end = self.s.frame;
}
else
{
self.think = 0;
self.nextthink = 0;
}
gi.linkentity(self);
}
/*
=================
debris
=================
*/
static void(entity self, entity inflictor, entity attacker, int damage, vector point) debris_die =
{
G_FreeEdict(self);
}
void(entity self, string modelname, float speed, vector origin) ThrowDebris =
{
entity chunk;
vector v;
chunk = G_Spawn();
chunk.s.origin = origin;
gi.setmodel(chunk, modelname);
v.x = random(-100f, 100f);
v.y = random(-100f, 100f);
v.z = random(0f, 200f);
chunk.velocity = self.velocity + (speed * v);
chunk.movetype = MOVETYPE_BOUNCE;
chunk.solid = SOLID_NOT;
chunk.avelocity = randomv('600 600 600');
chunk.think = G_FreeEdict;
chunk.nextthink = level.framenum + (int)(random(5f, 10f) * BASE_FRAMERATE);
chunk.s.frame = 0;
chunk.flags = 0;
chunk.classname = "debris";
chunk.takedamage = true;
chunk.die = debris_die;
gi.linkentity(chunk);
}
/*QUAKED path_corner (.5 .3 0) (-8 -8 -8) (8 8 8) TELEPORT
Target: next path corner
Pathtarget: gets used when an entity that has
this path_corner targeted touches it
*/
static void(entity self, entity other, vector plane, csurface_t surf) path_corner_touch =
{
vector v;
entity next;
if (other.movetarget != self)
return;
if (other.enemy)
return;
if (self.pathtarget)
{
string savetarget = self.target;
self.target = self.pathtarget;
G_UseTargets(self, other);
self.target = savetarget;
}
if (self.target)
next = G_PickTarget(self.target);
else
next = world;
if (next && (next.spawnflags & 1))
{
v = next.s.origin;
v.z += next.mins.z;
v.z -= other.mins.z;
other.s.origin = v;
next = G_PickTarget(next.target);
other.s.event = EV_OTHER_TELEPORT;
}
other.goalentity = other.movetarget = next;
#ifdef SINGLE_PLAYER
if (self.wait)
{
other.monsterinfo.pause_framenum = level.framenum + (int)(self.wait * BASE_FRAMERATE);
other.monsterinfo.stand(other);
return;
}
if (!other.movetarget)
{
other.monsterinfo.pause_framenum = INT_MAX;
other.monsterinfo.stand(other);
}
else
{
v = other.goalentity.s.origin - other.s.origin;
other.ideal_yaw = vectoyaw(v);
}
#endif
}
API_FUNC static void(entity self) SP_path_corner =
{
if (!self.targetname)
{
gi.dprintf("path_corner with no targetname at %s\n", vtos(self.s.origin));
G_FreeEdict(self);
return;
}
self.solid = SOLID_TRIGGER;
self.touch = path_corner_touch;
self.mins = '-8 -8 -8';
self.maxs = '8 8 8';
self.svflags |= SVF_NOCLIENT;
gi.linkentity(self);
}
#ifdef SINGLE_PLAYER
/*QUAKED point_combat (0.5 0.3 0) (-8 -8 -8) (8 8 8) Hold
Makes this the target of a monster and it will head here
when first activated before going after the activator. If
hold is selected, it will stay here.
*/
static void(entity self, entity other, vector plane, csurface_t surf) point_combat_touch =
{
entity cactivator;
if (other.movetarget != self)
return;
if (self.target)
{
other.target = self.target;
other.goalentity = other.movetarget = G_PickTarget(other.target);
if (!other.goalentity)
{
gi.dprintf("%s at %s target %s does not exist\n", self.classname, vtos(self.s.origin), self.target);
other.movetarget = self;
}
self.target = 0;
}
else if ((self.spawnflags & 1) && !(other.flags & (FL_SWIM | FL_FLY)))
{
other.monsterinfo.pause_framenum = INT_MAX;
other.monsterinfo.aiflags |= AI_STAND_GROUND;
other.monsterinfo.stand(other);
}
if (other.movetarget == self)
{
other.target = 0;
other.movetarget = world;
other.goalentity = other.enemy;
other.monsterinfo.aiflags &= ~AI_COMBAT_POINT;
}
if (self.pathtarget)
{
string savetarget = self.target;
self.target = self.pathtarget;
if (other.enemy && other.enemy.is_client)
cactivator = other.enemy;
else if (other.oldenemy && other.oldenemy.is_client)
cactivator = other.oldenemy;
else if (other.activator && other.activator.is_client)
cactivator = other.activator;
else
cactivator = other;
G_UseTargets(self, cactivator);
self.target = savetarget;
}
}
API_FUNC static void(entity self) SP_point_combat =
{
if (deathmatch.intVal)
{
G_FreeEdict(self);
return;
}
self.solid = SOLID_TRIGGER;
self.touch = point_combat_touch;
self.mins = '-8 -8 -16';
self.maxs = '8 8 16';
self.svflags = SVF_NOCLIENT;
gi.linkentity(self);
}
#endif
/*QUAKED info_null (0 0.5 0) (-4 -4 -4) (4 4 4)
Used as a positional target for spotlights, etc.
*/
API_FUNC void(entity self) SP_info_null =
{
G_FreeEdict(self);
}
/*QUAKED info_notnull (0 0.5 0) (-4 -4 -4) (4 4 4)
Used as a positional target for lightning.
*/
API_FUNC void(entity self) SP_info_notnull =
{
self.absmin = self.s.origin;
self.absmax = self.s.origin;
}
/*QUAKED light (0 1 0) (-8 -8 -8) (8 8 8) START_OFF
Non-displayed light.
Default light value is 300.
Default style is 0.
If targeted, will toggle between on and off.
Default _cone value is 10 (used to set size of light for spotlights)
*/
#ifdef SINGLE_PLAYER
const int START_OFF = 1;
static void(entity self, entity other, entity cactivator) light_use =
{
if (self.spawnflags & START_OFF) {
gi.configstring(CS_LIGHTS + self.style, "m");
self.spawnflags &= ~START_OFF;
} else {
gi.configstring(CS_LIGHTS + self.style, "a");
self.spawnflags |= START_OFF;
}
}
#endif
API_FUNC static void(entity self) SP_light =
{
#ifdef SINGLE_PLAYER
// no targeted lights in deathmatch, because they cause global messages
if (!self.targetname || deathmatch.intVal)
{
#endif
G_FreeEdict(self);
#ifdef SINGLE_PLAYER
return;
}
if (self.style >= 32)
{
self.use = light_use;
if (self.spawnflags & START_OFF)
gi.configstring(CS_LIGHTS + self.style, "a");
else
gi.configstring(CS_LIGHTS + self.style, "m");
}
#endif
}
/*QUAKED func_wall (0 .5 .8) ? TRIGGER_SPAWN TOGGLE START_ON ANIMATED ANIMATED_FAST
This is just a solid wall if not inhibited
TRIGGER_SPAWN the wall will not be present until triggered
it will then blink in to existance; it will
kill anything that was in it's way
TOGGLE only valid for TRIGGER_SPAWN walls
this allows the wall to be turned on and off
START_ON only valid for TRIGGER_SPAWN walls
the wall will initially be present
*/
static void(entity self, entity other, entity cactivator) func_wall_use =
{
if (self.solid == SOLID_NOT) {
self.solid = SOLID_BSP;
self.svflags &= ~SVF_NOCLIENT;
KillBox(self);
} else {
self.solid = SOLID_NOT;
self.svflags |= SVF_NOCLIENT;
}
gi.linkentity(self);
if (!(self.spawnflags & 2))
self.use = 0;
}
API_FUNC static void(entity self) SP_func_wall =
{
self.movetype = MOVETYPE_PUSH;
gi.setmodel(self, self.model);
if (self.spawnflags & 8)
self.s.effects |= EF_ANIM_ALL;
if (self.spawnflags & 16)
self.s.effects |= EF_ANIM_ALLFAST;
// just a wall
if ((self.spawnflags & 7) == 0) {
self.solid = SOLID_BSP;
gi.linkentity(self);
return;
}
// it must be TRIGGER_SPAWN
if (!(self.spawnflags & 1)) {
// gi.dprintf("func_wall missing TRIGGER_SPAWN\n");
self.spawnflags |= 1;
}
// yell if the spawnflags are odd
if (self.spawnflags & 4) {
if (!(self.spawnflags & 2)) {
gi.dprintf("func_wall START_ON without TOGGLE\n");
self.spawnflags |= 2;
}
}
self.use = func_wall_use;
if (self.spawnflags & 4) {
self.solid = SOLID_BSP;
} else {
self.solid = SOLID_NOT;
self.svflags |= SVF_NOCLIENT;
}
gi.linkentity(self);
}
/*QUAKED func_object (0 .5 .8) ? TRIGGER_SPAWN ANIMATED ANIMATED_FAST
This is solid bmodel that will fall if it's support it removed.
*/
static void(entity self, entity other, vector normal, csurface_t surf) func_object_touch =
{
// only squash thing we fall on top of
if (!normal)
return;
if (normal[2] < 1.0f)
return;
if (other.takedamage == false)
return;
T_Damage(other, self, self, vec3_origin, self.s.origin, vec3_origin, self.dmg, 1, 0, MOD_CRUSH);
}
static void(entity self) func_object_release =
{
self.movetype = MOVETYPE_TOSS;
self.touch = func_object_touch;
}
static void(entity self, entity other, entity cactivator) func_object_use =
{
self.solid = SOLID_BSP;
self.svflags &= ~SVF_NOCLIENT;
self.use = 0;
KillBox(self);
func_object_release(self);
}
API_FUNC static void(entity self) SP_func_object =
{
gi.setmodel(self, self.model);
self.mins.x += 1;
self.mins.y += 1;
self.mins.z += 1;
self.maxs.x -= 1;
self.maxs.y -= 1;
self.maxs.z -= 1;
if (!self.dmg)
self.dmg = 100;
if (self.spawnflags == 0) {
self.solid = SOLID_BSP;
self.movetype = MOVETYPE_PUSH;
self.think = func_object_release;
self.nextthink = level.framenum + 2;
} else {
self.solid = SOLID_NOT;
self.movetype = MOVETYPE_PUSH;
self.use = func_object_use;
self.svflags |= SVF_NOCLIENT;
}
if (self.spawnflags & 2)
self.s.effects |= EF_ANIM_ALL;
if (self.spawnflags & 4)
self.s.effects |= EF_ANIM_ALLFAST;
self.clipmask = MASK_MONSTERSOLID;
gi.linkentity(self);
}
#ifdef SINGLE_PLAYER
/*QUAKED func_explosive (0 .5 .8) ? Trigger_Spawn ANIMATED ANIMATED_FAST
Any brush that you want to explode or break apart. If you want an
ex0plosion, set dmg and it will do a radius explosion of that amount
at the center of the bursh.
If targeted it will not be shootable.
health defaults to 100.
mass defaults to 75. This determines how much debris is emitted when
it explodes. You get one large chunk per 100 of mass (up to 8) and
one small chunk per 25 of mass (up to 16). So 800 gives the most.
*/
static void(entity self, entity inflictor, entity attacker, int damage, vector point) func_explosive_explode =
{
vector origin;
vector chunkorigin;
vector csize;
int count;
int cmass;
// bmodel origins are (0 0 0), we need to adjust that here
csize = self.size * 0.5f;
origin = self.absmin + csize;
self.s.origin = origin;
self.takedamage = false;
if (self.dmg)
T_RadiusDamage(self, attacker, self.dmg, 0, self.dmg + 40, MOD_EXPLOSIVE);
self.velocity = self.s.origin - inflictor.s.origin;
VectorNormalize(self.velocity);
self.velocity *= 150;
// start chunks towards the center
csize *= 0.5f;
cmass = self.mass;
if (!cmass)
cmass = 75;
// big chunks
if (cmass >= 100) {
count = cmass / 100;
if (count > 8)
count = 8;
while (count--) {
chunkorigin = origin + randomv(-csize, csize);
ThrowDebris(self, "models/objects/debris1/tris.md2", 1, chunkorigin);
}
}
// small chunks
count = cmass / 25;
if (count > 16)
count = 16;
while (count--) {
chunkorigin = origin + randomv(-csize, csize);
ThrowDebris(self, "models/objects/debris2/tris.md2", 2, chunkorigin);
}
#ifdef GROUND_ZERO
// PMM - if we're part of a train, clean ourselves out of it
bool done = false;
entity master;
if (self.flags & FL_TEAMSLAVE)
{
if (self.teammaster)
{
master = self.teammaster;
if(master && master.inuse) // because mappers (other than jim (usually)) are stupid....
{
while (!done)
{
if (master.teamchain == self)
{
master.teamchain = self.teamchain;
done = true;
}
master = master.teamchain;
}
}
}
}
#endif
G_UseTargets(self, attacker);
if (self.dmg)
BecomeExplosion1(self);
else
G_FreeEdict(self);
}
static void(entity self, entity other, entity cactivator) func_explosive_use =
{
func_explosive_explode(self, self, other, self.health, vec3_origin);
}
#ifdef GROUND_ZERO
static void(entity self, entity other, entity cactivator) func_explosive_activate =
{
bool approved = false;
if (other && other.target)
{
if(other.target == self.targetname)
approved = true;
}
if (!approved && cactivator && cactivator.target)
{
if(cactivator.target == self.targetname)
approved = true;
}
if (!approved)
return;
self.use = func_explosive_use;
if (!self.health)
self.health = 100;
self.die = func_explosive_explode;
self.takedamage = true;
}
#endif
static void(entity self, entity other, entity cactivator) func_explosive_spawn =
{
self.solid = SOLID_BSP;
self.svflags &= ~SVF_NOCLIENT;
self.use = 0;
KillBox(self);
gi.linkentity(self);
}
API_FUNC static void(entity self) SP_func_explosive =
{
if (deathmatch.intVal)
{
// auto-remove for deathmatch
G_FreeEdict(self);
return;
}
self.movetype = MOVETYPE_PUSH;
gi.modelindex("models/objects/debris1/tris.md2");
gi.modelindex("models/objects/debris2/tris.md2");
gi.setmodel(self, self.model);
if (self.spawnflags & 1)
{
self.svflags |= SVF_NOCLIENT;
self.solid = SOLID_NOT;
self.use = func_explosive_spawn;
}
#ifdef GROUND_ZERO
else if (self.spawnflags & 8)
{
self.solid = SOLID_BSP;
if(self.targetname)
self.use = func_explosive_activate;
}
#endif
else
{
self.solid = SOLID_BSP;
if (self.targetname)
self.use = func_explosive_use;
}
if (self.spawnflags & 2)
self.s.effects |= EF_ANIM_ALL;
if (self.spawnflags & 4)
self.s.effects |= EF_ANIM_ALLFAST;
if (self.use != func_explosive_use
#ifdef GROUND_ZERO
&& self.use != func_explosive_activate
#endif
) {
if (!self.health)
self.health = 100;
self.die = func_explosive_explode;
self.takedamage = true;
}
gi.linkentity(self);
}
/*QUAKED misc_explobox (0 .5 .8) (-16 -16 0) (16 16 40)
Large exploding box. You can override its mass (100),
health (80), and dmg (150).
*/
static void(entity self, entity other, vector plane, csurface_t surf) barrel_touch =
{
float ratio;
vector v;
if ((other.groundentity == null_entity) || (other.groundentity == self))
return;
ratio = (float)other.mass / (float)self.mass;
v = self.s.origin - other.s.origin;
M_walkmove(self, vectoyaw(v), 20 * ratio * FRAMETIME);
}
static void(entity self) barrel_explode =
{
vector org;
float spd;
vector save;
T_RadiusDamage(self, self.activator, self.dmg, 0, self.dmg + 40, MOD_BARREL);
save = self.s.origin;
self.s.origin = self.absmin + (0.5f * self.size);
// a few big chunks
spd = 1.5f * (float)self.dmg / 200.0f;
org = self.s.origin + randomv(-self.size, self.size);
ThrowDebris(self, "models/objects/debris1/tris.md2", spd, org);
org = self.s.origin + randomv(-self.size, self.size);
ThrowDebris(self, "models/objects/debris1/tris.md2", spd, org);
// bottom corners
spd = 1.75f * (float)self.dmg / 200.0f;
org = self.absmin;
ThrowDebris(self, "models/objects/debris3/tris.md2", spd, org);
org = self.absmin;
org.x += self.size.x;
ThrowDebris(self, "models/objects/debris3/tris.md2", spd, org);
org = self.absmin;
org.y += self.size.y;
ThrowDebris(self, "models/objects/debris3/tris.md2", spd, org);
org = self.absmin;
org.x += self.size.x;
org.y += self.size.y;
ThrowDebris(self, "models/objects/debris3/tris.md2", spd, org);
// a bunch of little chunks
spd = 2f * self.dmg / 200f;
org = self.s.origin + randomv(-self.size, self.size);
ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org = self.s.origin + randomv(-self.size, self.size);
ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org = self.s.origin + randomv(-self.size, self.size);
ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org = self.s.origin + randomv(-self.size, self.size);
ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org = self.s.origin + randomv(-self.size, self.size);
ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org = self.s.origin + randomv(-self.size, self.size);
ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org = self.s.origin + randomv(-self.size, self.size);
ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
org = self.s.origin + randomv(-self.size, self.size);
ThrowDebris(self, "models/objects/debris2/tris.md2", spd, org);
self.s.origin = save;
if (self.groundentity != null_entity)
BecomeExplosion2(self);
else
BecomeExplosion1(self);
}
static void(entity self, entity inflictor, entity attacker, int damage, vector point) barrel_delay =
{
self.takedamage = false;
self.nextthink = level.framenum + 2;
self.think = barrel_explode;
self.activator = attacker;
}
#ifdef GROUND_ZERO
static void(entity self) barrel_think =
{
// the think needs to be first since later stuff may override.
self.think = barrel_think;
self.nextthink = level.framenum + 1;
M_CatagorizePosition (self);
self.flags |= FL_IMMUNE_SLIME;
self.air_finished_framenum = level.framenum + (100 * BASE_FRAMERATE);
M_WorldEffects (self);
}
static void(entity self) barrel_start =
{
M_droptofloor(self);
self.think = barrel_think;
self.nextthink = level.framenum + 1;
}
#endif
API_FUNC static void(entity self) SP_misc_explobox =
{
if (deathmatch.intVal)
{
// auto-remove for deathmatch
G_FreeEdict(self);
return;
}
gi.modelindex("models/objects/debris1/tris.md2");
gi.modelindex("models/objects/debris2/tris.md2");
gi.modelindex("models/objects/debris3/tris.md2");
self.solid = SOLID_BBOX;
self.movetype = MOVETYPE_STEP;
self.model = "models/objects/barrels/tris.md2";
self.s.modelindex = gi.modelindex(self.model);
self.mins = '-16 -16 0';
self.maxs = '16 16 40';
if (!self.mass)
self.mass = 400;
if (!self.health)
self.health = 10;
if (!self.dmg)
self.dmg = 150;
self.die = barrel_delay;
self.takedamage = true;
self.monsterinfo.aiflags = AI_NOSTEP;
self.touch = barrel_touch;
#ifdef GROUND_ZERO
self.think = barrel_start;
#else
self.think = M_droptofloor;
#endif
self.nextthink = level.framenum + 2;
gi.linkentity(self);
}
#endif
//
// miscellaneous specialty items
//
/*QUAKED misc_blackhole (1 .5 0) (-8 -8 -8) (8 8 8)
*/
static void(entity ent, entity other, entity cactivator) misc_blackhole_use =
{
G_FreeEdict(ent);
}
static void(entity self) misc_blackhole_think =
{
if (++self.s.frame < 19)
self.nextthink = level.framenum + 1;
else
{
self.s.frame = 0;
self.nextthink = level.framenum + 1;
}
}
API_FUNC static void(entity ent) SP_misc_blackhole =
{
ent.movetype = MOVETYPE_NONE;
ent.solid = SOLID_NOT;
ent.mins = '-64 -64 0';
ent.maxs = '64 64 8';
ent.s.modelindex = gi.modelindex("models/objects/black/tris.md2");
ent.s.renderfx = RF_TRANSLUCENT;
ent.use = misc_blackhole_use;
ent.think = misc_blackhole_think;
ent.nextthink = level.framenum + 2;
gi.linkentity(ent);
}
/*QUAKED misc_eastertank (1 .5 0) (-32 -32 -16) (32 32 32)
*/
static void(entity self) misc_eastertank_think =
{