mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-24 05:30:05 +01:00
+37






![tgstation-ci[bot] <179393467+tgstation-ci[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)


Alexis
GitHub
tgstation-ci[bot] <179393467+tgstation-ci[bot]@users.noreply.github.com>
ArcaneMusic
MrMelbert
Rhials
rageguy505
LemonInTheDark
John Willard
Aliceee2ch
Time-Green
Tsar-Salat
SmArtKar
Maxipat
SyncIt21
deltanedas
SimplyLogan
loganuk
Leland Kemble
FalloutFalcon
Roxy
Lucy
siliconOpossum
Isratosh
TheRyeGuyWhoWillNowDie
Neocloudy
Alexander V.
ElGitificador
Twaticus
dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bloop
Cameron Lennox
Tim
Iamgoofball
Layzu666
Arturlang
_0Steven
mrmanlikesbt
Ben10Omintrix
John F. Kennedy
Cursor
Josh
Josh Powell
Yobrocharlie
Hardly3D
shayoki
LT3
21b4095dfd
Upstream 04/17/2026 fixes https://github.com/Bubberstation/Bubberstation/issues/5549 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: tgstation-ci[bot] <179393467+tgstation-ci[bot]@users.noreply.github.com> Co-authored-by: ArcaneMusic <41715314+ArcaneMusic@users.noreply.github.com> Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Co-authored-by: Rhials <28870487+Rhials@users.noreply.github.com> Co-authored-by: rageguy505 <54517726+rageguy505@users.noreply.github.com> Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com> Co-authored-by: Aliceee2ch <160794176+Aliceee2ch@users.noreply.github.com> Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com> Co-authored-by: Tsar-Salat <62388554+Tsar-Salat@users.noreply.github.com> Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com> Co-authored-by: Maxipat <108554989+Maxipat112@users.noreply.github.com> Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: SimplyLogan <47579821+loganuk@users.noreply.github.com> Co-authored-by: loganuk <fakeemail123@aol.com> Co-authored-by: Leland Kemble <70413276+lelandkemble@users.noreply.github.com> Co-authored-by: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com> Co-authored-by: Roxy <75404941+TealSeer@users.noreply.github.com> Co-authored-by: Lucy <lucy@absolucy.moe> Co-authored-by: siliconOpossum <138069572+siliconOpossum@users.noreply.github.com> Co-authored-by: Isratosh <Isratosh@hotmail.com> Co-authored-by: TheRyeGuyWhoWillNowDie <70169560+TheRyeGuyWhoWillNowDie@users.noreply.github.com> Co-authored-by: Neocloudy <88008002+Neocloudy@users.noreply.github.com> Co-authored-by: Alexander V. <volas@ya.ru> Co-authored-by: ElGitificador <168473461+ElGitificador@users.noreply.github.com> Co-authored-by: Twaticus <46540570+Twaticus@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com> Co-authored-by: Cameron Lennox <killer65311@gmail.com> Co-authored-by: Tim <timothymtorres@gmail.com> Co-authored-by: Iamgoofball <iamgoofball@gmail.com> Co-authored-by: Layzu666 <121319428+Layzu666@users.noreply.github.com> Co-authored-by: Arturlang <24881678+Arturlang@users.noreply.github.com> Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com> Co-authored-by: mrmanlikesbt <99309552+mrmanlikesbt@users.noreply.github.com> Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> Co-authored-by: John F. Kennedy <54908920+MacaroniCritter@users.noreply.github.com> Co-authored-by: Cursor <102828457+theselfish@users.noreply.github.com> Co-authored-by: Josh <josh.adam.powell@gmail.com> Co-authored-by: Josh Powell <josh.powell@softwire.com> Co-authored-by: Yobrocharlie <Charliemiller5617@gmail.com> Co-authored-by: Hardly3D <66234359+Hardly3D@users.noreply.github.com> Co-authored-by: shayoki <96078776+shayoki@users.noreply.github.com> Co-authored-by: LT3 <83487515+lessthnthree@users.noreply.github.com>
327 lines
9.7 KiB
Plaintext
327 lines
9.7 KiB
Plaintext
|
|
/**
|
|
* Specialized reagent container for plumbing. Uses the round robin approach of transferring reagents
|
|
* so transfer 5 from 15 water, 15 sugar and 15 plasma becomes 10, 15, 15 instead of 13.3333, 13.3333 13.3333. Good if you hate floating point errors
|
|
*/
|
|
/datum/reagents/plumbing
|
|
|
|
/**
|
|
* Same as the parent trans_to except only a few arguments have impact here & the rest of the arguments are discarded.
|
|
* Arguments
|
|
*
|
|
* * atom/target - the target we are transfering to
|
|
* * amount - amount to transfer
|
|
* * datum/reagent/target_id - the reagent id we want to transfer. if null everything gets transfered
|
|
* * methods - this is key for deciding between round-robin or proportional transfer. It does not mean the same as the
|
|
* parent proc. LINEAR for round robin(in this technique reagents are missing/lost/not preserved when there isn't enough space to hold them)
|
|
* NONE means everything is transfered regardless of how much space is available in the receiver in proportions
|
|
*/
|
|
/datum/reagents/plumbing/trans_to(
|
|
atom/target,
|
|
amount = 1,
|
|
multiplier = 1, //unused for plumbing
|
|
datum/reagent/target_id,
|
|
preserve_data = TRUE, //unused for plumbing
|
|
no_react = FALSE, //unused for plumbing we always want reactions
|
|
mob/transferred_by, //unused for plumbing logging is not important inside plumbing machines
|
|
remove_blacklisted = FALSE, //unused for plumbing, we don't care what reagents are inside us
|
|
methods = LINEAR, //default round robin technique for transferring reagents
|
|
show_message = TRUE, //unused for plumbing, used for logging only
|
|
ignore_stomach = FALSE, //unused for plumbing, reagents flow only between machines & is not injected to mobs at any point in time
|
|
copy_only = FALSE //unused
|
|
)
|
|
if(QDELETED(target) || !total_volume)
|
|
return FALSE
|
|
|
|
if(!IS_FINITE(amount))
|
|
stack_trace("non finite amount passed to trans_to [amount] amount of reagents")
|
|
return FALSE
|
|
|
|
if(!isnull(target_id) && !ispath(target_id))
|
|
stack_trace("invalid target reagent id [target_id] passed to trans_to")
|
|
return FALSE
|
|
|
|
var/datum/reagents/target_holder
|
|
if(istype(target, /datum/reagents))
|
|
target_holder = target
|
|
else
|
|
target_holder = target.reagents
|
|
|
|
// Prevents small amount problems, as well as zero and below zero amounts.
|
|
amount = round(min(amount, total_volume, target_holder.maximum_volume - target_holder.total_volume), CHEMICAL_QUANTISATION_LEVEL)
|
|
if(amount <= 0)
|
|
return FALSE
|
|
|
|
var/list/cached_reagents = reagent_list
|
|
var/transfer_amount
|
|
var/transfered_amount
|
|
var/total_transfered_amount = 0
|
|
|
|
var/round_robin = methods & LINEAR
|
|
var/part
|
|
var/to_transfer
|
|
if(round_robin)
|
|
to_transfer = amount
|
|
else
|
|
part = amount / total_volume
|
|
|
|
//first add reagents to target
|
|
for(var/datum/reagent/reagent as anything in cached_reagents)
|
|
if(round_robin && !to_transfer)
|
|
break
|
|
|
|
if(!isnull(target_id))
|
|
if(reagent.type == target_id)
|
|
transfer_amount = min(amount, reagent.volume)
|
|
else
|
|
continue
|
|
else
|
|
if(round_robin)
|
|
transfer_amount = min(to_transfer, reagent.volume)
|
|
else
|
|
transfer_amount = reagent.volume * part
|
|
|
|
if(reagent.intercept_reagents_transfer(target_holder, transfer_amount))
|
|
continue
|
|
|
|
transfered_amount = target_holder.add_reagent(reagent.type, transfer_amount, copy_data(reagent), chem_temp, reagent.purity, reagent.ph, no_react = TRUE) //we only handle reaction after every reagent has been transferred.
|
|
if(!transfered_amount)
|
|
continue
|
|
total_transfered_amount += transfered_amount
|
|
if(round_robin)
|
|
to_transfer -= transfered_amount
|
|
reagent.volume -= transfered_amount
|
|
|
|
if(!isnull(target_id))
|
|
break
|
|
update_total()
|
|
|
|
return total_transfered_amount
|
|
|
|
///Excludes catalysts during the emptying process
|
|
/datum/reagents/plumbing/reaction_chamber
|
|
|
|
///Returns the total volume of reagents without the catalysts
|
|
/datum/reagents/plumbing/reaction_chamber/proc/get_catalyst_excluded_volume()
|
|
SHOULD_NOT_OVERRIDE(TRUE)
|
|
|
|
. = 0
|
|
|
|
//no reagents
|
|
if(!total_volume)
|
|
return
|
|
|
|
var/obj/machinery/plumbing/reaction_chamber/reactor = my_atom
|
|
var/list/datum/reagent/catalysts = reactor.catalysts
|
|
|
|
//no catalysts
|
|
if(!catalysts.len)
|
|
return total_volume
|
|
|
|
//filter out catalysts except when we have excess of them
|
|
var/working_volume
|
|
var/catalyst_volume
|
|
var/list/cached_reagents = reagent_list
|
|
for(var/datum/reagent/reagent as anything in cached_reagents)
|
|
catalyst_volume = catalysts[reagent.type]
|
|
working_volume = reagent.volume
|
|
|
|
//regular reagent add to total as normal
|
|
if(!catalyst_volume)
|
|
. += working_volume
|
|
continue
|
|
|
|
//only add the excess to total as that's what will get transferred
|
|
if(working_volume > catalyst_volume)
|
|
. += working_volume - catalyst_volume
|
|
. = min(round(., CHEMICAL_VOLUME_ROUNDING), maximum_volume)
|
|
|
|
/datum/reagents/plumbing/reaction_chamber/trans_to(
|
|
atom/target,
|
|
amount = 1,
|
|
multiplier = 1,
|
|
datum/reagent/target_id,
|
|
preserve_data = TRUE,
|
|
no_react = FALSE,
|
|
mob/transferred_by,
|
|
remove_blacklisted = FALSE,
|
|
methods = LINEAR,
|
|
show_message = TRUE,
|
|
ignore_stomach = FALSE,
|
|
copy_only = FALSE
|
|
)
|
|
var/obj/machinery/plumbing/reaction_chamber/reactor = my_atom
|
|
var/list/datum/reagent/catalysts = reactor.catalysts
|
|
|
|
//usual stuff
|
|
if(!catalysts.len)
|
|
return ..()
|
|
|
|
if(QDELETED(target))
|
|
return FALSE
|
|
|
|
if(!IS_FINITE(amount))
|
|
stack_trace("non finite amount passed to trans_to [amount] amount of reagents")
|
|
return FALSE
|
|
|
|
if(!isnull(target_id) && !ispath(target_id))
|
|
stack_trace("invalid target reagent id [target_id] passed to trans_to")
|
|
return FALSE
|
|
|
|
var/datum/reagents/target_holder
|
|
if(istype(target, /datum/reagents))
|
|
target_holder = target
|
|
else
|
|
target_holder = target.reagents
|
|
var/list/cached_reagents = reagent_list
|
|
|
|
var/actual_volume = get_catalyst_excluded_volume()
|
|
|
|
// Prevents small amount problems, as well as zero and below zero amounts.
|
|
amount = round(min(amount, actual_volume, target_holder.maximum_volume - target_holder.total_volume), CHEMICAL_QUANTISATION_LEVEL)
|
|
if(amount <= 0)
|
|
return FALSE
|
|
|
|
var/working_volume
|
|
var/catalyst_volume
|
|
var/transfer_amount
|
|
var/transfered_amount
|
|
var/total_transfered_amount = 0
|
|
|
|
var/round_robin = methods & LINEAR
|
|
var/part
|
|
var/to_transfer
|
|
if(round_robin)
|
|
to_transfer = amount
|
|
else
|
|
part = amount / actual_volume
|
|
|
|
//first add reagents to target
|
|
for(var/datum/reagent/reagent as anything in cached_reagents)
|
|
if(round_robin && !to_transfer)
|
|
break
|
|
working_volume = reagent.volume
|
|
|
|
catalyst_volume = catalysts[reagent.type]
|
|
if(catalyst_volume) //we have a working catalyst
|
|
if(reagent.volume <= catalyst_volume) //dont transfer since we have the required volume
|
|
continue
|
|
else
|
|
working_volume -= catalyst_volume //dump out the excess
|
|
|
|
if(!isnull(target_id))
|
|
if(reagent.type == target_id)
|
|
transfer_amount = min(amount, working_volume)
|
|
else
|
|
continue
|
|
else
|
|
if(round_robin)
|
|
transfer_amount = min(to_transfer, working_volume)
|
|
else
|
|
transfer_amount = working_volume * part
|
|
|
|
if(reagent.intercept_reagents_transfer(target_holder, transfer_amount))
|
|
continue
|
|
|
|
transfered_amount = target_holder.add_reagent(reagent.type, transfer_amount, copy_data(reagent), chem_temp, reagent.purity, reagent.ph, no_react = TRUE) //we only handle reaction after every reagent has been transferred.
|
|
if(!transfered_amount)
|
|
continue
|
|
total_transfered_amount += transfered_amount
|
|
if(round_robin)
|
|
to_transfer -= transfered_amount
|
|
reagent.volume -= transfered_amount
|
|
|
|
if(!isnull(target_id))
|
|
break
|
|
update_total()
|
|
|
|
return total_transfered_amount
|
|
|
|
|
|
|
|
///Excludes blacklisted reagents during the transfer process
|
|
/datum/reagents/plumbing/filter
|
|
|
|
/datum/reagents/plumbing/filter/trans_to(
|
|
atom/target,
|
|
amount = 1,
|
|
multiplier = 1,
|
|
datum/reagent/target_id,
|
|
preserve_data = TRUE,
|
|
no_react = FALSE,
|
|
mob/transferred_by,
|
|
remove_blacklisted = null,
|
|
methods = LINEAR,
|
|
show_message = TRUE,
|
|
ignore_stomach = FALSE,
|
|
copy_only = FALSE
|
|
)
|
|
//usual stuff
|
|
if(!length(remove_blacklisted) || (!isnull(target_id) && ispath(target_id)))
|
|
return ..()
|
|
|
|
if(QDELETED(target))
|
|
return FALSE
|
|
|
|
if(!IS_FINITE(amount))
|
|
stack_trace("non finite amount passed to trans_to [amount] amount of reagents")
|
|
return FALSE
|
|
|
|
var/datum/reagents/target_holder
|
|
if(istype(target, /datum/reagents))
|
|
target_holder = target
|
|
else
|
|
target_holder = target.reagents
|
|
var/list/cached_reagents = reagent_list
|
|
|
|
var/actual_volume = 0
|
|
for(var/datum/reagent/reagent as anything in cached_reagents)
|
|
if(reagent.type in remove_blacklisted)
|
|
continue
|
|
actual_volume += reagent.volume
|
|
actual_volume = min(round(actual_volume, CHEMICAL_VOLUME_ROUNDING), maximum_volume)
|
|
|
|
// Prevents small amount problems, as well as zero and below zero amounts.
|
|
amount = round(min(amount, actual_volume, target_holder.maximum_volume - target_holder.total_volume), CHEMICAL_QUANTISATION_LEVEL)
|
|
if(amount <= 0)
|
|
return FALSE
|
|
|
|
var/transfer_amount
|
|
var/transfered_amount
|
|
var/total_transfered_amount = 0
|
|
|
|
var/round_robin = methods & LINEAR
|
|
var/part
|
|
var/to_transfer
|
|
if(round_robin)
|
|
to_transfer = amount
|
|
else
|
|
part = amount / actual_volume
|
|
|
|
//first add reagents to target
|
|
for(var/datum/reagent/reagent as anything in cached_reagents)
|
|
if(round_robin && !to_transfer)
|
|
break
|
|
|
|
if(reagent.type in remove_blacklisted)
|
|
continue
|
|
else
|
|
if(round_robin)
|
|
transfer_amount = min(to_transfer, reagent.volume)
|
|
else
|
|
transfer_amount = reagent.volume * part
|
|
|
|
if(reagent.intercept_reagents_transfer(target_holder, transfer_amount))
|
|
continue
|
|
|
|
transfered_amount = target_holder.add_reagent(reagent.type, transfer_amount, copy_data(reagent), chem_temp, reagent.purity, reagent.ph, no_react = TRUE) //we only handle reaction after every reagent has been transferred.
|
|
if(!transfered_amount)
|
|
continue
|
|
total_transfered_amount += transfered_amount
|
|
if(round_robin)
|
|
to_transfer -= transfered_amount
|
|
reagent.volume -= transfered_amount
|
|
update_total()
|
|
|
|
return total_transfered_amount
|