Skip to content

FoodSpoilage

SphereII edited this page Sep 18, 2024 · 1 revision

Food Spoilage

The Food Spoilage system allows you to spoil food over time.

 

This would allow you to spoil fresh meat into rotting meat, or change teas into cold teas.

 

It allows storage containers to have a spoilage value that will reduce how fast something spoils, while other storage containers may spoil faster.

 

The best write up is from khzmusik, and I'll link his repo here: https://gitlab.com/karlgiesing/7d2d-1.0-mods/-/tree/main/khzmusik_Food_Spoilage?ref_type=heads

 

Here is a snippet:

 

 

 

Food spoilage is calculated when the player opens a container with one or more stacks of consumable items in it. The term SphereII uses for this calculation is loss calculation.

A loss calculation can only happen after a certain number of game ticks since the last time the loss was calculated. This number of ticks is called ticks per loss. The ticks per loss is configurable in XML, and can be set individually per consumable item.

The loss caluclation can happen multiple times at once, if the ticks per loss would have been reached multiple times since the container was last opened. For example, if ticks per loss is 100, and it has been 1000 ticks since the user last opened the container, then the loss calculation will happen 10 times when the user opens that container.

Each time the loss calculation occurs, it uses a number of different values to determine the amount of food spoilage:

  • The spoilage amount starts as an amount specified for that consumable item in the item's XML. This amount is called spoilage per tick (though it should probably be called "spoilage per loss" or "spoilage per calculation").
  • The stack of consumable items is always located in some container, and that container adds a number to the spoilage amount. The container can be the player's backpack, the player's toolbar, or a loot container. All three of these locations have their values set globally in XML.
  • If the item stack is located in a loot container, that container can offset the global amount of spoilage that is added for all loot containers. This is called the preserve bonus of the container. The preserve bonus is subtracted from the spoilage amount.

Once that amount is calculated, it is compared against the total amount of spoilage that can occur before one consumable item spoils. That total amount of spoilage is called the maximum spoilage.

This process happens until the calculated spoilage amount is less than the maximum spoilage:

  • One consumable item is removed from the item stack.
  • A spoiled item, representing a spoiled version of the original item, is created. The spoiled item can be specified in the XML for each consumable item, or defaults to rotten meat. If this is set to the consumable item itself, then the consumable item spoils into nothing.
  • The spoiled item is placed in the player's backpack, creating a new stack if necessary. (It goes into the player's backpack regardless of which container held the original item.) If there is no room in the player's backpack, the spoiled item is dropped on the ground.
  • The maximum spoilage is subtracted from the calculated spoilage amount.

Created with the Personal Edition of HelpNDoc: Streamline Your Documentation Process with HelpNDoc's Intuitive Interface

0-SCore

Table of contents

Clone this wiki locally