forked from sears2424/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeam_shared.cpp
1201 lines (1018 loc) · 32.3 KB
/
beam_shared.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 Valve Corporation, All rights reserved. ============//
//
// Purpose: Implements visual effects entities: sprites, beams, bubbles, etc.
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "beam_shared.h"
#include "decals.h"
#include "model_types.h"
#include "IEffects.h"
#include "util_shared.h"
#if !defined( CLIENT_DLL )
#include "ndebugoverlay.h"
#include "sendproxy.h"
#else
#include "iviewrender_beams.h"
#include "c_pixel_visibility.h"
#include "iclientmode.h"
#include "viewrender.h"
#include "view.h"
#ifdef PORTAL
#include "c_prop_portal.h"
#endif //ifdef PORTAL
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define BEAM_DEFAULT_HALO_SCALE 10
#if !defined( CLIENT_DLL )
// Lightning target, just alias landmark
class CInfoTarget : public CPointEntity
{
public:
DECLARE_CLASS( CInfoTarget, CPointEntity );
void Spawn( void );
};
//info targets are like point entities except you can force them to spawn on the client
void CInfoTarget::Spawn( void )
{
BaseClass::Spawn();
if ( HasSpawnFlags(0x01) )
{
SetEFlags( EFL_FORCE_CHECK_TRANSMIT );
}
}
LINK_ENTITY_TO_CLASS( info_target, CInfoTarget );
#endif
//-----------------------------------------------------------------------------
// Purpose: Returns true if the given entity is a fixed target for lightning.
//-----------------------------------------------------------------------------
bool IsStaticPointEntity( CBaseEntity *pEnt )
{
if ( pEnt->GetMoveParent() )
return false;
if ( !pEnt->GetModelIndex() )
return 1;
if ( FClassnameIs( pEnt, "info_target" ) || FClassnameIs( pEnt, "info_landmark" ) ||
FClassnameIs( pEnt, "path_corner" ) )
return true;
return false;
}
#if defined( CLIENT_DLL )
extern bool ComputeBeamEntPosition( CBaseEntity *pEnt, int nAttachment, bool bInterpretAttachmentIndexAsHitboxIndex, Vector& pt );
void RecvProxy_Beam_ScrollSpeed( const CRecvProxyData *pData, void *pStruct, void *pOut )
{
C_Beam *beam;
float val;
// Unpack the data.
val = pData->m_Value.m_Float;
val *= 0.1;
beam = ( C_Beam * )pStruct;
Assert( pOut == &beam->m_fSpeed );
beam->m_fSpeed = val;
}
#else
#if !defined( NO_ENTITY_PREDICTION )
static void* SendProxy_SendPredictableId( const SendProp *pProp, const void *pStruct, const void *pVarData, CSendProxyRecipients *pRecipients, int objectID )
{
CBaseEntity *pEntity = (CBaseEntity *)pStruct;
if ( !pEntity || !pEntity->m_PredictableID->IsActive() )
return NULL;
if ( !pEntity->GetOwnerEntity() )
return NULL;
CBaseEntity *owner = pEntity->GetOwnerEntity();
if ( !owner || !owner->IsPlayer() )
return NULL;
CBasePlayer *pOwner = static_cast< CBasePlayer * >( owner );
if ( !pOwner )
return NULL;
int id_player_index = pEntity->m_PredictableID->GetPlayer();
int owner_player_index = pOwner->entindex() - 1;
// Only send to owner player
// FIXME: Is this ever not the case due to the SetOnly call?
if ( id_player_index != owner_player_index )
return NULL;
pRecipients->SetOnly( owner_player_index );
return ( void * )pVarData;
}
REGISTER_SEND_PROXY_NON_MODIFIED_POINTER( SendProxy_SendPredictableId );
#endif
#endif
LINK_ENTITY_TO_CLASS( beam, CBeam );
// This table encodes the CBeam data.
IMPLEMENT_NETWORKCLASS_ALIASED( Beam, DT_Beam )
#if !defined( NO_ENTITY_PREDICTION )
BEGIN_NETWORK_TABLE_NOBASE( CBeam, DT_BeamPredictableId )
#if !defined( CLIENT_DLL )
SendPropPredictableId( SENDINFO( m_PredictableID ) ),
SendPropInt( SENDINFO( m_bIsPlayerSimulated ), 1, SPROP_UNSIGNED ),
#else
RecvPropPredictableId( RECVINFO( m_PredictableID ) ),
RecvPropInt( RECVINFO( m_bIsPlayerSimulated ) ),
#endif
END_NETWORK_TABLE()
#endif
BEGIN_NETWORK_TABLE_NOBASE( CBeam, DT_Beam )
#if !defined( CLIENT_DLL )
SendPropInt (SENDINFO(m_nBeamType), Q_log2(NUM_BEAM_TYPES)+1, SPROP_UNSIGNED ),
SendPropInt (SENDINFO(m_nBeamFlags), NUM_BEAM_FLAGS, SPROP_UNSIGNED ),
SendPropInt (SENDINFO(m_nNumBeamEnts ), 5, SPROP_UNSIGNED ),
SendPropArray3
(
SENDINFO_ARRAY3(m_hAttachEntity),
SendPropEHandle( SENDINFO_ARRAY(m_hAttachEntity) )
),
SendPropArray3
(
SENDINFO_ARRAY3(m_nAttachIndex),
SendPropInt( SENDINFO_ARRAY(m_nAttachIndex), ATTACHMENT_INDEX_BITS, SPROP_UNSIGNED)
),
SendPropInt (SENDINFO(m_nHaloIndex), 16, SPROP_UNSIGNED ),
SendPropFloat (SENDINFO(m_fHaloScale), 0, SPROP_NOSCALE ),
SendPropFloat (SENDINFO(m_fWidth), 10, SPROP_ROUNDUP, 0.0f, MAX_BEAM_WIDTH ),
SendPropFloat (SENDINFO(m_fEndWidth), 10, SPROP_ROUNDUP, 0.0f, MAX_BEAM_WIDTH ),
SendPropFloat (SENDINFO(m_fFadeLength), 0, SPROP_NOSCALE ),
SendPropFloat (SENDINFO(m_fAmplitude), 8, SPROP_ROUNDDOWN, 0.0f, MAX_BEAM_NOISEAMPLITUDE ),
SendPropFloat (SENDINFO(m_fStartFrame), 8, SPROP_ROUNDDOWN, 0.0f, 256.0f),
SendPropFloat (SENDINFO(m_fSpeed), 8, SPROP_NOSCALE, 0.0f, MAX_BEAM_SCROLLSPEED),
SendPropInt (SENDINFO(m_nRenderFX), 8, SPROP_UNSIGNED ),
SendPropInt (SENDINFO(m_nRenderMode), 8, SPROP_UNSIGNED ),
SendPropFloat (SENDINFO(m_flFrameRate), 10, SPROP_ROUNDUP, -25.0f, 25.0f ),
SendPropFloat (SENDINFO(m_flHDRColorScale), 0, SPROP_NOSCALE, 0.0f, 100.0f ),
SendPropFloat (SENDINFO(m_flFrame), 20, SPROP_ROUNDDOWN | SPROP_CHANGES_OFTEN, 0.0f, 256.0f),
SendPropInt (SENDINFO(m_clrRender), 32, SPROP_UNSIGNED | SPROP_CHANGES_OFTEN ),
SendPropVector (SENDINFO(m_vecEndPos), -1, SPROP_COORD ),
#ifdef PORTAL
SendPropBool (SENDINFO(m_bDrawInMainRender) ),
SendPropBool (SENDINFO(m_bDrawInPortalRender) ),
#endif
SendPropModelIndex(SENDINFO(m_nModelIndex) ),
SendPropVector (SENDINFO(m_vecOrigin), 19, SPROP_CHANGES_OFTEN, MIN_COORD_INTEGER, MAX_COORD_INTEGER),
SendPropEHandle(SENDINFO_NAME(m_hMoveParent, moveparent) ),
SendPropInt (SENDINFO(m_nMinDXLevel), 8, SPROP_UNSIGNED ),
#if !defined( NO_ENTITY_PREDICTION )
SendPropDataTable( "beampredictable_id", 0, &REFERENCE_SEND_TABLE( DT_BeamPredictableId ), SendProxy_SendPredictableId ),
#endif
#else
RecvPropInt (RECVINFO(m_nBeamType)),
RecvPropInt (RECVINFO(m_nBeamFlags)),
RecvPropInt (RECVINFO(m_nNumBeamEnts)),
RecvPropArray3
(
RECVINFO_ARRAY( m_hAttachEntity ),
RecvPropEHandle (RECVINFO(m_hAttachEntity[0]))
),
RecvPropArray3
(
RECVINFO_ARRAY( m_nAttachIndex ),
RecvPropInt (RECVINFO(m_nAttachIndex[0]))
),
RecvPropInt (RECVINFO(m_nHaloIndex)),
RecvPropFloat (RECVINFO(m_fHaloScale)),
RecvPropFloat (RECVINFO(m_fWidth)),
RecvPropFloat (RECVINFO(m_fEndWidth)),
RecvPropFloat (RECVINFO(m_fFadeLength)),
RecvPropFloat (RECVINFO(m_fAmplitude)),
RecvPropFloat (RECVINFO(m_fStartFrame)),
RecvPropFloat (RECVINFO(m_fSpeed), 0, RecvProxy_Beam_ScrollSpeed ),
RecvPropFloat(RECVINFO(m_flFrameRate)),
RecvPropFloat(RECVINFO(m_flHDRColorScale)),
RecvPropInt(RECVINFO(m_clrRender)),
RecvPropInt(RECVINFO(m_nRenderFX)),
RecvPropInt(RECVINFO(m_nRenderMode)),
RecvPropFloat(RECVINFO(m_flFrame)),
RecvPropVector(RECVINFO(m_vecEndPos)),
#ifdef PORTAL
RecvPropBool(RECVINFO(m_bDrawInMainRender) ),
RecvPropBool(RECVINFO(m_bDrawInPortalRender) ),
#endif
RecvPropInt(RECVINFO(m_nModelIndex)),
RecvPropInt(RECVINFO(m_nMinDXLevel)),
RecvPropVector(RECVINFO_NAME(m_vecNetworkOrigin, m_vecOrigin)),
RecvPropInt( RECVINFO_NAME(m_hNetworkMoveParent, moveparent), 0, RecvProxy_IntToMoveParent ),
#if !defined( NO_ENTITY_PREDICTION )
RecvPropDataTable( "beampredictable_id", 0, 0, &REFERENCE_RECV_TABLE( DT_BeamPredictableId ) ),
#endif
#endif
END_NETWORK_TABLE()
#if !defined( CLIENT_DLL )
BEGIN_DATADESC( CBeam )
DEFINE_FIELD( m_nHaloIndex, FIELD_MODELINDEX ),
DEFINE_FIELD( m_nBeamType, FIELD_INTEGER ),
DEFINE_FIELD( m_nBeamFlags, FIELD_INTEGER ),
DEFINE_FIELD( m_nNumBeamEnts, FIELD_INTEGER ),
DEFINE_ARRAY( m_hAttachEntity, FIELD_EHANDLE, MAX_BEAM_ENTS ),
DEFINE_ARRAY( m_nAttachIndex, FIELD_INTEGER, MAX_BEAM_ENTS ),
DEFINE_FIELD( m_nMinDXLevel, FIELD_INTEGER ),
DEFINE_FIELD( m_fWidth, FIELD_FLOAT ),
DEFINE_FIELD( m_fEndWidth, FIELD_FLOAT ),
DEFINE_FIELD( m_fFadeLength, FIELD_FLOAT ),
DEFINE_FIELD( m_fHaloScale, FIELD_FLOAT ),
DEFINE_FIELD( m_fAmplitude, FIELD_FLOAT ),
DEFINE_FIELD( m_fStartFrame, FIELD_FLOAT ),
DEFINE_FIELD( m_fSpeed, FIELD_FLOAT ),
DEFINE_FIELD( m_flFrameRate, FIELD_FLOAT ),
DEFINE_FIELD( m_flFrame, FIELD_FLOAT ),
DEFINE_KEYFIELD( m_flHDRColorScale, FIELD_FLOAT, "HDRColorScale" ),
DEFINE_KEYFIELD( m_flDamage, FIELD_FLOAT, "damage" ),
DEFINE_FIELD( m_flFireTime, FIELD_TIME ),
DEFINE_FIELD( m_vecEndPos, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_hEndEntity, FIELD_EHANDLE ),
DEFINE_KEYFIELD( m_nDissolveType, FIELD_INTEGER, "dissolvetype" ),
#ifdef PORTAL
DEFINE_FIELD( m_bDrawInMainRender, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bDrawInPortalRender, FIELD_BOOLEAN ),
#endif
// Inputs
DEFINE_INPUTFUNC( FIELD_FLOAT, "Width", InputWidth ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "Noise", InputNoise ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "ColorRedValue", InputColorRedValue ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "ColorGreenValue", InputColorGreenValue ),
DEFINE_INPUTFUNC( FIELD_FLOAT, "ColorBlueValue", InputColorBlueValue ),
DEFINE_INPUT( m_fSpeed, FIELD_FLOAT, "ScrollSpeed" ),
// don't save this
//DEFINE_FIELD( m_queryHandleHalo, FIELD_ ),
END_DATADESC()
#else
BEGIN_PREDICTION_DATA( CBeam )
DEFINE_PRED_FIELD( m_nBeamType, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_nNumBeamEnts, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_ARRAY( m_hAttachEntity, FIELD_EHANDLE, MAX_BEAM_ENTS, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_ARRAY( m_nAttachIndex, FIELD_INTEGER, MAX_BEAM_ENTS, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_nHaloIndex, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_fHaloScale, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_fWidth, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_fEndWidth, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_fFadeLength, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_fAmplitude, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_fStartFrame, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_fSpeed, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_nRenderFX, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_nRenderMode, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_flFrameRate, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_flFrame, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_clrRender, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_nMinDXLevel, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD_TOL( m_vecEndPos, FIELD_VECTOR, FTYPEDESC_INSENDTABLE, 0.125f ),
#ifdef PORTAL
DEFINE_PRED_FIELD( m_bDrawInMainRender, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_bDrawInPortalRender, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
#endif
DEFINE_PRED_FIELD( m_nModelIndex, FIELD_INTEGER, FTYPEDESC_INSENDTABLE | FTYPEDESC_MODELINDEX ),
DEFINE_PRED_FIELD_TOL( m_vecOrigin, FIELD_VECTOR, FTYPEDESC_INSENDTABLE, 0.125f ),
//DEFINE_PRED_FIELD( m_pMoveParent, SendProxy_MoveParent ),
//DEFINE_PRED_FIELD( m_flHDRColorScale, SendProxy_HDRColorScale ),
END_PREDICTION_DATA()
#endif
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CBeam::CBeam( void )
{
#ifdef _DEBUG
// necessary since in debug, we initialize vectors to NAN for debugging
m_vecEndPos.Init();
#endif
m_nMinDXLevel = 0;
m_flHDRColorScale = 1.0f; // default value.
#if !defined( CLIENT_DLL )
m_nDissolveType = -1;
#else
m_queryHandleHalo = 0;
#endif
#ifdef PORTAL
m_bDrawInMainRender = true;
m_bDrawInPortalRender = true;
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *szModelName -
//-----------------------------------------------------------------------------
void CBeam::SetModel( const char *szModelName )
{
int modelIndex = modelinfo->GetModelIndex( szModelName );
const model_t *model = modelinfo->GetModel( modelIndex );
if ( model && modelinfo->GetModelType( model ) != mod_sprite )
{
Msg( "Setting CBeam to non-sprite model %s\n", szModelName );
}
#if !defined( CLIENT_DLL )
UTIL_SetModel( this, szModelName );
#else
BaseClass::SetModel( szModelName );
#endif
}
void CBeam::Spawn( void )
{
SetMoveType( MOVETYPE_NONE );
SetSolid( SOLID_NONE ); // Remove model & collisions
SetRenderMode( kRenderTransTexture );
// Opt out of all shadow routines
AddEffects( EF_NOSHADOW | EF_NORECEIVESHADOW );
Precache( );
}
void CBeam::Precache( void )
{
if ( GetOwnerEntity() )
{
SetStartEntity( GetOwnerEntity() );
}
if ( m_hEndEntity.Get() )
{
SetEndEntity( m_hEndEntity );
}
}
void CBeam::SetType( int type )
{
Assert( type < NUM_BEAM_TYPES );
m_nBeamType = type;
}
void CBeam::SetBeamFlags( int flags )
{
Assert( flags < (1 << NUM_BEAM_FLAGS) );
m_nBeamFlags = flags;
}
void CBeam::SetBeamFlag( int flag )
{
m_nBeamFlags |= flag;
}
int CBeam::GetType( void ) const
{
return m_nBeamType;
}
int CBeam::GetBeamFlags( void ) const
{
return m_nBeamFlags;
}
void CBeam::SetStartEntity( CBaseEntity *pEntity )
{
Assert( m_nNumBeamEnts >= 2 );
m_hAttachEntity.Set( 0, pEntity );
SetOwnerEntity( pEntity );
RelinkBeam();
pEntity->AddEFlags( EFL_FORCE_CHECK_TRANSMIT );
}
void CBeam::SetEndEntity( CBaseEntity *pEntity )
{
Assert( m_nNumBeamEnts >= 2 );
m_hAttachEntity.Set( m_nNumBeamEnts-1, pEntity );
m_hEndEntity = pEntity;
RelinkBeam();
pEntity->AddEFlags( EFL_FORCE_CHECK_TRANSMIT );
}
//-----------------------------------------------------------------------------
// This will change things so the abs position matches the requested spot
//-----------------------------------------------------------------------------
void CBeam::SetAbsStartPos( const Vector &pos )
{
if (!GetMoveParent())
{
SetStartPos( pos );
return;
}
Vector vecLocalPos;
matrix3x4_t worldToBeam;
MatrixInvert( EntityToWorldTransform(), worldToBeam );
VectorTransform( pos, worldToBeam, vecLocalPos );
SetStartPos( vecLocalPos );
}
void CBeam::SetAbsEndPos( const Vector &pos )
{
if (!GetMoveParent())
{
SetEndPos( pos );
return;
}
Vector vecLocalPos;
matrix3x4_t worldToBeam;
MatrixInvert( EntityToWorldTransform(), worldToBeam );
VectorTransform( pos, worldToBeam, vecLocalPos );
SetEndPos( vecLocalPos );
}
#if !defined( CLIENT_DLL )
// These don't take attachments into account
const Vector &CBeam::GetAbsStartPos( void ) const
{
if ( GetType() == BEAM_ENTS && GetStartEntity() )
{
edict_t *pent = engine->PEntityOfEntIndex( GetStartEntity() );
CBaseEntity *ent = CBaseEntity::Instance( pent );
if ( !ent )
{
return GetAbsOrigin();
}
return ent->GetAbsOrigin();
}
return GetAbsOrigin();
}
const Vector &CBeam::GetAbsEndPos( void ) const
{
if ( GetType() != BEAM_POINTS && GetType() != BEAM_HOSE && GetEndEntity() )
{
edict_t *pent = engine->PEntityOfEntIndex( GetEndEntity() );
CBaseEntity *ent = CBaseEntity::Instance( pent );
if ( ent )
return ent->GetAbsOrigin();
}
if (!const_cast<CBeam*>(this)->GetMoveParent())
return m_vecEndPos.Get();
// FIXME: Cache this off?
static Vector vecAbsPos;
VectorTransform( m_vecEndPos, EntityToWorldTransform(), vecAbsPos );
return vecAbsPos;
}
#else
//-----------------------------------------------------------------------------
// Unlike the server, these take attachments into account
//-----------------------------------------------------------------------------
const Vector &C_Beam::GetAbsStartPos( void ) const
{
static Vector vecStartAbsPosition;
if ( GetType() != BEAM_POINTS && GetType() != BEAM_HOSE )
{
if (ComputeBeamEntPosition( m_hAttachEntity[0], m_nAttachIndex[0], false, vecStartAbsPosition ))
return vecStartAbsPosition;
}
return GetAbsOrigin();
}
const Vector &C_Beam::GetAbsEndPos( void ) const
{
static Vector vecEndAbsPosition;
if ( GetType() != BEAM_POINTS && GetType() != BEAM_HOSE )
{
if (ComputeBeamEntPosition( m_hAttachEntity[m_nNumBeamEnts-1], m_nAttachIndex[m_nNumBeamEnts-1], false, vecEndAbsPosition ))
return vecEndAbsPosition;
}
if (!const_cast<C_Beam*>(this)->GetMoveParent())
return m_vecEndPos.Get();
// FIXME: Cache this off?
VectorTransform( m_vecEndPos, EntityToWorldTransform(), vecEndAbsPosition );
return vecEndAbsPosition;
}
#endif
CBeam *CBeam::BeamCreate( const char *pSpriteName, float width )
{
// Create a new entity with CBeam private data
CBeam *pBeam = CREATE_ENTITY( CBeam, "beam" );
pBeam->BeamInit( pSpriteName, width );
return pBeam;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pSpriteName -
// &origin -
// animate -
// Output : CSprite
//-----------------------------------------------------------------------------
CBeam *CBeam::BeamCreatePredictable( const char *module, int line, bool persist, const char *pSpriteName, float width, CBasePlayer *pOwner )
{
#if !defined( NO_ENTITY_PREDICTION )
CBeam *pBeam = ( CBeam * )CBaseEntity::CreatePredictedEntityByName( "beam", module, line, persist );
if ( pBeam )
{
pBeam->BeamInit( pSpriteName, width );
pBeam->SetOwnerEntity( pOwner );
pBeam->SetPlayerSimulated( pOwner );
}
return pBeam;
#else
return NULL;
#endif
}
void CBeam::BeamInit( const char *pSpriteName, float width )
{
SetColor( 255, 255, 255 );
SetBrightness( 255 );
SetNoise( 0 );
SetFrame( 0 );
SetScrollRate( 0 );
SetModelName( MAKE_STRING( pSpriteName ) );
SetRenderMode( kRenderTransTexture );
SetTexture( PrecacheModel( pSpriteName ) );
SetWidth( width );
SetEndWidth( width );
SetFadeLength( 0 ); // No fade
for (int i=0;i<MAX_BEAM_ENTS;i++)
{
m_hAttachEntity.Set( i, NULL );
m_nAttachIndex.Set( i, 0 );
}
m_nHaloIndex = 0;
m_fHaloScale = BEAM_DEFAULT_HALO_SCALE;
m_nBeamType = 0;
m_nBeamFlags = 0;
}
void CBeam::PointsInit( const Vector &start, const Vector &end )
{
SetType( BEAM_POINTS );
m_nNumBeamEnts = 2;
SetStartPos( start );
SetEndPos( end );
SetStartAttachment( 0 );
SetEndAttachment( 0 );
RelinkBeam();
}
void CBeam::HoseInit( const Vector &start, const Vector &direction )
{
SetType( BEAM_HOSE );
m_nNumBeamEnts = 2;
SetStartPos( start );
SetEndPos( direction );
SetStartAttachment( 0 );
SetEndAttachment( 0 );
RelinkBeam();
}
void CBeam::PointEntInit( const Vector &start, CBaseEntity *pEndEntity )
{
SetType( BEAM_ENTPOINT );
m_nNumBeamEnts = 2;
SetStartPos( start );
SetEndEntity( pEndEntity );
SetStartAttachment( 0 );
SetEndAttachment( 0 );
RelinkBeam();
}
void CBeam::EntsInit( CBaseEntity *pStartEntity, CBaseEntity *pEndEntity )
{
SetType( BEAM_ENTS );
m_nNumBeamEnts = 2;
SetStartEntity( pStartEntity );
SetEndEntity( pEndEntity );
SetStartAttachment( 0 );
SetEndAttachment( 0 );
RelinkBeam();
}
void CBeam::LaserInit( CBaseEntity *pStartEntity, CBaseEntity *pEndEntity )
{
SetType( BEAM_LASER );
m_nNumBeamEnts = 2;
SetStartEntity( pStartEntity );
SetEndEntity( pEndEntity );
SetStartAttachment( 0 );
SetEndAttachment( 0 );
RelinkBeam();
}
void CBeam::SplineInit( int nNumEnts, CBaseEntity** pEntList, int *attachment )
{
if (nNumEnts < 2)
{
Msg("ERROR: Min of 2 ents required for spline beam.\n");
}
else if (nNumEnts > MAX_BEAM_ENTS)
{
Msg("ERROR: Max of %i ents allowed for spline beam.\n",MAX_BEAM_ENTS);
}
SetType( BEAM_SPLINE );
for (int i=0;i<nNumEnts;i++)
{
m_hAttachEntity.Set( i, pEntList[i] );
m_nAttachIndex.Set( i, attachment[i] );
}
m_nNumBeamEnts = nNumEnts;
RelinkBeam();
}
void CBeam::RelinkBeam( void )
{
// FIXME: Why doesn't this just define the absbox too?
// It seems that we don't need to recompute the absbox
// in CBaseEntity::SetObjectCollisionBox, in fact the absbox
// computed there seems way too big
Vector startPos = GetAbsStartPos(), endPos = GetAbsEndPos();
Vector vecAbsExtra1, vecAbsExtra2;
bool bUseExtraPoints = false;
#ifdef PORTAL
CBaseEntity *pStartEntity = GetStartEntityPtr();
CTraceFilterSkipClassname traceFilter( pStartEntity, "prop_energy_ball", COLLISION_GROUP_NONE );
ITraceFilter *pEntityBeamTraceFilter = NULL;
if ( pStartEntity )
pEntityBeamTraceFilter = pStartEntity->GetBeamTraceFilter();
CTraceFilterChain traceFilterChain( &traceFilter, pEntityBeamTraceFilter );
bUseExtraPoints = UTIL_Portal_Trace_Beam( this, startPos, endPos, vecAbsExtra1, vecAbsExtra2, &traceFilterChain );
#endif
// UNDONE: Should we do this to make the boxes smaller?
//SetAbsOrigin( startPos );
Vector vecBeamMin, vecBeamMax;
VectorMin( startPos, endPos, vecBeamMin );
VectorMax( startPos, endPos, vecBeamMax );
if ( bUseExtraPoints )
{
VectorMin( vecBeamMin, vecAbsExtra1, vecBeamMin );
VectorMin( vecBeamMin, vecAbsExtra2, vecBeamMin );
VectorMax( vecBeamMax, vecAbsExtra1, vecBeamMax );
VectorMax( vecBeamMax, vecAbsExtra2, vecBeamMax );
}
SetCollisionBounds( vecBeamMin - GetAbsOrigin(), vecBeamMax - GetAbsOrigin() );
}
CBaseEntity *CBeam::RandomTargetname( const char *szName )
{
#if !defined( CLIENT_DLL )
int total = 0;
CBaseEntity *pEntity = NULL;
CBaseEntity *pNewEntity = NULL;
while ((pNewEntity = gEntList.FindEntityByName( pNewEntity, szName )) != NULL)
{
total++;
if (random->RandomInt(0,total-1) < 1)
pEntity = pNewEntity;
}
return pEntity;
#else
return NULL;
#endif
}
void CBeam::DoSparks( const Vector &start, const Vector &end )
{
#if !defined( CLIENT_DLL )
if ( HasSpawnFlags(SF_BEAM_SPARKSTART|SF_BEAM_SPARKEND) )
{
if ( HasSpawnFlags( SF_BEAM_SPARKSTART ) )
{
g_pEffects->Sparks( start );
}
if ( HasSpawnFlags( SF_BEAM_SPARKEND ) )
{
g_pEffects->Sparks( end );
}
}
#endif
}
//-----------------------------------------------------------------------------
// Purpose: Damages anything in the beam.
// Input : ptr -
//-----------------------------------------------------------------------------
void CBeam::BeamDamage( trace_t *ptr )
{
RelinkBeam();
#if !defined( CLIENT_DLL )
if ( ptr->fraction != 1.0 && ptr->m_pEnt != NULL )
{
CBaseEntity *pHit = ptr->m_pEnt;
if ( pHit )
{
ClearMultiDamage();
Vector dir = ptr->endpos - GetAbsOrigin();
VectorNormalize( dir );
int nDamageType = DMG_ENERGYBEAM;
#ifndef HL1_DLL
if (m_nDissolveType == 0)
{
nDamageType = DMG_DISSOLVE;
}
else if ( m_nDissolveType > 0 )
{
nDamageType = DMG_DISSOLVE | DMG_SHOCK;
}
#endif
CTakeDamageInfo info( this, this, m_flDamage * (gpGlobals->curtime - m_flFireTime), nDamageType );
CalculateMeleeDamageForce( &info, dir, ptr->endpos );
pHit->DispatchTraceAttack( info, dir, ptr );
ApplyMultiDamage();
if ( HasSpawnFlags( SF_BEAM_DECALS ) )
{
if ( pHit->IsBSPModel() )
{
UTIL_DecalTrace( ptr, GetDecalName() );
}
}
}
}
#endif
m_flFireTime = gpGlobals->curtime;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBeam::TurnOn( void )
{
AddEffects( EF_NODRAW );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBeam::TurnOff( void )
{
RemoveEffects( EF_NODRAW );
}
#if !defined( CLIENT_DLL )
//-----------------------------------------------------------------------------
// Purpose: Input handler for the beam width. Sets the end width based on the
// beam width.
// Input : Beam width in tenths of world units.
//-----------------------------------------------------------------------------
void CBeam::InputWidth( inputdata_t &inputdata )
{
SetWidth( inputdata.value.Float() );
SetEndWidth( inputdata.value.Float() );
}
void CBeam::InputColorRedValue( inputdata_t &inputdata )
{
int nNewColor = clamp( FastFloatToSmallInt(inputdata.value.Float()), 0, 255 );
SetColor( nNewColor, m_clrRender->g, m_clrRender->b );
}
void CBeam::InputColorGreenValue( inputdata_t &inputdata )
{
int nNewColor =clamp( FastFloatToSmallInt(inputdata.value.Float()), 0, 255 );
SetColor( m_clrRender->r, nNewColor, m_clrRender->b );
}
void CBeam::InputColorBlueValue( inputdata_t &inputdata )
{
int nNewColor = clamp( FastFloatToSmallInt(inputdata.value.Float()), 0, 255 );
SetColor( m_clrRender->r, m_clrRender->g, nNewColor );
}
void CBeam::InputNoise( inputdata_t &inputdata )
{
SetNoise( inputdata.value.Float() );
}
int CBeam::UpdateTransmitState( void )
{
// we must call ShouldTransmit() if we have a move parent
if ( GetMoveParent() )
return SetTransmitState( FL_EDICT_FULLCHECK );
return BaseClass::UpdateTransmitState( );
}
void CBeam::SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways )
{
// Are we already marked for transmission?
if ( pInfo->m_pTransmitEdict->Get( entindex() ) )
return;
BaseClass::SetTransmit( pInfo, bAlways );
// Force our attached entities to go too...
for ( int i=0; i < MAX_BEAM_ENTS; ++i )
{
if ( m_hAttachEntity[i].Get() )
{
m_hAttachEntity[i]->SetTransmit( pInfo, bAlways );
}
}
}
int CBeam::ShouldTransmit( const CCheckTransmitInfo *pInfo )
{
if ( IsEffectActive( EF_NODRAW ) )
return FL_EDICT_DONTSEND;
// Transmit us with the same rules as our move parent
if ( GetMoveParent() )
{
return GetMoveParent()->ShouldTransmit( pInfo );
}
return BaseClass::ShouldTransmit( pInfo );
}
#endif
//-----------------------------------------------------------------------------
// Purpose: Draw any debug text overlays.
// Output : Returns the new text offset from the top.
//-----------------------------------------------------------------------------
int CBeam::DrawDebugTextOverlays(void)
{
#if !defined( CLIENT_DLL )
int text_offset = BaseClass::DrawDebugTextOverlays();
if (m_debugOverlays & OVERLAY_TEXT_BIT)
{
// Print state
char tempstr[512];
Q_snprintf(tempstr, sizeof(tempstr), "start: (%.2f,%.2f,%.2f)", GetAbsOrigin().x, GetAbsOrigin().y, GetAbsOrigin().z);
EntityText(text_offset,tempstr,0);
text_offset++;
Q_snprintf(tempstr, sizeof(tempstr), "end : (%.2f,%.2f,%.2f)", m_vecEndPos.GetX(), m_vecEndPos.GetY(), m_vecEndPos.GetZ());
EntityText(text_offset,tempstr,0);
text_offset++;
}
return text_offset;
#else
return 0;
#endif
}
#if defined( CLIENT_DLL )
// Purpose:
// Input : isbeingremoved -
// *predicted -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CBeam::OnPredictedEntityRemove( bool isbeingremoved, C_BaseEntity *predicted )
{
BaseClass::OnPredictedEntityRemove( isbeingremoved, predicted );
CBeam *beam = dynamic_cast< CBeam * >( predicted );
if ( !beam )
{
// Hrm, we didn't link up to correct type!!!
Assert( 0 );
// Delete right away since it's fucked up
return true;
}
if ( beam->IsEFlagSet( EFL_KILLME ) )
{
// Don't delete right away
AddEFlags( EFL_KILLME );
return false;
}
// Go ahead and delete if it's not short-lived
return true;
}
extern bool g_bRenderingScreenshot;
extern ConVar r_drawviewmodel;
int CBeam::DrawModel( int flags )
{
if ( !m_bReadyToDraw )
return 0;
if ( IsMarkedForDeletion() )
return 0;
if ( CurrentViewID() == VIEW_SHADOW_DEPTH_TEXTURE )
return 0;
#ifdef PORTAL
if ( ( !g_pPortalRender->IsRenderingPortal() && !m_bDrawInMainRender ) ||
( g_pPortalRender->IsRenderingPortal() && !m_bDrawInPortalRender ) )
{
return 0;
}
#endif //#ifdef PORTAL
// Tracker 16432: If rendering a savegame screenshot don't draw beams
// who have viewmodels as their attached entity
if ( g_bRenderingScreenshot || !r_drawviewmodel.GetBool() )
{
// If the beam is attached
for (int i=0;i<MAX_BEAM_ENTS;i++)
{
C_BaseViewModel *vm = dynamic_cast<C_BaseViewModel *>(m_hAttachEntity[i].Get());
if ( vm )
{
return 0;
}
}
}
beams->DrawBeam( this );