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.

150 lines
5.1 KiB

  1. // chicken.h
  2. // An interactive, shootable chicken
  3. #ifndef CHICKEN_H
  4. #define CHICKEN_H
  5. #include "props.h"
  6. #include "GameEventListener.h"
  7. #include "nav_mesh.h"
  8. #include "cs_nav_path.h"
  9. #include "cs_nav_pathfind.h"
  10. #include "improv_locomotor.h"
  11. class CCSPlayer;
  12. class CChicken : public CDynamicProp, public CGameEventListener, public CImprovLocomotor
  13. {
  14. public:
  15. DECLARE_CLASS( CChicken, CDynamicProp );
  16. DECLARE_SERVERCLASS();
  17. DECLARE_DATADESC();
  18. CChicken();
  19. virtual ~CChicken();
  20. virtual void Precache( void );
  21. virtual void Spawn( void );
  22. virtual void ChickenTouch( CBaseEntity *pOther );
  23. virtual int OnTakeDamage( const CTakeDamageInfo &info );
  24. virtual void Event_Killed( const CTakeDamageInfo &info );
  25. virtual void FireGameEvent( IGameEvent *event );
  26. virtual bool IsAlive( void ) { return true; }
  27. void ChickenThink( void );
  28. bool IsZombie( void ) { return m_flWhenZombified > 0; }
  29. void Zombify( void ) { m_flWhenZombified = gpGlobals->curtime; }
  30. bool IsFollowingSomeone( void );
  31. bool IsFollowing( const CBaseEntity *entity );
  32. bool IsOnGround( void ) const;
  33. void Follow( CCSPlayer *leader ); // begin following "leader"
  34. CCSPlayer *GetLeader( void ) const; // return our leader, or NULL
  35. void FaceTowards( const Vector &target, float deltaT ); // rotate body to face towards "target"
  36. int ObjectCaps( void ) { return ( BaseClass::ObjectCaps( ) | FCAP_IMPULSE_USE ); }
  37. public:
  38. // begin CImprovLocomotor -----------------------------------------------------------------------------------------------------------------
  39. virtual const Vector &GetCentroid( void ) const;
  40. virtual const Vector &GetFeet( void ) const; // return position of "feet" - point below centroid of improv at feet level
  41. virtual const Vector &GetEyes( void ) const;
  42. virtual float GetMoveAngle( void ) const; // return direction of movement
  43. virtual CNavArea *GetLastKnownArea( void ) const;
  44. virtual bool GetSimpleGroundHeightWithFloor( const Vector &pos, float *height, Vector *normal = NULL ); // find "simple" ground height, treating current nav area as part of the floor
  45. virtual void Crouch( void );
  46. virtual void StandUp( void ); // "un-crouch"
  47. virtual bool IsCrouching( void ) const;
  48. virtual void Jump( void ); // initiate a jump
  49. virtual bool IsJumping( void ) const;
  50. bool CanJump( void ) const;
  51. void Jump( float flVelocity );
  52. virtual void Run( void ); // set movement speed to running
  53. virtual void Walk( void ); // set movement speed to walking
  54. virtual bool IsRunning( void ) const;
  55. virtual void StartLadder( const CNavLadder *ladder, NavTraverseType how, const Vector &approachPos, const Vector &departPos ); // invoked when a ladder is encountered while following a path
  56. virtual bool TraverseLadder( const CNavLadder *ladder, NavTraverseType how, const Vector &approachPos, const Vector &departPos, float deltaT ); // traverse given ladder
  57. virtual bool IsUsingLadder( void ) const;
  58. virtual void TrackPath( const Vector &pathGoal, float deltaT ); // move along path by following "pathGoal"
  59. virtual void OnMoveToSuccess( const Vector &goal ); // invoked when an improv reaches its MoveTo goal
  60. virtual void OnMoveToFailure( const Vector &goal, MoveToFailureType reason ); // invoked when an improv fails to reach a MoveTo goal
  61. // end CImprovLocomotor -------------------------------------------------------------------------------------------------------------------
  62. protected:
  63. virtual void ChickenUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  64. void SetChickenStartFollowingPlayer( CCSPlayer *pPlayer );
  65. private:
  66. void Idle();
  67. // void Walk();
  68. void Flee( CBaseEntity *fleeFrom, float duration );
  69. void Fly();
  70. void Land();
  71. void Update( void );
  72. CountdownTimer m_updateTimer;
  73. float AvoidObstacles( void );
  74. Vector m_stuckAnchor;
  75. CountdownTimer m_stuckTimer;
  76. void ResolveCollisions( const Vector &desiredPosition, float deltaT );
  77. bool m_isOnGround;
  78. Activity m_activity;
  79. CountdownTimer m_activityTimer;
  80. float m_turnRate;
  81. CHandle< CBaseEntity > m_fleeFrom;
  82. CountdownTimer m_moveRateThrottleTimer;
  83. CountdownTimer m_startleTimer;
  84. CountdownTimer m_vocalizeTimer;
  85. float m_flWhenZombified;
  86. CNetworkVar( bool, m_jumpedThisFrame );
  87. CNetworkVar( EHANDLE, m_leader ); // the player we are following
  88. void UpdateFollowing( float deltaT ); // do following behavior
  89. int m_lastLeaderID;
  90. CountdownTimer m_reuseTimer; // to throttle how often hostage can be used
  91. bool m_hasBeenUsed;
  92. CountdownTimer m_jumpTimer; // if zero, we can jump
  93. float m_flLastJumpTime;
  94. bool m_bInJump;
  95. bool m_isWaitingForLeader; // true if we are waiting for our rescuer to move
  96. CCSNavPath m_path; // current path to follow
  97. CountdownTimer m_repathTimer; // throttle pathfinder
  98. CountdownTimer m_inhibitDoorTimer;
  99. CNavPathFollower m_pathFollower; // path tracking mechanism
  100. CountdownTimer m_inhibitObstacleAvoidanceTimer; // when active, turn off path following feelers
  101. CNavArea *m_lastKnownArea; // last area we were in
  102. Vector m_vecPathGoal;
  103. float m_flActiveFollowStartTime; // when the current follow started
  104. };
  105. #endif // CHICKEN_H