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 another part of the rotting code (the code about rotting). #9353

Merged
merged 3 commits into from Oct 2, 2014

Conversation

BevapDin
Copy link
Contributor

@BevapDin BevapDin commented Oct 1, 2014

The save from #6414 (comment) contains that case. The first meat chunk in the fridge is actually rotten (try to eat it and you will see), but that is not displayed.

Found the failure: the meat chunks are rotten. The commits 946f873, 4468053 and 456da78 worked together in a very unfortunate way.

The first one makes food items active so they are processed to simulate the rot. The third commit stored the "is rotten" property in a separate member of the item class. That members was not stored in the save files! But the code that displays the "(rotten)" tag uses that member.

What happened is this: the meat starts as active, is processed (item::calc_rot is called each turn), until it is rotten. calc_rot sets item::is_rotten to true and makes the item inactive (4468053). Everything is fine now (rotten tag is displayed properly), until the game is saved and reloaded.

The is_rotten member is not stored nor loaded, so it reverts to the default value false, the item is not active either (that property is stored and was loaded, but was set to false in calc_rot). In the end, the item is rotten (item::rot * 600 is bigger than it_comest::spoils), but the tag was not displayed and the player though it is not rotten.

There is an explicit call to calc_rot in player::eat which would recalculate the rotting (increases item::rot, but that does not matter), it sets item::is_rotten to true again (because the comparison with the item type member says that the item should be rotten) and the following code ask the player to really eat the rotten item.


Fixed all of this by moving the rotting related stuff into the item class, and making all loaded items that rot but are not yet rotten active again.

I also converted it_comest::spoils to be in turns (not hours) and be a signed int. It is compared to a signed int (the rot) anyway, and it is converted to turns all the time, so why not put that into the loading code.

Remove is_rotten member, it's not stored nor loaded.
Being active will allow the item to rot normally by triggering the processing of active items.
We don't need yet another time scale. Making everything the same time scale (turns) avoids confusion.
Also making it a (signed) int avoids comparison warnings/problems.
@tivec
Copy link
Contributor

tivec commented Oct 1, 2014

I just filed PR #9352 that will recolor rotten items. I will see if I can pull your changes for testing along side of my changes to see that my code still works as intended.

Edit: Verified to work perfectly fine alongside your changes - even better, in fact. I don't have to try and eat stuff to figure out it is rotten now.

tivec added a commit to tivec/Cataclysm-DDA that referenced this pull request Oct 1, 2014
This commit is now depending on changes in PR CleverRaven#9353. Do not merge before that one is merged.
@Robik81
Copy link
Contributor

Robik81 commented Oct 1, 2014

Sorry for the confusion. I checked the save again and you are right, meat in top stack is already rotten. I must ate meat from wrong stack :(

Thanks for fixing it. This bug is super annoying.

@KA101 KA101 added the (S2 - Confirmed) Bug that's been confirmed to exist label Oct 1, 2014
@Barhandar
Copy link
Contributor

I bet it also fixes #9297.

@KA101 KA101 self-assigned this Oct 2, 2014
* The turn when this item has been put into a fridge.
* 0 if this item is not in a fridge.
*/
int fridge;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for documenting all the variables. :-D

@KA101 KA101 merged commit 6877796 into CleverRaven:master Oct 2, 2014
@kevingranade kevingranade removed the (S2 - Confirmed) Bug that's been confirmed to exist label Oct 2, 2014
@BevapDin BevapDin deleted the rotten branch October 2, 2014 12:53
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.

None yet

6 participants