purchasesettings.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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/purchasesettings.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 1/05/02 6:04p $*
  29. * *
  30. * $Revision:: 6 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "purchasesettings.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 (PurchaseSettings)
  47. ///////////////////////////////////////////////////////////////////////////////////////////
  48. // Factories
  49. ///////////////////////////////////////////////////////////////////////////////////////////
  50. SimplePersistFactoryClass<PurchaseSettingsDefClass, CHUNKID_GLOBAL_SETTINGS_DEF_PURCHASE> _PurchaseDefPersistFactory;
  51. DECLARE_DEFINITION_FACTORY(PurchaseSettingsDefClass, CLASSID_GLOBAL_SETTINGS_DEF_PURCHASE, "Purchase Settings") _PurchaseDefDefFactory;
  52. ///////////////////////////////////////////////////////////////////////////////////////////
  53. // Save/load constants
  54. ///////////////////////////////////////////////////////////////////////////////////////////
  55. enum
  56. {
  57. CHUNKID_PARENT = 0x08071203,
  58. CHUNKID_VARIABLES,
  59. VARID_TEAM = 1,
  60. VARID_TYPE,
  61. XXX_VARID_ROW,
  62. XXX_VARID_COL,
  63. VARID_COST,
  64. VARID_DEFINITION,
  65. VARID_TEXTURE_NAME,
  66. VARID_NAME,
  67. VARID_INDEX,
  68. VARID_ALT_INDEX,
  69. VARID_ALT_TEXTURE_NAME,
  70. VARID_ALT_DEFINITION
  71. };
  72. //////////////////////////////////////////////////////////////////////
  73. // Static member initialization
  74. //////////////////////////////////////////////////////////////////////
  75. PurchaseSettingsDefClass * PurchaseSettingsDefClass::DefinitionArray[TYPE_COUNT][TEAM_COUNT] = { 0 };
  76. //////////////////////////////////////////////////////////////////////
  77. //
  78. // PurchaseSettingsDefClass
  79. //
  80. //////////////////////////////////////////////////////////////////////
  81. PurchaseSettingsDefClass::PurchaseSettingsDefClass (void) :
  82. Team (TEAM_GDI),
  83. Type (TYPE_CLASSES)
  84. {
  85. //
  86. // Initialize the cost and definition lists
  87. //
  88. ::memset (CostList, 0, sizeof (CostList));
  89. ::memset (DefinitionList, 0, sizeof (DefinitionList));
  90. ::memset (NameList, 0, sizeof (NameList));
  91. ::memset (AlternateDefinitionList, 0, sizeof (AlternateDefinitionList));
  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. param1->Add_Value ("Mutant GDI", TEAM_MUTANT_GDI);
  101. param1->Add_Value ("Mutant NOD", TEAM_MUTANT_NOD);
  102. GENERIC_EDITABLE_PARAM (PurchaseSettingsDefClass, param1)
  103. EnumParameterClass *param2 = new EnumParameterClass ((int *)&Type);
  104. param2->Set_Name ("Team");
  105. param2->Add_Value ("Character Classes", TYPE_CLASSES);
  106. param2->Add_Value ("Vehicles", TYPE_VEHICLES);
  107. param2->Add_Value ("Equipment", TYPE_EQUIPMENT);
  108. param2->Add_Value ("Secret Classes", TYPE_SECRET_CLASSES);
  109. param2->Add_Value ("Secret Vehicles", TYPE_SECRET_VEHICLES);
  110. GENERIC_EDITABLE_PARAM (PurchaseSettingsDefClass, param2)
  111. #endif //PARAM_EDITING_ON
  112. //
  113. // Configure the editable system
  114. //
  115. for (int index = 0; index < MAX_ENTRIES; index ++) {
  116. //
  117. // Add a separator for this entry
  118. //
  119. StringClass name;
  120. name.Format ("Entry %d", index + 1);
  121. PARAM_SEPARATOR (PurchaseSettingsDefClass, (const char *)name);
  122. //
  123. // Add fields for the cost, texture, and object
  124. //
  125. NAMED_EDITABLE_PARAM (PurchaseSettingsDefClass, ParameterClass::TYPE_STRINGSDB_ID, NameList[index], "Name");
  126. NAMED_EDITABLE_PARAM (PurchaseSettingsDefClass, ParameterClass::TYPE_INT, CostList[index], "Cost");
  127. NAMED_EDITABLE_PARAM (PurchaseSettingsDefClass, ParameterClass::TYPE_STRING, TextureList[index], "Texture");
  128. #ifdef PARAM_EDITING_ON
  129. GenericDefParameterClass *param = new GenericDefParameterClass (&(DefinitionList[index]));
  130. param->Set_Class_ID (CLASSID_GAME_OBJECTS);
  131. param->Set_Name ("Object");
  132. GENERIC_EDITABLE_PARAM(PurchaseSettingsDefClass, param)
  133. //
  134. // Insert the alternate textures and definitions
  135. //
  136. for (int alt_index = 0; alt_index < MAX_ALTERNATES; alt_index ++) {
  137. name.Format ("Alt Texture %d", alt_index + 1);
  138. NAMED_EDITABLE_PARAM (PurchaseSettingsDefClass, ParameterClass::TYPE_STRING, AlternateTextureList[index][alt_index], name);
  139. name.Format ("Alt Object %d", alt_index + 1);
  140. GenericDefParameterClass *param = new GenericDefParameterClass (&(AlternateDefinitionList[index][alt_index]));
  141. param->Set_Class_ID (CLASSID_GAME_OBJECTS);
  142. param->Set_Name (name);
  143. GENERIC_EDITABLE_PARAM (PurchaseSettingsDefClass, param)
  144. }
  145. #endif //PARAM_EDITING_ON
  146. }
  147. return ;
  148. }
  149. //////////////////////////////////////////////////////////////////////
  150. //
  151. // ~PurchaseSettingsDefClass
  152. //
  153. //////////////////////////////////////////////////////////////////////
  154. PurchaseSettingsDefClass::~PurchaseSettingsDefClass (void)
  155. {
  156. //
  157. // Remove this entry from the static array
  158. //
  159. if (Type < TYPE_COUNT && Team < TEAM_COUNT) {
  160. DefinitionArray[Type][Team] = NULL;
  161. }
  162. return ;
  163. }
  164. ///////////////////////////////////////////////////////////////////////////////////////////
  165. //
  166. // Get_Class_ID
  167. //
  168. ///////////////////////////////////////////////////////////////////////////////////////////
  169. uint32
  170. PurchaseSettingsDefClass::Get_Class_ID (void) const
  171. {
  172. return CLASSID_GLOBAL_SETTINGS_DEF_PURCHASE;
  173. }
  174. ///////////////////////////////////////////////////////////////////////////////////////////
  175. //
  176. // Get_Factory
  177. //
  178. ///////////////////////////////////////////////////////////////////////////////////////////
  179. const PersistFactoryClass &
  180. PurchaseSettingsDefClass::Get_Factory (void) const
  181. {
  182. return _PurchaseDefPersistFactory;
  183. }
  184. ///////////////////////////////////////////////////////////////////////////////////////////
  185. //
  186. // Create
  187. //
  188. ///////////////////////////////////////////////////////////////////////////////////////////
  189. PersistClass *
  190. PurchaseSettingsDefClass::Create (void) const
  191. {
  192. WWASSERT (0);
  193. return NULL;
  194. }
  195. ///////////////////////////////////////////////////////////////////////////////////////////
  196. //
  197. // Save
  198. //
  199. ///////////////////////////////////////////////////////////////////////////////////////////
  200. bool
  201. PurchaseSettingsDefClass::Save (ChunkSaveClass &csave)
  202. {
  203. csave.Begin_Chunk (CHUNKID_PARENT);
  204. DefinitionClass::Save (csave);
  205. csave.End_Chunk ();
  206. csave.Begin_Chunk (CHUNKID_VARIABLES);
  207. //
  208. // Save the simple variables
  209. //
  210. WRITE_MICRO_CHUNK (csave, VARID_TEAM, Team);
  211. WRITE_MICRO_CHUNK (csave, VARID_TYPE, Type);
  212. //
  213. // Save the lists
  214. //
  215. for (int index = 0; index < MAX_ENTRIES; index ++) {
  216. WRITE_MICRO_CHUNK (csave, VARID_INDEX, index);
  217. WRITE_MICRO_CHUNK (csave, VARID_COST, CostList[index]);
  218. WRITE_MICRO_CHUNK (csave, VARID_DEFINITION, DefinitionList[index]);
  219. WRITE_MICRO_CHUNK (csave, VARID_NAME, NameList[index]);
  220. WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_TEXTURE_NAME, TextureList[index]);
  221. for (int alt_index = 0; alt_index < MAX_ALTERNATES; alt_index ++) {
  222. WRITE_MICRO_CHUNK (csave, VARID_ALT_INDEX, alt_index);
  223. WRITE_MICRO_CHUNK_WWSTRING (csave, VARID_ALT_TEXTURE_NAME, AlternateTextureList[index][alt_index]);
  224. WRITE_MICRO_CHUNK (csave, VARID_ALT_DEFINITION, AlternateDefinitionList[index][alt_index]);
  225. }
  226. }
  227. csave.End_Chunk();
  228. return true;
  229. }
  230. ///////////////////////////////////////////////////////////////////////////////////////////
  231. //
  232. // Load
  233. //
  234. ///////////////////////////////////////////////////////////////////////////////////////////
  235. bool
  236. PurchaseSettingsDefClass::Load (ChunkLoadClass &cload)
  237. {
  238. while (cload.Open_Chunk ()) {
  239. switch(cload.Cur_Chunk_ID ()) {
  240. case CHUNKID_PARENT:
  241. DefinitionClass::Load (cload);
  242. break;
  243. case CHUNKID_VARIABLES:
  244. Load_Variables (cload);
  245. break;
  246. default:
  247. Debug_Say(("Unhandled Chunk:%d File:%s Line:%d\r\n",cload.Cur_Chunk_ID(),__FILE__,__LINE__));
  248. break;
  249. }
  250. cload.Close_Chunk();
  251. }
  252. return true;
  253. }
  254. ///////////////////////////////////////////////////////////////////////////////////////////
  255. //
  256. // Load_Variables
  257. //
  258. ///////////////////////////////////////////////////////////////////////////////////////////
  259. void
  260. PurchaseSettingsDefClass::Load_Variables (ChunkLoadClass &cload)
  261. {
  262. int entry_index = 0;
  263. int alt_index = 0;
  264. while (cload.Open_Micro_Chunk ()) {
  265. switch(cload.Cur_Micro_Chunk_ID ()) {
  266. //
  267. // Read the type and team information
  268. //
  269. READ_MICRO_CHUNK (cload, VARID_TEAM, Team);
  270. READ_MICRO_CHUNK (cload, VARID_TYPE, Type);
  271. //
  272. // Read the current list entry
  273. //
  274. READ_MICRO_CHUNK (cload, VARID_INDEX, entry_index);
  275. READ_MICRO_CHUNK (cload, VARID_ALT_INDEX, alt_index);
  276. case VARID_COST:
  277. if (entry_index >= 0 && entry_index < MAX_ENTRIES) {
  278. LOAD_MICRO_CHUNK (cload, CostList[entry_index]);
  279. }
  280. break;
  281. case VARID_DEFINITION:
  282. if (entry_index >= 0 && entry_index < MAX_ENTRIES) {
  283. LOAD_MICRO_CHUNK (cload, DefinitionList[entry_index]);
  284. }
  285. break;
  286. case VARID_NAME:
  287. if (entry_index >= 0 && entry_index < MAX_ENTRIES) {
  288. LOAD_MICRO_CHUNK (cload, NameList[entry_index]);
  289. }
  290. break;
  291. case VARID_TEXTURE_NAME:
  292. if (entry_index >= 0 && entry_index < MAX_ENTRIES) {
  293. LOAD_MICRO_CHUNK_WWSTRING (cload, TextureList[entry_index]);
  294. }
  295. break;
  296. case VARID_ALT_DEFINITION:
  297. if (entry_index >= 0 && entry_index < MAX_ENTRIES && alt_index >= 0 && alt_index < MAX_ALTERNATES) {
  298. LOAD_MICRO_CHUNK (cload, AlternateDefinitionList[entry_index][alt_index]);
  299. }
  300. break;
  301. case VARID_ALT_TEXTURE_NAME:
  302. if (entry_index >= 0 && entry_index < MAX_ENTRIES && alt_index >= 0 && alt_index < MAX_ALTERNATES) {
  303. LOAD_MICRO_CHUNK_WWSTRING (cload, AlternateTextureList[entry_index][alt_index]);
  304. }
  305. break;
  306. default:
  307. Debug_Say (("Unhandled Micro Chunk:%d File:%s Line:%d\r\n", cload.Cur_Micro_Chunk_ID (), __FILE__, __LINE__));
  308. break;
  309. }
  310. cload.Close_Micro_Chunk();
  311. }
  312. //
  313. // Add this definition to the static array
  314. //
  315. if (Type < TYPE_COUNT && Team < TEAM_COUNT) {
  316. DefinitionArray[Type][Team] = this;
  317. }
  318. return ;
  319. }
  320. ///////////////////////////////////////////////////////////////////////////////////////////
  321. //
  322. // Get_Name
  323. //
  324. ///////////////////////////////////////////////////////////////////////////////////////////
  325. const WCHAR *
  326. PurchaseSettingsDefClass::Get_Name (int index)
  327. {
  328. const WCHAR *retval = NULL;
  329. //
  330. // Return the translated string...
  331. //
  332. if (index >= 0 && index < MAX_ENTRIES && NameList[index] != 0) {
  333. retval = TRANSLATE (NameList[index]);
  334. }
  335. return retval;
  336. }
  337. ///////////////////////////////////////////////////////////////////////////////////////////
  338. //
  339. // Find_Definition
  340. //
  341. ///////////////////////////////////////////////////////////////////////////////////////////
  342. PurchaseSettingsDefClass *
  343. PurchaseSettingsDefClass::Find_Definition (TYPE type, TEAM team)
  344. {
  345. PurchaseSettingsDefClass *retval = DefinitionArray[type][team];
  346. if (retval == NULL) {
  347. //
  348. // If the type is "secret classes" try the base classes
  349. //
  350. if (type == TYPE_SECRET_CLASSES) {
  351. type = TYPE_CLASSES;
  352. }
  353. if (type == TYPE_SECRET_VEHICLES) {
  354. type = TYPE_VEHICLES;
  355. }
  356. //
  357. // Return the "base" definition if there was no definition
  358. // for one of the mutant types
  359. //
  360. if (team == TEAM_MUTANT_GDI) {
  361. retval = DefinitionArray[type][TEAM_GDI];
  362. } else if (team == TEAM_MUTANT_NOD) {
  363. retval = DefinitionArray[type][TEAM_NOD];
  364. }
  365. }
  366. return retval;
  367. }