diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/server/tf2/tf_obj_rallyflag.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'game/server/tf2/tf_obj_rallyflag.cpp')
| -rw-r--r-- | game/server/tf2/tf_obj_rallyflag.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/game/server/tf2/tf_obj_rallyflag.cpp b/game/server/tf2/tf_obj_rallyflag.cpp new file mode 100644 index 0000000..8cc9bf9 --- /dev/null +++ b/game/server/tf2/tf_obj_rallyflag.cpp @@ -0,0 +1,108 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// +#include "cbase.h" +#include "tf_player.h" +#include "tf_team.h" +#include "tf_gamerules.h" +#include "tf_obj.h" +#include "tf_obj_rallyflag.h" +#include "ndebugoverlay.h" + +BEGIN_DATADESC( CObjectRallyFlag ) + + DEFINE_THINKFUNC( RallyThink ), + +END_DATADESC() + +IMPLEMENT_SERVERCLASS_ST(CObjectRallyFlag, DT_ObjectRallyFlag) +END_SEND_TABLE(); + +LINK_ENTITY_TO_CLASS(obj_rallyflag, CObjectRallyFlag); +PRECACHE_REGISTER(obj_rallyflag); + +ConVar obj_rallyflag_health( "obj_rallyflag_health","100", FCVAR_NONE, "Rally Flag health" ); + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +CObjectRallyFlag::CObjectRallyFlag() +{ + UseClientSideAnimation(); +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CObjectRallyFlag::Spawn() +{ + Precache(); + SetModel( RALLYFLAG_MODEL ); + SetSolid( SOLID_BBOX ); + SetCollisionGroup( TFCOLLISION_GROUP_COMBATOBJECT ); + + UTIL_SetSize(this, RALLYFLAG_MINS, RALLYFLAG_MAXS); + m_takedamage = DAMAGE_YES; + m_iHealth = obj_rallyflag_health.GetInt(); + + SetThink( RallyThink ); + SetNextThink( gpGlobals->curtime + 0.1f ); + m_flExpiresAt = gpGlobals->curtime + RALLYFLAG_LIFETIME; + + SetType( OBJ_RALLYFLAG ); + m_fObjectFlags |= OF_SUPPRESS_NOTIFY_UNDER_ATTACK | OF_SUPPRESS_TECH_ANALYZER | + OF_DONT_AUTO_REPAIR | OF_DONT_PREVENT_BUILD_NEAR_OBJ | OF_DOESNT_NEED_POWER; + + BaseClass::Spawn(); +} + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +void CObjectRallyFlag::Precache() +{ + PrecacheModel( RALLYFLAG_MODEL ); +} + + +//----------------------------------------------------------------------------- +// Purpose: Look for friendlies to rally +//----------------------------------------------------------------------------- +void CObjectRallyFlag::RallyThink( void ) +{ + if ( !GetTeam() ) + return; + + // Time to die? + if ( gpGlobals->curtime > m_flExpiresAt ) + { + UTIL_Remove( this ); + return; + } + + // Look for nearby players to rally + for ( int i = 0; i < GetTFTeam()->GetNumPlayers(); i++ ) + { + CBaseTFPlayer *pPlayer = (CBaseTFPlayer *)GetTFTeam()->GetPlayer(i); + assert(pPlayer); + + // Is it within range? + if ( ((pPlayer->GetAbsOrigin() - GetAbsOrigin()).Length() < RALLYFLAG_RADIUS ) && pPlayer->IsAlive() ) + { + // Can I see it? + trace_t tr; + UTIL_TraceLine( EyePosition(), pPlayer->EyePosition(), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr); + CBaseEntity *pEntity = tr.m_pEnt; + if ( (tr.fraction == 1.0) || ( pEntity == pPlayer ) ) + { + pPlayer->AttemptToPowerup( POWERUP_RUSH, RALLYFLAG_ADRENALIN_TIME ); + } + } + } + + SetNextThink( gpGlobals->curtime + RALLYFLAG_RATE ); +} + |