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.

127 lines
4.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #include "cbase.h"
  8. #include "player_command.h"
  9. #include "igamemovement.h"
  10. #include "in_buttons.h"
  11. #include "ipredictionsystem.h"
  12. #include "tf_player.h"
  13. static CMoveData g_MoveData;
  14. CMoveData *g_pMoveData = &g_MoveData;
  15. IPredictionSystem *IPredictionSystem::g_pPredictionSystems = NULL;
  16. //-----------------------------------------------------------------------------
  17. // Sets up the move data for TF2
  18. //-----------------------------------------------------------------------------
  19. class CTFPlayerMove : public CPlayerMove
  20. {
  21. DECLARE_CLASS( CTFPlayerMove, CPlayerMove );
  22. public:
  23. virtual void StartCommand( CBasePlayer *player, CUserCmd *cmd );
  24. virtual void SetupMove( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move );
  25. virtual void FinishMove( CBasePlayer *player, CUserCmd *ucmd, CMoveData *move );
  26. };
  27. // PlayerMove Interface
  28. static CTFPlayerMove g_PlayerMove;
  29. //-----------------------------------------------------------------------------
  30. // Singleton accessor
  31. //-----------------------------------------------------------------------------
  32. CPlayerMove *PlayerMove()
  33. {
  34. return &g_PlayerMove;
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Main setup, finish
  38. //-----------------------------------------------------------------------------
  39. void CTFPlayerMove::StartCommand( CBasePlayer *player, CUserCmd *cmd )
  40. {
  41. BaseClass::StartCommand( player, cmd );
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose: This is called pre player movement and copies all the data necessary
  45. // from the player for movement. (Server-side, the client-side version
  46. // of this code can be found in prediction.cpp.)
  47. //-----------------------------------------------------------------------------
  48. void CTFPlayerMove::SetupMove( CBasePlayer *player, CUserCmd *ucmd, IMoveHelper *pHelper, CMoveData *move )
  49. {
  50. CTFPlayer *pTFPlayer = ToTFPlayer( player );
  51. if ( pTFPlayer )
  52. {
  53. // Check to see if we are a crouched, heavy, firing his weapons and zero out movement.
  54. if ( pTFPlayer->GetPlayerClass()->IsClass( TF_CLASS_HEAVYWEAPONS ) )
  55. {
  56. if ( pTFPlayer->m_Shared.InCond( TF_COND_AIMING ) )
  57. {
  58. if ( pTFPlayer->GetFlags() & FL_DUCKING )
  59. {
  60. ucmd->forwardmove = 0.0f;
  61. ucmd->sidemove = 0.0f;
  62. }
  63. // Don't allow jumping while firing (unless the design changes)
  64. ucmd->buttons &= ~IN_JUMP;
  65. }
  66. }
  67. // targe Exploit fix. Clients sending higher view angle changes then allowed
  68. // Clamp their YAW Movement
  69. if ( pTFPlayer->m_Shared.InCond( TF_COND_SHIELD_CHARGE ) )
  70. {
  71. // Get the view deltas and clamp them if they are too high, give a high tolerance (lag)
  72. float flCap = pTFPlayer->m_Shared.CalculateChargeCap();
  73. flCap *= 2.5f;
  74. QAngle qAngle = pTFPlayer->m_qPreviousChargeEyeAngle;
  75. float flDiff = abs( qAngle[YAW] ) - abs( ucmd->viewangles[YAW] );
  76. if ( flDiff > flCap )
  77. {
  78. //float flReportedPitchDelta = qAngle[YAW] - ucmd->viewangles[YAW];
  79. if ( ucmd->viewangles[YAW] > qAngle[YAW] )
  80. {
  81. ucmd->viewangles[YAW] = qAngle[YAW] + flCap;
  82. pTFPlayer->SnapEyeAngles( ucmd->viewangles );
  83. }
  84. else // smaller values
  85. {
  86. ucmd->viewangles[YAW] = qAngle[YAW] - flCap;
  87. pTFPlayer->SnapEyeAngles( ucmd->viewangles );
  88. }
  89. }
  90. pTFPlayer->m_qPreviousChargeEyeAngle = ucmd->viewangles;
  91. }
  92. else
  93. {
  94. pTFPlayer->m_qPreviousChargeEyeAngle = pTFPlayer->EyeAngles();
  95. }
  96. }
  97. BaseClass::SetupMove( player, ucmd, pHelper, move );
  98. }
  99. //-----------------------------------------------------------------------------
  100. // Purpose: This is called post player movement to copy back all data that
  101. // movement could have modified and that is necessary for future
  102. // movement. (Server-side, the client-side version of this code can
  103. // be found in prediction.cpp.)
  104. //-----------------------------------------------------------------------------
  105. void CTFPlayerMove::FinishMove( CBasePlayer *player, CUserCmd *ucmd, CMoveData *move )
  106. {
  107. // Call the default FinishMove code.
  108. BaseClass::FinishMove( player, ucmd, move );
  109. }