summaryrefslogtreecommitdiff
path: root/game/shared/tf2/plasmaprojectile_shared.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/shared/tf2/plasmaprojectile_shared.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/shared/tf2/plasmaprojectile_shared.cpp')
-rw-r--r--game/shared/tf2/plasmaprojectile_shared.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/game/shared/tf2/plasmaprojectile_shared.cpp b/game/shared/tf2/plasmaprojectile_shared.cpp
new file mode 100644
index 0000000..8bbe622
--- /dev/null
+++ b/game/shared/tf2/plasmaprojectile_shared.cpp
@@ -0,0 +1,72 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+#include "cbase.h"
+#include "plasmaprojectile_shared.h"
+
+#define PLASMA_LIFETIME 2.0
+
+ConVar plasma_gravity( "plasma_gravity","1000", FCVAR_REPLICATED, "Plasma gravity" );
+ConVar plasma_drag( "plasma_drag","2", FCVAR_REPLICATED, "Plasma drag" );
+
+
+//-----------------------------------------------------------------------------
+// Setup state needed to perform the physics computation
+//-----------------------------------------------------------------------------
+void CPlasmaProjectileShared::Init( const Vector &vecStart, const Vector &vecDir, float flSpawnSpeed )
+{
+ m_vecSpawnPosition = vecStart;
+ m_vTracerDir = vecDir;
+ m_flSpawnSpeed = flSpawnSpeed;
+}
+
+void CPlasmaProjectileShared::SetSpawnTime( float flSpawnTime )
+{
+ m_flSpawnTime = flSpawnTime;
+}
+
+void CPlasmaProjectileShared::SetDeathTime( float flDeathTime )
+{
+ m_flDeathTime = flDeathTime;
+}
+
+
+//-----------------------------------------------------------------------------
+// Perform custom physics on this dude (when we're in ballistic mode)
+//-----------------------------------------------------------------------------
+void CPlasmaProjectileShared::ComputePosition( float flTime, Vector *pNewPosition, Vector *pNewVelocity, QAngle *pNewAngles, QAngle *pNewAngVelocity )
+{
+ float flLifeTime = flTime - m_flSpawnTime;
+ if (flLifeTime < 0)
+ return;
+
+ // Travel ballistically until we run out of juice..
+ if (flTime <= m_flDeathTime)
+ {
+ VectorMultiply( m_vTracerDir, m_flSpawnSpeed, *pNewVelocity );
+ VectorMA( m_vecSpawnPosition, flLifeTime, *pNewVelocity, *pNewPosition );
+ }
+ else
+ {
+ VectorMultiply( m_vTracerDir, m_flSpawnSpeed, *pNewVelocity );
+ VectorMA( m_vecSpawnPosition, m_flDeathTime - m_flSpawnTime, *pNewVelocity, *pNewPosition );
+
+ // Ran out of juice... fall!
+ float flFallTime = flTime - m_flDeathTime;
+
+ float flDragFactor = exp( -plasma_drag.GetFloat() * flFallTime );
+ *pNewVelocity *= flDragFactor;
+
+ float flDist = (m_flSpawnSpeed / plasma_drag.GetFloat()) * ( 1.0f - flDragFactor );
+ VectorMA( *pNewPosition, flDist, m_vTracerDir, *pNewPosition );
+
+ // Add in the effects of gravity!
+ pNewVelocity->z -= flFallTime * plasma_gravity.GetFloat();
+ pNewPosition->z -= 0.5f * plasma_gravity.GetFloat() * flFallTime * flFallTime;
+ }
+}
+
+