From f537be6cd339d5a459ab96d94fc5b603fd242def Mon Sep 17 00:00:00 2001 From: Kashargul <144968721+Kashargul@users.noreply.github.com> Date: Wed, 11 Feb 2026 20:09:35 +0100 Subject: [PATCH] fix algae farm (#19164) --- .../binary_devices/algae_generator_vr.dm | 44 ++++++++++++++----- code/game/turfs/flooring/flooring.dm | 10 ++--- code/game/world.dm | 7 --- .../modules/materials/materials/_materials.dm | 7 +-- 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/code/ATMOSPHERICS/components/binary_devices/algae_generator_vr.dm b/code/ATMOSPHERICS/components/binary_devices/algae_generator_vr.dm index 952ebf8df9..c14e4db523 100644 --- a/code/ATMOSPHERICS/components/binary_devices/algae_generator_vr.dm +++ b/code/ATMOSPHERICS/components/binary_devices/algae_generator_vr.dm @@ -230,17 +230,41 @@ // TODO - These should be replaced with materials datum. // 0 amount = 0 means ejecting a full stack; -1 means eject everything -/obj/machinery/atmospherics/binary/algae_farm/proc/eject_materials(var/material_name, var/amount) - var/recursive = amount == -1 ? 1 : 0 - var/datum/material/matdata = get_material_by_name(material_name) - var/stack_type = matdata.stack_type - var/obj/item/stack/material/S = new stack_type(loc, -1) - var/ejected = min(round(stored_material[material_name] / S.perunit), amount) - if(!S.set_amount(min(ejected, amount))) +/obj/machinery/atmospherics/binary/algae_farm/proc/eject_materials(material_name, amount) + if(!stored_material[material_name]) return - stored_material[material_name] -= ejected * S.perunit - if(recursive && stored_material[material_name] >= S.perunit) - eject_materials(material_name, -1) + var/datum/material/matdata = get_material_by_name(material_name) + if(!matdata) + return + + var/obj/item/stack/material/new_stack = new matdata.stack_type(loc) + var/perunit = new_stack.perunit + + var/available_units = stored_material[material_name] / perunit + + var/units_to_eject + if(!amount) + units_to_eject = available_units + else + units_to_eject = min(amount, available_units) + + var/to_set = min(units_to_eject, new_stack.max_amount) + if(!new_stack.set_amount(to_set)) + return + + stored_material[material_name] -= to_set * perunit + units_to_eject -= to_set + + while(units_to_eject > 0) + new_stack = new matdata.stack_type(loc) + to_set = min(units_to_eject, new_stack.max_amount) + + if(!new_stack.set_amount(to_set)) + break + + stored_material[material_name] -= to_set * perunit + units_to_eject -= to_set + // Attept to load materials. Returns 0 if item wasn't a stack of materials, otherwise 1 (even if failed to load) /obj/machinery/atmospherics/binary/algae_farm/proc/try_load_materials(var/mob/user, var/obj/item/stack/material/S) diff --git a/code/game/turfs/flooring/flooring.dm b/code/game/turfs/flooring/flooring.dm index 218aa68bc6..3b91b136fa 100644 --- a/code/game/turfs/flooring/flooring.dm +++ b/code/game/turfs/flooring/flooring.dm @@ -1,14 +1,12 @@ -GLOBAL_LIST_EMPTY(flooring_types) +GLOBAL_LIST_INIT(flooring_types, populate_flooring_types()) /proc/populate_flooring_types() + var/list/floor_types = list() for (var/flooring_path in typesof(/decl/flooring)) - GLOB.flooring_types["[flooring_path]"] = new flooring_path + floor_types["[flooring_path]"] = new flooring_path + return floor_types /proc/get_flooring_data(var/flooring_path) - if(!GLOB.flooring_types) - GLOB.flooring_types = list() - if(!GLOB.flooring_types["[flooring_path]"]) - GLOB.flooring_types["[flooring_path]"] = new flooring_path return GLOB.flooring_types["[flooring_path]"] // State values: diff --git a/code/game/world.dm b/code/game/world.dm index 362d5b1d88..61dfc7bc09 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -175,16 +175,9 @@ GLOBAL_VAR(restart_counter) log_test("Unit Tests Enabled. This will destroy the world when testing is complete.") log_test("If you did not intend to enable this please check code/__defines/unit_testing.dm") #endif - - // This is kinda important. Set up details of what the hell things are made of. - populate_material_list() - // Create frame types. populate_frame_types() - // Create floor types. - populate_flooring_types() - // Create robolimbs for chargen. populate_robolimb_list() diff --git a/code/modules/materials/materials/_materials.dm b/code/modules/materials/materials/_materials.dm index 357408940b..7e9c7dc528 100644 --- a/code/modules/materials/materials/_materials.dm +++ b/code/modules/materials/materials/_materials.dm @@ -36,7 +36,7 @@ */ // Assoc list containing all material datums indexed by name. -GLOBAL_LIST_EMPTY(name_to_material) +GLOBAL_LIST_INIT(name_to_material, populate_material_list()) //Returns the material the object is made of, if applicable. //Will we ever need to return more than one value here? Or should we just return the "dominant" material. @@ -96,12 +96,13 @@ GLOBAL_LIST_EMPTY(name_to_material) // Builds the datum list above. /proc/populate_material_list() + var/list/materia_list = list() for(var/type in subtypesof(/datum/material)) var/datum/material/new_mineral = new type if(!new_mineral.name) continue - GLOB.name_to_material[lowertext(new_mineral.name)] = new_mineral - return 1 + materia_list[lowertext(new_mineral.name)] = new_mineral + return materia_list // Safety proc to make sure the material list exists before trying to grab from it. /proc/get_material_by_name(name)