From 64f85b6c9b08ac5a72a0c90b92de7d94660f28d6 Mon Sep 17 00:00:00 2001 From: silversurfer Date: Sat, 11 Oct 2014 09:10:34 +0000 Subject: [PATCH] Fix (by Ocular): Removing attached grenade launchers makes their grenades vanish under NAS. This fix removes the grenades first and then the launcher. http://www.ja-galaxy-forum.com/ubbthreads.php/topics/336539/[PATCH]_Fix_missing_UGL_grenad#Post336539 git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@7550 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Strategic/Map Screen Interface Map Inventory.cpp | 10 +++++++--- Tactical/Turn Based Input.cpp | 11 ++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Strategic/Map Screen Interface Map Inventory.cpp b/Strategic/Map Screen Interface Map Inventory.cpp index 634ce2d13..10f6432fc 100644 --- a/Strategic/Map Screen Interface Map Inventory.cpp +++ b/Strategic/Map Screen Interface Map Inventory.cpp @@ -4931,11 +4931,15 @@ void SortSectorInventorySeparateAttachments() // Iterate through stacks for (int x = 0; x < pInventoryPoolList[uiLoop].object.ubNumberOfObjects; ++x) { - UINT8 cnt = 0, uiLoopCnt = 0; + UINT8 size = 0, cnt = 0, uiLoopCnt = 0; - while(pInventoryPoolList[uiLoop].object[x]->attachments.size() != cnt) + // Iterate backwards through attachments in order to detach grenades from underbarrel + // launchers before detaching the launchers (and their grenade slots) themselves. + // Since the size of the attachmentList remains constant under NAS but decrements by one + // under OAS, recheck the list size every iteration in order to calculate an rindex. + while((size = pInventoryPoolList[uiLoop].object[x]->attachments.size()) != cnt) { - gTempObject = *(pInventoryPoolList[uiLoop].object[x]->GetAttachmentAtIndex(cnt)); + gTempObject = *(pInventoryPoolList[uiLoop].object[x]->GetAttachmentAtIndex(size - 1 - cnt)); //WarmSteel - This actually still works with NAS, be it by accident if (pInventoryPoolList[uiLoop].object.RemoveAttachment(&gTempObject,0,x)) diff --git a/Tactical/Turn Based Input.cpp b/Tactical/Turn Based Input.cpp index 280adf0f2..9d01b92fe 100644 --- a/Tactical/Turn Based Input.cpp +++ b/Tactical/Turn Based Input.cpp @@ -6653,13 +6653,18 @@ void SeperateItems() // from AddItemToPool, resets gWorldItems when it increases it's size. This means // iter loses it's relationship which causes a CTD if we use this hotkey and there // aren't enough open WorldItems to accomodate all the attachments we're seperating. - UINT8 cnt = 0, uiLoopCnt = 0; + UINT8 size = 0, cnt = 0, uiLoopCnt = 0; // uiLoopCnt is an extra failsafe. I think I've already managed to eliminate the // infinite loop, but just in case, we'll use uiLoopCnt to force a break after a // certain point. - while(gWorldItems[uiLoop].object[x]->attachments.size() != cnt) + + // Iterate backwards through attachments in order to detach grenades from underbarrel + // launchers before detaching the launchers (and their grenade slots) themselves. + // Since the size of the attachmentList remains constant under NAS but decrements by one + // under OAS, recheck the list size every iteration in order to calculate an rindex. + while((size = gWorldItems[uiLoop].object[x]->attachments.size()) != cnt) { - gTempObject = *gWorldItems[uiLoop].object[x]->GetAttachmentAtIndex(cnt); + gTempObject = *gWorldItems[uiLoop].object[x]->GetAttachmentAtIndex(size - 1 - cnt); //WarmSteel - This actually still works with NAS, be it by accident if (gWorldItems[ uiLoop ].object.RemoveAttachment(&gTempObject,0,x))