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.

140 lines
4.3 KiB

  1. //========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // fish.h
  9. // Simple fish behavior
  10. // Author: Michael S. Booth, April 2005
  11. #ifndef _FISH_H_
  12. #define _FISH_H_
  13. #include "baseanimating.h"
  14. #include "GameEventListener.h"
  15. class CFishPool;
  16. //----------------------------------------------------------------------------------------------
  17. /**
  18. * Simple ambient fish
  19. */
  20. class CFish : public CBaseAnimating
  21. {
  22. public:
  23. DECLARE_CLASS( CFish, CBaseAnimating );
  24. DECLARE_SERVERCLASS();
  25. DECLARE_DATADESC();
  26. CFish( void );
  27. virtual ~CFish();
  28. void Initialize( CFishPool *pool, unsigned int id );
  29. virtual void Spawn( void );
  30. virtual void Event_Killed( const CTakeDamageInfo &info );
  31. virtual void Touch( CBaseEntity *other ); ///< in contact with "other"
  32. void Update( float deltaT ); ///< invoked each server tick
  33. void FlockTo( CFish *other, float amount ); ///< influence my motion to flock with other nearby fish
  34. float Avoid( void );
  35. void Panic( void ); ///< panic for awhile
  36. void ResetVisible( void ); ///< zero the visible vector
  37. void AddVisible( CFish *fish ); ///< add this fish to our visible vector
  38. private:
  39. friend void SendProxy_FishOriginX( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID );
  40. friend void SendProxy_FishOriginY( const SendProp *pProp, const void *pStruct, const void *pData, DVariant *pOut, int iElement, int objectID );
  41. CHandle<CFishPool> m_pool; ///< the pool we are in
  42. unsigned int m_id; ///< our unique ID
  43. CNetworkVar( float, m_x ); ///< have to send position coordinates separately since Z is unused
  44. CNetworkVar( float, m_y ); ///< have to send position coordinates separately since Z is unused
  45. CNetworkVar( float, m_z ); ///< only sent once since fish always swim at the same depth
  46. CNetworkVar( float, m_angle ); ///< only yaw changes
  47. float m_angleChange;
  48. Vector m_forward;
  49. Vector m_perp;
  50. CNetworkVector( m_poolOrigin ); ///< used to efficiently network our relative position
  51. CNetworkVar( float, m_waterLevel );
  52. float m_speed;
  53. float m_desiredSpeed;
  54. float m_calmSpeed; ///< speed the fish moves when calm
  55. float m_panicSpeed; ///< speed the fish moves when panicked
  56. float m_avoidRange; ///< range to avoid obstacles
  57. CountdownTimer m_turnTimer; ///< every so often our turn preference changes
  58. bool m_turnClockwise; ///< if true this fish prefers to turn clockwise, else CCW
  59. CountdownTimer m_goTimer; ///< start the fish moving when timer elapses
  60. CountdownTimer m_moveTimer; ///< dont decay speed while we are moving
  61. CountdownTimer m_panicTimer; ///< if active, fish is panicked
  62. CountdownTimer m_disperseTimer; ///< initial non-flocking time
  63. CUtlVector< CFish * > m_visible; ///< vector of fish that we can see
  64. };
  65. //----------------------------------------------------------------------------------------------
  66. /**
  67. * This class defines a volume of water where a number of CFish swim
  68. */
  69. class CFishPool : public CBaseEntity, public CGameEventListener
  70. {
  71. public:
  72. DECLARE_CLASS( CFishPool, CBaseEntity );
  73. DECLARE_DATADESC();
  74. CFishPool( void );
  75. virtual void Spawn();
  76. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  77. virtual void FireGameEvent( IGameEvent *event );
  78. void Update( void ); ///< invoked each server tick
  79. float GetWaterLevel( void ) const; ///< return Z coordinate of water in world coords
  80. float GetMaxRange( void ) const; ///< return how far a fish is allowed to wander
  81. private:
  82. int m_fishCount; ///< number of fish in the pool
  83. float m_maxRange; ///< how far a fish is allowed to wander
  84. float m_swimDepth; ///< the depth the fish swim below the water surface
  85. float m_waterLevel; ///< Z of water surface
  86. bool m_isDormant;
  87. CUtlVector< CHandle<CFish> > m_fishes; ///< vector of all fish in this pool
  88. CountdownTimer m_visTimer; ///< for throttling line of sight checks between all fish
  89. };
  90. inline float CFishPool::GetMaxRange( void ) const
  91. {
  92. return m_maxRange;
  93. }
  94. inline float CFishPool::GetWaterLevel( void ) const
  95. {
  96. return m_waterLevel;
  97. }
  98. #endif // _FISH_H_