-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathg_misc.cpp
2602 lines (2138 loc) · 74 KB
/
g_misc.cpp
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
// Copyright (c) ZeniMax Media Inc.
// Licensed under the GNU General Public License 2.0.
// g_misc.c
#include "g_local.h"
/*QUAKED func_group (0 0 0) ? x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Used to group brushes together just for editor convenience.
*/
//=====================================================
static USE(Use_Areaportal) (gentity_t *ent, gentity_t *other, gentity_t *activator) -> void {
ent->count ^= 1; // toggle state
gi.SetAreaPortalState(ent->style, ent->count);
}
/*QUAKED func_areaportal (0 0 0) ? x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
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(gentity_t *ent) {
ent->use = Use_Areaportal;
ent->count = 0; // always start closed;
}
//=====================================================
/*
=================
Misc functions
=================
*/
void VelocityForDamage(int damage, vec3_t &v) {
v[0] = 100.0f * crandom();
v[1] = 100.0f * crandom();
v[2] = frandom(200.0f, 300.0f);
if (damage < 50)
v = v * 0.7f;
else
v = v * 1.2f;
}
void ClipGibVelocity(gentity_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
=================
*/
DIE(gib_die) (gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, const vec3_t &point, const mod_t &mod) -> void {
if (mod.id == MOD_CRUSH)
G_FreeEntity(self);
}
static TOUCH(gib_touch) (gentity_t *self, gentity_t *other, const trace_t &tr, bool other_touching_self) -> void {
if (tr.plane.normal[2] > 0.7f) {
self->s.angles[PITCH] = clamp(self->s.angles[PITCH], -5.0f, 5.0f);
self->s.angles[ROLL] = clamp(self->s.angles[ROLL], -5.0f, 5.0f);
}
}
/*
=============
GibSink
After sitting around for x seconds, fall into the ground and disappear
=============
*/
static THINK(GibSink) (gentity_t *ent) -> void {
if (level.time > ent->timestamp) {
ent->svflags = SVF_NOCLIENT;
ent->takedamage = false;
ent->solid = SOLID_NOT;
G_FreeEntity(ent);
return;
}
//ent->s.renderfx = RF_FULLBRIGHT;
ent->nextthink = level.time + gtime_t::from_ms(50);
ent->s.origin[2] -= 0.5;
}
gentity_t *ThrowGib(gentity_t *self, const char *gibname, int damage, gib_type_t type, float scale) {
gentity_t *gib;
vec3_t vd;
vec3_t origin;
vec3_t size;
float vscale;
if (type & GIB_HEAD) {
gib = self;
gib->s.event = EV_OTHER_TELEPORT;
// remove setskin so that it doesn't set the skin wrongly later
self->monsterinfo.setskin = nullptr;
} else
gib = G_Spawn();
size = self->size * 0.5f;
// since absmin is bloated by 1, un-bloat it here
origin = (self->absmin + vec3_t{ 1, 1, 1 }) + size;
int32_t i;
for (i = 0; i < 3; i++) {
gib->s.origin = origin + vec3_t{ crandom(), crandom(), crandom() }.scaled(size);
// try 3 times to get a good, non-solid position
if (!(gi.pointcontents(gib->s.origin) & MASK_SOLID))
break;
}
if (i == 3) {
// only free us if we're not being turned into the gib, otherwise
// just spawn inside a wall
if (gib != self) {
G_FreeEntity(gib);
return nullptr;
}
}
gib->s.modelindex = gi.modelindex(gibname);
gib->s.modelindex2 = 0;
gib->s.scale = scale;
gib->solid = SOLID_NOT;
gib->svflags |= SVF_DEADMONSTER;
gib->svflags &= ~SVF_MONSTER;
gib->clipmask = MASK_SOLID;
gib->s.effects = EF_NONE;
gib->s.renderfx = RF_LOW_PRIORITY | RF_FULLBRIGHT;
//gib->s.renderfx |= RF_NOSHADOW;
if (!(type & GIB_DEBRIS)) {
if (type & GIB_ACID)
gib->s.effects |= EF_GREENGIB;
else
gib->s.effects |= EF_GIB;
gib->s.renderfx |= RF_IR_VISIBLE;
}
gib->flags |= FL_NO_KNOCKBACK | FL_NO_DAMAGE_EFFECTS;
gib->takedamage = true;
gib->die = gib_die;
gib->classname = "gib";
if (type & GIB_SKINNED)
gib->s.skinnum = self->s.skinnum;
else
gib->s.skinnum = 0;
gib->s.frame = 0;
gib->mins = gib->maxs = {};
gib->s.sound = 0;
gib->monsterinfo.engine_sound = 0;
if (!(type & GIB_METALLIC)) {
gib->movetype = MOVETYPE_TOSS;
vscale = (type & GIB_ACID) ? 3.0 : 0.5;
} else {
gib->movetype = MOVETYPE_BOUNCE;
vscale = 1.0;
}
if (type & GIB_DEBRIS) {
vec3_t v;
v[0] = 100 * crandom();
v[1] = 100 * crandom();
v[2] = 100 + 100 * crandom();
gib->velocity = self->velocity + (v * damage);
} else {
VelocityForDamage(damage, vd);
gib->velocity = self->velocity + (vd * vscale);
ClipGibVelocity(gib);
}
if (type & GIB_UPRIGHT) {
gib->touch = gib_touch;
gib->flags |= FL_ALWAYS_TOUCH;
}
gib->avelocity[0] = frandom(600);
gib->avelocity[1] = frandom(600);
gib->avelocity[2] = frandom(600);
gib->s.angles[PITCH] = frandom(359);
gib->s.angles[YAW] = frandom(359);
gib->s.angles[ROLL] = frandom(359);
gib->think = GibSink;
if (g_instagib->integer)
gib->nextthink = level.time + random_time(1_sec, 5_sec);
else
gib->nextthink = level.time + random_time(10_sec, 20_sec);
gib->timestamp = gib->nextthink + gtime_t::from_sec(1.5);
gi.linkentity(gib);
gib->watertype = gi.pointcontents(gib->s.origin);
if (gib->watertype & MASK_WATER)
gib->waterlevel = WATER_FEET;
else
gib->waterlevel = WATER_NONE;
return gib;
}
void ThrowClientHead(gentity_t *self, int damage) {
vec3_t vd;
const char *gibname;
if (brandom()) {
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] += 16;
self->s.frame = 0;
gi.setmodel(self, gibname);
self->mins = { -8, -8, 0 }; //{ -16, -16, 0 };
self->maxs = { 8, 8, 8 }; //{ 16, 16, 16 };
self->takedamage = true; // [Paril-KEX] allow takedamage so we get crushed
self->solid = SOLID_TRIGGER; // [Paril-KEX] make 'trigger' so we still move but don't block shots/explode
self->svflags |= SVF_DEADMONSTER;
self->s.effects = EF_GIB;
self->s.renderfx = RF_LOW_PRIORITY | RF_FULLBRIGHT | RF_IR_VISIBLE;
self->s.sound = 0;
self->flags |= FL_NO_KNOCKBACK | FL_NO_DAMAGE_EFFECTS;
self->movetype = MOVETYPE_BOUNCE;
VelocityForDamage(damage, vd);
self->velocity += vd;
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 = nullptr;
self->nextthink = 0_ms;
}
self->think = GibSink;
if (g_instagib->integer)
self->nextthink = level.time + random_time(1_sec, 5_sec);
else
self->nextthink = level.time + random_time(10_sec, 20_sec);
self->timestamp = self->nextthink + gtime_t::from_sec(1.5);
gi.linkentity(self);
}
void BecomeExplosion1(gentity_t *self) {
gi.WriteByte(svc_temp_entity);
gi.WriteByte(TE_EXPLOSION1);
gi.WritePosition(self->s.origin);
gi.multicast(self->s.origin, MULTICAST_PHS, false);
G_FreeEntity(self);
}
static void BecomeExplosion2(gentity_t *self) {
gi.WriteByte(svc_temp_entity);
gi.WriteByte(TE_EXPLOSION2);
gi.WritePosition(self->s.origin);
gi.multicast(self->s.origin, MULTICAST_PHS, false);
G_FreeEntity(self);
}
/*QUAKED path_corner (.5 .3 0) (-8 -8 -8) (8 8 8) TELEPORT x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Target: next path corner
Pathtarget: gets used when an entity that has
this path_corner targeted touches it
*/
static TOUCH(path_corner_touch) (gentity_t *self, gentity_t *other, const trace_t &tr, bool other_touching_self) -> void {
vec3_t v;
gentity_t *next;
if (other->movetarget != self)
return;
if (other->enemy)
return;
if (self->pathtarget) {
const char *savetarget;
savetarget = self->target;
self->target = self->pathtarget;
G_UseTargets(self, other);
self->target = savetarget;
}
// see m_move; this is just so we don't needlessly check it
self->flags |= FL_PARTIALGROUND;
if (self->target)
next = G_PickTarget(self->target);
else
next = nullptr;
// [Paril-KEX] don't teleport to a point_combat, it means HOLD for them.
if ((next) && !strcmp(next->classname, "path_corner") && next->spawnflags.has(SPAWNFLAG_PATH_CORNER_TELEPORT)) {
v = next->s.origin;
v[2] += next->mins[2];
v[2] -= other->mins[2];
other->s.origin = v;
next = G_PickTarget(next->target);
other->s.event = EV_OTHER_TELEPORT;
}
other->goalentity = other->movetarget = next;
if (self->wait) {
other->monsterinfo.pausetime = level.time + gtime_t::from_sec(self->wait);
other->monsterinfo.stand(other);
return;
}
if (!other->movetarget) {
// N64 cutscene behavior
if (other->hackflags & HACKFLAG_END_CUTSCENE) {
G_FreeEntity(other);
return;
}
other->monsterinfo.pausetime = HOLD_FOREVER;
other->monsterinfo.stand(other);
} else {
v = other->goalentity->s.origin - other->s.origin;
other->ideal_yaw = vectoyaw(v);
}
}
void SP_path_corner(gentity_t *self) {
if (!self->targetname) {
gi.Com_PrintFmt("{} with no targetname\n", *self);
G_FreeEntity(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);
}
/*QUAKED point_combat (0.5 0.3 0) (-8 -8 -8) (8 8 8) HOLD x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
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.
*/
TOUCH(point_combat_touch) (gentity_t *self, gentity_t *other, const trace_t &tr, bool other_touching_self) -> void {
gentity_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.Com_PrintFmt("{} target {} does not exist\n", *self, self->target);
other->movetarget = self;
}
// [Paril-KEX] allow them to be re-used
//self->target = nullptr;
} else if (self->spawnflags.has(SPAWNFLAG_POINT_COMBAT_HOLD) && !(other->flags & (FL_SWIM | FL_FLY))) {
// already standing
if (other->monsterinfo.aiflags & AI_STAND_GROUND)
return;
other->monsterinfo.pausetime = HOLD_FOREVER;
other->monsterinfo.aiflags |= AI_STAND_GROUND | AI_REACHED_HOLD_COMBAT | AI_THIRD_EYE;
other->monsterinfo.stand(other);
}
if (other->movetarget == self) {
// [Paril-KEX] if we're holding, keep movetarget set; we will
// use this to make sure we haven't moved too far from where
// we want to "guard".
if (!self->spawnflags.has(SPAWNFLAG_POINT_COMBAT_HOLD)) {
other->target = nullptr;
other->movetarget = nullptr;
}
other->goalentity = other->enemy;
other->monsterinfo.aiflags &= ~AI_COMBAT_POINT;
}
if (self->pathtarget) {
const 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(gentity_t *self) {
if (deathmatch->integer && !ai_allow_dm_spawn->integer) {
G_FreeEntity(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);
}
/*QUAKED info_null (0 0.5 0) (-4 -4 -4) (4 4 4) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Used as a positional target for spotlights, etc.
*/
void SP_info_null(gentity_t *self) {
G_FreeEntity(self);
}
/*QUAKED info_notnull (0 0.5 0) (-4 -4 -4) (4 4 4) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Used as a positional target for entities.
*/
void SP_info_notnull(gentity_t *self) {
self->absmin = self->s.origin;
self->absmax = self->s.origin;
}
/*QUAKED light (0 1 0) (-8 -8 -8) (8 8 8) START_OFF ALLOW_IN_DM x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
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)
*/
constexpr spawnflags_t SPAWNFLAG_LIGHT_START_OFF = 1_spawnflag;
constexpr spawnflags_t SPAWNFLAG_LIGHT_ALLOW_IN_DM = 2_spawnflag;
static USE(light_use) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
if (self->spawnflags.has(SPAWNFLAG_LIGHT_START_OFF)) {
gi.configstring(CS_LIGHTS + self->style, self->style_on);
self->spawnflags &= ~SPAWNFLAG_LIGHT_START_OFF;
} else {
gi.configstring(CS_LIGHTS + self->style, self->style_off);
self->spawnflags |= SPAWNFLAG_LIGHT_START_OFF;
}
}
// ---------------------------------------------------------------------------------
// [Sam-KEX] For keeping track of shadow light parameters and setting them up on
// the server side.
// TODO move to level_locals_t
struct shadow_light_info_t {
int entity_number;
shadow_light_data_t shadowlight;
};
static shadow_light_info_t shadowlightinfo[MAX_SHADOW_LIGHTS];
const shadow_light_data_t *GetShadowLightData(int32_t entity_number) {
for (size_t i = 0; i < level.shadow_light_count; i++) {
if (shadowlightinfo[i].entity_number == entity_number)
return &shadowlightinfo[i].shadowlight;
}
return nullptr;
}
void setup_shadow_lights() {
for (int i = 0; i < level.shadow_light_count; ++i) {
gentity_t *self = &g_entities[shadowlightinfo[i].entity_number];
shadowlightinfo[i].shadowlight.lighttype = shadow_light_type_t::point;
shadowlightinfo[i].shadowlight.conedirection = {};
if (self->target) {
gentity_t *target = G_FindByString<&gentity_t::targetname>(nullptr, self->target);
if (target) {
shadowlightinfo[i].shadowlight.conedirection = (target->s.origin - self->s.origin).normalized();
shadowlightinfo[i].shadowlight.lighttype = shadow_light_type_t::cone;
}
}
if (self->itemtarget) {
gentity_t *target = G_FindByString<&gentity_t::targetname>(nullptr, self->itemtarget);
if (target)
shadowlightinfo[i].shadowlight.lightstyle = target->style;
}
gi.configstring(CS_SHADOWLIGHTS + i, G_Fmt("{};{};{:1};{};{:1};{:1};{:1};{};{:1};{:1};{:1};{:1}",
self->s.number,
(int)shadowlightinfo[i].shadowlight.lighttype,
shadowlightinfo[i].shadowlight.radius,
shadowlightinfo[i].shadowlight.resolution,
shadowlightinfo[i].shadowlight.intensity,
shadowlightinfo[i].shadowlight.fade_start,
shadowlightinfo[i].shadowlight.fade_end,
shadowlightinfo[i].shadowlight.lightstyle,
shadowlightinfo[i].shadowlight.coneangle,
shadowlightinfo[i].shadowlight.conedirection[0],
shadowlightinfo[i].shadowlight.conedirection[1],
shadowlightinfo[i].shadowlight.conedirection[2]).data());
}
}
// fix an oversight in shadow light code that causes
// lights to be ordered wrong on return levels
// if the spawn functions are changed.
// this will work without changing the save/load code.
void G_LoadShadowLights() {
for (size_t i = 0; i < level.shadow_light_count; i++) {
const char *cstr = gi.get_configstring(CS_SHADOWLIGHTS + i);
const char *token = COM_ParseEx(&cstr, ";");
if (token && *token) {
shadowlightinfo[i].entity_number = atoi(token);
token = COM_ParseEx(&cstr, ";");
shadowlightinfo[i].shadowlight.lighttype = (shadow_light_type_t)atoi(token);
token = COM_ParseEx(&cstr, ";");
shadowlightinfo[i].shadowlight.radius = atof(token);
token = COM_ParseEx(&cstr, ";");
shadowlightinfo[i].shadowlight.resolution = atoi(token);
token = COM_ParseEx(&cstr, ";");
shadowlightinfo[i].shadowlight.intensity = atof(token);
token = COM_ParseEx(&cstr, ";");
shadowlightinfo[i].shadowlight.fade_start = atof(token);
token = COM_ParseEx(&cstr, ";");
shadowlightinfo[i].shadowlight.fade_end = atof(token);
token = COM_ParseEx(&cstr, ";");
shadowlightinfo[i].shadowlight.lightstyle = atoi(token);
token = COM_ParseEx(&cstr, ";");
shadowlightinfo[i].shadowlight.coneangle = atof(token);
token = COM_ParseEx(&cstr, ";");
shadowlightinfo[i].shadowlight.conedirection[0] = atof(token);
token = COM_ParseEx(&cstr, ";");
shadowlightinfo[i].shadowlight.conedirection[1] = atof(token);
token = COM_ParseEx(&cstr, ";");
shadowlightinfo[i].shadowlight.conedirection[2] = atof(token);
}
}
}
// ---------------------------------------------------------------------------------
static void setup_dynamic_light(gentity_t *self) {
// [Sam-KEX] Shadow stuff
if (st.sl.data.radius > 0) {
self->s.renderfx = RF_CASTSHADOW;
self->itemtarget = st.sl.lightstyletarget;
shadowlightinfo[level.shadow_light_count].entity_number = self->s.number;
shadowlightinfo[level.shadow_light_count].shadowlight = st.sl.data;
level.shadow_light_count++;
self->mins[0] = self->mins[1] = self->mins[2] = 0;
self->maxs[0] = self->maxs[1] = self->maxs[2] = 0;
gi.linkentity(self);
}
}
static USE(dynamic_light_use) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
self->svflags ^= SVF_NOCLIENT;
}
void SP_dynamic_light(gentity_t *self) {
setup_dynamic_light(self);
if (self->targetname) {
self->use = dynamic_light_use;
}
if (self->spawnflags.has(SPAWNFLAG_LIGHT_START_OFF))
self->svflags ^= SVF_NOCLIENT;
}
void SP_light(gentity_t *self) {
// no targeted lights in deathmatch, because they cause global messages
if ((!self->targetname || (deathmatch->integer && !(self->spawnflags.has(SPAWNFLAG_LIGHT_ALLOW_IN_DM)))) && st.sl.data.radius == 0) // [Sam-KEX]
{
G_FreeEntity(self);
return;
}
if (self->style >= 32) {
self->use = light_use;
if (!self->style_on || !*self->style_on)
self->style_on = "m";
else if (*self->style_on >= '0' && *self->style_on <= '9')
self->style_on = gi.get_configstring(CS_LIGHTS + atoi(self->style_on));
if (!self->style_off || !*self->style_off)
self->style_off = "a";
else if (*self->style_off >= '0' && *self->style_off <= '9')
self->style_off = gi.get_configstring(CS_LIGHTS + atoi(self->style_off));
if (self->spawnflags.has(SPAWNFLAG_LIGHT_START_OFF))
gi.configstring(CS_LIGHTS + self->style, self->style_off);
else
gi.configstring(CS_LIGHTS + self->style, self->style_on);
}
setup_dynamic_light(self);
}
/*QUAKED func_wall (0 .5 .8) ? TRIGGER_SPAWN TOGGLE START_ON ANIMATED ANIMATED_FAST x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
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
*/
constexpr spawnflags_t SPAWNFLAG_WALL_TRIGGER_SPAWN = 1_spawnflag;
constexpr spawnflags_t SPAWNFLAG_WALL_TOGGLE = 2_spawnflag;
constexpr spawnflags_t SPAWNFLAG_WALL_START_ON = 4_spawnflag;
constexpr spawnflags_t SPAWNFLAG_WALL_ANIMATED = 8_spawnflag;
constexpr spawnflags_t SPAWNFLAG_WALL_ANIMATED_FAST = 16_spawnflag;
static USE(func_wall_use) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
if (self->solid == SOLID_NOT) {
self->solid = SOLID_BSP;
self->svflags &= ~SVF_NOCLIENT;
gi.linkentity(self);
KillBox(self, false);
} else {
self->solid = SOLID_NOT;
self->svflags |= SVF_NOCLIENT;
gi.linkentity(self);
}
if (!self->spawnflags.has(SPAWNFLAG_WALL_TOGGLE))
self->use = nullptr;
}
void SP_func_wall(gentity_t *self) {
self->movetype = MOVETYPE_PUSH;
gi.setmodel(self, self->model);
if (self->spawnflags.has(SPAWNFLAG_WALL_ANIMATED))
self->s.effects |= EF_ANIM_ALL;
if (self->spawnflags.has(SPAWNFLAG_WALL_ANIMATED_FAST))
self->s.effects |= EF_ANIM_ALLFAST;
// just a wall
if (!self->spawnflags.has(SPAWNFLAG_WALL_TRIGGER_SPAWN | SPAWNFLAG_WALL_TOGGLE | SPAWNFLAG_WALL_START_ON)) {
self->solid = SOLID_BSP;
gi.linkentity(self);
return;
}
// it must be TRIGGER_SPAWN
if (!(self->spawnflags & SPAWNFLAG_WALL_TRIGGER_SPAWN))
self->spawnflags |= SPAWNFLAG_WALL_TRIGGER_SPAWN;
// yell if the spawnflags are odd
if (self->spawnflags.has(SPAWNFLAG_WALL_START_ON)) {
if (!self->spawnflags.has(SPAWNFLAG_WALL_TOGGLE)) {
gi.Com_Print("func_wall START_ON without TOGGLE\n");
self->spawnflags |= SPAWNFLAG_WALL_TOGGLE;
}
}
self->use = func_wall_use;
if (self->spawnflags.has(SPAWNFLAG_WALL_START_ON)) {
self->solid = SOLID_BSP;
} else {
self->solid = SOLID_NOT;
self->svflags |= SVF_NOCLIENT;
}
gi.linkentity(self);
}
// [Paril-KEX]
/*QUAKED func_animation (0 .5 .8) ? START_ON x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Similar to func_wall, but triggering it will toggle animation
state rather than going on/off.
START_ON will start in alterate animation
*/
constexpr spawnflags_t SPAWNFLAG_ANIMATION_START_ON = 1_spawnflag;
USE(func_animation_use) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
self->bmodel_anim.alternate = !self->bmodel_anim.alternate;
}
void SP_func_animation(gentity_t *self) {
if (!self->bmodel_anim.enabled) {
gi.Com_PrintFmt("{} has no animation data\n", *self);
G_FreeEntity(self);
return;
}
self->movetype = MOVETYPE_PUSH;
gi.setmodel(self, self->model);
self->solid = SOLID_BSP;
self->use = func_animation_use;
self->bmodel_anim.alternate = self->spawnflags.has(SPAWNFLAG_ANIMATION_START_ON);
if (self->bmodel_anim.alternate)
self->s.frame = self->bmodel_anim.alt_start;
else
self->s.frame = self->bmodel_anim.start;
gi.linkentity(self);
}
/*QUAKED func_object (0 .5 .8) ? TRIGGER_SPAWN ANIMATED ANIMATED_FAST x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
This is solid bmodel that will fall if it's support it removed.
*/
constexpr spawnflags_t SPAWNFLAGS_OBJECT_TRIGGER_SPAWN = 1_spawnflag;
constexpr spawnflags_t SPAWNFLAGS_OBJECT_ANIMATED = 2_spawnflag;
constexpr spawnflags_t SPAWNFLAGS_OBJECT_ANIMATED_FAST = 4_spawnflag;
TOUCH(func_object_touch) (gentity_t *self, gentity_t *other, const trace_t &tr, bool other_touching_self) -> void {
// only squash thing we fall on top of
if (other_touching_self)
return;
if (tr.plane.normal[2] < 1.0f)
return;
if (other->takedamage == false)
return;
if (other->damage_debounce_time > level.time)
return;
T_Damage(other, self, self, vec3_origin, closest_point_to_box(other->s.origin, self->absmin, self->absmax), tr.plane.normal, self->dmg, 1, DAMAGE_NONE, MOD_CRUSH);
other->damage_debounce_time = level.time + 10_hz;
}
THINK(func_object_release) (gentity_t *self) -> void {
self->movetype = MOVETYPE_TOSS;
self->touch = func_object_touch;
}
USE(func_object_use) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
self->solid = SOLID_BSP;
self->svflags &= ~SVF_NOCLIENT;
self->use = nullptr;
func_object_release(self);
KillBox(self, false);
}
void SP_func_object(gentity_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 & SPAWNFLAGS_OBJECT_TRIGGER_SPAWN)) {
self->solid = SOLID_BSP;
self->movetype = MOVETYPE_PUSH;
self->think = func_object_release;
self->nextthink = level.time + 20_hz;
} else {
self->solid = SOLID_NOT;
self->movetype = MOVETYPE_PUSH;
self->use = func_object_use;
self->svflags |= SVF_NOCLIENT;
}
if (self->spawnflags.has(SPAWNFLAGS_OBJECT_ANIMATED))
self->s.effects |= EF_ANIM_ALL;
if (self->spawnflags.has(SPAWNFLAGS_OBJECT_ANIMATED_FAST))
self->s.effects |= EF_ANIM_ALLFAST;
self->clipmask = MASK_MONSTERSOLID;
self->flags |= FL_NO_STANDING;
gi.linkentity(self);
}
/*QUAKED func_explosive (0 .5 .8) ? TRIGGER_SPAWN ANIMATED ANIMATED_FAST INACTIVE ALWAYS_SHOOTABLE x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
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.
INACTIVE - specifies that the entity is not explodable until triggered. If you use this you must
target the entity you want to trigger it. This is the only entity approved to activate it.
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.
*/
constexpr spawnflags_t SPAWNFLAGS_EXPLOSIVE_TRIGGER_SPAWN = 1_spawnflag;
constexpr spawnflags_t SPAWNFLAGS_EXPLOSIVE_ANIMATED = 2_spawnflag;
constexpr spawnflags_t SPAWNFLAGS_EXPLOSIVE_ANIMATED_FAST = 4_spawnflag;
constexpr spawnflags_t SPAWNFLAGS_EXPLOSIVE_INACTIVE = 8_spawnflag;
constexpr spawnflags_t SPAWNFLAGS_EXPLOSIVE_ALWAYS_SHOOTABLE = 16_spawnflag;
static DIE(func_explosive_explode) (gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, const vec3_t &point, const mod_t &mod) -> void {
size_t count;
int mass;
gentity_t *master;
bool done = false;
self->takedamage = false;
if (self->dmg)
T_RadiusDamage(self, attacker, (float)self->dmg, nullptr, (float)(self->dmg + 40), DAMAGE_NONE, MOD_EXPLOSIVE);
self->velocity = inflictor->s.origin - self->s.origin;
self->velocity.normalize();
self->velocity *= 150;
mass = self->mass;
if (!mass)
mass = 75;
// big chunks
if (mass >= 100) {
count = mass / 100;
if (count > 8)
count = 8;
ThrowGibs(self, 1, {
{ count, "models/objects/debris1/tris.md2", GIB_METALLIC | GIB_DEBRIS }
});
}
// small chunks
count = mass / 25;
if (count > 16)
count = 16;
ThrowGibs(self, 2, {
{ count, "models/objects/debris2/tris.md2", GIB_METALLIC | GIB_DEBRIS }
});
// PMM - if we're part of a train, clean ourselves out of it
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;
}
}
}
}
G_UseTargets(self, attacker);
self->s.origin = (self->absmin + self->absmax) * 0.5f;
if (self->noise_index)
gi.positioned_sound(self->s.origin, self, CHAN_AUTO, self->noise_index, 1, ATTN_NORM, 0);
if (self->dmg)
BecomeExplosion1(self);
else
G_FreeEntity(self);
}
static USE(func_explosive_use) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
// Paril: pass activator to explode as attacker. this fixes
// "strike" trying to centerprint to the relay. Should be
// a safe change.
func_explosive_explode(self, self, activator, self->health, vec3_origin, MOD_EXPLOSIVE);
}
static USE(func_explosive_activate) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
int approved;
approved = 0;
// PMM - looked like target and targetname were flipped here
if (other != nullptr && other->target) {
if (!strcmp(other->target, self->targetname))
approved = 1;
}
if (!approved && activator != nullptr && activator->target) {
if (!strcmp(activator->target, self->targetname))
approved = 1;
}
if (!approved)
return;
self->use = func_explosive_use;
if (!self->health)
self->health = 100;
self->die = func_explosive_explode;
self->takedamage = true;
}
// PGM
static USE(func_explosive_spawn) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
self->solid = SOLID_BSP;
self->svflags &= ~SVF_NOCLIENT;
self->use = nullptr;
gi.linkentity(self);
KillBox(self, false);
}
void SP_func_explosive(gentity_t *self) {
/*
if (deathmatch->integer)
{ // auto-remove for deathmatch
G_FreeEntity(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.has(SPAWNFLAGS_EXPLOSIVE_TRIGGER_SPAWN)) {
self->svflags |= SVF_NOCLIENT;
self->solid = SOLID_NOT;
self->use = func_explosive_spawn;
} else if (self->spawnflags.has(SPAWNFLAGS_EXPLOSIVE_INACTIVE)) {
self->solid = SOLID_BSP;
if (self->targetname)
self->use = func_explosive_activate;
} else {
self->solid = SOLID_BSP;
if (self->targetname)
self->use = func_explosive_use;
}
if (self->spawnflags.has(SPAWNFLAGS_EXPLOSIVE_ANIMATED))
self->s.effects |= EF_ANIM_ALL;
if (self->spawnflags.has(SPAWNFLAGS_EXPLOSIVE_ANIMATED_FAST))
self->s.effects |= EF_ANIM_ALLFAST;
if (self->spawnflags.has(SPAWNFLAGS_EXPLOSIVE_ALWAYS_SHOOTABLE) || ((self->use != func_explosive_use) && (self->use != func_explosive_activate))) {
if (!self->health)
self->health = 100;
self->die = func_explosive_explode;
self->takedamage = true;
}
if (self->sounds) {