From e7212913e9943cb9c7afbe790ec898928193cbb1 Mon Sep 17 00:00:00 2001 From: InsightfulParasite <invaderchris4898@hotmail.com> Date: Wed, 18 Dec 2024 00:06:01 -0500 Subject: [PATCH 1/2] Tg Stock Market Console Port Requested by Kirie. Ported from TG. Some parts of the code were changed to make it more lorefriendly to the Project Moon universe. The defined list of all the districts is so i dont have to post that long list over and over and over. Hypothetically can be used by Representative for ahn generation. :cl: add: Lore defines file add: stockexchange computer /:cl: ughhhghhh it begins rapid decompression --- code/__DEFINES/text.dm | 10 + code/controllers/subsystem/stockmarket.dm | 107 ++++++++ code/modules/stock_market/articles.dm | 115 ++++++++ code/modules/stock_market/computer.dm | 320 ++++++++++++++++++++++ code/modules/stock_market/events.dm | 237 ++++++++++++++++ code/modules/stock_market/industries.dm | 242 ++++++++++++++++ code/modules/stock_market/stocks.dm | 260 ++++++++++++++++++ lobotomy-corp13.dme | 7 + 8 files changed, 1298 insertions(+) create mode 100644 code/__DEFINES/text.dm create mode 100644 code/controllers/subsystem/stockmarket.dm create mode 100644 code/modules/stock_market/articles.dm create mode 100644 code/modules/stock_market/computer.dm create mode 100644 code/modules/stock_market/events.dm create mode 100644 code/modules/stock_market/industries.dm create mode 100644 code/modules/stock_market/stocks.dm diff --git a/code/__DEFINES/text.dm b/code/__DEFINES/text.dm new file mode 100644 index 000000000000..d0c7f93f0f31 --- /dev/null +++ b/code/__DEFINES/text.dm @@ -0,0 +1,10 @@ +/// BYOND's string procs don't support being used on datum references (as in it doesn't look for a name for stringification) +/// We just use this macro to ensure that we will only pass strings to this BYOND-level function without developers needing to really worry about it. +#define LOWER_TEXT(thing) lowertext(UNLINT("[thing]")) + +/// Folder directory for strings +#define STRING_DIRECTORY "strings" + +#define ALPHABET list("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z") +#define VOWELS list("a", "e", "i", "o", "u") +#define CONSONANTS list("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z") diff --git a/code/controllers/subsystem/stockmarket.dm b/code/controllers/subsystem/stockmarket.dm new file mode 100644 index 000000000000..801270b29446 --- /dev/null +++ b/code/controllers/subsystem/stockmarket.dm @@ -0,0 +1,107 @@ +SUBSYSTEM_DEF(stockmarket) + name = "Stock Market" + wait = 30 SECONDS + //STOCK MARKET VARS + var/list/stocks = list() + var/list/last_read = list() + var/list/stock_brokers = list() + +/datum/controller/subsystem/stockmarket/Initialize(timeofday) + generateBrokers() + generateStocks() + return ..() + +/datum/controller/subsystem/stockmarket/fire(resumed = 0) + for(var/stock in stocks) + var/datum/stock/S = stock + S.process() + +//STOCK MARKET PROCS +/datum/controller/subsystem/stockmarket/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/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] District [rand(4,24)] [pick(company)]" + if (4) + pname = "[prob(10) ? "The " : null][pick(names)] District [rand(4,24)] [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/stockmarket/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/stockmarket/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 = "[pick(CONSONANTS)][pick(VOWELS)]E" + 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() diff --git a/code/modules/stock_market/articles.dm b/code/modules/stock_market/articles.dm new file mode 100644 index 000000000000..36c9016ee958 --- /dev/null +++ b/code/modules/stock_market/articles.dm @@ -0,0 +1,115 @@ +/* +* 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)]" + +/proc/ucfirsts(S) + var/list/L = splittext(S, " ") + var/list/M = list() + for (var/P in L) + M += ucfirst(P) + return jointext(M, " ") + +/datum/article + var/headline = "Something big is happening" + var/subtitle = "Investors panic as stock market collapses" + var/article = "God, it's going to be fun to randomly generate this." + var/author = "P. Pubbie" + var/spacetime = "" + var/opinion = 0 + var/ticks = 0 + var/datum/stock/about = null + var/outlet = "" + var/static/list/outlets = list() + var/static/list/default_tokens = list( \ + "buy" = list("buy!", "buy, buy, buy!", "get in now!", "ride the share value to the stars!"), \ + "company" = list("company", "conglomerate", "enterprise", "venture"), \ + "complete" = list("complete", "total", "absolute", "incredible"), \ + "development" = list("development", "unfolding of events", "turn of events", "new shit"), \ + "dip" = list("dip", "fall", "plunge", "decrease"), \ + "excited" = list("excited", "euphoric", "exhilarated", "thrilled", "stimulated"), \ + "expand_influence" = list("expands their influence over", "continues to dominate", "gains traction in", "rolls their new product line out in"), \ + "failure" = list("failure", "meltdown", "breakdown", "crash", "defeat", "wreck"), \ + "famous" = list("famous", "prominent", "leading", "renowned", "expert"), \ + "hit_shelves" = list("hit the shelves", "appeared on the market", "came out", "was released"), \ + "industry" = list("industry", "sector"), \ + "industrial" = list("industrial"), \ + "jobs" = list("workers", "clerks"), \ + "negative_outcome" = list("it's not leaving the shelves", "nobody seems to care", "it's a huge money sink", "they have already pulled all advertising and marketing support"), \ + "neutral_outcome" = list("it's not lifting off as expected", "it's not selling according to expectations", "it's only generating enough profit to cover the marketing and manufacturing costs", "it does not look like it will become a massive success", "it's experiencing modest sales"), \ + "positive_outcome" = list("it's already sold out", "it has already sold over one billion units", "suppliers cannot keep up with the wild demand", "several companies using this new technology are already reporting a projected increase in profits"), \ + "resounding" = list("resounding", "tremendous", "total", "massive", "terrific", "colossal"), \ + "rise" = list("rise", "increase", "fly off the positive side of the charts", "skyrocket", "lift off"), \ + "sell" = list("sell!", "sell, sell, sell!", "bail!", "abandon ship!", "get out before it's too late!", "evacuate!", "withdraw!"), \ + "signifying" = list("signifying", "indicating", "implying", "displaying", "suggesting"), \ + "sneak_peek" = list("review", "sneak peek", "preview", "exclusive look"), \ + "stock_market" = list("stock market", "stock exchange"), \ + "stockholder" = list("stockholder", "shareholder"), \ + "success" = list("success", "triumph", "victory"), \ + "this_time" = list("this week", "last week", "this month", "yesterday", "today", "a few days ago") \ + ) + +/datum/article/New() + ..() + if((outlets.len && !prob(100 / (outlets.len + 1))) || !outlets.len) + var/ON = generateOutletName() + if (!(ON in outlets)) + outlets[ON] = list() + outlet = ON + else + outlet = pick(outlets) + + var/list/authors = outlets[outlet] + if((authors.len && !prob(100 / (authors.len + 1))) || !authors.len) + var/AN = generateAuthorName() + outlets[outlet] += AN + author = AN + else + author = pick(authors) + + ticks = world.time + +/datum/article/proc/generateOutletName() + var/list/nouns = list("Post", "Herald", "Sun", "Tribune", "Mail", "Times", "Journal", "Report") + var/list/timely = list("Daily", "Hourly", "Weekly", "Biweekly", "Monthly", "Yearly") + + switch(rand(1,2)) + if (1) + return "The District [rand(4,24)] [pick(nouns)]" + if (2) + return "The [pick(timely)] [pick(nouns)]" + +/datum/article/proc/generateAuthorName() + switch(rand(1,3)) + if (1) + return "[pick(CONSONANTS)]. [pick(GLOB.last_names)]" + if (2) + return "[prob(50) ? pick(GLOB.first_names_male) : pick(GLOB.first_names_female)] [pick(CONSONANTS)].[prob(50) ? "[pick(CONSONANTS)]. " : null] [pick(GLOB.last_names)]" + if (3) + return "[prob(50) ? pick(GLOB.first_names_male) : pick(GLOB.first_names_female)] \"[prob(50) ? pick(GLOB.first_names_male) : pick(GLOB.first_names_female)]\" [pick(GLOB.last_names)]" + +/datum/article/proc/formatSpacetime() + var/ticksc = round(ticks/100) + ticksc = ticksc % 100000 + var/ticksp = "[ticksc]" + 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]" + +/datum/article/proc/formatArticle() + if (spacetime == "") + formatSpacetime() + var/output = "<div class='article'><div class='headline'>[headline]</div><div class='subtitle'>[subtitle]</div><div class='article-body'>[article]</div><div class='author'>[author]</div><div class='timestamp'>[spacetime]</div></div>" + return output + +/datum/article/proc/detokenize(token_string, list/industry_tokens, list/product_tokens = list()) + var/list/T_list = default_tokens.Copy() + for (var/I in industry_tokens) + T_list[I] = industry_tokens[I] + for (var/I in product_tokens) + T_list[I] = list(product_tokens[I]) + for (var/I in T_list) + token_string = replacetext(token_string, "%[I]%", pick(T_list[I])) + return ucfirst(token_string) diff --git a/code/modules/stock_market/computer.dm b/code/modules/stock_market/computer.dm new file mode 100644 index 000000000000..97b462f2764f --- /dev/null +++ b/code/modules/stock_market/computer.dm @@ -0,0 +1,320 @@ +// 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." + icon = 'icons/obj/computer.dmi' + icon_state = "oldcomp" + icon_screen = "stock_computer" + icon_keyboard = "no_keyboard" + var/logged_in = "Representative" + var/vmode = 1 + var/credits = 0 + interaction_flags_atom = INTERACT_ATOM_REQUIRES_DEXTERITY | INTERACT_ATOM_UI_INTERACT | INTERACT_ATOM_ATTACK_HAND | INTERACT_ATOM_REQUIRES_ANCHORED + + light_color = LIGHT_COLOR_GREEN + var/list/logs = list() + +/obj/machinery/computer/stockexchange/Initialize() + . = ..() + logged_in = "Representative" + +/obj/machinery/computer/stockexchange/proc/AdjustMonies(new_monies) + credits += new_monies + +/obj/machinery/computer/stockexchange/proc/RefundMonies(refund_monies) + if(refund_monies <= 0) + return + var/obj/item/holochip/holochip = new (get_turf(src)) + holochip.credits = refund_monies + holochip.name = "[holochip.credits] ahn holochip" + AdjustMonies(-1 * refund_monies) + +/obj/machinery/computer/stockexchange/proc/balance() + if (!logged_in) + return 0 + return credits + +/obj/machinery/computer/stockexchange/ui_interact(mob/user) + . = ..() + var/css={"<style> +.change { + font-weight: bold; + font-family: monospace; +} +.up { + background: #00a000; +} +.down { + background: #a00000; +} +.stable { + width: 100% + border-collapse: collapse; + border: 1px solid #305260; + border-spacing: 4px 4px; +} +.stable td, .stable th { + border: 1px solid #305260; + padding: 0px 3px; +} +.bankrupt { + border: 1px solid #a00000; + background: #a00000; +} + +a.updated { + color: red; +} +</style>"} + 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>" + dat += " <A href='byond://?src=[REF(src)];reclaimAhn=[REF(src)]'>-[credits] AHN-</A><br>" + for (var/datum/stock/S in SSstockmarket.last_read) + var/list/LR = SSstockmarket.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 += "<h3>Listed stocks</h3>" + + if (vmode == 0) + for (var/datum/stock/S in SSstockmarket.stocks) + var/mystocks = 0 + if (logged_in && (logged_in in S.shareholders)) + mystocks = S.shareholders[logged_in] + dat += "<hr /><div class='stock'><span class='company'>[S.name]</span> <span class='s_company'>([S.short_name])</span>[S.bankrupt ? " <b style='color:red'>BANKRUPT</b>" : null]<br>" + if (S.last_unification) + dat += "<b>Unified shares</b> [DisplayTimeText(world.time - S.last_unification)] ago.<br>" + dat += "<b>Current value per share:</b> [S.current_value] | <a href='?src=[REF(src)];viewhistory=[REF(S)]'>View history</a><br><br>" + dat += "You currently own <b>[mystocks]</b> shares in this company. There are [S.available_shares] purchasable shares on the market currently.<br>" + if (S.bankrupt) + dat += "You cannot buy or sell shares in a bankrupt company!<br><br>" + else + dat += "<a href='?src=[REF(src)];buyshares=[REF(S)]'>Buy shares</a> | <a href='?src=[REF(src)];sellshares=[REF(S)]'>Sell shares</a><br><br>" + dat += "<b>Prominent products:</b><br>" + for (var/prod in S.products) + dat += "<i>[prod]</i><br>" + var/news = 0 + if (logged_in) + var/list/LR = SSstockmarket.last_read[S] + var/lrt = LR[logged_in] + for (var/datum/article/A in S.articles) + if (A.ticks > lrt) + news = 1 + break + if (!news) + for (var/datum/stockEvent/E in S.events) + if (E.last_change > lrt && !E.hidden) + news = 1 + break + dat += "<a href='?src=[REF(src)];archive=[REF(S)]'>View news archives</a>[news ? " <span style='color:red'>(updated)</span>" : null]</div>" + else if (vmode == 1) + dat += "<b>Actions:</b> + Buy, - Sell, (A)rchives, (H)istory<br><br>" + dat += "<table class='stable'>" + dat += "<tr><th> </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 SSstockmarket.stocks) + var/mystocks = 0 + if (logged_in && (logged_in in S.shareholders)) + mystocks = S.shareholders[logged_in] + + if(S.bankrupt) + dat += "<tr class='bankrupt'>" + else + dat += "<tr>" + + if(S.disp_value_change > 0) + dat += "<td class='change up'>+</td>" + else if(S.disp_value_change < 0) + dat += "<td class='change down'>-</td>" + else + dat += "<td class='change'>=</td>" + + dat += "<td><b>[S.short_name]</b></td>" + dat += "<td>[S.name]</td>" + + if(!S.bankrupt) + dat += "<td>[S.current_value]</td>" + else + dat += "<td>0</td>" + + if(mystocks) + dat += "<td><b>[mystocks]</b></td>" + else + dat += "<td>0</td>" + + dat += "<td>[S.available_shares]</td>" + var/news = 0 + if (logged_in) + var/list/LR = SSstockmarket.last_read[S] + var/lrt = LR[logged_in] + for (var/datum/article/A in S.articles) + if (A.ticks > lrt) + news = 1 + break + if (!news) + for (var/datum/stockEvent/E in S.events) + if (E.last_change > lrt && !E.hidden) + news = 1 + break + dat += "<td>" + if (S.bankrupt) + dat += "<span class='linkOff'>+</span> <span class='linkOff'>-</span> " + else + dat += "<a href='?src=[REF(src)];buyshares=[REF(S)]'>+</a> <a href='?src=[REF(src)];sellshares=[REF(S)]'>-</a> " + dat += "<a href='?src=[REF(src)];archive=[REF(S)]' class='[news ? "updated" : "default"]'>(A)</a> <a href='?src=[REF(src)];viewhistory=[REF(S)]'>(H)</a></td>" + + dat += "</tr>" + + dat += "</table>" + + dat += "</body></html>" + var/datum/browser/popup = new(user, "computer", "Stock Exchange", 600, 600) + popup.set_content(dat) + popup.open() + +/obj/machinery/computer/stockexchange/Topic(href, href_list) + if (..()) + return 1 + + if (!usr || (!(usr in range(1, src)) && iscarbon(usr))) + usr.machine = src + + if (href_list["viewhistory"]) + var/datum/stock/S = locate(href_list["viewhistory"]) in SSstockmarket.stocks + if (S) + S.displayValues(usr) + + if (href_list["logout"]) + logged_in = null + + if (href_list["reclaimAhn"]) + RefundMonies(credits) + playsound(get_turf(src), 'sound/machines/terminal_prompt_confirm.ogg', 50, TRUE) + + if (href_list["buyshares"]) + var/datum/stock/S = locate(href_list["buyshares"]) in SSstockmarket.stocks + if (S) + buy_some_shares(S, usr) + + if (href_list["sellshares"]) + var/datum/stock/S = locate(href_list["sellshares"]) in SSstockmarket.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 logs) + dat += "[D]<br>" + var/datum/browser/popup = new(usr, "stock_logs", "Stock Transaction Logs", 600, 400) + popup.set_content(dat) + popup.open() + + if (href_list["archive"]) + var/datum/stock/S = locate(href_list["archive"]) + if (logged_in && logged_in != "") + var/list/LR = SSstockmarket.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>" + var/p = 0 + for (var/datum/stockEvent/E in S.events) + if (E.hidden) + continue + if (p > 0) + dat += "<hr>" + dat += "<div><b style='font-size:1.25em'>[E.current_title]</b><br>[E.current_desc]</div>" + p++ + dat += "</div><hr><div><h3>Articles</h3>" + p = 0 + for (var/datum/article/A in S.articles) + if (p > 0) + dat += "<hr>" + dat += "<div><b style='font-size:1.25em'>[A.headline]</b><br><i>[A.subtitle]</i><br><br>[A.article]<br>- [A.author], [A.spacetime] (via <i>[A.outlet]</i>)</div>" + p++ + dat += "</div></body></html>" + var/datum/browser/popup = new(usr, "archive_[S.name]", "Stock News", 600, 400) + popup.set_content(dat) + popup.open() + + if (href_list["cycleview"]) + if(vmode == TRUE) + vmode = 0 + else + vmode = 1 + src.add_fingerprint(usr) + src.updateUsrDialog() + +/obj/machinery/computer/stockexchange/proc/sell_some_shares(datum/stock/S, mob/user) + if (!user || !S) + return + var/li = logged_in + if (!li) + to_chat(user, span_danger("No active account on the console!")) + return + var/b = SSshuttle.points + var/avail = S.shareholders[logged_in] + if (!avail) + to_chat(user, span_danger("This account does not own any shares of [S.name]!")) + return + var/price = S.current_value + var/amt = round(input(user, "How many shares? \n(Have: [avail], unit price: [price])", "Sell shares in [S.name]", 0) as num|null) + amt = min(amt, S.shareholders[logged_in]) + + if (!user || (!(user in range(1, src)) && iscarbon(user))) + return + if (!amt) + return + if (li != logged_in) + return + b = SSshuttle.points + if (!isnum(b)) + to_chat(user, span_danger("No active account on the console!")) + return + + var/total = amt * S.current_value + if (!S.sellShares(logged_in, amt)) + to_chat(user, span_danger("Could not complete transaction.")) + return + var/feedback = span_notice("Sold [amt] shares of [S.name] at [S.current_value] a share for [total] ahn.") + to_chat(user, feedback) + logs += feedback + +/obj/machinery/computer/stockexchange/proc/buy_some_shares(datum/stock/S, mob/user) + if (!user || !S) + return + var/li = logged_in + if (!li) + to_chat(user, span_danger("No active account on the console!")) + return + var/b = balance() + if (!isnum(b)) + to_chat(user, span_danger("No active account on the console!")) + return + var/avail = S.available_shares + var/price = S.current_value + var/canbuy = round(b / price) + var/amt = round(input(user, "How many shares? \n(Available: [avail], unit price: [price], can buy: [canbuy])", "Buy shares in [S.name]", 0) as num|null) + if (!user || (!(user in range(1, src)) && iscarbon(user))) + return + if (li != logged_in) + return + b = balance() + if (!isnum(b)) + to_chat(user, span_danger("No active account on the console!")) + return + + amt = min(amt, S.available_shares, round(b / S.current_value)) + if (!amt) + return + if (!S.buyShares(logged_in, amt)) + to_chat(user, span_danger("Could not complete transaction.")) + return + + var/total = amt * S.current_value + var/feedback = span_notice("Bought [amt] shares of [S.name] at [S.current_value] a share for [total] ahn.") + to_chat(user, feedback) + logs += feedback diff --git a/code/modules/stock_market/events.dm b/code/modules/stock_market/events.dm new file mode 100644 index 000000000000..b8fc3391e79e --- /dev/null +++ b/code/modules/stock_market/events.dm @@ -0,0 +1,237 @@ +#define TIME_MULTIPLIER 0.7 // so I can speed up/slow down shit + +/datum/stockEvent + var/name = "event" + var/next_phase = 0 + var/datum/stock/company = null + var/current_title = "A company holding a conference in the W Corp Conference Center" + var/current_desc = "We will continue to monitor their stocks as the situation unfolds." + var/phase_id = 0 + var/hidden = 0 + var/finished = 0 + var/last_change = 0 + +/datum/stockEvent/process() + if (finished) + return + if (world.time > next_phase) + transition() + +/datum/stockEvent/proc/transition() + return + +/datum/stockEvent/proc/spacetime(ticks) + var/seconds = round(ticks / 10) + var/minutes = round(seconds / 60) + seconds -= minutes * 60 + return "[minutes] minute(s) and [seconds] second(s)" + +/datum/stockEvent/product + name = "product" + var/product_name = "" + var/datum/article/product_article = null + var/effect = 0 + +/datum/stockEvent/product/New(datum/stock/S) + company = S + var/mins = rand(5*TIME_MULTIPLIER,20*TIME_MULTIPLIER) + next_phase = mins * (600*TIME_MULTIPLIER) + world.time + current_title = "Product demo" + current_desc = S.industry.detokenize("[S.name] will unveil a new product on an upcoming %industrial% conference held at spacetime [spacetime(next_phase)]") + S.addEvent(src) + + +/datum/stockEvent/product/transition() + last_change = world.time + switch (phase_id) + if (0) + next_phase = world.time + rand(300*TIME_MULTIPLIER, 600*TIME_MULTIPLIER) * (10*TIME_MULTIPLIER) + product_name = company.industry.generateProductName(company.name) + current_title = "Product release: [product_name]" + current_desc = "[company.name] unveiled their newest product, [product_name], at a conference. Product release is expected to happen at spacetime [spacetime(next_phase)]." + var/datum/article/A = company.industry.generateInCharacterProductArticle(product_name, company) + product_article = A + effect = A.opinion + rand(-1, 1) + company.affectPublicOpinion(effect) + phase_id = 1 + if (1) + finished = 1 + hidden = 1 + company.addArticle(product_article) + effect += product_article.opinion * 5 + company.affectPublicOpinion(effect) + phase_id = 2 + company.generateEvent(type) + +/datum/stockEvent/bankruptcy + name = "bankruptcy" + var/effect = 0 + var/bailout_millions = 0 + +/datum/stockEvent/bankruptcy/New(datum/stock/S) + hidden = 1 + company = S + var/mins = rand(9*TIME_MULTIPLIER,60*TIME_MULTIPLIER) + bailout_millions = rand(70, 190) + next_phase = mins * 300*TIME_MULTIPLIER + world.time + current_title = "" + current_desc = "" + S.addEvent(src) + +/datum/stockEvent/bankruptcy/transition() + switch (phase_id) + if (0) + next_phase = world.time + rand(300*TIME_MULTIPLIER, 600*TIME_MULTIPLIER) * (10*TIME_MULTIPLIER) + var/datum/article/A = generateBankruptcyArticle() + if (!A.opinion) + effect = rand(5) * (prob(50) ? -1 : 1) + else + effect = prob(25) ? -A.opinion * rand(8) : A.opinion * rand(4) + company.addArticle(A) + company.affectPublicOpinion(rand(-6, -3)) + hidden = 0 + current_title = "Bailout pending due to bankruptcy" + current_desc = "The government prepared a press release, which will occur at spacetime [spacetime(next_phase)]." + phase_id = 1 + if (1) + next_phase = world.time + rand(300*TIME_MULTIPLIER, 600*TIME_MULTIPLIER) * (10*TIME_MULTIPLIER) + finished = 1 + if (effect <= -5 && prob(10)) + current_title = "[company.name]: Complete crash" + current_desc = "The company had gone bankrupt, was not bailed out and could not recover. No further stock trade will take place. All shares in the company are effectively worthless." + company.bankrupt = 1 + for (var/X in company.shareholders) + var/amt = company.shareholders[X] + SSstockmarket.balanceLog(X, -amt * company.current_value) + company.shareholders = list() + company.current_value = 0 + company.borrow_brokers = list() + SSstockmarket.generateStocks(1) + + var/bailout = (effect > 0 && prob(80)) || (effect < 0 && prob(20)) + current_title = "[company.name] [bailout ? "bailed out" : "on a painful rebound"]" + if (bailout) + current_desc = "The company has been bailed out by the government. Investors are highly optimistic." + company.affectPublicOpinion(abs(effect) * 2) + else + current_desc = "The company was not bailed out, but managed to crawl out of bankruptcy. Stockholder trust is severely dented." + company.affectPublicOpinion(-abs(effect) / 2) + company.generateEvent(type) + +/datum/stockEvent/bankruptcy/proc/generateBankruptcyArticle() + var/datum/article/A = new + var/list/bankrupt_reason = list("investor pessimism", "failure of product lines", "economic recession", "overblown inflation", "overblown deflation", + "collapsed pyramid schemes", "a Ponzi scheme", "economic terrorism", "extreme hedonism", "unfavourable economic climate", "rampant government corruption", + "divine conspiracy", "some total bullshit", "volatile plans" + ) + A.about = company + A.headline = pick( "[company.name] filing for bankruptcy", \ + "[company.name] unable to pay, investors run", \ + "[company.name] crashes, in foreclosure", \ + "[company.name] in dire need of ahn") + A.subtitle = "Investors panic, bailout pending" + if (prob(15)) + A.opinion = rand(-1, 1) + var/article = "Another one might bite the dust: [company.current_trend > 0 ? "despite their positive trend" : "in line with their failing model"], [company.name] \ + files for bankruptcy citing [pick(bankrupt_reason)]. The director of District [rand(4,24)] has been asked to bail the company out, " + if (!A.opinion) + article += "but no answer has been given by the administration to date. Our tip to stay safe is: %sell%" + else if (A.opinion > 0) + article += "and the administration responded positively. When the share value hits its lowest, it is a safe bet to %buy%" + else + article += "but the outlook is not good. For investors, now would be an ideal time to %sell%" + A.article = A.detokenize(article, company.industry.tokens) + return A + +/datum/stockEvent/arrest + name = "arrest" + var/female = 0 + var/tname = "Elvis Presley" + var/position = "CEO" + var/offenses = "murder" + var/effect = 0 + +/datum/stockEvent/arrest/New(datum/stock/S) + hidden = 1 + company = S + var/mins = rand(10*TIME_MULTIPLIER, 35*TIME_MULTIPLIER) + next_phase = mins * 600*TIME_MULTIPLIER + world.time + current_title = "" + current_desc = "" + female = prob(50) + if (prob(50)) + position = "C[prob(20) ? pick(VOWELS) : pick(CONSONANTS)]O" + else + position = ucfirsts(company.industry.detokenize("Lead %industrial% Engineer")) + offenses = "" + var/list/O = list("corruption", "murder", "grand theft", "assault", "battery", "drug possession", "burglary", "theft", "grand sabotage", "bribery", + "disorderly conduct", "treason", "sedition", "shoplifting", "tax evasion", "tax fraud", "insurance fraud", "perjury", "kidnapping", "manslaughter", "vandalism", "forgery", "extortion", "embezzlement", + "public indecency", "public intoxication", "trespassing", "loitering", "littering", "vigilantism", "squatting", "panhandling", "arson", "spacepodjacking", "shuttlejacking", "carjacking", "singularityjacking", + "dereliction of duty", "spacecraft piracy", "music piracy", "tabletop game piracy", "software piracy", "seniornapping", "clownnapping", "corginapping", "catnapping", + "sleeping on the job", "terrorism", "counterterrorism", "drug distribution", "insubordination", "jaywalking", "owning a computer", "owning a cellphone", "owning a PDA", "owning a pAI", "adultery", + "committing an unnatural act with another person", "corrupting public morals", "skateboarding without a license", "shitcurity", "erotic roleplay", "accidentally strangling a prostitute", + "gnome conspiracy", "Artificial Intelligence Ethics Amendment violation", "cloning", "full restoration necromancy", "owning a gun that can damage property", + "smuggling of sentient non-humans into the city", "erasure of a VIP", "imperfect erasure of a crime from reality", "deicide", "being an ass", + "conspiracy", "lycanthropy", "distortion cultivation", "cognitohazard breach", "soul stealing", "prosthetic ownership", "district taboo violation") + if(prob(60)) + var/offense = pick(O) + O -= offense + offense = "[prob(20) ? "attempted " : (prob(20) ? "being accessory to " : null)][offense][prob(5) ? " of the [pick("first", "second", "third", "fourth", "fifth", "sixth")] degree" : null]" + if (offenses == "") + offenses = offense + else + offenses += ", [offense]" + offenses += " and [prob(20) ? "attempted " : null][pick(O)]" // lazy + S.addEvent(src) + +/datum/stockEvent/arrest/transition() + switch (phase_id) + if (0) + tname = "[female ? pick(GLOB.first_names_female) : pick(GLOB.first_names_male)] [pick(GLOB.last_names)]" + next_phase = world.time + rand(300*TIME_MULTIPLIER, 600*TIME_MULTIPLIER) * (10*TIME_MULTIPLIER) + var/datum/article/A = generateArrestArticle() + if (!A.opinion) + effect = rand(5) * (prob(50) ? -1 : 1) + else + effect = prob(25) ? -A.opinion * rand(5) : A.opinion * rand(3) + company.addArticle(A) + company.affectPublicOpinion(rand(-3, -1)) + hidden = 0 + current_title = "Trial of [tname] ([position]) scheduled" + current_desc = "[female ? "She": "He"] has been charged with [offenses]; the trial is scheduled to occur at company time [spacetime(next_phase)]." + phase_id = 1 + if (1) + next_phase = world.time + rand(300*TIME_MULTIPLIER, 600*TIME_MULTIPLIER) * (10*TIME_MULTIPLIER) + finished = 1 + current_title = "[tname] [effect > 0 ? "acquitted" : "found guilty"]" + if (effect > 0) + current_desc = "The accused has been acquitted of all charges. Investors optimistic." + else + current_desc = "The accused has been found guilty of all charges. Investor trust takes massive hit." + company.affectPublicOpinion(effect) + company.generateEvent(type) + +/datum/stockEvent/arrest/proc/generateArrestArticle() + var/datum/article/A = new + A.about = company + A.headline = company.industry.detokenize(pick( \ + "[tname], [position] of [company.name] arrested", \ + "[position] of [company.name] facing jail time", \ + "[tname] behind bars", \ + "[position] of %industrial% company before trial", \ + "Police arrest [tname] in daring raid", \ + "Job vacancy ahead: [company.name]'s [position] in serious trouble")) + A.subtitle = "[A.author] reporting directly from the courtroom" + if (prob(15)) + A.opinion = rand(-1, 1) + var/article = "[pick("Security", "Law enforcement")] forces issued a statement that [tname], the [position] of [company.name], \ + the %famous% %industrial% %company% was arrested %this_time%. The trial has been scheduled and the statement reports that \ + the arrested individual is being charged with [offenses]. " + if (!A.opinion) + article += "While we cannot predict the outcome of this trial, our tip to stay safe is: %sell%" + else if (A.opinion > 0) + article += "Our own investigation shows that these charges are baseless and the arrest is most likely a publicity stunt. Our advice? You should %buy%" + else + article += "[tname] has a prior history of similar misdeeds and we're confident the charges will stand. For investors, now would be an ideal time to %sell%" + A.article = A.detokenize(article, company.industry.tokens) + return A diff --git a/code/modules/stock_market/industries.dm b/code/modules/stock_market/industries.dm new file mode 100644 index 000000000000..0b2edfcd7ada --- /dev/null +++ b/code/modules/stock_market/industries.dm @@ -0,0 +1,242 @@ +/* +* 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() + + var/list/title_templates = list("The brand new %product_name% by %company_name% will revolutionize %industry%", \ + "%jobs% rejoice as %product_name% hits shelves", \ + "Does %product_name% threaten to reorganize the %industrial% status quo?", \ + "%company_name% headed toward corporate renaissance with %product_name%") + + var/list/title_templates_neutral = list("%product_name%: as if nothing happened", \ + "Nothing new but the name: %product_name% not quite exciting %jobs%", \ + "Same old %company_name%, same old product", \ + "%product_name% underwhelms, but sells") + + var/list/title_templates_bad = list("%product_name% shaping up to be the disappointment of the century", \ + "Recipe for disaster: %company_name% releases %product_name%", \ + "Atrocious quality - %jobs% boycott %product_name%", \ + "%product_name%: Inside the worst product launch in recent history") + + var/list/title_templates_ooc = list("%company_name% is looking to enter the %industry% playing field with %product_name%", \ + "%company_name% broadens spectrum, %product_name% is their latest and greatest") + var/list/subtitle_templates = list( "%author% investigates whether or not you should invest!", \ + "%outlet%'s very own %author% takes it to the magnifying glass", \ + "%outlet% lets you know if you should use it", \ + "Read our top tips for investors", \ + "%author% wants you to know if it's a safe bet to buy") + +/datum/industry/proc/generateProductName(company_name) + return + +/datum/industry/proc/generateInCharacterProductArticle(product_name, datum/stock/S) + var/datum/article/A = new + var/list/add_tokens = list("company_name" = S.name, "product_name" = product_name, "outlet" = A.outlet, "author" = A.author) + A.about = S + A.opinion = rand(-1, 1) + + A.subtitle = A.detokenize(pick(subtitle_templates), tokens, add_tokens) + var/article = {"%company_name% %expand_influence% %industry%. [ucfirst(product_name)] %hit_shelves% %this_time% "} + if (A.opinion > 0) + A.headline = A.detokenize(pick(title_templates), tokens, add_tokens) + article += "but %positive_outcome%, %signifying% the %resounding% %success% the product is. The %stock_market% is %excited% over this %development%, and %stockholder% optimism is expected to %rise% as well as the stock value. Our advice: %buy%." + else if (A.opinion == 0) + A.headline = A.detokenize(pick(title_templates_neutral), tokens, add_tokens) + article += "but %neutral_outcome%. For the average %stockholder%, no significant change on the market will be apparent over this %development%. Our advice is to continue investing as if this product was never released." + else + A.headline = A.detokenize(pick(title_templates_bad), tokens, add_tokens) + article += "but %negative_outcome%. Following this %complete% %failure%, %stockholder% optimism and stock value are projected to %dip%. Our advice: %sell%." + A.article = A.detokenize(article, tokens, add_tokens) + return A + +/datum/industry/proc/detokenize(str) + for (var/T in tokens) + str = replacetext(str, "%[T]%", pick(tokens[T])) + return str + +/datum/industry/agriculture + name = "Agriculture" + tokens = list( \ + "industry" = list("agriculture", "farming", "botany", "horticulture", "hydroponics"), \ + "industrial" = list("agricultural", "horticultural", "botanical"), \ + "jobs" = list("farmers", "agricultural experts", "botanists", "assistant gardeners") + ) + title_templates = list( "The brand new %product_name% by %company_name% will revolutionize %industry%", \ + "%jobs% rejoice as %product_name% hits shelves", \ + "Does %product name% threaten to reorganize the %industrial% status quo?", \ + "Took it for a field trip: our first %sneak_peek% of %product_name%.", \ + "Reaping the fruits of %product_name% - %sneak_peek% by %author%", \ + "Cultivating a new %industrial% future with %product_name%", \ + "%company_name% grows and thrives: %product_name% now on the farmer's market", \ + "It's almost harvest season: %product_name% promises to ease your life", \ + "Become the best on the farmer's market with %product_name%", \ + "%product_name%: a gene-modified reimagination of an age-old classic") + + title_templates_ooc = list( "%company_name% is looking to enter the %industry% playing field with %product_name%", \ + "A questionable decision: %product_name% grown on the soil of %company_name%", \ + "%company_name% broadens spectrum, %product_name% is their latest and greatest", \ + "Will %company_name% grow on %industrial% wasteland? Owners of %product_name% may decide", \ + "%company_name% looking to reap profits off the %industrial% sector with %product_name%") + +/datum/industry/agriculture/generateProductName(company_name) + var/list/products = list("water tank", "cattle prod", "scythe", "plough", "sickle", "cultivator", "loy", "spade", "hoe", "daisy grubber", "cotton gin") + var/list/prefix = list("[company_name]'s ", "the [company_name] ", "the fully automatic ", "the full-duplex ", "the semi-automatic ", "the drone-mounted ", "the industry-leading ", "the world-class ") + var/list/suffix = list(" of farming", " multiplex", " +[rand(1,15)]", " [pick(CONSONANTS)][rand(1000, 9999)]", " hybrid", " maximus", " extreme") + return "[pick(prefix)][pick(products)][pick(suffix)]" + + + +/datum/industry/it + name = "Information Technology" + tokens = list( \ + "industry" = list("information technology", "computing", "computer industry"), \ + "industrial" = list("information technological", "computing", "computer industrial"), \ + "jobs" = list("coders", "electricians", "engineers", "programmers", "devops experts", "developers") + ) + +/datum/industry/it/proc/latin_number(n) + if (n < 20 || !(n % 10)) + switch(n) + if (0) + return "Nihil" + if (1) + return "Unus" + if (2) + return "Duo" + if (3) + return "Tres" + if (4) + return "Quattour" + if (5) + return "Quinque" + if (6) + return "Sex" + if (7) + return "Septem" + if (8) + return "Octo" + if (9) + return "Novem" + if (10) + return "Decim" + if (11) + return "Undecim" + if (12) + return "Duodecim" + if (13) + return "Tredecim" + if (14) + return "Quattourdecim" + if (15) + return "Quindecim" + if (16) + return "Sedecim" + if (17) + return "Septdecim" + if (18) + return "Duodeviginti" + if (19) + return "Undeviginti" + if (20) + return "Viginti" + if (30) + return "Triginta" + if (40) + return "Quadriginta" + if (50) + return "Quinquaginta" + if (60) + return "Sexaginta" + if (70) + return "Septuaginta" + if (80) + return "Octoginta" + if (90) + return "Nonaginta" + else + return "[latin_number(n - (n % 10))] [lowertext(latin_number(n % 10))]" + +/datum/industry/it/generateProductName(company_name) + var/list/products = list("generator", "laptop", "keyboard", "memory card", "display", "operating system", "processor", "graphics card", "nanobots", "power supply", "pAI", "mech", "capacitor", "cell") + var/list/prefix = list("the [company_name] ", "the high performance ", "the mobile ", "the portable ", "the professional ", "the extreme ", "the incredible ", "the blazing fast ", "the bleeding edge ", "the bluespace-powered ", null) + var/list/l_list = CONSONANTS + list("Seed ", "Radiant ", "Robust ", "Pentathon ", "Athlete ", "Phantom ", "Semper Fi ") + var/L = l_list + var/N = rand(1, 99) + var/prefix2 = "[L][N][prob(5) ? " " + latin_number(N) : null]" + return "[pick(prefix)][prefix2] [pick(products)]" + +/datum/industry/communications + name = "Communications" + tokens = list( \ + "industry" = list("telecommunications", "telecomms"), \ + "industrial" = list("telecommunicational"), \ + "jobs" = list("electrical engineers", "microengineers", "developers") + ) + +/datum/industry/communications/generateProductName(company_name) + var/list/products = list("mobile phone", "PDA", "tablet computer", "newscaster", "social network") + var/list/prefix = list("the [company_name] ", "the high performance ", "the mobile ", "the portable ", "the professional ", "the extreme ", "the incredible ", "the blazing fast ", "the bleeding edge ", null) + var/L = pick("Phone ", "Universe ", "Xperience ", "Next ", "Engin Y ", "Cyborg ") + var/N = rand(1,99) + var/prefix2 = "[L][N][prob(25) ? pick(" Tiny", " Mini", " Micro", " Slim", " Water", " Air", " Fire", " Earth", " Nano", " Pico", " Femto", " Planck") : null]" + return "[pick(prefix)][prefix2] [pick(products)]" + +/datum/industry/health + name = "Medicine" + tokens = list( \ + "industry" = list("medicine"), \ + "industrial" = list("medicinal"), \ + "jobs" = list("medical doctors", "nurses", "paramedics", "psychologists", "psychiatrists", "chemists") + ) + +/datum/industry/health/generateProductName(company_name) + var/list/prefix = list("amino", "nucleo", "nitro", "panto", "meth", "eth", "as", "algo", "coca", "hero", "lotsu", "opiod", "morph", "trinitro", "prop", "but", "acet", "acyclo", "lansop", "dyclo", "hydro", "oxycod", "vicod", "cannabi", "cryo", "dex", "chloro") + var/list/suffix = list("phen", "pirin", "pyrine", "ane", "amphetamine", "prazoline", "ine", "yl", "amine", "aminophen", "one", "ide", "phenate", "anol", "toulene", "glycerine", "vir", "tol", "trinic", "oxide") + var/list/uses = list("antidepressant", "analgesic", "anesthetic", "antiretroviral", "antiviral", "antibiotic", "cough drop", "depressant", "hangover cure", "homeopathic", "fertility drug", "hypnotic", "narcotic", "laxative", "multivitamin", "patch", "purgative", "relaxant", "steroid", "sleeping pill", "suppository", "tranquilizer") + return "[pick(prefix)][pick(suffix)], the [pick(uses)]" + +/datum/industry/consumer + name = "Consumer" + tokens = list( \ + "industry" = list("shops", "stores"), \ + "industrial" = list("consumer industrial"), \ + "jobs" = list("shopkeepers", "assistants", "manual daytime hygiene engineers", "janitors", "chefs", "cooks") + ) + +/datum/industry/consumer/generateProductName(company) + var/list/meat = list("chicken", "lizard", "corgi", "monkey", "goat", "fly", "xenomorph", "human", "walrus", "wendigo", "bear", "clown", "turkey", "pork", "carp", "crab", "mimic", "mystery") + var/list/qualifier = list("synthetic", "organic", "bio", "diet", "sugar-free", "paleolithic", "homeopathic", "recycled", "reclaimed", "vat-grown") + return "the [pick(qualifier)] [pick(meat)] meat product line" + +/datum/industry/mining + name = "Mining" + tokens = list( \ + "industry" = list("mines", "large scale mining operations"), \ + "industrial" = list("resource acquisitional"), \ + "jobs" = list("shaft miners", "drill operators", "mining foremen", "gibtonite handlers") + ) + +/datum/industry/mining/generateProductName(company) + var/list/equipment = list("drill", "pickaxe", "shovel", "jackhammer", "mini-pickaxe", "power hammer", "power gloves", "power armor", "hardsuit", "kinetic accelerator", "resonator", "oxygen tank", "emergency bike horn") + var/list/material = list("mauxite", "pharosium", "molitz", "adamantium", "mithril", "cobryl", "bohrum", "claretine", "viscerite", "syreline", "cerenkite", "plasmastone", "gold", "koshmarite", "phoron", "carbon dioxide") + return "the [pick(material)] [pick(equipment)]" + +/datum/industry/defense + name = "Defense" + tokens = list ( \ + "industry" = list("defense", "warfare", "security", "law enforcement"), \ + "industrial" = list("defense"), \ + "jobs" = list("security officers", "government officials", "soldiers", "weapons engineers") + ) + +/datum/industry/defense/generateProductName(company) + var/list/equipment = list("energy gun", "laser gun", "machine gun", "grenade", "stun baton", "artillery", "bomb", "attack drone", "missile", "chem sprayer") + var/list/material = list("bluespace", "stealth", "heat-seeking", "crime-seeking", "wide-range", "bioterror", "auto-reloading", "smart", "sentient", "rapid-fire", "species-targeting", "gibtonite", "mass-market", "perpetual-motion", "nuclear", "fission", "fusion") + return "the [pick(material)] [pick(equipment)]" diff --git a/code/modules/stock_market/stocks.dm b/code/modules/stock_market/stocks.dm new file mode 100644 index 000000000000..6de4697077eb --- /dev/null +++ b/code/modules/stock_market/stocks.dm @@ -0,0 +1,260 @@ +/datum/stock + var/name = "Stock" + var/short_name = "STK" + var/desc = "A company that does not exist." + var/list/values = list() + var/current_value = 10 + var/last_value = 10 + var/list/products = list() + + var/performance = 0 // The current performance of the company. Tends itself to 0 when no events happen. + + // These variables determine standard fluctuational patterns for this stock. + var/fluctuational_coefficient = 1 // How much the price fluctuates on an average daily basis + var/average_optimism = 0 // The history of shareholder optimism of this stock + var/current_trend = 0 + var/last_trend = 0 + var/speculation = 0 + var/bankrupt = 0 + + var/disp_value_change = 0 + var/optimism = 0 + var/last_unification = 0 + var/average_shares = 100 + var/outside_shareholders = 10000 // The amount of offstation people holding shares in this company. The higher it is, the more fluctuation it causes. + var/available_shares = 500000 + + var/list/borrow_brokers = list() + var/list/shareholders = list() + var/list/borrows = list() + var/list/events = list() + var/list/articles = list() + var/fluctuation_rate = 15 + var/fluctuation_counter = 0 + var/datum/industry/industry = null + +/datum/stock/process() + if (bankrupt) + return + fluctuation_counter++ + if (fluctuation_counter >= fluctuation_rate) + for (var/E in events) + var/datum/stockEvent/EV = E + EV.process() + fluctuation_counter = 0 + fluctuate() + +/datum/stock/proc/addEvent(datum/stockEvent/E) + events |= E + +/datum/stock/proc/addArticle(datum/article/A) + if (!(A in articles)) + articles.Insert(1, A) + A.ticks = world.time + +/datum/stock/proc/generateEvents() + var/list/types = typesof(/datum/stockEvent) - /datum/stockEvent + for (var/T in types) + generateEvent(T) + +/datum/stock/proc/generateEvent(T) + var/datum/stockEvent/E = new T(src) + addEvent(E) + +/datum/stock/proc/affectPublicOpinion(boost) + optimism += rand(0, 500) / 500 * boost + average_optimism += rand(0, 150) / 5000 * boost + speculation += rand(-1, 50) / 10 * boost + performance += rand(0, 150) / 100 * boost + +/datum/stock/proc/generateIndustry() + if (findtext(name, "Farms")) + industry = new /datum/industry/agriculture + else if (findtext(name, "Software") || findtext(name, "Programming") || findtext(name, "IT Group") || findtext(name, "Electronics") || findtext(name, "Electric") || findtext(name, "Nanotechnology")) + industry = new /datum/industry/it + else if (findtext(name, "Mobile") || findtext(name, "Communications")) + industry = new /datum/industry/communications + else if (findtext(name, "Pharmaceuticals") || findtext(name, "Health")) + industry = new /datum/industry/health + else if (findtext(name, "Wholesale") || findtext(name, "Stores")) + industry = new /datum/industry/consumer + else + var/ts = typesof(/datum/industry) - /datum/industry + var/in_t = pick(ts) + industry = new in_t + for (var/i = 0, i < rand(2, 5), i++) + products += industry.generateProductName(name) + +/datum/stock/proc/frc(amt) + var/shares = available_shares + outside_shareholders * average_shares + var/fr = amt / 100 / shares * fluctuational_coefficient * fluctuation_rate * max(-(current_trend / 100), 1) + if ((fr < 0 && speculation < 0) || (fr > 0 && speculation > 0)) + fr *= max(abs(speculation) / 5, 1) + else + fr /= max(abs(speculation) / 5, 1) + return fr + +/datum/stock/proc/supplyGrowth(amt) + var/fr = frc(amt) + available_shares += amt + if (abs(fr) < 0.0001) + return + current_value -= fr * current_value + +/datum/stock/proc/supplyDrop(amt) + supplyGrowth(-amt) + +/datum/stock/proc/fluctuate() + var/change = rand(-100, 100) / 10 + optimism * rand(200) / 10 + optimism -= (optimism - average_optimism) * (rand(10,80) / 1000) + var/shift_score = change + current_trend + var/as_score = abs(shift_score) + var/sh_change_dev = rand(-10, 10) / 10 + var/sh_change = shift_score / (as_score + 100) + sh_change_dev + var/shareholder_change = round(sh_change) + outside_shareholders += shareholder_change + var/share_change = shareholder_change * average_shares + if (as_score > 20 && prob(as_score / 4)) + var/avg_change_dev = rand(-10, 10) / 10 + var/avg_change = shift_score / (as_score + 100) + avg_change_dev + average_shares += avg_change + share_change += outside_shareholders * avg_change + + var/cv = last_value + supplyDrop(share_change) + available_shares += share_change // temporary + + if (prob(25)) + average_optimism = max(min(average_optimism + (rand(-3, 3) - current_trend * 0.15) / 100, 1), -1) + + var/aspec = abs(speculation) + if (prob((aspec - 75) * 2)) + speculation += rand(-4, 4) + else + if (prob(50)) + speculation += rand(-4, 4) + else + speculation += rand(-400, 0) / 1000 * speculation + if (prob(1) && prob(5)) // pop that bubble + speculation += rand(-4000, 0) / 1000 * speculation + + if (current_value < 5) + current_value = 5 + + if (performance != 0) + performance = rand(900,1050) / 1000 * performance + if (abs(performance) < 0.2) + performance = 0 + + disp_value_change = (cv < current_value) ? 1 : ((cv > current_value) ? -1 : 0) + last_value = current_value + if (values.len >= 50) + values.Cut(1,2) + values += current_value + + if (current_value < 10) + unifyShares() + + last_trend = current_trend + current_trend += rand(-200, 200) / 100 + optimism * rand(200) / 10 + max(50 - abs(speculation), 0) / 50 * rand(0, 200) / 1000 * (-current_trend) + max(speculation - 50, 0) * rand(0, 200) / 1000 * speculation / 400 + +/datum/stock/proc/unifyShares() + for (var/I in shareholders) + var/shr = shareholders[I] + if (shr % 2) + sellShares(I, 1) + shr -= 1 + shareholders[I] /= 2 + if (!shareholders[I]) + shareholders -= I + average_shares /= 2 + available_shares /= 2 + current_value *= 2 + last_unification = world.time + +/datum/stock/proc/modifyAccount(whose, by, force=0) + if (SSshuttle.points) + if (by < 0 && SSshuttle.points + by < 0 && !force) + return 0 + SSshuttle.points += by + SSstockmarket.balanceLog(whose, by) + return 1 + return 0 + +/datum/stock/proc/buyShares(who, howmany) + if (howmany <= 0) + return + howmany = round(howmany) + var/loss = howmany * current_value + if (available_shares < howmany) + return 0 + if (modifyAccount(who, -loss)) + supplyDrop(howmany) + if (!(who in shareholders)) + shareholders[who] = howmany + else + shareholders[who] += howmany + return 1 + return 0 + +/datum/stock/proc/sellShares(whose, howmany) + if (howmany < 0) + return + howmany = round(howmany) + var/gain = howmany * current_value + if (shareholders[whose] < howmany) + return 0 + if (modifyAccount(whose, gain)) + supplyGrowth(howmany) + shareholders[whose] -= howmany + if (shareholders[whose] <= 0) + shareholders -= whose + return 1 + return 0 + +/datum/stock/proc/displayValues(mob/user) + user << browse(plotBarGraph(values, "[name] share value per share"), "window=stock_[name];size=450x450") + +/datum/stock/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'> </td>" + else + output += "<td style='border:none; height: 20px; width: [cwid]px; background:black'> </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>" + + return "[output]</table>" diff --git a/lobotomy-corp13.dme b/lobotomy-corp13.dme index 16ba50f799ce..afb0903907b3 100644 --- a/lobotomy-corp13.dme +++ b/lobotomy-corp13.dme @@ -139,6 +139,7 @@ #include "code\__DEFINES\storage.dm" #include "code\__DEFINES\subsystems.dm" #include "code\__DEFINES\TeguDefines.dm" +#include "code\__DEFINES\text.dm" #include "code\__DEFINES\tgs.config.dm" #include "code\__DEFINES\tgs.dm" #include "code\__DEFINES\tgui.dm" @@ -362,6 +363,7 @@ #include "code\controllers\subsystem\speech_controller.dm" #include "code\controllers\subsystem\statpanel.dm" #include "code\controllers\subsystem\stickyban.dm" +#include "code\controllers\subsystem\stockmarket.dm" #include "code\controllers\subsystem\sun.dm" #include "code\controllers\subsystem\tcgsetup.dm" #include "code\controllers\subsystem\tgui.dm" @@ -3702,6 +3704,11 @@ #include "code\modules\station_goals\dna_vault.dm" #include "code\modules\station_goals\shield.dm" #include "code\modules\station_goals\station_goal.dm" +#include "code\modules\stock_market\articles.dm" +#include "code\modules\stock_market\computer.dm" +#include "code\modules\stock_market\events.dm" +#include "code\modules\stock_market\industries.dm" +#include "code\modules\stock_market\stocks.dm" #include "code\modules\suppressions\_core_suppression.dm" #include "code\modules\suppressions\command.dm" #include "code\modules\suppressions\control.dm" From c4a7c9e7558e72c79d0ffe2a05debdec4546305e Mon Sep 17 00:00:00 2001 From: InsightfulParasite <invaderchris4898@hotmail.com> Date: Mon, 30 Dec 2024 22:00:16 -0500 Subject: [PATCH 2/2] frusteration and difficulty --- code/modules/stock_market/computer.dm | 14 ++++++++++-- code/modules/stock_market/events.dm | 3 --- code/modules/stock_market/stocks.dm | 31 +++++++++++++-------------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/code/modules/stock_market/computer.dm b/code/modules/stock_market/computer.dm index 97b462f2764f..4f4a6dc2537a 100644 --- a/code/modules/stock_market/computer.dm +++ b/code/modules/stock_market/computer.dm @@ -248,6 +248,16 @@ a.updated { src.add_fingerprint(usr) src.updateUsrDialog() +/obj/machinery/computer/stockexchange/attackby(obj/I, mob/user, params) + if(istype(I, /obj/item/holochip)) + var/obj/item/holochip/H = I + var/ahn_amount = H.get_item_credit_value() + H.spend(ahn_amount) + AdjustMonies(ahn_amount) + return + else + return ..() + /obj/machinery/computer/stockexchange/proc/sell_some_shares(datum/stock/S, mob/user) if (!user || !S) return @@ -255,7 +265,7 @@ a.updated { if (!li) to_chat(user, span_danger("No active account on the console!")) return - var/b = SSshuttle.points + var/b = credits var/avail = S.shareholders[logged_in] if (!avail) to_chat(user, span_danger("This account does not own any shares of [S.name]!")) @@ -270,7 +280,7 @@ a.updated { return if (li != logged_in) return - b = SSshuttle.points + b = credits if (!isnum(b)) to_chat(user, span_danger("No active account on the console!")) return diff --git a/code/modules/stock_market/events.dm b/code/modules/stock_market/events.dm index b8fc3391e79e..8aa9b6be2307 100644 --- a/code/modules/stock_market/events.dm +++ b/code/modules/stock_market/events.dm @@ -100,9 +100,6 @@ current_title = "[company.name]: Complete crash" current_desc = "The company had gone bankrupt, was not bailed out and could not recover. No further stock trade will take place. All shares in the company are effectively worthless." company.bankrupt = 1 - for (var/X in company.shareholders) - var/amt = company.shareholders[X] - SSstockmarket.balanceLog(X, -amt * company.current_value) company.shareholders = list() company.current_value = 0 company.borrow_brokers = list() diff --git a/code/modules/stock_market/stocks.dm b/code/modules/stock_market/stocks.dm index 6de4697077eb..ace2db1bc6bb 100644 --- a/code/modules/stock_market/stocks.dm +++ b/code/modules/stock_market/stocks.dm @@ -172,43 +172,42 @@ current_value *= 2 last_unification = world.time -/datum/stock/proc/modifyAccount(whose, by, force=0) - if (SSshuttle.points) - if (by < 0 && SSshuttle.points + by < 0 && !force) +/datum/stock/proc/modifyAccount(obj/machinery/computer/stockexchange/stonker, by, force=0) + if (stonker.credits) + if (by < 0 && stonker.credits + by < 0 && !force) return 0 - SSshuttle.points += by - SSstockmarket.balanceLog(whose, by) + stonker.credits += by return 1 return 0 -/datum/stock/proc/buyShares(who, howmany) +/datum/stock/proc/buyShares(obj/machinery/computer/stockexchange/stonker, howmany) if (howmany <= 0) return howmany = round(howmany) var/loss = howmany * current_value if (available_shares < howmany) return 0 - if (modifyAccount(who, -loss)) + if (modifyAccount(stonker, -loss)) supplyDrop(howmany) - if (!(who in shareholders)) - shareholders[who] = howmany + if (!(stonker in shareholders)) + shareholders[stonker] = howmany else - shareholders[who] += howmany + shareholders[stonker] += howmany return 1 return 0 -/datum/stock/proc/sellShares(whose, howmany) +/datum/stock/proc/sellShares(obj/machinery/computer/stockexchange/stonker, howmany) if (howmany < 0) return howmany = round(howmany) var/gain = howmany * current_value - if (shareholders[whose] < howmany) + if (shareholders[stonker] < howmany) return 0 - if (modifyAccount(whose, gain)) + if (modifyAccount(stonker, gain)) supplyGrowth(howmany) - shareholders[whose] -= howmany - if (shareholders[whose] <= 0) - shareholders -= whose + shareholders[stonker] -= howmany + if (shareholders[stonker] <= 0) + shareholders -= stonker return 1 return 0