Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CR] Fix nested pockets pickup #54941

Merged
merged 13 commits into from
Feb 5, 2022

Conversation

robkuijper
Copy link
Contributor

@robkuijper robkuijper commented Jan 30, 2022

Summary

Bugfixes "Nested pickups using (g) interface"

Purpose of change

Nested pickups were not working as intended.
Looking at couple of issues, there were instances where an item was flagged as 'valid' for picking up (using (g) menu), but was not actually picked up correctly because of a mismatch of intended functionality.

Found a couple of (slightly) related issues, among others: #54725 #53807

Describe the solution

This PR looks to streamline checks between character::can_pickVolume to item::can_contain, and item::best_pocket functionality, while also using recursion to allow deeply-nested pickups (i.e. socks -> tin -> pot -> bucket -> backpack) if the volume allows for it.

Describe alternatives you've considered

A smaller fix could be made just to item::can_contain to streamline intended functionality.
Deeply nested pockets would not be possible, but items would also not be flagged as 'valid' pickup as they are now.

Testing

Thoroughly tested using different related issues as a base, namely using the attached save from #54725.
Using the save, one can play around with the different containers to see if nesting is actually working as intended.

Additional context

Trying to pickup too many items in one go is still possible, and fails silently (i.e. trying to pickup two stones, but one fails because inventory is full after picking up the first). This should still be fixed, but I thought it'd be out of scope for this 'fix'.

Removed (slightly related) code duplication between character::can_pickVolume and character::canPickVolume_partial.
Replaced contain_code for item_pocket::can_contain and item_pocket::is_compatible.

A followup issue would be solving multi-pickup cancellation due to full inventory (either prevent it, or give the player a headsup).

There are quite some discrepancies between can_contain and
best_pocket functionality. This commit looks to fix that and actually
allow nested pockets to work properly as long as there is space.
fixes CleverRaven#54725
@github-actions github-actions bot added json-styled JSON lint passed, label assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Jan 30, 2022
src/item.cpp Show resolved Hide resolved
@Maleclypse Maleclypse added <Bugfix> This is a fix for a bug (or closes open issue) Items: Containers Things that hold other things labels Jan 31, 2022
@robkuijper robkuijper marked this pull request as ready for review February 2, 2022 18:13
@github-actions github-actions bot added the astyled astyled PR, label is assigned by github actions label Feb 4, 2022
There are quite some discrepancies between can_contain and
best_pocket functionality. This commit looks to fix that and actually
allow nested pockets to work properly as long as there is space.
fixes CleverRaven#54725
@robkuijper robkuijper changed the base branch from master to fungal-spread-forever February 4, 2022 06:58
@robkuijper robkuijper changed the base branch from fungal-spread-forever to master February 4, 2022 06:58
@robkuijper
Copy link
Contributor Author

Apologies for the mess. Github does not agree with rebases on branches for existing PRs. Had to change the target branch from- and back to fix.

tests/item_pocket_test.cpp Outdated Show resolved Hide resolved
src/item_pocket.cpp Outdated Show resolved Hide resolved
tests/item_pocket_test.cpp Outdated Show resolved Hide resolved
@mqrause
Copy link
Contributor

mqrause commented Feb 4, 2022

Apologies for the mess. Github does not agree with rebases on branches for existing PRs. Had to change the target branch from- and back to fix.

You need to force push after rebasing.

tests/item_pocket_test.cpp Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) Items: Containers Things that hold other things json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants