From 67811ac4314180a0d3227cd5f9e61609babb543a Mon Sep 17 00:00:00 2001 From: MaddMugsy Date: Fri, 4 Aug 2006 15:48:16 +0000 Subject: [PATCH] -added ammo weight fixes from Pulmu, including dynamic ammo weight option in ini file git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@401 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- GameSettings.cpp | 2 ++ GameSettings.h | 2 ++ GameVersion.cpp | 4 +-- Tactical/Items.cpp | 76 ++++++++++++++++++++++++++++++++++++++------- Tactical/Points.cpp | 5 +++ 5 files changed, 75 insertions(+), 14 deletions(-) diff --git a/GameSettings.cpp b/GameSettings.cpp index 212a786c5..b536d9cd3 100644 --- a/GameSettings.cpp +++ b/GameSettings.cpp @@ -480,6 +480,8 @@ void LoadGameExternalOptions() gGameExternalOptions.iMilitiaTrainingCost = iniReader.ReadInteger("JA2 Gameplay Settings","MILITIA_TRAINING_COST",750); gGameExternalOptions.iMinLoyaltyToTrain = iniReader.ReadInteger("JA2 Gameplay Settings","MIN_LOYALTY_TO_TRAIN",20); + //Misc + gGameExternalOptions.fAmmoDynamicWeight = iniReader.ReadBoolean("JA2 Gameplay Settings", "DYNAMIC_AMMO_WEIGHT", TRUE); //Pulmu } diff --git a/GameSettings.h b/GameSettings.h index 259b8aff4..2080b2632 100644 --- a/GameSettings.h +++ b/GameSettings.h @@ -303,6 +303,8 @@ typedef struct BOOLEAN gfHardAggressiveQueen; BOOLEAN gfInsaneAggressiveQueen; + BOOLEAN fAmmoDynamicWeight; //Pulmu + } GAME_EXTERNAL_OPTIONS; //This structure will contain general Ja2 settings NOT individual game settings. diff --git a/GameVersion.cpp b/GameVersion.cpp index d04ea034c..11009d5ce 100644 --- a/GameVersion.cpp +++ b/GameVersion.cpp @@ -23,12 +23,12 @@ INT16 zVersionLabel[256] = { L"Beta v. 0.98" }; #else //RELEASE BUILD VERSION - INT16 zVersionLabel[256] = { L"Release v1.13.400" }; + INT16 zVersionLabel[256] = { L"Release v1.13.401" }; #endif -INT8 czVersionNumber[16] = { "Build 06.08.03" }; +INT8 czVersionNumber[16] = { "Build 06.08.04" }; INT16 zTrackingNumber[16] = { L"Z" }; diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index 32c80336c..5a4a77e0d 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -2179,6 +2179,7 @@ UINT8 CalculateObjectWeight( OBJECTTYPE *pObject ) if ( pItem->ubPerPocket < 2 && pItem->usItemClass != IC_AMMO ) { + // account for any attachments for ( cnt = 0; cnt < MAX_ATTACHMENTS; cnt++ ) { @@ -2191,19 +2192,63 @@ UINT8 CalculateObjectWeight( OBJECTTYPE *pObject ) // add in weight of ammo if (Item[ pObject->usItem ].usItemClass == IC_GUN && pObject->ubGunShotsLeft > 0) { - usWeight += (INT16)((pObject->ubGunShotsLeft / Magazine[Item[pObject->usGunAmmoItem].ubClassIndex].ubMagSize ) * Item[ pObject->usGunAmmoItem ].ubWeight);//Madd: added weight allowance for ammo not being full - } - } - else if ( pItem->usItemClass == IC_AMMO )//Madd: added weight allowance for ammo not being full - { - for ( cnt = 0; cnt < MAX_OBJECTS_PER_SLOT; cnt++ ) - { - if (pObject->ubShotsLeft[cnt] > 0 ) + if( gGameExternalOptions.fAmmoDynamicWeight == TRUE ) { - usWeight += (INT16)(pObject->ubShotsLeft[cnt]/Magazine[pItem->ubClassIndex].ubMagSize) * pItem->ubWeight; + //Pulmu: + //Temporary calculation for minWeight + UINT32 uiMinWeight = (Item[ pObject->usGunAmmoItem].ubWeight / 5.0) + 0.5; + if( uiMinWeight < 1 || uiMinWeight > Item[ pObject->usGunAmmoItem].ubWeight) + { + uiMinWeight = 1; + } + + if( uiMinWeight == Item[ pObject->usGunAmmoItem].ubWeight ) + { + usWeight += uiMinWeight; + } + else + { + double weight = (double)uiMinWeight + (( (double)pObject->ubGunShotsLeft / (double)Weapon[pObject->usItem].ubMagSize) * ( (double)Item[ pObject->usGunAmmoItem].ubWeight - (double)uiMinWeight )) + 0.5; //Pulmu: Account for number of rounds left. + usWeight += (UINT16)weight; + } + } + else + { + usWeight += Item[ pObject->usGunAmmoItem ].ubWeight; } } } + else if ( pItem->usItemClass == IC_AMMO && gGameExternalOptions.fAmmoDynamicWeight == TRUE )//Pulmu: added weight allowance for ammo not being full + { + usWeight = 0; + //Temporary calculation for minWeight. 0.2*ubWeight rounded correctly + UINT32 uiMinWeight = (Item[pObject->usItem].ubWeight / 5.0) + 0.5; + //UINT32 uiMinWeight = Magazine[ Item[ pObject->usItem].ubClassIndex].ubMinWeight; //Minimum weight of magazine, now disabled because not corresponding entry in magazines.xml and weapons.h + if( uiMinWeight < 1 || uiMinWeight > Item[pObject->usItem].ubWeight) + { + uiMinWeight = 1; + } + + double weight = 0.0; + + for( cnt = 0; cnt < pObject->ubNumberOfObjects; cnt++ ) + { + if(pObject->ubShotsLeft[cnt] > 0) + { + if( uiMinWeight == Item[pObject->usItem].ubWeight ) + { + weight += (double)uiMinWeight; + } + else + { + weight += (double)uiMinWeight + (( (double)pObject->ubShotsLeft[cnt] / (double)Magazine[ Item[ pObject->usItem].ubClassIndex ].ubMagSize) * ( (double)Item[pObject->usItem].ubWeight - (double)uiMinWeight )); + } + } + } + weight += 0.5; //Pulmu:To round correctly + usWeight = (UINT16)weight; + //Pulmu end + } // make sure it really fits into that UINT8, in case we ever add anything real heavy with attachments/ammo @@ -2223,10 +2268,11 @@ UINT32 CalculateCarriedWeight( SOLDIERTYPE * pSoldier ) UINT16 usWeight; UINT8 ubStrengthForCarrying; + //Pulmu: Changes for dynamic ammo weight for( ubLoop = 0; ubLoop < NUM_INV_SLOTS; ubLoop++) { usWeight = pSoldier->inv[ubLoop].ubWeight; - if (Item[ pSoldier->inv[ubLoop].usItem ].ubPerPocket > 1) + if (Item[ pSoldier->inv[ubLoop].usItem ].ubPerPocket > 1 && (Item[ pSoldier->inv[ubLoop].usItem].usItemClass != IC_AMMO || gGameExternalOptions.fAmmoDynamicWeight == FALSE)) { // account for # of items usWeight *= pSoldier->inv[ubLoop].ubNumberOfObjects; @@ -2784,7 +2830,9 @@ BOOLEAN EmptyWeaponMagazine( OBJECTTYPE * pWeapon, OBJECTTYPE *pAmmo ) } pWeapon->ubWeight = CalculateObjectWeight( pWeapon ); - + // Pulmu bugfix: + pAmmo->ubWeight = CalculateObjectWeight( pAmmo ); + // Pulmu end: return( TRUE ); } else @@ -3755,7 +3803,9 @@ BOOLEAN PlaceObject( SOLDIERTYPE * pSoldier, INT8 bPos, OBJECTTYPE * pObj ) } ApplyEquipmentBonuses(pSoldier); - + //Pulmu bugfix + pInSlot->ubWeight = CalculateObjectWeight(pInSlot); + //Pulmu end return( TRUE ); } @@ -3768,6 +3818,8 @@ BOOLEAN InternalAutoPlaceObject( SOLDIERTYPE * pSoldier, OBJECTTYPE * pObj, BOOL // statuses of extra objects would be 0 if the # exceeds the maximum Assert( pObj->ubNumberOfObjects <= MAX_OBJECTS_PER_SLOT); + //Pulmu bugfix + pObj->ubWeight = CalculateObjectWeight( pObj); pItem = &(Item[pObj->usItem]); ubPerSlot = pItem->ubPerPocket; diff --git a/Tactical/Points.cpp b/Tactical/Points.cpp index 43e693e39..279ef2f6e 100644 --- a/Tactical/Points.cpp +++ b/Tactical/Points.cpp @@ -1629,6 +1629,11 @@ void DeductAmmo( SOLDIERTYPE *pSoldier, INT8 bInvPos ) if ( pObj->ubGunShotsLeft != 0 ) { pObj->ubGunShotsLeft--; + //Pulmu: Update weight after firing gun to account for bullets fired + if( gGameExternalOptions.fAmmoDynamicWeight == TRUE && pObj->ubGunShotsLeft > 0) + { + pSoldier->inv[HANDPOS].ubWeight = CalculateObjectWeight( &(pSoldier->inv[HANDPOS])); + } } } else