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.

129 lines
3.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Special handling for hl2 usable ladders
  4. //
  5. //=============================================================================//
  6. #include "gamemovement.h"
  7. #include "func_ladder.h"
  8. #if defined( CLIENT_DLL )
  9. #include "c_basehlplayer.h"
  10. #define CHL2_Player C_BaseHLPlayer
  11. #else
  12. #include "hl2_player.h"
  13. #endif
  14. struct LadderMove_t;
  15. class CInfoLadderDismount;
  16. struct NearbyDismount_t
  17. {
  18. CInfoLadderDismount *dismount;
  19. float distSqr;
  20. };
  21. //-----------------------------------------------------------------------------
  22. // Purpose: HL2 specific movement code
  23. //-----------------------------------------------------------------------------
  24. class CHL2GameMovement : public CGameMovement
  25. {
  26. typedef CGameMovement BaseClass;
  27. public:
  28. CHL2GameMovement();
  29. // Overrides
  30. virtual void FullLadderMove();
  31. virtual bool LadderMove( void );
  32. virtual bool OnLadder( trace_t &trace );
  33. virtual int GetCheckInterval( IntervalType_t type );
  34. virtual void SetGroundEntity( trace_t *pm );
  35. virtual bool CanAccelerate( void );
  36. private:
  37. // See if we are pressing use near a ladder "mount" point and if so, latch us onto the ladder
  38. bool CheckLadderAutoMount( CFuncLadder *ladder, const Vector& bestOrigin );
  39. bool CheckLadderAutoMountCone( CFuncLadder *ladder, const Vector& bestOrigin, float maxAngleDelta, float maxDistToLadder );
  40. bool CheckLadderAutoMountEndPoint(CFuncLadder *ladder, const Vector& bestOrigin );
  41. bool LookingAtLadder( CFuncLadder *ladder );
  42. // Are we forcing the user's position to a new spot
  43. bool IsForceMoveActive();
  44. // Start forcing player position
  45. void StartForcedMove( bool mounting, float transit_speed, const Vector& goalpos, CFuncLadder *ladder );
  46. // Returns false when finished
  47. bool ContinueForcedMove();
  48. // Given a list of nearby ladders, find the best ladder and the "mount" origin
  49. void Findladder( float maxdist, CFuncLadder **ppLadder, Vector& ladderOrigin, const CFuncLadder *skipLadder );
  50. // Debounce the +USE key
  51. void SwallowUseKey();
  52. // Returns true if the player will auto-exit the ladder via a dismount node
  53. bool ExitLadderViaDismountNode( CFuncLadder *ladder, bool strict, bool useAlternate = false );
  54. void GetSortedDismountNodeList( const Vector &org, float radius, CFuncLadder *ladder, CUtlRBTree< NearbyDismount_t, int >& list );
  55. LadderMove_t *GetLadderMove();
  56. CHL2_Player *GetHL2Player();
  57. void SetLadder( CFuncLadder *ladder );
  58. CFuncLadder *GetLadder();
  59. };
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. //-----------------------------------------------------------------------------
  63. inline CHL2_Player *CHL2GameMovement::GetHL2Player()
  64. {
  65. return static_cast< CHL2_Player * >( player );
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. // Output : inline LadderMove*
  70. //-----------------------------------------------------------------------------
  71. inline LadderMove_t *CHL2GameMovement::GetLadderMove()
  72. {
  73. CHL2_Player *p = GetHL2Player();
  74. if ( !p )
  75. {
  76. return NULL;
  77. }
  78. return p->GetLadderMove();
  79. }
  80. //-----------------------------------------------------------------------------
  81. // Purpose:
  82. // Input : *ladder -
  83. //-----------------------------------------------------------------------------
  84. inline void CHL2GameMovement::SetLadder( CFuncLadder *ladder )
  85. {
  86. CFuncLadder* oldLadder = GetLadder();
  87. if ( !ladder && oldLadder )
  88. {
  89. oldLadder->PlayerGotOff( GetHL2Player() );
  90. }
  91. GetHL2Player()->m_HL2Local.m_hLadder.Set( ladder );
  92. }
  93. //-----------------------------------------------------------------------------
  94. // Purpose:
  95. // Output : CFuncLadder
  96. //-----------------------------------------------------------------------------
  97. inline CFuncLadder *CHL2GameMovement::GetLadder()
  98. {
  99. return static_cast<CFuncLadder*>( static_cast<CBaseEntity *>( GetHL2Player()->m_HL2Local.m_hLadder.Get() ) );
  100. }