Skip to content

Machines

Kesomannen edited this page Jul 20, 2023 · 18 revisions

Overview

Machines in Food Dynasty are composed of a GridObject and various machine components. Components communicate with each other using Events and Conditions, instead of hard-coded references. For example, the Food Dispenser component raises an event whenever it dispenses food, which a Supply can listen to and subtract its current value.

Additionally, all machines have the MouseEventTrigger and MachineEntity components. The former listens for mouse input and raises events, allowing machines to be selected and interacted with. The later links the machine to the corresponding MachineItemData, allowing it to be removed and returned to the inventory.

Assets

Some components accept and/or require separate assets. These are regular ScriptableObject types that are created in the editor.

Filters

FoodFilterGroups filter out FoodBehaviours based on traits. They are composed of multiple FoodFilters which target one trait each. For float and integer traits, filters check if the trait is in a specified range, while boolean traits are checked with a simple comparison. If a trait is not present, its default value is used (0 for numbers, false for booleans). Filters checking for a tag ignore this rule and simply check if the tag exists.

bild

Example of simple filter group that checks for cooked bread. It has two filters: one that checks for the Dough tag, and a second one for the Baked tag.

bild

Example of a filter group that checks if food can be softened. It has the same filters as the previous one as well as one that checks if the Softened trait is between 0 and 9.

Modifiers

FoodModifierGroups consist of multiple trait and model modifiers, and a sell price modifier. The sell price modifier is of the type Modifier, which allows for percentual, multiplicative and additive operations.

A model can be added as a base model, overriding the original one (for example baking bread), or as a topping, which adds to the original (for example adding cheese). For performance reasons, you have to provide a GenericObjectPool instead of a traditional prefab for model modifiers.

Trait modifiers target one trait each. Modifiers targeting int and float traits can either set or apply a Modifier to the current value of that trait. Bool modifiers can only set the current value, while tag modifiers simply add the tag if not already present on the FoodBehaviour.

bild

Example of modifier group that bakes bread. It multiplies the sell price by 10 and applies a base model from the Bread Pool. It also contains one trait modifier, which adds the tag Baked.

bild

Example of modifier group that softens food. It will increase the food's value by 10% and the Softened trait by 1.

Events

Events are normal C# events wrapped in a component, allowing them to be referenced in the editor. Events can have an argument of any type, but machine components almost always use FoodBehaviour events. For example, the FoodTrigger component raises a FoodBehaviour event when it is triggered, passing the food that triggered it as an argument.

Conditions can be polled by any component, returning a boolean value. Other components can add their own criterion, which must succeed for the polling to succeed. For example, the Supply component adds a criterion that checks whether there is adequate supply. A FoodModifier can then poll the same condition to check if it can apply a topping to incoming food.

Components

Some components derive from the abstract FoodMachineComponent. It provides an abstraction for components that accept food through an event, filtered by a FoodFilterGroup and/or a Condition.

Derived from FoodMachineComponent

  • Food Seller: Applies a Modifier to food's sell price before disposing it and converting its value to money.

  • Food Disposer: Disposes food without selling.

  • Food Modifier: Applies a FoodModifierGroup.

  • Food Merger: Requires a reference to a Supply. Disposes food, merging a number of them, combining their sell price and adding supply. Can listen to a separate event in order to apply the merged sell values to other food.

  • Food Splitter: Similar to Food Merger, but adds multiple supply units per food.

Other

  • Food Dispenser: Draws FoodBehaviours from a pool at a spawn point with a configurable interval. Polls a condition whenever a dispense is attempted and raises an event when food is dispensed.

  • Supply:

  • Conveyor: Requires a kinematic Rigidbody component. Moves objects at a configurable speed.

  • Food Trigger: Uses standard Unity trigger messages to detect incoming FoodBehaviours and raises an event. Most often used in conjunction with FoodMachineComponents.

Examples

BreadOven drawio(9)

Structure of Bread Oven.

BreadOven drawio(8)

Structure of Dough Dispenser.

BreadOven drawio(7)

Structure of Spice Adder.

Clone this wiki locally