Autolathe: Implement Material Container Component

First implementation, allows insertion but printing doesn't work yet.
This commit is contained in:
ShadowLarkens
2021-06-12 18:17:46 -07:00
parent 2a70cfe91f
commit a3674a664d
3 changed files with 81 additions and 108 deletions
+1 -1
View File
@@ -420,7 +420,7 @@
mat = GET_MATERIAL_REF(mat)
return materials[mat]
/// List format is list(material_name = list(amount = ..., ref = ..., etc.))
/// List format is list(list(name = ..., amount = ..., ref = ..., etc.), list(...))
/datum/component/material_container/tgui_data(mob/user)
var/list/data = list()
+79 -106
View File
@@ -13,8 +13,8 @@
circuit = /obj/item/weapon/circuitboard/autolathe
var/static/datum/category_collection/autolathe/autolathe_recipes
var/list/stored_material = list(DEFAULT_WALL_MATERIAL = 0, MAT_GLASS = 0, MAT_PLASTEEL = 0, MAT_PLASTIC = 0)
var/list/storage_capacity = list(DEFAULT_WALL_MATERIAL = 0, MAT_GLASS = 0, MAT_PLASTEEL = 0, MAT_PLASTIC = 0)
// var/list/stored_material = list(DEFAULT_WALL_MATERIAL = 0, MAT_GLASS = 0, MAT_PLASTEEL = 0, MAT_PLASTIC = 0)
// var/list/storage_capacity = list(DEFAULT_WALL_MATERIAL = 0, MAT_GLASS = 0, MAT_PLASTEEL = 0, MAT_PLASTIC = 0)
var/hacked = 0
var/disabled = 0
@@ -32,17 +32,18 @@
var/filtertext
/obj/machinery/autolathe/Initialize()
AddComponent(/datum/component/material_container, subtypesof(/datum/material), 0, MATCONTAINER_EXAMINE, _after_insert = CALLBACK(src, .proc/AfterMaterialInsert))
. = ..()
if(!autolathe_recipes)
autolathe_recipes = new()
wires = new(src)
for(var/Name in name_to_material)
if(Name in stored_material)
continue
// for(var/Name in name_to_material)
// if(Name in stored_material)
// continue
stored_material[Name] = 0
storage_capacity[Name] = 0
// stored_material[Name] = 0
// storage_capacity[Name] = 0
default_apply_parts()
RefreshParts()
@@ -95,19 +96,9 @@
/obj/machinery/autolathe/tgui_data(mob/user, datum/tgui/ui, datum/tgui_state/state)
var/list/data = ..()
var/list/material_data = list()
for(var/mat_id in stored_material)
var/amount = stored_material[mat_id]
var/list/material_info = list(
"name" = mat_id,
"amount" = amount,
"sheets" = round(amount / SHEET_MATERIAL_AMOUNT),
"removable" = amount >= SHEET_MATERIAL_AMOUNT
)
material_data += list(material_info)
data["busy"] = busy
data["materials"] = material_data
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
data["materials"] = materials.tgui_data()
data["mat_efficiency"] = mat_efficiency
return data
@@ -146,70 +137,69 @@
wires.Interact(user)
return
if(O.loc != user && !(istype(O,/obj/item/stack)))
return 0
if(is_robot_module(O))
return 0
if(istype(O,/obj/item/ammo_magazine/clip) || istype(O,/obj/item/ammo_magazine/s357) || istype(O,/obj/item/ammo_magazine/s38) || istype (O,/obj/item/ammo_magazine/s44)/* VOREstation Edit*/) // Prevents ammo recycling exploit with speedloaders.
to_chat(user, "\The [O] is too hazardous to recycle with the autolathe!")
return
return ..()
//Resources are being loaded.
var/obj/item/eating = O
if(!eating.matter)
to_chat(user, "\The [eating] does not contain significant amounts of useful materials and cannot be accepted.")
return
// //Resources are being loaded.
// var/obj/item/eating = O
// if(!eating.matter)
// to_chat(user, "\The [eating] does not contain significant amounts of useful materials and cannot be accepted.")
// return
var/filltype = 0 // Used to determine message.
var/total_used = 0 // Amount of material used.
var/mass_per_sheet = 0 // Amount of material constituting one sheet.
// var/filltype = 0 // Used to determine message.
// var/total_used = 0 // Amount of material used.
// var/mass_per_sheet = 0 // Amount of material constituting one sheet.
for(var/material in eating.matter)
// for(var/material in eating.matter)
if(isnull(stored_material[material]) || isnull(storage_capacity[material]))
continue
// if(isnull(stored_material[material]) || isnull(storage_capacity[material]))
// continue
if(stored_material[material] >= storage_capacity[material])
continue
// if(stored_material[material] >= storage_capacity[material])
// continue
var/total_material = eating.matter[material]
// var/total_material = eating.matter[material]
//If it's a stack, we eat multiple sheets.
if(istype(eating,/obj/item/stack))
var/obj/item/stack/stack = eating
total_material *= stack.get_amount()
// //If it's a stack, we eat multiple sheets.
// if(istype(eating,/obj/item/stack))
// var/obj/item/stack/stack = eating
// total_material *= stack.get_amount()
if(stored_material[material] + total_material > storage_capacity[material])
total_material = storage_capacity[material] - stored_material[material]
filltype = 1
else
filltype = 2
// if(stored_material[material] + total_material > storage_capacity[material])
// total_material = storage_capacity[material] - stored_material[material]
// filltype = 1
// else
// filltype = 2
stored_material[material] += total_material
total_used += total_material
mass_per_sheet += eating.matter[material]
// stored_material[material] += total_material
// total_used += total_material
// mass_per_sheet += eating.matter[material]
if(!filltype)
to_chat(user, "<span class='notice'>\The [src] is full. Please remove material from the autolathe in order to insert more.</span>")
return
else if(filltype == 1)
to_chat(user, "You fill \the [src] to capacity with \the [eating].")
else
to_chat(user, "You fill \the [src] with \the [eating].")
// if(!filltype)
// to_chat(user, "<span class='notice'>\The [src] is full. Please remove material from the autolathe in order to insert more.</span>")
// return
// else if(filltype == 1)
// to_chat(user, "You fill \the [src] to capacity with \the [eating].")
// else
// to_chat(user, "You fill \the [src] with \the [eating].")
flick("autolathe_loading", src) // Plays metal insertion animation. Work out a good way to work out a fitting animation. ~Z
// flick("autolathe_loading", src) // Plays metal insertion animation. Work out a good way to work out a fitting animation. ~Z
if(istype(eating,/obj/item/stack))
var/obj/item/stack/stack = eating
stack.use(max(1, round(total_used/mass_per_sheet))) // Always use at least 1 to prevent infinite materials.
else
user.remove_from_mob(O)
qdel(O)
// if(istype(eating,/obj/item/stack))
// var/obj/item/stack/stack = eating
// stack.use(max(1, round(total_used/mass_per_sheet))) // Always use at least 1 to prevent infinite materials.
// else
// user.remove_from_mob(O)
// qdel(O)
updateUsrDialog()
return
// updateUsrDialog()
// return
/obj/machinery/autolathe/attack_hand(mob/user as mob)
user.set_machine(src)
@@ -233,36 +223,39 @@
if(making.hidden && !hacked)
return
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
var/list/materials_used = list()
var/multiplier = 1
if(making.is_stack)
var/max_sheets
for(var/material in making.resources)
var/coeff = (making.no_scale ? 1 : mat_efficiency) //stacks are unaffected by production coefficient
var/sheets = round(stored_material[material]/round(making.resources[material]*coeff))
var/sheets = round(materials.get_material_amount(material) / round(making.resources[material] * coeff))
if(isnull(max_sheets) || max_sheets > sheets)
max_sheets = sheets
if(!isnull(stored_material[material]) && stored_material[material] < round(making.resources[material]*coeff))
if(!isnull(materials.get_material_amount(material)) && materials.get_material_amount(material) < round(making.resources[material] * coeff))
max_sheets = 0
//Build list of multipliers for sheets.
multiplier = input(usr, "How many do you want to print? (0-[max_sheets])") as num|null
if(!multiplier || multiplier <= 0 || multiplier > max_sheets || tgui_status(usr, state) != STATUS_INTERACTIVE)
return FALSE
busy = making.name
update_use_power(USE_POWER_ACTIVE)
//Check if we still have the materials.
var/coeff = (making.no_scale ? 1 : mat_efficiency) //stacks are unaffected by production coefficient
for(var/material in making.resources)
if(!isnull(stored_material[material]))
if(stored_material[material] < round(making.resources[material] * coeff) * multiplier)
return
for(var/MAT in making.resources)
var/datum/material/used_material = MAT
var/amount_needed = making.resources[MAT] * coeff * multiplier
materials_used[used_material] = amount_needed
if(!materials.has_materials(materials_used))
return
//Consume materials.
for(var/material in making.resources)
if(!isnull(stored_material[material]))
stored_material[material] = max(0, stored_material[material] - round(making.resources[material] * coeff) * multiplier)
materials.use_materials(materials_used)
busy = making.name
update_use_power(USE_POWER_ACTIVE)
update_icon() // So lid closes
@@ -329,39 +322,19 @@
for(var/obj/item/weapon/stock_parts/manipulator/M in component_parts)
man_rating += M.rating
for(var/mat_name in storage_capacity)
storage_capacity[mat_name] = mb_rating * 25000
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
materials.max_amount = mb_rating * 25000
build_time = 50 / man_rating
mat_efficiency = 1.1 - man_rating * 0.1// Normally, price is 1.25 the amount of material, so this shouldn't go higher than 0.6. Maximum rating of parts is 5
update_tgui_static_data(usr)
/obj/machinery/autolathe/dismantle()
for(var/mat in stored_material)
var/datum/material/M = get_material_by_name(mat)
if(!istype(M))
continue
var/obj/item/stack/material/S = new M.stack_type(get_turf(src))
if(stored_material[mat] > S.perunit)
S.amount = round(stored_material[mat] / S.perunit)
else
qdel(S)
..()
return 1
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
materials.retrieve_all()
return ..()
/obj/machinery/autolathe/proc/eject_materials(var/material, var/amount) // 0 amount = 0 means ejecting a full stack; -1 means eject everything
var/recursive = amount == -1 ? 1 : 0
var/matstring = lowertext(material)
var/datum/material/M = get_material_by_name(matstring)
var/obj/item/stack/material/S = M.place_sheet(get_turf(src))
if(amount <= 0)
amount = S.max_amount
var/ejected = min(round(stored_material[matstring] / S.perunit), amount)
S.amount = min(ejected, amount)
if(S.amount <= 0)
qdel(S)
return
stored_material[matstring] -= ejected * S.perunit
if(recursive && stored_material[matstring] >= S.perunit)
eject_materials(matstring, -1)
/obj/machinery/autolathe/proc/AfterMaterialInsert(obj/item/item_inserted, id_inserted, amount_inserted)
flick("autolathe_loading", src)//plays metal insertion animation
// use_power(min(1000, amount_inserted / 100))
SStgui.update_uis(src)
@@ -154,7 +154,7 @@ var/list/name_to_material
if(length(named_arguments))
named_arguments = sortList(named_arguments)
fullid += named_arguments
return list2params(fullid)
return replacetext(list2params(fullid), "+", " ")
// Material definition and procs follow.