Compound System

This article describes design decisions that will be rediscussed before their implementation in the future, and as such are not final.

The compound system is one of the groundwork game mechanics underlying simulations throughout the entire game, designed for use everywhere from cellular homeostasis to interstellar trade.

Overview


  • In Thrive the substances that things are composed of are known as compounds, which can be thought of as like resources. They aren’t limited to the scientific definition of "Compound" of two or more elements bonded together. Compounds in the resource sense can be elements (like oxygen), compounds (such as ammonia), or other substances (chemical agents or toxins).
  • Basically everything in the game is made of some compound. The compound system is to keep track of what organisms are made of, to track what the organism has eaten, what it's converted it into, and what waste products it expels. Everything else is part of the environment, and available to other organisms.

Microbe Stage


  • Compounds are the materials that the world and organisms are made of. So, stuff like elemental compounds (like carbon), natural resources (salt, water), organic compounds (amino acids) and organic polymers (proteins).
  • Later, there will be composites (bone, muscle) made up of other compounds combined.
  • The end products are things like the cell membrane, and can be treated just like compounds. Another important end product is energy.
  • Compounds exist in several states in the environment:
    • Compound clouds
    • In the storage of microbes/bacteria
    • In the organelles of microbes/bacteria
    • In non-living objects
  • No compounds enter or leave the total ecosystem.
  • Compounds can change form (e.g. breaking down water into hydrogen and oxygen)
  • Compound clouds are based on a grid representation of environmental resources. Their concentration can vary, and with higher concentration comes a cloud with a more intense colour.

Organelles

  • This is where processes generally take place. Some processes require certain organelles. They can vary depending on the quality of the organelle.
  • In later stages, this would be organs, workshops/factories and cities.

Collection and Storage

  • Amount of compounds in a system measured in a unit based on moles
  • Each compound has a weight. This affects how much storage space it takes up in a cell.
  • Compounds are automatically absorbed by microbes by swimming through them, if the microbe has space to store it. They are stored in the cytoplasm or in vacuoles.
  • Vacuoles can be designated to only store specific compounds.

Priority System

  • Because storage is just going to be general, there need to be priorities on what compounds get stored and which ones to eject first in case the storage is filled.

Processes

  • These control how compounds are converted from one to another, and what is required to do so. If an organism isn't capable of carrying out a particular process, it may not have access to that process' products, and will need to acquire them some other way (probably by eating something), or may not be able to acquire them at all (for example, eating a rhino horn doesn't allow you to grow one yourself).
  • The processes you're able to carry out, and how effectively you can do so, define your organism, your species, and your place in the food chain.
  • Not all processes will be available at the beginning and the player will need to get certain organelles in order to unlock them.

Agents

  • Agents are special compounds with powerful effects, and most are made from the same constituents for the sake of simplicity. Converting incoming compounds into agents is done using the golgi apparatus and endoplasmic reticulum, which consume ATP at a fixed rate whether performing this task or not.
  • More details on the Agents page.

Organisms

  • Organisms are individuals of a species, whether it be a cell, plant, or creature.
  • Each has particular organelles/organs, is capable of particular processes, can store particular compounds, and considers others to be waste products.
  • Each one continually carries out the processes it is capable of in order to produce the compounds it needs.
  • A compound can be a nutrient for one species and not for another.

Implementation

Phase 1: Calculating the Prices

  • At the beginning of the update method, each process calculates its price, and the price function is a function of the demand, the supply, and the previous price of the compound.
    • Supply of a compound is the amount of it the compound bag has.
    • Demand and old price are calculated on a previous call to the update method (and the initial values are arbitrary).

In the current implementation the function is:

P = √(D / (S + 1)) * COMPOUND_PRICE_MOMENTUM + oldP * (1 - COMPOUND_PRICE_MOMENTUM))

With:
P the price
D the demand
S the supply
oldP the old price
COMPOUND_PRICE_MOMENTUM a constant between 0 and 1.
The function also performs a check to raise the value from 0 to a small positive number if needed.

  • After that's done, if the compound is marked as “useful” (this is done on the compound table), then the price gets inflated by a certain amount, depending on the compound supply. This is done so that the process system knows which compounds does it want to make (otherwise all prices would decay to 0 and that would be no fun).

In the current implementation, the price inflating function is:

PI = IMPORTANT_COMPOUND_BIAS / (S + 1)
With:
PI the price inflation
S the supply
IMPORTANT_COMPOUND_BIAS an arbitrary constant
It’s important to notice that for the first price equation the old price used is the non-inflated one.
If, after all that, the price is below a certain small number, then the price is rounded down to zero (and therefore dumped later).

Phase 2: Calculating the Rate

  • After all those calculations are done for all of the compounds, the process system needs to decide the desired rate for each of the processes.
  • This rate could, potentially, be larger than the maximum capacity the process has.
  • Said rate is calculated by making a simple prediction about the prices of the compounds, by replicating the same calculations of phase 1 on each compound, but assuming the supply is one unit larger, and then assuming the price is linear in respect of the supply.
  • If the price of the compound was 0 on phase 1 it’s assumed that the price of that compound is always 0, regardless of the supply.
  • Finally, it’s assumed that the price is 0 for any value of supply that the linearization would make it’s price negative (aka, the minimum value of a function is 0).
  • Here’s an example of one of those functions, made in the google drive equivalent of MS Paint:
GKEExEf.png
  • Then all the process system has to do is get the rate at which the sum of all the input compound prices would equal the sum of all the output compound prices, and that is the desired rate.
  • If all of the output compounds have a price of 0, then the desired rate is made 0.
  • An example of a process would be like this:
GKEFzr6.png

*To account for the storage space, a similar calculation is made but multiplying the prices of the compounds by a function that returns a value between 0.0 and 1.0, depending on the available space and the size and amount of the compounds processed.

In the current implementation, the function is:

M = 2.0 * (1.0 - sigmoid(RS / (AS + 1.0) * STORAGE_SPACE_MULTIPLIER));
With:
M is the multiplier between 0 and 1.
RS is the required space of the compound (volume * amount produced/processed)
AS is the available storage space
STORAGE_SPACE_MULTIPLIER is an arbitrary constant (currently 2.0)

  • Then the inputs get converted into the outputs by a rate of the minimum of the desired rate considering the storage space ONLY if by doing so the rate is reduced, otherwise the space is not considered (this is to avoid the process system to destroy compounds to gain space, when the compound purging code should do that), and the max capacity of the process (assuming there are enough inputs and storage space to do so).

Phase 3: Calculating the Demand

  • After the desired rates are found, the process must determine the demand of the compounds.
  • The demand of a compound is equal to the sum of all the demands generated by all the processes, which is defined by the equation

D = DR * IN * soft(PC * IN)
with:
D the demand generated by a process.
DR the desired rate of that process (without capacity, input or storage space limitations being considered).
IN the input needed by the process (aka the amount of input spent on running the process at a rate of 1).
PC the maximum process capacity
soft(x) a continuous, monotonically increasing function that equals 0 when x = 0, and
1 when x ⟶ ∞

In the current implementation:

soft(x) = 2 * sigmoid(x * PROCESS_CAPACITY_DEMAND_MULTIPLIER) - 1
with PROCESS_CAPACITY_DEMAND_MULTIPLIER being an arbitrary constant.

  • It’s important to note that a process like A ⟶ B, with a rate of 2 * x it’s exactly the same as the process 2 * A ⟶ 2 * B, with a rate of x
  • It’s also important that processes with a max capacity of 0 do not affect the system in any way.
  • That’s it! :D

Compound List


For the full list of compounds in the Microbe Stage, look at the Compounds table on the Microbe Appendices page.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License