Cleans up and fixes some bugs in operating table code (#21487)

* Remove old+bugged ways to put people on optables

* Remove doubled hulk attack interaction

* Fix optable patient updates using old resting-based code

* Reorganize procs

* Clean up `check_table()`

* Move sanity checks to generic proc

* Remove double feedback, unnecessary inventory close, double fingerprint

* Simplify out `is_occupied()`

* This is not a lazy list

* Update and simplify `optable/process()`

* Fix reagent injection feedback message for non-patient mobs

* Fix optable patients always facing operating computer

* Init runtimes hiding other runtimes my beloathed
This commit is contained in:
Nathan Winters
2023-07-07 16:36:53 +02:00
committed by GitHub
parent 62a2c82eab
commit cdce533eb7
+37 -73
View File
@@ -20,8 +20,8 @@
/obj/machinery/optable/Initialize(mapload)
. = ..()
for(dir in list(NORTH,EAST,SOUTH,WEST))
computer = locate(/obj/machinery/computer/operating, get_step(src, dir))
for(var/direction in list(NORTH,EAST,SOUTH,WEST))
computer = locate(/obj/machinery/computer/operating, get_step(src, direction))
if(computer)
computer.table = src
break
@@ -37,13 +37,6 @@
. = ..()
. += "<span class='notice'><b>Click-drag</b> someone to the table to place them on top of the table.</span>"
/obj/machinery/optable/attack_hulk(mob/living/carbon/human/user, does_attack_animation = FALSE)
if(user.a_intent == INTENT_HARM)
..(user, TRUE)
visible_message("<span class='warning'>[user] destroys [src]!</span>")
qdel(src)
return TRUE
/obj/machinery/optable/CanPass(atom/movable/mover, turf/target, height=0)
if(height == 0)
return TRUE
@@ -57,75 +50,54 @@
return FALSE
/obj/machinery/optable/MouseDrop_T(atom/movable/O, mob/user)
if(!ishuman(user) && !isrobot(user)) //Only Humanoids and Cyborgs can put things on this table
return
if(!check_table()) //If the Operating Table is occupied, you cannot put someone else on it
return
if(user.buckled || user.incapacitated()) //Is the person trying to use the table incapacitated or restrained?
return
if(!ismob(O) || !iscarbon(O)) //Only Mobs and Carbons can go on this table (no syptic patches please)
return
if(!user_buckle_mob(O, user, check_loc = FALSE))
return
take_patient(O, user)
return TRUE
return take_patient(O, user)
/**
* Updates the `patient` var to be the mob occupying the table
*/
/// Updates `patient` to be a carbon mob occupying the table, and returns it
/obj/machinery/optable/proc/update_patient()
var/mob/living/carbon/C = locate(/mob/living/carbon, loc)
if(C && IS_HORIZONTAL(C))
patient = C
else
patient = null
if(patient in buckled_mobs)
return patient // Current patient is still here, no need to look
patient = null
if(length(buckled_mobs))
for(var/mob/living/carbon/C in buckled_mobs)
patient = C
if(length(injected_reagents))
to_chat(C, "<span class='danger'>You feel a series of tiny pricks!</span>")
break
if(!no_icon_updates)
if(C && C.pulse)
if(patient && patient.pulse)
icon_state = "table2-active"
else
icon_state = "table2-idle"
/obj/machinery/optable/Crossed(atom/movable/AM, oldloc)
. = ..()
if(iscarbon(AM) && LAZYLEN(injected_reagents))
to_chat(AM, "<span class='danger'>You feel a series of tiny pricks!</span>")
return patient
/obj/machinery/optable/proc/take_patient(mob/living/carbon/new_patient, mob/living/carbon/user)
if((!ishuman(user) && !isrobot(user)) || !istype(new_patient))
return
if(update_patient())
to_chat(usr, "<span class='notice'>The table is already occupied!</span>")
return
// Attempt to settle the patient in
if(!user_buckle_mob(new_patient, user, check_loc = FALSE))
return // User is incapacitated, patient is already buckled to something else, etc.
update_patient()
return TRUE
/obj/machinery/optable/process()
update_patient()
if(LAZYLEN(injected_reagents))
for(var/mob/living/carbon/C in get_turf(src))
if(C.stat == DEAD)
continue
var/datum/reagents/R = C.reagents
for(var/chemical in injected_reagents)
R.check_and_add(chemical,reagent_target_amount,inject_amount)
/obj/machinery/optable/proc/take_patient(mob/living/carbon/new_patient, mob/living/carbon/user)
if(new_patient == user)
user.visible_message("[user] climbs on [src].","You climb on [src].")
else
visible_message("<span class='alert'>[new_patient] has been laid on [src] by [user].</span>")
if(new_patient.s_active) //Close the container opened
new_patient.s_active.close(new_patient)
add_fingerprint(user)
update_patient()
/obj/machinery/optable/verb/climb_on()
set name = "Climb On Table"
set category = "Object"
set src in oview(1)
if(usr.stat || !iscarbon(usr) || usr.restrained() || !check_table())
if(!length(injected_reagents) || !patient || patient.stat == DEAD)
return
take_patient(usr, usr)
/obj/machinery/optable/attackby(obj/item/I, mob/living/carbon/user, params)
if(istype(I, /obj/item/grab))
var/obj/item/grab/G = I
if(iscarbon(G.affecting))
take_patient(G.affecting, user)
qdel(G)
else
return ..()
for(var/chemical in injected_reagents)
patient.reagents.check_and_add(chemical, reagent_target_amount, inject_amount)
/obj/machinery/optable/wrench_act(mob/user, obj/item/I)
. = TRUE
@@ -135,11 +107,3 @@
to_chat(user, "<span class='notice'>You deconstruct the table.</span>")
new /obj/item/stack/sheet/plasteel(loc, 5)
qdel(src)
/obj/machinery/optable/proc/check_table()
update_patient()
if(patient != null)
to_chat(usr, "<span class='notice'>The table is already occupied!</span>")
return FALSE
else
return TRUE