bones.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Combat/bones.cpp $*
  25. * *
  26. * $Author:: Greg_h $*
  27. * *
  28. * $Modtime:: 6/14/02 10:41a $*
  29. * *
  30. * $Revision:: 8 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "bones.h"
  36. #include "debug.h"
  37. #include "assets.h"
  38. #include "wwstring.h"
  39. #include "stl.h"
  40. static bool _BonesMangerInitted = false;
  41. /*
  42. **
  43. */
  44. class BoneDataClass {
  45. public:
  46. BoneDataClass( const char * screen_name, float damage_scale ) :
  47. ScreenName( screen_name ), DamageScale( damage_scale ) {}
  48. StringClass ScreenName;
  49. float DamageScale;
  50. };
  51. typedef std::map< StringClass , BoneDataClass * > BoneMapper;
  52. BoneMapper BoneMap;
  53. /*
  54. ** Database Loading
  55. */
  56. #define BONES_INI_FILENAME "BONES.INI"
  57. #define SECTION_LIST "Bones_List"
  58. #define ENTRY_NAME "Name"
  59. #define ENTRY_SCREEN_NAME "ScreenName"
  60. #define ENTRY_DAMAGE_SCALE "DamageScale"
  61. void Load_Bones( void )
  62. {
  63. INIClass * bonesINI = Get_INI( BONES_INI_FILENAME );
  64. if (bonesINI != NULL) {
  65. WWASSERT( bonesINI && bonesINI->Section_Count() > 0 );
  66. int count = bonesINI->Entry_Count( SECTION_LIST ); // Load gang list
  67. for ( int entry = 0; entry < count; entry++ ) {
  68. char name[80];
  69. char screen_name[80];
  70. char section_name[80];
  71. bonesINI->Get_String( SECTION_LIST, bonesINI->Get_Entry( SECTION_LIST, entry),
  72. "", section_name, sizeof( section_name ) );
  73. bonesINI->Get_String( section_name, ENTRY_NAME, "", name, sizeof( name ) );
  74. bonesINI->Get_String( section_name, ENTRY_SCREEN_NAME, "", screen_name, sizeof( screen_name ) );
  75. float damage_scale = bonesINI->Get_Float( section_name, ENTRY_DAMAGE_SCALE, 1.0 );
  76. BoneMap[ name ] = new BoneDataClass( screen_name, damage_scale );
  77. // Debug_Say(( "Add bone %s %s %f\n", name, screen_name, damage_scale ));
  78. }
  79. Release_INI( bonesINI );
  80. } else {
  81. Debug_Say(("Load_Bones - Unable to load %s\n", BONES_INI_FILENAME));
  82. }
  83. }
  84. /*
  85. **
  86. */
  87. void BonesManager::Init( void )
  88. {
  89. if (_BonesMangerInitted) {
  90. Shutdown();
  91. }
  92. Load_Bones();
  93. _BonesMangerInitted = true;
  94. }
  95. void BonesManager::Shutdown( void )
  96. {
  97. for(BoneMapper::iterator it = BoneMap.begin(); it != BoneMap.end(); it++) {
  98. delete it->second;
  99. }
  100. BoneMap.clear();
  101. _BonesMangerInitted = false;
  102. }
  103. const char * BonesManager::Get_Bone_Screen_Name( const char * bone_name )
  104. {
  105. BoneMapper::iterator i = BoneMap.find( bone_name );
  106. if ( i != BoneMap.end() ) {
  107. return i->second->ScreenName;
  108. }
  109. return "???";
  110. }
  111. float BonesManager::Get_Bone_Damage_Scale( const char * bone_name )
  112. {
  113. StringClass bone_name_string(bone_name,true);
  114. BoneMapper::iterator i = BoneMap.find( bone_name_string );
  115. if ( i != BoneMap.end() ) {
  116. return i->second->DamageScale;
  117. }
  118. return 1.0f;
  119. }