From 9ea748b1309c1b83e985642c6ac71cf8637ff202 Mon Sep 17 00:00:00 2001 From: SteelSlayer <42044220+SteelSlayer@users.noreply.github.com> Date: Fri, 26 Jun 2020 02:19:27 -0500 Subject: [PATCH] Mountable frame bugfixes and minor refactor (#13076) * initial * bit of code cleanup / refactoring * review changes * CRLF to LF * GLOB stuff * travis did not like that Co-authored-by: SteelSlayer --- code/game/atoms.dm | 28 +++++++++++++++++++ code/game/machinery/alarm.dm | 11 ++++---- code/game/machinery/defib_mount.dm | 7 ++--- code/game/machinery/doors/brigdoors.dm | 3 +- code/game/machinery/firealarm.dm | 6 ++-- .../objects/items/devices/radio/intercom.dm | 13 ++++----- .../items/mountable_frames/fire_alarm.dm | 2 +- code/game/objects/structures/extinguisher.dm | 11 ++++---- code/modules/power/apc.dm | 11 ++++---- 9 files changed, 57 insertions(+), 35 deletions(-) diff --git a/code/game/atoms.dm b/code/game/atoms.dm index f089ddb0a87..5d3c6d688ac 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -158,6 +158,34 @@ SEND_SIGNAL(src, COMSIG_ATOM_DIR_CHANGE, dir, newdir) dir = newdir +/* + Sets the atom's pixel locations based on the atom's `dir` variable, and what pixel offset arguments are passed into it + If no arguments are supplied, `pixel_x` or `pixel_y` will be set to 0 + Used primarily for when players attach mountable frames to walls (APC frame, fire alarm frame, etc.) +*/ +/atom/proc/set_pixel_offsets_from_dir(pixel_north = 0, pixel_south = 0, pixel_east = 0, pixel_west = 0) + switch(dir) + if(NORTH) + pixel_y = pixel_north + if(SOUTH) + pixel_y = pixel_south + if(EAST) + pixel_x = pixel_east + if(WEST) + pixel_x = pixel_west + if(NORTHEAST) + pixel_y = pixel_north + pixel_x = pixel_east + if(NORTHWEST) + pixel_y = pixel_north + pixel_x = pixel_west + if(SOUTHEAST) + pixel_y = pixel_south + pixel_x = pixel_east + if(SOUTHWEST) + pixel_y = pixel_south + pixel_x = pixel_west + ///Handle melee attack by a mech /atom/proc/mech_melee_attack(obj/mecha/M) return diff --git a/code/game/machinery/alarm.dm b/code/game/machinery/alarm.dm index d71c4e7674d..6174f4a497d 100644 --- a/code/game/machinery/alarm.dm +++ b/code/game/machinery/alarm.dm @@ -199,8 +199,8 @@ mode = AALARM_MODE_REPLACEMENT apply_mode() -/obj/machinery/alarm/New(var/loc, var/dir, var/building = 0) - ..() +/obj/machinery/alarm/New(loc, direction, building = 0) + . = ..() GLOB.air_alarms += src GLOB.air_alarms = sortAtom(GLOB.air_alarms) @@ -211,12 +211,11 @@ src.loc = loc if(dir) - src.dir = dir + setDir(direction) buildstage = 0 wiresexposed = 1 - pixel_x = (dir & 3)? 0 : (dir == 4 ? -24 : 24) - pixel_y = (dir & 3)? (dir ==1 ? -24 : 24) : 0 + set_pixel_offsets_from_dir(-24, 24, -24, 24) update_icon() return @@ -251,7 +250,7 @@ /obj/machinery/alarm/proc/master_is_operating() if(!alarm_area) - alarm_area = areaMaster + alarm_area = get_area(src) if(!alarm_area) log_runtime(EXCEPTION("Air alarm /obj/machinery/alarm lacks alarm_area and areaMaster vars during proc/master_is_operating()"), src) return FALSE diff --git a/code/game/machinery/defib_mount.dm b/code/game/machinery/defib_mount.dm index 9ee32716e53..79d02155832 100644 --- a/code/game/machinery/defib_mount.dm +++ b/code/game/machinery/defib_mount.dm @@ -29,11 +29,10 @@ loc = location if(direction) - dir = direction + setDir(direction) if(building) - pixel_x = (dir & 3)? 0 : (dir == 4 ? -30 : 30) - pixel_y = (dir & 3)? (dir == 1 ? -30 : 30) : 0 + set_pixel_offsets_from_dir(30, -30, 30, -30) /obj/machinery/defibrillator_mount/loaded/New() //loaded subtype for mapping use ..() @@ -157,6 +156,6 @@ w_class = WEIGHT_CLASS_BULKY /obj/item/mounted/frame/defib_mount/do_build(turf/on_wall, mob/user) - new /obj/machinery/defibrillator_mount(get_turf(src), get_dir(on_wall, user), 1) + new /obj/machinery/defibrillator_mount(get_turf(src), get_dir(user, on_wall), 1) playsound(src, 'sound/machines/click.ogg', 50, TRUE) qdel(src) diff --git a/code/game/machinery/doors/brigdoors.dm b/code/game/machinery/doors/brigdoors.dm index 1b9847c09db..9970974e4ff 100644 --- a/code/game/machinery/doors/brigdoors.dm +++ b/code/game/machinery/doors/brigdoors.dm @@ -137,8 +137,7 @@ Radio.config(list("Security" = 0)) Radio.follow_target = src - pixel_x = ((dir & 3)? (0) : (dir == 4 ? 32 : -32)) - pixel_y = ((dir & 3)? (dir ==1 ? 32 : -32) : (0)) + set_pixel_offsets_from_dir(32, -32, 32, -32) spawn(20) for(var/obj/machinery/door/window/brigdoor/M in GLOB.airlocks) diff --git a/code/game/machinery/firealarm.dm b/code/game/machinery/firealarm.dm index 9beba3f4789..f12361f1664 100644 --- a/code/game/machinery/firealarm.dm +++ b/code/game/machinery/firealarm.dm @@ -309,13 +309,13 @@ FIRE ALARM update_icon() /obj/machinery/firealarm/New(location, direction, building) - ..() + . = ..() if(building) buildstage = 0 wiresexposed = TRUE - pixel_x = (dir & 3)? 0 : (dir == 4 ? -24 : 24) - pixel_y = (dir & 3)? (dir ==1 ? -24 : 24) : 0 + setDir(direction) + set_pixel_offsets_from_dir(26, -26, 26, -26) if(is_station_contact(z) && show_alert_level) if(GLOB.security_level) diff --git a/code/game/objects/items/devices/radio/intercom.dm b/code/game/objects/items/devices/radio/intercom.dm index 13c97f26730..59d2c2a99bd 100644 --- a/code/game/objects/items/devices/radio/intercom.dm +++ b/code/game/objects/items/devices/radio/intercom.dm @@ -46,16 +46,15 @@ name = "station intercom (Security)" frequency = SEC_I_FREQ -/obj/item/radio/intercom/New(turf/loc, ndir, building = 3) - ..() +/obj/item/radio/intercom/New(turf/loc, direction, building = 3) + . = ..() buildstage = building if(buildstage) START_PROCESSING(SSobj, src) else - if(ndir) - pixel_x = (ndir & EAST|WEST) ? (ndir == EAST ? 28 : -28) : 0 - pixel_y = (ndir & NORTH|SOUTH) ? (ndir == NORTH ? 28 : -28) : 0 - dir=ndir + if(direction) + setDir(direction) + set_pixel_offsets_from_dir(28, -28, 28, -28) b_stat=1 on = 0 GLOB.global_intercoms.Add(src) @@ -204,7 +203,7 @@ STOP_PROCESSING(SSobj, src) /obj/item/radio/intercom/welder_act(mob/user, obj/item/I) - if(!buildstage) + if(buildstage != 0) return . = TRUE if(!I.tool_use_check(user, 3)) diff --git a/code/game/objects/items/mountable_frames/fire_alarm.dm b/code/game/objects/items/mountable_frames/fire_alarm.dm index 83f435a277c..22c526664aa 100644 --- a/code/game/objects/items/mountable_frames/fire_alarm.dm +++ b/code/game/objects/items/mountable_frames/fire_alarm.dm @@ -6,5 +6,5 @@ mount_reqs = list("simfloor", "nospace") /obj/item/mounted/frame/firealarm/do_build(turf/on_wall, mob/user) - new /obj/machinery/firealarm(get_turf(src), get_dir(on_wall, user), 1) + new /obj/machinery/firealarm(get_turf(src), get_dir(user, on_wall), 1) qdel(src) diff --git a/code/game/objects/structures/extinguisher.dm b/code/game/objects/structures/extinguisher.dm index 2dc0cf415cc..cd7b3525478 100644 --- a/code/game/objects/structures/extinguisher.dm +++ b/code/game/objects/structures/extinguisher.dm @@ -17,11 +17,11 @@ var/opened = 0 var/material_drop = /obj/item/stack/sheet/metal -/obj/structure/extinguisher_cabinet/New(turf/loc, ndir = null) +/obj/structure/extinguisher_cabinet/New(turf/loc, direction = null) ..() - if(ndir) - pixel_x = (ndir & EAST|WEST) ? (ndir == EAST ? 28 : -28) : 0 - pixel_y = (ndir & NORTH|SOUTH)? (ndir == WEST ? 28 : -28) : 0 + if(direction) + setDir(direction) + set_pixel_offsets_from_dir(28, -28, 30, -30) switch(extinguishertype) if(NO_EXTINGUISHER) return @@ -165,9 +165,8 @@ else icon_state = "extinguisher_empty" -/obj/structure/extinguisher_cabinet/empty/New(turf/loc, ndir = null) +/obj/structure/extinguisher_cabinet/empty extinguishertype = NO_EXTINGUISHER - ..() #undef NO_EXTINGUISHER #undef NORMAL_EXTINGUISHER diff --git a/code/modules/power/apc.dm b/code/modules/power/apc.dm index 4b8e3bd8c21..f613f34a8fd 100644 --- a/code/modules/power/apc.dm +++ b/code/modules/power/apc.dm @@ -147,7 +147,7 @@ if(terminal) terminal.connect_to_network() -/obj/machinery/power/apc/New(turf/loc, ndir, building = 0) +/obj/machinery/power/apc/New(turf/loc, direction, building = 0) if(!armor) armor = list("melee" = 20, "bullet" = 20, "laser" = 10, "energy" = 100, "bomb" = 30, "bio" = 100, "rad" = 100, "fire" = 90, "acid" = 50) ..() @@ -158,12 +158,11 @@ // offset 24 pixels in direction of dir // this allows the APC to be embedded in a wall, yet still inside an area if(building) - setDir(ndir) - tdir = dir // to fix Vars bug - setDir(SOUTH) + setDir(direction) // We set this to direction only for pixel location determination. + + set_pixel_offsets_from_dir(24, -24, 24, -24) // Set pixel offsets based on `dir` + setDir(SOUTH) // APC's should always appear to *face* south. - pixel_x = (src.tdir & 3)? 0 : (src.tdir == 4 ? 24 : -24) - pixel_y = (src.tdir & 3)? (src.tdir ==1 ? 24 : -24) : 0 if(building) area = get_area(src) area.apc |= src