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.

202 lines
7.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef ENV_METEOR_SHARED_H
  8. #define ENV_METEOR_SHARED_H
  9. #pragma once
  10. #include "vstdlib/random.h"
  11. #include "mathlib/vector.h"
  12. #include "utlvector.h"
  13. //=============================================================================
  14. //
  15. // Shared Meteor Class
  16. //
  17. #define METEOR_INVALID_TIME -9999.9f
  18. #define METEOR_PASSIVE_TIME 0.0f
  19. #define METEOR_MAX_LIFETIME 60.0f
  20. #define METEOR_MIN_SIZE Vector( -100, -100, -100 )
  21. #define METEOR_MAX_SIZE Vector( 100, 100, 100 )
  22. #define METEOR_LOCATION_INVALID -1
  23. #define METEOR_LOCATION_WORLD 0
  24. #define METEOR_LOCATION_SKYBOX 1
  25. class CEnvMeteorShared
  26. {
  27. public:
  28. //-------------------------------------------------------------------------
  29. // Initialization.
  30. //-------------------------------------------------------------------------
  31. CEnvMeteorShared();
  32. void Init( int nID, float flStartTime, float flPassiveTime,
  33. const Vector &vecStartPosition,
  34. const Vector &vecDirection, float flSpeed, float flDamageRadius,
  35. const Vector &vecTriggerMins, const Vector &vecTriggerMaxs );
  36. //-------------------------------------------------------------------------
  37. // Returns the position of the object at a given time.
  38. //-------------------------------------------------------------------------
  39. void GetPositionAtTime( float flTime, Vector &vecPosition );
  40. //-------------------------------------------------------------------------
  41. // Changes an objects paramters from "skybox space" to "world space."
  42. //-------------------------------------------------------------------------
  43. void ConvertFromSkyboxToWorld( void );
  44. //-------------------------------------------------------------------------
  45. // Changes an objects paramters from "world space" to "skybox space."
  46. //-------------------------------------------------------------------------
  47. void ConvertFromWorldToSkybox( void );
  48. //-------------------------------------------------------------------------
  49. // Returns whether or not the object is the the skybox given the time.
  50. //-------------------------------------------------------------------------
  51. bool IsInSkybox( float flTime );
  52. //-------------------------------------------------------------------------
  53. // Returns whether or not the object is moving in the skybox (or passive).
  54. //-------------------------------------------------------------------------
  55. bool IsPassive( float flTime );
  56. //-------------------------------------------------------------------------
  57. // Returns whether or not the object will ever transition from skybox to world.
  58. //-------------------------------------------------------------------------
  59. bool WillTransition( void );
  60. //-------------------------------------------------------------------------
  61. // Returns the splash damage radius of the object.
  62. //-------------------------------------------------------------------------
  63. float GetDamageRadius( void );
  64. public:
  65. int m_nID; // unique identifier
  66. // The objects initial parametric conditions.
  67. Vector m_vecStartPosition;
  68. Vector m_vecDirection;
  69. float m_flSpeed; // (units/sec), unit = 1 inch
  70. float m_flStartTime;
  71. // NOTE: All times are absolute - ie m_flStartTime has been added in.
  72. // The time after the starting time in which it object starts to "move."
  73. float m_flPassiveTime;
  74. // The enter and exit times define the times at which the object enters and
  75. // exits the world. In other words, m_flEnterTime is the time at which the
  76. // object leaves the skybox and enters the world. m_flExitTime is the opposite.
  77. float m_flWorldEnterTime;
  78. float m_flWorldExitTime;
  79. float m_flPosTime; // Timer used to find the position of the meteor.
  80. Vector m_vecPos;
  81. //
  82. int m_nLocation; // 0 = Skybox, 1 = World
  83. float m_flDamageRadius; //
  84. private:
  85. // Calculate the enter/exit times. (called from Init)
  86. void CalcEnterAndExitTimes( const Vector &vecTriggerMins, const Vector &vecTriggerMaxs );
  87. };
  88. //=============================================================================
  89. //
  90. // Meteor Factory Interface
  91. //
  92. abstract_class IMeteorFactory
  93. {
  94. public:
  95. virtual void CreateMeteor( int nID, int iType,
  96. const Vector &vecPosition, const Vector &vecDirection,
  97. float flSpeed, float flStartTime, float flDamageRadius,
  98. const Vector &vecTriggerMins, const Vector &vecTriggerMaxs ) = 0;
  99. };
  100. //=============================================================================
  101. //
  102. // Shared Meteor Spawner Class
  103. //
  104. class CEnvMeteorSpawnerShared
  105. {
  106. public:
  107. DECLARE_CLASS_NOBASE( CEnvMeteorSpawnerShared );
  108. DECLARE_EMBEDDED_NETWORKVAR();
  109. //-------------------------------------------------------------------------
  110. // Initialization.
  111. //-------------------------------------------------------------------------
  112. CEnvMeteorSpawnerShared();
  113. void Init( IMeteorFactory *pFactory, int nRandomSeed, float flTime,
  114. const Vector &vecMinBounds, const Vector &vecMaxBounds,
  115. const Vector &vecTriggerMins, const Vector &vecTriggerMaxs );
  116. //-------------------------------------------------------------------------
  117. // Method to generate meteors.
  118. // Time passed in here is global time, not delta time.
  119. // The function returns the time at which it must be called again.
  120. //-------------------------------------------------------------------------
  121. float MeteorThink( float flTime );
  122. //-------------------------------------------------------------------------
  123. // Add meteor target data, used to determine meteor travel direction.
  124. //-------------------------------------------------------------------------
  125. void AddToTargetList( const Vector &vecPosition, float flRadius );
  126. // Debugging!
  127. int GetRandomInt( int nMin, int nMax );
  128. float GetRandomFloat( float flMin, float flMax );
  129. public:
  130. // Factory.
  131. IMeteorFactory *m_pFactory; // Meteor creation factory.
  132. int m_nMeteorCount; // Number of meteors created - used as IDs
  133. // Initial spawner data.
  134. CNetworkVar( float, m_flStartTime ); // Start time.
  135. CNetworkVar( int, m_nRandomSeed ); // The random number stream seed.
  136. CNetworkVar( int, m_iMeteorType ); // Type of meteor.
  137. float m_flMeteorDamageRadius; // Meteor damage radius.
  138. CNetworkVar( bool, m_bSkybox ); // Is the spawner in the skybox?
  139. CNetworkVar( float, m_flMinSpawnTime ); // Spawn time - Min
  140. CNetworkVar( float, m_flMaxSpawnTime ); // Max
  141. CNetworkVar( int, m_nMinSpawnCount ); // Number of meteors to spawn - Min
  142. CNetworkVar( int, m_nMaxSpawnCount ); // Max
  143. CNetworkVector( m_vecMinBounds ); // Spawner volume (space) - Min
  144. CNetworkVector( m_vecMaxBounds ); // Max
  145. CNetworkVar( float, m_flMinSpeed ); // Meteor speed - Min
  146. CNetworkVar( float, m_flMaxSpeed ); // Max
  147. CNetworkVector( m_vecTriggerMins ); // World Bounds (Trigger) in 3D Skybox - Min
  148. CNetworkVector( m_vecTriggerMaxs ); // Max
  149. Vector m_vecTriggerCenter;
  150. // Generated data.
  151. int m_nRandomCallCount; // Debug! Keep track of number steam calls.
  152. float m_flNextSpawnTime; // Next meteor spawn time (random).
  153. CUniformRandomStream m_NumberStream; // Used to generate random numbers.
  154. // Use "Targets" to determine meteor direction(s).
  155. struct meteortarget_t
  156. {
  157. Vector m_vecPosition;
  158. float m_flRadius;
  159. };
  160. CUtlVector<meteortarget_t> m_aTargets;
  161. };
  162. #endif // ENV_METEOR_SHARED_H