mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-08-28 06:28:01 +01:00
fix algae farm (#19164)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user