From 177dc7323652e52d909b4e33a9b717d3feea24f8 Mon Sep 17 00:00:00 2001 From: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Date: Sat, 12 Jul 2025 00:30:35 +0530 Subject: [PATCH] GMM correctly adjusts ordered materials with proper feedback (#92009) ## About The Pull Request - Fixes #82910 Cargo now adjusts the material market quantity & prices when the shuttle is called from the order console itself instead of adjusting it after the shuttle arrives 1 minute later. This has 2 implications - If the market crashes 1 minute after calling the shuttle i.e when it arrives, the ordered quantities are not affected because it retrieved those sheets from the market at the time of calling the shuttle from the order console - If some orders could not be satisfied because there were not enough materials at the time of calling the shuttle then instead of arriving with an empty crate a detailed summary is displayed explaining which orders could not be delivered & why, even cancelling the order if needed **a) Order adjusted** ![Screenshot (489)](https://github.com/user-attachments/assets/39aa8746-8848-4415-a23d-c0a7cbd433db) **b) Order adjusted & cancelled** ![Screenshot (491)](https://github.com/user-attachments/assets/7a800f55-47d9-4d22-b871-c67858c8329a) **c) Order fully cancelled** ![Screenshot (492)](https://github.com/user-attachments/assets/e3231156-aaa8-44f5-b50a-2a8bd34d9064) ## Changelog :cl: fix: ordering materials from the GMM won't result in empty crates & will display detailed feedback if there weren't enough sheets in the market /:cl: --- code/modules/cargo/order.dm | 4 -- code/modules/cargo/packs/_packs.dm | 39 ++++++++++++------- .../shuttle/mobile_port/variants/supply.dm | 15 +++++++ 3 files changed, 41 insertions(+), 17 deletions(-) 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