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.

229 lines
7.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TRIGGERS_H
  8. #define TRIGGERS_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "basetoggle.h"
  13. #include "entityoutput.h"
  14. //
  15. // Spawnflags
  16. //
  17. enum
  18. {
  19. SF_TRIGGER_ALLOW_CLIENTS = 0x01, // Players can fire this trigger
  20. SF_TRIGGER_ALLOW_NPCS = 0x02, // NPCS can fire this trigger
  21. SF_TRIGGER_ALLOW_PUSHABLES = 0x04, // Pushables can fire this trigger
  22. SF_TRIGGER_ALLOW_PHYSICS = 0x08, // Physics objects can fire this trigger
  23. SF_TRIGGER_ONLY_PLAYER_ALLY_NPCS = 0x10, // *if* NPCs can fire this trigger, this flag means only player allies do so
  24. SF_TRIGGER_ONLY_CLIENTS_IN_VEHICLES = 0x20, // *if* Players can fire this trigger, this flag means only players inside vehicles can
  25. SF_TRIGGER_ALLOW_ALL = 0x40, // Everything can fire this trigger EXCEPT DEBRIS!
  26. SF_TRIGGER_ONLY_CLIENTS_OUT_OF_VEHICLES = 0x200, // *if* Players can fire this trigger, this flag means only players outside vehicles can
  27. SF_TRIG_PUSH_ONCE = 0x80, // trigger_push removes itself after firing once
  28. SF_TRIG_PUSH_AFFECT_PLAYER_ON_LADDER = 0x100, // if pushed object is player on a ladder, then this disengages them from the ladder (HL2only)
  29. SF_TRIG_TOUCH_DEBRIS = 0x400, // Will touch physics debris objects
  30. SF_TRIGGER_ONLY_NPCS_IN_VEHICLES = 0X800, // *if* NPCs can fire this trigger, only NPCs in vehicles do so (respects player ally flag too)
  31. SF_TRIGGER_DISALLOW_BOTS = 0x1000, // Bots are not allowed to fire this trigger
  32. };
  33. // DVS TODO: get rid of CBaseToggle
  34. //-----------------------------------------------------------------------------
  35. // Purpose:
  36. //-----------------------------------------------------------------------------
  37. class CBaseTrigger : public CBaseToggle
  38. {
  39. DECLARE_CLASS( CBaseTrigger, CBaseToggle );
  40. public:
  41. CBaseTrigger();
  42. void Activate( void );
  43. virtual void PostClientActive( void );
  44. void InitTrigger( void );
  45. void Enable( void );
  46. void Disable( void );
  47. void Spawn( void );
  48. void UpdateOnRemove( void );
  49. void TouchTest( void );
  50. // Input handlers
  51. virtual void InputEnable( inputdata_t &inputdata );
  52. virtual void InputDisable( inputdata_t &inputdata );
  53. virtual void InputDisableAndEndTouch( inputdata_t &inputdata );
  54. virtual void InputToggle( inputdata_t &inputdata );
  55. virtual void InputTouchTest ( inputdata_t &inputdata );
  56. virtual void InputStartTouch( inputdata_t &inputdata );
  57. virtual void InputEndTouch( inputdata_t &inputdata );
  58. virtual bool UsesFilter( void ){ return ( m_hFilter.Get() != NULL ); }
  59. virtual bool PassesTriggerFilters(CBaseEntity *pOther);
  60. virtual void StartTouch(CBaseEntity *pOther);
  61. virtual void EndTouch(CBaseEntity *pOther);
  62. virtual void StartTouchAll() {}
  63. virtual void EndTouchAll() {}
  64. virtual bool IsTouching( const CBaseEntity *pOther ) const;
  65. CBaseEntity *GetTouchedEntityOfType( const char *sClassName );
  66. int DrawDebugTextOverlays(void);
  67. // by default, triggers don't deal with TraceAttack
  68. void TraceAttack(CBaseEntity *pAttacker, float flDamage, const Vector &vecDir, trace_t *ptr, int bitsDamageType) {}
  69. bool PointIsWithin( const Vector &vecPoint );
  70. bool m_bDisabled;
  71. string_t m_iFilterName;
  72. CHandle<class CBaseFilter> m_hFilter;
  73. protected:
  74. // Outputs
  75. COutputEvent m_OnStartTouch;
  76. COutputEvent m_OnStartTouchAll;
  77. COutputEvent m_OnEndTouch;
  78. COutputEvent m_OnEndTouchAll;
  79. COutputEvent m_OnTouching;
  80. COutputEvent m_OnNotTouching;
  81. // Entities currently being touched by this trigger
  82. CUtlVector< EHANDLE > m_hTouchingEntities;
  83. DECLARE_DATADESC();
  84. };
  85. //-----------------------------------------------------------------------------
  86. // Purpose: Variable sized repeatable trigger. Must be targeted at one or more entities.
  87. // If "delay" is set, the trigger waits some time after activating before firing.
  88. // "wait" : Seconds between triggerings. (.2 default/minimum)
  89. //-----------------------------------------------------------------------------
  90. class CTriggerMultiple : public CBaseTrigger
  91. {
  92. DECLARE_CLASS( CTriggerMultiple, CBaseTrigger );
  93. public:
  94. void Spawn( void );
  95. void MultiTouch( CBaseEntity *pOther );
  96. void MultiWaitOver( void );
  97. void ActivateMultiTrigger(CBaseEntity *pActivator);
  98. DECLARE_DATADESC();
  99. // Outputs
  100. COutputEvent m_OnTrigger;
  101. };
  102. // Global list of triggers that care about weapon fire
  103. extern CUtlVector< CHandle<CTriggerMultiple> > g_hWeaponFireTriggers;
  104. //------------------------------------------------------------------------------
  105. // Base VPhysics trigger implementation
  106. // NOTE: This uses vphysics to compute touch events. It doesn't do a per-frame Touch call, so the
  107. // Entity I/O is different from a regular trigger
  108. //------------------------------------------------------------------------------
  109. #define SF_VPHYSICS_MOTION_MOVEABLE 0x1000
  110. class CBaseVPhysicsTrigger : public CBaseEntity
  111. {
  112. DECLARE_CLASS( CBaseVPhysicsTrigger , CBaseEntity );
  113. public:
  114. DECLARE_DATADESC();
  115. virtual void Spawn();
  116. virtual void UpdateOnRemove();
  117. virtual bool CreateVPhysics();
  118. virtual void Activate( void );
  119. virtual bool PassesTriggerFilters(CBaseEntity *pOther);
  120. // UNDONE: Pass trigger event in or change Start/EndTouch. Add ITriggerVPhysics perhaps?
  121. // BUGBUG: If a player touches two of these, his movement will screw up.
  122. // BUGBUG: If a player uses crouch/uncrouch it will generate touch events and clear the motioncontroller flag
  123. virtual void StartTouch( CBaseEntity *pOther );
  124. virtual void EndTouch( CBaseEntity *pOther );
  125. void InputToggle( inputdata_t &inputdata );
  126. void InputEnable( inputdata_t &inputdata );
  127. void InputDisable( inputdata_t &inputdata );
  128. protected:
  129. bool m_bDisabled;
  130. string_t m_iFilterName;
  131. CHandle<class CBaseFilter> m_hFilter;
  132. };
  133. //-----------------------------------------------------------------------------
  134. // Purpose: Hurts anything that touches it. If the trigger has a targetname,
  135. // firing it will toggle state.
  136. //-----------------------------------------------------------------------------
  137. // This class is to get around the fact that DEFINE_FUNCTION doesn't like multiple inheritance
  138. class CTriggerHurtShim : public CBaseTrigger
  139. {
  140. virtual void RadiationThink( void ) = 0;
  141. virtual void HurtThink( void ) = 0;
  142. public:
  143. void RadiationThinkShim( void ){ RadiationThink(); }
  144. void HurtThinkShim( void ){ HurtThink(); }
  145. };
  146. DECLARE_AUTO_LIST( ITriggerHurtAutoList );
  147. class CTriggerHurt : public CTriggerHurtShim, public ITriggerHurtAutoList
  148. {
  149. public:
  150. CTriggerHurt()
  151. {
  152. // This field came along after levels were built so the field defaults to 20 here in the constructor.
  153. m_flDamageCap = 20.0f;
  154. }
  155. DECLARE_CLASS( CTriggerHurt, CTriggerHurtShim );
  156. void Spawn( void );
  157. void RadiationThink( void );
  158. void HurtThink( void );
  159. void Touch( CBaseEntity *pOther );
  160. void EndTouch( CBaseEntity *pOther );
  161. bool HurtEntity( CBaseEntity *pOther, float damage );
  162. int HurtAllTouchers( float dt );
  163. DECLARE_DATADESC();
  164. float m_flOriginalDamage; // Damage as specified by the level designer.
  165. float m_flDamage; // Damage per second.
  166. float m_flDamageCap; // Maximum damage per second.
  167. float m_flLastDmgTime; // Time that we last applied damage.
  168. float m_flDmgResetTime; // For forgiveness, the time to reset the counter that accumulates damage.
  169. int m_bitsDamageInflict; // DMG_ damage type that the door or tigger does
  170. int m_damageModel;
  171. bool m_bNoDmgForce; // Should damage from this trigger impart force on what it's hurting
  172. enum
  173. {
  174. DAMAGEMODEL_NORMAL = 0,
  175. DAMAGEMODEL_DOUBLE_FORGIVENESS,
  176. };
  177. // Outputs
  178. COutputEvent m_OnHurt;
  179. COutputEvent m_OnHurtPlayer;
  180. CUtlVector<EHANDLE> m_hurtEntities;
  181. };
  182. bool IsTakingTriggerHurtDamageAtPoint( const Vector &vecPoint );
  183. #endif // TRIGGERS_H