Moves get_area to a macro (#24712)

* Moves get_area to a macro

* fixes

* Update code/game/machinery/camera/camera.dm

Co-authored-by: Charlie Nolan <funnyman3595@gmail.com>

* runtime fix

* moer fix

---------

Co-authored-by: Charlie Nolan <funnyman3595@gmail.com>
This commit is contained in:
GDN
2024-04-08 16:42:22 -05:00
committed by GitHub
parent 744d9c6bed
commit b6be540b43
18 changed files with 72 additions and 60 deletions
+3
View File
@@ -138,6 +138,9 @@
#define MIN_SUPPLIED_LAW_NUMBER 15
#define MAX_SUPPLIED_LAW_NUMBER 50
/// Grabs the area of a supplied object. Passing an area in to this will result in an error
#define get_area(T) ((get_step(T, 0).loc))
//check_target_facings() return defines
#define FACING_FAILED 0
#define FACING_SAME_DIR 1
+2 -11
View File
@@ -1,10 +1,3 @@
/proc/get_area(atom/A)
RETURN_TYPE(/area)
if(isarea(A))
return A
var/turf/T = get_turf(A)
return T ? T.loc : null
/proc/get_area_name(atom/X, format_text = FALSE)
var/area/A = isarea(X) ? X : get_area(X)
if(!A)
@@ -403,23 +396,21 @@
/proc/mobs_in_area(area/the_area, client_needed=0, moblist=GLOB.mob_list)
var/list/mobs_found[0]
var/area/our_area = get_area(the_area)
for(var/mob/M in moblist)
if(client_needed && !M.client)
continue
if(our_area != get_area(M))
if(the_area != get_area(M))
continue
mobs_found += M
return mobs_found
/proc/alone_in_area(area/the_area, mob/must_be_alone, check_type = /mob/living/carbon)
var/area/our_area = get_area(the_area)
for(var/C in GLOB.alive_mob_list)
if(!istype(C, check_type))
continue
if(C == must_be_alone)
continue
if(our_area == get_area(C))
if(the_area == get_area(C))
return 0
return 1
+5 -1
View File
@@ -307,7 +307,11 @@
var/loglevel = ATKLOG_MOST
if(!isnull(custom_level))
loglevel = custom_level
var/area/A = get_area(MT)
var/area/A
if(isatom(MT) && !QDELETED(MT))
A = get_area(MT)
else
A = get_area(user)
if(A && A.hide_attacklogs)
loglevel = ATKLOG_ALL
else if(istype(MT))
+2 -1
View File
@@ -63,7 +63,8 @@ SUBSYSTEM_DEF(afk)
After being AFK for another [GLOB.configuration.afk.auto_despawn_minutes] minutes you will be fully despawned. \
Please eject yourself (right click, eject) out of the cryostorage if you want to avoid being despawned.</span>")
else
message_admins("[key_name_admin(H)] at ([get_area(T).name] [ADMIN_JMP(T)]) is AFK for [mins_afk] and can't be automatically cryod due to it's antag status: ([H.mind.special_role]).")
var/area/our_area = get_area(T)
message_admins("[key_name_admin(H)] at ([our_area.name] [ADMIN_JMP(T)]) is AFK for [mins_afk] and can't be automatically cryod due to it's antag status: ([H.mind.special_role]).")
afk_players[H.ckey] = AFK_ADMINS_WARNED
else if(afk_players[H.ckey] != AFK_ADMINS_WARNED && mins_afk >= GLOB.configuration.afk.auto_despawn_minutes)
+1 -1
View File
@@ -110,7 +110,7 @@
/datum/weather/proc/can_weather_act(mob/living/L) //Can this weather impact a mob?
var/turf/mob_turf = get_turf(L)
if(!istype(L))
if(!istype(L) || !mob_turf)
return FALSE
if(mob_turf && !(mob_turf.z in impacted_z_levels))
return FALSE
+3 -1
View File
@@ -508,7 +508,9 @@
/proc/has_gravity(atom/AT, turf/T)
if(!T)
T = get_turf(AT)
T = get_turf(AT) // If we still don't have a turf, don't process the other stuff
if(!T)
return
var/area/A = get_area(T)
if(isspaceturf(T)) // Turf never has gravity
return 0
+2
View File
@@ -100,6 +100,8 @@ GLOBAL_VAR(scoreboard) // Variable to save the scoreboard string once it's been
var/mob/M = _I
if(is_station_level(M.z))
check_station_player(M)
else if(!M.loc)
stack_trace("[M] ended up without a location!")
else if(SSshuttle.emergency.mode >= SHUTTLE_ENDGAME && istype(get_area(M), SSshuttle.emergency.areaInstance))
check_shuttle_player(M)
+10 -6
View File
@@ -50,7 +50,8 @@
if(part_of_camera_network)
GLOB.cameranet.addCamera(src)
if(isturf(loc))
LAZYADD(get_area(src).cameras, UID())
var/area/our_area = get_area(src)
LAZYADD(our_area.cameras, UID())
if(is_station_level(z) && prob(3) && !start_active)
turn_off(null, FALSE)
wires.cut_all()
@@ -68,8 +69,9 @@
QDEL_NULL(assembly)
QDEL_NULL(wires)
GLOB.cameranet.cameras -= src
if(isarea(get_area(src)))
LAZYREMOVE(get_area(src).cameras, UID())
var/area/our_area = get_area(src)
if(our_area) // We should probably send out the warning alarms if this doesn't exist, because this should always have an area!
LAZYREMOVE(our_area.cameras, UID())
var/area/station/ai_monitored/A = get_area(src)
if(istype(A))
A.motioncameras -= src
@@ -271,7 +273,8 @@
return
status = TRUE
if(!emp_recover && isturf(loc))
LAZYADD(get_area(src).cameras, UID())
var/area/our_area = get_area(src)
LAZYADD(our_area.cameras, UID())
if(display_message)
if(user)
@@ -289,8 +292,9 @@
if(!emped)
status = FALSE
if(isarea(get_area(src)))
LAZYREMOVE(get_area(src).cameras, UID())
var/area/our_area = get_area(src)
if(our_area)
LAZYREMOVE(our_area.cameras, UID())
set_light(0)
@@ -327,7 +327,8 @@ GLOBAL_LIST_EMPTY(gas_sensors)
for(var/obj/machinery/atmospherics/unary/vent_pump/VP as anything in GLOB.all_vent_pumps)
if(VP.autolink_id == outlet_vent_autolink_id)
outlet_vent_uid = VP.UID()
get_area(VP).vents -= VP
var/area/our_area = get_area(src)
our_area.vents -= VP
VP.on = TRUE
VP.releasing = FALSE
VP.internal_pressure_bound = outlet_setting
@@ -404,7 +405,8 @@ GLOBAL_LIST_EMPTY(gas_sensors)
outlet_vent_uid = linked_datum.UID() // Make sure the multitool ref didnt change while they had the menu open
var/obj/machinery/atmospherics/unary/vent_pump/VP = linked_datum
// Setup some defaults
get_area(VP).vents -= VP
var/area/our_area = get_area(src)
our_area.vents -= VP
VP.on = TRUE
VP.releasing = FALSE
VP.internal_pressure_bound = outlet_setting
+2 -1
View File
@@ -249,7 +249,8 @@
find_control_computer()
/obj/machinery/cryopod/proc/find_control_computer(urgent=0)
for(var/obj/machinery/computer/cryopod/C in get_area(src).contents)
var/area/our_area = get_area(src)
for(var/obj/machinery/computer/cryopod/C in our_area)
if(C.type == console_type)
control_computer = C
break
+6 -3
View File
@@ -46,7 +46,8 @@ FIRE ALARM
setDir(direction)
set_pixel_offsets_from_dir(26, -26, 26, -26)
LAZYADD(get_area(src).firealarms, src)
var/area/our_area = get_area(src)
LAZYADD(our_area.firealarms, src)
if(is_station_contact(z))
RegisterSignal(SSsecurity_level, COMSIG_SECURITY_LEVEL_CHANGED, PROC_REF(on_security_level_update))
@@ -228,7 +229,8 @@ FIRE ALARM
/obj/machinery/firealarm/obj_break(damage_flag)
if(!(stat & BROKEN) && !(flags & NODECONSTRUCT) && buildstage != 0) //can't break the electronics if there isn't any inside.
stat |= BROKEN
LAZYREMOVE(get_area(src).firealarms, src)
var/area/our_area = get_area(src)
LAZYREMOVE(our_area.firealarms, src)
update_icon()
/obj/machinery/firealarm/deconstruct(disassembled = TRUE)
@@ -330,7 +332,8 @@ FIRE ALARM
/obj/machinery/firealarm/Destroy()
LAZYREMOVE(GLOB.firealarm_soundloop.output_atoms, src)
LAZYREMOVE(get_area(src).firealarms, src)
var/area/our_area = get_area(src)
LAZYREMOVE(our_area.firealarms, src)
return ..()
/*
+6 -4
View File
@@ -31,7 +31,8 @@
if(stat & NOPOWER)
icon_state = "light-p"
return
icon_state = "light[get_area(src).lightswitch]"
var/area/our_area = get_area(src)
icon_state = "light[our_area.lightswitch]"
/obj/machinery/light_switch/update_overlays()
. = ..()
@@ -39,13 +40,14 @@
if(stat & NOPOWER)
return
. += "light[get_area(src).lightswitch]"
var/area/our_area = get_area(src)
. += "light[our_area.lightswitch]"
underlays += emissive_appearance(icon, "light_lightmask")
/obj/machinery/light_switch/examine(mob/user)
. = ..()
. += "<span class='notice'>It is [get_area(src).lightswitch ? "on" : "off"].</span>"
var/area/our_area = get_area(src)
. += "<span class='notice'>It is [our_area.lightswitch ? "on" : "off"].</span>"
/obj/machinery/light_switch/attack_ghost(mob/user)
if(user.can_advanced_admin_interact())
+1 -2
View File
@@ -93,8 +93,7 @@
data["teleporterhub"] = null
data["calibrated"] = null
data["regime"] = regime
var/area/targetarea = get_area(target)
data["target"] = (!target || !targetarea) ? "None" : sanitize(targetarea.name)
data["target"] = (!target || !get_turf(target)) ? "None" : sanitize(get_area(target))
data["calibrating"] = calibrating
data["locked"] = locked ? TRUE : FALSE
data["targetsTeleport"] = null
+16 -21
View File
@@ -55,9 +55,9 @@
/obj/item/areaeditor/permit/attack_self(mob/user)
. = ..()
var/area/A = get_area()
var/area/our_area = get_area(src)
if(get_area_type() == AREA_STATION)
. += "<p>According to [src], you are now in <b>\"[sanitize(A.name)]\"</b>.</p>"
. += "<p>According to [src], you are now in <b>\"[sanitize(our_area.name)]\"</b>.</p>"
var/datum/browser/popup = new(user, "blueprints", "[src]", 700, 500)
popup.set_content(.)
popup.open()
@@ -77,9 +77,9 @@
/obj/item/areaeditor/golem/attack_self(mob/user)
. = ..()
var/area/A = get_area()
var/area/our_area = get_area(src)
if(get_area_type() == AREA_STATION)
. += "<p>According to [src], you are now in <b>\"[sanitize(A.name)]\"</b>.</p>"
. += "<p>According to [src], you are now in <b>\"[sanitize(our_area.name)]\"</b>.</p>"
var/datum/browser/popup = new(user, "blueprints", "[src]", 700, 500)
popup.set_content(.)
popup.open()
@@ -104,9 +104,9 @@
/obj/item/areaeditor/blueprints/attack_self(mob/user)
. = ..()
var/area/A = get_area()
var/area/our_area = get_area(src)
if(get_area_type() == AREA_STATION)
. += "<p>According to [src], you are now in <b>\"[sanitize(A.name)]\"</b>.</p>"
. += "<p>According to [src], you are now in <b>\"[sanitize(our_area.name)]\"</b>.</p>"
. += "<p>You may <a href='?src=[UID()];edit_area=1'> move an amendment</a> to the drawing.</p>"
if(!viewing)
. += "<p><a href='?src=[UID()];view_blueprints=1'>View structural data</a></p>"
@@ -166,13 +166,9 @@
..()
clear_viewer()
/obj/item/areaeditor/proc/get_area()
var/turf/T = get_turf(usr)
var/area/A = T.loc
return A
/obj/item/areaeditor/proc/get_area_type(area/A = get_area())
/obj/item/areaeditor/proc/get_area_type(area/A)
if(!A)
A = get_area(src)
if(A.outdoors)
return AREA_SPACE
var/list/SPECIALS = list(
@@ -234,23 +230,22 @@
return area_created
/obj/item/areaeditor/proc/edit_area()
var/area/A = get_area()
var/prevname = "[sanitize(A.name)]"
var/area/our_area = get_area(src)
var/prevname = "[sanitize(our_area.name)]"
var/str = tgui_input_text(usr, "New area name:", "Blueprint Editing", prevname, MAX_NAME_LEN, encode = FALSE)
if(!str || !length(str) || str == prevname) // Cancel
return
set_area_machinery_title(A,str,prevname)
A.name = str
if(A.firedoors)
for(var/D in A.firedoors)
set_area_machinery_title(our_area, str, prevname)
our_area.name = str
if(our_area.firedoors)
for(var/D in our_area.firedoors)
var/obj/machinery/door/firedoor/FD = D
FD.CalculateAffectingAreas()
to_chat(usr, "<span class='notice'>You rename the '[prevname]' to '[str]'.</span>")
interact()
message_admins("A room was renamed by [key_name_admin(usr)] at [ADMIN_VERBOSEJMP(usr)] changing the name from [prevname] to [str]")
log_game("A room was renamed by [key_name(usr)] at [AREACOORD(usr)] changing the name from [prevname] to [str] ")
return 1
return TRUE
/obj/item/areaeditor/proc/set_area_machinery_title(area/A, title, oldtitle)
if(!oldtitle) // or replacetext goes to infinite loop
@@ -245,9 +245,9 @@
underlays += emissive_appearance(icon, "intercom_lightmask")
/obj/item/radio/intercom/proc/update_operating_status(on = TRUE)
var/area/current_area = get_area(src)
if(!current_area)
if(!loc) // We init a few radios in nullspace to prevent them from needing power.
return
var/area/current_area = get_area(src)
if(on)
RegisterSignal(current_area.powernet, COMSIG_POWERNET_POWER_CHANGE, PROC_REF(local_powernet_check))
else
@@ -266,7 +266,7 @@ GLOBAL_LIST_EMPTY(deadsay_radio_systems)
connection = radio_connection
channel = null
if(is_type_in_list(get_area(src), blacklisted_areas))
if(loc && is_type_in_list(get_area(src), blacklisted_areas))
// add a debug log so people testing things won't be fighting against a "broken" radio for too long.
log_debug("Radio message from [src] was used in restricted area [get_area(src)].")
return
+4 -2
View File
@@ -233,7 +233,8 @@
for(var/mob/living/simple_animal/bot/B in bots)
botsCount++
if(B.loc)
botsData[++botsData.len] = list("Name" = sanitize(B.name), "Location" = sanitize(get_area(B).name), "uid" = "[B.UID()]")
var/area/our_area = get_area(B)
botsData[++botsData.len] = list("Name" = sanitize(B.name), "Location" = sanitize(our_area.name), "uid" = "[B.UID()]")
if(!length(botsData))
botsData[++botsData.len] = list("Name" = "No bots found", "Location" = "Invalid", "uid"= null)
@@ -309,7 +310,8 @@
for(var/mob/living/simple_animal/bot/mulebot/B in GLOB.bots_list)
mulebotsCount++
if(B.loc)
mulebotsData[++mulebotsData.len] = list("Name" = sanitize(B.name), "Location" = get_area(B).name, "uid" = "[B.UID()]")
var/area/our_area = get_area(B)
mulebotsData[++mulebotsData.len] = list("Name" = sanitize(B.name), "Location" = our_area.name, "uid" = "[B.UID()]")
if(!mulebotsData.len)
mulebotsData[++mulebotsData.len] = list("Name" = "No bots found", "Location" = "Invalid", "uid"= null)
+2 -1
View File
@@ -401,7 +401,8 @@
input_level--
update_icon()
if(prob(input_level - safe_levels + (emagged * 5))) //at dangerous levels, start doing freaky shit. prob with values less than 0 treat it as 0
GLOB.major_announcement.Announce("Unexpected power spike during Bluespace Harvester Operation. Extra-dimensional intruder alert. Expected location: [get_area(src).name]. [emagged ? "DANGER: Emergency shutdown failed! Please proceed with manual shutdown." : "Emergency shutdown initiated."]", "Bluespace Harvester Malfunction", 'sound/AI/harvester.ogg')
var/area/our_area = get_area(src)
GLOB.major_announcement.Announce("Unexpected power spike during Bluespace Harvester Operation. Extra-dimensional intruder alert. Expected location: [our_area.name]. [emagged ? "DANGER: Emergency shutdown failed! Please proceed with manual shutdown." : "Emergency shutdown initiated."]", "Bluespace Harvester Malfunction", 'sound/AI/harvester.ogg')
if(!emagged)
input_level = 0 //emergency shutdown unless we're sabotaged
desired_level = 0