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.

200 lines
4.9 KiB

  1. //========= Copyright 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_BaseNPC;
  20. struct Task_t;
  21. #ifndef MAX_CONDITIONS
  22. #define MAX_CONDITIONS 32*8
  23. #endif
  24. typedef CBitVec<MAX_CONDITIONS> CAI_ScheduleBits;
  25. //==================================================
  26. // goalType_t
  27. //==================================================
  28. enum goalType_t
  29. {
  30. GOAL_NONE = -1,
  31. GOAL_ENEMY, //Our current enemy's position
  32. GOAL_TARGET, //Our current target's position
  33. GOAL_ENEMY_LKP, //Our current enemy's last known position
  34. GOAL_SAVED_POSITION, //Our saved position
  35. };
  36. //==================================================
  37. // pathType_t
  38. //==================================================
  39. enum pathType_t
  40. {
  41. PATH_NONE = -1,
  42. PATH_TRAVEL, //Path that will take us to the goal
  43. PATH_LOS, //Path that gives us line of sight to our goal
  44. //PATH_FLANK, //Path that will take us to a flanking position of our goal
  45. //PATH_FLANK_LOS, //Path that will take us to within line of sight to the flanking position of our goal
  46. PATH_COVER, //Path that will give us cover from our goal
  47. //PATH_COVER_LOS, //Path that will give us line of sight to cover from our goal
  48. };
  49. //=============================================================================
  50. // >> CAI_Schedule
  51. //=============================================================================
  52. class CAI_Schedule;
  53. class CAI_SchedulesManager
  54. {
  55. public:
  56. CAI_SchedulesManager()
  57. {
  58. allSchedules = NULL;
  59. m_CurLoadSig = 0; // Note when schedules reset
  60. }
  61. int GetScheduleLoadSignature() { return m_CurLoadSig; }
  62. CAI_Schedule* GetScheduleFromID( int schedID ); // Function to return schedule from linked list
  63. CAI_Schedule* GetScheduleByName( const char *name );
  64. bool LoadAllSchedules(void);
  65. bool LoadSchedules( const char* prefix, CAI_ClassScheduleIdSpace *pIdSpace );
  66. bool LoadSchedulesFromBuffer( const char *prefix, const char *pfile, CAI_ClassScheduleIdSpace *pIdSpace );
  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. class CAI_Schedule
  86. {
  87. // ---------
  88. // Static
  89. // ---------
  90. // ---------
  91. public:
  92. int GetId() const
  93. {
  94. return m_iScheduleID;
  95. }
  96. const Task_t *GetTaskList() const
  97. {
  98. return m_pTaskList;
  99. }
  100. int NumTasks() const
  101. {
  102. return m_iNumTasks;
  103. }
  104. void GetInterruptMask( CAI_ScheduleBits *pBits ) const
  105. {
  106. m_InterruptMask.CopyTo( pBits );
  107. }
  108. bool HasInterrupt( int condition ) const
  109. {
  110. return m_InterruptMask.IsBitSet( condition );
  111. }
  112. const char *GetName() const
  113. {
  114. return m_pName;
  115. }
  116. private:
  117. friend class CAI_SchedulesManager;
  118. int m_iScheduleID; // The id number of this schedule
  119. Task_t *m_pTaskList;
  120. int m_iNumTasks;
  121. CAI_ScheduleBits m_InterruptMask; // a bit mask of conditions that can interrupt this schedule
  122. char *m_pName;
  123. CAI_Schedule *nextSchedule; // The next schedule in the list of schedules
  124. CAI_Schedule(char *name,int schedule_id, CAI_Schedule *pNext);
  125. ~CAI_Schedule( void );
  126. };
  127. //-----------------------------------------------------------------------------
  128. //
  129. // In-memory schedules
  130. //
  131. #define AI_DEFINE_SCHEDULE( name, text ) \
  132. const char * g_psz##name = \
  133. "\n Schedule" \
  134. "\n " #name \
  135. text \
  136. "\n"
  137. #define AI_LOAD_SCHEDULE( classname, name ) \
  138. do \
  139. { \
  140. extern const char * g_psz##name; \
  141. if ( classname::gm_SchedLoadStatus.fValid ) \
  142. { \
  143. classname::gm_SchedLoadStatus.fValid = g_AI_SchedulesManager.LoadSchedulesFromBuffer( #classname,(char *)g_psz##name,&classname::gm_ClassScheduleIdSpace ); \
  144. } \
  145. } while (false)
  146. // For loading default schedules in memory (see ai_default.cpp)
  147. #define AI_LOAD_DEF_SCHEDULE( classname, name ) \
  148. do \
  149. { \
  150. extern const char * g_psz##name; \
  151. if (!g_AI_SchedulesManager.LoadSchedulesFromBuffer( #classname,(char *)g_psz##name,&classname::gm_ClassScheduleIdSpace )) \
  152. return false; \
  153. } while (false)
  154. //-----------------------------------------------------------------------------
  155. #endif // AI_SCHEDULE_H