Files
Bubberstation/code/modules/cargo/exports/materials.dm
T
SyncIt21andGitHub d36a5af64f Removes material breakdown flags, traits & miscellaneous fixes. (#80389)
## About The Pull Request
1. Removes material breakdown flags i.e. all flags with the format
`BREAKDOWN_XXX`. These flags do nothing, there are no special checks to
transform materials based on these flags, they are passed around just
because certain procs require them for syntax purposes only.

Apparently there were plans to make these flags do something special
from the comment

https://github.com/tgstation/tgstation/blob/302247c0d1e980478f59d9c497169290ee259887/code/__DEFINES/construction/material.dm#L43
But nobody got any ideas for years now. The only special thing we can do
with them now is remove them and reduce code clutter, so let's do that
    
The only flag that ever did something was the
`BREAKDOWN_INCLUDE_ALCHEMY` flag. This only worked when coupled together
with `TRAIT_MAT_TRANSMUTED` trait(which is only used by the reagent
metalgen) and when both this trait & flag are combined together... they
still do nothing

https://github.com/tgstation/tgstation/blob/302247c0d1e980478f59d9c497169290ee259887/code/game/atom/atom_materials.dm#L41-L42
Yup they cancel out each other to prevent returning an empty list, the
traits only job was to prevent materials from being recycled (like why?
what's the benefit of that? nothing) and the flag was meant to bypass
this restriction so both the trait & the flag cancel out each other
therefore doing nothing meaningful. Best remove them both and call it a
day.

2. Fixes an error in displaying number of sheets inserted into a mat
container when that sheet is made up of alloy materials. it would count
as 2 or more because it would take the sum of total material amount
inserted and not the actual sheets. That's fixed now.

3. Remote materials now properly respect the `MATCONTAINER_NO_INSERT`
flag

4. Adds helper proc to insert materials via the remote material
component with proper context

## Changelog
🆑
fix: mat container displays correct number of sheets inserted for alloy
materials.
fix: remote materials now properly respect the `MATCONTAINER_NO_INSERT`
flag.
code: removes material breakdown flags and related traits.
code: adds helper proc to insert materials via the remote material
component with proper context.
/🆑
2023-12-25 02:29:26 +01:00

176 lines
5.9 KiB
Plaintext

/datum/export/material
cost = 5 // Cost per SHEET_MATERIAL_AMOUNT, which is 100cm3 as of May 2023.
message = "cm3 of developer's tears. Please, report this on github"
amount_report_multiplier = SHEET_MATERIAL_AMOUNT
var/datum/material/material_id = null
export_types = list(
/obj/item/stack/sheet/mineral,
/obj/item/stack/tile/mineral,
/obj/item/stack/ore,
/obj/item/coin
)
// Yes, it's a base type containing export_types.
// But it has no material_id, so any applies_to check will return false, and these types reduce amount of copypasta a lot
/datum/export/material/get_amount(obj/O)
if(!material_id)
return 0
if(!isitem(O))
return 0
var/obj/item/I = O
var/list/mat_comp = I.get_material_composition()
var/datum/material/mat_ref = ispath(material_id) ? locate(material_id) in mat_comp : GET_MATERIAL_REF(material_id)
if(isnull(mat_comp[mat_ref]))
return 0
var/amount = mat_comp[mat_ref]
if(istype(I, /obj/item/stack/ore))
amount *= 0.8 // Station's ore redemption equipment is really goddamn good.
return round(amount / SHEET_MATERIAL_AMOUNT)
// Materials. Static materials exist as parent types, while materials subject to the stock market have a fluid cost as determined by material/market types
// If you're adding a new material to the stock market, make sure its export type is added here.
/datum/export/material/plasma
cost = CARGO_CRATE_VALUE * 0.4
k_elasticity = 0
material_id = /datum/material/plasma
message = "cm3 of plasma"
/datum/export/material/bananium
cost = CARGO_CRATE_VALUE * 2
material_id = /datum/material/bananium
message = "cm3 of bananium"
/datum/export/material/diamond
cost = CARGO_CRATE_VALUE
material_id = /datum/material/adamantine
message = "cm3 of adamantine"
/datum/export/material/mythril
cost = CARGO_CRATE_VALUE * 3
material_id = /datum/material/mythril
message = "cm3 of mythril"
/datum/export/material/plastic
cost = CARGO_CRATE_VALUE * 0.05
message = "cm3 of plastic"
material_id = /datum/material/plastic
/datum/export/material/runite
cost = CARGO_CRATE_VALUE * 1.2
message = "cm3 of runite"
material_id = /datum/material/runite
/datum/export/material/hot_ice
cost = CARGO_CRATE_VALUE * 0.8
message = "cm3 of Hot Ice"
material_id = /datum/material/hot_ice
export_types = /obj/item/stack/sheet/hot_ice
/datum/export/material/metal_hydrogen
cost = CARGO_CRATE_VALUE * 1.05
message = "cm3 of metallic hydrogen"
material_id = /datum/material/metalhydrogen
export_types = /obj/item/stack/sheet/mineral/metal_hydrogen
/datum/export/material/market
/datum/export/material/market/diamond
material_id = /datum/material/diamond
message = "cm3 of diamonds"
/datum/export/material/market/uranium
material_id = /datum/material/uranium
message = "cm3 of uranium"
/datum/export/material/market/gold
material_id = /datum/material/gold
message = "cm3 of gold"
/datum/export/material/market/silver
material_id = /datum/material/silver
message = "cm3 of silver"
/datum/export/material/market/titanium
material_id = /datum/material/titanium
message = "cm3 of titanium"
/datum/export/material/market/bscrystal
message = "of bluespace crystals"
material_id = /datum/material/bluespace
export_types = list(/obj/item/stack/sheet/bluespace_crystal, /obj/item/stack/ore) //For whatever reason, bluespace crystals are not a mineral
/datum/export/material/market/iron
message = "cm3 of iron"
material_id = /datum/material/iron
export_types = list(
/obj/item/stack/sheet/iron,
/obj/item/stack/tile/iron,
/obj/item/stack/rods,
/obj/item/stack/ore,
/obj/item/coin
)
/datum/export/material/market/glass
message = "cm3 of glass"
material_id = /datum/material/glass
export_types = list(
/obj/item/stack/sheet/glass,
/obj/item/stack/ore,
/obj/item/shard
)
/datum/export/material/market/get_cost(obj/O, apply_elastic = FALSE)
var/obj/item/I = O
var/amount = get_amount(I)
if(!amount)
return 0
var/material_value = (SSstock_market.materials_prices[material_id]) * amount * MARKET_PROFIT_MODIFIER
return round(material_value)
/datum/export/material/market/sell_object(obj/sold_item, datum/export_report/report, dry_run, apply_elastic)
. = ..()
var/amount = get_amount(sold_item)
if(!amount)
return
//This formula should impact lower quantity materials greater, and higher quantity materials less. Still, it's a bit rough. Tweaking may be needed.
if(!dry_run)
//this material is worthless. no point adding more to the stock
var/market_price = SSstock_market.materials_prices[material_id]
if(!market_price)
return
//decrease the market price
market_price -= round((market_price) * (amount / (amount + SSstock_market.materials_quantity[material_id])))
if(market_price < 0)
market_price = 0
SSstock_market.materials_prices[material_id] = market_price
//increase the stock
SSstock_market.materials_quantity[material_id] += amount
// Stock blocks are a special type of export that can be used to sell a quantity of materials at a specific price on the market.
/datum/export/stock_block
cost = 0
message = "stock block"
export_types = list(/obj/item/stock_block)
/datum/export/stock_block/get_cost(obj/O, apply_elastic = FALSE)
var/obj/item/stock_block/block = O
return block.export_value
/datum/export/stock_block/sell_object(obj/sold_item, datum/export_report/report, dry_run, apply_elastic)
. = ..()
if(dry_run)
return
var/obj/item/stock_block/sold_block = sold_item
var/sale_value = sold_block.export_value
SSstock_market.materials_quantity[sold_block.export_mat] += sold_block.quantity
SSstock_market.materials_prices[sold_block.export_mat] -= round((sale_value) * (sold_block.quantity / (sold_block.quantity + SSstock_market.materials_quantity[sold_block.export_mat])))
SSstock_market.materials_prices[sold_block.export_mat] = round(clamp(SSstock_market.materials_prices[sold_block.export_mat], initial(sold_block.export_mat.value_per_unit) * SHEET_MATERIAL_AMOUNT * 0.5 , initial(sold_block.export_mat.value_per_unit) * SHEET_MATERIAL_AMOUNT * 3))