Republish - Machinery processing refactor (#49307)

* initial

small thing

* improvements

1. Removes loops for picking up items. its now an item by item basis unless there is an ore box involved
2. Removed pickup_rate and ore_buffer var for the ORM, they aren't needed anymore
3. Fixed conveyors not moving items that get created on top of them (New / Initialize), by sending signals when atoms are created.

* renames the registered signal proc name so travis doesn't throw a fit

* signal improvement

* forgot to update other proc names

* ninjanomnom review changes

replace NEVER_PROCESS with START_PROCESSING_MANUALLY

default_unfasten_wrench override for ORM

50 -> 5 SECONDS

I totally didn't mispell anything

* makes a new signal: COMSIG_ATOM_CREATED

* more review changes

* duh

* even more review improvements

* switch >= to >

* reverts conveyors back to using process() for moving stuff

* various touch ups, adds documentation

* rebase to fix map conflicts with forgottenship.dmm

Co-authored-by: SteelSlayer <SteelSlayer@users.noreply.github.com>
This commit is contained in:
SteelSlayer
2020-03-31 01:52:25 -03:00
committed by GitHub
co-authored by SteelSlayer
parent 7afbda1500
commit b391baeb74
12 changed files with 167 additions and 108 deletions
+47 -6
View File
@@ -3,9 +3,47 @@
/**********************Mineral processing unit console**************************/
/obj/machinery/mineral
processing_flags = START_PROCESSING_MANUALLY
subsystem_type = /datum/controller/subsystem/processing/fastprocess
/// The current direction of `input_turf`, in relation to the machine.
var/input_dir = NORTH
/// The current direction, in relation to the machine, that items will be output to.
var/output_dir = SOUTH
/// The turf the machines listens to for items to pick up. Calls the `pickup_item()` proc.
var/turf/input_turf = null
/// Determines if this machine needs to pick up items. Used to avoid registering signals to `/mineral` machines that don't pickup items.
var/needs_item_input = FALSE
/obj/machinery/mineral/Initialize(mapload)
. = ..()
if(needs_item_input)
register_input_turf()
/// Gets the turf in the `input_dir` direction adjacent to the machine, and registers signals for ATOM_ENTERED and ATOM_CREATED. Calls the `pickup_item()` proc when it recieves these signals.
/obj/machinery/mineral/proc/register_input_turf()
input_turf = get_step(src, input_dir)
if(input_turf) // make sure there is actually a turf
RegisterSignal(input_turf, list(COMSIG_ATOM_CREATED, COMSIG_ATOM_ENTERED), .proc/pickup_item)
/// Unregisters signals that are registered the machine's input turf, if it has one.
/obj/machinery/mineral/proc/unregister_input_turf()
if(input_turf)
UnregisterSignal(input_turf, list(COMSIG_ATOM_ENTERED, COMSIG_ATOM_CREATED))
/**
Base proc for all `/mineral` subtype machines to use. Place your item pickup behavior in this proc when you override it for your specific machine.
Called when the COMSIG_ATOM_ENTERED and COMSIG_ATOM_CREATED signals are sent.
Arguments:
* source - the turf that is listening for the signals.
* target - the atom that just moved onto the `source` turf.
* oldLoc - the old location that `target` was at before moving onto `source`.
*/
/obj/machinery/mineral/proc/pickup_item(datum/source, atom/movable/target, atom/oldLoc)
return
/// Generic unloading proc. Takes an atom as an argument and forceMove's it to the turf adjacent to this machine in the `output_dir` direction.
/obj/machinery/mineral/proc/unload_mineral(atom/movable/S)
S.forceMove(drop_location())
var/turf/T = get_step(src,output_dir)
@@ -19,7 +57,6 @@
density = TRUE
var/obj/machinery/mineral/processing_unit/machine = null
var/machinedir = EAST
speed_process = TRUE
/obj/machinery/mineral/processing_unit_console/Initialize()
. = ..()
@@ -58,6 +95,7 @@
if(href_list["set_on"])
machine.on = (href_list["set_on"] == "on")
machine.begin_processing()
updateUsrDialog()
return
@@ -75,6 +113,7 @@
icon = 'icons/obj/machines/mining_machines.dmi'
icon_state = "furnace"
density = TRUE
needs_item_input = TRUE
var/obj/machinery/mineral/CONSOLE = null
var/on = FALSE
var/datum/material/selected_material = null
@@ -93,10 +132,6 @@
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)
@@ -142,8 +177,12 @@
return dat
/obj/machinery/mineral/processing_unit/pickup_item(datum/source, atom/movable/target, atom/oldLoc)
if(istype(target, /obj/item/stack/ore))
process_ore(target)
/obj/machinery/mineral/processing_unit/process()
if (on)
if(on)
if(selected_material)
smelt_ore()
@@ -153,6 +192,8 @@
if(CONSOLE)
CONSOLE.updateUsrDialog()
else
end_processing()
/obj/machinery/mineral/processing_unit/proc/smelt_ore()
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
+29 -32
View File
@@ -10,19 +10,19 @@
input_dir = NORTH
output_dir = SOUTH
req_access = list(ACCESS_MINERAL_STOREROOM)
speed_process = TRUE
layer = BELOW_OBJ_LAYER
circuit = /obj/item/circuitboard/machine/ore_redemption
ui_x = 440
ui_y = 550
needs_item_input = TRUE
processing_flags = START_PROCESSING_MANUALLY
var/points = 0
var/ore_pickup_rate = 15
var/ore_multiplier = 1
var/point_upgrade = 1
var/list/ore_values = list(/datum/material/iron = 1, /datum/material/glass = 1, /datum/material/plasma = 15, /datum/material/silver = 16, /datum/material/gold = 18, /datum/material/titanium = 30, /datum/material/uranium = 30, /datum/material/diamond = 50, /datum/material/bluespace = 50, /datum/material/bananium = 60)
var/message_sent = FALSE
var/list/ore_buffer = list()
/// Variable that holds a timer which is used for callbacks to `send_console_message()`. Used for preventing multiple calls to this proc while the ORM is eating a stack of ores.
var/console_notify_timer
var/datum/techweb/stored_research
var/obj/item/disk/design_disk/inserted_disk
var/datum/component/remote_materials/materials
@@ -38,23 +38,19 @@
return ..()
/obj/machinery/mineral/ore_redemption/RefreshParts()
var/ore_pickup_rate_temp = 15
var/point_upgrade_temp = 1
var/ore_multiplier_temp = 1
for(var/obj/item/stock_parts/matter_bin/B in component_parts)
ore_multiplier_temp = 0.65 + (0.35 * B.rating)
for(var/obj/item/stock_parts/manipulator/M in component_parts)
ore_pickup_rate_temp = 15 * M.rating
for(var/obj/item/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
ore_multiplier = round(ore_multiplier_temp, 0.01)
/obj/machinery/mineral/ore_redemption/examine(mob/user)
. = ..()
if(in_range(user, src) || isobserver(user))
. += "<span class='notice'>The status display reads: Smelting <b>[ore_multiplier]</b> sheet(s) per piece of ore.<br>Reward point generation at <b>[point_upgrade*100]%</b>.<br>Ore pickup speed at <b>[ore_pickup_rate]</b>.</span>"
. += "<span class='notice'>The status display reads: Smelting <b>[ore_multiplier]</b> sheet(s) per piece of ore.<br>Reward point generation at <b>[point_upgrade*100]%</b>.</span>"
if(panel_open)
. += "<span class='notice'>Alt-click to rotate the input and output direction.</span>"
@@ -66,8 +62,6 @@
if(O.refined_type == null)
return
ore_buffer -= O
if(O && O.refined_type)
points += O.points * point_upgrade * O.amount
@@ -113,17 +107,15 @@
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()
var/datum/component/material_container/mat_container = materials.mat_container
if(!mat_container || !is_station_level(z))
return
message_sent = TRUE
console_notify_timer = null
var/area/A = get_area(src)
var/msg = "Now available in [A]:<br>"
@@ -149,26 +141,29 @@
))
signal.send_to_receivers()
/obj/machinery/mineral/ore_redemption/process()
/obj/machinery/mineral/ore_redemption/pickup_item(datum/source, atom/movable/target, atom/oldLoc)
if(!materials.mat_container || 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/stack/ore/O in input)
if(QDELETED(O))
continue
ore_buffer |= O
O.forceMove(src)
CHECK_TICK
if(istype(target, /obj/structure/ore_box))
var/obj/structure/ore_box/box = target
process_ores(box.contents)
else if(istype(target, /obj/item/stack/ore))
var/obj/item/stack/ore/O = target
smelt_ore(O)
else
return
if(LAZYLEN(ore_buffer))
message_sent = FALSE
process_ores(ore_buffer)
else if(!message_sent)
send_console_message()
if(!console_notify_timer)
// gives 5 seconds for a load of ores to be sucked up by the ORM before it sends out request console notifications. This should be enough time for most deposits that people make
console_notify_timer = addtimer(CALLBACK(src, .proc/send_console_message), 5 SECONDS)
/obj/machinery/mineral/ore_redemption/default_unfasten_wrench(mob/user, obj/item/I)
. = ..()
if(anchored)
register_input_turf() // someone just wrenched us down, re-register the turf
else
unregister_input_turf() // someone just un-wrenched us, unregister the turf
/obj/machinery/mineral/ore_redemption/attackby(obj/item/W, mob/user, params)
if(default_unfasten_wrench(user, W))
@@ -199,10 +194,12 @@
. = ..()
if(!user.canUseTopic(src, BE_CLOSE))
return
if (panel_open)
if(panel_open)
input_dir = turn(input_dir, -90)
output_dir = turn(output_dir, -90)
to_chat(user, "<span class='notice'>You change [src]'s I/O settings, setting the input to [dir2text(input_dir)] and the output to [dir2text(output_dir)].</span>")
unregister_input_turf() // someone just rotated the input and output directions, unregister the old turf
register_input_turf() // register the new one
return TRUE
/obj/machinery/mineral/ore_redemption/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.default_state)
+10 -20
View File
@@ -8,24 +8,14 @@
density = TRUE
input_dir = WEST
output_dir = EAST
speed_process = TRUE
needs_item_input = TRUE
processing_flags = START_PROCESSING_MANUALLY
/obj/machinery/mineral/unloading_machine/process()
var/turf/T = get_step(src,input_dir)
if(T)
var/limit
for(var/obj/structure/ore_box/B in T)
for (var/obj/item/stack/ore/O in B)
B.contents -= O
unload_mineral(O)
limit++
if (limit>=10)
return
CHECK_TICK
CHECK_TICK
for(var/obj/item/I in T)
unload_mineral(I)
limit++
if (limit>=10)
return
CHECK_TICK
/obj/machinery/mineral/unloading_machine/pickup_item(datum/source, atom/movable/target, atom/oldLoc)
if(istype(target, /obj/structure/ore_box))
var/obj/structure/ore_box/box = target
for(var/obj/item/stack/ore/O in box)
unload_mineral(O)
else if(istype(target, /obj/item/stack/ore))
var/obj/item/stack/ore/O = target
unload_mineral(O)
+13 -6
View File
@@ -9,6 +9,7 @@
input_dir = EAST
ui_x = 300
ui_y = 250
needs_item_input = TRUE
var/produced_coins = 0 // how many coins the machine has made in it's last cycle
var/processing = FALSE
@@ -34,16 +35,19 @@
chosen = SSmaterials.GetMaterialRef(chosen)
/obj/machinery/mineral/mint/process()
var/turf/T = get_step(src, input_dir)
/obj/machinery/mineral/mint/pickup_item(datum/source, atom/movable/target, atom/oldLoc)
if(!istype(target, /obj/item/stack))
return
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
var/obj/item/stack/S = target
for(var/obj/item/stack/O in T)
var/inserted = materials.insert_item(O)
if(inserted)
qdel(O)
if(materials.insert_item(S))
qdel(S)
/obj/machinery/mineral/mint/process()
if(processing)
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
var/datum/material/M = chosen
if(!M)
@@ -71,6 +75,7 @@
if(!found_new)
processing = FALSE
else
end_processing()
icon_state = "coinpress0"
/obj/machinery/mineral/mint/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, \
@@ -114,8 +119,10 @@
if (!processing)
produced_coins = 0
processing = TRUE
begin_processing()
if ("stoppress")
processing = FALSE
end_processing()
if ("changematerial")
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
for(var/datum/material/mat in materials.materials)