diff --git a/code/modules/cargo/order.dm b/code/modules/cargo/order.dm index 66987b3f0a1..1c52f8436aa 100644 --- a/code/modules/cargo/order.dm +++ b/code/modules/cargo/order.dm @@ -217,15 +217,11 @@ pack.cost += cost_increase /// Custom type of order who's supply pack can be safely deleted -/datum/supply_order/disposable - /datum/supply_order/disposable/Destroy(force) QDEL_NULL(pack) return ..() /// Custom material order to append cargo crate value to the final order cost -/datum/supply_order/disposable/materials - /datum/supply_order/disposable/materials/get_final_cost() return (..() + CARGO_CRATE_VALUE) diff --git a/code/modules/cargo/packs/_packs.dm b/code/modules/cargo/packs/_packs.dm index 44d3cb46aea..71f8ed26c7a 100644 --- a/code/modules/cargo/packs/_packs.dm +++ b/code/modules/cargo/packs/_packs.dm @@ -149,24 +149,26 @@ src.cost = cost src.contains = contains -/datum/supply_pack/custom/minerals/fill(obj/structure/closet/crate/C) +///Alters material amrkey & adjust order quantities if they exceed whats on the market +/datum/supply_pack/custom/minerals/proc/adjust_market() + . = list() for(var/obj/item/stack/sheet/possible_stack as anything in contains) - var/material_type = initial(possible_stack.material_type) + var/material_type = possible_stack.material_type //in case we ordered more than what's in the market at the time due to market fluctuations //we find the min of what was ordered & what's actually available in the market at this point of time var/market_quantity = SSstock_market.materials_quantity[material_type] - var/available_quantity = min(contains[possible_stack], market_quantity) - if(!available_quantity) - continue + var/available_quantity = contains[possible_stack] + if(available_quantity > market_quantity) + var/message = "[possible_stack::singular_name]: requested=[available_quantity] sheets, available=[market_quantity] sheets, adjusted=[market_quantity - available_quantity] sheets." + available_quantity = market_quantity + if(!available_quantity) + . += "[possible_stack::singular_name]: order cancelled due to insufficient sheets in the market." + contains -= possible_stack + continue + . += message - //spawn the ordered stack inside the crate - var/sheets_to_spawn = available_quantity - while(sheets_to_spawn) - var/spawn_quantity = min(sheets_to_spawn, MAX_STACK_SIZE) - var/obj/item/stack/sheet/ordered_stack = new possible_stack(C, spawn_quantity) - if(admin_spawned) - ordered_stack.flags_1 |= ADMIN_SPAWNED_1 - sheets_to_spawn -= spawn_quantity + //adjust the order based ont the available quantity + contains[possible_stack] = available_quantity //Prices go up as material quantity becomes scarce var/fraction = available_quantity @@ -176,3 +178,14 @@ //We decrease the quantity only after adjusting our prices for accurate values SSstock_market.adjust_material_quantity(material_type, -available_quantity) + +/datum/supply_pack/custom/minerals/fill(obj/structure/closet/crate/C) + for(var/obj/item/stack/sheet/possible_stack as anything in contains) + //spawn the ordered stack inside the crate + var/sheets_to_spawn = contains[possible_stack] + while(sheets_to_spawn) + var/spawn_quantity = min(sheets_to_spawn, MAX_STACK_SIZE) + var/obj/item/stack/sheet/ordered_stack = new possible_stack(C, spawn_quantity) + if(admin_spawned) + ordered_stack.flags_1 |= ADMIN_SPAWNED_1 + sheets_to_spawn -= spawn_quantity diff --git a/code/modules/shuttle/mobile_port/variants/supply.dm b/code/modules/shuttle/mobile_port/variants/supply.dm index c6d37d81a64..2c4d14b6281 100644 --- a/code/modules/shuttle/mobile_port/variants/supply.dm +++ b/code/modules/shuttle/mobile_port/variants/supply.dm @@ -169,6 +169,21 @@ GLOBAL_LIST_INIT(blacklisted_cargo_types, typecacheof(list( for(var/datum/supply_order/spawning_order in SSshuttle.shopping_list) if(!empty_turfs.len) break + + //adjust galactic material market based on the ordered quantities + var/datum/supply_pack/custom/minerals/sheets = astype(spawning_order.pack) + if(!isnull(sheets)) + var/list/orders_adjusted = sheets.adjust_market() + if(orders_adjusted.len) + var/datum/bank_account/paying_for_this = spawning_order.paying_account || SSeconomy.get_dep_account(ACCOUNT_CAR) + if(!sheets.contains.len) //no sheets in the market at all + paying_for_this.bank_card_talk("Order #[spawning_order.id] ([spawning_order.pack.name]) was cancelled due to insufficient materials in the market!.") + SSshuttle.shopping_list -= spawning_order + clean_up_orders += spawning_order + continue + //some of the orders were adjusted(quantity changed or cancelled) according to the market + paying_for_this.bank_card_talk("Order #[spawning_order.id] ([spawning_order.pack.name]) had the following orders adjusted
[orders_adjusted.Join("
")]
.") + price = spawning_order.get_final_cost() // department orders EARN money for cargo, not the other way around