Fixes matter duplication glitch (#19101)

This commit is contained in:
Cameron Lennox
2026-02-07 00:33:19 +01:00
committed by GitHub
parent 486486e3be
commit fe69017af5
+37 -39
View File
@@ -1594,47 +1594,45 @@ GLOBAL_DATUM(dview_mob, /mob/dview)
* * [target_object][atom] - the target object who's custom materials we are trying to modify
*/
/proc/split_materials_uniformly(list/custom_materials, multiplier, obj/item/target_object)
target_object.set_custom_materials(custom_materials)
if(!length(target_object.contents)) //most common case where the object is just 1 thing
target_object.set_custom_materials(custom_materials, multiplier)
return
// if(!length(target_object.contents)) //most common case where the object is just 1 thing
// target_object.set_custom_materials(custom_materials, multiplier)
// return
//Step 1: Get recursive contents of all objects, only filter obj cause that what's material container accepts
var/list/reccursive_contents = target_object.get_all_contents_type(/obj/item)
// //Step 1: Get recursive contents of all objects, only filter obj cause that what's material container accepts
// var/list/reccursive_contents = target_object.get_all_contents_type(/obj/item)
//Step 2: find the sum of each material type per object and record their amounts into an 2D list
var/list/material_map_sum = list()
var/list/material_map_amounts = list()
for(var/obj/item/object as anything in reccursive_contents)
var/list/item_materials = object.matter
for(var/mat as anything in custom_materials)
var/mat_amount = 1 //no materials mean we assign this default amount
if(length(item_materials))
mat_amount = item_materials[mat] || 1 //if this object doesn't have our material type then assign a default value of 1
// //Step 2: find the sum of each material type per object and record their amounts into an 2D list
// var/list/material_map_sum = list()
// var/list/material_map_amounts = list()
// for(var/obj/object as anything in reccursive_contents)
// var/list/item_materials = object.matter
// for(var/mat as anything in custom_materials)
// var/mat_amount = 1 //no materials mean we assign this default amount
// if(length(item_materials))
// mat_amount = item_materials[mat] || 1 //if this object doesn't have our material type then assign a default value of 1
//record the sum of mats for normalizing
material_map_sum[mat] += mat_amount
//record the material amount for each item into an 2D list
var/list/mat_list_per_item = material_map_amounts[mat]
if(isnull(mat_list_per_item))
material_map_amounts[mat] = list(mat_amount)
else
mat_list_per_item += mat_amount
// //record the sum of mats for normalizing
// material_map_sum[mat] += mat_amount
// //record the material amount for each item into an 2D list
// var/list/mat_list_per_item = material_map_amounts[mat]
// if(isnull(mat_list_per_item))
// material_map_amounts[mat] = list(mat_amount)
// else
// mat_list_per_item += mat_amount
//Step 3: normalize & scale material_map_amounts with material_map_sum
for(var/mat as anything in material_map_amounts)
var/mat_sum = material_map_sum[mat]
var/list/mat_per_item = material_map_amounts[mat]
for(var/i in 1 to mat_per_item.len)
mat_per_item[i] = (mat_per_item[i] / mat_sum) * custom_materials[mat]
// //Step 3: normalize & scale material_map_amounts with material_map_sum
// for(var/mat as anything in material_map_amounts)
// var/mat_sum = material_map_sum[mat]
// var/list/mat_per_item = material_map_amounts[mat]
// for(var/i in 1 to mat_per_item.len)
// mat_per_item[i] = (mat_per_item[i] / mat_sum) * custom_materials[mat]
// //Step 4 flatten the 2D list and assign the final values to each atom
// var/index = 1
// for(var/obj/object as anything in reccursive_contents)
// var/list/final_material_list = list()
// for(var/mat as anything in material_map_amounts)
// var/list/mat_per_item = material_map_amounts[mat]
// final_material_list[mat] = mat_per_item[index]
// object.set_custom_materials(final_material_list, multiplier)
// index += 1
//Step 4 flatten the 2D list and assign the final values to each atom
var/index = 1
for(var/obj/item/object as anything in reccursive_contents)
var/list/final_material_list = list()
for(var/mat as anything in material_map_amounts)
var/list/mat_per_item = material_map_amounts[mat]
final_material_list[mat] = mat_per_item[index]
object.set_custom_materials(final_material_list, multiplier)
index += 1