Skip to content

Commit

Permalink
[MIRROR] [NO GBP] Apply multiplier correctly when transferring reagen…
Browse files Browse the repository at this point in the history
…ts. [MDB IGNORE] (#24489)

* [NO GBP] Apply multiplier correctly when transferring reagents. (#79084)

## About The Pull Request
- Fixes #79083

The multiplier should be applied per reagent volume & not on the
requested amount as a whole.

## Changelog
:cl:
fix: cryo and stuff that transfers reagents with a multiplier should
transfer correct volumes as expected.
/:cl:

* [NO GBP] Apply multiplier correctly when transferring reagents.

---------

Co-authored-by: SyncIt21 <[email protected]>
  • Loading branch information
2 people authored and FFMirrorBot committed Oct 21, 2023
1 parent a9d96ac commit 576854b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion code/datums/components/plumbing/reaction_chamber.dm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

//compute how much more is needed and round it
diff = chamber.required_reagents[required_reagent] - present_amount
if(diff >= CHEMICAL_QUANTISATION_LEVEL * 10) //should be safe even after rounding
if(diff >= 0.01)
process_request(min(diff, MACHINE_REAGENT_TRANSFER), required_reagent, dir)
return

Expand Down
2 changes: 1 addition & 1 deletion code/modules/plumbing/plumbers/bottler.dm
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
return PROCESS_KILL

///see if machine has enough to fill, is anchored down and has any inputspot objects to pick from
if(reagents.total_volume + (CHEMICAL_QUANTISATION_LEVEL * 10) >= wanted_amount && anchored && length(inputspot.contents))
if(reagents.total_volume + 0.01 >= wanted_amount && anchored && length(inputspot.contents))
use_power(active_power_usage * seconds_per_tick)
var/obj/AM = pick(inputspot.contents)///pick a reagent_container that could be used
if((is_reagent_container(AM) && !istype(AM, /obj/item/reagent_containers/hypospray/medipen)) || istype(AM, /obj/item/ammo_casing/shotgun/dart))
Expand Down
2 changes: 1 addition & 1 deletion code/modules/plumbing/plumbers/pill_press.dm
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
return

//shift & check to account for floating point inaccuracies
if(reagents.total_volume + (CHEMICAL_QUANTISATION_LEVEL * 10) >= current_volume)
if(reagents.total_volume + 0.01 >= current_volume)
var/obj/item/reagent_containers/container = locate(packaging_type)
container = new container(src)
var/suffix
Expand Down
40 changes: 22 additions & 18 deletions code/modules/reagents/chemistry/holder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
if(!ignore_splitting && (flags & REAGENT_HOLDER_ALIVE)) //Stomachs are a pain - they will constantly call on_mob_add unless we split on addition to stomachs, but we also want to make sure we don't double split
var/adjusted_vol = FLOOR(process_mob_reagent_purity(glob_reagent, amount, added_purity), CHEMICAL_QUANTISATION_LEVEL)
if(adjusted_vol <= 0) //If we're inverse or FALSE cancel addition
return TRUE
return amount
/* We return true here because of #63301
The only cases where this will be false or 0 if its an inverse chem, an impure chem of 0 purity (highly unlikely if even possible), or if glob_reagent is null (which shouldn't happen at all as there's a check for that a few lines up),
In the first two cases, we would want to return TRUE so trans_to and other similar methods actually delete the corresponding chemical from the original reagent holder.
Expand Down Expand Up @@ -158,7 +158,7 @@
SEND_SIGNAL(src, COMSIG_REAGENTS_ADD_REAGENT, iter_reagent, amount, reagtemp, data, no_react)
if(!no_react && !is_reacting) //To reduce the amount of calculations for a reaction the reaction list is only updated on a reagents addition.
handle_reactions()
return TRUE
return amount

//otherwise make a new one
var/datum/reagent/new_reagent = new reagent_type(data)
Expand Down Expand Up @@ -187,7 +187,7 @@
SEND_SIGNAL(src, COMSIG_REAGENTS_NEW_REAGENT, new_reagent, amount, reagtemp, data, no_react)
if(!no_react)
handle_reactions()
return TRUE
return amount

/**
* Like add_reagent but you can enter a list.
Expand Down Expand Up @@ -227,7 +227,7 @@
var/list/cached_reagents = reagent_list
for(var/datum/reagent/cached_reagent as anything in cached_reagents)
if(cached_reagent.type == reagent_type)
cached_reagent.volume = FLOOR(max(cached_reagent.volume - amount, 0), CHEMICAL_QUANTISATION_LEVEL)
cached_reagent.volume = FLOOR(max(cached_reagent.volume - amount, 0), CHEMICAL_QUANTISATION_LEVEL)
update_total()
if(!safety)//So it does not handle reactions when it need not to
handle_reactions()
Expand Down Expand Up @@ -491,7 +491,7 @@
* Arguments:
* * obj/target - Target to attempt transfer to
* * amount - amount of reagent volume to transfer
* * multiplier - multiplies amount of each reagent by this number
* * multiplier - multiplies each reagent amount by this number well byond their available volume before transfering. used to create reagents from thin air if you ever need to
* * preserve_data - if preserve_data=0, the reagents data will be lost. Usefull if you use data for some strange stuff and don't want it to be transferred.
* * no_react - passed through to [/datum/reagents/proc/add_reagent]
* * mob/transferred_by - used for logging
Expand Down Expand Up @@ -546,7 +546,7 @@
var/cached_amount = amount

// Prevents small amount problems, as well as zero and below zero amounts.
amount = FLOOR(min(amount * multiplier, total_volume, target_holder.maximum_volume - target_holder.total_volume), CHEMICAL_QUANTISATION_LEVEL)
amount = FLOOR(min(amount, total_volume, target_holder.maximum_volume - target_holder.total_volume), CHEMICAL_QUANTISATION_LEVEL)
if(amount <= 0)
return FALSE

Expand All @@ -561,7 +561,8 @@

var/part = amount / total_volume
var/transfer_amount
var/transfered_amount = 0
var/transfered_amount
var/total_transfered_amount = 0

//first add reagents to target
for(var/datum/reagent/reagent as anything in cached_reagents)
Expand All @@ -571,13 +572,14 @@
trans_data = copy_data(reagent)
if(reagent.intercept_reagents_transfer(target_holder, cached_amount))
continue
transfer_amount = FLOOR(reagent.volume * part, CHEMICAL_QUANTISATION_LEVEL)
if(!target_holder.add_reagent(reagent.type, transfer_amount, trans_data, chem_temp, reagent.purity, reagent.ph, no_react = TRUE, ignore_splitting = reagent.chemical_flags & REAGENT_DONOTSPLIT)) //we only handle reaction after every reagent has been transferred.
transfer_amount = reagent.volume * part
transfered_amount = target_holder.add_reagent(reagent.type, transfer_amount * multiplier, trans_data, chem_temp, reagent.purity, reagent.ph, no_react = TRUE, ignore_splitting = reagent.chemical_flags & REAGENT_DONOTSPLIT) //we only handle reaction after every reagent has been transferred.
if(!transfered_amount)
continue
if(methods)
r_to_send += reagent
reagents_to_remove += list(list("R" = reagent, "T" = transfer_amount))
transfered_amount += transfer_amount
total_transfered_amount += transfered_amount

//expose target to reagent changes
target_holder.expose_multiple(r_to_send, isorgan(target_atom) ? target : target_atom, methods, part, show_message)
Expand All @@ -600,7 +602,7 @@
if(!no_react)
target_holder.handle_reactions()
src.handle_reactions()
return transfered_amount
return FLOOR(total_transfered_amount, CHEMICAL_QUANTISATION_LEVEL)

/**
* Transfer a specific reagent id to the target object
Expand Down Expand Up @@ -665,7 +667,7 @@
* Arguments
*
* * [target][obj] - the target to transfer reagents to
* * multiplier - the multiplier applied on all reagent volumes before transfering
* * multiplier - multiplies each reagent amount by this number well byond their available volume before transfering. used to create reagents from thin air if you ever need to
* * preserve_data - preserve user data of all reagents after transfering
* * no_react - if TRUE will not handle reactions
*/
Expand All @@ -692,23 +694,25 @@
target_holder = target.reagents

// Prevents small amount problems, as well as zero and below zero amounts.
amount = FLOOR(min(amount * multiplier, total_volume, target_holder.maximum_volume - target_holder.total_volume), CHEMICAL_QUANTISATION_LEVEL)
amount = FLOOR(min(amount, total_volume, target_holder.maximum_volume - target_holder.total_volume), CHEMICAL_QUANTISATION_LEVEL)
if(amount <= 0)
return

var/list/cached_reagents = reagent_list
var/part = amount / total_volume
var/transfer_amount
var/transfered_amount = 0
var/total_transfered_amount = 0
var/trans_data = null

for(var/datum/reagent/reagent as anything in cached_reagents)
transfer_amount = FLOOR(reagent.volume * part, CHEMICAL_QUANTISATION_LEVEL)
transfer_amount = reagent.volume * part * multiplier
if(preserve_data)
trans_data = reagent.data
if(!target_holder.add_reagent(reagent.type, transfer_amount, trans_data, chem_temp, reagent.purity, reagent.ph, no_react = TRUE, ignore_splitting = reagent.chemical_flags & REAGENT_DONOTSPLIT))
transfered_amount = target_holder.add_reagent(reagent.type, transfer_amount, trans_data, chem_temp, reagent.purity, reagent.ph, no_react = TRUE, ignore_splitting = reagent.chemical_flags & REAGENT_DONOTSPLIT)
if(!transfered_amount)
continue
transfered_amount += transfer_amount
total_transfered_amount += transfered_amount

if(!no_react)
// pass over previous ongoing reactions before handle_reactions is called
Expand All @@ -717,7 +721,7 @@
target_holder.update_total()
target_holder.handle_reactions()

return transfered_amount
return FLOOR(total_transfered_amount, CHEMICAL_QUANTISATION_LEVEL)

/**
* Multiplies the reagents inside this holder by a specific amount
Expand Down Expand Up @@ -1410,7 +1414,7 @@

/// Is this holder full or not
/datum/reagents/proc/holder_full()
return total_volume >= maximum_volume
return total_volume + 0.01 >= maximum_volume

/**
* Get the amount of this reagent or the sum of all its subtypes if specified
Expand Down

0 comments on commit 576854b

Please sign in to comment.