Dupe item fix when standing on terrain that won't hold items #45290
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SUMMARY: Bugfixes "Dupe item fix when standing on terrain that won't hold items"
Purpose of change
Fixes #45242
Problem was caused when trying to wear an item from an adjacent space, with a full inventory and while standing on terrain that cannot contain any items. An open window frame is this type of location.
Describe the solution
The sequence of events had a few conditions that led to the dupe bug. An attempt to wear an item would first put it in inventory. If inventory was full, it would query the player to wield it or handle it. Escaping out of this menu would wear the item anyway, and the item on the ground could not be deleted because the game assumed it would be at the player's feet, which would be impossible in this circumstance.
This fix addresses the issue by changing the player::wear() method to require an
item_location
instead of anitem
. Theitem_location
can now be deleted reliably. Also, the item is not initially placed into the player's inventory before attempting to wear it. This avoids the query menu popup to wield or handle the item while having a full inventory.Also using an autodoc to install a splint has been simplified and changed to just wear the
item
directly. Attempting to wear using anitem_location
led to an error message while having a full inventory. Since the method call had to be changed anyway due to the change in signature, I figure this is closely related to this issue and can be included in this PR.Describe alternatives you've considered
Testing
Ran full test: no problems found.
With full inventory and also with plenty of inventory space, using steps outlined in issue above (window not available for autodoc):
Backpack: worn with no duplicate, error message, or popup.
Assorted clothing items: worn with no duplicate, popup, or error message
Autodoc install of splint: splint is worn with no duplicate, error message, or popup.
Install splint manually: splint is worn with no duplicate, error message, or popup.
Additional context
I had to change the parameter
item_location
to pass by value instead of by reference due to clang complaining about rvalue. Another option would have been to make it a const reference but that would have made deleting the item_location impossible.