From b643ddc7f3de89a77990b7514baaf1f796d29a81 Mon Sep 17 00:00:00 2001 From: Flugente Date: Sun, 18 Aug 2013 14:31:55 +0000 Subject: [PATCH] Fix: nada items or CTD when 'move item' assignment takes items from a sector that is currently loaded in tactical. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6288 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Strategic/Assignments.cpp | 44 ++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/Strategic/Assignments.cpp b/Strategic/Assignments.cpp index 6fd77fb43..9577ac800 100644 --- a/Strategic/Assignments.cpp +++ b/Strategic/Assignments.cpp @@ -6002,6 +6002,12 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ ) pWorldItem_Target[ uiCount ].fExists = FALSE; + // if the sector is currently loaded, we need to also remove items from item pools + if( ( gWorldSectorX == targetX )&&( gWorldSectorY == targetY ) && (gbWorldSectorZ == bZ ) ) + { + RemoveItemFromPool(pWorldItem_Target[ uiCount ].sGridNo, uiCount, pWorldItem_Target[ uiCount ].ubLevel); + } + if ( moveditems > maxitems ) break; @@ -6040,28 +6046,32 @@ void HandleEquipmentMove( INT16 sMapX, INT16 sMapY, INT8 bZ ) if ( !moveditems ) continue; - // hack - WORLDITEM* pWorldItem_tmp = new WORLDITEM[ uiTotalNumberOfRealItems_Target ]; - - // copy over old inventory - UINT32 newcount = 0; - for( UINT32 uiCount = 0; uiCount < uiTotalNumberOfRealItems_Target; ++uiCount ) + // if the sector we took stuff from isn't loaded, do a resort, otherwise the item list will have holes (linked lists have to be rebuilt) + WORLDITEM* pWorldItem_tmp = NULL; + if( ( gWorldSectorX != targetX ) || ( gWorldSectorY != targetY ) || (gbWorldSectorZ != bZ ) ) { - if ( pWorldItem_Target[ uiCount ].fExists ) + pWorldItem_tmp = new WORLDITEM[ uiTotalNumberOfRealItems_Target ]; + + // copy over old inventory + UINT32 newcount = 0; + for( UINT32 uiCount = 0; uiCount < uiTotalNumberOfRealItems_Target; ++uiCount ) { - pWorldItem_tmp[newcount] = pWorldItem_Target[uiCount]; - ++newcount; + if ( pWorldItem_Target[ uiCount ].fExists ) + { + pWorldItem_tmp[newcount] = pWorldItem_Target[uiCount]; + ++newcount; + } } - } - // use the new map - if ( pWorldItem_Target ) - { - delete[] pWorldItem_Target; - pWorldItem_Target = NULL; - } + // use the new map + if ( pWorldItem_Target ) + { + delete[] pWorldItem_Target; + pWorldItem_Target = NULL; + } - pWorldItem_Target = pWorldItem_tmp; + pWorldItem_Target = pWorldItem_tmp; + } // save the changed inventory if( ( targetX == gWorldSectorX )&&( gWorldSectorY == targetY ) && (gbWorldSectorZ == bZ ) )