From eae7233c5b353a8fa21511b85b72d8982ab4b34d Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Tue, 31 Aug 2021 21:26:36 +0200 Subject: [PATCH] [MIRROR] small refactor to can_interact() so that borg range is fully respected (#7891) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * small refactor to can_interact() so that borg range is fully respected (#60693) Its a relatively small refactor that changes the previous machinery "can_interact()" proc that literally did a full override despite half of their checks already existing in not one, but TWO parent procs, so i removed the redundant checks, added callbacks to its parents and then added the cyborg range check on the can_interact_with() itself. in doing so i also moved the interaction range var from silicons only, to mobs as a whole and defaulted it to a single tile, silicons override it to 7 (so pAIs and borgs like before) but then set AI and AI.eye to "null", because i have a check in can_interact that if there is no range set, then the range is effectively unlimited. and i even added code for when AI is carded and their wireless transmission is disabled it sets their range to "0" aka, it has no range to do anything even if it could this was really complicated for me so despite my extensive testing it probably would be a bad thing if any of you want to test my code yourself to ensure there isnt a bug with this (theres no runtimes ive come across) note: i did a lot of searching and going through machinery to ensure i caught all the little snowflake overrides and added can_interact() checks to them, but i may have missed one or two things, especially maybe a altclick or ctrlclick somewhere, however i believe i caught most of them one nice side effect of this refactor is that you can actually set another mobs range to something other than 1 tile and they can interact at range, rather than only silicons getting this ability, an admin could VV a human to have a 3 tile arm reach as a meme if they want * small refactor to can_interact() so that borg range is fully respected Co-authored-by: 小月猫 --- code/_onclick/click.dm | 8 ++++++++ code/game/machinery/Sleeper.dm | 1 + code/game/machinery/_machinery.dm | 19 ++++--------------- code/game/machinery/computer/_computer.dm | 2 ++ code/game/machinery/computer/arcade/arcade.dm | 1 + code/game/machinery/computer/dna_console.dm | 3 +++ code/game/machinery/defibrillator_mount.dm | 1 + code/game/machinery/dish_drive.dm | 1 + code/game/machinery/firealarm.dm | 3 ++- code/game/machinery/harvester.dm | 4 ++++ code/game/machinery/stasis.dm | 3 +++ code/game/objects/items/devices/aicard.dm | 4 ++++ .../objects/structures/training_machine.dm | 2 ++ .../atmospherics/machinery/airalarm.dm | 4 +++- code/modules/mob/living/silicon/ai/ai.dm | 2 ++ .../mob/living/silicon/ai/freelook/eye.dm | 1 + .../modules/mob/living/silicon/robot/robot.dm | 6 +----- code/modules/mob/living/silicon/silicon.dm | 2 +- .../mob/living/simple_animal/bot/bot.dm | 3 +++ code/modules/mob/mob.dm | 9 +++++++++ code/modules/mob/mob_defines.dm | 2 ++ .../computers/item/laptop.dm | 3 +++ .../computers/machinery/modular_computer.dm | 3 +++ code/modules/power/apc.dm | 4 +++- 24 files changed, 67 insertions(+), 24 deletions(-) diff --git a/code/_onclick/click.dm b/code/_onclick/click.dm index 640cf4e1bc5..fd71fc7c4d2 100644 --- a/code/_onclick/click.dm +++ b/code/_onclick/click.dm @@ -345,6 +345,8 @@ return /atom/proc/CtrlClick(mob/user) + if(!can_interact(user)) + return FALSE SEND_SIGNAL(src, COMSIG_CLICK_CTRL, user) SEND_SIGNAL(user, COMSIG_MOB_CTRL_CLICKED, src) var/mob/living/ML = user @@ -392,6 +394,8 @@ A.AltClick(src) /atom/proc/AltClick(mob/user) + if(!can_interact(user)) + return FALSE if(SEND_SIGNAL(src, COMSIG_CLICK_ALT, user) & COMPONENT_CANCEL_CLICK_ALT) return var/turf/T = get_turf(src) @@ -408,6 +412,8 @@ ///The base proc of when something is right clicked on when alt is held /atom/proc/alt_click_secondary(mob/user) + if(!can_interact(user)) + return FALSE if(SEND_SIGNAL(src, COMSIG_CLICK_ALT_SECONDARY, user) & COMPONENT_CANCEL_CLICK_ALT_SECONDARY) return @@ -434,6 +440,8 @@ return /atom/proc/CtrlShiftClick(mob/user) + if(!can_interact(user)) + return FALSE SEND_SIGNAL(src, COMSIG_CLICK_CTRL_SHIFT, user) return diff --git a/code/game/machinery/Sleeper.dm b/code/game/machinery/Sleeper.dm index 81777b1df49..a72dcee50e7 100644 --- a/code/game/machinery/Sleeper.dm +++ b/code/game/machinery/Sleeper.dm @@ -145,6 +145,7 @@ ui.open() /obj/machinery/sleeper/AltClick(mob/user) + . = ..() if(!user.canUseTopic(src, !issilicon(user))) return if(state_open) diff --git a/code/game/machinery/_machinery.dm b/code/game/machinery/_machinery.dm index cacff2b476a..08b46ea40b5 100644 --- a/code/game/machinery/_machinery.dm +++ b/code/game/machinery/_machinery.dm @@ -343,16 +343,11 @@ if((machine_stat & (NOPOWER|BROKEN)) && !(interaction_flags_machine & INTERACT_MACHINE_OFFLINE)) // Check if the machine is broken, and if we can still interact with it if so return FALSE - if(isAdminGhostAI(user)) - return TRUE //if you're an admin, you probably know what you're doing (or at least have permission to do what you're doing) - - if(!isliving(user)) - return FALSE //no ghosts in the machine allowed, sorry - if(SEND_SIGNAL(user, COMSIG_TRY_USE_MACHINE, src) & COMPONENT_CANT_USE_MACHINE_INTERACT) return FALSE - var/mob/living/living_user = user + if(!isliving(user)) + return FALSE //no ghosts allowed, sorry var/is_dextrous = FALSE if(isanimal(user)) @@ -370,10 +365,9 @@ if(panel_open && !(interaction_flags_machine & INTERACT_MACHINE_OPEN) && !(interaction_flags_machine & INTERACT_MACHINE_OPEN_SILICON)) return FALSE - return TRUE //silicons don't care about petty mortal concerns like needing to be next to a machine to use it + return user.can_interact_with(src) //AIs don't care about petty mortal concerns like needing to be next to a machine to use it, but borgs do care somewhat - if(living_user.incapacitated()) //idk why silicons aren't supposed to care about incapacitation when interacting with machines, but it was apparently like this before - return FALSE + . = ..() if((interaction_flags_machine & INTERACT_MACHINE_REQUIRES_SIGHT) && user.is_blind()) to_chat(user, span_warning("This machine requires sight to use.")) @@ -385,11 +379,6 @@ if(interaction_flags_machine & INTERACT_MACHINE_REQUIRES_SILICON) //if the user was a silicon, we'd have returned out earlier, so the user must not be a silicon return FALSE - if(!Adjacent(user)) // Next make sure we are next to the machine unless we have telekinesis - var/mob/living/carbon/carbon_user = living_user - if(!istype(carbon_user) || !carbon_user.has_dna() || !carbon_user.dna.check_mutation(TK)) - return FALSE - return TRUE // If we passed all of those checks, woohoo! We can interact with this machine. /obj/machinery/proc/check_nap_violations() diff --git a/code/game/machinery/computer/_computer.dm b/code/game/machinery/computer/_computer.dm index 523903b411a..0d9938b86c2 100644 --- a/code/game/machinery/computer/_computer.dm +++ b/code/game/machinery/computer/_computer.dm @@ -117,5 +117,7 @@ /obj/machinery/computer/AltClick(mob/user) . = ..() + if(!can_interact(user)) + return if(!user.canUseTopic(src, !issilicon(user)) || !is_operational) return diff --git a/code/game/machinery/computer/arcade/arcade.dm b/code/game/machinery/computer/arcade/arcade.dm index 5bb0a24ed0a..0eda90230cd 100644 --- a/code/game/machinery/computer/arcade/arcade.dm +++ b/code/game/machinery/computer/arcade/arcade.dm @@ -641,6 +641,7 @@ GLOBAL_LIST_INIT(arcade_prize_pool, list( circuit = /obj/item/circuitboard/computer/arcade/amputation /obj/machinery/computer/arcade/amputation/attack_hand(mob/user, list/modifiers) + . = ..() if(!iscarbon(user)) return var/mob/living/carbon/c_user = user diff --git a/code/game/machinery/computer/dna_console.dm b/code/game/machinery/computer/dna_console.dm index 1971f67b239..6ad04869516 100644 --- a/code/game/machinery/computer/dna_console.dm +++ b/code/game/machinery/computer/dna_console.dm @@ -199,6 +199,9 @@ /obj/machinery/computer/scan_consolenew/AltClick(mob/user) // Make sure the user can interact with the machine. + . = ..() + if(!can_interact(user)) + return if(!user.canUseTopic(src, !issilicon(user))) return diff --git a/code/game/machinery/defibrillator_mount.dm b/code/game/machinery/defibrillator_mount.dm index 538f88249e7..f24e7adc26e 100644 --- a/code/game/machinery/defibrillator_mount.dm +++ b/code/game/machinery/defibrillator_mount.dm @@ -98,6 +98,7 @@ //defib interaction /obj/machinery/defibrillator_mount/attack_hand(mob/living/user, list/modifiers) + . = ..() if(!defib) to_chat(user, span_warning("There's no defibrillator unit loaded!")) return diff --git a/code/game/machinery/dish_drive.dm b/code/game/machinery/dish_drive.dm index cf4e1f416da..70d8b7edf62 100644 --- a/code/game/machinery/dish_drive.dm +++ b/code/game/machinery/dish_drive.dm @@ -38,6 +38,7 @@ . += span_notice("Alt-click it to beam its contents to any nearby disposal bins.") /obj/machinery/dish_drive/attack_hand(mob/living/user, list/modifiers) + . = ..() if(!LAZYLEN(dish_drive_contents)) to_chat(user, span_warning("There's nothing in [src]!")) return diff --git a/code/game/machinery/firealarm.dm b/code/game/machinery/firealarm.dm index a3ba6e9fbeb..b1a3af3cc87 100644 --- a/code/game/machinery/firealarm.dm +++ b/code/game/machinery/firealarm.dm @@ -184,7 +184,8 @@ /obj/machinery/firealarm/attack_hand(mob/user, list/modifiers) if(buildstage != 2) - return ..() + return + . = ..() add_fingerprint(user) var/area/area = get_area(src) if(area.fire) diff --git a/code/game/machinery/harvester.dm b/code/game/machinery/harvester.dm index 422cfdacbca..3f0e44a88b1 100644 --- a/code/game/machinery/harvester.dm +++ b/code/game/machinery/harvester.dm @@ -50,12 +50,16 @@ harvesting = FALSE /obj/machinery/harvester/attack_hand(mob/user, list/modifiers) + . = ..() if(state_open) close_machine() else if(!harvesting) open_machine() /obj/machinery/harvester/AltClick(mob/user) + . = ..() + if(!can_interact(user)) + return if(harvesting || !user || !isliving(user) || state_open) return if(can_harvest()) diff --git a/code/game/machinery/stasis.dm b/code/game/machinery/stasis.dm index efc0fe2f175..242859999df 100644 --- a/code/game/machinery/stasis.dm +++ b/code/game/machinery/stasis.dm @@ -38,6 +38,9 @@ last_stasis_sound = _running /obj/machinery/stasis/AltClick(mob/user) + . = ..() + if(!can_interact(user)) + return if(world.time >= stasis_can_toggle && user.canUseTopic(src, !issilicon(user))) stasis_enabled = !stasis_enabled stasis_can_toggle = world.time + STASIS_TOGGLE_COOLDOWN diff --git a/code/game/objects/items/devices/aicard.dm b/code/game/objects/items/devices/aicard.dm index 611b52d0461..de58c0d2c03 100644 --- a/code/game/objects/items/devices/aicard.dm +++ b/code/game/objects/items/devices/aicard.dm @@ -100,6 +100,10 @@ . = TRUE if("wireless") AI.control_disabled = !AI.control_disabled + if(!AI.control_disabled) + AI.interaction_range = null + else + AI.interaction_range = 0 to_chat(AI, span_warning("[src]'s wireless port has been [AI.control_disabled ? "disabled" : "enabled"]!")) . = TRUE if("radio") diff --git a/code/game/objects/structures/training_machine.dm b/code/game/objects/structures/training_machine.dm index ce66b7bce07..e5129c8bb63 100644 --- a/code/game/objects/structures/training_machine.dm +++ b/code/game/objects/structures/training_machine.dm @@ -396,6 +396,8 @@ /obj/item/training_toolbox/AltClick(mob/user) . = ..() + if(!can_interact(user)) + return to_chat(user, span_notice("You push the 'Lap' button on the toolbox's display.")) lap_hits = initial(lap_hits) diff --git a/code/modules/atmospherics/machinery/airalarm.dm b/code/modules/atmospherics/machinery/airalarm.dm index a2c1636682b..169c4d6ddb4 100644 --- a/code/modules/atmospherics/machinery/airalarm.dm +++ b/code/modules/atmospherics/machinery/airalarm.dm @@ -858,7 +858,9 @@ return FALSE /obj/machinery/airalarm/AltClick(mob/user) - ..() + . = ..() + if(!can_interact(user)) + return if(!user.canUseTopic(src, !issilicon(user)) || !isturf(loc)) return else diff --git a/code/modules/mob/living/silicon/ai/ai.dm b/code/modules/mob/living/silicon/ai/ai.dm index d3c7f017726..bf150c0ff11 100644 --- a/code/modules/mob/living/silicon/ai/ai.dm +++ b/code/modules/mob/living/silicon/ai/ai.dm @@ -104,6 +104,7 @@ var/datum/alarm_listener/listener ///remember AI's last location var/atom/lastloc + interaction_range = null @@ -786,6 +787,7 @@ new_core.circuit.battery = battery ai_restore_power()//So the AI initially has power. control_disabled = TRUE //Can't control things remotely if you're stuck in a card! + interaction_range = 0 radio_enabled = FALSE //No talking on the built-in radio for you either! forceMove(card) card.AI = src diff --git a/code/modules/mob/living/silicon/ai/freelook/eye.dm b/code/modules/mob/living/silicon/ai/freelook/eye.dm index 73afadf8930..92edf73bd49 100644 --- a/code/modules/mob/living/silicon/ai/freelook/eye.dm +++ b/code/modules/mob/living/silicon/ai/freelook/eye.dm @@ -16,6 +16,7 @@ var/static_visibility_range = 16 var/ai_detector_visible = TRUE var/ai_detector_color = COLOR_RED + interaction_range = null /mob/camera/ai_eye/Initialize() . = ..() diff --git a/code/modules/mob/living/silicon/robot/robot.dm b/code/modules/mob/living/silicon/robot/robot.dm index efc2a3ca314..8540eee1cdf 100644 --- a/code/modules/mob/living/silicon/robot/robot.dm +++ b/code/modules/mob/living/silicon/robot/robot.dm @@ -287,11 +287,7 @@ return TRUE //bypass for borg tablets if (low_power_mode) return FALSE - var/turf/T0 = get_turf(src) - var/turf/T1 = get_turf(A) - if (!T0 || ! T1) - return FALSE - return ISINRANGE(T1.x, T0.x - interaction_range, T0.x + interaction_range) && ISINRANGE(T1.y, T0.y - interaction_range, T0.y + interaction_range) + return ..() /mob/living/silicon/robot/proc/allowed(mob/M) //check if it doesn't require any access at all diff --git a/code/modules/mob/living/silicon/silicon.dm b/code/modules/mob/living/silicon/silicon.dm index 47e48ab761d..d8b3a1c3369 100644 --- a/code/modules/mob/living/silicon/silicon.dm +++ b/code/modules/mob/living/silicon/silicon.dm @@ -43,7 +43,7 @@ var/updating = FALSE //portable camera camerachunk update var/hack_software = FALSE //Will be able to use hacking actions - var/interaction_range = 7 //wireless control range + interaction_range = 7 //wireless control range var/obj/item/pda/ai/aiPDA /mob/living/silicon/Initialize() diff --git a/code/modules/mob/living/simple_animal/bot/bot.dm b/code/modules/mob/living/simple_animal/bot/bot.dm index beb56724f51..7f0c209aa7b 100644 --- a/code/modules/mob/living/simple_animal/bot/bot.dm +++ b/code/modules/mob/living/simple_animal/bot/bot.dm @@ -308,6 +308,9 @@ show_controls(user) /mob/living/simple_animal/bot/AltClick(mob/user) + . = ..() + if(!can_interact(user)) + return if(!user.canUseTopic(src, !issilicon(user))) return unlock_with_id(user) diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 34c632b7f19..f929a66d2b4 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -1020,6 +1020,15 @@ if(mob_dna?.check_mutation(TK) && tkMaxRangeCheck(src, A)) return TRUE + //range check + if(!interaction_range) + return TRUE + var/turf/our_turf = get_turf(src) + var/turf/their_turf = get_turf(A) + if (!our_turf || !their_turf) + return FALSE + return ISINRANGE(their_turf.x, our_turf.x - interaction_range, our_turf.x + interaction_range) && ISINRANGE(their_turf.y, our_turf.y - interaction_range, our_turf.y + interaction_range) + ///Can the mob use Topic to interact with machines /mob/proc/canUseTopic(atom/movable/M, be_close=FALSE, no_dexterity=FALSE, no_tk=FALSE, need_hands = FALSE, floor_okay=FALSE) return diff --git a/code/modules/mob/mob_defines.dm b/code/modules/mob/mob_defines.dm index caa49c97eb6..e64786fa54d 100644 --- a/code/modules/mob/mob_defines.dm +++ b/code/modules/mob/mob_defines.dm @@ -227,3 +227,5 @@ /// A mock client, provided by tests and friends var/datum/client_interface/mock_client + + var/interaction_range = 1 //how far a mob has to be to interact with something, defaulted to 1 tile diff --git a/code/modules/modular_computers/computers/item/laptop.dm b/code/modules/modular_computers/computers/item/laptop.dm index c4432c12d5c..ae860c62d25 100644 --- a/code/modules/modular_computers/computers/item/laptop.dm +++ b/code/modules/modular_computers/computers/item/laptop.dm @@ -93,6 +93,9 @@ /obj/item/modular_computer/laptop/AltClick(mob/user) + . = ..() + if(!can_interact(user)) + return if(screen_on) // Close it. try_toggle_open(user) else diff --git a/code/modules/modular_computers/computers/machinery/modular_computer.dm b/code/modules/modular_computers/computers/machinery/modular_computer.dm index 87ae3ec4b09..1d08d12252a 100644 --- a/code/modules/modular_computers/computers/machinery/modular_computer.dm +++ b/code/modules/modular_computers/computers/machinery/modular_computer.dm @@ -92,6 +92,9 @@ return update_icon(updates) /obj/machinery/modular_computer/AltClick(mob/user) + . = ..() + if(!can_interact(user)) + return if(cpu) cpu.AltClick(user) diff --git a/code/modules/power/apc.dm b/code/modules/power/apc.dm index da720ad6fcd..7d5389ad437 100644 --- a/code/modules/power/apc.dm +++ b/code/modules/power/apc.dm @@ -807,7 +807,9 @@ return FALSE /obj/machinery/power/apc/AltClick(mob/user) - ..() + . = ..() + if(!can_interact(user)) + return if(!user.canUseTopic(src, !issilicon(user)) || !isturf(loc)) return else