Minor refactor of how gas IDs are handled

This commit is contained in:
duncathan salt
2017-10-12 00:30:09 -05:00
committed by CitadelStationBot
parent 5b4e26cb06
commit c0e9cde5c2
52 changed files with 438 additions and 331 deletions
@@ -268,8 +268,11 @@ GLOBAL_LIST_INIT(gaslist_cache, init_gaslist_cache())
gas -= "TEMP"
gases.Cut()
for(var/id in gas)
ADD_GAS(id, gases)
gases[id][MOLES] = text2num(gas[id])
var/path = id
if(!ispath(path))
path = gas_id2path(path) //a lot of these strings can't have embedded expressions (especially for mappers), so support for IDs needs to stick around
ADD_GAS(path, gases)
gases[path][MOLES] = text2num(gas[id])
return 1
/datum/gas_mixture/share(datum/gas_mixture/sharer, atmos_adjacent_turfs = 4)
@@ -1,9 +1,9 @@
GLOBAL_LIST_INIT(hardcoded_gases, list("o2","n2","co2","plasma")) //the main four gases, which were at one time hardcoded
GLOBAL_LIST_INIT(hardcoded_gases, list(/datum/gas/oxygen, /datum/gas/nitrogen, /datum/gas/carbon_dioxide, /datum/gas/plasma)) //the main four gases, which were at one time hardcoded
/proc/meta_gas_list()
. = new /list
for(var/gas_path in subtypesof(/datum/gas))
var/list/gas_info = new(5)
. = subtypesof(/datum/gas)
for(var/gas_path in .)
var/list/gas_info = new(6)
var/datum/gas/gas = gas_path
gas_info[META_GAS_SPECIFIC_HEAT] = initial(gas.specific_heat)
@@ -12,7 +12,14 @@ GLOBAL_LIST_INIT(hardcoded_gases, list("o2","n2","co2","plasma")) //the main fou
if(initial(gas.moles_visible) != null)
gas_info[META_GAS_OVERLAY] = new /obj/effect/overlay/gas(initial(gas.gas_overlay))
gas_info[META_GAS_DANGER] = initial(gas.dangerous)
.[initial(gas.id)] = gas_info
gas_info[META_GAS_ID] = initial(gas.id)
.[gas_path] = gas_info
/proc/gas_id2path(id)
var/meta_gas = meta_gas_list()
for(var/path in meta_gas)
if(meta_gas[path][META_GAS_ID] == id)
return path
/*||||||||||||||/----------\||||||||||||||*\
||||||||||||||||[GAS DATUMS]||||||||||||||||
@@ -69,8 +69,8 @@
/datum/gas_mixture/immutable/cloner/garbage_collect()
..()
ADD_GAS("n2", gases)
gases["n2"][MOLES] = MOLES_O2STANDARD + MOLES_N2STANDARD
ADD_GAS(/datum/gas/nitrogen, gases)
gases[/datum/gas/nitrogen][MOLES] = MOLES_O2STANDARD + MOLES_N2STANDARD
/datum/gas_mixture/immutable/cloner/heat_capacity()
return (MOLES_O2STANDARD + MOLES_N2STANDARD)*20 //specific heat of nitrogen is 20
@@ -44,21 +44,21 @@
/datum/gas_reaction/agent_b/init_reqs()
min_requirements = list(
"TEMP" = 900,
"agent_b" = MINIMUM_HEAT_CAPACITY,
"plasma" = MINIMUM_HEAT_CAPACITY,
"co2" = MINIMUM_HEAT_CAPACITY
/datum/gas/oxygen_agent_b = MINIMUM_HEAT_CAPACITY,
/datum/gas/plasma = MINIMUM_HEAT_CAPACITY,
/datum/gas/carbon_dioxide = MINIMUM_HEAT_CAPACITY
)
/datum/gas_reaction/agent_b/react(datum/gas_mixture/air)
var/list/cached_gases = air.gases
var/reaction_rate = min(cached_gases["co2"][MOLES]*0.75, cached_gases["plasma"][MOLES]*0.25, cached_gases["agent_b"][MOLES]*0.05)
var/reaction_rate = min(cached_gases[/datum/gas/carbon_dioxide][MOLES]*0.75, cached_gases[/datum/gas/plasma][MOLES]*0.25, cached_gases[/datum/gas/oxygen_agent_b][MOLES]*0.05)
cached_gases["co2"][MOLES] -= reaction_rate
cached_gases["agent_b"][MOLES] -= reaction_rate*0.05
cached_gases[/datum/gas/carbon_dioxide][MOLES] -= reaction_rate
cached_gases[/datum/gas/oxygen_agent_b][MOLES] -= reaction_rate*0.05
ASSERT_GAS("o2", air) //only need to assert oxygen, as this reaction doesn't occur without the other gases existing
cached_gases["o2"][MOLES] += reaction_rate
ASSERT_GAS(/datum/gas/oxygen, air) //only need to assert oxygen, as this reaction doesn't occur without the other gases existing
cached_gases[/datum/gas/oxygen][MOLES] += reaction_rate
air.temperature -= (reaction_rate*20000)/air.heat_capacity()
@@ -71,7 +71,7 @@
id = "freon"
/datum/gas_reaction/freon/init_reqs()
min_requirements = list("freon" = MOLES_PLASMA_VISIBLE)
min_requirements = list(/datum/gas/freon = MOLES_PLASMA_VISIBLE)
/datum/gas_reaction/freon/react(datum/gas_mixture/air, turf/open/location)
. = NO_REACTION
@@ -85,12 +85,12 @@
id = "vapor"
/datum/gas_reaction/water_vapor/init_reqs()
min_requirements = list("water_vapor" = MOLES_PLASMA_VISIBLE)
min_requirements = list(/datum/gas/water_vapor = MOLES_PLASMA_VISIBLE)
/datum/gas_reaction/water_vapor/react(datum/gas_mixture/air, turf/open/location)
. = NO_REACTION
if(location && location.water_vapor_gas_act())
air.gases["water_vapor"][MOLES] -= MOLES_PLASMA_VISIBLE
air.gases[/datum/gas/water_vapor][MOLES] -= MOLES_PLASMA_VISIBLE
. = REACTING
//fire: combustion of plasma and volatile fuel (treated as hydrocarbons). creates hotspots. exothermic
@@ -111,28 +111,28 @@
cached_results[id] = 0
//General volatile gas burn
if(cached_gases["v_fuel"] && cached_gases["v_fuel"][MOLES])
if(cached_gases[/datum/gas/volatile_fuel] && cached_gases[/datum/gas/volatile_fuel][MOLES])
var/burned_fuel
if(!cached_gases["o2"])
if(!cached_gases[/datum/gas/oxygen])
burned_fuel = 0
else if(cached_gases["o2"][MOLES] < cached_gases["v_fuel"][MOLES])
burned_fuel = cached_gases["o2"][MOLES]
cached_gases["v_fuel"][MOLES] -= burned_fuel
cached_gases["o2"][MOLES] = 0
else if(cached_gases[/datum/gas/oxygen][MOLES] < cached_gases[/datum/gas/volatile_fuel][MOLES])
burned_fuel = cached_gases[/datum/gas/oxygen][MOLES]
cached_gases[/datum/gas/volatile_fuel][MOLES] -= burned_fuel
cached_gases[/datum/gas/oxygen][MOLES] = 0
else
burned_fuel = cached_gases["v_fuel"][MOLES]
cached_gases["o2"][MOLES] -= cached_gases["v_fuel"][MOLES]
burned_fuel = cached_gases[/datum/gas/volatile_fuel][MOLES]
cached_gases[/datum/gas/oxygen][MOLES] -= cached_gases[/datum/gas/volatile_fuel][MOLES]
if(burned_fuel)
energy_released += FIRE_CARBON_ENERGY_RELEASED * burned_fuel
ASSERT_GAS("co2", air)
cached_gases["co2"][MOLES] += burned_fuel
ASSERT_GAS(/datum/gas/carbon_dioxide, air)
cached_gases[/datum/gas/carbon_dioxide][MOLES] += burned_fuel
cached_results[id] += burned_fuel
//Handle plasma burning
if(cached_gases["plasma"] && cached_gases["plasma"][MOLES] > MINIMUM_HEAT_CAPACITY)
if(cached_gases[/datum/gas/plasma] && cached_gases[/datum/gas/plasma][MOLES] > MINIMUM_HEAT_CAPACITY)
var/plasma_burn_rate = 0
var/oxygen_burn_rate = 0
//more plasma released at higher temperatures
@@ -142,17 +142,17 @@
else
temperature_scale = (temperature-PLASMA_MINIMUM_BURN_TEMPERATURE)/(PLASMA_UPPER_TEMPERATURE-PLASMA_MINIMUM_BURN_TEMPERATURE)
if(temperature_scale > 0)
ASSERT_GAS("o2", air)
ASSERT_GAS(/datum/gas/oxygen, air)
oxygen_burn_rate = OXYGEN_BURN_RATE_BASE - temperature_scale
if(cached_gases["o2"][MOLES] > cached_gases["plasma"][MOLES]*PLASMA_OXYGEN_FULLBURN)
plasma_burn_rate = (cached_gases["plasma"][MOLES]*temperature_scale)/PLASMA_BURN_RATE_DELTA
if(cached_gases[/datum/gas/oxygen][MOLES] > cached_gases[/datum/gas/plasma][MOLES]*PLASMA_OXYGEN_FULLBURN)
plasma_burn_rate = (cached_gases[/datum/gas/plasma][MOLES]*temperature_scale)/PLASMA_BURN_RATE_DELTA
else
plasma_burn_rate = (temperature_scale*(cached_gases["o2"][MOLES]/PLASMA_OXYGEN_FULLBURN))/PLASMA_BURN_RATE_DELTA
plasma_burn_rate = (temperature_scale*(cached_gases[/datum/gas/oxygen][MOLES]/PLASMA_OXYGEN_FULLBURN))/PLASMA_BURN_RATE_DELTA
if(plasma_burn_rate > MINIMUM_HEAT_CAPACITY)
ASSERT_GAS("co2", air)
cached_gases["plasma"][MOLES] = QUANTIZE(cached_gases["plasma"][MOLES] - plasma_burn_rate)
cached_gases["o2"][MOLES] = QUANTIZE(cached_gases["o2"][MOLES] - (plasma_burn_rate * oxygen_burn_rate))
cached_gases["co2"][MOLES] += plasma_burn_rate
ASSERT_GAS(/datum/gas/carbon_dioxide, air)
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))
cached_gases[/datum/gas/carbon_dioxide][MOLES] += plasma_burn_rate
energy_released += FIRE_PLASMA_ENERGY_RELEASED * (plasma_burn_rate)
@@ -185,36 +185,36 @@
/datum/gas_reaction/fusion/init_reqs()
min_requirements = list(
"ENER" = PLASMA_BINDING_ENERGY * 10,
"plasma" = MINIMUM_HEAT_CAPACITY,
"co2" = MINIMUM_HEAT_CAPACITY
/datum/gas/plasma = MINIMUM_HEAT_CAPACITY,
/datum/gas/carbon_dioxide = MINIMUM_HEAT_CAPACITY
)
/datum/gas_reaction/fusion/react(datum/gas_mixture/air)
var/list/cached_gases = air.gases
var/temperature = air.temperature
if((cached_gases["plasma"][MOLES]+cached_gases["co2"][MOLES])/air.total_moles() < FUSION_PURITY_THRESHOLD)
if((cached_gases[/datum/gas/plasma][MOLES]+cached_gases[/datum/gas/carbon_dioxide][MOLES])/air.total_moles() < FUSION_PURITY_THRESHOLD)
//Fusion wont occur if the level of impurities is too high.
return NO_REACTION
var/old_heat_capacity = air.heat_capacity()
var/carbon_efficency = min(cached_gases["plasma"][MOLES]/cached_gases["co2"][MOLES],MAX_CARBON_EFFICENCY)
var/carbon_efficency = min(cached_gases[/datum/gas/plasma][MOLES]/cached_gases[/datum/gas/carbon_dioxide][MOLES],MAX_CARBON_EFFICENCY)
var/reaction_energy = THERMAL_ENERGY(air)
var/moles_impurities = air.total_moles()-(cached_gases["plasma"][MOLES]+cached_gases["co2"][MOLES])
var/moles_impurities = air.total_moles()-(cached_gases[/datum/gas/plasma][MOLES]+cached_gases[/datum/gas/carbon_dioxide][MOLES])
var/plasma_fused = (PLASMA_FUSED_COEFFICENT*carbon_efficency)*(temperature/PLASMA_BINDING_ENERGY)
var/carbon_catalyzed = (CARBON_CATALYST_COEFFICENT*carbon_efficency)*(temperature/PLASMA_BINDING_ENERGY)
var/oxygen_added = carbon_catalyzed
var/nitrogen_added = (plasma_fused-oxygen_added)-(THERMAL_ENERGY(air)/PLASMA_BINDING_ENERGY)
reaction_energy = max(reaction_energy+((carbon_efficency*cached_gases["plasma"][MOLES])/((moles_impurities/carbon_efficency)+2)*10)+((plasma_fused/(moles_impurities/carbon_efficency))*PLASMA_BINDING_ENERGY),0)
reaction_energy = max(reaction_energy+((carbon_efficency*cached_gases[/datum/gas/plasma][MOLES])/((moles_impurities/carbon_efficency)+2)*10)+((plasma_fused/(moles_impurities/carbon_efficency))*PLASMA_BINDING_ENERGY),0)
air.assert_gases("o2", "n2")
air.assert_gases(/datum/gas/oxygen, /datum/gas/nitrogen)
cached_gases["plasma"][MOLES] -= plasma_fused
cached_gases["co2"][MOLES] -= carbon_catalyzed
cached_gases["o2"][MOLES] += oxygen_added
cached_gases["n2"][MOLES] += nitrogen_added
cached_gases[/datum/gas/plasma][MOLES] -= plasma_fused
cached_gases[/datum/gas/carbon_dioxide][MOLES] -= carbon_catalyzed
cached_gases[/datum/gas/oxygen][MOLES] += oxygen_added
cached_gases[/datum/gas/nitrogen][MOLES] += nitrogen_added
if(reaction_energy > 0)
var/new_heat_capacity = air.heat_capacity()