Counter Strike : Global Offensive Source Code
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.

391 lines
11 KiB

  1. //========= Copyright � 1996-2005, 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. #include "triggers_shared.h"
  15. // DVS TODO: get rid of CBaseToggle
  16. //-----------------------------------------------------------------------------
  17. // Purpose:
  18. //-----------------------------------------------------------------------------
  19. class CBaseTrigger : public CBaseToggle
  20. {
  21. DECLARE_CLASS( CBaseTrigger, CBaseToggle );
  22. DECLARE_SERVERCLASS();
  23. public:
  24. CBaseTrigger();
  25. void Activate( void );
  26. virtual void PostClientActive( void );
  27. void InitTrigger( void );
  28. virtual void Enable( void );
  29. virtual void Disable( void );
  30. void Spawn( void );
  31. void UpdateOnRemove( void );
  32. void TouchTest( void );
  33. // Input handlers
  34. virtual void InputEnable( inputdata_t &inputdata );
  35. virtual void InputDisable( inputdata_t &inputdata );
  36. virtual void InputToggle( inputdata_t &inputdata );
  37. virtual void InputTouchTest ( inputdata_t &inputdata );
  38. virtual void InputStartTouch( inputdata_t &inputdata );
  39. virtual void InputEndTouch( inputdata_t &inputdata );
  40. virtual bool UsesFilter( void ){ return ( m_hFilter.Get() != NULL ); }
  41. virtual bool PassesTriggerFilters(CBaseEntity *pOther);
  42. virtual void StartTouch(CBaseEntity *pOther);
  43. virtual void EndTouch(CBaseEntity *pOther);
  44. virtual void OnStartTouchAll(CBaseEntity *pOther);
  45. virtual void OnEndTouchAll(CBaseEntity *pOther);
  46. bool IsTouching( CBaseEntity *pOther );
  47. CBaseEntity *GetTouchedEntityOfType( const char *sClassName );
  48. virtual int DrawDebugTextOverlays(void);
  49. // by default, triggers don't deal with TraceAttack
  50. void TraceAttack(CBaseEntity *pAttacker, float flDamage, const Vector &vecDir, trace_t *ptr, int bitsDamageType) {}
  51. CNetworkVarForDerived( bool, m_bDisabled );
  52. string_t m_iFilterName;
  53. CHandle<class CBaseFilter> m_hFilter;
  54. const CUtlVector< EHANDLE > *GetTouchingEntities( void ) const
  55. {
  56. return &m_hTouchingEntities;
  57. }
  58. protected:
  59. // Outputs
  60. COutputEvent m_OnStartTouch;
  61. COutputEvent m_OnStartTouchAll;
  62. COutputEvent m_OnEndTouch;
  63. COutputEvent m_OnEndTouchAll;
  64. COutputEvent m_OnTouching;
  65. COutputEvent m_OnNotTouching;
  66. // Entities currently being touched by this trigger
  67. CUtlVector< EHANDLE > m_hTouchingEntities;
  68. DECLARE_DATADESC();
  69. // True if trigger participates in client side prediction
  70. CNetworkVar( bool, m_bClientSidePredicted );
  71. };
  72. //-----------------------------------------------------------------------------
  73. // Purpose: Variable sized repeatable trigger. Must be targeted at one or more entities.
  74. // If "delay" is set, the trigger waits some time after activating before firing.
  75. // "wait" : Seconds between triggerings. (.2 default/minimum)
  76. //-----------------------------------------------------------------------------
  77. class CTriggerMultiple : public CBaseTrigger
  78. {
  79. DECLARE_CLASS( CTriggerMultiple, CBaseTrigger );
  80. public:
  81. void Spawn( void );
  82. void MultiTouch( CBaseEntity *pOther );
  83. void MultiWaitOver( void );
  84. virtual void ActivateMultiTrigger(CBaseEntity *pActivator);
  85. DECLARE_DATADESC();
  86. // Outputs
  87. COutputEvent m_OnTrigger;
  88. };
  89. // Global list of triggers that care about weapon fire
  90. extern CUtlVector< CHandle<CTriggerMultiple> > g_hWeaponFireTriggers;
  91. //------------------------------------------------------------------------------
  92. // Base VPhysics trigger implementation
  93. // NOTE: This uses vphysics to compute touch events. It doesn't do a per-frame Touch call, so the
  94. // Entity I/O is different from a regular trigger
  95. //------------------------------------------------------------------------------
  96. #define SF_VPHYSICS_MOTION_MOVEABLE 0x1000
  97. class CBaseVPhysicsTrigger : public CBaseEntity
  98. {
  99. DECLARE_CLASS( CBaseVPhysicsTrigger , CBaseEntity );
  100. DECLARE_SERVERCLASS();
  101. public:
  102. DECLARE_DATADESC();
  103. virtual void Spawn();
  104. virtual void UpdateOnRemove();
  105. virtual bool CreateVPhysics();
  106. virtual void Activate( void );
  107. virtual bool PassesTriggerFilters(CBaseEntity *pOther);
  108. // UNDONE: Pass trigger event in or change Start/EndTouch. Add ITriggerVPhysics perhaps?
  109. // BUGBUG: If a player touches two of these, his movement will screw up.
  110. // BUGBUG: If a player uses crouch/uncrouch it will generate touch events and clear the motioncontroller flag
  111. virtual void StartTouch( CBaseEntity *pOther );
  112. virtual void EndTouch( CBaseEntity *pOther );
  113. void InputToggle( inputdata_t &inputdata );
  114. void InputEnable( inputdata_t &inputdata );
  115. void InputDisable( inputdata_t &inputdata );
  116. protected:
  117. CNetworkVarForDerived( bool, m_bDisabled );
  118. string_t m_iFilterName;
  119. CHandle<class CBaseFilter> m_hFilter;
  120. };
  121. //-----------------------------------------------------------------------------
  122. // Purpose: Hurts anything that touches it. If the trigger has a targetname,
  123. // firing it will toggle state.
  124. //-----------------------------------------------------------------------------
  125. class CTriggerHurt : public CBaseTrigger
  126. {
  127. public:
  128. CTriggerHurt()
  129. {
  130. // This field came along after levels were built so the field defaults to 20 here in the constructor.
  131. m_flDamageCap = 20.0f;
  132. }
  133. DECLARE_CLASS( CTriggerHurt, CBaseTrigger );
  134. void Spawn( void );
  135. void RadiationThink( void );
  136. void HurtThink( void );
  137. void Touch( CBaseEntity *pOther );
  138. void EndTouch( CBaseEntity *pOther );
  139. bool HurtEntity( CBaseEntity *pOther, float damage );
  140. int HurtAllTouchers( float dt );
  141. void NavThink( void );
  142. DECLARE_DATADESC();
  143. float m_flOriginalDamage; // Damage as specified by the level designer.
  144. float m_flDamage; // Damage per second.
  145. float m_flDamageCap; // Maximum damage per second.
  146. float m_flLastDmgTime; // Time that we last applied damage.
  147. float m_flDmgResetTime; // For forgiveness, the time to reset the counter that accumulates damage.
  148. int m_bitsDamageInflict; // DMG_ damage type that the door or tigger does
  149. int m_damageModel;
  150. bool m_bNoDmgForce; // Should damage from this trigger impart force on what it's hurting
  151. enum
  152. {
  153. DAMAGEMODEL_NORMAL = 0,
  154. DAMAGEMODEL_DOUBLE_FORGIVENESS,
  155. };
  156. // Outputs
  157. COutputEvent m_OnHurt;
  158. COutputEvent m_OnHurtPlayer;
  159. CUtlVector<EHANDLE> m_hurtEntities;
  160. };
  161. //
  162. // Callback trigger
  163. //
  164. class CTriggerCallback : public CBaseTrigger
  165. {
  166. public:
  167. DECLARE_CLASS( CTriggerCallback, CBaseTrigger );
  168. DECLARE_DATADESC();
  169. virtual void Spawn( void );
  170. virtual void StartTouch( CBaseEntity *pOther );
  171. static CTriggerCallback *Create( const Vector &vecOrigin, const QAngle &vecAngles, const Vector &vecMins, const Vector &vecMaxs, CBaseEntity *pOwner, void (CBaseEntity::*pfnCallback)(CBaseEntity *) )
  172. {
  173. CTriggerCallback *pTrigger = (CTriggerCallback *) CreateEntityByName( "trigger_callback" );
  174. if ( pTrigger == NULL )
  175. return NULL;
  176. UTIL_SetOrigin( pTrigger, vecOrigin );
  177. pTrigger->SetAbsAngles( vecAngles );
  178. UTIL_SetSize( pTrigger, vecMins, vecMaxs );
  179. DispatchSpawn( pTrigger );
  180. pTrigger->SetParent( (CBaseEntity *) pOwner );
  181. // Save our callback function
  182. pTrigger->m_pfnCallback = pfnCallback;
  183. return pTrigger;
  184. }
  185. private:
  186. void (CBaseEntity::*m_pfnCallback)(CBaseEntity *);
  187. };
  188. //-----------------------------------------------------------------------------
  189. // Purpose:
  190. //-----------------------------------------------------------------------------
  191. class CTriggerCamera : public CBaseEntity
  192. {
  193. public:
  194. DECLARE_CLASS( CTriggerCamera, CBaseEntity );
  195. // script description
  196. DECLARE_ENT_SCRIPTDESC();
  197. CTriggerCamera();
  198. void Spawn( void );
  199. bool KeyValue( const char *szKeyName, const char *szValue );
  200. void Enable( void );
  201. void Disable( void );
  202. void SetPlayer( CBaseEntity *pPlayer );
  203. void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  204. void FindAttachment( void );
  205. void FollowTarget( void );
  206. void ReturnToEyes( void );
  207. void MoveViewTo( QAngle vecGoalView );
  208. void Move( void );
  209. void StartCameraShot( const char *pszShotType, CBaseEntity *pSceneEntity, CBaseEntity *pActor1, CBaseEntity *pActor2, float duration );
  210. int ScriptGetFov( void );
  211. void ScriptSetFov( int iFOV, float rate );
  212. // Always transmit to clients so they know where to move the view to
  213. virtual int UpdateTransmitState();
  214. DECLARE_DATADESC();
  215. // Input handlers
  216. void InputEnable( inputdata_t &inputdata );
  217. void InputDisable( inputdata_t &inputdata );
  218. void InputSetTarget( inputdata_t &inputdata );
  219. void InputSetTargetAttachment( inputdata_t &inputdata );
  220. void InputReturnToEyes( inputdata_t &inputdata );
  221. void InputTeleportToView( inputdata_t &inputdata );
  222. void InputSetTrackSpeed( inputdata_t &inputdata );
  223. void InputSetPath( inputdata_t &inputdata );
  224. private:
  225. EHANDLE m_hPlayer;
  226. EHANDLE m_hTarget;
  227. // used for moving the camera along a path (rail rides)
  228. CBaseEntity *m_pPath;
  229. string_t m_sPath;
  230. float m_flWait;
  231. float m_flReturnTime;
  232. float m_flStopTime;
  233. float m_moveDistance;
  234. float m_targetSpeed;
  235. float m_initialSpeed;
  236. float m_acceleration;
  237. float m_deceleration;
  238. int m_state;
  239. Vector m_vecMoveDir;
  240. float m_fov;
  241. float m_fovSpeed;
  242. float m_trackSpeed;
  243. string_t m_iszTargetAttachment;
  244. int m_iAttachmentIndex;
  245. bool m_bSnapToGoal;
  246. #if HL2_EPISODIC
  247. bool m_bInterpolatePosition;
  248. // these are interpolation vars used for interpolating the camera over time
  249. Vector m_vStartPos, m_vEndPos;
  250. float m_flInterpStartTime;
  251. const static float kflPosInterpTime; // seconds
  252. #endif
  253. int m_nPlayerButtons;
  254. int m_nOldTakeDamage;
  255. private:
  256. COutputEvent m_OnEndFollow;
  257. };
  258. //-----------------------------------------------------------------------------
  259. // Purpose:
  260. //-----------------------------------------------------------------------------
  261. class CTriggerViewProxy : public CBaseEntity
  262. {
  263. public:
  264. DECLARE_CLASS( CTriggerViewProxy, CBaseEntity );
  265. CTriggerViewProxy();
  266. void Spawn( void );
  267. bool KeyValue( const char *szKeyName, const char *szValue );
  268. void Enable( void );
  269. void Disable( void );
  270. void SetPlayer( CBaseEntity *pPlayer );
  271. void TranslateViewToProxy( void );
  272. void Move( void );
  273. Vector GetPlayerOffset();
  274. // Always transmit to clients so they know where to move the view to
  275. virtual int UpdateTransmitState();
  276. DECLARE_DATADESC();
  277. // Input handlers
  278. void InputEnable( inputdata_t &inputdata );
  279. void InputDisable( inputdata_t &inputdata );
  280. void InputTeleportPlayerToProxy( inputdata_t &inputdata );
  281. private:
  282. EHANDLE m_hPlayer;
  283. CBaseEntity *m_pProxy;
  284. string_t m_sProxy;
  285. string_t m_sProxyAttachment;
  286. int m_nParentAttachment;
  287. int m_state;
  288. int m_nOffsetType;
  289. Vector m_vecInitialPosition;
  290. Vector m_vecLastPosition;
  291. Vector m_vecLastVelocity;
  292. Vector m_vecInitialOffset;
  293. float m_flTiltFraction;
  294. float m_flStartTime;
  295. bool m_bUseFakeAcceleration;
  296. bool m_bSkewAccelerationForward;
  297. float m_flAccelerationScalar;
  298. bool m_bEaseAnglesToCamera;
  299. int m_nPlayerButtons;
  300. int m_nOldTakeDamage;
  301. };
  302. #endif // TRIGGERS_H