Reagents & Chemistry
Relevant source files
The following files were used as context for generating this wiki page:
- code/modules/reagents/chemistry/fermi_readme.md
- tgui/packages/tgui/interfaces/ChemDispenser.tsx
- tgui/packages/tgui/interfaces/ChemReactionChamber.tsx
- tgui/packages/tgui/interfaces/ChemMaster.tsx
- tgui/packages/tgui/interfaces/MassSpec.tsx
- tgui/packages/tgui/interfaces/Reagents/types.ts
- html/changelogs/archive/2021-02.yml
The Reagents & Chemistry system simulates complex chemical interactions, including reaction rates, purity mechanics, and environmental dependencies. It manages the creation, processing, and purification of chemical compounds through various machinery and internal logical datums.
Sources: code/modules/reagents/chemistry/fermi_readme.md:1, html/changelogs/archive/2021-02.yml:379-385
Chemistry Core Architecture
The chemistry system relies on the datum/reagents holder to manage volumes and the equilibrium.dm logic to execute reactions. When the system detects a reaction, it creates an equilibrium object that calculates production steps based on temperature, pH, and available reagents.
Reaction Execution Flow
The following diagram shows how the system handles a new reaction after detection.
Key Data Structures
| Variable | Description |
|---|---|
chem_temp | Current temperature of the reagent holder. |
ph | Result of the sum of all reagents and buffers in the system. |
purity | Internal value used for splitting chemicals during consumption. |
creation_purity | The actual purity of the reagent at the time of its creation. |
is_reacting | A boolean flag indicating an active chemical reaction. |
Sources: code/modules/reagents/chemistry/fermi_readme.md:139-165, code/modules/reagents/chemistry/fermi_readme.md:183-195
Reaction Variables and Mechanics
Chemical reactions are governed by specific environmental variables that determine the speed and quality of the output.
Temperature Factors
Reaction rates scale with temperature. The system defines a required_temp to start, an optimal_temp for maximum yield, and an overheat_temp where the reaction becomes unstable. If temperatures exceed the optimal range, the system calls overheated(), which typically reduces product yield.
Sources: code/modules/reagents/chemistry/fermi_readme.md:46-65
pH and Purity
The pH of a solution determines the purity of the produced reagent. Each recipe defines an optimal_ph_min and optimal_ph_max.
- Optimal Range: Produces reagents with 1.0 purity.
- Deterministic Region: Purity drops exponentially or linearly as pH drifts from the optimal range.
- Minimum Purity: If purity falls below
purity_min(default 0.15), the reaction callsoverly_impure()and may convert the product into afailed_chem.
Sources: code/modules/reagents/chemistry/fermi_readme.md:76-118
Reagent Properties and Impurities
Reagents contain metadata that dictates their behavior when consumed or processed.
Purity Inversion
When a reagent is consumed or processed with the REACTION_CLEAR_INVERSE flag, the system checks its creation_purity.
- If purity is above
inverse_chem_val: The reagent splits into the main chem and animpure_chem. - If purity is below
inverse_chem_val: The reagent converts 100% into aninverse_chem.
Sources: code/modules/reagents/chemistry/fermi_readme.md:139-165
Reagent Bitflags
Reagents use bitflags to define special processing behaviors:
REAGENT_DEAD_PROCESS: Allows processing in dead bodies.REAGENT_INVISIBLE: Hides the reagent from health analyzers.REAGENT_SNEAKYNAME: Inverted chemicals keep the original chemical's name.REAGENT_SPLITRETAINVOL: Retains the initial volume during purity splitting.
Sources: code/modules/reagents/chemistry/fermi_readme.md:167-178
Chemistry Machinery
The system provides several interfaces for interacting with reagents.
Chemical Dispenser
Dispenses base chemicals into beakers. It features a reaction lookup tool and the ability to record custom recipes for automated dispensing.
Sources: tgui/packages/tgui/interfaces/ChemDispenser.tsx:100-150
Mass Spectrometer
Purifies reagents by selecting specific molecular masses. Users adjust sliders to target a "Mass (G)" range. The machine then separates reagents within that range into an output beaker.
Sources: tgui/packages/tgui/interfaces/MassSpec.tsx:40-80
Chem Master
Processes reagents into various delivery formats, such as pills, patches, or bottles. It includes an analysis tool to view reagent descriptions, pH, and metabolization rates.
Sources: tgui/packages/tgui/interfaces/ChemMaster.tsx:100-130
Reaction Flow Diagram
The following diagram illustrates the interaction between a user and the chemistry machinery to produce a final product.
Conclusion
The Reagents & Chemistry system is a high-fidelity simulation where environmental factors like temperature and pH directly influence the success and purity of chemical production. By utilizing specialized machinery like the Mass Spectrometer and Chem Master, chemists can refine raw reactions into potent medical or tactical supplies.
Sources: code/modules/reagents/chemistry/fermi_readme.md:126-135, html/changelogs/archive/2021-02.yml:379-400