Files
Bubberstation/code/modules/reagents/chem_splash.dm
T
SyncIt21andRoxy 67ba6cb2f3 Final reagent enhancements (#89289)
## About The Pull Request
**1. Code Improvements**
- `get_reagent_log_string()` now won't round reagent volumes cause they
are already rounded by `update_total()` so its slightly faster
- `trans_to()` now logs reagents faster as it does it in place without
the overhead of passing the list to `get_external_reagent_log_string()`
which parses our list into another list which is just unessassary
- `trans_to()` is now faster performance wise as it no longer relies on
`remove_reagent()` to remove the reagent
- Merged `multiply_single_reagent()` into a single proc `multiply()`
which does the job for both single & multiple reagents to reduce code.
it now no longer uses proc `remove_reagent()` making it faster when
reducing reagents
- `copy_to()` no longer rounds its return value thus improving
performance & won't return false negatives for values lesser than 0.01

**2. Fixes**
- Fixes `multiply_single_reagent()` multiplying reagent subtypes as well
instead of just the target type as it uses `locate()`
- Fixes `multiply_reagents()` multiplying reagents twice. Notice how it
would call `_multiply_reagent()` & then again do the exact same thing as
that proc in the next line

https://github.com/tgstation/tgstation/blob/dfe9f50ad74507dabf8b9a534f385cad170c53c1/code/modules/reagents/chemistry/holder/holder.dm#L605-L609
- `convert_reagent()` actually uses the weighted ph. I was wrong in what
I assumed `override_base_ph` did

Just lesser & faster code overall

## Changelog
🆑
fix: multiplying reagents in cases like fishing & chem splash will yield
accurate results. New amounts differ from present values
fix: converting reagents actually yields correct ph again
code: improved performance of reagent logging
code: copying reagents won't return false negatives for values lesser
than 0.01
/🆑
2025-03-12 16:05:34 -04:00

120 lines
4.8 KiB
Plaintext

// Replaces chemgrenade stuff, allowing reagent explosions to be called from anywhere.
// It should be called using a location, the range, and a list of reagents involved.
// Threatscale is a multiplier for the 'threat' of the grenade. If you're increasing the affected range drastically, you might want to improve this.
// Extra heat affects the temperature of the mixture, and may cause it to react in different ways.
/**
* The basic chemical bomb proc.
* Combines a set of reagent holders into one holder and reacts it.
* If there are any reagents left over it spreads them across the surrounding environment.
* The maximum volume of the holder is temporarily adjusted to allow for reactions which increase total volume to work at full effectiveness.
* The maximum volume of the holder is then reset to its original value.
*
* Arguments:
* - [epicenter][/turf]: The epicenter of the splash if some of the reagents aren't consumed.
* - [holder][/datum/reagents]: The holder to combine all of the reagents into. A temporary one is created if this is null.
* - [reactants][/list/datum/reagents]: The set of reagent holders to combine.
* - extra_heat: Some amount to heat the combined reagents by before reacting them.
* - threatscale: A multiplier for the reagent quantities involved.
* - adminlog: Whether to alert the admins that this has occured.
*/
/proc/chem_splash(turf/epicenter, datum/reagents/holder = null, affected_range = 3, list/datum/reagents/reactants = list(), extra_heat = 0, threatscale = 1, adminlog = 1)
if(!isturf(epicenter) || !reactants.len || threatscale <= 0)
return
var/total_reagents = holder?.total_volume
var/maximum_reagents = holder?.maximum_volume
for(var/datum/reagents/reactant in reactants)
if(reactant.total_volume)
total_reagents += reactant.total_volume
maximum_reagents += reactant.maximum_volume
if (total_reagents <= 0)
return FALSE
var/tmp_holder = null
var/original_max_volume = null
if (isnull(holder))
tmp_holder = TRUE
holder = new /datum/reagents(maximum_reagents * threatscale)
holder.my_atom = epicenter
else
tmp_holder = FALSE
original_max_volume = holder.maximum_volume
if(threatscale < 1)
holder.multiply(threatscale)
holder.maximum_volume = maximum_reagents * threatscale
else
holder.maximum_volume = maximum_reagents * threatscale
holder.multiply(threatscale)
for(var/datum/reagents/reactant as anything in reactants)
reactant.trans_to(holder, reactant.total_volume, threatscale, no_react = TRUE)
holder.chem_temp += extra_heat // Average temperature of reagents + extra heat.
holder.handle_reactions() // React them now.
if(holder.total_volume)
if(affected_range >= 0)
spread_reagents(holder, epicenter, affected_range)
holder.clear_reagents()
if(tmp_holder)
qdel(holder)
else
holder.maximum_volume = original_max_volume
return TRUE
/**
* Exposes all accessible atoms within some distance of an epicenter to some reagents.
* Does not clear the source reagent holder; that must be done manually if it is desired.
*
* Arguments:
* - [source][/datum/reagents]: The reagents to spread around.
* - [epicenter][/atom]: The epicenter/source location of the reagent spread.
* - spread_range: The range in which to spread the reagents. Will not go over 20
*/
/proc/spread_reagents(datum/reagents/source, atom/epicenter, spread_range)
spread_range = min(spread_range, 20) // Fuck off with trying to do more then this
var/datum/effect_system/steam_spread/steam = new /datum/effect_system/steam_spread()
steam.set_up(10, 0, epicenter)
steam.attach(epicenter)
steam.start()
// This is a basic floodfill algorithm of atmos connected tiles
// Turfs will be stored in the form turf -> TRUE
var/chem_temp = source.chem_temp
var/hot_chem = chem_temp >= 300
var/list/turflist = list()
var/list/reactable = list()
turflist[epicenter] = TRUE
for(var/i = 1; i <= length(turflist); i++)
var/turf/valid_step = turflist[i]
if(get_dist(valid_step, epicenter) > spread_range) // We are over threshold, don't add anything new and just keep goin
turflist.Cut(i, i+1)
i--
continue
for(var/turf/lad as anything in valid_step.atmos_adjacent_turfs)
if(turflist[lad])
continue
turflist[lad] = TRUE
reactable += valid_step.get_all_contents() // Yes this means multitile objects double react. I don't care. skill issue
if(hot_chem)
valid_step.hotspot_expose(chem_temp*2, 5)
// Remove anything we can't see
for(var/atom/thing as anything in (dview(spread_range, epicenter) & reactable))
var/distance = max(1, get_dist(thing, epicenter))
var/fraction = 0.5 / (2 ** distance) //50/25/12/6... for a 200u splash, 25/12/6/3... for a 100u, 12/6/3/1 for a 50u
source.expose(thing, TOUCH, fraction)
// SKYRAT EDIT ADDITION START - Liquids
if(isturf(epicenter))
var/turf/center_of_mess = epicenter
center_of_mess.add_liquid_from_reagents(source)
// SKYRAT EDIT ADDITION END