Refactors occupant to use setter (#54373)

This is to make it easier to attach a signal to the setting of the occupant.
This commit is contained in:
nicbn
2020-10-18 12:46:14 -03:00
committed by GitHub
parent 83ee251dde
commit a653bc6350
13 changed files with 94 additions and 67 deletions
+7
View File
@@ -477,6 +477,13 @@
#define COMSIG_MACHINERY_POWER_LOST "machinery_power_lost"
///from base power_change() when power is restored
#define COMSIG_MACHINERY_POWER_RESTORED "machinery_power_restored"
///from /obj/machinery/set_occupant(atom/movable/O): (new_occupant)
#define COMSIG_MACHINERY_SET_OCCUPANT "machinery_set_occupant"
// /obj/machinery/atmospherics/components/unary/cryo_cell signals
/// from /obj/machinery/atmospherics/components/unary/cryo_cell/set_on(bool): (on)
#define COMSIG_CRYO_SET_ON "cryo_set_on"
// /obj/machinery/door/airlock signals
+1 -1
View File
@@ -83,7 +83,7 @@
..(user)
var/mob/living/mob_occupant = occupant
if(mob_occupant && mob_occupant.stat != DEAD)
to_chat(occupant, "[enter_message]")
to_chat(mob_occupant, "[enter_message]")
/obj/machinery/sleeper/emp_act(severity)
. = ..()
+22 -10
View File
@@ -146,6 +146,12 @@ Class Procs:
return INITIALIZE_HINT_LATELOAD
/obj/machinery/proc/set_occupant(atom/movable/new_occupant)
SHOULD_CALL_PARENT(TRUE)
SEND_SIGNAL(src, COMSIG_MACHINERY_SET_OCCUPANT, new_occupant)
occupant = new_occupant
/// Helper proc for telling a machine to start processing with the subsystem type that is located in its `subsystem_type` var.
/obj/machinery/proc/begin_processing()
var/datum/controller/subsystem/processing/subsystem = locate(subsystem_type) in Master.subsystems
@@ -232,7 +238,7 @@ Class Procs:
movable_atom.forceMove(this_turf)
// We'll have dropped the occupant, circuit and component parts as part of this.
occupant = null
set_occupant(null)
circuit = null
LAZYCLEARLIST(component_parts)
@@ -256,7 +262,7 @@ Class Procs:
movable_atom.forceMove(this_turf)
if(occupant == movable_atom)
occupant = null
set_occupant(null)
/**
* Puts passed object in to user's hand
@@ -295,7 +301,7 @@ Class Procs:
var/mob/living/mobtarget = target
if(target && !target.has_buckled_mobs() && (!isliving(target) || !mobtarget.buckled))
occupant = target
set_occupant(target)
target.forceMove(src)
updateUsrDialog()
update_icon()
@@ -372,19 +378,19 @@ Class Procs:
var/datum/bank_account/insurance = I.registered_account
if(!insurance)
say("[market_verb] NAP Violation: No bank account found.")
nap_violation(occupant)
nap_violation(H)
return FALSE
else
if(!insurance.adjust_money(-fair_market_price))
say("[market_verb] NAP Violation: Unable to pay.")
nap_violation(occupant)
nap_violation(H)
return FALSE
var/datum/bank_account/D = SSeconomy.get_dep_account(payment_department)
if(D)
D.adjust_money(fair_market_price)
else
say("[market_verb] NAP Violation: No ID card found.")
nap_violation(occupant)
nap_violation(H)
return FALSE
return TRUE
@@ -509,12 +515,11 @@ Class Procs:
return TRUE
/obj/machinery/contents_explosion(severity, target)
if(occupant)
occupant.ex_act(severity, target)
occupant?.ex_act(severity, target)
/obj/machinery/handle_atom_del(atom/A)
if(A == occupant)
occupant = null
set_occupant(null)
update_icon()
updateUsrDialog()
return ..()
@@ -682,7 +687,7 @@ Class Procs:
/obj/machinery/Exited(atom/movable/AM, atom/newloc)
. = ..()
if(AM == occupant)
occupant = null
set_occupant(null)
if(AM == circuit)
circuit = null
@@ -697,6 +702,13 @@ Class Procs:
/obj/machinery/rust_heretic_act()
take_damage(500, BRUTE, MELEE, 1)
/obj/machinery/vv_edit_var(vname, vval)
if(vname == "occupant")
set_occupant(vval)
datum_flags |= DF_VAR_EDITED
return TRUE
return ..()
/**
* Generate a name devices
*
+1 -1
View File
@@ -90,7 +90,7 @@
else
if(sbed)
data["table"] = sbed
if(!ishuman(sbed.occupant) && !ismonkey(sbed.occupant))
if(!ishuman(sbed.occupant) && !ismonkey(sbed.occupant))
return data
data["patient"] = list()
patient = sbed.occupant
+1 -1
View File
@@ -55,7 +55,7 @@
if(occupant)
if(!iscarbon(occupant))
occupant.forceMove(drop_location())
occupant = null
set_occupant(null)
return
to_chat(occupant, "<span class='notice'>You enter [src].</span>")
addtimer(CALLBACK(src, .proc/start_extracting), 20, TIMER_OVERRIDE|TIMER_UNIQUE)
+4 -3
View File
@@ -40,13 +40,14 @@
/obj/machinery/hypnochair/ui_data()
var/list/data = list()
data["occupied"] = occupant ? 1 : 0
var/mob/living/mob_occupant = occupant
data["occupied"] = mob_occupant ? 1 : 0
data["open"] = state_open
data["interrogating"] = interrogating
data["occupant"] = list()
if(occupant)
var/mob/living/mob_occupant = occupant
if(mob_occupant)
data["occupant"]["name"] = mob_occupant.name
data["occupant"]["stat"] = mob_occupant.stat
+2 -2
View File
@@ -123,7 +123,7 @@
/obj/machinery/stasis/post_buckle_mob(mob/living/L)
if(!can_be_occupant(L))
return
occupant = L
set_occupant(L)
if(stasis_running() && check_nap_violations())
chill_out(L)
update_icon()
@@ -131,7 +131,7 @@
/obj/machinery/stasis/post_unbuckle_mob(mob/living/L)
thaw_them(L)
if(L == occupant)
occupant = null
set_occupant(null)
update_icon()
/obj/machinery/stasis/process()
+7 -7
View File
@@ -196,7 +196,7 @@
suit = null
mask = null
storage = null
occupant = null
set_occupant(null)
/obj/machinery/suit_storage_unit/deconstruct(disassembled = TRUE)
if(!(flags_1 & NODECONSTRUCT_1))
@@ -353,7 +353,7 @@
uv = TRUE
locked = TRUE
update_icon()
if(occupant)
if(mob_occupant)
if(uv_super)
mob_occupant.adjustFireLoss(rand(20, 36))
else
@@ -380,7 +380,7 @@
// The wires get damaged too.
wires.cut_all()
else
if(!occupant)
if(!mob_occupant)
visible_message("<span class='notice'>[src]'s door slides open. The glowing yellow lights dim to a gentle green.</span>")
else
visible_message("<span class='warning'>[src]'s door slides open, barraging you with the nauseating smell of charred flesh.</span>")
@@ -399,14 +399,14 @@
if(storage)
things_to_clear += storage
things_to_clear += storage.GetAllContents()
if(occupant)
things_to_clear += occupant
things_to_clear += occupant.GetAllContents()
if(mob_occupant)
things_to_clear += mob_occupant
things_to_clear += mob_occupant.GetAllContents()
for(var/am in things_to_clear) //Scorches away blood and forensic evidence, although the SSU itself is unaffected
var/atom/movable/dirty_movable = am
dirty_movable.wash(CLEAN_ALL)
open_machine(FALSE)
if(occupant)
if(mob_occupant)
dump_inventory_contents()
/obj/machinery/suit_storage_unit/process(delta_time)
@@ -37,12 +37,13 @@
/obj/machinery/implantchair/ui_data()
var/list/data = list()
data["occupied"] = occupant ? 1 : 0
var/mob/living/mob_occupant = occupant
data["occupied"] = mob_occupant ? 1 : 0
data["open"] = state_open
data["occupant"] = list()
if(occupant)
var/mob/living/mob_occupant = occupant
if(mob_occupant)
data["occupant"]["name"] = mob_occupant.name
data["occupant"]["stat"] = mob_occupant.stat
@@ -65,7 +66,7 @@
open_machine()
. = TRUE
if("implant")
implant(occupant,usr)
implant(occupant, usr)
. = TRUE
/obj/machinery/implantchair/proc/implant(mob/living/M,mob/user)
@@ -99,7 +99,7 @@
var/mob/living/mob_occupant = occupant
if(mob_occupant.stat == DEAD)
return
flash = experiment(occupant, params["experiment_type"], usr)
flash = experiment(mob_occupant, params["experiment_type"], usr)
return TRUE
/**
@@ -11,15 +11,32 @@
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
pixel_y = 22
appearance_flags = KEEP_TOGETHER
/// The current occupant being presented
var/mob/living/occupant
/atom/movable/visual/cryo_occupant/Initialize()
/atom/movable/visual/cryo_occupant/Initialize(mapload, obj/machinery/atmospherics/components/unary/cryo_cell/parent)
. = ..()
// Alpha masking
// It will follow this as the animation goes, but that's no problem as the "mask" icon state
// already accounts for this.
add_filter("alpha_mask", 1, list("type" = "alpha", "icon" = icon('icons/obj/cryogenics.dmi', "mask"), "y" = -22))
RegisterSignal(parent, COMSIG_MACHINERY_SET_OCCUPANT, .proc/on_set_occupant)
RegisterSignal(parent, COMSIG_CRYO_SET_ON, .proc/on_set_on)
/// COMSIG_MACHINERY_SET_OCCUPANT callback
/atom/movable/visual/cryo_occupant/proc/on_set_occupant(datum/source, mob/living/new_occupant)
SIGNAL_HANDLER
if(occupant)
vis_contents -= occupant
REMOVE_TRAIT(occupant, TRAIT_IMMOBILIZED, CRYO_TRAIT)
if(occupant.resting || HAS_TRAIT(occupant, TRAIT_FLOORED))
occupant.set_lying_down()
occupant = new_occupant
if(!occupant)
return
/atom/movable/visual/cryo_occupant/proc/on_occupant_enter(mob/living/occupant)
occupant.setDir(SOUTH)
vis_contents += occupant
pixel_y = 22
@@ -27,18 +44,15 @@
occupant.set_body_position(STANDING_UP)
occupant.set_lying_angle(0)
/atom/movable/visual/cryo_occupant/proc/on_occupant_exit(mob/living/occupant)
vis_contents -= occupant
REMOVE_TRAIT(occupant, TRAIT_IMMOBILIZED, CRYO_TRAIT)
if(occupant.resting || HAS_TRAIT(occupant, TRAIT_FLOORED))
occupant.set_lying_down()
/// COMSIG_CRYO_SET_ON callback
/atom/movable/visual/cryo_occupant/proc/on_set_on(datum/source, on)
SIGNAL_HANDLER
/atom/movable/visual/cryo_occupant/proc/on_toggle_on()
animate(src, pixel_y = 24, time = 20, loop = -1)
animate(pixel_y = 22, time = 20)
/atom/movable/visual/cryo_occupant/proc/on_toggle_off()
animate(src)
if(on)
animate(src, pixel_y = 24, time = 20, loop = -1)
animate(pixel_y = 22, time = 20)
else
animate(src)
/// Cryo cell
/obj/machinery/atmospherics/components/unary/cryo_cell
@@ -97,15 +111,12 @@
radio.canhear_range = 0
radio.recalculateChannels()
occupant_vis = new(null)
occupant_vis = new(null, src)
vis_contents += occupant_vis
/obj/machinery/atmospherics/components/unary/cryo_cell/Exited(atom/movable/AM, atom/newloc)
var/mob/living/oldoccupant = occupant
. = ..() // Parent proc takes care of removing occupant if necessary
if (oldoccupant && istype(oldoccupant) && AM == oldoccupant)
update_icon()
occupant_vis.on_occupant_exit(oldoccupant)
/obj/machinery/atmospherics/components/unary/cryo_cell/set_occupant(atom/movable/new_occupant)
. = ..()
update_icon()
/obj/machinery/atmospherics/components/unary/cryo_cell/on_construction()
..(dir, dir)
@@ -192,13 +203,10 @@ GLOBAL_VAR_INIT(cryo_overlay_cover_off, mutable_appearance('icons/obj/cryogenics
/obj/machinery/atmospherics/components/unary/cryo_cell/proc/set_on(new_value)
if(on == new_value)
return
SEND_SIGNAL(src, COMSIG_CRYO_SET_ON, new_value)
. = on
on = new_value
update_icon()
if(on)
occupant_vis.on_toggle_on()
else
occupant_vis.on_toggle_off()
/obj/machinery/atmospherics/components/unary/cryo_cell/on_set_is_operational(old_value)
if(old_value) //Turned off
@@ -279,8 +287,8 @@ GLOBAL_VAR_INIT(cryo_overlay_cover_off, mutable_appearance('icons/obj/cryogenics
var/cold_protection = 0
var/temperature_delta = air1.temperature - mob_occupant.bodytemperature // The only semi-realistic thing here: share temperature between the cell and the occupant.
if(ishuman(occupant))
var/mob/living/carbon/human/H = occupant
if(ishuman(mob_occupant))
var/mob/living/carbon/human/H = mob_occupant
cold_protection = H.get_cold_protection(air1.temperature)
if(abs(temperature_delta) > 1)
@@ -307,7 +315,7 @@ GLOBAL_VAR_INIT(cryo_overlay_cover_off, mutable_appearance('icons/obj/cryogenics
set_on(FALSE)
for(var/mob/M in contents) //only drop mobs
M.forceMove(get_turf(src))
occupant = null
set_occupant(null)
flick("pod-open-anim", src)
reagent_transfer = efficiency * 10 - 5 // wait before injecting the next occupant
..()
@@ -317,8 +325,6 @@ GLOBAL_VAR_INIT(cryo_overlay_cover_off, mutable_appearance('icons/obj/cryogenics
if((isnull(user) || istype(user)) && state_open && !panel_open)
flick("pod-close-anim", src)
..(user)
if(isliving(occupant))
occupant_vis.on_occupant_enter(occupant)
return occupant
/obj/machinery/atmospherics/components/unary/cryo_cell/container_resist_act(mob/living/user)
@@ -452,7 +458,6 @@ GLOBAL_VAR_INIT(cryo_overlay_cover_off, mutable_appearance('icons/obj/cryogenics
set_on(FALSE)
else if(!state_open)
set_on(TRUE)
update_icon()
. = TRUE
if("door")
if(state_open)
@@ -98,7 +98,7 @@
if(C && user.pulling == C && !C.buckled && !C.has_buckled_mobs() && !occupant)
user.visible_message("<span class='danger'>[user] stuffs [C] into the gibber!</span>")
C.forceMove(src)
occupant = C
set_occupant(C)
update_icon()
else
startgibbing(user)
@@ -136,14 +136,14 @@
update_icon()
/obj/machinery/gibber/proc/startgibbing(mob/user)
if(src.operating)
if(operating)
return
if(!src.occupant)
if(!occupant)
audible_message("<span class='hear'>You hear a loud metallic grinding sound.</span>")
return
use_power(1000)
audible_message("<span class='hear'>You hear a loud squelchy grinding sound.</span>")
playsound(src.loc, 'sound/machines/juicer.ogg', 50, TRUE)
playsound(loc, 'sound/machines/juicer.ogg', 50, TRUE)
operating = TRUE
update_icon()
@@ -199,7 +199,8 @@
log_combat(user, occupant, "gibbed")
mob_occupant.death(1)
mob_occupant.ghostize()
qdel(src.occupant)
set_occupant(null)
qdel(mob_occupant)
addtimer(CALLBACK(src, .proc/make_meat, skin, allmeat, meat_produced, gibtype, diseases), gibtime)
/obj/machinery/gibber/proc/make_meat(obj/item/stack/sheet/animalhide/skin, list/obj/item/food/meat/slab/allmeat, meat_produced, gibtype, list/datum/disease/diseases)
@@ -124,9 +124,9 @@
var/mob/living/carbon/carbon_occupant = occupant
var/implant_msg = carbon_occupant.implant_skillchip(inserted_skillchip, FALSE)
if(implant_msg)
to_chat(occupant,"<span class='notice'>Operation failed! [implant_msg]</span>")
to_chat(carbon_occupant,"<span class='notice'>Operation failed! [implant_msg]</span>")
else
to_chat(occupant,"<span class='notice'>Operation complete!</span>")
to_chat(carbon_occupant,"<span class='notice'>Operation complete!</span>")
inserted_skillchip = null
update_icon()