Fixing the main holder reaction loop - fermi is it's own proc

This commit is contained in:
Fermi
2019-04-22 20:08:19 +01:00
parent 5657fd8cde
commit 744b1328e8
4 changed files with 299 additions and 285 deletions
@@ -1,4 +1,3 @@
/proc/build_chemical_reagent_list()
//Chemical Reagents - Initialises all /datum/reagent into a list indexed by reagent id
@@ -368,7 +367,25 @@
var/meets_temp_requirement = 0
var/has_special_react = C.special_react
var/can_special_react = 0
var/reactedVol = 0
//FermiChem WHY ARE VARIBLES SO ESTRANGED it makes me sad
/*
var/OptimalTempMin = C.OptimalTempMin // Lower area of bell curve for determining heat based rate reactions
var/OptimalTempMax = C.OptimalTempMax
var/ExplodeTemp = C.ExplodeTemp
var/OptimalpHMin = C.OptimalpHMin
var/OptimalpHMax = C.OptimalpHMax
var/ReactpHLim = C.ReactpHLim
//var/CatalystFact = C.CatalystFact
var/CurveSharpT = C.CurveSharpT
var/CurveSharppH = C.CurveSharppH
var/ThermicConstant = C.ThermicConstant
var/HIonRelease = C.HIonRelease
var/RateUpLim = C.RateUpLim
var/FermiChem = C.FermiChem
var/FermiExplode = C.FermiExplode
var/ImpureChem = C.ImpureChem
*/
//FermiChem
for(var/B in cached_required_reagents)
if(!has_reagent(B, cached_required_reagents[B]))
@@ -402,14 +419,12 @@
matching_other = 1
//FermiChem
/*
if (chem_temp > C.ExplodeTemp)//Check to see if reaction is too hot!
if (C.FermiExplode == TRUE)
//To be added!
else
FermiExplode()
//explode function!!
*/
if(required_temp == 0 || (is_cold_recipe && chem_temp <= required_temp) || (!is_cold_recipe && chem_temp >= required_temp))//Temperature check!!
meets_temp_requirement = 1//binary pass
@@ -442,21 +457,110 @@
//Splits reactions into two types; FermiChem is advanced reaction mechanics, Other is default reaction.
//FermiChem relies on two additional properties; pH and impurity
//Temperature plays into a larger role too.
//BRANCH HERE
//if(selected_reaction)
var/datum/chemical_reaction/C = selected_reaction
if (C.FermiChem == TRUE)
message_admins("FermiChem Proc'd")
//FermiReact(C)
//B is Beaker
//P is product
//multiplier = min(multiplier, round(get_reagent_amount(B) / cached_required_reagents[B]))//a simple one over the other? (Is this for multiplying end product? Useful for toxinsludge buildup)
var/deltaT = 0
var/deltapH = 0
var/stepChemAmmount = 0
var/ammoReacted = 0
//get purity from combined beaker reactant purities.
var/purity = 1
while (reactedVol < multiplier)
reactedVol = FermiReact(selected_reaction, chem_temp, pH, multiplier, reactedVol, special_react_result, cached_required_reagents, cached_results, selected_reaction.results)
while (ammoReacted < multiplier)
message_admins("Loop beginning")
CHECK_TICK
reaction_occurred = 1
SSblackbox.record_feedback("tally", "Fermi_chemical_reaction", reactedVol, C.id)//log
//Begin Parse
//Standard reaction mechanics:
else
//Check extremes first
if (chem_temp > C.ExplodeTemp)
//go to explode proc
message_admins("temperature is over limit: [C.ExplodeTemp] Current temperature: [chem_temp]")
FermiExplode()
if (pH > 14 || pH < 0)
//Create chemical sludge eventually(for now just destroy the beaker I guess?)
//TODO Strong acids eat glass, make it so you NEED plastic beakers for superacids(for some reactions)
message_admins("pH is lover limit, cur pH: [pH]")
FermiExplode()
//For now, purity is handled elsewhere
//Calculate DeltaT (Deviation of T from optimal)
if (chem_temp < C.OptimalTempMax || chem_temp >= C.OptimalTempMin)
deltaT = (((C.OptimalTempMin - chem_temp)**C.CurveSharpT)/((C.OptimalTempMax - C.OptimalTempMin)**C.CurveSharpT))
// 350 300
else if (chem_temp >= C.OptimalTempMax)
deltaT = 1
else
deltaT = 0
message_admins("calculating temperature factor, min: [C.OptimalTempMin], max: [C.OptimalTempMax], Exponential: [C.CurveSharpT], deltaT: [deltaT]")
//Calculate DeltapH (Deviation of pH from optimal)
//Lower range
if (pH < C.OptimalpHMin)
if (pH < (C.OptimalpHMin - C.ReactpHLim))
deltapH = 0
else
deltapH = (((pH - (C.OptimalpHMin - C.ReactpHLim))**C.CurveSharppH)/(C.ReactpHLim**C.CurveSharppH))
//Upper range
else if (pH > C.OptimalpHMin)
if (pH > (C.OptimalpHMin + C.ReactpHLim))
deltapH = 0
else
deltapH = ((C.ReactpHLim -(pH - (C.OptimalpHMax + C.ReactpHLim))+C.ReactpHLim)/(C.ReactpHLim**C.CurveSharppH))
//Within mid range
else if (pH >= C.OptimalpHMin && pH <= C.OptimalpHMax)
deltapH = 1
//This should never proc:
else
message_admins("Fermichem's pH broke!! Please let Fermis know!!")
WARNING("[my_atom] attempted to determine FermiChem pH for '[C.id]' which broke for some reason! ([usr])")
//TODO Add CatalystFact
message_admins("calculating pH factor(purity), pH: [pH], min: [C.OptimalpHMin]-[C.ReactpHLim], max: [C.OptimalpHMax]+[C.ReactpHLim], deltapH: [deltapH]")
stepChemAmmount = multiplier * deltaT
if (stepChemAmmount > C.RateUpLim)
stepChemAmmount = C.RateUpLim
else if (stepChemAmmount < 0.01)
stepChemAmmount = 0.1
if (ammoReacted > 0)
purity = ((purity * ammoReacted) + (deltapH * stepChemAmmount)) /((ammoReacted + stepChemAmmount)) //This should add the purity to the product
else
purity = deltapH
message_admins("purity: [purity], purity of beaker")
message_admins("Temp before change: [chem_temp], pH after change: [pH]")
//Apply pH changes and thermal output of reaction to beaker
chem_temp += (C.ThermicConstant * stepChemAmmount)
pH += (C.HIonRelease * stepChemAmmount)
message_admins("Temp after change: [chem_temp], pH after change: [pH]")
// End.
selected_reaction.on_reaction(src, multiplier, special_react_result)
message_admins("cached_results: [cached_results], multiplier: [multiplier], stepChemAmmount [stepChemAmmount]")
for(var/B in cached_required_reagents)
message_admins("cached_results: [cached_results], multiplier: [multiplier], stepChemAmmount [stepChemAmmount]")
remove_reagent(B, (stepChemAmmount * cached_required_reagents[B]), safety = 1)//safety? removes reagents from beaker using remove function.
for(var/P in selected_reaction.results)//Not sure how this works, what is selected_reaction.results?
multiplier = max(multiplier, 1) //this shouldnt happen ...
SSblackbox.record_feedback("tally", "chemical_reaction", cached_results[P]*stepChemAmmount, P)//log
add_reagent(P, cached_results[P]*stepChemAmmount, null, chem_temp)//add reagent function!! I THINK I can do this:
ammoReacted = ammoReacted + stepChemAmmount
CHECK_TICK
reaction_occurred = 1
SSblackbox.record_feedback("tally", "Fermi_chemical_reaction", ammoReacted, C.id)//log
//Standard reaction mechanics:
else:
for(var/B in cached_required_reagents) //
multiplier = min(multiplier, round(get_reagent_amount(B) / cached_required_reagents[B]))//a simple one over the other? (Is this for multiplying end product? Useful for toxinsludge buildup)
@@ -470,129 +574,34 @@
add_reagent(P, cached_results[P]*multiplier, null, chem_temp)//add reagent function!! I THINK I can do this:
var/list/seen = viewers(4, get_turf(my_atom))//Sound and sight checkers
var/iconhtml = icon2html(cached_my_atom, seen)
if(cached_my_atom)
if(!ismob(cached_my_atom)) // No bubbling mobs
if(selected_reaction.mix_sound)
playsound(get_turf(cached_my_atom), selected_reaction.mix_sound, 80, 1)
var/list/seen = viewers(4, get_turf(my_atom))//Sound and sight checkers
var/iconhtml = icon2html(cached_my_atom, seen)
if(cached_my_atom)
if(!ismob(cached_my_atom)) // No bubbling mobs
if(selected_reaction.mix_sound)
playsound(get_turf(cached_my_atom), selected_reaction.mix_sound, 80, 1)
for(var/mob/M in seen)
to_chat(M, "<span class='notice'>[iconhtml] [selected_reaction.mix_message]</span>")
if(istype(cached_my_atom, /obj/item/slime_extract))//if there's an extract and it's used up.
var/obj/item/slime_extract/ME2 = my_atom
ME2.Uses--
if(ME2.Uses <= 0) // give the notification that the slime core is dead
for(var/mob/M in seen)
to_chat(M, "<span class='notice'>[iconhtml] [selected_reaction.mix_message]</span>")
to_chat(M, "<span class='notice'>[iconhtml] \The [my_atom]'s power is consumed in the reaction.</span>")
ME2.name = "used slime extract"
ME2.desc = "This extract has been used up."
if(istype(cached_my_atom, /obj/item/slime_extract))//if there's an extract and it's used up.
var/obj/item/slime_extract/ME2 = my_atom
ME2.Uses--
if(ME2.Uses <= 0) // give the notification that the slime core is dead
for(var/mob/M in seen)
to_chat(M, "<span class='notice'>[iconhtml] \The [my_atom]'s power is consumed in the reaction.</span>")
ME2.name = "used slime extract"
ME2.desc = "This extract has been used up."
selected_reaction.on_reaction(src, multiplier, special_react_result)
reaction_occurred = 1
selected_reaction.on_reaction(src, multiplier, special_react_result)
reaction_occurred = 1
while(reaction_occurred)//while do nothing?
update_total()//Don't know waht this does.
return 0//end!
/datum/reagents/proc/FermiReact(selected_reaction, chem_temp, pH, multiplier, totalVol, special_react_result, cached_required_reagents, cached_results, selected_reaction.results)
var/datum/chemical_reaction/C = selected_reaction
var/deltaT = 0
var/deltapH = 0
var/stepChemAmmount = 0
var/ammoReacted = 0
//get purity from combined beaker reactant purities HERE.
var/purity = 1
var/tempVol = totalVol
//var/list/multiplier = INFINITY
message_admins("Loop beginning")
//Begin Parse
//Check extremes first
if (chem_temp > C.ExplodeTemp)
//go to explode proc
message_admins("temperature is over limit: [C.ExplodeTemp] Current temperature: [chem_temp]")
FermiExplode()
if (pH > 14 || pH < 0)
//Create chemical sludge eventually(for now just destroy the beaker I guess?)
//TODO Strong acids eat glass, make it so you NEED plastic beakers for superacids(for some reactions)
message_admins("pH is lover limit, cur pH: [pH]")
FermiExplode()
//For now, purity is handled elsewhere
//Calculate DeltaT (Deviation of T from optimal)
if (chem_temp < C.OptimalTempMax && chem_temp >= C.OptimalTempMin)
deltaT = (((C.OptimalTempMin - chem_temp)**C.CurveSharpT)/((C.OptimalTempMax - C.OptimalTempMin)**C.CurveSharpT))
else if (chem_temp >= C.OptimalTempMax)
deltaT = 1
else
deltaT = 0
message_admins("calculating temperature factor, min: [C.OptimalTempMin], max: [C.OptimalTempMax], Exponential: [C.CurveSharpT], deltaT: [deltaT]")
//Calculate DeltapH (Deviation of pH from optimal)
//Lower range
if (pH < C.OptimalpHMin)
if (pH < (C.OptimalpHMin - C.ReactpHLim))
deltapH = 0
else
deltapH = (((pH - (C.OptimalpHMin - C.ReactpHLim))**C.CurveSharppH)/(C.ReactpHLim**C.CurveSharppH))
//Upper range
else if (pH > C.OptimalpHMin)
if (pH > (C.OptimalpHMin + C.ReactpHLim))
deltapH = 0
else
deltapH = ((C.ReactpHLim -(pH - (C.OptimalpHMax + C.ReactpHLim))+C.ReactpHLim)/(C.ReactpHLim**C.CurveSharppH))
//Within mid range
else if (pH >= C.OptimalpHMin && pH <= C.OptimalpHMax)
deltapH = 1
//This should never proc:
else
message_admins("Fermichem's pH broke!! Please let Fermis know!!")
WARNING("[my_atom] attempted to determine FermiChem pH for '[C.id]' which broke for some reason! ([usr])")
//TODO Add CatalystFact
message_admins("calculating pH factor(purity), pH: [pH], min: [C.OptimalpHMin]-[C.ReactpHLim], max: [C.OptimalpHMax]+[C.ReactpHLim], deltapH: [deltapH]")
stepChemAmmount = tempVol * deltaT
if (stepChemAmmount > C.RateUpLim)
stepChemAmmount = C.RateUpLim
else if (stepChemAmmount < 0.01)
stepChemAmmount = 0.01
if (totalVol > 0)
purity = ((purity * ammoReacted) + (deltapH * stepChemAmmount)) /((ammoReacted + stepChemAmmount)) //This should add the purity to the product
else
purity = deltapH
message_admins("purity: [purity], purity of beaker")
message_admins("Temp before change: [chem_temp], pH after change: [pH]")
//Apply pH changes and thermal output of reaction to beaker
chem_temp += (C.ThermicConstant * stepChemAmmount)
pH += (C.HIonRelease * stepChemAmmount)
message_admins("Temp after change: [chem_temp], pH after change: [pH]")
// End.
/*
for(var/B in cached_required_reagents) //
tempVol = min(totalVol, round(get_reagent_amount(B) / cached_required_reagents[B]))//a simple one over the other? (Is this for multiplying end product? Useful for toxinsludge buildup)
*/
message_admins("cached_results: [cached_results], totalVol: [totalVol], stepChemAmmount [stepChemAmmount]")
for(var/B in cached_required_reagents)
message_admins("cached_required_reagents(B): [cached_required_reagents[B]], totalVol: [totalVol], base stepChemAmmount [stepChemAmmount]")
remove_reagent(B, (stepChemAmmount * cached_required_reagents[B]), safety = 1)//safety? removes reagents from beaker using remove function.
for(var/P in selected_reaction.results)//Not sure how this works, what is selected_reaction.results?
totalVol = max(totalVol, 1) //this shouldnt happen ...
SSblackbox.record_feedback("tally", "chemical_reaction", cached_results[P]*stepChemAmmount, P)//log
add_reagent(P, cached_results[P]*stepChemAmmount, null, chem_temp)//add reagent function!! I THINK I can do this:
totalVol = totalVol + stepChemAmmount
CHECK_TICK
return (totalVol)
/datum/reagents/proc/FermiReact()
return
/datum/reagents/proc/FermiExplode()
return
@@ -955,4 +964,4 @@
if(initial(R.can_synth))
random_reagents += initial(R.id)
var/picked_reagent = pick(random_reagents)
return picked_reagent
return picked_reagent
+143 -140
View File
@@ -1,3 +1,4 @@
/proc/build_chemical_reagent_list()
//Chemical Reagents - Initialises all /datum/reagent into a list indexed by reagent id
@@ -367,25 +368,8 @@
var/meets_temp_requirement = 0
var/has_special_react = C.special_react
var/can_special_react = 0
//FermiChem WHY ARE VARIBLES SO ESTRANGED it makes me sad
/*
var/OptimalTempMin = C.OptimalTempMin // Lower area of bell curve for determining heat based rate reactions
var/OptimalTempMax = C.OptimalTempMax
var/ExplodeTemp = C.ExplodeTemp
var/OptimalpHMin = C.OptimalpHMin
var/OptimalpHMax = C.OptimalpHMax
var/ReactpHLim = C.ReactpHLim
//var/CatalystFact = C.CatalystFact
var/CurveSharpT = C.CurveSharpT
var/CurveSharppH = C.CurveSharppH
var/ThermicConstant = C.ThermicConstant
var/HIonRelease = C.HIonRelease
var/RateUpLim = C.RateUpLim
var/FermiChem = C.FermiChem
var/FermiExplode = C.FermiExplode
var/ImpureChem = C.ImpureChem
*/
//FermiChem
var/reactedVol = 0
va/continue_reacting = FALSE
for(var/B in cached_required_reagents)
if(!has_reagent(B, cached_required_reagents[B]))
@@ -419,12 +403,14 @@
matching_other = 1
//FermiChem
/*
if (chem_temp > C.ExplodeTemp)//Check to see if reaction is too hot!
if (C.FermiExplode == TRUE)
//To be added!
else
FermiExplode()
//explode function!!
*/
if(required_temp == 0 || (is_cold_recipe && chem_temp <= required_temp) || (!is_cold_recipe && chem_temp >= required_temp))//Temperature check!!
meets_temp_requirement = 1//binary pass
@@ -457,110 +443,25 @@
//Splits reactions into two types; FermiChem is advanced reaction mechanics, Other is default reaction.
//FermiChem relies on two additional properties; pH and impurity
//Temperature plays into a larger role too.
//BRANCH HERE
//if(selected_reaction)
var/datum/chemical_reaction/C = selected_reaction
if (C.FermiChem == TRUE)
//FermiReact(C)
//B is Beaker
//P is product
//multiplier = min(multiplier, round(get_reagent_amount(B) / cached_required_reagents[B]))//a simple one over the other? (Is this for multiplying end product? Useful for toxinsludge buildup)
var/deltaT = 0
var/deltapH = 0
var/stepChemAmmount = 0
var/ammoReacted = 0
//get purity from combined beaker reactant purities.
var/purity = 1
while (ammoReacted < multiplier)
message_admins("Loop beginning")
CHECK_TICK
//Begin Parse
//Check extremes first
if (chem_temp > C.ExplodeTemp)
//go to explode proc
message_admins("temperature is over limit: [C.ExplodeTemp] Current temperature: [chem_temp]")
FermiExplode()
if (pH > 14 || pH < 0)
//Create chemical sludge eventually(for now just destroy the beaker I guess?)
//TODO Strong acids eat glass, make it so you NEED plastic beakers for superacids(for some reactions)
message_admins("pH is lover limit, cur pH: [pH]")
FermiExplode()
//For now, purity is handled elsewhere
//Calculate DeltaT (Deviation of T from optimal)
if (chem_temp < C.OptimalTempMax || chem_temp >= C.OptimalTempMin)
deltaT = (((C.OptimalTempMin - chem_temp)**C.CurveSharpT)/((C.OptimalTempMax - C.OptimalTempMin)**C.CurveSharpT))
// 350 300
else if (chem_temp >= C.OptimalTempMax)
deltaT = 1
else
deltaT = 0
message_admins("calculating temperature factor, min: [C.OptimalTempMin], max: [C.OptimalTempMax], Exponential: [C.CurveSharpT], deltaT: [deltaT]")
//Calculate DeltapH (Deviation of pH from optimal)
//Lower range
if (pH < C.OptimalpHMin)
if (pH < (C.OptimalpHMin - C.ReactpHLim))
deltapH = 0
else
deltapH = (((pH - (C.OptimalpHMin - C.ReactpHLim))**C.CurveSharppH)/(C.ReactpHLim**C.CurveSharppH))
//Upper range
else if (pH > C.OptimalpHMin)
if (pH > (C.OptimalpHMin + C.ReactpHLim))
deltapH = 0
else
deltapH = ((C.ReactpHLim -(pH - (C.OptimalpHMax + C.ReactpHLim))+C.ReactpHLim)/(C.ReactpHLim**C.CurveSharppH))
//Within mid range
else if (pH >= C.OptimalpHMin && pH <= C.OptimalpHMax)
deltapH = 1
//This should never proc:
else
message_admins("Fermichem's pH broke!! Please let Fermis know!!")
WARNING("[my_atom] attempted to determine FermiChem pH for '[C.id]' which broke for some reason! ([usr])")
//TODO Add CatalystFact
message_admins("calculating pH factor(purity), pH: [pH], min: [C.OptimalpHMin]-[C.ReactpHLim], max: [C.OptimalpHMax]+[C.ReactpHLim], deltapH: [deltapH]")
stepChemAmmount = multiplier * deltaT
if (stepChemAmmount > C.RateUpLim)
stepChemAmmount = C.RateUpLim
else if (stepChemAmmount < 0.01)
stepChemAmmount = 0.1
if (ammoReacted > 0)
purity = ((purity * ammoReacted) + (deltapH * stepChemAmmount)) /((ammoReacted + stepChemAmmount)) //This should add the purity to the product
else
purity = deltapH
message_admins("purity: [purity], purity of beaker")
message_admins("Temp before change: [chem_temp], pH after change: [pH]")
//Apply pH changes and thermal output of reaction to beaker
chem_temp += (C.ThermicConstant * stepChemAmmount)
pH += (C.HIonRelease * stepChemAmmount)
message_admins("Temp after change: [chem_temp], pH after change: [pH]")
// End.
selected_reaction.on_reaction(src, multiplier, special_react_result)
message_admins("cached_results: [cached_results], multiplier: [multiplier], stepChemAmmount [stepChemAmmount]")
for(var/B in cached_required_reagents)
message_admins("cached_results: [cached_results], multiplier: [multiplier], stepChemAmmount [stepChemAmmount]")
remove_reagent(B, (stepChemAmmount * cached_required_reagents[B]), safety = 1)//safety? removes reagents from beaker using remove function.
for(var/P in selected_reaction.results)//Not sure how this works, what is selected_reaction.results?
multiplier = max(multiplier, 1) //this shouldnt happen ...
SSblackbox.record_feedback("tally", "chemical_reaction", cached_results[P]*stepChemAmmount, P)//log
add_reagent(P, cached_results[P]*stepChemAmmount, null, chem_temp)//add reagent function!! I THINK I can do this:
ammoReacted = ammoReacted + stepChemAmmount
CHECK_TICK
if (C.FermiChem == TRUE && !continue_reacting == TRUE)
message_admins("FermiChem Proc'd")
reaction_occurred = 1
SSblackbox.record_feedback("tally", "Fermi_chemical_reaction", ammoReacted, C.id)//log
//Standard reaction mechanics:
else:
for(var/P in selected_reaction.results)
var/targetVol = cached_results[P]*multiplier
while (reactedVol < targetVol)
reactedVol = FermiReact(selected_reaction, chem_temp, pH, multiplier, reactedVol, targetVol cached_required_reagents, cached_results)
SSblackbox.record_feedback("tally", "Fermi_chemical_reaction", reactedVol, C.id)//log
//Standard reaction mechanics:
else
for(var/B in cached_required_reagents) //
multiplier = min(multiplier, round(get_reagent_amount(B) / cached_required_reagents[B]))//a simple one over the other? (Is this for multiplying end product? Useful for toxinsludge buildup)
@@ -574,34 +475,136 @@
add_reagent(P, cached_results[P]*multiplier, null, chem_temp)//add reagent function!! I THINK I can do this:
var/list/seen = viewers(4, get_turf(my_atom))//Sound and sight checkers
var/iconhtml = icon2html(cached_my_atom, seen)
if(cached_my_atom)
if(!ismob(cached_my_atom)) // No bubbling mobs
if(selected_reaction.mix_sound)
playsound(get_turf(cached_my_atom), selected_reaction.mix_sound, 80, 1)
var/list/seen = viewers(4, get_turf(my_atom))//Sound and sight checkers
var/iconhtml = icon2html(cached_my_atom, seen)
if(cached_my_atom)
if(!ismob(cached_my_atom)) // No bubbling mobs
if(selected_reaction.mix_sound)
playsound(get_turf(cached_my_atom), selected_reaction.mix_sound, 80, 1)
for(var/mob/M in seen)
to_chat(M, "<span class='notice'>[iconhtml] [selected_reaction.mix_message]</span>")
if(istype(cached_my_atom, /obj/item/slime_extract))//if there's an extract and it's used up.
var/obj/item/slime_extract/ME2 = my_atom
ME2.Uses--
if(ME2.Uses <= 0) // give the notification that the slime core is dead
for(var/mob/M in seen)
to_chat(M, "<span class='notice'>[iconhtml] \The [my_atom]'s power is consumed in the reaction.</span>")
ME2.name = "used slime extract"
ME2.desc = "This extract has been used up."
to_chat(M, "<span class='notice'>[iconhtml] [selected_reaction.mix_message]</span>")
selected_reaction.on_reaction(src, multiplier, special_react_result)
reaction_occurred = 1
if(istype(cached_my_atom, /obj/item/slime_extract))//if there's an extract and it's used up.
var/obj/item/slime_extract/ME2 = my_atom
ME2.Uses--
if(ME2.Uses <= 0) // give the notification that the slime core is dead
for(var/mob/M in seen)
to_chat(M, "<span class='notice'>[iconhtml] \The [my_atom]'s power is consumed in the reaction.</span>")
ME2.name = "used slime extract"
ME2.desc = "This extract has been used up."
selected_reaction.on_reaction(src, multiplier, special_react_result)
reaction_occurred = 1
continue_reacting = TRUE
while(reaction_occurred)//while do nothing?
update_total()//Don't know waht this does.
return 0//end!
/datum/reagents/proc/FermiReact()
return
/datum/reagents/proc/FermiReact(selected_reaction, chem_temp, pH, multiplier, reactedVol, targetVol, cached_required_reagents, cached_results)
var/datum/chemical_reaction/C = selected_reaction
var/deltaT = 0
var/deltapH = 0
var/stepChemAmmount = 0
var/ammoReacted = 0
//get purity from combined beaker reactant purities HERE.
var/purity = 1
var/tempVol = totalVol
//var/list/multiplier = INFINITY
message_admins("Loop beginning")
//Begin Parse
//Check extremes first
if (chem_temp > C.ExplodeTemp)
//go to explode proc
message_admins("temperature is over limit: [C.ExplodeTemp] Current temperature: [chem_temp]")
FermiExplode()
if (pH > 14 || pH < 0)
//Create chemical sludge eventually(for now just destroy the beaker I guess?)
//TODO Strong acids eat glass, make it so you NEED plastic beakers for superacids(for some reactions)
message_admins("pH is lover limit, cur pH: [pH]")
FermiExplode()
//For now, purity is handled elsewhere
//Calculate DeltaT (Deviation of T from optimal)
if (chem_temp < C.OptimalTempMax && chem_temp >= C.OptimalTempMin)
deltaT = (((C.OptimalTempMin - chem_temp)**C.CurveSharpT)/((C.OptimalTempMax - C.OptimalTempMin)**C.CurveSharpT))
else if (chem_temp >= C.OptimalTempMax)
deltaT = 1
else
deltaT = 0
message_admins("calculating temperature factor, min: [C.OptimalTempMin], max: [C.OptimalTempMax], Exponential: [C.CurveSharpT], deltaT: [deltaT]")
//Calculate DeltapH (Deviation of pH from optimal)
//Lower range
if (pH < C.OptimalpHMin)
if (pH < (C.OptimalpHMin - C.ReactpHLim))
deltapH = 0
else
deltapH = (((pH - (C.OptimalpHMin - C.ReactpHLim))**C.CurveSharppH)/(C.ReactpHLim**C.CurveSharppH))
//Upper range
else if (pH > C.OptimalpHMin)
if (pH > (C.OptimalpHMin + C.ReactpHLim))
deltapH = 0
else
deltapH = ((C.ReactpHLim -(pH - (C.OptimalpHMax + C.ReactpHLim))+C.ReactpHLim)/(C.ReactpHLim**C.CurveSharppH))
//Within mid range
else if (pH >= C.OptimalpHMin && pH <= C.OptimalpHMax)
deltapH = 1
//This should never proc:
else
message_admins("Fermichem's pH broke!! Please let Fermis know!!")
WARNING("[my_atom] attempted to determine FermiChem pH for '[C.id]' which broke for some reason! ([usr])")
//TODO Add CatalystFact
message_admins("calculating pH factor(purity), pH: [pH], min: [C.OptimalpHMin]-[C.ReactpHLim], max: [C.OptimalpHMax]+[C.ReactpHLim], deltapH: [deltapH]")
stepChemAmmount = targetVol * deltaT
if (stepChemAmmount > C.RateUpLim)
stepChemAmmount = C.RateUpLim
else if (stepChemAmmount < 0.01)
stepChemAmmount = 0.01
if ((reactedVol + stepChemAmmount) > targetVol)
stepChemAmmount = targetVol - reactedVol
message_admins("target volume reached. Reaction should stop after this loop")
if (reactedVol > 0)
purity = ((purity * ammoReacted) + (deltapH * stepChemAmmount)) /((ammoReacted + stepChemAmmount)) //This should add the purity to the product
else
purity = deltapH
message_admins("purity: [purity], purity of beaker")
message_admins("Temp before change: [chem_temp], pH after change: [pH]")
//Apply pH changes and thermal output of reaction to beaker
chem_temp += (C.ThermicConstant * stepChemAmmount)
pH += (C.HIonRelease * stepChemAmmount)
message_admins("Temp after change: [chem_temp], pH after change: [pH]")
// End.
/*
for(var/B in cached_required_reagents) //
tempVol = min(reactedVol, round(get_reagent_amount(B) / cached_required_reagents[B]))//a simple one over the other? (Is this for multiplying end product? Useful for toxinsludge buildup)
*/
message_admins("cached_results: [cached_results], reactedVol: [reactedVol], stepChemAmmount [stepChemAmmount]")
for(var/B in cached_required_reagents)
message_admins("cached_required_reagents(B): [cached_required_reagents[B]], reactedVol: [reactedVol], base stepChemAmmount [stepChemAmmount]")
remove_reagent(B, (stepChemAmmount * cached_required_reagents[B]), safety = 1)//safety? removes reagents from beaker using remove function.
for(var/P in selected_reaction.results)//Not sure how this works, what is selected_reaction.results?
reactedVol = max(reactedVol, 1) //this shouldnt happen ...
SSblackbox.record_feedback("tally", "chemical_reaction", cached_results[P]*stepChemAmmount, P)//log
add_reagent(P, cached_results[P]*stepChemAmmount, null, chem_temp)//add reagent function!! I THINK I can do this:
reactedVol = reactedVol + stepChemAmmount
return (reactedVol)
/datum/reagents/proc/FermiExplode()
return
@@ -964,4 +967,4 @@
if(initial(R.can_synth))
random_reagents += initial(R.id)
var/picked_reagent = pick(random_reagents)
return picked_reagent
return picked_reagent
@@ -578,6 +578,7 @@
for(var/B in cached_required_reagents) //
tempVol = min(totalVol, round(get_reagent_amount(B) / cached_required_reagents[B]))//a simple one over the other? (Is this for multiplying end product? Useful for toxinsludge buildup)
message_admins("cached_results: [cached_results], totalVol: [totalVol], stepChemAmmount [stepChemAmmount]")
for(var/B in cached_required_reagents)
message_admins("cached_required_reagents(B): [cached_required_reagents[B]], totalVol: [totalVol], base stepChemAmmount [stepChemAmmount]")