Files
VOREStation/code/controllers/subsystems/chemistry.dm
Cameron Lennox e31df5e920 Recipie conflict unit test + Chemanalyzer PRO (#17270)
* conflict test

* crash fix

* test bad chem

* tweaked

* is this even working

* what?

* is this broken?

* test fix

* force reactions

* Another attempt

* oop

* another

* oop

* actual check

* inverted

* distilling pain

* backward

* attempting again

* slime rules

* wrong path

* fix for slime

* no test chem

* oops lol

* inhibitor test

* var

* another fix

* what is going on

* oh that's how that works

* this?

* again...

* better inhibitors

* fixed order

* clear beaker

* lets try this, plus cleanup

* comments

* another test

* fix

* stale ref?

* more logs

* round and round

* keycheck

* reverse lookup lists

* chemanalyzer update

* addiction code commented out

* span cleanup, downstream code commented out

* debug cleanup

* reaction fixing

* reduced scale again

* another wrapper

* more info in test

* document reagents

* scaling dynamic

* check single inhibitors too

* oop

* using unittest data signal

* fixes

* this is still needed

* broken reactions, and bad id reactions

* oops

* this too actually

* single chems are illegal

* validity on lists

* oops again

* invalid key check, fixed invalid reactions

* test remove

* pretty chat messages

* spanred

* slimecore results

* grinding unit test and grinding results in chem analyzer

* ore check

* fluid pump info

* correct id

* enforce id case

* compliance

* it makes no sense that this machine gives no feedback that you need to reanchor it after construction

* lets not unseal either

* display chems produced

* notify players of belly liquids, as they do not react with anything

---------

Co-authored-by: Willburd <7099514+Willburd@users.noreply.github.com>
Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
2025-03-21 04:36:06 -04:00

69 lines
2.7 KiB
Plaintext

SUBSYSTEM_DEF(chemistry)
name = "Chemistry"
wait = 20
flags = SS_NO_FIRE
init_order = INIT_ORDER_CHEMISTRY
var/list/chemical_reactions = list()
var/list/chemical_reactions_by_product = list()
var/list/instant_reactions_by_reagent = list()
var/list/distilled_reactions_by_reagent = list()
var/list/distilled_reactions_by_product = list()
// var/list/fusion_reactions_by_reagent = list() // TODO: Fusion reactions as chemical reactions
var/list/chemical_reagents = list()
/datum/controller/subsystem/chemistry/Recover()
log_debug("[name] subsystem Recover().")
chemical_reactions = SSchemistry.chemical_reactions
chemical_reagents = SSchemistry.chemical_reagents
/datum/controller/subsystem/chemistry/Initialize()
initialize_chemical_reagents()
initialize_chemical_reactions()
return SS_INIT_SUCCESS
/datum/controller/subsystem/chemistry/stat_entry(msg)
msg = "C: [chemical_reagents.len] | R: [chemical_reactions.len]"
return ..()
//Chemical Reactions - Initialises all /decl/chemical_reaction into a list
// It is filtered into multiple lists within a list.
// For example:
// chemical_reactions_by_reagent[REAGENT_ID_PHORON] is a list of all reactions relating to phoron
// Note that entries in the list are NOT duplicated. So if a reaction pertains to
// more than one chemical it will still only appear in only one of the sublists.
/datum/controller/subsystem/chemistry/proc/initialize_chemical_reactions()
var/list/paths = decls_repository.get_decls_of_subtype(/decl/chemical_reaction)
for(var/path in paths)
var/decl/chemical_reaction/D = paths[path]
chemical_reactions += D
if(D.required_reagents && D.required_reagents.len)
var/reagent_id = D.required_reagents[1]
var/list/add_to = instant_reactions_by_reagent // Default to instant reactions list, if something's gone wrong
// if(istype(D, /decl/chemical_reaction/fusion)) // TODO: fusion reactions as chemical reactions
// add_to = fusion_reactions_by_reagent
if(istype(D, /decl/chemical_reaction/distilling))
add_to = distilled_reactions_by_reagent
if(istype(D, /decl/chemical_reaction/distilling))
LAZYINITLIST(distilled_reactions_by_product[D.result])
distilled_reactions_by_product[D.result] += D // for reverse lookup
else
LAZYINITLIST(chemical_reactions_by_product[D.result])
chemical_reactions_by_product[D.result] += D // for reverse lookup
LAZYINITLIST(add_to[reagent_id])
add_to[reagent_id] += D
//Chemical Reagents - Initialises all /datum/reagent into a list indexed by reagent id
/datum/controller/subsystem/chemistry/proc/initialize_chemical_reagents()
var/paths = subtypesof(/datum/reagent)
chemical_reagents = list()
for(var/path in paths)
var/datum/reagent/D = new path()
if(!D.name)
continue
chemical_reagents[D.id] = D