mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-23 21:18:37 +01:00
[MIRROR] [NO GBP]Mat container Final clean-up & patches [MDB IGNORE] (#22765)
* [NO GBP]Mat container Final clean-up & patches (#77092) ## About The Pull Request 1. Fixes #77177 Some things were not connecting to the ore silo round start because the silo was not initialized yet so it went to local storage. Now it connects with the ore silo again 3. Removed some unused code in remote materials 4. Protolathe uses `eject_sheets()` defined in remote materials and not it's own version because that's redundant 5. Don't put the item back in the players hand when inserting it in the material container cause we haven't even removed it yet 6. `fast_split()` is now even faster & robust and is a global proc 7. Some code cleanup for RHD silo link ## Changelog 🆑 fix: some things not connecting to the ore silo round start /🆑 * [NO GBP]Mat container Final clean-up & patches --------- Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
This commit is contained in:
committed by
nevimer
co-authored by
SyncIt21
parent
0f45698515
commit
f46a300a93
@@ -37,15 +37,11 @@
|
||||
* Has special internal uses for e.g. by the material container
|
||||
*
|
||||
* Arguments:
|
||||
* - [target][obj/item]: the stack to splot
|
||||
* - [target][obj/item/stack]: the stack to split
|
||||
* - [amount]: amount to split by
|
||||
*/
|
||||
/datum/component/material_container/proc/fast_split_stack(obj/item/stack/target, amount)
|
||||
/proc/fast_split_stack(obj/item/stack/target, amount)
|
||||
if(!target.use(amount, TRUE, FALSE))
|
||||
return null
|
||||
|
||||
. = new target.type(target.drop_location(), amount, FALSE, target.mats_per_unit)
|
||||
target.loc.atom_storage?.refresh_views()
|
||||
|
||||
target.is_zero_amount(delete_if_zero = TRUE)
|
||||
|
||||
|
||||
@@ -286,16 +286,12 @@
|
||||
|
||||
//not a solid subtype or an hologram
|
||||
if((target.item_flags & ABSTRACT) || (target.flags_1 & HOLOGRAM_1))
|
||||
if(target == active_held) //was this the original item in the players hand? put it back because we coudn't salvage it
|
||||
user.put_in_active_hand(target)
|
||||
continue
|
||||
|
||||
//item is either not allowed for redemption, not in the allowed types
|
||||
if((target.item_flags & NO_MAT_REDEMPTION) || (allowed_item_typecache && !is_type_in_typecache(target, allowed_item_typecache)))
|
||||
if(!(mat_container_flags & MATCONTAINER_SILENT))
|
||||
to_chat(user, span_warning("[parent] won't accept [target]!"))
|
||||
if(target == active_held) //was this the original item in the players hand? put it back because we coudn't salvage it
|
||||
user.put_in_active_hand(target)
|
||||
continue
|
||||
|
||||
//untouchable, move it out the way, code copied from recycler
|
||||
|
||||
@@ -11,19 +11,24 @@ handles linking back and forth.
|
||||
// 2. silo is null, materials is parented to parent
|
||||
// 3. silo is null, materials is null
|
||||
|
||||
/// The silo machine this container is connected to
|
||||
///The silo machine this container is connected to
|
||||
var/obj/machinery/ore_silo/silo
|
||||
//material container. the value is either the silo or local
|
||||
///Material container. the value is either the silo or local
|
||||
var/datum/component/material_container/mat_container
|
||||
//should we create a local storage if we can't connect to silo
|
||||
///Should we create a local storage if we can't connect to silo
|
||||
var/allow_standalone
|
||||
//are we trying to connect to the silo
|
||||
var/connecting
|
||||
//local size of container when silo = null
|
||||
///Local size of container when silo = null
|
||||
var/local_size = INFINITY
|
||||
///Flags used when converting inserted materials into their component materials.
|
||||
var/mat_container_flags = NONE
|
||||
|
||||
//Internal vars
|
||||
|
||||
///Prepare storage when component is registered to parent. This allows local material container(if created) to be first in the component list so it gets GC'd properly
|
||||
var/_prepare_on_register = FALSE
|
||||
///Are we trying to to connect to remote ore silo or not
|
||||
var/_connect_to_silo = FALSE
|
||||
|
||||
/datum/component/remote_materials/Initialize(mapload, allow_standalone = TRUE, force_connect = FALSE, mat_container_flags = NONE)
|
||||
if (!isatom(parent))
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
@@ -35,16 +40,25 @@ handles linking back and forth.
|
||||
RegisterSignal(parent, COMSIG_ATOM_TOOL_ACT(TOOL_MULTITOOL), PROC_REF(OnMultitool))
|
||||
|
||||
var/turf/T = get_turf(parent)
|
||||
_connect_to_silo = FALSE
|
||||
if(force_connect || (mapload && is_station_level(T.z)))
|
||||
connecting = TRUE
|
||||
_connect_to_silo = TRUE
|
||||
|
||||
if(mapload) // wait for silo to initialize during mapload
|
||||
addtimer(CALLBACK(src, PROC_REF(_PrepareStorage), _connect_to_silo))
|
||||
else //directly register in round
|
||||
_prepare_on_register = TRUE
|
||||
|
||||
/datum/component/remote_materials/RegisterWithParent()
|
||||
if (connecting)
|
||||
if(_prepare_on_register)
|
||||
_PrepareStorage(_connect_to_silo)
|
||||
|
||||
/datum/component/remote_materials/proc/_PrepareStorage(connect_to_silo)
|
||||
if (connect_to_silo)
|
||||
silo = GLOB.ore_silo_default
|
||||
if (silo)
|
||||
silo.ore_connected_machines += src
|
||||
mat_container = silo.GetComponent(/datum/component/material_container)
|
||||
connecting = FALSE
|
||||
if (!mat_container && allow_standalone)
|
||||
_MakeLocal()
|
||||
|
||||
@@ -163,24 +177,25 @@ handles linking back and forth.
|
||||
if (silo)
|
||||
silo.silo_log(M || parent, action, amount, noun, mats)
|
||||
|
||||
/datum/component/remote_materials/proc/format_amount()
|
||||
if (mat_container)
|
||||
return "[mat_container.total_amount()] / [mat_container.max_amount == INFINITY ? "Unlimited" : mat_container.max_amount] ([silo ? "remote" : "local"])"
|
||||
else
|
||||
return "0 / 0"
|
||||
|
||||
/// Ejects the given material ref and logs it, or says out loud the problem.
|
||||
/datum/component/remote_materials/proc/eject_sheets(datum/material/material_ref, eject_amount)
|
||||
var/atom/movable/movable_parent = parent
|
||||
if (!istype(movable_parent))
|
||||
return 0
|
||||
|
||||
if (!mat_container)
|
||||
if (!mat_container) //no silolink & local storage not supported
|
||||
movable_parent.say("No access to material storage, please contact the quartermaster.")
|
||||
return 0
|
||||
if (on_hold())
|
||||
if(!mat_container.can_hold_material(material_ref)) //material not supported by container
|
||||
movable_parent.say("Invalid material requested.")
|
||||
return 0
|
||||
if(eject_amount <= 0) //invalid amount
|
||||
movable_parent.say("Invalid amount requested.")
|
||||
return 0
|
||||
if(on_hold()) //silo on hold
|
||||
movable_parent.say("Mineral access is on hold, please contact the quartermaster.")
|
||||
return 0
|
||||
|
||||
var/count = mat_container.retrieve_sheets(eject_amount, material_ref, movable_parent.drop_location())
|
||||
var/list/matlist = list()
|
||||
matlist[material_ref] = eject_amount
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
/obj/item/construction/proc/get_silo_iron()
|
||||
if(silo_link && silo_mats.mat_container && !silo_mats.on_hold())
|
||||
return silo_mats.mat_container.get_material_amount(/datum/material/iron) / SILO_USE_AMOUNT
|
||||
return FALSE
|
||||
return 0
|
||||
|
||||
///returns local matter units available. overriden by rcd borg to return power units available
|
||||
/obj/item/construction/proc/get_matter(mob/user)
|
||||
@@ -176,15 +176,15 @@
|
||||
if(user)
|
||||
balloon_alert(user, "no silo detected!")
|
||||
return FALSE
|
||||
if(!silo_mats.mat_container.has_materials(list(/datum/material/iron = SILO_USE_AMOUNT), multiplier = amount))
|
||||
|
||||
if(!silo_mats.mat_container.has_enough_of_material(/datum/material/iron, amount * SILO_USE_AMOUNT))
|
||||
if(user)
|
||||
balloon_alert(user, "not enough silo material!")
|
||||
return FALSE
|
||||
|
||||
var/list/materials = list()
|
||||
materials[GET_MATERIAL_REF(/datum/material/iron)] = SILO_USE_AMOUNT
|
||||
silo_mats.mat_container.use_materials(materials, multiplier = amount)
|
||||
silo_mats.silo_log(src, "consume", -amount, "build", materials)
|
||||
silo_mats.mat_container.use_amount_mat(amount * SILO_USE_AMOUNT, /datum/material/iron)
|
||||
var/static/list/mats = list(GET_MATERIAL_REF(/datum/material/iron) = SILO_USE_AMOUNT)
|
||||
silo_mats.silo_log(src, "consume", -amount, "build", mats)
|
||||
return TRUE
|
||||
|
||||
///shared data for rcd,rld & plumbing
|
||||
@@ -238,7 +238,7 @@
|
||||
if(user)
|
||||
balloon_alert(user, "silo on hold!")
|
||||
return FALSE
|
||||
. = silo_mats.mat_container.has_materials(list(/datum/material/iron = SILO_USE_AMOUNT), multiplier = amount)
|
||||
. = silo_mats.mat_container.has_enough_of_material(/datum/material/iron, amount * SILO_USE_AMOUNT)
|
||||
if(!. && user)
|
||||
balloon_alert(user, "low ammo!")
|
||||
if(has_ammobar)
|
||||
|
||||
@@ -174,13 +174,9 @@
|
||||
switch (action)
|
||||
if("remove_mat")
|
||||
var/datum/material/material = locate(params["ref"])
|
||||
|
||||
if(!materials.mat_container.can_hold_material(material))
|
||||
// I don't know who you are or what you want, but whatever it is,
|
||||
// we don't have it.
|
||||
return
|
||||
|
||||
eject_sheets(material, params["amount"])
|
||||
var/amount = text2num(params["amount"])
|
||||
// SAFETY: eject_sheets checks for valid mats
|
||||
materials.eject_sheets(material, amount)
|
||||
|
||||
if("build")
|
||||
user_try_print_id(params["ref"], params["amount"])
|
||||
@@ -323,26 +319,6 @@
|
||||
|
||||
return TRUE
|
||||
|
||||
/obj/machinery/rnd/production/proc/eject_sheets(eject_sheet, eject_amt)
|
||||
var/datum/component/material_container/mat_container = materials.mat_container
|
||||
|
||||
if(!mat_container)
|
||||
say("No access to material storage, please contact the quartermaster.")
|
||||
return 0
|
||||
|
||||
if(materials.on_hold())
|
||||
say("Mineral access is on hold, please contact the quartermaster.")
|
||||
return 0
|
||||
|
||||
var/count = mat_container.retrieve_sheets(text2num(eject_amt), eject_sheet, drop_location())
|
||||
|
||||
var/list/matlist = list()
|
||||
matlist[eject_sheet] = SHEET_MATERIAL_AMOUNT * count
|
||||
|
||||
materials.silo_log(src, "ejected", -count, "sheets", matlist)
|
||||
|
||||
return count
|
||||
|
||||
// Stuff for the stripe on the department machines
|
||||
/obj/machinery/rnd/production/default_deconstruction_screwdriver(mob/user, icon_state_open, icon_state_closed, obj/item/screwdriver)
|
||||
. = ..()
|
||||
|
||||
@@ -469,10 +469,6 @@
|
||||
if("remove_mat")
|
||||
var/datum/material/material = locate(params["ref"])
|
||||
var/amount = text2num(params["amount"])
|
||||
|
||||
if (!amount)
|
||||
return
|
||||
|
||||
// SAFETY: eject_sheets checks for valid mats
|
||||
rmat.eject_sheets(material, amount)
|
||||
return
|
||||
|
||||
@@ -148,10 +148,6 @@
|
||||
if ("remove_mat")
|
||||
var/datum/material/material = locate(params["ref"])
|
||||
var/amount = text2num(params["amount"])
|
||||
|
||||
if (!amount)
|
||||
return TRUE
|
||||
|
||||
// SAFETY: eject_sheets checks for valid mats
|
||||
materials.eject_sheets(material, amount)
|
||||
|
||||
@@ -393,10 +389,6 @@
|
||||
if ("remove_mat")
|
||||
var/datum/material/material = locate(params["ref"])
|
||||
var/amount = text2num(params["amount"])
|
||||
|
||||
if (!amount)
|
||||
return TRUE
|
||||
|
||||
// SAFETY: eject_sheets checks for valid mats
|
||||
materials.eject_sheets(material, amount)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user