From a18a0e23d66281e22cbd6684ba7e7a005d92c860 Mon Sep 17 00:00:00 2001 From: EgorDinamit Date: Wed, 14 Feb 2024 19:15:04 +0300 Subject: [PATCH] Payrolls test --- code/controllers/subsystems/supply.dm | 6 ++++++ code/modules/economy/Accounts.dm | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/code/controllers/subsystems/supply.dm b/code/controllers/subsystems/supply.dm index 0398fa1ede2..cf1942974ee 100644 --- a/code/controllers/subsystems/supply.dm +++ b/code/controllers/subsystems/supply.dm @@ -3,6 +3,8 @@ SUBSYSTEM_DEF(supply) name = "Supply" priority = SS_PRIORITY_SUPPLY flags = SS_NO_FIRE + runlevels = RUNLEVEL_GAME|RUNLEVEL_POSTGAME + wait = 30 MINUTES /// Budget for trading stations with spawn_always at FALSE var/trade_stations_budget = 5 @@ -65,6 +67,10 @@ SUBSYSTEM_DEF(supply) DeInitTradeStations() . = ..() +/datum/controller/subsystem/supply/fire() + for(var/datum/money_account/A in all_money_accounts) + A.PayrollTick() + /datum/controller/subsystem/supply/proc/GetFaction(fac) if(!(fac in factions)) return null diff --git a/code/modules/economy/Accounts.dm b/code/modules/economy/Accounts.dm index ae31ed28f76..a7dfc0573cb 100644 --- a/code/modules/economy/Accounts.dm +++ b/code/modules/economy/Accounts.dm @@ -10,6 +10,8 @@ //1 - require manual login / account number and pin //2 - require card and manual login var/account_type = ACCOUNT_TYPE_PERSONAL + /// Associative list of money accounts which we pay into every 30 minutes; account_number = money + var/list/payroll_accounts = list() /datum/money_account/New(var/account_type) account_type = account_type ? account_type : ACCOUNT_TYPE_PERSONAL @@ -38,6 +40,17 @@ var/datum/transaction/T = new(src, to_account, amount, purpose) return T.perform() +// Called by supply subsystem fire() proc every ~30 minutes +/datum/money_account/proc/PayrollTick() + listclearnulls(payroll_accounts) + for(var/datum/money_account/A in payroll_accounts) + if(!payroll_accounts[A]) + payroll_accounts[A] = 0 + continue + var/pay = payroll_accounts[A] + if(!pay || pay > money) + continue + transfer(A, pay, "Payroll from [account_name]") /proc/create_account(var/account_name = "Default account name", var/owner_name, var/starting_funds = 0, var/account_type = ACCOUNT_TYPE_PERSONAL, var/obj/machinery/computer/account_database/source_db)