mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-12 08:36:00 +01:00
[MIRROR] Integrated circuits for modular computers (#26196)
Integrated circuits for modular computers (#80530) This PR integrates circuits for modular computers and a good bits of their programs. The peculiarity here is that modular computers have no fixed amount of unremovable components (except the base one with just a couple ports for now), instead, they're added and removed along with programs. With a few exceptions (such as the messenger and signaler), for these program circuits to work, their associated program has to be either open or in the background. For a reason or another, not all programs have a circuit associated to them, still, however the programs with a circuit are still a handful. They are: - Nanotrasen Pay System - Notepad - SiliConnect - WireCarp - MODsuit Control - Spectre Meter - Direct Messenger* - LifeConnect - Custodial Locator - Fission360 - Camera - Status Display - SignalCommander *By the by, sending messages has a cooldown, so it shouldn't be as spammy. If it turns out to not be enough, I can make it so messages from circuit will be ignored by other messenger circuits. The PR is no longer WIP. I believe modular computers could make for some interesting setups with circuits, since they're fairly flexible and stocked with features unlike many other appliances, therefore also a speck more abusable, though limits, cooldowns, logging and sanitization have been implemented to keep it in check. 🆑 add: Modular Computers now support integrated circuits. What can be done with them depends on the programs installed and whether they're running (open or background). add: Modular Consoles (the machinery) now have a small backup cell they draw power from if the power goes out. /🆑 Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* Circuit components of modular programs are special.
|
||||
* They're added to the unremovable components of the shell when the prog is installed and deleted if uninstalled.
|
||||
* This means they don't work like normal unremovable comps that live and die along with their shell.
|
||||
*/
|
||||
/obj/item/circuit_component/mod_program
|
||||
display_name = "Abstract Modular Program"
|
||||
desc = "I've spent lot of time thinking how to get this to work. If you see this, I either failed or someone else did, so report it."
|
||||
/**
|
||||
* The program that installed us into the shell/usb_port comp. Needed to avoid having too many signals for every program.
|
||||
* This is also the program we need to install on the modular computer if the circuit is admin-loaded.
|
||||
* Just make sure each of these components is associated to one and only type of program, no subtypes of anything.
|
||||
*/
|
||||
var/datum/computer_file/program/associated_program
|
||||
|
||||
///Starts the program if possible, placing it in the background if another's active.
|
||||
var/datum/port/input/start
|
||||
///kills the program.
|
||||
var/datum/port/input/kill
|
||||
///binary for whether the program is running or not
|
||||
var/datum/port/output/running
|
||||
|
||||
/obj/item/circuit_component/mod_program/Initialize(mapload)
|
||||
if(associated_program)
|
||||
display_name = initial(associated_program.filedesc)
|
||||
desc = initial(associated_program.extended_desc)
|
||||
return ..() // Set the name correctly
|
||||
|
||||
/obj/item/circuit_component/mod_program/register_shell(atom/movable/shell)
|
||||
. = ..()
|
||||
var/obj/item/modular_computer/computer
|
||||
if(istype(shell, /obj/item/modular_computer))
|
||||
computer = shell
|
||||
else if(istype(shell, /obj/machinery/modular_computer))
|
||||
var/obj/machinery/modular_computer/console = shell
|
||||
computer = console.cpu
|
||||
|
||||
///Find the associated program in the computer's stored_files (install it otherwise) and store a reference to it.
|
||||
var/datum/computer_file/program/found_program = locate(associated_program) in computer.stored_files
|
||||
///The integrated circuit was loaded/duplicated
|
||||
if(isnull(found_program))
|
||||
associated_program = new associated_program()
|
||||
computer.store_file(associated_program)
|
||||
else
|
||||
associated_program = found_program
|
||||
|
||||
RegisterSignal(associated_program, COMSIG_COMPUTER_PROGRAM_START, PROC_REF(on_start))
|
||||
RegisterSignal(associated_program, COMSIG_COMPUTER_PROGRAM_KILL, PROC_REF(on_kill))
|
||||
|
||||
/obj/item/circuit_component/mod_program/unregister_shell()
|
||||
UnregisterSignal(associated_program, list(COMSIG_COMPUTER_PROGRAM_START, COMSIG_COMPUTER_PROGRAM_KILL))
|
||||
associated_program = initial(associated_program)
|
||||
return ..()
|
||||
|
||||
/obj/item/circuit_component/mod_program/populate_ports()
|
||||
. = ..()
|
||||
SHOULD_CALL_PARENT(TRUE)
|
||||
start = add_input_port("Start", PORT_TYPE_SIGNAL, trigger = PROC_REF(start_prog))
|
||||
kill = add_input_port("Kill", PORT_TYPE_SIGNAL, trigger = PROC_REF(kill_prog))
|
||||
running = add_output_port("Running", PORT_TYPE_NUMBER)
|
||||
|
||||
///For most programs, triggers only work if they're open (either active or idle).
|
||||
/obj/item/circuit_component/mod_program/should_receive_input(datum/port/input/port)
|
||||
. = ..()
|
||||
if(!.)
|
||||
return FALSE
|
||||
if(isnull(associated_program))
|
||||
return FALSE
|
||||
if(associated_program.program_flags & PROGRAM_CIRCUITS_RUN_WHEN_CLOSED || COMPONENT_TRIGGERED_BY(start, port))
|
||||
return TRUE
|
||||
var/obj/item/modular_computer/computer = associated_program.computer
|
||||
if(computer.active_program == associated_program || (associated_program in computer.idle_threads))
|
||||
return TRUE
|
||||
return FALSE
|
||||
|
||||
/obj/item/circuit_component/mod_program/proc/start_prog(datum/port/input/port)
|
||||
associated_program.computer.open_program(program = associated_program)
|
||||
|
||||
/obj/item/circuit_component/mod_program/proc/on_start(mob/living/user)
|
||||
SIGNAL_HANDLER
|
||||
running.set_value(TRUE)
|
||||
|
||||
/obj/item/circuit_component/mod_program/proc/kill_prog(datum/port/input/port)
|
||||
associated_program.kill_program()
|
||||
|
||||
/obj/item/circuit_component/mod_program/proc/on_kill(mob/living/user)
|
||||
SIGNAL_HANDLER
|
||||
running.set_value(FALSE)
|
||||
|
||||
/obj/item/circuit_component/mod_program/get_ui_notices()
|
||||
. = ..()
|
||||
if(!(associated_program.program_flags & PROGRAM_CIRCUITS_RUN_WHEN_CLOSED))
|
||||
. += create_ui_notice("Requires program to be running", "purple")
|
||||
Reference in New Issue
Block a user