-
Notifications
You must be signed in to change notification settings - Fork 106
/
g_misc.c
1859 lines (1549 loc) · 43.5 KB
/
g_misc.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
// g_misc.c
#include "g_local.h"
/*QUAKED func_group (0 0 0) ?
Used to group brushes together just for editor convenience.
*/
//=====================================================
void Use_Areaportal (edict_t *ent, edict_t *other, edict_t *activator)
{
ent->count ^= 1; // toggle state
// gi.dprintf ("portalstate: %i = %i\n", ent->style, ent->count);
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.
*/
void SP_func_areaportal (edict_t *ent)
{
ent->use = Use_Areaportal;
ent->count = 0; // always start closed;
}
//=====================================================
/*
=================
Misc functions
=================
*/
void VelocityForDamage (int damage, vec3_t v)
{
v[0] = 100.0 * crandom();
v[1] = 100.0 * crandom();
v[2] = 200.0 + 100.0 * random();
if (damage < 50)
VectorScale (v, 0.7, v);
else
VectorScale (v, 1.2, v);
}
void ClipGibVelocity (edict_t *ent)
{
if (ent->velocity[0] < -300)
ent->velocity[0] = -300;
else if (ent->velocity[0] > 300)
ent->velocity[0] = 300;
if (ent->velocity[1] < -300)
ent->velocity[1] = -300;
else if (ent->velocity[1] > 300)
ent->velocity[1] = 300;
if (ent->velocity[2] < 200)
ent->velocity[2] = 200; // always some upwards
else if (ent->velocity[2] > 500)
ent->velocity[2] = 500;
}
/*
=================
gibs
=================
*/
void gib_think (edict_t *self)
{
self->s.frame++;
self->nextthink = level.time + FRAMETIME;
if (self->s.frame == 10)
{
self->think = G_FreeEdict;
self->nextthink = level.time + 8 + random()*10;
}
}
void gib_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
vec3_t normal_angles, right;
if (!self->groundentity)
return;
self->touch = NULL;
if (plane)
{
gi.sound (self, CHAN_VOICE, gi.soundindex ("misc/fhit3.wav"), 1, ATTN_NORM, 0);
vectoangles (plane->normal, normal_angles);
AngleVectors (normal_angles, NULL, right, NULL);
vectoangles (right, self->s.angles);
if (self->s.modelindex == sm_meat_index)
{
self->s.frame++;
self->think = gib_think;
self->nextthink = level.time + FRAMETIME;
}
}
}
void gib_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
G_FreeEdict (self);
}
void ThrowGib (edict_t *self, char *gibname, int damage, int type)
{
edict_t *gib;
vec3_t vd;
vec3_t origin;
vec3_t size;
float vscale;
gib = G_Spawn();
VectorScale (self->size, 0.5, size);
VectorAdd (self->absmin, size, origin);
gib->s.origin[0] = origin[0] + crandom() * size[0];
gib->s.origin[1] = origin[1] + crandom() * size[1];
gib->s.origin[2] = origin[2] + crandom() * size[2];
gi.setmodel (gib, gibname);
gib->solid = SOLID_NOT;
gib->s.effects |= EF_GIB;
gib->flags |= FL_NO_KNOCKBACK;
gib->takedamage = DAMAGE_YES;
gib->die = gib_die;
if (type == GIB_ORGANIC)
{
gib->movetype = MOVETYPE_TOSS;
gib->touch = gib_touch;
vscale = 0.5;
}
else
{
gib->movetype = MOVETYPE_BOUNCE;
vscale = 1.0;
}
VelocityForDamage (damage, vd);
VectorMA (self->velocity, vscale, vd, gib->velocity);
ClipGibVelocity (gib);
gib->avelocity[0] = random()*600;
gib->avelocity[1] = random()*600;
gib->avelocity[2] = random()*600;
gib->think = G_FreeEdict;
gib->nextthink = level.time + 10 + random()*10;
gi.linkentity (gib);
}
void ThrowHead (edict_t *self, char *gibname, int damage, int type)
{
vec3_t vd;
float vscale;
self->s.skinnum = 0;
self->s.frame = 0;
VectorClear (self->mins);
VectorClear (self->maxs);
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 = DAMAGE_YES;
self->die = gib_die;
if (type == GIB_ORGANIC)
{
self->movetype = MOVETYPE_TOSS;
self->touch = gib_touch;
vscale = 0.5;
}
else
{
self->movetype = MOVETYPE_BOUNCE;
vscale = 1.0;
}
VelocityForDamage (damage, vd);
VectorMA (self->velocity, vscale, vd, self->velocity);
ClipGibVelocity (self);
self->avelocity[YAW] = crandom()*600;
self->think = G_FreeEdict;
self->nextthink = level.time + 10 + random()*10;
gi.linkentity (self);
}
void ThrowClientHead (edict_t *self, int damage)
{
vec3_t vd;
char *gibname;
if (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);
VectorSet (self->mins, -16, -16, 0);
VectorSet (self->maxs, 16, 16, 16);
self->takedamage = DAMAGE_NO;
self->solid = SOLID_NOT;
self->s.effects = EF_GIB;
self->s.sound = 0;
self->flags |= FL_NO_KNOCKBACK;
self->movetype = MOVETYPE_BOUNCE;
VelocityForDamage (damage, vd);
VectorAdd (self->velocity, vd, self->velocity);
if (self->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 = NULL;
self->nextthink = 0;
}
gi.linkentity (self);
}
/*
=================
debris
=================
*/
void debris_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
G_FreeEdict (self);
}
void ThrowDebris (edict_t *self, char *modelname, float speed, vec3_t origin)
{
edict_t *chunk;
vec3_t v;
chunk = G_Spawn();
VectorCopy (origin, chunk->s.origin);
gi.setmodel (chunk, modelname);
v[0] = 100 * crandom();
v[1] = 100 * crandom();
v[2] = 100 + 100 * crandom();
VectorMA (self->velocity, speed, v, chunk->velocity);
chunk->movetype = MOVETYPE_BOUNCE;
chunk->solid = SOLID_NOT;
chunk->avelocity[0] = random()*600;
chunk->avelocity[1] = random()*600;
chunk->avelocity[2] = random()*600;
chunk->think = G_FreeEdict;
chunk->nextthink = level.time + 5 + random()*5;
chunk->s.frame = 0;
chunk->flags = 0;
chunk->classname = "debris";
chunk->takedamage = DAMAGE_YES;
chunk->die = debris_die;
gi.linkentity (chunk);
}
void BecomeExplosion1 (edict_t *self)
{
gi.WriteByte (svc_temp_entity);
gi.WriteByte (TE_EXPLOSION1);
gi.WritePosition (self->s.origin);
gi.multicast (self->s.origin, MULTICAST_PVS);
G_FreeEdict (self);
}
void BecomeExplosion2 (edict_t *self)
{
gi.WriteByte (svc_temp_entity);
gi.WriteByte (TE_EXPLOSION2);
gi.WritePosition (self->s.origin);
gi.multicast (self->s.origin, MULTICAST_PVS);
G_FreeEdict (self);
}
/*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
*/
void path_corner_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
vec3_t v;
edict_t *next;
if (other->movetarget != self)
return;
if (other->enemy)
return;
if (self->pathtarget)
{
char *savetarget;
savetarget = self->target;
self->target = self->pathtarget;
G_UseTargets (self, other);
self->target = savetarget;
}
if (self->target)
next = G_PickTarget(self->target);
else
next = NULL;
if ((next) && (next->spawnflags & 1))
{
VectorCopy (next->s.origin, v);
v[2] += next->mins[2];
v[2] -= other->mins[2];
VectorCopy (v, other->s.origin);
next = G_PickTarget(next->target);
other->s.event = EV_OTHER_TELEPORT;
}
other->goalentity = other->movetarget = next;
if (self->wait)
{
other->monsterinfo.pausetime = level.time + self->wait;
other->monsterinfo.stand (other);
return;
}
if (!other->movetarget)
{
other->monsterinfo.pausetime = level.time + 100000000;
other->monsterinfo.stand (other);
}
else
{
VectorSubtract (other->goalentity->s.origin, other->s.origin, v);
other->ideal_yaw = vectoyaw (v);
}
}
void SP_path_corner (edict_t *self)
{
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;
VectorSet (self->mins, -8, -8, -8);
VectorSet (self->maxs, 8, 8, 8);
self->svflags |= SVF_NOCLIENT;
gi.linkentity (self);
}
/*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.
*/
void point_combat_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
edict_t *activator;
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 = NULL;
}
else if ((self->spawnflags & 1) && !(other->flags & (FL_SWIM|FL_FLY)))
{
other->monsterinfo.pausetime = level.time + 100000000;
other->monsterinfo.aiflags |= AI_STAND_GROUND;
other->monsterinfo.stand (other);
}
if (other->movetarget == self)
{
other->target = NULL;
other->movetarget = NULL;
other->goalentity = other->enemy;
other->monsterinfo.aiflags &= ~AI_COMBAT_POINT;
}
if (self->pathtarget)
{
char *savetarget;
savetarget = self->target;
self->target = self->pathtarget;
if (other->enemy && other->enemy->client)
activator = other->enemy;
else if (other->oldenemy && other->oldenemy->client)
activator = other->oldenemy;
else if (other->activator && other->activator->client)
activator = other->activator;
else
activator = other;
G_UseTargets (self, activator);
self->target = savetarget;
}
}
void SP_point_combat (edict_t *self)
{
if (deathmatch->value)
{
G_FreeEdict (self);
return;
}
self->solid = SOLID_TRIGGER;
self->touch = point_combat_touch;
VectorSet (self->mins, -8, -8, -16);
VectorSet (self->maxs, 8, 8, 16);
self->svflags = SVF_NOCLIENT;
gi.linkentity (self);
};
/*QUAKED viewthing (0 .5 .8) (-8 -8 -8) (8 8 8)
Just for the debugging level. Don't use
*/
void TH_viewthing(edict_t *ent)
{
ent->s.frame = (ent->s.frame + 1) % 7;
ent->nextthink = level.time + FRAMETIME;
}
void SP_viewthing(edict_t *ent)
{
gi.dprintf ("viewthing spawned\n");
ent->movetype = MOVETYPE_NONE;
ent->solid = SOLID_BBOX;
ent->s.renderfx = RF_FRAMELERP;
VectorSet (ent->mins, -16, -16, -24);
VectorSet (ent->maxs, 16, 16, 32);
ent->s.modelindex = gi.modelindex ("models/objects/banner/tris.md2");
gi.linkentity (ent);
ent->nextthink = level.time + 0.5;
ent->think = TH_viewthing;
return;
}
/*QUAKED info_null (0 0.5 0) (-4 -4 -4) (4 4 4)
Used as a positional target for spotlights, etc.
*/
void SP_info_null (edict_t *self)
{
G_FreeEdict (self);
};
/*QUAKED info_notnull (0 0.5 0) (-4 -4 -4) (4 4 4)
Used as a positional target for lightning.
*/
void SP_info_notnull (edict_t *self)
{
VectorCopy (self->s.origin, self->absmin);
VectorCopy (self->s.origin, self->absmax);
};
/*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)
*/
#define START_OFF 1
static void light_use (edict_t *self, edict_t *other, edict_t *activator)
{
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;
}
}
void SP_light (edict_t *self)
{
// no targeted lights in deathmatch, because they cause global messages
if (!self->targetname || deathmatch->value)
{
G_FreeEdict (self);
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");
}
}
/*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
*/
void func_wall_use (edict_t *self, edict_t *other, edict_t *activator)
{
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 = NULL;
}
void SP_func_wall (edict_t *self)
{
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.
*/
void func_object_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
// only squash thing we fall on top of
if (!plane)
return;
if (plane->normal[2] < 1.0)
return;
if (other->takedamage == DAMAGE_NO)
return;
T_Damage (other, self, self, vec3_origin, self->s.origin, vec3_origin, self->dmg, 1, 0, MOD_CRUSH);
}
void func_object_release (edict_t *self)
{
self->movetype = MOVETYPE_TOSS;
self->touch = func_object_touch;
}
void func_object_use (edict_t *self, edict_t *other, edict_t *activator)
{
self->solid = SOLID_BSP;
self->svflags &= ~SVF_NOCLIENT;
self->use = NULL;
KillBox (self);
func_object_release (self);
}
void SP_func_object (edict_t *self)
{
gi.setmodel (self, self->model);
self->mins[0] += 1;
self->mins[1] += 1;
self->mins[2] += 1;
self->maxs[0] -= 1;
self->maxs[1] -= 1;
self->maxs[2] -= 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.time + 2 * FRAMETIME;
}
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);
}
/*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.
*/
void func_explosive_explode (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
vec3_t origin;
vec3_t chunkorigin;
vec3_t size;
int count;
int mass;
// bmodel origins are (0 0 0), we need to adjust that here
VectorScale (self->size, 0.5, size);
VectorAdd (self->absmin, size, origin);
VectorCopy (origin, self->s.origin);
self->takedamage = DAMAGE_NO;
if (self->dmg)
T_RadiusDamage (self, attacker, self->dmg, NULL, self->dmg+40, MOD_EXPLOSIVE);
VectorSubtract (self->s.origin, inflictor->s.origin, self->velocity);
VectorNormalize (self->velocity);
VectorScale (self->velocity, 150, self->velocity);
// start chunks towards the center
VectorScale (size, 0.5, size);
mass = self->mass;
if (!mass)
mass = 75;
// big chunks
if (mass >= 100)
{
count = mass / 100;
if (count > 8)
count = 8;
while(count--)
{
chunkorigin[0] = origin[0] + crandom() * size[0];
chunkorigin[1] = origin[1] + crandom() * size[1];
chunkorigin[2] = origin[2] + crandom() * size[2];
ThrowDebris (self, "models/objects/debris1/tris.md2", 1, chunkorigin);
}
}
// small chunks
count = mass / 25;
if (count > 16)
count = 16;
while(count--)
{
chunkorigin[0] = origin[0] + crandom() * size[0];
chunkorigin[1] = origin[1] + crandom() * size[1];
chunkorigin[2] = origin[2] + crandom() * size[2];
ThrowDebris (self, "models/objects/debris2/tris.md2", 2, chunkorigin);
}
G_UseTargets (self, attacker);
if (self->dmg)
BecomeExplosion1 (self);
else
G_FreeEdict (self);
}
void func_explosive_use(edict_t *self, edict_t *other, edict_t *activator)
{
func_explosive_explode (self, self, other, self->health, vec3_origin);
}
void func_explosive_spawn (edict_t *self, edict_t *other, edict_t *activator)
{
self->solid = SOLID_BSP;
self->svflags &= ~SVF_NOCLIENT;
self->use = NULL;
KillBox (self);
gi.linkentity (self);
}
void SP_func_explosive (edict_t *self)
{
if (deathmatch->value)
{ // 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;
}
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)
{
if (!self->health)
self->health = 100;
self->die = func_explosive_explode;
self->takedamage = DAMAGE_YES;
}
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).
*/
void barrel_touch (edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf)
{
float ratio;
vec3_t v;
if ((!other->groundentity) || (other->groundentity == self))
return;
ratio = (float)other->mass / (float)self->mass;
VectorSubtract (self->s.origin, other->s.origin, v);
M_walkmove (self, vectoyaw(v), 20 * ratio * FRAMETIME);
}
void barrel_explode (edict_t *self)
{
vec3_t org;
float spd;
vec3_t save;
T_RadiusDamage (self, self->activator, self->dmg, NULL, self->dmg+40, MOD_BARREL);
VectorCopy (self->s.origin, save);
VectorMA (self->absmin, 0.5, self->size, self->s.origin);
// a few big chunks
spd = 1.5 * (float)self->dmg / 200.0;
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
ThrowDebris (self, "models/objects/debris1/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
ThrowDebris (self, "models/objects/debris1/tris.md2", spd, org);
// bottom corners
spd = 1.75 * (float)self->dmg / 200.0;
VectorCopy (self->absmin, org);
ThrowDebris (self, "models/objects/debris3/tris.md2", spd, org);
VectorCopy (self->absmin, org);
org[0] += self->size[0];
ThrowDebris (self, "models/objects/debris3/tris.md2", spd, org);
VectorCopy (self->absmin, org);
org[1] += self->size[1];
ThrowDebris (self, "models/objects/debris3/tris.md2", spd, org);
VectorCopy (self->absmin, org);
org[0] += self->size[0];
org[1] += self->size[1];
ThrowDebris (self, "models/objects/debris3/tris.md2", spd, org);
// a bunch of little chunks
spd = 2 * self->dmg / 200;
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
org[0] = self->s.origin[0] + crandom() * self->size[0];
org[1] = self->s.origin[1] + crandom() * self->size[1];
org[2] = self->s.origin[2] + crandom() * self->size[2];
ThrowDebris (self, "models/objects/debris2/tris.md2", spd, org);
VectorCopy (save, self->s.origin);
if (self->groundentity)
BecomeExplosion2 (self);
else
BecomeExplosion1 (self);
}
void barrel_delay (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
self->takedamage = DAMAGE_NO;
self->nextthink = level.time + 2 * FRAMETIME;
self->think = barrel_explode;
self->activator = attacker;
}
void SP_misc_explobox (edict_t *self)
{
if (deathmatch->value)
{ // 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);
VectorSet (self->mins, -16, -16, 0);
VectorSet (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 = DAMAGE_YES;
self->monsterinfo.aiflags = AI_NOSTEP;
self->touch = barrel_touch;
self->think = M_droptofloor;
self->nextthink = level.time + 2 * FRAMETIME;
gi.linkentity (self);
}
//
// miscellaneous specialty items
//
/*QUAKED misc_blackhole (1 .5 0) (-8 -8 -8) (8 8 8)
*/