From 00313a526b64d8a11704947d312015c968dd6bbd Mon Sep 17 00:00:00 2001 From: Flugente Date: Thu, 2 Jul 2020 22:11:11 +0000 Subject: [PATCH] Minor code improvements git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@8833 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Items.cpp | 25 +++++++++++++------------ Tactical/SkillCheck.cpp | 7 +++++-- Tactical/Soldier Control.cpp | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index 69c0c2e8..bf664c27 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -2972,7 +2972,7 @@ UINT16 CalculateAmmoWeight( UINT16 usGunAmmoItem, UINT16 ubShotsLeft ) uiMinWeight = 1; } - double weight = 0.0; + double weight = 0.5; //Pulmu:To round correctly if(ubShotsLeft > 0) { @@ -2985,7 +2985,7 @@ UINT16 CalculateAmmoWeight( UINT16 usGunAmmoItem, UINT16 ubShotsLeft ) weight += (double)uiMinWeight + (( (double)ubShotsLeft / (double)Magazine[ Item[usGunAmmoItem].ubClassIndex ].ubMagSize) * ( (double)Item[usGunAmmoItem].ubWeight - (double)uiMinWeight )); } } - weight += 0.5; //Pulmu:To round correctly + return (UINT16)weight; //Pulmu end } @@ -3010,11 +3010,10 @@ UINT16 CalculateObjectWeight( OBJECTTYPE *pObject ) weight += CalculateAmmoWeight(pObject->usItem, (*pObject)[cnt]->data.ubShotsLeft); } } - else { - // Start with base weight - weight = pItem->ubWeight; - //multiply by the number of objects, can be 0 - weight *= pObject->ubNumberOfObjects; + else + { + // Start with base weight, multiply by the number of objects, can be 0 + weight = pItem->ubWeight * pObject->ubNumberOfObjects; } } else { @@ -3040,7 +3039,7 @@ UINT16 OBJECTTYPE::GetWeightOfObjectInStack(unsigned int index) UINT16 weight = pItem->ubWeight; // Are we looking at an LBENODE item? New inventory only. - if ( pItem->usItemClass == IC_LBEGEAR && IsActiveLBE( index ) && ( UsingNewInventorySystem() == true ) ) + if ( UsingNewInventorySystem() && IsActiveLBE( index ) ) { LBENODE* pLBE = GetLBEPointer( index ); if ( pLBE ) @@ -3081,8 +3080,7 @@ UINT16 OBJECTTYPE::GetWeightOfObjectInStack(unsigned int index) weight += Item[ (*this)[index]->data.gun.usGunAmmoItem ].ubWeight; } } - - if ( gGameExternalOptions.fAmmoDynamicWeight && ( pItem->camouflagekit || pItem->canteen || pItem->drugtype || pItem->foodtype || usItem == JAR_ELIXIR ) ) + else if ( gGameExternalOptions.fAmmoDynamicWeight && ( pItem->camouflagekit || pItem->canteen || pItem->drugtype || pItem->foodtype || usItem == JAR_ELIXIR ) ) { weight *= (FLOAT)( ( *this )[index] )->data.objectStatus / 100.0f; } @@ -3150,8 +3148,11 @@ UINT32 CalculateCarriedWeight( SOLDIERTYPE * pSoldier, BOOLEAN fConsiderDragging // Flugente: diseases can affect stat effectivity INT16 diseaseeffect = 0; - for ( int i = 0; i < NUM_DISEASES; ++i ) - diseaseeffect += Disease[i].sEffCarryStrength * pSoldier->GetDiseaseMagnitude( i ); + if ( gGameExternalOptions.fDisease ) + { + for ( int i = 0; i < NUM_DISEASES; ++i ) + diseaseeffect += Disease[i].sEffCarryStrength * pSoldier->GetDiseaseMagnitude( i ); + } ubStrengthForCarrying = (ubStrengthForCarrying * (100 + diseaseeffect + pSoldier->GetBackgroundValue( BG_PERC_CARRYSTRENGTH )) / 100); diff --git a/Tactical/SkillCheck.cpp b/Tactical/SkillCheck.cpp index 9456aacd..fa8f9619 100644 --- a/Tactical/SkillCheck.cpp +++ b/Tactical/SkillCheck.cpp @@ -52,8 +52,11 @@ INT16 EffectiveStrength( SOLDIERTYPE *pSoldier, BOOLEAN fTrainer ) // Flugente: diseases can affect stat effectivity INT16 diseaseeffect = 0; - for ( int i = 0; i < NUM_DISEASES; ++i ) - diseaseeffect += Disease[i].sEffStat[INFST_STR] * pSoldier->GetDiseaseMagnitude( i ); + if ( gGameExternalOptions.fDisease ) + { + for ( int i = 0; i < NUM_DISEASES; ++i ) + diseaseeffect += Disease[i].sEffStat[INFST_STR] * pSoldier->GetDiseaseMagnitude( i ); + } iEffStrength = (iEffStrength * (100 + diseaseeffect + pSoldier->GetBackgroundValue( BG_STRENGTH ))) / 100; diff --git a/Tactical/Soldier Control.cpp b/Tactical/Soldier Control.cpp index c7c29bb0..498544a5 100644 --- a/Tactical/Soldier Control.cpp +++ b/Tactical/Soldier Control.cpp @@ -11283,7 +11283,7 @@ BOOLEAN SOLDIERTYPE::InternalDoMercBattleSound( UINT8 ubBattleSoundID, INT8 bSpe } } - UINT16 soundtoplay = 1 + Random( numBattleSounds_Npc[entrynum][pSoldier->ubBattleSoundID][ubSoundID] ); + UINT32 soundtoplay = 1 + Random( numBattleSounds_Npc[entrynum][pSoldier->ubBattleSoundID][ubSoundID] ); sprintf( zFilename, "BATTLESNDS\\%s%d_%s%d", gBattleSndsNpcHelperData[entrynum].zName, pSoldier->ubBattleSoundID, gBattleSndsData[ubSoundID].zName, soundtoplay );