CleverRaven/Cataclysm-DDA — pull request #9283 by BevapDin (2014-09-27 22:32:32+00:00)
Title: Fix the rotten crafting results issue, maybe.

This might be the cause behind the "crafting rotten soup from non-rotten meat" issue. The code currently moves the birthday of the item back when the ingredients spoil.

The code calculates the relative rot for each ingredient (`item::rot / it_comest::spoils`), than the average of those values over all ingredients (in both cases only items that actually do spoil are considered).

That value is than used to move the birthday back in time to make the item older and simulate rot. `item::last_rot_check` of the new item has never been touched and is still 0. So `item::calc_rot` calculates the rot based on the birthday of the item. And so the item is retroactively rotten for the time before it was created.

As an example: crafting meat soup. Meat chunks have a spoils value of 24 hours, meat soup has 120 hours.

At the end of the crafting the (originally fresh) meat is rotten to 12 hours (`item::rot` is 12 hours, the factor used by the crafting system is `item::rot / it_comest::spoils == 12/24 == 0.5`).

The birthday of the new item is decreased by 0.5 * spoils-time of the new item, that is `0.5 * 120 hours == 60 hours`. As soon as you view the item `item::calc_rot` is called and calculates the rot from the last checked time (or in this case from the birthday as there is no last checked time).

During high temperatures items rot up 6 times as fast as normal, so the rotting of those 60 hours becomes 360 hours, which is stored in `item::rot`, and that is clearly rotten. Under "normal" temperatures, the rotting is slower and the soup might end up with the normal rot of 60 hours (not rotten).

----

I changed the code to set the rot value to `item::rot`, instead of changing the birthday of the item. It also set `item::last_rot_check` to the current turn (end of crafting), so the rot calculation starts at the that time. Note that the birthday might not actually be the current turn because of that fuzzy birthday thing, but that is not important as `calc_rot` will use `last_rot_check` instead.

Now the factor `item::rot / it_comest::spoils` is the same for both ingredients and the resulting item.