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.

183 lines
5.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Engineer's Teleporter
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TF_OBJ_TELEPORTER_H
  8. #define TF_OBJ_TELEPORTER_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tf_obj.h"
  13. #include "GameEventListener.h"
  14. class CTFPlayer;
  15. enum
  16. {
  17. TTYPE_NONE=0,
  18. TTYPE_ENTRANCE,
  19. TTYPE_EXIT,
  20. #ifdef STAGING_ONLY
  21. TTYPE_SPEEDPAD,
  22. #endif
  23. };
  24. #define TELEPORTER_MAX_HEALTH 150
  25. // ------------------------------------------------------------------------ //
  26. // Base Teleporter object
  27. // ------------------------------------------------------------------------ //
  28. class CObjectTeleporter : public CBaseObject, public CGameEventListener
  29. {
  30. DECLARE_CLASS( CObjectTeleporter, CBaseObject );
  31. public:
  32. DECLARE_SERVERCLASS();
  33. CObjectTeleporter();
  34. virtual void Spawn();
  35. virtual void UpdateOnRemove();
  36. virtual void FirstSpawn( void );
  37. virtual void Precache();
  38. virtual bool StartBuilding( CBaseEntity *pBuilder );
  39. virtual void SetStartBuildingModel( void );
  40. virtual void OnGoActive( void );
  41. virtual int DrawDebugTextOverlays(void) ;
  42. virtual bool IsPlacementPosValid( void );
  43. virtual void SetModel( const char *pModel );
  44. virtual void InitializeMapPlacedObject( void );
  45. virtual void FinishedBuilding( void );
  46. void SetState( int state );
  47. virtual void DeterminePlaybackRate( void );
  48. void RecieveTeleportingPlayer( CTFPlayer* pTeleportingPlayer );
  49. void TeleporterThink( void );
  50. void TeleporterTouch( CBaseEntity *pOther );
  51. virtual void StartTouch( CBaseEntity *pOther );
  52. virtual void EndTouch( CBaseEntity *pOther );
  53. virtual void TeleporterSend( CTFPlayer *pPlayer );
  54. virtual void TeleporterReceive( CTFPlayer *pPlayer, float flDelay );
  55. virtual void StartUpgrading( void );
  56. virtual void FinishUpgrading( void );
  57. CObjectTeleporter *GetMatchingTeleporter( void );
  58. CObjectTeleporter *FindMatch( void ); // Find the teleport partner to this object
  59. bool IsReady( void ); // is this teleporter connected and functional? (ie: not sapped, disabled, upgrading, unconnected, etc)
  60. bool IsMatchingTeleporterReady( void );
  61. bool IsSendingPlayer( CTFPlayer *player ); // returns true if we are in the process of teleporting the given player
  62. int GetState( void ) { return m_iState; } // state of the object ( building, charging, ready etc )
  63. void SetTeleportingPlayer( CTFPlayer *pPlayer )
  64. {
  65. m_hTeleportingPlayer = pPlayer;
  66. }
  67. // Wrench hits
  68. virtual bool Command_Repair( CTFPlayer *pActivator, float flRepairMod );
  69. void AddHealth( int nHealthToAdd )
  70. {
  71. SetHealth( MIN( GetMaxHealth(), GetHealth() + nHealthToAdd ) );
  72. }
  73. virtual bool InputWrenchHit( CTFPlayer *pPlayer, CTFWrench *pWrench, Vector hitLoc );
  74. // Upgrading
  75. virtual bool IsUpgrading( void ) const { return ( m_iState == TELEPORTER_STATE_UPGRADING ); }
  76. virtual bool CheckUpgradeOnHit( CTFPlayer *pPlayer );
  77. void CopyUpgradeStateToMatch( CObjectTeleporter *pMatch, bool bFrom );
  78. virtual void Explode( void );
  79. bool PlayerCanBeTeleported( CTFPlayer *pPlayer );
  80. void SetTeleporterType( int iVal ) { m_iTeleportType = iVal; }
  81. int GetTeleporterType( void ) { return m_iTeleportType; }
  82. bool IsEntrance( void ) { return m_iTeleportType == TTYPE_ENTRANCE; }
  83. bool IsExit( void ) { return m_iTeleportType == TTYPE_EXIT; }
  84. #ifdef STAGING_ONLY
  85. // STAGING_ENGY
  86. bool IsSpeedPad( void ) { return m_iTeleportType == TTYPE_SPEEDPAD; }
  87. #endif
  88. virtual void MakeCarriedObject( CTFPlayer *pCarrier );
  89. virtual void SetObjectMode( int iVal );
  90. virtual int GetBaseHealth( void ) { return TELEPORTER_MAX_HEALTH; }
  91. virtual int GetUpgradeMetalRequired();
  92. void SetTeleportWhere( const CUtlStringList& teleportWhereName )
  93. {
  94. // deep copy strings
  95. for ( int i=0; i<teleportWhereName.Count(); ++i )
  96. {
  97. m_teleportWhereName.CopyAndAddToTail( teleportWhereName[i] );
  98. }
  99. }
  100. const CUtlStringList& GetTeleportWhere() { return m_teleportWhereName; }
  101. virtual void InputEnable( inputdata_t &inputdata ) OVERRIDE;
  102. virtual void InputDisable( inputdata_t &inputdata ) OVERRIDE;
  103. #ifdef STAGING_ONLY
  104. // STAGING_ENGY
  105. void ApplySpeedBoost( CTFPlayer *pPlayer );
  106. #endif
  107. CTFPlayer *GetTeleportingPlayer( void ){ return m_hTeleportingPlayer.Get(); }
  108. virtual void FireGameEvent( IGameEvent *event ) OVERRIDE;
  109. protected:
  110. CNetworkVar( int, m_iState );
  111. CNetworkVar( float, m_flRechargeTime );
  112. CNetworkVar( float, m_flCurrentRechargeDuration );
  113. CNetworkVar( int, m_iTimesUsed );
  114. CNetworkVar( float, m_flYawToExit );
  115. CNetworkVar( bool, m_bMatchBuilding );
  116. CHandle<CObjectTeleporter> m_hMatchingTeleporter;
  117. float m_flLastStateChangeTime;
  118. float m_flMyNextThink; // replace me
  119. CHandle<CTFPlayer> m_hReservedForPlayer;
  120. float m_flReserveAfterTouchUntil;
  121. CHandle<CTFPlayer> m_hTeleportingPlayer;
  122. float m_flNextEnemyTouchHint;
  123. // Direction Arrow, shows roughly what direction the exit is from the entrance
  124. void ShowDirectionArrow( bool bShow );
  125. bool m_bShowDirectionArrow;
  126. int m_iDirectionBodygroup;
  127. int m_iBlurBodygroup;
  128. int m_iTeleportType;
  129. string_t m_iszMatchingMapPlacedTeleporter;
  130. private:
  131. DECLARE_DATADESC();
  132. void UpdateMaxHealth( int nHealth, bool bForce = false );
  133. void SpawnBread( const CTFPlayer* pTeleportingPlayer );
  134. CUtlStringList m_teleportWhereName;
  135. };
  136. #endif // TF_OBJ_TELEPORTER_H