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

Fix eating from vehicle #25017

Merged
merged 5 commits into from Aug 23, 2018
Merged

Conversation

alanbrady
Copy link
Contributor

@alanbrady alanbrady commented Aug 21, 2018

The problem is when dragging around a shopping cart and eating some food
from a non-resealable container, the game just puts the newly unsealed
tin can back in the cart. Putting an opened bucket/non-resealable
container back into a vehicle causes the contents to then spill. This
is almost certainly not what the player wanted.

This fixes the issue by using the same check used in put_into_vehicle()
to put potentially spillable things into vehicles. To avoid code
duplication this puts the needed functionality into its own function into
pickup.h/cpp and refactors put_into_vehicle() to use the new function.

As a side affect, this fixes the player being able to have spillable buckets in
their inventory if they start as sealed and become unsealed.

A future fix should probably add the option to wield the container directly
as well.

Fixes #18168

SUMMARY: Bugfixes "Fix eating from tin cans from a vehicle"

The problem is when dragging around a shopping cart and eating some food
from a non-resealable container, the game just puts the newly unsealed
tin can back in the cart.  Putting an opened bucket/non-resealable
container back into a vehicle causes the contents to then spill.  This
is almost certainly not what the player wanted.

This fixes the issue by using the same check used in put_into_vehicle()
to put potentially spillable things into vehicles.  To avoid code
duplication this puts the needed functionality into its own function in
the item class and refactors put_into_vehicle() to use the new function.

Fixes CleverRaven#18168
src/item.cpp Outdated
@@ -4139,6 +4139,21 @@ const item &item::get_contained() const
return contents.front();
}

bool item::handle_spillable_contents( player &p )
{
if( is_bucket_nonempty() && !spill_contents( p ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excessive space before &&.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good eye

src/item.cpp Outdated
@@ -4139,6 +4139,21 @@ const item &item::get_contained() const
return contents.front();
}

bool item::handle_spillable_contents( player &p )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be made a free function bool handle_spillable_contents( player &p, item &it) since item functions is_bucket_nonempty and spill_contents are publicly accessible. This does not need to be a member function.

@alanbrady
Copy link
Contributor Author

alanbrady commented Aug 21, 2018

Hrm just did some more testing and I seem to have broke something in put_into_vehicle, will check it out. Nevermind

@alanbrady alanbrady changed the title Fix eating from vehicle [WIP] Fix eating from vehicle Aug 21, 2018
@alanbrady alanbrady changed the title [WIP] Fix eating from vehicle Fix eating from vehicle Aug 21, 2018
@alanbrady alanbrady force-pushed the fix-soup-eating branch 2 times, most recently from 44f8a9d to e10a835 Compare August 21, 2018 18:02
@ZhilkinSerg ZhilkinSerg merged commit cf1a229 into CleverRaven:master Aug 23, 2018
alanbrady added a commit to alanbrady/Cataclysm-DDA that referenced this pull request Aug 24, 2018
PR CleverRaven#25017 broke using aluminum cans and caused a duplication bug when
eating from tin cans from inventory.

This fixes it by adjusting the placement of the call to
handle_spillable_contents() to a more appropriate place in the flow
of consuming an item.  We also check if handle_spillable_content handled
our comestible or not.  If it did we need to remove it from inventory.
kevingranade pushed a commit that referenced this pull request Aug 24, 2018
PR #25017 broke using aluminum cans and caused a duplication bug when
eating from tin cans from inventory.

This fixes it by adjusting the placement of the call to
handle_spillable_contents() to a more appropriate place in the flow
of consuming an item.  We also check if handle_spillable_content handled
our comestible or not.  If it did we need to remove it from inventory.
@alanbrady alanbrady deleted the fix-soup-eating branch September 5, 2018 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'E'ating soup from a tin located in a dragged shopping cart dumps the remainder of the soup on the floor.
4 participants