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:
@@ -22,29 +22,30 @@
metabolization_rate = 0.5 * REAGENTS_METABOLISM
addiction_stage3_end = 40
addiction_stage4_end = 55 //Incase it's too long
var/turf/open/location_created = null
var/turf/open/location_return = null
///obj/item/reagent/fermi/eigenstate/Initialize()
/datum/reagent/fermi/eigenstate/Initialize()
//. = ..() Unneeded?
var/turf/open/T = get_turf(src)//Sets up coordinate of where it was created
..()
/datum/reagent/fermi/eigenstate/New()
. = ..() //Unneeded?
location_created = get_turf(src) //Sets up coordinate of where it was created
/datum/reagent/fermi/eigenstate/on_mob_life(mob/living/carbon/M) //Teleports to chemistry!
if (holder.has_reagent("eigenstate"))
do_sparks(5,FALSE,src)
else
var/turf/open/T2 = get_turf(src) //sets up return point
location_return = get_turf(src) //sets up return point
to_chat(M, "<span class='userdanger'>You feel your wavefunction split!</span>")
do_sparks(5,FALSE,src)
src.forceMove(T) //Teleports to creation location
M.forceMove(location_created) //Teleports to creation location
do_sparks(5,FALSE,src)
..()
/datum/reagent/fermi/eigenstate/on_mob_delete(mob/living/M) //returns back to original location
do_sparks(5,FALSE,src)
to_chat(M, "<span class='userdanger'>You feel your wavefunction collapse!</span>")
src.forceMove(T2) //Teleports home
M.forceMove(location_return) //Teleports home
do_sparks(5,FALSE,src)
..()
@@ -74,7 +75,9 @@
to_chat(M, "<span class='userdanger'>You start to convlse violently as you feel your consciousness split and merge across realities as your possessions fly wildy off your body.</span>")
M.Jitter(50)
M.AdjustKnockdown(-40, 0)
for(var/obj/item/I in M.get_contents()); do_teleport(I, get_turf(I), 5, no_effects=TRUE);
for(var/item in M.get_contents())
var/obj/item/I = item
do_teleport(I, get_turf(I), 5, no_effects=TRUE);
..()
/datum/reagent/fermi/eigenstate/addiction_act_stage3(mob/living/M)//Pulls multiple copies of the character from alternative realities while teleporting them around!
@@ -85,7 +88,7 @@
//Clone function - spawns a clone then deletes it - simulates multiple copies of the player teleporting in
if(1)
var/typepath = M.type
fermi_Tclone = new typepath(M.loc)
var/fermi_Tclone = new typepath(M.loc)
//var/mob/living/carbon/O = M
var/mob/living/carbon/C = fermi_Tclone
C.appearance = M.appearance
@@ -143,7 +146,7 @@
var/mob/dead/observer/C = pick(candidates)
SM.key = C.key
SM.mind.enslave_mind_to_creator(user)
SM.sentience_act()
//SM.sentience_act()
to_chat(SM, "<span class='warning'>You feel a strange sensation building in your mind as you realise there's two of you, before you get a chance to think about it, you suddenly split from your old body, and find yourself face to face with yourself, or rather, your original self.</span>")
to_chat(SM, "<span class='userdanger'>While you find your newfound existence strange, you share the same memories as [M.real_name]. [pick("However, You find yourself indifferent to the goals you previously had, and take more interest in your newfound independence, but still have an indescribable care for the safety of your original", "Your mind has not deviated from the tasks you set out to do, and now that there's two of you the tasks should be much easier.")]</span>")
to_chat(M, "<span class='notice'>You feel a strange sensation building in your mind as you realise there's two of you, before you get a chance to think about it, you suddenly split from your old body, and find yourself face to face with yourself.</span>")
@@ -42,7 +42,7 @@
OptimalpHMax = 9.5 // Higest value for above
ReactpHLim = 2 // How far out pH wil react, giving impurity place (Exponential phase)
CatalystFact = 0 // How much the catalyst affects the reaction (0 = no catalyst)
CurveSharp = 4 // How sharp the exponential curve is (to the power of value)
CurveSharpT = 4 // How sharp the exponential curve is (to the power of value)
ThermicConstant = -2.5 //Temperature change per 1u produced
HIonRelease = 0.01 //pH change per 1u reaction
RateUpLim = 50 //Optimal/max rate possible if all conditions are perfect