Team Fortress 2 Source Code as on 22/4/2020
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.

291 lines
8.8 KiB

  1. //========= Copyright 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.0f // ms
  20. #define GAMEMOVEMENT_JUMP_TIME 510.0f // ms approx - based on the 21 unit height jump
  21. #define GAMEMOVEMENT_JUMP_HEIGHT 21.0f // units
  22. #define GAMEMOVEMENT_TIME_TO_UNDUCK ( TIME_TO_UNDUCK * 1000.0f ) // ms
  23. #define GAMEMOVEMENT_TIME_TO_UNDUCK_INV ( GAMEMOVEMENT_DUCK_TIME - GAMEMOVEMENT_TIME_TO_UNDUCK )
  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 StartTrackPredictionErrors( CBasePlayer *pPlayer );
  40. virtual void FinishTrackPredictionErrors( CBasePlayer *pPlayer );
  41. virtual void DiffPrint( PRINTF_FORMAT_STRING char const *fmt, ... );
  42. virtual Vector GetPlayerMins( bool ducked ) const;
  43. virtual Vector GetPlayerMaxs( bool ducked ) const;
  44. virtual Vector GetPlayerViewOffset( bool ducked ) const;
  45. // For sanity checking getting stuck on CMoveData::SetAbsOrigin
  46. virtual void TracePlayerBBox( const Vector& start, const Vector& end, unsigned int fMask, int collisionGroup, trace_t& pm );
  47. // allows derived classes to exclude entities from trace
  48. virtual void TryTouchGround( const Vector& start, const Vector& end, const Vector& mins, const Vector& maxs, unsigned int fMask, int collisionGroup, trace_t& pm );
  49. #define BRUSH_ONLY true
  50. virtual unsigned int PlayerSolidMask( bool brushOnly = false ); ///< returns the solid mask for the given player, so bots can have a more-restrictive set
  51. CBasePlayer *player;
  52. CMoveData *GetMoveData() { return mv; }
  53. protected:
  54. // Input/Output for this movement
  55. CMoveData *mv;
  56. int m_nOldWaterLevel;
  57. float m_flWaterEntryTime;
  58. int m_nOnLadder;
  59. Vector m_vecForward;
  60. Vector m_vecRight;
  61. Vector m_vecUp;
  62. // Does most of the player movement logic.
  63. // Returns with origin, angles, and velocity modified in place.
  64. // were contacted during the move.
  65. virtual void PlayerMove( void );
  66. // Set ground data, etc.
  67. void FinishMove( void );
  68. virtual float CalcRoll( const QAngle &angles, const Vector &velocity, float rollangle, float rollspeed );
  69. virtual void DecayPunchAngle( void );
  70. virtual void CheckWaterJump(void );
  71. virtual void WaterMove( void );
  72. void WaterJump( void );
  73. // Handles both ground friction and water friction
  74. void Friction( void );
  75. virtual void AirAccelerate( Vector& wishdir, float wishspeed, float accel );
  76. virtual void AirMove( void );
  77. virtual float GetAirSpeedCap( void ) { return 30.f; }
  78. virtual bool CanAccelerate();
  79. virtual void Accelerate( Vector& wishdir, float wishspeed, float accel);
  80. // Only used by players. Moves along the ground when player is a MOVETYPE_WALK.
  81. virtual void WalkMove( void );
  82. // Try to keep a walking player on the ground when running down slopes etc
  83. void StayOnGround( void );
  84. // Handle MOVETYPE_WALK.
  85. virtual void FullWalkMove();
  86. // allow overridden versions to respond to jumping
  87. virtual void OnJump( float fImpulse ) {}
  88. virtual void OnLand( float fVelocity ) {}
  89. // Implement this if you want to know when the player collides during OnPlayerMove
  90. virtual void OnTryPlayerMoveCollision( trace_t &tr ) {}
  91. virtual Vector GetPlayerMins( void ) const; // uses local player
  92. virtual Vector GetPlayerMaxs( void ) const; // uses local player
  93. typedef enum
  94. {
  95. GROUND = 0,
  96. STUCK,
  97. LADDER
  98. } IntervalType_t;
  99. virtual int GetCheckInterval( IntervalType_t type );
  100. // Useful for things that happen periodically. This lets things happen on the specified interval, but
  101. // spaces the events onto different frames for different players so they don't all hit their spikes
  102. // simultaneously.
  103. bool CheckInterval( IntervalType_t type );
  104. // Decompoosed gravity
  105. void StartGravity( void );
  106. void FinishGravity( void );
  107. // Apply normal ( undecomposed ) gravity
  108. void AddGravity( void );
  109. // Handle movement in noclip mode.
  110. void FullNoClipMove( float factor, float maxacceleration );
  111. // Returns true if he started a jump (ie: should he play the jump animation)?
  112. virtual bool CheckJumpButton( void ); // Overridden by each game.
  113. // Dead player flying through air., e.g.
  114. virtual void FullTossMove( void );
  115. // Player is a Observer chasing another player
  116. void FullObserverMove( void );
  117. // Handle movement when in MOVETYPE_LADDER mode.
  118. virtual void FullLadderMove();
  119. // The basic solid body movement clip that slides along multiple planes
  120. virtual int TryPlayerMove( Vector *pFirstDest=NULL, trace_t *pFirstTrace=NULL );
  121. virtual bool LadderMove( void );
  122. virtual bool OnLadder( trace_t &trace );
  123. virtual float LadderDistance( void ) const { return 2.0f; } ///< Returns the distance a player can be from a ladder and still attach to it
  124. virtual unsigned int LadderMask( void ) const { return MASK_PLAYERSOLID; }
  125. virtual float ClimbSpeed( void ) const { return MAX_CLIMB_SPEED; }
  126. virtual float LadderLateralMultiplier( void ) const { return 1.0f; }
  127. // See if the player has a bogus velocity value.
  128. void CheckVelocity( void );
  129. // Does not change the entities velocity at all
  130. void PushEntity( Vector& push, trace_t *pTrace );
  131. // Slide off of the impacting object
  132. // returns the blocked flags:
  133. // 0x01 == floor
  134. // 0x02 == step / wall
  135. int ClipVelocity( Vector& in, Vector& normal, Vector& out, float overbounce );
  136. // If pmove.origin is in a solid position,
  137. // try nudging slightly on all axis to
  138. // allow for the cut precision of the net coordinates
  139. virtual int CheckStuck( void );
  140. // Check if the point is in water.
  141. // Sets refWaterLevel and refWaterType appropriately.
  142. // If in water, applies current to baseVelocity, and returns true.
  143. virtual bool CheckWater( void );
  144. // Determine if player is in water, on ground, etc.
  145. virtual void CategorizePosition( void );
  146. virtual void CheckParameters( void );
  147. virtual void ReduceTimers( void );
  148. virtual void CheckFalling( void );
  149. virtual void PlayerRoughLandingEffects( float fvol );
  150. void PlayerWaterSounds( void );
  151. void ResetGetPointContentsCache();
  152. int GetPointContentsCached( const Vector &point, int slot );
  153. // Ducking
  154. virtual void Duck( void );
  155. virtual void HandleDuckingSpeedCrop();
  156. virtual void FinishUnDuck( void );
  157. virtual void FinishDuck( void );
  158. virtual bool CanUnduck();
  159. void UpdateDuckJumpEyeOffset( void );
  160. bool CanUnDuckJump( trace_t &trace );
  161. void StartUnDuckJump( void );
  162. void FinishUnDuckJump( trace_t &trace );
  163. void SetDuckedEyeOffset( float duckFraction );
  164. void FixPlayerCrouchStuck( bool moveup );
  165. float SplineFraction( float value, float scale );
  166. void CategorizeGroundSurface( trace_t &pm );
  167. bool InWater( void );
  168. // Commander view movement
  169. void IsometricMove( void );
  170. // Traces the player bbox as it is swept from start to end
  171. virtual CBaseHandle TestPlayerPosition( const Vector& pos, int collisionGroup, trace_t& pm );
  172. // Checks to see if we should actually jump
  173. void PlaySwimSound();
  174. bool IsDead( void ) const;
  175. // Figures out how the constraint should slow us down
  176. float ComputeConstraintSpeedFactor( void );
  177. virtual void SetGroundEntity( trace_t *pm );
  178. virtual void StepMove( Vector &vecDestination, trace_t &trace );
  179. // when we step on ground that's too steep, search to see if there's any ground nearby that isn't too steep
  180. void TryTouchGroundInQuadrants( const Vector& start, const Vector& end, unsigned int fMask, int collisionGroup, trace_t& pm );
  181. protected:
  182. // Performs the collision resolution for fliers.
  183. void PerformFlyCollisionResolution( trace_t &pm, Vector &move );
  184. virtual bool GameHasLadders() const;
  185. enum
  186. {
  187. // eyes, waist, feet points (since they are all deterministic
  188. MAX_PC_CACHE_SLOTS = 3,
  189. };
  190. // Cache used to remove redundant calls to GetPointContents().
  191. int m_CachedGetPointContents[ MAX_PLAYERS ][ MAX_PC_CACHE_SLOTS ];
  192. Vector m_CachedGetPointContentsPoint[ MAX_PLAYERS ][ MAX_PC_CACHE_SLOTS ];
  193. Vector m_vecProximityMins; // Used to be globals in sv_user.cpp.
  194. Vector m_vecProximityMaxs;
  195. float m_fFrameTime;
  196. //private:
  197. int m_iSpeedCropped;
  198. float m_flStuckCheckTime[MAX_PLAYERS+1][2]; // Last time we did a full test
  199. // special function for teleport-with-duck for episodic
  200. #ifdef HL2_EPISODIC
  201. public:
  202. void ForceDuck( void );
  203. #endif
  204. };
  205. #endif // GAMEMOVEMENT_H