Files
Bubberstation/code/modules/modular_computers/computers/item/laptop.dm
小月猫 62cf2ef21b 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
2021-08-31 13:59:39 -04:00

123 lines
2.9 KiB
Plaintext

/obj/item/modular_computer/laptop
name = "laptop"
desc = "A portable laptop computer."
icon = 'icons/obj/modular_laptop.dmi'
icon_state = "laptop-closed"
icon_state_powered = "laptop"
icon_state_unpowered = "laptop-off"
icon_state_menu = "menu"
display_overlays = FALSE
hardware_flag = PROGRAM_LAPTOP
max_hardware_size = 2
w_class = WEIGHT_CLASS_NORMAL
max_bays = 4
// No running around with open laptops in hands.
item_flags = SLOWS_WHILE_IN_HAND
screen_on = FALSE // Starts closed
var/start_open = TRUE // unless this var is set to 1
var/icon_state_closed = "laptop-closed"
var/w_class_open = WEIGHT_CLASS_BULKY
var/slowdown_open = TRUE
/obj/item/modular_computer/laptop/examine(mob/user)
. = ..()
if(screen_on)
. += span_notice("Alt-click to close it.")
/obj/item/modular_computer/laptop/Initialize()
. = ..()
if(start_open && !screen_on)
toggle_open()
/obj/item/modular_computer/laptop/update_icon_state()
if(!screen_on)
icon_state = icon_state_closed
return
return ..()
/obj/item/modular_computer/laptop/update_overlays()
if(!screen_on)
cut_overlays()
return
return ..()
/obj/item/modular_computer/laptop/attack_self(mob/user)
if(!screen_on)
try_toggle_open(user)
else
return ..()
/obj/item/modular_computer/laptop/verb/open_computer()
set name = "Toggle Open"
set category = "Object"
set src in view(1)
try_toggle_open(usr)
/obj/item/modular_computer/laptop/MouseDrop(obj/over_object, src_location, over_location)
. = ..()
if(over_object == usr || over_object == src)
try_toggle_open(usr)
return
if(istype(over_object, /atom/movable/screen/inventory/hand))
var/atom/movable/screen/inventory/hand/H = over_object
var/mob/M = usr
if(M.stat != CONSCIOUS || HAS_TRAIT(M, TRAIT_HANDS_BLOCKED))
return
if(!isturf(loc) || !Adjacent(M))
return
M.put_in_hand(src, H.held_index)
/obj/item/modular_computer/laptop/attack_hand(mob/user, list/modifiers)
. = ..()
if(.)
return
if(screen_on && isturf(loc))
return attack_self(user)
/obj/item/modular_computer/laptop/proc/try_toggle_open(mob/living/user)
if(issilicon(user))
return
if(!isturf(loc) && !ismob(loc)) // No opening it in backpack.
return
if(!user.canUseTopic(src, BE_CLOSE))
return
toggle_open(user)
/obj/item/modular_computer/laptop/AltClick(mob/user)
. = ..()
if(!can_interact(user))
return
if(screen_on) // Close it.
try_toggle_open(user)
else
return ..()
/obj/item/modular_computer/laptop/proc/toggle_open(mob/living/user=null)
if(screen_on)
to_chat(user, span_notice("You close \the [src]."))
slowdown = initial(slowdown)
w_class = initial(w_class)
else
to_chat(user, span_notice("You open \the [src]."))
slowdown = slowdown_open
w_class = w_class_open
screen_on = !screen_on
display_overlays = screen_on
update_appearance()
// Laptop frame, starts empty and closed.
/obj/item/modular_computer/laptop/buildable
start_open = FALSE