aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/server/waterbullet.cpp
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
committerJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
commit39ed87570bdb2f86969d4be821c94b722dc71179 (patch)
treeabc53757f75f40c80278e87650ea92808274aa59 /mp/src/game/server/waterbullet.cpp
downloadsource-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz
source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/game/server/waterbullet.cpp')
-rw-r--r--mp/src/game/server/waterbullet.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/mp/src/game/server/waterbullet.cpp b/mp/src/game/server/waterbullet.cpp
new file mode 100644
index 00000000..904867ea
--- /dev/null
+++ b/mp/src/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 );
+}