forked from ValveSoftware/source-sdk-2013
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtf_obj.cpp
More file actions
3839 lines (3213 loc) · 110 KB
/
tf_obj.cpp
File metadata and controls
3839 lines (3213 loc) · 110 KB
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: Base Object built by players
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "tf_player.h"
#include "tf_team.h"
#include "tf_obj.h"
#include "tf_weaponbase.h"
#include "rope.h"
#include "rope_shared.h"
#include "bone_setup.h"
#include "ndebugoverlay.h"
#include "rope_helpers.h"
#include "IEffects.h"
#include "vstdlib/random.h"
#include "tier1/strtools.h"
#include "basegrenade_shared.h"
#include "tf_gamerules.h"
#include "engine/IEngineSound.h"
#include "tf_shareddefs.h"
#include "vguiscreen.h"
#include "hierarchy.h"
#include "func_no_build.h"
#include "func_respawnroom.h"
#include <KeyValues.h>
#include "ihasbuildpoints.h"
#include "utldict.h"
#include "filesystem.h"
#include "npcevent.h"
#include "tf_shareddefs.h"
#include "animation.h"
#include "effect_dispatch_data.h"
#include "te_effect_dispatch.h"
#include "tf_gamestats.h"
#include "tf_ammo_pack.h"
#include "tf_obj_sapper.h"
#include "particle_parse.h"
#include "tf_fx.h"
#include "trains.h"
#include "serverbenchmark_base.h"
#include "tf_weapon_wrench.h"
#include "tf_weapon_grenade_pipebomb.h"
#include "tf_weapon_builder.h"
#include "tf_objective_resource.h"
#include "player_vs_environment/tf_population_manager.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
// Control panels
#define SCREEN_OVERLAY_MATERIAL "vgui/screens/vgui_overlay"
#define ROPE_HANG_DIST 150
#define UPGRADE_LEVEL_HEALTH_MULTIPLIER 1.2f
#ifdef _DEBUG
//------------------------------------------------------------------------------
// Damage the player's buildings the specified amount
//------------------------------------------------------------------------------
void CC_HurtBuilding_f( const CCommand &args )
{
if ( !sv_cheats->GetBool() )
return;
CBasePlayer *pPlayer = ToBasePlayer( UTIL_GetCommandClient() );
if ( !pPlayer )
return;
int iDamage = 10;
if ( args.ArgC() >= 2 )
{
iDamage = atoi( args[ 1 ] );
}
CTFPlayer *pTFPlayer = ToTFPlayer( pPlayer );
if ( pTFPlayer )
{
for ( int i = pTFPlayer->GetObjectCount() - 1; i >= 0; i-- )
{
CBaseObject *obj = pTFPlayer->GetObject( i );
Assert( obj );
if ( obj )
{
obj->TakeDamage( CTakeDamageInfo( NULL, NULL, iDamage, DMG_GENERIC ) );
}
}
}
}
static ConCommand hurtbuilding( "hurtbuilding", CC_HurtBuilding_f, "Hurt the player's buildings.\n\tArguments: <health to lose>", FCVAR_CHEAT );
#endif // _DEBUG
ConVar tf_obj_gib_velocity_min( "tf_obj_gib_velocity_min", "100", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
ConVar tf_obj_gib_velocity_max( "tf_obj_gib_velocity_max", "450", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
ConVar tf_obj_gib_maxspeed( "tf_obj_gib_maxspeed", "800", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
ConVar tf_obj_upgrade_per_hit( "tf_obj_upgrade_per_hit", "25", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
ConVar object_verbose( "object_verbose", "0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Debug object system." );
ConVar obj_damage_factor( "obj_damage_factor","0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Factor applied to all damage done to objects" );
ConVar obj_child_damage_factor( "obj_child_damage_factor","0.25", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Factor applied to damage done to objects that are built on a buildpoint" );
ConVar tf_fastbuild("tf_fastbuild", "0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
ConVar tf_obj_ground_clearance( "tf_obj_ground_clearance", "32", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY, "Object corners can be this high above the ground" );
ConVar tf_obj_damage_tank_achievement_amount( "tf_obj_damage_tank_achievement_amount", "2000", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
extern short g_sModelIndexFireball;
extern ConVar tf_cheapobjects;
// Minimum distance between 2 objects to ensure player movement between them
#define MINIMUM_OBJECT_SAFE_DISTANCE 100
// Maximum number of a type of objects on a single resource zone
#define MAX_OBJECTS_PER_ZONE 1
// Time it takes a fully healed object to deteriorate
ConVar object_deterioration_time( "object_deterioration_time", "30", 0, "Time it takes for a fully-healed object to deteriorate." );
// Time after taking damage that an object will still drop resources on death
#define MAX_DROP_TIME_AFTER_DAMAGE 5
#define OBJ_BASE_THINK_CONTEXT "BaseObjectThink"
#define PLASMA_DISABLE_TIME 4
IMPLEMENT_AUTO_LIST( IBaseObjectAutoList );
BEGIN_DATADESC( CBaseObject )
// keys
DEFINE_KEYFIELD_NOT_SAVED( m_SolidToPlayers, FIELD_INTEGER, "SolidToPlayer" ),
DEFINE_KEYFIELD( m_nDefaultUpgradeLevel, FIELD_INTEGER, "defaultupgrade" ),
DEFINE_THINKFUNC( UpgradeThink ),
// Inputs
DEFINE_INPUTFUNC( FIELD_INTEGER, "SetHealth", InputSetHealth ),
DEFINE_INPUTFUNC( FIELD_INTEGER, "AddHealth", InputAddHealth ),
DEFINE_INPUTFUNC( FIELD_INTEGER, "RemoveHealth", InputRemoveHealth ),
DEFINE_INPUTFUNC( FIELD_INTEGER, "SetSolidToPlayer", InputSetSolidToPlayer ),
DEFINE_INPUTFUNC( FIELD_STRING, "SetBuilder", InputSetBuilder ),
DEFINE_INPUTFUNC( FIELD_VOID, "Show", InputShow ),
DEFINE_INPUTFUNC( FIELD_VOID, "Hide", InputHide ),
DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
// Outputs
DEFINE_OUTPUT( m_OnDestroyed, "OnDestroyed" ),
DEFINE_OUTPUT( m_OnDamaged, "OnDamaged" ),
DEFINE_OUTPUT( m_OnRepaired, "OnRepaired" ),
DEFINE_OUTPUT( m_OnBecomingDisabled, "OnDisabled" ),
DEFINE_OUTPUT( m_OnBecomingReenabled, "OnReenabled" ),
DEFINE_OUTPUT( m_OnObjectHealthChanged, "OnObjectHealthChanged" )
END_DATADESC()
IMPLEMENT_SERVERCLASS_ST(CBaseObject, DT_BaseObject)
SendPropInt(SENDINFO(m_iHealth), -1, SPROP_VARINT ),
SendPropInt(SENDINFO(m_iMaxHealth), -1, SPROP_VARINT ),
SendPropBool(SENDINFO(m_bHasSapper) ),
SendPropInt(SENDINFO(m_iObjectType), Q_log2( OBJ_LAST ) + 1, SPROP_UNSIGNED ),
SendPropBool(SENDINFO(m_bBuilding) ),
SendPropBool(SENDINFO(m_bPlacing) ),
SendPropBool(SENDINFO(m_bCarried) ),
SendPropBool(SENDINFO(m_bCarryDeploy) ),
SendPropBool(SENDINFO(m_bMiniBuilding) ),
SendPropFloat(SENDINFO(m_flPercentageConstructed), 8, 0, 0.0, 1.0f ),
SendPropInt(SENDINFO(m_fObjectFlags), OF_BIT_COUNT, SPROP_UNSIGNED ),
SendPropEHandle(SENDINFO(m_hBuiltOnEntity)),
SendPropBool( SENDINFO( m_bDisabled ) ),
SendPropEHandle( SENDINFO( m_hBuilder ) ),
SendPropVector( SENDINFO( m_vecBuildMaxs ), -1, SPROP_COORD ),
SendPropVector( SENDINFO( m_vecBuildMins ), -1, SPROP_COORD ),
SendPropInt( SENDINFO( m_iDesiredBuildRotations ), 2, SPROP_UNSIGNED ),
SendPropBool( SENDINFO( m_bServerOverridePlacement ) ),
SendPropInt( SENDINFO(m_iUpgradeLevel), 5 ),
SendPropInt( SENDINFO(m_iUpgradeMetal), 10 ),
SendPropInt( SENDINFO(m_iUpgradeMetalRequired), 10 ),
SendPropInt( SENDINFO(m_iHighestUpgradeLevel), 3 ),
SendPropInt( SENDINFO(m_iObjectMode), 2, SPROP_UNSIGNED ),
SendPropBool( SENDINFO( m_bDisposableBuilding ) ),
SendPropBool( SENDINFO( m_bWasMapPlaced ) ),
SendPropBool( SENDINFO( m_bPlasmaDisable ) ),
END_SEND_TABLE();
bool PlayerIndexLessFunc( const int &lhs, const int &rhs )
{
return lhs < rhs;
}
// This controls whether ropes attached to objects are transmitted or not. It's important that
// ropes aren't transmitted to guys who don't own them.
class CObjectRopeTransmitProxy : public CBaseTransmitProxy
{
public:
CObjectRopeTransmitProxy( CBaseEntity *pRope ) : CBaseTransmitProxy( pRope )
{
}
virtual int ShouldTransmit( const CCheckTransmitInfo *pInfo, int nPrevShouldTransmitResult )
{
// Don't transmit the rope if it's not even visible.
if ( !nPrevShouldTransmitResult )
return FL_EDICT_DONTSEND;
// This proxy only wants to be active while one of the two objects is being placed.
// When they're done being placed, the proxy goes away and the rope draws like normal.
bool bAnyObjectPlacing = (m_hObj1 && m_hObj1->IsPlacing()) || (m_hObj2 && m_hObj2->IsPlacing());
if ( !bAnyObjectPlacing )
{
Release();
return nPrevShouldTransmitResult;
}
// Give control to whichever object is being placed.
if ( m_hObj1 && m_hObj1->IsPlacing() )
return m_hObj1->ShouldTransmit( pInfo );
else if ( m_hObj2 && m_hObj2->IsPlacing() )
return m_hObj2->ShouldTransmit( pInfo );
else
return FL_EDICT_ALWAYS;
}
CHandle<CBaseObject> m_hObj1;
CHandle<CBaseObject> m_hObj2;
};
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CBaseObject::CBaseObject()
{
m_iHealth = m_iMaxHealth = m_flHealth = 0;
m_flPercentageConstructed = 0;
m_bPlacing = false;
m_bBuilding = false;
m_Activity = ACT_INVALID;
m_bDisabled = false;
m_SolidToPlayers = SOLID_TO_PLAYER_USE_DEFAULT;
m_bPlacementOK = false;
m_aGibs.Purge();
m_iHighestUpgradeLevel = 1;
m_bCarryDeploy = false;
m_flCarryDeployTime = 0;
m_iHealthOnPickup = 0;
m_iLifetimeDamage = 0;
m_bCannotDie = false;
m_bMiniBuilding = false;
m_flPlasmaDisableTime = 0;
m_bPlasmaDisable = false;
m_bDisposableBuilding = false;
m_vecBuildForward = vec3_origin;
m_flBuildDistance = 0.0f;
m_bForceQuickBuild = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseObject::UpdateOnRemove( void )
{
m_bDying = true;
// check for sapper crits
CObjectSapper *pSapper = GetSapper();
if ( pSapper )
{
// give an assist to the sapper's owner
CTFPlayer *pSapperOwner = pSapper->GetOwner();
if ( pSapperOwner )
{
pSapperOwner->m_Shared.IncrementRevengeCrits();
}
}
DestroyObject();
if ( GetTeam() )
{
((CTFTeam*)GetTeam())->RemoveObject( this );
}
DetachObjectFromObject();
// Make sure the object isn't in either team's list of objects...
//Assert( !GetGlobalTFTeam(1)->IsObjectOnTeam( this ) );
//Assert( !GetGlobalTFTeam(2)->IsObjectOnTeam( this ) );
// Chain at end to mimic destructor unwind order
BaseClass::UpdateOnRemove();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CBaseObject::UpdateTransmitState()
{
return SetTransmitState( FL_EDICT_FULLCHECK );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CBaseObject::ShouldTransmit( const CCheckTransmitInfo *pInfo )
{
// Always transmit to owner
if ( GetBuilder() && pInfo->m_pClientEnt == GetBuilder()->edict() )
return FL_EDICT_ALWAYS;
// Placement models only transmit to owners
if ( IsPlacing() )
return FL_EDICT_DONTSEND;
if ( pInfo->m_pClientEnt )
{
CBaseEntity *pRecipientEntity = CBaseEntity::Instance( pInfo->m_pClientEnt );
if ( pRecipientEntity && pRecipientEntity->ShouldForceTransmitsForTeam( GetTeamNumber() ) )
return FL_EDICT_ALWAYS;
}
return BaseClass::ShouldTransmit( pInfo );
}
void CBaseObject::SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways )
{
// Are we already marked for transmission?
if ( pInfo->m_pTransmitEdict->Get( entindex() ) )
return;
BaseClass::SetTransmit( pInfo, bAlways );
// Force our screens to be sent too.
int nTeam = CBaseEntity::Instance( pInfo->m_pClientEnt )->GetTeamNumber();
for ( int i=0; i < m_hScreens.Count(); i++ )
{
CVGuiScreen *pScreen = m_hScreens[i].Get();
if ( pScreen && pScreen->IsVisibleToTeam( nTeam ) )
pScreen->SetTransmit( pInfo, bAlways );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseObject::Precache()
{
PrecacheMaterial( SCREEN_OVERLAY_MATERIAL );
PrecacheScriptSound( GetObjectInfo( ObjectType() )->m_pExplodeSound );
PrecacheScriptSound( GetObjectInfo( ObjectType() )->m_pUpgradeSound );
const char *pEffect = GetObjectInfo( ObjectType() )->m_pExplosionParticleEffect;
if ( pEffect && pEffect[0] != '\0' )
{
PrecacheParticleSystem( pEffect );
}
PrecacheParticleSystem( "nutsnbolts_build" );
PrecacheParticleSystem( "nutsnbolts_upgrade" );
PrecacheParticleSystem( "nutsnbolts_repair" );
PrecacheModel( "models/weapons/w_models/w_toolbox.mdl" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseObject::Spawn( void )
{
Precache();
CollisionProp()->SetSurroundingBoundsType( USE_BEST_COLLISION_BOUNDS );
SetSolidToPlayers( m_SolidToPlayers, true );
m_bWasMapPlaced = false;
m_bHasSapper = false;
if ( HasSpawnFlags(SF_BASEOBJ_INVULN) )
{
m_takedamage = DAMAGE_NO;
}
else
{
m_takedamage = DAMAGE_YES;
}
AddFlag( FL_OBJECT ); // So NPCs will notice it
SetViewOffset( WorldSpaceCenter() - GetAbsOrigin() );
m_iDesiredBuildRotations = 0;
m_flCurrentBuildRotation = 0;
if ( MustBeBuiltOnAttachmentPoint() )
{
AddEffects( EF_NODRAW );
}
// assume valid placement
m_bServerOverridePlacement = true;
m_iUpgradeLevel = 1;
m_iUpgradeMetalRequired = GetUpgradeMetalRequired();
if ( !IsCarried() )
{
FirstSpawn();
}
UpdateLastKnownArea();
}
//-----------------------------------------------------------------------------
// Purpose: Initialization that should only be done when the object is first created.
//-----------------------------------------------------------------------------
void CBaseObject::FirstSpawn()
{
if ( !VPhysicsGetObject() )
VPhysicsInitStatic();
m_iUpgradeMetal = 0;
m_iKills = 0;
m_iAssists = 0;
m_ConstructorList.SetLessFunc( PlayerIndexLessFunc );
m_flHealth = m_iMaxHealth = m_iHealth;
SetContextThink( &CBaseObject::BaseObjectThink, gpGlobals->curtime + 0.1, OBJ_BASE_THINK_CONTEXT );
}
//-----------------------------------------------------------------------------
// Returns information about the various control panels
//-----------------------------------------------------------------------------
void CBaseObject::GetControlPanelInfo( int nPanelIndex, const char *&pPanelName )
{
pPanelName = NULL;
}
//-----------------------------------------------------------------------------
// Returns information about the various control panels
//-----------------------------------------------------------------------------
void CBaseObject::GetControlPanelClassName( int nPanelIndex, const char *&pPanelName )
{
pPanelName = "vgui_screen";
}
//-----------------------------------------------------------------------------
// This is called by the base object when it's time to spawn the control panels
//-----------------------------------------------------------------------------
void CBaseObject::SpawnControlPanels()
{
char buf[64];
// FIXME: Deal with dynamically resizing control panels?
// If we're attached to an entity, spawn control panels on it instead of use
CBaseAnimating *pEntityToSpawnOn = this;
const char *pOrgLL = "controlpanel%d_ll";
const char *pOrgUR = "controlpanel%d_ur";
const char *pAttachmentNameLL = pOrgLL;
const char *pAttachmentNameUR = pOrgUR;
if ( IsBuiltOnAttachment() )
{
pEntityToSpawnOn = dynamic_cast<CBaseAnimating*>((CBaseEntity*)m_hBuiltOnEntity.Get());
if ( pEntityToSpawnOn )
{
char sBuildPointLL[64];
char sBuildPointUR[64];
Q_snprintf( sBuildPointLL, sizeof( sBuildPointLL ), "bp%d_controlpanel%%d_ll", m_iBuiltOnPoint );
Q_snprintf( sBuildPointUR, sizeof( sBuildPointUR ), "bp%d_controlpanel%%d_ur", m_iBuiltOnPoint );
pAttachmentNameLL = sBuildPointLL;
pAttachmentNameUR = sBuildPointUR;
}
else
{
pEntityToSpawnOn = this;
}
}
Assert( pEntityToSpawnOn );
// Lookup the attachment point...
int nPanel;
for ( nPanel = 0; true; ++nPanel )
{
Q_snprintf( buf, sizeof( buf ), pAttachmentNameLL, nPanel );
int nLLAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf);
if (nLLAttachmentIndex <= 0)
{
// Try and use my panels then
pEntityToSpawnOn = this;
Q_snprintf( buf, sizeof( buf ), pOrgLL, nPanel );
nLLAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf);
if (nLLAttachmentIndex <= 0)
return;
}
Q_snprintf( buf, sizeof( buf ), pAttachmentNameUR, nPanel );
int nURAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf);
if (nURAttachmentIndex <= 0)
{
// Try and use my panels then
Q_snprintf( buf, sizeof( buf ), pOrgUR, nPanel );
nURAttachmentIndex = pEntityToSpawnOn->LookupAttachment(buf);
if (nURAttachmentIndex <= 0)
return;
}
const char *pScreenName = NULL;
GetControlPanelInfo( nPanel, pScreenName );
if (!pScreenName)
continue;
const char *pScreenClassname;
GetControlPanelClassName( nPanel, pScreenClassname );
if ( !pScreenClassname )
continue;
// Compute the screen size from the attachment points...
matrix3x4_t panelToWorld;
pEntityToSpawnOn->GetAttachment( nLLAttachmentIndex, panelToWorld );
matrix3x4_t worldToPanel;
MatrixInvert( panelToWorld, worldToPanel );
// Now get the lower right position + transform into panel space
Vector lr, lrlocal;
pEntityToSpawnOn->GetAttachment( nURAttachmentIndex, panelToWorld );
MatrixGetColumn( panelToWorld, 3, lr );
VectorTransform( lr, worldToPanel, lrlocal );
float flWidth = lrlocal.x;
float flHeight = lrlocal.y;
CVGuiScreen *pScreen = CreateVGuiScreen( pScreenClassname, pScreenName, pEntityToSpawnOn, this, nLLAttachmentIndex );
pScreen->ChangeTeam( GetTeamNumber() );
pScreen->SetActualSize( flWidth, flHeight );
pScreen->SetActive( false );
pScreen->MakeVisibleOnlyToTeammates( true );
pScreen->SetOverlayMaterial( SCREEN_OVERLAY_MATERIAL );
pScreen->SetTransparency( true );
// for now, only input by the owning player
pScreen->SetPlayerOwner( GetBuilder(), true );
int nScreen = m_hScreens.AddToTail( );
m_hScreens[nScreen].Set( pScreen );
}
}
//-----------------------------------------------------------------------------
// Handle commands sent from vgui panels on the client
//-----------------------------------------------------------------------------
bool CBaseObject::ClientCommand( CTFPlayer *pSender, const CCommand &args )
{
//const char *pCmd = args[0];
return false;
}
#define BASE_OBJECT_THINK_DELAY 0.1
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseObject::BaseObjectThink( void )
{
SetNextThink( gpGlobals->curtime + BASE_OBJECT_THINK_DELAY, OBJ_BASE_THINK_CONTEXT );
// Make sure animation is up to date
DetermineAnimation();
DeterminePlaybackRate();
if ( m_bPlasmaDisable )
{
if ( gpGlobals->curtime > (m_flPlasmaDisableTime ) )
{
m_bPlasmaDisable = false;
UpdateDisabledState();
}
}
// Do nothing while we're being placed
if ( IsPlacing() )
{
if ( MustBeBuiltOnAttachmentPoint() )
{
UpdateAttachmentPlacement();
m_bServerOverridePlacement = true;
}
else
{
m_bServerOverridePlacement = IsPlacementPosValid();
UpdateDesiredBuildRotation( BASE_OBJECT_THINK_DELAY );
}
return;
}
// If we're building, keep going
if ( IsBuilding() )
{
BuildingThink();
return;
}
if ( IsUpgrading() )
{
UpgradeThink();
}
else
{
if ( GetReversesBuildingConstructionSpeed() > 0.0f )
{
DoReverseBuild();
}
else
{
if ( GetUpgradeLevel() < GetHighestUpgradeLevel() )
{
// Keep moving up levels until we reach the level we were at before.
StartUpgrading();
}
else
{
m_bCarryDeploy = false;
}
}
}
}
void CBaseObject::ResetPlacement( void )
{
m_bPlacementOK = false;
// Clear out previous parent
if ( m_hBuiltOnEntity.Get() )
{
m_hBuiltOnEntity = NULL;
m_iBuiltOnPoint = 0;
SetParent( NULL );
}
// teleport to builder's origin
CTFPlayer *pPlayer = GetOwner();
if ( pPlayer )
{
Teleport( &pPlayer->WorldSpaceCenter(), &GetLocalAngles(), NULL );
}
}
bool CBaseObject::UpdateAttachmentPlacement( CBaseObject *pObjectOverride )
{
// See if we should snap to a build position
// finding one implies it is a valid position
if ( FindSnapToBuildPos( pObjectOverride ) )
{
m_bPlacementOK = true;
Teleport( &m_vecBuildOrigin, &GetLocalAngles(), NULL );
}
else
{
ResetPlacement();
}
return m_bPlacementOK;
}
//-----------------------------------------------------------------------------
// Purpose: Cheap check to see if we are in any server-defined No-build areas.
//-----------------------------------------------------------------------------
bool CBaseObject::EstimateValidBuildPos( void )
{
// Make sure CalculatePlacementPos() has been called to setup the member variables used below
CTFPlayer *pPlayer = GetOwner();
if ( !pPlayer )
return false;
// Cannot build inside a nobuild brush
if ( PointInNoBuild( m_vecBuildOrigin, this ) )
return false;
if ( PointInNoBuild( m_vecBuildCenterOfMass, this ) )
return false;
// If we're receiving trigger hurt damage, don't allow building here.
if ( IsTakingTriggerHurtDamageAtPoint( m_vecBuildOrigin ) )
return false;
if ( IsTakingTriggerHurtDamageAtPoint( m_vecBuildCenterOfMass ) )
return false;
if ( PointInRespawnRoom( NULL, m_vecBuildOrigin ) && !g_pServerBenchmark->IsBenchmarkRunning() )
return false;
if ( PointInRespawnRoom( NULL, m_vecBuildCenterOfMass ) && !g_pServerBenchmark->IsBenchmarkRunning() )
return false;
Vector vecBuildFarEdge = m_vecBuildOrigin + m_vecBuildForward * ( m_flBuildDistance + 8.0f );
if ( PointsCrossRespawnRoomVisualizer( pPlayer->WorldSpaceCenter(), vecBuildFarEdge ) )
return false;
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseObject::DeterminePlaybackRate( void )
{
float flReverseBuildingConstructionSpeed = GetReversesBuildingConstructionSpeed();
if ( flReverseBuildingConstructionSpeed == 0.0f )
{
flReverseBuildingConstructionSpeed = 1.0f;
}
else
{
flReverseBuildingConstructionSpeed *= -1.0f;
}
// If a sapper was added or removed part way through construction we need to invert the time to completion
bool bAdjustCompleteTime = ( flReverseBuildingConstructionSpeed > 0.0f && GetPlaybackRate() < 0.0f ) ||
( flReverseBuildingConstructionSpeed < 0.0f && GetPlaybackRate() >= 0.0f );
if ( IsBuilding() )
{
// Default half rate, author build anim as if one player is building
// ConstructionMultiplier already contains the reverse
SetPlaybackRate( GetConstructionMultiplier() * 0.5 );
}
else
{
SetPlaybackRate( 1.0 * flReverseBuildingConstructionSpeed );
}
if ( bAdjustCompleteTime )
{
float fRelativeCycle = ( ( flReverseBuildingConstructionSpeed > 0.0f ) ? ( 1.0f - GetCycle() ) : ( GetCycle() ) );
float flUpgradeTime = GetUpgradeDuration();
flUpgradeTime /= ( ( flReverseBuildingConstructionSpeed < 0.0f ) ? ( flReverseBuildingConstructionSpeed * -1.0 ) : 1.0f );
m_flUpgradeCompleteTime = gpGlobals->curtime + flUpgradeTime * fRelativeCycle;
m_flTotalConstructionTime = m_flConstructionTimeLeft = GetTotalTime();
float flNewConstructionTimeLeft = m_flConstructionTimeLeft * fRelativeCycle;
m_flConstructionTimeLeft *= fRelativeCycle;
m_flConstructionStartTime += m_flConstructionTimeLeft - flNewConstructionTimeLeft;
m_flConstructionTimeLeft = flNewConstructionTimeLeft;
}
if ( !(m_fObjectFlags & OF_DOESNT_HAVE_A_MODEL) )
{
StudioFrameAdvance();
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFPlayer *CBaseObject::GetOwner()
{
return m_hBuilder;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseObject::SetBuilder( CTFPlayer *pBuilder )
{
TRACE_OBJECT( UTIL_VarArgs( "%0.2f CBaseObject::SetBuilder builder %s\n", gpGlobals->curtime,
pBuilder ? pBuilder->GetPlayerName() : "NULL" ) );
m_hBuilder = pBuilder;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CBaseObject::ObjectType( ) const
{
return m_iObjectType;
}
//-----------------------------------------------------------------------------
// Purpose: Destroys the object, gives a chance to spawn an explosion
//-----------------------------------------------------------------------------
void CBaseObject::DetonateObject( void )
{
// Blow us up.
CTakeDamageInfo info( this, this, vec3_origin, GetAbsOrigin(), 0, DMG_GENERIC );
Killed( info );
}
//-----------------------------------------------------------------------------
// Purpose: Remove this object from it's team and mark for deletion
//-----------------------------------------------------------------------------
void CBaseObject::DestroyObject( void )
{
TRACE_OBJECT( UTIL_VarArgs( "%0.2f CBaseObject::DestroyObject %p:%s\n", gpGlobals->curtime, this, GetClassname() ) );
// If we are carried, uncarry us before destruction.
if ( IsCarried() && GetBuilder() )
{
DropCarriedObject( GetBuilder() );
CTFWeaponBuilder *pBuilder = dynamic_cast<CTFWeaponBuilder*>( GetBuilder()->Weapon_OwnsThisID( TF_WEAPON_BUILDER ) );
if ( pBuilder )
{
pBuilder->SwitchOwnersWeaponToLast();
}
}
if ( GetBuilder() )
{
GetBuilder()->OwnedObjectDestroyed( this );
}
UTIL_Remove( this );
DestroyScreens();
}
//-----------------------------------------------------------------------------
// Purpose: Remove any screens that are active on this object
//-----------------------------------------------------------------------------
void CBaseObject::DestroyScreens( void )
{
// Kill the control panels
int i;
for ( i = m_hScreens.Count(); --i >= 0; )
{
DestroyVGuiScreen( m_hScreens[i].Get() );
}
m_hScreens.RemoveAll();
}
//-----------------------------------------------------------------------------
// Purpose: Get the total time it will take to build this object
//-----------------------------------------------------------------------------
float CBaseObject::GetTotalTime( void )
{
float flBuildTime = GetObjectInfo( ObjectType() )->m_flBuildTime;
CTFPlayer *pTFBuilder = GetBuilder();
if ( pTFBuilder )
{
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pTFBuilder, flBuildTime, mod_build_rate );
}
if ( tf_fastbuild.GetInt() )
return Min( flBuildTime, 2.f );
if ( TFGameRules()->IsQuickBuildTime() )
return Min( flBuildTime, 1.f );
return flBuildTime;
}
//-----------------------------------------------------------------------------
// Purpose: Start placing the object
//-----------------------------------------------------------------------------
void CBaseObject::StartPlacement( CTFPlayer *pPlayer )
{
AddSolidFlags( FSOLID_NOT_SOLID );
m_bPlacing = true;
m_bBuilding = false;
if ( pPlayer )
{
SetBuilder( pPlayer );
ChangeTeam( pPlayer->GetTeamNumber() );
}
// needed?
m_nRenderMode = kRenderNormal;
// Set my build size
CollisionProp()->WorldSpaceAABB( &m_vecBuildMins.GetForModify(), &m_vecBuildMaxs.GetForModify() );
m_vecBuildMins -= Vector( 4,4,0 );
m_vecBuildMaxs += Vector( 4,4,0 );
m_vecBuildMins -= GetAbsOrigin();
m_vecBuildMaxs -= GetAbsOrigin();
// Set the skin
m_nSkin = ( GetTeamNumber() == TF_TEAM_RED ) ? 0 : 1;
}
//-----------------------------------------------------------------------------
// Purpose: Stop placing the object
//-----------------------------------------------------------------------------
void CBaseObject::StopPlacement( void )
{
UTIL_Remove( this );
}
//-----------------------------------------------------------------------------
// Purpose: Find the nearest buildpoint on the specified entity
//-----------------------------------------------------------------------------
bool CBaseObject::FindNearestBuildPoint( CBaseEntity *pEntity, CBasePlayer *pBuilder, float &flNearestPoint, Vector &vecNearestBuildPoint, bool bIgnoreChecks )
{
bool bFoundPoint = false;
IHasBuildPoints *pBPInterface = dynamic_cast<IHasBuildPoints*>(pEntity);
Assert( pBPInterface );
// Any empty buildpoints?
for ( int i = 0; i < pBPInterface->GetNumBuildPoints(); i++ )
{
// Can this object build on this point?
if ( pBPInterface->CanBuildObjectOnBuildPoint( i, GetType() ) )
{
// Close to this point?
Vector vecBPOrigin;
QAngle vecBPAngles;
if ( pBPInterface->GetBuildPoint(i, vecBPOrigin, vecBPAngles) )
{
if ( !bIgnoreChecks )
{
// ignore build points outside our view
if ( !pBuilder->FInViewCone( vecBPOrigin ) )
continue;
// Do a trace to make sure we don't place attachments through things (players, world, etc...)
Vector vecStart = pBuilder->EyePosition();
trace_t trace;
CTraceFilterNoNPCsOrPlayer ignorePlayersFilter( pBuilder, COLLISION_GROUP_NONE );
UTIL_TraceLine( vecStart, vecBPOrigin, MASK_SOLID, &ignorePlayersFilter, &trace );
if ( trace.m_pEnt != pEntity && trace.fraction != 1.0 )
continue;
}
float flDist = (vecBPOrigin - pBuilder->GetAbsOrigin()).Length();
// if this is closer, or is the first one in our view, check it out
if ( bIgnoreChecks || ( flDist < Min( flNearestPoint, pBPInterface->GetMaxSnapDistance( i ) ) ) )
{
flNearestPoint = flDist;
vecNearestBuildPoint = vecBPOrigin;
m_hBuiltOnEntity = pEntity;
m_iBuiltOnPoint = i;
// Set our angles to the buildpoint's angles
SetAbsAngles( vecBPAngles );
bFoundPoint = true;
}
}
}
}
return bFoundPoint;
}
//-----------------------------------------------------------------------------
// Purpose: Find a buildpoint on the specified player
//-----------------------------------------------------------------------------
bool CBaseObject::FindBuildPointOnPlayer( CTFPlayer *pTFPlayer, CBasePlayer *pBuilder, float &flNearestPoint, Vector &vecNearestBuildPoint )
{
bool bFoundPoint = false;
if ( !pTFPlayer )
return false;
if ( pTFPlayer->m_Shared.InCond( TF_COND_SAPPED ) )
return false;
if ( pTFPlayer->m_Shared.IsInvulnerable() )
return false;
if ( pTFPlayer->m_Shared.InCond( TF_COND_PHASE ) )
return false;
Vector vecOrigin = pTFPlayer->GetAbsOrigin();
QAngle vecAngles = pTFPlayer->GetAbsAngles();
float flDist = ( vecOrigin - pBuilder->GetAbsOrigin() ).Length();
if ( flDist <= 160.f )
{
flNearestPoint = flDist;
vecNearestBuildPoint = vecOrigin;
m_hBuiltOnEntity = (CBaseEntity *)pTFPlayer;
// Set our angles to the buildpoint's angles