Files
Yogstation/code/modules/research/rdmachines.dm
ACCount 40699a8aea [READY]Refactors reagent container types (#33470)
* Replaces a bunch of manual OPENCONTAINER checks with helper procs

* Removes unnecessary vars

* Updates reagent bitflags, adds some new ones

* Replaces most of the is_open_container calls with more specific ones

* Puts new AMOUNT_VISIBLE flag to use

* Uses new helper procs in more objects

* Standardizes chemicals logging

* De-snowflakes two more checks

* Fixes

* Minor fixes and improvements
2017-12-18 22:55:01 -06:00

120 lines
3.5 KiB
Plaintext

//All devices that link into the R&D console fall into thise type for easy identification and some shared procs.
/obj/machinery/rnd
name = "R&D Device"
icon = 'icons/obj/machines/research.dmi'
density = TRUE
anchored = TRUE
use_power = IDLE_POWER_USE
var/busy = FALSE
var/hacked = FALSE
var/console_link = TRUE //allow console link.
var/requires_console = TRUE
var/disabled = FALSE
var/shocked = FALSE
var/obj/machinery/computer/rdconsole/linked_console
var/obj/item/loaded_item = null //the item loaded inside the machine (currently only used by experimentor and destructive analyzer)
var/allowed_department_flags = ALL
/obj/machinery/rnd/proc/reset_busy()
busy = FALSE
/obj/machinery/rnd/Initialize()
. = ..()
wires = new /datum/wires/rnd(src)
/obj/machinery/rnd/Destroy()
QDEL_NULL(wires)
return ..()
/obj/machinery/rnd/proc/shock(mob/user, prb)
if(stat & (BROKEN|NOPOWER)) // unpowered, no shock
return FALSE
if(!prob(prb))
return FALSE
do_sparks(5, TRUE, src)
if (electrocute_mob(user, get_area(src), src, 0.7, TRUE))
return TRUE
else
return FALSE
/obj/machinery/rnd/attack_hand(mob/user)
if(shocked)
if(shock(user,50))
return
if(panel_open)
wires.interact(user)
/obj/machinery/rnd/attackby(obj/item/O, mob/user, params)
if (shocked)
if(shock(user,50))
return TRUE
if (default_deconstruction_screwdriver(user, "[initial(icon_state)]_t", initial(icon_state), O))
if(linked_console)
disconnect_console()
return
if(exchange_parts(user, O))
return
if(default_deconstruction_crowbar(O))
return
if(is_refillable() && O.is_drainable())
return FALSE //inserting reagents into the machine
if(Insert_Item(O, user))
return TRUE
else
return ..()
//to disconnect the machine from the r&d console it's linked to
/obj/machinery/rnd/proc/disconnect_console()
linked_console = null
//proc used to handle inserting items or reagents into rnd machines
/obj/machinery/rnd/proc/Insert_Item(obj/item/I, mob/user)
return
//whether the machine can have an item inserted in its current state.
/obj/machinery/rnd/proc/is_insertion_ready(mob/user)
if(panel_open)
to_chat(user, "<span class='warning'>You can't load [src] while it's opened!</span>")
return FALSE
if(disabled)
return FALSE
if(requires_console && !linked_console)
to_chat(user, "<span class='warning'>[src] must be linked to an R&D console first!</span>")
return FALSE
if(busy)
to_chat(user, "<span class='warning'>[src] is busy right now.</span>")
return FALSE
if(stat & BROKEN)
to_chat(user, "<span class='warning'>[src] is broken.</span>")
return FALSE
if(stat & NOPOWER)
to_chat(user, "<span class='warning'>[src] has no power.</span>")
return FALSE
if(loaded_item)
to_chat(user, "<span class='warning'>[src] is already loaded.</span>")
return FALSE
return TRUE
//we eject the loaded item when deconstructing the machine
/obj/machinery/rnd/on_deconstruction()
if(loaded_item)
loaded_item.forceMove(loc)
..()
/obj/machinery/rnd/proc/AfterMaterialInsert(type_inserted, id_inserted, amount_inserted)
var/stack_name
if(ispath(type_inserted, /obj/item/ore/bluespace_crystal))
stack_name = "bluespace"
use_power(MINERAL_MATERIAL_AMOUNT / 10)
else
var/obj/item/stack/S = type_inserted
stack_name = initial(S.name)
use_power(max(1000, (MINERAL_MATERIAL_AMOUNT * amount_inserted / 10)))
add_overlay("protolathe_[stack_name]")
addtimer(CALLBACK(src, /atom/proc/cut_overlay, "protolathe_[stack_name]"), 10)