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
Conversation
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.
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. |
This commit is now depending on changes in PR CleverRaven#9353. Do not merge before that one is merged.
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. |
I bet it also fixes #9297. |
* The turn when this item has been put into a fridge. | ||
* 0 if this item is not in a fridge. | ||
*/ | ||
int fridge; |
There was a problem hiding this comment.
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
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
setsitem::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 valuefalse
, the item is not active either (that property is stored and was loaded, but was set to false incalc_rot
). In the end, the item is rotten (item::rot * 600
is bigger thanit_comest::spoils
), but the tag was not displayed and the player though it is not rotten.There is an explicit call to
calc_rot
inplayer::eat
which would recalculate the rotting (increasesitem::rot
, but that does not matter), it setsitem::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.