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.

237 lines
6.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef PHYSOBJ_H
  8. #define PHYSOBJ_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #ifndef PHYSICS_H
  13. #include "physics.h"
  14. #endif
  15. #include "entityoutput.h"
  16. #include "func_break.h"
  17. #include "player_pickup.h"
  18. // ---------------------------------------------------------------------
  19. //
  20. // CPhysBox -- physically simulated brush rectangular solid
  21. //
  22. // ---------------------------------------------------------------------
  23. // Physbox Spawnflags. Start at 0x01000 to avoid collision with CBreakable's
  24. #define SF_PHYSBOX_ASLEEP 0x01000
  25. #define SF_PHYSBOX_IGNOREUSE 0x02000
  26. #define SF_PHYSBOX_DEBRIS 0x04000
  27. #define SF_PHYSBOX_MOTIONDISABLED 0x08000
  28. #define SF_PHYSBOX_USEPREFERRED 0x10000
  29. #define SF_PHYSBOX_ENABLE_ON_PHYSCANNON 0x20000
  30. #define SF_PHYSBOX_NO_ROTORWASH_PUSH 0x40000 // The rotorwash doesn't push these
  31. #define SF_PHYSBOX_ENABLE_PICKUP_OUTPUT 0x80000
  32. #define SF_PHYSBOX_ALWAYS_PICK_UP 0x100000 // Physcannon can always pick this up, no matter what mass or constraints may apply.
  33. #define SF_PHYSBOX_NEVER_PICK_UP 0x200000 // Physcannon will never be able to pick this up.
  34. #define SF_PHYSBOX_NEVER_PUNT 0x400000 // Physcannon will never be able to punt this object.
  35. #define SF_PHYSBOX_PREVENT_PLAYER_TOUCH_ENABLE 0x800000 // If set, the player will not cause the object to enable its motion when bumped into
  36. // UNDONE: Hook collisions into the physics system to generate touch functions and take damage on falls
  37. // UNDONE: Base class PhysBrush
  38. class CPhysBox : public CBreakable
  39. {
  40. DECLARE_CLASS( CPhysBox, CBreakable );
  41. public:
  42. DECLARE_SERVERCLASS();
  43. void Spawn ( void );
  44. bool CreateVPhysics();
  45. void Move( const Vector &force );
  46. virtual int ObjectCaps();
  47. virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  48. virtual int DrawDebugTextOverlays(void);
  49. virtual void VPhysicsUpdate( IPhysicsObject *pPhysics );
  50. virtual void VPhysicsCollision( int index, gamevcollisionevent_t *pEvent );
  51. int OnTakeDamage( const CTakeDamageInfo &info );
  52. void EnableMotion( void );
  53. bool CanBePickedUpByPhyscannon();
  54. // IPlayerPickupVPhysics
  55. virtual void OnPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason );
  56. virtual void OnPhysGunDrop( CBasePlayer *pPhysGunUser, PhysGunDrop_t Reason );
  57. bool HasPreferredCarryAnglesForPlayer( CBasePlayer *pPlayer );
  58. virtual QAngle PreferredCarryAngles( void ) { return m_angPreferredCarryAngles; }
  59. // inputs
  60. void InputWake( inputdata_t &inputdata );
  61. void InputSleep( inputdata_t &inputdata );
  62. void InputEnableMotion( inputdata_t &inputdata );
  63. void InputDisableMotion( inputdata_t &inputdata );
  64. void InputForceDrop( inputdata_t &inputdata );
  65. void InputDisableFloating( inputdata_t &inputdata );
  66. DECLARE_DATADESC();
  67. protected:
  68. int m_damageType;
  69. float m_massScale;
  70. string_t m_iszOverrideScript;
  71. int m_damageToEnableMotion;
  72. float m_flForceToEnableMotion;
  73. QAngle m_angPreferredCarryAngles;
  74. bool m_bNotSolidToWorld;
  75. // Outputs
  76. COutputEvent m_OnDamaged;
  77. COutputEvent m_OnAwakened;
  78. COutputEvent m_OnMotionEnabled;
  79. COutputEvent m_OnPhysGunPickup;
  80. COutputEvent m_OnPhysGunPunt;
  81. COutputEvent m_OnPhysGunOnlyPickup;
  82. COutputEvent m_OnPhysGunDrop;
  83. COutputEvent m_OnPlayerUse;
  84. CHandle<CBasePlayer> m_hCarryingPlayer; // Player who's carrying us
  85. };
  86. // ---------------------------------------------------------------------
  87. //
  88. // CPhysExplosion -- physically simulated explosion
  89. //
  90. // ---------------------------------------------------------------------
  91. class CPhysExplosion : public CPointEntity
  92. {
  93. public:
  94. DECLARE_CLASS( CPhysExplosion, CPointEntity );
  95. void Spawn ( void );
  96. void Explode( CBaseEntity *pActivator, CBaseEntity *pCaller );
  97. CBaseEntity *FindEntity( CBaseEntity *pEntity, CBaseEntity *pActivator, CBaseEntity *pCaller );
  98. int DrawDebugTextOverlays(void);
  99. // Input handlers
  100. void InputExplode( inputdata_t &inputdata );
  101. DECLARE_DATADESC();
  102. private:
  103. float GetRadius( void );
  104. float m_damage;
  105. float m_radius;
  106. string_t m_targetEntityName;
  107. float m_flInnerRadius;
  108. COutputEvent m_OnPushedPlayer;
  109. };
  110. //==================================================
  111. // CPhysImpact
  112. //==================================================
  113. class CPhysImpact : public CPointEntity
  114. {
  115. public:
  116. DECLARE_CLASS( CPhysImpact, CPointEntity );
  117. void Spawn( void );
  118. //void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  119. void Activate( void );
  120. void InputImpact( inputdata_t &inputdata );
  121. DECLARE_DATADESC();
  122. private:
  123. void PointAtEntity( void );
  124. float m_damage;
  125. float m_distance;
  126. string_t m_directionEntityName;
  127. };
  128. //-----------------------------------------------------------------------------
  129. // Purpose: A magnet that creates constraints between itself and anything it touches
  130. //-----------------------------------------------------------------------------
  131. struct magnetted_objects_t
  132. {
  133. IPhysicsConstraint *pConstraint;
  134. EHANDLE hEntity;
  135. DECLARE_SIMPLE_DATADESC();
  136. };
  137. class CPhysMagnet : public CBaseAnimating, public IPhysicsConstraintEvent
  138. {
  139. DECLARE_CLASS( CPhysMagnet, CBaseAnimating );
  140. public:
  141. DECLARE_DATADESC();
  142. DECLARE_SERVERCLASS();
  143. CPhysMagnet();
  144. ~CPhysMagnet();
  145. void Spawn( void );
  146. void Precache( void );
  147. void Touch( CBaseEntity *pOther );
  148. void VPhysicsCollision( int index, gamevcollisionevent_t *pEvent );
  149. void DoMagnetSuck( CBaseEntity *pOther );
  150. void SetConstraintGroup( IPhysicsConstraintGroup *pGroup );
  151. bool IsOn( void ) { return m_bActive; }
  152. int GetNumAttachedObjects( void );
  153. float GetTotalMassAttachedObjects( void );
  154. CBaseEntity *GetAttachedObject( int iIndex );
  155. // Checking for hitting something
  156. void ResetHasHitSomething( void ) { m_bHasHitSomething = false; }
  157. bool HasHitSomething( void ) { return m_bHasHitSomething; }
  158. // Inputs
  159. void InputToggle( inputdata_t &inputdata );
  160. void InputTurnOn( inputdata_t &inputdata );
  161. void InputTurnOff( inputdata_t &inputdata );
  162. void InputConstraintBroken( inputdata_t &inputdata );
  163. void DetachAll( void );
  164. // IPhysicsConstraintEvent
  165. public:
  166. void ConstraintBroken( IPhysicsConstraint *pConstraint );
  167. protected:
  168. // Outputs
  169. COutputEvent m_OnMagnetAttach;
  170. COutputEvent m_OnMagnetDetach;
  171. // Keys
  172. float m_massScale;
  173. string_t m_iszOverrideScript;
  174. float m_forceLimit;
  175. float m_torqueLimit;
  176. CUtlVector< magnetted_objects_t > m_MagnettedEntities;
  177. IPhysicsConstraintGroup *m_pConstraintGroup;
  178. bool m_bActive;
  179. bool m_bHasHitSomething;
  180. float m_flTotalMass;
  181. float m_flRadius;
  182. float m_flNextSuckTime;
  183. int m_iMaxObjectsAttached;
  184. };
  185. #endif // PHYSOBJ_H