CleverRaven/Cataclysm-DDA — pull request #9353 by BevapDin (2014-10-01 14:31:55+00:00)
Title: Fix another part of the rotting code (the code about rotting).

The save from https://github.com/CleverRaven/Cataclysm-DDA/issues/6414#issuecomment-57453503 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 946f8736f1c0829f40751db50f79459c23142971, 446805311f4ee9c4c1b6a4ae9995cd8b327acf7f and 456da78c50e3c277fb4a0748bf2a71ab8594431e 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 (446805311f4ee9c4c1b6a4ae9995cd8b327acf7f). 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.