From 96da7be01b1c7e96f1a51138a6c7a5e2c964958a Mon Sep 17 00:00:00 2001 From: Aronai Sieyes Date: Mon, 11 May 2020 22:05:41 -0400 Subject: [PATCH] Put APCs and SMESes into GLOB lists to ease iteration --- code/controllers/subsystems/nightshift.dm | 2 +- code/game/gamemodes/cult/hell_universe.dm | 2 +- .../endgame/supermatter_cascade/universe.dm | 2 +- code/game/gamemodes/events.dm | 6 +-- code/game/gamemodes/events/power_failure.dm | 10 ++--- .../newmalf_ability_trees/HELPERS.dm | 2 +- .../tree_manipulation.dm | 4 +- .../newmalf_ability_trees/tree_networking.dm | 4 +- code/modules/admin/verbs/debug.dm | 2 +- code/modules/events/electrical_storm.dm | 2 +- code/modules/events/ion_storm.dm | 4 +- .../events/everyone/electrical_fault.dm | 2 +- .../programs/engineering/rcon_console.dm | 2 +- code/modules/power/apc.dm | 4 ++ code/modules/power/smes.dm | 4 ++ code/modules/power/supermatter/supermatter.dm | 2 +- .../xenoarcheaology/effects/cellcharge.dm | 38 +++++++++++++++---- .../xenoarcheaology/effects/celldrain.dm | 36 +++++++++++++++--- 18 files changed, 92 insertions(+), 36 deletions(-) diff --git a/code/controllers/subsystems/nightshift.dm b/code/controllers/subsystems/nightshift.dm index 3f0d9bfda8..91b1c6bb35 100644 --- a/code/controllers/subsystems/nightshift.dm +++ b/code/controllers/subsystems/nightshift.dm @@ -64,7 +64,7 @@ SUBSYSTEM_DEF(nightshift) announce("Good evening, crew. To reduce power consumption and stimulate the circadian rhythms of some species, all of the lights aboard the station have been dimmed for the night.") else announce("Good morning, crew. As it is now day time, all of the lights aboard the station have been restored to their former brightness.") - for(var/obj/machinery/power/apc/apc in machines) + for(var/obj/machinery/power/apc/apc in GLOB.apcs) if(apc.z in using_map.station_levels) apc.set_nightshift(active, TRUE) CHECK_TICK diff --git a/code/game/gamemodes/cult/hell_universe.dm b/code/game/gamemodes/cult/hell_universe.dm index f67f689288..df05607311 100644 --- a/code/game/gamemodes/cult/hell_universe.dm +++ b/code/game/gamemodes/cult/hell_universe.dm @@ -78,7 +78,7 @@ In short: alm.ex_act(2) /datum/universal_state/hell/proc/APCSet() - for (var/obj/machinery/power/apc/APC in machines) + for (var/obj/machinery/power/apc/APC in GLOB.apcs) if (!(APC.stat & BROKEN) && !APC.is_critical) APC.emagged = 1 APC.queue_icon_update() diff --git a/code/game/gamemodes/endgame/supermatter_cascade/universe.dm b/code/game/gamemodes/endgame/supermatter_cascade/universe.dm index f8a8581075..310a7a9ae7 100644 --- a/code/game/gamemodes/endgame/supermatter_cascade/universe.dm +++ b/code/game/gamemodes/endgame/supermatter_cascade/universe.dm @@ -107,7 +107,7 @@ The access requirements on the Asteroid Shuttles' consoles have now been revoked alm.ex_act(2) /datum/universal_state/supermatter_cascade/proc/APCSet() - for (var/obj/machinery/power/apc/APC in machines) + for (var/obj/machinery/power/apc/APC in GLOB.apcs) if (!(APC.stat & BROKEN) && !APC.is_critical) APC.chargemode = 0 if(APC.cell) diff --git a/code/game/gamemodes/events.dm b/code/game/gamemodes/events.dm index 1cb4e8a2dc..ba737a416a 100644 --- a/code/game/gamemodes/events.dm +++ b/code/game/gamemodes/events.dm @@ -236,7 +236,7 @@ var/hadevent = 0 apc.overload_lighting() else - for(var/obj/machinery/power/apc/apc in machines) + for(var/obj/machinery/power/apc/apc in GLOB.apcs) apc.overload_lighting() return @@ -362,14 +362,14 @@ Would like to add a law like "Law x is _______" where x = a number, and _____ is spawn(0) to_world("Started processing APCs") - for (var/obj/machinery/power/apc/APC in machines) + for (var/obj/machinery/power/apc/APC in GLOB.APCs) if(APC.z in station_levels) APC.ion_act() apcnum++ to_world("Finished processing APCs. Processed: [apcnum]") spawn(0) to_world("Started processing SMES") - for (var/obj/machinery/power/smes/SMES in machines) + for (var/obj/machinery/power/smes/SMES in GLOB.smeses) if(SMES.z in station_levels) SMES.ion_act() smesnum++ diff --git a/code/game/gamemodes/events/power_failure.dm b/code/game/gamemodes/events/power_failure.dm index 2cd257e0bb..5ebf1e07bc 100644 --- a/code/game/gamemodes/events/power_failure.dm +++ b/code/game/gamemodes/events/power_failure.dm @@ -5,7 +5,7 @@ var/list/skipped_areas = list(/area/ai) - for(var/obj/machinery/power/smes/S in machines) + for(var/obj/machinery/power/smes/S in GLOB.smeses) var/area/current_area = get_area(S) if(current_area.type in skipped_areas || !(S.z in using_map.station_levels)) continue @@ -19,7 +19,7 @@ S.power_change() - for(var/obj/machinery/power/apc/C in machines) + for(var/obj/machinery/power/apc/C in GLOB.apcs) if(!C.is_critical && C.cell && (C.z in using_map.station_levels)) C.cell.charge = 0 @@ -28,10 +28,10 @@ if(announce) command_announcement.Announce("Power has been restored to [station_name()]. We apologize for the inconvenience.", "Power Systems Nominal", new_sound = 'sound/AI/poweron.ogg') - for(var/obj/machinery/power/apc/C in machines) + for(var/obj/machinery/power/apc/C in GLOB.apcs) if(C.cell && (C.z in using_map.station_levels)) C.cell.charge = C.cell.maxcharge - for(var/obj/machinery/power/smes/S in machines) + for(var/obj/machinery/power/smes/S in GLOB.smeses) var/area/current_area = get_area(S) if(current_area.type in skipped_areas || isNotStationLevel(S.z)) continue @@ -45,7 +45,7 @@ if(announce) command_announcement.Announce("All SMESs on [station_name()] have been recharged. We apologize for the inconvenience.", "Power Systems Nominal", new_sound = 'sound/AI/poweron.ogg') - for(var/obj/machinery/power/smes/S in machines) + for(var/obj/machinery/power/smes/S in GLOB.smeses) if(isNotStationLevel(S.z)) continue S.charge = S.capacity diff --git a/code/game/gamemodes/malfunction/newmalf_ability_trees/HELPERS.dm b/code/game/gamemodes/malfunction/newmalf_ability_trees/HELPERS.dm index 18ba0950ac..8c27df2732 100644 --- a/code/game/gamemodes/malfunction/newmalf_ability_trees/HELPERS.dm +++ b/code/game/gamemodes/malfunction/newmalf_ability_trees/HELPERS.dm @@ -168,7 +168,7 @@ // Description: Returns a list of all unhacked APCs /proc/get_unhacked_apcs(var/mob/living/silicon/ai/user) var/list/H = list() - for(var/obj/machinery/power/apc/A in machines) + for(var/obj/machinery/power/apc/A in GLOB.apcs) if(A.hacker && A.hacker == user) continue H.Add(A) diff --git a/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_manipulation.dm b/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_manipulation.dm index ace83463a6..9d9bed799a 100644 --- a/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_manipulation.dm +++ b/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_manipulation.dm @@ -3,7 +3,7 @@ // Abilities in this tree allow the AI to physically manipulate systems around the station. // T1 - Electrical Pulse - Sends out pulse that breaks some lights and sometimes even APCs. This can actually break the AI's APC so be careful! // T2 - Hack Camera - Allows the AI to hack a camera. Deactivated areas may be reactivated, and functional cameras can be upgraded. -// T3 - Emergency Forcefield - Allows the AI to project 1 tile forcefield that blocks movement and air flow. Forcefield´dissipates over time. It is also very susceptible to energetic weaponry. +// T3 - Emergency Forcefield - Allows the AI to project 1 tile forcefield that blocks movement and air flow. Forcefield�dissipates over time. It is also very susceptible to energetic weaponry. // T4 - Machine Overload - Detonates machine of choice in a minor explosion. Two of these are usually enough to kill or K/O someone. @@ -47,7 +47,7 @@ if(!ability_prechecks(user, price) || !ability_pay(user,price)) return to_chat(user, "Sending feedback pulse...") - for(var/obj/machinery/power/apc/AP in machines) + for(var/obj/machinery/power/apc/AP in GLOB.apcs) if(prob(5)) AP.overload_lighting() if(prob(1) && prob(1)) // Very very small chance to actually destroy the APC. diff --git a/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_networking.dm b/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_networking.dm index 3405878bb6..6d9f5a36ff 100644 --- a/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_networking.dm +++ b/code/game/gamemodes/malfunction/newmalf_ability_trees/tree_networking.dm @@ -147,7 +147,7 @@ to_chat(user, "You already started the system override sequence.") return var/list/remaining_apcs = list() - for(var/obj/machinery/power/apc/A in machines) + for(var/obj/machinery/power/apc/A in GLOB.apcs) if(!(A.z in using_map.station_levels)) // Only station APCs continue if(A.hacker == user || A.aidisabled) // This one is already hacked, or AI control is disabled on it. @@ -193,7 +193,7 @@ to_chat(user, "## REACHABLE APC SYSTEMS OVERTAKEN. BYPASSING PRIMARY FIREWALL.") sleep(300) // Hack all APCs, including those built during hack sequence. - for(var/obj/machinery/power/apc/A in machines) + for(var/obj/machinery/power/apc/A in GLOB.apcs) if((!A.hacker || A.hacker != src) && !A.aidisabled && A.z in using_map.station_levels) A.ai_hack(src) diff --git a/code/modules/admin/verbs/debug.dm b/code/modules/admin/verbs/debug.dm index cc94db2f1d..dc5c10b964 100644 --- a/code/modules/admin/verbs/debug.dm +++ b/code/modules/admin/verbs/debug.dm @@ -345,7 +345,7 @@ if(!(A.type in areas_all)) areas_all.Add(A.type) - for(var/obj/machinery/power/apc/APC in machines) + for(var/obj/machinery/power/apc/APC in GLOB.apcs) var/area/A = get_area(APC) if(A && !(A.type in areas_with_APC)) areas_with_APC.Add(A.type) diff --git a/code/modules/events/electrical_storm.dm b/code/modules/events/electrical_storm.dm index c8ecbad8d4..6b2998c2b3 100644 --- a/code/modules/events/electrical_storm.dm +++ b/code/modules/events/electrical_storm.dm @@ -28,7 +28,7 @@ /datum/event/electrical_storm/start() ..() valid_apcs = list() - for(var/obj/machinery/power/apc/A in global.machines) + for(var/obj/machinery/power/apc/A in GLOB.apcs) if(A.z in affecting_z) valid_apcs.Add(A) endWhen = (severity * 60) + startWhen diff --git a/code/modules/events/ion_storm.dm b/code/modules/events/ion_storm.dm index 5ac9dfda17..3003654078 100644 --- a/code/modules/events/ion_storm.dm +++ b/code/modules/events/ion_storm.dm @@ -199,14 +199,14 @@ Would like to add a law like "Law x is _______" where x = a number, and _____ is spawn(0) to_world("Started processing APCs") - for (var/obj/machinery/power/apc/APC in machines) + for (var/obj/machinery/power/apc/APC in GLOB.apcs) if(APC.z in station_levels) APC.ion_act() apcnum++ to_world("Finished processing APCs. Processed: [apcnum]") spawn(0) to_world("Started processing SMES") - for (var/obj/machinery/power/smes/SMES in machines) + for (var/obj/machinery/power/smes/SMES in GLOB.smeses) if(SMES.z in station_levels) SMES.ion_act() smesnum++ diff --git a/code/modules/gamemaster/event2/events/everyone/electrical_fault.dm b/code/modules/gamemaster/event2/events/everyone/electrical_fault.dm index 6467646f1b..0645d2cfe3 100644 --- a/code/modules/gamemaster/event2/events/everyone/electrical_fault.dm +++ b/code/modules/gamemaster/event2/events/everyone/electrical_fault.dm @@ -38,7 +38,7 @@ valid_z_levels -= using_map.sealed_levels // Space levels only please! valid_apcs = list() - for(var/obj/machinery/power/apc/A in global.machines) + for(var/obj/machinery/power/apc/A in GLOB.apcs) if(A.z in valid_z_levels) valid_apcs += A diff --git a/code/modules/modular_computers/file_system/programs/engineering/rcon_console.dm b/code/modules/modular_computers/file_system/programs/engineering/rcon_console.dm index 7603b1115e..03f69cd949 100644 --- a/code/modules/modular_computers/file_system/programs/engineering/rcon_console.dm +++ b/code/modules/modular_computers/file_system/programs/engineering/rcon_console.dm @@ -126,7 +126,7 @@ var/z = get_z(nano_host()) var/list/map_levels = using_map.get_map_levels(z) - for(var/obj/machinery/power/smes/buildable/SMES in machines) + for(var/obj/machinery/power/smes/buildable/SMES in GLOB.smeses) if(!(SMES.z in map_levels)) continue if(SMES.RCon_tag && (SMES.RCon_tag != "NO_TAG") && SMES.RCon) diff --git a/code/modules/power/apc.dm b/code/modules/power/apc.dm index 33228c52f5..48ea5f17fa 100644 --- a/code/modules/power/apc.dm +++ b/code/modules/power/apc.dm @@ -1,3 +1,5 @@ +GLOBAL_LIST_EMPTY(apcs) + #define CRITICAL_APC_EMP_PROTECTION 10 // EMP effect duration is divided by this number if the APC has "critical" flag //update_state #define UPDATE_CELL_IN 1 @@ -169,6 +171,7 @@ /obj/machinery/power/apc/New(turf/loc, var/ndir, var/building=0) ..() wires = new(src) + GLOB.apcs += src // offset 24 pixels in direction of dir // this allows the APC to be embedded in a wall, yet still inside an area @@ -189,6 +192,7 @@ src.update_icon() /obj/machinery/power/apc/Destroy() + GLOB.apcs -= src src.update() area.apc = null area.power_light = 0 diff --git a/code/modules/power/smes.dm b/code/modules/power/smes.dm index 10424cee18..e79474b3a0 100644 --- a/code/modules/power/smes.dm +++ b/code/modules/power/smes.dm @@ -1,6 +1,8 @@ // the SMES // stores power +GLOBAL_LIST_EMPTY(smeses) + #define SMESMAXCHARGELEVEL 250000 #define SMESMAXOUTPUT 250000 @@ -65,6 +67,7 @@ /obj/machinery/power/smes/Initialize() . = ..() + GLOB.smeses += src for(var/d in GLOB.cardinal) var/turf/T = get_step(src, d) for(var/obj/machinery/power/terminal/term in T) @@ -85,6 +88,7 @@ for(var/obj/machinery/power/terminal/T in terminals) T.master = null terminals = null + GLOB.smeses -= src return ..() /obj/machinery/power/smes/add_avail(var/amount) diff --git a/code/modules/power/supermatter/supermatter.dm b/code/modules/power/supermatter/supermatter.dm index 621cdcba0b..3d651a2a0f 100644 --- a/code/modules/power/supermatter/supermatter.dm +++ b/code/modules/power/supermatter/supermatter.dm @@ -183,7 +183,7 @@ to_chat(mob, "An invisible force slams you against the ground!") // Effect 2: Z-level wide electrical pulse - for(var/obj/machinery/power/apc/A in machines) + for(var/obj/machinery/power/apc/A in GLOB.apcs) if(!(A.z in affected_z)) continue diff --git a/code/modules/xenoarcheaology/effects/cellcharge.dm b/code/modules/xenoarcheaology/effects/cellcharge.dm index 2a819bcadd..b5c8e6224b 100644 --- a/code/modules/xenoarcheaology/effects/cellcharge.dm +++ b/code/modules/xenoarcheaology/effects/cellcharge.dm @@ -6,7 +6,7 @@ /datum/artifact_effect/cellcharge/DoEffectTouch(var/mob/user) if(user) - if(istype(user, /mob/living/silicon/robot)) + if(isrobot(user)) var/mob/living/silicon/robot/R = user for (var/obj/item/weapon/cell/D in R.contents) D.charge += rand() * 100 + 50 @@ -16,12 +16,24 @@ /datum/artifact_effect/cellcharge/DoEffectAura() if(holder) var/turf/T = get_turf(holder) - for (var/obj/machinery/power/apc/C in range(200, T)) + for (var/obj/machinery/power/apc/C in GLOB.apcs) + if(T.z != C.z) + continue + if(get_dist(T, C) > 200) + continue for (var/obj/item/weapon/cell/B in C.contents) B.charge += 25 - for (var/obj/machinery/power/smes/S in range (src.effectrange,src)) + for (var/obj/machinery/power/smes/S in GLOB.smeses) + if(T.z != S.z) + continue + if(get_dist(T, S) > src.effectrange) + continue S.charge += 25 - for (var/mob/living/silicon/robot/M in range(50, T)) + for (var/mob/living/silicon/robot/M in silicon_mob_list) + if(T.z != M.z) + continue + if(get_dist(T, M) > 50) + continue for (var/obj/item/weapon/cell/D in M.contents) D.charge += 25 if(world.time - last_message > 200) @@ -32,12 +44,24 @@ /datum/artifact_effect/cellcharge/DoEffectPulse() if(holder) var/turf/T = get_turf(holder) - for (var/obj/machinery/power/apc/C in range(200, T)) + for (var/obj/machinery/power/apc/C in GLOB.apcs) + if(T.z != C.z) + continue + if(get_dist(T, C) > 200) + continue for (var/obj/item/weapon/cell/B in C.contents) B.charge += rand() * 100 - for (var/obj/machinery/power/smes/S in range (src.effectrange,src)) + for (var/obj/machinery/power/smes/S in GLOB.smeses) + if(T.z != S.z) + continue + if(get_dist(T, S) > src.effectrange) + continue S.charge += 250 - for (var/mob/living/silicon/robot/M in range(100, T)) + for (var/mob/living/silicon/robot/M in silicon_mob_list) + if(T.z != M.z) + continue + if(get_dist(T, M) > 100) + continue for (var/obj/item/weapon/cell/D in M.contents) D.charge += rand() * 100 if(world.time - last_message > 200) diff --git a/code/modules/xenoarcheaology/effects/celldrain.dm b/code/modules/xenoarcheaology/effects/celldrain.dm index 20d707d9de..ee279032ec 100644 --- a/code/modules/xenoarcheaology/effects/celldrain.dm +++ b/code/modules/xenoarcheaology/effects/celldrain.dm @@ -18,12 +18,24 @@ /datum/artifact_effect/celldrain/DoEffectAura() if(holder) var/turf/T = get_turf(holder) - for (var/obj/machinery/power/apc/C in range(200, T)) + for (var/obj/machinery/power/apc/C in GLOB.apcs) + if(T.z != C.z) + continue + if(get_dist(T, C) > 200) + continue for (var/obj/item/weapon/cell/B in C.contents) B.charge = max(B.charge - 50,0) - for (var/obj/machinery/power/smes/S in range (src.effectrange,src)) + for (var/obj/machinery/power/smes/S in GLOB.smeses) + if(T.z != S.z) + continue + if(get_dist(T, S) > src.effectrange) + continue S.charge = max(S.charge - 100,0) - for (var/mob/living/silicon/robot/M in range(50, T)) + for (var/mob/living/silicon/robot/M in silicon_mob_list) + if(T.z != M.z) + continue + if(get_dist(T, M) > 50) + continue for (var/obj/item/weapon/cell/D in M.contents) D.charge = max(D.charge - 50,0) if(world.time - last_message > 200) @@ -34,12 +46,24 @@ /datum/artifact_effect/celldrain/DoEffectPulse() if(holder) var/turf/T = get_turf(holder) - for (var/obj/machinery/power/apc/C in range(200, T)) + for (var/obj/machinery/power/apc/C in GLOB.apcs) + if(T.z != C.z) + continue + if(get_dist(T, C) > 200) + continue for (var/obj/item/weapon/cell/B in C.contents) B.charge = max(B.charge - rand() * 150,0) - for (var/obj/machinery/power/smes/S in range (src.effectrange,src)) + for (var/obj/machinery/power/smes/S in GLOB.smeses) + if(T.z != S.z) + continue + if(get_dist(T, S) > src.effectrange) + continue S.charge = max(S.charge - 250,0) - for (var/mob/living/silicon/robot/M in range(100, T)) + for (var/mob/living/silicon/robot/M in silicon_mob_list) + if(T.z != M.z) + continue + if(get_dist(T, M) > 100) + continue for (var/obj/item/weapon/cell/D in M.contents) D.charge = max(D.charge - rand() * 150,0) if(world.time - last_message > 200)