From 0caef258d6d8eca96fb6df0459316808d7175217 Mon Sep 17 00:00:00 2001 From: Belaya Date: Tue, 29 Jul 2025 15:32:20 -0500 Subject: [PATCH 1/3] Fix issue with plumbing reaction chambers getting stuck filling --- code/__DEFINES/reagents.dm | 3 +++ code/datums/components/plumbing/_plumbing.dm | 7 ++++++- code/datums/components/plumbing/reaction_chamber.dm | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/code/__DEFINES/reagents.dm b/code/__DEFINES/reagents.dm index 3e8f6081bd..b40ff65196 100644 --- a/code/__DEFINES/reagents.dm +++ b/code/__DEFINES/reagents.dm @@ -88,6 +88,9 @@ #define REACTION_CLEAR_IMPURE (1<<0) //Convert into impure/pure on reaction completion #define REACTION_CLEAR_INVERSE (1<<1) //Convert into inverse on reaction completion when purity is low enough +///The minimum volume of reagents than can be operated on. +#define CHEMICAL_QUANTISATION_LEVEL 0.0001 + //Chemical blacklists for smartdarts GLOBAL_LIST_INIT(blacklisted_medchems, list( /datum/reagent/medicine/morphine, /datum/reagent/medicine/haloperidol, //harmful chemicals in medicine diff --git a/code/datums/components/plumbing/_plumbing.dm b/code/datums/components/plumbing/_plumbing.dm index cebd7d4b0e..cc80581866 100644 --- a/code/datums/components/plumbing/_plumbing.dm +++ b/code/datums/components/plumbing/_plumbing.dm @@ -66,9 +66,14 @@ var/datum/component/plumbing/supplier = A if(supplier.can_give(amount, reagent, net)) valid_suppliers += supplier + // Need to ask for each in turn very carefully, making sure we get the total volume. This is to avoid a division that would always round down and become 0 + var/targetVolume = reagents.total_volume = amount + var/suppliersLeft = valid_suppliers.len for(var/A in valid_suppliers) var/datum/component/plumbing/give = A - give.transfer_to(src, amount / valid_suppliers.len, reagent, net) + var/currentRequest = (targetVolume - reagents.total_volume) / suppliersLeft + give.transfer_to(src, currentRequest, reagent, net) + suppliersLeft-- ///returns TRUE when they can give the specified amount and reagent. called by process request /datum/component/plumbing/proc/can_give(amount, reagent, datum/ductnet/net) if(amount <= 0) diff --git a/code/datums/components/plumbing/reaction_chamber.dm b/code/datums/components/plumbing/reaction_chamber.dm index 90f4e621da..6bd1464e59 100644 --- a/code/datums/components/plumbing/reaction_chamber.dm +++ b/code/datums/components/plumbing/reaction_chamber.dm @@ -23,7 +23,7 @@ var/datum/reagent/RD = A if(RT == RD.type) has_reagent = TRUE - if(RD.volume < RC.required_reagents[RT]) + if(RD.volume + CHEMICAL_QUANTISATION_LEVEL < RC.required_reagents[RT]) // Allow the chamber to exit filling mode when it feels it has enough even if short by a tiny fraction process_request(min(RC.required_reagents[RT] - RD.volume, MACHINE_REAGENT_TRANSFER) , RT, dir) return if(!has_reagent) From eba2dfdd88aa5db27ea02aa2c721534f8082804f Mon Sep 17 00:00:00 2001 From: Belaya Date: Thu, 31 Jul 2025 18:34:30 -0500 Subject: [PATCH 2/3] edit comment --- code/__DEFINES/reagents.dm | 1 + code/datums/components/plumbing/_plumbing.dm | 2 +- code/datums/components/plumbing/reaction_chamber.dm | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/code/__DEFINES/reagents.dm b/code/__DEFINES/reagents.dm index b40ff65196..913cb70cef 100644 --- a/code/__DEFINES/reagents.dm +++ b/code/__DEFINES/reagents.dm @@ -88,6 +88,7 @@ #define REACTION_CLEAR_IMPURE (1<<0) //Convert into impure/pure on reaction completion #define REACTION_CLEAR_INVERSE (1<<1) //Convert into inverse on reaction completion when purity is low enough +///GS13 edit ///The minimum volume of reagents than can be operated on. #define CHEMICAL_QUANTISATION_LEVEL 0.0001 diff --git a/code/datums/components/plumbing/_plumbing.dm b/code/datums/components/plumbing/_plumbing.dm index cc80581866..ad2050e401 100644 --- a/code/datums/components/plumbing/_plumbing.dm +++ b/code/datums/components/plumbing/_plumbing.dm @@ -66,7 +66,7 @@ var/datum/component/plumbing/supplier = A if(supplier.can_give(amount, reagent, net)) valid_suppliers += supplier - // Need to ask for each in turn very carefully, making sure we get the total volume. This is to avoid a division that would always round down and become 0 + ///GS13 Edit: Need to ask for each in turn very carefully, making sure we get the total volume. This is to avoid a division that would always round down and become 0 var/targetVolume = reagents.total_volume = amount var/suppliersLeft = valid_suppliers.len for(var/A in valid_suppliers) diff --git a/code/datums/components/plumbing/reaction_chamber.dm b/code/datums/components/plumbing/reaction_chamber.dm index 6bd1464e59..3019e99a44 100644 --- a/code/datums/components/plumbing/reaction_chamber.dm +++ b/code/datums/components/plumbing/reaction_chamber.dm @@ -23,7 +23,7 @@ var/datum/reagent/RD = A if(RT == RD.type) has_reagent = TRUE - if(RD.volume + CHEMICAL_QUANTISATION_LEVEL < RC.required_reagents[RT]) // Allow the chamber to exit filling mode when it feels it has enough even if short by a tiny fraction + if(RD.volume + CHEMICAL_QUANTISATION_LEVEL < RC.required_reagents[RT]) //GS13 Edit: Allow the chamber to exit filling mode when it feels it has enough even if short by a tiny fraction process_request(min(RC.required_reagents[RT] - RD.volume, MACHINE_REAGENT_TRANSFER) , RT, dir) return if(!has_reagent) From fe1d34c260837b3028259fef6027ecac5b5777dd Mon Sep 17 00:00:00 2001 From: Belaya Date: Thu, 31 Jul 2025 18:36:04 -0500 Subject: [PATCH 3/3] One more comment --- code/datums/components/plumbing/_plumbing.dm | 1 + 1 file changed, 1 insertion(+) diff --git a/code/datums/components/plumbing/_plumbing.dm b/code/datums/components/plumbing/_plumbing.dm index ad2050e401..e692b53fe4 100644 --- a/code/datums/components/plumbing/_plumbing.dm +++ b/code/datums/components/plumbing/_plumbing.dm @@ -71,6 +71,7 @@ var/suppliersLeft = valid_suppliers.len for(var/A in valid_suppliers) var/datum/component/plumbing/give = A + //GS13 Edit: See above comment var/currentRequest = (targetVolume - reagents.total_volume) / suppliersLeft give.transfer_to(src, currentRequest, reagent, net) suppliersLeft--