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.

116 lines
2.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "env_zoom.h"
  8. #ifdef HL2_DLL
  9. #include "hl2_player.h"
  10. #endif
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. #define ENV_ZOOM_OVERRIDE (1<<0)
  14. class CEnvZoom : public CPointEntity
  15. {
  16. public:
  17. DECLARE_CLASS( CEnvZoom, CPointEntity );
  18. void InputZoom( inputdata_t &inputdata );
  19. void InputUnZoom( inputdata_t &inputdata );
  20. int GetFOV( void ) { return m_nFOV; }
  21. float GetSpeed( void ) { return m_flSpeed; }
  22. private:
  23. float m_flSpeed;
  24. int m_nFOV;
  25. DECLARE_DATADESC();
  26. };
  27. LINK_ENTITY_TO_CLASS( env_zoom, CEnvZoom );
  28. BEGIN_DATADESC( CEnvZoom )
  29. DEFINE_KEYFIELD( m_flSpeed, FIELD_FLOAT, "Rate" ),
  30. DEFINE_KEYFIELD( m_nFOV, FIELD_INTEGER, "FOV" ),
  31. DEFINE_INPUTFUNC( FIELD_VOID, "Zoom", InputZoom ),
  32. DEFINE_INPUTFUNC( FIELD_VOID, "UnZoom", InputUnZoom ),
  33. END_DATADESC()
  34. bool CanOverrideEnvZoomOwner( CBaseEntity *pZoomOwner )
  35. {
  36. CEnvZoom *pZoom = dynamic_cast<CEnvZoom*>(pZoomOwner );
  37. if ( pZoom == NULL || ( pZoom && pZoom->HasSpawnFlags( ENV_ZOOM_OVERRIDE ) == false ) )
  38. return false;
  39. return true;
  40. }
  41. float GetZoomOwnerDesiredFOV( CBaseEntity *pZoomOwner )
  42. {
  43. if ( CanOverrideEnvZoomOwner( pZoomOwner ) )
  44. {
  45. CEnvZoom *pZoom = dynamic_cast<CEnvZoom*>( pZoomOwner );
  46. return pZoom->GetFOV();
  47. }
  48. return 0;
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Purpose:
  52. // Input : &inputdata -
  53. //-----------------------------------------------------------------------------
  54. void CEnvZoom::InputZoom( inputdata_t &inputdata )
  55. {
  56. CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
  57. if ( pPlayer )
  58. {
  59. #ifdef HL2_DLL
  60. if ( pPlayer == pPlayer->GetFOVOwner() )
  61. {
  62. CHL2_Player *pHLPlayer = static_cast<CHL2_Player*>( pPlayer );
  63. pHLPlayer->StopZooming();
  64. }
  65. #endif
  66. // If the player's already holding a fov from another env_zoom, we're allowed to overwrite it
  67. if ( pPlayer->GetFOVOwner() && FClassnameIs( pPlayer->GetFOVOwner(), "env_zoom" ) )
  68. {
  69. pPlayer->ClearZoomOwner();
  70. }
  71. //Stuff the values
  72. pPlayer->SetFOV( this, m_nFOV, m_flSpeed );
  73. }
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Purpose:
  77. // Input : &inputdata -
  78. //-----------------------------------------------------------------------------
  79. void CEnvZoom::InputUnZoom( inputdata_t &inputdata )
  80. {
  81. CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
  82. if ( pPlayer )
  83. {
  84. // Stuff the values
  85. pPlayer->SetFOV( this, 0 );
  86. }
  87. }