HDATA.CPP 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/HDATA.CPP 1 3/03/97 10:24a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** 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 ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : HDATA.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : May 22, 1994 *
  26. * *
  27. * Last Update : September 4, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * HouseTypeClass::As_Reference -- Fetches a reference to the house specified. *
  32. * HouseTypeClass::From_Name -- Fetch house pointer from its name. *
  33. * HouseTypeClass::HouseTypeClass -- Constructor for house type objects. *
  34. * HouseTypeClass::Init_Heap -- Allocate all heap objects for the house types. *
  35. * HouseTypeClass::One_Time -- One-time initialization *
  36. * HouseTypeClass::Read_INI -- Fetch the house control values from ini database. *
  37. * HouseTypeClass::Remap_Table -- Fetches the remap table for this house. *
  38. * HouseTypeClass::operator delete -- Returns a house type object back to the heap. *
  39. * HouseTypeClass::operator new -- Allocates a house type class object from special heap. *
  40. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  41. #include "function.h"
  42. static HouseTypeClass const HouseEngland(
  43. HOUSE_ENGLAND,
  44. "England", // NAME: House name.
  45. TXT_ENGLAND, // FULLNAME: Translated house name.
  46. "ENG", // SUFFIX: House file suffix.
  47. 0, // LEMON: Lemon vehicle frequency.
  48. PCOLOR_GREEN, // Remap color ID number.
  49. 'E' // VOICE: Voice prefix character.
  50. );
  51. static HouseTypeClass const HouseGermany(
  52. HOUSE_GERMANY,
  53. "Germany", // NAME: House name.
  54. TXT_GERMANY, // FULLNAME: Translated house name.
  55. "GER", // SUFFIX: House file suffix.
  56. 0, // LEMON: Lemon vehicle frequency.
  57. PCOLOR_GREY, // Remap color ID number.
  58. 'G' // VOICE: Voice prefix character.
  59. );
  60. static HouseTypeClass const HouseFrance(
  61. HOUSE_FRANCE,
  62. "France", // NAME: House name.
  63. TXT_FRANCE, // FULLNAME: Translated house name.
  64. "FRA", // SUFFIX: House file suffix.
  65. 0, // LEMON: Lemon vehicle frequency.
  66. PCOLOR_BLUE, // Remap color ID number.
  67. 'F' // VOICE: Voice prefix character.
  68. );
  69. static HouseTypeClass const HouseUkraine(
  70. HOUSE_UKRAINE,
  71. "Ukraine", // NAME: House name.
  72. TXT_UKRAINE, // FULLNAME: Translated house name.
  73. "UKA", // SUFFIX: House file suffix.
  74. 0, // LEMON: Lemon vehicle frequency.
  75. PCOLOR_ORANGE, // Remap color ID number.
  76. 'K' // VOICE: Voice prefix character.
  77. );
  78. static HouseTypeClass const HouseUSSR(
  79. HOUSE_USSR,
  80. "USSR", // NAME: House name.
  81. TXT_USSR, // FULLNAME: Translated house name.
  82. "RED", // SUFFIX: House file suffix.
  83. 0, // LEMON: Lemon vehicle frequency.
  84. PCOLOR_RED, // Remap color ID number.
  85. 'U' // VOICE: Voice prefix character.
  86. );
  87. static HouseTypeClass const HouseGreece(
  88. HOUSE_GREECE,
  89. "Greece", // NAME: House name.
  90. TXT_GREECE, // FULLNAME: Translated house name.
  91. "GRE", // SUFFIX: House file suffix.
  92. 0, // LEMON: Lemon vehicle frequency.
  93. PCOLOR_LTBLUE, // Remap color ID number.
  94. 'G' // VOICE: Voice prefix character.
  95. );
  96. static HouseTypeClass const HouseTurkey(
  97. HOUSE_TURKEY,
  98. "Turkey", // NAME: House name.
  99. TXT_TURKEY, // FULLNAME: Translated house name.
  100. "TRK", // SUFFIX: House file suffix.
  101. 0, // LEMON: Lemon vehicle frequency.
  102. PCOLOR_BROWN, // Remap color ID number.
  103. 'T' // VOICE: Voice prefix character.
  104. );
  105. static HouseTypeClass const HouseSpain(
  106. HOUSE_SPAIN,
  107. "Spain", // NAME: House name.
  108. TXT_SPAIN, // FULLNAME: Translated house name.
  109. "SPN", // SUFFIX: House file suffix.
  110. 0, // LEMON: Lemon vehicle frequency.
  111. PCOLOR_GOLD, // Remap color ID number.
  112. 'S' // VOICE: Voice prefix character.
  113. );
  114. static HouseTypeClass const HouseGood(
  115. HOUSE_GOOD,
  116. "GoodGuy", // NAME: House name.
  117. TXT_GOODGUY, // FULLNAME: Translated house name.
  118. "GDI", // SUFFIX: House file suffix.
  119. 0, // LEMON: Lemon vehicle frequency.
  120. PCOLOR_LTBLUE, // Remap color ID number.
  121. 'G' // VOICE: Voice prefix character.
  122. );
  123. static HouseTypeClass const HouseBad(
  124. HOUSE_BAD,
  125. "BadGuy", // NAME: House name.
  126. TXT_BADGUY, // FULLNAME: Translated house name.
  127. "NOD", // SUFFIX: House file suffix.
  128. 0, // LEMON: Lemon vehicle frequency.
  129. PCOLOR_RED, // Remap color ID number.
  130. 'B' // VOICE: Voice prefix character.
  131. );
  132. static HouseTypeClass const HouseCivilian(
  133. HOUSE_NEUTRAL,
  134. "Neutral", // NAME: House name.
  135. TXT_CIVILIAN, // FULLNAME: Translated house name.
  136. "CIV", // SUFFIX: House file suffix.
  137. 0, // LEMON: Lemon vehicle frequency.
  138. PCOLOR_GOLD, // Remap color ID number.
  139. 'C' // VOICE: Voice prefix character.
  140. );
  141. static HouseTypeClass const HouseJP(
  142. HOUSE_JP,
  143. "Special", // NAME: House name.
  144. TXT_JP, // FULLNAME: Translated house name.
  145. "JP", // SUFFIX: House file suffix.
  146. 0, // LEMON: Lemon vehicle frequency.
  147. PCOLOR_GOLD, // Remap color ID number.
  148. 'J' // VOICE: Voice prefix character.
  149. );
  150. static HouseTypeClass const HouseMulti1(
  151. HOUSE_MULTI1,
  152. "Multi1", // NAME: House name.
  153. TXT_CIVILIAN, // FULLNAME: Translated house name.
  154. "MP1", // SUFFIX: House file suffix.
  155. 0, // LEMON: Lemon vehicle frequency.
  156. PCOLOR_GOLD, // Remap color ID number.
  157. 'M' // VOICE: Voice prefix character.
  158. );
  159. static HouseTypeClass const HouseMulti2(
  160. HOUSE_MULTI2,
  161. "Multi2", // NAME: House name.
  162. TXT_CIVILIAN, // FULLNAME: Translated house name.
  163. "MP2", // SUFFIX: House file suffix.
  164. 0, // LEMON: Lemon vehicle frequency.
  165. PCOLOR_LTBLUE, // Remap color ID number.
  166. 'M' // VOICE: Voice prefix character.
  167. );
  168. static HouseTypeClass const HouseMulti3(
  169. HOUSE_MULTI3,
  170. "Multi3", // NAME: House name.
  171. TXT_CIVILIAN, // FULLNAME: Translated house name.
  172. "MP3", // SUFFIX: House file suffix.
  173. 0, // LEMON: Lemon vehicle frequency.
  174. PCOLOR_RED, // Remap color ID number.
  175. 'M' // VOICE: Voice prefix character.
  176. );
  177. static HouseTypeClass const HouseMulti4(
  178. HOUSE_MULTI4,
  179. "Multi4", // NAME: House name.
  180. TXT_CIVILIAN, // FULLNAME: Translated house name.
  181. "MP4", // SUFFIX: House file suffix.
  182. 0, // LEMON: Lemon vehicle frequency.
  183. PCOLOR_GREEN, // Remap color ID number.
  184. 'M' // VOICE: Voice prefix character.
  185. );
  186. static HouseTypeClass const HouseMulti5(
  187. HOUSE_MULTI5,
  188. "Multi5", // NAME: House name.
  189. TXT_CIVILIAN, // FULLNAME: Translated house name.
  190. "MP5", // SUFFIX: House file suffix.
  191. 0, // LEMON: Lemon vehicle frequency.
  192. PCOLOR_ORANGE, // Remap color ID number.
  193. 'M' // VOICE: Voice prefix character.
  194. );
  195. static HouseTypeClass const HouseMulti6(
  196. HOUSE_MULTI6,
  197. "Multi6", // NAME: House name.
  198. TXT_CIVILIAN, // FULLNAME: Translated house name.
  199. "MP6", // SUFFIX: House file suffix.
  200. 0, // LEMON: Lemon vehicle frequency.
  201. PCOLOR_GREY, // Remap color ID number.
  202. 'M' // VOICE: Voice prefix character.
  203. );
  204. static HouseTypeClass const HouseMulti7(
  205. HOUSE_MULTI7,
  206. "Multi7", // NAME: House name.
  207. TXT_CIVILIAN, // FULLNAME: Translated house name.
  208. "MP7", // SUFFIX: House file suffix.
  209. 0, // LEMON: Lemon vehicle frequency.
  210. PCOLOR_BLUE, // Remap color ID number.
  211. 'M' // VOICE: Voice prefix character.
  212. );
  213. static HouseTypeClass const HouseMulti8(
  214. HOUSE_MULTI8,
  215. "Multi8", // NAME: House name.
  216. TXT_CIVILIAN, // FULLNAME: Translated house name.
  217. "MP8", // SUFFIX: House file suffix.
  218. 0, // LEMON: Lemon vehicle frequency.
  219. PCOLOR_BROWN, // Remap color ID number.
  220. 'M' // VOICE: Voice prefix character.
  221. );
  222. #ifdef OBSOLETE
  223. HouseTypeClass const * const HouseTypeClass::Pointers[HOUSE_COUNT] = {
  224. &HouseSpain,
  225. &HouseGreece,
  226. &HouseUSSR,
  227. &HouseEngland,
  228. &HouseUkraine,
  229. &HouseGermany,
  230. &HouseFrance,
  231. &HouseTurkey,
  232. &HouseGood,
  233. &HouseBad,
  234. &HouseCivilian,
  235. &HouseJP,
  236. &HouseMulti1,
  237. &HouseMulti2,
  238. &HouseMulti3,
  239. &HouseMulti4,
  240. &HouseMulti5,
  241. &HouseMulti6,
  242. &HouseMulti7,
  243. &HouseMulti8,
  244. };
  245. #endif
  246. /***********************************************************************************************
  247. * HouseTypeClass::HouseTypeClass -- Constructor for house type objects. *
  248. * *
  249. * This is the constructor for house type objects. This object holds the constant data *
  250. * for the house type. *
  251. * *
  252. * INPUT: see below... *
  253. * *
  254. * OUTPUT: none *
  255. * *
  256. * WARNINGS: none *
  257. * *
  258. * HISTORY: *
  259. * 06/21/1994 JLB : Created. *
  260. *=============================================================================================*/
  261. HouseTypeClass::HouseTypeClass(
  262. HousesType house,
  263. char const * ini,
  264. int fullname,
  265. char const * ext,
  266. int lemon,
  267. PlayerColorType remapcolor,
  268. char prefix) :
  269. AbstractTypeClass(RTTI_HOUSETYPE, house, fullname, ini),
  270. // RTTI(RTTI_HOUSETYPE),
  271. // ID(house),
  272. House(house),
  273. // IniName(ini),
  274. // FullName(fullname),
  275. Lemon(lemon),
  276. RemapColor(remapcolor),
  277. Prefix(prefix),
  278. FirepowerBias(1),
  279. GroundspeedBias(1),
  280. AirspeedBias(1),
  281. ArmorBias(1),
  282. ROFBias(1),
  283. CostBias(1),
  284. BuildSpeedBias(1)
  285. {
  286. strncpy(Suffix, ext, 3);
  287. Suffix[3] = '\0';
  288. }
  289. /***********************************************************************************************
  290. * HouseTypeClass::operator new -- Allocates a house type class object from special heap. *
  291. * *
  292. * This will allocate a house type object from the special heap that is used to maintain *
  293. * objects of this type. *
  294. * *
  295. * INPUT: none *
  296. * *
  297. * OUTPUT: Returns a pointer to the newly allocated house type object. *
  298. * *
  299. * WARNINGS: If there is insufficient room, this routine may return NULL. *
  300. * *
  301. * HISTORY: *
  302. * 09/04/1996 JLB : Created. *
  303. *=============================================================================================*/
  304. void * HouseTypeClass::operator new(size_t)
  305. {
  306. return(HouseTypes.Alloc());
  307. }
  308. /***********************************************************************************************
  309. * HouseTypeClass::operator delete -- Returns a house type object back to the heap. *
  310. * *
  311. * This will return the house type object specified back into the special heap that *
  312. * is used to maintain house type objects. *
  313. * *
  314. * INPUT: ptr -- Pointer to the house type object to delete. *
  315. * *
  316. * OUTPUT: none *
  317. * *
  318. * WARNINGS: none *
  319. * *
  320. * HISTORY: *
  321. * 09/04/1996 JLB : Created. *
  322. *=============================================================================================*/
  323. void HouseTypeClass::operator delete(void * ptr)
  324. {
  325. HouseTypes.Free((HouseTypeClass *)ptr);
  326. }
  327. /***********************************************************************************************
  328. * HouseTypeClass::Init_Heap -- Allocate all heap objects for the house types. *
  329. * *
  330. * This will preallocate all the house types. They must be allocated in a particular order. *
  331. * *
  332. * INPUT: none *
  333. * *
  334. * OUTPUT: none *
  335. * *
  336. * WARNINGS: This routine should be called only once at the beginning of the game. *
  337. * *
  338. * HISTORY: *
  339. * 09/04/1996 JLB : Created. *
  340. *=============================================================================================*/
  341. void HouseTypeClass::Init_Heap(void)
  342. {
  343. /*
  344. ** These house type class objects must be allocated in the exact order that they
  345. ** are specified in the HousesType enumeration. This is necessary because the heap
  346. ** allocation block index serves double duty as the type number index.
  347. */
  348. new HouseTypeClass(HouseSpain);
  349. new HouseTypeClass(HouseGreece);
  350. new HouseTypeClass(HouseUSSR);
  351. new HouseTypeClass(HouseEngland);
  352. new HouseTypeClass(HouseUkraine);
  353. new HouseTypeClass(HouseGermany);
  354. new HouseTypeClass(HouseFrance);
  355. new HouseTypeClass(HouseTurkey);
  356. new HouseTypeClass(HouseGood);
  357. new HouseTypeClass(HouseBad);
  358. new HouseTypeClass(HouseCivilian);
  359. new HouseTypeClass(HouseJP);
  360. new HouseTypeClass(HouseMulti1);
  361. new HouseTypeClass(HouseMulti2);
  362. new HouseTypeClass(HouseMulti3);
  363. new HouseTypeClass(HouseMulti4);
  364. new HouseTypeClass(HouseMulti5);
  365. new HouseTypeClass(HouseMulti6);
  366. new HouseTypeClass(HouseMulti7);
  367. new HouseTypeClass(HouseMulti8);
  368. }
  369. /***********************************************************************************************
  370. * HouseTypeClass::From_Name -- Fetch house pointer from its name. *
  371. * *
  372. * This routine will convert the ASCII house name specified into a *
  373. * real house number. Typically, this is used when processing a *
  374. * scenario INI file. *
  375. * *
  376. * INPUT: name -- ASCII name of house to process. *
  377. * *
  378. * OUTPUT: Returns with actual house number represented by the ASCII *
  379. * name specified. *
  380. * *
  381. * WARNINGS: none *
  382. * *
  383. * HISTORY: *
  384. * 10/07/1992 JLB : Created. *
  385. * 05/21/1994 JLB : Converted to member function. *
  386. *=============================================================================================*/
  387. HousesType HouseTypeClass::From_Name(char const * name)
  388. {
  389. if (name != NULL) {
  390. for (HousesType house = HOUSE_FIRST; house < HOUSE_COUNT; house++) {
  391. if (stricmp(As_Reference(house).IniName, name) == 0) {
  392. // if (stricmp(Pointers[house]->IniName, name) == 0) {
  393. return(house);
  394. }
  395. }
  396. }
  397. return(HOUSE_NONE);
  398. }
  399. /***********************************************************************************************
  400. * HouseTypeClass::One_Time -- One-time initialization *
  401. * *
  402. * INPUT: none *
  403. * *
  404. * OUTPUT: none *
  405. * *
  406. * WARNINGS: none *
  407. * *
  408. * HISTORY: *
  409. * 05/21/1994 JLB : Converted to member function. *
  410. * 06/19/1996 JLB : Converted to regular heap class management. *
  411. *=============================================================================================*/
  412. void HouseTypeClass::One_Time(void)
  413. {
  414. }
  415. /***********************************************************************************************
  416. * HouseTypeClass::As_Reference -- Fetches a reference to the house specified. *
  417. * *
  418. * Use this routine to fetch a reference to the house number specified. *
  419. * *
  420. * INPUT: house -- The house number (HousesType) to look up. *
  421. * *
  422. * OUTPUT: Returns with a reference to the HouseTypeClass object that matches the house *
  423. * number specified. *
  424. * *
  425. * WARNINGS: none *
  426. * *
  427. * HISTORY: *
  428. * 01/23/1995 JLB : Created. *
  429. *=============================================================================================*/
  430. HouseTypeClass & HouseTypeClass::As_Reference(HousesType house)
  431. {
  432. return(*HouseTypes.Ptr(house));
  433. }
  434. /***********************************************************************************************
  435. * HouseTypeClass::Remap_Table -- Fetches the remap table for this house. *
  436. * *
  437. * Use this routine to fetch the remap table assigned to this house. The remap table is *
  438. * what gives the house's units/buildings their distinctive color. *
  439. * *
  440. * INPUT: none *
  441. * *
  442. * OUTPUT: Returns with a pointer to the remap table to use for this house. *
  443. * *
  444. * WARNINGS: none *
  445. * *
  446. * HISTORY: *
  447. * 06/03/1996 JLB : Created. *
  448. *=============================================================================================*/
  449. unsigned char const * HouseTypeClass::Remap_Table(void) const
  450. {
  451. return(ColorRemaps[RemapColor].RemapTable);
  452. }
  453. /***********************************************************************************************
  454. * HouseTypeClass::Read_INI -- Fetch the house control values from ini database. *
  455. * *
  456. * This routine will fetch the rules controllable values for the house type from the *
  457. * INI database specified. *
  458. * *
  459. * INPUT: ini -- Reference to the INI database to fetch the house control values from. *
  460. * *
  461. * OUTPUT: bool; Was the house section found and processed? *
  462. * *
  463. * WARNINGS: none *
  464. * *
  465. * HISTORY: *
  466. * 09/04/1996 JLB : Created. *
  467. *=============================================================================================*/
  468. bool HouseTypeClass::Read_INI(CCINIClass & ini)
  469. {
  470. if (ini.Is_Present(Name())) {
  471. FirepowerBias = ini.Get_Fixed(Name(), "Firepower", FirepowerBias);
  472. GroundspeedBias = ini.Get_Fixed(Name(), "Groundspeed", GroundspeedBias);
  473. AirspeedBias = ini.Get_Fixed(Name(), "Airspeed", AirspeedBias);
  474. ArmorBias = ini.Get_Fixed(Name(), "Armor", ArmorBias);
  475. ROFBias = ini.Get_Fixed(Name(), "ROF", ROFBias);
  476. CostBias = ini.Get_Fixed(Name(), "Cost", CostBias);
  477. BuildSpeedBias = ini.Get_Fixed(Name(), "BuildTime", BuildSpeedBias);
  478. return(true);
  479. }
  480. return(false);
  481. }