CleverRaven/Cataclysm-DDA — pull request #9027 by BevapDin (2014-09-15 16:54:42+00:00)
Title: Move all the item-processing into the item class.

Currently item processing (food rotting, items loosing the cold/hot flag, tools active consuming their charges, etc.) is done at two places: on the map and inside the player class for items in the players inventory. Both places share a lot of code (e.g. food rotting).

There are however slight differences, which I can see no reason for. Just some examples:
- map.cpp gives different messages for revived robots/creatures.
- map.cpp checks for `tmp->revert_to == "null" || it->charges == -1`, player.cpp checks only for `tmp->revert_to == "null"` to decide whether the tool should be destroyed when it has gone out of charges.
- map.cpp checks whether the item type has iuse-function before invoking it. player.cpp simply invokes it without checking.
- map.cpp uses the `item::burnt` value when checking whether a corpse can revive (a badly burnt corpse has a smaller chance than a non-burnt corpse). player.cpp ignores this.
- some code uses writes directly to `item::type`, some code calls `item::make`.

I combined the code from both places into `item::process`. That function can handle items on the ground and in the inventory of a player/npc.

This also fixes #8273 - previous code did not process food items in a container, the check was only whether the item was active and did not include a check whether it *contains* an active item. it also did not increase `submap::active_item_count` when a (inactive) container with an active item in it was dropped on the map, it only checked the container for being active. That prevents the item processing code (including rot) from being run on that submap.

It fixes #8676 - items in containers are probably processed. There was also some pointless code duplication: once for items that are food and once for items that are containers with food. The new functions simply processes all contained items recursively.

Items on the map are only processed when the `submap::active_item_count` indicates that there are any active items, but this counter is not always correct, especially since the item vector can be accessed through `map::i_at` and changed by anyone without considering `submap::active_item_count`.

There was another potential problem in the previous code: when a food item looses its HOT or COLD tag during the processing on the map (because its item counter has timed out), the `active_item_count` would have been decreased. When this item was the only active item on the submap, the `active_item_count` would than be 0 and no further processing of items on that submap had been done. But the food item must still be processed because it's food and might rot.

I have tested this branch with milk (which is surprisingly rare even in grocery shops), and it looses the fresh tag over time - even when not picked up and still in the container.

It seems that (maybe caused by the recent changes to the weather system) new games always start with weather at negative temperatures. This reduces the spoiling of food significantly. Even milk is non-rotten when the game starts.

Fixes #9024 it's very similar to #8273.

----

Any opinions are welcome (for example about the names of the functions). I tried to structure the processing a bit, instead of putting all code into one function it's separated into specific functions, e.g. to process rotting food, invoke the iuse of tools etc.

There are also some todo markers in the code:

- artifacts currently only work when carried by the player, not when on ground, not when in the possession of a npc, maybe this should be changed? You could give a npc a bad artifact to see them suffer...
- consider moving game::process_artifact into `item::process_artifact`.
- a message when a wet towel in the inventory of the player has dried (no message for npcs or when on ground), for the player it might be useful as the towel can than be used again.