Merge pull request #5216 from VOREStation/vplk-smelter-cleanup

Quick cleanup of mineral processing unit code
This commit is contained in:
Atermonera
2018-05-01 12:37:27 -07:00
committed by GitHub

View File

@@ -1,38 +1,39 @@
/**********************Mineral processing unit console**************************/
#define PROCESS_NONE 0
#define PROCESS_SMELT 1
#define PROCESS_COMPRESS 2
#define PROCESS_ALLOY 3
/obj/machinery/mineral/processing_unit_console
name = "production machine console"
icon = 'icons/obj/machines/mining_machines.dmi'
icon_state = "console"
density = 1
anchored = 1
density = TRUE
anchored = TRUE
var/obj/machinery/mineral/processing_unit/machine = null
//var/machinedir = EAST //Dumb
var/show_all_ores = 0
var/show_all_ores = FALSE
/obj/machinery/mineral/processing_unit_console/New()
..()
spawn(7)
//src.machine = locate(/obj/machinery/mineral/processing_unit, get_step(src, machinedir))
src.machine = locate(/obj/machinery/mineral/processing_unit) in range(5,src)
if (machine)
machine.console = src
else
world << "<span class='danger'>Warning: Ore processing machine console at [src.x], [src.y], [src.z] could not find its machine!</span>"
qdel(src)
/obj/machinery/mineral/processing_unit_console/initialize()
. = ..()
src.machine = locate(/obj/machinery/mineral/processing_unit) in range(5, src)
if (machine)
machine.console = src
else
log_debug("Ore processing machine console at [src.x], [src.y], [src.z] could not find its machine!")
qdel(src)
/obj/machinery/mineral/processing_unit_console/attack_hand(mob/user)
add_fingerprint(user)
if(..())
return
interact(user)
/obj/machinery/mineral/processing_unit_console/interact(mob/user)
if(..())
return
if(!allowed(user))
user << "<font color='red'>Access denied.</font>"
to_chat(user, "<span class='warning'>Access denied.</span>")
return
user.set_machine(src)
@@ -49,13 +50,13 @@
dat += "<tr><td width = 40><b>[capitalize(O.display_name)]</b></td><td width = 30>[machine.ores_stored[ore]]</td><td width = 100>"
if(machine.ores_processing[ore])
switch(machine.ores_processing[ore])
if(0)
if(PROCESS_NONE)
dat += "<font color='red'>not processing</font>"
if(1)
if(PROCESS_SMELT)
dat += "<font color='orange'>smelting</font>"
if(2)
if(PROCESS_COMPRESS)
dat += "<font color='blue'>compressing</font>"
if(3)
if(PROCESS_ALLOY)
dat += "<font color='gray'>alloying</font>"
else
dat += "<font color='red'>not processing</font>"
@@ -80,10 +81,10 @@
if(!choice) return
switch(choice)
if("Nothing") choice = 0
if("Smelting") choice = 1
if("Compressing") choice = 2
if("Alloying") choice = 3
if("Nothing") choice = PROCESS_NONE
if("Smelting") choice = PROCESS_SMELT
if("Compressing") choice = PROCESS_COMPRESS
if("Alloying") choice = PROCESS_ALLOY
machine.ores_processing[href_list["toggle_smelting"]] = choice
@@ -105,8 +106,8 @@
name = "material processor" //This isn't actually a goddamn furnace, we're in space and it's processing platinum and flammable phoron...
icon = 'icons/obj/machines/mining_machines.dmi'
icon_state = "furnace"
density = 1
anchored = 1
density = TRUE
anchored = TRUE
light_range = 3
var/obj/machinery/mineral/input = null
var/obj/machinery/mineral/output = null
@@ -115,17 +116,17 @@
var/list/ores_processing[0]
var/list/ores_stored[0]
var/static/list/alloy_data
var/active = 0
var/active = FALSE
/obj/machinery/mineral/processing_unit/New()
..()
// initialize static alloy_data list
if(!alloy_data)
alloy_data = list()
for(var/alloytype in typesof(/datum/alloy)-/datum/alloy)
alloy_data += new alloytype()
// TODO - Initializing this here is insane. Put it in global lists init or something. ~Leshana
if(!ore_data || !ore_data.len)
for(var/oretype in typesof(/ore)-/ore)
var/ore/OD = new oretype()
@@ -133,15 +134,16 @@
ores_processing[OD.name] = 0
ores_stored[OD.name] = 0
/obj/machinery/mineral/processing_unit/initialize()
. = ..()
// TODO - Eschew input/output machinery and just use dirs ~Leshana
//Locate our output and input machinery.
spawn(5)
for (var/dir in cardinal)
src.input = locate(/obj/machinery/mineral/input, get_step(src, dir))
if(src.input) break
for (var/dir in cardinal)
src.output = locate(/obj/machinery/mineral/output, get_step(src, dir))
if(src.output) break
return
for (var/dir in cardinal)
src.input = locate(/obj/machinery/mineral/input, get_step(src, dir))
if(src.input) break
for (var/dir in cardinal)
src.output = locate(/obj/machinery/mineral/output, get_step(src, dir))
if(src.output) break
return
/obj/machinery/mineral/processing_unit/process()
@@ -174,7 +176,7 @@
if(!O) continue
if(ores_processing[metal] == 3 && O.alloy) //Alloying.
if(ores_processing[metal] == PROCESS_ALLOY && O.alloy) //Alloying.
for(var/datum/alloy/A in alloy_data)
@@ -190,7 +192,7 @@
for(var/needs_metal in A.requires)
//Check if we're alloying the needed metal and have it stored.
if(ores_processing[needs_metal] != 3 || ores_stored[needs_metal] < A.requires[needs_metal])
if(ores_processing[needs_metal] != PROCESS_ALLOY || ores_stored[needs_metal] < A.requires[needs_metal])
enough_metal = 0
break
@@ -207,7 +209,7 @@
for(var/i=0,i<total,i++)
new A.product(output.loc)
else if(ores_processing[metal] == 2 && O.compresses_to) //Compressing.
else if(ores_processing[metal] == PROCESS_COMPRESS && O.compresses_to) //Compressing.
var/can_make = Clamp(ores_stored[metal],0,sheets_per_tick-sheets)
if(can_make%2>0) can_make--
@@ -222,7 +224,7 @@
sheets+=2
new M.stack_type(output.loc)
else if(ores_processing[metal] == 1 && O.smelts_to) //Smelting.
else if(ores_processing[metal] == PROCESS_SMELT && O.smelts_to) //Smelting.
var/can_make = Clamp(ores_stored[metal],0,sheets_per_tick-sheets)
@@ -242,3 +244,8 @@
continue
console.updateUsrDialog()
#undef PROCESS_NONE
#undef PROCESS_SMELT
#undef PROCESS_COMPRESS
#undef PROCESS_ALLOY