Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reagents: reactions #6816

Merged
merged 42 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9f1ba3f
rename reagent holder
silicons Oct 19, 2024
bfa581d
rename
silicons Oct 19, 2024
7db8c61
new reagent system???
silicons Oct 19, 2024
aeda2cd
all that
silicons Oct 20, 2024
d5d33ef
that
silicons Oct 20, 2024
c1f516e
update
silicons Oct 20, 2024
03a55b2
yikes
silicons Oct 20, 2024
1943293
dme
silicons Oct 20, 2024
c82e151
things
silicons Oct 21, 2024
f92b45a
mods
silicons Oct 21, 2024
ba82d9c
that
silicons Oct 21, 2024
59f3afb
That
silicons Oct 21, 2024
7e49e9a
that
silicons Oct 21, 2024
077eff9
that
silicons Oct 22, 2024
40e3d66
typo
silicons Oct 22, 2024
27e85ba
rewrite that
silicons Oct 22, 2024
5cdca2c
actually no ph, not yet
silicons Oct 22, 2024
489a3fa
thing
silicons Oct 23, 2024
730602e
that
silicons Oct 24, 2024
f12aa46
that
silicons Oct 24, 2024
6c3b03b
logging
silicons Oct 25, 2024
fdc05c8
fix and improve
silicons Oct 26, 2024
8b0d7d1
fix and improve
silicons Oct 26, 2024
572bf7c
Fixes
silicons Oct 26, 2024
1677196
Fix
silicons Oct 26, 2024
2e3cc0f
oop
silicons Oct 26, 2024
521b77f
fix
silicons Oct 26, 2024
5362fb4
Fix
silicons Oct 26, 2024
627e568
sigh
silicons Oct 26, 2024
3d7dc33
that
silicons Oct 26, 2024
4d9cc33
Fix
silicons Oct 26, 2024
0870745
Fix
silicons Oct 26, 2024
439a150
fix
silicons Oct 26, 2024
bd85d96
fix
silicons Oct 26, 2024
1965bec
algorithm fix
silicons Oct 26, 2024
7289500
algorithm fix
silicons Oct 26, 2024
2010054
algorithm fix
silicons Oct 26, 2024
fe72b72
that
silicons Oct 27, 2024
44ad2db
that
silicons Oct 27, 2024
22b7bf0
fix
silicons Oct 28, 2024
5208e14
sigh
silicons Oct 28, 2024
6984c9f
sigh
silicons Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions citadel.dme
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@
#include "code\__DEFINES\radiation\insulation.dm"
#include "code\__DEFINES\radiation\mobs.dm"
#include "code\__DEFINES\radiation\simulation.dm"
#include "code\__DEFINES\reagents\flags.dm"
#include "code\__DEFINES\reagents\chemical_reaction.dm"
#include "code\__DEFINES\reagents\reagent.dm"
#include "code\__DEFINES\reagents\reagent_holder.dm"
#include "code\__DEFINES\rendering\alert.dm"
#include "code\__DEFINES\rendering\ao.dm"
#include "code\__DEFINES\rendering\atom_huds.dm"
Expand Down Expand Up @@ -541,6 +543,7 @@
#include "code\controllers\subsystem\automata.dm"
#include "code\controllers\subsystem\bellies_vr.dm"
#include "code\controllers\subsystem\chat.dm"
#include "code\controllers\subsystem\chemistry.dm"
#include "code\controllers\subsystem\dcs.dm"
#include "code\controllers\subsystem\DPC.dm"
#include "code\controllers\subsystem\early_init.dm"
Expand Down Expand Up @@ -651,7 +654,6 @@
#include "code\controllers\subsystem\persistence\modules\turf_grid.dm"
#include "code\controllers\subsystem\persistence\modules\bulk_entity_serializers\debris.dm"
#include "code\controllers\subsystem\persistence\modules\bulk_entity_serializers\trash.dm"
#include "code\controllers\subsystem\processing\chemistry.dm"
#include "code\controllers\subsystem\processing\circuits.dm"
#include "code\controllers\subsystem\processing\instruments.dm"
#include "code\controllers\subsystem\processing\moving_cameras.dm"
Expand Down Expand Up @@ -3225,6 +3227,7 @@
#include "code\modules\loadout\accessories\insignia.dm"
#include "code\modules\loadout\accessories\utility.dm"
#include "code\modules\logging\logging.dm"
#include "code\modules\logging\api\reagents.dm"
#include "code\modules\loot\pack.dm"
#include "code\modules\loot\table.dm"
#include "code\modules\loot\packs\archeology.dm"
Expand Down Expand Up @@ -4572,22 +4575,33 @@
#include "code\modules\random_map\noise\noise.dm"
#include "code\modules\random_map\noise\ore.dm"
#include "code\modules\random_map\noise\tundra.dm"
#include "code\modules\reagents\Drink-Recipes.dm"
#include "code\modules\reagents\exposedprocs.dm"
#include "code\modules\reagents\Food-Recipes.dm"
#include "code\modules\reagents\Misc-Recipes.dm"
#include "code\modules\reagents\reagent_containers.dm"
#include "code\modules\reagents\Topical-Recipes.dm"
#include "code\modules\reagents\chemistry\_readme.dm"
#include "code\modules\reagents\chemistry\chemical_reaction-legacy.dm"
#include "code\modules\reagents\chemistry\chemical_reaction.dm"
#include "code\modules\reagents\chemistry\colors.dm"
#include "code\modules\reagents\chemistry\helpers.dm"
#include "code\modules\reagents\chemistry\holder.dm"
#include "code\modules\reagents\chemistry\logging.dm"
#include "code\modules\reagents\chemistry\machinery.dm"
#include "code\modules\reagents\chemistry\metabolism.dm"
#include "code\modules\reagents\chemistry\reaction.dm"
#include "code\modules\reagents\chemistry\reagent.dm"
#include "code\modules\reagents\chemistry\reagent_holder-legacy.dm"
#include "code\modules\reagents\chemistry\reagent_holder-reactions.dm"
#include "code\modules\reagents\chemistry\reagent_holder.dm"
#include "code\modules\reagents\chemistry\wiki_generation.dm"
#include "code\modules\reagents\chemistry\reactions\automata.dm"
#include "code\modules\reagents\chemistry\reactions\carpet.dm"
#include "code\modules\reagents\chemistry\reactions\detonation.dm"
#include "code\modules\reagents\chemistry\reactions\Drink-Recipes.dm"
#include "code\modules\reagents\chemistry\reactions\Food-Recipes.dm"
#include "code\modules\reagents\chemistry\reactions\medicine.dm"
#include "code\modules\reagents\chemistry\reactions\Misc-Recipes.dm"
#include "code\modules\reagents\chemistry\reactions\paint.dm"
#include "code\modules\reagents\chemistry\reactions\pyrotechnic.dm"
#include "code\modules\reagents\chemistry\reactions\solidification.dm"
#include "code\modules\reagents\chemistry\reactions\stack_synthesis.dm"
#include "code\modules\reagents\chemistry\reactions\Topical-Recipes.dm"
#include "code\modules\reagents\chemistry\reactions\food\food-synthesis.dm"
#include "code\modules\reagents\chemistry\reagents\Chemistry-Reagents-Core.dm"
#include "code\modules\reagents\chemistry\reagents\Chemistry-Reagents-Dispenser.dm"
#include "code\modules\reagents\chemistry\reagents\Chemistry-Reagents-Food-Drinks.dm"
Expand All @@ -4599,7 +4613,6 @@
#include "code\modules\reagents\chemistry\reagents\core\elements.dm"
#include "code\modules\reagents\chemistry\reagents\other\cleaner.dm"
#include "code\modules\reagents\chemistry\reagents\pyrotechnics\thermite.dm"
#include "code\modules\reagents\chemistry\recipes\medicine.dm"
#include "code\modules\reagents\distilling\Distilling-Recipes.dm"
#include "code\modules\reagents\distilling\distilling.dm"
#include "code\modules\reagents\items\hypospray.dm"
Expand Down
20 changes: 0 additions & 20 deletions code/__DEFINES/chemistry.dm
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,3 @@ var/list/cheartstopper = list("potassium_chloride") // Thi
//! Used by chem master
#define CONDIMASTER_STYLE_AUTO "auto"
#define CONDIMASTER_STYLE_FALLBACK "_"

/// When processing a reaction, iterate this many times.
#define PROCESS_REACTION_ITER 5

/**
* Helper that ensures the reaction rate holds after iterating
* Ex. REACTION_RATE(0.3) means that 30% of the reagents will react each chemistry tick (~2 seconds by default).
*/
#define REACTION_RATE(rate) (1.0 - (1.0-rate)**(1.0/PROCESS_REACTION_ITER))

/**
* Helper to define reaction rate in terms of half-life
*
* Ex.
* HALF_LIFE(0) -> Reaction completes immediately (default chems)
* HALF_LIFE(1) -> Half of the reagents react immediately, the rest over the following ticks.
* HALF_LIFE(2) -> Half of the reagents are consumed after 2 chemistry ticks.
* HALF_LIFE(3) -> Half of the reagents are consumed after 3 chemistry ticks.
*/
#define HALF_LIFE(ticks) (ticks? 1.0 - (0.5)**(1.0/(ticks*PROCESS_REACTION_ITER)) : 1.0)
20 changes: 20 additions & 0 deletions code/__DEFINES/reagents/chemical_reaction.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//* This file is explicitly licensed under the MIT license. *//
//* Copyright (c) 2024 Citadel Station Developers *//

//* flags for /datum/chemical_reaction/var/chemical_reaction_flags *//

// none yet

//* flags for /datum/chemical_reaction/var/reaction_guidebook_flags *//

/// doesn't show in guidebook reaction list
#define REACTION_GUIDEBOOK_UNLISTED (1<<0)
/// can't be pulled up on guidebook at all, other than name
#define REACTION_GUIDEBOOK_HIDDEN (1<<1)

DEFINE_SHARED_BITFIELD(reaction_guidebook_flags, list(
"reaction_guidebook_flags",
), list(
BITFIELD(REACTION_GUIDEBOOK_UNLISTED),
BITFIELD(REACTION_GUIDEBOOK_HIDDEN),
))
39 changes: 0 additions & 39 deletions code/__DEFINES/reagents/flags.dm

This file was deleted.

20 changes: 20 additions & 0 deletions code/__DEFINES/reagents/reagent.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//* This file is explicitly licensed under the MIT license. *//
//* Copyright (c) 2024 Citadel Station Developers *//

//* flags for /datum/reagent/var/reagent_flags *//

// none yet

//* flags for /datum/reagent/var/reagent_guidebook_flags *//

/// doesn't show in guidebook reagent list
#define REAGENT_GUIDEBOOK_UNLISTED (1<<0)
/// can't be pulled up on guidebook at all, other than name
#define REAGENT_GUIDEBOOK_HIDDEN (1<<1)

DEFINE_SHARED_BITFIELD(reagent_guidebook_flags, list(
"reagent_guidebook_flags",
), list(
BITFIELD(REAGENT_GUIDEBOOK_UNLISTED),
BITFIELD(REAGENT_GUIDEBOOK_HIDDEN),
))
7 changes: 7 additions & 0 deletions code/__DEFINES/reagents/reagent_holder.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//* This file is explicitly licensed under the MIT license. *//
//* Copyright (c) 2024 Citadel Station Developers *//

//* flags for /datum/reagent_holder/var/reagent_holder_flags *//

/// currently reacting
#define REAGENT_HOLDER_FLAG_CURRENTLY_REACTING (1<<0)
31 changes: 13 additions & 18 deletions code/__HELPERS/reagents.dm
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
// todo: this doesn't entirely work. see recipe for peridaxon requiring priority.
/proc/chem_recipes_do_conflict(datum/chemical_reaction/r1, datum/chemical_reaction/r2)
// do the non-list tests first, because they are cheaper
if(r1.required_container != r2.required_container)
// we can only conflict with something that requires the same container
if(r1.required_container_path != r2.required_container_path)
return FALSE
// if(r1.is_cold_recipe == r2.is_cold_recipe)
// if(r1.required_temp != r2.required_temp)
// //one reaction requires a more extreme temperature than the other, so there is no conflict
// return FALSE
// else
// var/datum/chemical_reaction/cold_one = r1.is_cold_recipe ? r1 : r2
// var/datum/chemical_reaction/warm_one = r1.is_cold_recipe ? r2 : r1
// if(cold_one.required_temp < warm_one.required_temp)
// //the range of temperatures does not overlap, so there is no conflict
// return FALSE

// we cannot conflict with a non-overlapping temperature range
if(r1.temperature_low >= r2.temperature_high || r1.temperature_high <= r2.temperature_low)
return FALSE

// todo: legacy below

//find the reactions with the shorter and longer required_reagents list
var/datum/chemical_reaction/long_req
var/datum/chemical_reaction/short_req
if(r1.required_reagents.len > r2.required_reagents.len)
if(length(r1.required_reagents) > length(r2.required_reagents))
long_req = r1
short_req = r2
else if(r1.required_reagents.len < r2.required_reagents.len)
else if(length(r1.required_reagents) < length(r2.required_reagents))
long_req = r2
short_req = r1
else
//if they are the same length, sort instead by the length of the catalyst list
//this is important if the required_reagents lists are the same
if(r1.catalysts.len > r2.catalysts.len)
if(length(r1.catalysts) > length(r2.catalysts))
long_req = r1
short_req = r2
else
Expand All @@ -35,15 +30,15 @@


//check if the shorter reaction list is a subset of the longer one
var/list/overlap = r1.required_reagents & r2.required_reagents
var/list/overlap = (r1.required_reagents || list()) & (r2.required_reagents || list())
if(overlap.len != short_req.required_reagents.len)
//there is at least one reagent in the short list that is not in the long list, so there is no conflict
return FALSE

//check to see if the shorter reaction's catalyst list is also a subset of the longer reaction's catalyst list
//if the longer reaction's catalyst list is a subset of the shorter ones, that is fine
//if the reaction lists are the same, the short reaction will have the shorter required_catalysts list, so it will register as a conflict
var/list/short_minus_long_catalysts = short_req.catalysts - long_req.catalysts
var/list/short_minus_long_catalysts = (short_req.catalysts || list()) - (long_req.catalysts || list())
if(short_minus_long_catalysts.len)
//there is at least one unique catalyst for the short reaction, so there is no conflict
return FALSE
Expand Down
Loading
Loading