integrate XGM into the code

New turf proc: assume_gas().  Maps to air.adjust_gas_temp().
Lots of optimizations to processing, fire, lighting, HasEntered() and
 more.
Zones now process all fire data and existance in one go, fire objects
 only handle spreading.
Most code has been ported straight so some of it mightn't be ideally
 structured for the new gas_mixtures.

Signed-off-by: Mloc-Argent <colmohici@gmail.com>
This commit is contained in:
Mloc-Argent
2014-07-22 19:52:12 +01:00
parent 0918f8bdde
commit d5e9851b62
99 changed files with 1175 additions and 1823 deletions
@@ -44,7 +44,7 @@
return 1
//Calculate necessary moles to transfer using PV = nRT
if((air1.total_moles() > 0) && (air1.temperature>0))
if((air1.total_moles > 0) && (air1.temperature>0))
var/pressure_delta = min(target_pressure - output_starting_pressure, (input_starting_pressure - output_starting_pressure)/2)
//Can not have a pressure delta that would cause output_pressure > input_pressure
@@ -172,4 +172,4 @@
"\blue You have unfastened \the [src].", \
"You hear ratchet.")
new /obj/item/pipe(loc, make_from=src)
del(src)
del(src)
@@ -69,7 +69,7 @@ Thus, the two variables affect pump operation are set in New():
return 1
//Calculate necessary moles to transfer using PV=nRT
if((air1.total_moles() > 0) && (air1.temperature>0))
if((air1.total_moles > 0) && (air1.temperature>0))
var/pressure_delta = target_pressure - output_starting_pressure
var/transfer_moles = pressure_delta*air2.volume/(air1.temperature * R_IDEAL_GAS_EQUATION)
@@ -204,4 +204,4 @@ Thus, the two variables affect pump operation are set in New():
"\blue You have unfastened \the [src].", \
"You hear ratchet.")
new /obj/item/pipe(loc, make_from=src)
del(src)
del(src)
@@ -46,7 +46,7 @@
..()
if(!on)
return 0
if(!input || !output)
return
@@ -54,7 +54,7 @@
var/datum/gas_mixture/input_air = input.air // it's completely happy with them if they're in a loop though i.e. "P.air.return_pressure()"... *shrug*
var/output_pressure = output_air.return_pressure()
if(output_pressure >= target_pressure)
return
for(var/datum/omni_port/P in filters)
@@ -63,49 +63,46 @@
var/pressure_delta = target_pressure - output_pressure
if(input_air.return_temperature() > 0)
input.transfer_moles = pressure_delta * output_air.volume / (input_air.return_temperature() * R_IDEAL_GAS_EQUATION)
if(input_air.temperature > 0)
input.transfer_moles = pressure_delta * output_air.volume / (input_air.temperature * R_IDEAL_GAS_EQUATION)
if(input.transfer_moles > 0)
var/datum/gas_mixture/removed = input_air.remove(input.transfer_moles)
if(!removed)
return
for(var/datum/omni_port/P in filters)
var/datum/gas_mixture/filtered_out = new
filtered_out.temperature = removed.return_temperature()
filtered_out.temperature = removed.temperature
switch(P.mode)
if(ATM_O2)
filtered_out.oxygen = removed.oxygen
removed.oxygen = 0
filtered_out.gas["oxygen"] = removed.gas["oxygen"]
removed.gas["oxygen"] = null
if(ATM_N2)
filtered_out.nitrogen = removed.nitrogen
removed.nitrogen = 0
filtered_out.gas["nitrogen"] = removed.gas["nitrogen"]
removed.gas["nitrogen"] = null
if(ATM_CO2)
filtered_out.carbon_dioxide = removed.carbon_dioxide
removed.carbon_dioxide = 0
filtered_out.gas["carbon_dioxide"] = removed.gas["carbon_dioxide"]
removed.gas["carbon_dioxide"] = null
if(ATM_P)
filtered_out.phoron = removed.phoron
removed.phoron = 0
filtered_out.gas["phoron"] = removed.gas["phoron"]
removed.gas["phoron"] = null
if(ATM_N2O)
if(removed.trace_gases.len>0)
for(var/datum/gas/sleeping_agent/trace_gas in removed.trace_gases)
if(istype(trace_gas))
removed.trace_gases -= trace_gas
filtered_out.trace_gases += trace_gas
filtered_out.gas["sleeping_agent"] = removed.gas["sleeping_agent"]
removed.gas["sleeping_agent"] = null
else
filtered_out = null
P.air.merge(filtered_out)
if(P.network)
P.network.update = 1
output_air.merge(removed)
if(output.network)
output.network.update = 1
input.transfer_moles = 0
if(input.network)
input.network.update = 1
@@ -9,7 +9,7 @@
var/datum/omni_port/output
//setup tags for initial concentration values (must be decimal)
var/tag_north_con
var/tag_north_con
var/tag_south_con
var/tag_east_con
var/tag_west_con
@@ -101,22 +101,22 @@
var/pressure_delta = target_pressure - output_pressure
for(var/datum/omni_port/P in inputs)
if(P.air.return_temperature() > 0)
P.transfer_moles = (P.concentration * pressure_delta) * output_air.return_volume() / (P.air.return_temperature() * R_IDEAL_GAS_EQUATION)
if(P.air.temperature > 0)
P.transfer_moles = (P.concentration * pressure_delta) * output_air.volume / (P.air.temperature * R_IDEAL_GAS_EQUATION)
var/ratio_check = null
for(var/datum/omni_port/P in inputs)
if(!P.transfer_moles)
return
if(P.air.total_moles() < P.transfer_moles)
if(P.air.total_moles < P.transfer_moles)
ratio_check = 1
continue
if(ratio_check)
var/list/ratio_list = new()
for(var/datum/omni_port/P in inputs)
ratio_list.Add(P.air.total_moles() / P.transfer_moles)
ratio_list.Add(P.air.total_moles / P.transfer_moles)
var/ratio = min(ratio_list)
@@ -41,7 +41,7 @@ Filter types:
icon_state = "m"
else
icon_state = ""
if(!powered())
icon_state += "off"
else if(node2 && node3 && node1)
@@ -106,38 +106,31 @@ Filter types:
switch(filter_type)
if(0) //removing hydrocarbons
filtered_out.phoron = removed.phoron
removed.phoron = 0
filtered_out.gas["phoron"] = removed.gas["phoron"]
removed.gas["phoron"] = 0
if(removed.trace_gases.len>0)
for(var/datum/gas/trace_gas in removed.trace_gases)
if(istype(trace_gas, /datum/gas/oxygen_agent_b))
removed.trace_gases -= trace_gas
filtered_out.trace_gases += trace_gas
filtered_out.gas["oxygen_agent_b"] = removed.gas["oxygen_agent_b"]
removed.gas["oxygen_agent_b"] = 0
if(1) //removing O2
filtered_out.oxygen = removed.oxygen
removed.oxygen = 0
filtered_out.gas["oxygen"] = removed.gas["oxygen"]
removed.gas["oxygen"] = 0
if(2) //removing N2
filtered_out.nitrogen = removed.nitrogen
removed.nitrogen = 0
filtered_out.gas["nitrogen"] = removed.gas["nitrogen"]
removed.gas["nitrogen"] = 0
if(3) //removing CO2
filtered_out.carbon_dioxide = removed.carbon_dioxide
removed.carbon_dioxide = 0
filtered_out.gas["carbon_dioxide"] = removed.gas["carbon_dioxide"]
removed.gas["carbon_dioxide"] = 0
if(4)//removing N2O
if(removed.trace_gases.len>0)
for(var/datum/gas/trace_gas in removed.trace_gases)
if(istype(trace_gas, /datum/gas/sleeping_agent))
removed.trace_gases -= trace_gas
filtered_out.trace_gases += trace_gas
filtered_out.gas["sleeping_agent"] = removed.gas["sleeping_agent"]
removed.gas["sleeping_agent"] = 0
else
filtered_out = null
air2.merge(filtered_out)
air3.merge(removed)
@@ -272,7 +265,7 @@ obj/machinery/atmospherics/trinary/filter/m_filter/New()
/obj/machinery/atmospherics/trinary/filter/m_filter/initialize()
set_frequency(frequency)
if(node1 && node2 && node3) return
var/node1_connect = turn(dir, -180)
@@ -295,4 +288,4 @@ obj/machinery/atmospherics/trinary/filter/m_filter/New()
break
update_icon()
update_underlays()
update_underlays()
@@ -19,7 +19,7 @@
icon_state = "t"
else
icon_state = ""
if(!powered())
icon_state += "off"
else if(node2 && node3 && node1)
@@ -83,8 +83,8 @@
if(air2.temperature > 0)
transfer_moles2 = (node2_concentration*pressure_delta)*air3.volume/(air2.temperature * R_IDEAL_GAS_EQUATION)
var/air1_moles = air1.total_moles()
var/air2_moles = air2.total_moles()
var/air1_moles = air1.total_moles
var/air2_moles = air2.total_moles
if((air1_moles < transfer_moles1) || (air2_moles < transfer_moles2))
if(!transfer_moles1 || !transfer_moles2) return
@@ -271,4 +271,4 @@ obj/machinery/atmospherics/trinary/mixer/m_mixer/initialize()
break
update_icon()
update_underlays()
update_underlays()
@@ -33,7 +33,7 @@ obj/machinery/atmospherics/unary/oxygen_generator
if(!on)
return 0
var/total_moles = air_contents.total_moles()
var/total_moles = air_contents.total_moles
if(total_moles < oxygen_content)
var/current_heat_capacity = air_contents.heat_capacity()
@@ -41,7 +41,7 @@ obj/machinery/atmospherics/unary/oxygen_generator
var/added_oxygen = oxygen_content - total_moles
air_contents.temperature = (current_heat_capacity*air_contents.temperature + 20*added_oxygen*T0C)/(current_heat_capacity+20*added_oxygen)
air_contents.oxygen += added_oxygen
air_contents.adjust_gas("oxygen", added_oxygen)
if(network)
network.update = 1
@@ -45,7 +45,7 @@
return
overlays.Cut()
var/scrubber_icon = "scrubber"
var/turf/T = get_turf(src)
@@ -125,8 +125,8 @@
var/datum/gas_mixture/environment = loc.return_air()
if(scrubbing)
if((environment.phoron>0.001) || (environment.carbon_dioxide>0.001) || (environment.trace_gases.len>0))
var/transfer_moles = min(1, volume_rate/environment.volume)*environment.total_moles()
if((environment.gas["phoron"]>0.001) || (environment.gas["carbon_dioxide"]>0.001) || (environment.gas["oxygen_agent_b"]>0.001) || (environment.gas["sleeping_agent"]>0.001))
var/transfer_moles = min(1, volume_rate/environment.volume)*environment.total_moles
//Take a gas sample
var/datum/gas_mixture/removed = loc.remove_air(transfer_moles)
@@ -137,21 +137,17 @@
var/datum/gas_mixture/filtered_out = new
filtered_out.temperature = removed.temperature
if(scrub_Toxins)
filtered_out.phoron = removed.phoron
removed.phoron = 0
filtered_out.gas["phoron"] = removed.gas["phoron"]
removed.gas["phoron"] = 0
if(scrub_CO2)
filtered_out.carbon_dioxide = removed.carbon_dioxide
removed.carbon_dioxide = 0
if(removed.trace_gases.len>0)
for(var/datum/gas/trace_gas in removed.trace_gases)
if(istype(trace_gas, /datum/gas/oxygen_agent_b))
removed.trace_gases -= trace_gas
filtered_out.trace_gases += trace_gas
else if(istype(trace_gas, /datum/gas/sleeping_agent) && scrub_N2O)
removed.trace_gases -= trace_gas
filtered_out.trace_gases += trace_gas
filtered_out.gas["carbon_dioxide"] = removed.gas["carbon_dioxide"]
removed.gas["carbon_dioxide"] = 0
if(scrub_N2O)
filtered_out.gas["sleeping_agent"] = removed.gas["sleeping_agent"]
removed.gas["sleeping_agent"] = 0
if(removed.gas["oxygen_agent_b"])
filtered_out.gas["oxygen_agent_b"] = removed.gas["oxygen_agent_b"]
removed.gas["oxygen_agent_b"] = 0
//Remix the resulting gases
air_contents.merge(filtered_out)
@@ -165,7 +161,7 @@
if (air_contents.return_pressure()>=50*ONE_ATMOSPHERE)
return
var/transfer_moles = environment.total_moles()*(volume_rate/environment.volume)
var/transfer_moles = environment.total_moles*(volume_rate/environment.volume)
var/datum/gas_mixture/removed = loc.remove_air(transfer_moles)
+3 -134
View File
@@ -8,10 +8,10 @@ datum/pipe_network
//membership roster to go through for updates and what not
var/update = 1
var/datum/gas_mixture/air_transient = null
//var/datum/gas_mixture/air_transient = null
New()
air_transient = new()
//air_transient = new()
..()
@@ -70,135 +70,4 @@ datum/pipe_network
gases += line_member.air
proc/reconcile_air()
//Perfectly equalize all gases members instantly
//Calculate totals from individual components
var/total_thermal_energy = 0
var/total_heat_capacity = 0
air_transient.volume = 0
air_transient.oxygen = 0
air_transient.nitrogen = 0
air_transient.phoron = 0
air_transient.carbon_dioxide = 0
air_transient.trace_gases = list()
for(var/datum/gas_mixture/gas in gases)
air_transient.volume += gas.volume
var/temp_heatcap = gas.heat_capacity()
total_thermal_energy += gas.temperature*temp_heatcap
total_heat_capacity += temp_heatcap
air_transient.oxygen += gas.oxygen
air_transient.nitrogen += gas.nitrogen
air_transient.phoron += gas.phoron
air_transient.carbon_dioxide += gas.carbon_dioxide
if(gas.trace_gases.len)
for(var/datum/gas/trace_gas in gas.trace_gases)
var/datum/gas/corresponding = locate(trace_gas.type) in air_transient.trace_gases
if(!corresponding)
corresponding = new trace_gas.type()
air_transient.trace_gases += corresponding
corresponding.moles += trace_gas.moles
if(air_transient.volume > 0)
if(total_heat_capacity > 0)
air_transient.temperature = total_thermal_energy/total_heat_capacity
//Allow air mixture to react
if(air_transient.react())
update = 1
else
air_transient.temperature = 0
//Update individual gas_mixtures by volume ratio
for(var/datum/gas_mixture/gas in gases)
gas.oxygen = air_transient.oxygen*gas.volume/air_transient.volume
gas.nitrogen = air_transient.nitrogen*gas.volume/air_transient.volume
gas.phoron = air_transient.phoron*gas.volume/air_transient.volume
gas.carbon_dioxide = air_transient.carbon_dioxide*gas.volume/air_transient.volume
gas.temperature = air_transient.temperature
if(air_transient.trace_gases.len)
for(var/datum/gas/trace_gas in air_transient.trace_gases)
var/datum/gas/corresponding = locate(trace_gas.type) in gas.trace_gases
if(!corresponding)
corresponding = new trace_gas.type()
gas.trace_gases += corresponding
corresponding.moles = trace_gas.moles*gas.volume/air_transient.volume
gas.update_values()
air_transient.update_values()
return 1
proc/equalize_gases(datum/gas_mixture/list/gases)
//Perfectly equalize all gases members instantly
//Calculate totals from individual components
var/total_volume = 0
var/total_thermal_energy = 0
var/total_heat_capacity = 0
var/total_oxygen = 0
var/total_nitrogen = 0
var/total_phoron = 0
var/total_carbon_dioxide = 0
var/list/total_trace_gases = list()
for(var/datum/gas_mixture/gas in gases)
total_volume += gas.volume
var/temp_heatcap = gas.heat_capacity()
total_thermal_energy += gas.temperature*temp_heatcap
total_heat_capacity += temp_heatcap
total_oxygen += gas.oxygen
total_nitrogen += gas.nitrogen
total_phoron += gas.phoron
total_carbon_dioxide += gas.carbon_dioxide
if(gas.trace_gases.len)
for(var/datum/gas/trace_gas in gas.trace_gases)
var/datum/gas/corresponding = locate(trace_gas.type) in total_trace_gases
if(!corresponding)
corresponding = new trace_gas.type()
total_trace_gases += corresponding
corresponding.moles += trace_gas.moles
if(total_volume > 0)
//Calculate temperature
var/temperature = 0
if(total_heat_capacity > 0)
temperature = total_thermal_energy/total_heat_capacity
//Update individual gas_mixtures by volume ratio
for(var/datum/gas_mixture/gas in gases)
gas.oxygen = total_oxygen*gas.volume/total_volume
gas.nitrogen = total_nitrogen*gas.volume/total_volume
gas.phoron = total_phoron*gas.volume/total_volume
gas.carbon_dioxide = total_carbon_dioxide*gas.volume/total_volume
gas.temperature = temperature
if(total_trace_gases.len)
for(var/datum/gas/trace_gas in total_trace_gases)
var/datum/gas/corresponding = locate(trace_gas.type) in gas.trace_gases
if(!corresponding)
corresponding = new trace_gas.type()
gas.trace_gases += corresponding
corresponding.moles = trace_gas.moles*gas.volume/total_volume
gas.update_values()
return 1
equalize_gases(gases)
+3 -16
View File
@@ -37,22 +37,9 @@ datum/pipeline
for(var/obj/machinery/atmospherics/pipe/member in members)
member.air_temporary = new
member.air_temporary.copy_from(air)
member.air_temporary.volume = member.volume
member.air_temporary.oxygen = air.oxygen*member.volume/air.volume
member.air_temporary.nitrogen = air.nitrogen*member.volume/air.volume
member.air_temporary.phoron = air.phoron*member.volume/air.volume
member.air_temporary.carbon_dioxide = air.carbon_dioxide*member.volume/air.volume
member.air_temporary.temperature = air.temperature
if(air.trace_gases.len)
for(var/datum/gas/trace_gas in air.trace_gases)
var/datum/gas/corresponding = new trace_gas.type()
member.air_temporary.trace_gases += corresponding
corresponding.moles = trace_gas.moles*member.volume/air.volume
member.air_temporary.update_values()
member.air_temporary.multiply(member.volume / air.volume)
proc/build_pipeline(obj/machinery/atmospherics/pipe/base)
air = new
@@ -213,7 +200,7 @@ datum/pipeline
air.temperature -= heat/total_heat_capacity
if(network)
network.update = 1
proc/radiate_heat(surface, thermal_conductivity)
var/total_heat_capacity = air.heat_capacity()
var/heat = STEFAN_BOLTZMANN_CONSTANT * surface * air.temperature ** 4 * thermal_conductivity
+16 -29
View File
@@ -106,7 +106,7 @@
update_icon()
/obj/machinery/atmospherics/pipe/add_underlay(var/obj/machinery/atmospherics/node, var/direction)
if(istype(src, /obj/machinery/atmospherics/pipe/tank)) //todo: move tanks to unary devices
if(istype(src, /obj/machinery/atmospherics/pipe/tank)) //todo: move tanks to unary devices
return ..()
if(node)
@@ -157,7 +157,7 @@
/obj/machinery/atmospherics/pipe/simple/New()
..()
// Pipe colors and icon states are handled by an image cache - so color and icon should
// be null. For mapping purposes color is defined in the object definitions.
icon = null
@@ -473,7 +473,7 @@
overlays += icon_manager.get_atmos_icon("manifold", , pipe_color, "core")
overlays += icon_manager.get_atmos_icon("manifold", , , "clamps")
underlays.Cut()
var/list/directions = list(NORTH, SOUTH, EAST, WEST)
directions -= dir
@@ -678,7 +678,7 @@
overlays += icon_manager.get_atmos_icon("manifold", , pipe_color, "4way")
overlays += icon_manager.get_atmos_icon("manifold", , , "clamps_4way")
underlays.Cut()
var/list/directions = list(NORTH, SOUTH, EAST, WEST)
directions -= add_underlay(node1)
@@ -931,24 +931,13 @@
O << "\red [user] has used the analyzer on \icon[icon]"
var/pressure = parent.air.return_pressure()
var/total_moles = parent.air.total_moles()
var/total_moles = parent.air.total_moles
user << "\blue Results of analysis of \icon[icon]"
if (total_moles>0)
var/o2_concentration = parent.air.oxygen/total_moles
var/n2_concentration = parent.air.nitrogen/total_moles
var/co2_concentration = parent.air.carbon_dioxide/total_moles
var/phoron_concentration = parent.air.phoron/total_moles
var/unknown_concentration = 1-(o2_concentration+n2_concentration+co2_concentration+phoron_concentration)
user << "\blue Pressure: [round(pressure,0.1)] kPa"
user << "\blue Nitrogen: [round(n2_concentration*100)]%"
user << "\blue Oxygen: [round(o2_concentration*100)]%"
user << "\blue CO2: [round(co2_concentration*100)]%"
user << "\blue Phoron: [round(phoron_concentration*100)]%"
if(unknown_concentration>0.01)
user << "\red Unknown: [round(unknown_concentration*100)]%"
for(var/g in parent.air.gas)
user << "\blue [gas_data.name[g]]: [round((parent.air.gas[g] / total_moles) * 100)]%"
user << "\blue Temperature: [round(parent.air.temperature-T0C)]&deg;C"
else
user << "\blue Tank is empty!"
@@ -962,10 +951,11 @@
air_temporary.volume = volume
air_temporary.temperature = T20C
air_temporary.oxygen = (25*ONE_ATMOSPHERE*O2STANDARD)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature)
air_temporary.nitrogen = (25*ONE_ATMOSPHERE*N2STANDARD)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature)
air_temporary.adjust_multi("oxygen", (25*ONE_ATMOSPHERE*O2STANDARD)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature), \
"nitrogen",(25*ONE_ATMOSPHERE*N2STANDARD)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature))
..()
..()
icon_state = "air"
/obj/machinery/atmospherics/pipe/tank/oxygen
@@ -977,7 +967,7 @@
air_temporary.volume = volume
air_temporary.temperature = T20C
air_temporary.oxygen = (25*ONE_ATMOSPHERE)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature)
air_temporary.adjust_gas("oxygen", (25*ONE_ATMOSPHERE)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature))
..()
icon_state = "o2"
@@ -991,7 +981,7 @@
air_temporary.volume = volume
air_temporary.temperature = T20C
air_temporary.nitrogen = (25*ONE_ATMOSPHERE)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature)
air_temporary.adjust_gas("nitrogen", (25*ONE_ATMOSPHERE)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature))
..()
icon_state = "n2"
@@ -1005,7 +995,7 @@
air_temporary.volume = volume
air_temporary.temperature = T20C
air_temporary.carbon_dioxide = (25*ONE_ATMOSPHERE)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature)
air_temporary.adjust_gas("carbon_dioxide", (25*ONE_ATMOSPHERE)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature))
..()
icon_state = "co2"
@@ -1019,7 +1009,7 @@
air_temporary.volume = volume
air_temporary.temperature = T20C
air_temporary.phoron = (25*ONE_ATMOSPHERE)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature)
air_temporary.adjust_gas("phoron", (25*ONE_ATMOSPHERE)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature))
..()
icon_state = "phoron"
@@ -1033,10 +1023,7 @@
air_temporary.volume = volume
air_temporary.temperature = T0C
var/datum/gas/sleeping_agent/trace_gas = new
trace_gas.moles = (25*ONE_ATMOSPHERE)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature)
air_temporary.trace_gases += trace_gas
air_temporary.adjust_gas("sleeping_agent", (25*ONE_ATMOSPHERE)*(air_temporary.volume)/(R_IDEAL_GAS_EQUATION*air_temporary.temperature))
..()
icon_state = "n2o"