Files
GS13NG/code/modules/research/nanites/public_chamber.dm
2018-09-11 07:51:01 -05:00

179 lines
5.1 KiB
Plaintext

/obj/machinery/public_nanite_chamber
name = "public nanite chamber"
desc = "A device that can rapidly implant cloud-synced nanites without an external operator."
circuit = /obj/item/circuitboard/machine/public_nanite_chamber
icon = 'icons/obj/machines/nanite_chamber.dmi'
icon_state = "nanite_chamber"
layer = ABOVE_WINDOW_LAYER
use_power = IDLE_POWER_USE
anchored = TRUE
density = TRUE
idle_power_usage = 50
active_power_usage = 300
var/cloud_id = 1
var/locked = FALSE
var/breakout_time = 1200
var/busy = FALSE
var/busy_icon_state
var/message_cooldown = 0
/obj/machinery/public_nanite_chamber/Initialize()
. = ..()
occupant_typecache = GLOB.typecache_living
/obj/machinery/public_nanite_chamber/RefreshParts()
var/obj/item/circuitboard/machine/public_nanite_chamber/board = circuit
if(board)
cloud_id = board.cloud_id
/obj/machinery/public_nanite_chamber/proc/set_busy(status, working_icon)
busy = status
busy_icon_state = working_icon
update_icon()
/obj/machinery/public_nanite_chamber/proc/inject_nanites()
if(stat & (NOPOWER|BROKEN))
return
if((stat & MAINT) || panel_open)
return
if(!occupant || busy)
return
var/locked_state = locked
locked = TRUE
//TODO OMINOUS MACHINE SOUNDS
set_busy(TRUE, "[initial(icon_state)]_raising")
addtimer(CALLBACK(src, .proc/set_busy, TRUE, "[initial(icon_state)]_active"),20)
addtimer(CALLBACK(src, .proc/set_busy, TRUE, "[initial(icon_state)]_falling"),60)
addtimer(CALLBACK(src, .proc/complete_injection, locked_state),80)
/obj/machinery/public_nanite_chamber/proc/complete_injection(locked_state)
//TODO MACHINE DING
locked = locked_state
set_busy(FALSE)
if(!occupant)
return
occupant.AddComponent(/datum/component/nanites, 75, cloud_id)
/obj/machinery/public_nanite_chamber/update_icon()
cut_overlays()
if((stat & MAINT) || panel_open)
add_overlay("maint")
else if(!(stat & (NOPOWER|BROKEN)))
if(busy || locked)
add_overlay("red")
if(locked)
add_overlay("bolted")
else
add_overlay("green")
//running and someone in there
if(occupant)
if(busy)
icon_state = busy_icon_state
else
icon_state = initial(icon_state)+ "_occupied"
return
//running
icon_state = initial(icon_state)+ (state_open ? "_open" : "")
/obj/machinery/public_nanite_chamber/power_change()
. = ..()
update_icon()
/obj/machinery/public_nanite_chamber/proc/toggle_open(mob/user)
if(panel_open)
to_chat(user, "<span class='notice'>Close the maintenance panel first.</span>")
return
if(state_open)
close_machine()
return
else if(locked)
to_chat(user, "<span class='notice'>The bolts are locked down, securing the door shut.</span>")
return
open_machine()
/obj/machinery/public_nanite_chamber/container_resist(mob/living/user)
if(!locked)
open_machine()
return
if(busy)
return
user.changeNext_move(CLICK_CD_BREAKOUT)
user.last_special = world.time + CLICK_CD_BREAKOUT
user.visible_message("<span class='notice'>You see [user] kicking against the door of [src]!</span>", \
"<span class='notice'>You lean on the back of [src] and start pushing the door open... (this will take about [DisplayTimeText(breakout_time)].)</span>", \
"<span class='italics'>You hear a metallic creaking from [src].</span>")
if(do_after(user,(breakout_time), target = src))
if(!user || user.stat != CONSCIOUS || user.loc != src || state_open || !locked || busy)
return
locked = FALSE
user.visible_message("<span class='warning'>[user] successfully broke out of [src]!</span>", \
"<span class='notice'>You successfully break out of [src]!</span>")
open_machine()
/obj/machinery/public_nanite_chamber/close_machine(mob/living/carbon/user)
if(!state_open)
return FALSE
..()
. = TRUE
addtimer(CALLBACK(src, .proc/try_inject_nanites), 30) //If someone is shoved in give them a chance to get out before the injection starts
/obj/machinery/public_nanite_chamber/proc/try_inject_nanites()
if(occupant)
var/mob/living/L = occupant
if(SEND_SIGNAL(L, COMSIG_HAS_NANITES))
return
if((MOB_ORGANIC in L.mob_biotypes) || (MOB_UNDEAD in L.mob_biotypes))
inject_nanites()
/obj/machinery/public_nanite_chamber/open_machine()
if(state_open)
return FALSE
..()
return TRUE
/obj/machinery/public_nanite_chamber/relaymove(mob/user as mob)
if(user.stat || locked)
if(message_cooldown <= world.time)
message_cooldown = world.time + 50
to_chat(user, "<span class='warning'>[src]'s door won't budge!</span>")
return
open_machine()
/obj/machinery/public_nanite_chamber/attackby(obj/item/I, mob/user, params)
if(!occupant && default_deconstruction_screwdriver(user, icon_state, icon_state, I))//sent icon_state is irrelevant...
update_icon()//..since we're updating the icon here, since the scanner can be unpowered when opened/closed
return
if(default_pry_open(I))
return
if(default_deconstruction_crowbar(I))
return
return ..()
/obj/machinery/public_nanite_chamber/interact(mob/user)
toggle_open(user)
/obj/machinery/public_nanite_chamber/MouseDrop_T(mob/target, mob/user)
if(user.stat || user.lying || !Adjacent(user) || !user.Adjacent(target) || !iscarbon(target) || !user.IsAdvancedToolUser())
return
close_machine(target)