Files
Yogstation/code/modules/mining/machine_processing.dm
Theos 79f9ca537a fixes coin mint not working at all (#12594)
* fixes coin mint not working at all

* Update machine_processing.dm
2021-11-04 09:41:14 -04:00

213 lines
6.5 KiB
Plaintext

#define SMELT_AMOUNT 10
/**********************Mineral processing unit console**************************/
/obj/machinery/mineral
var/input_dir = NORTH
var/output_dir = SOUTH
/obj/machinery/mineral/proc/unload_mineral(atom/movable/S)
if(!istype(S, /obj/item/stack/ore) && !istype(S, /obj/item/stack/sheet) && !istype(S, /obj/item/storage/bag/money)) // Realistically who is gonna shove a sheet into the loading machine --Redmoogle
return
S.forceMove(drop_location())
var/turf/T = get_step(src,output_dir)
if(T)
S.forceMove(T)
/obj/machinery/mineral/processing_unit_console
name = "production machine console"
icon = 'icons/obj/machines/mining_machines.dmi'
icon_state = "console"
density = TRUE
var/obj/machinery/mineral/processing_unit/machine = null
var/machinedir = EAST
speed_process = TRUE
/obj/machinery/mineral/processing_unit_console/Initialize()
. = ..()
machine = locate(/obj/machinery/mineral/processing_unit, get_step(src, machinedir))
if (machine)
machine.CONSOLE = src
else
return INITIALIZE_HINT_QDEL
/obj/machinery/mineral/processing_unit_console/ui_interact(mob/user)
. = ..()
if(!machine)
return
var/dat = machine.get_machine_data()
var/datum/browser/popup = new(user, "processing", "Smelting Console", 300, 500)
popup.set_content(dat)
popup.open()
/obj/machinery/mineral/processing_unit_console/Topic(href, href_list)
if(..())
return
usr.set_machine(src)
add_fingerprint(usr)
if(href_list["material"])
var/datum/material/new_material = locate(href_list["material"])
if(istype(new_material))
machine.selected_material = new_material
machine.selected_alloy = null
if(href_list["alloy"])
machine.selected_material = null
machine.selected_alloy = href_list["alloy"]
if(href_list["set_on"])
machine.on = (href_list["set_on"] == "on")
updateUsrDialog()
return
/obj/machinery/mineral/processing_unit_console/Destroy()
machine = null
return ..()
/**********************Mineral processing unit**************************/
/obj/machinery/mineral/processing_unit
name = "furnace"
icon = 'icons/obj/machines/mining_machines.dmi'
icon_state = "furnace"
density = TRUE
var/obj/machinery/mineral/CONSOLE = null
var/on = FALSE
var/selected_material = /datum/material/iron
var/selected_alloy = null
var/datum/techweb/stored_research
/obj/machinery/mineral/processing_unit/Initialize()
. = ..()
proximity_monitor = new(src, 1)
AddComponent(/datum/component/material_container, list(/datum/material/iron, /datum/material/glass, /datum/material/silver, /datum/material/gold, /datum/material/diamond, /datum/material/plasma, /datum/material/uranium, /datum/material/bananium, /datum/material/titanium, /datum/material/bluespace, /datum/material/dilithium),INFINITY, TRUE, /obj/item/stack) //Yogs: added dilithium
stored_research = new /datum/techweb/specialized/autounlocking/smelter
/obj/machinery/mineral/processing_unit/Destroy()
CONSOLE = null
QDEL_NULL(stored_research)
return ..()
/obj/machinery/mineral/processing_unit/HasProximity(atom/movable/AM)
if(istype(AM, /obj/item/stack/ore) && AM.loc == get_step(src, input_dir))
process_ore(AM)
/obj/machinery/mineral/processing_unit/proc/process_ore(obj/item/stack/ore/O)
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
var/material_amount = materials.get_item_material_amount(O)
if(!materials.has_space(material_amount))
unload_mineral(O)
else
materials.insert_item(O)
qdel(O)
if(CONSOLE)
CONSOLE.updateUsrDialog()
/obj/machinery/mineral/processing_unit/proc/get_machine_data()
var/dat = "<b>Smelter control console</b><br><br>"
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
for(var/datum/material/M in materials.materials)
var/amount = materials.materials[M]
dat += "<span class=\"res_name\">[M.name]: </span>[amount] cm&sup3;"
if (selected_material == M)
dat += " <i>Smelting</i>"
else
dat += " <A href='?src=[REF(CONSOLE)];material=[REF(M)]'><b>Not Smelting</b></A> "
dat += "<br>"
dat += "<br><br>"
dat += "<b>Smelt Alloys</b><br>"
for(var/v in stored_research.researched_designs)
var/datum/design/D = SSresearch.techweb_design_by_id(v)
dat += "<span class=\"res_name\">[D.name] "
if (selected_alloy == D.id)
dat += " <i>Smelting</i>"
else
dat += " <A href='?src=[REF(CONSOLE)];alloy=[D.id]'><b>Not Smelting</b></A> "
dat += "<br>"
dat += "<br><br>"
//On or off
dat += "Machine is currently "
if (on)
dat += "<A href='?src=[REF(CONSOLE)];set_on=off'>On</A> "
else
dat += "<A href='?src=[REF(CONSOLE)];set_on=on'>Off</A> "
return dat
/obj/machinery/mineral/processing_unit/process()
if (on)
if(selected_material)
smelt_ore()
else if(selected_alloy)
smelt_alloy()
if(CONSOLE)
CONSOLE.updateUsrDialog()
/obj/machinery/mineral/processing_unit/proc/smelt_ore()
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
var/datum/material/mat = selected_material
if(mat)
var/sheets_to_remove = (materials.materials[mat] >= (MINERAL_MATERIAL_AMOUNT * SMELT_AMOUNT) ) ? SMELT_AMOUNT : round(materials.materials[mat] / MINERAL_MATERIAL_AMOUNT)
if(!sheets_to_remove)
on = FALSE
else
var/out = get_step(src, output_dir)
materials.retrieve_sheets(sheets_to_remove, mat, out)
/obj/machinery/mineral/processing_unit/proc/smelt_alloy()
var/datum/design/alloy = stored_research.isDesignResearchedID(selected_alloy) //check if it's a valid design
if(!alloy)
on = FALSE
return
var/amount = can_smelt(alloy)
if(!amount)
on = FALSE
return
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
materials.use_materials(alloy.materials, amount)
generate_mineral(alloy.build_path)
/obj/machinery/mineral/processing_unit/proc/can_smelt(datum/design/D)
if(D.make_reagents.len)
return FALSE
var/build_amount = SMELT_AMOUNT
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
for(var/mat_cat in D.materials)
var/required_amount = D.materials[mat_cat]
var/amount = materials.materials[mat_cat]
build_amount = min(build_amount, round(amount / required_amount))
return build_amount
/obj/machinery/mineral/processing_unit/proc/generate_mineral(P)
var/O = new P(src)
unload_mineral(O)
/obj/machinery/mineral/processing_unit/on_deconstruction()
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
materials.retrieve_all()
..()
#undef SMELT_AMOUNT