-
Notifications
You must be signed in to change notification settings - Fork 148
/
g_misc.cpp
3297 lines (2727 loc) · 94.8 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
// g_misc.c
// leave this line at the top for all g_xxxx.cpp files...
#include "g_headers.h"
#include "g_local.h"
#include "g_functions.h"
#include "g_nav.h"
#include "g_items.h"
extern gentity_t *G_FindDoorTrigger( gentity_t *door );
extern void G_SetEnemy( gentity_t *self, gentity_t *enemy );
extern void SetMiscModelDefaults( gentity_t *ent, useFunc_t use_func, char *material, int solid_mask,int animFlag,
qboolean take_damage, qboolean damage_model);
#define MAX_AMMO_GIVE 4
/*QUAKED func_group (0 0 0) ?
Used to group brushes together just for editor convenience. They are turned into normal brushes by the utilities.
q3map_onlyvertexlighting 1 = brush only gets vertex lighting (reduces bsp size!)
*/
/*QUAKED info_null (0 0.5 0) (-4 -4 -4) (4 4 4) LIGHT
Used as a positional target for calculations in the utilities (spotlights, etc), but removed during gameplay.
LIGHT - If this info_null is only targeted by a non-switchable light (a light without a targetname), it does NOT spawn in at all and doesn't count towards the # of entities on the map, even at map spawn/load
*/
void SP_info_null( gentity_t *self ) {
if ( (self->spawnflags&1) )
{//only used as a light target, so bugger off
G_FreeEntity( self );
return;
}
//FIXME: store targetname and vector (origin) in a list for further reference... remove after 1st second of game?
G_SetOrigin( self, self->s.origin );
self->e_ThinkFunc = thinkF_G_FreeEntity;
//Give other ents time to link
self->nextthink = level.time + START_TIME_REMOVE_ENTS;
}
/*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 ){
//FIXME: store in ref_tag system?
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->misc_dlight_active)
{ //turn off
if (mLightOffStyle) //i have a light style i'd like to use when off
{
char lightstyle[32];
gi.GetConfigstring(CS_LIGHT_STYLES + (mLightOffStyle*3)+0, lightstyle, 32);
gi.SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+0, lightstyle);
gi.GetConfigstring(CS_LIGHT_STYLES + (mLightOffStyle*3)+1, lightstyle, 32);
gi.SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+1, lightstyle);
gi.GetConfigstring(CS_LIGHT_STYLES + (mLightOffStyle*3)+2, lightstyle, 32);
gi.SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+2, lightstyle);
}else
{
gi.SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+0, "a");
gi.SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+1, "a");
gi.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];
gi.GetConfigstring(CS_LIGHT_STYLES + (mLightSwitchStyle*3)+0, lightstyle, 32);
gi.SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+0, lightstyle);
gi.GetConfigstring(CS_LIGHT_STYLES + (mLightSwitchStyle*3)+1, lightstyle, 32);
gi.SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+1, lightstyle);
gi.GetConfigstring(CS_LIGHT_STYLES + (mLightSwitchStyle*3)+2, lightstyle, 32);
gi.SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+2, lightstyle);
}
else
{
gi.SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+0, "z");
gi.SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+1, "z");
gi.SetConfigstring(CS_LIGHT_STYLES + (mLightStyle*3)+2, "z");
}
}
}
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 );
gi.linkentity( self );
self->e_UseFunc = useF_misc_dlight_use;
self->e_clThinkFunc = clThinkF_NULL;
self->s.eType = ET_GENERAL;
self->misc_dlight_active = qfalse;
self->svFlags |= SVF_NOCLIENT;
if ( !(self->spawnflags & 4) )
{ //turn myself on now
self->misc_dlight_active = qtrue;
}
misc_lightstyle_set (self);
}
void misc_dlight_use ( gentity_t *ent, gentity_t *other, gentity_t *activator )
{
G_ActivateBehavior(ent,BSET_USE);
ent->misc_dlight_active = !ent->misc_dlight_active; //toggle
misc_lightstyle_set (ent);
}
/*
=================================================================================
TELEPORTERS
=================================================================================
*/
void TeleportPlayer( gentity_t *player, vec3_t origin, vec3_t angles )
{
if ( player->NPC && ( player->NPC->aiFlags&NPCAI_FORM_TELE_NAV ) )
{
//My leader teleported, I was trying to catch up, take this off
player->NPC->aiFlags &= ~NPCAI_FORM_TELE_NAV;
}
// unlink to make sure it can't possibly interfere with G_KillBox
gi.unlinkentity (player);
VectorCopy ( origin, player->client->ps.origin );
player->client->ps.origin[2] += 1;
VectorCopy ( player->client->ps.origin, player->currentOrigin );
// spit the player out
AngleVectors( angles, player->client->ps.velocity, NULL, NULL );
VectorScale( player->client->ps.velocity, 0, player->client->ps.velocity );
//player->client->ps.pm_time = 160; // hold time
//player->client->ps.pm_flags |= PMF_TIME_KNOCKBACK;
// toggle the teleport bit so the client knows to not lerp
player->client->ps.eFlags ^= EF_TELEPORT_BIT;
// set angles
SetClientViewAngle( player, angles );
// kill anything at the destination
G_KillBox (player);
// save results of pmove
PlayerStateToEntityState( &player->client->ps, &player->s );
gi.linkentity (player);
}
void TeleportMover( gentity_t *mover, vec3_t origin, vec3_t diffAngles, qboolean snapAngle )
{//FIXME: need an effect
vec3_t oldAngle, newAngle;
float speed;
// unlink to make sure it can't possibly interfere with G_KillBox
gi.unlinkentity (mover);
//reposition it
VectorCopy( origin, mover->s.pos.trBase );
VectorCopy( origin, mover->currentOrigin );
//Maintain their previous speed, but adjusted for new direction
if ( snapAngle )
{//not a diffAngle, actually an absolute angle
vec3_t dir;
VectorCopy( diffAngles, newAngle );
AngleVectors( newAngle, dir, NULL, NULL );
VectorNormalize( dir );//necessary?
speed = VectorLength( mover->s.pos.trDelta );
VectorScale( dir, speed, mover->s.pos.trDelta );
mover->s.pos.trTime = level.time;
VectorSubtract( newAngle, mover->s.apos.trBase, diffAngles );
VectorCopy( newAngle, mover->s.apos.trBase );
}
else
{
speed = VectorNormalize( mover->s.pos.trDelta );
vectoangles( mover->s.pos.trDelta, oldAngle );
VectorAdd( oldAngle, diffAngles, newAngle );
AngleVectors( newAngle, mover->s.pos.trDelta, NULL, NULL );
VectorNormalize( mover->s.pos.trDelta );
VectorScale( mover->s.pos.trDelta, speed, mover->s.pos.trDelta );
mover->s.pos.trTime = level.time;
//Maintain their previous angles, but adjusted to new orientation
VectorAdd( mover->s.apos.trBase, diffAngles, mover->s.apos.trBase );
}
//Maintain their previous anglespeed, but adjusted to new orientation
speed = VectorNormalize( mover->s.apos.trDelta );
VectorAdd( mover->s.apos.trDelta, diffAngles, mover->s.apos.trDelta );
VectorNormalize( mover->s.apos.trDelta );
VectorScale( mover->s.apos.trDelta, speed, mover->s.apos.trDelta );
mover->s.apos.trTime = level.time;
//Tell them it was teleported this move
mover->s.eFlags |= EF_TELEPORT_BIT;
// kill anything at the destination
//G_KillBox (mover);
//FIXME: call touch func instead of killbox?
gi.linkentity (mover);
}
void teleporter_touch (gentity_t *self, gentity_t *other, trace_t *trace)
{
gentity_t *dest;
if (!other->client)
return;
dest = G_PickTarget( self->target );
if (!dest) {
gi.Printf ("Couldn't find teleporter destination\n");
return;
}
TeleportPlayer( other, dest->s.origin, dest->s.angles );
}
/*QUAK-D misc_teleporter (1 0 0) (-32 -32 -24) (32 32 -16)
Stepping onto this disc will teleport players to the targeted misc_teleporter_dest object.
*/
void SP_misc_teleporter (gentity_t *ent)
{
gentity_t *trig;
if (!ent->target)
{
gi.Printf ("teleporter without a target.\n");
G_FreeEntity( ent );
return;
}
ent->s.modelindex = G_ModelIndex( "models/objects/dmspot.md3" );
ent->s.clientNum = 1;
// ent->s.loopSound = G_SoundIndex("sound/world/amb10.wav");
ent->contents = CONTENTS_SOLID;
G_SetOrigin( ent, ent->s.origin );
VectorSet (ent->mins, -32, -32, -24);
VectorSet (ent->maxs, 32, 32, -16);
gi.linkentity (ent);
trig = G_Spawn ();
trig->e_TouchFunc = touchF_teleporter_touch;
trig->contents = CONTENTS_TRIGGER;
trig->target = ent->target;
trig->owner = ent;
G_SetOrigin( trig, ent->s.origin );
VectorSet (trig->mins, -8, -8, 8);
VectorSet (trig->maxs, 8, 8, 24);
gi.linkentity (trig);
}
/*QUAK-D misc_teleporter_dest (1 0 0) (-32 -32 -24) (32 32 -16) - - NODRAW
Point teleporters at these.
*/
void SP_misc_teleporter_dest( gentity_t *ent ) {
if ( ent->spawnflags & 4 ){
return;
}
G_SetOrigin( ent, ent->s.origin );
gi.linkentity (ent);
}
//===========================================================
/*QUAKED misc_model (1 0 0) (-16 -16 -16) (16 16 16) RMG SOLID
"model" arbitrary .md3 or .ase file to display
"_frame" "x" which frame from an animated md3
"modelscale" "x" uniform scale
"modelscale_vec" "x y z" scale model in each axis
"_remap" "from to" remap a shader in this model
turns into BSP triangles - not solid by default (click SOLID or use _clipmodel shader)
*/
void SP_misc_model( gentity_t *ent ) {
G_FreeEntity( ent );
}
/*QUAKED misc_model_static (1 0 0) (-16 -16 0) (16 16 16)
"model" arbitrary .md3 file to display
"_frame" "x" which frame from an animated md3
"modelscale" "x" uniform scale
"modelscale_vec" "x y z" scale model in each axis
"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.
loaded as a model in the renderer - does not take up precious bsp space!
*/
extern void CG_CreateMiscEntFromGent(gentity_t *ent, const vec3_t scale, float zOff); //cg_main.cpp
void SP_misc_model_static(gentity_t *ent)
{
char *value;
float temp;
float zOff;
vec3_t scale;
G_SpawnString("modelscale_vec", "1 1 1", &value);
sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] );
G_SpawnFloat( "modelscale", "0", &temp);
if (temp != 0.0f)
{
scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = temp;
}
G_SpawnFloat( "zoffset", "0", &zOff);
if (!ent->model)
{
Com_Error( ERR_DROP,"misc_model_static at %s with out a MODEL!\n", vtos(ent->s.origin) );
}
//we can be horrible and cheat since this is SP!
CG_CreateMiscEntFromGent(ent, scale, zOff);
G_FreeEntity( ent );
}
//===========================================================
void setCamera ( gentity_t *ent )
{
vec3_t dir;
gentity_t *target = 0;
// frame holds the rotate speed
if ( ent->owner->spawnflags & 1 )
{
ent->s.frame = 25;
}
else if ( ent->owner->spawnflags & 2 )
{
ent->s.frame = 75;
}
// clientNum holds the rotate offset
ent->s.clientNum = ent->owner->s.clientNum;
VectorCopy( ent->owner->s.origin, ent->s.origin2 );
// see if the portal_camera has a target
if (ent->owner->target) {
target = G_PickTarget( ent->owner->target );
}
if ( target )
{
VectorSubtract( target->s.origin, ent->owner->s.origin, dir );
VectorNormalize( dir );
}
else
{
G_SetMovedir( ent->owner->s.angles, dir );
}
ent->s.eventParm = DirToByte( dir );
}
void cycleCamera( gentity_t *self )
{
self->owner = G_Find( self->owner, FOFS(targetname), self->target );
if ( self->owner == NULL )
{
//Uh oh! Not targeted at any ents! Or reached end of list? Which is it?
//for now assume reached end of list and are cycling
self->owner = G_Find( self->owner, FOFS(targetname), self->target );
if ( self->owner == NULL )
{//still didn't find one
gi.Printf( "Couldn't find target for misc_portal_surface\n" );
G_FreeEntity( self );
return;
}
}
setCamera( self );
if ( self->e_ThinkFunc == thinkF_cycleCamera )
{
if ( self->owner->wait > 0 )
{
self->nextthink = level.time + self->owner->wait;
}
else
{
self->nextthink = level.time + self->wait;
}
}
}
void misc_portal_use( gentity_t *self, gentity_t *other, gentity_t *activator )
{
cycleCamera( self );
}
void locateCamera( gentity_t *ent )
{//FIXME: make this fadeout with distance from misc_camera_portal
ent->owner = G_Find(NULL, FOFS(targetname), ent->target);
if ( !ent->owner )
{
gi.Printf( "Couldn't find target for misc_portal_surface\n" );
G_FreeEntity( ent );
return;
}
setCamera( ent );
if ( !ent->targetname )
{//not targetted, so auto-cycle
if ( G_Find(ent->owner, FOFS(targetname), ent->target) != NULL )
{//targeted at more than one thing
ent->e_ThinkFunc = thinkF_cycleCamera;
if ( ent->owner->wait > 0 )
{
ent->nextthink = level.time + ent->owner->wait;
}
else
{
ent->nextthink = level.time + ent->wait;
}
}
}
}
/*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!
targetname - When used, cycles to the next misc_portal_camera it's targeted
wait - makes it auto-cycle between all cameras it's pointed at at intevervals of specified number of seconds.
cameras will be cycled through in the order they were created on the map.
*/
void SP_misc_portal_surface(gentity_t *ent)
{
VectorClear( ent->mins );
VectorClear( ent->maxs );
gi.linkentity (ent);
ent->svFlags = SVF_PORTAL;
ent->s.eType = ET_PORTAL;
ent->wait *= 1000;
if ( !ent->target )
{//mirror?
VectorCopy( ent->s.origin, ent->s.origin2 );
}
else
{
ent->e_ThinkFunc = thinkF_locateCamera;
ent->nextthink = level.time + 100;
if ( ent->targetname )
{
ent->e_UseFunc = useF_misc_portal_use;
}
}
}
/*QUAKED misc_portal_camera (0 0 1) (-8 -8 -8) (8 8 8) slowrotate fastrotate
The target for a misc_portal_surface. You can set either angles or target another entity (NOT an info_null) 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->mins );
VectorClear( ent->maxs );
gi.linkentity (ent);
G_SpawnFloat( "roll", "0", &roll );
ent->s.clientNum = roll/360.0 * 256;
ent->wait *= 1000;
}
void G_SubBSPSpawnEntitiesFromString(const char *entityString, vec3_t posOffset, vec3_t angOffset);
/*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);
gi.SetBrushModel( 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;
level.mBSPInstanceDepth++;
VectorCopy( ent->s.origin, ent->s.pos.trBase );
VectorCopy( ent->s.origin, ent->currentOrigin );
VectorCopy( ent->s.angles, ent->s.apos.trBase );
VectorCopy( ent->s.angles, ent->currentAngles );
ent->s.eType = ET_MOVER;
gi.linkentity (ent);
const char *ents = gi.SetActiveSubBSP(ent->s.modelindex);
if (ents)
{
G_SubBSPSpawnEntitiesFromString(ents, ent->s.origin, ent->s.angles);
}
gi.SetActiveSubBSP(-1);
level.mBSPInstanceDepth--;
}
#define MAX_INSTANCE_TYPES 16
void AddSpawnField(char *field, char *value);
/*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 SP_terrain(gentity_t *ent)
{
#ifdef _XBOX
assert(0);
#else
char temp[MAX_INFO_STRING];
char final[MAX_QPATH];
// char seed[MAX_QPATH];
// char missionType[MAX_QPATH];
// char soundSet[MAX_QPATH];
int shaderNum, i;
char *value;
int terrainID;
//k, found a terrain, just set rmg to 1.
//This should always get set before RE_LoadWorldMap and all that is
//called which is all that matters.
//gi.cvar_set("RMG", "1");
VectorClear (ent->s.angles);
gi.SetBrushModel( ent, ent->model );
// Get the shader from the top of the brush
// shaderNum = gi.CM_GetShaderNum(s.modelindex);
shaderNum = 0;
//rww - Why not do this all the time? Not like terrain entities are used when you don't want them to be terrain.
/* if (g_RMG->integer)
{
gi.Cvar_VariableStringBuffer("RMG_seed", seed, MAX_QPATH);
gi.Cvar_VariableStringBuffer("RMG_mission", missionType, MAX_QPATH);
// gi.Cvar_VariableStringBuffer("RMG_soundset", soundSet, MAX_QPATH);
// gi.SetConfigstring(CS_AMBIENT_SOUNDSETS, soundSet );
}
*/
// Arbitrary (but sane) limits to the number of terxels
// if((mTerxels < MIN_TERXELS) || (mTerxels > MAX_TERXELS))
{
// Com_printf("G_Terrain: terxels out of range - defaulting to 4\n");
// mTerxels = 4;
}
// Get info required for the common init
temp[0] = 0;
G_SpawnString("heightmap", "", &value);
Info_SetValueForKey(temp, "heightMap", value);
G_SpawnString("numpatches", "400", &value);
Info_SetValueForKey(temp, "numPatches", va("%d", atoi(value)));
G_SpawnString("terxels", "4", &value);
Info_SetValueForKey(temp, "terxels", va("%d", atoi(value)));
//Info_SetValueForKey(temp, "seed", seed);
Info_SetValueForKey(temp, "minx", va("%f", ent->mins[0]));
Info_SetValueForKey(temp, "miny", va("%f", ent->mins[1]));
Info_SetValueForKey(temp, "minz", va("%f", ent->mins[2]));
Info_SetValueForKey(temp, "maxx", va("%f", ent->maxs[0]));
Info_SetValueForKey(temp, "maxy", va("%f", ent->maxs[1]));
Info_SetValueForKey(temp, "maxz", va("%f", ent->maxs[2]));
Info_SetValueForKey(temp, "modelIndex", va("%d", ent->s.modelindex));
G_SpawnString("terraindef", "grassyhills", &value);
Info_SetValueForKey(temp, "terrainDef", value);
G_SpawnString("instancedef", "", &value);
Info_SetValueForKey(temp, "instanceDef", value);
G_SpawnString("miscentdef", "", &value);
Info_SetValueForKey(temp, "miscentDef", value);
//Info_SetValueForKey(temp, "missionType", missionType);
for(i = 0; i < MAX_INSTANCE_TYPES; i++)
{
gi.Cvar_VariableStringBuffer(va("RMG_instance%d", i), final, MAX_QPATH);
if(strlen(final))
{
Info_SetValueForKey(temp, va("inst%d", i), final);
}
}
// Set additional data required on the client only
G_SpawnString("densitymap", "", &value);
Info_SetValueForKey(temp, "densityMap", value);
Info_SetValueForKey(temp, "shader", va("%d", shaderNum));
G_SpawnString("texturescale", "0.005", &value);
Info_SetValueForKey(temp, "texturescale", va("%f", atof(value)));
// Initialise the common aspects of the terrain
terrainID = gi.CM_RegisterTerrain(temp);
// SetCommon(common);
Info_SetValueForKey(temp, "terrainId", va("%d", terrainID));
// Let the entity know if it is random generated or not
// SetIsRandom(common->GetIsRandom());
// Let the game remember everything
// level.landScapes[terrainID] = ent;
//rww - I'm not doing this. Because it didn't even appear to be used. Is it?
// Send all the data down to the client
gi.SetConfigstring(CS_TERRAINS + terrainID, temp);
// Make sure the contents are properly set
ent->contents = CONTENTS_TERRAIN;
ent->svFlags = SVF_NOCLIENT;
ent->s.eFlags = EF_PERMANENT;
ent->s.eType = ET_TERRAIN;
// Hook into the world so physics will work
gi.linkentity(ent);
// If running RMG then initialize the terrain and handle team skins
//rww - Why not do this all the time? Not like terrain entities are used when you don't want them to be terrain.
/* not using RMG
if ( g_RMG->integer )
{
gi.RMG_Init(terrainID);
}
*/
#endif // _XBOX
}
//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 && gi.inPVS(ent->s.origin, scan->currentOrigin))
{
trace_t tr;
gi.trace(&tr, ent->s.origin, vec3_origin, vec3_origin, scan->currentOrigin, ent->s.number, CONTENTS_SOLID, G2_NOCOLLIDE, 0);
if (tr.fraction == 1.0 || (tr.entityNum == scan->s.number && tr.entityNum != ENTITYNUM_NONE && tr.entityNum != ENTITYNUM_WORLD))
{
scan->s.isPortalEnt = qtrue; //he's flagged now
}
}
i++;
}
ent->e_ThinkFunc = thinkF_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 (.6 .7 .7) (-8 -8 0) (8 8 16)
To have the portal sky fogged, enter any of the following values:
"fogcolor" (r g b) (values 0.0-1.0)
"fognear" distance from entity to start fogging
"fogfar" distance from entity that fog is opaque
rww - NOTE: fog doesn't work with these currently (at least not in this way).
Use a fog brush instead.
*/
void SP_misc_skyportal (gentity_t *ent)
{
vec3_t fogv; //----(SA)
int fogn; //----(SA)
int fogf; //----(SA)
int isfog = 0; // (SA)
isfog += G_SpawnVector ("fogcolor", "0 0 0", fogv);
isfog += G_SpawnInt ("fognear", "0", &fogn);
isfog += G_SpawnInt ("fogfar", "300", &fogf);
gi.SetConfigstring( CS_SKYBOXORG, va("%.2f %.2f %.2f %i %.2f %.2f %.2f %i %i", ent->s.origin[0], ent->s.origin[1], ent->s.origin[2], isfog, fogv[0], fogv[1], fogv[2], fogn, fogf ) );
ent->e_ThinkFunc = thinkF_G_PortalifyEntities;
ent->nextthink = level.time + 1050; //give it some time first so that all other entities are spawned.
}
extern qboolean G_ClearViewEntity( gentity_t *ent );
extern void G_SetViewEntity( gentity_t *self, gentity_t *viewEntity );
extern void SP_fx_runner( gentity_t *ent );
void camera_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int mod,int dFlags,int hitLoc )
{
if ( player && player->client && player->client->ps.viewEntity == self->s.number )
{
G_UseTargets2( self, player, self->target4 );
G_ClearViewEntity( player );
G_Sound( player, self->soundPos2 );
}
G_UseTargets2( self, player, self->closetarget );
//FIXME: explosion fx/sound
//leave sparks at origin- where base's pole is still at?
gentity_t *sparks = G_Spawn();
if ( sparks )
{
sparks->fxFile = "sparks/spark";
sparks->delay = 100;
sparks->random = 500;
sparks->s.angles[0] = 180;//point down
VectorCopy( self->s.origin, sparks->s.origin );
SP_fx_runner( sparks );
}
//bye!
self->takedamage = qfalse;
self->contents = 0;
self->s.eFlags |= EF_NODRAW;
self->s.modelindex = 0;
}
void camera_use( gentity_t *self, gentity_t *other, gentity_t *activator )
{
if ( !activator || !activator->client || activator->s.number )
{//really only usable by the player
return;
}
self->painDebounceTime = level.time + (self->wait*1000);//FRAMETIME*5;//don't check for player buttons for 500 ms
// FIXME: I guess we are allowing them to switch to a dead camera. Maybe we should conditionally do this though?
if ( /*self->health <= 0 ||*/ (player && player->client && player->client->ps.viewEntity == self->s.number) )
{//I'm already viewEntity, or I'm destroyed, find next
gentity_t *next = NULL;
if ( self->target2 != NULL )
{
next = G_Find( NULL, FOFS(targetname), self->target2 );
}
if ( next )
{//found another one
if ( !Q_stricmp( "misc_camera", next->classname ) )
{//make sure it's another camera
camera_use( next, other, activator );
}
}
else //if ( self->health > 0 )
{//I was the last (only?) one, clear out the viewentity
G_UseTargets2( self, activator, self->target4 );
G_ClearViewEntity( activator );
G_Sound( activator, self->soundPos2 );
}
}
else
{//set me as view entity
G_UseTargets2( self, activator, self->target3 );
self->s.eFlags |= EF_NODRAW;
self->s.modelindex = 0;
G_SetViewEntity( activator, self );
G_Sound( activator, self->soundPos1 );
}
}
void camera_aim( gentity_t *self )
{
self->nextthink = level.time + FRAMETIME;
if ( player && player->client && player->client->ps.viewEntity == self->s.number )
{//I am the viewEntity
if ( player->client->usercmd.forwardmove || player->client->usercmd.rightmove || player->client->usercmd.upmove )
{//player wants to back out of camera
G_UseTargets2( self, player, self->target4 );
G_ClearViewEntity( player );
G_Sound( player, self->soundPos2 );
self->painDebounceTime = level.time + (self->wait*1000);//FRAMETIME*5;//don't check for player buttons for 500 ms
if ( player->client->usercmd.upmove > 0 )
{//stop player from doing anything for a half second after
player->aimDebounceTime = level.time + 500;
}
}
else if ( self->painDebounceTime < level.time )
{//check for use button
if ( (player->client->usercmd.buttons&BUTTON_USE) )
{//player pressed use button, wants to cycle to next
camera_use( self, player, player );
}
}
else
{//don't draw me when being looked through
self->s.eFlags |= EF_NODRAW;
self->s.modelindex = 0;
}
}
else if ( self->health > 0 )
{//still alive, can draw me again
self->s.eFlags &= ~EF_NODRAW;
self->s.modelindex = self->s.modelindex3;
}
//update my aim
if ( self->target )
{
gentity_t *targ = G_Find( NULL, FOFS(targetname), self->target );
if ( targ )
{
vec3_t angles, dir;
VectorSubtract( targ->currentOrigin, self->currentOrigin, dir );
vectoangles( dir, angles );
//FIXME: if a G2 model, do a bone override..???
VectorCopy( self->currentAngles, self->s.apos.trBase );
for( int i = 0; i < 3; i++ )
{
angles[i] = AngleNormalize180( angles[i] );
self->s.apos.trDelta[i] = AngleNormalize180( (angles[i]-self->currentAngles[i])*10 );
}
//VectorSubtract( angles, self->currentAngles, self->s.apos.trDelta );
//VectorScale( self->s.apos.trDelta, 10, self->s.apos.trDelta );
self->s.apos.trTime = level.time;
self->s.apos.trDuration = FRAMETIME;
VectorCopy( angles, self->currentAngles );
if ( DistanceSquared( self->currentAngles, self->lastAngles ) > 0.01f ) // if it moved at all, start a loop sound? not exactly the "bestest" solution
{
self->s.loopSound = G_SoundIndex( "sound/movers/objects/cameramove_lp2" );
}
else
{
self->s.loopSound = 0; // not moving so don't bother
}
VectorCopy( self->currentAngles, self->lastAngles );
//G_SetAngles( self, angles );
}
}
}
/*QUAKED misc_camera (0 0 1) (-8 -8 -12) (8 8 16) VULNERABLE
A model in the world that can be used by the player to look through it's viewpoint
There will be a video overlay instead of the regular HUD and the FOV will be wider
VULNERABLE - allow camera to be destroyed
"target" - camera will remain pointed at this entity (if it's a train or some other moving object, it will keep following it)
"target2" - when player is in this camera and hits the use button, it will cycle to this next camera (if no target2, returns to normal view )
"target3" - thing to use when player enters this camera view
"target4" - thing to use when player leaves this camera view
"closetarget" - (sigh...) yet another target, fired this when it's destroyed
"wait" - how long to wait between being used (default 0.5)
*/
void SP_misc_camera( gentity_t *self )
{
G_SpawnFloat( "wait", "0.5", &self->wait );
//FIXME: spawn base, too
gentity_t *base = G_Spawn();
if ( base )
{
base->s.modelindex = G_ModelIndex( "models/map_objects/kejim/impcam_base.md3" );
VectorCopy( self->s.origin, base->s.origin );
base->s.origin[2] += 16;