Skip to content

Commit

Permalink
Replace waterlevel magic constants with named ones. Add LineOfSightSe…
Browse files Browse the repository at this point in the history
…paratedByWaterSurface to deduplicate some checks
  • Loading branch information
FreeSlave committed Nov 25, 2024
1 parent 1803925 commit 252d7f5
Show file tree
Hide file tree
Showing 28 changed files with 56 additions and 43 deletions.
2 changes: 1 addition & 1 deletion cl_dll/tri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions cl_dll/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++ )
Expand Down
1 change: 1 addition & 0 deletions common/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions common/const_waterlevel.h
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions dlls/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions dlls/combat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion dlls/eagle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dlls/egon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dlls/fgrunt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions dlls/func_break.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions dlls/gauss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 )
{
Expand Down
4 changes: 2 additions & 2 deletions dlls/ggrenade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions dlls/h_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dlls/hgrunt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion dlls/ichthyosaur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion dlls/leech.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion dlls/m249.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions dlls/mp5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dlls/nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions dlls/pitworm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -2108,7 +2108,7 @@ void CBasePlayer::Jump()
if( FBitSet( pev->flags, FL_WATERJUMP ) )
return;

if( pev->waterlevel >= 2 )
if( pev->waterlevel >= WL_Waist )
{
return;
}
Expand Down Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion dlls/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dlls/shockbeam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion dlls/shockrifle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions dlls/shotgun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion dlls/sniperrifle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions dlls/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion dlls/uzi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 252d7f5

Please sign in to comment.