/obj/machinery/computer/stockexchange name = "stock exchange computer" icon = 'icons/obj/computer.dmi' icon_state = "oldcomp" icon_screen = "stock_computer" icon_keyboard = "no_keyboard" var/logged_in = "Cargo Department" var/vmode = 1 clockwork = TRUE //it'd look weird /obj/machinery/computer/stockexchange/New() ..() logged_in = "[world.name] Cargo Department" /obj/machinery/computer/stockexchange/proc/balance() if (!logged_in) return 0 return SSshuttle.points /obj/machinery/computer/stockexchange/attack_hand(var/mob/user) if(..()) return user.machine = src var/css={""} var/dat = "[station_name()] Stock Exchange[css]" dat += "Welcome, [logged_in]
Credits: [balance()]
" for (var/datum/stock/S in stockExchange.last_read) var/list/LR = stockExchange.last_read[S] if (!(logged_in in LR)) LR[logged_in] = 0 dat += "View mode: [vmode ? "Compact" : "Full"] " dat += "Stock Transaction Log: Check
" dat += "This is a work in progress. Certain features may not be available." dat += "

Listed stocks

" if (vmode == 0) for (var/datum/stock/S in stockExchange.stocks) var/mystocks = 0 if (logged_in && (logged_in in S.shareholders)) mystocks = S.shareholders[logged_in] dat += "
[S.name] ([S.short_name])[S.bankrupt ? " BANKRUPT" : null]
" if (S.last_unification) dat += "Unified shares [(world.time - S.last_unification) / 600] minutes ago.
" dat += "Current value per share: [S.current_value] | View history

" dat += "You currently own [mystocks] shares in this company. There are [S.available_shares] purchasable shares on the market currently.
" if (S.bankrupt) dat += "You cannot buy or sell shares in a bankrupt company!

" else dat += "Buy shares | Sell shares

" dat += "Prominent products:
" for (var/prod in S.products) dat += "[prod]
" dat += "
Borrow options:
" if (S.borrow_brokers.len) for (var/datum/borrow/B in S.borrow_brokers) dat += "[B.broker] offers [B.share_amount] shares for borrowing, for a deposit of [B.deposit * 100]% of the shares' value.
" dat += "The broker expects the return of the shares after [B.lease_time / 600] minutes, with a grace period of [B.grace_time / 600] minute(s).
" dat += "This offer expires in [(B.offer_expires - world.time) / 600] minutes.
" dat += "Note: If you do not return all shares by the end of the grace period, you will lose your deposit and the value of all unreturned shares at current value from your account!
" dat += "Note: You cannot withdraw or transfer money off your account while a borrow is active.
" dat += "Take offer (Estimated deposit: [B.deposit * S.current_value * B.share_amount] credits)

" else dat += "No borrow options available

" for (var/datum/borrow/B in S.borrows) if (B.borrower == logged_in) dat += "You are borrowing [B.share_amount] shares from [B.broker].
" dat += "Your deposit riding on the deal is [B.deposit] credits.
" if (world.time < B.lease_expires) dat += "You are expected to return the borrowed shares in [(B.lease_expires - world.time) / 600] minutes.

" else dat += "The brokering agency is collecting. You still owe them [B.share_debt] shares, which you have [(B.grace_expires - world.time) / 600] minutes to present.

" var/news = 0 if (logged_in) var/list/LR = stockExchange.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 += "View news archives[news ? " (updated)" : null]
" else if (vmode == 1) dat += "Actions: + Buy, - Sell, (A)rchives, (H)istory

" dat += "" dat += "" for (var/datum/stock/S in stockExchange.stocks) var/mystocks = 0 if (logged_in && (logged_in in S.shareholders)) mystocks = S.shareholders[logged_in] if(S.bankrupt) dat += "" else dat += "" if(S.disp_value_change > 0) dat += "" else if(S.disp_value_change < 0) dat += "" else dat += "" dat += "" dat += "" if(!S.bankrupt) dat += "" else dat += "" if(mystocks) dat += "" else dat += "" dat += "" var/news = 0 if (logged_in) var/list/LR = stockExchange.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 += "" dat += "" dat += "
 IDNameValueOwnedAvailActions
+-=[S.short_name][S.name][S.current_value]0[mystocks]0[S.available_shares]" if (S.bankrupt) dat += "+ - " else dat += "+ - " dat += "(A) (H)
" dat += "" var/datum/browser/popup = new(user, "computer", "Stock Exchange", 600, 600) popup.set_content(dat) popup.set_title_image(user.browse_rsc_icon(src.icon, src.icon_state)) popup.open() return /obj/machinery/computer/stockexchange/proc/sell_some_shares(var/datum/stock/S, var/mob/user) if (!user || !S) return var/li = logged_in if (!li) user << "No active account on the console!" return var/b = SSshuttle.points var/avail = S.shareholders[logged_in] if (!avail) user << "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))) return if (!amt) return if (li != logged_in) return b = SSshuttle.points if (!isnum(b)) user << "No active account on the console!" return var/total = amt * S.current_value if (!S.sellShares(logged_in, amt)) user << "Could not complete transaction." return user << "Sold [amt] shares of [S.name] at [S.current_value] a share for [total] credits." stockExchange.add_log(/datum/stock_log/sell, user.name, S.name, amt, S.current_value, total) /obj/machinery/computer/stockexchange/proc/buy_some_shares(var/datum/stock/S, var/mob/user) if (!user || !S) return var/li = logged_in if (!li) user << "No active account on the console!" return var/b = balance() if (!isnum(b)) user << "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))) return if (li != logged_in) return b = balance() if (!isnum(b)) user << "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)) user << "<Could not complete transaction." return var/total = amt * S.current_value user << "Bought [amt] shares of [S.name] at [S.current_value] a share for [total] credits." stockExchange.add_log(/datum/stock_log/buy, user.name, S.name, amt, S.current_value, total) /obj/machinery/computer/stockexchange/proc/do_borrowing_deal(var/datum/borrow/B, var/mob/user) if (B.stock.borrow(B, logged_in)) user << "You successfully borrowed [B.share_amount] shares. Deposit: [B.deposit]." stockExchange.add_log(/datum/stock_log/borrow, user.name, B.stock.name, B.share_amount, B.deposit) else user << "Could not complete transaction. Check your account balance." /obj/machinery/computer/stockexchange/Topic(href, href_list) if (..()) return 1 if (usr in range(1, src)) usr.machine = src if (href_list["viewhistory"]) var/datum/stock/S = locate(href_list["viewhistory"]) if (S) S.displayValues(usr) if (href_list["logout"]) logged_in = null if (href_list["buyshares"]) var/datum/stock/S = locate(href_list["buyshares"]) if (S) buy_some_shares(S, usr) if (href_list["sellshares"]) var/datum/stock/S = locate(href_list["sellshares"]) if (S) sell_some_shares(S, usr) if (href_list["take"]) var/datum/borrow/B = locate(href_list["take"]) if (B && !B.lease_expires) do_borrowing_deal(B, usr) if (href_list["show_logs"]) var/dat = "Stock Transaction Logs

Stock Transaction Logs

Refresh

" for(var/D in stockExchange.logs) var/datum/stock_log/L = D if(istype(L, /datum/stock_log/buy)) dat += "[L.time] | [L.user_name] bought [L.stocks] stocks at [L.shareprice] a share for [L.money] total credits in [L.company_name].
" continue if(istype(L, /datum/stock_log/sell)) dat += "[L.time] | [L.user_name] sold [L.stocks] stocks at [L.shareprice] a share for [L.money] total credits from [L.company_name].
" continue if(istype(L, /datum/stock_log/borrow)) dat += "[L.time] | [L.user_name] borrowed [L.stocks] stocks with a deposit of [L.money] credits in [L.company_name].
" continue var/datum/browser/popup = new(usr, "stock_logs", "Stock Transaction Logs", 600, 400) popup.set_content(dat) popup.set_title_image(usr.browse_rsc_icon(src.icon, src.icon_state)) popup.open() if (href_list["archive"]) var/datum/stock/S = locate(href_list["archive"]) if (logged_in && logged_in != "") var/list/LR = stockExchange.last_read[S] LR[logged_in] = world.time var/dat = "News feed for [S.name]

News feed for [S.name]

Refresh
" dat += "

Events

" var/p = 0 for (var/datum/stockEvent/E in S.events) if (E.hidden) continue if (p > 0) dat += "
" dat += "
[E.current_title]
[E.current_desc]
" p++ dat += "

Articles

" p = 0 for (var/datum/article/A in S.articles) if (p > 0) dat += "
" dat += "
[A.headline]
[A.subtitle]

[A.article]
- [A.author], [A.spacetime] (via [A.outlet])
" p++ dat += "
" var/datum/browser/popup = new(usr, "archive_[S.name]", "Stock News", 600, 400) popup.set_content(dat) popup.set_title_image(usr.browse_rsc_icon(src.icon, src.icon_state)) popup.open() if (href_list["cycleview"]) vmode++ if (vmode > 1) vmode = 0 src.add_fingerprint(usr) src.updateUsrDialog()