2023-10-03 14:23:56 +00:00
//========= Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ============//
2020-04-22 16:56:21 +00:00
//
// Purpose:
//
// $Workfile: $
// $Date: $
// $NoKeywords: $
//=============================================================================//
# if !defined( GAMEMOVEMENT_H )
# define GAMEMOVEMENT_H
# ifdef _WIN32
# pragma once
# endif
# include "igamemovement.h"
# include "cmodel.h"
# include "tier0/vprof.h"
# define CTEXTURESMAX 512 // max number of textures loaded
# define CBTEXTURENAMEMAX 13 // only load first n chars of name
2023-10-03 14:23:56 +00:00
# define GAMEMOVEMENT_DUCK_TIME 1000 // ms
# define GAMEMOVEMENT_JUMP_TIME 510 // ms approx - based on the 21 unit height jump
2020-04-22 16:56:21 +00:00
# define GAMEMOVEMENT_JUMP_HEIGHT 21.0f // units
2023-10-03 14:23:56 +00:00
# define GAMEMOVEMENT_TIME_TO_UNDUCK_MSECS ( TIME_TO_UNDUCK_MSECS ) // ms
# define GAMEMOVEMENT_TIME_TO_UNDUCK_MSECS_INV ( GAMEMOVEMENT_DUCK_TIME - GAMEMOVEMENT_TIME_TO_UNDUCK_MSECS )
2020-04-22 16:56:21 +00:00
struct surfacedata_t ;
class CBasePlayer ;
class CGameMovement : public IGameMovement
{
public :
DECLARE_CLASS_NOBASE ( CGameMovement ) ;
CGameMovement ( void ) ;
virtual ~ CGameMovement ( void ) ;
virtual void ProcessMovement ( CBasePlayer * pPlayer , CMoveData * pMove ) ;
2023-10-03 14:23:56 +00:00
virtual void Reset ( void ) ;
2020-04-22 16:56:21 +00:00
virtual void StartTrackPredictionErrors ( CBasePlayer * pPlayer ) ;
virtual void FinishTrackPredictionErrors ( CBasePlayer * pPlayer ) ;
2023-10-03 14:23:56 +00:00
virtual void DiffPrint ( char const * fmt , . . . ) ;
virtual const Vector & GetPlayerMins ( bool ducked ) const ;
virtual const Vector & GetPlayerMaxs ( bool ducked ) const ;
virtual const Vector & GetPlayerViewOffset ( bool ducked ) const ;
virtual void SetupMovementBounds ( CMoveData * pMove ) ;
virtual bool IsMovingPlayerStuck ( void ) const ;
virtual CBasePlayer * GetMovingPlayer ( void ) const ;
virtual void UnblockPusher ( CBasePlayer * pPlayer , CBaseEntity * pPusher ) ;
2020-04-22 16:56:21 +00:00
// For sanity checking getting stuck on CMoveData::SetAbsOrigin
2023-10-03 14:23:56 +00:00
virtual void TracePlayerBBox ( const Vector & start , const Vector & end , unsigned int fMask , int collisionGroup , trace_t & pm ) ;
2020-04-22 16:56:21 +00:00
2023-10-03 14:23:56 +00:00
// wrapper around tracehull to allow tracelistdata optimizations
void GameMovementTraceHull ( const Vector & start , const Vector & end , const Vector & mins , const Vector & maxs , unsigned int fMask , ITraceFilter * pFilter , trace_t * pTrace ) ;
2020-04-22 16:56:21 +00:00
# define BRUSH_ONLY true
2023-10-03 14:23:56 +00:00
virtual unsigned int PlayerSolidMask ( bool brushOnly = false , CBasePlayer * testPlayer = NULL ) const ; ///< returns the solid mask for the given player, so bots can have a more-restrictive set
2020-04-22 16:56:21 +00:00
CBasePlayer * player ;
CMoveData * GetMoveData ( ) { return mv ; }
protected :
// Input/Output for this movement
CMoveData * mv ;
int m_nOldWaterLevel ;
float m_flWaterEntryTime ;
int m_nOnLadder ;
Vector m_vecForward ;
Vector m_vecRight ;
Vector m_vecUp ;
// Does most of the player movement logic.
// Returns with origin, angles, and velocity modified in place.
// were contacted during the move.
virtual void PlayerMove ( void ) ;
// Set ground data, etc.
void FinishMove ( void ) ;
virtual float CalcRoll ( const QAngle & angles , const Vector & velocity , float rollangle , float rollspeed ) ;
virtual void DecayPunchAngle ( void ) ;
virtual void CheckWaterJump ( void ) ;
virtual void WaterMove ( void ) ;
2023-10-03 14:23:56 +00:00
virtual void WaterJump ( void ) ;
2020-04-22 16:56:21 +00:00
// Handles both ground friction and water friction
2023-10-03 14:23:56 +00:00
virtual void Friction ( void ) ;
2020-04-22 16:56:21 +00:00
virtual void AirAccelerate ( Vector & wishdir , float wishspeed , float accel ) ;
virtual void AirMove ( void ) ;
virtual bool CanAccelerate ( ) ;
virtual void Accelerate ( Vector & wishdir , float wishspeed , float accel ) ;
// Only used by players. Moves along the ground when player is a MOVETYPE_WALK.
virtual void WalkMove ( void ) ;
// Try to keep a walking player on the ground when running down slopes etc
2023-10-03 14:23:56 +00:00
virtual void StayOnGround ( void ) ;
2020-04-22 16:56:21 +00:00
// Handle MOVETYPE_WALK.
virtual void FullWalkMove ( ) ;
// Implement this if you want to know when the player collides during OnPlayerMove
virtual void OnTryPlayerMoveCollision ( trace_t & tr ) { }
2023-10-03 14:23:56 +00:00
virtual const Vector & GetPlayerMins ( void ) const ; // uses local player
virtual const Vector & GetPlayerMaxs ( void ) const ; // uses local player
2020-04-22 16:56:21 +00:00
typedef enum
{
GROUND = 0 ,
STUCK ,
2023-10-03 14:23:56 +00:00
LADDER ,
LADDER_WEDGE
2020-04-22 16:56:21 +00:00
} IntervalType_t ;
virtual int GetCheckInterval ( IntervalType_t type ) ;
// Useful for things that happen periodically. This lets things happen on the specified interval, but
// spaces the events onto different frames for different players so they don't all hit their spikes
// simultaneously.
bool CheckInterval ( IntervalType_t type ) ;
// Decompoosed gravity
2023-10-03 14:23:56 +00:00
virtual void StartGravity ( void ) ;
virtual void FinishGravity ( void ) ;
2020-04-22 16:56:21 +00:00
// Apply normal ( undecomposed ) gravity
2023-10-03 14:23:56 +00:00
virtual void AddGravity ( void ) ;
2020-04-22 16:56:21 +00:00
// Handle movement in noclip mode.
void FullNoClipMove ( float factor , float maxacceleration ) ;
// Returns true if he started a jump (ie: should he play the jump animation)?
virtual bool CheckJumpButton ( void ) ; // Overridden by each game.
// Dead player flying through air., e.g.
virtual void FullTossMove ( void ) ;
// Player is a Observer chasing another player
void FullObserverMove ( void ) ;
// Handle movement when in MOVETYPE_LADDER mode.
virtual void FullLadderMove ( ) ;
// The basic solid body movement clip that slides along multiple planes
virtual int TryPlayerMove ( Vector * pFirstDest = NULL , trace_t * pFirstTrace = NULL ) ;
virtual bool LadderMove ( void ) ;
virtual bool OnLadder ( trace_t & trace ) ;
virtual float LadderDistance ( void ) const { return 2.0f ; } ///< Returns the distance a player can be from a ladder and still attach to it
virtual unsigned int LadderMask ( void ) const { return MASK_PLAYERSOLID ; }
virtual float ClimbSpeed ( void ) const { return MAX_CLIMB_SPEED ; }
virtual float LadderLateralMultiplier ( void ) const { return 1.0f ; }
// See if the player has a bogus velocity value.
void CheckVelocity ( void ) ;
// Does not change the entities velocity at all
void PushEntity ( Vector & push , trace_t * pTrace ) ;
// Slide off of the impacting object
// returns the blocked flags:
// 0x01 == floor
// 0x02 == step / wall
2023-10-03 14:23:56 +00:00
virtual int ClipVelocity ( Vector & in , Vector & normal , Vector & out , float overbounce ) ;
2020-04-22 16:56:21 +00:00
// If pmove.origin is in a solid position,
// try nudging slightly on all axis to
// allow for the cut precision of the net coordinates
2023-10-03 14:23:56 +00:00
int CheckStuck ( void ) ;
2020-04-22 16:56:21 +00:00
// Check if the point is in water.
// Sets refWaterLevel and refWaterType appropriately.
// If in water, applies current to baseVelocity, and returns true.
2023-10-03 14:23:56 +00:00
virtual bool CheckWater ( void ) ;
virtual void GetWaterCheckPosition ( int waterLevel , Vector * pos ) ;
2020-04-22 16:56:21 +00:00
// Determine if player is in water, on ground, etc.
virtual void CategorizePosition ( void ) ;
virtual void CheckParameters ( void ) ;
virtual void ReduceTimers ( void ) ;
virtual void CheckFalling ( void ) ;
virtual void PlayerRoughLandingEffects ( float fvol ) ;
void PlayerWaterSounds ( void ) ;
2023-10-03 14:23:56 +00:00
void ResetGetWaterContentsForPointCache ( ) ;
int GetWaterContentsForPointCached ( const Vector & point , int slot ) ;
2020-04-22 16:56:21 +00:00
// Ducking
virtual void Duck ( void ) ;
virtual void HandleDuckingSpeedCrop ( ) ;
virtual void FinishUnDuck ( void ) ;
virtual void FinishDuck ( void ) ;
virtual bool CanUnduck ( ) ;
2023-10-03 14:23:56 +00:00
virtual void UpdateDuckJumpEyeOffset ( void ) ;
virtual bool CanUnDuckJump ( trace_t & trace ) ;
virtual void StartUnDuckJump ( void ) ;
virtual void FinishUnDuckJump ( trace_t & trace ) ;
virtual void SetDuckedEyeOffset ( float duckFraction ) ;
virtual void FixPlayerCrouchStuck ( bool moveup ) ;
2020-04-22 16:56:21 +00:00
float SplineFraction ( float value , float scale ) ;
2023-10-03 14:23:56 +00:00
virtual void CategorizeGroundSurface ( trace_t & pm ) ;
2020-04-22 16:56:21 +00:00
2023-10-03 14:23:56 +00:00
virtual bool InWater ( void ) ;
2020-04-22 16:56:21 +00:00
// Commander view movement
void IsometricMove ( void ) ;
// Traces the player bbox as it is swept from start to end
virtual CBaseHandle TestPlayerPosition ( const Vector & pos , int collisionGroup , trace_t & pm ) ;
// Checks to see if we should actually jump
void PlaySwimSound ( ) ;
bool IsDead ( void ) const ;
// Figures out how the constraint should slow us down
float ComputeConstraintSpeedFactor ( void ) ;
virtual void SetGroundEntity ( trace_t * pm ) ;
virtual void StepMove ( Vector & vecDestination , trace_t & trace ) ;
protected :
2023-10-03 14:23:56 +00:00
virtual ITraceFilter * LockTraceFilter ( int collisionGroup ) ;
virtual void UnlockTraceFilter ( ITraceFilter * & pFilter ) ;
2020-04-22 16:56:21 +00:00
// Performs the collision resolution for fliers.
void PerformFlyCollisionResolution ( trace_t & pm , Vector & move ) ;
virtual bool GameHasLadders ( ) const ;
enum
{
// eyes, waist, feet points (since they are all deterministic
MAX_PC_CACHE_SLOTS = 3 ,
} ;
2023-10-03 14:23:56 +00:00
// Cache used to remove redundant calls to GetPointContents() for water.
2020-04-22 16:56:21 +00:00
int m_CachedGetPointContents [ MAX_PLAYERS ] [ MAX_PC_CACHE_SLOTS ] ;
Vector m_CachedGetPointContentsPoint [ MAX_PLAYERS ] [ MAX_PC_CACHE_SLOTS ] ;
//private:
2023-10-03 14:23:56 +00:00
bool m_bSpeedCropped ;
bool m_bProcessingMovement ;
bool m_bInStuckTest ;
2020-04-22 16:56:21 +00:00
float m_flStuckCheckTime [ MAX_PLAYERS + 1 ] [ 2 ] ; // Last time we did a full test
// special function for teleport-with-duck for episodic
# ifdef HL2_EPISODIC
public :
void ForceDuck ( void ) ;
# endif
2023-10-03 14:23:56 +00:00
ITraceListData * m_pTraceListData ;
int m_nTraceCount ;
2020-04-22 16:56:21 +00:00
} ;
2023-10-03 14:23:56 +00:00
//-----------------------------------------------------------------------------
// Traces player movement + position
//-----------------------------------------------------------------------------
inline void CGameMovement : : TracePlayerBBox ( const Vector & start , const Vector & end , unsigned int fMask , int collisionGroup , trace_t & pm )
{
+ + m_nTraceCount ;
VPROF ( " CGameMovement::TracePlayerBBox " ) ;
Ray_t ray ;
ray . Init ( start , end , GetPlayerMins ( ) , GetPlayerMaxs ( ) ) ;
ITraceFilter * pFilter = LockTraceFilter ( collisionGroup ) ;
if ( m_pTraceListData & & m_pTraceListData - > CanTraceRay ( ray ) )
{
enginetrace - > TraceRayAgainstLeafAndEntityList ( ray , m_pTraceListData , fMask , pFilter , & pm ) ;
}
else
{
enginetrace - > TraceRay ( ray , fMask , pFilter , & pm ) ;
}
UnlockTraceFilter ( pFilter ) ;
}
inline void CGameMovement : : GameMovementTraceHull ( const Vector & start , const Vector & end , const Vector & mins , const Vector & maxs , unsigned int fMask , ITraceFilter * pFilter , trace_t * pTrace )
{
+ + m_nTraceCount ;
Ray_t ray ;
ray . Init ( start , end , mins , maxs ) ;
if ( m_pTraceListData & & m_pTraceListData - > CanTraceRay ( ray ) )
{
enginetrace - > TraceRayAgainstLeafAndEntityList ( ray , m_pTraceListData , fMask , pFilter , pTrace ) ;
}
else
{
enginetrace - > TraceRay ( ray , fMask , pFilter , pTrace ) ;
}
}
2020-04-22 16:56:21 +00:00
# endif // GAMEMOVEMENT_H