CCINI.CPP 100 KB

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