From 0177eafe788834765056117ef3a17ee2f28639a4 Mon Sep 17 00:00:00 2001 From: duncathan salt Date: Wed, 2 Dec 2015 15:17:03 -0600 Subject: [PATCH 1/4] removes unused gas mixture code, pass 1 --- code/datums/gas_mixture.dm | 144 +------------------------------------ 1 file changed, 2 insertions(+), 142 deletions(-) diff --git a/code/datums/gas_mixture.dm b/code/datums/gas_mixture.dm index 92c6f24c7e3..19949050064 100644 --- a/code/datums/gas_mixture.dm +++ b/code/datums/gas_mixture.dm @@ -135,7 +135,7 @@ What are the archived variables for? var/old_heat_capacity = heat_capacity() var/datum/gas/volatile_fuel/fuel_store = locate(/datum/gas/volatile_fuel/) in trace_gases - if(fuel_store) //General volatile gas burn + if(fuel_store) //General volatile gas burnar var/burned_fuel = 0 if(oxygen < fuel_store.moles) @@ -192,11 +192,6 @@ What are the archived variables for? //Merges all air from giver into self. Deletes giver. //Returns: 1 on success (no failure cases yet) -/datum/gas_mixture/proc/check_then_merge(datum/gas_mixture/giver) - //Similar to merge(...) but first checks to see if the amount of air assumed is small enough - // that group processing is still accurate for source (aborts if not) - //Returns: 1 on successful merge, 0 if the check failed - /datum/gas_mixture/proc/remove(amount) //Proportionally removes amount of gas from the gas_mixture //Returns: gas_mixture with the gases removed @@ -205,18 +200,10 @@ What are the archived variables for? //Proportionally removes amount of gas from the gas_mixture //Returns: gas_mixture with the gases removed -/datum/gas_mixture/proc/subtract(datum/gas_mixture/right_side) - //Subtracts right_side from air_mixture. Used to help turfs mingle - -/datum/gas_mixture/proc/check_then_remove(amount) - //Similar to remove(...) but first checks to see if the amount of air removed is small enough - // that group processing is still accurate for source (aborts if not) - //Returns: gas_mixture with the gases removed or null - /datum/gas_mixture/proc/copy_from(datum/gas_mixture/sample) //Copies variables from sample -/datum/gas_mixture/proc/share(datum/gas_mixture/sharer) +/datum/gas_mixture/proc/share(datum/gas_mixture/sharer) //potential candidate for removal //Performs air sharing calculations between two gas_mixtures assuming only 1 boundary length //Return: amount of gas exchanged (+ if sharer received) @@ -224,43 +211,15 @@ What are the archived variables for? //Similar to share(...), except the model is not modified //Return: amount of gas exchanged -/datum/gas_mixture/proc/check_gas_mixture(datum/gas_mixture/sharer) - //Returns: 0 if the self-check failed then -1 if sharer-check failed then 1 if both checks pass - /datum/gas_mixture/proc/check_turf(turf/model) //Returns: 0 if self-check failed or 1 if check passes -// check_me_then_share(datum/gas_mixture/sharer) - //Similar to share(...) but first checks to see if amount of air moved is small enough - // that group processing is still accurate for source (aborts if not) - //Returns: 1 on successful share, 0 if the check failed - -// check_me_then_mimic(turf/model) - //Similar to mimic(...) but first checks to see if amount of air moved is small enough - // that group processing is still accurate (aborts if not) - //Returns: 1 on successful mimic, 0 if the check failed - -// check_both_then_share(datum/gas_mixture/sharer) - //Similar to check_me_then_share(...) but also checks to see if amount of air moved is small enough - // that group processing is still accurate for the sharer (aborts if not) - //Returns: 0 if the self-check failed then -1 if sharer-check failed then 1 if successful share - - /datum/gas_mixture/proc/temperature_mimic(turf/model, conduction_coefficient) /datum/gas_mixture/proc/temperature_share(datum/gas_mixture/sharer, conduction_coefficient) /datum/gas_mixture/proc/temperature_turf_share(turf/simulated/sharer, conduction_coefficient) - -/datum/gas_mixture/proc/check_me_then_temperature_mimic(turf/model, conduction_coefficient) - -/datum/gas_mixture/proc/check_me_then_temperature_share(datum/gas_mixture/sharer, conduction_coefficient) - -/datum/gas_mixture/proc/check_both_then_temperature_share(datum/gas_mixture/sharer, conduction_coefficient) - -/datum/gas_mixture/proc/check_me_then_temperature_turf_share(turf/simulated/sharer, conduction_coefficient) - /datum/gas_mixture/proc/compare(datum/gas_mixture/sample) //Compares sample to self to see if within acceptable ranges that group processing may be enabled @@ -278,25 +237,6 @@ What are the archived variables for? return 1 -/datum/gas_mixture/check_then_merge(datum/gas_mixture/giver) - if(!giver) - return 0 - if(((giver.oxygen > MINIMUM_AIR_TO_SUSPEND) && (giver.oxygen >= oxygen*MINIMUM_AIR_RATIO_TO_SUSPEND)) \ - || ((giver.carbon_dioxide > MINIMUM_AIR_TO_SUSPEND) && (giver.carbon_dioxide >= carbon_dioxide*MINIMUM_AIR_RATIO_TO_SUSPEND)) \ - || ((giver.nitrogen > MINIMUM_AIR_TO_SUSPEND) && (giver.nitrogen >= nitrogen*MINIMUM_AIR_RATIO_TO_SUSPEND)) \ - || ((giver.toxins > MINIMUM_AIR_TO_SUSPEND) && (giver.toxins >= toxins*MINIMUM_AIR_RATIO_TO_SUSPEND))) - return 0 - if(abs(giver.temperature - temperature) > MINIMUM_TEMPERATURE_DELTA_TO_SUSPEND) - return 0 - - if(giver.trace_gases.len) - for(var/datum/gas/trace_gas in giver.trace_gases) - var/datum/gas/corresponding = locate(trace_gas.type) in trace_gases - if((trace_gas.moles > MINIMUM_AIR_TO_SUSPEND) && (!corresponding || (trace_gas.moles >= corresponding.moles*MINIMUM_AIR_RATIO_TO_SUSPEND))) - return 0 - - return merge(giver) - /datum/gas_mixture/merge(datum/gas_mixture/giver) if(!giver) return 0 @@ -387,17 +327,6 @@ What are the archived variables for? return removed -/datum/gas_mixture/check_then_remove(amount) - - //Since it is all proportional, the check may be done on the gas as a whole - var/sum = total_moles() - amount = min(amount,sum) //Can not take more air than tile has! - - if((amount > MINIMUM_AIR_RATIO_TO_SUSPEND) && (amount > sum*MINIMUM_AIR_RATIO_TO_SUSPEND)) - return 0 - - return remove(amount) - /datum/gas_mixture/copy_from(datum/gas_mixture/sample) oxygen = sample.oxygen carbon_dioxide = sample.carbon_dioxide @@ -416,75 +345,6 @@ What are the archived variables for? return 1 -/datum/gas_mixture/subtract(datum/gas_mixture/right_side) - oxygen -= right_side.oxygen - carbon_dioxide -= right_side.carbon_dioxide - nitrogen -= right_side.nitrogen - toxins -= right_side.toxins - - if((trace_gases.len > 0)||(right_side.trace_gases.len > 0)) - for(var/datum/gas/trace_gas in right_side.trace_gases) - var/datum/gas/corresponding = locate(trace_gas.type) in trace_gases - if(!corresponding) - corresponding = new trace_gas.type() - trace_gases += corresponding - - corresponding.moles -= trace_gas.moles - - return 1 - -/datum/gas_mixture/check_gas_mixture(datum/gas_mixture/sharer) - if(!sharer) return 0 - var/delta_oxygen = (oxygen_archived - sharer.oxygen_archived)/5 - var/delta_carbon_dioxide = (carbon_dioxide_archived - sharer.carbon_dioxide_archived)/5 - var/delta_nitrogen = (nitrogen_archived - sharer.nitrogen_archived)/5 - var/delta_toxins = (toxins_archived - sharer.toxins_archived)/5 - - var/delta_temperature = (temperature_archived - sharer.temperature_archived) - - if(((abs(delta_oxygen) > MINIMUM_AIR_TO_SUSPEND) && (abs(delta_oxygen) >= oxygen_archived*MINIMUM_AIR_RATIO_TO_SUSPEND)) \ - || ((abs(delta_carbon_dioxide) > MINIMUM_AIR_TO_SUSPEND) && (abs(delta_carbon_dioxide) >= carbon_dioxide_archived*MINIMUM_AIR_RATIO_TO_SUSPEND)) \ - || ((abs(delta_nitrogen) > MINIMUM_AIR_TO_SUSPEND) && (abs(delta_nitrogen) >= nitrogen_archived*MINIMUM_AIR_RATIO_TO_SUSPEND)) \ - || ((abs(delta_toxins) > MINIMUM_AIR_TO_SUSPEND) && (abs(delta_toxins) >= toxins_archived*MINIMUM_AIR_RATIO_TO_SUSPEND))) - return 0 - - if(abs(delta_temperature) > MINIMUM_TEMPERATURE_DELTA_TO_SUSPEND) - return 0 - - if(sharer.trace_gases.len) - for(var/datum/gas/trace_gas in sharer.trace_gases) - if(trace_gas.moles_archived > MINIMUM_AIR_TO_SUSPEND*4) - var/datum/gas/corresponding = locate(trace_gas.type) in trace_gases - if(corresponding) - if(trace_gas.moles_archived >= corresponding.moles_archived*MINIMUM_AIR_RATIO_TO_SUSPEND*4) - return 0 - else - return 0 - - if(trace_gases.len) - for(var/datum/gas/trace_gas in trace_gases) - if(trace_gas.moles_archived > MINIMUM_AIR_TO_SUSPEND*4) - if(!locate(trace_gas.type) in sharer.trace_gases) - return 0 - - if(((abs(delta_oxygen) > MINIMUM_AIR_TO_SUSPEND) && (abs(delta_oxygen) >= sharer.oxygen_archived*MINIMUM_AIR_RATIO_TO_SUSPEND)) \ - || ((abs(delta_carbon_dioxide) > MINIMUM_AIR_TO_SUSPEND) && (abs(delta_carbon_dioxide) >= sharer.carbon_dioxide_archived*MINIMUM_AIR_RATIO_TO_SUSPEND)) \ - || ((abs(delta_nitrogen) > MINIMUM_AIR_TO_SUSPEND) && (abs(delta_nitrogen) >= sharer.nitrogen_archived*MINIMUM_AIR_RATIO_TO_SUSPEND)) \ - || ((abs(delta_toxins) > MINIMUM_AIR_TO_SUSPEND) && (abs(delta_toxins) >= sharer.toxins_archived*MINIMUM_AIR_RATIO_TO_SUSPEND))) - return -1 - - if(trace_gases.len) - for(var/datum/gas/trace_gas in trace_gases) - if(trace_gas.moles_archived > MINIMUM_AIR_TO_SUSPEND*4) - var/datum/gas/corresponding = locate(trace_gas.type) in sharer.trace_gases - if(corresponding) - if(trace_gas.moles_archived >= corresponding.moles_archived*MINIMUM_AIR_RATIO_TO_SUSPEND*4) - return -1 - else - return -1 - - return 1 - /datum/gas_mixture/check_turf(turf/model, atmos_adjacent_turfs = 4) var/delta_oxygen = (oxygen_archived - model.oxygen)/(atmos_adjacent_turfs+1) var/delta_carbon_dioxide = (carbon_dioxide_archived - model.carbon_dioxide)/(atmos_adjacent_turfs+1) From 70d801639d57504343707a9ab0ee560223b502a4 Mon Sep 17 00:00:00 2001 From: duncathan salt Date: Wed, 2 Dec 2015 17:33:32 -0600 Subject: [PATCH 2/4] Actually removes some of the procs --- code/datums/gas_mixture.dm | 110 ------------------------------------- 1 file changed, 110 deletions(-) diff --git a/code/datums/gas_mixture.dm b/code/datums/gas_mixture.dm index 19949050064..bfd300fc3ee 100644 --- a/code/datums/gas_mixture.dm +++ b/code/datums/gas_mixture.dm @@ -599,116 +599,6 @@ What are the archived variables for? else return 0 -/datum/gas_mixture/check_both_then_temperature_share(datum/gas_mixture/sharer, conduction_coefficient) - var/delta_temperature = (temperature_archived - sharer.temperature_archived) - - var/self_heat_capacity = heat_capacity_archived() - var/sharer_heat_capacity = sharer.heat_capacity_archived() - - var/self_temperature_delta = 0 - var/sharer_temperature_delta = 0 - - if((sharer_heat_capacity > MINIMUM_HEAT_CAPACITY) && (self_heat_capacity > MINIMUM_HEAT_CAPACITY)) - var/heat = conduction_coefficient*delta_temperature* \ - (self_heat_capacity*sharer_heat_capacity/(self_heat_capacity+sharer_heat_capacity)) - - self_temperature_delta = -heat/(self_heat_capacity) - sharer_temperature_delta = heat/(sharer_heat_capacity) - else - return 1 - - if((abs(self_temperature_delta) > MINIMUM_TEMPERATURE_DELTA_TO_SUSPEND) \ - && (abs(self_temperature_delta) > MINIMUM_TEMPERATURE_RATIO_TO_SUSPEND*temperature_archived)) - return 0 - - if((abs(sharer_temperature_delta) > MINIMUM_TEMPERATURE_DELTA_TO_SUSPEND) \ - && (abs(sharer_temperature_delta) > MINIMUM_TEMPERATURE_RATIO_TO_SUSPEND*sharer.temperature_archived)) - return -1 - - temperature += self_temperature_delta - sharer.temperature += sharer_temperature_delta - - return 1 - //Logic integrated from: temperature_share(sharer, conduction_coefficient) for efficiency - -/datum/gas_mixture/check_me_then_temperature_share(datum/gas_mixture/sharer, conduction_coefficient) - var/delta_temperature = (temperature_archived - sharer.temperature_archived) - - var/self_heat_capacity = heat_capacity_archived() - var/sharer_heat_capacity = sharer.heat_capacity_archived() - - var/self_temperature_delta = 0 - var/sharer_temperature_delta = 0 - - if((sharer_heat_capacity > MINIMUM_HEAT_CAPACITY) && (self_heat_capacity > MINIMUM_HEAT_CAPACITY)) - var/heat = conduction_coefficient*delta_temperature* \ - (self_heat_capacity*sharer_heat_capacity/(self_heat_capacity+sharer_heat_capacity)) - - self_temperature_delta = -heat/self_heat_capacity - sharer_temperature_delta = heat/sharer_heat_capacity - else - return 1 - - if((abs(self_temperature_delta) > MINIMUM_TEMPERATURE_DELTA_TO_SUSPEND) \ - && (abs(self_temperature_delta) > MINIMUM_TEMPERATURE_RATIO_TO_SUSPEND*temperature_archived)) - return 0 - - temperature += self_temperature_delta - sharer.temperature += sharer_temperature_delta - - return 1 - //Logic integrated from: temperature_share(sharer, conduction_coefficient) for efficiency - -/datum/gas_mixture/check_me_then_temperature_turf_share(turf/simulated/sharer, conduction_coefficient) - var/delta_temperature = (temperature_archived - sharer.temperature) - - var/self_temperature_delta = 0 - var/sharer_temperature_delta = 0 - - if(abs(delta_temperature) > MINIMUM_TEMPERATURE_DELTA_TO_CONSIDER) - var/self_heat_capacity = heat_capacity_archived() - - if((sharer.heat_capacity > MINIMUM_HEAT_CAPACITY) && (self_heat_capacity > MINIMUM_HEAT_CAPACITY)) - var/heat = conduction_coefficient*delta_temperature* \ - (self_heat_capacity*sharer.heat_capacity/(self_heat_capacity+sharer.heat_capacity)) - - self_temperature_delta = -heat/self_heat_capacity - sharer_temperature_delta = heat/sharer.heat_capacity - else - return 1 - - if((abs(self_temperature_delta) > MINIMUM_TEMPERATURE_DELTA_TO_SUSPEND) \ - && (abs(self_temperature_delta) > MINIMUM_TEMPERATURE_RATIO_TO_SUSPEND*temperature_archived)) - return 0 - - temperature += self_temperature_delta - sharer.temperature += sharer_temperature_delta - - return 1 - //Logic integrated from: temperature_turf_share(sharer, conduction_coefficient) for efficiency - -/datum/gas_mixture/check_me_then_temperature_mimic(turf/model, conduction_coefficient) - var/delta_temperature = (temperature_archived - model.temperature) - var/self_temperature_delta = 0 - - if(abs(delta_temperature) > MINIMUM_TEMPERATURE_DELTA_TO_CONSIDER) - var/self_heat_capacity = heat_capacity_archived() - - if((model.heat_capacity > MINIMUM_HEAT_CAPACITY) && (self_heat_capacity > MINIMUM_HEAT_CAPACITY)) - var/heat = conduction_coefficient*delta_temperature* \ - (self_heat_capacity*model.heat_capacity/(self_heat_capacity+model.heat_capacity)) - - self_temperature_delta = -heat/self_heat_capacity - - if((abs(self_temperature_delta) > MINIMUM_TEMPERATURE_DELTA_TO_SUSPEND) \ - && (abs(self_temperature_delta) > MINIMUM_TEMPERATURE_RATIO_TO_SUSPEND*temperature_archived)) - return 0 - - temperature += self_temperature_delta - - return 1 - //Logic integrated from: temperature_mimic(model, conduction_coefficient) for efficiency - /datum/gas_mixture/temperature_share(datum/gas_mixture/sharer, conduction_coefficient) var/delta_temperature = (temperature_archived - sharer.temperature_archived) From 8b74e975b5fc28db741f4932ec1eb42cd82309d1 Mon Sep 17 00:00:00 2001 From: duncathan salt Date: Wed, 2 Dec 2015 17:39:09 -0600 Subject: [PATCH 3/4] there's no way that share() isn't called, is there? --- code/datums/gas_mixture.dm | 135 +------------------------------------ 1 file changed, 1 insertion(+), 134 deletions(-) diff --git a/code/datums/gas_mixture.dm b/code/datums/gas_mixture.dm index bfd300fc3ee..1331aeb4d2b 100644 --- a/code/datums/gas_mixture.dm +++ b/code/datums/gas_mixture.dm @@ -135,7 +135,7 @@ What are the archived variables for? var/old_heat_capacity = heat_capacity() var/datum/gas/volatile_fuel/fuel_store = locate(/datum/gas/volatile_fuel/) in trace_gases - if(fuel_store) //General volatile gas burnar + if(fuel_store) //General volatile gas burn var/burned_fuel = 0 if(oxygen < fuel_store.moles) @@ -203,10 +203,6 @@ What are the archived variables for? /datum/gas_mixture/proc/copy_from(datum/gas_mixture/sample) //Copies variables from sample -/datum/gas_mixture/proc/share(datum/gas_mixture/sharer) //potential candidate for removal - //Performs air sharing calculations between two gas_mixtures assuming only 1 boundary length - //Return: amount of gas exchanged (+ if sharer received) - /datum/gas_mixture/proc/mimic(turf/model) //Similar to share(...), except the model is not modified //Return: amount of gas exchanged @@ -391,135 +387,6 @@ What are the archived variables for? return 1 -/datum/gas_mixture/share(datum/gas_mixture/sharer, atmos_adjacent_turfs = 4) - if(!sharer) return 0 - var/delta_oxygen = QUANTIZE(oxygen_archived - sharer.oxygen_archived)/(atmos_adjacent_turfs+1) - var/delta_carbon_dioxide = QUANTIZE(carbon_dioxide_archived - sharer.carbon_dioxide_archived)/(atmos_adjacent_turfs+1) - var/delta_nitrogen = QUANTIZE(nitrogen_archived - sharer.nitrogen_archived)/(atmos_adjacent_turfs+1) - var/delta_toxins = QUANTIZE(toxins_archived - sharer.toxins_archived)/(atmos_adjacent_turfs+1) - - var/delta_temperature = (temperature_archived - sharer.temperature_archived) - - var/old_self_heat_capacity = 0 - var/old_sharer_heat_capacity = 0 - - var/heat_capacity_self_to_sharer = 0 - var/heat_capacity_sharer_to_self = 0 - - if(abs(delta_temperature) > MINIMUM_TEMPERATURE_DELTA_TO_CONSIDER) - - var/delta_air = delta_oxygen+delta_nitrogen - if(delta_air) - var/air_heat_capacity = SPECIFIC_HEAT_AIR*delta_air - if(delta_air > 0) - heat_capacity_self_to_sharer += air_heat_capacity - else - heat_capacity_sharer_to_self -= air_heat_capacity - - if(delta_carbon_dioxide) - var/carbon_dioxide_heat_capacity = SPECIFIC_HEAT_CDO*delta_carbon_dioxide - if(delta_carbon_dioxide > 0) - heat_capacity_self_to_sharer += carbon_dioxide_heat_capacity - else - heat_capacity_sharer_to_self -= carbon_dioxide_heat_capacity - - if(delta_toxins) - var/toxins_heat_capacity = SPECIFIC_HEAT_TOXIN*delta_toxins - if(delta_toxins > 0) - heat_capacity_self_to_sharer += toxins_heat_capacity - else - heat_capacity_sharer_to_self -= toxins_heat_capacity - - old_self_heat_capacity = heat_capacity() - old_sharer_heat_capacity = sharer.heat_capacity() - - oxygen -= delta_oxygen - sharer.oxygen += delta_oxygen - - carbon_dioxide -= delta_carbon_dioxide - sharer.carbon_dioxide += delta_carbon_dioxide - - nitrogen -= delta_nitrogen - sharer.nitrogen += delta_nitrogen - - toxins -= delta_toxins - sharer.toxins += delta_toxins - - var/moved_moles = (delta_oxygen + delta_carbon_dioxide + delta_nitrogen + delta_toxins) - last_share = abs(delta_oxygen) + abs(delta_carbon_dioxide) + abs(delta_nitrogen) + abs(delta_toxins) - - var/list/trace_types_considered = list() - - if(trace_gases.len) - for(var/datum/gas/trace_gas in trace_gases) - - var/datum/gas/corresponding = locate(trace_gas.type) in sharer.trace_gases - var/delta = 0 - - if(corresponding) - delta = QUANTIZE(trace_gas.moles_archived - corresponding.moles_archived)/(atmos_adjacent_turfs+1) - else - corresponding = new trace_gas.type() - sharer.trace_gases += corresponding - - delta = trace_gas.moles_archived/(atmos_adjacent_turfs+1) - - trace_gas.moles -= delta - corresponding.moles += delta - - if(delta) - var/individual_heat_capacity = trace_gas.specific_heat*delta - if(delta > 0) - heat_capacity_self_to_sharer += individual_heat_capacity - else - heat_capacity_sharer_to_self -= individual_heat_capacity - - moved_moles += delta - last_share += abs(delta) - - trace_types_considered += trace_gas.type - - - if(sharer.trace_gases.len) - for(var/datum/gas/trace_gas in sharer.trace_gases) - if(trace_gas.type in trace_types_considered) continue - else - var/datum/gas/corresponding - var/delta = 0 - - corresponding = new trace_gas.type() - trace_gases += corresponding - - delta = trace_gas.moles_archived/5 - - trace_gas.moles -= delta - corresponding.moles += delta - - //Guaranteed transfer from sharer to self - var/individual_heat_capacity = trace_gas.specific_heat*delta - heat_capacity_sharer_to_self += individual_heat_capacity - - moved_moles += -delta - last_share += abs(delta) - - if(abs(delta_temperature) > MINIMUM_TEMPERATURE_DELTA_TO_CONSIDER) - var/new_self_heat_capacity = old_self_heat_capacity + heat_capacity_sharer_to_self - heat_capacity_self_to_sharer - var/new_sharer_heat_capacity = old_sharer_heat_capacity + heat_capacity_self_to_sharer - heat_capacity_sharer_to_self - - if(new_self_heat_capacity > MINIMUM_HEAT_CAPACITY) - temperature = (old_self_heat_capacity*temperature - heat_capacity_self_to_sharer*temperature_archived + heat_capacity_sharer_to_self*sharer.temperature_archived)/new_self_heat_capacity - - if(new_sharer_heat_capacity > MINIMUM_HEAT_CAPACITY) - sharer.temperature = (old_sharer_heat_capacity*sharer.temperature-heat_capacity_sharer_to_self*sharer.temperature_archived + heat_capacity_self_to_sharer*temperature_archived)/new_sharer_heat_capacity - - if(abs(old_sharer_heat_capacity) > MINIMUM_HEAT_CAPACITY) - if(abs(new_sharer_heat_capacity/old_sharer_heat_capacity - 1) < 0.10) // <10% change in sharer heat capacity - temperature_share(sharer, OPEN_HEAT_TRANSFER_COEFFICIENT) - - if((delta_temperature > MINIMUM_TEMPERATURE_TO_MOVE) || abs(moved_moles) > MINIMUM_MOLES_DELTA_TO_MOVE) - var/delta_pressure = temperature_archived*(total_moles() + moved_moles) - sharer.temperature_archived*(sharer.total_moles() - moved_moles) - return delta_pressure*R_IDEAL_GAS_EQUATION/volume - /datum/gas_mixture/mimic(turf/model, border_multiplier, atmos_adjacent_turfs = 4) var/delta_oxygen = QUANTIZE(oxygen_archived - model.oxygen)/(atmos_adjacent_turfs+1) var/delta_carbon_dioxide = QUANTIZE(carbon_dioxide_archived - model.carbon_dioxide)/(atmos_adjacent_turfs+1) From 8b1ef6a768256b468c529af746df7125032a8b40 Mon Sep 17 00:00:00 2001 From: duncathan salt Date: Thu, 3 Dec 2015 09:08:55 -0600 Subject: [PATCH 4/4] I was right; there was no way --- code/datums/gas_mixture.dm | 132 +++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/code/datums/gas_mixture.dm b/code/datums/gas_mixture.dm index 1331aeb4d2b..de566dec464 100644 --- a/code/datums/gas_mixture.dm +++ b/code/datums/gas_mixture.dm @@ -203,6 +203,9 @@ What are the archived variables for? /datum/gas_mixture/proc/copy_from(datum/gas_mixture/sample) //Copies variables from sample +/datum/gas_mixture/proc/share(datum/gas_mixture/sharer) + //Performs air sharing calculations between two gas_mixtures assuming only 1 boundary length + //Return: amount of gas exchanged (+ if sharer received) /datum/gas_mixture/proc/mimic(turf/model) //Similar to share(...), except the model is not modified //Return: amount of gas exchanged @@ -387,6 +390,135 @@ What are the archived variables for? return 1 +/datum/gas_mixture/share(datum/gas_mixture/sharer, atmos_adjacent_turfs = 4) + if(!sharer) return 0 + var/delta_oxygen = QUANTIZE(oxygen_archived - sharer.oxygen_archived)/(atmos_adjacent_turfs+1) + var/delta_carbon_dioxide = QUANTIZE(carbon_dioxide_archived - sharer.carbon_dioxide_archived)/(atmos_adjacent_turfs+1) + var/delta_nitrogen = QUANTIZE(nitrogen_archived - sharer.nitrogen_archived)/(atmos_adjacent_turfs+1) + var/delta_toxins = QUANTIZE(toxins_archived - sharer.toxins_archived)/(atmos_adjacent_turfs+1) + + var/delta_temperature = (temperature_archived - sharer.temperature_archived) + + var/old_self_heat_capacity = 0 + var/old_sharer_heat_capacity = 0 + + var/heat_capacity_self_to_sharer = 0 + var/heat_capacity_sharer_to_self = 0 + + if(abs(delta_temperature) > MINIMUM_TEMPERATURE_DELTA_TO_CONSIDER) + + var/delta_air = delta_oxygen+delta_nitrogen + if(delta_air) + var/air_heat_capacity = SPECIFIC_HEAT_AIR*delta_air + if(delta_air > 0) + heat_capacity_self_to_sharer += air_heat_capacity + else + heat_capacity_sharer_to_self -= air_heat_capacity + + if(delta_carbon_dioxide) + var/carbon_dioxide_heat_capacity = SPECIFIC_HEAT_CDO*delta_carbon_dioxide + if(delta_carbon_dioxide > 0) + heat_capacity_self_to_sharer += carbon_dioxide_heat_capacity + else + heat_capacity_sharer_to_self -= carbon_dioxide_heat_capacity + + if(delta_toxins) + var/toxins_heat_capacity = SPECIFIC_HEAT_TOXIN*delta_toxins + if(delta_toxins > 0) + heat_capacity_self_to_sharer += toxins_heat_capacity + else + heat_capacity_sharer_to_self -= toxins_heat_capacity + + old_self_heat_capacity = heat_capacity() + old_sharer_heat_capacity = sharer.heat_capacity() + + oxygen -= delta_oxygen + sharer.oxygen += delta_oxygen + + carbon_dioxide -= delta_carbon_dioxide + sharer.carbon_dioxide += delta_carbon_dioxide + + nitrogen -= delta_nitrogen + sharer.nitrogen += delta_nitrogen + + toxins -= delta_toxins + sharer.toxins += delta_toxins + + var/moved_moles = (delta_oxygen + delta_carbon_dioxide + delta_nitrogen + delta_toxins) + last_share = abs(delta_oxygen) + abs(delta_carbon_dioxide) + abs(delta_nitrogen) + abs(delta_toxins) + + var/list/trace_types_considered = list() + + if(trace_gases.len) + for(var/datum/gas/trace_gas in trace_gases) + + var/datum/gas/corresponding = locate(trace_gas.type) in sharer.trace_gases + var/delta = 0 + + if(corresponding) + delta = QUANTIZE(trace_gas.moles_archived - corresponding.moles_archived)/(atmos_adjacent_turfs+1) + else + corresponding = new trace_gas.type() + sharer.trace_gases += corresponding + + delta = trace_gas.moles_archived/(atmos_adjacent_turfs+1) + + trace_gas.moles -= delta + corresponding.moles += delta + + if(delta) + var/individual_heat_capacity = trace_gas.specific_heat*delta + if(delta > 0) + heat_capacity_self_to_sharer += individual_heat_capacity + else + heat_capacity_sharer_to_self -= individual_heat_capacity + + moved_moles += delta + last_share += abs(delta) + + trace_types_considered += trace_gas.type + + + if(sharer.trace_gases.len) + for(var/datum/gas/trace_gas in sharer.trace_gases) + if(trace_gas.type in trace_types_considered) continue + else + var/datum/gas/corresponding + var/delta = 0 + + corresponding = new trace_gas.type() + trace_gases += corresponding + + delta = trace_gas.moles_archived/5 + + trace_gas.moles -= delta + corresponding.moles += delta + + //Guaranteed transfer from sharer to self + var/individual_heat_capacity = trace_gas.specific_heat*delta + heat_capacity_sharer_to_self += individual_heat_capacity + + moved_moles += -delta + last_share += abs(delta) + + if(abs(delta_temperature) > MINIMUM_TEMPERATURE_DELTA_TO_CONSIDER) + var/new_self_heat_capacity = old_self_heat_capacity + heat_capacity_sharer_to_self - heat_capacity_self_to_sharer + var/new_sharer_heat_capacity = old_sharer_heat_capacity + heat_capacity_self_to_sharer - heat_capacity_sharer_to_self + + if(new_self_heat_capacity > MINIMUM_HEAT_CAPACITY) + temperature = (old_self_heat_capacity*temperature - heat_capacity_self_to_sharer*temperature_archived + heat_capacity_sharer_to_self*sharer.temperature_archived)/new_self_heat_capacity + + if(new_sharer_heat_capacity > MINIMUM_HEAT_CAPACITY) + sharer.temperature = (old_sharer_heat_capacity*sharer.temperature-heat_capacity_sharer_to_self*sharer.temperature_archived + heat_capacity_self_to_sharer*temperature_archived)/new_sharer_heat_capacity + + if(abs(old_sharer_heat_capacity) > MINIMUM_HEAT_CAPACITY) + if(abs(new_sharer_heat_capacity/old_sharer_heat_capacity - 1) < 0.10) // <10% change in sharer heat capacity + temperature_share(sharer, OPEN_HEAT_TRANSFER_COEFFICIENT) + + if((delta_temperature > MINIMUM_TEMPERATURE_TO_MOVE) || abs(moved_moles) > MINIMUM_MOLES_DELTA_TO_MOVE) + var/delta_pressure = temperature_archived*(total_moles() + moved_moles) - sharer.temperature_archived*(sharer.total_moles() - moved_moles) + return delta_pressure*R_IDEAL_GAS_EQUATION/volume + /datum/gas_mixture/mimic(turf/model, border_multiplier, atmos_adjacent_turfs = 4) var/delta_oxygen = QUANTIZE(oxygen_archived - model.oxygen)/(atmos_adjacent_turfs+1) var/delta_carbon_dioxide = QUANTIZE(carbon_dioxide_archived - model.carbon_dioxide)/(atmos_adjacent_turfs+1)