Skip to content

Commit

Permalink
minor tweaks: optimizations, cleanup, modular results var
Browse files Browse the repository at this point in the history
  • Loading branch information
duncathan committed Apr 4, 2017
1 parent 6eedb9d commit 76277fa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions code/modules/atmospherics/environmental/LINDA_fire.dm
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@

if(bypassing)
if(!just_spawned)
volume = location.air.fuel_burnt*FIRE_GROWTH_RATE
volume = location.air.reaction_results["fire"]*FIRE_GROWTH_RATE
temperature = location.air.temperature
else
var/datum/gas_mixture/affected = location.air.remove_ratio(volume/location.air.volume)
affected.temperature = temperature
affected.react()
temperature = affected.temperature
volume = affected.fuel_burnt*FIRE_GROWTH_RATE
volume = affected.reaction_results["fire"]*FIRE_GROWTH_RATE
location.assume_air(affected)

for(var/A in loc)
Expand Down
18 changes: 5 additions & 13 deletions code/modules/atmospherics/gasmixtures/gas_mixture.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ var/list/gaslist_cache = init_gaslist_cache()
var/tmp/temperature_archived
var/volume //liters
var/last_share
var/tmp/fuel_burnt
//var/datum/holder
var/list/reaction_results

/datum/gas_mixture/New(volume = CELL_VOLUME)
gases = new
temperature = 0
temperature_archived = 0
src.volume = volume
last_share = 0
fuel_burnt = 0
reaction_results = new

//listmos procs

Expand Down Expand Up @@ -417,11 +416,11 @@ var/list/gaslist_cache = init_gaslist_cache()

return ""

/datum/gas_mixture/react(turf/open/dump_location, debug)
/datum/gas_mixture/react(turf/open/dump_location)
. = 0
if(temperature < TCMB) //just for safety
temperature = TCMB
fuel_burnt = 0
reaction_results = new

var/list/cached_gases = gases
var/temp = temperature
Expand All @@ -434,16 +433,12 @@ var/list/gaslist_cache = init_gaslist_cache()
var/list/min_reqs = reaction.min_requirements.Copy()
if((min_reqs["TEMP"] && temp < min_reqs["TEMP"]) \
|| (min_reqs["ENER"] && ener < min_reqs["ENER"]))
if(debug)
to_chat(world, "Reaction: [reaction.name] did not occur because temperature or energy requirements were not met.")
continue
min_reqs -= "TEMP"
min_reqs -= "ENER"

for(var/id in min_reqs)
if(!cached_gases[id] || cached_gases[id][MOLES] < min_reqs[id])
if(debug)
to_chat(world, "Reaction: [reaction.name] did not occur because [id] requirements were not met. Requirement: [text2num(min_reqs[id])] moles. Current level: [cached_gases[id] ? cached_gases[id][MOLES] : 0] moles.")
continue reaction_loop
//at this point, all minimum requirements for the reaction are satisfied.

Expand All @@ -461,10 +456,7 @@ var/list/gaslist_cache = init_gaslist_cache()
//at this point, all requirements for the reaction are satisfied. we can now react()
*/

var/result = reaction.react(src, dump_location)
. |= result
if(result && debug)
to_chat(world, "Reaction: [reaction.name] succesfully reacted.")
. |= reaction.react(src, dump_location)
if(.)
garbage_collect()

Expand Down
17 changes: 12 additions & 5 deletions code/modules/atmospherics/gasmixtures/reactions.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
var/list/min_requirements
var/list/max_requirements
var/exclude = FALSE //do it this way to allow for addition/removal of reactions midmatch in the future
var/priority //lower numbers are checked/react later than higher numbers. if two reactions have the same priority they may happen in either order
var/priority = 100 //lower numbers are checked/react later than higher numbers. if two reactions have the same priority they may happen in either order
var/name = "reaction"
var/id = "r"

/datum/gas_reaction/New()
init_reqs()
Expand All @@ -38,6 +39,7 @@
/datum/gas_reaction/agent_b
priority = 2
name = "Agent B"
id = "agent_b"

/datum/gas_reaction/agent_b/init_reqs()
min_requirements = list(
Expand Down Expand Up @@ -66,6 +68,7 @@
/datum/gas_reaction/freon
priority = 1
name = "Freon"
id = "freon"

/datum/gas_reaction/freon/init_reqs()
min_requirements = list("freon" = MOLES_PLASMA_VISIBLE)
Expand All @@ -80,6 +83,7 @@
/datum/gas_reaction/water_vapor
priority = 1
name = "Water Vapor"
id = "vapor"

/datum/gas_reaction/water_vapor/init_reqs()
min_requirements = list("water_vapor" = MOLES_PLASMA_VISIBLE)
Expand All @@ -94,6 +98,7 @@
/datum/gas_reaction/fire
priority = -1 //fire should ALWAYS be last
name = "Hydrocarbon Combustion"
id = "fire"

/datum/gas_reaction/fire/init_reqs()
min_requirements = list("TEMP" = FIRE_MINIMUM_TEMPERATURE_TO_EXIST) //doesn't include plasma reqs b/c of volatile fuel stuff - consider finally axing volatile fuel
Expand All @@ -103,13 +108,14 @@
var/old_heat_capacity = air.heat_capacity()
var/list/cached_gases = air.gases //this speeds things up because accessing datum vars is slow
var/temperature = air.temperature
var/list/cached_results = air.reaction_results

//to_chat(world, "pre [temperature], [cached_gases["o2"][MOLES]], [cached_gases["plasma"][MOLES]]")
cached_results[id] = 0

//General volatile gas burn
if(cached_gases["v_fuel"] && cached_gases["v_fuel"][MOLES])
var/burned_fuel

if(!cached_gases["o2"])
burned_fuel = 0
else if(cached_gases["o2"][MOLES] < cached_gases["v_fuel"][MOLES])
Expand All @@ -126,7 +132,7 @@
air.assert_gas("co2")
cached_gases["co2"][MOLES] += burned_fuel

air.fuel_burnt += burned_fuel
cached_results[id] += burned_fuel

//Handle plasma burning
if(cached_gases["plasma"] && cached_gases["plasma"][MOLES] > MINIMUM_HEAT_CAPACITY)
Expand All @@ -153,7 +159,7 @@

energy_released += FIRE_PLASMA_ENERGY_RELEASED * (plasma_burn_rate)

air.fuel_burnt += (plasma_burn_rate)*(1+oxygen_burn_rate)
cached_results[id] += (plasma_burn_rate)*(1+oxygen_burn_rate)

if(energy_released > 0)
var/new_heat_capacity = air.heat_capacity()
Expand All @@ -172,13 +178,14 @@
item.temperature_expose(air, temperature, CELL_VOLUME)
location.temperature_expose(air, temperature, CELL_VOLUME)

return air.fuel_burnt ? REACTING : NO_REACTION
return cached_results[id] ? REACTING : NO_REACTION

//fusion: a terrible idea that was fun to try. turns co2 and plasma into REALLY HOT oxygen and nitrogen. super exothermic lol
/datum/gas_reaction/fusion
exclude = TRUE
priority = 2
name = "Plasmic Fusion"
id = "fusion"

/datum/gas_reaction/fusion/init_reqs()
min_requirements = list(
Expand Down

0 comments on commit 76277fa

Please sign in to comment.