Ensure that casings are stackable #45746
Merged
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 "Ensure that casings are stackable (fixes pickup performance issues)"
Purpose of change
Fix #44469.
The problem is two-fold:
Character::drop_invalid_inventory()
Describe the solution
This PR addresses only the first issue. I made all currently existing casings stackable and added a unit test to (hopefully) ensure that all casings added in the future are also stackable.
The downside of this fix is that already disassembled ammo is still saved as individual items and will be slow to pick up. However, I think the issue is uncommon enough to bother with adding any kind of migration.
Describe alternatives you've considered
Alternative would be to address second part of the problem: inventory speed. Unfortunately, fixing that is by no means trivial. There is an ongoing discussion regarding some of the ways such improvements could be done.
Testing
Added unit test, verified that it was failing before the change and succeeds after.
Loaded the save file from #44469, disassembled .22 ammo into the stack of 4000+, picked it up instantaneously.
Additional context
After:
![pick_up2](https://user-images.githubusercontent.com/2865203/100683842-02989b80-332e-11eb-862c-2b916a07385c.gif)