Merge pull request #6989 from VOREStation/upstream-merge-6892

[MIRROR] Distillery tweaks
This commit is contained in:
Novacat
2020-03-25 19:22:23 -04:00
committed by GitHub
3 changed files with 85 additions and 19 deletions

View File

@@ -108,6 +108,57 @@
..()
/obj/machinery/portable_atmospherics/powered/reagent_distillery/examine(mob/user)
..()
if(get_dist(user, src) < 3)
to_chat(user, "<span class='notice'>\The [src] is powered [on ? "on" : "off"].</span>")
to_chat(user, "<span class='notice'>\The [src]'s gauges read:</span>")
if(!use_atmos)
to_chat(user, "<span class='notice'>- Target Temperature:</span> <span class='warning'>[target_temp]</span>")
to_chat(user, "<span class='notice'>- Temperature:</span> <span class='warning'>[current_temp]</span>")
if(InputBeaker)
if(InputBeaker.reagents.reagent_list.len)
to_chat(user, "<span class='notice'>\The [src]'s input beaker holds [InputBeaker.reagents.total_volume] units of liquid.</span>")
else
to_chat(user, "<span class='notice'>\The [src]'s input beaker is empty!</span>")
if(Reservoir.reagents.reagent_list.len)
to_chat(user, "<span class='notice'>\The [src]'s internal buffer holds [Reservoir.reagents.total_volume] units of liquid.</span>")
else
to_chat(user, "<span class='notice'>\The [src]'s internal buffer is empty!</span>")
if(OutputBeaker)
if(OutputBeaker.reagents.reagent_list.len)
to_chat(user, "<span class='notice'>\The [src]'s output beaker holds [OutputBeaker.reagents.total_volume] units of liquid.</span>")
else
to_chat(user, "<span class='notice'>\The [src]'s output beaker is empty!</span>")
/obj/machinery/portable_atmospherics/powered/reagent_distillery/verb/toggle_power(mob/user = usr)
set name = "Toggle Distillery Heating"
set category = "Object"
set src in view(1)
if(powered())
on = !on
to_chat(user, "<span class='notice'>You turn \the [src] [on ? "on" : "off"].</span>")
else
to_chat(user, "<span class='notice'> Nothing happens.</span>")
/obj/machinery/portable_atmospherics/powered/reagent_distillery/verb/toggle_mixing(mob/user = usr)
set name = "Start Distillery Mixing"
set category = "Object"
set src in view(1)
to_chat(user, "<span class='notice'>You press \the [src]'s chamber agitator button.</span>")
if(on)
visible_message("<span class='notice'>\The [src] rattles to life.</span>")
Reservoir.reagents.handle_reactions()
else
spawn(1 SECOND)
to_chat(user, "<span class='notice'>Nothing happens..</span>")
/obj/machinery/portable_atmospherics/powered/reagent_distillery/attack_hand(mob/user)
var/list/options = list()
options["examine"] = radial_examine
@@ -138,9 +189,7 @@
examine(user)
if("use")
if(powered())
on = !on
to_chat(user, "<span class='notice'>You turn \the [src] [on ? "on" : "off"].</span>")
toggle_power(user)
if("inspect gauges")
to_chat(user, "<span class='notice'>\The [src]'s gauges read:</span>")
@@ -149,13 +198,7 @@
to_chat(user, "<span class='notice'>- Temperature:</span> <span class='warning'>[current_temp]</span>")
if("pulse agitator")
to_chat(user, "<span class='notice'>You press \the [src]'s chamber agitator button.</span>")
if(on)
visible_message("<span class='notice'>\The [src] rattles to life.</span>")
Reservoir.reagents.handle_reactions()
else
spawn(1 SECOND)
to_chat(user, "<span class='notice'>Nothing happens..</span>")
toggle_mixing(user)
if("eject input")
if(InputBeaker)
@@ -252,19 +295,36 @@
if(!powered())
on = FALSE
if(!on || (use_atmos && (!connected_port || avg_pressure < 1000)))
if(!on || (use_atmos && (!connected_port || (avg_pressure / avg_temp) < (1000 / T20C)))) // This mostly respects gas laws by ignoring volume but it should make it usable at low temps
current_temp = round((current_temp + T20C) / 2)
else if(on)
if(!use_atmos)
if(current_temp != round(target_temp))
var/shift_mod = 0
if(current_temp < target_temp)
shift_mod = 1
else if(current_temp > target_temp)
shift_mod = -1
current_temp = CLAMP(round((current_temp + 1 * shift_mod) + (rand(-5, 5) / 10)), min_temp, max_temp)
// Some horrible bastardized attempt at approximating the values of a logistic function, bounded by (max_temp, target_temp, min_temp)
// So we can attempt to estimate the change in temperature for this process() step
// Apply inverse of the logistic function to fetch our x value
var/x = -1 * log((current_temp < target_temp ? (target_temp - min_temp) / (current_temp - min_temp) : (max_temp - target_temp) / (max_temp - current_temp)) - 1)
if(!x)
x = 0 // Keep null from propagating into the temp
// Apply the derivative of the logistic function to get the slope
var/dy = (NUM_E ** (-1 * x)) / ((1 + (NUM_E ** (-1 * x))) ** 2)
// Compute temperature diff, being farther from the target should result in larger steps
// IMPORTANT: If you want to tweak how quickly this changes, tweak this *10!
// As of initial testing, a *10 gives ~5-6 minutes to go from room temp to 500C (+/-0.5C)
var/temp_diff = (current_temp < target_temp ? dy * 10 * target_temp / current_temp : dy * -10 * current_temp / target_temp)
current_temp = CLAMP(round((current_temp + temp_diff), 0.01), min_temp, max_temp)
use_power(power_rating * CELLRATE)
if(target_temp == round(current_temp, 1.0))
current_temp = target_temp // Hard set it so we don't need to worry about exact decimals any more, after we've been keeping track of it all this time
playsound(src, 'sound/machines/ping.ogg', 50, 0)
src.visible_message("<span class='notice'>\The [src] pings as it reaches the target temperature.</span>")
else if(connected_port && avg_pressure > 1000)
current_temp = round((current_temp + avg_temp) / 2)
else if(!run_pump)