Refactors operating tables to be event driven + QoL + Unit Test (#69015)

* Event driven table

* Operating computer fix + loosening of check

* Unit testing

* IT NEEDS TO BE FORCE MOVE YOU GOTTA CLIMB TABLES AAAAH

* Migrated patient to carbon instead of human
Has no real bearing on the experiments tbh

* DNAs can be null apparently

* Simplify replacement code

* Move comments
This commit is contained in:
vincentiusvin
2022-08-12 10:09:07 -04:00
committed by GitHub
parent 6e4c131fa6
commit b011e723c6
5 changed files with 82 additions and 35 deletions
+40 -27
View File
@@ -681,7 +681,7 @@
buckle_lying = NO_BUCKLE_LYING
buckle_requires_restraints = TRUE
custom_materials = list(/datum/material/silver = 2000)
var/mob/living/carbon/human/patient = null
var/mob/living/carbon/patient = null
var/obj/machinery/computer/operating/computer = null
/obj/structure/table/optable/Initialize(mapload)
@@ -691,44 +691,57 @@
if(computer)
computer.table = src
break
RegisterSignal(loc, COMSIG_ATOM_ENTERED, .proc/mark_patient)
RegisterSignal(loc, COMSIG_ATOM_EXITED, .proc/unmark_patient)
/obj/structure/table/optable/Destroy()
. = ..()
if(computer && computer.table == src)
computer.table = null
patient = null
UnregisterSignal(loc, COMSIG_ATOM_ENTERED)
UnregisterSignal(loc, COMSIG_ATOM_EXITED)
return ..()
/obj/structure/table/optable/tablepush(mob/living/user, mob/living/pushed_mob)
pushed_mob.forceMove(loc)
pushed_mob.set_resting(TRUE, TRUE)
visible_message(span_notice("[user] lays [pushed_mob] on [src]."))
get_patient()
/obj/structure/table/optable/proc/get_patient()
var/mob/living/carbon/M = locate(/mob/living/carbon) in loc
if(M)
if(M.resting)
set_patient(M)
else
set_patient(null)
/obj/structure/table/optable/proc/set_patient(new_patient)
if(patient)
UnregisterSignal(patient, COMSIG_PARENT_QDELETING)
patient = new_patient
if(patient)
RegisterSignal(patient, COMSIG_PARENT_QDELETING, .proc/patient_deleted)
/obj/structure/table/optable/proc/patient_deleted(datum/source)
/// Any mob that enters our tile will be marked as a potential patient. They will be turned into a patient if they lie down.
/obj/structure/table/optable/proc/mark_patient(datum/source, mob/living/carbon/potential_patient)
SIGNAL_HANDLER
set_patient(null)
if(!istype(potential_patient))
return
RegisterSignal(potential_patient, COMSIG_LIVING_SET_BODY_POSITION, .proc/recheck_patient)
recheck_patient(potential_patient) // In case the mob is already lying down before they entered.
/obj/structure/table/optable/proc/check_eligible_patient()
get_patient()
if(!patient)
return FALSE
if(ishuman(patient))
return TRUE
return FALSE
/// Unmark the potential patient.
/obj/structure/table/optable/proc/unmark_patient(datum/source, mob/living/carbon/potential_patient)
SIGNAL_HANDLER
if(!istype(potential_patient))
return
if(potential_patient == patient)
recheck_patient(patient) // Can just set patient to null, but doing the recheck lets us find a replacement patient.
UnregisterSignal(potential_patient, COMSIG_LIVING_SET_BODY_POSITION)
/// Someone on our tile just lied down, got up, moved in, or moved out.
/// potential_patient is the mob that had one of those four things change.
/// The check is a bit broad so we can find a replacement patient.
/obj/structure/table/optable/proc/recheck_patient(mob/living/carbon/potential_patient)
SIGNAL_HANDLER
if(patient && patient != potential_patient)
return
if(potential_patient.body_position == LYING_DOWN && potential_patient.loc == loc)
patient = potential_patient
return
// Find another lying mob as a replacement.
for (var/mob/living/carbon/replacement_patient in loc.contents)
if(replacement_patient.body_position == LYING_DOWN)
patient = replacement_patient
return
patient = null
/*
* Racks