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.

256 lines
5.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef NPC_CROW_H
  7. #define NPC_CROW_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #define BIRDTYPE_CROW 1
  12. #define BIRDTYPE_PIGEON 2
  13. #define BIRDTYPE_SEAGULL 3
  14. //
  15. // Spawnflags.
  16. //
  17. #define SF_CROW_FLYING 16
  18. #define CROW_TAKEOFF_SPEED 170
  19. #define CROW_AIRSPEED 220 // FIXME: should be about 440, but I need to add acceleration
  20. //
  21. // Custom schedules.
  22. //
  23. enum
  24. {
  25. SCHED_CROW_IDLE_WALK = LAST_SHARED_SCHEDULE,
  26. SCHED_CROW_IDLE_FLY,
  27. //
  28. // Various levels of wanting to get away from something, selected
  29. // by current value of m_nMorale.
  30. //
  31. SCHED_CROW_WALK_AWAY,
  32. SCHED_CROW_RUN_AWAY,
  33. SCHED_CROW_HOP_AWAY,
  34. SCHED_CROW_FLY_AWAY,
  35. SCHED_CROW_FLY,
  36. SCHED_CROW_FLY_FAIL,
  37. SCHED_CROW_BARNACLED,
  38. };
  39. //
  40. // Custom tasks.
  41. //
  42. enum
  43. {
  44. TASK_CROW_FIND_FLYTO_NODE = LAST_SHARED_TASK,
  45. //TASK_CROW_PREPARE_TO_FLY,
  46. TASK_CROW_TAKEOFF,
  47. //TASK_CROW_LAND,
  48. TASK_CROW_FLY,
  49. TASK_CROW_FLY_TO_HINT,
  50. TASK_CROW_PICK_RANDOM_GOAL,
  51. TASK_CROW_PICK_EVADE_GOAL,
  52. TASK_CROW_HOP,
  53. TASK_CROW_FALL_TO_GROUND,
  54. TASK_CROW_PREPARE_TO_FLY_RANDOM,
  55. TASK_CROW_WAIT_FOR_BARNACLE_KILL,
  56. };
  57. //
  58. // Custom conditions.
  59. //
  60. enum
  61. {
  62. COND_CROW_ENEMY_TOO_CLOSE = LAST_SHARED_CONDITION,
  63. COND_CROW_ENEMY_WAY_TOO_CLOSE,
  64. COND_CROW_FORCED_FLY,
  65. COND_CROW_BARNACLED,
  66. };
  67. enum FlyState_t
  68. {
  69. FlyState_Walking = 0,
  70. FlyState_Flying,
  71. FlyState_Falling,
  72. FlyState_Landing,
  73. };
  74. //-----------------------------------------------------------------------------
  75. // The crow class.
  76. //-----------------------------------------------------------------------------
  77. class CNPC_Crow : public CAI_BaseNPC
  78. {
  79. DECLARE_CLASS( CNPC_Crow, CAI_BaseNPC );
  80. public:
  81. //
  82. // CBaseEntity:
  83. //
  84. virtual void Spawn( void );
  85. virtual void Precache( void );
  86. virtual Vector BodyTarget( const Vector &posSrc, bool bNoisy = true );
  87. virtual int DrawDebugTextOverlays( void );
  88. //
  89. // CBaseCombatCharacter:
  90. //
  91. virtual int OnTakeDamage_Alive( const CTakeDamageInfo &info );
  92. virtual bool CorpseGib( const CTakeDamageInfo &info );
  93. bool BecomeRagdollOnClient( const Vector &force );
  94. //
  95. // CAI_BaseNPC:
  96. //
  97. virtual float MaxYawSpeed( void ) { return 120.0f; }
  98. virtual Class_T Classify( void );
  99. virtual void GatherEnemyConditions( CBaseEntity *pEnemy );
  100. virtual void HandleAnimEvent( animevent_t *pEvent );
  101. virtual int GetSoundInterests( void );
  102. virtual int SelectSchedule( void );
  103. virtual void StartTask( const Task_t *pTask );
  104. virtual void RunTask( const Task_t *pTask );
  105. virtual bool HandleInteraction( int interactionType, void *data, CBaseCombatCharacter *sourceEnt );
  106. virtual void OnChangeActivity( Activity eNewActivity );
  107. virtual bool OverrideMove( float flInterval );
  108. virtual bool FValidateHintType( CAI_Hint *pHint );
  109. virtual Activity GetHintActivity( short sHintType, Activity HintsActivity );
  110. virtual void PainSound( const CTakeDamageInfo &info );
  111. virtual void DeathSound( const CTakeDamageInfo &info );
  112. virtual void IdleSound( void );
  113. virtual void AlertSound( void );
  114. virtual void StopLoopingSounds( void );
  115. virtual void UpdateEfficiency( bool bInPVS );
  116. virtual bool QueryHearSound( CSound *pSound );
  117. void InputFlyAway( inputdata_t &inputdata );
  118. void TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator );
  119. void StartTargetHandling( CBaseEntity *pTargetEnt );
  120. DEFINE_CUSTOM_AI;
  121. DECLARE_DATADESC();
  122. int m_iBirdType;
  123. bool m_bOnJeep;
  124. protected:
  125. void SetFlyingState( FlyState_t eState );
  126. inline bool IsFlying( void ) const { return GetNavType() == NAV_FLY; }
  127. void Takeoff( const Vector &vGoal );
  128. void FlapSound( void );
  129. void MoveCrowFly( float flInterval );
  130. bool Probe( const Vector &vecMoveDir, float flSpeed, Vector &vecDeflect );
  131. bool IsDeaf() { return m_bIsDeaf; }
  132. protected:
  133. float m_flGroundIdleMoveTime;
  134. float m_flEnemyDist; // Distance to GetEnemy(), cached in GatherEnemyConditions.
  135. int m_nMorale; // Used to determine which avoidance schedule to pick. Degrades as I pick avoidance schedules.
  136. bool m_bReachedMoveGoal;
  137. float m_flHopStartZ; // Our Z coordinate when we started a hop. Used to check for accidentally hopping off things.
  138. bool m_bPlayedLoopingSound;
  139. private:
  140. Activity NPC_TranslateActivity( Activity eNewActivity );
  141. float m_flSoarTime;
  142. bool m_bSoar;
  143. Vector m_vLastStoredOrigin;
  144. float m_flLastStuckCheck;
  145. float m_flDangerSoundTime;
  146. Vector m_vDesiredTarget;
  147. Vector m_vCurrentTarget;
  148. bool m_bIsDeaf;
  149. };
  150. //-----------------------------------------------------------------------------
  151. // Purpose: Seagull. Crow with a different model.
  152. //-----------------------------------------------------------------------------
  153. class CNPC_Seagull : public CNPC_Crow
  154. {
  155. DECLARE_CLASS( CNPC_Seagull, CNPC_Crow );
  156. public:
  157. void Spawn( void )
  158. {
  159. SetModelName( AllocPooledString("models/seagull.mdl") );
  160. BaseClass::Spawn();
  161. m_iBirdType = BIRDTYPE_SEAGULL;
  162. }
  163. void PainSound( const CTakeDamageInfo &info )
  164. {
  165. EmitSound( "NPC_Seagull.Pain" );
  166. }
  167. void DeathSound( const CTakeDamageInfo &info )
  168. {
  169. EmitSound( "NPC_Seagull.Pain" );
  170. }
  171. void IdleSound( void )
  172. {
  173. EmitSound( "NPC_Seagull.Idle" );
  174. }
  175. };
  176. //-----------------------------------------------------------------------------
  177. // Purpose: Pigeon. Crow with a different model.
  178. //-----------------------------------------------------------------------------
  179. class CNPC_Pigeon : public CNPC_Crow
  180. {
  181. DECLARE_CLASS( CNPC_Pigeon, CNPC_Crow );
  182. public:
  183. void Spawn( void )
  184. {
  185. SetModelName( AllocPooledString("models/pigeon.mdl") );
  186. BaseClass::Spawn();
  187. m_iBirdType = BIRDTYPE_PIGEON;
  188. }
  189. void IdleSound( void )
  190. {
  191. EmitSound( "NPC_Pigeon.Idle" );
  192. }
  193. };
  194. #endif // NPC_CROW_H