PathfindSectorBuilder.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/PathfindSectorBuilder.h $Modtime:: 5/27/00 4:10p $*
  25. * *
  26. * $Revision:: 25 $*
  27. * *
  28. *---------------------------------------------------------------------------------------------*
  29. * Functions: *
  30. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  31. #if defined(_MSC_VER)
  32. #pragma once
  33. #endif
  34. #ifndef _PATHFIND_SECTOR_BUILDER_H
  35. #define _PATHFIND_SECTOR_BUILDER_H
  36. #include "vector3.h"
  37. #include "matrix3d.h"
  38. #include "vector.h"
  39. //#include "physcontrol.h"
  40. #include "pathfindsector.h"
  41. #include "floodfillbox.h"
  42. #include "transition.h"
  43. #include "aabtreecull.h"
  44. #include "floodfillgrid.h"
  45. #include "heightwatcher.h"
  46. #include "levelfeature.h"
  47. //////////////////////////////////////////////////////////////////////////
  48. // Forward declarations
  49. //////////////////////////////////////////////////////////////////////////
  50. class Phys3Class;
  51. class SimDirInfoClass;
  52. class ZoneInstanceClass;
  53. class GeneratingPathfindDialogClass;
  54. class TransitionNodeClass;
  55. //////////////////////////////////////////////////////////////////////////
  56. // BOX_PERIMETER
  57. //////////////////////////////////////////////////////////////////////////
  58. typedef struct _BOX_PERIMETER
  59. {
  60. int count_up;
  61. int count_down;
  62. int count_left;
  63. int count_right;
  64. bool stop_up;
  65. bool stop_down;
  66. bool stop_left;
  67. bool stop_right;
  68. } BOX_PERIMETER;
  69. //////////////////////////////////////////////////////////////////////////
  70. // Typedefs
  71. //////////////////////////////////////////////////////////////////////////
  72. typedef DynamicVectorClass<Vector3> START_POINT_LIST;
  73. typedef DynamicVectorClass<LevelFeatureClass *> LEVEL_FEATURE_LIST;
  74. typedef TypedAABTreeCullSystemClass<LevelFeatureClass> LEVEL_FEATURE_CULLING_SYSTEM;
  75. //////////////////////////////////////////////////////////////////////////
  76. //
  77. // PathfindSectorBuilderClass
  78. //
  79. //////////////////////////////////////////////////////////////////////////
  80. class PathfindSectorBuilderClass
  81. {
  82. public:
  83. ////////////////////////////////////////////////////////////////////
  84. // Public constructors/destructors
  85. ////////////////////////////////////////////////////////////////////
  86. PathfindSectorBuilderClass (void);
  87. ~PathfindSectorBuilderClass (void);
  88. ////////////////////////////////////////////////////////////////////
  89. // Public methods
  90. ////////////////////////////////////////////////////////////////////
  91. //
  92. // Initialization
  93. //
  94. void Initialize (void);
  95. void Shutdown (void);
  96. //
  97. // Generation management
  98. //
  99. void Add_Start_Point (const Vector3 &start_pos);
  100. void Generate_Sectors (void);
  101. void Compress_Sectors_For_Pathfind (void);
  102. void Compress_Sectors_For_Dyna_Culling (void);
  103. //
  104. // Compression control
  105. //
  106. void Set_Max_Sector_Size (float max_dim);
  107. //
  108. // Flags
  109. //
  110. void Allow_Water_Floodfill (bool onoff);
  111. protected:
  112. ////////////////////////////////////////////////////////////////////
  113. // Protected methods
  114. ////////////////////////////////////////////////////////////////////
  115. void Do_Physics_Sim (const Vector3 &start_pos, PATHFIND_DIR direction);
  116. void Do_Real_Physics_Sim (const Vector3 &start_pos, PATHFIND_DIR direction);
  117. void Floodfill (const Vector3 &start_pos);
  118. bool Try_Standing_Here (const Vector3 &expected_pos, AABoxClass *real_pos);
  119. bool Try_Moving_Here (const Vector3 &start_pos, const Vector3 &expected_pos, AABoxClass *real_pos);
  120. bool Find_Ground (const Vector3 &pos, float *ground_pos);
  121. bool Find_Ceiling (const Vector3 &pos, float *ceiling_pos);
  122. FloodfillBoxClass * Get_Sector_Occupant (const Vector3 &pos);
  123. FloodfillBoxClass * Mark_Sector (const AABoxClass &bounding_box);
  124. void Mark_Sector (FloodfillBoxClass *body_box);
  125. FloodfillBoxClass * Submit_Box (FloodfillBoxClass *from_obj, const AABoxClass &new_box, PATHFIND_DIR direction);
  126. PathfindSectorClass * Build_Sector (FloodfillBoxClass *upper_left_ptr, int cells_right, int cells_down);
  127. void Generate_Portals (void);
  128. void Free_Floodfill_Boxes (void);
  129. void Determine_Height (FloodfillBoxClass *start_box, float *min_z_pos, float *max_z_pos);
  130. int Build_Height_Values (void);
  131. void Compress_Sectors (DynamicVectorClass<AABoxClass> *box_list = NULL);
  132. FloodfillBoxClass * Find_Perimeter (FloodfillBoxClass *start_box, BOX_PERIMETER *perimeter);
  133. bool Check_Edge (FloodfillBoxClass *start_box, int count_left, int count_right, int count_up, int count_down, PATHFIND_DIR move_dir);
  134. FloodfillBoxClass * Move_Dir (FloodfillBoxClass *start_box, PATHFIND_DIR dir, int dir_mask);
  135. //
  136. // Ladder and other transition handling
  137. //
  138. void Post_Process_Floodfill_For_Level_Features (void);
  139. void Apply_Level_Features (void);
  140. void Build_Sector_For_Level_Feature (LevelFeatureClass *level_feature);
  141. void Check_For_Level_Feature (FloodfillBoxClass *body_box);
  142. void Path_Across_Feature (LevelFeatureClass *level_feature);
  143. void Detect_Level_Features (void);
  144. void Detect_Elevators (void);
  145. void Detect_Doors (void);
  146. void Detect_Level_Transitions (void);
  147. void Cleanup_Level_Features (void);
  148. //
  149. // Environment detection methods
  150. //
  151. TransitionInstanceClass * Find_Transition (TransitionDataClass::StyleType type, const Vector3 &start_pos, float z_delta, TransitionNodeClass **transition_node);
  152. PathfindSectorClass * Find_Sector (const Vector3 &point, const AABoxClass &box);
  153. //
  154. // Prepartion methods
  155. //
  156. void Prepare_Level (void);
  157. void Restore_Level (void);
  158. //
  159. // Floodfill box methods
  160. //
  161. AABoxClass Get_Body_Box_Bounds (FloodfillBoxClass *box);
  162. //
  163. // User interface methods
  164. //
  165. void Show_Dialog (void);
  166. void Close_Dialog (void);
  167. bool Is_Valid_Sector (FloodfillBoxClass **upper_left_ptr, int &cells_right, int &cells_down);
  168. private:
  169. ////////////////////////////////////////////////////////////////////
  170. // Private member data
  171. ////////////////////////////////////////////////////////////////////
  172. FloodfillBoxClass * m_CurrentSector;
  173. Vector3 m_SimBoundingBox;
  174. Vector3 m_SimBoxExtents;
  175. float m_StepHeight;
  176. bool m_AllowWaterFloodfill;
  177. START_POINT_LIST m_StartPointList;
  178. BODY_BOX_LIST m_FloodFillProcessList;
  179. FloodfillGridClass m_BodyBoxCullingSystem;
  180. LEVEL_FEATURE_LIST m_LevelFeatureList;
  181. LEVEL_FEATURE_CULLING_SYSTEM m_LevelFeatureCullingSystem;
  182. SimDirInfoClass * m_DirInfo;
  183. BODY_BOX_LIST m_PossiblePortalList;
  184. BODY_BOX_LIST m_BodyBoxReleaseList;
  185. //
  186. // Compression
  187. //
  188. HeightWatcherClass m_HeightWatcher;
  189. // Simulation data
  190. Vector3 m_SimMovement;
  191. AABoxClass m_SimSweepBox;
  192. // UI
  193. GeneratingPathfindDialogClass *m_pDialog;
  194. int m_TotalBoxCount;
  195. int m_BeforeUpdateCount;
  196. int m_TotalBoxGuess;
  197. float m_MaxSectorDim;
  198. };
  199. ////////////////////////////////////////////////////////////////////
  200. // Get_Body_Box_Bounds
  201. ////////////////////////////////////////////////////////////////////
  202. inline AABoxClass
  203. PathfindSectorBuilderClass::Get_Body_Box_Bounds (FloodfillBoxClass *box)
  204. {
  205. return AABoxClass (box->Get_Position (), m_SimBoxExtents);
  206. }
  207. ////////////////////////////////////////////////////////////////////
  208. // Allow_Water_Floodfill
  209. ////////////////////////////////////////////////////////////////////
  210. inline void
  211. PathfindSectorBuilderClass::Allow_Water_Floodfill (bool onoff)
  212. {
  213. m_AllowWaterFloodfill = onoff;
  214. return ;
  215. }
  216. ////////////////////////////////////////////////////////////////////
  217. // Add_Start_Point
  218. ////////////////////////////////////////////////////////////////////
  219. inline void
  220. PathfindSectorBuilderClass::Add_Start_Point (const Vector3 &start_pos)
  221. {
  222. m_StartPointList.Add (start_pos);
  223. return ;
  224. }
  225. ////////////////////////////////////////////////////////////////////
  226. // Set_Max_Sector_Size
  227. ////////////////////////////////////////////////////////////////////
  228. inline void
  229. PathfindSectorBuilderClass::Set_Max_Sector_Size (float max_dim)
  230. {
  231. m_MaxSectorDim = max_dim;
  232. return ;
  233. }
  234. #endif //_PATHFIND_SECTOR_BUILDER_H