mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-28 15:47:15 +01:00
[MIRROR] General code maintenance for Mat container related stuff [MDB IGNORE] (#23251)
* General code maintenance for Mat container related stuff (#77671) 1. Removes `/obj/machinery/ore_silo/proc/remote_attackby()`. This proc calls `datum/component/material_container/user_insert()` anyway which performs all the checks necessary for inserting stuff into the ore silo and `/obj/machinery/ore_silo/proc/remote_attackby()` was just repeating its code & checks. So now inserting into the ore silo is directly handled by the mat container without this proxy proc making the operation slightly faster 2. Removed silo `attackby` code. Same operations can be done via `screwdriver_act` & `crowbar_act` procs much cleaner 3. The ore silo now hooks onto signals `COMSIG_MATCONTAINER_ITEM_CONSUMED` and `COMSIG_MATCONTAINER_SHEETS_RETRIVED` and logs into silo when they are triggered. This means when you insert/eject sheets from the silo the connected machine performing the operation no longer has to do the logging manually thus the proc `silo_log` has been removed from a lot of places ,reducing overall code size 4. A lot of stuff that use materials from the ore silo follow this pattern. i.e. They first use the materials from the silo and then log it via `silo_log` proc. This code pattern is repeated in a lot of places so let's just merge these 2 lines with some extra sanity checks into a single proc inside `remote_materials` itself. That's what was done and the number of places where you log manually into the silo has been removed further reducing code size everywhere. 5. Added auto doc & cleaned up some procs Since logging is now done by the ore silo directly, we need a way to pass the machine that is inserting items into the silo to the signal handlers of the ore silo [via the `context` var]. So other code changes elsewhere is because of this var * General code maintenance for Mat container related stuff --------- Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
This commit is contained in:
@@ -88,16 +88,12 @@
|
||||
unload_mineral(gathered_ore)
|
||||
|
||||
else
|
||||
var/list/stack_mats = gathered_ore.get_material_composition(BREAKDOWN_FLAGS_ORM)
|
||||
var/mats = stack_mats & mat_container.materials
|
||||
var/ore_amount = gathered_ore.amount
|
||||
var/ore_points= gathered_ore.points
|
||||
var/ore_name = gathered_ore.name
|
||||
var/refined_type = gathered_ore?.refined_type
|
||||
if(mat_container.insert_item(gathered_ore, ore_multiplier, breakdown_flags = BREAKDOWN_FLAGS_ORM) > 0) //increase points only if insertion was successfull
|
||||
if(mat_container.insert_item(gathered_ore, ore_multiplier, breakdown_flags = BREAKDOWN_FLAGS_ORM, context = src) > 0) //increase points only if insertion was successfull
|
||||
if(refined_type)
|
||||
points += ore_points * point_upgrade * ore_amount
|
||||
materials.silo_log(src, "smelted", ore_amount, ore_name, mats)
|
||||
|
||||
SEND_SIGNAL(src, COMSIG_ORM_COLLECTED_ORE)
|
||||
|
||||
@@ -356,12 +352,7 @@
|
||||
|
||||
var/desired = text2num(params["sheets"])
|
||||
var/sheets_to_remove = round(min(desired, 50, stored_amount))
|
||||
|
||||
var/count = mat_container.retrieve_sheets(sheets_to_remove, mat, get_step(src, output_dir))
|
||||
var/list/mats = list()
|
||||
mats[mat] = SHEET_MATERIAL_AMOUNT
|
||||
materials.silo_log(src, "released", -count, "sheets", mats)
|
||||
//Logging deleted for quick coding
|
||||
materials.eject_sheets(mat, sheets_to_remove, get_step(src, output_dir))
|
||||
return TRUE
|
||||
if("Smelt")
|
||||
if(!mat_container)
|
||||
@@ -379,8 +370,7 @@
|
||||
var/amount = round(min(text2num(params["sheets"]), 50, can_smelt_alloy(alloy)))
|
||||
if(amount < 1) //no negative mats
|
||||
return
|
||||
mat_container.use_materials(alloy.materials, multiplier = amount)
|
||||
materials.silo_log(src, "released", -amount, "sheets", alloy.materials)
|
||||
materials.use_materials(alloy.materials, action = "released", name = "sheets")
|
||||
var/output
|
||||
if(ispath(alloy.build_path, /obj/item/stack/sheet))
|
||||
output = new alloy.build_path(src, amount)
|
||||
|
||||
@@ -37,7 +37,10 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
|
||||
/datum/component/material_container, \
|
||||
materials_list, \
|
||||
INFINITY, \
|
||||
MATCONTAINER_NO_INSERT, \
|
||||
container_signals = list( \
|
||||
COMSIG_MATCONTAINER_ITEM_CONSUMED = TYPE_PROC_REF(/obj/machinery/ore_silo, log_item_consumed), \
|
||||
COMSIG_MATCONTAINER_SHEETS_RETRIVED = TYPE_PROC_REF(/obj/machinery/ore_silo, log_sheets_ejected), \
|
||||
), \
|
||||
allowed_items = /obj/item/stack \
|
||||
)
|
||||
if (!GLOB.ore_silo_default && mapload && is_station_level(z))
|
||||
@@ -55,39 +58,21 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
|
||||
|
||||
return ..()
|
||||
|
||||
/obj/machinery/ore_silo/proc/remote_attackby(obj/machinery/M, mob/living/user, obj/item/stack/I, breakdown_flags=NONE)
|
||||
if(user.combat_mode)
|
||||
return
|
||||
if(I.item_flags & ABSTRACT)
|
||||
return
|
||||
if(!istype(I) || (I.flags_1 & HOLOGRAM_1) || (I.item_flags & NO_MAT_REDEMPTION))
|
||||
to_chat(user, span_warning("[M] won't accept [I]!"))
|
||||
return
|
||||
var/item_mats = materials.get_item_material_amount(I, breakdown_flags)
|
||||
if(!item_mats)
|
||||
to_chat(user, span_warning("[I] does not contain sufficient materials to be accepted by [M]."))
|
||||
return
|
||||
// assumes unlimited space...
|
||||
var/amount = I.amount
|
||||
materials.user_insert(I, user, breakdown_flags)
|
||||
var/list/matlist = I.get_material_composition(breakdown_flags)
|
||||
silo_log(M, "deposited", amount, I.name, matlist)
|
||||
return TRUE
|
||||
/obj/machinery/ore_silo/proc/log_item_consumed(datum/component/material_container/container, obj/item/item_inserted, last_inserted_id, mats_consumed, amount_inserted, atom/context)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
/obj/machinery/ore_silo/attackby(obj/item/W, mob/user, params)
|
||||
if(default_deconstruction_screwdriver(user, icon_state, icon_state, W))
|
||||
updateUsrDialog()
|
||||
return
|
||||
if(default_deconstruction_crowbar(W))
|
||||
return
|
||||
silo_log(context, "deposited", amount_inserted, item_inserted.name, mats_consumed)
|
||||
|
||||
if(!powered())
|
||||
return ..()
|
||||
/obj/machinery/ore_silo/proc/log_sheets_ejected(datum/component/material_container/container, obj/item/stack/sheet/sheets, atom/context)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if (isstack(W))
|
||||
return remote_attackby(src, user, W)
|
||||
silo_log(context, "ejected", -sheets.amount, "[sheets.singular_name]", sheets.custom_materials)
|
||||
|
||||
return ..()
|
||||
/obj/machinery/ore_silo/screwdriver_act(mob/living/user, obj/item/tool)
|
||||
return default_deconstruction_screwdriver(user, icon_state, icon_state, tool)
|
||||
|
||||
/obj/machinery/ore_silo/crowbar_act(mob/living/user, obj/item/tool)
|
||||
return default_deconstruction_crowbar(tool)
|
||||
|
||||
/obj/machinery/ore_silo/ui_interact(mob/user)
|
||||
user.set_machine(src)
|
||||
@@ -169,10 +154,8 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
|
||||
return TRUE
|
||||
else if(href_list["ejectsheet"])
|
||||
var/datum/material/eject_sheet = locate(href_list["ejectsheet"])
|
||||
var/count = materials.retrieve_sheets(text2num(href_list["eject_amt"]), eject_sheet, drop_location())
|
||||
var/list/matlist = list()
|
||||
matlist[eject_sheet] = SHEET_MATERIAL_AMOUNT * count
|
||||
silo_log(src, "ejected", -count, "sheets", matlist)
|
||||
var/amount = text2num(href_list["eject_amt"])
|
||||
materials.retrieve_sheets(amount, eject_sheet, drop_location())
|
||||
return TRUE
|
||||
else if(href_list["page"])
|
||||
log_page = text2num(href_list["page"]) || 1
|
||||
|
||||
@@ -145,8 +145,7 @@
|
||||
if(materials.silo && !materials.on_hold())
|
||||
var/matlist = inp.custom_materials & materials.mat_container.materials
|
||||
if (length(matlist))
|
||||
var/inserted = materials.mat_container.insert_item(inp)
|
||||
materials.silo_log(src, "collected", inserted, "sheets", matlist)
|
||||
materials.mat_container.insert_item(inp, context = src)
|
||||
return
|
||||
|
||||
// No silo attached process to internal storage
|
||||
|
||||
Reference in New Issue
Block a user