From 5930c905853757a47d5d9c8ab60e09fe3069860b Mon Sep 17 00:00:00 2001 From: MaddMugsy Date: Thu, 17 May 2012 17:14:21 +0000 Subject: [PATCH] Fix - after merging or transforming an item, any attachments on the base item which themselves had default inseparable attachments, would see those attachments lost upon the result of the merge/transformation. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@5283 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Items.cpp | 22 +++++++++++++++------- Tactical/World Items.cpp | 1 - 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Tactical/Items.cpp b/Tactical/Items.cpp index bcbb22ad..5b430626 100644 --- a/Tactical/Items.cpp +++ b/Tactical/Items.cpp @@ -5428,7 +5428,7 @@ void ReInitMergedItem(SOLDIERTYPE* pSoldier, OBJECTTYPE* pObj, UINT16 usOldItem, for(UINT16 cnt = 0; cnt < MAX_DEFAULT_ATTACHMENTS && Item[pObj->usItem].defaultattachments[cnt] != 0; cnt++){ //Only add inseparable default attachments, because they are likely "part" of the gun. if(Item[Item[pObj->usItem].defaultattachments[cnt]].inseparable == 1){ - static OBJECTTYPE defaultAttachment; + OBJECTTYPE defaultAttachment; CreateItem(Item [ pObj->usItem ].defaultattachments[cnt],(*pObj)[ubStatusIndex]->data.objectStatus,&defaultAttachment); AssertMsg(pObj->AttachObject(NULL,&defaultAttachment, FALSE, ubStatusIndex, -1, FALSE), "A default attachment could not be attached after merging, this should not be possible."); } @@ -5438,7 +5438,9 @@ void ReInitMergedItem(SOLDIERTYPE* pSoldier, OBJECTTYPE* pObj, UINT16 usOldItem, for (attachmentList::iterator iter = tempSlotChangingAttachList.begin(); iter != tempSlotChangingAttachList.end();) { if( ValidItemAttachmentSlot(pObj, iter->usItem, TRUE, FALSE, ubStatusIndex )){ //This seems to be rather valid. Can't be 100% sure though. - if(pObj->AttachObject(NULL, &(*iter), FALSE, ubStatusIndex)){ + OBJECTTYPE tempAttachment; // Madd: we must recreate the attachments because they may themselves have default inseparable attachments... + CreateItem(iter->usItem, (*iter)[0]->data.objectStatus, &tempAttachment); + if(pObj->AttachObject(NULL, &tempAttachment, FALSE, ubStatusIndex)){ //Ok now we can be sure, lets remove this object so we don't try to drop it later. iter = tempSlotChangingAttachList.erase(iter); } else { @@ -5453,7 +5455,9 @@ void ReInitMergedItem(SOLDIERTYPE* pSoldier, OBJECTTYPE* pObj, UINT16 usOldItem, for (attachmentList::iterator iter = tempAttachList.begin(); iter != tempAttachList.end();) { if( ValidItemAttachmentSlot(pObj, iter->usItem, TRUE, FALSE, ubStatusIndex)){ //This seems to be rather valid. Can't be 100% sure though. - if(pObj->AttachObject(NULL, &(*iter), FALSE, ubStatusIndex)){ + OBJECTTYPE tempAttachment; // Madd: we must recreate the attachments because they may themselves have default inseparable attachments... + CreateItem(iter->usItem, (*iter)[0]->data.objectStatus, &tempAttachment); + if(pObj->AttachObject(NULL, &tempAttachment, FALSE, ubStatusIndex)){ //Ok now we can be sure, lets remove this object so we don't try to drop it later. iter = tempAttachList.erase(iter); } else { @@ -5469,10 +5473,12 @@ void ReInitMergedItem(SOLDIERTYPE* pSoldier, OBJECTTYPE* pObj, UINT16 usOldItem, if ( Item[iter->usItem].inseparable != 1) {//WarmSteel - Couldn't re-attach this item, try to drop it. if (pSoldier) { - if ( !AutoPlaceObject( pSoldier, &(*iter), FALSE ) ) + OBJECTTYPE tempAttachment; // Madd: we must recreate the attachments because they may themselves have default inseparable attachments... + CreateItem(iter->usItem, (*iter)[0]->data.objectStatus, &tempAttachment); + if ( !AutoPlaceObject( pSoldier, &tempAttachment, FALSE ) ) { // put it on the ground // HEADROCK HAM 5: A much more suitable function. Works in both tactical and mapscreen! - AutoPlaceObjectToWorld( pSoldier, &(*iter), true ); + AutoPlaceObjectToWorld( pSoldier, &tempAttachment, true ); //AddItemToPool( pSoldier->sGridNo, &(*iter), 1, pSoldier->pathing.bLevel, 0 , -1 ); } } @@ -5483,10 +5489,12 @@ void ReInitMergedItem(SOLDIERTYPE* pSoldier, OBJECTTYPE* pObj, UINT16 usOldItem, if ( Item[iter->usItem].inseparable != 1) {//WarmSteel - Couldn't re-attach this item, try to drop it. if (pSoldier) { - if ( !AutoPlaceObject( pSoldier, &(*iter), FALSE ) ) + OBJECTTYPE tempAttachment; // Madd: we must recreate the attachments because they may themselves have default inseparable attachments... + CreateItem(iter->usItem, (*iter)[0]->data.objectStatus, &tempAttachment); + if ( !AutoPlaceObject( pSoldier, &tempAttachment, FALSE ) ) { // put it on the ground // HEADROCK HAM 5: A much more suitable function. Works in both tactical and mapscreen! - AutoPlaceObjectToWorld( pSoldier, &(*iter), true ); + AutoPlaceObjectToWorld( pSoldier, &tempAttachment, true ); //AddItemToPool( pSoldier->sGridNo, &(*iter), 1, pSoldier->pathing.bLevel, 0 , -1 ); } } diff --git a/Tactical/World Items.cpp b/Tactical/World Items.cpp index a0bef163..a91c8bee 100644 --- a/Tactical/World Items.cpp +++ b/Tactical/World Items.cpp @@ -682,7 +682,6 @@ void LoadWorldItemsFromMap( INT8 **hBuffer, float dMajorMapVersion, int ubMinorM if(Item [ dummyItem.object.usItem ].defaultattachments[cnt] == 0) break; - //cannot use gTempObject OBJECTTYPE defaultAttachment; CreateItem(Item [ dummyItem.object.usItem ].defaultattachments[cnt],100,&defaultAttachment); dummyItem.object.AttachObject(NULL,&defaultAttachment, FALSE);