From 0d2ab1789f35f18d6a93208b4f734424a164ebf5 Mon Sep 17 00:00:00 2001 From: Theos Date: Sun, 1 Nov 2020 13:28:33 -0500 Subject: [PATCH] stitches together some tg code to make swarmers able to eat stuff I think (#10287) * Update atoms.dm * add return composition bit * yeah this'll probably work * ok * Update swarmer_act.dm --- code/datums/materials/_material.dm | 13 ++++++++++++- code/game/atoms.dm | 21 ++++++++++++++++++++- code/modules/swarmers/swarmer_act.dm | 5 +++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/code/datums/materials/_material.dm b/code/datums/materials/_material.dm index 7ef566dadb28..9dde16b137a8 100644 --- a/code/datums/materials/_material.dm +++ b/code/datums/materials/_material.dm @@ -64,4 +64,15 @@ Simple datum which is instanced once per type and is used for every object of sa o.max_integrity = new_max_integrity o.force = initial(o.force) - o.throwforce = initial(o.throwforce) \ No newline at end of file + o.throwforce = initial(o.throwforce) + +/** Returns the composition of this material. + * + * Mostly used for alloys when breaking down materials. + * + * Arguments: + * - amount: The amount of the material to break down. + * - breakdown_flags: Some flags dictating how exactly this material is being broken down. + */ +/datum/material/proc/return_composition(amount=1, breakdown_flags=NONE) + return list((src) = amount) // Yes we need the parenthesis, without them BYOND stringifies src into "src" and things break. diff --git a/code/game/atoms.dm b/code/game/atoms.dm index 0fbad190ea0d..bae3c8665c40 100644 --- a/code/game/atoms.dm +++ b/code/game/atoms.dm @@ -1116,6 +1116,25 @@ /atom/proc/intercept_zImpact(atom/movable/AM, levels = 1) return FALSE +/**Returns the material composition of the atom. + * + * Used when recycling items, specifically to turn alloys back into their component mats. + * + * Exists because I'd need to add a way to un-alloy alloys or otherwise deal + * with people converting the entire stations material supply into alloys. + * + * Arguments: + * - flags: A set of flags determining how exactly the materials are broken down. + */ +/atom/proc/get_material_composition(breakdown_flags=NONE) + . = list() + var/list/cached_materials = custom_materials + for(var/mat in cached_materials) + var/datum/material/material = getmaterialref(mat) + var/list/material_comp = material.return_composition(cached_materials[material], breakdown_flags) + for(var/comp_mat in material_comp) + .[comp_mat] += material_comp[comp_mat] + /** * Causes effects when the atom gets hit by a rust effect from heretics * @@ -1156,4 +1175,4 @@ var/datum/material/custom_material = x custom_material.on_applied(src, materials[custom_material] * multiplier, material_flags) - custom_materials[custom_material] += materials[x] * multiplier \ No newline at end of file + custom_materials[custom_material] += materials[x] * multiplier diff --git a/code/modules/swarmers/swarmer_act.dm b/code/modules/swarmers/swarmer_act.dm index 3631ef84a062..7a6c8d65b351 100644 --- a/code/modules/swarmers/swarmer_act.dm +++ b/code/modules/swarmers/swarmer_act.dm @@ -28,7 +28,8 @@ return 0 /obj/item/integrate_amount() //returns the amount of resources gained when eating this item - if(materials[/datum/material/iron] || materials[/datum/material/glass]) + var/list/mats = get_material_composition(ALL) // Ensures that items made from plasteel, and plas/titanium/plastitaniumglass get integrated correctly. + if(length(mats) && (mats[getmaterialref(/datum/material/iron)] || mats[getmaterialref(/datum/material/glass)])) return 1 return ..() @@ -227,4 +228,4 @@ /obj/machinery/shieldwall/swarmer_act(mob/living/simple_animal/hostile/swarmer/actor) to_chat(actor, "This object does not contain solid matter. Aborting.") - return FALSE \ No newline at end of file + return FALSE