Skip to content

Commit

Permalink
rapid decompression
Browse files Browse the repository at this point in the history
  • Loading branch information
InsightfulParasite committed Dec 21, 2024
1 parent e58548a commit 2284142
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 213 deletions.
124 changes: 124 additions & 0 deletions code/controllers/subsystem/economy.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,21 @@ SUBSYSTEM_DEF(economy)
///The modifier multiplied to the value of cargo pack prices.
var/pack_price_modifier = 1
var/market_crashing = FALSE
//STOCK MARKET VARS
var/list/stocks = list()
var/list/balances = list()
var/list/last_read = list()
var/list/stock_brokers = list()
var/list/logs = list()
var/list/frozen_accounts = list()


/datum/controller/subsystem/economy/Initialize(timeofday)
var/budget_to_hand_out = round(budget_pool / department_accounts.len)
for(var/A in department_accounts)
new /datum/bank_account/department(A, budget_to_hand_out)
generateBrokers()
generateStocks()
return ..()

/datum/controller/subsystem/economy/Recover()
Expand All @@ -66,6 +76,9 @@ SUBSYSTEM_DEF(economy)
station_target = max(round(temporary_total / max(bank_accounts_by_id.len * 2, 1)) + station_target_buffer, 1)
// if(!market_crashing)
// price_update() Fucks up Workshop, I'll figure out how to make it override soon:tm: - Kirie
for(var/stock in stocks)
var/datum/stock/S = stock
S.process()

/**
* Handy proc for obtaining a department's bank account, given the department ID, AKA the define assigned for what department they're under.
Expand Down Expand Up @@ -113,3 +126,114 @@ SUBSYSTEM_DEF(economy)
return 1
inflation_value = max(round(((station_total / bank_accounts_by_id.len) / station_target), 0.1), 1.0)
return inflation_value

//STOCK MARKET PROCS
/datum/controller/subsystem/economy/proc/list_frozen()
for(var/A in frozen_accounts)
to_chat(usr, "[A]: [length(frozen_accounts[A])] borrows")

/datum/controller/subsystem/economy/proc/balanceLog(whose, net)
if (!(whose in balances))
balances[whose] = net
else
balances[whose] += net

/datum/controller/subsystem/economy/proc/generateBrokers()
stock_brokers = list()
var/list/fnames = list("Goldman", "Edward", "James", "Luis", "Alexander", "Walter", "Eugene", "Mary", "Morgan", "Jane", "Elizabeth", "Xavier", "Hayden", "Samuel", "Lee")
var/list/names = list("Johnson", "Rothschild", "Sachs", "Stanley", "Hepburn", "Brown", "McColl", "Fischer", "Edwards", "Becker", "Witter", "Walker", "Lambert", "Smith", "Montgomery", "Lynch", "Roosevelt", "Lehman")
var/list/locations = LC_DISTRICT_LIST
var/list/first = list("The", "First", "Premier", "Finest", "Prime")
var/list/company = list("Investments", "Securities", "Corporation", "Bank", "Brokerage", "& Co.", "Brothers", "& Sons", "Investement Firm", "Union", "Partners", "Capital", "Trade", "Holdings")
for(var/i in 1 to 5)
var/pname = ""
switch (rand(1,5))
if (1)
pname = "[prob(10) ? pick(first) + " " : null][pick(names)] [pick(company)]"
if (2)
pname = "[pick(names)] & [pick(names)][prob(25) ? " " + pick(company) : null]"
if (3)
pname = "[prob(45) ? pick(first) + " " : null][pick(locations)] [pick(company)]"
if (4)
pname = "[prob(10) ? "The " : null][pick(names)] [pick(locations)] [pick(company)]"
if (5)
pname = "[prob(10) ? "The " : null][pick(fnames)] [pick(names)][prob(10) ? " " + pick(company) : null]"
if (pname in stock_brokers)
i--
continue
stock_brokers += pname

/datum/controller/subsystem/economy/proc/generateDesignation(name)
if (length(name) <= 4)
return uppertext(name)
var/list/w = splittext(name, " ")
if (w.len >= 2)
var/d = ""
for(var/i in 1 to min(5, w.len))
d += uppertext(ascii2text(text2ascii(w[i], 1)))
return d
else
var/d = uppertext(ascii2text(text2ascii(name, 1)))
for(var/i in 2 to length(name))
if (prob(100 / i))
d += uppertext(ascii2text(text2ascii(name, i)))
return d

/datum/controller/subsystem/economy/proc/generateStocks(amt = 15)
var/list/fruits = list("Banana", "Mimana", "Watermelon", "Ambrosia", "Pomegranate", "Reishi", "Papaya", "Mango", "Tomato", "Conkerberry", "Wood", "Lychee", "Mandarin", "Harebell", "Pumpkin", "Rhubarb", "Tamarillo", "Yantok", "Ziziphus", "Oranges", "Gatfruit", "Daisy", "Kudzu")
var/list/tech_prefix = list("Nano", "Cyber", "Funk", "Astro", "Fusion", "Tera", "Exo", "Star", "Virtual", "Plasma", "Robust", "Bit", "Future", "Hugbox", "Carbon", "Nerf", "Buff", "Nova", "Space", "Meta", "Cyber")
var/list/tech_short = list("soft", "tech", "prog", "tec", "tek", "ware", "", "gadgets", "nics", "tric", "trasen", "tronic", "coin")
var/list/random_nouns = list("Johnson", "Cluwne", "General", "Specific", "Master", "King", "Queen", "Table", "Rupture", "Dynamic", "Massive", "Mega", "Giga", "Certain", "Singulo", "State", "National", "International", "Interplanetary", "Sector", "Planet", "Burn", "Robust", "Exotic", "Solar", "Lunar", "Chelp", "Corgi", "Lag", "Lizard")
var/list/company = list("Company", "Factory", "Incorporated", "Industries", "Group", "Consolidated", "GmbH", "LLC", "Ltd", "Inc.", "Association", "Limited", "Software", "Technology", "Programming", "IT Group", "Electronics", "Nanotechnology", "Farms", "Stores", "Mobile", "Motors", "Electric", "Designs", "Energy", "Pharmaceuticals", "Communications", "Wholesale", "Holding", "Health", "Machines", "Astrotech", "Gadgets", "Kinetics")
for (var/i = 1, i <= amt, i++)
var/datum/stock/S = new
var/sname = ""
switch (rand(1,6))
if(1)
if(sname == "" || sname == "FAG") // honestly it's a 0.6% chance per round this happens - or once in 166 rounds - so i'm accounting for it before someone yells at me
sname = "[CONSONANTS][VOWELS][CONSONANTS]"
if (2)
sname = "[pick(tech_prefix)][pick(tech_short)][prob(20) ? " " + pick(company) : null]"
if (3 to 4)
var/fruit = pick(fruits)
fruits -= fruit
sname = "[prob(10) ? "The " : null][fruit][prob(40) ? " " + pick(company): null]"
if (5 to 6)
var/pname = pick(random_nouns)
random_nouns -= pname
switch (rand(1,3))
if (1)
sname = "[pname] & [pname]"
if (2)
sname = "[pname] [pick(company)]"
if (3)
sname = "[pname]"
S.name = sname
S.short_name = generateDesignation(S.name)
S.current_value = rand(10, 125)
var/dv = rand(10, 40) / 10
S.fluctuational_coefficient = prob(50) ? (1 / dv) : dv
S.average_optimism = rand(-10, 10) / 100
S.optimism = S.average_optimism + (rand(-40, 40) / 100)
S.current_trend = rand(-200, 200) / 10
S.last_trend = S.current_trend
S.disp_value_change = rand(-1, 1)
S.speculation = rand(-20, 20)
S.average_shares = round(rand(500, 10000) / 10)
S.outside_shareholders = rand(1000, 30000)
S.available_shares = rand(200000, 800000)
S.fluctuation_rate = rand(6, 20)
S.generateIndustry()
S.generateEvents()
stocks += S
last_read[S] = list()

/datum/controller/subsystem/economy/proc/add_log(log_type, user, company_name, stocks, shareprice, money)
var/datum/stock_log/L = new log_type
L.user_name = user
L.company_name = company_name
L.stocks = stocks
L.shareprice = shareprice
L.money = money
L.time = time2text(world.timeofday, "hh:mm")
logs += L
2 changes: 1 addition & 1 deletion code/controllers/subsystem/shuttle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ SUBSYSTEM_DEF(shuttle)
//supply shuttle stuff
var/obj/docking_port/mobile/supply/supply
var/ordernum = 1 //order number given to next order
var/points = 5000 //number of trade-points we have
var/points = 500 //number of trade-points we have
var/centcom_message = "" //Remarks from CentCom on how well you checked the last order.
var/list/discoveredPlants = list() //Typepaths for unusual plants we've already sent CentCom, associated with their potencies

Expand Down
56 changes: 49 additions & 7 deletions code/modules/stock_market/articles.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* This is the code that generates the articles
* that tell you that your stock has plummeted.
*/
/proc/ucfirst(S)
return "[uppertext(ascii2text(text2ascii(S, 1)))][copytext(S, 2)]"

Expand All @@ -8,11 +12,49 @@
M += ucfirst(P)
return jointext(M, " ")

GLOBAL_LIST_EMPTY(FrozenAccounts)
/proc/plotBarGraph(list/points, base_text, width=400, height=400)
var/output = "<table style='border:1px solid black; border-collapse: collapse; width: [width]px; height: [height]px'>"
if (points.len && height > 20 && width > 20)
var/min = points[1]
var/max = points[1]
for (var/v in points)
if (v < min)
min = v
if (v > max)
max = v
var/cells = (height - 20) / 20
if (cells > round(cells))
cells = round(cells) + 1
var/diff = max - min
var/ost = diff / cells
if (min > 0)
min = max(min - ost, 0)
diff = max - min
ost = diff / cells
var/cval = max
var/cwid = width / (points.len + 1)
for (var/y = cells, y > 0, y--)
if (y == cells)
output += "<tr>"
else
output += "<tr style='border:none; border-top:1px solid #00ff00; height: 20px'>"
for (var/x = 0, x <= points.len, x++)
if (x == 0)
output += "<td style='border:none; height: 20px; width: [cwid]px; font-size:10px; color:#00ff00; background:black; text-align:right; vertical-align:bottom'>[round(cval - ost)]</td>"
else
var/v = points[x]
if (v >= cval)
output += "<td style='border:none; height: 20px; width: [cwid]px; background:#0000ff'>&nbsp;</td>"
else
output += "<td style='border:none; height: 20px; width: [cwid]px; background:black'>&nbsp;</td>"
output += "</tr>"
cval -= ost
output += "<tr><td style='font-size:10px; height: 20px; width: 100%; background:black; color:green; text-align:center' colspan='[points.len + 1]'>[base_text]</td></tr>"
else
output += "<tr><td style='width:[width]px; height:[height]px; background: black'></td></tr>"
output += "<tr><td style='font-size:10px; background:black; color:green; text-align:center'>[base_text]</td></tr>"

/proc/list_frozen()
for(var/A in GLOB.FrozenAccounts)
to_chat(usr, "[A]: [length(GLOB.FrozenAccounts[A])] borrows")
return "[output]</table>"

/datum/article
var/headline = "Something big is happening"
Expand Down Expand Up @@ -56,7 +98,7 @@ GLOBAL_LIST_EMPTY(FrozenAccounts)

/datum/article/New()
..()
if ((outlets.len && !prob(100 / (outlets.len + 1))) || !outlets.len)
if((outlets.len && !prob(100 / (outlets.len + 1))) || !outlets.len)
var/ON = generateOutletName()
if (!(ON in outlets))
outlets[ON] = list()
Expand All @@ -65,7 +107,7 @@ GLOBAL_LIST_EMPTY(FrozenAccounts)
outlet = pick(outlets)

var/list/authors = outlets[outlet]
if ((authors.len && !prob(100 / (authors.len + 1))) || !authors.len)
if((authors.len && !prob(100 / (authors.len + 1))) || !authors.len)
var/AN = generateAuthorName()
outlets[outlet] += AN
author = AN
Expand Down Expand Up @@ -98,7 +140,7 @@ GLOBAL_LIST_EMPTY(FrozenAccounts)
var/ticksc = round(ticks/100)
ticksc = ticksc % 100000
var/ticksp = "[ticksc]"
for(var/cycle = 1 to 5)
for(var/cycle = 0 to 4)
ticksp = "0[ticksp]"
spacetime = "[ticksp][time2text(world.realtime, "MM")][time2text(world.realtime, "DD")][text2num(time2text(world.realtime, "YYYY"))+540]"

Expand Down
32 changes: 16 additions & 16 deletions code/modules/stock_market/computer.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// The computer you sell stocks at. Mostly UI code.

/obj/machinery/computer/stockexchange
name = "stock exchange computer"
desc = "A console that connects to the cities stock market."
Expand Down Expand Up @@ -55,19 +57,17 @@ a.updated {
var/dat = "<html><head><title>[station_name()] Stock Exchange</title>[css]</head><body>"

dat += "<span class='user'>Welcome, <b>[station_name()] Cargo Department</b></span><br><span class='balance'><b>Ahn:</b> [balance()] </span><br>"
for (var/datum/stock/S in GLOB.stockExchange.last_read)
var/list/LR = GLOB.stockExchange.last_read[S]
for (var/datum/stock/S in SSeconomy.last_read)
var/list/LR = SSeconomy.last_read[S]
if (!(logged_in in LR))
LR[logged_in] = 0
dat += "<b>View mode:</b> <a href='?src=[REF(src)];cycleview=1'>[vmode ? "Compact" : "Full"]</a> "
dat += "<b>Stock Transaction Log:</b> <a href='?src=[REF(src)];show_logs=1'>Check</a><br>"

dat += "<i>This is a work in progress. Certain features may not be available.</i>"

dat += "<h3>Listed stocks</h3>"

if (vmode == 0)
for (var/datum/stock/S in GLOB.stockExchange.stocks)
for (var/datum/stock/S in SSeconomy.stocks)
var/mystocks = 0
if (logged_in && (logged_in in S.shareholders))
mystocks = S.shareholders[logged_in]
Expand All @@ -85,7 +85,7 @@ a.updated {
dat += "<i>[prod]</i><br>"
var/news = 0
if (logged_in)
var/list/LR = GLOB.stockExchange.last_read[S]
var/list/LR = SSeconomy.last_read[S]
var/lrt = LR[logged_in]
for (var/datum/article/A in S.articles)
if (A.ticks > lrt)
Expand All @@ -102,7 +102,7 @@ a.updated {
dat += "<table class='stable'>"
dat += "<tr><th>&nbsp;</th><th>ID</th><th>Name</th><th>Value</th><th>Owned</th><th>Avail</th><th>Actions</th></tr>"

for (var/datum/stock/S in GLOB.stockExchange.stocks)
for (var/datum/stock/S in SSeconomy.stocks)
var/mystocks = 0
if (logged_in && (logged_in in S.shareholders))
mystocks = S.shareholders[logged_in]
Expand Down Expand Up @@ -135,7 +135,7 @@ a.updated {
dat += "<td>[S.available_shares]</td>"
var/news = 0
if (logged_in)
var/list/LR = GLOB.stockExchange.last_read[S]
var/list/LR = SSeconomy.last_read[S]
var/lrt = LR[logged_in]
for (var/datum/article/A in S.articles)
if (A.ticks > lrt)
Expand Down Expand Up @@ -194,7 +194,7 @@ a.updated {
to_chat(user, "<span class='danger'>Could not complete transaction.</span>")
return
to_chat(user, "<span class='notice'>Sold [amt] shares of [S.name] at [S.current_value] a share for [total] ahn.</span>")
GLOB.stockExchange.add_log(/datum/stock_log/sell, user.name, S.name, amt, S.current_value, total)
SSeconomy.add_log(/datum/stock_log/sell, user.name, S.name, amt, S.current_value, total)

/obj/machinery/computer/stockexchange/proc/buy_some_shares(datum/stock/S, mob/user)
if (!user || !S)
Expand Down Expand Up @@ -229,12 +229,12 @@ a.updated {

var/total = amt * S.current_value
to_chat(user, "<span class='notice'>Bought [amt] shares of [S.name] at [S.current_value] a share for [total] ahn.</span>")
GLOB.stockExchange.add_log(/datum/stock_log/buy, user.name, S.name, amt, S.current_value, total)
SSeconomy.add_log(/datum/stock_log/buy, user.name, S.name, amt, S.current_value, total)

/obj/machinery/computer/stockexchange/proc/do_borrowing_deal(datum/borrow/B, mob/user)
if (B.stock.borrow(B, logged_in))
to_chat(user, "<span class='notice'>You successfully borrowed [B.share_amount] shares. Deposit: [B.deposit].</span>")
GLOB.stockExchange.add_log(/datum/stock_log/borrow, user.name, B.stock.name, B.share_amount, B.deposit)
SSeconomy.add_log(/datum/stock_log/borrow, user.name, B.stock.name, B.share_amount, B.deposit)
else
to_chat(user, "<span class='danger'>Could not complete transaction. Check your account balance.</span>")

Expand All @@ -246,26 +246,26 @@ a.updated {
usr.machine = src

if (href_list["viewhistory"])
var/datum/stock/S = locate(href_list["viewhistory"]) in GLOB.stockExchange.stocks
var/datum/stock/S = locate(href_list["viewhistory"]) in SSeconomy.stocks
if (S)
S.displayValues(usr)

if (href_list["logout"])
logged_in = null

if (href_list["buyshares"])
var/datum/stock/S = locate(href_list["buyshares"]) in GLOB.stockExchange.stocks
var/datum/stock/S = locate(href_list["buyshares"]) in SSeconomy.stocks
if (S)
buy_some_shares(S, usr)

if (href_list["sellshares"])
var/datum/stock/S = locate(href_list["sellshares"]) in GLOB.stockExchange.stocks
var/datum/stock/S = locate(href_list["sellshares"]) in SSeconomy.stocks
if (S)
sell_some_shares(S, usr)

if (href_list["show_logs"])
var/dat = "<html><head><title>Stock Transaction Logs</title></head><body><h2>Stock Transaction Logs</h2><div><a href='?src=[REF(src)];show_logs=1'>Refresh</a></div><br>"
for(var/D in GLOB.stockExchange.logs)
for(var/D in SSeconomy.logs)
var/datum/stock_log/L = D
if(istype(L, /datum/stock_log/buy))
dat += "[L.time] | <b>[L.user_name]</b> bought <b>[L.stocks]</b> stocks at [L.shareprice] a share for <b>[L.money]</b> total ahn in <b>[L.company_name]</b>.<br>"
Expand All @@ -283,7 +283,7 @@ a.updated {
if (href_list["archive"])
var/datum/stock/S = locate(href_list["archive"])
if (logged_in && logged_in != "")
var/list/LR = GLOB.stockExchange.last_read[S]
var/list/LR = SSeconomy.last_read[S]
LR[logged_in] = world.time
var/dat = "<html><head><title>News feed for [S.name]</title></head><body><h2>News feed for [S.name]</h2><div><a href='?src=[REF(src)];archive=[REF(S)]'>Refresh</a></div>"
dat += "<div><h3>Events</h3>"
Expand Down
4 changes: 2 additions & 2 deletions code/modules/stock_market/events.dm
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@
company.bankrupt = 1
for (var/X in company.shareholders)
var/amt = company.shareholders[X]
GLOB.stockExchange.balanceLog(X, -amt * company.current_value)
SSeconomy.balanceLog(X, -amt * company.current_value)
company.shareholders = list()
company.current_value = 0
company.borrow_brokers = list()
GLOB.stockExchange.generateStocks(1)
SSeconomy.generateStocks(1)

var/bailout = (effect > 0 && prob(80)) || (effect < 0 && prob(20))
current_title = "[company.name] [bailout ? "bailed out" : "on a painful rebound"]"
Expand Down
8 changes: 8 additions & 0 deletions code/modules/stock_market/industries.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* This inconsequential code is for generating products to invest in.
* Each time a company tries to improve its stock value with a product
* the product is themed based on the companies industry.
* /datum/industry/agriculture will be farming themed while
* /datum/industry/health will be drug themed.
*/

/datum/industry
var/name = "Industry"
var/list/tokens = list()
Expand Down
4 changes: 4 additions & 0 deletions code/modules/stock_market/logs.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Code made specifically for record
* keeping purposes.
*/
/datum/stock_log
var/user_name = ""
var/company_name = ""
Expand Down
Loading

0 comments on commit 2284142

Please sign in to comment.