From 9b910552fdd0900f5d4642a75e7f981941b10936 Mon Sep 17 00:00:00 2001 From: BordListian Date: Tue, 6 Feb 2018 22:16:26 +0100 Subject: [PATCH] Forces gases to obey certain laws of nature (#35277) * - Fixes most gas reactions deleting more gas than exists and thus making gas out of nowhere. - Makes Noblium formation no longer multiplicative. - Expunges invocation of a byond bug by stimulum production. * - Redundant parenthesis - I'm going back to sleep * - Sends fire and fusion to jail * - Deletes redundant line in lung code - Adds garbage_collect and clamp to cryocells - Adds clamp to collectors * - Reverted the tritium burn changes because apparently I'm dumb * - FUCK * - Fixes division by zero when fusion has no impurities * - Adds extra commentary for the next unlucky sod - Compresses lines for performance or so they say - Adds ..() to rad_act on turfs * - Fuck it, fixes rad collectors, open turfs, geiger counters and living mobs not signalling rad_act components --- .../objects/items/devices/geiger_counter.dm | 1 + code/game/turfs/open.dm | 2 ++ .../atmospherics/gasmixtures/reactions.dm | 20 +++++++++---------- .../components/unary_devices/cryo.dm | 6 ++++-- code/modules/mob/living/living.dm | 2 ++ code/modules/power/singularity/collector.dm | 3 ++- code/modules/surgery/organs/lungs.dm | 1 - 7 files changed, 21 insertions(+), 14 deletions(-) diff --git a/code/game/objects/items/devices/geiger_counter.dm b/code/game/objects/items/devices/geiger_counter.dm index 64d710be25..c16ef8710e 100644 --- a/code/game/objects/items/devices/geiger_counter.dm +++ b/code/game/objects/items/devices/geiger_counter.dm @@ -119,6 +119,7 @@ loop.start() /obj/item/device/geiger_counter/rad_act(amount) + . = ..() if(amount <= RAD_BACKGROUND_RADIATION || !scanning) return current_tick_amount += amount diff --git a/code/game/turfs/open.dm b/code/game/turfs/open.dm index 12b37d0e01..da1f941ccc 100644 --- a/code/game/turfs/open.dm +++ b/code/game/turfs/open.dm @@ -352,7 +352,9 @@ /turf/open/rad_act(pulse_strength) + . = ..() if (air.gases[/datum/gas/carbon_dioxide] && air.gases[/datum/gas/oxygen]) + pulse_strength = min(pulse_strength,air.gases[/datum/gas/carbon_dioxide][MOLES]*1000,air.gases[/datum/gas/oxygen][MOLES]*2000) //Ensures matter is conserved properly air.gases[/datum/gas/carbon_dioxide][MOLES]=max(air.gases[/datum/gas/carbon_dioxide][MOLES]-(pulse_strength/1000),0) air.gases[/datum/gas/oxygen][MOLES]=max(air.gases[/datum/gas/oxygen][MOLES]-(pulse_strength/2000),0) air.assert_gas(/datum/gas/pluoxium) diff --git a/code/modules/atmospherics/gasmixtures/reactions.dm b/code/modules/atmospherics/gasmixtures/reactions.dm index aabbe089fb..67bb932df2 100644 --- a/code/modules/atmospherics/gasmixtures/reactions.dm +++ b/code/modules/atmospherics/gasmixtures/reactions.dm @@ -152,6 +152,7 @@ if(plasma_burn_rate > MINIMUM_HEAT_CAPACITY) ASSERT_GAS(/datum/gas/carbon_dioxide, air) //don't need to assert o2, since if it isn't present we'll never reach this point anyway + plasma_burn_rate = min(plasma_burn_rate,cached_gases[/datum/gas/plasma][MOLES],cached_gases[/datum/gas/oxygen][MOLES]/oxygen_burn_rate) //Ensures matter is conserved properly cached_gases[/datum/gas/plasma][MOLES] = QUANTIZE(cached_gases[/datum/gas/plasma][MOLES] - plasma_burn_rate) cached_gases[/datum/gas/oxygen][MOLES] = QUANTIZE(cached_gases[/datum/gas/oxygen][MOLES] - (plasma_burn_rate * oxygen_burn_rate)) if (super_saturation) @@ -207,13 +208,13 @@ var/old_heat_capacity = air.heat_capacity() var/catalyst_efficency = max(min(cached_gases[/datum/gas/plasma][MOLES]/cached_gases[/datum/gas/tritium][MOLES],MAX_CATALYST_EFFICENCY)-(temperature/FUSION_HEAT_DROPOFF),1) var/reaction_energy = THERMAL_ENERGY(air) - var/moles_impurities = air.total_moles()-(cached_gases[/datum/gas/plasma][MOLES]+cached_gases[/datum/gas/tritium][MOLES]) + var/moles_impurities = max(air.total_moles()-(cached_gases[/datum/gas/plasma][MOLES]+cached_gases[/datum/gas/tritium][MOLES]),1) //This makes it assume a minimum of 1 mol impurities so the reaction energy doesn't divide by 0 - var/plasma_fused = (PLASMA_FUSED_COEFFICENT*catalyst_efficency)*(temperature/PLASMA_BINDING_ENERGY)/10 - var/tritium_catalyzed = (CATALYST_COEFFICENT*catalyst_efficency)*(temperature/PLASMA_BINDING_ENERGY)/40 + var/plasma_fused = min((PLASMA_FUSED_COEFFICENT*catalyst_efficency)*(temperature/PLASMA_BINDING_ENERGY)/10,cached_gases[/datum/gas/plasma][MOLES]) //Preserve matter + var/tritium_catalyzed = min((CATALYST_COEFFICENT*catalyst_efficency)*(temperature/PLASMA_BINDING_ENERGY)/40,cached_gases[/datum/gas/tritium][MOLES]) //Ditto var/oxygen_added = tritium_catalyzed var/waste_added = max((plasma_fused-oxygen_added)-((air.total_moles()*air.heat_capacity())/PLASMA_BINDING_ENERGY),0) - reaction_energy = max(reaction_energy+((catalyst_efficency*cached_gases[/datum/gas/plasma][MOLES])/((moles_impurities/catalyst_efficency)+2)*10)+((plasma_fused/((moles_impurities/catalyst_efficency)))*PLASMA_BINDING_ENERGY),0) + reaction_energy = max(reaction_energy+((catalyst_efficency*cached_gases[/datum/gas/plasma][MOLES])/((moles_impurities/catalyst_efficency)+2)*10)+((plasma_fused/(moles_impurities/catalyst_efficency))*PLASMA_BINDING_ENERGY),0) air.assert_gases(/datum/gas/oxygen, /datum/gas/carbon_dioxide, /datum/gas/water_vapor, /datum/gas/nitrous_oxide, /datum/gas/nitryl) //Fusion produces an absurd amount of waste products now, requiring active filtration. @@ -251,7 +252,7 @@ var/temperature = air.temperature var/old_heat_capacity = air.heat_capacity() - var/heat_efficency = temperature/(FIRE_MINIMUM_TEMPERATURE_TO_EXIST*100) + var/heat_efficency = min(temperature/(FIRE_MINIMUM_TEMPERATURE_TO_EXIST*100),cached_gases[/datum/gas/oxygen][MOLES],cached_gases[/datum/gas/nitrogen][MOLES]) var/energy_used = heat_efficency*NITRYL_FORMATION_ENERGY ASSERT_GAS(/datum/gas/nitryl,air) @@ -283,7 +284,7 @@ var/pressure = air.return_pressure() var/old_heat_capacity = air.heat_capacity() - var/reaction_efficency = 1/((pressure/(0.1*ONE_ATMOSPHERE))*(max(cached_gases[/datum/gas/plasma][MOLES]/cached_gases[/datum/gas/tritium][MOLES],1))) + var/reaction_efficency = min(1/((pressure/(0.1*ONE_ATMOSPHERE))*(max(cached_gases[/datum/gas/plasma][MOLES]/cached_gases[/datum/gas/tritium][MOLES],1))),cached_gases[/datum/gas/tritium][MOLES],cached_gases[/datum/gas/plasma][MOLES]/2) var/energy_released = 2*reaction_efficency*FIRE_CARBON_ENERGY_RELEASED ASSERT_GAS(/datum/gas/bz,air) @@ -314,9 +315,8 @@ var/list/cached_gases = air.gases var/old_heat_capacity = air.heat_capacity() - var/heat_scale = air.temperature/STIMULUM_HEAT_SCALE - var/stim_energy_change - stim_energy_change =heat_scale + (STIMULUM_FIRST_RISE(heat_scale**2)) - (STIMULUM_FIRST_DROP(heat_scale**3)) + (STIMULUM_SECOND_RISE(heat_scale**4)) - (STIMULUM_ABSOLUTE_DROP(heat_scale**5)) + var/heat_scale = min(air.temperature/STIMULUM_HEAT_SCALE,cached_gases[/datum/gas/tritium][MOLES],cached_gases[/datum/gas/plasma][MOLES],cached_gases[/datum/gas/nitryl][MOLES]) + var/stim_energy_change = heat_scale + STIMULUM_FIRST_RISE*(heat_scale**2) - STIMULUM_FIRST_DROP*(heat_scale**3) + STIMULUM_SECOND_RISE*(heat_scale**4) - STIMULUM_ABSOLUTE_DROP*(heat_scale**5) ASSERT_GAS(/datum/gas/stimulum,air) cached_gases[/datum/gas/stimulum][MOLES]+= heat_scale/10 @@ -345,7 +345,7 @@ var/list/cached_gases = air.gases air.assert_gases(/datum/gas/hypernoblium,/datum/gas/bz) var/old_heat_capacity = air.heat_capacity() - var/nob_formed = (cached_gases[/datum/gas/nitrogen][MOLES]*cached_gases[/datum/gas/tritium][MOLES])/100 + var/nob_formed = min((cached_gases[/datum/gas/nitrogen][MOLES]+cached_gases[/datum/gas/tritium][MOLES])/100,cached_gases[/datum/gas/tritium][MOLES]/10,cached_gases[/datum/gas/nitrogen][MOLES]/20) var/energy_taken = nob_formed*(NOBLIUM_FORMATION_ENERGY/(max(cached_gases[/datum/gas/bz][MOLES],1))) cached_gases[/datum/gas/tritium][MOLES] = max(cached_gases[/datum/gas/tritium][MOLES]- 10*nob_formed,0) cached_gases[/datum/gas/nitrogen][MOLES] = max(cached_gases[/datum/gas/nitrogen][MOLES]- 20*nob_formed,0) diff --git a/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm b/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm index 2a59e14121..df76a47b82 100644 --- a/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm +++ b/code/modules/atmospherics/machinery/components/unary_devices/cryo.dm @@ -184,7 +184,8 @@ if(reagent_transfer == 0) // Magically transfer reagents. Because cryo magic. beaker.reagents.trans_to(occupant, 1, efficiency * 0.25) // Transfer reagents. beaker.reagents.reaction(occupant, VAPOR) - air1.gases[/datum/gas/oxygen][MOLES] -= 2 / efficiency //Let's use gas for this + air1.gases[/datum/gas/oxygen][MOLES] -= max(0,air1.gases[/datum/gas/oxygen][MOLES] - 2 / efficiency) //Let's use gas for this + air1.garbage_collect() if(++reagent_transfer >= 10 * efficiency) // Throttle reagent transfer (higher efficiency will transfer the same amount but consume less from the beaker). reagent_transfer = 0 @@ -220,7 +221,8 @@ air1.temperature = max(air1.temperature - heat / air_heat_capacity, TCMB) mob_occupant.bodytemperature = max(mob_occupant.bodytemperature + heat / heat_capacity, TCMB) - air1.gases[/datum/gas/oxygen][MOLES] -= 0.5 / efficiency // Magically consume gas? Why not, we run on cryo magic. + air1.gases[/datum/gas/oxygen][MOLES] = max(0,air1.gases[/datum/gas/oxygen][MOLES] - 0.5 / efficiency) // Magically consume gas? Why not, we run on cryo magic. + air1.garbage_collect() /obj/machinery/atmospherics/components/unary/cryo_cell/power_change() ..() diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index 9716ee135d..9301e3b409 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -865,6 +865,8 @@ to_chat(G, "Your summoner has changed form!") /mob/living/rad_act(amount) + . = ..() + if(!amount || amount < RAD_MOB_SKIN_PROTECTION) return diff --git a/code/modules/power/singularity/collector.dm b/code/modules/power/singularity/collector.dm index 8523ab9f43..f587e578d9 100644 --- a/code/modules/power/singularity/collector.dm +++ b/code/modules/power/singularity/collector.dm @@ -44,7 +44,7 @@ playsound(src, 'sound/machines/ding.ogg', 50, 1) eject() else - var/gasdrained = powerproduction_drain*drainratio + var/gasdrained = min(powerproduction_drain*drainratio,loaded_tank.air_contents.gases[/datum/gas/plasma][MOLES]) loaded_tank.air_contents.gases[/datum/gas/plasma][MOLES] -= gasdrained loaded_tank.air_contents.assert_gas(/datum/gas/tritium) loaded_tank.air_contents.gases[/datum/gas/tritium][MOLES] += gasdrained @@ -189,6 +189,7 @@ update_icons() /obj/machinery/power/rad_collector/rad_act(pulse_strength) + . = ..() if(loaded_tank && active && pulse_strength > RAD_COLLECTOR_EFFICIENCY) last_power += (pulse_strength-RAD_COLLECTOR_EFFICIENCY)*RAD_COLLECTOR_COEFFICIENT diff --git a/code/modules/surgery/organs/lungs.dm b/code/modules/surgery/organs/lungs.dm index 42f5adfeca..f49b041b49 100644 --- a/code/modules/surgery/organs/lungs.dm +++ b/code/modules/surgery/organs/lungs.dm @@ -282,7 +282,6 @@ H.reagents.add_reagent("nitryl_gas",1) breath_gases[/datum/gas/nitryl][MOLES]-=gas_breathed - gas_breathed = 0 // Stimulum gas_breathed = breath_gases[/datum/gas/stimulum][MOLES] if (gas_breathed > gas_stimulation_min)