From d5085463103fc379db8541c46c404fd99b6d58c4 Mon Sep 17 00:00:00 2001 From: Watermelon914 <37270891+Watermelon914@users.noreply.github.com> Date: Fri, 28 Jan 2022 10:05:50 +0000 Subject: [PATCH] Optimized steal item searcher to not search through the entire game world. (#64354) Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com> --- code/game/gamemodes/objective_items.dm | 123 +++++++++++++++++- code/game/objects/items.dm | 6 + .../antagonists/traitor/objectives/steal.dm | 26 ++-- 3 files changed, 138 insertions(+), 17 deletions(-) diff --git a/code/game/gamemodes/objective_items.dm b/code/game/gamemodes/objective_items.dm index a43bbccb60e..2f756b21345 100644 --- a/code/game/gamemodes/objective_items.dm +++ b/code/game/gamemodes/objective_items.dm @@ -1,8 +1,9 @@ -//Contains the target item datums for Steal objectives. +#define ADD_STEAL_ITEM(Source, Type) GLOB.steal_item_handler.objectives_by_path[Type] += Source +//Contains the target item datums for Steal objectives. /datum/objective_item var/name = "A silly bike horn! Honk!" - var/targetitem = /obj/item/bikehorn //typepath of the objective item + var/targetitem = /obj/item/bikehorn var/list/valid_containers = list() // Valid containers that the target item can be in. var/difficulty = 9001 //vaguely how hard it is to do this objective var/list/excludefromjob = list() //If you don't want a job to get a certain objective (no captain stealing his own medal, etcetc) @@ -47,10 +48,16 @@ targetitem = /obj/item/circuitboard/computer/aiupload circuitboard_name = "ai upload" +/obj/item/circuitboard/computer/aiupload/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/circuitboard/computer/aiupload) + /datum/objective_item/steal/low_risk/techboard/borgupload targetitem = /obj/item/circuitboard/computer/borgupload circuitboard_name = "cyborg upload" +/obj/item/circuitboard/computer/borgupload/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/circuitboard/computer/borgupload) + /datum/objective_item/steal/low_risk/techboard/New() . = ..() name = replacetext(name, "(TECH BOARD)", circuitboard_name) @@ -70,6 +77,9 @@ ) exists_on_map = TRUE +/obj/item/aicard/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/aicard) + // Unique-ish low risk objectives /datum/objective_item/steal/low_risk/bartender_shotgun name = "the bartender's shotgun" @@ -77,23 +87,35 @@ excludefromjob = list(JOB_BARTENDER) exists_on_map = TRUE +/obj/item/gun/ballistic/shotgun/doublebarrel/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/gun/ballistic/shotgun/doublebarrel) + /datum/objective_item/steal/low_risk/fireaxe name = "a fire axe" targetitem = /obj/item/fireaxe excludefromjob = list(JOB_CHIEF_ENGINEER,JOB_STATION_ENGINEER,JOB_ATMOSPHERIC_TECHNICIAN) exists_on_map = TRUE +/obj/item/fireaxe/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/fireaxe) + /datum/objective_item/steal/low_risk/nullrod name = "the chaplain's null rod" targetitem = /obj/item/nullrod excludefromjob = list(JOB_CHAPLAIN) exists_on_map = TRUE +/obj/item/nullrod/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/nullrod) + /datum/objective_item/steal/low_risk/clown_shoes name = "the clown's shoes" targetitem = /obj/item/clothing/shoes/clown_shoes excludefromjob = list(JOB_CLOWN, JOB_CARGO_TECHNICIAN, JOB_QUARTERMASTER) +/obj/item/clothing/shoes/clown_shoes/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/clothing/shoes/clown_shoes) + /datum/objective_item/steal/low_risk/clown_shoes/TargetExists() for(var/mob/player as anything in GLOB.player_list) if(player.stat == DEAD) @@ -111,6 +133,9 @@ excludefromjob = list(JOB_QUARTERMASTER, JOB_CARGO_TECHNICIAN) exists_on_map = TRUE +/obj/item/card/id/departmental_budget/car/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/card/id/departmental_budget/car) + // High risk steal objectives /datum/objective_item/steal/caplaser name = "the captain's antique laser gun" @@ -119,6 +144,9 @@ excludefromjob = list(JOB_CAPTAIN) exists_on_map = TRUE +/obj/item/gun/energy/laser/captain/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/gun/energy/laser/captain) + /datum/objective_item/steal/hoslaser name = "the head of security's personal laser gun" targetitem = /obj/item/gun/energy/e_gun/hos @@ -126,6 +154,9 @@ excludefromjob = list(JOB_HEAD_OF_SECURITY) exists_on_map = TRUE +/obj/item/gun/energy/e_gun/hos/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/gun/energy/e_gun/hos) + /datum/objective_item/steal/handtele name = "a hand teleporter" targetitem = /obj/item/hand_tele @@ -133,6 +164,9 @@ excludefromjob = list(JOB_CAPTAIN, JOB_RESEARCH_DIRECTOR, JOB_HEAD_OF_PERSONNEL) exists_on_map = TRUE +/obj/item/hand_tele/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/hand_tele) + /datum/objective_item/steal/jetpack name = "the Captain's jetpack" targetitem = /obj/item/tank/jetpack/oxygen/captain @@ -140,6 +174,9 @@ excludefromjob = list(JOB_CAPTAIN) exists_on_map = TRUE +/obj/item/tank/jetpack/oxygen/captain/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/tank/jetpack/oxygen/captain) + /datum/objective_item/steal/magboots name = "the chief engineer's advanced magnetic boots" targetitem = /obj/item/clothing/shoes/magboots/advance @@ -147,6 +184,9 @@ excludefromjob = list(JOB_CHIEF_ENGINEER) exists_on_map = TRUE +/obj/item/clothing/shoes/magboots/advance/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/clothing/shoes/magboots/advance) + /datum/objective_item/steal/capmedal name = "the medal of captaincy" targetitem = /obj/item/clothing/accessory/medal/gold/captain @@ -154,6 +194,9 @@ excludefromjob = list(JOB_CAPTAIN) exists_on_map = TRUE +/obj/item/clothing/accessory/medal/gold/captain/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/clothing/accessory/medal/gold/captain) + /datum/objective_item/steal/hypo name = "the hypospray" targetitem = /obj/item/reagent_containers/hypospray/cmo @@ -161,12 +204,18 @@ excludefromjob = list(JOB_CHIEF_MEDICAL_OFFICER) exists_on_map = TRUE +/obj/item/reagent_containers/hypospray/cmo/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/reagent_containers/hypospray/cmo) + /datum/objective_item/steal/nukedisc name = "the nuclear authentication disk" targetitem = /obj/item/disk/nuclear difficulty = 5 excludefromjob = list(JOB_CAPTAIN) +/obj/item/disk/nuclear/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/disk/nuclear) + /datum/objective_item/steal/nukedisc/check_special_completion(obj/item/disk/nuclear/N) return !N.fake @@ -177,6 +226,9 @@ excludefromjob = list(JOB_HEAD_OF_SECURITY, JOB_WARDEN) exists_on_map = TRUE +/obj/item/clothing/suit/hooded/ablative/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/clothing/suit/hooded/ablative) + /datum/objective_item/steal/reactive name = "the reactive teleport armor" targetitem = /obj/item/clothing/suit/armor/reactive/teleport @@ -184,12 +236,18 @@ excludefromjob = list(JOB_RESEARCH_DIRECTOR) exists_on_map = TRUE +/obj/item/clothing/suit/armor/reactive/teleport/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/clothing/suit/armor/reactive/teleport) + /datum/objective_item/steal/documents name = "any set of secret documents of any organization" - targetitem = /obj/item/documents //Any set of secret documents. Doesn't have to be NT's + targetitem = /obj/item/documents difficulty = 5 exists_on_map = TRUE +/obj/item/documents/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/documents) //Any set of secret documents. Doesn't have to be NT's + /datum/objective_item/steal/nuke_core name = "the heavily radioactive plutonium core from the onboard self-destruct" valid_containers = list(/obj/item/nuke_core_container) @@ -197,6 +255,9 @@ difficulty = 15 exists_on_map = TRUE +/obj/item/nuke_core/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/nuke_core) + /datum/objective_item/steal/nuke_core/New() special_equipment += /obj/item/storage/box/syndie_kit/nuke ..() @@ -208,6 +269,9 @@ excludefromjob = list(JOB_RESEARCH_DIRECTOR, JOB_SCIENTIST, JOB_ROBOTICIST, JOB_GENETICIST) exists_on_map = TRUE +/obj/item/computer_hardware/hard_drive/cluster/hdd_theft/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/computer_hardware/hard_drive/cluster/hdd_theft) + /datum/objective_item/steal/hdd_extraction/New() special_equipment += /obj/item/paper/guides/antag/hdd_extraction return ..() @@ -219,6 +283,9 @@ valid_containers = list(/obj/item/nuke_core_container/supermatter) difficulty = 15 +/obj/item/nuke_core/supermatter_sliver/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/nuke_core/supermatter_sliver) + /datum/objective_item/steal/supermatter/New() special_equipment += /obj/item/storage/box/syndie_kit/supermatter ..() @@ -236,6 +303,9 @@ JOB_RESEARCH_DIRECTOR, JOB_SCIENTIST, JOB_ROBOTICIST, ) +/obj/item/tank/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/tank) + /datum/objective_item/steal/plasma/check_special_completion(obj/item/tank/T) var/target_amount = text2num(name) var/found_amount = 0 @@ -249,6 +319,9 @@ targetitem = /obj/item/aicard difficulty = 20 //beyond the impossible +/obj/item/aicard/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/aicard) + /datum/objective_item/steal/functionalai/check_special_completion(obj/item/aicard/C) for(var/mob/living/silicon/ai/A in C) if(isAI(A) && A.stat != DEAD) //See if any AI's are alive inside that card. @@ -263,6 +336,9 @@ altitems = list(/obj/item/photo) exists_on_map = TRUE +/obj/item/areaeditor/blueprints/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/areaeditor/blueprints) + /datum/objective_item/steal/blueprints/check_special_completion(obj/item/I) if(istype(I, /obj/item/areaeditor/blueprints)) return TRUE @@ -278,6 +354,9 @@ difficulty = 3 excludefromjob = list(JOB_RESEARCH_DIRECTOR, JOB_SCIENTIST) +/obj/item/slime_extract/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/slime_extract) + /datum/objective_item/steal/slime/check_special_completion(obj/item/slime_extract/E) if(E.Uses > 0) return 1 @@ -290,6 +369,9 @@ excludefromjob = list(JOB_CHIEF_ENGINEER, JOB_STATION_ENGINEER, JOB_ATMOSPHERIC_TECHNICIAN) exists_on_map = TRUE +/obj/item/blackbox/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/blackbox) + //Unique Objectives /datum/objective_item/special/New() ..() @@ -309,36 +391,57 @@ difficulty = 10 exists_on_map = TRUE +/obj/item/pinpointer/nuke/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/pinpointer/nuke) + /datum/objective_item/special/aegun name = "an advanced energy gun" targetitem = /obj/item/gun/energy/e_gun/nuclear difficulty = 10 +/obj/item/gun/energy/e_gun/nuclear/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/gun/energy/e_gun/nuclear) + /datum/objective_item/special/ddrill name = "a diamond drill" targetitem = /obj/item/pickaxe/drill/diamonddrill difficulty = 10 +/obj/item/pickaxe/drill/diamonddrill/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/pickaxe/drill/diamonddrill) + /datum/objective_item/special/boh name = "a bag of holding" targetitem = /obj/item/storage/backpack/holding difficulty = 10 +/obj/item/storage/backpack/holding/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/storage/backpack/holding) + /datum/objective_item/special/hypercell name = "a hyper-capacity power cell" targetitem = /obj/item/stock_parts/cell/hyper difficulty = 5 +/obj/item/stock_parts/cell/hyper/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/stock_parts/cell/hyper) + /datum/objective_item/special/laserpointer name = "a laser pointer" targetitem = /obj/item/laser_pointer difficulty = 5 +/obj/item/laser_pointer/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/laser_pointer) + /datum/objective_item/special/corgimeat name = "a piece of corgi meat" targetitem = /obj/item/food/meat/slab/corgi difficulty = 5 +/obj/item/food/meat/slab/corgi/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/food/meat/slab/corgi) + /datum/objective_item/stack/New() ..() if(TargetExists()) @@ -356,6 +459,9 @@ targetitem = /obj/item/stack/sheet/cardboard difficulty = 9001 +/obj/item/stack/sheet/cardboard/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/stack/sheet/cardboard) + /datum/objective_item/stack/check_special_completion(obj/item/stack/S) var/target_amount = text2num(name) var/found_amount = 0 @@ -369,12 +475,23 @@ targetitem = /obj/item/stack/sheet/mineral/diamond difficulty = 10 +/obj/item/stack/sheet/mineral/diamond/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/stack/sheet/mineral/diamond) + /datum/objective_item/stack/gold name = "50 gold bars" targetitem = /obj/item/stack/sheet/mineral/gold difficulty = 15 +/obj/item/stack/sheet/mineral/gold/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/stack/sheet/mineral/gold) + /datum/objective_item/stack/uranium name = "25 refined uranium bars" targetitem = /obj/item/stack/sheet/mineral/uranium difficulty = 10 + +/obj/item/stack/sheet/mineral/uranium/add_stealing_item_objective() + ADD_STEAL_ITEM(src, /obj/item/stack/sheet/mineral/uranium) + +#undef ADD_STEAL_ITEM diff --git a/code/game/objects/items.dm b/code/game/objects/items.dm index cb1616b307e..499db82b3aa 100644 --- a/code/game/objects/items.dm +++ b/code/game/objects/items.dm @@ -239,6 +239,8 @@ GLOBAL_DATUM_INIT(fire_overlay, /mutable_appearance, mutable_appearance('icons/e SEND_GLOBAL_SIGNAL(COMSIG_GLOB_NEW_ITEM, src) if(LAZYLEN(embedding)) updateEmbedding() + if(mapload) + add_stealing_item_objective() /obj/item/Destroy() // This var exists as a weird proxy "owner" ref @@ -251,6 +253,10 @@ GLOBAL_DATUM_INIT(fire_overlay, /mutable_appearance, mutable_appearance('icons/e qdel(X) return ..() +/// Called if this item is supposed to be a steal objective item objective. Only done at mapload +/obj/item/proc/add_stealing_item_objective() + return + /// Adds the weapon_description element, which shows the 'warning label' for especially dangerous objects. Override this for item types with special notes. /obj/item/proc/add_weapon_description() AddElement(/datum/element/weapon_description) diff --git a/code/modules/antagonists/traitor/objectives/steal.dm b/code/modules/antagonists/traitor/objectives/steal.dm index df8c45a4e16..a861ef4f509 100644 --- a/code/modules/antagonists/traitor/objectives/steal.dm +++ b/code/modules/antagonists/traitor/objectives/steal.dm @@ -21,31 +21,29 @@ GLOBAL_DATUM_INIT(steal_item_handler, /datum/objective_item_handler, new()) /datum/objective_item_handler - var/list/objectives_by_path = list() + var/list/objectives_by_path /datum/objective_item_handler/New() . = ..() + objectives_by_path = list() + for(var/datum/objective_item/item as anything in subtypesof(/datum/objective_item)) + objectives_by_path[initial(item.targetitem)] = list() RegisterSignal(SSatoms, COMSIG_SUBSYSTEM_POST_INITIALIZE, .proc/save_items) // Very inefficient proc, only gets called when the map finishes loading. /datum/objective_item_handler/proc/save_items() - for(var/datum/objective_item/steal/steal as anything in subtypesof(/datum/objective_item/steal)) - if(!initial(steal.exists_on_map)) - continue - objectives_by_path[initial(steal.targetitem)] = list() - for(var/atom/object as anything in world) - var/turf/place = get_turf(object) - if(!place || !is_station_level(place.z)) - continue - for(var/typepath in objectives_by_path) - if(istype(object, typepath)) - objectives_by_path[typepath] += object - RegisterSignal(object, COMSIG_PARENT_QDELETING, .proc/remove_item) + for(var/obj/item/typepath as anything in objectives_by_path) + for(var/obj/item/object as anything in objectives_by_path[typepath]) + var/turf/place = get_turf(object) + if(!place || !is_station_level(place.z)) + objectives_by_path[typepath] -= object + continue + RegisterSignal(object, COMSIG_PARENT_QDELETING, .proc/remove_item) /datum/objective_item_handler/proc/remove_item(atom/source) SIGNAL_HANDLER for(var/typepath in objectives_by_path) - objectives_by_path[typepath] -= typepath + objectives_by_path[typepath] -= source /datum/traitor_objective/steal_item name = "Steal %ITEM% and place a bug on it. Hold it for %TIME% minutes"