[MIRROR] Machine var shim (#11878)

Co-authored-by: Will <7099514+Willburd@users.noreply.github.com>
Co-authored-by: C.L. <killer65311@gmail.com>
This commit is contained in:
CHOMPStation2StaffMirrorBot
2025-10-26 23:35:27 -07:00
committed by GitHub
parent 61146ef685
commit 4099a9435b
63 changed files with 307 additions and 224 deletions

View File

@@ -0,0 +1,179 @@
/**
* THIS IS A SHIM. IT SHOULD NOT BE INCLUDED IN FUTURE CODE. DEPRECATED, DO NOT USE.
*
* This is used to replace the machine var in mob, it is a holdover of pre-tgui code.
* This component operates similar to how the machine var did previous, but better contained.
* Any uses of set_machine() should eventually be removed in favor of tgui handling instead.
*
* All this does is ensure that the mob releases the machine when they leave it.
*/
/datum/component/using_machine_shim
var/mob/host_mob
var/obj/machinery/linked_machine
/datum/component/using_machine_shim/Initialize(obj/machinery/machine)
// Mob
host_mob = parent
RegisterSignal(host_mob, COMSIG_LIVING_LIFE, PROC_REF(on_mob_action))
RegisterSignal(host_mob, COMSIG_LIVING_HANDLE_VISION, PROC_REF(on_mob_vision_update))
RegisterSignal(host_mob, COMSIG_OBSERVER_MOVED, PROC_REF(on_mob_action))
RegisterSignal(host_mob, COMSIG_MOB_LOGOUT, PROC_REF(on_mob_logout))
// Machine
linked_machine = machine
RegisterSignal(linked_machine, COMSIG_QDELETING, PROC_REF(on_machine_qdelete))
linked_machine.in_use = TRUE
on_mob_vision_update()
// Lets complain if an object uses TGUI but is still setting the machine.
if(length(linked_machine.tgui_data()))
log_world("## ERROR [machine.type] implements tgui_data(), and has likely been ported to tgui already. It should no longer use set_machine().")
linked_machine.balloon_alert(host_mob,"you start using \the [linked_machine]")
/datum/component/using_machine_shim/Destroy(force)
. = ..()
linked_machine.balloon_alert(host_mob,"you stop using \the [linked_machine]")
// Machine
UnregisterSignal(linked_machine, COMSIG_QDELETING)
linked_machine.remove_visual(host_mob)
linked_machine.in_use = FALSE
linked_machine = null
// Mob
UnregisterSignal(host_mob, COMSIG_OBSERVER_MOVED)
UnregisterSignal(host_mob, COMSIG_LIVING_HANDLE_VISION)
UnregisterSignal(host_mob, COMSIG_LIVING_LIFE)
UnregisterSignal(host_mob, COMSIG_MOB_LOGOUT)
host_mob.reset_perspective() // Required, because our machine may have been operating a remote view
host_mob = null
/datum/component/using_machine_shim/proc/on_mob_action()
SHOULD_NOT_OVERRIDE(TRUE)
PRIVATE_PROC(TRUE)
SIGNAL_HANDLER
if(host_mob.stat == DEAD || !host_mob.client || !host_mob.Adjacent(linked_machine))
on_mob_vision_update()
qdel(src)
/datum/component/using_machine_shim/proc/on_machine_qdelete()
SHOULD_NOT_OVERRIDE(TRUE)
PRIVATE_PROC(TRUE)
SIGNAL_HANDLER
on_mob_vision_update()
qdel(src)
/datum/component/using_machine_shim/proc/on_mob_vision_update()
SHOULD_NOT_OVERRIDE(TRUE)
PRIVATE_PROC(TRUE)
SIGNAL_HANDLER
if(host_mob.stat == DEAD)
return
var/viewflags = linked_machine.check_eye(host_mob)
if(viewflags < 0)
return
if(host_mob.is_remote_viewing())
linked_machine.apply_visual(host_mob)
return
host_mob.sight |= viewflags
/datum/component/using_machine_shim/proc/on_mob_logout()
SHOULD_NOT_OVERRIDE(TRUE)
PRIVATE_PROC(TRUE)
SIGNAL_HANDLER
qdel(src)
/////////////////////////////////////////////////////////////////////////////////
// To be removed helper procs
/////////////////////////////////////////////////////////////////////////////////
/// deprecated, do not use
/mob/proc/get_current_machine()
RETURN_TYPE(/obj)
var/datum/component/using_machine_shim/shim = GetComponent(/datum/component/using_machine_shim)
if(!shim)
return
return shim.linked_machine
/// deprecated, do not use
/mob/proc/check_current_machine(var/obj/checking)
var/datum/component/using_machine_shim/shim = GetComponent(/datum/component/using_machine_shim)
if(!shim)
return FALSE
return (shim.linked_machine == checking)
/// deprecated, do not use
/mob/proc/unset_machine()
var/datum/component/using_machine_shim/shim = GetComponent(/datum/component/using_machine_shim)
if(shim)
qdel(shim)
/// deprecated, do not use
/mob/proc/set_machine(var/obj/O)
var/datum/component/using_machine_shim/shim = GetComponent(/datum/component/using_machine_shim)
if(shim)
if(shim.linked_machine == O) // Already in use
return
qdel(shim)
return
AddComponent(/datum/component/using_machine_shim, O)
/// deprecated, do not use, return flags that should be added to the viewer's sight var. Otherwise return a negative number to indicate that the view should be cancelled.
/atom/proc/check_eye(user as mob)
if (isAI(user)) // WHYYYY
return 0
return -1
/// deprecated, do not use
/obj/item/proc/updateSelfDialog()
var/mob/M = src.loc
if(istype(M) && M.client && M.check_current_machine(src))
src.attack_self(M)
/// deprecated, do not use
/obj/proc/updateUsrDialog(mob/user)
if(in_use)
var/is_in_use = 0
var/list/nearby = viewers(1, src)
for(var/mob/M in nearby)
if ((M.client && M.check_current_machine(src)))
is_in_use = 1
src.attack_hand(M)
if (isAI(user) || isrobot(user))
if (!(user in nearby))
if (user.client && user.check_current_machine(src)) // && M.machine == src is omitted because if we triggered this by using the dialog, it doesn't matter if our machine changed in between triggering it and this - the dialog is probably still supposed to refresh.
is_in_use = 1
src.attack_ai(user)
// check for TK users
if (ishuman(user))
var/mob/living/carbon/human/H = user
if(H.get_type_in_hands(/obj/item/tk_grab))
if(!(H in nearby))
if(H.client && H.check_current_machine(src))
is_in_use = 1
src.attack_hand(H)
in_use = is_in_use
/// deprecated, do not use
/obj/proc/updateDialog()
// Check that people are actually using the machine. If not, don't update anymore.
if(in_use)
var/list/nearby = viewers(1, src)
var/is_in_use = 0
for(var/mob/M in nearby)
if ((M.client && M.check_current_machine(src)))
is_in_use = 1
src.interact(M)
var/ai_in_use = AutoUpdateAI(src)
if(!ai_in_use && !is_in_use)
in_use = 0
/// deprecated, do not use
/obj/machinery/CouldUseTopic(var/mob/user)
..()
user.set_machine(src)
/// deprecated, do not use
/obj/machinery/CouldNotUseTopic(var/mob/user)
user.unset_machine()