Another round of unspaghettifying the code. A lot still to go.

This commit is contained in:
Useroth
2019-04-16 00:53:44 +02:00
parent 977462387c
commit f55b6ed18a
3 changed files with 84 additions and 89 deletions
+70 -78
View File
@@ -338,13 +338,6 @@
update_total()
/datum/reagents/proc/handle_reactions()//HERE EDIT HERE THE MAIN REACTION FERMICHEMS ASSEMBLE! I hope rp is similar
//FermiChem
var/purity = 1
var/ammoReacted = 0
var/deltaT = 0
var/deltapH = 0
var/stepChemAmmount = 0
var/list/cached_reagents = reagent_list //a list of the reagents?
var/list/cached_reactions = GLOB.chemical_reactions_list //a list of the whole reactions?
var/datum/cached_my_atom = my_atom //It says my atom, but I didn't bring one with me!!
@@ -376,7 +369,6 @@
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
@@ -392,16 +384,14 @@
var/FermiChem = C.FermiChem
var/FermiExplode = C.FermiExplode
var/ImpureChem = C.ImpureChem
*/
//FermiChem
/*
var/purity = 1
var/ammoReacted = 0
var/deltaT = 0
var/deltapH = 0
var/stepChemAmmount = 0
*/
for(var/B in cached_required_reagents)
if(!has_reagent(B, cached_required_reagents[B]))
@@ -435,6 +425,12 @@
matching_other = 1
//FermiChem
if (chem_temp > ExplodeTemp)//Check to see if reaction is too hot!
if (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
@@ -458,7 +454,6 @@
selected_reaction = competitor
var/list/cached_required_reagents = selected_reaction.required_reagents//update reagents list
var/list/cached_results = selected_reaction.results//resultant chemical list
var/special_react_result = selected_reaction.check_special_react(src)
var/list/multiplier = INFINITY //Wat
for(var/B in cached_required_reagents) //
@@ -467,87 +462,84 @@
//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.
if(selected_reaction)
var/datum/chemical_reaction/C = selected_reaction
if (C.FermiChem == TRUE)
message_admins("Hee!!!! Someone is doing a Fermi reaction!!! I'm so excited!!")
//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)
if (C.FermiChem == TRUE)
message_admins("Hee!!!! Someone is doing a Fermi reaction!!! I'm so excited!!")
//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)
while (ammoReacted < multiplier)
//Begin Parse
while (ammoReacted < multiplier)
//Begin Parse
//Check extremes first
if (chem_temp > C.ExplodeTemp)
//go to explode proc
FermiExplode()
//Check extremes first
if (chem_temp > ExplodeTemp)
//go to explode proc
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)
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)
FermiExplode()
//For now, purity is handled elsewhere
//For now, purity is handled elsewhere
//Calculate DeltaT (Deviation of T from optimal)
if (chem_temp < C.OptimalTempMax)
deltaT = (((C.OptimalTempMin - chem_temp)**C.CurveSharpT)/((C.OptimalTempMax - C.OptimalTempMax)**C.CurveSharpT))
else if (chem_temp >= C.OptimalTempMax)
deltaT = 1
//Calculate DeltaT (Deviation of T from optimal)
if (chem_temp < OptimalTempMax)
deltaT = (((OptimalTempMin - chem_temp)**CurveSharpT)/((OptimalTempMax - OptimalTempMax)**CurveSharpT))
else if (chem_temp >= C.OptimalTempMax)
deltaT = 1
else
deltaT = 0
//Calculate DeltapH (Deviation of pH from optimal)
//Lower range
if (pH < C.OptimalpHMin)
if (pH < (C.OptimalpHMin - C.ReactpHLim))
deltapH = 0
else
deltaT = 0
//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:
deltapH = (((pH - (C.OptimalpHMin - C.ReactpHLim))**C.CurveSharp)/(C.ReactpHLim**C.CurveSharppH))
//Upper range
else if (pH > C.OptimalpHMin)
if (pH > (C.OptimalpHMin + C.ReactpHLim))
deltapH = 0
else
message_admins("Fermichem's pH broke!! Please let Fermis know!!")
WARNING("[my_atom] attempted to determine FermiChem pH for '[C]' which broke for some reason! ([usr])")
//TODO Add CatalystFact
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 '[reagent]' which broke for some reason! ([usr])")
//TODO Add CatalystFact
stepChemAmmount = multiplier * deltaT
//Apply pH changes and thermal output of reaction to beaker
chem_temp += (C.ThermicConstant * stepChemAmmount)
pH += (C.HIonRelease * stepChemAmmount)
stepChemAmmount = multiplier * deltaT
if (ammoReacted > 0)
purity = ((purity * ammoReacted) + (deltapH * stepChemAmmount)) /(2 * (ammoReacted + stepChemAmmount)) //This should add the purity to the product
else
purity = deltapH
//Apply pH changes and thermal output of reaction to beaker
chem_temp += (C.ThermicConstant * stepChemAmmount)
pH += (C.HIonRelease * stepChemAmmount)
// End.
// End.
selected_reaction.on_reaction(src, multiplier, special_react_result)
selected_reaction.on_reaction(src, multiplier, special_react_result)
for(var/B in cached_required_reagents)
remove_reagent(B, (stepChemAmmount * cached_required_reagents[B]), safety = 1)//safety? removes reagents from beaker using remove function.
for(var/B in cached_required_reagents)
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?
if (ammoReacted > 0)
P.purity = ((P.purity * ammoReacted) + (deltapH * stepChemAmmount)) /(2 * (ammoReacted + stepChemAmmount)) //This should add the purity to the product
else
P.purity = deltapH
multiplier = max(multiplier, 1) //this shouldnt happen ...
SSblackbox.record_feedback("tally", "chemical_reaction", cached_results[P]*stepChemAmmount, P)//log
SSblackbox.record_feedback("tally", "Fermi_chemical_reaction", cached_results[P]*ammoReacted, P)//log
add_reagent(P, cached_results[P]*stepChemAmmount, null, chem_temp)//add reagent function!! I THINK I can do this:
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
reaction_occurred = 1
ammoReacted = ammoReacted + stepChemAmmount
reaction_occurred = 1
SSblackbox.record_feedback("tally", "Fermi_chemical_reaction", cached_results[P]*ammoReacted, P)//log
//Standard reaction mechanics:
else: