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