Skip to content

Commit

Permalink
HFR: Better observation of delta_time (#56009)
Browse files Browse the repository at this point in the history
This changes HFR's fusion_process() to better observe delta_time.
  • Loading branch information
esainane committed Jan 12, 2021
1 parent 3add7d5 commit 727c5cf
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions code/modules/atmospherics/machinery/components/fusion/hypertorus.dm
Expand Up @@ -928,7 +928,8 @@
var/datum/gas_mixture/internal_output = new
//gas consumption and production
if(check_fuel())
var/fuel_consumption = clamp((fuel_injection_rate * 0.001) * 5 * power_level, 0.05, 30) * delta_time
var/fuel_consumption_rate = clamp((fuel_injection_rate * 0.001) * 5 * power_level, 0.05, 30)
var/fuel_consumption = fuel_consumption_rate * delta_time
internal_fusion.gases[/datum/gas/tritium][MOLES] -= min(tritium, fuel_consumption * 0.85)
internal_fusion.gases[/datum/gas/hydrogen][MOLES] -= min(hydrogen, fuel_consumption * 0.95)
internal_fusion.gases[/datum/gas/helium][MOLES] += fuel_consumption * 0.5
Expand All @@ -937,7 +938,7 @@
if(power_output)
switch(power_level)
if(1)
var/scaled_production = clamp(heat_output * 1e-2, 0, fuel_consumption) * delta_time
var/scaled_production = clamp(heat_output * 1e-2, 0, fuel_consumption_rate) * delta_time
moderator_internal.gases[/datum/gas/carbon_dioxide][MOLES] += scaled_production * 0.95
moderator_internal.gases[/datum/gas/water_vapor][MOLES] += scaled_production *0.75
if(m_plasma > 100)
Expand All @@ -950,7 +951,7 @@
internal_output.gases[/datum/gas/proto_nitrate][MOLES] += scaled_production * 0.25
moderator_internal.gases[/datum/gas/bz][MOLES] -= min(moderator_internal.gases[/datum/gas/bz][MOLES], scaled_production * 0.95)
if(2)
var/scaled_production = clamp(heat_output * 1e-3, 0, fuel_consumption) * delta_time
var/scaled_production = clamp(heat_output * 1e-3, 0, fuel_consumption_rate) * delta_time
moderator_internal.gases[/datum/gas/carbon_dioxide][MOLES] += scaled_production * 1.65
moderator_internal.gases[/datum/gas/water_vapor][MOLES] += scaled_production
if(m_plasma > 50)
Expand All @@ -971,7 +972,7 @@
moderator_internal.gases[/datum/gas/halon] += scaled_production * 1.35
moderator_internal.gases[/datum/gas/nitrous_oxide][MOLES] -= min(moderator_internal.gases[/datum/gas/nitrous_oxide][MOLES], scaled_production * 1.5)
if(3, 4)
var/scaled_production = clamp(heat_output * 5e-4, 0, fuel_consumption) * delta_time
var/scaled_production = clamp(heat_output * 5e-4, 0, fuel_consumption_rate) * delta_time
if(power_level == 3)
moderator_internal.gases[/datum/gas/oxygen][MOLES] += scaled_production * 0.5
moderator_internal.gases[/datum/gas/nitrogen][MOLES] += scaled_production * 0.45
Expand Down Expand Up @@ -1004,7 +1005,7 @@
l.hallucination += power_level * 50 * D * delta_time
l.hallucination = clamp(l.hallucination, 0, 200)
if(5)
var/scaled_production = clamp(heat_output * 1e-6, 0, fuel_consumption) * delta_time
var/scaled_production = clamp(heat_output * 1e-6, 0, fuel_consumption_rate) * delta_time
moderator_internal.gases[/datum/gas/nitryl][MOLES] += scaled_production * 1.65
moderator_internal.gases[/datum/gas/water_vapor][MOLES] += scaled_production
if(m_plasma > 15)
Expand Down Expand Up @@ -1034,13 +1035,13 @@
moderator_internal.gases[/datum/gas/freon][MOLES] += scaled_production * 1.15
if(m_healium > 100)
if(critical_threshold_proximity > 400)
critical_threshold_proximity = max(critical_threshold_proximity - (m_healium / 100), 0)
critical_threshold_proximity = max(critical_threshold_proximity - (m_healium / 100 * delta_time ), 0)
moderator_internal.gases[/datum/gas/healium][MOLES] -= min(moderator_internal.gases[/datum/gas/healium][MOLES], scaled_production * 20)
if(moderator_internal.temperature < 1e7 || (m_plasma > 100 && m_bz > 50))
internal_output.assert_gases(/datum/gas/antinoblium)
internal_output.gases[/datum/gas/antinoblium][MOLES] += 0.1 * (scaled_helium / (fuel_injection_rate * 0.0065))
internal_output.gases[/datum/gas/antinoblium][MOLES] += 0.1 * (scaled_helium / (fuel_injection_rate * 0.0065)) * delta_time
if(6)
var/scaled_production = clamp(heat_output * 1e-7, 0, fuel_consumption) * delta_time
var/scaled_production = clamp(heat_output * 1e-7, 0, fuel_consumption_rate) * delta_time
if(m_plasma > 30)
moderator_internal.gases[/datum/gas/bz][MOLES] += scaled_production * 1.15
moderator_internal.gases[/datum/gas/plasma][MOLES] -= min(moderator_internal.gases[/datum/gas/plasma][MOLES], scaled_production * 1.45)
Expand All @@ -1053,14 +1054,15 @@
heat_output *= 2.25
if(m_bz)
for(var/mob/living/carbon/human/human in view(src, HALLUCINATION_RANGE(heat_output)))
//mesons won't protect you at fusion level 6
var/distance_root = sqrt(1 / max(1, get_dist(human, src)))
human.hallucination += power_level * 150 * distance_root
human.hallucination = clamp(human.hallucination, 0, 200)
moderator_internal.gases[/datum/gas/antinoblium][MOLES] += clamp((scaled_helium / (fuel_injection_rate * 0.0045)), 0, 10) * delta_time
if(m_healium > 100)
if(critical_threshold_proximity > 400)
critical_threshold_proximity = max(critical_threshold_proximity - (m_healium / 100), 0)
moderator_internal.gases[/datum/gas/healium][MOLES] -= min(moderator_internal.gases[/datum/gas/healium][MOLES], scaled_production * 20) * delta_time
critical_threshold_proximity = max(critical_threshold_proximity - (m_healium / 100 * delta_time ), 0)
moderator_internal.gases[/datum/gas/healium][MOLES] -= min(moderator_internal.gases[/datum/gas/healium][MOLES], scaled_production * 20)
internal_fusion.gases[/datum/gas/antinoblium][MOLES] += 0.01 * (scaled_helium / (fuel_injection_rate * 0.0095)) * delta_time

//heat up and output what's in the internal_output into the linked_output port
Expand All @@ -1073,7 +1075,7 @@

//High power fusion might create other matter other than helium, iron is dangerous inside the machine, damage can be seen
if(moderator_internal.total_moles() > 0)
moderator_internal.remove(moderator_internal.total_moles() * 0.0005 * power_level)
moderator_internal.remove(moderator_internal.total_moles() * (1 - (1 - 0.0005 * power_level) ** delta_time))
if(power_level > 4 && prob(17 * power_level))//at power level 6 is 100%
iron_content += 0.005 * delta_time
if(iron_content > 0 && power_level <= 4 && prob(25 / (power_level + 1)))
Expand All @@ -1088,16 +1090,16 @@
else
filtering = FALSE
if(filtering && moderator_internal.gases[filter_type])
var/datum/gas_mixture/removed = moderator_internal.remove_specific(filter_type, 20)
var/datum/gas_mixture/removed = moderator_internal.remove_specific(filter_type, 20 * delta_time)
if(removed)
linked_output.airs[1].merge(removed)

var/datum/gas_mixture/internal_remove
if(internal_fusion.gases[/datum/gas/helium][MOLES] > 0)
internal_remove = internal_fusion.remove_specific(/datum/gas/helium, internal_fusion.gases[/datum/gas/helium][MOLES] * 0.5)
internal_remove = internal_fusion.remove_specific(/datum/gas/helium, internal_fusion.gases[/datum/gas/helium][MOLES] * (1 - (1 - 0.5) ** delta_time))
linked_output.airs[1].merge(internal_remove)
if(internal_fusion.gases[/datum/gas/antinoblium][MOLES] > 0)
internal_remove = internal_fusion.remove_specific(/datum/gas/antinoblium, internal_fusion.gases[/datum/gas/antinoblium][MOLES] * 0.05)
internal_remove = internal_fusion.remove_specific(/datum/gas/antinoblium, internal_fusion.gases[/datum/gas/antinoblium][MOLES] * (1 - (1 - 0.05) ** delta_time))
linked_output.airs[1].merge(internal_remove)
internal_fusion.garbage_collect()
moderator_internal.garbage_collect()
Expand Down

0 comments on commit 727c5cf

Please sign in to comment.