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.

196 lines
4.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef AI_GOALENTITY_H
  7. #define AI_GOALENTITY_H
  8. #include "ai_basenpc.h"
  9. #include "utlvector.h"
  10. #if defined( _WIN32 )
  11. #pragma once
  12. #endif
  13. //-----------------------------------------------------------------------------
  14. //
  15. // CAI_GoalEntity
  16. //
  17. // Purpose: Serves as the base class for all entities the designer may place
  18. // that establish an NPC goal. Provides standard input, output &
  19. // fields common to all goals.
  20. //
  21. class CAI_GoalEntity : public CBaseEntity,
  22. public IEntityListener
  23. {
  24. DECLARE_CLASS( CAI_GoalEntity, CBaseEntity );
  25. public:
  26. CAI_GoalEntity()
  27. : m_iszActor(NULL_STRING),
  28. m_iszGoal(NULL_STRING),
  29. m_fStartActive(false),
  30. m_SearchType(ST_ENTNAME),
  31. m_iszConceptModifiers(NULL_STRING),
  32. m_hGoalEntity(INVALID_EHANDLE),
  33. m_flags( 0 )
  34. {
  35. }
  36. virtual int ObjectCaps() { return ((BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION) | FCAP_NOTIFY_ON_TRANSITION); }
  37. virtual void Spawn();
  38. virtual void OnRestore();
  39. virtual int DrawDebugTextOverlays();
  40. virtual void OnActivate() {}
  41. virtual void OnDeactivate() {}
  42. virtual void InputActivate( inputdata_t &inputdata );
  43. virtual void InputUpdateActors( inputdata_t &inputdata );
  44. virtual void InputDeactivate( inputdata_t &inputdata );
  45. // Goal entities can become Dormant if they're left behind on previous maps.
  46. // Transitioning back to the map with cause a dormant goal entity to reactivate itself.
  47. void EnterDormant( void );
  48. void ExitDormant( void );
  49. bool IsActive();
  50. int NumActors();
  51. CAI_BaseNPC * GetActor( int iActor = 0 );
  52. void SetGoalEntity( CBaseEntity *pGoalEntity );
  53. CBaseEntity * GetGoalEntity();
  54. const char * GetGoalEntityName();
  55. const char * GetConceptModifiers();
  56. protected:
  57. virtual void UpdateOnRemove();
  58. virtual void OnEntityCreated( CBaseEntity *pEntity );
  59. virtual void OnEntityDeleted( CBaseEntity *pEntity );
  60. virtual void EnableGoal( CAI_BaseNPC *pAI ) {}
  61. virtual void DisableGoal( CAI_BaseNPC *pAI ) {}
  62. virtual void ResolveNames();
  63. void UpdateActors();
  64. const CUtlVector<AIHANDLE> &AccessActors()
  65. {
  66. return m_actors;
  67. }
  68. protected:
  69. enum Flags_t
  70. {
  71. ACTIVE = 0x01,
  72. RESOLVED_NAME = 0x02,
  73. DORMANT = 0x04,
  74. };
  75. enum SearchType_t
  76. {
  77. ST_ENTNAME,
  78. ST_CLASSNAME,
  79. };
  80. void DelayedRefresh();
  81. void PruneActors();
  82. // From Worldcraft
  83. string_t m_iszActor;
  84. string_t m_iszGoal;
  85. bool m_fStartActive;
  86. SearchType_t m_SearchType;
  87. string_t m_iszConceptModifiers;
  88. CUtlVector<AIHANDLE> m_actors;
  89. EHANDLE m_hGoalEntity;
  90. unsigned m_flags;
  91. DECLARE_DATADESC();
  92. };
  93. //-------------------------------------
  94. // @TODO (toml 03-18-03): Efficiency wart -- make this an explicit duty of the client?
  95. inline void CAI_GoalEntity::UpdateActors()
  96. {
  97. if ( !( m_flags & ACTIVE ) || !( m_flags & RESOLVED_NAME ) )
  98. {
  99. ResolveNames();
  100. m_flags |= RESOLVED_NAME;
  101. }
  102. else
  103. PruneActors();
  104. }
  105. //-------------------------------------
  106. inline bool CAI_GoalEntity::IsActive()
  107. {
  108. if ( m_flags & ACTIVE )
  109. {
  110. UpdateActors();
  111. return ( m_actors.Count() != 0 );
  112. }
  113. return false;
  114. }
  115. //-------------------------------------
  116. inline int CAI_GoalEntity::NumActors()
  117. {
  118. UpdateActors();
  119. return m_actors.Count();
  120. }
  121. //-------------------------------------
  122. inline CAI_BaseNPC *CAI_GoalEntity::GetActor( int iActor )
  123. {
  124. UpdateActors();
  125. if ( m_actors.Count() > iActor )
  126. return m_actors[iActor];
  127. return NULL;
  128. }
  129. //-------------------------------------
  130. inline void CAI_GoalEntity::SetGoalEntity( CBaseEntity *pGoalEntity )
  131. {
  132. m_iszGoal = pGoalEntity->GetEntityName();
  133. m_hGoalEntity = pGoalEntity;
  134. }
  135. //-------------------------------------
  136. inline CBaseEntity *CAI_GoalEntity::GetGoalEntity()
  137. {
  138. UpdateActors();
  139. return m_hGoalEntity;
  140. }
  141. //-------------------------------------
  142. inline const char *CAI_GoalEntity::GetGoalEntityName()
  143. {
  144. return STRING( m_iszGoal );
  145. }
  146. //-------------------------------------
  147. inline const char *CAI_GoalEntity::GetConceptModifiers()
  148. {
  149. return STRING( m_iszConceptModifiers );
  150. }
  151. //-----------------------------------------------------------------------------
  152. #endif // AI_GOALENTITY_H