Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HL2DM] Fix ladder bugs #959

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/game/server/hl2mp/hl2mp_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ CHL2MP_Player::~CHL2MP_Player( void )

void CHL2MP_Player::UpdateOnRemove( void )
{
if ( auto p = GetLadderMove() )
{
UTIL_Remove( ( CBaseEntity * ) ( p->m_hReservedSpot.Get() ) );
p->m_hReservedSpot = NULL;
}

if ( m_hRagdoll )
{
UTIL_RemoveImmediate( m_hRagdoll );
Expand Down Expand Up @@ -955,6 +961,22 @@ bool CHL2MP_Player::BumpWeapon( CBaseCombatWeapon *pWeapon )
return true;
}

void CHL2MP_Player::LadderRespawnFix()
{
if ( auto lm = GetLadderMove() )
{
if ( lm->m_bForceLadderMove )
{
lm->m_bForceLadderMove = false;
if ( lm->m_hReservedSpot )
{
UTIL_Remove( ( CBaseEntity * ) lm->m_hReservedSpot.Get() );
lm->m_hReservedSpot = NULL;
}
}
}
}

void CHL2MP_Player::ChangeTeam( int iTeam )
{
/* if ( GetNextTeamChangeTime() >= gpGlobals->curtime )
Expand All @@ -966,6 +988,8 @@ void CHL2MP_Player::ChangeTeam( int iTeam )
return;
}*/

LadderRespawnFix();

bool bKill = false;

if ( HL2MPRules()->IsTeamplay() != true && iTeam != TEAM_SPECTATOR )
Expand Down Expand Up @@ -1298,6 +1322,8 @@ void CHL2MP_Player::DetonateTripmines( void )

void CHL2MP_Player::Event_Killed( const CTakeDamageInfo &info )
{
LadderRespawnFix();

//update damage info with our accumulated physics force
CTakeDamageInfo subinfo = info;
subinfo.SetDamageForce( m_vecTotalBulletForce );
Expand Down
2 changes: 2 additions & 0 deletions src/game/server/hl2mp/hl2mp_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class CHL2MP_Player : public CHL2_Player

bool IsThreatAimingTowardMe( CBaseEntity* threat, float cosTolerance = 0.8f ) const;
bool IsThreatFiringAtMe( CBaseEntity* threat ) const;

void LadderRespawnFix();
private:

CNetworkQAngle( m_angEyeAngles );
Expand Down
4 changes: 4 additions & 0 deletions src/game/server/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,9 @@ class CBasePlayer : public CBaseCombatCharacter
}
}

float GetLadderCooldownTime() const { return m_flLadderCooldownTime; }
void SetLadderCooldownTime( float cooldownTime ) { m_flLadderCooldownTime = cooldownTime; }

private:
// How much of a movement time buffer can we process from this user?
int m_nMovementTicksForUserCmdProcessingRemaining;
Expand All @@ -838,6 +841,7 @@ class CBasePlayer : public CBaseCombatCharacter

int DetermineSimulationTicks( void );
void AdjustPlayerTimeBase( int simulation_ticks );
float m_flLadderCooldownTime;

public:

Expand Down
40 changes: 35 additions & 5 deletions src/game/shared/hl2/hl_gamemovement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,27 @@ bool CHL2GameMovement::ExitLadderViaDismountNode( CFuncLadder *ladder, bool stri
continue;
}

// Now perform a trace to ensure there is a clear line of sight
// between the player and the dismount node
trace_t losTrace;
Vector playerPos = mv->GetAbsOrigin() + player->GetViewOffset(); // Player's view position

UTIL_TraceLine( playerPos, org, MASK_PLAYERSOLID, player, COLLISION_GROUP_PLAYER_MOVEMENT, &losTrace );

// Peter: If there's an obstruction (a wall or other object)
// between the player and the dismount node, skip it.
// There is an option in Hammer to prevent this, but
// level designer tend to forget to properly set this, so maps
// like dm_assault that have two ladders on either side means
// players can clip through walls and I fail to see
// why this should be a gameplay feature.
if ( losTrace.fraction != 1.0f )
{
continue;
}

// Find the best dot product
Vector vecToSpot = org - ( mv->GetAbsOrigin() + player->GetViewOffset() );
Vector vecToSpot = org - playerPos;
vecToSpot.z = 0.0f;
float d = VectorNormalize( vecToSpot );

Expand Down Expand Up @@ -964,6 +983,14 @@ bool CHL2GameMovement::LadderMove( void )

if ( !ladder )
{
#ifdef GAME_DLL
// Check if the player is still in the cooldown period after dismounting the ladder
if ( gpGlobals->curtime < GetHL2Player()->GetLadderCooldownTime() )
{
// Player is still in cooldown, prevent mounting
return false;
}
#endif
Findladder( 64.0f, &bestLadder, bestOrigin, NULL );
}

Expand Down Expand Up @@ -1083,6 +1110,11 @@ bool CHL2GameMovement::LadderMove( void )
{
mv->m_vecVelocity.z = mv->m_vecVelocity.z + 50;
}

#ifdef GAME_DLL
// Set cooldown time for remounting the ladder (0.5 seconds) - server-side only
GetHL2Player()->SetLadderCooldownTime( gpGlobals->curtime + 0.5f );
#endif
return false;
}

Expand Down Expand Up @@ -1188,9 +1220,7 @@ bool CHL2GameMovement::CanAccelerate()
}
#endif

BaseClass::CanAccelerate();

return true;
return BaseClass::CanAccelerate();
}


Expand All @@ -1200,4 +1230,4 @@ bool CHL2GameMovement::CanAccelerate()
IGameMovement *g_pGameMovement = ( IGameMovement * )&g_GameMovement;

EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CGameMovement, IGameMovement,INTERFACENAME_GAMEMOVEMENT, g_GameMovement );
#endif
#endif
1 change: 1 addition & 0 deletions src/game/shared/hl2mp/hl2mp_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@ void CHL2MPRules::RestartGame()
pPlayer->GetActiveWeapon()->Holster();
}
pPlayer->RemoveAllItems( true );
pPlayer->LadderRespawnFix();
respawn( pPlayer, false );
pPlayer->Reset();
}
Expand Down