inventory.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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/inventory.cpp $*
  25. * *
  26. * $Author:: Byon_g $*
  27. * *
  28. * $Modtime:: 8/15/01 11:37a $*
  29. * *
  30. * $Revision:: 4 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "inventory.h"
  36. #include "debug.h"
  37. #include "soldier.h"
  38. #include "weaponbag.h"
  39. #include "weapons.h"
  40. /*
  41. **
  42. */
  43. InventoryClass::InventoryClass( void )
  44. {
  45. Reset();
  46. }
  47. /*
  48. **
  49. */
  50. InventoryClass::~InventoryClass( void )
  51. {
  52. }
  53. /*
  54. **
  55. */
  56. void InventoryClass::Reset( void )
  57. {
  58. while ( WeaponAmmoList.Count() != 0 ) {
  59. WeaponAmmoList.Delete( 0 );
  60. }
  61. ShieldType = 0;
  62. ShieldStrength = 0.0f;
  63. ShieldStrengthMax = 0.0f;
  64. Health = 0.0f;
  65. HealthMax = 0.0f;
  66. }
  67. /*
  68. **
  69. */
  70. void InventoryClass::Store_Inventory( SoldierGameObj * soldier )
  71. {
  72. Reset();
  73. WWASSERT( soldier );
  74. ShieldType = soldier->Get_Defense_Object()->Get_Shield_Type();
  75. ShieldStrength = soldier->Get_Defense_Object()->Get_Shield_Strength();
  76. ShieldStrengthMax = soldier->Get_Defense_Object()->Get_Shield_Strength_Max();
  77. Health = soldier->Get_Defense_Object()->Get_Health();
  78. HealthMax = soldier->Get_Defense_Object()->Get_Health_Max();
  79. soldier->Get_Weapon_Bag()->Store_Inventory( this );
  80. }
  81. /*
  82. **
  83. */
  84. void InventoryClass::Add_Weapon( int id, int rounds, bool has_weapon )
  85. {
  86. WeaponAmmo entry;
  87. entry.WeaponID = id;
  88. entry.AmmoCount = rounds;
  89. entry.HasWeapon = has_weapon;
  90. WeaponAmmoList.Add( entry );
  91. }
  92. /*
  93. **
  94. */
  95. void InventoryClass::Restore_Inventory( SoldierGameObj * soldier )
  96. {
  97. DefenseObjectClass * def_obj = soldier->Get_Defense_Object();
  98. if ( (unsigned long)ShieldType > def_obj->Get_Shield_Type() ) {
  99. def_obj->Set_Shield_Type( ShieldType );
  100. }
  101. if ( ShieldStrengthMax > def_obj->Get_Shield_Strength_Max() ) {
  102. def_obj->Set_Shield_Strength_Max( ShieldStrengthMax );
  103. }
  104. if ( ShieldStrength > def_obj->Get_Shield_Strength() ) {
  105. def_obj->Set_Shield_Strength( ShieldStrength );
  106. }
  107. if ( HealthMax > def_obj->Get_Health_Max() ) {
  108. def_obj->Set_Health_Max( HealthMax );
  109. }
  110. if ( Health > def_obj->Get_Health() ) {
  111. def_obj->Set_Health( Health );
  112. }
  113. WeaponBagClass * bag = soldier->Get_Weapon_Bag();
  114. for ( int i = 0; i < WeaponAmmoList.Count(); i++ ) {
  115. const WeaponAmmo & entry = WeaponAmmoList[i];
  116. WeaponClass * weapon = bag->Add_Weapon( entry.WeaponID, 0, entry.HasWeapon );
  117. if ( entry.AmmoCount == -1 ) {
  118. weapon->Add_Rounds( -1 );
  119. } else if ( weapon->Get_Total_Rounds() < entry.AmmoCount ) {
  120. weapon->Add_Rounds( entry.AmmoCount - weapon->Get_Total_Rounds() );
  121. }
  122. }
  123. }