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.

180 lines
6.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef ENV_HEADCRABCANISTER_SHARED_H
  8. #define ENV_HEADCRABCANISTER_SHARED_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "vstdlib/random.h"
  13. #include "mathlib/vector.h"
  14. #include "utlvector.h"
  15. #include "networkvar.h"
  16. //=============================================================================
  17. //
  18. // Shared HeadcrabCanister Class
  19. //
  20. class CEnvHeadcrabCanisterShared
  21. {
  22. DECLARE_CLASS_NOBASE( CEnvHeadcrabCanisterShared );
  23. DECLARE_EMBEDDED_NETWORKVAR();
  24. DECLARE_SIMPLE_DATADESC();
  25. public:
  26. CEnvHeadcrabCanisterShared();
  27. // Initialization.
  28. void InitInWorld( float flLaunchTime, const Vector &vecStartPosition, const QAngle &vecStartAngles, const Vector &vecDirection, const Vector &vecImpactPosition, bool bLaunchedFromWithinWorld = false );
  29. void InitInSkybox( float flLaunchTime, const Vector &vecStartPosition, const QAngle &vecStartAngles, const Vector &vecDirection, const Vector &vecImpactPosition, const Vector &vecSkyboxOrigin, float flSkyboxScale );
  30. // Returns the position of the object at a given time.
  31. void GetPositionAtTime( float flTime, Vector &vecPosition, QAngle &vecAngles );
  32. // Returns whether or not the object is the the skybox
  33. bool IsInSkybox( );
  34. // Returns the time at which it enters the world
  35. float GetEnterWorldTime() const;
  36. // Convert from skybox to world
  37. void ConvertFromSkyboxToWorld();
  38. // Did we impact?
  39. bool DidImpact( float flTime ) const;
  40. public:
  41. // The objects initial parametric conditions.
  42. CNetworkVector( m_vecStartPosition );
  43. CNetworkVector( m_vecEnterWorldPosition );
  44. CNetworkVector( m_vecDirection );
  45. CNetworkQAngle( m_vecStartAngles );
  46. CNetworkVar( float, m_flFlightTime );
  47. CNetworkVar( float, m_flFlightSpeed );
  48. CNetworkVar( float, m_flLaunchTime );
  49. CNetworkVar( float, m_flInitialZSpeed );
  50. CNetworkVar( float, m_flZAcceleration );
  51. CNetworkVar( float, m_flHorizSpeed );
  52. CNetworkVar( bool, m_bLaunchedFromWithinWorld );
  53. CNetworkVector( m_vecParabolaDirection );
  54. // The time at which the canister enters the skybox
  55. CNetworkVar( float, m_flWorldEnterTime );
  56. // Skybox data
  57. CNetworkVector( m_vecSkyboxOrigin );
  58. CNetworkVar( float, m_flSkyboxScale );
  59. CNetworkVar( bool, m_bInSkybox );
  60. private:
  61. float m_flLaunchHeight;
  62. // Calculate the enter time. (called from Init)
  63. void CalcEnterTime( const Vector &vecTriggerMins, const Vector &vecTriggerMaxs );
  64. friend class CEnvHeadcrabCanister;
  65. friend class C_EnvHeadcrabCanister;
  66. };
  67. /*
  68. //=============================================================================
  69. //
  70. // HeadcrabCanister Factory Interface
  71. //
  72. abstract_class IHeadcrabCanisterFactory
  73. {
  74. public:
  75. virtual void CreateHeadcrabCanister( int nID, int iType,
  76. const Vector &vecPosition, const Vector &vecDirection,
  77. float flSpeed, float flStartTime, float flDamageRadius,
  78. const Vector &vecTriggerMins, const Vector &vecTriggerMaxs ) = 0;
  79. };
  80. //=============================================================================
  81. //
  82. // Shared HeadcrabCanister Spawner Class
  83. //
  84. class CEnvHeadcrabCanisterSpawnerShared
  85. {
  86. public:
  87. DECLARE_CLASS_NOBASE( CEnvHeadcrabCanisterSpawnerShared );
  88. DECLARE_EMBEDDED_NETWORKVAR();
  89. //-------------------------------------------------------------------------
  90. // Initialization.
  91. //-------------------------------------------------------------------------
  92. CEnvHeadcrabCanisterSpawnerShared();
  93. void Init( IHeadcrabCanisterFactory *pFactory, int nRandomSeed, float flTime,
  94. const Vector &vecMinBounds, const Vector &vecMaxBounds,
  95. const Vector &vecTriggerMins, const Vector &vecTriggerMaxs );
  96. //-------------------------------------------------------------------------
  97. // Method to generate HeadcrabCanisters.
  98. // Time passed in here is global time, not delta time.
  99. // The function returns the time at which it must be called again.
  100. //-------------------------------------------------------------------------
  101. float HeadcrabCanisterThink( float flTime );
  102. //-------------------------------------------------------------------------
  103. // Add HeadcrabCanister target data, used to determine HeadcrabCanister travel direction.
  104. //-------------------------------------------------------------------------
  105. void AddToTargetList( const Vector &vecPosition, float flRadius );
  106. // Debugging!
  107. int GetRandomInt( int nMin, int nMax );
  108. float GetRandomFloat( float flMin, float flMax );
  109. public:
  110. // Factory.
  111. IHeadcrabCanisterFactory *m_pFactory; // HeadcrabCanister creation factory.
  112. int m_nHeadcrabCanisterCount; // Number of HeadcrabCanisters created - used as IDs
  113. // Initial spawner data.
  114. CNetworkVar( float, m_flStartTime ); // Start time.
  115. CNetworkVar( int, m_nRandomSeed ); // The random number stream seed.
  116. CNetworkVar( int, m_iHeadcrabCanisterType ); // Type of HeadcrabCanister.
  117. float m_flHeadcrabCanisterDamageRadius; // HeadcrabCanister damage radius.
  118. CNetworkVar( bool, m_bSkybox ); // Is the spawner in the skybox?
  119. CNetworkVar( float, m_flMinSpawnTime ); // Spawn time - Min
  120. CNetworkVar( float, m_flMaxSpawnTime ); // Max
  121. CNetworkVar( int, m_nMinSpawnCount ); // Number of HeadcrabCanisters to spawn - Min
  122. CNetworkVar( int, m_nMaxSpawnCount ); // Max
  123. CNetworkVector( m_vecMinBounds ); // Spawner volume (space) - Min
  124. CNetworkVector( m_vecMaxBounds ); // Max
  125. CNetworkVar( float, m_flMinSpeed ); // HeadcrabCanister speed - Min
  126. CNetworkVar( float, m_flMaxSpeed ); // Max
  127. CNetworkVector( m_vecTriggerMins ); // World Bounds (Trigger) in 3D Skybox - Min
  128. CNetworkVector( m_vecTriggerMaxs ); // Max
  129. Vector m_vecTriggerCenter;
  130. // Generated data.
  131. int m_nRandomCallCount; // Debug! Keep track of number steam calls.
  132. float m_flNextSpawnTime; // Next HeadcrabCanister spawn time (random).
  133. CUniformRandomStream m_NumberStream; // Used to generate random numbers.
  134. // Use "Targets" to determine HeadcrabCanister direction(s).
  135. struct HeadcrabCanistertarget_t
  136. {
  137. Vector m_vecPosition;
  138. float m_flRadius;
  139. };
  140. CUtlVector<HeadcrabCanistertarget_t> m_aTargets;
  141. };
  142. */
  143. #endif // ENV_HEADCRAB_CANISTER_SHARED_H