From 56c6f4d9eb093f35e40c4bd63d099d2ee3c51868 Mon Sep 17 00:00:00 2001 From: MaddMugsy Date: Fri, 18 Aug 2006 18:16:38 +0000 Subject: [PATCH] -additional code for item merges: --prohibited attachments are removed from the new item --guns used as a merge target have their ammo removed if the magazine size or caliber don't match, or if the resulting item is no longer a gun This code change should allow for conversion kits for weapons (ie: Steyr Aug 5.56mm conversion kit to 9mm Steyr Aug Para) git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@455 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Items.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index 224aac05..f8a40443 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -3337,6 +3337,45 @@ BOOLEAN AttachObject( SOLDIERTYPE * pSoldier, OBJECTTYPE * pTargetObj, OBJECTTYP StatChange( pSoldier, WISDOMAMT, 5, FALSE ); } + //Madd: unload guns after merge if ammo caliber or mag size don't match + if ( Item[pTargetObj->usItem].usItemClass == IC_GUN && pTargetObj->usGunAmmoItem != NONE && pTargetObj->ubGunShotsLeft > 0 ) + { + if ( Item[usResult].usItemClass != IC_GUN || Weapon[Item[usResult].ubClassIndex].ubCalibre != Weapon[Item[pTargetObj->usItem].ubClassIndex].ubCalibre || pTargetObj->ubGunShotsLeft > Weapon[Item[usResult].ubClassIndex].ubMagSize ) + { // item types/calibers/magazines don't match, spit out old ammo + OBJECTTYPE newObj; + CreateItem(pTargetObj->usGunAmmoItem, 100, &newObj); + newObj.ubShotsLeft[0] = pTargetObj->ubGunShotsLeft; + pTargetObj->ubGunShotsLeft = 0; + pTargetObj->usGunAmmoItem = NONE; + if ( !AutoPlaceObject( pSoldier, &newObj, FALSE ) ) + { // put it on the ground + AddItemToPool( pSoldier->sGridNo, &newObj, 1, pSoldier->bLevel, 0 , -1 ); + } + } + } + + //Madd: remove any prohibited attachments + for (bAttachPos = 0; bAttachPos < MAX_ATTACHMENTS; bAttachPos++) + { + if (pTargetObj->usAttachItem[ bAttachPos ] != NOTHING && !ValidAttachment(pTargetObj->usAttachItem[ bAttachPos ],usResult) && !ValidLaunchable(pTargetObj->usAttachItem[ bAttachPos ],usResult) ) + { + if ( !Item[pTargetObj->usAttachItem[ bAttachPos ]].inseparable ) + {//remove it + OBJECTTYPE newObj; + RemoveAttachment(pTargetObj,bAttachPos,&newObj); + if ( !AutoPlaceObject( pSoldier, &newObj, FALSE ) ) + { // put it on the ground + AddItemToPool( pSoldier->sGridNo, &newObj, 1, pSoldier->bLevel, 0 , -1 ); + } + } + else + {//destroy it + pTargetObj->usAttachItem[bAttachPos] = NOTHING; + pTargetObj->bAttachStatus[bAttachPos] = 0; + } + } + } + pTargetObj->usItem = usResult; //AutoPlaceObject( pAttachment ); pTargetObj->ubWeight = CalculateObjectWeight( pTargetObj ); @@ -3423,6 +3462,46 @@ BOOLEAN AttachObject( SOLDIERTYPE * pSoldier, OBJECTTYPE * pTargetObj, OBJECTTYP // fall through default: // the merge will combine the two items + + //Madd: unload guns after merge if ammo caliber or mag size don't match + if ( Item[pTargetObj->usItem].usItemClass == IC_GUN && pTargetObj->usGunAmmoItem != NONE && pTargetObj->ubGunShotsLeft > 0 ) + { + if ( Item[usResult].usItemClass != IC_GUN || Weapon[Item[usResult].ubClassIndex].ubCalibre != Weapon[Item[pTargetObj->usItem].ubClassIndex].ubCalibre || pTargetObj->ubGunShotsLeft > Weapon[Item[usResult].ubClassIndex].ubMagSize ) + { // item types/calibers/magazines don't match, spit out old ammo + OBJECTTYPE newObj; + CreateItem(pTargetObj->usGunAmmoItem, 100, &newObj); + newObj.ubShotsLeft[0] = pTargetObj->ubGunShotsLeft; + pTargetObj->ubGunShotsLeft = 0; + pTargetObj->usGunAmmoItem = NONE; + if ( !AutoPlaceObject( pSoldier, &newObj, FALSE ) ) + { // put it on the ground + AddItemToPool( pSoldier->sGridNo, &newObj, 1, pSoldier->bLevel, 0 , -1 ); + } + } + } + + //Madd: remove any prohibited attachments + for (bAttachPos = 0; bAttachPos < MAX_ATTACHMENTS; bAttachPos++) + { + if (pTargetObj->usAttachItem[ bAttachPos ] != NOTHING && !ValidAttachment(pTargetObj->usAttachItem[ bAttachPos ],usResult) && !ValidLaunchable(pTargetObj->usAttachItem[ bAttachPos ],usResult) ) + { + if ( !Item[pTargetObj->usAttachItem[ bAttachPos ]].inseparable ) + {//remove it + OBJECTTYPE newObj; + RemoveAttachment(pTargetObj,bAttachPos,&newObj); + if ( !AutoPlaceObject( pSoldier, &newObj, FALSE ) ) + { // put it on the ground + AddItemToPool( pSoldier->sGridNo, &newObj, 1, pSoldier->bLevel, 0 , -1 ); + } + } + else + {//destroy it + pTargetObj->usAttachItem[bAttachPos] = NOTHING; + pTargetObj->bAttachStatus[bAttachPos] = 0; + } + } + } + pTargetObj->usItem = usResult; if ( ubType != TREAT_ARMOUR ) {