mapmgr.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/10/02 10:31a $*
  29. * *
  30. * $Revision:: 8 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __MAP_MGR_H
  39. #define __MAP_MGR_H
  40. #include "vector2.h"
  41. #include "vector3.h"
  42. #include "wwstring.h"
  43. #include "bittype.h"
  44. #include "saveloadsubsystem.h"
  45. #include "combatchunkid.h"
  46. ///////////////////////////////////////////////////////////////////////
  47. // Global singleton instance
  48. ///////////////////////////////////////////////////////////////////////
  49. extern class MapMgrClass _TheMapMgrSaveLoadSubsystem;
  50. ////////////////////////////////////////////////////////////////
  51. //
  52. // MapMgrClass
  53. //
  54. ////////////////////////////////////////////////////////////////
  55. class MapMgrClass : public SaveLoadSubSystemClass
  56. {
  57. public:
  58. ////////////////////////////////////////////////////////////////
  59. // Public constants
  60. ////////////////////////////////////////////////////////////////
  61. enum
  62. {
  63. CLOUD_WIDTH = 20,
  64. CLOUD_HEIGHT = 20,
  65. CLOUD_VECTOR_SIZE = ((CLOUD_WIDTH * CLOUD_HEIGHT) / 32) + 1,
  66. };
  67. ////////////////////////////////////////////////////////////////
  68. // Public methods
  69. ////////////////////////////////////////////////////////////////
  70. //
  71. // This is the texture that will be used to display the map
  72. //
  73. static void Set_Map_Texture (const char *filename);
  74. static void Get_Map_Texture_Filename (StringClass &filename);
  75. static const char * Get_Map_Texture_Pathname (void) { return MapTextureName; }
  76. //
  77. // Map centering and scale.
  78. //
  79. // Note: The scale means "how many pixels (of map) per meter (of world space)".
  80. // This value can differ in the X and Y axes.
  81. //
  82. // The map center is the pixel position (x,y) where world space (0, 0, 0) is.
  83. //
  84. static const Vector2 & Get_Map_Scale (void) { return MapScale; }
  85. static void Set_Map_Scale (const Vector2 &scale) { MapScale = scale; }
  86. static const Vector2 & Get_Map_Center (void) { return MapCenterPoint; }
  87. static void Set_Map_Center (const Vector2 &pos) { MapCenterPoint = pos; }
  88. //
  89. // Cloud support
  90. //
  91. static void Clear_Cloud_Cell (const Vector3 &pos);
  92. static void Clear_Cloud_Cells (const Vector3 &pos, int pixel_radius);
  93. static void Clear_Cloud_Cell (int x_pos, int y_pos);
  94. static void Clear_Cloud_Cell_By_Pixel (int x_pos, int y_pos);
  95. static void Clear_All_Cloud_Cells (void) { ::memset (CloudVector, 0, sizeof (CloudVector)); }
  96. static void Cloud_All_Cells (void) { ::memset (CloudVector, 0xFF, sizeof (CloudVector)); }
  97. static bool Is_Cell_Visible (int x_pos, int y_pos);
  98. //
  99. // VTOL Support. Some maps do not support VTOL aircraft.
  100. //
  101. static void Enable_VTOL_Vehicles(bool onoff) { EnableVTOL = onoff; }
  102. static bool Are_VTOL_Vehicles_Enabled(void) { return EnableVTOL; }
  103. //
  104. // From SaveLoadSubSystemClass
  105. //
  106. uint32 Chunk_ID (void) const { return CHUNKID_MAPMGR; }
  107. //
  108. // Title support
  109. //
  110. static void Set_Map_Title (int string_id) { MapTitleID = string_id; }
  111. static int Get_Map_Title (void) { return MapTitleID; }
  112. //
  113. // Player marker control
  114. //
  115. static bool Is_Player_Marker_Visible (void) { return IsPlayerMarkerVisible; }
  116. static void Show_Player_Marker (bool onoff) { IsPlayerMarkerVisible = onoff; }
  117. protected:
  118. //
  119. // From SaveLoadSubSystemClass
  120. //
  121. bool Save (ChunkSaveClass &csave);
  122. bool Load (ChunkLoadClass &cload);
  123. void On_Post_Load (void);
  124. const char * Name (void) const { return "MapMgrClass"; }
  125. //
  126. // Save load support
  127. //
  128. void Load_Variables (ChunkLoadClass &cload);
  129. private:
  130. ////////////////////////////////////////////////////////////////
  131. // Private member data
  132. ////////////////////////////////////////////////////////////////
  133. static bool IsPlayerMarkerVisible;
  134. static int MapTitleID;
  135. static StringClass MapTextureName;
  136. static Vector2 MapCenterPoint;
  137. static Vector2 MapScale;
  138. static Vector2 MapSize;
  139. static uint32 CloudVector[CLOUD_VECTOR_SIZE];
  140. static bool EnableVTOL;
  141. };
  142. ////////////////////////////////////////////////////////////////
  143. // Clear_Cloud_Cell
  144. ////////////////////////////////////////////////////////////////
  145. inline void
  146. MapMgrClass::Clear_Cloud_Cell (const Vector3 &pos)
  147. {
  148. if (MapSize.X <= 0 || MapSize.Y <= 0) {
  149. return ;
  150. }
  151. //
  152. // Calculate where (in map pixels) this position lies
  153. //
  154. float map_x_pos = MapCenterPoint.X + (pos.X * MapScale.X);
  155. float map_y_pos = MapCenterPoint.Y - (pos.Y * MapScale.Y);
  156. //
  157. // Convert this map coordinate into a cell coordinate
  158. //
  159. int cell_x = int((map_x_pos / MapSize.X) * CLOUD_WIDTH);
  160. int cell_y = int((map_y_pos / MapSize.Y) * CLOUD_HEIGHT);
  161. //
  162. // Clamp the cells
  163. //
  164. cell_x = max (cell_x, 0);
  165. cell_y = max (cell_y, 0);
  166. cell_x = min (cell_x, CLOUD_WIDTH - 1);
  167. cell_y = min (cell_y, CLOUD_HEIGHT - 1);
  168. //
  169. // Determine which bit we need to clear
  170. //
  171. int bit_offset = (cell_y * CLOUD_WIDTH) + cell_x;
  172. int index = bit_offset / 32;
  173. int bit = (bit_offset - (index * 32)) + 1;
  174. //
  175. // Clear the bit
  176. //
  177. CloudVector[index] &= ~(1 << bit);
  178. return ;
  179. }
  180. ////////////////////////////////////////////////////////////////
  181. // Clear_Cloud_Cell
  182. ////////////////////////////////////////////////////////////////
  183. inline void
  184. MapMgrClass::Clear_Cloud_Cell (int x_pos, int y_pos)
  185. {
  186. if (MapSize.X <= 0 || MapSize.Y <= 0) {
  187. return ;
  188. }
  189. //
  190. // Clamp the cells
  191. //
  192. int cell_x = max (x_pos, 0);
  193. int cell_y = max (y_pos, 0);
  194. cell_x = min (x_pos, CLOUD_WIDTH - 1);
  195. cell_y = min (y_pos, CLOUD_HEIGHT - 1);
  196. //
  197. // Determine which bit we need to clear
  198. //
  199. int bit_offset = (cell_y * CLOUD_WIDTH) + cell_x;
  200. int index = bit_offset / 32;
  201. int bit = (bit_offset - (index * 32)) + 1;
  202. //
  203. // Clear the bit
  204. //
  205. CloudVector[index] &= ~(1 << bit);
  206. return ;
  207. }
  208. ////////////////////////////////////////////////////////////////
  209. // Clear_Cloud_Cell_By_Pixel
  210. ////////////////////////////////////////////////////////////////
  211. inline void
  212. MapMgrClass::Clear_Cloud_Cell_By_Pixel (int x_pos, int y_pos)
  213. {
  214. if (MapSize.X <= 0 || MapSize.Y <= 0) {
  215. return ;
  216. }
  217. //
  218. // Convert this map coordinate into a cell coordinate
  219. //
  220. int cell_x = int((x_pos / MapSize.X) * CLOUD_WIDTH);
  221. int cell_y = int((y_pos / MapSize.Y) * CLOUD_HEIGHT);
  222. //
  223. // Clamp the cells
  224. //
  225. cell_x = max (cell_x, 0);
  226. cell_y = max (cell_y, 0);
  227. cell_x = min (cell_x, CLOUD_WIDTH - 1);
  228. cell_y = min (cell_y, CLOUD_HEIGHT - 1);
  229. //
  230. // Determine which bit we need to clear
  231. //
  232. int bit_offset = (cell_y * CLOUD_WIDTH) + cell_x;
  233. int index = bit_offset / 32;
  234. int bit = (bit_offset - (index * 32)) + 1;
  235. //
  236. // Clear the bit
  237. //
  238. CloudVector[index] &= ~(1 << bit);
  239. return ;
  240. }
  241. ////////////////////////////////////////////////////////////////
  242. // Is_Cell_Visible
  243. ////////////////////////////////////////////////////////////////
  244. inline bool
  245. MapMgrClass::Is_Cell_Visible (int x_pos, int y_pos)
  246. {
  247. int bit_offset = (y_pos * CLOUD_WIDTH) + x_pos;
  248. int index = bit_offset / 32;
  249. int bit = (bit_offset - (index * 32)) + 1;
  250. //
  251. // Index into the vector to see if this cell is clouded or not
  252. //
  253. return ((CloudVector[index] & (1 << bit)) == 0);
  254. }
  255. #endif //__MAP_MGR_H