From 66e0cb72b91e55265d361bd80b3fd81f192c55e9 Mon Sep 17 00:00:00 2001 From: DragonTrance Date: Wed, 8 Jun 2022 12:30:17 -0400 Subject: [PATCH 01/19] reworking economy, adding paychecks --- code/__DEFINES/subsystems.dm | 61 ++++++++++--------- .../antagonists/bloodsucker/bloodsucker_ui.dm | 2 +- code/modules/jobs/job_types/job.dm | 21 ++++--- code/modules/vending/_vending.dm | 4 +- .../code/controllers/subsystem/economy.dm | 19 +++++- hyperstation/code/modules/economy/account.dm | 38 +++++++----- hyperstation/code/obj/economy.dm | 8 +-- 7 files changed, 89 insertions(+), 64 deletions(-) diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index 43d17deaa..57900a9f6 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -90,37 +90,38 @@ // Subsystem fire priority, from lowest to highest priority // If the subsystem isn't listed here it's either DEFAULT or PROCESS (if it's a processing subsystem child) -#define FIRE_PRIORITY_PING 10 -#define FIRE_PRIORITY_IDLE_NPC 10 -#define FIRE_PRIORITY_SERVER_MAINT 10 -#define FIRE_PRIORITY_RESEARCH 10 -#define FIRE_PRIORITY_VIS 10 -#define FIRE_PRIORITY_VORE 10 -#define FIRE_PRIORITY_GARBAGE 15 -#define FIRE_PRIORITY_WET_FLOORS 20 -#define FIRE_PRIORITY_AIR 20 -#define FIRE_PRIORITY_NPC 80 -#define FIRE_PRIORITY_PROCESS 25 -#define FIRE_PRIORITY_THROWING 25 -#define FIRE_PRIORITY_SPACEDRIFT 30 -#define FIRE_PRIORITY_FIELDS 30 -#define FIRE_PRIOTITY_SMOOTHING 35 -#define FIRE_PRIORITY_NETWORKS 40 -#define FIRE_PRIORITY_OBJ 40 -#define FIRE_PRIORITY_ACID 40 -#define FIRE_PRIOTITY_BURNING 40 -#define FIRE_PRIORITY_AIR_TURFS 40 -#define FIRE_PRIORITY_DEFAULT 50 -#define FIRE_PRIORITY_PARALLAX 65 -#define FIRE_PRIORITY_FLIGHTPACKS 80 -#define FIRE_PRIORITY_MOBS 100 -#define FIRE_PRIORITY_TGUI 110 -#define FIRE_PRIORITY_TICKER 200 +#define FIRE_PRIORITY_PING 10 +#define FIRE_PRIORITY_IDLE_NPC 10 +#define FIRE_PRIORITY_SERVER_MAINT 10 +#define FIRE_PRIORITY_RESEARCH 10 +#define FIRE_PRIORITY_VIS 10 +#define FIRE_PRIORITY_VORE 10 +#define FIRE_PRIORITY_GARBAGE 15 +#define FIRE_PRIORITY_ECONOMY 20 +#define FIRE_PRIORITY_WET_FLOORS 20 +#define FIRE_PRIORITY_AIR 20 +#define FIRE_PRIORITY_PROCESS 25 +#define FIRE_PRIORITY_THROWING 25 +#define FIRE_PRIORITY_SPACEDRIFT 30 +#define FIRE_PRIORITY_FIELDS 30 +#define FIRE_PRIOTITY_SMOOTHING 35 +#define FIRE_PRIORITY_NETWORKS 40 +#define FIRE_PRIORITY_OBJ 40 +#define FIRE_PRIORITY_ACID 40 +#define FIRE_PRIOTITY_BURNING 40 +#define FIRE_PRIORITY_AIR_TURFS 40 +#define FIRE_PRIORITY_DEFAULT 50 +#define FIRE_PRIORITY_PARALLAX 65 +#define FIRE_PRIORITY_NPC 80 +#define FIRE_PRIORITY_FLIGHTPACKS 80 +#define FIRE_PRIORITY_MOBS 100 +#define FIRE_PRIORITY_TGUI 110 +#define FIRE_PRIORITY_TICKER 200 #define FIRE_PRIORITY_ATMOS_ADJACENCY 300 -#define FIRE_PRIORITY_STATPANEL 390 -#define FIRE_PRIORITY_CHAT 400 -#define FIRE_PRIORITY_OVERLAYS 500 -#define FIRE_PRIORITY_INPUT 1000 // This must always always be the max highest priority. Player input must never be lost. +#define FIRE_PRIORITY_STATPANEL 390 +#define FIRE_PRIORITY_CHAT 400 +#define FIRE_PRIORITY_OVERLAYS 500 +#define FIRE_PRIORITY_INPUT 1000 // This must always always be the max highest priority. Player input must never be lost. // SS runlevels diff --git a/code/modules/antagonists/bloodsucker/bloodsucker_ui.dm b/code/modules/antagonists/bloodsucker/bloodsucker_ui.dm index c72ad2ca9..e1436daf2 100644 --- a/code/modules/antagonists/bloodsucker/bloodsucker_ui.dm +++ b/code/modules/antagonists/bloodsucker/bloodsucker_ui.dm @@ -93,7 +93,7 @@ dat += "" dat += "" if(onstation && C && C.registered_account) - dat += "Balance: $[account.account_balance]" + dat += "Balance: $[account.balance]" if(istype(src, /obj/machinery/vending/snack)) dat += "

Chef's Food Selection

" dat += "
" diff --git a/code/modules/jobs/job_types/job.dm b/code/modules/jobs/job_types/job.dm index 79711fd1a..632f7cf7b 100644 --- a/code/modules/jobs/job_types/job.dm +++ b/code/modules/jobs/job_types/job.dm @@ -61,6 +61,9 @@ var/list/alt_titles = list() + /// A multiplier for how much a person gets each paycheck + var/base_paycheck_multiplier = 0.7 + var/override_roundstart_spawn = null //Where the player spawns at roundstart if defined //whitelisting @@ -95,15 +98,6 @@ if(!H) return FALSE - if(!visualsOnly) - var/datum/bank_account/bank_account = new(H.real_name, src) - bank_account.account_holder = H.real_name - bank_account.account_job = src - bank_account.account_id = rand(111111,999999) //give account ID! - //bank_account.account_pin = rand(1000,9999) //give random pin! - bank_account.account_balance = 80 - H.account_id = bank_account.account_id - if(CONFIG_GET(flag/enforce_human_authority) && (title in GLOB.command_positions)) if(H.dna.species.id != "human") H.set_species(/datum/species/human) @@ -118,7 +112,14 @@ H.dna.species.after_equip_job(src, H, visualsOnly) if(!visualsOnly && announce) - announce(H) + generate_bank_account() + if(announce) + announce(H) + +/// Generates a bank account for the person who's getting this job datum +/datum/job/proc/generate_bank_account(mob/living/carbon/human/reciever) + var/datum/bank_account/bank_account = new(H.real_name, src) + return bank_account /datum/job/proc/get_access() if(!config) //Needed for robots. diff --git a/code/modules/vending/_vending.dm b/code/modules/vending/_vending.dm index db6dd01d9..d57c37f32 100644 --- a/code/modules/vending/_vending.dm +++ b/code/modules/vending/_vending.dm @@ -497,8 +497,8 @@ IF YOU MODIFY THE PRODUCTS LIST OF A MACHINE, MAKE SURE TO UPDATE ITS RESUPPLY C updateUsrDialog() vend_ready = 1 if(bankid && R == buying) //if we have a bank id, and we are trying to buy the same thing! - if(bankid.account_balance >= R.price) - bankid.account_balance -= R.price //take the money from the account. + if(bankid.balance >= R.price) + bankid.balance -= R.price //take the money from the account. menu = 1 to_chat(usr, "You [R.name] via the provided bank account!") bankid = null //so noone can buy from your account after youve purchased stuff diff --git a/hyperstation/code/controllers/subsystem/economy.dm b/hyperstation/code/controllers/subsystem/economy.dm index e30e05c76..415569720 100644 --- a/hyperstation/code/controllers/subsystem/economy.dm +++ b/hyperstation/code/controllers/subsystem/economy.dm @@ -1,10 +1,23 @@ SUBSYSTEM_DEF(economy) name = "Economy" wait = 5 MINUTES + priority = FIRE_PRIORITY_ECONOMY init_order = INIT_ORDER_ECONOMY runlevels = RUNLEVEL_GAME - flags = SS_NO_FIRE //Let's not forget this. This subsystem does not use fire and was needlessly using CPU. + /// How many "paychecks" someone gets at the creation of the bank account var/roundstart_paychecks = 5 - var/budget_pool = 35000 - var/list/generated_accounts = list() var/list/bank_accounts = list() //List of normal accounts (not department accounts) + +/datum/controller/subsystem/economy/fire() + for(var/datum/bank_account/account as anything in bank_accounts) + account.AddPaycheck(GetPaycheck(account, account.account_job)) + +/** + * Returns a value of the amount of money a bank account would be getting. It's just some simple multiplication. + * Both the bank account and job is allowed to be null here. + * + * Thanks to the ultimate nature of byond, double-colon accessors, ::, get the default values of the bank account and + * job datums if the respective one is null. You can pass zero arguments here and you'd get the "default" amount of a paycheck. + */ +/datum/controller/subsystem/economy/proc/GetPaycheck(datum/bank_account/account, datum/job/job, multiplier=1) + return account::base_pay * job::base_paycheck_multiplier * multiplier diff --git a/hyperstation/code/modules/economy/account.dm b/hyperstation/code/modules/economy/account.dm index 039ab4482..011df17a2 100644 --- a/hyperstation/code/modules/economy/account.dm +++ b/hyperstation/code/modules/economy/account.dm @@ -1,29 +1,39 @@ #define DUMPTIME 3000 /datum/bank_account - var/account_holder = "Some pleb" - var/account_balance = 0 - var/account_offstation_balance = 0 + var/account_holder = "Some pleboid" + var/balance = 0 var/account_pin = 0 - var/account_dna = "" var/datum/job/account_job + var/obj/item/card/id/associated_id var/list/bank_cards = list() - var/add_to_accounts = TRUE - var/transferable = TRUE - var/account_id - var/withdrawDelay = 0 + var/account_id = 1 + var/base_pay = 60 -/datum/bank_account/New(newname, job) - if(add_to_accounts) - if(!SSeconomy) - log_world("Wack") - SSeconomy.bank_accounts += src +/datum/bank_account/New(newname="Some plebith", datum/job/job) account_holder = newname account_job = job account_id = rand(111111,999999) + if(!SSeconomy || !SSeconomy.initialized) + stack_trace("A new bank account was made without the economy subsystem being initialized first. If this is an issue, change the subsystem's init_order.") + return + + SSeconomy.bank_accounts += src + balance += SSeconomy.GetPaycheck(src, job, SSeconomy.roundstart_paychecks) + +/// Helper for whenever a paycheck gets processed into this account from the economy SS. Simply adds an amount to the account balance and notifies the user. +/datum/bank_account/proc/AddPaycheck(amount, silent=FALSE) + balance += amount + if(associated_id && !silent) + var/local_turf = get_turf(associated_id) + var/hearers = ohearers(1, local_turf) + for(var/mob/M in hearers) + M.playsound_local(local_turf, 'sound/machines/twobeep_high.ogg', 50, vary = TRUE) + to_chat(M, "[icon2html(src, associated_id.loc)]