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
This commit is contained in:
小月猫
2021-08-31 13:59:39 -04:00
committed by GitHub
parent f545621655
commit 62cf2ef21b
24 changed files with 67 additions and 24 deletions
@@ -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
+2
View File
@@ -103,6 +103,7 @@
var/datum/station_alert/alert_control
///remember AI's last location
var/atom/lastloc
interaction_range = null
/mob/living/silicon/ai/Initialize(mapload, datum/ai_laws/L, mob/target_ai)
. = ..()
@@ -742,6 +743,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
@@ -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()
. = ..()
@@ -259,11 +259,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
+1 -1
View File
@@ -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()
@@ -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)
+9
View File
@@ -1005,6 +1005,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
+2
View File
@@ -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
@@ -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
@@ -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)
+3 -1
View File
@@ -781,7 +781,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