From 0caef258d6d8eca96fb6df0459316808d7175217 Mon Sep 17 00:00:00 2001 From: Belaya Date: Tue, 29 Jul 2025 15:32:20 -0500 Subject: [PATCH] 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)