Some more harddel fixes (#58305)

This commit is contained in:
LemonInTheDark
2021-04-11 19:37:20 -07:00
committed by GitHub
parent 269492047d
commit 54f0b0ceb9
11 changed files with 50 additions and 49 deletions

View File

@@ -23,19 +23,20 @@
//Chemical Reactions - Initialises all /datum/chemical_reaction into a list
// It is filtered into multiple lists within a list.
// For example:
// chemical_reaction_list[/datum/reagent/toxin/plasma] is a list of all reactions relating to plasma
// chemical_reactions_list_reactant_index[/datum/reagent/toxin/plasma] is a list of all reactions relating to plasma
//For chemical reaction list product index - indexes reactions based off the product reagent type - see get_recipe_from_reagent_product() in helpers
//For chemical reactions list lookup list - creates a bit list of info passed to the UI. This is saved to reduce lag from new windows opening, since it's a lot of data.
//Prevent these reactions from appearing in lookup tables (UI code)
var/list/blacklist = (/datum/chemical_reaction/randomized)
if(GLOB.chemical_reactions_list)
if(GLOB.chemical_reactions_list_reactant_index)
return
//Randomized need to go last since they need to check against conflicts with normal recipes
var/paths = subtypesof(/datum/chemical_reaction) - typesof(/datum/chemical_reaction/randomized) + subtypesof(/datum/chemical_reaction/randomized)
GLOB.chemical_reactions_list = list() //reagents to reaction list
GLOB.chemical_reactions_list = list() //typepath to reaction list
GLOB.chemical_reactions_list_reactant_index = list() //reagents to reaction list
GLOB.chemical_reactions_results_lookup_list = list() //UI glob
GLOB.chemical_reactions_list_product_index = list() //product to reaction list
@@ -50,6 +51,8 @@
if(!D.required_reagents || !D.required_reagents.len) //Skip impossible reactions
continue
GLOB.chemical_reactions_list[path] = D
for(var/reaction in D.required_reagents)
reaction_ids += reaction
var/datum/reagent/reagent = find_reagent_object_from_type(reaction)
@@ -81,9 +84,9 @@
// Create filters based on each reagent id in the required reagents list - this is used to speed up handle_reactions()
for(var/id in reaction_ids)
if(!GLOB.chemical_reactions_list[id])
GLOB.chemical_reactions_list[id] = list()
GLOB.chemical_reactions_list[id] += D
if(!GLOB.chemical_reactions_list_reactant_index[id])
GLOB.chemical_reactions_list_reactant_index[id] = list()
GLOB.chemical_reactions_list_reactant_index[id] += D
break // Don't bother adding ourselves to other reagent ids, it is redundant
///////////////////////////////Main reagents code/////////////////////////////////////////////
@@ -818,7 +821,7 @@
return FALSE
var/list/cached_reagents = reagent_list
var/list/cached_reactions = GLOB.chemical_reactions_list
var/list/cached_reactions = GLOB.chemical_reactions_list_reactant_index
var/datum/cached_my_atom = my_atom
LAZYNULL(failed_but_capable_reactions)
@@ -1482,7 +1485,7 @@
var/list/possible_reactions = list()
if(!length(cached_reagents))
return null
cached_reactions = GLOB.chemical_reactions_list
cached_reactions = GLOB.chemical_reactions_list_reactant_index
for(var/_reagent in cached_reagents)
var/datum/reagent/reagent = _reagent
for(var/_reaction in cached_reactions[reagent.type]) // Was a big list but now it should be smaller since we filtered it with our reagent id

View File

@@ -77,10 +77,10 @@
/obj/machinery/chem_recipe_debug/proc/setup_reactions()
cached_reactions = list()
if(process_all)
for(var/reaction in GLOB.chemical_reactions_list)
if(is_type_in_list(GLOB.chemical_reactions_list[reaction], cached_reactions))
for(var/reaction in GLOB.chemical_reactions_list_reactant_index)
if(is_type_in_list(GLOB.chemical_reactions_list_reactant_index[reaction], cached_reactions))
continue
cached_reactions += GLOB.chemical_reactions_list[reaction]
cached_reactions += GLOB.chemical_reactions_list_reactant_index[reaction]
else
cached_reactions = reaction_names
reagents.clear_reagents()

View File

@@ -516,22 +516,9 @@ All effects don't start immediately, but rather get worse over time; the rate is
shot_glass_icon_state = "shotglassgold"
chemical_flags = REAGENT_CAN_BE_SYNTHESIZED
/// Ratio of gold that the goldschlager recipe contains
var/static/gold_ratio
// This drink is really popular with a certain demographic.
var/teenage_girl_quality = DRINK_VERYGOOD
/datum/reagent/consumable/ethanol/goldschlager/New()
. = ..()
if(!gold_ratio)
// Calculate the amount of gold that goldschlager is made from
var/datum/chemical_reaction/drink/goldschlager/goldschlager_reaction = new
var/vodka_amount = goldschlager_reaction.required_reagents[/datum/reagent/consumable/ethanol/vodka]
var/gold_amount = goldschlager_reaction.required_reagents[/datum/reagent/gold]
gold_ratio = gold_amount / (gold_amount + vodka_amount)
qdel(goldschlager_reaction)
/datum/reagent/consumable/ethanol/goldschlager/expose_mob(mob/living/exposed_mob, methods=TOUCH, reac_volume)
// Reset quality each time, since the bottle can be shared
quality = initial(quality)
@@ -548,7 +535,7 @@ All effects don't start immediately, but rather get worse over time; the rate is
if(!(methods & INGEST))
return ..()
var/convert_amount = trans_volume * gold_ratio
var/convert_amount = trans_volume * min(GOLDSCHLAGER_GOLD_RATIO, 1)
A.reagents.remove_reagent(/datum/reagent/consumable/ethanol/goldschlager, convert_amount)
A.reagents.add_reagent(/datum/reagent/gold, convert_amount)
return ..()

View File

@@ -35,7 +35,7 @@ GLOBAL_LIST_INIT(medicine_reagents, build_medicine_reagents())
/datum/chemical_reaction/randomized
//Increase default leniency because these are already hard enough
optimal_ph_min = 1
optimal_ph_min = 1
optimal_ph_max = 13
temp_exponent_factor = 0
ph_exponent_factor = 1
@@ -92,28 +92,28 @@ GLOBAL_LIST_INIT(medicine_reagents, build_medicine_reagents())
if(randomize_req_temperature)
is_cold_recipe = pick(TRUE,FALSE)
if(is_cold_recipe)
required_temp = rand(min_temp+50, max_temp)
optimal_temp = rand(min_temp+25, required_temp-10)
required_temp = rand(min_temp+50, max_temp)
optimal_temp = rand(min_temp+25, required_temp-10)
overheat_temp = rand(min_temp, optimal_temp-10)
if(overheat_temp >= 200) //Otherwise it can disappear when you're mixing and I don't want this to happen here
overheat_temp = 200
if(exo_or_endothermic)
thermic_constant = (rand(-200, 200))
else
required_temp = rand(min_temp, max_temp-50)
optimal_temp = rand(required_temp+10, max_temp-25)
required_temp = rand(min_temp, max_temp-50)
optimal_temp = rand(required_temp+10, max_temp-25)
overheat_temp = rand(optimal_temp, max_temp+50)
if(overheat_temp <= 400)
overheat_temp = 400
if(exo_or_endothermic)
thermic_constant = (rand(-200, 200))
if(randomize_req_ph)
optimal_ph_min = min_ph + rand(0, inoptimal_range_ph)
optimal_ph_max = max((max_ph + rand(0, inoptimal_range_ph)), (min_ph + 1)) //Always ensure we've a window of 1
determin_ph_range = inoptimal_range_ph
H_ion_release = (rand(0, 25)/100)// 0 - 0.25
if(randomize_impurity_minimum)
purity_min = (rand(0, 4)/10)
@@ -169,7 +169,7 @@ GLOBAL_LIST_INIT(medicine_reagents, build_medicine_reagents())
/datum/chemical_reaction/randomized/proc/HasConflicts()
for(var/x in required_reagents)
for(var/datum/chemical_reaction/R in GLOB.chemical_reactions_list[x])
for(var/datum/chemical_reaction/R in GLOB.chemical_reactions_list_reactant_index[x])
if(chem_recipes_do_conflict(R,src))
return TRUE
return FALSE