/**********************Ore Redemption Unit**************************/
//Turns all the various mining machines into a single unit to speed up mining and establish a point system
/obj/machinery/mineral/ore_redemption
name = "ore redemption machine"
desc = "A machine that accepts ore and instantly transforms it into workable material sheets. Points for ore are generated based on type and can be redeemed at a mining equipment vendor."
icon = 'icons/obj/machines/mining_machines.dmi'
icon_state = "ore_redemption"
density = 1
anchored = 1
input_dir = NORTH
output_dir = SOUTH
req_access = list(GLOB.access_mineral_storeroom)
var/req_access_reclaim = GLOB.access_mining_station
var/obj/item/weapon/card/id/inserted_id
var/points = 0
var/ore_pickup_rate = 15
var/sheet_per_ore = 1
var/point_upgrade = 1
var/list/ore_values = list("sand" = 1, "iron" = 1, "plasma" = 15, "silver" = 16, "gold" = 18, "titanium" = 30, "uranium" = 30, "diamond" = 50, "bluespace crystal" = 50, "bananium" = 60)
speed_process = 1
var/message_sent = FALSE
var/list/ore_buffer = list()
var/datum/material_container/materials
var/datum/research/files
var/obj/item/weapon/disk/design_disk/inserted_disk
/obj/machinery/mineral/ore_redemption/Initialize()
. = ..()
var/obj/item/weapon/circuitboard/machine/ore_redemption/B = new
B.apply_default_parts(src)
materials = new(src, list(MAT_METAL, MAT_GLASS, MAT_SILVER, MAT_GOLD, MAT_DIAMOND, MAT_PLASMA, MAT_URANIUM, MAT_BANANIUM, MAT_TITANIUM, MAT_BLUESPACE),INFINITY)
files = new /datum/research/smelter(src)
/obj/machinery/mineral/ore_redemption/Destroy()
QDEL_NULL(materials)
QDEL_NULL(files)
return ..()
/obj/item/weapon/circuitboard/machine/ore_redemption
name = "Ore Redemption (Machine Board)"
build_path = /obj/machinery/mineral/ore_redemption
origin_tech = "programming=1;engineering=2"
req_components = list(
/obj/item/weapon/stock_parts/console_screen = 1,
/obj/item/weapon/stock_parts/matter_bin = 1,
/obj/item/weapon/stock_parts/micro_laser = 1,
/obj/item/weapon/stock_parts/manipulator = 1,
/obj/item/device/assembly/igniter = 1)
/obj/machinery/mineral/ore_redemption/RefreshParts()
var/ore_pickup_rate_temp = 15
var/point_upgrade_temp = 1
var/sheet_per_ore_temp = 1
for(var/obj/item/weapon/stock_parts/matter_bin/B in component_parts)
sheet_per_ore_temp = 0.65 + (0.35 * B.rating)
for(var/obj/item/weapon/stock_parts/manipulator/M in component_parts)
ore_pickup_rate_temp = 15 * M.rating
for(var/obj/item/weapon/stock_parts/micro_laser/L in component_parts)
point_upgrade_temp = 0.65 + (0.35 * L.rating)
ore_pickup_rate = ore_pickup_rate_temp
point_upgrade = point_upgrade_temp
sheet_per_ore = sheet_per_ore_temp
/obj/machinery/mineral/ore_redemption/proc/smelt_ore(obj/item/weapon/ore/O)
ore_buffer -= O
if(O && O.refined_type)
points += O.points * point_upgrade
var/material_amount = materials.get_item_material_amount(O)
if(!material_amount)
qdel(O) //no materials, incinerate it
else if(!materials.has_space(material_amount * sheet_per_ore)) //if there is no space, eject it
unload_mineral(O)
else
materials.insert_item(O, sheet_per_ore) //insert it
qdel(O)
/obj/machinery/mineral/ore_redemption/proc/can_smelt_alloy(datum/design/D)
if(D.make_reagents.len)
return 0
var/build_amount = 0
for(var/mat_id in D.materials)
var/M = D.materials[mat_id]
var/datum/material/redemption_mat = materials.materials[mat_id]
if(!M || !redemption_mat)
return 0
var/smeltable_sheets = round(redemption_mat.amount / M)
if(!smeltable_sheets)
return 0
if(!build_amount)
build_amount = smeltable_sheets
build_amount = min(build_amount, smeltable_sheets)
return build_amount
/obj/machinery/mineral/ore_redemption/proc/process_ores(list/ores_to_process)
var/current_amount = 0
for(var/ore in ores_to_process)
if(current_amount >= ore_pickup_rate)
break
smelt_ore(ore)
/obj/machinery/mineral/ore_redemption/proc/send_console_message()
if(z != ZLEVEL_STATION)
return
message_sent = TRUE
var/area/A = get_area(src)
var/msg = "Now available in [A]:
"
var/has_minerals = FALSE
for(var/mat_id in materials.materials)
var/datum/material/M = materials.materials[mat_id]
var/mineral_amount = M.amount / MINERAL_MATERIAL_AMOUNT
if(mineral_amount)
has_minerals = TRUE
msg += "[capitalize(M.name)]: [mineral_amount] sheets
"
if(!has_minerals)
return
for(var/obj/machinery/requests_console/D in GLOB.allConsoles)
if(D.receive_ore_updates)
D.createmessage("Ore Redemption Machine", "New minerals available!", msg, 1, 0)
/obj/machinery/mineral/ore_redemption/process()
if(panel_open || !powered())
return
var/atom/input = get_step(src, input_dir)
var/obj/structure/ore_box/OB = locate() in input
if(OB)
input = OB
for(var/obj/item/weapon/ore/O in input)
if(QDELETED(O))
continue
ore_buffer |= O
O.forceMove(src)
CHECK_TICK
if(LAZYLEN(ore_buffer))
message_sent = FALSE
process_ores(ore_buffer)
else if(!message_sent)
send_console_message()
/obj/machinery/mineral/ore_redemption/attackby(obj/item/weapon/W, mob/user, params)
if(exchange_parts(user, W))
return
if(default_pry_open(W))
materials.retrieve_all()
return
if(default_unfasten_wrench(user, W))
return
if(default_deconstruction_screwdriver(user, "ore_redemption-open", "ore_redemption", W))
updateUsrDialog()
return
if(default_deconstruction_crowbar(W))
return
if(!powered())
return
if(istype(W,/obj/item/weapon/card/id))
var/obj/item/weapon/card/id/I = user.get_active_held_item()
if(istype(I) && !istype(inserted_id))
if(!user.drop_item())
return
I.forceMove(src)
inserted_id = I
interact(user)
return
if(istype(W, /obj/item/device/multitool) && panel_open)
input_dir = turn(input_dir, -90)
output_dir = turn(output_dir, -90)
to_chat(user, "You change [src]'s I/O settings, setting the input to [dir2text(input_dir)] and the output to [dir2text(output_dir)].")
return
if(istype(W, /obj/item/weapon/disk/design_disk))
if(user.transferItemToLoc(W, src))
inserted_disk = W
return TRUE
return ..()
/obj/machinery/mineral/ore_redemption/on_deconstruction()
materials.retrieve_all()
..()
/obj/machinery/mineral/ore_redemption/attack_hand(mob/user)
if(..())
return
interact(user)
/obj/machinery/mineral/ore_redemption/interact(mob/user)
var/dat = "This machine only accepts ore. Gibtonite and Slag are not accepted.
"
dat += "Current unclaimed points: [points]
"
if(inserted_id)
dat += "You have [inserted_id.mining_points] mining points collected. Eject ID.
"
dat += "Claim points.
"
else
dat += "No ID inserted. Insert ID.
"
for(var/mat_id in materials.materials)
var/datum/material/M = materials.materials[mat_id]
if(M.amount)
var/sheet_amount = M.amount / MINERAL_MATERIAL_AMOUNT
dat += "[capitalize(M.name)]: [sheet_amount] "
if(sheet_amount >= 1)
dat += "Release
"
else
dat += "Release
"
dat += "
Alloys:
"
for(var/v in files.known_designs)
var/datum/design/D = files.known_designs[v]
if(can_smelt_alloy(D))
dat += "[D.name]: Smelt
"
else
dat += "[D.name]: Smelt
"
dat += "
| [capitalize(ore)] | [value * point_upgrade] |