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.

171 lines
4.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef AI_COMPONENT_H
  8. #define AI_COMPONENT_H
  9. #if defined( _WIN32 )
  10. #pragma once
  11. #endif
  12. class CAI_BaseNPC;
  13. class CAI_Enemies;
  14. typedef int AI_TaskFailureCode_t;
  15. struct Task_t;
  16. //-----------------------------------------------------------------------------
  17. // CAI_Component
  18. //
  19. // Purpose: Shared functionality of all classes that assume some of the
  20. // responsibilities of an owner AI.
  21. //-----------------------------------------------------------------------------
  22. class CAI_Component
  23. {
  24. DECLARE_CLASS_NOBASE( CAI_Component );
  25. protected:
  26. CAI_Component( CAI_BaseNPC *pOuter = NULL )
  27. : m_pOuter(pOuter)
  28. {
  29. }
  30. virtual ~CAI_Component() {}
  31. public:
  32. virtual void SetOuter( CAI_BaseNPC *pOuter ) { m_pOuter = pOuter; }
  33. CAI_BaseNPC * GetOuter() { return m_pOuter; }
  34. const CAI_BaseNPC * GetOuter() const { return m_pOuter; }
  35. Hull_t GetHullType() const;
  36. float GetHullWidth() const;
  37. float GetHullHeight() const;
  38. const Vector & GetHullMins() const;
  39. const Vector & GetHullMaxs() const;
  40. protected:
  41. //
  42. // Common services provided by CAI_BaseNPC, Convenience methods to simplify derived code
  43. //
  44. edict_t * GetEdict();
  45. const Vector & GetLocalOrigin() const;
  46. void SetLocalOrigin( const Vector &origin );
  47. const Vector & GetAbsOrigin() const;
  48. const QAngle& GetAbsAngles() const;
  49. void SetLocalAngles( const QAngle& angles );
  50. const QAngle & GetLocalAngles( void ) const;
  51. const Vector& WorldAlignMins() const;
  52. const Vector& WorldAlignMaxs() const;
  53. Vector WorldSpaceCenter() const;
  54. int GetCollisionGroup() const;
  55. void SetSolid( SolidType_t val );
  56. SolidType_t GetSolid() const;
  57. float GetGravity() const;
  58. void SetGravity( float );
  59. CBaseEntity* GetEnemy();
  60. const Vector & GetEnemyLKP() const;
  61. void TranslateNavGoal( CBaseEntity *pEnemy, Vector &chasePosition);
  62. CBaseEntity* GetTarget();
  63. void SetTarget( CBaseEntity *pTarget );
  64. const Task_t* GetCurTask( void );
  65. virtual void TaskFail( AI_TaskFailureCode_t );
  66. void TaskFail( const char *pszGeneralFailText );
  67. virtual void TaskComplete( bool fIgnoreSetFailedCondition = false );
  68. int TaskIsRunning();
  69. inline int TaskIsComplete();
  70. Activity GetActivity();
  71. void SetActivity( Activity NewActivity );
  72. float GetIdealSpeed() const;
  73. float GetIdealAccel() const;
  74. int GetSequence();
  75. int GetEntFlags() const;
  76. void AddEntFlag( int flags );
  77. void RemoveEntFlag( int flagsToRemove );
  78. void ToggleEntFlag( int flagToToggle );
  79. void SetGroundEntity( CBaseEntity *ground );
  80. CBaseEntity* GetGoalEnt();
  81. void SetGoalEnt( CBaseEntity *pGoalEnt );
  82. void Remember( int iMemory );
  83. void Forget( int iMemory );
  84. bool HasMemory( int iMemory );
  85. CAI_Enemies * GetEnemies();
  86. const char * GetEntClassname();
  87. int CapabilitiesGet();
  88. float GetLastThink( const char *szContext = NULL );
  89. public:
  90. #if defined(new)
  91. #error
  92. #endif
  93. void *operator new( size_t nBytes )
  94. {
  95. MEM_ALLOC_CREDIT();
  96. void *pResult = MemAlloc_Alloc( nBytes );
  97. memset( pResult, 0, nBytes );
  98. return pResult;
  99. };
  100. void *operator new( size_t nBytes, int nBlockUse, const char *pFileName, int nLine )
  101. {
  102. MEM_ALLOC_CREDIT();
  103. void *pResult = MemAlloc_Alloc( nBytes, pFileName, nLine );
  104. memset( pResult, 0, nBytes );
  105. return pResult;
  106. }
  107. private:
  108. CAI_BaseNPC *m_pOuter;
  109. };
  110. //-----------------------------------------------------------------------------
  111. template <class NPC_CLASS, class BASE_COMPONENT = CAI_Component>
  112. class CAI_ComponentWithOuter : public BASE_COMPONENT
  113. {
  114. protected:
  115. CAI_ComponentWithOuter(NPC_CLASS *pOuter = NULL)
  116. : BASE_COMPONENT(pOuter)
  117. {
  118. }
  119. public:
  120. // Hides base version
  121. void SetOuter( NPC_CLASS *pOuter ) { BASE_COMPONENT::SetOuter((CAI_BaseNPC *)pOuter); }
  122. NPC_CLASS * GetOuter() { return (NPC_CLASS *)(BASE_COMPONENT::GetOuter()); }
  123. const NPC_CLASS * GetOuter() const { return (NPC_CLASS *)(BASE_COMPONENT::GetOuter()); }
  124. };
  125. //-----------------------------------------------------------------------------
  126. #define DEFINE_AI_COMPONENT_OUTER( NPC_CLASS ) \
  127. void SetOuter( NPC_CLASS *pOuter ) { CAI_Component::SetOuter((CAI_BaseNPC *)pOuter); } \
  128. NPC_CLASS * GetOuter() { return (NPC_CLASS *)(CAI_Component::GetOuter()); } \
  129. const NPC_CLASS * GetOuter() const { return (NPC_CLASS *)(CAI_Component::GetOuter()); }
  130. //-----------------------------------------------------------------------------
  131. #endif // AI_COMPONENT_H