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.

194 lines
4.1 KiB

  1. //========= Copyright 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(NULL),
  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 InputActivate( inputdata_t &inputdata );
  41. virtual void InputUpdateActors( inputdata_t &inputdata );
  42. virtual void InputDeactivate( inputdata_t &inputdata );
  43. // Goal entities can become Dormant if they're left behind on previous maps.
  44. // Transitioning back to the map with cause a dormant goal entity to reactivate itself.
  45. void EnterDormant( void );
  46. void ExitDormant( void );
  47. bool IsActive();
  48. int NumActors();
  49. CAI_BaseNPC * GetActor( int iActor = 0 );
  50. void SetGoalEntity( CBaseEntity *pGoalEntity );
  51. CBaseEntity * GetGoalEntity();
  52. const char * GetGoalEntityName();
  53. const char * GetConceptModifiers();
  54. protected:
  55. virtual void UpdateOnRemove();
  56. virtual void OnEntityCreated( CBaseEntity *pEntity );
  57. virtual void OnEntityDeleted( CBaseEntity *pEntity );
  58. virtual void EnableGoal( CAI_BaseNPC *pAI ) {}
  59. virtual void DisableGoal( CAI_BaseNPC *pAI ) {}
  60. void UpdateActors();
  61. const CUtlVector<AIHANDLE> &AccessActors()
  62. {
  63. return m_actors;
  64. }
  65. private:
  66. enum Flags_t
  67. {
  68. ACTIVE = 0x01,
  69. RESOLVED_NAME = 0x02,
  70. DORMANT = 0x04,
  71. };
  72. enum SearchType_t
  73. {
  74. ST_ENTNAME,
  75. ST_CLASSNAME,
  76. };
  77. void DelayedRefresh();
  78. void PruneActors();
  79. void ResolveNames();
  80. // From Worldcraft
  81. string_t m_iszActor;
  82. string_t m_iszGoal;
  83. bool m_fStartActive;
  84. SearchType_t m_SearchType;
  85. string_t m_iszConceptModifiers;
  86. CUtlVector<AIHANDLE> m_actors;
  87. EHANDLE m_hGoalEntity;
  88. unsigned m_flags;
  89. protected:
  90. DECLARE_DATADESC();
  91. };
  92. //-------------------------------------
  93. // @TODO (toml 03-18-03): Efficiency wart -- make this an explicit duty of the client?
  94. inline void CAI_GoalEntity::UpdateActors()
  95. {
  96. if ( !( m_flags & ACTIVE ) || !( m_flags & RESOLVED_NAME ) )
  97. {
  98. ResolveNames();
  99. m_flags |= RESOLVED_NAME;
  100. }
  101. else
  102. PruneActors();
  103. }
  104. //-------------------------------------
  105. inline bool CAI_GoalEntity::IsActive()
  106. {
  107. if ( m_flags & ACTIVE )
  108. {
  109. UpdateActors();
  110. return ( m_actors.Count() != 0 );
  111. }
  112. return false;
  113. }
  114. //-------------------------------------
  115. inline int CAI_GoalEntity::NumActors()
  116. {
  117. UpdateActors();
  118. return m_actors.Count();
  119. }
  120. //-------------------------------------
  121. inline CAI_BaseNPC *CAI_GoalEntity::GetActor( int iActor )
  122. {
  123. UpdateActors();
  124. if ( m_actors.Count() > iActor )
  125. return m_actors[iActor];
  126. return NULL;
  127. }
  128. //-------------------------------------
  129. inline void CAI_GoalEntity::SetGoalEntity( CBaseEntity *pGoalEntity )
  130. {
  131. m_iszGoal = pGoalEntity->GetEntityName();
  132. m_hGoalEntity = pGoalEntity;
  133. }
  134. //-------------------------------------
  135. inline CBaseEntity *CAI_GoalEntity::GetGoalEntity()
  136. {
  137. UpdateActors();
  138. return m_hGoalEntity;
  139. }
  140. //-------------------------------------
  141. inline const char *CAI_GoalEntity::GetGoalEntityName()
  142. {
  143. return STRING( m_iszGoal );
  144. }
  145. //-------------------------------------
  146. inline const char *CAI_GoalEntity::GetConceptModifiers()
  147. {
  148. return STRING( m_iszConceptModifiers );
  149. }
  150. //-----------------------------------------------------------------------------
  151. #endif // AI_GOALENTITY_H