Files
Bubberstation/code/datums/materials/_material.dm
Ghom 2531d69ff4 refactoring how materials effects are added to atoms (#86901)
## About The Pull Request
I'm "cooking" the materials system a bit, specifically the code
responsible for applying and removing effects. My goal is to move most
of the code to the objects-side, split it in smaller procs that can be
more easily overriden or called for object-specific modifiers and
effects, while also revamping things all around to better support items
made from multiple materials (the cleric mace will most likely be one in
this PR, with the handle and tip made of different materials).

PR NO LONGER WIP, TESTED AND ALL, CLERIC MACES CAN NOW BE MADE OF TWO
MATERIALS.

## Why It's Good For The Game
One of the nastiest flaws with the materials system is that it's just
unfeasable to have items made of multiple mats (with effects enabled)
right now, as they easily tend to override each other, where some of the
modifiers and effects should only be applied the main material.

Beside, the system's starting to show signs of its time, from the
several type checks used to apply different effects, the one letter
variables to the the material flags that are still being passed down as
arguments when you can access them from the atom/source arg anyway. It
would be disonhest of me if I went ahead and coded material fishing rods
or whatever fish fuckery with materials without ensuring it won't
further the technical debt the feature currently has.

## Changelog
🆑
refactor: Refactored materials code. report any issue.
add: Cleric maces (The autolathe-printable weapon design from outer
space) can now be made of two different materials.
balance: Buffed cleric maces a little.
fix: toolboxes' stats are now affected by materials again.
/🆑

---------

Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com>
2024-11-11 00:43:40 -08:00

158 lines
6.4 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
/** 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)
return
/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)
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)
// 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