Integrated circuits for modular computers (#80530)

## About The Pull Request
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.

## Why It's Good For The Game
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.

## Changelog

🆑
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.
/🆑
This commit is contained in:
Ghom
2024-01-20 21:21:42 +01:00
committed by GitHub
parent d0f07e4dcf
commit f9957b0373
60 changed files with 1286 additions and 239 deletions
@@ -8,6 +8,7 @@
can_run_on_flags = PROGRAM_PDA
tgui_id = "NtosCamera"
program_icon = "camera"
circuit_comp_type = /obj/item/circuit_component/mod_program/camera
/// Camera built-into the tablet.
var/obj/item/camera/internal_camera
@@ -16,6 +17,48 @@
/// How many pictures were taken already, used for the camera's TGUI photo display
var/picture_number = 1
/obj/item/circuit_component/mod_program/camera
associated_program = /datum/computer_file/program/maintenance/camera
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL
///A target to take a picture of.
var/datum/port/input/picture_target
///The photographed target
var/datum/port/output/photographed
/obj/item/circuit_component/mod_program/camera/populate_ports()
. = ..()
picture_target = add_input_port("Picture Target", PORT_TYPE_ATOM)
photographed = add_output_port("Photographed Entity", PORT_TYPE_ATOM)
/obj/item/circuit_component/mod_program/camera/register_shell(atom/movable/shell)
. = ..()
var/datum/computer_file/program/maintenance/camera/cam = associated_program
RegisterSignal(cam.internal_camera, COMSIG_CAMERA_IMAGE_CAPTURED, PROC_REF(on_image_captured))
/obj/item/circuit_component/mod_program/camera/unregister_shell()
var/datum/computer_file/program/maintenance/camera/cam = associated_program
UnregisterSignal(cam.internal_camera, COMSIG_CAMERA_IMAGE_CAPTURED)
return ..()
/obj/item/circuit_component/mod_program/camera/input_received(datum/port/input/port)
var/atom/target = picture_target.value
if(!target)
var/turf/our_turf = get_location()
target = locate(our_turf.x, our_turf.y, our_turf.z)
if(!target)
return
var/datum/computer_file/program/maintenance/camera/cam = associated_program
if(!cam.internal_camera.can_target(target))
return
var/pic_size_x = cam.internal_camera.picture_size_x - 1
var/pic_size_y = cam.internal_camera.picture_size_y - 1
INVOKE_ASYNC(cam.internal_camera, TYPE_PROC_REF(/obj/item/camera, captureimage), target, null, pic_size_x, pic_size_y)
/obj/item/circuit_component/mod_program/camera/proc/on_image_captured(obj/item/camera/source, atom/target, mob/user)
SIGNAL_HANDLER
photographed.set_output(target)
/datum/computer_file/program/maintenance/camera/on_install()
. = ..()
internal_camera = new(computer)
@@ -50,13 +93,13 @@
return data
/datum/computer_file/program/maintenance/camera/ui_act(action, params, datum/tgui/ui)
var/mob/living/user = usr
/datum/computer_file/program/maintenance/camera/ui_act(action, params, datum/tgui/ui, datum/ui_state/state)
. = ..()
switch(action)
if("print_photo")
if(computer.stored_paper <= 0)
to_chat(usr, span_notice("Hardware error: Printer out of paper."))
return
internal_camera.printpicture(user, internal_picture)
internal_camera.printpicture(usr, internal_picture)
computer.stored_paper--
computer.visible_message(span_notice("\The [computer] prints out a paper."))
@@ -7,6 +7,7 @@
size = 2
tgui_id = "NtosMODsuit"
program_icon = "user-astronaut"
circuit_comp_type = /obj/item/circuit_component/mod_program/modsuit_control
///The suit we have control over.
var/obj/item/mod/control/controlled_suit
@@ -20,12 +21,15 @@
. = ..()
if(!istype(attacking_item, /obj/item/mod/control))
return FALSE
sync_modsuit(attacking_item, user)
return TRUE
/datum/computer_file/program/maintenance/modsuit_control/proc/sync_modsuit(obj/item/mod/control/new_modsuit, mob/living/user)
if(controlled_suit)
unsync_modsuit()
controlled_suit = attacking_item
controlled_suit = new_modsuit
RegisterSignal(controlled_suit, COMSIG_QDELETING, PROC_REF(unsync_modsuit))
user.balloon_alert(user, "suit updated")
return TRUE
user?.balloon_alert(user, "suit updated")
/datum/computer_file/program/maintenance/modsuit_control/proc/unsync_modsuit(atom/source)
SIGNAL_HANDLER
@@ -43,4 +47,26 @@
return controlled_suit?.ui_static_data()
/datum/computer_file/program/maintenance/modsuit_control/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
return controlled_suit?.ui_act(action, params, ui, state)
/obj/item/circuit_component/mod_program/modsuit_control
associated_program = /datum/computer_file/program/maintenance/modsuit_control
///Circuit port for loading a new suit to control
var/datum/port/input/suit_port
/obj/item/circuit_component/mod_program/modsuit_control/populate_ports()
. = ..()
suit_port = add_input_port("MODsuit Controlled", PORT_TYPE_ATOM)
/obj/item/circuit_component/mod_program/modsuit_control/input_received(datum/port/port)
var/datum/computer_file/program/maintenance/modsuit_control/control = associated_program
var/obj/item/mod/control/mod = suit_port.value
if(isnull(mod) && control.controlled_suit)
control.unsync_modsuit()
return
if(!istype(mod))
return
control.sync_modsuit(mod)
@@ -1,9 +1,9 @@
#define SPOOK_VALUE_SAME_TURF_MULT 1.5
#define SPOOK_VALUE_LIVING_MULT 6
#define SPOOK_VALUE_DEF_MOB 10
#define SPOOK_VALUE_ICON_STATE_MAX 120
#define SPOOK_VALUE_SEGMENT 15
#define SPOOK_COOLDOWN 2 SECONDS
/datum/computer_file/program/maintenance/spectre_meter
filename = "spectre_meter"
@@ -16,6 +16,7 @@
tgui_id = "NtosSpectreMeter"
program_icon = "ghost"
program_open_overlay = "spectre_meter_0"
circuit_comp_type = /obj/item/circuit_component/mod_program/spectre_meter
/// The cooldown for manual scans
COOLDOWN_DECLARE(manual_scan_cd)
/// Whether the automatic scan mode is active or not
@@ -46,13 +47,11 @@
return data
/datum/computer_file/program/maintenance/spectre_meter/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
switch(action)
if("manual_scan")
if(COOLDOWN_FINISHED(src, manual_scan_cd))
INVOKE_ASYNC(src, PROC_REF(scan_surroundings))
COOLDOWN_START(src, manual_scan_cd, 2 SECONDS)
playsound(computer, 'sound/effects/ping_hit.ogg', vol = 40, vary = TRUE)
return TRUE
INVOKE_ASYNC(src, PROC_REF(scan_surroundings))
return TRUE
if("toggle_mode")
auto_mode = !auto_mode
if(auto_mode)
@@ -67,10 +66,13 @@
/datum/computer_file/program/maintenance/spectre_meter/process(seconds_per_tick)
if(auto_mode)
INVOKE_ASYNC(src, PROC_REF(scan_surroundings))
INVOKE_ASYNC(src, PROC_REF(scan_surroundings), FALSE)
///Return the "spook level" of the area the computer is in.
/datum/computer_file/program/maintenance/spectre_meter/proc/scan_surroundings()
/datum/computer_file/program/maintenance/spectre_meter/proc/scan_surroundings(manual = TRUE)
if(manual && !COOLDOWN_FINISHED(src, manual_scan_cd))
return
var/spook_value = 0
var/turf/turf = get_turf(computer)
@@ -103,6 +105,12 @@
if(program_open_overlay != old_open_overlay)
computer.update_appearance(UPDATE_OVERLAYS)
if(manual)
COOLDOWN_START(src, manual_scan_cd, SPOOK_COOLDOWN)
playsound(computer, 'sound/effects/ping_hit.ogg', vol = 40, vary = TRUE)
SEND_SIGNAL(computer, COMSIG_MODULAR_COMPUTER_SPECTRE_SCAN, last_spook_value)
/datum/looping_sound/spectre_meter
mid_sounds = /datum/looping_sound/geiger::mid_sounds
mid_length = 2
@@ -128,8 +136,41 @@
last_spook_value = 0
return ..()
/obj/item/circuit_component/mod_program/spectre_meter
associated_program = /datum/computer_file/program/maintenance/spectre_meter
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL
/// Returns the spookiness of each scan.
var/datum/port/output/scan_results
/obj/item/circuit_component/mod_program/spectre_meter/populate_ports()
. = ..()
scan_results = add_output_port("Scan Results", PORT_TYPE_NUMBER)
/obj/item/circuit_component/mod_program/spectre_meter/register_shell(atom/movable/shell)
. = ..()
RegisterSignal(associated_program.computer, COMSIG_MODULAR_COMPUTER_SPECTRE_SCAN, PROC_REF(on_scan))
/obj/item/circuit_component/mod_program/spectre_meter/unregister_shell()
UnregisterSignal(associated_program.computer, COMSIG_MODULAR_COMPUTER_SPECTRE_SCAN)
return ..()
/obj/item/circuit_component/mod_program/spectre_meter/get_ui_notices()
. = ..()
. += create_ui_notice("Scan Coooldown: [SPOOK_COOLDOWN]", "orange", "stopwatch")
/obj/item/circuit_component/mod_program/spectre_meter/input_received(datum/port/port)
var/datum/computer_file/program/maintenance/spectre_meter/meter = associated_program
INVOKE_ASYNC(meter, TYPE_PROC_REF(/datum/computer_file/program/maintenance/spectre_meter, scan_surroundings))
/obj/item/circuit_component/mod_program/spectre_meter/proc/on_scan(datum/source, spook_value)
SIGNAL_HANDLER
scan_results.set_value(spook_value)
#undef SPOOK_VALUE_SAME_TURF_MULT
#undef SPOOK_VALUE_LIVING_MULT
#undef SPOOK_VALUE_DEF_MOB
#undef SPOOK_VALUE_ICON_STATE_MAX
#undef SPOOK_VALUE_SEGMENT
#undef SPOOK_COOLDOWN
@@ -26,6 +26,7 @@
///Called post-installation of an application in a computer, after 'computer' var is set.
/datum/computer_file/program/maintenance/theme/on_install()
SHOULD_CALL_PARENT(FALSE)
//add the theme to the computer and increase its size to match
var/datum/computer_file/program/themeify/theme_app = locate() in computer.stored_files
if(theme_app)