Skip to content

Commit

Permalink
More supply updates
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorDinamit committed Feb 13, 2024
1 parent faae0ea commit 23e7de7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 23 deletions.
31 changes: 15 additions & 16 deletions code/controllers/subsystems/supply.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ SUBSYSTEM_DEF(supply)
var/list/all_trading_stations = list()
/// All visible and available stations
var/list/visible_trading_stations = list()
/// All hidden/unavailable stations
var/list/hidden_trading_stations = list()
/// All factions in the world; Assoc list Name = Datum.
/// Trading stations get the datums from here
var/list/factions = list()
Expand Down Expand Up @@ -96,7 +94,6 @@ SUBSYSTEM_DEF(supply)
for(var/datum/trading_station/TS in all_trading_stations)
TS.RegainTradeStationsBudget()
qdel(TS)
hidden_trading_stations -= TS
visible_trading_stations -= TS
all_trading_stations -= TS

Expand Down Expand Up @@ -275,7 +272,7 @@ SUBSYSTEM_DEF(supply)

return order_queue_slot

/datum/controller/subsystem/supply/proc/PurchaseOrder(obj/machinery/trade_beacon/receiving/beacon, order_id)
/datum/controller/subsystem/supply/proc/PurchaseOrder(obj/machinery/trade_beacon/receiving/beacon, order_id, used_faction = FACTION_INDEPENDENT)
if(QDELETED(beacon) || !beacon || !order_id)
return

Expand All @@ -289,12 +286,12 @@ SUBSYSTEM_DEF(supply)
var/total_cost = order["cost"] + order["fee"]
var/is_requestor_master = (requesting_account == master_account) ? TRUE : FALSE

Buy(beacon, master_account, shopping_list, !is_requestor_master, requesting_account.owner_name)
Buy(beacon, master_account, shopping_list, !is_requestor_master, requesting_account.owner_name, used_faction)
if(!is_requestor_master)
requesting_account.transfer(master_account, total_cost, "Order Request")
CreateLogEntry("Order", requesting_account.owner_name, viewable_contents, total_cost)
CreateLogEntry("Order", requesting_account.owner_name, used_faction, viewable_contents, total_cost)

/datum/controller/subsystem/supply/proc/Buy(obj/machinery/trade_beacon/receiving/senderBeacon, datum/money_account/account, list/shopList, is_order = FALSE, buyer_name = null)
/datum/controller/subsystem/supply/proc/Buy(obj/machinery/trade_beacon/receiving/senderBeacon, datum/money_account/account, list/shopList, is_order = FALSE, buyer_name = null, used_faction = FACTION_INDEPENDENT)
if(QDELETED(senderBeacon) || !istype(senderBeacon) || !account || !RecursiveLen(shopList))
return FALSE

Expand Down Expand Up @@ -348,14 +345,17 @@ SUBSYSTEM_DEF(supply)
if(count_of_all > 1)
invoice_location = C

CreateLogEntry("Shipping", account.owner_name, order_contents_info, price_for_all, FALSE, invoice_location)
CreateLogEntry("Shipping", account.owner_name, used_faction, order_contents_info, price_for_all, FALSE, invoice_location)
account.withdraw(price_for_all, "Purchase", "Trade Network")
return TRUE

/datum/controller/subsystem/supply/proc/Export(obj/machinery/trade_beacon/sending/senderBeacon, datum/money_account/moneyAccount)
/datum/controller/subsystem/supply/proc/Export(obj/machinery/trade_beacon/sending/senderBeacon, datum/money_account/moneyAccount, used_faction = FACTION_INDEPENDENT)
if(QDELETED(senderBeacon))
return

if(!senderBeacon.StartExport())
return

var/invoice_contents_info
var/export_count = 0
var/cost = 0
Expand Down Expand Up @@ -392,31 +392,30 @@ SUBSYSTEM_DEF(supply)
if(export_count > 100)
break

senderBeacon.StartExport()
moneyAccount.deposit(cost, "Export", "Trade Network")

if(invoice_contents_info) // If no info, then nothing was exported
CreateLogEntry("Export", moneyAccount.owner_name, invoice_contents_info, cost, FALSE, get_turf(senderBeacon))
CreateLogEntry("Export", moneyAccount.owner_name, used_faction, invoice_contents_info, cost, FALSE, get_turf(senderBeacon))
return TRUE

// Logging

/datum/controller/subsystem/supply/proc/CreateLogEntry(type, ordering_account, contents, total_paid, create_invoice = FALSE, invoice_location = null)
/datum/controller/subsystem/supply/proc/CreateLogEntry(type, ordering_account, assoc_faction = FACTION_INDEPENDENT, contents, total_paid, create_invoice = FALSE, invoice_location = null)
var/log_id

switch(type)
if("Shipping")
log_id = "[++shipping_invoice_number]-S"
shipping_log.Add(list(list("id" = log_id, "ordering_acct" = ordering_account, "contents" = contents, "total_paid" = total_paid, "time" = time2text(world.time, "hh:mm"))))
shipping_log.Add(list(list("id" = log_id, "ordering_acct" = ordering_account, "assoc_faction" = assoc_faction, "contents" = contents, "total_paid" = total_paid, "time" = time2text(world.time, "hh:mm"))))
if("Export")
log_id = "[++export_invoice_number]-E"
export_log.Add(list(list("id" = log_id, "ordering_acct" = ordering_account, "contents" = contents, "total_paid" = total_paid, "time" = time2text(world.time, "hh:mm"))))
export_log.Add(list(list("id" = log_id, "ordering_acct" = ordering_account, "assoc_faction" = assoc_faction, "contents" = contents, "total_paid" = total_paid, "time" = time2text(world.time, "hh:mm"))))
if("Special Offer")
log_id = "[++offer_invoice_number]-SO"
offer_log.Add(list(list("id" = log_id, "ordering_acct" = ordering_account, "contents" = contents, "total_paid" = total_paid, "time" = time2text(world.time, "hh:mm"))))
offer_log.Add(list(list("id" = log_id, "ordering_acct" = ordering_account, "assoc_faction" = assoc_faction, "contents" = contents, "total_paid" = total_paid, "time" = time2text(world.time, "hh:mm"))))
if("Order")
log_id = "[++order_number]-O"
order_log.Add(list(list("id" = log_id, "ordering_acct" = ordering_account, "contents" = contents, "total_paid" = total_paid, "time" = time2text(world.time, "hh:mm"))))
order_log.Add(list(list("id" = log_id, "ordering_acct" = ordering_account, "assoc_faction" = assoc_faction, "contents" = contents, "total_paid" = total_paid, "time" = time2text(world.time, "hh:mm"))))
else
return

Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/trade_beacon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
name = "sending trade beacon"
icon_state = "beacon_sending"
var/export_cooldown
var/export_cooldown_time = 120 SECONDS
var/export_cooldown_time = 90 SECONDS

/obj/machinery/trade_beacon/sending/Initialize()
. = ..()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@
return TRUE

if(href_list["PRG_log_screen"])
log_screen = input("Select log type", "Log Type", null) as null|anything in LOG_SCREEN_LIST
if(!(href_list["PRG_log_screen"] in LOG_SCREEN_LIST))
return FALSE

log_screen = href_list["PRG_log_screen"]
current_log_page = 1
return TRUE

Expand Down Expand Up @@ -595,7 +598,7 @@
if(get_area(receiving) != get_area(computer) && program_type != "master")
to_chat(usr, SPAN_WARNING("ERROR: Receiving beacon is too far from \the [computer]."))
return
if(!SSsupply.Buy(receiving, account, shopping_list))
if(!SSsupply.Buy(receiving, account, shopping_list, FALSE, null, faction))
to_chat(usr, SPAN_WARNING("ERROR: Purchase failed."))
return FALSE
ResetShopList()
Expand All @@ -606,7 +609,7 @@
if(get_area(sending) != get_area(computer) && program_type != "master")
to_chat(usr, SPAN_WARNING("ERROR: Sending beacon is too far from \the [computer]."))
return
SSsupply.Export(sending, account)
SSsupply.Export(sending, account, faction)
return TRUE

if(href_list["PRG_approve_order"])
Expand All @@ -625,7 +628,7 @@
to_chat(usr, SPAN_WARNING("ERROR: Not enough funds in requesting account ([requesting_account.owner_name] #[requesting_account.account_number])."))
return

SSsupply.PurchaseOrder(receiving, order)
SSsupply.PurchaseOrder(receiving, order, faction)
SSsupply.order_queue.Remove(order)
if(current_order == order)
current_order = null
Expand All @@ -652,6 +655,7 @@
dat += " | "
dat += trade_screen == CART_SCREEN ? "<b><u>Cart</u></b>" :"<A href='?src=\ref[src];PRG_trade_screen=[CART_SCREEN]'>Cart</A>"
dat += " | "
dat += trade_screen == LOG_SCREEN ? "<b><u>Logs</u></b>" :"<A href='?src=\ref[src];PRG_trade_screen=[LOG_SCREEN]'>Logs</A>"
dat += "<A href='?src=\ref[src];PC_exit=1'>Exit</A>"

dat += "<hr>"
Expand Down Expand Up @@ -754,9 +758,12 @@
if(!sending)
dat += "<b>Sending beacon is missing!</b>"
else
dat += "<A href='?src=\ref[src];PRG_update=1'>Update</A>"
dat += "<A href='?src=\ref[src];PRG_update=1'>Update</A> "
dat += "<A href='?src=\ref[src];PRG_export=1'>Export</A>"
dat += "<hr>"
if(sending.export_cooldown > world.time)
dat += "<b>Export cooldown: [round(sending.export_cooldown - world.time) / 1 SECONDS] seconds</b>"
dat += "<hr>"
var/total_cost = 0
for(var/atom/movable/AM in sending.GetObjects())
if(ishuman(AM))
Expand All @@ -767,12 +774,14 @@
var/cost = 0
for(var/atom/movable/item in reverselist(contents_incl_self))
cost += get_value(item)
if(!cost)
continue
dat += "- [AM.name] ([cost] [GLOB.using_map.local_currency_name_short])<br>"
total_cost += cost
if(total_cost)
dat += "<b>Total export cost: [total_cost] [GLOB.using_map.local_currency_name_short]</b>"
else
dat += "<b>There is no items within sending beacon's range!</b>"
dat += "<b>There is no items for export within sending beacon's range!</b>"

if(trade_screen == CART_SCREEN)
dat += "<A href='?src=\ref[src];PRG_receive=1'>Purchase</A> | "
Expand All @@ -794,6 +803,34 @@
dat += "<br>"
dat += "<br>"

if(trade_screen == LOG_SCREEN)
dat += trade_screen == LOG_SHIPPING ? "<b><u>Shipping</u></b>" :"<A href='?src=\ref[src];PRG_log_screen=[LOG_SHIPPING]'>Shipping</A>"
dat += " | "
dat += trade_screen == LOG_EXPORT ? "<b><u>Export</u></b>" :"<A href='?src=\ref[src];PRG_log_screen=[LOG_EXPORT]'>Export</A>"

dat += "<hr>"

switch(log_screen)
if(LOG_SHIPPING)
for(var/list/log in reverseRange(SSsupply.shipping_log))
for(var/log in reverseRange(SSsupply.export_log))
dat += "Time: [log["time"]]<br>"
dat += "Account: [log["ordering_acct"]]<br>"
dat += "Link: [log["assoc_faction"]]<br>"
dat += "Total invoice: [log["total_paid"]] [GLOB.using_map.local_currency_name_short]<br>"
dat += "Articles bought: [log["contents"]]<br>"
dat += "<A href='?src=\ref[src];PRG_print=[log["id"]]'>Print</A>"
dat += "<hr>"
if(LOG_EXPORT)
for(var/log in reverseRange(SSsupply.export_log))
dat += "Time: [log["time"]]<br>"
dat += "Account: [log["ordering_acct"]]<br>"
dat += "Link: [log["assoc_faction"]]<br>"
dat += "Total invoice: [log["total_paid"]] [GLOB.using_map.local_currency_name_short]<br>"
dat += "Articles sold: [log["contents"]]<br>"
dat += "<A href='?src=\ref[src];PRG_print=[log["id"]]'>Print</A>"
dat += "<hr>"

var/datum/browser/popup = new(user, "supply_prg", "Trade Network", 600, 680)
popup.set_content(dat)
popup.open()
Expand Down

0 comments on commit 23e7de7

Please sign in to comment.