mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-25 06:00:16 +01:00
[READY] Bespoke Datum Mats (#55296)
* Bespoke Material Backend - Adds support for bespoke materials: - Reimplements [/datum/material/var/id] - Ports GetIdFromArguments from SSdcs - Adds a wrapper define for GetMaterialRef - Adds [MATERIAL_INIT_BESPOKE] - Adds [/datum/material/proc/Initialize] - Does not actually add any bespoke materials - [ ] TODO: Code docs - [ ] TODO: Actually adding bespoke materials * Some has_material procs and cleaning up some spaghetti - Adds a pair of has_material procs for use in checking whether a given atom has a given material * Adds meat - Adds bespoke meat variants - Does not make them accessible - Shuts up the linter * Implements bespoke meat - Makes the material container preserve bespoke materials - Makes the sheetifier accept bespoke materials - Makes the autolathe accept bespoke materials - Makes the gibber produce bespoke meats * Makes butchering produce bespoke meats This is jank and really needs to be folded into a unified butchering and gibbing system * Material documentation - Adds, fixes, and touches up some documentation * Material container insertion callback - Changes the proc used to expand the material container's material list ot a proc used to check whether a material fits into a material container - Instantiating new materials is no longer O(n) relative to the number of autolathes in existence. * Makes processing meat conserve materials - Makes bespoke meat carry over into meatballs * Makes preserving custom materials an option - Implements the ability to turn preserving custom materials _off_ for processor recipes * Fixes all bespoke materials of the same type using the same singleton - We use ids now, not just types. * Makes the fat sucker produce bespoke meats - Because consistency is good. * Fixes autolathes merging bespoke stacks into normal stacks. * Makes the callback to test materials for holdibility optional - @Floyd * GetMaterialRef -> GET_MATERIAL_REF - We capitalize macros. * Removes an extraneous callback - Makes the sheetifier use functionality I didn't notice I implemented a few commits ago. * Makes mob and species meat null compatible * Fixes the ore silo - The ore silo had really snowflake material handling that has been brought in line with the rest. - The materials should show up in the correct order. * Fixes minor lathe bugs - Fixes stack_traces caused when lathes tried to fetch materials using reagent typepaths - Fixed the selective reagent disposal topic. I have no idea how long this has been broken. * Various documentation fixes - Clarified a couple comments - Removes an extraneous ?. operator - Fixed mat floor tiles having bugged reagent temperatures * More fixes -/datum/material/meat/mob -> /datum/material/meat/mob_meat - Adds atom typecheck to material containers. * Fixes old typepaths
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
/datum/component/butchering
|
||||
var/speed = 80 //time in deciseconds taken to butcher something
|
||||
var/effectiveness = 100 //percentage effectiveness; numbers above 100 yield extra drops
|
||||
var/bonus_modifier = 0 //percentage increase to bonus item chance
|
||||
var/butcher_sound = 'sound/effects/butcher.ogg' //sound played when butchering
|
||||
/// Time in deciseconds taken to butcher something
|
||||
var/speed = 8 SECONDS
|
||||
/// Percentage effectiveness; numbers above 100 yield extra drops
|
||||
var/effectiveness = 100
|
||||
/// Percentage increase to bonus item chance
|
||||
var/bonus_modifier = 0
|
||||
/// Sound played when butchering
|
||||
var/butcher_sound = 'sound/effects/butcher.ogg'
|
||||
/// Whether or not this component can be used to butcher currently. Used to temporarily disable butchering
|
||||
var/butchering_enabled = TRUE
|
||||
/// Whether or not this component is compatible with blunt tools.
|
||||
var/can_be_blunt = FALSE
|
||||
|
||||
/datum/component/butchering/Initialize(_speed, _effectiveness, _bonus_modifier, _butcher_sound, disabled, _can_be_blunt)
|
||||
@@ -77,7 +83,15 @@
|
||||
screaming_through_a_slit_throat.apply_wound(slit_throat)
|
||||
H.apply_status_effect(/datum/status_effect/neck_slice)
|
||||
|
||||
/**
|
||||
* Handles a user butchering a target
|
||||
*
|
||||
* Arguments:
|
||||
* - [butcher][/mob/living]: The mob doing the butchering
|
||||
* - [meat][/mob/living]: The mob being butchered
|
||||
*/
|
||||
/datum/component/butchering/proc/Butcher(mob/living/butcher, mob/living/meat)
|
||||
var/list/results = list()
|
||||
var/turf/T = meat.drop_location()
|
||||
var/final_effectiveness = effectiveness - meat.butcher_difficulty
|
||||
var/bonus_chance = max(0, (final_effectiveness - 100) + bonus_modifier) //so 125 total effectiveness = 25% extra chance
|
||||
@@ -88,20 +102,29 @@
|
||||
if(!prob(final_effectiveness))
|
||||
if(butcher)
|
||||
to_chat(butcher, "<span class='warning'>You fail to harvest some of the [initial(bones.name)] from [meat].</span>")
|
||||
else if(prob(bonus_chance))
|
||||
continue
|
||||
|
||||
if(prob(bonus_chance))
|
||||
if(butcher)
|
||||
to_chat(butcher, "<span class='info'>You harvest some extra [initial(bones.name)] from [meat]!</span>")
|
||||
for(var/i in 1 to 2)
|
||||
new bones (T)
|
||||
else
|
||||
new bones (T)
|
||||
results += new bones (T)
|
||||
results += new bones (T)
|
||||
|
||||
meat.butcher_results.Remove(bones) //in case you want to, say, have it drop its results on gib
|
||||
|
||||
for(var/V in meat.guaranteed_butcher_results)
|
||||
var/obj/sinew = V
|
||||
var/amount = meat.guaranteed_butcher_results[sinew]
|
||||
for(var/i in 1 to amount)
|
||||
new sinew (T)
|
||||
results += new sinew (T)
|
||||
meat.guaranteed_butcher_results.Remove(sinew)
|
||||
|
||||
for(var/obj/item/carrion in results)
|
||||
var/list/meat_mats = carrion.has_material_type(/datum/material/meat)
|
||||
if(!length(meat_mats))
|
||||
continue
|
||||
carrion.set_custom_materials((carrion.custom_materials - meat_mats) + list(GET_MATERIAL_REF(/datum/material/meat/mob_meat, meat) = counterlist_sum(meat_mats)))
|
||||
|
||||
if(butcher)
|
||||
butcher.visible_message("<span class='notice'>[butcher] butchers [meat].</span>", \
|
||||
"<span class='notice'>You butcher [meat].</span>")
|
||||
|
||||
@@ -10,42 +10,78 @@
|
||||
*/
|
||||
|
||||
/datum/component/material_container
|
||||
/// The total amount of materials this material container contains
|
||||
var/total_amount = 0
|
||||
/// The maximum amount of materials this material container can contain
|
||||
var/max_amount
|
||||
var/sheet_type
|
||||
/// Map of material ref -> amount
|
||||
var/list/materials //Map of key = material ref | Value = amount
|
||||
var/disable_attackby
|
||||
var/list/allowed_typecache
|
||||
/// The list of materials that this material container can accept
|
||||
var/list/allowed_materials
|
||||
/// The typecache of things that this material container can accept
|
||||
var/list/allowed_item_typecache
|
||||
/// The last main material that was inserted into this container
|
||||
var/last_inserted_id
|
||||
/// Whether or not this material container allows specific amounts from sheets to be inserted
|
||||
var/precise_insertion = FALSE
|
||||
/// A callback for checking wheter we can insert a material into this container
|
||||
var/datum/callback/insertion_check
|
||||
/// A callback invoked before materials are inserted into this container
|
||||
var/datum/callback/precondition
|
||||
/// A callback invoked after materials are inserted into this container
|
||||
var/datum/callback/after_insert
|
||||
///The material container flags. See __DEFINES/materials.dm.
|
||||
/// The material container flags. See __DEFINES/materials.dm.
|
||||
var/mat_container_flags
|
||||
|
||||
/// Sets up the proper signals and fills the list of materials with the appropriate references.
|
||||
/datum/component/material_container/Initialize(list/mat_list, max_amt = 0, _mat_container_flags=NONE, list/allowed_types, datum/callback/_precondition, datum/callback/_after_insert)
|
||||
/datum/component/material_container/Initialize(list/init_mats, max_amt = 0, _mat_container_flags=NONE, list/allowed_mats=init_mats, list/allowed_items, datum/callback/_insertion_check, datum/callback/_precondition, datum/callback/_after_insert)
|
||||
if(!isatom(parent))
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
|
||||
materials = list()
|
||||
max_amount = max(0, max_amt)
|
||||
mat_container_flags = _mat_container_flags
|
||||
|
||||
if(allowed_types)
|
||||
if(ispath(allowed_types) && allowed_types == /obj/item/stack)
|
||||
allowed_typecache = GLOB.typecache_stack
|
||||
allowed_materials = allowed_mats || list()
|
||||
if(allowed_items)
|
||||
if(ispath(allowed_items) && allowed_items == /obj/item/stack)
|
||||
allowed_item_typecache = GLOB.typecache_stack
|
||||
else
|
||||
allowed_typecache = typecacheof(allowed_types)
|
||||
allowed_item_typecache = typecacheof(allowed_items)
|
||||
|
||||
insertion_check = _insertion_check
|
||||
precondition = _precondition
|
||||
after_insert = _after_insert
|
||||
|
||||
for(var/mat in init_mats) //Make the assoc list material reference -> amount
|
||||
var/mat_ref = GET_MATERIAL_REF(mat)
|
||||
if(isnull(mat_ref))
|
||||
continue
|
||||
var/mat_amt = init_mats[mat]
|
||||
if(isnull(mat_amt))
|
||||
mat_amt = 0
|
||||
materials[mat_ref] += mat_amt
|
||||
|
||||
/datum/component/material_container/Destroy(force, silent)
|
||||
materials = null
|
||||
allowed_materials = null
|
||||
if(insertion_check)
|
||||
QDEL_NULL(insertion_check)
|
||||
if(precondition)
|
||||
QDEL_NULL(precondition)
|
||||
if(after_insert)
|
||||
QDEL_NULL(after_insert)
|
||||
return ..()
|
||||
|
||||
|
||||
/datum/component/material_container/RegisterWithParent()
|
||||
. = ..()
|
||||
|
||||
if(!(mat_container_flags & MATCONTAINER_NO_INSERT))
|
||||
RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, .proc/on_attackby)
|
||||
if(mat_container_flags & MATCONTAINER_EXAMINE)
|
||||
RegisterSignal(parent, COMSIG_PARENT_EXAMINE, .proc/on_examine)
|
||||
|
||||
for(var/mat in mat_list) //Make the assoc list ref | amount
|
||||
var/datum/material/M = SSmaterials.GetMaterialRef(mat)
|
||||
materials[M] = 0
|
||||
|
||||
/datum/component/material_container/vv_edit_var(var_name, var_value)
|
||||
var/old_flags = mat_container_flags
|
||||
@@ -75,7 +111,7 @@
|
||||
/datum/component/material_container/proc/on_attackby(datum/source, obj/item/I, mob/living/user)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
var/list/tc = allowed_typecache
|
||||
var/list/tc = allowed_item_typecache
|
||||
if(!(mat_container_flags & MATCONTAINER_ANY_INTENT) && user.a_intent != INTENT_HELP)
|
||||
return
|
||||
if(I.item_flags & ABSTRACT)
|
||||
@@ -136,54 +172,91 @@
|
||||
last_inserted_id = insert_item_materials(I, multiplier, breakdown_flags)
|
||||
return material_amount
|
||||
|
||||
/datum/component/material_container/proc/insert_item_materials(obj/item/I, multiplier = 1, breakdown_flags = mat_container_flags)
|
||||
/**
|
||||
* Inserts the relevant materials from an item into this material container.
|
||||
*
|
||||
* Arguments:
|
||||
* - [source][/obj/item]: The source of the materials we are inserting.
|
||||
* - multiplier: The multiplier for the materials being inserted.
|
||||
* - breakdown_flags: The breakdown bitflags that will be used to retrieve the materials from the source
|
||||
*/
|
||||
/datum/component/material_container/proc/insert_item_materials(obj/item/source, multiplier = 1, breakdown_flags = mat_container_flags)
|
||||
var/primary_mat
|
||||
var/max_mat_value = 0
|
||||
var/list/item_materials = I.get_material_composition(breakdown_flags)
|
||||
for(var/MAT in materials)
|
||||
var/list/item_materials = source.get_material_composition(breakdown_flags)
|
||||
for(var/MAT in item_materials)
|
||||
if(!can_hold_material(MAT))
|
||||
continue
|
||||
materials[MAT] += item_materials[MAT] * multiplier
|
||||
total_amount += item_materials[MAT] * multiplier
|
||||
if(item_materials[MAT] > max_mat_value)
|
||||
max_mat_value = item_materials[MAT]
|
||||
primary_mat = MAT
|
||||
|
||||
return primary_mat
|
||||
|
||||
/**
|
||||
* The default check for whether we can add materials to this material container.
|
||||
*
|
||||
* Arguments:
|
||||
* - [mat][/atom/material]: The material we are checking for insertability.
|
||||
*/
|
||||
/datum/component/material_container/proc/can_hold_material(datum/material/mat)
|
||||
if(mat in allowed_materials)
|
||||
return TRUE
|
||||
if(istype(mat) && ((mat.id in allowed_materials) || (mat.type in allowed_materials)))
|
||||
allowed_materials += mat // This could get messy with passing lists by ref... but if you're doing that the list expansion is probably being taken care of elsewhere anyway...
|
||||
return TRUE
|
||||
if(insertion_check?.Invoke(mat))
|
||||
allowed_materials += mat
|
||||
return TRUE
|
||||
return FALSE
|
||||
|
||||
/// For inserting an amount of material
|
||||
/datum/component/material_container/proc/insert_amount_mat(amt, datum/material/mat)
|
||||
if(!istype(mat))
|
||||
mat = SSmaterials.GetMaterialRef(mat)
|
||||
if(amt > 0 && has_space(amt))
|
||||
var/total_amount_saved = total_amount
|
||||
if(mat)
|
||||
materials[mat] += amt
|
||||
else
|
||||
for(var/i in materials)
|
||||
materials[i] += amt
|
||||
total_amount += amt
|
||||
return (total_amount - total_amount_saved)
|
||||
return FALSE
|
||||
if(amt <= 0 || !has_space(amt))
|
||||
return 0
|
||||
|
||||
var/total_amount_saved = total_amount
|
||||
if(mat)
|
||||
if(!istype(mat))
|
||||
mat = GET_MATERIAL_REF(mat)
|
||||
materials[mat] += amt
|
||||
else
|
||||
var/num_materials = length(materials)
|
||||
if(!num_materials)
|
||||
return 0
|
||||
|
||||
amt /= num_materials
|
||||
for(var/i in materials)
|
||||
materials[i] += amt
|
||||
total_amount += amt
|
||||
return (total_amount - total_amount_saved)
|
||||
|
||||
/// Uses an amount of a specific material, effectively removing it.
|
||||
/datum/component/material_container/proc/use_amount_mat(amt, datum/material/mat)
|
||||
if(!istype(mat))
|
||||
mat = SSmaterials.GetMaterialRef(mat)
|
||||
mat = GET_MATERIAL_REF(mat)
|
||||
|
||||
if(!mat)
|
||||
return 0
|
||||
var/amount = materials[mat]
|
||||
if(mat)
|
||||
if(amount >= amt)
|
||||
materials[mat] -= amt
|
||||
total_amount -= amt
|
||||
return amt
|
||||
return FALSE
|
||||
if(amount < amt)
|
||||
return 0
|
||||
|
||||
materials[mat] -= amt
|
||||
total_amount -= amt
|
||||
return amt
|
||||
|
||||
/// Proc for transfering materials to another container.
|
||||
/datum/component/material_container/proc/transer_amt_to(datum/component/material_container/T, amt, datum/material/mat)
|
||||
if(!istype(mat))
|
||||
mat = SSmaterials.GetMaterialRef(mat)
|
||||
mat = GET_MATERIAL_REF(mat)
|
||||
if((amt==0)||(!T)||(!mat))
|
||||
return FALSE
|
||||
if(amt<0)
|
||||
return T.transer_amt_to(src, -amt, mat)
|
||||
var/tr = min(amt, materials[mat],T.can_insert_amount_mat(amt, mat))
|
||||
var/tr = min(amt, materials[mat], T.can_insert_amount_mat(amt, mat))
|
||||
if(tr)
|
||||
use_amount_mat(tr, mat)
|
||||
T.insert_amount_mat(tr, mat)
|
||||
@@ -191,14 +264,14 @@
|
||||
return FALSE
|
||||
|
||||
/// Proc for checking if there is room in the component, returning the amount or else the amount lacking.
|
||||
/datum/component/material_container/proc/can_insert_amount_mat(amt, mat)
|
||||
if(amt && mat)
|
||||
var/datum/material/M = mat
|
||||
if(M)
|
||||
if((total_amount + amt) <= max_amount)
|
||||
return amt
|
||||
else
|
||||
return (max_amount-total_amount)
|
||||
/datum/component/material_container/proc/can_insert_amount_mat(amt, datum/material/mat)
|
||||
if(!amt || !mat)
|
||||
return 0
|
||||
|
||||
if((total_amount + amt) <= max_amount)
|
||||
return amt
|
||||
else
|
||||
return (max_amount - total_amount)
|
||||
|
||||
|
||||
/// For consuming a dictionary of materials. mats is the map of materials to use and the corresponding amounts, example: list(M/datum/material/glass =100, datum/material/iron=200)
|
||||
@@ -211,7 +284,7 @@
|
||||
for(var/x in mats) //Loop through all required materials
|
||||
var/datum/material/req_mat = x
|
||||
if(!istype(req_mat))
|
||||
req_mat = SSmaterials.GetMaterialRef(req_mat) //Get the ref if necesary
|
||||
req_mat = GET_MATERIAL_REF(req_mat) //Get the ref if necesary
|
||||
if(!materials[req_mat]) //Do we have the resource?
|
||||
return FALSE //Can't afford it
|
||||
var/amount_required = mats[x] * multiplier
|
||||
@@ -228,24 +301,25 @@
|
||||
return total_amount_save - total_amount
|
||||
|
||||
/// For spawning mineral sheets at a specific location. Used by machines to output sheets.
|
||||
/datum/component/material_container/proc/retrieve_sheets(sheet_amt, datum/material/M, target = null)
|
||||
/datum/component/material_container/proc/retrieve_sheets(sheet_amt, datum/material/M, atom/target = null)
|
||||
if(!M.sheet_type)
|
||||
return 0 //Add greyscale sheet handling here later
|
||||
if(sheet_amt <= 0)
|
||||
return 0
|
||||
|
||||
if(!target)
|
||||
target = get_turf(parent)
|
||||
var/atom/parent_atom = parent
|
||||
target = parent_atom.drop_location()
|
||||
if(materials[M] < (sheet_amt * MINERAL_MATERIAL_AMOUNT))
|
||||
sheet_amt = round(materials[M] / MINERAL_MATERIAL_AMOUNT)
|
||||
var/count = 0
|
||||
while(sheet_amt > MAX_STACK_SIZE)
|
||||
new M.sheet_type(target, MAX_STACK_SIZE)
|
||||
new M.sheet_type(target, MAX_STACK_SIZE, null, list((M) = MINERAL_MATERIAL_AMOUNT))
|
||||
count += MAX_STACK_SIZE
|
||||
use_amount_mat(sheet_amt * MINERAL_MATERIAL_AMOUNT, M)
|
||||
sheet_amt -= MAX_STACK_SIZE
|
||||
if(sheet_amt >= 1)
|
||||
new M.sheet_type(target, sheet_amt)
|
||||
new M.sheet_type(target, sheet_amt, null, list((M) = MINERAL_MATERIAL_AMOUNT))
|
||||
count += sheet_amt
|
||||
use_amount_mat(sheet_amt * MINERAL_MATERIAL_AMOUNT, M)
|
||||
return count
|
||||
@@ -272,7 +346,7 @@
|
||||
var/datum/material/req_mat = x
|
||||
if(!istype(req_mat))
|
||||
if(ispath(req_mat)) //Is this an actual material, or is it a category?
|
||||
req_mat = SSmaterials.GetMaterialRef(req_mat) //Get the ref
|
||||
req_mat = GET_MATERIAL_REF(req_mat) //Get the ref
|
||||
|
||||
else // Its a category. (For example MAT_CATEGORY_RIGID)
|
||||
if(!has_enough_of_category(req_mat, mats[x], multiplier)) //Do we have enough of this category?
|
||||
@@ -294,7 +368,6 @@
|
||||
categories += x
|
||||
return categories
|
||||
|
||||
|
||||
/// Returns TRUE if you have enough of the specified material.
|
||||
/datum/component/material_container/proc/has_enough_of_material(datum/material/req_mat, amount, multiplier=1)
|
||||
if(!materials[req_mat]) //Do we have the resource?
|
||||
@@ -331,12 +404,14 @@
|
||||
return 0
|
||||
var/material_amount = 0
|
||||
var/list/item_materials = I.get_material_composition(breakdown_flags)
|
||||
for(var/MAT in materials)
|
||||
for(var/MAT in item_materials)
|
||||
if(!can_hold_material(MAT))
|
||||
continue
|
||||
material_amount += item_materials[MAT]
|
||||
return material_amount
|
||||
|
||||
/// Returns the amount of a specific material in this container.
|
||||
/datum/component/material_container/proc/get_material_amount(datum/material/mat)
|
||||
if(!istype(mat))
|
||||
mat = SSmaterials.GetMaterialRef(mat)
|
||||
return(materials[mat])
|
||||
mat = GET_MATERIAL_REF(mat)
|
||||
return materials[mat]
|
||||
|
||||
@@ -72,7 +72,7 @@ handles linking back and forth.
|
||||
/datum/material/plastic,
|
||||
)
|
||||
|
||||
mat_container = parent.AddComponent(/datum/component/material_container, allowed_mats, local_size, mat_container_flags, /obj/item/stack)
|
||||
mat_container = parent.AddComponent(/datum/component/material_container, allowed_mats, local_size, mat_container_flags, allowed_items=/obj/item/stack)
|
||||
|
||||
/datum/component/remote_materials/proc/set_local_size(size)
|
||||
local_size = size
|
||||
|
||||
Reference in New Issue
Block a user