summaryrefslogtreecommitdiff
path: root/game/server/waterbullet.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/server/waterbullet.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/server/waterbullet.cpp')
-rw-r--r--game/server/waterbullet.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/game/server/waterbullet.cpp b/game/server/waterbullet.cpp
new file mode 100644
index 0000000..d5e726f
--- /dev/null
+++ b/game/server/waterbullet.cpp
@@ -0,0 +1,107 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: An effect for a single bullet passing through a body of water.
+// The slug quickly decelerates, leaving a trail of bubbles behind it.
+//
+// TODO: make clientside
+//
+//=============================================================================//
+#include "cbase.h"
+#include "waterbullet.h"
+#include "ndebugoverlay.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+#define WATERBULLET_INITIAL_SPEED 1000.0
+#define WATERBULLET_STOP_TIME 0.5 // how long it takes a bullet in water to come to a stop!
+
+#define WATERBULLET_DECAY ( WATERBULLET_INITIAL_SPEED / WATERBULLET_STOP_TIME )
+
+BEGIN_DATADESC( CWaterBullet )
+
+ // Function Pointers
+ DEFINE_FUNCTION( Touch ),
+ DEFINE_FUNCTION( BulletThink ),
+
+END_DATADESC()
+
+LINK_ENTITY_TO_CLASS( waterbullet, CWaterBullet );
+
+IMPLEMENT_SERVERCLASS_ST( CWaterBullet, DT_WaterBullet )
+END_SEND_TABLE()
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CWaterBullet::Precache()
+{
+ PrecacheModel( "models/weapons/w_bullet.mdl" );
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CWaterBullet::Spawn( const Vector &vecOrigin, const Vector &vecDir )
+{
+ Precache();
+
+ SetSolid( SOLID_BBOX );
+ SetModel( "models/weapons/w_bullet.mdl" );
+ UTIL_SetSize( this, vec3_origin, vec3_origin );
+
+ SetMoveType( MOVETYPE_FLY );
+
+ SetGravity( 0.0 );
+
+ QAngle angles;
+ SetAbsOrigin( vecOrigin );
+
+ SetAbsVelocity( vecDir * 1500.0f );
+ VectorAngles( GetAbsVelocity(), angles );
+ SetAbsAngles( angles );
+
+ SetCollisionGroup( COLLISION_GROUP_DEBRIS );
+ SetTouch( &CWaterBullet::Touch );
+
+ SetThink( &CWaterBullet::BulletThink );
+ SetNextThink( gpGlobals->curtime );
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+void CWaterBullet::BulletThink()
+{
+ //NDebugOverlay::Line( GetAbsOrigin(), GetAbsOrigin() - GetAbsVelocity() * 0.1, 255, 255, 255, false, 1 );
+ SetNextThink( gpGlobals->curtime + 0.05 );
+
+/*
+ QAngle angles = GetAbsAngles();
+ angles.x += random->RandomInt( -6, 6 );
+ angles.y += random->RandomInt( -6, 6 );
+ SetAbsAngles( angles );
+*/
+
+ Vector forward;
+ AngleVectors( GetAbsAngles(), &forward );
+ SetAbsVelocity( forward * 1500.0f );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CWaterBullet::Touch( CBaseEntity *pOther )
+{
+ Vector vecDir = GetAbsVelocity();
+ float speed = VectorNormalize( vecDir );
+
+ Vector vecStart = GetAbsOrigin() - ( vecDir * 8 );
+ Vector vecEnd = GetAbsOrigin() + ( vecDir * speed );
+
+ trace_t tr;
+ UTIL_TraceLine( vecStart, vecEnd, MASK_SHOT, NULL, &tr );
+ UTIL_ImpactTrace( &tr, DMG_BULLET );
+
+ UTIL_Remove( this );
+}