diff --git a/game/experiment/addons/gmod_compatibility/scripts/lua/includes/modules/gmod_compatibility/sh_init.lua b/game/experiment/addons/gmod_compatibility/scripts/lua/includes/modules/gmod_compatibility/sh_init.lua index d07184e3cb..c4af2389f3 100644 --- a/game/experiment/addons/gmod_compatibility/scripts/lua/includes/modules/gmod_compatibility/sh_init.lua +++ b/game/experiment/addons/gmod_compatibility/scripts/lua/includes/modules/gmod_compatibility/sh_init.lua @@ -515,6 +515,12 @@ PLAYER_META.AnimSetGestureWeight = PLAYER_META.AnimationSetGestureWeight PLAYER_META.GetName = PLAYER_META.GetPlayerName PLAYER_META.Name = PLAYER_META.GetPlayerName PLAYER_META.Nick = PLAYER_META.GetPlayerName +PLAYER_META.SetSlowWalkSpeed = PLAYER_META.SetWalkSpeed +PLAYER_META.GetSlowWalkSpeed = PLAYER_META.GetWalkSpeed +PLAYER_META.SetWalkSpeed = PLAYER_META.SetNormalSpeed +PLAYER_META.GetWalkSpeed = PLAYER_META.GetNormalSpeed +PLAYER_META.GetCrouchedWalkSpeed = PLAYER_META.GetCrouchWalkFraction +PLAYER_META.SetCrouchedWalkSpeed = PLAYER_META.SetCrouchWalkFraction function PLAYER_META:GetInfo(consoleVariableName) return engine.GetClientConsoleVariableValue(self, consoleVariableName) diff --git a/src/game/client/c_baseplayer.cpp b/src/game/client/c_baseplayer.cpp index 8019256d82..84d65889ae 100644 --- a/src/game/client/c_baseplayer.cpp +++ b/src/game/client/c_baseplayer.cpp @@ -348,7 +348,13 @@ RecvPropDataTable( "localdata", 0, 0, &REFERENCE_RECV_TABLE( DT_LocalPlayerExclu RecvPropInt( RECVINFO( m_iBonusProgress ) ), RecvPropInt( RECVINFO( m_iBonusChallenge ) ), - RecvPropFloat( RECVINFO( m_flMaxspeed ) ), RecvPropInt( RECVINFO( m_fFlags ) ), + RecvPropFloat( RECVINFO( m_flMaxspeed ) ), + RecvPropFloat( RECVINFO( m_flWalkSpeed ) ), + RecvPropFloat( RECVINFO( m_flNormalSpeed ) ), + RecvPropFloat( RECVINFO( m_flRunSpeed ) ), + RecvPropFloat( RECVINFO( m_flCrouchWalkFraction ) ), + + RecvPropInt( RECVINFO( m_fFlags ) ), RecvPropInt( RECVINFO( m_iObserverMode ), 0, RecvProxy_ObserverMode ), RecvPropEHandle( RECVINFO( m_hObserverTarget ), RecvProxy_ObserverTarget ), @@ -411,9 +417,9 @@ RecvPropDataTable( "localdata", 0, 0, &REFERENCE_RECV_TABLE( DT_LocalPlayerExclu END_PREDICTION_DATA() - BEGIN_PREDICTION_DATA( C_BasePlayer ) + BEGIN_PREDICTION_DATA( C_BasePlayer ) - DEFINE_PRED_TYPEDESCRIPTION( m_Local, CPlayerLocalData ), + DEFINE_PRED_TYPEDESCRIPTION( m_Local, CPlayerLocalData ), DEFINE_PRED_TYPEDESCRIPTION( pl, CPlayerState ), DEFINE_PRED_FIELD( m_iFOV, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ), @@ -423,6 +429,10 @@ RecvPropDataTable( "localdata", 0, 0, &REFERENCE_RECV_TABLE( DT_LocalPlayerExclu DEFINE_PRED_FIELD( m_hVehicle, FIELD_EHANDLE, FTYPEDESC_INSENDTABLE ), DEFINE_PRED_FIELD_TOL( m_flMaxspeed, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.5f ), + DEFINE_PRED_FIELD_TOL( m_flWalkSpeed, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.5f ), + DEFINE_PRED_FIELD_TOL( m_flNormalSpeed, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.5f ), + DEFINE_PRED_FIELD_TOL( m_flRunSpeed, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.5f ), + DEFINE_PRED_FIELD_TOL( m_flCrouchWalkFraction, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.5f ), DEFINE_PRED_FIELD( m_iHealth, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ), DEFINE_PRED_FIELD( m_iBonusProgress, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ), DEFINE_PRED_FIELD( m_iBonusChallenge, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ), diff --git a/src/game/client/c_baseplayer.h b/src/game/client/c_baseplayer.h index 9a2d3e128b..e75b4b94b9 100644 --- a/src/game/client/c_baseplayer.h +++ b/src/game/client/c_baseplayer.h @@ -245,11 +245,44 @@ class C_BasePlayer : public C_BaseCombatCharacter, public CGameEventListener { m_flMaxspeed = flMaxSpeed; } - float MaxSpeed() const + float GetMaxSpeed() const { return m_flMaxspeed; } + void SetWalkSpeed( float flSpeed ) + { + m_flWalkSpeed = flSpeed; + } + float GetWalkSpeed( void ) + { + return m_flWalkSpeed; + } + void SetNormalSpeed( float flSpeed ) + { + m_flNormalSpeed = flSpeed; + } + float GetNormalSpeed( void ) + { + return m_flNormalSpeed; + } + void SetRunSpeed( float flSpeed ) + { + m_flRunSpeed = flSpeed; + } + float GetRunSpeed( void ) + { + return m_flRunSpeed; + } + void SetCrouchWalkFraction( float flSpeed ) + { + m_flCrouchWalkFraction = flSpeed; + } + float GetCrouchWalkFraction( void ) + { + return m_flCrouchWalkFraction; + } + // Should this object cast shadows? virtual ShadowType_t ShadowCastType() { @@ -623,7 +656,13 @@ class C_BasePlayer : public C_BaseCombatCharacter, public CGameEventListener EHANDLE m_hOldVehicle; EHANDLE m_hUseEntity; - float m_flMaxspeed; + float m_flMaxspeed; // Current maximum speed + + // Values to set m_flMaxspeed to when walking slowly, normally, and running. + float m_flWalkSpeed; + float m_flNormalSpeed; + float m_flRunSpeed; + float m_flCrouchWalkFraction; int m_iBonusProgress; int m_iBonusChallenge; diff --git a/src/game/client/experiment/c_experiment_player.cpp b/src/game/client/experiment/c_experiment_player.cpp index 228584c8c7..2248e2b620 100644 --- a/src/game/client/experiment/c_experiment_player.cpp +++ b/src/game/client/experiment/c_experiment_player.cpp @@ -74,10 +74,6 @@ RecvPropVector( RECVINFO_NAME( m_vecNetworkOrigin, m_vecOrigin ) ), DEFINE_PRED_FIELD( m_nNewSequenceParity, FIELD_INTEGER, FTYPEDESC_OVERRIDE | FTYPEDESC_PRIVATE | FTYPEDESC_NOERRORCHECK ), END_PREDICTION_DATA() -#define HL2_WALK_SPEED 150 -#define HL2_NORM_SPEED 190 -#define HL2_SPRINT_SPEED 320 - static ConVar cl_playermodel( "cl_playermodel", "none", FCVAR_USERINFO | FCVAR_ARCHIVE | FCVAR_SERVER_CAN_EXECUTE, "Default Player Model" ); static ConVar cl_defaultweapon( "cl_defaultweapon", "weapon_physcannon", FCVAR_USERINFO | FCVAR_ARCHIVE, "Default Spawn Weapon" ); @@ -662,7 +658,13 @@ void C_Experiment_Player::StartSprinting( void ) filter.UsePredictionRules(); EmitSound( filter, entindex(), "HL2Player.SprintStart" ); +#if defined( EXPERIMENT_SOURCE ) + SetMaxSpeed( GetRunSpeed() ); +#elif defined( HL2MP ) SetMaxSpeed( HL2_SPRINT_SPEED ); +#else + SetMaxSpeed( hl2_sprintspeed.GetFloat() ); +#endif m_fIsSprinting = true; } @@ -670,7 +672,13 @@ void C_Experiment_Player::StartSprinting( void ) //----------------------------------------------------------------------------- void C_Experiment_Player::StopSprinting( void ) { +#if defined( EXPERIMENT_SOURCE ) + SetMaxSpeed( GetNormalSpeed() ); +#elif defined( HL2MP ) SetMaxSpeed( HL2_NORM_SPEED ); +#else + SetMaxSpeed( hl2_normspeed.GetFloat() ); +#endif m_fIsSprinting = false; } @@ -728,7 +736,13 @@ void C_Experiment_Player::HandleSpeedChanges( void ) //----------------------------------------------------------------------------- void C_Experiment_Player::StartWalking( void ) { +#if defined( EXPERIMENT_SOURCE ) + SetMaxSpeed( GetWalkSpeed() ); +#elif defined( HL2MP ) SetMaxSpeed( HL2_WALK_SPEED ); +#else + SetMaxSpeed( hl2_walkspeed.GetFloat() ); +#endif m_fIsWalking = true; } @@ -736,7 +750,13 @@ void C_Experiment_Player::StartWalking( void ) //----------------------------------------------------------------------------- void C_Experiment_Player::StopWalking( void ) { - SetMaxSpeed( HL2_NORM_SPEED ); +#if defined( EXPERIMENT_SOURCE ) + SetMaxSpeed( GetRunSpeed() ); +#elif defined( HL2MP ) + SetMaxSpeed( HL2_SPRINT_SPEED ); +#else + SetMaxSpeed( hl2_sprintspeed.GetFloat() ); +#endif m_fIsWalking = false; } diff --git a/src/game/server/experiment/experiment_player.cpp b/src/game/server/experiment/experiment_player.cpp index a1b9f93577..2b419047f9 100644 --- a/src/game/server/experiment/experiment_player.cpp +++ b/src/game/server/experiment/experiment_player.cpp @@ -749,7 +749,7 @@ bool CExperiment_Player::WantsLagCompensationOnEntity( // get max distance player could have moved within max lag compensation // time, multiply by 1.5 to to avoid "dead zones" (sqrt(2) would be the // exact value) - float maxDistance = 1.5 * pPlayer->MaxSpeed() * sv_maxunlag.GetFloat(); + float maxDistance = 1.5 * pPlayer->GetMaxSpeed() * sv_maxunlag.GetFloat(); // If the player is within this distance, lag compensate them in case // they're running past us. @@ -788,8 +788,6 @@ Activity CExperiment_Player::TranslateTeamActivity( Activity ActToTranslate ) return ActToTranslate; } -extern ConVar hl2_normspeed; - extern int gEvilImpulse101; //----------------------------------------------------------------------------- // Purpose: Player reacts to bumping a weapon. diff --git a/src/game/server/hl2/hl2_player.cpp b/src/game/server/hl2/hl2_player.cpp index bbe3f4554f..bfa9aa9590 100644 --- a/src/game/server/hl2/hl2_player.cpp +++ b/src/game/server/hl2/hl2_player.cpp @@ -91,16 +91,6 @@ ConVar hl2_sprintspeed( "hl2_sprintspeed", "320" ); ConVar hl2_darkness_flashlight_factor( "hl2_darkness_flashlight_factor", "1" ); -#if defined( HL2MP ) || defined( EXPERIMENT_SOURCE ) -#define HL2_WALK_SPEED 150 -#define HL2_NORM_SPEED 190 -#define HL2_SPRINT_SPEED 320 -#else -#define HL2_WALK_SPEED hl2_walkspeed.GetFloat() -#define HL2_NORM_SPEED hl2_normspeed.GetFloat() -#define HL2_SPRINT_SPEED hl2_sprintspeed.GetFloat() -#endif - ConVar player_showpredictedposition( "player_showpredictedposition", "0" ); ConVar player_showpredictedposition_timestep( "player_showpredictedposition_timestep", "1.0" ); @@ -1207,7 +1197,14 @@ void CHL2_Player::StartSprinting( void ) filter.UsePredictionRules(); EmitSound( filter, entindex(), "HL2Player.SprintStart" ); +#if defined( EXPERIMENT_SOURCE ) + SetMaxSpeed( GetRunSpeed() ); +#elif defined( HL2MP ) SetMaxSpeed( HL2_SPRINT_SPEED ); +#else + SetMaxSpeed( hl2_sprintspeed.GetFloat() ); +#endif + m_fIsSprinting = true; } @@ -1222,11 +1219,23 @@ void CHL2_Player::StopSprinting( void ) if ( IsSuitEquipped() ) { +#if defined( EXPERIMENT_SOURCE ) + SetMaxSpeed( GetNormalSpeed() ); +#elif defined( HL2MP ) SetMaxSpeed( HL2_NORM_SPEED ); +#else + SetMaxSpeed( hl2_normspeed.GetFloat() ); +#endif } else { +#if defined( EXPERIMENT_SOURCE ) + SetMaxSpeed( GetWalkSpeed() ); +#elif defined( HL2MP ) SetMaxSpeed( HL2_WALK_SPEED ); +#else + SetMaxSpeed( hl2_walkspeed.GetFloat() ); +#endif } m_fIsSprinting = false; @@ -1256,7 +1265,13 @@ void CHL2_Player::EnableSprint( bool bEnable ) //----------------------------------------------------------------------------- void CHL2_Player::StartWalking( void ) { +#if defined( EXPERIMENT_SOURCE ) + SetMaxSpeed( GetWalkSpeed() ); +#elif defined( HL2MP ) SetMaxSpeed( HL2_WALK_SPEED ); +#else + SetMaxSpeed( hl2_walkspeed.GetFloat() ); +#endif m_fIsWalking = true; } @@ -1264,7 +1279,13 @@ void CHL2_Player::StartWalking( void ) //----------------------------------------------------------------------------- void CHL2_Player::StopWalking( void ) { +#if defined( EXPERIMENT_SOURCE ) + SetMaxSpeed( GetNormalSpeed() ); +#elif defined( HL2MP ) SetMaxSpeed( HL2_NORM_SPEED ); +#else + SetMaxSpeed( hl2_normspeed.GetFloat() ); +#endif m_fIsWalking = false; } diff --git a/src/game/server/physics_main.cpp b/src/game/server/physics_main.cpp index a27a669aa1..2f815bef14 100644 --- a/src/game/server/physics_main.cpp +++ b/src/game/server/physics_main.cpp @@ -1734,7 +1734,7 @@ void CBaseEntity::PhysicsStep() { float maxAngular; VPhysicsGetObject()->GetShadowController()->GetMaxSpeed( NULL, &maxAngular ); - VPhysicsGetObject()->GetShadowController()->MaxSpeed( pUpdate->savedShadowControllerMaxSpeed, maxAngular ); + VPhysicsGetObject()->GetShadowController()->MaxSpeed( pUpdate->savedShadowControllerMaxSpeed, maxAngular ); DestroyDataObject(VPHYSICSUPDATEAI); } } diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 5b700b8e33..e05fbb98b1 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -385,6 +385,11 @@ DEFINE_FIELD( v_angle, FIELD_VECTOR ), DEFINE_AUTO_ARRAY( m_hViewModel, FIELD_EHANDLE ), DEFINE_FIELD( m_flMaxspeed, FIELD_FLOAT ), + DEFINE_FIELD( m_flWalkSpeed, FIELD_FLOAT ), + DEFINE_FIELD( m_flNormalSpeed, FIELD_FLOAT ), + DEFINE_FIELD( m_flRunSpeed, FIELD_FLOAT ), + DEFINE_FIELD( m_flCrouchWalkFraction, FIELD_FLOAT ), + DEFINE_FIELD( m_flWaterJumpTime, FIELD_TIME ), DEFINE_FIELD( m_vecWaterJumpVel, FIELD_VECTOR ), DEFINE_FIELD( m_nImpulse, FIELD_INTEGER ), @@ -758,7 +763,7 @@ bool CBasePlayer::WantsLagCompensationOnEntity( const CBasePlayer *pPlayer, cons // get max distance player could have moved within max lag compensation time, // multiply by 1.5 to to avoid "dead zones" (sqrt(2) would be the exact value) - float maxDistance = 1.5 * pPlayer->MaxSpeed() * sv_maxunlag.GetFloat(); + float maxDistance = 1.5 * pPlayer->GetMaxSpeed() * sv_maxunlag.GetFloat(); // If the player is within this distance, lag compensate them in case they're running past us. if ( vHisOrigin.DistTo( vMyOrigin ) < maxDistance ) @@ -8016,6 +8021,11 @@ SendPropDataTable( SENDINFO_DT( m_AttributeList ), &REFERENCE_SEND_TABLE( DT_Att SendPropInt( SENDINFO( m_iBonusProgress ), 15 ), SendPropInt( SENDINFO( m_iBonusChallenge ), 4 ), SendPropFloat( SENDINFO( m_flMaxspeed ), 12, SPROP_ROUNDDOWN, 0.0f, 2048.0f ), // CL + SendPropFloat( SENDINFO( m_flWalkSpeed ), 12, SPROP_ROUNDDOWN, 0.0f, 2048.0f ), // CL + SendPropFloat( SENDINFO( m_flNormalSpeed ), 12, SPROP_ROUNDDOWN, 0.0f, 2048.0f ), // CL + SendPropFloat( SENDINFO( m_flRunSpeed ), 12, SPROP_ROUNDDOWN, 0.0f, 2048.0f ), // CL + SendPropFloat( SENDINFO( m_flCrouchWalkFraction ), 12, SPROP_ROUNDDOWN, 0.0f, 2048.0f ), // CL + SendPropInt( SENDINFO( m_fFlags ), PLAYER_FLAG_BITS, SPROP_UNSIGNED | SPROP_CHANGES_OFTEN, SendProxy_CropFlagsToPlayerFlagBitsLength ), SendPropInt( SENDINFO( m_iObserverMode ), 3, SPROP_UNSIGNED ), SendPropEHandle( SENDINFO( m_hObserverTarget ) ), diff --git a/src/game/server/player.h b/src/game/server/player.h index 3d54d25eed..2baae286ec 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -845,10 +845,6 @@ class CBasePlayer : public CBaseCombatCharacter { return m_fInitHUD; } - float MaxSpeed() const - { - return m_flMaxspeed; - } Activity GetActivity() const { return m_Activity; @@ -929,10 +925,47 @@ class CBasePlayer : public CBaseCombatCharacter } virtual void EquipSuit( bool bPlayEffects = true ); virtual void RemoveSuit( void ); + void SetMaxSpeed( float flMaxSpeed ) { m_flMaxspeed = flMaxSpeed; } + float GetMaxSpeed() const + { + return m_flMaxspeed; + } + void SetWalkSpeed( float flSpeed ) + { + m_flWalkSpeed = flSpeed; + } + float GetWalkSpeed( void ) + { + return m_flWalkSpeed; + } + void SetNormalSpeed( float flSpeed ) + { + m_flNormalSpeed = flSpeed; + } + float GetNormalSpeed( void ) + { + return m_flNormalSpeed; + } + void SetRunSpeed( float flSpeed ) + { + m_flRunSpeed = flSpeed; + } + float GetRunSpeed( void ) + { + return m_flRunSpeed; + } + void SetCrouchWalkFraction( float flSpeed ) + { + m_flCrouchWalkFraction = flSpeed; + } + float GetCrouchWalkFraction( void ) + { + return m_flCrouchWalkFraction; + } void NotifyNearbyRadiationSource( float flRange ); @@ -1364,7 +1397,13 @@ class CBasePlayer : public CBaseCombatCharacter private: // Replicated to all clients - CNetworkVar( float, m_flMaxspeed ); + CNetworkVar( float, m_flMaxspeed ); // Current maximum speed + + // Values to set m_flMaxspeed to when walking slowly, normally, and running. + CNetworkVar( float, m_flWalkSpeed ); + CNetworkVar( float, m_flNormalSpeed ); + CNetworkVar( float, m_flRunSpeed ); + CNetworkVar( float, m_flCrouchWalkFraction ); // Not transmitted float m_flWaterJumpTime; // used to be called teleport_time diff --git a/src/game/shared/baseplayer_shared.cpp b/src/game/shared/baseplayer_shared.cpp index 4d398045c7..776dacffb3 100644 --- a/src/game/shared/baseplayer_shared.cpp +++ b/src/game/shared/baseplayer_shared.cpp @@ -180,8 +180,8 @@ float CBasePlayer::GetPlayerMaxSpeed() { // player max speed is the lower limit of m_flMaxSpeed and sv_maxspeed float fMaxSpeed = sv_maxspeed.GetFloat(); - if ( MaxSpeed() > 0.0f && MaxSpeed() < fMaxSpeed ) - fMaxSpeed = MaxSpeed(); + if ( GetMaxSpeed() > 0.0f && GetMaxSpeed() < fMaxSpeed ) + fMaxSpeed = GetMaxSpeed(); return fMaxSpeed; } @@ -2059,6 +2059,23 @@ void CBasePlayer::SharedSpawn() m_flNextAttack = gpGlobals->curtime; m_flMaxspeed = 0.0f; +#if defined( EXPERIMENT_SOURCE ) + SetWalkSpeed( EXPERIMENT_WALK_SPEED ); + SetNormalSpeed( EXPERIMENT_NORMAL_SPEED ); + SetRunSpeed( EXPERIMENT_RUN_SPEED ); + SetCrouchWalkFraction( EXPERIMENT_CROUCH_WALK_FRACTION ); +#elif defined( HL2MP ) + SetWalkSpeed( HL2_WALK_SPEED ); + SetNormalSpeed( HL2_NORM_SPEED ); + SetRunSpeed( HL2_SPRINT_SPEED ); + SetCrouchWalkFraction( HL2_WALK_SPEED ); +#else + SetWalkSpeed( hl2_walkspeed.GetFloat() ); + SetNormalSpeed( hl2_normspeed.GetFloat() ); + SetRunSpeed( hl2_sprintspeed.GetFloat() ); + SetCrouchWalkFraction( hl2_walkspeed.GetFloat() ); +#endif + MDLCACHE_CRITICAL_SECTION(); SetSequence( SelectWeightedSequence( ACT_IDLE ) ); diff --git a/src/game/shared/baseplayer_shared.h b/src/game/shared/baseplayer_shared.h index 8bdc095073..e03625216b 100644 --- a/src/game/shared/baseplayer_shared.h +++ b/src/game/shared/baseplayer_shared.h @@ -32,6 +32,27 @@ #define DEATH_ANIMATION_TIME 3.0f +#if defined( EXPERIMENT_SOURCE ) +#define EXPERIMENT_WALK_SPEED 90.0f // ALT-key (slow walk) +#define EXPERIMENT_NORMAL_SPEED 150.0f // no modifiers (light jog) +#define EXPERIMENT_RUN_SPEED 320.0f // SHIFT-key (full sprint) +#define EXPERIMENT_CROUCH_WALK_FRACTION 0.5f // CTRL-key (crouch walk) +#elif defined( HL2MP ) +#define HL2_WALK_SPEED 150 +#define HL2_NORM_SPEED 190 +#define HL2_SPRINT_SPEED 320 +#else +extern ConVar hl2_walkspeed; +extern ConVar hl2_normspeed; +extern ConVar hl2_sprintspeed; +#define HL2_WALK_SPEED hl2_walkspeed.GetFloat() +#define HL2_NORM_SPEED hl2_normspeed.GetFloat() +#define HL2_SPRINT_SPEED hl2_sprintspeed.GetFloat() +#endif + +// When moving this fast, we play run anim. +#define ARBITRARY_RUN_SPEED 175.0f + typedef struct { Vector m_vecAutoAimDir; // The direction autoaim wishes to point. diff --git a/src/game/shared/experiment/experiment_playeranimstate.cpp b/src/game/shared/experiment/experiment_playeranimstate.cpp index c8b4833e20..b49600977a 100644 --- a/src/game/shared/experiment/experiment_playeranimstate.cpp +++ b/src/game/shared/experiment/experiment_playeranimstate.cpp @@ -19,13 +19,6 @@ #include "experiment_player.h" #endif -#define Experiment_RUN_SPEED 320.0f -#define Experiment_WALK_SPEED 75.0f -#define Experiment_CROUCHWALK_SPEED 110.0f - -// When moving this fast, he plays run anim. -#define ARBITRARY_RUN_SPEED 175.0f - // Experiment; somehow get which type of leganim we're using // e.g: m_AnimConfig.m_LegAnimType == LEGANIM_9WAY; ConVar cl_leganimtype( @@ -41,9 +34,9 @@ CExperimentPlayerAnimState *CreateExperimentPlayerAnimState( CExperiment_Player // Setup the movement data. MultiPlayerMovementData_t movementData; movementData.m_flBodyYawRate = 720.0f; - movementData.m_flRunSpeed = Experiment_RUN_SPEED; - movementData.m_flWalkSpeed = Experiment_WALK_SPEED; - movementData.m_flSprintSpeed = -1.0f; + movementData.m_flRunSpeed = pPlayer ? pPlayer->GetRunSpeed() : EXPERIMENT_RUN_SPEED; + movementData.m_flWalkSpeed = pPlayer ? pPlayer->GetWalkSpeed() : EXPERIMENT_WALK_SPEED; + movementData.m_flSprintSpeed = -1.0f; // TODO: ? This is running and m_flRunSpeed above is normal speed? Where is this struct used? // Create animation state for this player. CExperimentPlayerAnimState *pRet = diff --git a/src/game/shared/experiment/weapon_experimentbasehlmpcombatweapon.cpp b/src/game/shared/experiment/weapon_experimentbasehlmpcombatweapon.cpp index 93a7310ee1..9404d9b482 100644 --- a/src/game/shared/experiment/weapon_experimentbasehlmpcombatweapon.cpp +++ b/src/game/shared/experiment/weapon_experimentbasehlmpcombatweapon.cpp @@ -256,7 +256,7 @@ float CBaseExperimentCombatWeapon::CalcViewmodelBob( void ) float speed = player->GetLocalVelocity().Length2D(); // FIXME: This maximum speed value must come from the server. - // MaxSpeed() is not sufficient for dealing with sprinting - jdw + // GetMaxSpeed() is not sufficient for dealing with sprinting - jdw speed = clamp( speed, -320, 320 ); diff --git a/src/game/shared/experiment/weapon_physcannon.cpp b/src/game/shared/experiment/weapon_physcannon.cpp index 15fa7ad3cb..cc7c3e1824 100644 --- a/src/game/shared/experiment/weapon_physcannon.cpp +++ b/src/game/shared/experiment/weapon_physcannon.cpp @@ -64,11 +64,6 @@ ConVar physcannon_cone( "physcannon_cone", "0.97", FCVAR_REPLICATED | FCVAR_CHEA ConVar physcannon_ball_cone( "physcannon_ball_cone", "0.997", FCVAR_REPLICATED | FCVAR_CHEAT ); ConVar player_throwforce( "player_throwforce", "1000", FCVAR_REPLICATED | FCVAR_CHEAT ); -#ifndef CLIENT_DLL -extern ConVar hl2_normspeed; -extern ConVar hl2_walkspeed; -#endif - #define PHYSCANNON_BEAM_SPRITE "sprites/orangelight1.vmt" #define PHYSCANNON_BEAM_SPRITE_NOZ "sprites/orangelight1_noz.vmt" #define PHYSCANNON_GLOW_SPRITE "sprites/glow04_noz" @@ -631,7 +626,13 @@ void CGrabController::DetachEntity( bool bClearVelocity ) else { #ifndef CLIENT_DLL +#if defined( EXPERIMENT_SOURCE) + ClampPhysicsVelocity( pPhys, EXPERIMENT_NORMAL_SPEED * 1.5f, 2.0f * 360.0f ); +#elif defined( HL2MP ) + ClampPhysicsVelocity( pPhys, HL2_NORM_SPEED * 1.5f, 2.0f * 360.0f ); +#else ClampPhysicsVelocity( pPhys, hl2_normspeed.GetFloat() * 1.5f, 2.0f * 360.0f ); +#endif #endif } } @@ -2410,7 +2411,14 @@ void CWeaponPhysCannon::DetachObject( bool playSound, bool wasLaunched ) if ( pOwner != NULL ) { pOwner->EnableSprint( true ); + +#if defined( EXPERIMENT_SOURCE ) + pOwner->SetMaxSpeed( pOwner->GetNormalSpeed() ); +#elif defined( HL2MP ) + pOwner->SetMaxSpeed( HL2_NORM_SPEED ); +#else pOwner->SetMaxSpeed( hl2_normspeed.GetFloat() ); +#endif } CBaseEntity *pObject = m_grabController.GetAttached(); diff --git a/src/game/shared/gamemovement.cpp b/src/game/shared/gamemovement.cpp index 849572e590..3344b24ced 100644 --- a/src/game/shared/gamemovement.cpp +++ b/src/game/shared/gamemovement.cpp @@ -4287,10 +4287,14 @@ void CGameMovement::HandleDuckingSpeedCrop( void ) { if ( !( m_iSpeedCropped & SPEED_CROPPED_DUCK ) && ( player->GetFlags() & FL_DUCKING ) && ( player->GetGroundEntity() != NULL ) ) { - float frac = 0.33333333f; - mv->m_flForwardMove *= frac; - mv->m_flSideMove *= frac; - mv->m_flUpMove *= frac; + #ifdef EXPERIMENT_SOURCE + float fraction = player->GetCrouchWalkFraction(); + #else + float fraction = 0.33333333f; + #endif + mv->m_flForwardMove *= fraction; + mv->m_flSideMove *= fraction; + mv->m_flUpMove *= fraction; m_iSpeedCropped |= SPEED_CROPPED_DUCK; } } diff --git a/src/game/shared/hl2/basehlcombatweapon_shared.cpp b/src/game/shared/hl2/basehlcombatweapon_shared.cpp index 2abc600ee3..b4b864d415 100644 --- a/src/game/shared/hl2/basehlcombatweapon_shared.cpp +++ b/src/game/shared/hl2/basehlcombatweapon_shared.cpp @@ -274,7 +274,7 @@ float CBaseHLCombatWeapon::CalcViewmodelBob( void ) float speed = player->GetLocalVelocity().Length2D(); //FIXME: This maximum speed value must come from the server. - // MaxSpeed() is not sufficient for dealing with sprinting - jdw + // GetMaxSpeed() is not sufficient for dealing with sprinting - jdw speed = clamp( speed, -320, 320 ); diff --git a/src/game/shared/hl2/hl_gamemovement.cpp b/src/game/shared/hl2/hl_gamemovement.cpp index a3092ceb7e..1c966ebc52 100644 --- a/src/game/shared/hl2/hl_gamemovement.cpp +++ b/src/game/shared/hl2/hl_gamemovement.cpp @@ -33,11 +33,11 @@ CHL2GameMovement::CHL2GameMovement() //----------------------------------------------------------------------------- int CHL2GameMovement::GetCheckInterval( IntervalType_t type ) { - // HL2 ladders need to check every frame!!! - if ( type == LADDER ) - return 1; + // HL2 ladders need to check every frame!!! + if ( type == LADDER ) + return 1; - return BaseClass::GetCheckInterval( type ); + return BaseClass::GetCheckInterval( type ); } //----------------------------------------------------------------------------- @@ -46,8 +46,8 @@ int CHL2GameMovement::GetCheckInterval( IntervalType_t type ) //----------------------------------------------------------------------------- bool CHL2GameMovement::IsForceMoveActive() { - LadderMove_t *lm = GetLadderMove(); - return lm->m_bForceLadderMove; + LadderMove_t *lm = GetLadderMove(); + return lm->m_bForceLadderMove; } //----------------------------------------------------------------------------- @@ -55,10 +55,10 @@ bool CHL2GameMovement::IsForceMoveActive() //----------------------------------------------------------------------------- void CHL2GameMovement::SwallowUseKey() { - mv->m_nOldButtons |= IN_USE; - player->m_afButtonPressed &= ~IN_USE; + mv->m_nOldButtons |= IN_USE; + player->m_afButtonPressed &= ~IN_USE; - GetHL2Player()->m_bPlayUseDenySound = false; + GetHL2Player()->m_bPlayUseDenySound = false; } #if !defined( CLIENT_DLL ) @@ -66,57 +66,61 @@ void CHL2GameMovement::SwallowUseKey() // can move into this spot and cause us to get stuck when we get there class CReservePlayerSpot : public CBaseEntity { - DECLARE_CLASS( CReservePlayerSpot, CBaseEntity ) -public: - static CReservePlayerSpot *ReserveSpot( CBasePlayer *owner, const Vector& org, const Vector& mins, const Vector& maxs, bool& validspot ); + DECLARE_CLASS( CReservePlayerSpot, CBaseEntity ) + public: + static CReservePlayerSpot *ReserveSpot( CBasePlayer *owner, const Vector &org, const Vector &mins, const Vector &maxs, bool &validspot ); - virtual void Spawn(); + virtual void Spawn(); }; CReservePlayerSpot *CReservePlayerSpot::ReserveSpot( - CBasePlayer *owner, const Vector& org, const Vector& mins, const Vector& maxs, bool& validspot ) + CBasePlayer *owner, + const Vector &org, + const Vector &mins, + const Vector &maxs, + bool &validspot ) { - CReservePlayerSpot *spot = ( CReservePlayerSpot * )CreateEntityByName( "reserved_spot" ); - Assert( spot ); - - spot->SetAbsOrigin( org ); - UTIL_SetSize( spot, mins, maxs ); - spot->SetOwnerEntity( owner ); - spot->Spawn(); - - // See if spot is valid - trace_t tr; - UTIL_TraceHull( - org, - org, - mins, - maxs, - MASK_PLAYERSOLID, - owner, - COLLISION_GROUP_PLAYER_MOVEMENT, - &tr ); - - validspot = !tr.startsolid; - - if ( !validspot ) - { - Vector org2 = org + Vector( 0, 0, 1 ); - - // See if spot is valid - trace_t tr; - UTIL_TraceHull( - org2, - org2, - mins, - maxs, - MASK_PLAYERSOLID, - owner, - COLLISION_GROUP_PLAYER_MOVEMENT, - &tr ); - validspot = !tr.startsolid; - } - - return spot; + CReservePlayerSpot *spot = ( CReservePlayerSpot * )CreateEntityByName( "reserved_spot" ); + Assert( spot ); + + spot->SetAbsOrigin( org ); + UTIL_SetSize( spot, mins, maxs ); + spot->SetOwnerEntity( owner ); + spot->Spawn(); + + // See if spot is valid + trace_t tr; + UTIL_TraceHull( + org, + org, + mins, + maxs, + MASK_PLAYERSOLID, + owner, + COLLISION_GROUP_PLAYER_MOVEMENT, + &tr ); + + validspot = !tr.startsolid; + + if ( !validspot ) + { + Vector org2 = org + Vector( 0, 0, 1 ); + + // See if spot is valid + trace_t tr; + UTIL_TraceHull( + org2, + org2, + mins, + maxs, + MASK_PLAYERSOLID, + owner, + COLLISION_GROUP_PLAYER_MOVEMENT, + &tr ); + validspot = !tr.startsolid; + } + + return spot; } //----------------------------------------------------------------------------- @@ -124,12 +128,12 @@ CReservePlayerSpot *CReservePlayerSpot::ReserveSpot( //----------------------------------------------------------------------------- void CReservePlayerSpot::Spawn() { - BaseClass::Spawn(); + BaseClass::Spawn(); - SetSolid( SOLID_BBOX ); - SetMoveType( MOVETYPE_NONE ); - // Make entity invisible - AddEffects( EF_NODRAW ); + SetSolid( SOLID_BBOX ); + SetMoveType( MOVETYPE_NONE ); + // Make entity invisible + AddEffects( EF_NODRAW ); } LINK_ENTITY_TO_CLASS( reserved_spot, CReservePlayerSpot ); @@ -142,80 +146,80 @@ LINK_ENTITY_TO_CLASS( reserved_spot, CReservePlayerSpot ); // goalpos - // *ladder - //----------------------------------------------------------------------------- -void CHL2GameMovement::StartForcedMove( bool mounting, float transit_speed, const Vector& goalpos, CFuncLadder *ladder ) +void CHL2GameMovement::StartForcedMove( bool mounting, float transit_speed, const Vector &goalpos, CFuncLadder *ladder ) { - LadderMove_t* lm = GetLadderMove(); - Assert( lm ); - // Already active, just ignore - if ( lm->m_bForceLadderMove ) - { - return; - } + LadderMove_t *lm = GetLadderMove(); + Assert( lm ); + // Already active, just ignore + if ( lm->m_bForceLadderMove ) + { + return; + } #if !defined( CLIENT_DLL ) - if ( ladder ) - { - ladder->PlayerGotOn( GetHL2Player() ); - - // If the Ladder only wants to be there for automount checking, abort now - if ( ladder->DontGetOnLadder() ) - return; - } - - // Reserve goal slot here - bool valid = false; - lm->m_hReservedSpot = CReservePlayerSpot::ReserveSpot( - player, - goalpos, - GetPlayerMins( ( player->GetFlags() & FL_DUCKING ) ? true : false ), - GetPlayerMaxs( ( player->GetFlags() & FL_DUCKING ) ? true : false ), - valid ); - if ( !valid ) - { - // FIXME: Play a deny sound? - if ( lm->m_hReservedSpot ) - { - UTIL_Remove( lm->m_hReservedSpot ); - lm->m_hReservedSpot = NULL; - } - return; - } + if ( ladder ) + { + ladder->PlayerGotOn( GetHL2Player() ); + + // If the Ladder only wants to be there for automount checking, abort now + if ( ladder->DontGetOnLadder() ) + return; + } + + // Reserve goal slot here + bool valid = false; + lm->m_hReservedSpot = CReservePlayerSpot::ReserveSpot( + player, + goalpos, + GetPlayerMins( ( player->GetFlags() & FL_DUCKING ) ? true : false ), + GetPlayerMaxs( ( player->GetFlags() & FL_DUCKING ) ? true : false ), + valid ); + if ( !valid ) + { + // FIXME: Play a deny sound? + if ( lm->m_hReservedSpot ) + { + UTIL_Remove( lm->m_hReservedSpot ); + lm->m_hReservedSpot = NULL; + } + return; + } #endif - // Use current player origin as start and new origin as dest - lm->m_vecGoalPosition = goalpos; - lm->m_vecStartPosition = mv->GetAbsOrigin(); + // Use current player origin as start and new origin as dest + lm->m_vecGoalPosition = goalpos; + lm->m_vecStartPosition = mv->GetAbsOrigin(); - // Figure out how long it will take to make the gap based on transit_speed - Vector delta = lm->m_vecGoalPosition - lm->m_vecStartPosition; + // Figure out how long it will take to make the gap based on transit_speed + Vector delta = lm->m_vecGoalPosition - lm->m_vecStartPosition; - float distance = delta.Length(); + float distance = delta.Length(); - Assert( transit_speed > 0.001f ); + Assert( transit_speed > 0.001f ); - // Compute time required to move that distance - float transit_time = distance / transit_speed; - if ( transit_time < 0.001f ) - { - transit_time = 0.001f; - } + // Compute time required to move that distance + float transit_time = distance / transit_speed; + if ( transit_time < 0.001f ) + { + transit_time = 0.001f; + } - lm->m_bForceLadderMove = true; - lm->m_bForceMount = mounting; + lm->m_bForceLadderMove = true; + lm->m_bForceMount = mounting; - lm->m_flStartTime = gpGlobals->curtime; - lm->m_flArrivalTime = lm->m_flStartTime + transit_time; + lm->m_flStartTime = gpGlobals->curtime; + lm->m_flArrivalTime = lm->m_flStartTime + transit_time; - lm->m_hForceLadder = ladder; + lm->m_hForceLadder = ladder; - // Don't get stuck during this traversal since we'll just be slamming the player origin - player->SetMoveType( MOVETYPE_NONE ); - player->SetMoveCollide( MOVECOLLIDE_DEFAULT ); - player->SetSolid( SOLID_NONE ); - SetLadder( ladder ); + // Don't get stuck during this traversal since we'll just be slamming the player origin + player->SetMoveType( MOVETYPE_NONE ); + player->SetMoveCollide( MOVECOLLIDE_DEFAULT ); + player->SetSolid( SOLID_NONE ); + SetLadder( ladder ); - // Debounce the use key - SwallowUseKey(); + // Debounce the use key + SwallowUseKey(); } //----------------------------------------------------------------------------- @@ -223,58 +227,58 @@ void CHL2GameMovement::StartForcedMove( bool mounting, float transit_speed, cons //----------------------------------------------------------------------------- bool CHL2GameMovement::ContinueForcedMove() { - LadderMove_t* lm = GetLadderMove(); - Assert( lm ); - Assert( lm->m_bForceLadderMove ); - - // Suppress regular motion - mv->m_flForwardMove = 0.0f; - mv->m_flSideMove = 0.0f; - mv->m_flUpMove = 0.0f; - - // How far along are we - float frac = ( gpGlobals->curtime - lm->m_flStartTime ) / ( lm->m_flArrivalTime - lm->m_flStartTime ); - if ( frac > 1.0f ) - { - lm->m_bForceLadderMove = false; + LadderMove_t *lm = GetLadderMove(); + Assert( lm ); + Assert( lm->m_bForceLadderMove ); + + // Suppress regular motion + mv->m_flForwardMove = 0.0f; + mv->m_flSideMove = 0.0f; + mv->m_flUpMove = 0.0f; + + // How far along are we + float frac = ( gpGlobals->curtime - lm->m_flStartTime ) / ( lm->m_flArrivalTime - lm->m_flStartTime ); + if ( frac > 1.0f ) + { + lm->m_bForceLadderMove = false; #if !defined( CLIENT_DLL ) - // Remove "reservation entity" - if ( lm->m_hReservedSpot ) - { - UTIL_Remove( lm->m_hReservedSpot ); - lm->m_hReservedSpot = NULL; - } + // Remove "reservation entity" + if ( lm->m_hReservedSpot ) + { + UTIL_Remove( lm->m_hReservedSpot ); + lm->m_hReservedSpot = NULL; + } #endif - } + } - frac = clamp( frac, 0.0f, 1.0f ); + frac = clamp( frac, 0.0f, 1.0f ); - // Move origin part of the way - Vector delta = lm->m_vecGoalPosition - lm->m_vecStartPosition; + // Move origin part of the way + Vector delta = lm->m_vecGoalPosition - lm->m_vecStartPosition; - // Compute interpolated position - Vector org; - VectorMA( lm->m_vecStartPosition, frac, delta, org ); - mv->SetAbsOrigin( org ); + // Compute interpolated position + Vector org; + VectorMA( lm->m_vecStartPosition, frac, delta, org ); + mv->SetAbsOrigin( org ); - // If finished moving, reset player to correct movetype (or put them on the ladder) - if ( !lm->m_bForceLadderMove ) - { - player->SetSolid( SOLID_BBOX ); - player->SetMoveType( MOVETYPE_WALK ); + // If finished moving, reset player to correct movetype (or put them on the ladder) + if ( !lm->m_bForceLadderMove ) + { + player->SetSolid( SOLID_BBOX ); + player->SetMoveType( MOVETYPE_WALK ); - if ( lm->m_bForceMount && lm->m_hForceLadder != NULL ) - { - player->SetMoveType( MOVETYPE_LADDER ); - SetLadder( lm->m_hForceLadder ); - } + if ( lm->m_bForceMount && lm->m_hForceLadder != NULL ) + { + player->SetMoveType( MOVETYPE_LADDER ); + SetLadder( lm->m_hForceLadder ); + } - // Zero out any velocity - mv->m_vecVelocity.Init(); - } + // Zero out any velocity + mv->m_vecVelocity.Init(); + } - // Stil active - return lm->m_bForceLadderMove; + // Stil active + return lm->m_bForceLadderMove; } //----------------------------------------------------------------------------- @@ -283,7 +287,7 @@ bool CHL2GameMovement::ContinueForcedMove() //----------------------------------------------------------------------------- bool CHL2GameMovement::OnLadder( trace_t &trace ) { - return ( GetLadder() != NULL ) ? true : false; + return ( GetLadder() != NULL ) ? true : false; } //----------------------------------------------------------------------------- @@ -293,118 +297,108 @@ bool CHL2GameMovement::OnLadder( trace_t &trace ) // **ppLadder - // ladderOrigin - //----------------------------------------------------------------------------- -void CHL2GameMovement::Findladder( float maxdist, CFuncLadder **ppLadder, Vector& ladderOrigin, const CFuncLadder *skipLadder ) +void CHL2GameMovement::Findladder( float maxdist, CFuncLadder **ppLadder, Vector &ladderOrigin, const CFuncLadder *skipLadder ) { - CFuncLadder *bestLadder = NULL; - float bestDist = MAX_COORD_INTEGER; - Vector bestOrigin; - - bestOrigin.Init(); - - float maxdistSqr = maxdist * maxdist; - - - int c = CFuncLadder::GetLadderCount(); - for ( int i = 0 ; i < c; i++ ) - { - CFuncLadder *ladder = CFuncLadder::GetLadder( i ); - - if ( !ladder->IsEnabled() ) - continue; - - if ( skipLadder && ladder == skipLadder ) - continue; - - Vector topPosition; - Vector bottomPosition; - - ladder->GetTopPosition( topPosition ); - ladder->GetBottomPosition( bottomPosition ); - - Vector closest; - CalcClosestPointOnLineSegment( mv->GetAbsOrigin(), bottomPosition, topPosition, closest, NULL ); - - float distSqr = ( closest - mv->GetAbsOrigin() ).LengthSqr(); - - // Too far away - if ( distSqr > maxdistSqr ) - { - continue; - } - - // Need to trace to see if it's clear - trace_t tr; - - UTIL_TraceLine( mv->GetAbsOrigin(), closest, - MASK_PLAYERSOLID, - player, - COLLISION_GROUP_NONE, - &tr ); - - if ( tr.fraction != 1.0f && - tr.m_pEnt && - tr.m_pEnt != ladder ) - { - // Try a trace stepped up from the ground a bit, in case there's something at ground level blocking us. - float sizez = GetPlayerMaxs().z - GetPlayerMins().z; - - UTIL_TraceLine( mv->GetAbsOrigin() + Vector( 0, 0, sizez * 0.5f ), closest, - MASK_PLAYERSOLID, - player, - COLLISION_GROUP_NONE, - &tr ); - - if ( tr.fraction != 1.0f && - tr.m_pEnt && - tr.m_pEnt != ladder && - !tr.m_pEnt->IsSolidFlagSet( FSOLID_TRIGGER ) ) - { - continue; - } - } - - // See if this is the best one so far - if ( distSqr < bestDist ) - { - bestDist = distSqr; - bestLadder = ladder; - bestOrigin = closest; - } - } - - // Return best ladder spot - *ppLadder = bestLadder; - ladderOrigin = bestOrigin; + CFuncLadder *bestLadder = NULL; + float bestDist = MAX_COORD_INTEGER; + Vector bestOrigin; + bestOrigin.Init(); + + float maxdistSqr = maxdist * maxdist; + + int c = CFuncLadder::GetLadderCount(); + for ( int i = 0; i < c; i++ ) + { + CFuncLadder *ladder = CFuncLadder::GetLadder( i ); + + if ( !ladder->IsEnabled() ) + continue; + + if ( skipLadder && ladder == skipLadder ) + continue; + + Vector topPosition; + Vector bottomPosition; + + ladder->GetTopPosition( topPosition ); + ladder->GetBottomPosition( bottomPosition ); + + Vector closest; + CalcClosestPointOnLineSegment( mv->GetAbsOrigin(), bottomPosition, topPosition, closest, NULL ); + + float distSqr = ( closest - mv->GetAbsOrigin() ).LengthSqr(); + + // Too far away + if ( distSqr > maxdistSqr ) + { + continue; + } + + // Need to trace to see if it's clear + trace_t tr; + + UTIL_TraceLine( mv->GetAbsOrigin(), closest, MASK_PLAYERSOLID, player, COLLISION_GROUP_NONE, &tr ); + + if ( tr.fraction != 1.0f && + tr.m_pEnt && + tr.m_pEnt != ladder ) + { + // Try a trace stepped up from the ground a bit, in case there's something at ground level blocking us. + float sizez = GetPlayerMaxs().z - GetPlayerMins().z; + + UTIL_TraceLine( mv->GetAbsOrigin() + Vector( 0, 0, sizez * 0.5f ), closest, MASK_PLAYERSOLID, player, COLLISION_GROUP_NONE, &tr ); + + if ( tr.fraction != 1.0f && + tr.m_pEnt && + tr.m_pEnt != ladder && + !tr.m_pEnt->IsSolidFlagSet( FSOLID_TRIGGER ) ) + { + continue; + } + } + + // See if this is the best one so far + if ( distSqr < bestDist ) + { + bestDist = distSqr; + bestLadder = ladder; + bestOrigin = closest; + } + } + + // Return best ladder spot + *ppLadder = bestLadder; + ladderOrigin = bestOrigin; } -static bool NearbyDismountLessFunc( const NearbyDismount_t& lhs, const NearbyDismount_t& rhs ) +static bool NearbyDismountLessFunc( const NearbyDismount_t &lhs, const NearbyDismount_t &rhs ) { - return lhs.distSqr < rhs.distSqr; + return lhs.distSqr < rhs.distSqr; } -void CHL2GameMovement::GetSortedDismountNodeList( const Vector &org, float radius, CFuncLadder *ladder, CUtlRBTree< NearbyDismount_t, int >& list ) +void CHL2GameMovement::GetSortedDismountNodeList( const Vector &org, float radius, CFuncLadder *ladder, CUtlRBTree< NearbyDismount_t, int > &list ) { - float radiusSqr = radius * radius; - - int i; - int c = ladder->GetDismountCount(); - for ( i = 0; i < c; i++ ) - { - CInfoLadderDismount *spot = ladder->GetDismount( i ); - if ( !spot ) - continue; - - float distSqr = ( spot->GetAbsOrigin() - org ).LengthSqr(); - if ( distSqr > radiusSqr ) - continue; - - NearbyDismount_t nd; - nd.dismount = spot; - nd.distSqr = distSqr; - - list.Insert( nd ); - } + float radiusSqr = radius * radius; + + int i; + int c = ladder->GetDismountCount(); + for ( i = 0; i < c; i++ ) + { + CInfoLadderDismount *spot = ladder->GetDismount( i ); + if ( !spot ) + continue; + + float distSqr = ( spot->GetAbsOrigin() - org ).LengthSqr(); + if ( distSqr > radiusSqr ) + continue; + + NearbyDismount_t nd; + nd.dismount = spot; + nd.distSqr = distSqr; + + list.Insert( nd ); + } } //----------------------------------------------------------------------------- @@ -414,106 +408,106 @@ void CHL2GameMovement::GetSortedDismountNodeList( const Vector &org, float radiu //----------------------------------------------------------------------------- bool CHL2GameMovement::ExitLadderViaDismountNode( CFuncLadder *ladder, bool strict, bool useAlternate ) { - // Find the best ladder exit node - float bestDot = -99999.0f; - float bestDistance = 99999.0f; - Vector bestDest; - bool found = false; - - // For 'alternate' dismount - bool foundAlternate = false; - Vector alternateDest; - float alternateDist = 99999.0f; - - CUtlRBTree< NearbyDismount_t, int > nearbyDismounts( 0, 0, NearbyDismountLessFunc ); - - GetSortedDismountNodeList( mv->GetAbsOrigin(), 100.0f, ladder, nearbyDismounts ); - - int i; - - for ( i = nearbyDismounts.FirstInorder(); i != nearbyDismounts.InvalidIndex() ; i = nearbyDismounts.NextInorder( i ) ) - { - CInfoLadderDismount *spot = nearbyDismounts[ i ].dismount; - if ( !spot ) - { - Assert( !"What happened to the spot!!!" ); - continue; - } - - // See if it's valid to put the player there... - Vector org = spot->GetAbsOrigin() + Vector( 0, 0, 1 ); - - trace_t tr; - UTIL_TraceHull( - org, - org, - GetPlayerMins( ( player->GetFlags() & FL_DUCKING ) ? true : false ), - GetPlayerMaxs( ( player->GetFlags() & FL_DUCKING ) ? true : false ), - MASK_PLAYERSOLID, - player, - COLLISION_GROUP_PLAYER_MOVEMENT, - &tr ); - - // Nope... - if ( tr.startsolid ) - { - continue; - } - - // Find the best dot product - Vector vecToSpot = org - ( mv->GetAbsOrigin() + player->GetViewOffset() ); - vecToSpot.z = 0.0f; - float d = VectorNormalize( vecToSpot ); - - float dot = vecToSpot.Dot( m_vecForward ); - - // We're not facing at it...ignore - if ( dot < 0.5f ) - { - if( useAlternate && d < alternateDist ) - { - alternateDest = org; - alternateDist = d; - foundAlternate = true; - } - - continue; - } - - if ( dot > bestDot ) - { - bestDest = org; - bestDistance = d; - bestDot = dot; - found = true; - } - } - - if ( found ) - { - // Require a more specific - if ( strict && - ( ( bestDot < 0.7f ) || ( bestDistance > 40.0f ) ) ) - { - return false; - } - - StartForcedMove( false, player->MaxSpeed(), bestDest, NULL ); - return true; - } - - if( useAlternate ) - { - // Desperate. Don't refuse to let a person off of a ladder if it can be helped. Use the - // alternate dismount if there is one. - if( foundAlternate && alternateDist <= 60.0f ) - { - StartForcedMove( false, player->MaxSpeed(), alternateDest, NULL ); - return true; - } - } - - return false; + // Find the best ladder exit node + float bestDot = -99999.0f; + float bestDistance = 99999.0f; + Vector bestDest; + bool found = false; + + // For 'alternate' dismount + bool foundAlternate = false; + Vector alternateDest; + float alternateDist = 99999.0f; + + CUtlRBTree< NearbyDismount_t, int > nearbyDismounts( 0, 0, NearbyDismountLessFunc ); + + GetSortedDismountNodeList( mv->GetAbsOrigin(), 100.0f, ladder, nearbyDismounts ); + + int i; + + for ( i = nearbyDismounts.FirstInorder(); i != nearbyDismounts.InvalidIndex(); i = nearbyDismounts.NextInorder( i ) ) + { + CInfoLadderDismount *spot = nearbyDismounts[i].dismount; + if ( !spot ) + { + Assert( !"What happened to the spot!!!" ); + continue; + } + + // See if it's valid to put the player there... + Vector org = spot->GetAbsOrigin() + Vector( 0, 0, 1 ); + + trace_t tr; + UTIL_TraceHull( + org, + org, + GetPlayerMins( ( player->GetFlags() & FL_DUCKING ) ? true : false ), + GetPlayerMaxs( ( player->GetFlags() & FL_DUCKING ) ? true : false ), + MASK_PLAYERSOLID, + player, + COLLISION_GROUP_PLAYER_MOVEMENT, + &tr ); + + // Nope... + if ( tr.startsolid ) + { + continue; + } + + // Find the best dot product + Vector vecToSpot = org - ( mv->GetAbsOrigin() + player->GetViewOffset() ); + vecToSpot.z = 0.0f; + float d = VectorNormalize( vecToSpot ); + + float dot = vecToSpot.Dot( m_vecForward ); + + // We're not facing at it...ignore + if ( dot < 0.5f ) + { + if ( useAlternate && d < alternateDist ) + { + alternateDest = org; + alternateDist = d; + foundAlternate = true; + } + + continue; + } + + if ( dot > bestDot ) + { + bestDest = org; + bestDistance = d; + bestDot = dot; + found = true; + } + } + + if ( found ) + { + // Require a more specific + if ( strict && + ( ( bestDot < 0.7f ) || ( bestDistance > 40.0f ) ) ) + { + return false; + } + + StartForcedMove( false, player->GetMaxSpeed(), bestDest, NULL ); + return true; + } + + if ( useAlternate ) + { + // Desperate. Don't refuse to let a person off of a ladder if it can be helped. Use the + // alternate dismount if there is one. + if ( foundAlternate && alternateDist <= 60.0f ) + { + StartForcedMove( false, player->GetMaxSpeed(), alternateDest, NULL ); + return true; + } + } + + return false; } //----------------------------------------------------------------------------- @@ -523,266 +517,266 @@ bool CHL2GameMovement::ExitLadderViaDismountNode( CFuncLadder *ladder, bool stri void CHL2GameMovement::FullLadderMove() { #if !defined( CLIENT_DLL ) - CFuncLadder *ladder = GetLadder(); - Assert( ladder ); - if ( !ladder ) - { - return; - } - - CheckWater(); - - // Was jump button pressed? If so, don't do anything here - if ( mv->m_nButtons & IN_JUMP ) - { - CheckJumpButton(); - return; - } - else - { - mv->m_nOldButtons &= ~IN_JUMP; - } - - player->SetGroundEntity( NULL ); - - // Remember old positions in case we cancel this movement - Vector oldVelocity = mv->m_vecVelocity; - Vector oldOrigin = mv->GetAbsOrigin(); - - Vector topPosition; - Vector bottomPosition; - - ladder->GetTopPosition( topPosition ); - ladder->GetBottomPosition( bottomPosition ); - - // Compute parametric distance along ladder vector... - float oldt; - CalcDistanceSqrToLine( mv->GetAbsOrigin(), topPosition, bottomPosition, &oldt ); - - // Perform the move accounting for any base velocity. - VectorAdd (mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity); - TryPlayerMove(); - VectorSubtract (mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity); - - // Pressed buttons are "changed(xor)" and'ed with the mask of currently held buttons - int buttonsChanged = ( mv->m_nOldButtons ^ mv->m_nButtons ); // These buttons have changed this frame - int buttonsPressed = buttonsChanged & mv->m_nButtons; - bool pressed_use = ( buttonsPressed & IN_USE ) ? true : false; - bool pressing_forward_or_side = mv->m_flForwardMove != 0.0f || mv->m_flSideMove != 0.0f; - - Vector ladderVec = topPosition - bottomPosition; - float LadderLength = VectorNormalize( ladderVec ); - // This test is not perfect by any means, but should help a bit - bool moving_along_ladder = false; - if ( pressing_forward_or_side ) - { - float fwdDot = m_vecForward.Dot( ladderVec ); - if ( fabs( fwdDot ) > 0.9f ) - { - moving_along_ladder = true; - } - } - - // Compute parametric distance along ladder vector... - float newt; - CalcDistanceSqrToLine( mv->GetAbsOrigin(), topPosition, bottomPosition, &newt ); - - // Fudge of 2 units - float tolerance = 1.0f / LadderLength; - - bool wouldleaveladder = false; - // Moving pPast top or bottom? - if ( newt < -tolerance ) - { - wouldleaveladder = newt < oldt; - } - else if ( newt > ( 1.0f + tolerance ) ) - { - wouldleaveladder = newt > oldt; - } - - // See if we are near the top or bottom but not moving - float dist1sqr, dist2sqr; - - dist1sqr = ( topPosition - mv->GetAbsOrigin() ).LengthSqr(); - dist2sqr = ( bottomPosition - mv->GetAbsOrigin() ).LengthSqr(); - - float dist = MIN( dist1sqr, dist2sqr ); - bool neardismountnode = ( dist < 16.0f * 16.0f ) ? true : false; - float ladderUnitsPerTick = ( MAX_CLIMB_SPEED * gpGlobals->interval_per_tick ); - bool neardismountnode2 = ( dist < ladderUnitsPerTick * ladderUnitsPerTick ) ? true : false; - - // Really close to node, cvar is set, and pressing a key, then simulate a +USE - bool auto_dismount_use = ( neardismountnode2 && - sv_autoladderdismount.GetBool() && - pressing_forward_or_side && - !moving_along_ladder ); - - bool fully_underwater = ( player->GetWaterLevel() == WL_Eyes ) ? true : false; - - // If the user manually pressed use or we're simulating it, then use_dismount will occur - bool use_dismount = pressed_use || auto_dismount_use; - - if ( fully_underwater && !use_dismount ) - { - // If fully underwater, we require looking directly at a dismount node - /// to "float off" a ladder mid way... - if ( ExitLadderViaDismountNode( ladder, true ) ) - { - // See if they +used a dismount point mid-span.. - return; - } - } - - // If the movement would leave the ladder and they're not automated or pressing use, disallow the movement - if ( !use_dismount ) - { - if ( wouldleaveladder ) - { - // Don't let them leave the ladder if they were on it - mv->m_vecVelocity = oldVelocity; - mv->SetAbsOrigin( oldOrigin ); - } - return; - } - - // If the move would not leave the ladder and we're near close to the end, then just accept the move - if ( !wouldleaveladder && !neardismountnode ) - { - // Otherwise, if the move would leave the ladder, disallow it. - if ( pressed_use ) - { - if ( ExitLadderViaDismountNode( ladder, false, IsX360() ) ) - { - // See if they +used a dismount point mid-span.. - return; - } - - player->SetMoveType( MOVETYPE_WALK ); - player->SetMoveCollide( MOVECOLLIDE_DEFAULT ); - SetLadder( NULL ); - GetHL2Player()->m_bPlayUseDenySound = false; - - // Dismount with a bit of velocity in facing direction - VectorScale( m_vecForward, USE_DISMOUNT_SPEED, mv->m_vecVelocity ); - mv->m_vecVelocity.z = 50; - } - return; - } - - // Debounce the use key - if ( pressed_use ) - { - SwallowUseKey(); - } - - // Try auto exit, if possible - if ( ExitLadderViaDismountNode( ladder, false, pressed_use ) ) - { - return; - } - - if ( wouldleaveladder ) - { - // Otherwise, if the move would leave the ladder, disallow it. - if ( pressed_use ) - { - player->SetMoveType( MOVETYPE_WALK ); - player->SetMoveCollide( MOVECOLLIDE_DEFAULT ); - SetLadder( NULL ); - - // Dismount with a bit of velocity in facing direction - VectorScale( m_vecForward, USE_DISMOUNT_SPEED, mv->m_vecVelocity ); - mv->m_vecVelocity.z = 50; - } - else - { - mv->m_vecVelocity = oldVelocity; - mv->SetAbsOrigin( oldOrigin ); - } - } + CFuncLadder *ladder = GetLadder(); + Assert( ladder ); + if ( !ladder ) + { + return; + } + + CheckWater(); + + // Was jump button pressed? If so, don't do anything here + if ( mv->m_nButtons & IN_JUMP ) + { + CheckJumpButton(); + return; + } + else + { + mv->m_nOldButtons &= ~IN_JUMP; + } + + player->SetGroundEntity( NULL ); + + // Remember old positions in case we cancel this movement + Vector oldVelocity = mv->m_vecVelocity; + Vector oldOrigin = mv->GetAbsOrigin(); + + Vector topPosition; + Vector bottomPosition; + + ladder->GetTopPosition( topPosition ); + ladder->GetBottomPosition( bottomPosition ); + + // Compute parametric distance along ladder vector... + float oldt; + CalcDistanceSqrToLine( mv->GetAbsOrigin(), topPosition, bottomPosition, &oldt ); + + // Perform the move accounting for any base velocity. + VectorAdd( mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity ); + TryPlayerMove(); + VectorSubtract( mv->m_vecVelocity, player->GetBaseVelocity(), mv->m_vecVelocity ); + + // Pressed buttons are "changed(xor)" and'ed with the mask of currently held buttons + int buttonsChanged = ( mv->m_nOldButtons ^ mv->m_nButtons ); // These buttons have changed this frame + int buttonsPressed = buttonsChanged & mv->m_nButtons; + bool pressed_use = ( buttonsPressed & IN_USE ) ? true : false; + bool pressing_forward_or_side = mv->m_flForwardMove != 0.0f || mv->m_flSideMove != 0.0f; + + Vector ladderVec = topPosition - bottomPosition; + float LadderLength = VectorNormalize( ladderVec ); + // This test is not perfect by any means, but should help a bit + bool moving_along_ladder = false; + if ( pressing_forward_or_side ) + { + float fwdDot = m_vecForward.Dot( ladderVec ); + if ( fabs( fwdDot ) > 0.9f ) + { + moving_along_ladder = true; + } + } + + // Compute parametric distance along ladder vector... + float newt; + CalcDistanceSqrToLine( mv->GetAbsOrigin(), topPosition, bottomPosition, &newt ); + + // Fudge of 2 units + float tolerance = 1.0f / LadderLength; + + bool wouldleaveladder = false; + // Moving pPast top or bottom? + if ( newt < -tolerance ) + { + wouldleaveladder = newt < oldt; + } + else if ( newt > ( 1.0f + tolerance ) ) + { + wouldleaveladder = newt > oldt; + } + + // See if we are near the top or bottom but not moving + float dist1sqr, dist2sqr; + + dist1sqr = ( topPosition - mv->GetAbsOrigin() ).LengthSqr(); + dist2sqr = ( bottomPosition - mv->GetAbsOrigin() ).LengthSqr(); + + float dist = MIN( dist1sqr, dist2sqr ); + bool neardismountnode = ( dist < 16.0f * 16.0f ) ? true : false; + float ladderUnitsPerTick = ( MAX_CLIMB_SPEED * gpGlobals->interval_per_tick ); + bool neardismountnode2 = ( dist < ladderUnitsPerTick * ladderUnitsPerTick ) ? true : false; + + // Really close to node, cvar is set, and pressing a key, then simulate a +USE + bool auto_dismount_use = ( neardismountnode2 && + sv_autoladderdismount.GetBool() && + pressing_forward_or_side && + !moving_along_ladder ); + + bool fully_underwater = ( player->GetWaterLevel() == WL_Eyes ) ? true : false; + + // If the user manually pressed use or we're simulating it, then use_dismount will occur + bool use_dismount = pressed_use || auto_dismount_use; + + if ( fully_underwater && !use_dismount ) + { + // If fully underwater, we require looking directly at a dismount node + /// to "float off" a ladder mid way... + if ( ExitLadderViaDismountNode( ladder, true ) ) + { + // See if they +used a dismount point mid-span.. + return; + } + } + + // If the movement would leave the ladder and they're not automated or pressing use, disallow the movement + if ( !use_dismount ) + { + if ( wouldleaveladder ) + { + // Don't let them leave the ladder if they were on it + mv->m_vecVelocity = oldVelocity; + mv->SetAbsOrigin( oldOrigin ); + } + return; + } + + // If the move would not leave the ladder and we're near close to the end, then just accept the move + if ( !wouldleaveladder && !neardismountnode ) + { + // Otherwise, if the move would leave the ladder, disallow it. + if ( pressed_use ) + { + if ( ExitLadderViaDismountNode( ladder, false, IsX360() ) ) + { + // See if they +used a dismount point mid-span.. + return; + } + + player->SetMoveType( MOVETYPE_WALK ); + player->SetMoveCollide( MOVECOLLIDE_DEFAULT ); + SetLadder( NULL ); + GetHL2Player()->m_bPlayUseDenySound = false; + + // Dismount with a bit of velocity in facing direction + VectorScale( m_vecForward, USE_DISMOUNT_SPEED, mv->m_vecVelocity ); + mv->m_vecVelocity.z = 50; + } + return; + } + + // Debounce the use key + if ( pressed_use ) + { + SwallowUseKey(); + } + + // Try auto exit, if possible + if ( ExitLadderViaDismountNode( ladder, false, pressed_use ) ) + { + return; + } + + if ( wouldleaveladder ) + { + // Otherwise, if the move would leave the ladder, disallow it. + if ( pressed_use ) + { + player->SetMoveType( MOVETYPE_WALK ); + player->SetMoveCollide( MOVECOLLIDE_DEFAULT ); + SetLadder( NULL ); + + // Dismount with a bit of velocity in facing direction + VectorScale( m_vecForward, USE_DISMOUNT_SPEED, mv->m_vecVelocity ); + mv->m_vecVelocity.z = 50; + } + else + { + mv->m_vecVelocity = oldVelocity; + mv->SetAbsOrigin( oldOrigin ); + } + } #endif } -bool CHL2GameMovement::CheckLadderAutoMountEndPoint( CFuncLadder *ladder, const Vector& bestOrigin ) +bool CHL2GameMovement::CheckLadderAutoMountEndPoint( CFuncLadder *ladder, const Vector &bestOrigin ) { - // See if we're really near an endpoint - if ( !ladder ) - return false; + // See if we're really near an endpoint + if ( !ladder ) + return false; - Vector top, bottom; - ladder->GetTopPosition( top ); - ladder->GetBottomPosition( bottom ); + Vector top, bottom; + ladder->GetTopPosition( top ); + ladder->GetBottomPosition( bottom ); - float d1, d2; + float d1, d2; - d1 = ( top - mv->GetAbsOrigin() ).LengthSqr(); - d2 = ( bottom - mv->GetAbsOrigin() ).LengthSqr(); + d1 = ( top - mv->GetAbsOrigin() ).LengthSqr(); + d2 = ( bottom - mv->GetAbsOrigin() ).LengthSqr(); - if ( d1 > 16 * 16 && d2 > 16 * 16 ) - return false; + if ( d1 > 16 * 16 && d2 > 16 * 16 ) + return false; - Vector ladderAxis; + Vector ladderAxis; - if ( d1 < 16 * 16 ) - { - // Close to top - ladderAxis = bottom - top; - } - else - { - ladderAxis = top - bottom; - } + if ( d1 < 16 * 16 ) + { + // Close to top + ladderAxis = bottom - top; + } + else + { + ladderAxis = top - bottom; + } - VectorNormalize( ladderAxis ); + VectorNormalize( ladderAxis ); - if ( ladderAxis.Dot( m_vecForward ) > sv_ladderautomountdot.GetFloat() ) - { - StartForcedMove( true, player->MaxSpeed(), bestOrigin, ladder ); - return true; - } + if ( ladderAxis.Dot( m_vecForward ) > sv_ladderautomountdot.GetFloat() ) + { + StartForcedMove( true, player->GetMaxSpeed(), bestOrigin, ladder ); + return true; + } - return false; + return false; } -bool CHL2GameMovement::CheckLadderAutoMountCone( CFuncLadder *ladder, const Vector& bestOrigin, float maxAngleDelta, float maxDistToLadder ) +bool CHL2GameMovement::CheckLadderAutoMountCone( CFuncLadder *ladder, const Vector &bestOrigin, float maxAngleDelta, float maxDistToLadder ) { - // Never 'back' onto ladders or stafe onto ladders - if ( ladder != NULL && - ( mv->m_flForwardMove > 0.0f ) ) - { - Vector top, bottom; - ladder->GetTopPosition( top ); - ladder->GetBottomPosition( bottom ); + // Never 'back' onto ladders or stafe onto ladders + if ( ladder != NULL && + ( mv->m_flForwardMove > 0.0f ) ) + { + Vector top, bottom; + ladder->GetTopPosition( top ); + ladder->GetBottomPosition( bottom ); - Vector ladderAxis = top - bottom; - VectorNormalize( ladderAxis ); + Vector ladderAxis = top - bottom; + VectorNormalize( ladderAxis ); - Vector probe = mv->GetAbsOrigin(); + Vector probe = mv->GetAbsOrigin(); - Vector closest; - CalcClosestPointOnLineSegment( probe, bottom, top, closest, NULL ); + Vector closest; + CalcClosestPointOnLineSegment( probe, bottom, top, closest, NULL ); - Vector vecToLadder = closest - probe; + Vector vecToLadder = closest - probe; - float dist = VectorNormalize( vecToLadder ); + float dist = VectorNormalize( vecToLadder ); - Vector flatLadder = vecToLadder; - flatLadder.z = 0.0f; - Vector flatForward = m_vecForward; - flatForward.z = 0.0f; + Vector flatLadder = vecToLadder; + flatLadder.z = 0.0f; + Vector flatForward = m_vecForward; + flatForward.z = 0.0f; - VectorNormalize( flatLadder ); - VectorNormalize( flatForward ); + VectorNormalize( flatLadder ); + VectorNormalize( flatForward ); - float facingDot = flatForward.Dot( flatLadder ); - float angle = acos( facingDot ) * 180 / M_PI; + float facingDot = flatForward.Dot( flatLadder ); + float angle = acos( facingDot ) * 180 / M_PI; - bool closetoladder = ( dist != 0.0f && dist < maxDistToLadder ) ? true : false; - bool reallyclosetoladder = ( dist != 0.0f && dist < 4.0f ) ? true : false; + bool closetoladder = ( dist != 0.0f && dist < maxDistToLadder ) ? true : false; + bool reallyclosetoladder = ( dist != 0.0f && dist < 4.0f ) ? true : false; - bool facingladderaxis = ( angle < maxAngleDelta ) ? true : false; - bool facingalongaxis = ( (float)fabs( ladderAxis.Dot( m_vecForward ) ) > sv_ladderautomountdot.GetFloat() ) ? true : false; + bool facingladderaxis = ( angle < maxAngleDelta ) ? true : false; + bool facingalongaxis = ( ( float )fabs( ladderAxis.Dot( m_vecForward ) ) > sv_ladderautomountdot.GetFloat() ) ? true : false; #if 0 Msg( "close %i length %.3f maxdist %.3f facing %.3f dot %.3f ang %.3f\n", closetoladder ? 1 : 0, @@ -793,19 +787,19 @@ bool CHL2GameMovement::CheckLadderAutoMountCone( CFuncLadder *ladder, const Vect angle); #endif - // Tracker 21776: Don't mount ladders this way if strafing - bool strafing = ( fabs( mv->m_flSideMove ) < 1.0f ) ? false : true; + // Tracker 21776: Don't mount ladders this way if strafing + bool strafing = ( fabs( mv->m_flSideMove ) < 1.0f ) ? false : true; - if ( ( ( facingDot > 0.0f && !strafing ) || facingalongaxis ) && - ( facingladderaxis || reallyclosetoladder ) && - closetoladder ) - { - StartForcedMove( true, player->MaxSpeed(), bestOrigin, ladder ); - return true; - } - } + if ( ( ( facingDot > 0.0f && !strafing ) || facingalongaxis ) && + ( facingladderaxis || reallyclosetoladder ) && + closetoladder ) + { + StartForcedMove( true, player->GetMaxSpeed(), bestOrigin, ladder ); + return true; + } + } - return false; + return false; } //----------------------------------------------------------------------------- @@ -815,67 +809,67 @@ bool CHL2GameMovement::CheckLadderAutoMountCone( CFuncLadder *ladder, const Vect //----------------------------------------------------------------------------- bool CHL2GameMovement::LookingAtLadder( CFuncLadder *ladder ) { - if ( !ladder ) - { - return false; - } + if ( !ladder ) + { + return false; + } - // Get ladder end points - Vector top, bottom; - ladder->GetTopPosition( top ); - ladder->GetBottomPosition( bottom ); + // Get ladder end points + Vector top, bottom; + ladder->GetTopPosition( top ); + ladder->GetBottomPosition( bottom ); - // Find closest point on ladder to player (could be an endpoint) - Vector closest; - CalcClosestPointOnLineSegment( mv->GetAbsOrigin(), bottom, top, closest, NULL ); + // Find closest point on ladder to player (could be an endpoint) + Vector closest; + CalcClosestPointOnLineSegment( mv->GetAbsOrigin(), bottom, top, closest, NULL ); - // Flatten our view direction to 2D - Vector flatForward = m_vecForward; - flatForward.z = 0.0f; + // Flatten our view direction to 2D + Vector flatForward = m_vecForward; + flatForward.z = 0.0f; - // Because the ladder itself is not a solid, the player's origin may actually be - // permitted to pass it, and that will screw up our dot product. - // So back up the player's origin a bit to do the facing calculation. - Vector vecAdjustedOrigin = mv->GetAbsOrigin() - 8.0f * flatForward; + // Because the ladder itself is not a solid, the player's origin may actually be + // permitted to pass it, and that will screw up our dot product. + // So back up the player's origin a bit to do the facing calculation. + Vector vecAdjustedOrigin = mv->GetAbsOrigin() - 8.0f * flatForward; - // Figure out vector from player to closest point on ladder - Vector vecToLadder = closest - vecAdjustedOrigin; + // Figure out vector from player to closest point on ladder + Vector vecToLadder = closest - vecAdjustedOrigin; - // Flatten it to 2D - Vector flatLadder = vecToLadder; - flatLadder.z = 0.0f; + // Flatten it to 2D + Vector flatLadder = vecToLadder; + flatLadder.z = 0.0f; - // Normalize the vectors (unnecessary) - VectorNormalize( flatLadder ); - VectorNormalize( flatForward ); + // Normalize the vectors (unnecessary) + VectorNormalize( flatLadder ); + VectorNormalize( flatForward ); - // Compute dot product to see if forward is in same direction as vec to ladder - float facingDot = flatForward.Dot( flatLadder ); + // Compute dot product to see if forward is in same direction as vec to ladder + float facingDot = flatForward.Dot( flatLadder ); - float requiredDot = ( sv_ladder_useonly.GetBool() ) ? -0.99 : 0.0; + float requiredDot = ( sv_ladder_useonly.GetBool() ) ? -0.99 : 0.0; - // Facing same direction if dot > = requiredDot... - bool facingladder = ( facingDot >= requiredDot ); + // Facing same direction if dot > = requiredDot... + bool facingladder = ( facingDot >= requiredDot ); - return facingladder; + return facingladder; } //----------------------------------------------------------------------------- // Purpose: // Input : &trace - //----------------------------------------------------------------------------- -bool CHL2GameMovement::CheckLadderAutoMount( CFuncLadder *ladder, const Vector& bestOrigin ) +bool CHL2GameMovement::CheckLadderAutoMount( CFuncLadder *ladder, const Vector &bestOrigin ) { #if !defined( CLIENT_DLL ) - if ( ladder != NULL ) - { - StartForcedMove( true, player->MaxSpeed(), bestOrigin, ladder ); - return true; - } + if ( ladder != NULL ) + { + StartForcedMove( true, player->GetMaxSpeed(), bestOrigin, ladder ); + return true; + } #endif - return false; + return false; } //----------------------------------------------------------------------------- @@ -883,270 +877,267 @@ bool CHL2GameMovement::CheckLadderAutoMount( CFuncLadder *ladder, const Vector& //----------------------------------------------------------------------------- bool CHL2GameMovement::LadderMove( void ) { + if ( player->GetMoveType() == MOVETYPE_NOCLIP ) + { + SetLadder( NULL ); + return false; + } + + // If being forced to mount/dismount continue to act like we are on the ladder + if ( IsForceMoveActive() && ContinueForcedMove() ) + { + return true; + } + + CFuncLadder *bestLadder = NULL; + Vector bestOrigin( 0, 0, 0 ); + + CFuncLadder *ladder = GetLadder(); + + // Something 1) deactivated the ladder... or 2) something external applied + // a force to us. In either case make the player fall, etc. + if ( ladder && + ( !ladder->IsEnabled() || + ( player->GetBaseVelocity().LengthSqr() > 1.0f ) ) ) + { + GetHL2Player()->ExitLadder(); + ladder = NULL; + } + + if ( !ladder ) + { + Findladder( 64.0f, &bestLadder, bestOrigin, NULL ); + } - if ( player->GetMoveType() == MOVETYPE_NOCLIP ) - { - SetLadder( NULL ); - return false; - } - - // If being forced to mount/dismount continue to act like we are on the ladder - if ( IsForceMoveActive() && ContinueForcedMove() ) - { - return true; - } - - CFuncLadder *bestLadder = NULL; - Vector bestOrigin( 0, 0, 0 ); - - CFuncLadder *ladder = GetLadder(); - - // Something 1) deactivated the ladder... or 2) something external applied - // a force to us. In either case make the player fall, etc. - if ( ladder && - ( !ladder->IsEnabled() || - ( player->GetBaseVelocity().LengthSqr() > 1.0f ) ) ) - { - GetHL2Player()->ExitLadder(); - ladder = NULL; - } - - if ( !ladder ) - { - Findladder( 64.0f, &bestLadder, bestOrigin, NULL ); - } - -#if !defined (CLIENT_DLL) - if( !ladder && bestLadder && sv_ladder_useonly.GetBool() ) - { - GetHL2Player()->DisplayLadderHudHint(); - } +#if !defined( CLIENT_DLL ) + if ( !ladder && bestLadder && sv_ladder_useonly.GetBool() ) + { + GetHL2Player()->DisplayLadderHudHint(); + } #endif - int buttonsChanged = ( mv->m_nOldButtons ^ mv->m_nButtons ); // These buttons have changed this frame - int buttonsPressed = buttonsChanged & mv->m_nButtons; - bool pressed_use = ( buttonsPressed & IN_USE ) ? true : false; - - // If I'm already moving on a ladder, use the previous ladder direction - if ( !ladder && !pressed_use ) - { - // If flying through air, allow mounting ladders if we are facing < 15 degress from the ladder and we are close - if ( !ladder && !sv_ladder_useonly.GetBool() ) - { - // Tracker 6625: Don't need to be leaping to auto mount using this method... - // But if we are on the ground, then we must not be backing into the ladder (Tracker 12961) - bool onground = player->GetGroundEntity() ? true : false; - if ( !onground || ( mv->m_flForwardMove > 0.0f ) ) - { - if ( CheckLadderAutoMountCone( bestLadder, bestOrigin, 15.0f, 32.0f ) ) - { - return true; - } - } - - // Pressing forward while looking at ladder and standing (or floating) near a mounting point - if ( mv->m_flForwardMove > 0.0f ) - { - if ( CheckLadderAutoMountEndPoint( bestLadder, bestOrigin ) ) - { - return true; - } - } - } - - return false; - } - - if ( !ladder && - LookingAtLadder( bestLadder ) && - CheckLadderAutoMount( bestLadder, bestOrigin ) ) - { - return true; - } - - // Reassign the ladder - ladder = GetLadder(); - if ( !ladder ) - { - return false; - } - - // Don't play the deny sound - if ( pressed_use ) - { - GetHL2Player()->m_bPlayUseDenySound = false; - } - - // Make sure we are on the ladder - player->SetMoveType( MOVETYPE_LADDER ); - player->SetMoveCollide( MOVECOLLIDE_DEFAULT ); - - player->SetGravity( 0.0f ); - - float forwardSpeed = 0.0f; - float rightSpeed = 0.0f; - - float speed = player->MaxSpeed(); - - - if ( mv->m_nButtons & IN_BACK ) - { - forwardSpeed -= speed; - } - - if ( mv->m_nButtons & IN_FORWARD ) - { - forwardSpeed += speed; - } - - if ( mv->m_nButtons & IN_MOVELEFT ) - { - rightSpeed -= speed; - } - - if ( mv->m_nButtons & IN_MOVERIGHT ) - { - rightSpeed += speed; - } - - if ( mv->m_nButtons & IN_JUMP ) - { - player->SetMoveType( MOVETYPE_WALK ); - // Remove from ladder - SetLadder( NULL ); - - // Jump in view direction - Vector jumpDir = m_vecForward; - - // unless pressing backward or something like that - if ( mv->m_flForwardMove < 0.0f ) - { - jumpDir = -jumpDir; - } - - VectorNormalize( jumpDir ); - - VectorScale( jumpDir, MAX_CLIMB_SPEED, mv->m_vecVelocity ); - // Tracker 13558: Don't add any extra z velocity if facing downward at all - if ( m_vecForward.z >= 0.0f ) - { - mv->m_vecVelocity.z = mv->m_vecVelocity.z + 50; - } - return false; - } - - if ( forwardSpeed != 0 || rightSpeed != 0 ) - { - // See if the player is looking toward the top or the bottom - Vector velocity; - - VectorScale( m_vecForward, forwardSpeed, velocity ); - VectorMA( velocity, rightSpeed, m_vecRight, velocity ); - - VectorNormalize( velocity ); - - Vector ladderUp; - ladder->ComputeLadderDir( ladderUp ); - VectorNormalize( ladderUp ); - - Vector topPosition; - Vector bottomPosition; - - ladder->GetTopPosition( topPosition ); - ladder->GetBottomPosition( bottomPosition ); - - // Check to see if we've mounted the ladder in a bogus spot and, if so, just fall off the ladder... - float dummyt = 0.0f; - float distFromLadderSqr = CalcDistanceSqrToLine( mv->GetAbsOrigin(), topPosition, bottomPosition, &dummyt ); - if ( distFromLadderSqr > 36.0f ) - { - // Uh oh, we fell off zee ladder... - player->SetMoveType( MOVETYPE_WALK ); - // Remove from ladder - SetLadder( NULL ); - return false; - } - - bool ishorizontal = fabs( topPosition.z - bottomPosition.z ) < 64.0f ? true : false; - - float changeover = ishorizontal ? 0.0f : 0.3f; - - float factor = 1.0f; - if ( velocity.z >= 0 ) - { - float dotTop = ladderUp.Dot( velocity ); - if ( dotTop < -changeover ) - { - // Aimed at bottom - factor = -1.0f; - } - } - else - { - float dotBottom = -ladderUp.Dot( velocity ); - if ( dotBottom > changeover ) - { - factor = -1.0f; - } - } + int buttonsChanged = ( mv->m_nOldButtons ^ mv->m_nButtons ); // These buttons have changed this frame + int buttonsPressed = buttonsChanged & mv->m_nButtons; + bool pressed_use = ( buttonsPressed & IN_USE ) ? true : false; + + // If I'm already moving on a ladder, use the previous ladder direction + if ( !ladder && !pressed_use ) + { + // If flying through air, allow mounting ladders if we are facing < 15 degress from the ladder and we are close + if ( !ladder && !sv_ladder_useonly.GetBool() ) + { + // Tracker 6625: Don't need to be leaping to auto mount using this method... + // But if we are on the ground, then we must not be backing into the ladder (Tracker 12961) + bool onground = player->GetGroundEntity() ? true : false; + if ( !onground || ( mv->m_flForwardMove > 0.0f ) ) + { + if ( CheckLadderAutoMountCone( bestLadder, bestOrigin, 15.0f, 32.0f ) ) + { + return true; + } + } + + // Pressing forward while looking at ladder and standing (or floating) near a mounting point + if ( mv->m_flForwardMove > 0.0f ) + { + if ( CheckLadderAutoMountEndPoint( bestLadder, bestOrigin ) ) + { + return true; + } + } + } + + return false; + } + + if ( !ladder && + LookingAtLadder( bestLadder ) && + CheckLadderAutoMount( bestLadder, bestOrigin ) ) + { + return true; + } + + // Reassign the ladder + ladder = GetLadder(); + if ( !ladder ) + { + return false; + } + + // Don't play the deny sound + if ( pressed_use ) + { + GetHL2Player()->m_bPlayUseDenySound = false; + } + + // Make sure we are on the ladder + player->SetMoveType( MOVETYPE_LADDER ); + player->SetMoveCollide( MOVECOLLIDE_DEFAULT ); + + player->SetGravity( 0.0f ); + + float forwardSpeed = 0.0f; + float rightSpeed = 0.0f; + + float speed = player->GetMaxSpeed(); + + if ( mv->m_nButtons & IN_BACK ) + { + forwardSpeed -= speed; + } + + if ( mv->m_nButtons & IN_FORWARD ) + { + forwardSpeed += speed; + } + + if ( mv->m_nButtons & IN_MOVELEFT ) + { + rightSpeed -= speed; + } + + if ( mv->m_nButtons & IN_MOVERIGHT ) + { + rightSpeed += speed; + } + + if ( mv->m_nButtons & IN_JUMP ) + { + player->SetMoveType( MOVETYPE_WALK ); + // Remove from ladder + SetLadder( NULL ); + + // Jump in view direction + Vector jumpDir = m_vecForward; + + // unless pressing backward or something like that + if ( mv->m_flForwardMove < 0.0f ) + { + jumpDir = -jumpDir; + } + + VectorNormalize( jumpDir ); + + VectorScale( jumpDir, MAX_CLIMB_SPEED, mv->m_vecVelocity ); + // Tracker 13558: Don't add any extra z velocity if facing downward at all + if ( m_vecForward.z >= 0.0f ) + { + mv->m_vecVelocity.z = mv->m_vecVelocity.z + 50; + } + return false; + } + + if ( forwardSpeed != 0 || rightSpeed != 0 ) + { + // See if the player is looking toward the top or the bottom + Vector velocity; + + VectorScale( m_vecForward, forwardSpeed, velocity ); + VectorMA( velocity, rightSpeed, m_vecRight, velocity ); + + VectorNormalize( velocity ); + + Vector ladderUp; + ladder->ComputeLadderDir( ladderUp ); + VectorNormalize( ladderUp ); + + Vector topPosition; + Vector bottomPosition; + + ladder->GetTopPosition( topPosition ); + ladder->GetBottomPosition( bottomPosition ); + + // Check to see if we've mounted the ladder in a bogus spot and, if so, just fall off the ladder... + float dummyt = 0.0f; + float distFromLadderSqr = CalcDistanceSqrToLine( mv->GetAbsOrigin(), topPosition, bottomPosition, &dummyt ); + if ( distFromLadderSqr > 36.0f ) + { + // Uh oh, we fell off zee ladder... + player->SetMoveType( MOVETYPE_WALK ); + // Remove from ladder + SetLadder( NULL ); + return false; + } + + bool ishorizontal = fabs( topPosition.z - bottomPosition.z ) < 64.0f ? true : false; + + float changeover = ishorizontal ? 0.0f : 0.3f; + + float factor = 1.0f; + if ( velocity.z >= 0 ) + { + float dotTop = ladderUp.Dot( velocity ); + if ( dotTop < -changeover ) + { + // Aimed at bottom + factor = -1.0f; + } + } + else + { + float dotBottom = -ladderUp.Dot( velocity ); + if ( dotBottom > changeover ) + { + factor = -1.0f; + } + } #ifdef _XBOX - if( sv_ladders_useonly.GetBool() ) - { - // Stick up climbs up, stick down climbs down. No matter which way you're looking. - if ( mv->m_nButtons & IN_FORWARD ) - { - factor = 1.0f; - } - else if( mv->m_nButtons & IN_BACK ) - { - factor = -1.0f; - } - } -#endif//_XBOX - - mv->m_vecVelocity = MAX_CLIMB_SPEED * factor * ladderUp; - } - else - { - mv->m_vecVelocity.Init(); - } - - return true; + if ( sv_ladders_useonly.GetBool() ) + { + // Stick up climbs up, stick down climbs down. No matter which way you're looking. + if ( mv->m_nButtons & IN_FORWARD ) + { + factor = 1.0f; + } + else if ( mv->m_nButtons & IN_BACK ) + { + factor = -1.0f; + } + } +#endif //_XBOX + + mv->m_vecVelocity = MAX_CLIMB_SPEED * factor * ladderUp; + } + else + { + mv->m_vecVelocity.Init(); + } + + return true; } void CHL2GameMovement::SetGroundEntity( trace_t *pm ) { - CBaseEntity *newGround = pm ? pm->m_pEnt : NULL; + CBaseEntity *newGround = pm ? pm->m_pEnt : NULL; - //Adrian: Special case for combine balls. - if ( newGround && newGround->GetCollisionGroup() == HL2COLLISION_GROUP_COMBINE_BALL_NPC ) - { - return; - } + // Adrian: Special case for combine balls. + if ( newGround && newGround->GetCollisionGroup() == HL2COLLISION_GROUP_COMBINE_BALL_NPC ) + { + return; + } - BaseClass::SetGroundEntity( pm ); + BaseClass::SetGroundEntity( pm ); } bool CHL2GameMovement::CanAccelerate() { #if defined( HL2MP ) || defined( EXPERIMENT_SOURCE ) - if ( player->IsObserver() ) - { - return true; - } + if ( player->IsObserver() ) + { + return true; + } #endif - BaseClass::CanAccelerate(); + BaseClass::CanAccelerate(); - return true; + return true; } +#ifndef PORTAL // Portal inherits from this but needs to declare it's own global interface +// Expose our interface. +static CHL2GameMovement g_GameMovement; +IGameMovement *g_pGameMovement = ( IGameMovement * )&g_GameMovement; -#ifndef PORTAL // Portal inherits from this but needs to declare it's own global interface - // Expose our interface. - static CHL2GameMovement g_GameMovement; - IGameMovement *g_pGameMovement = ( IGameMovement * )&g_GameMovement; - - EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CGameMovement, IGameMovement,INTERFACENAME_GAMEMOVEMENT, g_GameMovement ); +EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CGameMovement, IGameMovement, INTERFACENAME_GAMEMOVEMENT, g_GameMovement ); #endif diff --git a/src/game/shared/lbasecombatweapon_shared.cpp b/src/game/shared/lbasecombatweapon_shared.cpp index 867fa31853..1a27b2a740 100644 --- a/src/game/shared/lbasecombatweapon_shared.cpp +++ b/src/game/shared/lbasecombatweapon_shared.cpp @@ -965,6 +965,25 @@ LUA_BINDING_BEGIN( Weapon, SetIdealActivity, "class", "Set ideal activity." ) } LUA_BINDING_END() +// SetNextSecondaryFire and primary first: +LUA_BINDING_BEGIN( Weapon, SetNextPrimaryFire, "class", "Set next time before the player can fire the primary attack. E.g: `Engines.GetCurrentTime() + 2` for two seconds from now." ) +{ + lua_CBaseCombatWeapon *pWeapon = LUA_BINDING_ARGUMENT( luaL_checkweapon, 1, "entity" ); + float flTime = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "absoluteCurTime" ); + pWeapon->m_flNextPrimaryAttack = flTime; + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( Weapon, SetNextSecondaryFire, "class", "Set next time before the player can fire the secondary attack. E.g: `Engines.GetCurrentTime() + 2` for two seconds from now." ) +{ + lua_CBaseCombatWeapon *pWeapon = LUA_BINDING_ARGUMENT( luaL_checkweapon, 1, "entity" ); + float flTime = LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "absoluteCurTime" ); + pWeapon->m_flNextSecondaryAttack = flTime; + return 0; +} +LUA_BINDING_END() + LUA_BINDING_BEGIN( Weapon, SetPickupTouch, "class", "Set pickup touch." ) { lua_CBaseCombatWeapon *pWeapon = LUA_BINDING_ARGUMENT( luaL_checkweapon, 1, "entity" ); diff --git a/src/game/shared/lbaseplayer_shared.cpp b/src/game/shared/lbaseplayer_shared.cpp index 66c9d43fda..99b65c46df 100644 --- a/src/game/shared/lbaseplayer_shared.cpp +++ b/src/game/shared/lbaseplayer_shared.cpp @@ -726,7 +726,7 @@ LUA_BINDING_END() LUA_BINDING_BEGIN( Player, GetMaxSpeed, "class", "Get the player's max speed." ) { lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); - lua_pushnumber( L, player->MaxSpeed() ); + lua_pushnumber( L, player->GetMaxSpeed() ); return 1; } LUA_BINDING_END( "number", "The player's max speed." ) @@ -904,7 +904,7 @@ LUA_BINDING_BEGIN( Player, SetLadderNormal, "class", "Set the player's ladder no } LUA_BINDING_END() -LUA_BINDING_BEGIN( Player, SetMaxSpeed, "class", "Set the player's max speed." ) +LUA_BINDING_BEGIN( Player, SetMaxSpeed, "class", "Set the player's current max speed." ) { lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); player->SetMaxSpeed( LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "speed" ) ); @@ -912,6 +912,70 @@ LUA_BINDING_BEGIN( Player, SetMaxSpeed, "class", "Set the player's max speed." ) } LUA_BINDING_END() +LUA_BINDING_BEGIN( Player, SetWalkSpeed, "class", "Set the player's walking speed (for when they press ALT)." ) +{ + lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); + player->SetWalkSpeed( LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "speed" ) ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( Player, GetWalkSpeed, "class", "Get the player's walking speed (for when they press ALT)." ) +{ + lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); + lua_pushnumber( L, player->GetWalkSpeed() ); + return 1; +} +LUA_BINDING_END( "number", "The player's walking speed." ) + +LUA_BINDING_BEGIN( Player, SetNormalSpeed, "class", "Set the player's normal speed (for when neither sprinting, walking nor crouching)" ) +{ + lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); + player->SetNormalSpeed( LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "speed" ) ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( Player, GetNormalSpeed, "class", "Get the player's normal speed (for when neither sprinting, walking nor crouching)" ) +{ + lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); + lua_pushnumber( L, player->GetNormalSpeed() ); + return 1; +} +LUA_BINDING_END( "number", "The player's normal speed." ) + +LUA_BINDING_BEGIN( Player, SetRunSpeed, "class", "Set the player's sprint speed." ) +{ + lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); + player->SetRunSpeed( LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "speed" ) ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( Player, GetRunSpeed, "class", "Get the player's sprint speed." ) +{ + lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); + lua_pushnumber( L, player->GetRunSpeed() ); + return 1; +} +LUA_BINDING_END( "number", "The player's sprint speed." ) + +LUA_BINDING_BEGIN( Player, SetCrouchWalkFraction, "class", "Set the fraction by which player's walk speed will be multiplied when crouched." ) +{ + lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); + player->SetCrouchWalkFraction( LUA_BINDING_ARGUMENT( luaL_checknumber, 2, "speed" ) ); + return 0; +} +LUA_BINDING_END() + +LUA_BINDING_BEGIN( Player, GetCrouchWalkFraction, "class", "Get the fraction by which player's walk speed will be multiplied when crouched." ) +{ + lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" ); + lua_pushnumber( L, player->GetCrouchWalkFraction() ); + return 1; +} +LUA_BINDING_END( "number", "The player's crouched walk speed fraction." ) + LUA_BINDING_BEGIN( Player, SetNextAttack, "class", "Set the player's next attack." ) { lua_CBasePlayer *player = LUA_BINDING_ARGUMENT( luaL_checkplayer, 1, "player" );