From 8a3dcc5cc185177355c083eb1b34ed462ff3c021 Mon Sep 17 00:00:00 2001 From: Mechoid Date: Tue, 20 Feb 2018 12:58:13 -0800 Subject: [PATCH] Makes Mining Satchels brute-force their way out of lagging, minerborg prodding. --- .../objects/items/weapons/storage/bags.dm | 76 +++++++++++++++++++ code/modules/mining/satchel_ore_boxdm.dm | 10 ++- .../modules/mob/living/silicon/robot/robot.dm | 12 +++ 3 files changed, 94 insertions(+), 4 deletions(-) diff --git a/code/game/objects/items/weapons/storage/bags.dm b/code/game/objects/items/weapons/storage/bags.dm index 165855e50e..259436e063 100644 --- a/code/game/objects/items/weapons/storage/bags.dm +++ b/code/game/objects/items/weapons/storage/bags.dm @@ -68,6 +68,9 @@ // ----------------------------- // Mining Satchel // ----------------------------- +/* + * Mechoid - Orebags are the most common quick-gathering thing, and also have tons of lag associated with it. Their checks are going to be hyper-simplified due to this, and their INCREDIBLY singular target contents. + */ /obj/item/weapon/storage/bag/ore name = "mining satchel" @@ -79,7 +82,80 @@ max_storage_space = ITEMSIZE_COST_NORMAL * 25 max_w_class = ITEMSIZE_NORMAL can_hold = list(/obj/item/weapon/ore) + var/stored_ore = list() + var/last_update = 0 +/obj/item/weapon/storage/bag/ore/remove_from_storage(obj/item/W as obj, atom/new_location) + if(!istype(W)) return 0 + + if(new_location) + if(ismob(loc)) + W.dropped(usr) + if(ismob(new_location)) + W.hud_layerise() + else + W.reset_plane_and_layer() + W.forceMove(new_location) + else + W.forceMove(get_turf(src)) + + W.on_exit_storage(src) + update_icon() + return 1 + +/obj/item/weapon/storage/bag/ore/gather_all(turf/T as turf, mob/user as mob, var/silent = 0) + var/success = 0 + var/failure = 0 + for(var/obj/item/weapon/ore/I in T) //Only ever grabs ores. Doesn't do any extraneous checks, as all ore is the same size. Tons of checks means it causes hanging for up to three seconds. + if(contents.len >= max_storage_space) + failure = 1 + break + I.forceMove(src) + success = 1 + if(success && !failure && !silent) + to_chat(user, "You put everything in [src].") + else if(success && (!silent || (silent && contents.len >= max_storage_space))) + to_chat(user, "You fill the [src].") + else if(!silent) + to_chat(user, "You fail to pick anything up with \the [src].") + +/obj/item/weapon/storage/bag/ore/examine(mob/user) + ..() + + if(!Adjacent(user)) //Can only check the contents of ore boxes if you can physically reach them. + return + + if(istype(user, /mob/living)) + add_fingerprint(user) + + if(!contents.len) + to_chat(user, "It is empty.") + return + + if(world.time > last_update + 10) + update_ore_count() + last_update = world.time + + to_chat(user, "It holds:") + for(var/ore in stored_ore) + to_chat(user, "- [stored_ore[ore]] [ore]") + return + +/obj/item/weapon/storage/bag/ore/open(mob/user as mob) //No opening it for the weird UI of having shit-tons of ore inside it. + if(world.time > last_update + 10) + update_ore_count() + last_update = world.time + examine(user) + +/obj/item/weapon/storage/bag/ore/proc/update_ore_count() //Stolen from ore boxes. + + stored_ore = list() + + for(var/obj/item/weapon/ore/O in contents) + if(stored_ore[O.name]) + stored_ore[O.name]++ + else + stored_ore[O.name] = 1 // ----------------------------- // Plant bag diff --git a/code/modules/mining/satchel_ore_boxdm.dm b/code/modules/mining/satchel_ore_boxdm.dm index e8d8981d3e..b904a7cfad 100644 --- a/code/modules/mining/satchel_ore_boxdm.dm +++ b/code/modules/mining/satchel_ore_boxdm.dm @@ -14,12 +14,15 @@ if (istype(W, /obj/item/weapon/ore)) user.remove_from_mob(W) src.contents += W - if (istype(W, /obj/item/weapon/storage)) + + else if (istype(W, /obj/item/weapon/storage)) var/obj/item/weapon/storage/S = W + if(!S.contents.len) + return S.hide_from(usr) for(var/obj/item/weapon/ore/O in S.contents) S.remove_from_storage(O, src) //This will move the item to this item's contents - user << "You empty the satchel into the box." + to_chat(user,"You empty the satchel into the box.") update_ore_count() @@ -62,13 +65,12 @@ user << "- [stored_ore[ore]] [ore]" return - /obj/structure/ore_box/verb/empty_box() set name = "Empty Ore Box" set category = "Object" set src in view(1) - if(!istype(usr, /mob/living/carbon/human)) //Only living, intelligent creatures with hands can empty ore boxes. + if(!istype(usr, /mob/living/carbon/human) && !istype(usr, /mob/living/silicon/robot)) //Only living, intelligent creatures with gripping aparatti can empty ore boxes. usr << "You are physically incapable of emptying the ore box." return diff --git a/code/modules/mob/living/silicon/robot/robot.dm b/code/modules/mob/living/silicon/robot/robot.dm index 317b04bad5..2fb48b877b 100644 --- a/code/modules/mob/living/silicon/robot/robot.dm +++ b/code/modules/mob/living/silicon/robot/robot.dm @@ -885,6 +885,18 @@ cleaned_human.update_inv_shoes(0) cleaned_human.clean_blood(1) cleaned_human << "[src] cleans your face!" + + if((module_state_1 && istype(module_state_1, /obj/item/weapon/storage/bag/ore)) || (module_state_2 && istype(module_state_2, /obj/item/weapon/storage/bag/ore)) || (module_state_3 && istype(module_state_3, /obj/item/weapon/storage/bag/ore))) //Borgs and drones can use their mining bags ~automagically~ if they're deployed in a slot. Only mining bags, as they're optimized for mass use. + var/obj/item/weapon/storage/bag/ore/B = null + if(istype(module_state_1, /obj/item/weapon/storage/bag/ore)) //First orebag has priority, if they for some reason have multiple. + B = module_state_1 + else if(istype(module_state_2, /obj/item/weapon/storage/bag/ore)) + B = module_state_2 + else if(istype(module_state_3, /obj/item/weapon/storage/bag/ore)) + B = module_state_3 + var/turf/tile = loc + if(isturf(tile)) + B.gather_all(tile, src, 1) //Shhh, unless the bag fills, don't spam the borg's chat with stuff that's going on every time they move! return /mob/living/silicon/robot/proc/self_destruct()