mapmgr.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 : Combat *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/mapmgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/31/02 1:48p $*
  29. * *
  30. * $Revision:: 11 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "mapmgr.h"
  36. #include "texture.h"
  37. #include "assetmgr.h"
  38. #include "saveload.h"
  39. //#define FORCE_DISABLE_VTOL // remove this to allow VTOL's on maps that allow VTOLs
  40. ///////////////////////////////////////////////////////////////////////
  41. // Global singleton instance
  42. ///////////////////////////////////////////////////////////////////////
  43. MapMgrClass _TheMapMgrSaveLoadSubsystem;
  44. ////////////////////////////////////////////////////////////////
  45. // Local constants
  46. ////////////////////////////////////////////////////////////////
  47. enum
  48. {
  49. CHUNKID_VARIABLES = 0x07020522,
  50. CHUNKID_SHROUD
  51. };
  52. enum
  53. {
  54. VARID_TEXTURE_NAME = 0x01,
  55. VARID_CENTER_POINT,
  56. VARID_SCALE,
  57. VARID_MAP_TITLE_ID,
  58. VARID_IS_PLAYER_MARKDER_VISIBLE,
  59. VARID_ENABLE_VTOL
  60. };
  61. ////////////////////////////////////////////////////////////////
  62. // Static member intialization
  63. ////////////////////////////////////////////////////////////////
  64. bool MapMgrClass::IsPlayerMarkerVisible = true;
  65. int MapMgrClass::MapTitleID = 0;
  66. StringClass MapMgrClass::MapTextureName;
  67. Vector2 MapMgrClass::MapCenterPoint (0, 0);
  68. Vector2 MapMgrClass::MapScale (0, 0);
  69. Vector2 MapMgrClass::MapSize (0, 0);
  70. uint32 MapMgrClass::CloudVector[CLOUD_VECTOR_SIZE] = { 0 };
  71. bool MapMgrClass::EnableVTOL = false;
  72. ////////////////////////////////////////////////////////////////
  73. //
  74. // Get_Map_Texture_Filename
  75. //
  76. ////////////////////////////////////////////////////////////////
  77. void
  78. MapMgrClass::Get_Map_Texture_Filename (StringClass &filename)
  79. {
  80. //
  81. // Strip off the path if necessary
  82. //
  83. filename = MapTextureName;
  84. char *dir_delimiter = ::strrchr (MapTextureName, '\\');
  85. if (dir_delimiter != NULL) {
  86. filename = (dir_delimiter + 1);
  87. }
  88. return ;
  89. }
  90. ////////////////////////////////////////////////////////////////
  91. //
  92. // Set_Map_Texture
  93. //
  94. ////////////////////////////////////////////////////////////////
  95. void
  96. MapMgrClass::Set_Map_Texture (const char *filename)
  97. {
  98. //
  99. // Strip off the path if necessary
  100. //
  101. StringClass filename_only = filename;
  102. char *dir_delimiter = ::strrchr (filename, '\\');
  103. if (dir_delimiter != NULL) {
  104. filename_only = (dir_delimiter + 1);
  105. }
  106. //
  107. // Load the texture
  108. //
  109. TextureClass *texture = WW3DAssetManager::Get_Instance ()->Get_Texture (filename_only, TextureClass::MIP_LEVELS_1);
  110. if (texture != NULL) {
  111. //
  112. // Get the dimensions of the texture
  113. //
  114. // SurfaceClass::SurfaceDescription surface_desc;
  115. // texture->Get_Level_Description (surface_desc);
  116. // MapSize.X = surface_desc.Width;
  117. // MapSize.Y = surface_desc.Height;
  118. MapSize.X = texture->Get_Width();
  119. MapSize.Y = texture->Get_Height();
  120. //
  121. // Release our hold on the texture
  122. //
  123. REF_PTR_RELEASE (texture);
  124. }
  125. //
  126. // Cache the texture name
  127. //
  128. MapTextureName = filename;
  129. return ;
  130. }
  131. ////////////////////////////////////////////////////////////////
  132. //
  133. // Save
  134. //
  135. ////////////////////////////////////////////////////////////////
  136. bool
  137. MapMgrClass::Save (ChunkSaveClass &csave)
  138. {
  139. //
  140. // Write the variables
  141. //
  142. csave.Begin_Chunk (CHUNKID_VARIABLES);
  143. WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_TEXTURE_NAME, MapTextureName);
  144. WRITE_MICRO_CHUNK (csave, VARID_CENTER_POINT, MapCenterPoint);
  145. WRITE_MICRO_CHUNK (csave, VARID_SCALE, MapScale);
  146. WRITE_MICRO_CHUNK (csave, VARID_MAP_TITLE_ID, MapTitleID);
  147. WRITE_MICRO_CHUNK (csave, VARID_IS_PLAYER_MARKDER_VISIBLE, IsPlayerMarkerVisible);
  148. WRITE_MICRO_CHUNK (csave, VARID_ENABLE_VTOL, EnableVTOL);
  149. csave.End_Chunk ();
  150. //
  151. // Write the current shroud
  152. //
  153. csave.Begin_Chunk (CHUNKID_SHROUD);
  154. int size = CLOUD_VECTOR_SIZE;
  155. csave.Write (&size, sizeof (size));
  156. csave.Write (CloudVector, sizeof (CloudVector));
  157. csave.End_Chunk ();
  158. return true;
  159. }
  160. ////////////////////////////////////////////////////////////////
  161. //
  162. // Load
  163. //
  164. ////////////////////////////////////////////////////////////////
  165. bool
  166. MapMgrClass::Load (ChunkLoadClass &cload)
  167. {
  168. while (cload.Open_Chunk ()) {
  169. switch (cload.Cur_Chunk_ID ()) {
  170. //
  171. // Load all the variables from this chunk
  172. //
  173. case CHUNKID_VARIABLES:
  174. Load_Variables (cload);
  175. break;
  176. case CHUNKID_SHROUD:
  177. {
  178. //
  179. // Read the shroud vector from its chunk
  180. //
  181. int size = 0;
  182. cload.Read (&size, sizeof (size));
  183. if (size == CLOUD_VECTOR_SIZE) {
  184. cload.Read (CloudVector, sizeof (CloudVector));
  185. }
  186. break;
  187. }
  188. }
  189. cload.Close_Chunk ();
  190. }
  191. return true;
  192. }
  193. ////////////////////////////////////////////////////////////////
  194. //
  195. // Load_Variables
  196. //
  197. ////////////////////////////////////////////////////////////////
  198. void
  199. MapMgrClass::Load_Variables (ChunkLoadClass &cload)
  200. {
  201. while (cload.Open_Micro_Chunk ()) {
  202. switch (cload.Cur_Micro_Chunk_ID ()) {
  203. READ_MICRO_CHUNK_WWSTRING (cload, VARID_TEXTURE_NAME, MapTextureName);
  204. READ_MICRO_CHUNK (cload, VARID_CENTER_POINT, MapCenterPoint);
  205. READ_MICRO_CHUNK (cload, VARID_SCALE, MapScale);
  206. READ_MICRO_CHUNK (cload, VARID_MAP_TITLE_ID, MapTitleID);
  207. READ_MICRO_CHUNK (cload, VARID_IS_PLAYER_MARKDER_VISIBLE, IsPlayerMarkerVisible);
  208. READ_MICRO_CHUNK (cload, VARID_ENABLE_VTOL, EnableVTOL);
  209. }
  210. cload.Close_Micro_Chunk ();
  211. }
  212. //
  213. // (gth) VTOL DISABLE! We are not going to let Modders make VTOL aircraft
  214. // until we release some levels with them. FORCE the EnableVTOL flag to
  215. // false for now. When we release some maps with orcas, then we patch
  216. // the game with this line of code removed and the mod people can make them
  217. // too.
  218. //
  219. #ifdef FORCE_DISABLE_VTOL
  220. EnableVTOL = false;
  221. #endif
  222. SaveLoadSystemClass::Register_Post_Load_Callback (this);
  223. return ;
  224. }
  225. ///////////////////////////////////////////////////////////////////////
  226. //
  227. // On_Post_Load
  228. //
  229. ///////////////////////////////////////////////////////////////////////
  230. void
  231. MapMgrClass::On_Post_Load (void)
  232. {
  233. Set_Map_Texture (MapTextureName);
  234. return ;
  235. }
  236. ///////////////////////////////////////////////////////////////////////
  237. //
  238. // Clear_Cloud_Cells
  239. //
  240. ///////////////////////////////////////////////////////////////////////
  241. void
  242. MapMgrClass::Clear_Cloud_Cells (const Vector3 &pos, int pixel_radius)
  243. {
  244. if (MapSize.X <= 0 || MapSize.Y <= 0) {
  245. return ;
  246. }
  247. //
  248. // Calculate where (in map pixels) this position lies
  249. //
  250. float map_x_pos = MapCenterPoint.X + (pos.X * MapScale.X);
  251. float map_y_pos = MapCenterPoint.Y - (pos.Y * MapScale.Y);
  252. //
  253. // Determine what the min and max cells this region includes
  254. //
  255. int min_cell_x = int(((map_x_pos - pixel_radius) / MapSize.X) * CLOUD_WIDTH);
  256. int min_cell_y = int(((map_y_pos - pixel_radius) / MapSize.Y) * CLOUD_HEIGHT);
  257. int max_cell_x = int(((map_x_pos + pixel_radius) / MapSize.X) * CLOUD_WIDTH);
  258. int max_cell_y = int(((map_y_pos + pixel_radius) / MapSize.Y) * CLOUD_HEIGHT);
  259. //
  260. // Clear all the cells in this region
  261. //
  262. for (int cell_x = min_cell_x; cell_x <= max_cell_x; cell_x ++) {
  263. for (int cell_y = min_cell_y; cell_y <= max_cell_y; cell_y ++) {
  264. Clear_Cloud_Cell (cell_x, cell_y);
  265. }
  266. }
  267. return ;
  268. }