CCINI.CPP 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484
  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/CCINI.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 : CCINI.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 05/24/96 *
  26. * *
  27. * Last Update : November 1, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * CCINIClass::Calculate_Message_Digest -- Calculate a message digest for the current databas*
  32. * CCINIClass::Get_AnimType -- Fetch an animation type number from the INI database. *
  33. * CCINIClass::Get_ArmorType -- Fetches the armor type from the INI database. *
  34. * CCINIClass::Get_Buildings -- Fetch a building bitfield from the INI database. *
  35. * CCINIClass::Get_BulletType -- Fetch the bullet identifier from the INI database. *
  36. * CCINIClass::Get_CrateType -- Fetches a crate type value from the INI database. *
  37. * CCINIClass::Get_HousesType -- Fetch a house identifier from the INI database. *
  38. * CCINIClass::Get_Lepton -- Fetches a lepton value from the INI database. *
  39. * CCINIClass::Get_MPHType -- Fetches the speed value as a number from 0 to 100. *
  40. * CCINIClass::Get_OverlayType -- Fetch the overlay identifier from the INI database. *
  41. * CCINIClass::Get_Owners -- Fetch the owners (list of house bits). *
  42. * CCINIClass::Get_SourceType -- Fetch the source (edge) type from the INI database. *
  43. * CCINIClass::Get_TerrainType -- Fetch the terrain type identifier from the INI database. *
  44. * CCINIClass::Get_TheaterType -- Fetch the theater type from the INI database. *
  45. * CCINIClass::Get_ThemeType -- Fetch the theme identifier. *
  46. * CCINIClass::Get_TriggerType -- Fetch the trigger type identifier from the INI database. *
  47. * CCINIClass::Get_Unique_ID -- Fetch a unique identifier number for the INI file. *
  48. * CCINIClass::Get_VQType -- Fetch the VQ movie identifier from the INI database. *
  49. * CCINIClass::Get_VocType -- Fetch a voc (sound effect) from the INI database. *
  50. * CCINIClass::Get_WarheadType -- Fetch the warhead type from the INI database. *
  51. * CCINIClass::Get_WeaponType -- Fetches the weapon type from the INI database. *
  52. * CCINIClass::Invalidate_Message_Digest -- Flag message digest as being invalid. *
  53. * CCINIClass::Load -- Load the INI database from the data stream specified. *
  54. * CCINIClass::Load -- Load the INI database from the file specified. *
  55. * CCINIClass::Put_AnimType -- Stores the animation identifier to the INI database. *
  56. * CCINIClass::Put_ArmorType -- Store the armor type to the INI database. *
  57. * CCINIClass::Put_Buildings -- Store a building list to the INI database. *
  58. * CCINIClass::Put_BulletType -- Store the projectile identifier into the INI database. *
  59. * CCINIClass::Put_CrateType -- Stores the crate value in the section and entry specified. *
  60. * CCINIClass::Put_HousesType -- Store a house identifier to the INI database. *
  61. * CCINIClass::Put_Lepton -- Stores a lepton value to the INI database. *
  62. * CCINIClass::Put_MPHType -- Stores the speed value to the section & entry specified. *
  63. * CCINIClass::Put_OverlayType -- Store the overlay identifier into the INI database. *
  64. * CCINIClass::Put_Owners -- Store the house bitfield to the INI database. *
  65. * CCINIClass::Put_SourceType -- Store the source (edge) identifier to the INI database. *
  66. * CCINIClass::Put_TerrainType -- Store the terrain type number to the INI database. *
  67. * CCINIClass::Put_TheaterType -- Store the theater identifier to the INI database. *
  68. * CCINIClass::Put_ThemeType -- Store the theme identifier to the INI database. *
  69. * CCINIClass::Put_TriggerType -- Store the trigger identifier to the INI database. *
  70. * CCINIClass::Put_VQType -- Store the VQ movie identifier into the INI database. *
  71. * CCINIClass::Put_VocType -- Store a sound effect identifier into the INI database. *
  72. * CCINIClass::Put_WarheadType -- Stores the warhead identifier to the INI database. *
  73. * CCINIClass::Put_WeaponType -- Store the weapon identifier to the INI database. *
  74. * CCINIClass::Save -- Pipes the INI database to the pipe specified. *
  75. * CCINIClass::Save -- Save the INI data to the file specified. *
  76. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  77. #include "function.h"
  78. /***********************************************************************************************
  79. * CCINIClass::Load -- Load the INI database from the file specified. *
  80. * *
  81. * This routine will load the database from the file specified in much the same manner *
  82. * that the INIClass load function works. However, this class will examine the message *
  83. * digest (if present) and compare it to the actual digest. If they differ, a special *
  84. * return value is used. This will allow verification of the integrity of the ini data. *
  85. * *
  86. * INPUT: file -- Reference to the file that will be read from. *
  87. * *
  88. * withdigest -- Should a message digest be examined when loaded. If there is a *
  89. * mismatch detected, then an error will be returned. *
  90. * *
  91. * OUTPUT: If the file was not read, returns 0. If the file was read ok, returns 1. If the *
  92. * file was read ok, but the digest doesn't verify, returns 2. *
  93. * *
  94. * WARNINGS: If no message digest was present in the INI file, then no verification can *
  95. * be performed. *
  96. * *
  97. * HISTORY: *
  98. * 07/03/1996 JLB : Created. *
  99. * 08/21/1996 JLB : Handles digest control. *
  100. *=============================================================================================*/
  101. bool CCINIClass::Load(FileClass & file, bool withdigest)
  102. {
  103. return(Load(FileStraw(file), withdigest));
  104. }
  105. /***********************************************************************************************
  106. * CCINIClass::Load -- Load the INI database from the data stream specified. *
  107. * *
  108. * This will load the INI database and in the process, it will fetch and verify any *
  109. * message digest present. *
  110. * *
  111. * INPUT: straw -- The data stream to fetch the INI data from. *
  112. * *
  113. * withdigest -- Should a message digest be examined when loaded. If there is a *
  114. * mismatch detected, then an error will be returned. *
  115. * *
  116. * OUTPUT: bool; Was the database loaded ok? (hack: returns "2" if digest doesn't match). *
  117. * *
  118. * WARNINGS: none *
  119. * *
  120. * HISTORY: *
  121. * 07/10/1996 JLB : Created. *
  122. * 08/21/1996 JLB : Handles message digest control. *
  123. *=============================================================================================*/
  124. int CCINIClass::Load(Straw & file, bool withdigest)
  125. {
  126. bool ok = INIClass::Load(file);
  127. Invalidate_Message_Digest();
  128. if (ok && withdigest) {
  129. /*
  130. ** If a digest is present, fetch it.
  131. */
  132. unsigned char digest[20];
  133. int len = Get_UUBlock("Digest", digest, sizeof(digest));
  134. if (len > 0) {
  135. Clear("Digest");
  136. /*
  137. ** Calculate the message digest for the INI data that was read.
  138. */
  139. Calculate_Message_Digest();
  140. /*
  141. ** If the message digests don't match, then return with the special error code.
  142. */
  143. if (memcmp(digest, Digest, sizeof(digest)) != 0) {
  144. return(2);
  145. }
  146. }
  147. }
  148. return(ok);
  149. }
  150. /***********************************************************************************************
  151. * CCINIClass::Save -- Save the INI data to the file specified. *
  152. * *
  153. * This routine will save the INI data to the file. It will add a message digest so that *
  154. * validity check can be performed when the INI data is subsequently read. *
  155. * *
  156. * INPUT: file -- Reference to the file to write the INI data to. *
  157. * *
  158. * withdigest -- Should a message digest be generated and saved with the INI *
  159. * data file? *
  160. * *
  161. * OUTPUT: bool; Was the INI data saved? *
  162. * *
  163. * WARNINGS: none *
  164. * *
  165. * HISTORY: *
  166. * 07/03/1996 JLB : Created. *
  167. * 08/21/1996 JLB : Handles message digest control. *
  168. *=============================================================================================*/
  169. int CCINIClass::Save(FileClass & file, bool withdigest) const
  170. {
  171. return(Save(FilePipe(file), withdigest));
  172. }
  173. /***********************************************************************************************
  174. * CCINIClass::Save -- Pipes the INI database to the pipe specified. *
  175. * *
  176. * This routine will pipe the INI data to the pipe segment specified. It is functionally *
  177. * the same as the save operation. A message digest is added to the output data so that *
  178. * validity check can occur during a subsequent read. *
  179. * *
  180. * INPUT: straw -- Reference to the pipe that will receive the output ini data stream. *
  181. * *
  182. * withdigest -- Should a message digest be generated and saved with the INI *
  183. * data file? *
  184. * *
  185. * OUTPUT: Returns with the number of bytes output to the pipe. *
  186. * *
  187. * WARNINGS: none *
  188. * *
  189. * HISTORY: *
  190. * 07/03/1996 JLB : Created. *
  191. * 08/21/1996 JLB : Handles message digest control. *
  192. *=============================================================================================*/
  193. int CCINIClass::Save(Pipe & pipe, bool withdigest) const
  194. {
  195. if (!withdigest) {
  196. return(INIClass::Save(pipe));
  197. }
  198. /*
  199. ** Just in case these entries are present, clear them out.
  200. */
  201. ((CCINIClass *)this)->Clear("Digest");
  202. /*
  203. ** Calculate what the new digest should be.
  204. */
  205. ((CCINIClass *)this)->Calculate_Message_Digest();
  206. /*
  207. ** Store the actual digest into the INI database.
  208. */
  209. ((CCINIClass *)this)->Put_UUBlock("Digest", Digest, sizeof(Digest));
  210. /*
  211. ** Output the database to the pipe specified.
  212. */
  213. int length = INIClass::Save(pipe);
  214. /*
  215. ** Remove the digest from the database. It shouldn't stick around as if it were real data
  216. ** since it isn't really part of the INI database proper.
  217. */
  218. ((CCINIClass *)this)->Clear("Digest");
  219. /*
  220. ** Finally, return with the total number of bytes send out the pipe.
  221. */
  222. return(length);
  223. }
  224. static inline int _Scale_To_256(int val)
  225. {
  226. val = min(val, 100);
  227. val = max(val, 0);
  228. val = ((val * 256) / 100);
  229. val = min(val, 255);
  230. return(val);
  231. }
  232. /***********************************************************************************************
  233. * CCINIClass::Get_Lepton -- Fetches a lepton value from the INI database. *
  234. * *
  235. * This routine will fetch the lepton value as if it were expressed as cells. Example; *
  236. * a value of 1 would mean 256 in leptons. *
  237. * *
  238. * INPUT: section -- The section identifier to look under. *
  239. * *
  240. * entry -- The entry identifier to find. *
  241. * *
  242. * defvalue -- The default value to use if the specified section and entry could *
  243. * not be located. *
  244. * *
  245. * OUTPUT: Returns with the lepton value of the section & entry specified. If not found, then *
  246. * the default value is returned. *
  247. * *
  248. * WARNINGS: none *
  249. * *
  250. * HISTORY: *
  251. * 07/03/1996 JLB : Created. *
  252. *=============================================================================================*/
  253. LEPTON CCINIClass::Get_Lepton(char const * section, char const * entry, LEPTON defvalue) const
  254. {
  255. fixed result = Get_Fixed(section, entry, fixed(defvalue, CELL_LEPTON_W));
  256. return(result * CELL_LEPTON_W);
  257. }
  258. /***********************************************************************************************
  259. * CCINIClass::Put_Lepton -- Stores a lepton value to the INI database. *
  260. * *
  261. * This routine will store the lepton value as if it were expressed in cells. Example; *
  262. * A lepton of 128 will be stored as ".5". *
  263. * *
  264. * INPUT: section -- The section identifier to store the value under. *
  265. * *
  266. * entry -- The entry to store the lepton value at. *
  267. * *
  268. * value -- The lepton value to store. *
  269. * *
  270. * OUTPUT: bool; Was the lepton value stored? *
  271. * *
  272. * WARNINGS: none *
  273. * *
  274. * HISTORY: *
  275. * 07/03/1996 JLB : Created. *
  276. *=============================================================================================*/
  277. bool CCINIClass::Put_Lepton(char const * section, char const * entry, LEPTON value)
  278. {
  279. return(Put_Fixed(section, entry, fixed(value, CELL_LEPTON_W)));
  280. }
  281. /***********************************************************************************************
  282. * CCINIClass::Get_MPHType -- Fetches the speed value as a number from 0 to 100. *
  283. * *
  284. * This routine will fetch the speed value as if it were expressed as a number from 0 *
  285. * to 100. The value of 100 would translate into a speed of 256 leptons per game frame. *
  286. * *
  287. * INPUT: section -- The section identifier to search for the entry under. *
  288. * *
  289. * entry -- The entry identifier to find. *
  290. * *
  291. * defvalue -- The default speed value to use if the entry could not be located. *
  292. * *
  293. * OUTPUT: Returns with the speed value. If no entry could be found, then the default value *
  294. * will be returned. *
  295. * *
  296. * WARNINGS: none *
  297. * *
  298. * HISTORY: *
  299. * 07/03/1996 JLB : Created. *
  300. *=============================================================================================*/
  301. MPHType CCINIClass::Get_MPHType(char const * section, char const * entry, MPHType defvalue) const
  302. {
  303. int val = Get_Int(section, entry, ((int)defvalue * 100) / 256);
  304. return (MPHType(_Scale_To_256(val)));
  305. }
  306. /***********************************************************************************************
  307. * CCINIClass::Put_MPHType -- Stores the speed value to the section & entry specified. *
  308. * *
  309. * Use this routine to store a speed value into the INI database. The number stored will *
  310. * be in a 0..100 format. A speed of 256 leptons per tick would be stored as 100. *
  311. * *
  312. * INPUT: section -- The section identifier to store the entry under. *
  313. * *
  314. * entry -- The entry identifier to store the speed value to. *
  315. * *
  316. * value -- The speed value to store. *
  317. * *
  318. * OUTPUT: bool; Was the speed value stored? *
  319. * *
  320. * WARNINGS: none *
  321. * *
  322. * HISTORY: *
  323. * 07/03/1996 JLB : Created. *
  324. *=============================================================================================*/
  325. bool CCINIClass::Put_MPHType(char const * section, char const * entry, MPHType value)
  326. {
  327. return(Put_Int(section, entry, ((int)value * 100) / 256));
  328. }
  329. /***********************************************************************************************
  330. * CCINIClass::Get_Owners -- Fetch the owners (list of house bits). *
  331. * *
  332. * Use this to fetch a house bit array value from the INI database. This value will be *
  333. * various bit positions set (1 << house#) for each house specified in the database. *
  334. * Houses can be specified in series by the house name separated by commas or by the *
  335. * special group names of "soviet", and "allies" to cover the houses that are members of *
  336. * these groups. *
  337. * *
  338. * INPUT: section -- The section identifier to search for the entry under. *
  339. * *
  340. * entry -- The entry identifier to search for. *
  341. * *
  342. * defvalue -- The default house bitfield to use if the entry could not be found. *
  343. * *
  344. * OUTPUT: Returns with the house bitfield value. If the entry could not be found, then the *
  345. * default value is returned. *
  346. * *
  347. * WARNINGS: none *
  348. * *
  349. * HISTORY: *
  350. * 07/03/1996 JLB : Created. *
  351. *=============================================================================================*/
  352. long CCINIClass::Get_Owners(char const * section, char const * entry, long defvalue) const
  353. {
  354. char buffer[128];
  355. long ownable = defvalue;
  356. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  357. ownable = 0;
  358. char * name = strtok(buffer, ",");
  359. while (name) {
  360. ownable |= Owner_From_Name(name);
  361. name = strtok(NULL, ",");
  362. }
  363. }
  364. return(ownable);
  365. }
  366. /***********************************************************************************************
  367. * CCINIClass::Put_Owners -- Store the house bitfield to the INI database. *
  368. * *
  369. * Use this routine to store the house bitfield data into the database. The bitfield format *
  370. * matches the format used by the Get_Owners function. Example; if both England and *
  371. * Spain were specified in the bitfield, the entry would be stored as "England,Spain". *
  372. * *
  373. * INPUT: section -- The section identifier to store the entry under. *
  374. * *
  375. * entry -- The entry identifier that is assigned the value. *
  376. * *
  377. * value -- The value to assign to the entry. *
  378. * *
  379. * OUTPUT: bool; Was the entry stored in the INI database? *
  380. * *
  381. * WARNINGS: none *
  382. * *
  383. * HISTORY: *
  384. * 07/03/1996 JLB : Created. *
  385. *=============================================================================================*/
  386. bool CCINIClass::Put_Owners(char const * section, char const * entry, long value)
  387. {
  388. char buffer[128];
  389. buffer[0] = '\0';
  390. if ((value & HOUSEF_ALLIES) == HOUSEF_ALLIES) {
  391. strcat(buffer, "allies");
  392. value &= ~HOUSEF_ALLIES;
  393. }
  394. if ((value & HOUSEF_SOVIET) == HOUSEF_SOVIET) {
  395. if (buffer[0] != '\0') {
  396. strcat(buffer, ",");
  397. }
  398. strcat(buffer, "soviet");
  399. value &= ~HOUSEF_SOVIET;
  400. }
  401. for (HousesType house = HOUSE_FIRST; house < HOUSE_COUNT; house++) {
  402. if ((value & (1 << house)) != 0) {
  403. if (buffer[0] != '\0') {
  404. strcat(buffer, ",");
  405. }
  406. strcat(buffer, HouseTypeClass::As_Reference(house).Name());
  407. }
  408. }
  409. if (buffer[0] != '\0') {
  410. return(Put_String(section, entry, buffer));
  411. }
  412. return(true);
  413. }
  414. /***********************************************************************************************
  415. * CCINIClass::Get_ArmorType -- Fetches the armor type from the INI database. *
  416. * *
  417. * This routine will fetch the armor type from the database. *
  418. * *
  419. * INPUT: section -- Identifier for the section to search for the entry under. *
  420. * *
  421. * entry -- Th identifier for the entry to search for. *
  422. * *
  423. * defvalue -- The default value to use if the entry could not be located. *
  424. * *
  425. * OUTPUT: Returns with the armor type specified in the INI database. If it could not be *
  426. * found, then the default value is returned instead. *
  427. * *
  428. * WARNINGS: none *
  429. * *
  430. * HISTORY: *
  431. * 07/03/1996 JLB : Created. *
  432. *=============================================================================================*/
  433. ArmorType CCINIClass::Get_ArmorType(char const * section, char const * entry, ArmorType defvalue) const
  434. {
  435. char buffer[128];
  436. Get_String(section, entry, ArmorName[defvalue], buffer, sizeof(buffer));
  437. return(Armor_From_Name(buffer));
  438. }
  439. /***********************************************************************************************
  440. * CCINIClass::Put_ArmorType -- Store the armor type to the INI database. *
  441. * *
  442. * Use this routine to store the specified armor type to the INI database. *
  443. * *
  444. * INPUT: section -- The section identifier to store the entry under. *
  445. * *
  446. * entry -- The entry to store the value at. *
  447. * *
  448. * value -- The value to store in the database. *
  449. * *
  450. * OUTPUT: bool; Was the entry stored in the database? *
  451. * *
  452. * WARNINGS: none *
  453. * *
  454. * HISTORY: *
  455. * 07/03/1996 JLB : Created. *
  456. *=============================================================================================*/
  457. bool CCINIClass::Put_ArmorType(char const * section, char const * entry, ArmorType value)
  458. {
  459. return(Put_String(section, entry, ArmorName[value]));
  460. }
  461. /***********************************************************************************************
  462. * CCINIClass::Get_VocType -- Fetch a voc (sound effect) from the INI database. *
  463. * *
  464. * This routine will fetch a voc number from the database. The voc number will either *
  465. * be a valid sound effect or VOC_NONE if no match could be found. *
  466. * *
  467. * INPUT: section -- Identifier for the section to search for the entry under. *
  468. * *
  469. * entry -- The entry to search for. *
  470. * *
  471. * defvalue -- The default value to return if the entry could not be located. *
  472. * *
  473. * OUTPUT: Returns with the sound effect (VocType) from the INI database. If the entry could *
  474. * not be located, then the default value is returned. *
  475. * *
  476. * WARNINGS: none *
  477. * *
  478. * HISTORY: *
  479. * 07/03/1996 JLB : Created. *
  480. *=============================================================================================*/
  481. VocType CCINIClass::Get_VocType(char const * section, char const * entry, VocType defvalue) const
  482. {
  483. char buffer[128];
  484. Get_String(section, entry, Voc_Name(defvalue), buffer, sizeof(buffer));
  485. return(Voc_From_Name(buffer));
  486. }
  487. /***********************************************************************************************
  488. * CCINIClass::Put_VocType -- Store a sound effect identifier into the INI database. *
  489. * *
  490. * Use this routine to store a voc identifier (stored a the text name of the sound) into *
  491. * the INI database. *
  492. * *
  493. * INPUT: section -- Identifier for the section to store the entry under. *
  494. * *
  495. * entry -- The entry to assign the value to. *
  496. * *
  497. * value -- The sound effect to store to the entry. *
  498. * *
  499. * OUTPUT: bool; Was the sound effect entry stored? *
  500. * *
  501. * WARNINGS: none *
  502. * *
  503. * HISTORY: *
  504. * 07/03/1996 JLB : Created. *
  505. *=============================================================================================*/
  506. bool CCINIClass::Put_VocType(char const * section, char const * entry, VocType value)
  507. {
  508. if (value == VOC_NONE) {
  509. return(Put_String(section, entry, "<none>"));
  510. }
  511. return(Put_String(section, entry, Voc_Name(value)));
  512. }
  513. /***********************************************************************************************
  514. * CCINIClass::Get_AnimType -- Fetch an animation type number from the INI database. *
  515. * *
  516. * This will fetch an AnimType number from the INI database. The anim is stored as a text *
  517. * name of the art file used for that anim. *
  518. * *
  519. * INPUT: section -- The section to search for the entry under. *
  520. * *
  521. * entry -- The entry to search for. *
  522. * *
  523. * defvalue -- The default AnimType to use if the entry could not be located. *
  524. * *
  525. * OUTPUT: Returns with the anim type specified in the database. If it could not be found, *
  526. * then the default value is returned. *
  527. * *
  528. * WARNINGS: none *
  529. * *
  530. * HISTORY: *
  531. * 07/03/1996 JLB : Created. *
  532. *=============================================================================================*/
  533. AnimType CCINIClass::Get_AnimType(char const * section, char const * entry, AnimType defvalue) const
  534. {
  535. char buffer[128];
  536. Get_String(section, entry, Anim_Name(defvalue), buffer, sizeof(buffer));
  537. return(Anim_From_Name(buffer));
  538. }
  539. /***********************************************************************************************
  540. * CCINIClass::Put_AnimType -- Stores the animation identifier to the INI database. *
  541. * *
  542. * This routine will store the animation identifier (stored as the text name of the art *
  543. * file it uses) to the INI database. *
  544. * *
  545. * INPUT: section -- The section identifier to place the entry under. *
  546. * *
  547. * entry -- The entry identifier to assign the animation number to. *
  548. * *
  549. * value -- The animation identifier to store with the entry. *
  550. * *
  551. * OUTPUT: bool; Was the animation identifier stored? *
  552. * *
  553. * WARNINGS: none *
  554. * *
  555. * HISTORY: *
  556. * 07/03/1996 JLB : Created. *
  557. *=============================================================================================*/
  558. bool CCINIClass::Put_AnimType(char const * section, char const * entry, AnimType value)
  559. {
  560. if (value == ANIM_NONE) {
  561. return(Put_String(section, entry, "<none>"));
  562. }
  563. return(Put_String(section, entry, Anim_Name(value)));
  564. }
  565. UnitType CCINIClass::Get_UnitType(char const * section, char const * entry, UnitType defvalue) const
  566. {
  567. char buffer[128];
  568. char const * def = "<none>";
  569. if (defvalue != UNIT_NONE) {
  570. def = UnitTypeClass::As_Reference(defvalue).Name();
  571. }
  572. Get_String(section, entry, def, buffer, sizeof(buffer));
  573. return(UnitTypeClass::From_Name(buffer));
  574. }
  575. bool CCINIClass::Put_UnitType(char const * section, char const * entry, UnitType value)
  576. {
  577. if (value == UNIT_NONE) {
  578. return(Put_String(section, entry, "<none>"));
  579. }
  580. return(Put_String(section, entry, UnitTypeClass::As_Reference(value).Name()));
  581. }
  582. /***********************************************************************************************
  583. * CCINIClass::Get_WeaponType -- Fetches the weapon type from the INI database. *
  584. * *
  585. * This routine will fetch the weapon type from the INI database. The weapon type is *
  586. * stored as a custom identifier string. *
  587. * *
  588. * INPUT: section -- The section identifier to search for the entry under. *
  589. * *
  590. * entry -- The entry identifier to search for. *
  591. * *
  592. * defvalue -- The default weapon value to return if the entry could not be located. *
  593. * *
  594. * OUTPUT: Returns with the weapon type specified by the entry. If the entry could not be *
  595. * found then the default value is returned. *
  596. * *
  597. * WARNINGS: none *
  598. * *
  599. * HISTORY: *
  600. * 07/03/1996 JLB : Created. *
  601. *=============================================================================================*/
  602. WeaponType CCINIClass::Get_WeaponType(char const * section, char const * entry, WeaponType defvalue) const
  603. {
  604. char buffer[128];
  605. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  606. return(Weapon_From_Name(buffer));
  607. }
  608. return(defvalue);
  609. }
  610. /***********************************************************************************************
  611. * CCINIClass::Put_WeaponType -- Store the weapon identifier to the INI database. *
  612. * *
  613. * Store the weapon identifier (as custom string name) to the INI database. *
  614. * *
  615. * INPUT: section -- Identifier for the section to store the entry under. *
  616. * *
  617. * entry -- Identifier to store the weapon identifier with. *
  618. * *
  619. * value -- The weapon identifier to store. *
  620. * *
  621. * OUTPUT: bool; Was the weapon identifier stored? *
  622. * *
  623. * WARNINGS: none *
  624. * *
  625. * HISTORY: *
  626. * 07/03/1996 JLB : Created. *
  627. *=============================================================================================*/
  628. bool CCINIClass::Put_WeaponType(char const * section, char const * entry, WeaponType value)
  629. {
  630. if (value == WEAPON_NONE) {
  631. return(Put_String(section, entry, "<none>"));
  632. }
  633. return(Put_String(section, entry, WeaponTypeClass::As_Pointer(value)->Name()));
  634. }
  635. /***********************************************************************************************
  636. * CCINIClass::Get_WarheadType -- Fetch the warhead type from the INI database. *
  637. * *
  638. * Will fetch the warhead identifier from the INI database. *
  639. * *
  640. * INPUT: section -- The identifier for the section to search for the entry under. *
  641. * *
  642. * entry -- The entry to search for. *
  643. * *
  644. * defvalue -- The default return value to use if the entry could not be located. *
  645. * *
  646. * OUTPUT: Returns with the found warhead type. If the entry could not be found then the *
  647. * default warhead value is returned. *
  648. * *
  649. * WARNINGS: none *
  650. * *
  651. * HISTORY: *
  652. * 07/03/1996 JLB : Created. *
  653. *=============================================================================================*/
  654. WarheadType CCINIClass::Get_WarheadType(char const * section, char const * entry, WarheadType defvalue) const
  655. {
  656. char buffer[128];
  657. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  658. for (WarheadType wh = WARHEAD_FIRST; wh < WARHEAD_COUNT; wh++) {
  659. if (stricmp(WarheadTypeClass::As_Pointer(wh)->Name(), buffer) == 0) {
  660. return(wh);
  661. }
  662. }
  663. }
  664. return(defvalue);
  665. }
  666. /***********************************************************************************************
  667. * CCINIClass::Put_WarheadType -- Stores the warhead identifier to the INI database. *
  668. * *
  669. * This will store the weapon identifier specified to the INI database. *
  670. * *
  671. * INPUT: section -- The section identifier to store the entry under. *
  672. * *
  673. * entry -- The entry to store the warhead identifier. *
  674. * *
  675. * value -- The warhead identifier to store. *
  676. * *
  677. * OUTPUT: bool; Was the warhead identifier stored to the database? *
  678. * *
  679. * WARNINGS: none *
  680. * *
  681. * HISTORY: *
  682. * 07/03/1996 JLB : Created. *
  683. *=============================================================================================*/
  684. bool CCINIClass::Put_WarheadType(char const * section, char const * entry, WarheadType value)
  685. {
  686. if (value == WARHEAD_NONE) {
  687. return(Put_String(section, entry, "<none>"));
  688. }
  689. return(Put_String(section, entry, WarheadTypeClass::As_Pointer(value)->Name()));
  690. }
  691. /***********************************************************************************************
  692. * CCINIClass::Get_OverlayType -- Fetch the overlay identifier from the INI database. *
  693. * *
  694. * This routine will fetch the overlay identifier from the database. *
  695. * *
  696. * INPUT: section -- Identifier for the section to search for the entry under. *
  697. * *
  698. * entry -- The entry to search for. *
  699. * *
  700. * defvalue -- The default value to use if the entry could not be located. *
  701. * *
  702. * OUTPUT: Returns with the overlay identifier found. If it could not be found, then the *
  703. * default value is returned. *
  704. * *
  705. * WARNINGS: none *
  706. * *
  707. * HISTORY: *
  708. * 07/03/1996 JLB : Created. *
  709. *=============================================================================================*/
  710. OverlayType CCINIClass::Get_OverlayType(char const * section, char const * entry, OverlayType defvalue) const
  711. {
  712. char buffer[128];
  713. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  714. return(OverlayTypeClass::From_Name(buffer));
  715. }
  716. return(defvalue);
  717. }
  718. /***********************************************************************************************
  719. * CCINIClass::Put_OverlayType -- Store the overlay identifier into the INI database. *
  720. * *
  721. * Use this routine to store the overlay identifier into the INI database. *
  722. * *
  723. * INPUT: section -- Identifier for to search for the entry under. *
  724. * *
  725. * entry -- The entry to search for. *
  726. * *
  727. * value -- The overlay type value to store with the entry. *
  728. * *
  729. * OUTPUT: bool; Was the overlay value stored? *
  730. * *
  731. * WARNINGS: none *
  732. * *
  733. * HISTORY: *
  734. * 07/03/1996 JLB : Created. *
  735. *=============================================================================================*/
  736. bool CCINIClass::Put_OverlayType(char const * section, char const * entry, OverlayType value)
  737. {
  738. assert(value != OVERLAY_NONE);
  739. return(Put_String(section, entry, OverlayTypeClass::As_Reference(value).Name()));
  740. }
  741. /***********************************************************************************************
  742. * CCINIClass::Get_BulletType -- Fetch the bullet identifier from the INI database. *
  743. * *
  744. * Use this routine to fetch the bullet type identifier from the INI database. *
  745. * *
  746. * INPUT: section -- The section identifier to search for the entry under. *
  747. * *
  748. * entry -- The entry to search for. *
  749. * *
  750. * defvalue -- The default bullet type value to return if the entry could not be *
  751. * located. *
  752. * *
  753. * OUTPUT: Returns with the bullet type identifier found. If the entry could not be found *
  754. * then the default value is returned. *
  755. * *
  756. * WARNINGS: none *
  757. * *
  758. * HISTORY: *
  759. * 07/03/1996 JLB : Created. *
  760. *=============================================================================================*/
  761. BulletType CCINIClass::Get_BulletType(char const * section, char const * entry, BulletType defvalue) const
  762. {
  763. char buffer[128];
  764. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  765. for (BulletType proj = BULLET_FIRST; proj < BULLET_COUNT; proj++) {
  766. if (stricmp(BulletTypeClass::As_Reference(proj).Name(), buffer) == 0) {
  767. // if (stricmp(ProjectileNames[proj], buffer) == 0) {
  768. return(proj);
  769. }
  770. }
  771. }
  772. return(defvalue);
  773. }
  774. /***********************************************************************************************
  775. * CCINIClass::Put_BulletType -- Store the projectile identifier into the INI database. *
  776. * *
  777. * This routine will store the projectile name (as the identifier) to the INI database. *
  778. * *
  779. * INPUT: section -- The section to store the entry under. *
  780. * *
  781. * entry -- The entry identifier to store the projectile value with. *
  782. * *
  783. * value -- The projectile identifier to store. *
  784. * *
  785. * OUTPUT: bool; Was the projectile identifier stored? *
  786. * *
  787. * WARNINGS: none *
  788. * *
  789. * HISTORY: *
  790. * 07/03/1996 JLB : Created. *
  791. *=============================================================================================*/
  792. bool CCINIClass::Put_BulletType(char const * section, char const * entry, BulletType value)
  793. {
  794. if (value == BULLET_NONE) {
  795. return(Put_String(section, entry, "<none>"));
  796. }
  797. return(Put_String(section, entry, BulletTypeClass::As_Reference(value).Name()));
  798. // return(Put_String(section, entry, ProjectileNames[value]));
  799. }
  800. /***********************************************************************************************
  801. * CCINIClass::Get_HousesType -- Fetch a house identifier from the INI database. *
  802. * *
  803. * Use this routine to fetch an individual house identifier from the INI database. This is *
  804. * somewhat similar to the Get_Owners function but is limited to a single house. *
  805. * *
  806. * INPUT: section -- Identifier for the section to search for the entry under. *
  807. * *
  808. * entry -- Identifier for the entry to search for. *
  809. * *
  810. * defvalue -- The default value to use if the entry could not be located. *
  811. * *
  812. * OUTPUT: Returns with the house identifier if it was found. If not found, then the default *
  813. * value is returned. *
  814. * *
  815. * WARNINGS: none *
  816. * *
  817. * HISTORY: *
  818. * 07/03/1996 JLB : Created. *
  819. *=============================================================================================*/
  820. HousesType CCINIClass::Get_HousesType(char const * section, char const * entry, HousesType defvalue) const
  821. {
  822. char buffer[128];
  823. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  824. return(HouseTypeClass::From_Name(buffer));
  825. }
  826. return(defvalue);
  827. }
  828. /***********************************************************************************************
  829. * CCINIClass::Put_HousesType -- Store a house identifier to the INI database. *
  830. * *
  831. * Use this routine to store the specified house identifier to the INI database. *
  832. * *
  833. * INPUT: section -- The section to store the entry under. *
  834. * *
  835. * entry -- Identifier for the entry to search for. *
  836. * *
  837. * value -- The house identifier to store in the database. *
  838. * *
  839. * OUTPUT: bool; Was the house identifier stored? *
  840. * *
  841. * WARNINGS: none *
  842. * *
  843. * HISTORY: *
  844. * 07/03/1996 JLB : Created. *
  845. *=============================================================================================*/
  846. bool CCINIClass::Put_HousesType(char const * section, char const * entry, HousesType value)
  847. {
  848. return(Put_String(section, entry, HouseTypeClass::As_Reference(value).Name()));
  849. }
  850. /***********************************************************************************************
  851. * CCINIClass::Get_VQType -- Fetch the VQ movie identifier from the INI database. *
  852. * *
  853. * Fetches the VQ movie name (identifier) from the INI database. *
  854. * *
  855. * INPUT: section -- Identifier for the section to search for the entry under. *
  856. * *
  857. * entry -- Identifier for the entry to search for. *
  858. * *
  859. * defvalue -- The default value to use if the entry could not be located. *
  860. * *
  861. * OUTPUT: Returns with the VQ movie identifier found. If the entry could not be located, *
  862. * then the default value is returned. *
  863. * *
  864. * WARNINGS: none *
  865. * *
  866. * HISTORY: *
  867. * 07/03/1996 JLB : Created. *
  868. *=============================================================================================*/
  869. VQType CCINIClass::Get_VQType(char const * section, char const * entry, VQType defvalue) const
  870. {
  871. char buffer[128];
  872. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  873. for (VQType vq = VQ_FIRST; vq < VQ_COUNT; vq++) {
  874. if (stricmp(buffer, VQName[vq]) == 0) {
  875. return(vq);
  876. }
  877. }
  878. }
  879. return(defvalue);
  880. }
  881. /***********************************************************************************************
  882. * CCINIClass::Put_VQType -- Store the VQ movie identifier into the INI database. *
  883. * *
  884. * Use this routine to store the VQ movie identifier into the INI database. *
  885. * *
  886. * INPUT: section -- The section to store the entry under. *
  887. * *
  888. * entry -- Identifier for the entry to store. *
  889. * *
  890. * value -- The VQ movie identifier to store to the INI database. *
  891. * *
  892. * OUTPUT: bool; Was the VQ identifier stored? *
  893. * *
  894. * WARNINGS: none *
  895. * *
  896. * HISTORY: *
  897. * 07/03/1996 JLB : Created. *
  898. *=============================================================================================*/
  899. bool CCINIClass::Put_VQType(char const * section, char const * entry, VQType value)
  900. {
  901. if (value == VQ_NONE) {
  902. return(Put_String(section, entry, "<none>"));
  903. }
  904. return(Put_String(section, entry, VQName[value]));
  905. }
  906. /***********************************************************************************************
  907. * CCINIClass::Get_TheaterType -- Fetch the theater type from the INI database. *
  908. * *
  909. * This will fetch the theater identifier from the INI database. *
  910. * *
  911. * INPUT: section -- Identifier for the section to search for the entry under. *
  912. * *
  913. * entry -- Identifier for the entry to search for. *
  914. * *
  915. * defvalue -- The default value to use if the entry could not be located. *
  916. * *
  917. * OUTPUT: Returns with the theater type found. If the entry could not be found, then the *
  918. * default value is returned. *
  919. * *
  920. * WARNINGS: none *
  921. * *
  922. * HISTORY: *
  923. * 07/03/1996 JLB : Created. *
  924. *=============================================================================================*/
  925. TheaterType CCINIClass::Get_TheaterType(char const * section, char const * entry, TheaterType defvalue) const
  926. {
  927. char buffer[128];
  928. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  929. return(Theater_From_Name(buffer));
  930. }
  931. return(defvalue);
  932. }
  933. /***********************************************************************************************
  934. * CCINIClass::Put_TheaterType -- Store the theater identifier to the INI database. *
  935. * *
  936. * Use this routine to store the theater name to the INI database. *
  937. * *
  938. * INPUT: section -- The section to store the entry under. *
  939. * *
  940. * entry -- Identifier for the entry to store. *
  941. * *
  942. * value -- The theater identifier to store. *
  943. * *
  944. * OUTPUT: bool; Was the theater identifier stored? *
  945. * *
  946. * WARNINGS: none *
  947. * *
  948. * HISTORY: *
  949. * 07/03/1996 JLB : Created. *
  950. *=============================================================================================*/
  951. bool CCINIClass::Put_TheaterType(char const * section, char const * entry, TheaterType value)
  952. {
  953. return(Put_String(section, entry, Theaters[value].Name));
  954. }
  955. /***********************************************************************************************
  956. * CCINIClass::Get_TriggerType -- Fetch the trigger type identifier from the INI database. *
  957. * *
  958. * This routine will fetch the trigger type identifier from the INI database. *
  959. * *
  960. * INPUT: section -- The section to search for the entry under. *
  961. * *
  962. * entry -- Identifier of the entry to search for. *
  963. * *
  964. * OUTPUT: Returns with the trigger type pointer if a match was found. No match found will *
  965. * return a NULL. *
  966. * *
  967. * WARNINGS: none *
  968. * *
  969. * HISTORY: *
  970. * 07/03/1996 JLB : Created. *
  971. *=============================================================================================*/
  972. TriggerTypeClass * CCINIClass::Get_TriggerType(char const * section, char const * entry) const
  973. {
  974. char buffer[128];
  975. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  976. return(TriggerTypeClass::From_Name(buffer));
  977. }
  978. return(NULL);
  979. }
  980. /***********************************************************************************************
  981. * CCINIClass::Put_TriggerType -- Store the trigger identifier to the INI database. *
  982. * *
  983. * This routine will store the trigger (as its name) to the INI database. *
  984. * *
  985. * INPUT: section -- The section to store the entry under. *
  986. * *
  987. * entry -- The entry name to store the trigger identifier to. *
  988. * *
  989. * value -- The trigger type to store. The trigger name will be stored. *
  990. * *
  991. * OUTPUT: bool; Was the trigger name stored? *
  992. * *
  993. * WARNINGS: none *
  994. * *
  995. * HISTORY: *
  996. * 07/03/1996 JLB : Created. *
  997. *=============================================================================================*/
  998. bool CCINIClass::Put_TriggerType(char const * section, char const * entry, TriggerTypeClass * value)
  999. {
  1000. return(Put_String(section, entry, value->Name()));
  1001. }
  1002. /***********************************************************************************************
  1003. * CCINIClass::Get_ThemeType -- Fetch the theme identifier. *
  1004. * *
  1005. * This routine will fetch the theme identifier from the INI database. *
  1006. * *
  1007. * INPUT: section -- The section to search for the entry under. *
  1008. * *
  1009. * entry -- Identifier of the entry to search for. *
  1010. * *
  1011. * defvalue -- The default theme identifier to return if the entry could not be found.*
  1012. * *
  1013. * OUTPUT: Returns with the theme identifier if it was found. If not found, then the default *
  1014. * value is returned instead. *
  1015. * *
  1016. * WARNINGS: none *
  1017. * *
  1018. * HISTORY: *
  1019. * 07/03/1996 JLB : Created. *
  1020. *=============================================================================================*/
  1021. ThemeType CCINIClass::Get_ThemeType(char const * section, char const * entry, ThemeType defvalue) const
  1022. {
  1023. char buffer[128];
  1024. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  1025. return(Theme.From_Name(buffer));
  1026. }
  1027. return(defvalue);
  1028. }
  1029. /***********************************************************************************************
  1030. * CCINIClass::Put_ThemeType -- Store the theme identifier to the INI database. *
  1031. * *
  1032. * This routine will store the specified theme identifier to the INI database. *
  1033. * *
  1034. * INPUT: section -- Identifier for the section to store the entry under. *
  1035. * *
  1036. * entry -- Identifier for the entry to store the value to. *
  1037. * *
  1038. * value -- The theme identifier to store. *
  1039. * *
  1040. * OUTPUT: bool; Was the theme identifier stored. *
  1041. * *
  1042. * WARNINGS: none *
  1043. * *
  1044. * HISTORY: *
  1045. * 07/03/1996 JLB : Created. *
  1046. *=============================================================================================*/
  1047. bool CCINIClass::Put_ThemeType(char const * section, char const * entry, ThemeType value)
  1048. {
  1049. return(Put_String(section, entry, Theme.Base_Name(value)));
  1050. }
  1051. /***********************************************************************************************
  1052. * CCINIClass::Get_SourceType -- Fetch the source (edge) type from the INI database. *
  1053. * *
  1054. * This routine will fetch the source (reinforcement edge) identifier from the INI *
  1055. * database. *
  1056. * *
  1057. * INPUT: section -- Identifier for the section that the entry will be searched under. *
  1058. * *
  1059. * entry -- Identifier for the entry that will be searched for. *
  1060. * *
  1061. * defvalue -- The default value to return if the entry could not be located. *
  1062. * *
  1063. * OUTPUT: Returns with the source type of the entry if found. If not found, then the *
  1064. * default value is returned. *
  1065. * *
  1066. * WARNINGS: none *
  1067. * *
  1068. * HISTORY: *
  1069. * 07/03/1996 JLB : Created. *
  1070. *=============================================================================================*/
  1071. SourceType CCINIClass::Get_SourceType(char const * section, char const * entry, SourceType defvalue) const
  1072. {
  1073. char buffer[128];
  1074. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  1075. return(Source_From_Name(buffer));
  1076. }
  1077. return(defvalue);
  1078. }
  1079. /***********************************************************************************************
  1080. * CCINIClass::Put_SourceType -- Store the source (edge) identifier to the INI database. *
  1081. * *
  1082. * This will store the source type (reinforcement edge) to the INI database. *
  1083. * *
  1084. * INPUT: section -- The section to store the entry under. *
  1085. * *
  1086. * entry -- Identifier of the entry to store the source identifier to. *
  1087. * *
  1088. * value -- The source (edge) value to store. *
  1089. * *
  1090. * OUTPUT: bool; Was the source identifier stored? *
  1091. * *
  1092. * WARNINGS: none *
  1093. * *
  1094. * HISTORY: *
  1095. * 07/03/1996 JLB : Created. *
  1096. *=============================================================================================*/
  1097. bool CCINIClass::Put_SourceType(char const * section, char const * entry, SourceType value)
  1098. {
  1099. return(Put_String(section, entry, SourceName[value]));
  1100. }
  1101. /***********************************************************************************************
  1102. * CCINIClass::Get_CrateType -- Fetches a crate type value from the INI database. *
  1103. * *
  1104. * This will return with the crate type specified in the INI database. *
  1105. * *
  1106. * INPUT: section -- Identifier for the section to search under. *
  1107. * *
  1108. * entry -- The entry to find the matching crate value for. *
  1109. * *
  1110. * defvalue -- The default crate value to return if the entry could not be found. *
  1111. * *
  1112. * OUTPUT: Returns with the crate type identified with the specified entry. If the entry *
  1113. * could not be located, then the default value is returned. *
  1114. * *
  1115. * WARNINGS: none *
  1116. * *
  1117. * HISTORY: *
  1118. * 08/08/1996 JLB : Created. *
  1119. *=============================================================================================*/
  1120. CrateType CCINIClass::Get_CrateType(char const * section, char const * entry, CrateType defvalue) const
  1121. {
  1122. char buffer[128];
  1123. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  1124. return(Crate_From_Name(buffer));
  1125. }
  1126. return(defvalue);
  1127. }
  1128. /***********************************************************************************************
  1129. * CCINIClass::Put_CrateType -- Stores the crate value in the section and entry specified. *
  1130. * *
  1131. * This will store the specified crate value to the section and entry specified. *
  1132. * *
  1133. * INPUT: section -- The section identifier to store the entry under. *
  1134. * *
  1135. * entry -- The entry identifier to store the crate value with. *
  1136. * *
  1137. * value -- The crate value to store. *
  1138. * *
  1139. * OUTPUT: bool; Was the crate value stored to the INI database? *
  1140. * *
  1141. * WARNINGS: none *
  1142. * *
  1143. * HISTORY: *
  1144. * 08/08/1996 JLB : Created. *
  1145. *=============================================================================================*/
  1146. bool CCINIClass::Put_CrateType(char const * section, char const * entry, CrateType value)
  1147. {
  1148. return(Put_String(section, entry, CrateNames[value]));
  1149. }
  1150. /***********************************************************************************************
  1151. * CCINIClass::Get_TerrainType -- Fetch the terrain type identifier from the INI database. *
  1152. * *
  1153. * Fetches the terrain type number from the INI database. *
  1154. * *
  1155. * INPUT: section -- The section to search for the entry under. *
  1156. * *
  1157. * entry -- Identifier for the entry to search for. *
  1158. * *
  1159. * defvalue -- The default value to use if the entry could not be located. *
  1160. * *
  1161. * OUTPUT: Returns with the terrain type if found. If the entry wasn't found, then the *
  1162. * default value will be returned. *
  1163. * *
  1164. * WARNINGS: none *
  1165. * *
  1166. * HISTORY: *
  1167. * 07/03/1996 JLB : Created. *
  1168. *=============================================================================================*/
  1169. TerrainType CCINIClass::Get_TerrainType(char const * section, char const * entry, TerrainType defvalue) const
  1170. {
  1171. char buffer[128];
  1172. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  1173. return(TerrainTypeClass::From_Name(strtok(buffer, ",")));
  1174. }
  1175. return(defvalue);
  1176. }
  1177. /***********************************************************************************************
  1178. * CCINIClass::Put_TerrainType -- Store the terrain type number to the INI database. *
  1179. * *
  1180. * This will store the terrain type identifier to the INI database. *
  1181. * *
  1182. * INPUT: section -- The section to store the entry under. *
  1183. * *
  1184. * entry -- Identifier that the terrain number will be stored to. *
  1185. * *
  1186. * value -- The terrain type identifier to store. *
  1187. * *
  1188. * OUTPUT: bool; Was the terrain identifier stored? *
  1189. * *
  1190. * WARNINGS: none *
  1191. * *
  1192. * HISTORY: *
  1193. * 07/03/1996 JLB : Created. *
  1194. *=============================================================================================*/
  1195. bool CCINIClass::Put_TerrainType(char const * section, char const * entry, TerrainType value)
  1196. {
  1197. return(Put_String(section, entry, TerrainTypeClass::As_Reference(value).Name()));
  1198. }
  1199. /***********************************************************************************************
  1200. * CCINIClass::Get_Buildings -- Fetch a building bitfield from the INI database. *
  1201. * *
  1202. * This routing will fetch the a list of buildings from the INI database. The buildings *
  1203. * are expressed as a comma separated list of building identifiers. The return value is *
  1204. * a composite of bits that represent these buildings -- one bit per building type. *
  1205. * *
  1206. * INPUT: section -- The section to search for the entry under. *
  1207. * *
  1208. * entry -- The entry to fetch the building list from. *
  1209. * *
  1210. * defvalue -- The default value to return if the section and entry could not be *
  1211. * located. *
  1212. * *
  1213. * OUTPUT: Returns with the building list (as a bitfield). If the entry could not be *
  1214. * found, the the default value is returned instead. *
  1215. * *
  1216. * WARNINGS: none *
  1217. * *
  1218. * HISTORY: *
  1219. * 07/11/1996 JLB : Created. *
  1220. *=============================================================================================*/
  1221. long CCINIClass::Get_Buildings(char const * section, char const * entry, long defvalue) const
  1222. {
  1223. char buffer[128];
  1224. long pre;
  1225. if (Get_String(section, entry, "", buffer, sizeof(buffer))) {
  1226. pre = 0;
  1227. char * token = strtok(buffer, ",");
  1228. while (token != NULL && *token != '\0') {
  1229. StructType building = BuildingTypeClass::From_Name(token);
  1230. if (building != STRUCT_NONE) {
  1231. pre |= (1L << building);
  1232. }
  1233. token = strtok(NULL, ",");
  1234. }
  1235. } else {
  1236. pre = defvalue;
  1237. }
  1238. return(pre);
  1239. }
  1240. /***********************************************************************************************
  1241. * CCINIClass::Put_Buildings -- Store a building list to the INI database. *
  1242. * *
  1243. * This will store a list of buildings to the INI database. The buildings are listed by *
  1244. * their identifier names separated by commas. *
  1245. * *
  1246. * INPUT: section -- The identifier for the section to store the entry under. *
  1247. * *
  1248. * entry -- The entry to store the building list to. *
  1249. * *
  1250. * value -- A list of buildings (in the form of a bit field -- one bit per *
  1251. * building type). *
  1252. * *
  1253. * OUTPUT: Was the building list stored to the INI file? *
  1254. * *
  1255. * WARNINGS: This is limited to the buildings that can be expressed in a bitfield long. *
  1256. * Which means, there can be only a maximum of 32 building types listed and *
  1257. * even then, the total line length generated must not exceed 128 bytes. *
  1258. * *
  1259. * HISTORY: *
  1260. * 07/11/1996 JLB : Created. *
  1261. *=============================================================================================*/
  1262. bool CCINIClass::Put_Buildings(char const * section, char const * entry, long value)
  1263. {
  1264. char buffer[128] = "";
  1265. int maxi = (32 < STRUCT_COUNT) ? 32 : STRUCT_COUNT;
  1266. for (StructType index = STRUCT_FIRST; index < maxi; index++) {
  1267. if ((value & (1L << index)) != 0) {
  1268. if (buffer[0] != '\0') {
  1269. strcat(buffer, ",");
  1270. }
  1271. strcat(buffer, BuildingTypeClass::As_Reference(index).IniName);
  1272. }
  1273. }
  1274. return(Put_String(section, entry, buffer));
  1275. }
  1276. /***********************************************************************************************
  1277. * CCINIClass::Get_Unique_ID -- Fetch a unique identifier number for the INI file. *
  1278. * *
  1279. * This is a shorthand version of the message digest. It calculates the ID number from the *
  1280. * message digest itself. *
  1281. * *
  1282. * INPUT: none *
  1283. * *
  1284. * OUTPUT: Returns with a 32 bit unique identifier number for the INI database. *
  1285. * *
  1286. * WARNINGS: Since the return value is only 32 bits, it is much less secure than the *
  1287. * complete message digest. *
  1288. * *
  1289. * HISTORY: *
  1290. * 11/01/1996 JLB : Created. *
  1291. *=============================================================================================*/
  1292. int CCINIClass::Get_Unique_ID(void) const
  1293. {
  1294. if (!IsDigestPresent) {
  1295. ((CCINIClass *)this)->Calculate_Message_Digest();
  1296. }
  1297. return(CRCEngine()(&Digest[0], sizeof(Digest)));
  1298. }
  1299. /***********************************************************************************************
  1300. * CCINIClass::Calculate_Message_Digest -- Calculate a message digest for the current database *
  1301. * *
  1302. * This will calculate a new message digest according to the current state of the INI *
  1303. * database. *
  1304. * *
  1305. * INPUT: none *
  1306. * *
  1307. * OUTPUT: none *
  1308. * *
  1309. * WARNINGS: If the database is changed in any fashion, this message digest will be rendered *
  1310. * obsolete. *
  1311. * *
  1312. * HISTORY: *
  1313. * 11/01/1996 JLB : Created. *
  1314. *=============================================================================================*/
  1315. void CCINIClass::Calculate_Message_Digest(void)
  1316. {
  1317. /*
  1318. ** Calculate the message digest for the INI data that was read.
  1319. */
  1320. SHAPipe sha;
  1321. INIClass::Save(sha);
  1322. sha.Result(Digest);
  1323. IsDigestPresent = true;
  1324. }
  1325. /***********************************************************************************************
  1326. * CCINIClass::Invalidate_Message_Digest -- Flag message digest as being invalid. *
  1327. * *
  1328. * This flags the message digest as being invalid so that it will be recalculated when *
  1329. * needed. *
  1330. * *
  1331. * INPUT: none *
  1332. * *
  1333. * OUTPUT: none *
  1334. * *
  1335. * WARNINGS: none *
  1336. * *
  1337. * HISTORY: *
  1338. * 11/01/1996 JLB : Created. *
  1339. *=============================================================================================*/
  1340. void CCINIClass::Invalidate_Message_Digest(void)
  1341. {
  1342. IsDigestPresent = false;
  1343. }