Skip to content

Commit

Permalink
Market crash effect!
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorDinamit committed Feb 14, 2024
1 parent 24560e5 commit bf88f40
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
32 changes: 31 additions & 1 deletion code/controllers/subsystems/supply.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ SUBSYSTEM_DEF(supply)
var/order_queue_id = 0
var/list/order_queue = list()

// For exporting
var/list/export_modifier = list()
var/list/export_counter = list()
/// Paths of atoms that are entirely unaffected by export price modifiers
var/list/export_modifier_exempt_types = list(
/obj/item/stack,
/obj/item/reagent_containers,
)

/datum/controller/subsystem/supply/Initialize()
. = ..()
for(var/faction_type in typesof(/datum/trade_faction))
Expand Down Expand Up @@ -70,6 +79,9 @@ SUBSYSTEM_DEF(supply)
/datum/controller/subsystem/supply/fire()
for(var/datum/money_account/A in all_money_accounts)
A.PayrollTick()
for(var/A in export_counter)
export_counter[A] = max(0, export_counter[A] -= 10000)
ExportCounterCheck()

/datum/controller/subsystem/supply/proc/GetFaction(fac)
if(!(fac in factions))
Expand Down Expand Up @@ -382,12 +394,16 @@ SUBSYSTEM_DEF(supply)
if(istype(item, /obj/screen))
continue

var/item_price = get_value(item)
var/item_price = GetExportValue(item)
var/export_value = item_price

if(export_value)
invoice_contents_info += "<li>[item.name]</li>"
cost += export_value
if(!(is_path_in_list(item.type, export_modifier_exempt_types)))
if(!(item.type in export_counter))
export_counter[item.type] = 0
export_counter[item.type] += export_value
//SEND_SIGNAL(src, COMSIG_TRADE_BEACON, item)
qdel(item)
++export_count
Expand All @@ -401,12 +417,26 @@ SUBSYSTEM_DEF(supply)
if(export_count > 100)
break

ExportCounterCheck()

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

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

/datum/controller/subsystem/supply/proc/GetExportValue(atom/A)
. = get_value(A)
if(A.type in export_modifier)
. *= export_modifier[A.type]

/datum/controller/subsystem/supply/proc/ExportCounterCheck()
for(var/A in export_counter)
if(export_counter[A] > 25000)
export_modifier[A] = clamp(round(25000 / export_counter[A], 0.01), 0.5, 2.0)
else if(A in export_modifier)
export_modifier -= A

// Logging

/datum/controller/subsystem/supply/proc/CreateLogEntry(type, ordering_account, assoc_faction = FACTION_INDEPENDENT, contents, total_paid, create_invoice = FALSE, invoice_location = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,11 +787,20 @@
if(is_path_in_list(/mob/living/carbon/human, contents_incl_self))
continue
var/cost = 0
var/normal_cost = 0
for(var/atom/movable/item in reverselist(contents_incl_self))
cost += get_value(item)
cost += SSsupply.GetExportValue(item)
normal_cost += get_value(item)
if(!cost)
continue
dat += "- [AM.name] ([cost] [GLOB.using_map.local_currency_name_short])<br>"
dat += "- [AM.name] ([cost] [GLOB.using_map.local_currency_name_short])"
if(cost < normal_cost)
var/percent_diff = round(cost / normal_cost, 0.01) * 100
dat += " <span style='color: [COLOR_RED]'>([percent_diff]%)</span>"
else if(cost > normal_cost)
var/percent_diff = round(cost / normal_cost, 0.01) * 100
dat += " <span style='color: [COLOR_GREEN]'>([percent_diff]%)</span>"
dat += "<br>"
total_cost += cost
if(total_cost)
dat += "<b>Total export cost: [total_cost] [GLOB.using_map.local_currency_name_short]</b>"
Expand Down

0 comments on commit bf88f40

Please sign in to comment.