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.

249 lines
7.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Engineer's Dispenser
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TF_OBJ_DISPENSER_H
  8. #define TF_OBJ_DISPENSER_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tf_obj.h"
  13. #include "triggers.h"
  14. class CTFPlayer;
  15. #define DISPENSER_MAX_HEALTH 150
  16. #define DISPENSER_MINI_MAX_HEALTH 100
  17. #define DISPENSER_MINI_MAX_LEVEL 1
  18. #define DISPENSER_MINI_HEAL_RATE 10.0
  19. #define DISPENSER_MINI_AMMO_RATE 0.2
  20. #define DISPENSER_MINI_AMMO_THINK 0.5
  21. #define SF_DISPENSER_IGNORE_LOS (SF_BASEOBJ_INVULN<<1)
  22. #define SF_DISPENSER_DONT_HEAL_DISGUISED_SPIES (SF_BASEOBJ_INVULN<<2)
  23. // ------------------------------------------------------------------------ //
  24. // Repair Trigger
  25. // ------------------------------------------------------------------------ //
  26. class CDispenserTouchTrigger : public CBaseTrigger
  27. {
  28. DECLARE_CLASS( CDispenserTouchTrigger, CBaseTrigger );
  29. public:
  30. CDispenserTouchTrigger() {}
  31. void Spawn( void )
  32. {
  33. BaseClass::Spawn();
  34. AddSpawnFlags( SF_TRIGGER_ALLOW_CLIENTS );
  35. InitTrigger();
  36. }
  37. virtual void StartTouch( CBaseEntity *pEntity )
  38. {
  39. if ( PassesTriggerFilters( pEntity ) )
  40. {
  41. CBaseEntity *pParent = GetOwnerEntity();
  42. if ( pParent )
  43. {
  44. pParent->StartTouch( pEntity );
  45. }
  46. }
  47. }
  48. virtual void EndTouch( CBaseEntity *pEntity )
  49. {
  50. if ( PassesTriggerFilters( pEntity ) )
  51. {
  52. CBaseEntity *pParent = GetOwnerEntity();
  53. if ( pParent )
  54. {
  55. pParent->EndTouch( pEntity );
  56. }
  57. }
  58. }
  59. };
  60. // Ground placed version
  61. #define DISPENSER_MODEL_PLACEMENT "models/buildables/dispenser_blueprint.mdl"
  62. #define DISPENSER_MODEL_BUILDING "models/buildables/dispenser.mdl"
  63. #define DISPENSER_MODEL "models/buildables/dispenser_light.mdl"
  64. #define DISPENSER_MODEL_BUILDING_LVL2 "models/buildables/dispenser_lvl2.mdl"
  65. #define DISPENSER_MODEL_LVL2 "models/buildables/dispenser_lvl2_light.mdl"
  66. #define DISPENSER_MODEL_BUILDING_LVL3 "models/buildables/dispenser_lvl3.mdl"
  67. #define DISPENSER_MODEL_LVL3 "models/buildables/dispenser_lvl3_light.mdl"
  68. #ifdef STAGING_ONLY
  69. // Mini models
  70. #define MINI_DISPENSER_MODEL_PLACEMENT "models/workshop/buildables/mini_dispenser/mini_dispenser.mdl"
  71. #define MINI_DISPENSER_MODEL_BUILDING "models/workshop/buildables/mini_dispenser/mini_dispenser.mdl"
  72. #define MINI_DISPENSER_MODEL "models/workshop/buildables/mini_dispenser/mini_dispenser.mdl"
  73. #endif // STAGING_ONLY
  74. // ------------------------------------------------------------------------ //
  75. // Resupply object that's built by the player
  76. // ------------------------------------------------------------------------ //
  77. class CObjectDispenser : public CBaseObject
  78. {
  79. DECLARE_CLASS( CObjectDispenser, CBaseObject );
  80. public:
  81. DECLARE_SERVERCLASS();
  82. CObjectDispenser();
  83. ~CObjectDispenser();
  84. static CObjectDispenser* Create(const Vector &vOrigin, const QAngle &vAngles);
  85. virtual void Spawn() OVERRIDE;
  86. virtual void FirstSpawn( void ) OVERRIDE;
  87. virtual void GetControlPanelInfo( int nPanelIndex, const char *&pPanelName ) OVERRIDE;
  88. virtual void Precache() OVERRIDE;
  89. virtual void DetonateObject( void ) OVERRIDE;
  90. virtual void DestroyObject( void ) OVERRIDE; // Silent cleanup
  91. virtual void OnGoActive( void );
  92. virtual void StartPlacement( CTFPlayer *pPlayer ) OVERRIDE;
  93. virtual bool StartBuilding( CBaseEntity *pBuilder ) OVERRIDE;
  94. virtual void SetStartBuildingModel( void ) OVERRIDE;
  95. virtual int DrawDebugTextOverlays(void) OVERRIDE;
  96. virtual void SetModel( const char *pModel ) OVERRIDE;
  97. virtual void InitializeMapPlacedObject( void ) OVERRIDE;
  98. virtual bool ShouldBeMiniBuilding( CTFPlayer* pPlayer ) OVERRIDE;
  99. virtual bool IsUpgrading( void ) const OVERRIDE { return ( m_iState == DISPENSER_STATE_UPGRADING ); }
  100. virtual void StartUpgrading( void ) OVERRIDE;
  101. virtual void FinishUpgrading( void ) OVERRIDE;
  102. virtual int DispenseMetal( CTFPlayer *pPlayer );
  103. virtual int GetAvailableMetal( void ) const;
  104. virtual void RefillThink( void );
  105. virtual void DispenseThink( void );
  106. virtual void StartTouch( CBaseEntity *pOther ) OVERRIDE;
  107. virtual void Touch( CBaseEntity *pOther ) OVERRIDE;
  108. virtual void EndTouch( CBaseEntity *pOther ) OVERRIDE;
  109. virtual const char* GetBuildingModel( int iLevel );
  110. virtual const char* GetFinishedModel( int iLevel );
  111. virtual const char* GetPlacementModel();
  112. virtual int ObjectCaps( void ) OVERRIDE { return (BaseClass::ObjectCaps() | FCAP_IMPULSE_USE); }
  113. virtual bool DispenseAmmo( CTFPlayer *pPlayer );
  114. virtual void DropSpellPickup() { /* DO NOTHING */ }
  115. virtual void DropDuckPickup() { /* DO NOTHING */ }
  116. virtual void DispenseSouls() { /* Do nothing */}
  117. virtual float GetHealRate() const;
  118. virtual void StartHealing( CBaseEntity *pOther );
  119. void StopHealing( CBaseEntity *pOther );
  120. void AddHealingTarget( CBaseEntity *pOther );
  121. bool RemoveHealingTarget( CBaseEntity *pOther );
  122. bool IsHealingTarget( CBaseEntity *pTarget );
  123. bool CouldHealTarget( CBaseEntity *pTarget );
  124. virtual float GetDispenserRadius( void );
  125. Vector GetHealOrigin( void );
  126. CUtlVector< EHANDLE > m_hHealingTargets;
  127. virtual void MakeMiniBuilding( CTFPlayer* pPlayer ) OVERRIDE;
  128. virtual void MakeCarriedObject( CTFPlayer *pCarrier );
  129. virtual int GetBaseHealth( void ) { return DISPENSER_MAX_HEALTH; }
  130. virtual int GetMaxUpgradeLevel( void ) OVERRIDE;
  131. virtual int GetMiniBuildingStartingHealth( void ) OVERRIDE { return DISPENSER_MINI_MAX_HEALTH; }
  132. CBaseEntity *GetTouchTrigger() const { return m_hTouchTrigger; }
  133. void DisableAmmoPickupSound() { m_bPlayAmmoPickupSound = false; }
  134. void DisableGenerateMetalSound() { m_bUseGenerateMetalSound = false; }
  135. private:
  136. virtual void PlayActiveSound();
  137. void ResetHealingTargets( void );
  138. protected:
  139. // The regular and mini dispenser can be repaired
  140. virtual bool CanBeRepaired() const OVERRIDE { return true; }
  141. CNetworkVar( int, m_iState );
  142. CNetworkVar( int, m_iAmmoMetal );
  143. CNetworkVar( int, m_iMiniBombCounter );
  144. bool m_bUseGenerateMetalSound;
  145. // Entities currently being touched by this trigger
  146. CUtlVector< EHANDLE > m_hTouchingEntities;
  147. float m_flNextAmmoDispense;
  148. bool m_bThrown;
  149. string_t m_iszCustomTouchTrigger;
  150. EHANDLE m_hTouchTrigger;
  151. DECLARE_DATADESC();
  152. private:
  153. CountdownTimer m_spellTimer;
  154. CountdownTimer m_duckTimer;
  155. CountdownTimer m_soulTimer;
  156. float m_flPrevRadius;
  157. bool m_bPlayAmmoPickupSound;
  158. };
  159. inline int CObjectDispenser::GetAvailableMetal( void ) const
  160. {
  161. return m_iAmmoMetal;
  162. }
  163. //------------------------------------------------------------------------------
  164. class CObjectCartDispenser : public CObjectDispenser
  165. {
  166. DECLARE_CLASS( CObjectCartDispenser, CObjectDispenser );
  167. public:
  168. DECLARE_SERVERCLASS();
  169. DECLARE_DATADESC();
  170. CObjectCartDispenser();
  171. virtual void Spawn( void );
  172. virtual void OnGoActive( void );
  173. virtual void GetControlPanelInfo( int nPanelIndex, const char *&pPanelName );
  174. virtual int DispenseMetal( CTFPlayer *pPlayer );
  175. virtual void DropSpellPickup();
  176. virtual void DropDuckPickup();
  177. virtual void DispenseSouls() OVERRIDE;
  178. virtual bool CanBeUpgraded( CTFPlayer *pPlayer ){ return false; }
  179. virtual void SetModel( const char *pModel );
  180. void InputFireHalloweenBonus( inputdata_t &inputdata );
  181. void InputSetDispenserLevel( inputdata_t &inputdata );
  182. void InputEnable( inputdata_t &inputdata );
  183. void InputDisable( inputdata_t &inputdata );
  184. };
  185. #endif // TF_OBJ_DISPENSER_H