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

Projects
None yet
6 participants
@BevapDin
Copy link
Contributor

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.

BevapDin added some commits Oct 1, 2014

Move item rotting related stuff into the item class.
Remove is_rotten member, it's not stored nor loaded.
Upon loading make spoiling but not jet rotten food active again.
Being active will allow the item to rot normally by triggering the processing of active items.
Convert it_comest::spoils to signed int and into turns, not hours.
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

This comment has been minimized.

Copy link
Contributor

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

More cleanup and preparation for PR CleverRaven#9353
This commit is now depending on changes in PR CleverRaven#9353. Do not merge before that one is merged.
@Robik81

This comment has been minimized.

Copy link
Contributor

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.

@Barhandar

This comment has been minimized.

Copy link
Contributor

commented Oct 1, 2014

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;

This comment has been minimized.

Copy link
@KA101

KA101 Oct 2, 2014

Contributor

Thanks for documenting all the variables. :-D

// Rotting found *must* be active to trigger the rotting process,
// if it's already rotten, no need to do this.
active = true;
}

This comment has been minimized.

Copy link
@KA101

KA101 Oct 2, 2014

Contributor

Was gonna ask if we needed a save handler for this. Looks like you've got it sorted.

@KA101 KA101 merged commit 6877796 into CleverRaven:master Oct 2, 2014

1 check passed

default
Details

@BevapDin BevapDin deleted the BevapDin:rotten branch Oct 2, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.