From c93da6790037a6835e2211ad648b6a3242fbddb4 Mon Sep 17 00:00:00 2001 From: Matt Atlas Date: Mon, 23 May 2022 12:42:50 +0200 Subject: [PATCH] You can now open/close doors and interact with elevator buttons/panels by clicking the tile they are on. (#14017) --- aurorastation.dme | 1 + .../datums/components/turf_click/turf_hand.dm | 19 ++++++++ code/game/machinery/doors/door.dm | 4 ++ code/game/machinery/doors/firedoor.dm | 2 + code/game/objects/structures/curtains.dm | 1 + code/game/turfs/turf.dm | 45 ++++++++++++------- code/modules/multiz/structures.dm | 2 + code/modules/turbolift/turbolift_console.dm | 7 +++ ...attatlas-thatwillbe5eurospaypalomicega.yml | 42 +++++++++++++++++ 9 files changed, 108 insertions(+), 15 deletions(-) create mode 100644 code/datums/components/turf_click/turf_hand.dm create mode 100644 html/changelogs/mattatlas-thatwillbe5eurospaypalomicega.yml diff --git a/aurorastation.dme b/aurorastation.dme index 41ce4a4cc61..c2f28f2e3c7 100644 --- a/aurorastation.dme +++ b/aurorastation.dme @@ -274,6 +274,7 @@ #include "code\datums\components\multitool\multitool.dm" #include "code\datums\components\multitool\circuitboards\circuitboards.dm" #include "code\datums\components\multitool\circuitboards\stationalert.dm" +#include "code\datums\components\turf_click\turf_hand.dm" #include "code\datums\discord\bot.dm" #include "code\datums\discord\webhook.dm" #include "code\datums\elements\_element.dm" diff --git a/code/datums/components/turf_click/turf_hand.dm b/code/datums/components/turf_click/turf_hand.dm new file mode 100644 index 00000000000..9f31948f5f8 --- /dev/null +++ b/code/datums/components/turf_click/turf_hand.dm @@ -0,0 +1,19 @@ +/* + This component is used on airlocks and cult runes. + When a mob [attack_hand]s a turf, it will look for objects in itself containing this component. + If such is found, it will call attack_hand on that atom + + When multiple of these components are in the tile, the one with the highest priority wins it. +*/ +/datum/component/turf_hand + var/priority = 1 + var/atom/our_owner + +/datum/component/turf_hand/Initialize(var/priority = 1) + ..() + if(isatom(parent)) + our_owner = parent + src.priority = priority + +/datum/component/turf_hand/proc/OnHandInterception(var/mob/user) + return our_owner.attack_hand(user) \ No newline at end of file diff --git a/code/game/machinery/doors/door.dm b/code/game/machinery/doors/door.dm index 7457b42f6d6..9071b22fa89 100644 --- a/code/game/machinery/doors/door.dm +++ b/code/game/machinery/doors/door.dm @@ -43,6 +43,8 @@ var/image/hatch_image + var/turf_hand_priority = 3 + //Multi-tile doors dir = SOUTH var/width = 1 @@ -78,6 +80,8 @@ update_nearby_tiles(need_rebuild=1) if(hashatch && !(width > 1)) setup_hatch() + if(turf_hand_priority) + AddComponent(/datum/component/turf_hand, turf_hand_priority) /obj/machinery/door/Move(new_loc, new_dir) . = ..() diff --git a/code/game/machinery/doors/firedoor.dm b/code/game/machinery/doors/firedoor.dm index 095a6f013c1..a495a1e2e35 100644 --- a/code/game/machinery/doors/firedoor.dm +++ b/code/game/machinery/doors/firedoor.dm @@ -40,6 +40,8 @@ idle_power_usage = 5 dir = SOUTH + turf_hand_priority = 2 //Lower priority than normal doors to prevent interference + var/enable_smart_generation = TRUE var/list/tile_info[4] diff --git a/code/game/objects/structures/curtains.dm b/code/game/objects/structures/curtains.dm index 8b3bdcadf36..a98f253072f 100644 --- a/code/game/objects/structures/curtains.dm +++ b/code/game/objects/structures/curtains.dm @@ -16,6 +16,7 @@ /obj/structure/curtain/Initialize() . = ..() material = SSmaterials.get_material_by_name(curtain_material) + AddComponent(/datum/component/turf_hand) /obj/structure/curtain/open icon_state = "open" diff --git a/code/game/turfs/turf.dm b/code/game/turfs/turf.dm index 3ecebcc5f04..1d7570dada0 100644 --- a/code/game/turfs/turf.dm +++ b/code/game/turfs/turf.dm @@ -138,21 +138,36 @@ return 0 /turf/attack_hand(mob/user) - if(!(user.canmove) || user.restrained() || !(user.pulling)) - return 0 - if(user.pulling.anchored || !isturf(user.pulling.loc)) - return 0 - if(user.pulling.loc != user.loc && get_dist(user, user.pulling) > 1) - return 0 - if(ismob(user.pulling)) - var/mob/M = user.pulling - var/atom/movable/t = M.pulling - M.stop_pulling() - step(user.pulling, get_dir(user.pulling.loc, src)) - M.start_pulling(t) - else - step(user.pulling, get_dir(user.pulling.loc, src)) - return 1 + if(!(user.canmove) || user.restrained()) + return FALSE + if(user.pulling) + if(user.pulling.anchored || !isturf(user.pulling.loc)) + return FALSE + if(user.pulling.loc != user.loc && get_dist(user, user.pulling) > 1) + return FALSE + if(ismob(user.pulling)) + var/mob/M = user.pulling + var/atom/movable/t = M.pulling + M.stop_pulling() + step(user.pulling, get_dir(user.pulling.loc, src)) + M.start_pulling(t) + else + step(user.pulling, get_dir(user.pulling.loc, src)) + + . = handle_hand_interception(user) + if (!.) + return TRUE + return TRUE + +/turf/proc/handle_hand_interception(var/mob/user) + var/datum/component/turf_hand/THE + for (var/atom/A in src) + var/datum/component/turf_hand/TH = A.GetComponent(/datum/component/turf_hand) + if (istype(TH) && TH.priority > THE?.priority) //Only overwrite if the new one is higher. For matching values, its first come first served + THE = TH + + if (THE) + return THE.OnHandInterception(user) /turf/Enter(atom/movable/mover as mob|obj, atom/forget as mob|obj|turf|area) if(movement_disabled && usr.ckey != movement_disabled_exception) diff --git a/code/modules/multiz/structures.dm b/code/modules/multiz/structures.dm index 2854d69b934..445edfc6c22 100644 --- a/code/modules/multiz/structures.dm +++ b/code/modules/multiz/structures.dm @@ -42,6 +42,8 @@ L.update_icon() break + AddComponent(/datum/component/turf_hand) + update_icon() /obj/structure/ladder/Destroy() diff --git a/code/modules/turbolift/turbolift_console.dm b/code/modules/turbolift/turbolift_console.dm index 2cd2ce9e93f..c79d3c8b306 100644 --- a/code/modules/turbolift/turbolift_console.dm +++ b/code/modules/turbolift/turbolift_console.dm @@ -57,6 +57,10 @@ var/light_up = FALSE var/datum/turbolift_floor/floor +/obj/structure/lift/button/Initialize(mapload, datum/turbolift/_lift) + . = ..() + AddComponent(/datum/component/turf_hand) + /obj/structure/lift/button/Destroy() if(floor && floor.ext_panel == src) floor.ext_panel = null @@ -95,6 +99,9 @@ name = "elevator control panel" icon_state = "panel" +/obj/structure/lift/panel/Initialize(mapload, datum/turbolift/_lift) + . = ..() + AddComponent(/datum/component/turf_hand) /obj/structure/lift/panel/attack_ghost(var/mob/user) return interact(user) diff --git a/html/changelogs/mattatlas-thatwillbe5eurospaypalomicega.yml b/html/changelogs/mattatlas-thatwillbe5eurospaypalomicega.yml new file mode 100644 index 00000000000..3de81221ec6 --- /dev/null +++ b/html/changelogs/mattatlas-thatwillbe5eurospaypalomicega.yml @@ -0,0 +1,42 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# wip (For works in progress) +# tweak +# soundadd +# sounddel +# rscadd (general adding of nice things) +# rscdel (general deleting of nice things) +# imageadd +# imagedel +# maptweak +# spellcheck (typo fixes) +# experiment +# balance +# admin +# backend +# security +# refactor +################################# + +# Your name. +author: MattAtlas + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries. +# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog. +changes: + - rscadd: "You now interact with doors if you click the tile under them. Doors are given precedence to firedoors." + - rscadd: "You now interact with elevator buttons or lift panels if you click the tile in front of them -- not the wall they're on, as the buttons are mapped on the floors."