diff --git a/code/game/machinery/_machinery.dm b/code/game/machinery/_machinery.dm index 849192afc5c..b78b3263e98 100644 --- a/code/game/machinery/_machinery.dm +++ b/code/game/machinery/_machinery.dm @@ -512,19 +512,24 @@ return TRUE ///Get a valid powered area to reference for power use, mainly for wall-mounted machinery that isn't always mapped directly in a powered location. -/obj/machinery/proc/get_room_area(area/machine_room) +/obj/machinery/proc/get_room_area() var/area/machine_area = get_area(src) - if(!machine_area.always_unpowered) ///check our loc first to see if its a powered area - machine_room = machine_area - return machine_room - var/turf/mounted_wall = get_step(src,dir) - if (mounted_wall && istype(mounted_wall, /turf/closed)) + if(isnull(machine_area)) + return null // ?? + + // check our own loc first to see if its a powered area + if(!machine_area.always_unpowered) + return machine_area + + // loc area wasn't good, checking adjacent wall for a good area to use + var/turf/mounted_wall = get_step(src, dir) + if(isclosedturf(mounted_wall)) var/area/wall_area = get_area(mounted_wall) - if(!wall_area.always_unpowered) //loc area wasn't good, checking adjacent wall for a good area to use - machine_room = wall_area - return machine_room - machine_room = machine_area ///couldn't find a proper powered area on loc or adjacent wall, defaulting back to loc and blaming mappers - return machine_room + if(!wall_area.always_unpowered) + return wall_area + + // couldn't find a proper powered area on loc or adjacent wall, defaulting back to loc and blaming mappers + return machine_area ///makes this machine draw power from its area according to which use_power mode it is set to /obj/machinery/proc/update_current_power_usage() diff --git a/code/modules/power/lighting/light.dm b/code/modules/power/lighting/light.dm index ed4b2159cab..3d6ec46e496 100644 --- a/code/modules/power/lighting/light.dm +++ b/code/modules/power/lighting/light.dm @@ -101,7 +101,7 @@ qdel(on_turf) if(!mapload) //sync up nightshift lighting for player made lights - var/area/our_area = get_room_area(src) + var/area/our_area = get_room_area() var/obj/machinery/power/apc/temp_apc = our_area.apc nightshift_enabled = temp_apc?.nightshift_lights @@ -131,7 +131,7 @@ update(trigger = FALSE) /obj/machinery/light/Destroy() - var/area/local_area = get_room_area(src) + var/area/local_area = get_room_area() if(local_area) on = FALSE QDEL_NULL(cell) @@ -154,7 +154,7 @@ /obj/machinery/light/update_icon_state() switch(status) // set icon_states if(LIGHT_OK) - var/area/local_area = get_area(src) + var/area/local_area = get_room_area() if(low_power_mode || major_emergency || (local_area?.fire)) icon_state = "[base_state]_emergency" else @@ -174,7 +174,7 @@ . += emissive_appearance(overlay_icon, "[base_state]", src, alpha = src.alpha) - var/area/local_area = get_room_area(src) + var/area/local_area = get_room_area() if(low_power_mode || major_emergency || (local_area?.fire)) . += mutable_appearance(overlay_icon, "[base_state]_emergency") @@ -196,7 +196,7 @@ . = ..() if(!.) return - var/area/our_area = get_room_area(src) + var/area/our_area = get_room_area() RegisterSignal(our_area, COMSIG_AREA_FIRE_CHANGED, PROC_REF(handle_fire)) /obj/machinery/light/on_enter_area(datum/source, area/area_to_register) @@ -227,7 +227,7 @@ color_set = color if(reagents) START_PROCESSING(SSmachines, src) - var/area/local_area =get_room_area(src) + var/area/local_area = get_room_area() if (local_area?.fire) color_set = fire_colour brightness_set = fire_brightness @@ -286,7 +286,7 @@ static_power_used = 0 else if(on) //Light is on, just recalculate usage var/static_power_used_new = 0 - var/area/local_area = get_room_area(src) + var/area/local_area = get_room_area() if (nightshift_enabled && !local_area?.fire) static_power_used_new = nightshift_brightness * nightshift_light_power * power_consumption_rate else @@ -475,13 +475,13 @@ // returns if the light has power /but/ is manually turned off // if a light is turned off, it won't activate emergency power /obj/machinery/light/proc/turned_off() - var/area/local_area = get_room_area(src) - return !local_area.lightswitch && local_area.power_light || flickering || constant_flickering //SKYRAT EDIT CHANGE + var/area/local_area = get_room_area() + return !local_area.lightswitch && local_area.power_light || flickering || constant_flickering //SKYRAT EDIT CHANGE - ORIGINAL : return !local_area.lightswitch && local_area.power_light || flickering // returns whether this light has power // true if area has power and lightswitch is on /obj/machinery/light/proc/has_power() - var/area/local_area =get_room_area(src) + var/area/local_area = get_room_area() //SKYRAT EDIT ADDITION BEGIN if(isnull(local_area)) return FALSE @@ -687,7 +687,7 @@ // called when area power state changes /obj/machinery/light/power_change() SHOULD_CALL_PARENT(FALSE) - var/area/local_area =get_room_area(src) + var/area/local_area = get_room_area() set_on(local_area.lightswitch && local_area.power_light) // called when heated