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.

256 lines
10 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef PROPS_SHARED_H
  7. #define PROPS_SHARED_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "igamesystem.h"
  12. #include <keyvalues.h>
  13. // Phys prop spawnflags
  14. #define SF_PHYSPROP_START_ASLEEP 0x000001
  15. #define SF_PHYSPROP_DONT_TAKE_PHYSICS_DAMAGE 0x000002 // this prop can't be damaged by physics collisions
  16. #define SF_PHYSPROP_DEBRIS 0x000004
  17. #define SF_PHYSPROP_MOTIONDISABLED 0x000008 // motion disabled at startup (flag only valid in spawn - motion can be enabled via input)
  18. #define SF_PHYSPROP_TOUCH 0x000010 // can be 'crashed through' by running player (plate glass)
  19. #define SF_PHYSPROP_PRESSURE 0x000020 // can be broken by a player standing on it
  20. #define SF_PHYSPROP_ENABLE_ON_PHYSCANNON 0x000040 // enable motion only if the player grabs it with the physcannon
  21. #define SF_PHYSPROP_NO_ROTORWASH_PUSH 0x000080 // The rotorwash doesn't push these
  22. #define SF_PHYSPROP_ENABLE_PICKUP_OUTPUT 0x000100 // If set, allow the player to +USE this for the purposes of generating an output
  23. #define SF_PHYSPROP_PREVENT_PICKUP 0x000200 // If set, prevent +USE/Physcannon pickup of this prop
  24. #define SF_PHYSPROP_PREVENT_PLAYER_TOUCH_ENABLE 0x000400 // If set, the player will not cause the object to enable its motion when bumped into
  25. #define SF_PHYSPROP_HAS_ATTACHED_RAGDOLLS 0x000800 // Need to remove attached ragdolls on enable motion/etc
  26. #define SF_PHYSPROP_FORCE_TOUCH_TRIGGERS 0x001000 // Override normal debris behavior and respond to triggers anyway
  27. #define SF_PHYSPROP_FORCE_SERVER_SIDE 0x002000 // Force multiplayer physics object to be serverside
  28. #define SF_PHYSPROP_RADIUS_PICKUP 0x004000 // For Xbox, makes small objects easier to pick up by allowing them to be found
  29. #define SF_PHYSPROP_DISABLE_MOTION_ON_FREEZE 0x010000 // Phys prop disables motion the first time it comes to rest
  30. #define SF_PHYSPROP_ALWAYS_PICK_UP 0x100000 // Physcannon can always pick this up, no matter what mass or constraints may apply.
  31. #define SF_PHYSPROP_NO_COLLISIONS 0x200000 // Don't enable collisions on spawn
  32. #define SF_PHYSPROP_IS_GIB 0x400000 // Limit # of active gibs
  33. // Any barrel farther away than this is ignited rather than exploded.
  34. #define PROP_EXPLOSION_IGNITE_RADIUS 32.0f
  35. // ParsePropData returns
  36. enum
  37. {
  38. PARSE_SUCCEEDED, // Parsed propdata. Prop must be a prop_physics.
  39. PARSE_SUCCEEDED_ALLOWED_STATIC, // Parsed propdata. Prop allowed to be prop_physics or prop_dynamic/prop_static.
  40. PARSE_FAILED_NO_DATA, // Parse failed, no propdata in model. Prop must be prop_dynamic/prop_static.
  41. PARSE_FAILED_BAD_DATA, // Parse failed, found propdata but it had bad data.
  42. };
  43. // Propdata defined interactions
  44. enum propdata_interactions_t
  45. {
  46. PROPINTER_PHYSGUN_WORLD_STICK, // "onworldimpact" "stick"
  47. PROPINTER_PHYSGUN_FIRST_BREAK, // "onfirstimpact" "break"
  48. PROPINTER_PHYSGUN_FIRST_PAINT, // "onfirstimpact" "paintsplat"
  49. PROPINTER_PHYSGUN_FIRST_IMPALE, // "onfirstimpact" "impale"
  50. PROPINTER_PHYSGUN_LAUNCH_SPIN_NONE, // "onlaunch" "spin_none"
  51. PROPINTER_PHYSGUN_LAUNCH_SPIN_Z, // "onlaunch" "spin_zaxis"
  52. PROPINTER_PHYSGUN_BREAK_EXPLODE, // "onbreak" "explode_fire"
  53. PROPINTER_PHYSGUN_BREAK_EXPLODE_ICE, // "onbreak" "explode_ice"
  54. PROPINTER_PHYSGUN_DAMAGE_NONE, // "damage" "none"
  55. PROPINTER_FIRE_FLAMMABLE, // "flammable" "yes"
  56. PROPINTER_FIRE_EXPLOSIVE_RESIST, // "explosive_resist" "yes"
  57. PROPINTER_FIRE_IGNITE_HALFHEALTH, // "ignite" "halfhealth"
  58. PROPINTER_PHYSGUN_CREATE_FLARE, // "onpickup" "create_flare"
  59. PROPINTER_PHYSGUN_ALLOW_OVERHEAD, // "allow_overhead" "yes"
  60. PROPINTER_WORLD_BLOODSPLAT, // "onworldimpact", "bloodsplat"
  61. PROPINTER_PHYSGUN_NOTIFY_CHILDREN, // "onfirstimpact" cause attached flechettes to explode
  62. PROPINTER_MELEE_IMMUNE, // "melee_immune" "yes"
  63. // If we get more than 32 of these, we'll need a different system
  64. PROPINTER_NUM_INTERACTIONS,
  65. };
  66. // Entities using COLLISION_GROUP_SPECIAL_PHYSICS should support this interface.
  67. abstract_class IMultiplayerPhysics
  68. {
  69. public:
  70. virtual int GetMultiplayerPhysicsMode() = 0;
  71. virtual float GetMass() = 0;
  72. virtual bool IsAsleep() = 0;
  73. };
  74. #define PHYSICS_MULTIPLAYER_AUTODETECT 0 // use multiplayer physics mode as defined in model prop data
  75. #define PHYSICS_MULTIPLAYER_SOLID 1 // soild, pushes player away
  76. #define PHYSICS_MULTIPLAYER_NON_SOLID 2 // nonsolid, but pushed by player
  77. #define PHYSICS_MULTIPLAYER_CLIENTSIDE 3 // Clientside only, nonsolid
  78. enum mp_break_t
  79. {
  80. MULTIPLAYER_BREAK_DEFAULT,
  81. MULTIPLAYER_BREAK_SERVERSIDE,
  82. MULTIPLAYER_BREAK_CLIENTSIDE,
  83. MULTIPLAYER_BREAK_BOTH
  84. };
  85. enum PerformanceMode_t
  86. {
  87. PM_NORMAL,
  88. PM_NO_GIBS,
  89. PM_FULL_GIBS,
  90. PM_REDUCED_GIBS,
  91. };
  92. //=============================================================================================================
  93. // PROP DATA
  94. //=============================================================================================================
  95. //-----------------------------------------------------------------------------
  96. // Purpose: Derive your entity from this if you want your entity to parse propdata
  97. //-----------------------------------------------------------------------------
  98. abstract_class IBreakableWithPropData
  99. {
  100. public:
  101. // Damage modifiers
  102. virtual void SetDmgModBullet( float flDmgMod ) = 0;
  103. virtual void SetDmgModClub( float flDmgMod ) = 0;
  104. virtual void SetDmgModExplosive( float flDmgMod ) = 0;
  105. virtual float GetDmgModBullet( void ) = 0;
  106. virtual float GetDmgModClub( void ) = 0;
  107. virtual float GetDmgModExplosive( void ) = 0;
  108. virtual float GetDmgModFire( void ) = 0;
  109. // Explosive
  110. virtual void SetExplosiveRadius( float flRadius ) = 0;
  111. virtual void SetExplosiveDamage( float flDamage ) = 0;
  112. virtual float GetExplosiveRadius( void ) = 0;
  113. virtual float GetExplosiveDamage( void ) = 0;
  114. // Physics damage tables
  115. virtual void SetPhysicsDamageTable( string_t iszTableName ) = 0;
  116. virtual string_t GetPhysicsDamageTable( void ) = 0;
  117. // Breakable chunks
  118. virtual void SetBreakableModel( string_t iszModel ) = 0;
  119. virtual string_t GetBreakableModel( void ) = 0;
  120. virtual void SetBreakableSkin( int iSkin ) = 0;
  121. virtual int GetBreakableSkin( void ) = 0;
  122. virtual void SetBreakableCount( int iCount ) = 0;
  123. virtual int GetBreakableCount( void ) = 0;
  124. virtual void SetMaxBreakableSize( int iSize ) = 0;
  125. virtual int GetMaxBreakableSize( void ) = 0;
  126. // LOS blocking
  127. virtual void SetPropDataBlocksLOS( bool bBlocksLOS ) = 0;
  128. virtual void SetPropDataIsAIWalkable( bool bBlocksLOS ) = 0;
  129. // Interactions
  130. virtual void SetInteraction( propdata_interactions_t Interaction ) = 0;
  131. virtual bool HasInteraction( propdata_interactions_t Interaction ) = 0;
  132. // Multiplayer physics mode
  133. virtual void SetPhysicsMode(int iMode) = 0;
  134. virtual int GetPhysicsMode() = 0;
  135. // Multiplayer breakable spawn behavior
  136. virtual void SetMultiplayerBreakMode( mp_break_t mode ) = 0;
  137. virtual mp_break_t GetMultiplayerBreakMode( void ) const = 0;
  138. // Used for debugging
  139. virtual void SetBasePropData( string_t iszBase ) = 0;
  140. virtual string_t GetBasePropData( void ) = 0;
  141. };
  142. //-----------------------------------------------------------------------------
  143. // Purpose: Gamesystem that parses the prop data file
  144. //-----------------------------------------------------------------------------
  145. class CPropData : public CAutoGameSystem
  146. {
  147. public:
  148. CPropData( void );
  149. // Inherited from IAutoServerSystem
  150. virtual void LevelInitPreEntity( void );
  151. virtual void LevelShutdownPostEntity( void );
  152. // Read in the data from the prop data file
  153. void ParsePropDataFile( void );
  154. // Parse a keyvalues section into the prop
  155. int ParsePropFromKV( CBaseEntity *pProp, IBreakableWithPropData *pBreakableInterface, KeyValues *pSection, KeyValues *pInteractionSection );
  156. // Fill out a prop's with base data parsed from the propdata file
  157. int ParsePropFromBase( CBaseEntity *pProp, IBreakableWithPropData *pBreakableInterface, const char *pszPropData );
  158. // Get a random chunk in the specified breakable section
  159. const char *GetRandomChunkModel( const char *pszBreakableSection, int iMaxSize = -1 );
  160. protected:
  161. KeyValues *m_pKVPropData;
  162. bool m_bPropDataLoaded;
  163. struct propdata_breakablechunk_t
  164. {
  165. string_t iszChunkType;
  166. CUtlVector<string_t> iszChunkModels;
  167. };
  168. CUtlVector<propdata_breakablechunk_t> m_BreakableChunks;
  169. };
  170. extern CPropData g_PropDataSystem;
  171. struct breakmodel_t
  172. {
  173. Vector offset;
  174. char modelName[512];
  175. char placementName[512];
  176. float fadeTime;
  177. float fadeMinDist;
  178. float fadeMaxDist;
  179. float health;
  180. float burstScale;
  181. int collisionGroup;
  182. bool isRagdoll;
  183. bool placementIsBone;
  184. bool isMotionDisabled;
  185. mp_break_t mpBreakMode;
  186. };
  187. struct breakablepropparams_t
  188. {
  189. breakablepropparams_t( const Vector &_origin, const QAngle &_angles, const Vector &_velocity, const AngularImpulse &_angularVelocity )
  190. : origin(_origin), angles(_angles), velocity(_velocity), angularVelocity(_angularVelocity)
  191. {
  192. impactEnergyScale = 0;
  193. defBurstScale = 0;
  194. defCollisionGroup = COLLISION_GROUP_NONE;
  195. }
  196. const Vector &origin;
  197. const QAngle &angles;
  198. const Vector &velocity;
  199. const AngularImpulse &angularVelocity;
  200. float impactEnergyScale;
  201. float defBurstScale;
  202. int defCollisionGroup;
  203. };
  204. const char *GetMassEquivalent(float flMass);
  205. int GetAutoMultiplayerPhysicsMode( Vector size, float mass );
  206. void BreakModelList( CUtlVector<breakmodel_t> &list, int modelindex, float defBurstScale, int defCollisionGroup );
  207. void PropBreakableCreateAll( int modelindex, IPhysicsObject *pPhysics, const breakablepropparams_t &params, CBaseEntity *pEntity, int iPrecomputedBreakableCount, bool bIgnoreGibLImit, bool defaultLocation = true );
  208. void PropBreakableCreateAll( int modelindex, IPhysicsObject *pPhysics, const Vector &origin, const QAngle &angles, const Vector &velocity, const AngularImpulse &angularVelocity, float impactEnergyScale, float burstScale, int collisionGroup, CBaseEntity *pEntity = NULL, bool defaultLocation = true );
  209. // Player gibs.
  210. void PrecacheGibsForModel( int iModel );
  211. void BuildGibList( CUtlVector<breakmodel_t> &list, int modelindex, float defBurstScale, int defCollisionGroup );
  212. CBaseEntity *CreateGibsFromList( CUtlVector<breakmodel_t> &list, int modelindex, IPhysicsObject *pPhysics, const breakablepropparams_t &params, CBaseEntity *pEntity, int iPrecomputedBreakableCount, bool bIgnoreGibLImit, bool defaultLocation = true, CUtlVector<EHANDLE> *pGibList = NULL, bool bBurning = false );
  213. #endif // PROPS_SHARED_H