Put APCs and SMESes into GLOB lists to ease iteration

This commit is contained in:
Aronai Sieyes
2020-05-11 22:05:41 -04:00
parent 9c6aeb6aa0
commit 96da7be01b
18 changed files with 92 additions and 36 deletions

View File

@@ -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

View File

@@ -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()

View File

@@ -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)

View File

@@ -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++

View File

@@ -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

View File

@@ -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)

View File

@@ -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<6C>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<6C>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.

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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++

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -183,7 +183,7 @@
to_chat(mob, "<span class='danger'>An invisible force slams you against the ground!</span>")
// 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

View File

@@ -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)

View File

@@ -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)