Makes some more lists lazy (#94388)

Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
This commit is contained in:
Bloop
2025-12-28 19:57:42 +01:00
committed by GitHub
co-authored by SyncIt21 MrMelbert
parent b88e1a1328
commit 53ed83bb9d
58 changed files with 268 additions and 253 deletions
+8 -7
View File
@@ -6,7 +6,7 @@
var/oblivion_message = "You stumble and stare into the abyss before you. It stares back, and you fall into the enveloping dark."
/// List of refs to falling objects -> how many levels deep we've fallen
var/static/list/falling_atoms = list()
var/static/list/falling_atoms
var/static/list/forbidden_types = typecacheof(list(
/obj/docking_port,
/obj/effect/abstract,
@@ -106,7 +106,8 @@
/datum/component/chasm/proc/droppable(atom/movable/dropped_thing)
var/datum/weakref/falling_ref = WEAKREF(dropped_thing)
// avoid an infinite loop, but allow falling a large distance
if(falling_atoms[falling_ref] && falling_atoms[falling_ref] > 30)
var/falling_atom = LAZYACCESS(falling_atoms, falling_ref)
if(falling_atom && falling_atom > 30)
return CHASM_NOT_DROPPING
if(is_type_in_typecache(dropped_thing, forbidden_types) || (!isliving(dropped_thing) && !isobj(dropped_thing)))
return CHASM_NOT_DROPPING
@@ -133,14 +134,14 @@
var/datum/weakref/falling_ref = WEAKREF(dropped_thing)
//Make sure the item is still there after our sleep
if(!dropped_thing || !falling_ref?.resolve())
falling_atoms -= falling_ref
LAZYREMOVE(falling_atoms, falling_ref)
return
falling_atoms[falling_ref] = (falling_atoms[falling_ref] || 0) + 1
LAZYSET(falling_atoms, falling_ref, (falling_atoms[falling_ref] || 0) + 1)
var/turf/below_turf = target_turf
var/atom/parent = src.parent
if(falling_atoms[falling_ref] > 1)
if(LAZYACCESS(falling_atoms, falling_ref) > 1)
return // We're already handling this
if(SEND_SIGNAL(dropped_thing, COMSIG_MOVABLE_CHASM_DROPPED, parent) & COMPONENT_NO_CHASM_DROP)
@@ -164,7 +165,7 @@
var/mob/living/fallen = dropped_thing
fallen.Paralyze(100)
fallen.adjust_brute_loss(30)
falling_atoms -= falling_ref
LAZYREMOVE(falling_atoms, falling_ref)
return
// send to oblivion
@@ -235,7 +236,7 @@
fallen_mob.death(TRUE)
fallen_mob.apply_damage(300)
falling_atoms -= falling_ref
LAZYREMOVE(falling_atoms, falling_ref)
/**
* Called when something has left the chasm depths storage.
+24 -18
View File
@@ -8,7 +8,7 @@
///type paths of items consumed associated with how many are needed
var/list/reqs = list()
///type paths of items explicitly not allowed as an ingredient
var/list/blacklist = list()
var/list/blacklist
///type path of item resulting from this craft
var/result
/// String defines of items needed but not consumed. Lazy list.
@@ -23,13 +23,13 @@
///time in seconds. Remember to use the SECONDS define!
var/time = 3 SECONDS
///type paths of items that will be forceMoved() into the result instead of being deleted
var/list/parts = list()
var/list/parts
///items, structures and machineries of types that are in this list won't transfer their materials to the result
var/list/requirements_mats_blacklist
///if set, the materials in this list and their values will be subtracted from the result.
var/list/removed_mats
///like tool_behaviors but for reagents
var/list/chem_catalysts = list()
var/list/chem_catalysts
///where it shows up in the crafting UI
var/category
///Required machines for the craft, set the assigned value of the typepath to CRAFTING_MACHINERY_CONSUME or CRAFTING_MACHINERY_USE. Lazy associative list: type_path key -> flag value.
@@ -50,19 +50,15 @@
var/delete_contents = TRUE
/// Allows you to craft so that you don't have to click the craft button many times.
var/mass_craftable = FALSE
///crafting_flags var to hold bool values
var/crafting_flags = CRAFT_CHECK_DENSITY
/datum/crafting_recipe/New()
if(!name && result)
var/atom/atom_result = result
name = initial(atom_result.name)
if(!(result in reqs))
blacklist += result
// These should be excluded from all crafting recipies
blacklist += list(
/**
* Should the recipe blacklist its result? Default behavior is to blacklist any result that isn't in reqs.
* Can be set to ALWAYS_BLACKLIST_RESULT or NEVER_BLACKLIST_RESULT to override the default behavior.
*/
var/blacklist_result = BLACKLIST_RESULT_IF_NOT_IN_REQS
/// Global crafting blacklist. These should be excluded from all crafting recipes no matter what.
var/static/list/global_blacklist = typecacheof(list(
/obj/item/cautery/augment,
/obj/item/cautery/cruel/augment,
/obj/item/circular_saw/augment,
@@ -81,15 +77,25 @@
/obj/item/weldingtool/largetank/cyborg,
/obj/item/wirecutters/cyborg,
/obj/item/wrench/cyborg,
)
))
/datum/crafting_recipe/New()
if(!name && result)
var/atom/atom_result = result
name = initial(atom_result.name)
if(result && blacklist_result == BLACKLIST_RESULT_IF_NOT_IN_REQS && !(result in reqs))
blacklist_result = ALWAYS_BLACKLIST_RESULT
if(tool_behaviors)
tool_behaviors = string_list(tool_behaviors)
if(tool_paths)
tool_paths = string_list(tool_paths)
for(var/key in parts)
if(!parts[key])
for(var/key, part in parts)
if(!part)
//ensure every single, same-type part used for the recipe will be transferred if the value is otherwise not specified
parts[key] = INFINITY
part = INFINITY
/datum/crafting_recipe/stack
abstract_type = /datum/crafting_recipe/stack
/datum/crafting_recipe/stack/New(obj/item/stack/material, datum/stack_recipe/stack_recipe)
if(!material || !stack_recipe || !stack_recipe.result_type)
+16 -12
View File
@@ -68,12 +68,17 @@
var/list/requirements_list = list()
// Process all requirements
for(var/requirement_path in recipe.reqs)
var/recipe_result
if(recipe.blacklist_result)
recipe_result = recipe.result
for(var/requirement_path, needed_amount in recipe.reqs)
// Check we have the appropriate amount available in the contents list
var/needed_amount = recipe.reqs[requirement_path]
for(var/content_item_path in contents)
// Right path and not blacklisted
if(!ispath(content_item_path, requirement_path) || recipe.blacklist.Find(content_item_path))
if(!ispath(content_item_path, requirement_path) || (content_item_path in recipe.blacklist) || is_type_in_typecache(recipe.global_blacklist, content_item_path))
continue
// If we are a recipe that is blacklisting its result, make sure we skip that path
if(recipe_result && content_item_path == recipe_result)
continue
needed_amount -= contents[content_item_path]
@@ -85,14 +90,14 @@
// Store the instances of what we will use for recipe.check_requirements() for requirement_path
var/list/instances_list = list()
for(var/instance_path in item_instances)
for(var/instance_path, item_instance in item_instances)
if(ispath(instance_path, requirement_path))
instances_list += item_instances[instance_path]
instances_list += item_instance
requirements_list[requirement_path] = instances_list
for(var/requirement_path in recipe.chem_catalysts)
if(contents[requirement_path] < recipe.chem_catalysts[requirement_path])
for(var/requirement_path, chem_amount in recipe.chem_catalysts)
if(contents[requirement_path] < chem_amount)
return FALSE
var/mech_found = FALSE
@@ -245,8 +250,7 @@
var/list/total_materials = list()
var/list/stuff_to_use = get_used_reqs(recipe, crafter, total_materials)
for(var/mat in recipe.removed_mats)
var/to_remove = recipe.removed_mats[mat]
for(var/mat, to_remove in recipe.removed_mats)
var/datum/material/ref_mat = locate(mat) in total_materials
if(!ref_mat)
continue
@@ -680,11 +684,11 @@
data["reqs"]["[id]"] = recipe.reqs[req_atom]
// Catalysts
if(recipe.chem_catalysts.len)
if(LAZYLEN(recipe.chem_catalysts))
data["chem_catalysts"] = list()
for(var/req_atom in recipe.chem_catalysts)
for(var/req_atom, chem_amount in recipe.chem_catalysts)
var/id = atoms.Find(req_atom)
data["chem_catalysts"]["[id]"] = recipe.chem_catalysts[req_atom]
data["chem_catalysts"]["[id]"] = chem_amount
// Reaction data
if(ispath(recipe.reaction))
+18 -12
View File
@@ -10,8 +10,8 @@
category = CAT_EQUIPMENT
/datum/crafting_recipe/strobeshield/New()
..()
blacklist |= subtypesof(/obj/item/shield/riot)
LAZYADD(blacklist, typecacheof(/obj/item/shield/riot, ignore_root_path = TRUE))
return ..()
/datum/crafting_recipe/improvisedshield
name = "Improvised Shield"
@@ -33,8 +33,19 @@
time = 4 SECONDS
category = CAT_EQUIPMENT
/datum/crafting_recipe/radio_containing
abstract_type = /datum/crafting_recipe/radio_containing
/// Shared blacklist of all the radio types for anything that uses a radio in its construction, so we don't repeat it.
var/static/list/radio_types_blacklist
/datum/crafting_recipe/radiogloves
/datum/crafting_recipe/radio_containing/New()
if(isnull(radio_types_blacklist))
// because we got shit like /obj/item/radio/off ... WHY!?!
radio_types_blacklist = typecacheof(list(/obj/item/radio/headset, /obj/item/radio/intercom))
blacklist = radio_types_blacklist
return ..()
/datum/crafting_recipe/radio_containing/radiogloves
name = "Radio Gloves"
result = /obj/item/clothing/gloves/radio
time = 1.5 SECONDS
@@ -46,11 +57,6 @@
tool_behaviors = list(TOOL_WIRECUTTER)
category = CAT_EQUIPMENT
/datum/crafting_recipe/radiogloves/New()
..()
blacklist |= typesof(/obj/item/radio/headset)
blacklist |= typesof(/obj/item/radio/intercom)
/datum/crafting_recipe/wheelchair
name = "Wheelchair"
result = /obj/vehicle/ridden/wheelchair
@@ -163,8 +169,8 @@
category = CAT_EQUIPMENT
/datum/crafting_recipe/flashlight_eyes/New()
. = ..()
blacklist += typesof(/obj/item/flashlight/flare)
LAZYADD(blacklist, typecacheof(/obj/item/flashlight/flare))
return ..()
/datum/crafting_recipe/extendohand_r
name = "Extendo-Hand (Right Arm)"
@@ -308,8 +314,8 @@
tool_behaviors = list(TOOL_WELDER, TOOL_SCREWDRIVER, TOOL_WIRECUTTER)
/datum/crafting_recipe/morbid_surgical_toolset/New()
..()
blacklist |= subtypesof(/obj/item/organ/cyberimp/arm/toolkit/surgery)
LAZYADD(blacklist, typecacheof(/obj/item/organ/cyberimp/arm/toolkit/surgery, ignore_root_path = TRUE))
return ..()
/datum/crafting_recipe/surgical_toolset
name = "Surgical Toolset Implant"
@@ -89,7 +89,6 @@
time = 4 SECONDS
category = CAT_WEAPON_MELEE
/datum/crafting_recipe/balloon_mallet
name = "Balloon Mallet"
result = /obj/item/balloon_mallet
@@ -67,8 +67,8 @@
category = CAT_WEAPON_RANGED
/datum/crafting_recipe/advancedegun/New()
..()
blacklist += subtypesof(/obj/item/gun/energy/e_gun)
LAZYADD(blacklist, typecacheof(/obj/item/gun/energy/e_gun, ignore_root_path = TRUE))
return ..()
/datum/crafting_recipe/tempgun
name = "Temperature Gun"
@@ -81,8 +81,8 @@
category = CAT_WEAPON_RANGED
/datum/crafting_recipe/tempgun/New()
..()
blacklist += subtypesof(/obj/item/gun/energy/e_gun)
LAZYADD(blacklist, typecacheof(/obj/item/gun/energy/e_gun, ignore_root_path = TRUE))
return ..()
/datum/crafting_recipe/beam_rifle
name = "Event Horizon Anti-Existential Beam Rifle"
@@ -108,7 +108,18 @@
time = 10 SECONDS
category = CAT_WEAPON_RANGED
/datum/crafting_recipe/xraylaser
/datum/crafting_recipe/laser
abstract_type = /datum/crafting_recipe/laser
/// We will use the same blacklist for every type here to avoid repeating lists
var/static/list/laser_blacklist
/datum/crafting_recipe/laser/New()
if(isnull(laser_blacklist))
laser_blacklist = typecacheof(/obj/item/gun/energy/laser, ignore_root_path = TRUE)
blacklist = laser_blacklist
return ..()
/datum/crafting_recipe/laser/xraylaser
name = "X-ray Laser Gun"
result = /obj/item/gun/energy/laser/xray
reqs = list(
@@ -118,11 +129,7 @@
time = 10 SECONDS
category = CAT_WEAPON_RANGED
/datum/crafting_recipe/xraylaser/New()
..()
blacklist += subtypesof(/obj/item/gun/energy/laser)
/datum/crafting_recipe/hellgun
/datum/crafting_recipe/laser/hellgun
name = "Hellfire Laser Gun"
result = /obj/item/gun/energy/laser/hellgun
reqs = list(
@@ -132,11 +139,7 @@
time = 10 SECONDS
category = CAT_WEAPON_RANGED
/datum/crafting_recipe/hellgun/New()
..()
blacklist += subtypesof(/obj/item/gun/energy/laser)
/datum/crafting_recipe/ioncarbine
/datum/crafting_recipe/laser/ioncarbine
name = "Ion Carbine"
result = /obj/item/gun/energy/ionrifle/carbine
reqs = list(
@@ -146,10 +149,6 @@
time = 10 SECONDS
category = CAT_WEAPON_RANGED
/datum/crafting_recipe/ioncarbine/New()
..()
blacklist += subtypesof(/obj/item/gun/energy/laser)
/datum/crafting_recipe/teslacannon
name = "Tesla Cannon"
result = /obj/item/gun/energy/tesla_cannon
@@ -241,8 +240,8 @@
/obj/item/gun/ballistic/rifle/rebarxbow = 1,
)
blacklist = list(
/obj/item/gun/ballistic/rifle/rebarxbow/forced,
/obj/item/gun/ballistic/rifle/rebarxbow/syndie,
/obj/item/gun/ballistic/rifle/rebarxbow/forced,
/obj/item/gun/ballistic/rifle/rebarxbow/syndie,
)
tool_behaviors = list(TOOL_CROWBAR)
time = 1 SECONDS
@@ -289,8 +288,8 @@
crafting_flags = CRAFT_CHECK_DENSITY | CRAFT_MUST_BE_LEARNED
/datum/crafting_recipe/deagle_prime/New()
..()
blacklist += subtypesof(/obj/item/gun/ballistic/automatic/pistol)
LAZYADD(blacklist, typecacheof(/obj/item/gun/ballistic/automatic/pistol, ignore_root_path = TRUE))
return ..()
/datum/crafting_recipe/deagle_prime_mag
name = "Regal Condor Magazine (10mm Reaper)"
+1 -6
View File
@@ -421,12 +421,7 @@
)
reqs = list(/obj/item/stack/sheet/cloth = 4)
category = CAT_CLOTHING
/datum/crafting_recipe/chaplain_hood/New()
. = ..()
//the resulting hoodie can be used to craft other hoodies.
//recipe blacklists should be refactored to only affect components and not tools.
blacklist -= result
blacklist_result = NEVER_BLACKLIST_RESULT //the resulting hoodie can be used to craft other hoodies.
/datum/crafting_recipe/flower_garland
name = "Flower Garland"
+2 -2
View File
@@ -36,7 +36,7 @@
heal_when_sinked = TRUE,
health_per_second = 1,
outline_colour = COLOR_PALE_GREEN,
damage_res_sinked = list(BRUTE = 1, BURN = 1, TOX = 1, STAMINA = 0, OXY = 1))
damage_res_sinked = string_assoc_list(list(BRUTE = 1, BURN = 1, TOX = 1, STAMINA = 0, OXY = 1)))
if (!isbasicmob(parent))
return COMPONENT_INCOMPATIBLE
@@ -112,7 +112,7 @@
if(sinked && heal_when_sinked)
stop_regenerating()
living_target.icon_state = target_icon_state
living_target.damage_coeff = list(BRUTE = 1, BURN = 1, TOX = 1, STAMINA = 0, OXY = 1)
living_target.damage_coeff = string_assoc_list(list(BRUTE = 1, BURN = 1, TOX = 1, STAMINA = 0, OXY = 1))
living_target.set_density(TRUE)
sinked = FALSE
+4 -4
View File
@@ -1,6 +1,6 @@
/datum/component/soapbox
/// List of our current soapboxxer(s) who are gaining loud speech
var/list/soapboxers = list()
var/list/soapboxers
/// Gives atoms moving over us the soapbox speech and takes it away when they leave
var/static/list/loc_connections = list(
COMSIG_ATOM_ENTERED = PROC_REF(on_loc_entered),
@@ -21,21 +21,21 @@
if(QDELETED(soapbox_arrive))
return
RegisterSignal(soapbox_arrive, COMSIG_MOB_SAY, PROC_REF(soapbox_speech))
soapboxers += soapbox_arrive
LAZYADD(soapboxers, soapbox_arrive)
///Takes away loud speech from our movable when it leaves the turf our parent is on
/datum/component/soapbox/proc/on_loc_exited(datum/source, mob/living/soapbox_leave)
SIGNAL_HANDLER
if(soapbox_leave in soapboxers)
UnregisterSignal(soapbox_leave, COMSIG_MOB_SAY)
soapboxers -= soapbox_leave
LAZYREMOVE(soapboxers, soapbox_leave)
///We don't want our soapboxxer to keep their loud say if the parent is moved out from under them
/datum/component/soapbox/proc/parent_moved(datum/source)
SIGNAL_HANDLER
for(var/atom/movable/loud as anything in soapboxers)
UnregisterSignal(loud, COMSIG_MOB_SAY)
soapboxers.Cut()
LAZYNULL(soapboxers)
///Gives a mob a unique say span
/datum/component/soapbox/proc/soapbox_speech(datum/source, list/speech_args)