diff --git a/code/__DEFINES/misc_defines.dm b/code/__DEFINES/misc_defines.dm index b3bb3de5491..2429543f600 100644 --- a/code/__DEFINES/misc_defines.dm +++ b/code/__DEFINES/misc_defines.dm @@ -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 diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index 54137f7d081..99bfadbddae 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -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 diff --git a/code/__HELPERS/mob_helpers.dm b/code/__HELPERS/mob_helpers.dm index 6abb34f3423..8054554c411 100644 --- a/code/__HELPERS/mob_helpers.dm +++ b/code/__HELPERS/mob_helpers.dm @@ -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)) diff --git a/code/controllers/subsystem/SSafk.dm b/code/controllers/subsystem/SSafk.dm index 9d66631b757..b83f7d05d73 100644 --- a/code/controllers/subsystem/SSafk.dm +++ b/code/controllers/subsystem/SSafk.dm @@ -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.") 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) diff --git a/code/datums/weather/weather_datum.dm b/code/datums/weather/weather_datum.dm index f49969d69f5..adeceb51aba 100644 --- a/code/datums/weather/weather_datum.dm +++ b/code/datums/weather/weather_datum.dm @@ -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 diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 71b3b64014e..12b81b96e95 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -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 diff --git a/code/game/gamemodes/scoreboard.dm b/code/game/gamemodes/scoreboard.dm index 00fdd1e6b10..feda362192d 100644 --- a/code/game/gamemodes/scoreboard.dm +++ b/code/game/gamemodes/scoreboard.dm @@ -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) diff --git a/code/game/machinery/camera/camera.dm b/code/game/machinery/camera/camera.dm index 1cded54f77f..4902760f4b5 100644 --- a/code/game/machinery/camera/camera.dm +++ b/code/game/machinery/camera/camera.dm @@ -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) diff --git a/code/game/machinery/computer/atmos_controllers.dm b/code/game/machinery/computer/atmos_controllers.dm index 07b678b54e7..2a8286e2eaf 100644 --- a/code/game/machinery/computer/atmos_controllers.dm +++ b/code/game/machinery/computer/atmos_controllers.dm @@ -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 diff --git a/code/game/machinery/cryopod.dm b/code/game/machinery/cryopod.dm index be54c452d93..a7384e2b57e 100644 --- a/code/game/machinery/cryopod.dm +++ b/code/game/machinery/cryopod.dm @@ -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 diff --git a/code/game/machinery/firealarm.dm b/code/game/machinery/firealarm.dm index e4dfa178770..b9cafd1eb76 100644 --- a/code/game/machinery/firealarm.dm +++ b/code/game/machinery/firealarm.dm @@ -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 ..() /* diff --git a/code/game/machinery/lightswitch.dm b/code/game/machinery/lightswitch.dm index 734f85d0f5f..778be4f2648 100644 --- a/code/game/machinery/lightswitch.dm +++ b/code/game/machinery/lightswitch.dm @@ -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) . = ..() - . += "It is [get_area(src).lightswitch ? "on" : "off"]." + var/area/our_area = get_area(src) + . += "It is [our_area.lightswitch ? "on" : "off"]." /obj/machinery/light_switch/attack_ghost(mob/user) if(user.can_advanced_admin_interact()) diff --git a/code/game/machinery/teleporter.dm b/code/game/machinery/teleporter.dm index cf0e87a5228..cece7b32c0a 100644 --- a/code/game/machinery/teleporter.dm +++ b/code/game/machinery/teleporter.dm @@ -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 diff --git a/code/game/objects/items/blueprints.dm b/code/game/objects/items/blueprints.dm index 36678fa5875..7036efed4e7 100644 --- a/code/game/objects/items/blueprints.dm +++ b/code/game/objects/items/blueprints.dm @@ -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) - . += "

According to [src], you are now in \"[sanitize(A.name)]\".

" + . += "

According to [src], you are now in \"[sanitize(our_area.name)]\".

" 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) - . += "

According to [src], you are now in \"[sanitize(A.name)]\".

" + . += "

According to [src], you are now in \"[sanitize(our_area.name)]\".

" 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) - . += "

According to [src], you are now in \"[sanitize(A.name)]\".

" + . += "

According to [src], you are now in \"[sanitize(our_area.name)]\".

" . += "

You may move an amendment to the drawing.

" if(!viewing) . += "

View structural data

" @@ -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, "You rename the '[prevname]' to '[str]'.") 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 diff --git a/code/game/objects/items/devices/radio/intercom.dm b/code/game/objects/items/devices/radio/intercom.dm index 1370f1f2b42..d8ff1d46d74 100644 --- a/code/game/objects/items/devices/radio/intercom.dm +++ b/code/game/objects/items/devices/radio/intercom.dm @@ -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 diff --git a/code/game/objects/items/devices/radio/radio_objects.dm b/code/game/objects/items/devices/radio/radio_objects.dm index 6757df97d49..2f7f5e4f184 100644 --- a/code/game/objects/items/devices/radio/radio_objects.dm +++ b/code/game/objects/items/devices/radio/radio_objects.dm @@ -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 diff --git a/code/modules/pda/cart_apps.dm b/code/modules/pda/cart_apps.dm index c52d71f4886..6ec43486b6c 100644 --- a/code/modules/pda/cart_apps.dm +++ b/code/modules/pda/cart_apps.dm @@ -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) diff --git a/code/modules/station_goals/bluespace_tap.dm b/code/modules/station_goals/bluespace_tap.dm index a87db6da4c1..cfa51561e12 100644 --- a/code/modules/station_goals/bluespace_tap.dm +++ b/code/modules/station_goals/bluespace_tap.dm @@ -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