Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

342 lines
11 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #if !defined( GAMEMOVEMENT_H )
  10. #define GAMEMOVEMENT_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "igamemovement.h"
  15. #include "cmodel.h"
  16. #include "tier0/vprof.h"
  17. #define CTEXTURESMAX 512 // max number of textures loaded
  18. #define CBTEXTURENAMEMAX 13 // only load first n chars of name
  19. #define GAMEMOVEMENT_DUCK_TIME 1000 // ms
  20. #define GAMEMOVEMENT_JUMP_TIME 510 // ms approx - based on the 21 unit height jump
  21. #define GAMEMOVEMENT_JUMP_HEIGHT 21.0f // units
  22. #define GAMEMOVEMENT_TIME_TO_UNDUCK_MSECS ( TIME_TO_UNDUCK_MSECS ) // ms
  23. #define GAMEMOVEMENT_TIME_TO_UNDUCK_MSECS_INV ( GAMEMOVEMENT_DUCK_TIME - GAMEMOVEMENT_TIME_TO_UNDUCK_MSECS )
  24. enum
  25. {
  26. SPEED_CROPPED_RESET = 0,
  27. SPEED_CROPPED_DUCK = 1,
  28. SPEED_CROPPED_WEAPON = 2,
  29. };
  30. struct surfacedata_t;
  31. class CBasePlayer;
  32. class CGameMovement : public IGameMovement
  33. {
  34. public:
  35. DECLARE_CLASS_NOBASE( CGameMovement );
  36. CGameMovement( void );
  37. virtual ~CGameMovement( void );
  38. virtual void ProcessMovement( CBasePlayer *pPlayer, CMoveData *pMove );
  39. virtual void Reset( void );
  40. virtual void StartTrackPredictionErrors( CBasePlayer *pPlayer );
  41. virtual void FinishTrackPredictionErrors( CBasePlayer *pPlayer );
  42. virtual void DiffPrint( PRINTF_FORMAT_STRING char const *fmt, ... );
  43. virtual const Vector& GetPlayerMins( bool ducked ) const;
  44. virtual const Vector& GetPlayerMaxs( bool ducked ) const;
  45. virtual const Vector& GetPlayerViewOffset( bool ducked ) const;
  46. virtual void SetupMovementBounds( CMoveData *pMove );
  47. virtual bool IsMovingPlayerStuck( void ) const;
  48. virtual CBasePlayer *GetMovingPlayer( void ) const;
  49. virtual void UnblockPusher( CBasePlayer *pPlayer, CBaseEntity *pPusher );
  50. // For sanity checking getting stuck on CMoveData::SetAbsOrigin
  51. virtual void TracePlayerBBox( const Vector& start, const Vector& end, unsigned int fMask, int collisionGroup, trace_t& pm );
  52. // wrapper around tracehull to allow tracelistdata optimizations
  53. void GameMovementTraceHull( const Vector& start, const Vector& end, const Vector &mins, const Vector &maxs, unsigned int fMask, ITraceFilter *pFilter, trace_t *pTrace );
  54. #define BRUSH_ONLY true
  55. 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
  56. CBasePlayer *player;
  57. CMoveData *GetMoveData() { return mv; }
  58. protected:
  59. // Input/Output for this movement
  60. CMoveData *mv;
  61. int m_nOldWaterLevel;
  62. float m_flWaterEntryTime;
  63. int m_nOnLadder;
  64. Vector m_vecForward;
  65. Vector m_vecRight;
  66. Vector m_vecUp;
  67. // Does most of the player movement logic.
  68. // Returns with origin, angles, and velocity modified in place.
  69. // were contacted during the move.
  70. virtual void PlayerMove( void );
  71. // Set ground data, etc.
  72. void FinishMove( void );
  73. virtual float CalcRoll( const QAngle &angles, const Vector &velocity, float rollangle, float rollspeed );
  74. // helper function for decaying punch angles over time with exponential and linear terms
  75. void DecayAngles( QAngle& v, float fExp, float fLin, float dT );
  76. virtual void DecayViewPunchAngle( void );
  77. virtual void CheckWaterJump(void );
  78. virtual void WaterMove( void );
  79. virtual void WaterJump( void );
  80. // Handles both ground friction and water friction
  81. virtual void Friction( void );
  82. virtual void AirAccelerate( Vector& wishdir, float wishspeed, float accel );
  83. virtual void AirMove( void );
  84. virtual bool CanAccelerate();
  85. virtual void Accelerate( Vector& wishdir, float wishspeed, float accel);
  86. // Only used by players. Moves along the ground when player is a MOVETYPE_WALK.
  87. virtual void WalkMove( void );
  88. // Try to keep a walking player on the ground when running down slopes etc
  89. virtual void StayOnGround( void );
  90. // Handle MOVETYPE_WALK.
  91. virtual void FullWalkMove();
  92. // allow overridden versions to respond to jumping
  93. virtual void OnJump( float fImpulse ) {}
  94. virtual void OnLand( float fVelocity ) {}
  95. // Implement this if you want to know when the player collides during OnPlayerMove
  96. virtual void OnTryPlayerMoveCollision( trace_t &tr ) {}
  97. virtual const Vector& GetPlayerMins( void ) const; // uses local player
  98. virtual const Vector& GetPlayerMaxs( void ) const; // uses local player
  99. typedef enum
  100. {
  101. GROUND = 0,
  102. STUCK,
  103. LADDER,
  104. LADDER_WEDGE
  105. } IntervalType_t;
  106. virtual int GetCheckInterval( IntervalType_t type );
  107. // Useful for things that happen periodically. This lets things happen on the specified interval, but
  108. // spaces the events onto different frames for different players so they don't all hit their spikes
  109. // simultaneously.
  110. bool CheckInterval( IntervalType_t type );
  111. // Decompoosed gravity
  112. virtual void StartGravity( void );
  113. virtual void FinishGravity( void );
  114. // Apply normal ( undecomposed ) gravity
  115. virtual void AddGravity( void );
  116. // Handle movement in noclip mode.
  117. void FullNoClipMove( float factor, float maxacceleration );
  118. // Returns true if he started a jump (ie: should he play the jump animation)?
  119. virtual bool CheckJumpButton( void ); // Overridden by each game.
  120. // Dead player flying through air., e.g.
  121. virtual void FullTossMove( void );
  122. // Player is a Observer chasing another player
  123. void FullObserverMove( void );
  124. // Handle movement when in MOVETYPE_LADDER mode.
  125. virtual void FullLadderMove();
  126. // The basic solid body movement clip that slides along multiple planes
  127. virtual int TryPlayerMove( Vector *pFirstDest=NULL, trace_t *pFirstTrace=NULL );
  128. virtual bool LadderMove( void );
  129. virtual bool OnLadder( trace_t &trace );
  130. virtual float LadderDistance( void ) const { return 2.0f; } ///< Returns the distance a player can be from a ladder and still attach to it
  131. virtual unsigned int LadderMask( void ) const { return MASK_PLAYERSOLID; }
  132. virtual float ClimbSpeed( void ) const { return MAX_CLIMB_SPEED; }
  133. virtual float LadderLateralMultiplier( void ) const { return 1.0f; }
  134. // special case code when starting the Ladder MoveType
  135. void OnStartMoveTypeLadder( void );
  136. // See if the player has a bogus velocity value.
  137. void CheckVelocity( void );
  138. // Does not change the entities velocity at all
  139. void PushEntity( Vector& push, trace_t *pTrace );
  140. // Slide off of the impacting object
  141. // returns the blocked flags:
  142. // 0x01 == floor
  143. // 0x02 == step / wall
  144. virtual int ClipVelocity( Vector& in, Vector& normal, Vector& out, float overbounce );
  145. // If pmove.origin is in a solid position,
  146. // try nudging slightly on all axis to
  147. // allow for the cut precision of the net coordinates
  148. #ifdef PORTAL
  149. virtual
  150. #endif
  151. int CheckStuck( void );
  152. // Check if the point is in water.
  153. // Sets refWaterLevel and refWaterType appropriately.
  154. // If in water, applies current to baseVelocity, and returns true.
  155. virtual bool CheckWater( void );
  156. virtual void GetWaterCheckPosition( int waterLevel, Vector *pos );
  157. // Determine if player is in water, on ground, etc.
  158. virtual void CategorizePosition( void );
  159. virtual void CheckParameters( void );
  160. virtual void ReduceTimers( void );
  161. virtual void CheckFalling( void );
  162. virtual void PlayerRoughLandingEffects( float fvol );
  163. void PlayerWaterSounds( void );
  164. void ResetGetWaterContentsForPointCache();
  165. int GetWaterContentsForPointCached( const Vector &point, int slot );
  166. // Ducking
  167. virtual void Duck( void );
  168. virtual void HandleDuckingSpeedCrop();
  169. virtual void FinishUnDuck( void );
  170. virtual void FinishDuck( void );
  171. virtual bool CanUnduck();
  172. virtual void UpdateDuckJumpEyeOffset( void );
  173. virtual bool CanUnDuckJump( trace_t &trace );
  174. virtual void StartUnDuckJump( void );
  175. virtual void FinishUnDuckJump( trace_t &trace );
  176. virtual void SetDuckedEyeOffset( float duckFraction );
  177. virtual void FixPlayerCrouchStuck( bool moveup );
  178. float SplineFraction( float value, float scale );
  179. virtual void CategorizeGroundSurface( trace_t &pm );
  180. virtual bool InWater( void );
  181. // Commander view movement
  182. void IsometricMove( void );
  183. // Traces the player bbox as it is swept from start to end
  184. virtual CBaseHandle TestPlayerPosition( const Vector& pos, int collisionGroup, trace_t& pm );
  185. // Checks to see if we should actually jump
  186. void PlaySwimSound();
  187. bool IsDead( void ) const;
  188. // Figures out how the constraint should slow us down
  189. float ComputeConstraintSpeedFactor( void );
  190. virtual void SetGroundEntity( trace_t *pm );
  191. virtual void StepMove( Vector &vecDestination, trace_t &trace );
  192. bool CheckValidStandableGroundCandidate( trace_t &pm, float flStandableZ );
  193. protected:
  194. virtual ITraceFilter *LockTraceFilter( int collisionGroup );
  195. virtual void UnlockTraceFilter( ITraceFilter *&pFilter );
  196. // Performs the collision resolution for fliers.
  197. void PerformFlyCollisionResolution( trace_t &pm, Vector &move );
  198. virtual bool GameHasLadders() const;
  199. enum
  200. {
  201. // eyes, waist, feet points (since they are all deterministic
  202. MAX_PC_CACHE_SLOTS = 3,
  203. };
  204. // Cache used to remove redundant calls to GetPointContents() for water.
  205. int m_CachedGetPointContents[ MAX_PLAYERS ][ MAX_PC_CACHE_SLOTS ];
  206. Vector m_CachedGetPointContentsPoint[ MAX_PLAYERS ][ MAX_PC_CACHE_SLOTS ];
  207. //private:
  208. int m_iSpeedCropped;
  209. bool m_bProcessingMovement;
  210. bool m_bInStuckTest;
  211. float m_flStuckCheckTime[MAX_PLAYERS+1][2]; // Last time we did a full test
  212. // special function for teleport-with-duck for episodic
  213. #ifdef HL2_EPISODIC
  214. public:
  215. void ForceDuck( void );
  216. #endif
  217. ITraceListData *m_pTraceListData;
  218. int m_nTraceCount;
  219. };
  220. //-----------------------------------------------------------------------------
  221. // Traces player movement + position
  222. //-----------------------------------------------------------------------------
  223. inline void CGameMovement::TracePlayerBBox( const Vector& start, const Vector& end, unsigned int fMask, int collisionGroup, trace_t& pm )
  224. {
  225. ++m_nTraceCount;
  226. VPROF( "CGameMovement::TracePlayerBBox" );
  227. Ray_t ray;
  228. ray.Init( start, end, GetPlayerMins(), GetPlayerMaxs() );
  229. ITraceFilter *pFilter = LockTraceFilter( collisionGroup );
  230. if ( m_pTraceListData && m_pTraceListData->CanTraceRay(ray) )
  231. {
  232. enginetrace->TraceRayAgainstLeafAndEntityList( ray, m_pTraceListData, fMask, pFilter, &pm );
  233. }
  234. else
  235. {
  236. enginetrace->TraceRay( ray, fMask, pFilter, &pm );
  237. }
  238. UnlockTraceFilter( pFilter );
  239. }
  240. inline void CGameMovement::GameMovementTraceHull( const Vector& start, const Vector& end, const Vector &mins, const Vector &maxs, unsigned int fMask, ITraceFilter *pFilter, trace_t *pTrace )
  241. {
  242. ++m_nTraceCount;
  243. Ray_t ray;
  244. ray.Init( start, end, mins, maxs );
  245. if ( m_pTraceListData && m_pTraceListData->CanTraceRay(ray) )
  246. {
  247. enginetrace->TraceRayAgainstLeafAndEntityList( ray, m_pTraceListData, fMask, pFilter, pTrace );
  248. }
  249. else
  250. {
  251. enginetrace->TraceRay( ray, fMask, pFilter, pTrace );
  252. }
  253. }
  254. #endif // GAMEMOVEMENT_H