mirror of
https://github.com/yogstation13/Yogstation.git
synced 2025-02-26 09:04:50 +00:00
Merge pull request #33622 from duncathan/assert_gas
restores add_gas(), assert_gas(), and thermal_energy() as wrapper procs
This commit is contained in:
@@ -176,6 +176,4 @@
|
|||||||
#define ADD_GAS(gas_id, out_list)\
|
#define ADD_GAS(gas_id, out_list)\
|
||||||
var/list/tmp_gaslist = GLOB.gaslist_cache[gas_id]; out_list[gas_id] = tmp_gaslist.Copy();
|
var/list/tmp_gaslist = GLOB.gaslist_cache[gas_id]; out_list[gas_id] = tmp_gaslist.Copy();
|
||||||
|
|
||||||
//ASSERT_GAS(gas_id, gas_mixture) - used to guarantee that the gas list for this id exists in gas_mixture.gases.
|
|
||||||
//Must be used before adding to a gas. May be used before reading from a gas.
|
|
||||||
#define ASSERT_GAS(gas_id, gas_mixture) if (!gas_mixture.gases[gas_id]) { ADD_GAS(gas_id, gas_mixture.gases) };
|
#define ASSERT_GAS(gas_id, gas_mixture) if (!gas_mixture.gases[gas_id]) { ADD_GAS(gas_id, gas_mixture.gases) };
|
||||||
|
|||||||
@@ -422,7 +422,7 @@
|
|||||||
if(!istype(T))
|
if(!istype(T))
|
||||||
return
|
return
|
||||||
var/datum/gas_mixture/GM = new
|
var/datum/gas_mixture/GM = new
|
||||||
ADD_GAS(/datum/gas/plasma, GM.gases)
|
GM.add_gas(/datum/gas/plasma)
|
||||||
if(prob(10))
|
if(prob(10))
|
||||||
GM.gases[/datum/gas/plasma][MOLES] += 100
|
GM.gases[/datum/gas/plasma][MOLES] += 100
|
||||||
GM.temperature = 1500+T0C //should be enough to start a fire
|
GM.temperature = 1500+T0C //should be enough to start a fire
|
||||||
|
|||||||
@@ -169,7 +169,7 @@
|
|||||||
qdel(H)
|
qdel(H)
|
||||||
var/list/G_gases = G.gases
|
var/list/G_gases = G.gases
|
||||||
if(G_gases[/datum/gas/plasma])
|
if(G_gases[/datum/gas/plasma])
|
||||||
ASSERT_GAS(/datum/gas/nitrogen, G)
|
G.assert_gas(/datum/gas/nitrogen)
|
||||||
G_gases[/datum/gas/nitrogen][MOLES] += (G_gases[/datum/gas/plasma][MOLES])
|
G_gases[/datum/gas/nitrogen][MOLES] += (G_gases[/datum/gas/plasma][MOLES])
|
||||||
G_gases[/datum/gas/plasma][MOLES] = 0
|
G_gases[/datum/gas/plasma][MOLES] = 0
|
||||||
G.garbage_collect()
|
G.garbage_collect()
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
/obj/item/tank/jetpack/New()
|
/obj/item/tank/jetpack/New()
|
||||||
..()
|
..()
|
||||||
if(gas_type)
|
if(gas_type)
|
||||||
ASSERT_GAS(gas_type,air_contents)
|
air_contents.assert_gas(gas_type)
|
||||||
air_contents.gases[gas_type][MOLES] = (6 * ONE_ATMOSPHERE) * volume / (R_IDEAL_GAS_EQUATION * T20C)
|
air_contents.gases[gas_type][MOLES] = (6 * ONE_ATMOSPHERE) * volume / (R_IDEAL_GAS_EQUATION * T20C)
|
||||||
|
|
||||||
ion_trail = new
|
ion_trail = new
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
/obj/item/tank/internals/oxygen/New()
|
/obj/item/tank/internals/oxygen/New()
|
||||||
..()
|
..()
|
||||||
ASSERT_GAS(/datum/gas/oxygen, air_contents)
|
air_contents.assert_gas(/datum/gas/oxygen)
|
||||||
air_contents.gases[/datum/gas/oxygen][MOLES] = (6*ONE_ATMOSPHERE)*volume/(R_IDEAL_GAS_EQUATION*T20C)
|
air_contents.gases[/datum/gas/oxygen][MOLES] = (6*ONE_ATMOSPHERE)*volume/(R_IDEAL_GAS_EQUATION*T20C)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
|
|
||||||
/obj/item/tank/internals/plasma/New()
|
/obj/item/tank/internals/plasma/New()
|
||||||
..()
|
..()
|
||||||
ASSERT_GAS(/datum/gas/plasma, air_contents)
|
air_contents.assert_gas(/datum/gas/plasma)
|
||||||
air_contents.gases[/datum/gas/plasma][MOLES] = (3*ONE_ATMOSPHERE)*volume/(R_IDEAL_GAS_EQUATION*T20C)
|
air_contents.gases[/datum/gas/plasma][MOLES] = (3*ONE_ATMOSPHERE)*volume/(R_IDEAL_GAS_EQUATION*T20C)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@
|
|||||||
|
|
||||||
/obj/item/tank/internals/plasmaman/New()
|
/obj/item/tank/internals/plasmaman/New()
|
||||||
..()
|
..()
|
||||||
ASSERT_GAS(/datum/gas/plasma, air_contents)
|
air_contents.assert_gas(/datum/gas/plasma)
|
||||||
air_contents.gases[/datum/gas/plasma][MOLES] = (3*ONE_ATMOSPHERE)*volume/(R_IDEAL_GAS_EQUATION*T20C)
|
air_contents.gases[/datum/gas/plasma][MOLES] = (3*ONE_ATMOSPHERE)*volume/(R_IDEAL_GAS_EQUATION*T20C)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@
|
|||||||
|
|
||||||
/obj/item/tank/internals/emergency_oxygen/New()
|
/obj/item/tank/internals/emergency_oxygen/New()
|
||||||
..()
|
..()
|
||||||
ASSERT_GAS(/datum/gas/oxygen, air_contents)
|
air_contents.assert_gas(/datum/gas/oxygen)
|
||||||
air_contents.gases[/datum/gas/oxygen][MOLES] = (3*ONE_ATMOSPHERE)*volume/(R_IDEAL_GAS_EQUATION*T20C)
|
air_contents.gases[/datum/gas/oxygen][MOLES] = (3*ONE_ATMOSPHERE)*volume/(R_IDEAL_GAS_EQUATION*T20C)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -355,6 +355,6 @@
|
|||||||
if (air.gases[/datum/gas/carbon_dioxide] && air.gases[/datum/gas/oxygen])
|
if (air.gases[/datum/gas/carbon_dioxide] && air.gases[/datum/gas/oxygen])
|
||||||
air.gases[/datum/gas/carbon_dioxide][MOLES]=max(air.gases[/datum/gas/carbon_dioxide][MOLES]-(pulse_strength/1000),0)
|
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.gases[/datum/gas/oxygen][MOLES]=max(air.gases[/datum/gas/oxygen][MOLES]-(pulse_strength/2000),0)
|
||||||
ASSERT_GAS(/datum/gas/pluoxium,air)
|
air.assert_gas(/datum/gas/pluoxium)
|
||||||
air.gases[/datum/gas/pluoxium][MOLES]+=(pulse_strength/4000)
|
air.gases[/datum/gas/pluoxium][MOLES]+=(pulse_strength/4000)
|
||||||
air.garbage_collect()
|
air.garbage_collect()
|
||||||
|
|||||||
@@ -735,7 +735,7 @@ GLOBAL_PROTECT(LastAdminCalledProc)
|
|||||||
if(Rad.anchored)
|
if(Rad.anchored)
|
||||||
if(!Rad.loaded_tank)
|
if(!Rad.loaded_tank)
|
||||||
var/obj/item/tank/internals/plasma/Plasma = new/obj/item/tank/internals/plasma(Rad)
|
var/obj/item/tank/internals/plasma/Plasma = new/obj/item/tank/internals/plasma(Rad)
|
||||||
ASSERT_GAS(/datum/gas/plasma, Plasma.air_contents)
|
Plasma.air_contents.assert_gas(/datum/gas/plasma)
|
||||||
Plasma.air_contents.gases[/datum/gas/plasma][MOLES] = 70
|
Plasma.air_contents.gases[/datum/gas/plasma][MOLES] = 70
|
||||||
Rad.drainratio = 0
|
Rad.drainratio = 0
|
||||||
Rad.loaded_tank = Plasma
|
Rad.loaded_tank = Plasma
|
||||||
|
|||||||
@@ -37,14 +37,24 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
|
|||||||
reaction_results = new
|
reaction_results = new
|
||||||
|
|
||||||
//listmos procs
|
//listmos procs
|
||||||
|
//use the macros in performance intensive areas. for their definitions, refer to code/__DEFINES/atmospherics.dm
|
||||||
|
|
||||||
// The following procs used to live here: thermal_energy(), assert_gas() and add_gas(). They have been moved into defines in code/__DEFINES/atmospherics.dm
|
//assert_gas(gas_id) - used to guarantee that the gas list for this id exists in gas_mixture.gases.
|
||||||
|
//Must be used before adding to a gas. May be used before reading from a gas.
|
||||||
|
/datum/gas_mixture/proc/assert_gas(gas_id)
|
||||||
|
ASSERT_GAS(gas_id, src)
|
||||||
|
|
||||||
//assert_gases(args) - shorthand for calling ASSERT_GAS() once for each gas type.
|
//assert_gases(args) - shorthand for calling ASSERT_GAS() once for each gas type.
|
||||||
/datum/gas_mixture/proc/assert_gases()
|
/datum/gas_mixture/proc/assert_gases()
|
||||||
for(var/id in args)
|
for(var/id in args)
|
||||||
ASSERT_GAS(id, src)
|
ASSERT_GAS(id, src)
|
||||||
|
|
||||||
|
//add_gas(gas_id) - similar to assert_gas(), but does not check for an existing
|
||||||
|
//gas list for this id. This can clobber existing gases.
|
||||||
|
//Used instead of assert_gas() when you know the gas does not exist. Faster than assert_gas().
|
||||||
|
/datum/gas_mixture/proc/add_gas(gas_id)
|
||||||
|
ADD_GAS(gas_id, gases)
|
||||||
|
|
||||||
//add_gases(args) - shorthand for calling add_gas() once for each gas_type.
|
//add_gases(args) - shorthand for calling add_gas() once for each gas_type.
|
||||||
/datum/gas_mixture/proc/add_gases()
|
/datum/gas_mixture/proc/add_gases()
|
||||||
var/cached_gases = gases
|
var/cached_gases = gases
|
||||||
@@ -101,6 +111,9 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
|
|||||||
/datum/gas_mixture/proc/return_volume() //liters
|
/datum/gas_mixture/proc/return_volume() //liters
|
||||||
return max(0, volume)
|
return max(0, volume)
|
||||||
|
|
||||||
|
/datum/gas_mixture/proc/thermal_energy() //joules
|
||||||
|
return THERMAL_ENERGY(src) //see code/__DEFINES/atmospherics.dm; use the define in performance critical areas
|
||||||
|
|
||||||
/datum/gas_mixture/proc/archive()
|
/datum/gas_mixture/proc/archive()
|
||||||
//Update archived versions of variables
|
//Update archived versions of variables
|
||||||
//Returns: 1 in all cases
|
//Returns: 1 in all cases
|
||||||
|
|||||||
@@ -103,7 +103,7 @@
|
|||||||
var/datum/gas_mixture/filtered_out = new
|
var/datum/gas_mixture/filtered_out = new
|
||||||
|
|
||||||
filtered_out.temperature = removed.temperature
|
filtered_out.temperature = removed.temperature
|
||||||
ASSERT_GAS(filter_type, filtered_out)
|
filtered_out.add_gas(filter_type)
|
||||||
filtered_out.gases[filter_type][MOLES] = removed.gases[filter_type][MOLES]
|
filtered_out.gases[filter_type][MOLES] = removed.gases[filter_type][MOLES]
|
||||||
|
|
||||||
removed.gases[filter_type][MOLES] = 0
|
removed.gases[filter_type][MOLES] = 0
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
air_contents.volume = volume
|
air_contents.volume = volume
|
||||||
air_contents.temperature = T20C
|
air_contents.temperature = T20C
|
||||||
if(gas_type)
|
if(gas_type)
|
||||||
ASSERT_GAS(gas_type, air_contents)
|
air_contents.assert_gas(gas_type)
|
||||||
air_contents.gases[gas_type][MOLES] = AIR_CONTENTS
|
air_contents.gases[gas_type][MOLES] = AIR_CONTENTS
|
||||||
name = "[name] ([air_contents.gases[gas_type][GAS_META][META_GAS_NAME]])"
|
name = "[name] ([air_contents.gases[gas_type][GAS_META][META_GAS_NAME]])"
|
||||||
|
|
||||||
|
|||||||
@@ -175,7 +175,7 @@
|
|||||||
filtered_out.temperature = removed.temperature
|
filtered_out.temperature = removed.temperature
|
||||||
|
|
||||||
for(var/gas in filter_types & removed_gases)
|
for(var/gas in filter_types & removed_gases)
|
||||||
ADD_GAS(gas, filtered_gases)
|
filtered_out.add_gas(gas)
|
||||||
filtered_gases[gas][MOLES] = removed_gases[gas][MOLES]
|
filtered_gases[gas][MOLES] = removed_gases[gas][MOLES]
|
||||||
removed_gases[gas][MOLES] = 0
|
removed_gases[gas][MOLES] = 0
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@
|
|||||||
if(!isopenturf(O))
|
if(!isopenturf(O))
|
||||||
return FALSE
|
return FALSE
|
||||||
var/datum/gas_mixture/merger = new
|
var/datum/gas_mixture/merger = new
|
||||||
ASSERT_GAS(spawn_id, merger)
|
merger.assert_gas(spawn_id)
|
||||||
merger.gases[spawn_id][MOLES] = (spawn_mol)
|
merger.gases[spawn_id][MOLES] = (spawn_mol)
|
||||||
merger.temperature = spawn_temp
|
merger.temperature = spawn_temp
|
||||||
O.assume_air(merger)
|
O.assume_air(merger)
|
||||||
|
|||||||
@@ -196,7 +196,7 @@
|
|||||||
|
|
||||||
/obj/machinery/portable_atmospherics/canister/proc/create_gas()
|
/obj/machinery/portable_atmospherics/canister/proc/create_gas()
|
||||||
if(gas_type)
|
if(gas_type)
|
||||||
ADD_GAS(gas_type, air_contents.gases)
|
air_contents.add_gas(gas_type)
|
||||||
if(starter_temp)
|
if(starter_temp)
|
||||||
air_contents.temperature = starter_temp
|
air_contents.temperature = starter_temp
|
||||||
air_contents.gases[gas_type][MOLES] = (maximum_pressure * filled) * air_contents.volume / (R_IDEAL_GAS_EQUATION * air_contents.temperature)
|
air_contents.gases[gas_type][MOLES] = (maximum_pressure * filled) * air_contents.volume / (R_IDEAL_GAS_EQUATION * air_contents.temperature)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
filtered.temperature = filtering.temperature
|
filtered.temperature = filtering.temperature
|
||||||
for(var/gas in filtering.gases & scrubbing)
|
for(var/gas in filtering.gases & scrubbing)
|
||||||
ADD_GAS(gas, filtered.gases)
|
filtered.add_gas(gas)
|
||||||
filtered.gases[gas][MOLES] = filtering.gases[gas][MOLES] // Shuffle the "bad" gasses to the filtered mixture.
|
filtered.gases[gas][MOLES] = filtering.gases[gas][MOLES] // Shuffle the "bad" gasses to the filtered mixture.
|
||||||
filtering.gases[gas][MOLES] = 0
|
filtering.gases[gas][MOLES] = 0
|
||||||
filtering.garbage_collect() // Now that the gasses are set to 0, clean up the mixture.
|
filtering.garbage_collect() // Now that the gasses are set to 0, clean up the mixture.
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
eject()
|
eject()
|
||||||
else
|
else
|
||||||
loaded_tank.air_contents.gases[/datum/gas/plasma][MOLES] -= 0.001*drainratio
|
loaded_tank.air_contents.gases[/datum/gas/plasma][MOLES] -= 0.001*drainratio
|
||||||
ASSERT_GAS(/datum/gas/tritium,loaded_tank.air_contents)
|
loaded_tank.air_contents.assert_gas(/datum/gas/tritium)
|
||||||
loaded_tank.air_contents.gases[/datum/gas/tritium][MOLES] += 0.001*drainratio
|
loaded_tank.air_contents.gases[/datum/gas/tritium][MOLES] += 0.001*drainratio
|
||||||
loaded_tank.air_contents.garbage_collect()
|
loaded_tank.air_contents.garbage_collect()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user