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

Allow player to pick up frozen liquids #32763

Merged
merged 19 commits into from Aug 16, 2019

Conversation

EddiTheBambi
Copy link
Contributor

@EddiTheBambi EddiTheBambi commented Jul 30, 2019

Summary

SUMMARY: Features "Allow player to pick up and handle frozen liquids"

Purpose of change

Closes #28638 - Players should be able to chip or crush ice or other frozen liquids and pick them up and keep them in their inventory as long as they're frozen since they're technically solid.

Describe the solution

  • Allows picking up liquids with the FROZEN tag

  • Checks if player has a hammering implement to chip the frozen liquid with

  • Frozen liquid can be stored in a container, carried away and melted

  • Advanced inventory handling

  • Chipping frozen liquids from a toilet should sometimes lead to breaking said toilet. - suggestion by @FuelType-Memes: Performing single (s)mash on tile using hammering item used when picking up frozen liquid risking breakage of fragile furniture or items sharing the tile, Chipping with sledgehammer is riskier, logically

  • Drop liquid upon melting outside of a container

  • Error message - frozen fruit juice is not ammo

  • Prompt for crush on attempting reload with frozen liquid and stop player from reloading frozen liquid from container

Describe alternatives you've considered

  • Only allow this for toilets and tanks (main use)
  • Not allow at all

Additional context

bild
bild
bild
bild
bild

Players should be able to chip or crush ice or other frozen liquids
and pick them up and keep them in their inventory as long as they're
frozen
@EddiTheBambi EddiTheBambi changed the title Allow player to pick up frozen liquids [WIP]Allow player to pick up frozen liquids Jul 30, 2019
@Hirmuolio
Copy link
Contributor

Can the picked frozen liquid be larger than one charge?

Large frozen items would probably behave a bit strange. They would stay frozen until the whole thing is liquid and then suddenly go all at once.

Multiple separate frozen items (that may stack) wouldn't have this problem.

Alternatively some melting handling could be made so that as the item melts the melting part is removed from the frozen item. (containers with mixed frozen-liquid contents would be pretty cool too)

@EddiTheBambi
Copy link
Contributor Author

Can the picked frozen liquid be larger than one charge?

Yes, it's handled through the [g]et menu for now with ability to select number of charges like usual, will need to add a case for [/]advanced inventory as well.

Large frozen items would probably behave a bit strange. They would stay frozen until the whole thing is liquid and then suddenly go all at once.

Multiple separate frozen items (that may stack) wouldn't have this problem.

Alternatively some melting handling could be made so that as the item melts the melting part is removed from the frozen item. (containers with mixed frozen-liquid contents would be pretty cool too)

This could potentially be done by extracting one charge, erasing FROZEN tag from it and decreasing the temperature of the original item by a few degrees whenever it rises above melting point. This should work for containers too. There might be issues with that approach that I haven't considered but it was the first thing I could come up with. I'll update the PR with this.

@EddiTheBambi EddiTheBambi changed the title [WIP]Allow player to pick up frozen liquids [WIP]Frozen liquid overhaul Jul 30, 2019
@EddiTheBambi EddiTheBambi changed the title [WIP]Frozen liquid overhaul [WIP]Allow player to pick up frozen liquids Jul 30, 2019
@EddiTheBambi
Copy link
Contributor Author

Partial melting and other features will be part of a larger project concerning frozen liquids and will be handled in separate PRs

@nexusmrsep
Copy link
Contributor

I believe that liquids that you'd pick that way should be also flagged DIRTY in the process. I can't imagine chipping away on frozen soda spilt on the ground, without it getting dirt, dust etc. Mixed up with it.

That said, the melting mechanic will be very important as a foundation for later implementation of freezing bodies of water and snow gathering in winter.

@EddiTheBambi
Copy link
Contributor Author

should be also flagged DIRTY in the process

Not all liquids (e.g. water from a toilet) should be dirty when chipped. The application of the DIRTY tag already happens as soon as a comestible liquid is spilt on the ground, however not all liquids get this tag. Perhaps that functionality should be added to things like gasoline if it is indeed possible to get it cold enough to freeze it, chip it and pick it up. This does require a small change to make it unusable as fuel for vehicles however.

@FuelType-Memes
Copy link
Contributor

Chipping frozen liquids from a toilet should sometimes lead to breaking said toilet. Swinging a hammer near ceramics is nonono

Player can't scoop up solid ice with their hands, need something to chip off chunks with
Missed astyle in last commit
Used default astyle options previously
@Hirmuolio
Copy link
Contributor

While the partial melting comes later I'll just give the rough math for it now. It is suprisingly simple actually.

Basics:

  • Check when part of interesting size has melted.
  • Energy is split between the parts.
  • Temperature stays constant. We don't need to calculate it at all.

Freeze percentage is already calculated in the code.

freeze_percentage = ( completely_liquid_specific_energy - new_specific_energy ) / ( completely_liquid_specific_energy - completely_frozen_specific_energy );

Currently at 50% is the cutoff at which melting/freezing happens for the whole item. With partial melting the cutoff would be based on the number of units of parts in item. For example item with 10 parts you would want to remove one liquid part at 90% freeze_percentage.

The removed part would be 100% liquid at freeze temperature. So its specific energy would be:
melted_part_liquid_specific_energy = completely_frozen_specific_energy + latent_heat
(completely_frozen_specific_energy is just specific_heat_solid * freezing_temperature)

The remaining part would probably be a bit less than 100% frozen so some more math would be needed.
frozen_part_specific_energy = ( before_split_specific_energy * remaining_frozen_mass - completely_liquid_specific_energy * melted_mass ) / original_mass

Even though the items are "separated" after the part melts you can just handle them are at same temperature until they are really separated and water is dropped on ground. If you want to do liquid+frozen water mixture in bottle the mixture will stay in one temperature as a whole until the thing is completely frozen or completely liquid.

src/pickup.cpp Outdated Show resolved Hide resolved
@ZhilkinSerg ZhilkinSerg added <Bugfix> This is a fix for a bug (or closes open issue) <Enhancement / Feature> New features, or enhancements on existing [C++] Changes (can be) made in C++. Previously named `Code` Items / Item Actions / Item Qualities Items and how they work and interact Mechanics: Temperature Freezing, cooling, thawing, heating, etc. mechanics labels Jul 31, 2019
@EddiTheBambi
Copy link
Contributor Author

Even though the items are "separated" after the part melts you can just handle them are at same temperature until they are really separated and water is dropped on ground. If you want to do liquid+frozen water mixture in bottle the mixture will stay in one temperature as a whole until the thing is completely frozen or completely liquid.

I'd like to be able to mix liquids in one container and have them affect eachother in different ways, for example adding frozen water to your dark cola that has been standing out in the summer sun for 3 days to make it (cold). Going to be quite tricky to pull off and probably not going to work in the end considering the liquids don't actually mix even when fully liquid, but a man can dream.

@Zireael07
Copy link
Contributor

Mixing liquids is out of scope of this PR I believe - remember, the bigger the PR, the less likely it's to get merged.

@EddiTheBambi
Copy link
Contributor Author

EddiTheBambi commented Aug 1, 2019

Mixing liquids is out of scope of this PR I believe

Oh absolutely! It's just a dream I have, I may have worded my previous comment weirdly. It depends on other systems yet to be implemented so if it were to ever happen it would definitely NOT be in this PR. This PR is exclusively for the action of picking up existing frozen liquids and the bare minimum features to give it any use whatsoever. However, i am still interested in adding more utility to liquids in the future.

Adding utility to the ability to pick up frozen liquids and fixing
earlier traslation issues. There is still an issue relating to
assigning AMMO to frozen liquids, functionality is there though game
spits out an error message.
Copy link
Contributor

@AMurkin AMurkin left a comment

Choose a reason for hiding this comment

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

1's are default values for the has_quality. And hammering level more than 1 could also be used, so no need to specify the level in the message.

src/pickup.cpp Outdated Show resolved Hide resolved
src/pickup.cpp Outdated Show resolved Hide resolved
EddiTheBambi and others added 3 commits August 1, 2019 18:40
Co-Authored-By: Alexey Mostovoy <amurkin1988@yandex.ru>
Co-Authored-By: Alexey Mostovoy <amurkin1988@yandex.ru>
Adds function item_with_best_of_quality() to player.h to smash tile
with correct tool. Includes advanced inventory support and minor
changes to popup clarity and wording
src/item.cpp Outdated Show resolved Hide resolved
Suggestions from @BevapDin, finishing functionality
@EddiTheBambi
Copy link
Contributor Author

Apologies for monstrous commit, implemented changes suggested above by @BevapDin. I am aware of a bug with reloading some items and looking for a fix. Apart from that this is starting to feel fairly complete.

@AMurkin
Copy link
Contributor

AMurkin commented Aug 13, 2019

Cataclysm-DDA/src/item.h

Lines 1087 to 1088 in 181d996

bool is_frozen_liquid()
const; //Returns true if the item is A: of type LIQUID and if it B: has the FROZEN tag

It'd be better to comment it like so:

        /** Returns true if the item is A: of type LIQUID and if it B: has the FROZEN tag */
        bool is_frozen_liquid() const;

There was previously an accidental typo in player.h, it is now fixed
Removed redundant parameter to crush_frozen_liquid()
Changed function comments on suggestion of @AMurkin
There was a bug where items reloaded after frozen liquid logic wouldn't
reload, this has now been resolved.
@EddiTheBambi EddiTheBambi changed the title [WIP]Allow player to pick up frozen liquids Allow player to pick up frozen liquids Aug 13, 2019
@EddiTheBambi
Copy link
Contributor Author

I'd say this is ready for review. I'm going to run tests locally and unless there are any problems in testing or concerns here this is done and dusted 😁

src/player.cpp Outdated Show resolved Hide resolved
src/player.cpp Outdated Show resolved Hide resolved
src/player.cpp Outdated Show resolved Hide resolved
EddiTheBambi and others added 2 commits August 14, 2019 01:12
Co-Authored-By: BevapDin <tho_ki@gmx.de>
Co-Authored-By: BevapDin <tho_ki@gmx.de>
@ZhilkinSerg ZhilkinSerg self-assigned this Aug 14, 2019
src/player.h Outdated Show resolved Hide resolved
EddiTheBambi and others added 2 commits August 14, 2019 09:51
Co-Authored-By: ZhilkinSerg <ZhilkinSerg@users.noreply.github.com>
src/player.h Outdated Show resolved Hide resolved
@AMurkin
Copy link
Contributor

AMurkin commented Aug 16, 2019

Jenkins rebuild.

@kevingranade kevingranade merged commit 946365f into CleverRaven:master Aug 16, 2019
@ZhilkinSerg ZhilkinSerg removed their assignment Aug 16, 2019
misterprimus pushed a commit to misterprimus/Cataclysm-DDA that referenced this pull request Sep 21, 2019
* allow player to pick frozen liquids
Players should be able to chip or crush ice or other frozen liquids
and pick them up and keep them in their inventory as long as they're
frozen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` <Enhancement / Feature> New features, or enhancements on existing Items / Item Actions / Item Qualities Items and how they work and interact Mechanics: Temperature Freezing, cooling, thawing, heating, etc. mechanics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pick up frozen liquids
9 participants