teampurchasesettings.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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/teampurchasesettings.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 10/23/01 3:22p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "teampurchasesettings.h"
  36. #include "combatchunkid.h"
  37. #include "wwhack.h"
  38. #include "persistfactory.h"
  39. #include "definitionfactory.h"
  40. #include "simpledefinitionfactory.h"
  41. #include "debug.h"
  42. #include "translatedb.h"
  43. //////////////////////////////////////////////////////////////////////
  44. // Force links
  45. //////////////////////////////////////////////////////////////////////
  46. DECLARE_FORCE_LINK (TeamPurchaseSettings)
  47. ///////////////////////////////////////////////////////////////////////////////////////////
  48. // Factories
  49. ///////////////////////////////////////////////////////////////////////////////////////////
  50. SimplePersistFactoryClass<TeamPurchaseSettingsDefClass, CHUNKID_GLOBAL_SETTINGS_DEF_TEAM_PURCHASE> _TeamPurchaseDefPersistFactory;
  51. DECLARE_DEFINITION_FACTORY(TeamPurchaseSettingsDefClass, CLASSID_GLOBAL_SETTINGS_DEF_TEAM_PURCHASE, "Team Purchase Settings") _TeamPurchaseDefDefFactory;
  52. ///////////////////////////////////////////////////////////////////////////////////////////
  53. // Save/load constants
  54. ///////////////////////////////////////////////////////////////////////////////////////////
  55. enum
  56. {
  57. CHUNKID_PARENT = 0x10231215,
  58. CHUNKID_VARIABLES,
  59. VARID_TEAM = 1,
  60. VARID_DEFINITION,
  61. VARID_TEXTURE_NAME,
  62. VARID_NAME,
  63. VARID_INDEX,
  64. VARID_BEACON_DEFINITION,
  65. VARID_BEACON_NAME,
  66. VARID_BEACON_TEXTURE_NAME,
  67. VARID_BEACON_COST,
  68. VARID_SUPPLY_NAME,
  69. VARID_SUPPLY_TEXTURE_NAME
  70. };
  71. //////////////////////////////////////////////////////////////////////
  72. // Static member initialization
  73. //////////////////////////////////////////////////////////////////////
  74. TeamPurchaseSettingsDefClass * TeamPurchaseSettingsDefClass::DefinitionArray[TEAM_COUNT] = { 0 };
  75. //////////////////////////////////////////////////////////////////////
  76. //
  77. // TeamPurchaseSettingsDefClass
  78. //
  79. //////////////////////////////////////////////////////////////////////
  80. TeamPurchaseSettingsDefClass::TeamPurchaseSettingsDefClass (void) :
  81. Team (TEAM_GDI),
  82. BeaconNameID (0),
  83. BeaconDefinitionID (0),
  84. BeaconCost (0),
  85. SupplyNameID (0)
  86. {
  87. //
  88. // Initialize the lists
  89. //
  90. ::memset (DefinitionList, 0, sizeof (DefinitionList));
  91. ::memset (NameList, 0, sizeof (NameList));
  92. //
  93. // Configure the enum parameters for the editable system
  94. //
  95. #ifdef PARAM_EDITING_ON
  96. EnumParameterClass *param1 = new EnumParameterClass ((int *)&Team);
  97. param1->Set_Name ("Team");
  98. param1->Add_Value ("GDI", TEAM_GDI);
  99. param1->Add_Value ("NOD", TEAM_NOD);
  100. GENERIC_EDITABLE_PARAM (TeamPurchaseSettingsDefClass, param1)
  101. #endif //PARAM_EDITING_ON
  102. //
  103. // Add the beacon parameters
  104. //
  105. NAMED_EDITABLE_PARAM (TeamPurchaseSettingsDefClass, ParameterClass::TYPE_STRINGSDB_ID, BeaconNameID, "Beacon Name");
  106. NAMED_EDITABLE_PARAM (TeamPurchaseSettingsDefClass, ParameterClass::TYPE_STRING, BeaconTextureName, "Beacon Texture");
  107. NAMED_EDITABLE_PARAM (TeamPurchaseSettingsDefClass, ParameterClass::TYPE_INT, BeaconCost, "Beacon Cost");
  108. #ifdef PARAM_EDITING_ON
  109. GenericDefParameterClass *param = new GenericDefParameterClass (&BeaconDefinitionID);
  110. param->Set_Class_ID (CLASSID_GAME_OBJECTS);
  111. param->Set_Name ("Beacon Object");
  112. GENERIC_EDITABLE_PARAM (TeamPurchaseSettingsDefClass, param)
  113. #endif //PARAM_EDITING_ON
  114. //
  115. // Add the supply parameters
  116. //
  117. NAMED_EDITABLE_PARAM (TeamPurchaseSettingsDefClass, ParameterClass::TYPE_STRINGSDB_ID, SupplyNameID, "Supply Name");
  118. NAMED_EDITABLE_PARAM (TeamPurchaseSettingsDefClass, ParameterClass::TYPE_STRING, SupplyTextureName, "Supply Texture");
  119. //
  120. // Add the enlisted parameters
  121. //
  122. for (int index = 0; index < MAX_ENTRIES; index ++) {
  123. //
  124. // Add a separator for this entry
  125. //
  126. StringClass name;
  127. name.Format ("Enlisted %d", index + 1);
  128. PARAM_SEPARATOR (TeamPurchaseSettingsDefClass, (const char *)name);
  129. //
  130. // Add fields for the texture and object
  131. //
  132. NAMED_EDITABLE_PARAM (TeamPurchaseSettingsDefClass, ParameterClass::TYPE_STRINGSDB_ID, NameList[index], "Name");
  133. NAMED_EDITABLE_PARAM (TeamPurchaseSettingsDefClass, ParameterClass::TYPE_STRING, TextureList[index], "Texture");
  134. #ifdef PARAM_EDITING_ON
  135. GenericDefParameterClass *param = new GenericDefParameterClass (&(DefinitionList[index]));
  136. param->Set_Class_ID (CLASSID_GAME_OBJECTS);
  137. param->Set_Name ("Object");
  138. GENERIC_EDITABLE_PARAM(TeamPurchaseSettingsDefClass, param)
  139. #endif //PARAM_EDITING_ON
  140. }
  141. return ;
  142. }
  143. //////////////////////////////////////////////////////////////////////
  144. //
  145. // ~TeamPurchaseSettingsDefClass
  146. //
  147. //////////////////////////////////////////////////////////////////////
  148. TeamPurchaseSettingsDefClass::~TeamPurchaseSettingsDefClass (void)
  149. {
  150. //
  151. // Remove this entry from the static array
  152. //
  153. if (Team < TEAM_COUNT) {
  154. DefinitionArray[Team] = NULL;
  155. }
  156. return ;
  157. }
  158. ///////////////////////////////////////////////////////////////////////////////////////////
  159. //
  160. // Get_Class_ID
  161. //
  162. ///////////////////////////////////////////////////////////////////////////////////////////
  163. uint32
  164. TeamPurchaseSettingsDefClass::Get_Class_ID (void) const
  165. {
  166. return CLASSID_GLOBAL_SETTINGS_DEF_TEAM_PURCHASE;
  167. }
  168. ///////////////////////////////////////////////////////////////////////////////////////////
  169. //
  170. // Get_Factory
  171. //
  172. ///////////////////////////////////////////////////////////////////////////////////////////
  173. const PersistFactoryClass &
  174. TeamPurchaseSettingsDefClass::Get_Factory (void) const
  175. {
  176. return _TeamPurchaseDefPersistFactory;
  177. }
  178. ///////////////////////////////////////////////////////////////////////////////////////////
  179. //
  180. // Create
  181. //
  182. ///////////////////////////////////////////////////////////////////////////////////////////
  183. PersistClass *
  184. TeamPurchaseSettingsDefClass::Create (void) const
  185. {
  186. WWASSERT (0);
  187. return NULL;
  188. }
  189. ///////////////////////////////////////////////////////////////////////////////////////////
  190. //
  191. // Save
  192. //
  193. ///////////////////////////////////////////////////////////////////////////////////////////
  194. bool
  195. TeamPurchaseSettingsDefClass::Save (ChunkSaveClass &csave)
  196. {
  197. csave.Begin_Chunk (CHUNKID_PARENT);
  198. DefinitionClass::Save (csave);
  199. csave.End_Chunk ();
  200. csave.Begin_Chunk (CHUNKID_VARIABLES);
  201. //
  202. // Save the simple variables
  203. //
  204. WRITE_MICRO_CHUNK (csave, VARID_TEAM, Team);
  205. WRITE_MICRO_CHUNK (csave, VARID_BEACON_DEFINITION, BeaconDefinitionID);
  206. WRITE_MICRO_CHUNK (csave, VARID_BEACON_NAME, BeaconNameID);
  207. WRITE_MICRO_CHUNK (csave, VARID_BEACON_COST, BeaconCost);
  208. WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_BEACON_TEXTURE_NAME, BeaconTextureName);
  209. WRITE_MICRO_CHUNK (csave, VARID_SUPPLY_NAME, SupplyNameID);
  210. WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_SUPPLY_TEXTURE_NAME, SupplyTextureName);
  211. //
  212. // Save the lists
  213. //
  214. for (int index = 0; index < MAX_ENTRIES; index ++) {
  215. WRITE_MICRO_CHUNK (csave, VARID_INDEX, index);
  216. WRITE_MICRO_CHUNK (csave, VARID_DEFINITION, DefinitionList[index]);
  217. WRITE_MICRO_CHUNK (csave, VARID_NAME, NameList[index]);
  218. WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_TEXTURE_NAME, TextureList[index]);
  219. }
  220. csave.End_Chunk();
  221. return true;
  222. }
  223. ///////////////////////////////////////////////////////////////////////////////////////////
  224. //
  225. // Load
  226. //
  227. ///////////////////////////////////////////////////////////////////////////////////////////
  228. bool
  229. TeamPurchaseSettingsDefClass::Load (ChunkLoadClass &cload)
  230. {
  231. while (cload.Open_Chunk ()) {
  232. switch(cload.Cur_Chunk_ID ()) {
  233. case CHUNKID_PARENT:
  234. DefinitionClass::Load (cload);
  235. break;
  236. case CHUNKID_VARIABLES:
  237. Load_Variables (cload);
  238. break;
  239. default:
  240. Debug_Say(("Unhandled Chunk:%d File:%s Line:%d\r\n",cload.Cur_Chunk_ID(),__FILE__,__LINE__));
  241. break;
  242. }
  243. cload.Close_Chunk();
  244. }
  245. return true;
  246. }
  247. ///////////////////////////////////////////////////////////////////////////////////////////
  248. //
  249. // Load_Variables
  250. //
  251. ///////////////////////////////////////////////////////////////////////////////////////////
  252. void
  253. TeamPurchaseSettingsDefClass::Load_Variables (ChunkLoadClass &cload)
  254. {
  255. int entry_index = 0;
  256. while (cload.Open_Micro_Chunk ()) {
  257. switch(cload.Cur_Micro_Chunk_ID ()) {
  258. //
  259. // Read the type and team information
  260. //
  261. READ_MICRO_CHUNK (cload, VARID_TEAM, Team);
  262. READ_MICRO_CHUNK (cload, VARID_BEACON_DEFINITION, BeaconDefinitionID);
  263. READ_MICRO_CHUNK (cload, VARID_BEACON_NAME, BeaconNameID);
  264. READ_MICRO_CHUNK (cload, VARID_BEACON_COST, BeaconCost);
  265. READ_MICRO_CHUNK_WWSTRING (cload, VARID_BEACON_TEXTURE_NAME, BeaconTextureName);
  266. READ_MICRO_CHUNK (cload, VARID_SUPPLY_NAME, SupplyNameID);
  267. READ_MICRO_CHUNK_WWSTRING (cload, VARID_SUPPLY_TEXTURE_NAME, SupplyTextureName);
  268. //
  269. // Read the current list entry
  270. //
  271. READ_MICRO_CHUNK (cload, VARID_INDEX, entry_index);
  272. case VARID_DEFINITION:
  273. if (entry_index >= 0 && entry_index < MAX_ENTRIES) {
  274. LOAD_MICRO_CHUNK (cload, DefinitionList[entry_index]);
  275. }
  276. break;
  277. case VARID_NAME:
  278. if (entry_index >= 0 && entry_index < MAX_ENTRIES) {
  279. LOAD_MICRO_CHUNK (cload, NameList[entry_index]);
  280. }
  281. break;
  282. case VARID_TEXTURE_NAME:
  283. if (entry_index >= 0 && entry_index < MAX_ENTRIES) {
  284. LOAD_MICRO_CHUNK_WWSTRING (cload, TextureList[entry_index]);
  285. }
  286. break;
  287. default:
  288. Debug_Say (("Unhandled Micro Chunk:%d File:%s Line:%d\r\n", cload.Cur_Micro_Chunk_ID (), __FILE__, __LINE__));
  289. break;
  290. }
  291. cload.Close_Micro_Chunk();
  292. }
  293. //
  294. // Add this definition to the static array
  295. //
  296. if (Team < TEAM_COUNT) {
  297. DefinitionArray[Team] = this;
  298. }
  299. return ;
  300. }
  301. ///////////////////////////////////////////////////////////////////////////////////////////
  302. //
  303. // Get_Enlisted_Name
  304. //
  305. ///////////////////////////////////////////////////////////////////////////////////////////
  306. const WCHAR *
  307. TeamPurchaseSettingsDefClass::Get_Enlisted_Name (int index)
  308. {
  309. const WCHAR *retval = NULL;
  310. //
  311. // Return the translated string...
  312. //
  313. if (index >= 0 && index < MAX_ENTRIES && NameList[index] != 0) {
  314. retval = TRANSLATE (NameList[index]);
  315. }
  316. return retval;
  317. }
  318. ///////////////////////////////////////////////////////////////////////////////////////////
  319. //
  320. // Get_Definition
  321. //
  322. ///////////////////////////////////////////////////////////////////////////////////////////
  323. TeamPurchaseSettingsDefClass *
  324. TeamPurchaseSettingsDefClass::Get_Definition (TEAM team)
  325. {
  326. return DefinitionArray[team];
  327. }