forked from circa-III/basejkaplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathg_misc.c
3648 lines (3013 loc) · 91.1 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
/*
===========================================================================
Copyright (C) 1999 - 2005, Id Software, Inc.
Copyright (C) 2000 - 2013, Raven Software, Inc.
Copyright (C) 2001 - 2013, Activision, Inc.
Copyright (C) 2013 - 2015, OpenJK contributors
This file is part of the OpenJK source code.
OpenJK is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/
// g_misc.c
#include "g_local.h"
#include "ghoul2/G2.h"
#include "ai_main.h" //for the g2animents
#define HOLOCRON_RESPAWN_TIME 30000
#define MAX_AMMO_GIVE 2
#define STATION_RECHARGE_TIME 100
void HolocronThink(gentity_t *ent);
/*QUAKED func_group (0 0 0) ?
Used to group brushes together just for editor convenience. They are turned into normal brushes by the utilities.
*/
/*QUAKED info_camp (0 0.5 0) (-4 -4 -4) (4 4 4)
Used as a positional target for calculations in the utilities (spotlights, etc), but removed during gameplay.
*/
void SP_info_camp( gentity_t *self ) {
G_SetOrigin( self, self->s.origin );
}
/*QUAKED info_null (0 0.5 0) (-4 -4 -4) (4 4 4)
Used as a positional target for calculations in the utilities (spotlights, etc), but removed during gameplay.
*/
void SP_info_null( gentity_t *self ) {
G_FreeEntity( self );
}
/*QUAKED info_notnull (0 0.5 0) (-4 -4 -4) (4 4 4)
Used as a positional target for in-game calculation, like jumppad targets.
target_position does the same thing
*/
void SP_info_notnull( gentity_t *self ){
G_SetOrigin( self, self->s.origin );
}
/*QUAKED lightJunior (0 0.7 0.3) (-8 -8 -8) (8 8 8) nonlinear angle negative_spot negative_point
Non-displayed light that only affects dynamic game models, but does not contribute to lightmaps
"light" overrides the default 300 intensity.
Nonlinear checkbox gives inverse square falloff instead of linear
Angle adds light:surface angle calculations (only valid for "Linear" lights) (wolf)
Lights pointed at a target will be spotlights.
"radius" overrides the default 64 unit radius of a spotlight at the target point.
"fade" falloff/radius adjustment value. multiply the run of the slope by "fade" (1.0f default) (only valid for "Linear" lights) (wolf)
*/
/*QUAKED light (0 1 0) (-8 -8 -8) (8 8 8) linear noIncidence START_OFF
Non-displayed light.
"light" overrides the default 300 intensity. - affects size
a negative "light" will subtract the light's color
'Linear' checkbox gives linear falloff instead of inverse square
'noIncidence' checkbox makes lighting smoother
Lights pointed at a target will be spotlights.
"radius" overrides the default 64 unit radius of a spotlight at the target point.
"scale" multiplier for the light intensity - does not affect size (default 1)
greater than 1 is brighter, between 0 and 1 is dimmer.
"color" sets the light's color
"targetname" to indicate a switchable light - NOTE that all lights with the same targetname will be grouped together and act as one light (ie: don't mix colors, styles or start_off flag)
"style" to specify a specify light style, even for switchable lights!
"style_off" light style to use when switched off (Only for switchable lights)
1 FLICKER (first variety)
2 SLOW STRONG PULSE
3 CANDLE (first variety)
4 FAST STROBE
5 GENTLE PULSE 1
6 FLICKER (second variety)
7 CANDLE (second variety)
8 CANDLE (third variety)
9 SLOW STROBE (fourth variety)
10 FLUORESCENT FLICKER
11 SLOW PULSE NOT FADE TO BLACK
12 FAST PULSE FOR JEREMY
13 Test Blending
*/
static void misc_lightstyle_set ( gentity_t *ent)
{
const int mLightStyle = ent->count;
const int mLightSwitchStyle = ent->bounceCount;
const int mLightOffStyle = ent->fly_sound_debounce_time;
if (!ent->alt_fire)
{ //turn off
if (mLightOffStyle) //i have a light style i'd like to use when off
{
char lightstyle[32];
trap->GetConfigstring(CS_LIGHT_STYLES + (mLightOffStyle*3)+0, lightstyle, 32);
trap->SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+0, lightstyle);
trap->GetConfigstring(CS_LIGHT_STYLES + (mLightOffStyle*3)+1, lightstyle, 32);
trap->SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+1, lightstyle);
trap->GetConfigstring(CS_LIGHT_STYLES + (mLightOffStyle*3)+2, lightstyle, 32);
trap->SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+2, lightstyle);
}else
{
trap->SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+0, "a");
trap->SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+1, "a");
trap->SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+2, "a");
}
}
else
{ //Turn myself on now
if (mLightSwitchStyle) //i have a light style i'd like to use when on
{
char lightstyle[32];
trap->GetConfigstring(CS_LIGHT_STYLES + (mLightSwitchStyle*3)+0, lightstyle, 32);
trap->SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+0, lightstyle);
trap->GetConfigstring(CS_LIGHT_STYLES + (mLightSwitchStyle*3)+1, lightstyle, 32);
trap->SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+1, lightstyle);
trap->GetConfigstring(CS_LIGHT_STYLES + (mLightSwitchStyle*3)+2, lightstyle, 32);
trap->SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+2, lightstyle);
}
else
{
trap->SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+0, "z");
trap->SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+1, "z");
trap->SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+2, "z");
}
}
}
void misc_dlight_use ( gentity_t *ent, gentity_t *other, gentity_t *activator )
{
G_ActivateBehavior(ent,BSET_USE);
ent->alt_fire = !ent->alt_fire; //toggle
misc_lightstyle_set (ent);
}
void SP_light( gentity_t *self ) {
if (!self->targetname )
{//if i don't have a light style switch, the i go away
G_FreeEntity( self );
return;
}
G_SpawnInt( "style", "0", &self->count );
G_SpawnInt( "switch_style", "0", &self->bounceCount );
G_SpawnInt( "style_off", "0", &self->fly_sound_debounce_time );
G_SetOrigin( self, self->s.origin );
trap->LinkEntity( (sharedEntity_t *)self );
self->use = misc_dlight_use;
self->s.eType = ET_GENERAL;
self->alt_fire = qfalse;
self->r.svFlags |= SVF_NOCLIENT;
if ( !(self->spawnflags & 4) )
{ //turn myself on now
self->alt_fire = qtrue;
}
misc_lightstyle_set (self);
}
/*
=================================================================================
TELEPORTERS
=================================================================================
*/
void TeleportPlayer( gentity_t *player, vec3_t origin, vec3_t angles ) {
gentity_t *tent;
qboolean isNPC = qfalse;
qboolean noAngles;
if (player->s.eType == ET_NPC)
{
isNPC = qtrue;
}
noAngles = (angles[0] > 999999.0) ? qtrue : qfalse;
// use temp events at source and destination to prevent the effect
// from getting dropped by a second player event
if ( player->client->sess.sessionTeam != TEAM_SPECTATOR ) {
tent = G_TempEntity( player->client->ps.origin, EV_PLAYER_TELEPORT_OUT, player->s.number );
tent->s.clientNum = player->s.clientNum;
tent = G_TempEntity( origin, EV_PLAYER_TELEPORT_IN, player->s.number);
tent->s.clientNum = player->s.clientNum;
}
// unlink to make sure it can't possibly interfere with G_KillBox
trap->UnlinkEntity ((sharedEntity_t *)player);
VectorCopy ( origin, player->client->ps.origin );
player->client->ps.origin[2] += 1;
// spit the player out
if ( !noAngles ) {
AngleVectors( angles, player->client->ps.velocity, NULL, NULL );
VectorScale( player->client->ps.velocity, 400, player->client->ps.velocity );
player->client->ps.pm_time = 160; // hold time
player->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
// set angles
SetClientViewAngle( player, angles );
}
// toggle the teleport bit so the client knows to not lerp
player->client->ps.eFlags ^= EF_TELEPORT_BIT;
// kill anything at the destination
if ( player->client->sess.sessionTeam != TEAM_SPECTATOR ) {
G_KillBox (player);
}
// save results of pmove
BG_PlayerStateToEntityState( &player->client->ps, &player->s, qtrue );
if (isNPC)
{
player->s.eType = ET_NPC;
}
// use the precise origin for linking
VectorCopy( player->client->ps.origin, player->r.currentOrigin );
if ( player->client->sess.sessionTeam != TEAM_SPECTATOR ) {
trap->LinkEntity ((sharedEntity_t *)player);
}
}
/*QUAKED misc_teleporter_dest (1 0 0) (-32 -32 -24) (32 32 -16)
Point teleporters at these.
Now that we don't have teleport destination pads, this is just
an info_notnull
*/
void SP_misc_teleporter_dest( gentity_t *ent ) {
}
//===========================================================
/*QUAKED misc_model (1 0 0) (-16 -16 -16) (16 16 16)
"model" arbitrary .md3 or .ase file to display
turns into map triangles - not solid
*/
void SP_misc_model( gentity_t *ent ) {
#if 0
ent->s.modelindex = G_ModelIndex( ent->model );
VectorSet (ent->r.mins, -16, -16, -16);
VectorSet (ent->r.maxs, 16, 16, 16);
trap->LinkEntity ((sharedEntity_t *)ent);
G_SetOrigin( ent, ent->s.origin );
VectorCopy( ent->s.angles, ent->s.apos.trBase );
#else
G_FreeEntity( ent );
#endif
}
/*QUAKED misc_model_static (1 0 0) (-16 -16 0) (16 16 16)
"model" arbitrary .md3 file to display
"zoffset" units to offset vertical culling position by, can be
negative or positive. This does not affect the actual
position of the model, only the culling position. Use
it for models with stupid origins that go below the
ground and whatnot.
"modelscale" scale on all axis
"modelscale_vec" scale difference axis
loaded as a model in the renderer - does not take up precious
bsp space!
*/
void SP_misc_model_static(gentity_t *ent)
{
G_FreeEntity( ent );
}
/*QUAKED misc_model_breakable (1 0 0) (-16 -16 -16) (16 16 16) SOLID AUTOANIMATE DEADSOLID NO_DMODEL NO_SMOKE USE_MODEL USE_NOT_BREAK PLAYER_USE NO_EXPLOSION
SOLID - Movement is blocked by it, if not set, can still be broken by explosions and shots if it has health
AUTOANIMATE - Will cycle it's anim
DEADSOLID - Stay solid even when destroyed (in case damage model is rather large).
NO_DMODEL - Makes it NOT display a damage model when destroyed, even if one exists
USE_MODEL - When used, will toggle to it's usemodel (model name + "_u1.md3")... this obviously does nothing if USE_NOT_BREAK is not checked
USE_NOT_BREAK - Using it, doesn't make it break, still can be destroyed by damage
PLAYER_USE - Player can use it with the use button
NO_EXPLOSION - By default, will explode when it dies...this is your override.
"model" arbitrary .md3 file to display
"health" how much health to have - default is zero (not breakable) If you don't set the SOLID flag, but give it health, it can be shot but will not block NPCs or players from moving
"targetname" when used, dies and displays damagemodel, if any (if not, removes itself)
"target" What to use when it dies
"target2" What to use when it's repaired
"target3" What to use when it's used while it's broken
"paintarget" target to fire when hit (but not destroyed)
"count" the amount of armor/health/ammo given (default 50)
"gravity" if set to 1, this will be affected by gravity
"radius" Chunk code tries to pick a good volume of chunks, but you can alter this to scale the number of spawned chunks. (default 1) (.5) is half as many chunks, (2) is twice as many chunks
Damage: default is none
"splashDamage" - damage to do (will make it explode on death)
"splashRadius" - radius for above damage
"team" - This cannot take damage from members of this team:
"player"
"neutral"
"enemy"
"material" - default is "8 - MAT_NONE" - choose from this list:
0 = MAT_METAL (grey metal)
1 = MAT_GLASS
2 = MAT_ELECTRICAL (sparks only)
3 = MAT_ELEC_METAL (METAL chunks and sparks)
4 = MAT_DRK_STONE (brown stone chunks)
5 = MAT_LT_STONE (tan stone chunks)
6 = MAT_GLASS_METAL (glass and METAL chunks)
7 = MAT_METAL2 (blue/grey metal)
8 = MAT_NONE (no chunks-DEFAULT)
9 = MAT_GREY_STONE (grey colored stone)
10 = MAT_METAL3 (METAL and METAL2 chunk combo)
11 = MAT_CRATE1 (yellow multi-colored crate chunks)
12 = MAT_GRATE1 (grate chunks--looks horrible right now)
13 = MAT_ROPE (for yavin_trial, no chunks, just wispy bits )
14 = MAT_CRATE2 (red multi-colored crate chunks)
15 = MAT_WHITE_METAL (white angular chunks for Stu, NS_hideout )
FIXME/TODO:
set size better?
multiple damage models?
custom explosion effect/sound?
*/
void misc_model_breakable_gravity_init( gentity_t *ent, qboolean dropToFloor );
void misc_model_breakable_init( gentity_t *ent );
void SP_misc_model_breakable( gentity_t *ent )
{
float grav;
G_SpawnInt( "material", "8", (int*)&ent->material );
G_SpawnFloat( "radius", "1", &ent->radius ); // used to scale chunk code if desired by a designer
misc_model_breakable_init( ent );
if ( !ent->r.mins[0] && !ent->r.mins[1] && !ent->r.mins[2] )
{
VectorSet (ent->r.mins, -16, -16, -16);
}
if ( !ent->r.maxs[0] && !ent->r.maxs[1] && !ent->r.maxs[2] )
{
VectorSet (ent->r.maxs, 16, 16, 16);
}
G_SetOrigin( ent, ent->s.origin );
G_SetAngles( ent, ent->s.angles );
trap->LinkEntity ((sharedEntity_t *)ent);
if ( ent->spawnflags & 128 )
{//Can be used by the player's BUTTON_USE
ent->r.svFlags |= SVF_PLAYER_USABLE;
}
ent->s.teamowner = 0;
G_SpawnFloat( "gravity", "0", &grav );
if ( grav )
{//affected by gravity
G_SetAngles( ent, ent->s.angles );
G_SetOrigin( ent, ent->r.currentOrigin );
misc_model_breakable_gravity_init( ent, qtrue );
}
}
void misc_model_breakable_gravity_init( gentity_t *ent, qboolean dropToFloor )
{
trace_t tr;
vec3_t top, bottom;
ent->s.eType = ET_GENERAL;
//ent->s.eFlags |= EF_BOUNCE_HALF; // FIXME
ent->clipmask = MASK_SOLID|CONTENTS_BODY|CONTENTS_MONSTERCLIP|CONTENTS_BOTCLIP;//?
ent->physicsBounce = ent->mass = VectorLength( ent->r.maxs ) + VectorLength( ent->r.mins );
//drop to floor
if ( dropToFloor )
{
VectorCopy( ent->r.currentOrigin, top );
top[2] += 1;
VectorCopy( ent->r.currentOrigin, bottom );
bottom[2] = MIN_WORLD_COORD;
trap->Trace( &tr, top, ent->r.mins, ent->r.maxs, bottom, ent->s.number, MASK_NPCSOLID, qfalse, 0, 0 );
if ( !tr.allsolid && !tr.startsolid && tr.fraction < 1.0 )
{
G_SetOrigin( ent, tr.endpos );
trap->LinkEntity( (sharedEntity_t *)ent );
}
}
else
{
G_SetOrigin( ent, ent->r.currentOrigin );
trap->LinkEntity( (sharedEntity_t *)ent );
}
//set up for object thinking
if ( VectorCompare( ent->s.pos.trDelta, vec3_origin ) )
{//not moving
ent->s.pos.trType = TR_STATIONARY;
}
else
{
ent->s.pos.trType = TR_GRAVITY;
}
VectorCopy( ent->r.currentOrigin, ent->s.pos.trBase );
VectorClear( ent->s.pos.trDelta );
ent->s.pos.trTime = level.time;
if ( VectorCompare( ent->s.apos.trDelta, vec3_origin ) )
{//not moving
ent->s.apos.trType = TR_STATIONARY;
}
else
{
ent->s.apos.trType = TR_LINEAR;
}
VectorCopy( ent->r.currentAngles, ent->s.apos.trBase );
VectorClear( ent->s.apos.trDelta );
ent->s.apos.trTime = level.time;
}
void misc_model_breakable_init( gentity_t *ent )
{
if (!ent->model) {
trap->Error( ERR_DROP, "no model set on %s at (%.1f %.1f %.1f)\n", ent->classname, ent->s.origin[0],ent->s.origin[1],ent->s.origin[2] );
}
//Main model
ent->s.modelindex = ent->sound2to1 = G_ModelIndex( ent->model );
if ( ent->spawnflags & 1 )
{//Blocks movement
ent->r.contents = CONTENTS_SOLID|CONTENTS_OPAQUE|CONTENTS_BODY|CONTENTS_MONSTERCLIP|CONTENTS_BOTCLIP;//Was CONTENTS_SOLID, but only architecture should be this
}
else if ( ent->health )
{//Can only be shot
ent->r.contents = CONTENTS_SHOTCLIP;
}
// TODO: fix using
// TODO: fix health/dying funcs
}
/*QUAKED misc_G2model (1 0 0) (-16 -16 -16) (16 16 16)
"model" arbitrary .glm file to display
*/
void SP_misc_G2model( gentity_t *ent ) {
#if 0
char name1[200] = "models/players/kyle/modelmp.glm";
trap->G2API_InitGhoul2Model(&ent->s, name1, G_ModelIndex( name1 ), 0, 0, 0, 0);
trap->G2API_SetBoneAnim(ent->s.ghoul2, 0, "model_root", 0, 12, BONE_ANIM_OVERRIDE_LOOP, 1.0f, level.time, -1, -1);
ent->s.radius = 150;
// VectorSet (ent->r.mins, -16, -16, -16);
// VectorSet (ent->r.maxs, 16, 16, 16);
trap->LinkEntity ((sharedEntity_t *)ent);
G_SetOrigin( ent, ent->s.origin );
VectorCopy( ent->s.angles, ent->s.apos.trBase );
#else
G_FreeEntity( ent );
#endif
}
//===========================================================
void locateCamera( gentity_t *ent ) {
vec3_t dir;
gentity_t *target;
gentity_t *owner;
owner = G_PickTarget( ent->target );
if ( !owner ) {
trap->Print( "Couldn't find target for misc_partal_surface\n" );
G_FreeEntity( ent );
return;
}
ent->r.ownerNum = owner->s.number;
// frame holds the rotate speed
if ( owner->spawnflags & 1 ) {
ent->s.frame = 25;
} else if ( owner->spawnflags & 2 ) {
ent->s.frame = 75;
}
// swing camera ?
if ( owner->spawnflags & 4 ) {
// set to 0 for no rotation at all
ent->s.powerups = 0;
}
else {
ent->s.powerups = 1;
}
// clientNum holds the rotate offset
ent->s.clientNum = owner->s.clientNum;
VectorCopy( owner->s.origin, ent->s.origin2 );
// see if the portal_camera has a target
target = G_PickTarget( owner->target );
if ( target ) {
VectorSubtract( target->s.origin, owner->s.origin, dir );
VectorNormalize( dir );
} else {
G_SetMovedir( owner->s.angles, dir );
}
ent->s.eventParm = DirToByte( dir );
}
/*QUAKED misc_portal_surface (0 0 1) (-8 -8 -8) (8 8 8)
The portal surface nearest this entity will show a view from the targeted misc_portal_camera, or a mirror view if untargeted.
This must be within 64 world units of the surface!
*/
void SP_misc_portal_surface(gentity_t *ent) {
VectorClear( ent->r.mins );
VectorClear( ent->r.maxs );
trap->LinkEntity ((sharedEntity_t *)ent);
ent->r.svFlags = SVF_PORTAL;
ent->s.eType = ET_PORTAL;
if ( !ent->target ) {
VectorCopy( ent->s.origin, ent->s.origin2 );
} else {
ent->think = locateCamera;
ent->nextthink = level.time + 100;
}
}
/*QUAKED misc_portal_camera (0 0 1) (-8 -8 -8) (8 8 8) slowrotate fastrotate noswing
The target for a misc_portal_director. You can set either angles or target another entity to determine the direction of view.
"roll" an angle modifier to orient the camera around the target vector;
*/
void SP_misc_portal_camera(gentity_t *ent) {
float roll;
VectorClear( ent->r.mins );
VectorClear( ent->r.maxs );
trap->LinkEntity ((sharedEntity_t *)ent);
G_SpawnFloat( "roll", "0", &roll );
ent->s.clientNum = roll/360.0 * 256;
}
/*QUAKED misc_bsp (1 0 0) (-16 -16 -16) (16 16 16)
"bspmodel" arbitrary .bsp file to display
*/
void SP_misc_bsp(gentity_t *ent)
{
char temp[MAX_QPATH];
char *out;
float newAngle;
int tempint;
G_SpawnFloat( "angle", "0", &newAngle );
if (newAngle != 0.0)
{
ent->s.angles[1] = newAngle;
}
// don't support rotation any other way
ent->s.angles[0] = 0.0;
ent->s.angles[2] = 0.0;
G_SpawnString("bspmodel", "", &out);
ent->s.eFlags = EF_PERMANENT;
// Mainly for debugging
G_SpawnInt( "spacing", "0", &tempint);
ent->s.time2 = tempint;
G_SpawnInt( "flatten", "0", &tempint);
ent->s.time = tempint;
Com_sprintf(temp, MAX_QPATH, "#%s", out);
trap->SetBrushModel( (sharedEntity_t *)ent, temp ); // SV_SetBrushModel -- sets mins and maxs
G_BSPIndex(temp);
level.mNumBSPInstances++;
Com_sprintf(temp, MAX_QPATH, "%d-", level.mNumBSPInstances);
VectorCopy(ent->s.origin, level.mOriginAdjust);
level.mRotationAdjust = ent->s.angles[1];
level.mTargetAdjust = temp;
//level.hasBspInstances = qtrue; //rww - also not referenced anywhere.
level.mBSPInstanceDepth++;
/*
G_SpawnString("filter", "", &out);
strcpy(level.mFilter, out);
*/
G_SpawnString("teamfilter", "", &out);
strcpy(level.mTeamFilter, out);
VectorCopy( ent->s.origin, ent->s.pos.trBase );
VectorCopy( ent->s.origin, ent->r.currentOrigin );
VectorCopy( ent->s.angles, ent->s.apos.trBase );
VectorCopy( ent->s.angles, ent->r.currentAngles );
ent->s.eType = ET_MOVER;
trap->LinkEntity ((sharedEntity_t *)ent);
trap->SetActiveSubBSP(ent->s.modelindex);
G_SpawnEntitiesFromString(qtrue);
trap->SetActiveSubBSP(-1);
level.mBSPInstanceDepth--;
//level.mFilter[0] = level.mTeamFilter[0] = 0;
level.mTeamFilter[0] = 0;
/*
if ( g_debugRMG.integer )
{
G_SpawnDebugCylinder ( ent->s.origin, ent->s.time2, &g_entities[0], 2000, COLOR_WHITE );
if ( ent->s.time )
{
G_SpawnDebugCylinder ( ent->s.origin, ent->s.time, &g_entities[0], 2000, COLOR_RED );
}
}
*/
}
/*QUAKED terrain (1.0 1.0 1.0) ? NOVEHDMG
NOVEHDMG - don't damage vehicles upon impact with this terrain
Terrain entity
It will stretch to the full height of the brush
numPatches - integer number of patches to split the terrain brush into (default 200)
terxels - integer number of terxels on a patch side (default 4) (2 <= count <= 8)
seed - integer seed for random terrain generation (default 0)
textureScale - float scale of texture (default 0.005)
heightmap - name of heightmap data image to use, located in heightmaps/*.png. (must be PNG format)
terrainDef - defines how the game textures the terrain (file is base/ext_data/rmg/*.terrain - default is grassyhills)
instanceDef - defines which bsp instances appear
miscentDef - defines which client models spawn on the terrain (file is base/ext_data/rmg/*.miscents)
densityMap - how dense the client models are packed
*/
void AddSpawnField(char *field, char *value);
#define MAX_INSTANCE_TYPES 16
void SP_terrain(gentity_t *ent)
{
G_FreeEntity (ent);
}
//rww - Called by skyportal entities. This will check through entities and flag them
//as portal ents if they are in the same pvs as a skyportal entity and pass
//a direct point trace check between origins. I really wanted to use an eFlag for
//flagging portal entities, but too many entities like to reset their eFlags.
//Note that this was not part of the original wolf sky portal stuff.
void G_PortalifyEntities(gentity_t *ent)
{
int i = 0;
gentity_t *scan = NULL;
while (i < MAX_GENTITIES)
{
scan = &g_entities[i];
if (scan && scan->inuse && scan->s.number != ent->s.number && trap->InPVS(ent->s.origin, scan->r.currentOrigin))
{
trace_t tr;
trap->Trace(&tr, ent->s.origin, vec3_origin, vec3_origin, scan->r.currentOrigin, ent->s.number, CONTENTS_SOLID, qfalse, 0, 0);
if (tr.fraction == 1.0 || (tr.entityNum == scan->s.number && tr.entityNum != ENTITYNUM_NONE && tr.entityNum != ENTITYNUM_WORLD))
{
if (!scan->client || scan->s.eType == ET_NPC)
{ //making a client a portal entity would be bad.
scan->s.isPortalEnt = qtrue; //he's flagged now
}
}
}
i++;
}
ent->think = G_FreeEntity; //the portal entity is no longer needed because its information is stored in a config string.
ent->nextthink = level.time;
}
/*QUAKED misc_skyportal_orient (.6 .7 .7) (-8 -8 0) (8 8 16)
point from which to orient the sky portal cam in relation
to the regular view position.
"modelscale" the scale at which to scale positions
*/
void SP_misc_skyportal_orient (gentity_t *ent)
{
G_FreeEntity(ent);
}
/*QUAKED misc_skyportal (.6 .7 .7) (-8 -8 0) (8 8 16)
"fov" for the skybox default is 80
To have the portal sky fogged, enter any of the following values:
"onlyfoghere" if non-0 allows you to set a global fog, but will only use that fog within this sky portal.
Also note that entities in the same PVS and visible (via point trace) from this
object will be flagged as portal entities. This means they will be sent and
updated from the server for every client every update regardless of where
they are, and they will essentially be added to the scene twice if the client
is in the same PVS as them (only once otherwise, but still once no matter
where the client is). In other words, don't go overboard with it or everything
will explode.
*/
void SP_misc_skyportal (gentity_t *ent)
{
char *fov;
vec3_t fogv; //----(SA)
int fogn; //----(SA)
int fogf; //----(SA)
int isfog = 0; // (SA)
float fov_x;
G_SpawnString ("fov", "80", &fov);
fov_x = atof (fov);
isfog += G_SpawnVector ("fogcolor", "0 0 0", fogv);
isfog += G_SpawnInt ("fognear", "0", &fogn);
isfog += G_SpawnInt ("fogfar", "300", &fogf);
trap->SetConfigstring( CS_SKYBOXORG, va("%.2f %.2f %.2f %.1f %i %.2f %.2f %.2f %i %i", ent->s.origin[0], ent->s.origin[1], ent->s.origin[2], fov_x, (int)isfog, fogv[0], fogv[1], fogv[2], fogn, fogf ) );
ent->think = G_PortalifyEntities;
ent->nextthink = level.time + 1050; //give it some time first so that all other entities are spawned.
}
/*QUAKED misc_holocron (0 0 1) (-8 -8 -8) (8 8 8)
count Set to type of holocron (based on force power value)
HEAL = 0
JUMP = 1
SPEED = 2
PUSH = 3
PULL = 4
TELEPATHY = 5
GRIP = 6
LIGHTNING = 7
RAGE = 8
PROTECT = 9
ABSORB = 10
TEAM HEAL = 11
TEAM FORCE = 12
DRAIN = 13
SEE = 14
SABERATTACK = 15
SABERDEFEND = 16
SABERTHROW = 17
*/
/*char *holocronTypeModels[] = {
"models/chunks/rock/rock_big.md3",//FP_HEAL,
"models/chunks/rock/rock_big.md3",//FP_LEVITATION,
"models/chunks/rock/rock_big.md3",//FP_SPEED,
"models/chunks/rock/rock_big.md3",//FP_PUSH,
"models/chunks/rock/rock_big.md3",//FP_PULL,
"models/chunks/rock/rock_big.md3",//FP_TELEPATHY,
"models/chunks/rock/rock_big.md3",//FP_GRIP,
"models/chunks/rock/rock_big.md3",//FP_LIGHTNING,
"models/chunks/rock/rock_big.md3",//FP_RAGE,
"models/chunks/rock/rock_big.md3",//FP_PROTECT,
"models/chunks/rock/rock_big.md3",//FP_ABSORB,
"models/chunks/rock/rock_big.md3",//FP_TEAM_HEAL,
"models/chunks/rock/rock_big.md3",//FP_TEAM_FORCE,
"models/chunks/rock/rock_big.md3",//FP_DRAIN,
"models/chunks/rock/rock_big.md3",//FP_SEE
"models/chunks/rock/rock_big.md3",//FP_SABER_OFFENSE
"models/chunks/rock/rock_big.md3",//FP_SABER_DEFENSE
"models/chunks/rock/rock_big.md3"//FP_SABERTHROW
};*/
void HolocronRespawn(gentity_t *self)
{
self->s.modelindex = (self->count - 128);
}
void HolocronPopOut(gentity_t *self)
{
if (Q_irand(1, 10) < 5)
{
self->s.pos.trDelta[0] = 150 + Q_irand(1, 100);
}
else
{
self->s.pos.trDelta[0] = -150 - Q_irand(1, 100);
}
if (Q_irand(1, 10) < 5)
{
self->s.pos.trDelta[1] = 150 + Q_irand(1, 100);
}
else
{
self->s.pos.trDelta[1] = -150 - Q_irand(1, 100);
}
self->s.pos.trDelta[2] = 150 + Q_irand(1, 100);
}
void HolocronTouch(gentity_t *self, gentity_t *other, trace_t *trace)
{
int i = 0;
int othercarrying = 0;
float time_lowest = 0;
int index_lowest = -1;
int hasall = 1;
int forceReselect = WP_NONE;
if (trace)
{
self->s.groundEntityNum = trace->entityNum;
}
if (!other || !other->client || other->health < 1)
{
return;
}
if (!self->s.modelindex)
{
return;
}
if (self->enemy)
{
return;
}
if (other->client->ps.holocronsCarried[self->count])
{
return;
}
if (other->client->ps.holocronCantTouch == self->s.number && other->client->ps.holocronCantTouchTime > level.time)
{
return;
}
while (i < NUM_FORCE_POWERS)
{
if (other->client->ps.holocronsCarried[i])
{
othercarrying++;
if (index_lowest == -1 || other->client->ps.holocronsCarried[i] < time_lowest)
{
index_lowest = i;
time_lowest = other->client->ps.holocronsCarried[i];
}
}
else if (i != self->count)
{
hasall = 0;
}
i++;
}
if (hasall)
{ //once we pick up this holocron we'll have all of them, so give us super special best prize!
//trap->Print("You deserve a pat on the back.\n");
}
if (!(other->client->ps.fd.forcePowersActive & (1 << other->client->ps.fd.forcePowerSelected)))
{ //If the player isn't using his currently selected force power, select this one
if (self->count != FP_SABER_OFFENSE && self->count != FP_SABER_DEFENSE && self->count != FP_SABERTHROW && self->count != FP_LEVITATION)
{
other->client->ps.fd.forcePowerSelected = self->count;
}
}
if (g_maxHolocronCarry.integer && othercarrying >= g_maxHolocronCarry.integer)
{ //make the oldest holocron carried by the player pop out to make room for this one
other->client->ps.holocronsCarried[index_lowest] = 0;
/*
if (index_lowest == FP_SABER_OFFENSE && !HasSetSaberOnly())
{ //you lost your saberattack holocron, so no more saber for you
other->client->ps.stats[STAT_WEAPONS] |= (1 << WP_STUN_BATON);
other->client->ps.stats[STAT_WEAPONS] &= ~(1 << WP_SABER);
if (other->client->ps.weapon == WP_SABER)
{
forceReselect = WP_SABER;
}
}
*/
//NOTE: No longer valid as we are now always giving a force level 1 saber attack level in holocron
}
//G_Sound(other, CHAN_AUTO, G_SoundIndex("sound/weapons/w_pkup.wav"));
G_AddEvent( other, EV_ITEM_PICKUP, self->s.number );
other->client->ps.holocronsCarried[self->count] = level.time;
self->s.modelindex = 0;
self->enemy = other;
self->pos2[0] = 1;
self->pos2[1] = level.time + HOLOCRON_RESPAWN_TIME;
/*
if (self->count == FP_SABER_OFFENSE && !HasSetSaberOnly())
{ //player gets a saber
other->client->ps.stats[STAT_WEAPONS] |= (1 << WP_SABER);
other->client->ps.stats[STAT_WEAPONS] &= ~(1 << WP_STUN_BATON);
if (other->client->ps.weapon == WP_STUN_BATON)
{
forceReselect = WP_STUN_BATON;
}
}
*/
if (forceReselect != WP_NONE)
{
G_AddEvent(other, EV_NOAMMO, forceReselect);
}
//trap->Print("DON'T TOUCH ME\n");
}
void HolocronThink(gentity_t *ent)
{
if (ent->pos2[0] && (!ent->enemy || !ent->enemy->client || ent->enemy->health < 1))
{
if (ent->enemy && ent->enemy->client)
{
HolocronRespawn(ent);
VectorCopy(ent->enemy->client->ps.origin, ent->s.pos.trBase);
VectorCopy(ent->enemy->client->ps.origin, ent->s.origin);
VectorCopy(ent->enemy->client->ps.origin, ent->r.currentOrigin);
//copy to person carrying's origin before popping out of them
HolocronPopOut(ent);
ent->enemy->client->ps.holocronsCarried[ent->count] = 0;
ent->enemy = NULL;
goto justthink;
}
}
else if (ent->pos2[0] && ent->enemy && ent->enemy->client)
{
ent->pos2[1] = level.time + HOLOCRON_RESPAWN_TIME;
}
if (ent->enemy && ent->enemy->client)
{
if (!ent->enemy->client->ps.holocronsCarried[ent->count])
{
ent->enemy->client->ps.holocronCantTouch = ent->s.number;
ent->enemy->client->ps.holocronCantTouchTime = level.time + 5000;
HolocronRespawn(ent);
VectorCopy(ent->enemy->client->ps.origin, ent->s.pos.trBase);
VectorCopy(ent->enemy->client->ps.origin, ent->s.origin);
VectorCopy(ent->enemy->client->ps.origin, ent->r.currentOrigin);
//copy to person carrying's origin before popping out of them
HolocronPopOut(ent);
ent->enemy = NULL;
goto justthink;
}
if (!ent->enemy->inuse || (ent->enemy->client && ent->enemy->client->ps.fallingToDeath))
{