From 5758e561fd93f29f4bddba90485bb2d8fe6c39d6 Mon Sep 17 00:00:00 2001 From: Andrew James Date: Mon, 21 Oct 2024 20:59:30 +1100 Subject: [PATCH] allow auto-equipping two-handed weapons with both hands occupied specifically where the larger item is in the right hand, this would fail previously in certain circumstances. --- Source/inv.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Source/inv.cpp b/Source/inv.cpp index ba9aef94090..6a88617c86a 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -837,20 +837,25 @@ void CheckInvCut(Player &player, Point cursorPosition, bool automaticMove, bool // the left hand), invloc isn't used there. invloc = INVLOC_HAND_RIGHT; } else { - // Both hands are holding items, we must unequip the right hand item and check that there's - // space for the left before trying to auto-equip - if (!AutoPlaceItemInInventory(player, player.InvBody[INVLOC_HAND_RIGHT])) { - // No space to move right hand item to inventory, abort. - break; + // Both hands are holding items, we must unequip one of the items and check that there's + // space for the other before trying to auto-equip + inv_body_loc mainHand = INVLOC_HAND_LEFT; + inv_body_loc offHand = INVLOC_HAND_RIGHT; + if (!AutoPlaceItemInInventory(player, player.InvBody[offHand])) { + // No space to move right hand item to inventory, can we move the left instead? + std::swap(mainHand, offHand); + if (!AutoPlaceItemInInventory(player, player.InvBody[offHand])) { + break; + } } - if (!CouldFitItemInInventory(player, player.InvBody[INVLOC_HAND_LEFT], iv)) { - // No space for left item. Move back right item to right hand and abort. - player.InvBody[INVLOC_HAND_RIGHT] = player.InvList[player._pNumInv - 1]; + if (!CouldFitItemInInventory(player, player.InvBody[mainHand], iv)) { + // No space for the main hand item. Move the other item back to the off hand and abort. + player.InvBody[offHand] = player.InvList[player._pNumInv - 1]; player.RemoveInvItem(player._pNumInv - 1, false); break; } - RemoveEquipment(player, INVLOC_HAND_RIGHT, false); - invloc = INVLOC_HAND_LEFT; + RemoveEquipment(player, offHand, false); + invloc = mainHand; } break; default: