-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathg_target.cpp
2706 lines (2166 loc) · 82.9 KB
/
g_target.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.
#include "g_local.h"
/*QUAKED target_temp_entity (1 0 0) (-8 -8 -8) (8 8 8) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Fire an origin based temp entity event to the clients.
"style" type byte
*/
static USE(Use_Target_Tent) (gentity_t *ent, gentity_t *other, gentity_t *activator) -> void {
gi.WriteByte(svc_temp_entity);
gi.WriteByte(ent->style);
gi.WritePosition(ent->s.origin);
gi.multicast(ent->s.origin, MULTICAST_PVS, false);
}
void SP_target_temp_entity(gentity_t *ent) {
if (level.is_n64 && ent->style == 27)
ent->style = TE_TELEPORT_EFFECT;
ent->use = Use_Target_Tent;
}
//==========================================================
//==========================================================
/*QUAKED target_speaker (1 0 0) (-8 -8 -8) (8 8 8) LOOPED-ON LOOPED-OFF RELIABLE x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
"noise" wav file to play
"attenuation"
-1 = none, send to whole level
1 = normal fighting sounds
2 = idle sound level
3 = ambient sound level
"volume" 0.0 to 1.0
Normal sounds play each time the target is used. The reliable flag can be set for crucial voiceovers.
[Paril-KEX] looped sounds are by default atten 3 / vol 1, and the use function toggles it on/off.
*/
constexpr spawnflags_t SPAWNFLAG_SPEAKER_LOOPED_ON = 1_spawnflag;
constexpr spawnflags_t SPAWNFLAG_SPEAKER_LOOPED_OFF = 2_spawnflag;
constexpr spawnflags_t SPAWNFLAG_SPEAKER_RELIABLE = 4_spawnflag;
constexpr spawnflags_t SPAWNFLAG_SPEAKER_NO_STEREO = 8_spawnflag;
static USE(Use_Target_Speaker) (gentity_t *ent, gentity_t *other, gentity_t *activator) -> void {
soundchan_t chan;
if (ent->spawnflags.has(SPAWNFLAG_SPEAKER_LOOPED_ON | SPAWNFLAG_SPEAKER_LOOPED_OFF)) { // looping sound toggles
if (ent->s.sound)
ent->s.sound = 0; // turn it off
else
ent->s.sound = ent->noise_index; // start it
} else { // normal sound
if (ent->spawnflags.has(SPAWNFLAG_SPEAKER_RELIABLE))
chan = CHAN_VOICE | CHAN_RELIABLE;
else
chan = CHAN_VOICE;
// use a positioned_sound, because this entity won't normally be
// sent to any clients because it is invisible
gi.positioned_sound(ent->s.origin, ent, chan, ent->noise_index, ent->volume, ent->attenuation, 0);
}
}
void SP_target_speaker(gentity_t *ent) {
if (!st.noise) {
gi.Com_PrintFmt("{}: no noise set\n", *ent);
return;
}
if (!strstr(st.noise, ".wav"))
ent->noise_index = gi.soundindex(G_Fmt("{}.wav", st.noise).data());
else
ent->noise_index = gi.soundindex(st.noise);
if (!ent->volume)
ent->volume = ent->s.loop_volume = 1.0;
if (!ent->attenuation) {
if (ent->spawnflags.has(SPAWNFLAG_SPEAKER_LOOPED_OFF | SPAWNFLAG_SPEAKER_LOOPED_ON))
ent->attenuation = ATTN_STATIC;
else
ent->attenuation = ATTN_NORM;
} else if (ent->attenuation == -1) // use -1 so 0 defaults to 1
{
if (ent->spawnflags.has(SPAWNFLAG_SPEAKER_LOOPED_OFF | SPAWNFLAG_SPEAKER_LOOPED_ON)) {
ent->attenuation = ATTN_LOOP_NONE;
ent->svflags |= SVF_NOCULL;
} else
ent->attenuation = ATTN_NONE;
}
ent->s.loop_attenuation = ent->attenuation;
// check for prestarted looping sound
if (ent->spawnflags.has(SPAWNFLAG_SPEAKER_LOOPED_ON))
ent->s.sound = ent->noise_index;
if (ent->spawnflags.has(SPAWNFLAG_SPEAKER_NO_STEREO))
ent->s.renderfx |= RF_NO_STEREO;
ent->use = Use_Target_Speaker;
// must link the entity so we get areas and clusters so
// the server can determine who to send updates to
gi.linkentity(ent);
}
//==========================================================
constexpr spawnflags_t SPAWNFLAG_HELP_HELP1 = 1_spawnflag;
constexpr spawnflags_t SPAWNFLAG_SET_POI = 2_spawnflag;
extern void target_poi_use(gentity_t *ent, gentity_t *other, gentity_t *activator);
static USE(Use_Target_Help) (gentity_t *ent, gentity_t *other, gentity_t *activator) -> void {
if (ent->spawnflags.has(SPAWNFLAG_HELP_HELP1)) {
if (strcmp(game.helpmessage1, ent->message)) {
Q_strlcpy(game.helpmessage1, ent->message, sizeof(game.helpmessage1));
game.help1changed++;
}
} else {
if (strcmp(game.helpmessage2, ent->message)) {
Q_strlcpy(game.helpmessage2, ent->message, sizeof(game.helpmessage2));
game.help2changed++;
}
}
if (ent->spawnflags.has(SPAWNFLAG_SET_POI)) {
target_poi_use(ent, other, activator);
}
}
/*QUAKED target_help (1 0 1) (-16 -16 -24) (16 16 24) HELP1 SETPOI x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
When fired, the "message" key becomes the current personal computer string, and the message light will be set on all clients status bars.
*/
void SP_target_help(gentity_t *ent) {
if (deathmatch->integer) { // auto-remove for deathmatch
G_FreeEntity(ent);
return;
}
if (!ent->message) {
gi.Com_PrintFmt("{}: no message\n", *ent);
G_FreeEntity(ent);
return;
}
ent->use = Use_Target_Help;
if (ent->spawnflags.has(SPAWNFLAG_SET_POI)) {
if (st.image)
ent->noise_index = gi.imageindex(st.image);
else
ent->noise_index = gi.imageindex("friend");
}
}
//==========================================================
/*QUAKED target_secret (1 0 1) (-8 -8 -8) (8 8 8) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Counts a secret found.
These are single use targets.
*/
static USE(use_target_secret) (gentity_t *ent, gentity_t *other, gentity_t *activator) -> void {
gi.sound(ent, CHAN_VOICE, ent->noise_index, 1, ATTN_NORM, 0);
level.found_secrets++;
G_UseTargets(ent, activator);
G_FreeEntity(ent);
}
static THINK(G_VerifyTargetted) (gentity_t *ent) -> void {
if (!ent->targetname || !*ent->targetname)
gi.Com_PrintFmt("WARNING: missing targetname on {}\n", *ent);
else if (!G_FindByString<&gentity_t::target>(nullptr, ent->targetname))
gi.Com_PrintFmt("WARNING: doesn't appear to be anything targeting {}\n", *ent);
}
void SP_target_secret(gentity_t *ent) {
if (deathmatch->integer) { // auto-remove for deathmatch
G_FreeEntity(ent);
return;
}
ent->think = G_VerifyTargetted;
ent->nextthink = level.time + 10_ms;
ent->use = use_target_secret;
if (!st.noise)
st.noise = "misc/secret.wav";
ent->noise_index = gi.soundindex(st.noise);
ent->svflags = SVF_NOCLIENT;
level.total_secrets++;
}
//==========================================================
// [Paril-KEX] notify this player of a goal change
void G_PlayerNotifyGoal(gentity_t *player) {
// no goals in DM
if (deathmatch->integer)
return;
if (!player->client->pers.spawned)
return;
else if ((level.time - player->client->resp.entertime) < 300_ms)
return;
// N64 goals
if (level.goals) {
// if the goal has updated, commit it first
if (game.help1changed != game.help2changed) {
const char *current_goal = level.goals;
// skip ahead by the number of goals we've finished
for (size_t i = 0; i < level.goal_num; i++) {
while (*current_goal && *current_goal != '\t')
current_goal++;
if (!*current_goal)
gi.Com_Error("invalid n64 goals; tell Paril\n");
current_goal++;
}
// find the end of this goal
const char *goal_end = current_goal;
while (*goal_end && *goal_end != '\t')
goal_end++;
Q_strlcpy(game.helpmessage1, current_goal, min((size_t)(goal_end - current_goal + 1), sizeof(game.helpmessage1)));
game.help2changed = game.help1changed;
}
if (player->client->pers.game_help1changed != game.help1changed) {
gi.LocClient_Print(player, PRINT_TYPEWRITER, game.helpmessage1);
gi.local_sound(player, player, CHAN_AUTO | CHAN_RELIABLE, gi.soundindex("misc/talk.wav"), 1.0f, ATTN_NONE, 0.0f, GetUnicastKey());
player->client->pers.game_help1changed = game.help1changed;
}
// no regular goals
return;
}
if (player->client->pers.game_help1changed != game.help1changed) {
player->client->pers.game_help1changed = game.help1changed;
player->client->pers.helpchanged = 1;
player->client->pers.help_time = level.time + 5_sec;
if (*game.helpmessage1)
// [Sam-KEX] Print objective to screen
gi.LocClient_Print(player, PRINT_TYPEWRITER, "$g_primary_mission_objective", game.helpmessage1);
}
if (player->client->pers.game_help2changed != game.help2changed) {
player->client->pers.game_help2changed = game.help2changed;
player->client->pers.helpchanged = 1;
player->client->pers.help_time = level.time + 5_sec;
if (*game.helpmessage2)
// [Sam-KEX] Print objective to screen
gi.LocClient_Print(player, PRINT_TYPEWRITER, "$g_secondary_mission_objective", game.helpmessage2);
}
}
/*QUAKED target_goal (1 0 1) (-8 -8 -8) (8 8 8) KEEP_MUSIC x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Counts a goal completed.
These are single use targets.
*/
constexpr spawnflags_t SPAWNFLAG_GOAL_KEEP_MUSIC = 1_spawnflag;
static USE(use_target_goal) (gentity_t *ent, gentity_t *other, gentity_t *activator) -> void {
gi.sound(ent, CHAN_VOICE, ent->noise_index, 1, ATTN_NORM, 0);
level.found_goals++;
if (level.found_goals == level.total_goals && !ent->spawnflags.has(SPAWNFLAG_GOAL_KEEP_MUSIC)) {
if (ent->sounds)
gi.configstring(CS_CDTRACK, G_Fmt("{}", ent->sounds).data());
else
gi.configstring(CS_CDTRACK, "0");
}
// [Paril-KEX] n64 goals
if (level.goals) {
level.goal_num++;
game.help1changed++;
for (auto player : active_clients())
G_PlayerNotifyGoal(player);
}
G_UseTargets(ent, activator);
G_FreeEntity(ent);
}
void SP_target_goal(gentity_t *ent) {
if (deathmatch->integer) { // auto-remove for deathmatch
G_FreeEntity(ent);
return;
}
ent->use = use_target_goal;
if (!st.noise)
st.noise = "misc/secret.wav";
ent->noise_index = gi.soundindex(st.noise);
ent->svflags = SVF_NOCLIENT;
level.total_goals++;
}
//==========================================================
/*QUAKED target_explosion (1 0 0) (-8 -8 -8) (8 8 8) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Spawns an explosion temporary entity when used.
"delay" wait this long before going off
"dmg" how much radius damage should be done, defaults to 0
*/
static THINK(target_explosion_explode) (gentity_t *self) -> void {
float save;
gi.WriteByte(svc_temp_entity);
gi.WriteByte(TE_EXPLOSION1);
gi.WritePosition(self->s.origin);
gi.multicast(self->s.origin, MULTICAST_PHS, false);
T_RadiusDamage(self, self->activator, (float)self->dmg, nullptr, (float)self->dmg + 40, DAMAGE_NONE, MOD_EXPLOSIVE);
save = self->delay;
self->delay = 0;
G_UseTargets(self, self->activator);
self->delay = save;
}
static USE(use_target_explosion) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
self->activator = activator;
if (!self->delay) {
target_explosion_explode(self);
return;
}
self->think = target_explosion_explode;
self->nextthink = level.time + gtime_t::from_sec(self->delay);
}
void SP_target_explosion(gentity_t *ent) {
ent->use = use_target_explosion;
ent->svflags = SVF_NOCLIENT;
}
//==========================================================
/*QUAKED target_changelevel (1 0 0) (-8 -8 -8) (8 8 8) END_OF_UNIT x x CLEAR_INVENTORY NO_END_OF_UNIT FADE_OUT IMMEDIATE_LEAVE x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Changes level to "map" when fired
*/
static USE(use_target_changelevel) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
if (level.intermission_time)
return; // already activated
if (!deathmatch->integer && !coop->integer)
if (g_entities[1].health <= 0)
return;
// if noexit, do a ton of damage to other
if (deathmatch->integer && !g_dm_allow_exit->integer && other != world) {
T_Damage(other, self, self, vec3_origin, other->s.origin, vec3_origin, 10 * other->max_health, 1000, DAMAGE_NONE, MOD_EXIT);
return;
}
// if multiplayer, let everyone know who hit the exit
if (deathmatch->integer) {
if (level.time < 10_sec)
return;
if (activator && activator->client)
gi.LocBroadcast_Print(PRINT_HIGH, "$g_exited_level", activator->client->pers.netname);
}
// if going to a new unit, clear cross triggers
if (strstr(self->map, "*"))
game.cross_level_flags &= ~(SFL_CROSS_TRIGGER_MASK);
// if map has a landmark, store position instead of using spawn next map
if (activator && activator->client && !deathmatch->integer) {
activator->client->landmark_name = nullptr;
activator->client->landmark_rel_pos = vec3_origin;
self->target_ent = G_PickTarget(self->target);
if (self->target_ent && activator && activator->client) {
activator->client->landmark_name = G_CopyString(self->target_ent->targetname, TAG_GAME);
// get relative vector to landmark pos, and unrotate by the landmark angles in preparation to be
// rotated by the next map
activator->client->landmark_rel_pos = activator->s.origin - self->target_ent->s.origin;
activator->client->landmark_rel_pos = RotatePointAroundVector({ 1, 0, 0 }, activator->client->landmark_rel_pos, -self->target_ent->s.angles[PITCH]);
activator->client->landmark_rel_pos = RotatePointAroundVector({ 0, 1, 0 }, activator->client->landmark_rel_pos, -self->target_ent->s.angles[ROLL]);
activator->client->landmark_rel_pos = RotatePointAroundVector({ 0, 0, 1 }, activator->client->landmark_rel_pos, -self->target_ent->s.angles[YAW]);
activator->client->oldvelocity = RotatePointAroundVector({ 1, 0, 0 }, activator->client->oldvelocity, -self->target_ent->s.angles[PITCH]);
activator->client->oldvelocity = RotatePointAroundVector({ 0, 1, 0 }, activator->client->oldvelocity, -self->target_ent->s.angles[ROLL]);
activator->client->oldvelocity = RotatePointAroundVector({ 0, 0, 1 }, activator->client->oldvelocity, -self->target_ent->s.angles[YAW]);
// unrotate our view angles for the next map too
activator->client->oldviewangles = activator->client->ps.viewangles - self->target_ent->s.angles;
}
}
BeginIntermission(self);
}
void SP_target_changelevel(gentity_t *ent) {
if (!ent->map) {
gi.Com_PrintFmt("{}: no map\n", *ent);
G_FreeEntity(ent);
return;
}
ent->use = use_target_changelevel;
ent->svflags = SVF_NOCLIENT;
}
//==========================================================
/*QUAKED target_splash (1 0 0) (-8 -8 -8) (8 8 8) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Creates a particle splash effect when used.
Set "sounds" to one of the following:
1) sparks
2) blue water
3) brown water
4) slime
5) lava
6) blood
"count" how many pixels in the splash
"dmg" if set, does a radius damage at this location when it splashes
useful for lava/sparks
*/
static USE(use_target_splash) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
gi.WriteByte(svc_temp_entity);
gi.WriteByte(TE_SPLASH);
gi.WriteByte(self->count);
gi.WritePosition(self->s.origin);
gi.WriteDir(self->movedir);
gi.WriteByte(self->sounds);
gi.multicast(self->s.origin, MULTICAST_PVS, false);
if (self->dmg)
T_RadiusDamage(self, activator, (float)self->dmg, nullptr, (float)self->dmg + 40, DAMAGE_NONE, MOD_SPLASH);
}
void SP_target_splash(gentity_t *self) {
self->use = use_target_splash;
G_SetMovedir(self->s.angles, self->movedir);
if (!self->count)
self->count = 32;
// N64 "sparks" are blue, not yellow.
if (level.is_n64 && self->sounds == 1)
self->sounds = 7;
self->svflags = SVF_NOCLIENT;
}
//==========================================================
/*QUAKED target_spawner (1 0 0) (-8 -8 -8) (8 8 8) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Set target to the type of entity you want spawned.
Useful for spawning monsters and gibs in the factory levels.
For monsters:
Set direction to the facing you want it to have.
For gibs:
Set direction if you want it moving and
speed how fast it should be moving otherwise it
will just be dropped
*/
void ED_CallSpawn(gentity_t *ent);
static USE(use_target_spawner) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
gentity_t *ent;
ent = G_Spawn();
ent->classname = self->target;
ent->flags = self->flags;
ent->s.origin = self->s.origin;
ent->s.angles = self->s.angles;
st = {};
// [Paril-KEX] although I fixed these in our maps, this is just
// in case anybody else does this by accident. Don't count these monsters
// so they don't inflate the monster count.
ent->monsterinfo.aiflags |= AI_DO_NOT_COUNT;
ED_CallSpawn(ent);
gi.linkentity(ent);
KillBox(ent, false);
if (self->speed)
ent->velocity = self->movedir;
ent->s.renderfx |= RF_IR_VISIBLE;
}
void SP_target_spawner(gentity_t *self) {
self->use = use_target_spawner;
self->svflags = SVF_NOCLIENT;
if (self->speed) {
G_SetMovedir(self->s.angles, self->movedir);
self->movedir *= self->speed;
}
}
//==========================================================
/*QUAKED target_blaster (1 0 0) (-8 -8 -8) (8 8 8) NOTRAIL NOEFFECTS x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Fires a blaster bolt in the set direction when triggered.
dmg default is 15
speed default is 1000
*/
constexpr spawnflags_t SPAWNFLAG_BLASTER_NOTRAIL = 1_spawnflag;
constexpr spawnflags_t SPAWNFLAG_BLASTER_NOEFFECTS = 2_spawnflag;
static USE(use_target_blaster) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
effects_t effect;
if (self->spawnflags.has(SPAWNFLAG_BLASTER_NOEFFECTS))
effect = EF_NONE;
else if (self->spawnflags.has(SPAWNFLAG_BLASTER_NOTRAIL))
effect = EF_HYPERBLASTER;
else
effect = EF_BLASTER;
fire_blaster(self, self->s.origin, self->movedir, self->dmg, (int)self->speed, effect, MOD_TARGET_BLASTER);
gi.sound(self, CHAN_VOICE, self->noise_index, 1, ATTN_NORM, 0);
}
void SP_target_blaster(gentity_t *self) {
self->use = use_target_blaster;
G_SetMovedir(self->s.angles, self->movedir);
self->noise_index = gi.soundindex("weapons/laser2.wav");
if (!self->dmg)
self->dmg = 15;
if (!self->speed)
self->speed = 1000;
self->svflags = SVF_NOCLIENT;
}
//==========================================================
/*QUAKED target_crosslevel_trigger (.5 .5 .5) (-8 -8 -8) (8 8 8) TRIGGER1 TRIGGER2 TRIGGER3 TRIGGER4 TRIGGER5 TRIGGER6 TRIGGER7 TRIGGER8 NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
Once this trigger is touched/used, any trigger_crosslevel_target with the same trigger number is automatically used when a level is started within the same unit. It is OK to check multiple triggers. Message, delay, target, and killtarget also work.
*/
static USE(trigger_crosslevel_trigger_use) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
game.cross_level_flags |= self->spawnflags.value;
G_FreeEntity(self);
}
void SP_target_crosslevel_trigger(gentity_t *self) {
self->svflags = SVF_NOCLIENT;
self->use = trigger_crosslevel_trigger_use;
}
/*QUAKED target_crosslevel_target (.5 .5 .5) (-8 -8 -8) (8 8 8) TRIGGER1 TRIGGER2 TRIGGER3 TRIGGER4 TRIGGER5 TRIGGER6 TRIGGER7 TRIGGER8 x x x x x x x x TRIGGER9 TRIGGER10 TRIGGER11 TRIGGER12 TRIGGER13 TRIGGER14 TRIGGER15 TRIGGER16
Triggered by a trigger_crosslevel elsewhere within a unit. If multiple triggers are checked, all must be true. Delay, target and
killtarget also work.
"delay" delay before using targets if the trigger has been activated (default 1)
*/
static THINK(target_crosslevel_target_think) (gentity_t *self) -> void {
if (self->spawnflags.value == (game.cross_level_flags & SFL_CROSS_TRIGGER_MASK & self->spawnflags.value)) {
G_UseTargets(self, self);
G_FreeEntity(self);
}
}
void SP_target_crosslevel_target(gentity_t *self) {
if (!self->delay)
self->delay = 1;
self->svflags = SVF_NOCLIENT;
self->think = target_crosslevel_target_think;
self->nextthink = level.time + gtime_t::from_sec(self->delay);
}
//==========================================================
/*QUAKED target_laser (0 .5 .8) (-8 -8 -8) (8 8 8) START_ON RED GREEN BLUE YELLOW ORANGE FAT WINDOWSTOP NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
When triggered, fires a laser. You can either set a target or a direction.
WINDOWSTOP - stops at CONTENTS_WINDOW
*/
constexpr spawnflags_t SPAWNFLAG_LASER_STOPWINDOW = 0x0080_spawnflag;
struct laser_pierce_t : pierce_args_t {
gentity_t *self;
int32_t count;
bool damaged_thing = false;
inline laser_pierce_t(gentity_t *self, int32_t count) :
pierce_args_t(),
self(self),
count(count) {}
// we hit an entity; return false to stop the piercing.
// you can adjust the mask for the re-trace (for water, etc).
virtual bool hit(contents_t &mask, vec3_t &end) override {
// hurt it if we can
if (self->dmg > 0 && (tr.ent->takedamage) && !(tr.ent->flags & FL_IMMUNE_LASER) && self->damage_debounce_time <= level.time) {
damaged_thing = true;
T_Damage(tr.ent, self, self->activator, self->movedir, tr.endpos, vec3_origin, self->dmg, 1, DAMAGE_ENERGY, MOD_TARGET_LASER);
}
// if we hit something that's not a monster or player or is immune to lasers, we're done
if (!(tr.ent->svflags & SVF_MONSTER) && (!tr.ent->client) && !(tr.ent->flags & FL_DAMAGEABLE)) {
if (self->spawnflags.has(SPAWNFLAG_LASER_ZAP)) {
self->spawnflags &= ~SPAWNFLAG_LASER_ZAP;
gi.WriteByte(svc_temp_entity);
gi.WriteByte(TE_LASER_SPARKS);
gi.WriteByte(count);
gi.WritePosition(tr.endpos);
gi.WriteDir(tr.plane.normal);
gi.WriteByte(self->s.skinnum);
gi.multicast(tr.endpos, MULTICAST_PVS, false);
}
return false;
}
if (!mark(tr.ent))
return false;
return true;
}
};
static THINK(target_laser_think) (gentity_t *self) -> void {
int32_t count;
if (self->spawnflags.has(SPAWNFLAG_LASER_ZAP))
count = 8;
else
count = 4;
if (self->enemy) {
vec3_t last_movedir = self->movedir;
vec3_t point = (self->enemy->absmin + self->enemy->absmax) * 0.5f;
self->movedir = point - self->s.origin;
self->movedir.normalize();
if (self->movedir != last_movedir)
self->spawnflags |= SPAWNFLAG_LASER_ZAP;
}
vec3_t start = self->s.origin;
vec3_t end = start + (self->movedir * 2048);
laser_pierce_t args{
self,
count
};
contents_t mask = self->spawnflags.has(SPAWNFLAG_LASER_STOPWINDOW) ? MASK_SHOT : (CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_PLAYER | CONTENTS_DEADMONSTER);
pierce_trace(start, end, self, args, mask);
self->s.old_origin = args.tr.endpos;
if (args.damaged_thing)
self->damage_debounce_time = level.time + 10_hz;
self->nextthink = level.time + FRAME_TIME_S;
gi.linkentity(self);
}
static void target_laser_on(gentity_t *self) {
if (!self->activator)
self->activator = self;
self->spawnflags |= SPAWNFLAG_LASER_ZAP | SPAWNFLAG_LASER_ON;
self->svflags &= ~SVF_NOCLIENT;
self->flags |= FL_TRAP;
target_laser_think(self);
}
void target_laser_off(gentity_t *self) {
self->spawnflags &= ~SPAWNFLAG_LASER_ON;
self->svflags |= SVF_NOCLIENT;
self->flags &= ~FL_TRAP;
self->nextthink = 0_ms;
}
static USE(target_laser_use) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
self->activator = activator;
if (self->spawnflags.has(SPAWNFLAG_LASER_ON))
target_laser_off(self);
else
target_laser_on(self);
}
static THINK(target_laser_start) (gentity_t *self) -> void {
gentity_t *ent;
self->movetype = MOVETYPE_NONE;
self->solid = SOLID_NOT;
self->s.renderfx |= RF_BEAM;
self->s.modelindex = MODELINDEX_WORLD; // must be non-zero
// [Sam-KEX] On Q2N64, spawnflag of 128 turns it into a lightning bolt
if (level.is_n64) {
// Paril: fix for N64
if (self->spawnflags.has(SPAWNFLAG_LASER_STOPWINDOW)) {
self->spawnflags &= ~SPAWNFLAG_LASER_STOPWINDOW;
self->spawnflags |= SPAWNFLAG_LASER_LIGHTNING;
}
}
if (self->spawnflags.has(SPAWNFLAG_LASER_LIGHTNING)) {
self->s.renderfx |= RF_BEAM_LIGHTNING; // tell renderer it is lightning
if (!self->s.skinnum)
self->s.skinnum = 0xf3f3f1f1; // default lightning color
}
// set the beam diameter
// [Paril-KEX] lab has this set prob before lightning was implemented
if (!level.is_n64 && self->spawnflags.has(SPAWNFLAG_LASER_FAT))
self->s.frame = 16;
else
self->s.frame = 4;
// set the color
if (!self->s.skinnum) {
if (self->spawnflags.has(SPAWNFLAG_LASER_RED))
self->s.skinnum = 0xf2f2f0f0;
else if (self->spawnflags.has(SPAWNFLAG_LASER_GREEN))
self->s.skinnum = 0xd0d1d2d3;
else if (self->spawnflags.has(SPAWNFLAG_LASER_BLUE))
self->s.skinnum = 0xf3f3f1f1;
else if (self->spawnflags.has(SPAWNFLAG_LASER_YELLOW))
self->s.skinnum = 0xdcdddedf;
else if (self->spawnflags.has(SPAWNFLAG_LASER_ORANGE))
self->s.skinnum = 0xe0e1e2e3;
}
if (!self->enemy) {
if (self->target) {
ent = G_FindByString<&gentity_t::targetname>(nullptr, self->target);
if (!ent)
gi.Com_PrintFmt("{}: {} is a bad target\n", *self, self->target);
else {
self->enemy = ent;
// N64 fix
// FIXME: which map was this for again? oops
if (level.is_n64 && !strcmp(self->enemy->classname, "func_train") && !(self->enemy->spawnflags & SPAWNFLAG_TRAIN_START_ON))
self->enemy->use(self->enemy, self, self);
}
} else {
G_SetMovedir(self->s.angles, self->movedir);
}
}
self->use = target_laser_use;
self->think = target_laser_think;
if (!self->dmg)
self->dmg = 1;
self->mins = { -8, -8, -8 };
self->maxs = { 8, 8, 8 };
gi.linkentity(self);
if (self->spawnflags.has(SPAWNFLAG_LASER_ON))
target_laser_on(self);
else
target_laser_off(self);
}
void SP_target_laser(gentity_t *self) {
// let everything else get spawned before we start firing
self->think = target_laser_start;
self->flags |= FL_TRAP_LASER_FIELD;
self->nextthink = level.time + 1_sec;
}
//==========================================================
/*QUAKED target_lightramp (0 .5 .8) (-8 -8 -8) (8 8 8) TOGGLE x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
speed How many seconds the ramping will take
message two letters; starting lightlevel and ending lightlevel
*/
constexpr spawnflags_t SPAWNFLAG_LIGHTRAMP_TOGGLE = 1_spawnflag;
static THINK(target_lightramp_think) (gentity_t *self) -> void {
char style[2];
style[0] = (char)('a' + self->movedir[0] + ((level.time - self->timestamp) / gi.frame_time_s).seconds() * self->movedir[2]);
style[1] = 0;
gi.configstring(CS_LIGHTS + self->enemy->style, style);
if ((level.time - self->timestamp).seconds() < self->speed) {
self->nextthink = level.time + FRAME_TIME_S;
} else if (self->spawnflags.has(SPAWNFLAG_LIGHTRAMP_TOGGLE)) {
char temp;
temp = (char)self->movedir[0];
self->movedir[0] = self->movedir[1];
self->movedir[1] = temp;
self->movedir[2] *= -1;
}
}
static USE(target_lightramp_use) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
if (!self->enemy) {
gentity_t *e;
// check all the targets
e = nullptr;
while (1) {
e = G_FindByString<&gentity_t::targetname>(e, self->target);
if (!e)
break;
if (strcmp(e->classname, "light") != 0) {
gi.Com_PrintFmt("{}: target {} ({}) is not a light\n", *self, self->target, *e);
} else {
self->enemy = e;
}
}
if (!self->enemy) {
gi.Com_PrintFmt("{}: target {} not found\n", *self, self->target);
G_FreeEntity(self);
return;
}
}
self->timestamp = level.time;
target_lightramp_think(self);
}
void SP_target_lightramp(gentity_t *self) {
if (!self->message || strlen(self->message) != 2 || self->message[0] < 'a' || self->message[0] > 'z' || self->message[1] < 'a' || self->message[1] > 'z' || self->message[0] == self->message[1]) {
gi.Com_PrintFmt("{}: bad ramp ({})\n", *self, self->message ? self->message : "null string");
G_FreeEntity(self);
return;
}
if (deathmatch->integer) {
G_FreeEntity(self);
return;
}
if (!self->target) {
gi.Com_PrintFmt("{}: no target\n", *self);
G_FreeEntity(self);
return;
}
self->svflags |= SVF_NOCLIENT;
self->use = target_lightramp_use;
self->think = target_lightramp_think;
self->movedir[0] = (float)(self->message[0] - 'a');
self->movedir[1] = (float)(self->message[1] - 'a');
self->movedir[2] = (self->movedir[1] - self->movedir[0]) / (self->speed / gi.frame_time_s);
}
//==========================================================
/*QUAKED target_earthquake (1 0 0) (-8 -8 -8) (8 8 8) SILENT TOGGLE UNKNOWN_ROGUE ONE_SHOT x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
When triggered, this initiates a level-wide earthquake.
All players are affected with a screen shake.
"speed" severity of the quake (default:200)
"count" duration of the quake (default:5)
*/
constexpr spawnflags_t SPAWNFLAGS_EARTHQUAKE_SILENT = 1_spawnflag;
constexpr spawnflags_t SPAWNFLAGS_EARTHQUAKE_TOGGLE = 2_spawnflag;
[[maybe_unused]] constexpr spawnflags_t SPAWNFLAGS_EARTHQUAKE_UNKNOWN_ROGUE = 4_spawnflag;
constexpr spawnflags_t SPAWNFLAGS_EARTHQUAKE_ONE_SHOT = 8_spawnflag;
static THINK(target_earthquake_think) (gentity_t *self) -> void {
uint32_t i;
gentity_t *e;
if (!(self->spawnflags & SPAWNFLAGS_EARTHQUAKE_SILENT)) {
if (self->last_move_time < level.time) {
gi.positioned_sound(self->s.origin, self, CHAN_VOICE, self->noise_index, 1.0, ATTN_NONE, 0);
self->last_move_time = level.time + 6.5_sec;
}
}
for (i = 1, e = g_entities + i; i < globals.num_entities; i++, e++) {
if (!e->inuse)
continue;
if (!e->client)
break;
e->client->quake_time = level.time + 1000_ms;
}
if (level.time < self->timestamp)
self->nextthink = level.time + 10_hz;
}
static USE(target_earthquake_use) (gentity_t *self, gentity_t *other, gentity_t *activator) -> void {
if (self->spawnflags.has(SPAWNFLAGS_EARTHQUAKE_ONE_SHOT)) {
uint32_t i;
gentity_t *e;
for (i = 1, e = g_entities + i; i < globals.num_entities; i++, e++) {
if (!e->inuse)
continue;
if (!e->client)
break;
e->client->v_dmg_pitch = -self->speed * 0.1f;
e->client->v_dmg_time = level.time + DAMAGE_TIME();
}
return;
}
self->timestamp = level.time + gtime_t::from_sec(self->count);
if (self->spawnflags.has(SPAWNFLAGS_EARTHQUAKE_TOGGLE)) {
if (self->style)
self->nextthink = 0_ms;
else
self->nextthink = level.time + FRAME_TIME_S;
self->style = !self->style;
} else {
self->nextthink = level.time + FRAME_TIME_S;
self->last_move_time = 0_ms;
}
self->activator = activator;
}
void SP_target_earthquake(gentity_t *self) {
if (!self->targetname)
gi.Com_PrintFmt("{}: untargeted\n", *self);
if (level.is_n64) {
self->spawnflags |= SPAWNFLAGS_EARTHQUAKE_TOGGLE;
self->speed = 5;
}
if (!self->count)
self->count = 5;
if (!self->speed)
self->speed = 200;
self->svflags |= SVF_NOCLIENT;
self->think = target_earthquake_think;
self->use = target_earthquake_use;
if (!(self->spawnflags & SPAWNFLAGS_EARTHQUAKE_SILENT))
self->noise_index = gi.soundindex("world/quake.wav");
}
/*QUAKED target_camera (1 0 0) (-8 -8 -8) (8 8 8) x x x x x x x x NOT_EASY NOT_MEDIUM NOT_HARD NOT_DM NOT_COOP
[Sam-KEX] Creates a camera path as seen in the N64 version.
*/
constexpr size_t HACKFLAG_TELEPORT_OUT = 2;
constexpr size_t HACKFLAG_SKIPPABLE = 64;
constexpr size_t HACKFLAG_END_OF_UNIT = 128;
static void camera_lookat_pathtarget(gentity_t *self, vec3_t origin, vec3_t *dest) {
if (self->pathtarget) {
gentity_t *pt = nullptr;
pt = G_FindByString<&gentity_t::targetname>(pt, self->pathtarget);
if (pt) {
float yaw, pitch;
vec3_t delta = pt->s.origin - origin;
float d = delta[0] * delta[0] + delta[1] * delta[1];
if (d == 0.0f) {
yaw = 0.0f;
pitch = (delta[2] > 0.0f) ? 90.0f : -90.0f;
} else {
yaw = atan2(delta[1], delta[0]) * (180.0f / PIf);
pitch = atan2(delta[2], sqrt(d)) * (180.0f / PIf);
}