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.

172 lines
4.6 KiB

  1. //========= Copyright � 1996-2005, 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. int GetHullTraceMask() const;
  41. protected:
  42. //
  43. // Common services provided by CAI_BaseNPC, Convenience methods to simplify derived code
  44. //
  45. edict_t * GetEdict();
  46. const Vector & GetLocalOrigin() const;
  47. void SetLocalOrigin( const Vector &origin );
  48. const Vector & GetAbsOrigin() const;
  49. const QAngle& GetAbsAngles() const;
  50. void SetLocalAngles( const QAngle& angles );
  51. const QAngle & GetLocalAngles( void ) const;
  52. const Vector& WorldAlignMins() const;
  53. const Vector& WorldAlignMaxs() const;
  54. Vector WorldSpaceCenter() const;
  55. int GetCollisionGroup() const;
  56. void SetSolid( SolidType_t val );
  57. SolidType_t GetSolid() const;
  58. float GetGravity() const;
  59. void SetGravity( float );
  60. CBaseEntity* GetEnemy();
  61. const Vector & GetEnemyLKP() const;
  62. void TranslateNavGoal( CBaseEntity *pEnemy, Vector &chasePosition);
  63. CBaseEntity* GetTarget();
  64. void SetTarget( CBaseEntity *pTarget );
  65. const Task_t* GetCurTask( void );
  66. virtual void TaskFail( AI_TaskFailureCode_t );
  67. void TaskFail( const char *pszGeneralFailText );
  68. virtual void TaskComplete( bool fIgnoreSetFailedCondition = false );
  69. int TaskIsRunning();
  70. inline int TaskIsComplete();
  71. Activity GetActivity();
  72. void SetActivity( Activity NewActivity );
  73. float GetIdealSpeed() const;
  74. float GetIdealAccel() const;
  75. int GetSequence();
  76. int GetEntFlags() const;
  77. void AddEntFlag( int flags );
  78. void RemoveEntFlag( int flagsToRemove );
  79. void ToggleEntFlag( int flagToToggle );
  80. void SetGroundEntity( CBaseEntity *ground );
  81. CBaseEntity* GetGoalEnt();
  82. void SetGoalEnt( CBaseEntity *pGoalEnt );
  83. void Remember( int iMemory );
  84. void Forget( int iMemory );
  85. bool HasMemory( int iMemory );
  86. CAI_Enemies * GetEnemies();
  87. const char * GetEntClassname();
  88. int CapabilitiesGet();
  89. float GetLastThink( const char *szContext = NULL );
  90. public:
  91. #if defined(new)
  92. #error
  93. #endif
  94. void *operator new( size_t nBytes )
  95. {
  96. MEM_ALLOC_CREDIT();
  97. void *pResult = MemAlloc_Alloc( nBytes );
  98. memset( pResult, 0, nBytes );
  99. return pResult;
  100. };
  101. void *operator new( size_t nBytes, int nBlockUse, const char *pFileName, int nLine )
  102. {
  103. MEM_ALLOC_CREDIT();
  104. void *pResult = MemAlloc_Alloc( nBytes, pFileName, nLine );
  105. memset( pResult, 0, nBytes );
  106. return pResult;
  107. }
  108. private:
  109. CAI_BaseNPC *m_pOuter;
  110. };
  111. //-----------------------------------------------------------------------------
  112. template <class NPC_CLASS, class BASE_COMPONENT = CAI_Component>
  113. class CAI_ComponentWithOuter : public BASE_COMPONENT
  114. {
  115. protected:
  116. CAI_ComponentWithOuter(NPC_CLASS *pOuter = NULL)
  117. : BASE_COMPONENT(pOuter)
  118. {
  119. }
  120. public:
  121. // Hides base version
  122. void SetOuter( NPC_CLASS *pOuter ) { BASE_COMPONENT::SetOuter((CAI_BaseNPC *)pOuter); }
  123. NPC_CLASS * GetOuter() { return (NPC_CLASS *)(BASE_COMPONENT::GetOuter()); }
  124. const NPC_CLASS * GetOuter() const { return (NPC_CLASS *)(BASE_COMPONENT::GetOuter()); }
  125. };
  126. //-----------------------------------------------------------------------------
  127. #define DEFINE_AI_COMPONENT_OUTER( NPC_CLASS ) \
  128. void SetOuter( NPC_CLASS *pOuter ) { CAI_Component::SetOuter((CAI_BaseNPC *)pOuter); } \
  129. NPC_CLASS * GetOuter() { return (NPC_CLASS *)(CAI_Component::GetOuter()); } \
  130. const NPC_CLASS * GetOuter() const { return (NPC_CLASS *)(CAI_Component::GetOuter()); }
  131. //-----------------------------------------------------------------------------
  132. #endif // AI_COMPONENT_H