diff --git a/cl_dll/tri.cpp b/cl_dll/tri.cpp index b5a1631ce..5f349a623 100644 --- a/cl_dll/tri.cpp +++ b/cl_dll/tri.cpp @@ -141,7 +141,7 @@ static void RenderFogImpl(short r, short g, short b, float startDist, float endD void RenderFog ( void ) { const FogProperties& fog = gHUD.fog; - bool bFog = g_iWaterLevel < 3 && (fog.endDist > 0 || fog.density > 0); + bool bFog = g_iWaterLevel < WL_Eyes && (fog.endDist > 0 || fog.density > 0); if (bFog) { RenderFogImpl(fog.r,fog.g,fog.b, fog.startDist, fog.endDist, fog.affectSkybox, fog.density, fog.type); diff --git a/cl_dll/view.cpp b/cl_dll/view.cpp index a50febfbd..62d95a2cc 100644 --- a/cl_dll/view.cpp +++ b/cl_dll/view.cpp @@ -482,7 +482,7 @@ void V_CalcNormalRefdef( struct ref_params_s *pparams ) // -- this prevents drawing errors in GL due to waves waterOffset = 0; - if( pparams->waterlevel >= 2 ) + if( pparams->waterlevel >= WL_Waist ) { int contents, waterDist, waterEntity; Vector point; @@ -508,7 +508,7 @@ void V_CalcNormalRefdef( struct ref_params_s *pparams ) VectorCopy( pparams->vieworg, point ); // Eyes are above water, make sure we're above the waves - if( pparams->waterlevel == 2 ) + if( pparams->waterlevel == WL_Waist ) { point[2] -= waterDist; for( i = 0; i < waterDist; i++ ) diff --git a/common/const.h b/common/const.h index c294f9b8e..c4019bf5e 100644 --- a/common/const.h +++ b/common/const.h @@ -20,6 +20,7 @@ #include "vector.h" #include "const_render.h" #include "const_sound.h" +#include "const_waterlevel.h" // // Constants shared by the engine and dlls diff --git a/common/const_waterlevel.h b/common/const_waterlevel.h new file mode 100644 index 000000000..b04713329 --- /dev/null +++ b/common/const_waterlevel.h @@ -0,0 +1,10 @@ +#pragma once +#ifndef WATERLEVEL_H +#define WATERLEVEL_H + +#define WL_NotInWater 0 +#define WL_Feet 1 +#define WL_Waist 2 +#define WL_Eyes 3 + +#endif diff --git a/dlls/combat.cpp b/dlls/combat.cpp index be535d9c9..01381ce9f 100644 --- a/dlls/combat.cpp +++ b/dlls/combat.cpp @@ -1399,8 +1399,7 @@ BOOL CBaseEntity::FVisible( CBaseEntity *pEntity ) return FALSE; // don't look through water - if( ( pev->waterlevel != 3 && pEntity->pev->waterlevel == 3 ) - || ( pev->waterlevel == 3 && pEntity->pev->waterlevel == 0 ) ) + if( LineOfSightSeparatedByWaterSurface(pev->waterlevel, pEntity->pev->waterlevel) ) return FALSE; vecLookerOrigin = pev->origin + pev->view_ofs;//look through the caller's 'eyes' diff --git a/dlls/combat.h b/dlls/combat.h index f4457a812..eae49f821 100644 --- a/dlls/combat.h +++ b/dlls/combat.h @@ -75,9 +75,9 @@ void RadiusDamage(CBaseEntity* pLooker, Vector vecSrc, entvars_t *pevInflictor, // blast's don't tavel into or out of water if (flags & RADIUSDAMAGE_DONT_TRAVEL_THROUGH_WATER) { - if( bInWater && pEntity->pev->waterlevel == 0 ) + if( bInWater && pEntity->pev->waterlevel == WL_NotInWater ) continue; - if( !bInWater && pEntity->pev->waterlevel == 3 ) + if( !bInWater && pEntity->pev->waterlevel == WL_Eyes ) continue; } diff --git a/dlls/eagle.cpp b/dlls/eagle.cpp index 0a7233117..af0ca1cfc 100644 --- a/dlls/eagle.cpp +++ b/dlls/eagle.cpp @@ -143,7 +143,7 @@ void CEagle::PrimaryAttack() } // don't fire underwater - if (m_pPlayer->pev->waterlevel == 3) + if (m_pPlayer->pev->waterlevel == WL_Eyes) { PlayEmptySound( ); m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.15f; diff --git a/dlls/egon.cpp b/dlls/egon.cpp index ed362f21d..43b91a229 100644 --- a/dlls/egon.cpp +++ b/dlls/egon.cpp @@ -138,7 +138,7 @@ void CEgon::UseAmmo( int count ) void CEgon::Attack( void ) { // don't fire underwater - if( m_pPlayer->pev->waterlevel == 3 ) + if( m_pPlayer->pev->waterlevel == WL_Eyes ) { if( m_fireState != FIRE_OFF #if !CLIENT_DLL diff --git a/dlls/fgrunt.cpp b/dlls/fgrunt.cpp index 0459ed1b6..2bfb5d379 100644 --- a/dlls/fgrunt.cpp +++ b/dlls/fgrunt.cpp @@ -1488,7 +1488,7 @@ BOOL CHFGrunt::CheckRangeAttack2Impl( float grenadeSpeed, float flDot, float flD return m_fThrowGrenade; } - if ( !FBitSet ( m_hEnemy->pev->flags, FL_ONGROUND ) && m_hEnemy->pev->waterlevel == 0 && m_vecEnemyLKP.z > pev->absmax.z ) + if ( !FBitSet ( m_hEnemy->pev->flags, FL_ONGROUND ) && m_hEnemy->pev->waterlevel == WL_NotInWater && m_vecEnemyLKP.z > pev->absmax.z ) { //!!!BUGBUG - we should make this check movetype and make sure it isn't FLY? Players who jump a lot are unlikely to // be grenaded. diff --git a/dlls/func_break.cpp b/dlls/func_break.cpp index 750943a2a..30a513219 100644 --- a/dlls/func_break.cpp +++ b/dlls/func_break.cpp @@ -1094,7 +1094,7 @@ void CPushable::Move( CBaseEntity *pOther, int push ) if( FBitSet( pevToucher->flags,FL_ONGROUND ) && pevToucher->groundentity && VARS( pevToucher->groundentity ) == pev ) { // Only push if floating - if( pev->waterlevel > 0 ) + if( pev->waterlevel > WL_NotInWater ) pev->velocity.z += pevToucher->velocity.z * 0.1f; return; @@ -1130,7 +1130,7 @@ void CPushable::Move( CBaseEntity *pOther, int push ) { if( !( pevToucher->flags & FL_ONGROUND ) ) // Don't push away from jumping/falling players unless in water { - if( pev->waterlevel < 1 ) + if( pev->waterlevel < WL_Feet ) return; else factor = 0.1f; diff --git a/dlls/gauss.cpp b/dlls/gauss.cpp index 26e1ba51c..ea64abf62 100644 --- a/dlls/gauss.cpp +++ b/dlls/gauss.cpp @@ -118,7 +118,7 @@ void CGauss::Holster() void CGauss::PrimaryAttack() { // don't fire underwater - if( m_pPlayer->pev->waterlevel == 3 ) + if( m_pPlayer->pev->waterlevel == WL_Eyes ) { PlayEmptySound(); m_flNextSecondaryAttack = m_flNextPrimaryAttack = GetNextAttackDelay( 0.15f ); @@ -148,7 +148,7 @@ void CGauss::SecondaryAttack() if( m_pPlayer->m_flStartCharge > gpGlobals->time ) m_pPlayer->m_flStartCharge = gpGlobals->time; // don't fire underwater - if( m_pPlayer->pev->waterlevel == 3 ) + if( m_pPlayer->pev->waterlevel == WL_Eyes ) { if( m_fInAttack != 0 ) { diff --git a/dlls/ggrenade.cpp b/dlls/ggrenade.cpp index 133263ff6..9e52c4593 100644 --- a/dlls/ggrenade.cpp +++ b/dlls/ggrenade.cpp @@ -218,7 +218,7 @@ void CGrenade::DangerSoundThink( void ) CSoundEnt::InsertSound( bits_SOUND_DANGER, pev->origin + pev->velocity * 0.5f, pev->dmg * DEFAULT_EXPLOSION_RADIUS_MULTIPLIER, 0.2 ); pev->nextthink = gpGlobals->time + 0.2f; - if( pev->waterlevel != 0 ) + if( pev->waterlevel != WL_NotInWater ) { pev->velocity = pev->velocity * 0.5f; } @@ -334,7 +334,7 @@ void CGrenade::TumbleThink( void ) { SetThink( &CGrenade::Detonate ); } - if( pev->waterlevel != 0 ) + if( pev->waterlevel != WL_NotInWater ) { pev->velocity = pev->velocity * 0.5f; pev->framerate = 0.2f; diff --git a/dlls/h_ai.cpp b/dlls/h_ai.cpp index 0cc5d3060..5a70df7ae 100644 --- a/dlls/h_ai.cpp +++ b/dlls/h_ai.cpp @@ -47,8 +47,7 @@ DLL_GLOBAL BOOL g_fDrawLines = FALSE; BOOL FBoxVisible( entvars_t *pevLooker, entvars_t *pevTarget, Vector &vecTargetOrigin, float flSize ) { // don't look through water - if( ( pevLooker->waterlevel != 3 && pevTarget->waterlevel == 3 ) - || ( pevLooker->waterlevel == 3 && pevTarget->waterlevel == 0 ) ) + if( LineOfSightSeparatedByWaterSurface(pevLooker->waterlevel, pevTarget->waterlevel) ) return FALSE; TraceResult tr; diff --git a/dlls/hgrunt.cpp b/dlls/hgrunt.cpp index 1473877df..f0b932ed0 100644 --- a/dlls/hgrunt.cpp +++ b/dlls/hgrunt.cpp @@ -457,7 +457,7 @@ BOOL CHGrunt::CheckRangeAttack2Impl( float grenadeSpeed, float flDot, float flDi return m_fThrowGrenade; } - if( !FBitSet ( m_hEnemy->pev->flags, FL_ONGROUND ) && m_hEnemy->pev->waterlevel == 0 && m_vecEnemyLKP.z > pev->absmax.z ) + if( !FBitSet ( m_hEnemy->pev->flags, FL_ONGROUND ) && m_hEnemy->pev->waterlevel == WL_NotInWater && m_vecEnemyLKP.z > pev->absmax.z ) { //!!!BUGBUG - we should make this check movetype and make sure it isn't FLY? Players who jump a lot are unlikely to // be grenaded. diff --git a/dlls/ichthyosaur.cpp b/dlls/ichthyosaur.cpp index dedb42271..724d59671 100644 --- a/dlls/ichthyosaur.cpp +++ b/dlls/ichthyosaur.cpp @@ -739,7 +739,7 @@ void CIchthyosaur::RunTask( Task_t *pTask ) case TASK_ICHTHYOSAUR_FLOAT: pev->angles.x = UTIL_ApproachAngle( 0, pev->angles.x, 20 ); pev->velocity = pev->velocity * 0.8f; - if( pev->waterlevel > 1 && pev->velocity.z < 64 ) + if( pev->waterlevel > WL_Feet && pev->velocity.z < 64 ) { pev->velocity.z += 8; } diff --git a/dlls/leech.cpp b/dlls/leech.cpp index e5e3da20f..1054059f1 100644 --- a/dlls/leech.cpp +++ b/dlls/leech.cpp @@ -263,7 +263,7 @@ void CLeech::SwitchLeechState( void ) { Look( m_flDistLook ); CBaseEntity *pEnemy = BestVisibleEnemy(); - if( pEnemy && pEnemy->pev->waterlevel != 0 ) + if( pEnemy && pEnemy->pev->waterlevel != WL_NotInWater ) { m_hEnemy = pEnemy; SetState( MONSTERSTATE_COMBAT ); diff --git a/dlls/m249.cpp b/dlls/m249.cpp index 280be9159..5b5aca3bc 100644 --- a/dlls/m249.cpp +++ b/dlls/m249.cpp @@ -118,7 +118,7 @@ void CM249::Holster() void CM249::PrimaryAttack() { // don't fire underwater - if (m_pPlayer->pev->waterlevel == 3) + if (m_pPlayer->pev->waterlevel == WL_Eyes) { PlayEmptySound(); m_flNextPrimaryAttack = 0.15; diff --git a/dlls/mp5.cpp b/dlls/mp5.cpp index 2fead4c7f..c59e948eb 100644 --- a/dlls/mp5.cpp +++ b/dlls/mp5.cpp @@ -103,7 +103,7 @@ BOOL CMP5::Deploy() void CMP5::PrimaryAttack() { // don't fire underwater - if( m_pPlayer->pev->waterlevel == 3 ) + if( m_pPlayer->pev->waterlevel == WL_Eyes ) { PlayEmptySound(); m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.15f; @@ -157,7 +157,7 @@ void CMP5::PrimaryAttack() void CMP5::SecondaryAttack( void ) { // don't fire underwater - if( m_pPlayer->pev->waterlevel == 3 ) + if( m_pPlayer->pev->waterlevel == WL_Eyes ) { PlayEmptySound( ); m_flNextPrimaryAttack = 0.15f; diff --git a/dlls/nodes.cpp b/dlls/nodes.cpp index caea96e36..b906313a4 100644 --- a/dlls/nodes.cpp +++ b/dlls/nodes.cpp @@ -417,7 +417,7 @@ int CGraph::NodeType( const CBaseEntity *pEntity ) { if( pEntity->pev->movetype == MOVETYPE_FLY ) { - if( pEntity->pev->waterlevel != 0 ) + if( pEntity->pev->waterlevel != WL_NotInWater ) { return bits_NODE_WATER; } diff --git a/dlls/pitworm.cpp b/dlls/pitworm.cpp index 7f7aaa6c1..ce2a896a4 100644 --- a/dlls/pitworm.cpp +++ b/dlls/pitworm.cpp @@ -394,8 +394,7 @@ BOOL CPitWorm::FVisible(CBaseEntity *pEntity) if( FBitSet( pEntity->pev->flags, FL_NOTARGET ) ) return FALSE; - if( ( pev->waterlevel != 3 && pEntity->pev->waterlevel == 3 ) - || ( pev->waterlevel == 3 && pEntity->pev->waterlevel == 0 ) ) + if( LineOfSightSeparatedByWaterSurface(pev->waterlevel, pEntity->pev->waterlevel) ) return FALSE; TraceResult tr; @@ -1408,7 +1407,7 @@ void CPitwormGib::Spawn() void CPitwormGib::GibFloat() { - if (pev->waterlevel == 3) + if (pev->waterlevel == WL_Eyes) { pev->movetype = MOVETYPE_FLY; pev->velocity = pev->velocity * 0.8; diff --git a/dlls/player.cpp b/dlls/player.cpp index 8e340e178..5d9287b80 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -1307,7 +1307,7 @@ void CBasePlayer::SetAnimation( PLAYER_ANIM playerAnim ) { m_IdealActivity = m_Activity; } - else if( pev->waterlevel > 1 ) + else if( pev->waterlevel > WL_Feet ) { if( speed == 0 ) m_IdealActivity = ACT_HOVER; @@ -1323,7 +1323,7 @@ void CBasePlayer::SetAnimation( PLAYER_ANIM playerAnim ) { if (FBitSet(pev->flags, FL_ONGROUND)) { - if (pev->waterlevel > 1) + if (pev->waterlevel > WL_Feet) { if (speed == 0) m_IdealActivity = ACT_HOVER; @@ -1473,7 +1473,7 @@ void CBasePlayer::WaterMove() // waterlevel 2 - waist in water // waterlevel 3 - head in water - if( pev->waterlevel != 3 ) + if( pev->waterlevel != WL_Eyes ) { // not underwater @@ -1540,7 +1540,7 @@ void CBasePlayer::WaterMove() } // make bubbles - if( pev->waterlevel == 3 ) + if( pev->waterlevel == WL_Eyes ) { air = (int)( pev->air_finished - gpGlobals->time ); if( !RANDOM_LONG( 0, 0x1f ) && RANDOM_LONG( 0, AIRTIME - 1 ) >= air ) @@ -2108,7 +2108,7 @@ void CBasePlayer::Jump() if( FBitSet( pev->flags, FL_WATERJUMP ) ) return; - if( pev->waterlevel >= 2 ) + if( pev->waterlevel >= WL_Waist ) { return; } @@ -3558,7 +3558,7 @@ void CBasePlayer::PostThink() SetAnimation( PLAYER_IDLE ); else if( ( pev->velocity.x || pev->velocity.y ) && ( FBitSet( pev->flags, FL_ONGROUND ) ) ) SetAnimation( PLAYER_WALK ); - else if( pev->waterlevel > 1 ) + else if( pev->waterlevel > WL_Feet ) SetAnimation( PLAYER_WALK ); } @@ -5751,7 +5751,7 @@ Vector CBasePlayer::AutoaimDeflection( const Vector &vecSrc, float flDist, float if( tr.pHit && tr.pHit->v.takedamage != DAMAGE_NO ) { // don't look through water - if( !( ( pev->waterlevel != 3 && tr.pHit->v.waterlevel == 3 ) || ( pev->waterlevel == 3 && tr.pHit->v.waterlevel == 0 ) ) ) + if( !LineOfSightSeparatedByWaterSurface(pev->waterlevel, tr.pHit->v.waterlevel) ) { if( tr.pHit->v.takedamage == DAMAGE_AIM ) m_fOnTarget = TRUE; @@ -5786,7 +5786,7 @@ Vector CBasePlayer::AutoaimDeflection( const Vector &vecSrc, float flDist, float continue; // don't look through water - if( ( pev->waterlevel != 3 && pEntity->pev->waterlevel == 3 ) || ( pev->waterlevel == 3 && pEntity->pev->waterlevel == 0 ) ) + if( LineOfSightSeparatedByWaterSurface(pev->waterlevel, pEntity->pev->waterlevel) ) continue; center = pEntity->BodyTarget( vecSrc ); diff --git a/dlls/python.cpp b/dlls/python.cpp index f6f625a93..a9938bed8 100644 --- a/dlls/python.cpp +++ b/dlls/python.cpp @@ -128,7 +128,7 @@ void CPython::SecondaryAttack( void ) void CPython::PrimaryAttack() { // don't fire underwater - if( m_pPlayer->pev->waterlevel == 3 ) + if( m_pPlayer->pev->waterlevel == WL_Eyes ) { PlayEmptySound(); m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.15f; diff --git a/dlls/shockbeam.cpp b/dlls/shockbeam.cpp index 2f2400d06..fc464f1d0 100644 --- a/dlls/shockbeam.cpp +++ b/dlls/shockbeam.cpp @@ -101,7 +101,7 @@ void CShock::Precache() void CShock::FlyThink() { - if (pev->waterlevel == 3) + if (pev->waterlevel == WL_Eyes) { entvars_t *pevOwner = VARS(pev->owner); EmitSoundScript(impactSoundScript); diff --git a/dlls/shockrifle.cpp b/dlls/shockrifle.cpp index 30ee47620..fb277530d 100644 --- a/dlls/shockrifle.cpp +++ b/dlls/shockrifle.cpp @@ -150,7 +150,7 @@ void CShockrifle::PrimaryAttack() if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0) return; - if (m_pPlayer->pev->waterlevel == 3) + if (m_pPlayer->pev->waterlevel == WL_Eyes) { #if !CLIENT_DLL int attenuation = 150 * m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]; diff --git a/dlls/shotgun.cpp b/dlls/shotgun.cpp index 532e354e2..deff739ea 100644 --- a/dlls/shotgun.cpp +++ b/dlls/shotgun.cpp @@ -96,7 +96,7 @@ BOOL CShotgun::Deploy() void CShotgun::PrimaryAttack() { // don't fire underwater - if( m_pPlayer->pev->waterlevel == 3 ) + if( m_pPlayer->pev->waterlevel == WL_Eyes ) { PlayEmptySound(); m_flNextPrimaryAttack = GetNextAttackDelay( 0.15f ); @@ -163,7 +163,7 @@ void CShotgun::PrimaryAttack() void CShotgun::SecondaryAttack( void ) { // don't fire underwater - if( m_pPlayer->pev->waterlevel == 3 ) + if( m_pPlayer->pev->waterlevel == WL_Eyes ) { PlayEmptySound(); m_flNextPrimaryAttack = GetNextAttackDelay( 0.15f ); diff --git a/dlls/sniperrifle.cpp b/dlls/sniperrifle.cpp index 01e6c4783..061742994 100644 --- a/dlls/sniperrifle.cpp +++ b/dlls/sniperrifle.cpp @@ -141,7 +141,7 @@ void CSniperrifle::PrimaryAttack() } // don't fire underwater - if (m_pPlayer->pev->waterlevel == 3) + if (m_pPlayer->pev->waterlevel == WL_Eyes) { PlayEmptySound( ); m_flNextPrimaryAttack = 0.15f; diff --git a/dlls/util.h b/dlls/util.h index 7814afa4e..76adc329d 100644 --- a/dlls/util.h +++ b/dlls/util.h @@ -595,6 +595,11 @@ float RandomizeNumberFromRange(float minF, float maxF); int RandomizeNumberFromRange(const IntRange& r); int RandomizeNumberFromRange(int minI, int maxI); +inline bool LineOfSightSeparatedByWaterSurface(int lookerWaterlevel, int targetWaterlevel) +{ + return (lookerWaterlevel != WL_Eyes && targetWaterlevel == WL_Eyes) || (lookerWaterlevel == WL_Eyes && targetWaterlevel == WL_NotInWater); +} + void ReportAIStateByClassname(const char* name); inline Vector VectorFromColor(const Color& color) { diff --git a/dlls/uzi.cpp b/dlls/uzi.cpp index 55be1f4dd..822f8932e 100644 --- a/dlls/uzi.cpp +++ b/dlls/uzi.cpp @@ -111,7 +111,7 @@ BOOL CUzi::Deploy() void CUzi::PrimaryAttack() { // don't fire underwater - if( m_pPlayer->pev->waterlevel == 3 ) + if( m_pPlayer->pev->waterlevel == WL_Eyes ) { PlayEmptySound(); m_flNextPrimaryAttack = 0.15;