Files
Bubberstation/code/datums/materials/_material.dm
Ghom 1f3894e793 Crafting refactor, implementing materials (#89465)
My original plan was to just implement materials into crafting so that
items would inherit the materials of their components, allowing for some
interesting stuff if the material flags of the item allow it. However to
my dismay crafting is a pile of old tech debt, starting from the old
`del_reqs` and `CheckParts` which still contain lines about old janky
bandaids that are no longer in use nor reachable, up to the
`customizable_reagent_holder` component which has some harddel issues
when your custom food is sliced, and items used in food recipes not
being deleted and instead stored inside the result with no purpose as
well as other inconsistencies like stack recipes that transfer materials
having counterparts in the UI that don't do that.

EDIT: Several things have come up while working on this, so I apologise
that it ended up changing over 100+ files. I managed to atomize some of
the changes, but it's a bit tedious.

EDIT: TLDR because I was told this section is too vague and there's too
much going on. This PR:
- Improves the dated crafting code (not the UI).
- replaced `atom/CheckParts` and `crafting_recipe/on_craft_completion`
with `atom/on_craft_completion`.
- Reqs used in food recipes are now deleted by default and not stored
inside the result (they did nothing).
- Renames the customizable_reagent_holder comp and improves it (No
harddels/ref issues).
- Adds a unit test that tries to craft all recipes to see what's wrong
(it skips some of the much more specific reqs for now).
- In the unit test is also the code to make sure materials of the
crafted item and a non-crafted item of the same type are roughly the
same, so far only applied to food.
- Some mild material/food refactoring around the fact that food item
code has been changed to support materials.

Improving the backbone of the crafting system. Also materials and food
code.

🆑
refactor: Refactored crafting backend. Report possible pesky bugs.
balance: the MEAT backpack (from the MEAT cargo pack) may be a smidge
different because of code standardization.
/🆑
2025-06-05 20:05:13 -04:00

190 lines
8.2 KiB
Plaintext

/*! Material datum
Simple datum which is instanced once per type and is used for every object of said material. It has a variety of variables that define behavior. Subtyping from this makes it easier to create your own materials.
*/
/datum/material
/// What the material is referred to as IC.
var/name = "material"
/// A short description of the material. Not used anywhere, yet...
var/desc = "its..stuff."
/// What the material is indexed by in the SSmaterials.materials list. Defaults to the type of the material.
var/id
/**
* Base color of the material, for items that don't have greyscale configs nor are made of multiple materials. Item isn't changed in color if this is null.
* This can be a RGB or color matrix, but it cannot be RGBA as alpha is automatically filled in.
*/
var/color
/**
* If the color is a color matrix and either the item uses greyscale configs or is made of multiple colored materials. This will be used instead because
* neither greyscale configs nor BlendRGB() support color matrices.
* Also this has to be RRGGBB, six characters, no alpha channel as it's automatically filled in.
*
* Basically, set this if the color is a color matrix (list)
*/
var/greyscale_color
/// Base alpha of the material
var/alpha = 255
///Starlight color of the material
///This is the color of light it'll emit if its turf is transparent and over space. Defaults to COLOR_STARLIGHT if not set
var/starlight_color
///Bitflags that influence how SSmaterials handles this material.
var/init_flags = MATERIAL_INIT_MAPLOAD
///Materials "Traits". its a map of key = category | Value = Bool. Used to define what it can be used for
var/list/categories = list()
///The type of sheet this material creates. This should be replaced as soon as possible by greyscale sheets
var/sheet_type
/// What type of ore is this material associated with? Used for mining, and not every material has one.
var/obj/item/ore_type
///This is a modifier for force, and resembles the strength of the material
var/strength_modifier = 1
///This is a modifier for integrity, and resembles the strength of the material
var/integrity_modifier = 1
///This is the amount of value per 1 unit of the material
var/value_per_unit = 0
///This is the minimum value of the material, used in the stock market for any mat that isn't set to null
var/minimum_value_override = null
///Is this material traded on the stock market?
var/tradable = FALSE
///If this material is tradable, what is the base quantity of the material on the stock market?
var/tradable_base_quantity = 0
///Armor modifiers, multiplies an items normal armor vars by these amounts.
var/armor_modifiers = list(MELEE = 1, BULLET = 1, LASER = 1, ENERGY = 1, BOMB = 1, BIO = 1, FIRE = 1, ACID = 1)
///How beautiful is this material per unit.
var/beauty_modifier = 0
///Can be used to override the sound items make, lets add some SLOSHing.
var/item_sound_override
///Can be used to override the stepsound a turf makes. MORE SLOOOSH
var/turf_sound_override
///what texture icon state to overlay
var/texture_layer_icon_state
///a cached icon for the texture filter
var/cached_texture_filter_icon
///What type of shard the material will shatter to
var/obj/item/shard_type
///How resistant the material is to rusting when applied to a turf
var/mat_rust_resistance = RUST_RESISTANCE_ORGANIC
///What type of debris the tile will leave behind when shattered.
var/obj/effect/decal/debris_type
/// How likely this mineral is to be found in a boulder during mining.
var/mineral_rarity = MATERIAL_RARITY_COMMON
/// How many points per units of ore does this grant?
var/points_per_unit = 1
/// The slowdown that is added to items.
var/added_slowdown = 0
/// Fish made of or infused with this material have their weight multiplied by this value.
var/fish_weight_modifier = 1
/// Additive bonus/malus to the fishing difficulty modifier of any rod made of this item. Negative is good, positive bad
var/fishing_difficulty_modifier = 0
/// Additive bonus/malus to the cast range of the fishing rod
var/fishing_cast_range = 0
/// The multiplier of how much experience is gained when using a fishing rod made of this material
var/fishing_experience_multiplier = 1
/// The multiplier to the completion gain of the fishing rod made of this material
var/fishing_completion_speed = 1
/// The multiplier of the bait/bobber speed of the fishing challenge for fishing rods made of this material
var/fishing_bait_speed_mult = 1
/// The multiplier of the deceleration/friction for fishing rods made of this material
var/fishing_deceleration_mult = 1
/// The multiplier of the bounciness of the bait/bobber upon hitting the edges of the minigame area
var/fishing_bounciness_mult = 1
/// The multiplier of negative velocity that pulls the bait/bobber of a fishing rod down when not holding the click
var/fishing_gravity_mult = 1
/** Handles initializing the material.
*
* Arguments:
* - _id: The ID the material should use. Overrides the existing ID.
*/
/datum/material/proc/Initialize(_id, ...)
if(_id)
id = _id
else if(isnull(id))
id = type
if(texture_layer_icon_state)
cached_texture_filter_icon = icon('icons/turf/composite.dmi', texture_layer_icon_state)
return TRUE
///This proc is called when the material is added to an object.
/datum/material/proc/on_applied(atom/source, mat_amount, multiplier)
return
///This proc is called when the material becomes the one the object is composed of the most
/datum/material/proc/on_main_applied(atom/source, mat_amount, multiplier)
SHOULD_CALL_PARENT(TRUE)
if(beauty_modifier >= 0.15 && HAS_TRAIT(source, TRAIT_FISHING_BAIT))
source.AddElement(/datum/element/shiny_bait)
/datum/material/proc/setup_glow(turf/on)
if(GET_TURF_PLANE_OFFSET(on) != GET_LOWEST_STACK_OFFSET(on.z)) // We ain't the bottom brother
return
// We assume no parallax means no space means no light
if(SSmapping.level_trait(on.z, ZTRAIT_NOPARALLAX))
return
if(!starlight_color)
on.RegisterSignal(SSdcs, COMSIG_STARLIGHT_COLOR_CHANGED, TYPE_PROC_REF(/turf, material_starlight_changed))
RegisterSignal(on, COMSIG_QDELETING, PROC_REF(lit_turf_deleted))
on.set_light(2, 1, starlight_color || GLOB.starlight_color, l_height = LIGHTING_HEIGHT_SPACE)
/turf/proc/material_starlight_changed(datum/source, old_star, new_star)
if(light_color == old_star)
set_light_color(new_star)
/datum/material/proc/lit_turf_deleted(turf/source)
source.set_light(0, 0, null)
///This proc is called when the material is removed from an object.
/datum/material/proc/on_removed(atom/source, amount, material_flags)
return
///This proc is called when the material is no longer the one the object is composed by the most
/datum/material/proc/on_main_removed(atom/source, mat_amount, multiplier)
SHOULD_CALL_PARENT(TRUE)
if(beauty_modifier >= 0.15 && HAS_TRAIT(source, TRAIT_FISHING_BAIT))
source.RemoveElement(/datum/element/shiny_bait)
////Called in `/datum/component/edible/proc/on_material_effects`
/datum/material/proc/on_edible_applied(atom/source, datum/component/edible/edible)
return
////Called in `/datum/component/edible/proc/on_remove_material_effects`
/datum/material/proc/on_edible_removed(atom/source, datum/component/edible/edible)
return
/**
* This proc is called when the mat is found in an item that's consumed by accident. see /obj/item/proc/on_accidental_consumption.
* Arguments
* * M - person consuming the mat
* * S - (optional) item the mat is contained in (NOT the item with the mat itself)
*/
/datum/material/proc/on_accidental_mat_consumption(mob/living/carbon/M, obj/item/S)
return FALSE
/** Returns the composition of this material.
*
* Mostly used for alloys when breaking down materials.
*
* Arguments:
* - amount: The amount of the material to break down.
*/
/datum/material/proc/return_composition(amount = 1, flags)
// Yes we need the parenthesis, without them BYOND stringifies src into "src" and things break.
return list((src) = amount)
///Returns the list of armor modifiers, with each element having its assoc value multiplied by the multiplier arg
/datum/material/proc/get_armor_modifiers(multiplier)
SHOULD_NOT_OVERRIDE(TRUE)
var/list/return_list = list()
for(var/armor in armor_modifiers)
return_list[armor] = return_list[armor] * multiplier
return return_list