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.

201 lines
5.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: A schedule
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #include "bitstring.h"
  14. #ifndef AI_SCHEDULE_H
  15. #define AI_SCHEDULE_H
  16. #pragma once
  17. class CStringRegistry;
  18. class CAI_ClassScheduleIdSpace;
  19. class CAI_GlobalScheduleNamespace;
  20. class CAI_BaseNPC;
  21. struct Task_t;
  22. #ifndef MAX_CONDITIONS
  23. #define MAX_CONDITIONS 32*8
  24. #endif
  25. typedef CBitVec<MAX_CONDITIONS> CAI_ScheduleBits;
  26. //==================================================
  27. // goalType_t
  28. //==================================================
  29. enum goalType_t
  30. {
  31. GOAL_NONE = -1,
  32. GOAL_ENEMY, //Our current enemy's position
  33. GOAL_TARGET, //Our current target's position
  34. GOAL_ENEMY_LKP, //Our current enemy's last known position
  35. GOAL_SAVED_POSITION, //Our saved position
  36. };
  37. //==================================================
  38. // pathType_t
  39. //==================================================
  40. enum pathType_t
  41. {
  42. PATH_NONE = -1,
  43. PATH_TRAVEL, //Path that will take us to the goal
  44. PATH_LOS, //Path that gives us line of sight to our goal
  45. //PATH_FLANK, //Path that will take us to a flanking position of our goal
  46. //PATH_FLANK_LOS, //Path that will take us to within line of sight to the flanking position of our goal
  47. PATH_COVER, //Path that will give us cover from our goal
  48. //PATH_COVER_LOS, //Path that will give us line of sight to cover from our goal
  49. };
  50. //=============================================================================
  51. // >> CAI_Schedule
  52. //=============================================================================
  53. class CAI_Schedule;
  54. class CAI_SchedulesManager
  55. {
  56. public:
  57. CAI_SchedulesManager()
  58. {
  59. allSchedules = NULL;
  60. m_CurLoadSig = 0; // Note when schedules reset
  61. }
  62. int GetScheduleLoadSignature() { return m_CurLoadSig; }
  63. CAI_Schedule* GetScheduleFromID( int schedID ); // Function to return schedule from linked list
  64. CAI_Schedule* GetScheduleByName( const char *name );
  65. bool LoadAllSchedules(void);
  66. bool LoadSchedulesFromBuffer( const char *prefix, char *pfile, CAI_ClassScheduleIdSpace *pIdSpace, CAI_GlobalScheduleNamespace *pGlobalNamespace );
  67. private:
  68. friend class CAI_SystemHook;
  69. int m_CurLoadSig; // Note when schedules reset
  70. CAI_Schedule* allSchedules; // A linked list of all schedules
  71. CAI_Schedule * CreateSchedule(char *name, int schedule_id);
  72. void CreateStringRegistries( void );
  73. void DestroyStringRegistries( void );
  74. void DeleteAllSchedules(void);
  75. //static bool LoadSchedules( char* prefix, int taskIDOffset, int taskENOffset,
  76. // int schedIDOffset, int schedENOffset,
  77. // int condIDOffset, int condENOffset);
  78. // parsing helpers
  79. int GetStateID(const char *state_name);
  80. int GetMemoryID(const char *memory_name);
  81. int GetPathID( const char *token );
  82. int GetGoalID( const char *token );
  83. };
  84. extern CAI_SchedulesManager g_AI_SchedulesManager;
  85. extern CAI_SchedulesManager g_AI_AgentSchedulesManager;
  86. class CAI_Schedule
  87. {
  88. // ---------
  89. // Static
  90. // ---------
  91. // ---------
  92. public:
  93. int GetId() const
  94. {
  95. return m_iScheduleID;
  96. }
  97. const Task_t *GetTaskList() const
  98. {
  99. return m_pTaskList;
  100. }
  101. int NumTasks() const
  102. {
  103. return m_iNumTasks;
  104. }
  105. void GetInterruptMask( CAI_ScheduleBits *pBits ) const
  106. {
  107. m_InterruptMask.CopyTo( pBits );
  108. }
  109. bool HasInterrupt( int condition ) const
  110. {
  111. return m_InterruptMask.IsBitSet( condition );
  112. }
  113. const char *GetName() const
  114. {
  115. return m_pName;
  116. }
  117. private:
  118. friend class CAI_SchedulesManager;
  119. int m_iScheduleID; // The id number of this schedule
  120. Task_t *m_pTaskList;
  121. int m_iNumTasks;
  122. CAI_ScheduleBits m_InterruptMask; // a bit mask of conditions that can interrupt this schedule
  123. char *m_pName;
  124. CAI_Schedule *nextSchedule; // The next schedule in the list of schedules
  125. CAI_Schedule(char *name,int schedule_id, CAI_Schedule *pNext);
  126. ~CAI_Schedule( void );
  127. };
  128. //-----------------------------------------------------------------------------
  129. //
  130. // In-memory schedules
  131. //
  132. #define AI_DEFINE_SCHEDULE( name, text ) \
  133. const char * g_psz##name = \
  134. "\n Schedule" \
  135. "\n " #name \
  136. text \
  137. "\n"
  138. #define AI_LOAD_SCHEDULE( classname, name ) \
  139. do \
  140. { \
  141. extern const char * g_psz##name; \
  142. if ( classname::gm_SchedLoadStatus.fValid ) \
  143. { \
  144. classname::gm_SchedLoadStatus.fValid = g_AI_SchedulesManager.LoadSchedulesFromBuffer( #classname,(char *)g_psz##name,&classname::gm_ClassScheduleIdSpace, classname::GetSchedulingSymbols() ); \
  145. } \
  146. } while (false)
  147. // For loading default schedules in memory (see ai_default.cpp)
  148. #define AI_LOAD_DEF_SCHEDULE( classname, name ) \
  149. do \
  150. { \
  151. extern const char * g_psz##name; \
  152. if (!g_AI_SchedulesManager.LoadSchedulesFromBuffer( #classname,(char *)g_psz##name,&classname::gm_ClassScheduleIdSpace, classname::GetSchedulingSymbols() )) \
  153. return false; \
  154. } while (false)
  155. //-----------------------------------------------------------------------------
  156. #endif // AI_SCHEDULE_H