From 4da74143398a326efde068c0c74b1045d7e772f0 Mon Sep 17 00:00:00 2001 From: CitadelStationBot Date: Sat, 29 Apr 2017 03:46:03 -0500 Subject: [PATCH] Old ore processor cleanup --- code/__DEFINES/machines.dm | 1 + code/datums/material_container.dm | 18 +- .../mining/machine_input_output_plates.dm | 4 +- code/modules/mining/machine_processing.dm | 528 ++++++------------ .../research/designs/smelting_designs.dm | 18 + code/modules/research/research.dm | 15 + tgstation.dme | 1 + 7 files changed, 206 insertions(+), 379 deletions(-) create mode 100644 code/modules/research/designs/smelting_designs.dm diff --git a/code/__DEFINES/machines.dm b/code/__DEFINES/machines.dm index 004ea378da..9524fc9a43 100644 --- a/code/__DEFINES/machines.dm +++ b/code/__DEFINES/machines.dm @@ -23,6 +23,7 @@ #define MECHFAB 16 //Remember, objects utilising this flag should have construction_time and construction_cost vars. #define BIOGENERATOR 32 //Uses biomass #define LIMBGROWER 64 //Uses synthetic flesh +#define SMELTER 128 //uses various minerals //Note: More then one of these can be added to a design but imprinter and lathe designs are incompatable. //Modular computer/NTNet defines diff --git a/code/datums/material_container.dm b/code/datums/material_container.dm index af227212a7..76de0329cd 100644 --- a/code/datums/material_container.dm +++ b/code/datums/material_container.dm @@ -136,7 +136,7 @@ return FALSE //For spawning mineral sheets; internal use only -/datum/material_container/proc/retrieve(sheet_amt, datum/material/M) +/datum/material_container/proc/retrieve(sheet_amt, datum/material/M, target = null) if(!M.sheet_type) return 0 if(sheet_amt > 0) @@ -149,26 +149,28 @@ use_amount_type(sheet_amt * MINERAL_MATERIAL_AMOUNT, M.id) sheet_amt -= MAX_STACK_SIZE if(round((sheet_amt * MINERAL_MATERIAL_AMOUNT) / MINERAL_MATERIAL_AMOUNT)) - new M.sheet_type(get_turf(owner), sheet_amt) + var/obj/item/stack/sheet/s = new M.sheet_type(get_turf(owner), sheet_amt) + if(target) + s.forceMove(target) count += sheet_amt use_amount_type(sheet_amt * MINERAL_MATERIAL_AMOUNT, M.id) return count return 0 -/datum/material_container/proc/retrieve_sheets(sheet_amt, id) +/datum/material_container/proc/retrieve_sheets(sheet_amt, id, target = null) if(materials[id]) - return retrieve(sheet_amt, materials[id]) + return retrieve(sheet_amt, materials[id], target) return 0 -/datum/material_container/proc/retrieve_amount(amt, id) - return retrieve_sheets(amount2sheet(amt), id) +/datum/material_container/proc/retrieve_amount(amt, id, target) + return retrieve_sheets(amount2sheet(amt), id, target) -/datum/material_container/proc/retrieve_all() +/datum/material_container/proc/retrieve_all(target = null) var/result = 0 var/datum/material/M for(var/MAT in materials) M = materials[MAT] - result += retrieve_sheets(amount2sheet(M.amount), MAT) + result += retrieve_sheets(amount2sheet(M.amount), MAT, target) return result /datum/material_container/proc/has_space(amt = 0) diff --git a/code/modules/mining/machine_input_output_plates.dm b/code/modules/mining/machine_input_output_plates.dm index a2e5e9ad3c..7e888217a1 100644 --- a/code/modules/mining/machine_input_output_plates.dm +++ b/code/modules/mining/machine_input_output_plates.dm @@ -25,7 +25,7 @@ var/output_dir = SOUTH /obj/machinery/mineral/proc/unload_mineral(atom/movable/S) - S.loc = loc + S.forceMove(loc) var/turf/T = get_step(src,output_dir) if(T) - S.loc = T \ No newline at end of file + S.forceMove(T) \ No newline at end of file diff --git a/code/modules/mining/machine_processing.dm b/code/modules/mining/machine_processing.dm index 8b4903259e..e62392a8c8 100644 --- a/code/modules/mining/machine_processing.dm +++ b/code/modules/mining/machine_processing.dm @@ -1,3 +1,5 @@ +#define SMELT_AMOUNT 10 + /**********************Mineral processing unit console**************************/ /obj/machinery/mineral/processing_unit_console @@ -10,182 +12,50 @@ var/machinedir = EAST speed_process = 1 -/obj/machinery/mineral/processing_unit_console/New() - ..() - spawn(7) - src.machine = locate(/obj/machinery/mineral/processing_unit, get_step(src, machinedir)) - if (machine) - machine.CONSOLE = src - else - qdel(src) +/obj/machinery/mineral/processing_unit_console/Initialize() + . = ..() + machine = locate(/obj/machinery/mineral/processing_unit, get_step(src, machinedir)) + if (machine) + machine.CONSOLE = src + else + qdel(src) /obj/machinery/mineral/processing_unit_console/attack_hand(mob/user) - var/dat = "Smelter control console

" - //iron - if(machine.ore_iron || machine.ore_glass || machine.ore_plasma || machine.ore_uranium || machine.ore_gold || machine.ore_silver || machine.ore_diamond || machine.ore_clown || machine.ore_adamantine) - if(machine.ore_iron) - if (machine.selected_iron==1) - dat += "Smelting " - else - dat += "Not smelting " - dat += "Iron: [machine.ore_iron]
" - else - machine.selected_iron = 0 - - //sand - glass - if(machine.ore_glass) - if (machine.selected_glass==1) - dat += "Smelting " - else - dat += "Not smelting " - dat += "Sand: [machine.ore_glass]
" - else - machine.selected_glass = 0 - - //plasma - if(machine.ore_plasma) - if (machine.selected_plasma==1) - dat += "Smelting " - else - dat += "Not smelting " - dat += "Plasma: [machine.ore_plasma]
" - else - machine.selected_plasma = 0 - - //uranium - if(machine.ore_uranium) - if (machine.selected_uranium==1) - dat += "Smelting " - else - dat += "Not smelting " - dat += "Uranium: [machine.ore_uranium]
" - else - machine.selected_uranium = 0 - - //gold - if(machine.ore_gold) - if (machine.selected_gold==1) - dat += "Smelting " - else - dat += "Not smelting " - dat += "Gold: [machine.ore_gold]
" - else - machine.selected_gold = 0 - - //silver - if(machine.ore_silver) - if (machine.selected_silver==1) - dat += "Smelting " - else - dat += "Not smelting " - dat += "Silver: [machine.ore_silver]
" - else - machine.selected_silver = 0 - - //diamond - if(machine.ore_diamond) - if (machine.selected_diamond==1) - dat += "Smelting " - else - dat += "Not smelting " - dat += "Diamond: [machine.ore_diamond]
" - else - machine.selected_diamond = 0 - - //bananium - if(machine.ore_clown) - if (machine.selected_clown==1) - dat += "Smelting " - else - dat += "Not smelting " - dat += "Bananium: [machine.ore_clown]
" - else - machine.selected_clown = 0 - - //titanium - if(machine.ore_titanium) - if (machine.selected_titanium==1) - dat += "Smelting " - else - dat += "Not smelting " - dat += "Titanium: [machine.ore_titanium]
" - else - machine.selected_titanium = 0 - - - //On or off - dat += text("Machine is currently ") - if (machine.on==1) - dat += text("On ") - else - dat += text("Off ") - else - dat+="---No Materials Loaded---" - - - user << browse(dat, "window=console_processing_unit") + 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) - src.add_fingerprint(usr) - if(href_list["sel_iron"]) - if (href_list["sel_iron"] == "yes") - machine.selected_iron = 1 - else - machine.selected_iron = 0 - if(href_list["sel_glass"]) - if (href_list["sel_glass"] == "yes") - machine.selected_glass = 1 - else - machine.selected_glass = 0 - if(href_list["sel_plasma"]) - if (href_list["sel_plasma"] == "yes") - machine.selected_plasma = 1 - else - machine.selected_plasma = 0 - if(href_list["sel_uranium"]) - if (href_list["sel_uranium"] == "yes") - machine.selected_uranium = 1 - else - machine.selected_uranium = 0 - if(href_list["sel_gold"]) - if (href_list["sel_gold"] == "yes") - machine.selected_gold = 1 - else - machine.selected_gold = 0 - if(href_list["sel_silver"]) - if (href_list["sel_silver"] == "yes") - machine.selected_silver = 1 - else - machine.selected_silver = 0 - if(href_list["sel_diamond"]) - if (href_list["sel_diamond"] == "yes") - machine.selected_diamond = 1 - else - machine.selected_diamond = 0 - if(href_list["sel_clown"]) - if (href_list["sel_clown"] == "yes") - machine.selected_clown = 1 - else - machine.selected_clown = 0 - if(href_list["sel_titanium"]) - if (href_list["sel_titanium"] == "yes") - machine.selected_titanium = 1 - else - machine.selected_titanium = 0 + add_fingerprint(usr) + + if(href_list["material"]) + machine.selected_material = href_list["material"] + machine.selected_alloy = null + + if(href_list["alloy"]) + machine.selected_material = null + machine.selected_alloy = href_list["alloy"] + if(href_list["set_on"]) - if (href_list["set_on"] == "on") - machine.on = 1 - else - machine.on = 0 - src.updateUsrDialog() + machine.on = (href_list["set_on"] == "on") + + updateUsrDialog() return +/obj/machinery/mineral/processing_unit_console/Destroy() + machine = null + return ..() + + /**********************Mineral processing unit**************************/ @@ -196,117 +66,84 @@ density = 1 anchored = 1 var/obj/machinery/mineral/CONSOLE = null - var/ore_gold = 0; - var/ore_silver = 0; - var/ore_diamond = 0; - var/ore_glass = 0; - var/ore_plasma = 0; - var/ore_uranium = 0; - var/ore_iron = 0; - var/ore_clown = 0; - var/ore_adamantine = 0; - var/ore_titanium = 0; - var/selected_gold = 0 - var/selected_silver = 0 - var/selected_diamond = 0 - var/selected_glass = 0 - var/selected_plasma = 0 - var/selected_uranium = 0 - var/selected_iron = 0 - var/selected_clown = 0 - var/selected_titanium = 0 - var/on = 0 //0 = off, 1 =... oh you know! + var/datum/material_container/materials + var/on = FALSE + var/selected_material = MAT_METAL + var/selected_alloy = null + var/datum/research/files + var/list/categories = list("Alloys") +/obj/machinery/mineral/processing_unit/Initialize() + . = ..() + proximity_monitor = new(src, 1) + 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/processing_unit/Destroy() + CONSOLE = null + qdel(materials) + return ..() + +/obj/machinery/mineral/processing_unit/HasProximity(atom/movable/AM) + if(istype(AM, /obj/item/weapon/ore) && AM.loc == get_step(src, input_dir)) + process_ore(AM) + +/obj/machinery/mineral/processing_unit/proc/process_ore(obj/item/weapon/ore/O) + 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 = "Smelter control console

" + for(var/mat_id in materials.materials) + var/datum/material/M = materials.materials[mat_id] + dat += "[M.name]: [M.amount] cm³" + if (selected_material == mat_id) + dat += " Smelting" + else + dat += " Not Smelting " + dat += "
" + + dat += "

" + dat += "Smelt Alloys
" + + for(var/v in files.known_designs) + var/datum/design/D = files.known_designs[v] + dat += "[D.name] " + if (selected_alloy == D.id) + dat += " Smelting" + else + dat += " Not Smelting " + dat += "
" + + dat += "

" + //On or off + dat += "Machine is currently " + if (on) + dat += "On " + else + dat += "Off " + + return dat + /obj/machinery/mineral/processing_unit/process() - for(var/i in 1 to 10) - if (on) - if (selected_glass && !selected_gold && !selected_silver && !selected_diamond && !selected_plasma && !selected_uranium && !selected_iron && !selected_clown && !selected_titanium) - if (ore_glass > 0) - ore_glass-- - generate_mineral(/obj/item/stack/sheet/glass) - else - on = 0 - continue - if (selected_glass && !selected_gold && !selected_silver && !selected_diamond && !selected_plasma && !selected_uranium && selected_iron && !selected_clown && !selected_titanium) - if (ore_glass > 0 && ore_iron > 0) - ore_glass-- - ore_iron-- - generate_mineral(/obj/item/stack/sheet/rglass) - else - on = 0 - continue - if (!selected_glass && selected_gold && !selected_silver && !selected_diamond && !selected_plasma && !selected_uranium && !selected_iron && !selected_clown && !selected_titanium) - if (ore_gold > 0) - ore_gold-- - generate_mineral(/obj/item/stack/sheet/mineral/gold) - else - on = 0 - continue - if (!selected_glass && !selected_gold && selected_silver && !selected_diamond && !selected_plasma && !selected_uranium && !selected_iron && !selected_clown && !selected_titanium) - if (ore_silver > 0) - ore_silver-- - generate_mineral(/obj/item/stack/sheet/mineral/silver) - else - on = 0 - continue - if (!selected_glass && !selected_gold && !selected_silver && selected_diamond && !selected_plasma && !selected_uranium && !selected_iron && !selected_clown && !selected_titanium) - if (ore_diamond > 0) - ore_diamond-- - generate_mineral(/obj/item/stack/sheet/mineral/diamond) - else - on = 0 - continue - if (!selected_glass && !selected_gold && !selected_silver && !selected_diamond && selected_plasma && !selected_uranium && !selected_iron && !selected_clown && !selected_titanium) - if (ore_plasma > 0) - ore_plasma-- - generate_mineral(/obj/item/stack/sheet/mineral/plasma) - else - on = 0 - continue - if (!selected_glass && !selected_gold && !selected_silver && !selected_diamond && !selected_plasma && selected_uranium && !selected_iron && !selected_clown && !selected_titanium) - if (ore_uranium > 0) - ore_uranium-- - generate_mineral(/obj/item/stack/sheet/mineral/uranium) - else - on = 0 - continue - if (!selected_glass && !selected_gold && !selected_silver && !selected_diamond && !selected_plasma && !selected_uranium && selected_iron && !selected_clown && !selected_titanium) - if (ore_iron > 0) - ore_iron-- - generate_mineral(/obj/item/stack/sheet/metal) - else - on = 0 - continue - if (!selected_glass && !selected_gold && !selected_silver && !selected_diamond && selected_plasma && !selected_uranium && selected_iron && !selected_clown && !selected_titanium) - if (ore_iron > 0 && ore_plasma > 0) - ore_iron-- - ore_plasma-- - generate_mineral(/obj/item/stack/sheet/plasteel) - else - on = 0 - continue - if (!selected_glass && !selected_gold && !selected_silver && !selected_diamond && !selected_plasma && !selected_uranium && !selected_iron && selected_clown && !selected_titanium) - if (ore_clown > 0) - ore_clown-- - generate_mineral(/obj/item/stack/sheet/mineral/bananium) - else - on = 0 - continue - if (!selected_glass && !selected_gold && !selected_silver && !selected_diamond && !selected_plasma && !selected_uranium && !selected_iron && !selected_clown && selected_titanium) - if (ore_titanium > 0) - ore_titanium-- - generate_mineral(/obj/item/stack/sheet/mineral/titanium) - else - on = 0 - continue - if (!selected_glass && !selected_gold && !selected_silver && !selected_diamond && selected_plasma && !selected_uranium && !selected_iron && !selected_clown && selected_titanium) - if (ore_titanium > 0) - ore_titanium-- - ore_plasma-- - generate_mineral(/obj/item/stack/sheet/mineral/plastitanium) - else - on = 0 - continue + if (on) + if(selected_material) + smelt_ore() + + else if(selected_alloy) + smelt_alloy() + + + if(CONSOLE) + CONSOLE.updateUsrDialog() + + //THESE TWO ARE CODED FOR URIST TO USE WHEN HE GETS AROUND TO IT. //They were coded on 18 Feb 2012. If you're reading this in 2015, then firstly congratulations on the world not ending on 21 Dec 2012 and secondly, Urist is apparently VERY lazy. ~Errorage //Even in the dark year of 2016, where /tg/ is dead, Urist still hasn't finished this -Bawhoppennn @@ -327,104 +164,57 @@ on = 0 continue*/ - - //if a non valid combination is selected - - var/b = 1 //this part checks if all required ores are available - - if (!(selected_gold || selected_silver ||selected_diamond || selected_uranium | selected_plasma || selected_iron || selected_iron)) - b = 0 - - if (selected_gold == 1) - if (ore_gold <= 0) - b = 0 - if (selected_silver == 1) - if (ore_silver <= 0) - b = 0 - if (selected_diamond == 1) - if (ore_diamond <= 0) - b = 0 - if (selected_uranium == 1) - if (ore_uranium <= 0) - b = 0 - if (selected_plasma == 1) - if (ore_plasma <= 0) - b = 0 - if (selected_iron == 1) - if (ore_iron <= 0) - b = 0 - if (selected_glass == 1) - if (ore_glass <= 0) - b = 0 - if (selected_clown == 1) - if (ore_clown <= 0) - b = 0 - - if (b) //if they are, deduct one from each, produce slag and shut the machine off - if (selected_gold == 1) - ore_gold-- - if (selected_silver == 1) - ore_silver-- - if (selected_diamond == 1) - ore_diamond-- - if (selected_uranium == 1) - ore_uranium-- - if (selected_plasma == 1) - ore_plasma-- - if (selected_iron == 1) - ore_iron-- - if (selected_clown == 1) - ore_clown-- - generate_mineral(/obj/item/weapon/ore/slag) - on = 0 - else - on = 0 - break - break - else - break - var/turf/T = get_step(src,input_dir) - if(T) - var/n = 0 - for(var/obj/item/O in T) - n++ - if(n>10) - break - if (istype(O,/obj/item/weapon/ore/iron)) - ore_iron++; - O.loc = null - continue - if (istype(O,/obj/item/weapon/ore/glass)) - ore_glass++; - O.loc = null - continue - if (istype(O,/obj/item/weapon/ore/diamond)) - ore_diamond++; - O.loc = null - continue - if (istype(O,/obj/item/weapon/ore/plasma)) - ore_plasma++ - O.loc = null - continue - if (istype(O,/obj/item/weapon/ore/gold)) - ore_gold++ - O.loc = null - continue - if (istype(O,/obj/item/weapon/ore/silver)) - ore_silver++ - O.loc = null - continue - if (istype(O,/obj/item/weapon/ore/uranium)) - ore_uranium++ - O.loc = null - continue - if (istype(O,/obj/item/weapon/ore/bananium)) - ore_clown++ - O.loc = null - continue - unload_mineral(O) - +/obj/machinery/mineral/processing_unit/proc/smelt_ore() + var/datum/material/mat = materials.materials[selected_material] + if(mat) + var/sheets_to_remove = (mat.amount >= (MINERAL_MATERIAL_AMOUNT * SMELT_AMOUNT) ) ? SMELT_AMOUNT : round(mat.amount / MINERAL_MATERIAL_AMOUNT) + if(!sheets_to_remove) + on = FALSE + else + var/out = get_step(src, output_dir) + materials.retrieve_sheets(sheets_to_remove, selected_material, out) + + +/obj/machinery/mineral/processing_unit/proc/smelt_alloy() + var/datum/design/alloy = files.FindDesignByID(selected_alloy) //check if it's a valid design + if(!alloy) + on = FALSE + return + + var/amount = can_smelt(alloy) + + if(!amount) + on = FALSE + return + + materials.use_amount(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 0 + + var/build_amount = SMELT_AMOUNT + + + for(var/mat_id in D.materials) + var/M = D.materials[mat_id] + var/datum/material/smelter_mat = materials.materials[mat_id] + + if(!M || !smelter_mat) + return 0 + + build_amount = min(build_amount, round(smelter_mat.amount / M)) + + 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() + materials.retrieve_all() + ..() + +#undef SMELT_AMOUNT \ No newline at end of file diff --git a/code/modules/research/designs/smelting_designs.dm b/code/modules/research/designs/smelting_designs.dm new file mode 100644 index 0000000000..2672e0e27a --- /dev/null +++ b/code/modules/research/designs/smelting_designs.dm @@ -0,0 +1,18 @@ +///////SMELTABLE ALLOYS/////// + +/datum/design/plasteel_alloy + name = "Plasma + Iron alloy" + id = "plasteel" + build_type = SMELTER + materials = list(MAT_METAL = MINERAL_MATERIAL_AMOUNT / 2, MAT_PLASMA = MINERAL_MATERIAL_AMOUNT / 2) + build_path = /obj/item/stack/sheet/plasteel + category = list("initial","Alloys") + + +/datum/design/plastitanium_alloy + name = "Plasma + Titanium alloy" + id = "plastitanium" + build_type = SMELTER + materials = list(MAT_TITANIUM = MINERAL_MATERIAL_AMOUNT / 2, MAT_PLASMA = MINERAL_MATERIAL_AMOUNT / 2) + build_path = /obj/item/stack/sheet/mineral/plastitanium + category = list("initial","Alloys") \ No newline at end of file diff --git a/code/modules/research/research.dm b/code/modules/research/research.dm index deb8d34ffc..674825b9f7 100644 --- a/code/modules/research/research.dm +++ b/code/modules/research/research.dm @@ -175,6 +175,21 @@ research holder datum. return ..() +//Smelter files +/datum/research/smelter/New() + for(var/T in (subtypesof(/datum/tech))) + possible_tech += new T(src) + for(var/path in subtypesof(/datum/design)) + var/datum/design/D = new path(src) + possible_designs += D + if((D.build_type & SMELTER) && ("initial" in D.category)) + AddDesign2Known(D) + +/datum/research/biogenerator/AddDesign2Known(datum/design/D) + if(!(D.build_type & SMELTER)) + return + ..() + /*************************************************************** ** Technology Datums ** diff --git a/tgstation.dme b/tgstation.dme index 1647912f6c..d70d1bf7f4 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -1995,6 +1995,7 @@ #include "code\modules\research\designs\mechfabricator_designs.dm" #include "code\modules\research\designs\medical_designs.dm" #include "code\modules\research\designs\power_designs.dm" +#include "code\modules\research\designs\smelting_designs.dm" #include "code\modules\research\designs\stock_parts_designs.dm" #include "code\modules\research\designs\telecomms_designs.dm" #include "code\modules\research\designs\weapon_designs.dm"