| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** Confidential - Westwood Studios ***
- ***********************************************************************************************
- * *
- * Project Name : Commando *
- * *
- * $Archive:: /Commando/Code/Combat/inventory.cpp $*
- * *
- * $Author:: Byon_g $*
- * *
- * $Modtime:: 8/15/01 11:37a $*
- * *
- * $Revision:: 4 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "inventory.h"
- #include "debug.h"
- #include "soldier.h"
- #include "weaponbag.h"
- #include "weapons.h"
- /*
- **
- */
- InventoryClass::InventoryClass( void )
- {
- Reset();
- }
- /*
- **
- */
- InventoryClass::~InventoryClass( void )
- {
- }
- /*
- **
- */
- void InventoryClass::Reset( void )
- {
- while ( WeaponAmmoList.Count() != 0 ) {
- WeaponAmmoList.Delete( 0 );
- }
- ShieldType = 0;
- ShieldStrength = 0.0f;
- ShieldStrengthMax = 0.0f;
- Health = 0.0f;
- HealthMax = 0.0f;
- }
- /*
- **
- */
- void InventoryClass::Store_Inventory( SoldierGameObj * soldier )
- {
- Reset();
- WWASSERT( soldier );
- ShieldType = soldier->Get_Defense_Object()->Get_Shield_Type();
- ShieldStrength = soldier->Get_Defense_Object()->Get_Shield_Strength();
- ShieldStrengthMax = soldier->Get_Defense_Object()->Get_Shield_Strength_Max();
- Health = soldier->Get_Defense_Object()->Get_Health();
- HealthMax = soldier->Get_Defense_Object()->Get_Health_Max();
- soldier->Get_Weapon_Bag()->Store_Inventory( this );
- }
- /*
- **
- */
- void InventoryClass::Add_Weapon( int id, int rounds, bool has_weapon )
- {
- WeaponAmmo entry;
- entry.WeaponID = id;
- entry.AmmoCount = rounds;
- entry.HasWeapon = has_weapon;
- WeaponAmmoList.Add( entry );
- }
- /*
- **
- */
- void InventoryClass::Restore_Inventory( SoldierGameObj * soldier )
- {
- DefenseObjectClass * def_obj = soldier->Get_Defense_Object();
- if ( (unsigned long)ShieldType > def_obj->Get_Shield_Type() ) {
- def_obj->Set_Shield_Type( ShieldType );
- }
- if ( ShieldStrengthMax > def_obj->Get_Shield_Strength_Max() ) {
- def_obj->Set_Shield_Strength_Max( ShieldStrengthMax );
- }
- if ( ShieldStrength > def_obj->Get_Shield_Strength() ) {
- def_obj->Set_Shield_Strength( ShieldStrength );
- }
- if ( HealthMax > def_obj->Get_Health_Max() ) {
- def_obj->Set_Health_Max( HealthMax );
- }
- if ( Health > def_obj->Get_Health() ) {
- def_obj->Set_Health( Health );
- }
- WeaponBagClass * bag = soldier->Get_Weapon_Bag();
- for ( int i = 0; i < WeaponAmmoList.Count(); i++ ) {
- const WeaponAmmo & entry = WeaponAmmoList[i];
- WeaponClass * weapon = bag->Add_Weapon( entry.WeaponID, 0, entry.HasWeapon );
- if ( entry.AmmoCount == -1 ) {
- weapon->Add_Rounds( -1 );
- } else if ( weapon->Get_Total_Rounds() < entry.AmmoCount ) {
- weapon->Add_Rounds( entry.AmmoCount - weapon->Get_Total_Rounds() );
- }
- }
- }
|