Updates minter to tg and the prereqs

This commit is contained in:
Artur
2020-07-14 18:08:12 +03:00
parent d0f1a805e4
commit f5ee74803f
5 changed files with 113 additions and 42 deletions

View File

@@ -32,6 +32,8 @@
#define COMSIG_ELEMENT_DETACH "element_detach"
// /atom signals
//from base of atom/proc/Initialize(): sent any time a new atom is created
#define COMSIG_ATOM_CREATED "atom_created"
#define COMSIG_PARENT_ATTACKBY "atom_attackby" //from base of atom/attackby(): (/obj/item, /mob/living, params)
#define COMPONENT_NO_AFTERATTACK 1 //Return this in response if you don't want afterattack to be called
#define COMSIG_ATOM_HULK_ATTACK "hulk_attack" //from base of atom/attack_hulk(): (/mob/living/carbon/human)

View File

@@ -101,6 +101,8 @@
stack_trace("Warning: [src]([type]) initialized multiple times!")
flags_1 |= INITIALIZED_1
if(loc)
SEND_SIGNAL(loc, COMSIG_ATOM_CREATED, src) /// Sends a signal that the new atom `src`, has been created at `loc`
//atom color stuff
if(color)
add_atom_colour(color, FIXED_COLOUR_PRIORITY)

View File

@@ -121,7 +121,7 @@ Class Procs:
var/ui_style // ID of custom TGUI style (optional)
var/ui_x
var/ui_y
var/init_process = TRUE //Stop processing from starting on init
var/interaction_flags_machine = INTERACT_MACHINE_WIRES_IF_OPEN | INTERACT_MACHINE_ALLOW_SILICON | INTERACT_MACHINE_OPEN_SILICON | INTERACT_MACHINE_SET_MACHINE
var/fair_market_price = 69
@@ -138,7 +138,7 @@ Class Procs:
circuit = new circuit
circuit.apply_default_parts(src)
if(!speed_process)
if(!speed_process && init_process)
START_PROCESSING(SSmachines, src)
else
START_PROCESSING(SSfastprocess, src)

View File

@@ -3,10 +3,54 @@
/**********************Mineral processing unit console**************************/
/obj/machinery/mineral
speed_process = TRUE
init_process = FALSE
/// 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
var/needs_item_input
/// 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 && anchored)
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 receives 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))
/obj/machinery/mineral/Moved()
. = ..()
if(!needs_item_input || !anchored)
return
unregister_input_turf()
register_input_turf()
/**
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)
@@ -20,7 +64,6 @@
density = TRUE
var/obj/machinery/mineral/processing_unit/machine = null
var/machinedir = EAST
speed_process = TRUE
/obj/machinery/mineral/processing_unit_console/Initialize()
. = ..()
@@ -59,6 +102,7 @@
if(href_list["set_on"])
machine.on = (href_list["set_on"] == "on")
START_PROCESSING(SSmachines, machine)
updateUsrDialog()
return
@@ -76,6 +120,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
@@ -94,11 +139,10 @@
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)
if(QDELETED(O))
return
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))
@@ -143,8 +187,14 @@
return dat
/obj/machinery/mineral/processing_unit/pickup_item(datum/source, atom/movable/target, atom/oldLoc)
if(QDELETED(target))
return
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()
@@ -154,6 +204,8 @@
if(CONSOLE)
CONSOLE.updateUsrDialog()
else
STOP_PROCESSING(SSmachines, src)
/obj/machinery/mineral/processing_unit/proc/smelt_ore()
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)

View File

@@ -9,7 +9,8 @@
input_dir = EAST
ui_x = 300
ui_y = 250
needs_item_input = TRUE
var/obj/item/storage/bag/money/bag_to_use
var/produced_coins = 0 // how many coins the machine has made in it's last cycle
var/processing = FALSE
var/chosen = /datum/material/iron //which material will be used to make coins
@@ -34,16 +35,21 @@
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(QDELETED(target))
return
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)
@@ -59,6 +65,7 @@
for(var/coin_to_make in 1 to 5)
create_coins()
produced_coins++
CHECK_TICK
else
var/found_new = FALSE
for(var/datum/material/inserted_material in materials.materials)
@@ -71,30 +78,30 @@
if(!found_new)
processing = FALSE
else
STOP_PROCESSING(SSmachines, src)
icon_state = "coinpress0"
/obj/machinery/mineral/mint/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)
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
ui = new(user, src, ui_key, "mint", name, ui_x, ui_y, master_ui, state)
ui = new(user, src, ui_key, "Mint", name, ui_x, ui_y, master_ui, state)
ui.open()
/obj/machinery/mineral/mint/ui_data()
var/list/data = list()
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
data["inserted_materials"] = list()
data["chosen_material"] = null
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
for(var/datum/material/inserted_material in materials.materials)
var/amount = materials.get_material_amount(inserted_material)
if(!amount)
continue
data["inserted_materials"] += list(list(
"material" = inserted_material.name,
"amount" = amount
"amount" = amount,
))
if(chosen == inserted_material)
data["chosen_material"] = inserted_material.name
@@ -104,18 +111,25 @@
return data;
/obj/machinery/mineral/mint/ui_act(action, params, datum/tgui/ui)
switch(action)
if ("startpress")
if (!processing)
produced_coins = 0
processing = TRUE
if ("stoppress")
processing = FALSE
if ("changematerial")
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
for(var/datum/material/mat in materials.materials)
if (params["material_name"] == mat.name)
chosen = mat
. = ..()
if(.)
return
if(action == "startpress")
if (!processing)
produced_coins = 0
processing = TRUE
START_PROCESSING(SSmachines, src)
return TRUE
if (action == "stoppress")
processing = FALSE
STOP_PROCESSING(SSmachines, src)
return TRUE
if (action == "changematerial")
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
for(var/datum/material/mat in materials.materials)
if (params["material_name"] == mat.name)
chosen = mat
return TRUE
/obj/machinery/mineral/mint/proc/create_coins()
var/turf/T = get_step(src,output_dir)
@@ -123,9 +137,10 @@
temp_list[chosen] = 400
if(T)
var/obj/item/O = new /obj/item/coin(src)
var/obj/item/storage/bag/money/B = locate(/obj/item/storage/bag/money, T)
O.set_custom_materials(temp_list)
if(!B)
B = new /obj/item/storage/bag/money(src)
unload_mineral(B)
O.forceMove(B)
if(QDELETED(bag_to_use) || (bag_to_use.loc != T) || !SEND_SIGNAL(bag_to_use, COMSIG_TRY_STORAGE_INSERT, O, null, TRUE)) //important to send the signal so we don't overfill the bag.
bag_to_use = new(src) //make a new bag if we can't find or use the old one.
unload_mineral(bag_to_use) //just forcemove memes.
O.forceMove(bag_to_use) //don't bother sending the signal, the new bag is empty and all that.
SSblackbox.record_feedback("amount", "coins_minted", 1)