[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:
SkyratBot
2024-01-21 14:59:14 +00:00
committed by GitHub
co-authored by Ghom
parent ab5a4d0f99
commit fdcfabefd8
60 changed files with 1286 additions and 240 deletions
@@ -1,3 +1,10 @@
#define NT_PAY_STATUS_NO_ACCOUNT 0
#define NT_PAY_STATUS_DEPT_ACCOUNT 1
#define NT_PAY_STATUS_INVALID_TOKEN 2
#define NT_PAY_SATUS_SENDER_IS_RECEIVER 3
#define NT_PAY_STATUS_INVALID_MONEY 4
#define NT_PAY_STATUS_SUCCESS 5
/datum/computer_file/program/nt_pay
filename = "ntpay"
filedesc = "Nanotrasen Pay System"
@@ -8,45 +15,19 @@
tgui_id = "NtosPay"
program_icon = "money-bill-wave"
can_run_on_flags = PROGRAM_ALL
circuit_comp_type = /obj/item/circuit_component/mod_program/nt_pay
///Reference to the currently logged in user.
var/datum/bank_account/current_user
///Pay token, by which we can send credits
var/token
///Amount of credits, which we sends
var/money_to_send = 0
///Pay token what we want to find
var/wanted_token
/datum/computer_file/program/nt_pay/ui_act(action, list/params, datum/tgui/ui)
/datum/computer_file/program/nt_pay/ui_act(action, list/params, datum/tgui/ui, datum/tgui/ui, datum/ui_state/state)
. = ..()
switch(action)
if("Transaction")
if(IS_DEPARTMENTAL_ACCOUNT(current_user))
return to_chat(usr, span_notice("The app is unable to withdraw from that card."))
token = params["token"]
money_to_send = params["amount"]
var/datum/bank_account/recipient
if(!token)
return to_chat(usr, span_notice("You need to enter your transfer target's pay token."))
if(!money_to_send)
return to_chat(usr, span_notice("You need to specify how much you're sending."))
if(token == current_user.pay_token)
return to_chat(usr, span_notice("You can't send credits to yourself."))
for(var/account as anything in SSeconomy.bank_accounts_by_id)
var/datum/bank_account/acc = SSeconomy.bank_accounts_by_id[account]
if(acc.pay_token == token)
recipient = acc
break
if(!recipient)
return to_chat(usr, span_notice("The app can't find who you're trying to pay. Did you enter the pay token right?"))
if(!current_user.has_money(money_to_send) || money_to_send < 1)
return current_user.bank_card_talk("You cannot afford it.")
recipient.bank_card_talk("You received [money_to_send] credit(s). Reason: transfer from [current_user.account_holder]")
recipient.transfer_money(current_user, money_to_send)
current_user.bank_card_talk("You send [money_to_send] credit(s) to [recipient.account_holder]. Now you have [current_user.account_balance] credit(s)")
var/token = params["token"]
var/money_to_send = params["amount"]
make_payment(token, money_to_send, usr)
if("GetPayToken")
wanted_token = null
@@ -58,8 +39,6 @@
if(!wanted_token)
return wanted_token = "Account \"[params["wanted_name"]]\" not found."
/datum/computer_file/program/nt_pay/ui_data(mob/user)
var/list/data = list()
@@ -74,3 +53,99 @@
data["transaction_list"] = current_user.transaction_history
return data
///Wrapper and signal for the main payment function of this program
/datum/computer_file/program/nt_pay/proc/make_payment(token, money_to_send, mob/user)
var/payment_result = _pay(token, money_to_send, user)
SEND_SIGNAL(computer, COMSIG_MODULAR_COMPUTER_NT_PAY_RESULT, payment_result)
/datum/computer_file/program/nt_pay/proc/_pay(token, money_to_send, mob/user)
if(IS_DEPARTMENTAL_ACCOUNT(current_user))
if(user)
to_chat(user, span_notice("The app is unable to withdraw from that card."))
return NT_PAY_STATUS_DEPT_ACCOUNT
var/datum/bank_account/recipient
if(!token)
if(user)
to_chat(user, span_notice("You need to enter your transfer target's pay token."))
return NT_PAY_STATUS_INVALID_TOKEN
if(money_to_send <= 0)
if(user)
to_chat(user, span_notice("You need to specify how much you're sending."))
return NT_PAY_STATUS_INVALID_MONEY
if(token == current_user.pay_token)
if(user)
to_chat(user, span_notice("You can't send credits to yourself."))
return NT_PAY_SATUS_SENDER_IS_RECEIVER
for(var/account as anything in SSeconomy.bank_accounts_by_id)
var/datum/bank_account/acc = SSeconomy.bank_accounts_by_id[account]
if(acc.pay_token == token)
recipient = acc
break
if(!recipient)
if(user)
to_chat(user, span_notice("The app can't find who you're trying to pay. Did you enter the pay token right?"))
return NT_PAY_STATUS_INVALID_TOKEN
if(!current_user.has_money(money_to_send) || money_to_send < 1)
current_user.bank_card_talk("You cannot afford it.")
return NT_PAY_STATUS_INVALID_MONEY
recipient.bank_card_talk("You received [money_to_send] credit(s). Reason: transfer from [current_user.account_holder]")
recipient.transfer_money(current_user, money_to_send)
current_user.bank_card_talk("You send [money_to_send] credit(s) to [recipient.account_holder]. Now you have [current_user.account_balance] credit(s)")
return NT_PAY_STATUS_SUCCESS
/obj/item/circuit_component/mod_program/nt_pay
associated_program = /datum/computer_file/program/nt_pay
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL
///Circuit variables. This one is for the token we want to pay
var/datum/port/input/token_port
///The port for the money to send
var/datum/port/input/money_port
///Let's us know if the payment has gone through or not.
var/datum/port/output/payment_status
/obj/item/circuit_component/mod_program/nt_pay/register_shell(atom/movable/shell)
. = ..()
RegisterSignal(associated_program.computer, COMSIG_MODULAR_COMPUTER_NT_PAY_RESULT, PROC_REF(on_payment_result))
/obj/item/circuit_component/mod_program/nt_pay/unregister_shell()
UnregisterSignal(associated_program.computer, COMSIG_MODULAR_COMPUTER_NT_PAY_RESULT)
return ..()
/obj/item/circuit_component/mod_program/nt_pay/populate_ports()
. = ..()
token_port = add_input_port("Token", PORT_TYPE_STRING)
money_port = add_input_port("Amount", PORT_TYPE_NUMBER)
payment_status = add_output_port("Status", PORT_TYPE_NUMBER)
/obj/item/circuit_component/mod_program/nt_pay/get_ui_notices()
. = ..()
. += create_ui_notice("NT-Pay Statuses:")
. += create_ui_notice("Fail (No Account) - [NT_PAY_STATUS_NO_ACCOUNT]", "red")
. += create_ui_notice("Fail (Dept Account) - [NT_PAY_STATUS_DEPT_ACCOUNT]", "red")
. += create_ui_notice("Fail (Invalid Token) - [NT_PAY_STATUS_INVALID_TOKEN]", "red")
. += create_ui_notice("Fail (Sender = Receiver) - [NT_PAY_SATUS_SENDER_IS_RECEIVER]", "red")
. += create_ui_notice("Fail (Invalid Amount) - [NT_PAY_STATUS_INVALID_MONEY]", "red")
. += create_ui_notice("Success - [NT_PAY_STATUS_SUCCESS]", "green")
/obj/item/circuit_component/mod_program/nt_pay/input_received(datum/port/port)
var/datum/computer_file/program/nt_pay/program = associated_program
program.make_payment(token_port.value, money_port.value)
/obj/item/circuit_component/mod_program/nt_pay/proc/on_payment_result(datum/source, payment_result)
SIGNAL_HANDLER
payment_status.set_output(payment_result)
#undef NT_PAY_STATUS_NO_ACCOUNT
#undef NT_PAY_STATUS_DEPT_ACCOUNT
#undef NT_PAY_STATUS_INVALID_TOKEN
#undef NT_PAY_SATUS_SENDER_IS_RECEIVER
#undef NT_PAY_STATUS_INVALID_MONEY
#undef NT_PAY_STATUS_SUCCESS