From 19c0b70171b83d2d306feb8a85b9b58207f76e4d Mon Sep 17 00:00:00 2001 From: chuga-git <98280110+chuga-git@users.noreply.github.com> Date: Sun, 24 Mar 2024 13:41:07 -0500 Subject: [PATCH] Slightly refactors storage item insertion (#24429) * everything is on fire * silent trait check * how did it even become CRLF * minor formatting * fix icon updating and adds silent insertion to global trait list * adds the new parameter to documentation - whoops! * pain * contra review * contra review again, reduces amount of checks for user in the loops --------- Co-authored-by: cybercapitalism <98280110+cybercapitalism@users.noreply.github.com> --- code/__HELPERS/trait_helpers.dm | 2 + code/_globalvars/traits.dm | 3 +- code/game/machinery/machinery.dm | 2 +- code/game/objects/items.dm | 4 +- .../objects/items/weapons/storage/backpack.dm | 2 +- .../objects/items/weapons/storage/bags.dm | 4 +- .../objects/items/weapons/storage/belt.dm | 4 +- .../items/weapons/storage/storage_base.dm | 56 +++++++++++-------- .../objects/items/weapons/storage/wallets.dm | 2 +- code/game/objects/items/weapons/twohanded.dm | 2 +- code/modules/fish/fishtank.dm | 4 +- code/modules/hydroponics/hydroponics_tray.dm | 2 +- code/modules/mob/inventory_procs.dm | 42 +++++++------- .../living/carbon/human/human_inventory.dm | 4 +- code/modules/mob/mob.dm | 6 +- code/modules/mod/mod_control.dm | 4 +- code/modules/projectiles/guns/chaos_bolt.dm | 4 +- .../projectiles/guns/energy/special_eguns.dm | 4 ++ 18 files changed, 84 insertions(+), 67 deletions(-) diff --git a/code/__HELPERS/trait_helpers.dm b/code/__HELPERS/trait_helpers.dm index 3455f302935..5e7dee8f2e3 100644 --- a/code/__HELPERS/trait_helpers.dm +++ b/code/__HELPERS/trait_helpers.dm @@ -249,6 +249,8 @@ Remember to update _globalvars/traits.dm if you're adding/removing/renaming trai #define TRAIT_FORCES_OPEN_DOORS_ITEM "forces_open_doors_item_varient" /// Makes the item no longer spit out a visible message when thrown #define TRAIT_NO_THROWN_MESSAGE "no_message_when_thrown" +/// Makes the item not display a message on storage insertion +#define TRAIT_SILENT_INSERTION "silent_insertion" /// A surgical tool; when in hand in help intent (and with a surgery in progress) won't attack the user #define TRAIT_SURGICAL "surgical_tool" diff --git a/code/_globalvars/traits.dm b/code/_globalvars/traits.dm index c9b5194dc5c..5937c9af4d6 100644 --- a/code/_globalvars/traits.dm +++ b/code/_globalvars/traits.dm @@ -107,7 +107,8 @@ GLOBAL_LIST_INIT(traits_by_type, list( "TRAIT_FORCES_OPEN_DOORS" = TRAIT_FORCES_OPEN_DOORS_ITEM, "TRAIT_OBSCURED_WIRES" = TRAIT_OBSCURED_WIRES, "TRAIT_XENO_INTERACTABLE" = TRAIT_XENO_INTERACTABLE, - "TRAIT_NO_THROWN_MESSAGE" = TRAIT_NO_THROWN_MESSAGE + "TRAIT_NO_THROWN_MESSAGE" = TRAIT_NO_THROWN_MESSAGE, + "TRAIT_SILENT_INSERTION" = TRAIT_SILENT_INSERTION ), /turf = list( "bluespace_speed_trait" = TRAIT_BLUESPACE_SPEED diff --git a/code/game/machinery/machinery.dm b/code/game/machinery/machinery.dm index 67fc6aa0aab..b62db80c705 100644 --- a/code/game/machinery/machinery.dm +++ b/code/game/machinery/machinery.dm @@ -397,7 +397,7 @@ else if(B.rating <= A.rating) continue W.remove_from_storage(B, src) - W.handle_item_insertion(A, 1) + W.handle_item_insertion(A, user, TRUE) component_parts -= A component_parts += B B.loc = null diff --git a/code/game/objects/items.dm b/code/game/objects/items.dm index 8e72b88a191..40acf701db2 100644 --- a/code/game/objects/items.dm +++ b/code/game/objects/items.dm @@ -368,7 +368,7 @@ GLOBAL_DATUM_INIT(welding_sparks, /mutable_appearance, mutable_appearance('icons failure = 1 continue success = 1 - S.handle_item_insertion(IT, 1) //The 1 stops the "You put the [src] into [S]" insertion message from being displayed. + S.handle_item_insertion(IT, user, TRUE) //The TRUE stops the "You put the [src] into [S]" insertion message from being displayed. if(success && !failure) to_chat(user, "You put everything in [S].") else if(success) @@ -377,7 +377,7 @@ GLOBAL_DATUM_INIT(welding_sparks, /mutable_appearance, mutable_appearance('icons to_chat(user, "You fail to pick anything up with [S].") else if(S.can_be_inserted(src)) - S.handle_item_insertion(src) + S.handle_item_insertion(src, user) else if(istype(I, /obj/item/stack/tape_roll)) if(isstorage(src)) //Don't tape the bag if we can put the duct tape inside it instead var/obj/item/storage/bag = src diff --git a/code/game/objects/items/weapons/storage/backpack.dm b/code/game/objects/items/weapons/storage/backpack.dm index 5f362b5ffe3..7a296d96441 100644 --- a/code/game/objects/items/weapons/storage/backpack.dm +++ b/code/game/objects/items/weapons/storage/backpack.dm @@ -454,7 +454,7 @@ // The following three procs handle refusing access to contents if the duffel is zipped -/obj/item/storage/backpack/duffel/handle_item_insertion(obj/item/I, prevent_warning, bypass_zip = FALSE) +/obj/item/storage/backpack/duffel/handle_item_insertion(obj/item/I, mob/user, prevent_warning, bypass_zip = FALSE) if(bypass_zip) return ..() diff --git a/code/game/objects/items/weapons/storage/bags.dm b/code/game/objects/items/weapons/storage/bags.dm index 7bc630ed97e..75d04fa1805 100644 --- a/code/game/objects/items/weapons/storage/bags.dm +++ b/code/game/objects/items/weapons/storage/bags.dm @@ -67,7 +67,7 @@ . = ..() update_weight() -/obj/item/storage/bag/trash/handle_item_insertion(obj/item/I, prevent_warning) +/obj/item/storage/bag/trash/handle_item_insertion(obj/item/I, mob/user, prevent_warning) . = ..() update_weight() @@ -273,7 +273,7 @@ // Modified handle_item_insertion. Would prefer not to, but... -/obj/item/storage/bag/sheetsnatcher/handle_item_insertion(obj/item/W as obj, prevent_warning = 0) +/obj/item/storage/bag/sheetsnatcher/handle_item_insertion(obj/item/W as obj, mob/user, prevent_warning = FALSE) var/obj/item/stack/sheet/S = W if(!istype(S)) return 0 diff --git a/code/game/objects/items/weapons/storage/belt.dm b/code/game/objects/items/weapons/storage/belt.dm index 20be9c3c465..9d11690e376 100644 --- a/code/game/objects/items/weapons/storage/belt.dm +++ b/code/game/objects/items/weapons/storage/belt.dm @@ -52,7 +52,7 @@ belt_image.color = I.color . += belt_image -/obj/item/storage/belt/handle_item_insertion(obj/item/I, prevent_warning) +/obj/item/storage/belt/handle_item_insertion(obj/item/I, mob/user, prevent_warning) . = ..() update_weight() @@ -754,7 +754,7 @@ else to_chat(user, "[src] is empty!") -/obj/item/storage/belt/rapier/handle_item_insertion(obj/item/W, prevent_warning) +/obj/item/storage/belt/rapier/handle_item_insertion(obj/item/W, mob/user, prevent_warning) if(!..()) return playsound(src, 'sound/weapons/blade_sheath.ogg', 20) diff --git a/code/game/objects/items/weapons/storage/storage_base.dm b/code/game/objects/items/weapons/storage/storage_base.dm index 5af23ef987a..e683012a13a 100644 --- a/code/game/objects/items/weapons/storage/storage_base.dm +++ b/code/game/objects/items/weapons/storage/storage_base.dm @@ -423,20 +423,21 @@ * This doesn't perform any checks of whether an item can be inserted. That's done by [/obj/item/storage/proc/can_be_inserted] * Arguments: * * obj/item/I - The item to be inserted + * * mob/user - The mob performing the insertion * * prevent_warning - Stop the insertion message being displayed. Intended for cases when you are inserting multiple items at once. */ -/obj/item/storage/proc/handle_item_insertion(obj/item/I, prevent_warning = FALSE) +/obj/item/storage/proc/handle_item_insertion(obj/item/I, mob/user, prevent_warning = FALSE) if(!istype(I)) return FALSE - if(usr) - if(!Adjacent(usr) && !isnewplayer(usr)) + if(user) + if(!Adjacent(user) && !isnewplayer(user)) return FALSE - if(!usr.unEquip(I, silent = TRUE)) + if(!user.unEquip(I, silent = TRUE)) return FALSE - usr.update_icons() //update our overlays + user.update_icons() //update our overlays if(QDELING(I)) return FALSE - if(silent) + if(silent || HAS_TRAIT(I, TRAIT_SILENT_INSERTION)) prevent_warning = TRUE I.forceMove(src) if(QDELING(I)) @@ -447,25 +448,34 @@ var/mob/M = _M if((M.s_active == src) && M.client) M.client.screen += I + if(user) + if(user.client && user.s_active != src) + user.client.screen -= I + I.dropped(user, TRUE) + add_fingerprint(user) - if(usr) - if(usr.client && usr.s_active != src) - usr.client.screen -= I - I.dropped(usr, TRUE) - add_fingerprint(usr) + if(!prevent_warning) + // all mobs with clients attached, sans the item's user + var/viewer_list = GLOB.player_list - user - if(!prevent_warning && !istype(I, /obj/item/gun/energy/kinetic_accelerator/crossbow)) - for(var/mob/M in viewers(usr, null)) - if(M == usr) - to_chat(usr, "You put [I] into [src].") - else if(M in range(1)) //If someone is standing close enough, they can tell what it is... - M.show_message("[usr] puts [I] into [src].") - else if(I && I.w_class >= WEIGHT_CLASS_NORMAL) //Otherwise they can only see large or normal items from a distance... - M.show_message("[usr] puts [I] into [src].") + // the item's user will always get a notification + to_chat(user, "You put [I] into [src].") + + // if the item less than normal sized, only people within 1 tile get the message, otherwise, everybody in view gets it + if(I.w_class < WEIGHT_CLASS_NORMAL) + for(var/mob/M in viewer_list) + if(in_range(M, user)) + M.show_message("[user] puts [I] into [src].") + else + // restrict player list to include only those in view + viewer_list = viewer_list & viewers(world.view, user) + for(var/mob/M in viewer_list) + M.show_message("[user] puts [I] into [src].") + + orient2hud(user) + if(user.s_active) + user.s_active.show_to(user) - orient2hud(usr) - if(usr.s_active) - usr.s_active.show_to(usr) I.mouse_opacity = MOUSE_OPACITY_OPAQUE //So you can click on the area around the item to equip it, instead of having to pixel hunt I.in_inventory = TRUE update_icon() @@ -545,7 +555,7 @@ return TRUE return FALSE - handle_item_insertion(I) + handle_item_insertion(I, user) /obj/item/storage/attack_hand(mob/user) if(ishuman(user)) diff --git a/code/game/objects/items/weapons/storage/wallets.dm b/code/game/objects/items/weapons/storage/wallets.dm index 890bdb3ec24..793b4302b6a 100644 --- a/code/game/objects/items/weapons/storage/wallets.dm +++ b/code/game/objects/items/weapons/storage/wallets.dm @@ -43,7 +43,7 @@ if(. && istype(I, /obj/item/card/id)) refresh_ID() -/obj/item/storage/wallet/handle_item_insertion(obj/item/I, prevent_warning = FALSE) +/obj/item/storage/wallet/handle_item_insertion(obj/item/I, mob/user, prevent_warning = FALSE) . = ..() if(. && istype(I, /obj/item/card/id)) refresh_ID() diff --git a/code/game/objects/items/weapons/twohanded.dm b/code/game/objects/items/weapons/twohanded.dm index 71a0768a94c..d2f28de7e2a 100644 --- a/code/game/objects/items/weapons/twohanded.dm +++ b/code/game/objects/items/weapons/twohanded.dm @@ -928,7 +928,7 @@ var/obj/item/storage/bag/trash/bag = jani_vehicle?.mybag || jani_cart?.mybag var/obj/trashed_into if(bag?.can_be_inserted(garbage, TRUE)) - bag.handle_item_insertion(garbage, TRUE) + bag.handle_item_insertion(garbage, user, TRUE) trashed_into = bag else if(target_bin) move_into_storage(user, target_bin, garbage) diff --git a/code/modules/fish/fishtank.dm b/code/modules/fish/fishtank.dm index 3b2ac70a4d8..a14e0205e97 100644 --- a/code/modules/fish/fishtank.dm +++ b/code/modules/fish/fishtank.dm @@ -296,7 +296,7 @@ if(egg != /obj/item/fish_eggs) // Don't harvest duds egg = new egg(get_turf(user)) //Spawn the egg at the user's feet if(fish_bag?.can_be_inserted(egg)) - fish_bag.handle_item_insertion(egg) + fish_bag.handle_item_insertion(egg, user) else duds++ egg_list.Remove(egg) //Remove the egg from the egg_list @@ -350,7 +350,7 @@ if(fish_item) var/obj/item/I = new fish_item(get_turf(user)) if(fish_bag?.can_be_inserted(I)) - fish_bag.handle_item_insertion(I) + fish_bag.handle_item_insertion(I, user) user.visible_message("[user.name] scoops \a [fish_name] from [src].", "You scoop \a [fish_name] out of [src].") kill_fish(fish_to_scoop) //Kill the caught fish from the tank diff --git a/code/modules/hydroponics/hydroponics_tray.dm b/code/modules/hydroponics/hydroponics_tray.dm index caaf5502565..e0c32d73808 100644 --- a/code/modules/hydroponics/hydroponics_tray.dm +++ b/code/modules/hydroponics/hydroponics_tray.dm @@ -828,7 +828,7 @@ for(var/obj/item/food/snacks/grown/G in locate(user.x,user.y,user.z)) if(!S.can_be_inserted(G)) return - S.handle_item_insertion(G, 1) + S.handle_item_insertion(G, user, TRUE) else if(istype(O, /obj/item/shovel/spade)) if(!myseed && !weedlevel) diff --git a/code/modules/mob/inventory_procs.dm b/code/modules/mob/inventory_procs.dm index fb4369f170e..f7ae6158509 100644 --- a/code/modules/mob/inventory_procs.dm +++ b/code/modules/mob/inventory_procs.dm @@ -243,50 +243,50 @@ /obj/item/proc/equip_to_best_slot(mob/M) if(src != M.get_active_hand()) to_chat(M, "You are not holding anything to equip!") - return 0 + return FALSE if(M.equip_to_appropriate_slot(src)) if(M.hand) M.update_inv_l_hand() else M.update_inv_r_hand() - return 1 + return TRUE - if(M.s_active && M.s_active.can_be_inserted(src, 1)) //if storage active insert there - M.s_active.handle_item_insertion(src) - return 1 + if(M.s_active && M.s_active.can_be_inserted(src, TRUE)) //if storage active insert there + M.s_active.handle_item_insertion(src, M) + return TRUE var/obj/item/storage/S = M.get_inactive_hand() - if(istype(S) && S.can_be_inserted(src, 1)) //see if we have box in other hand - S.handle_item_insertion(src) - return 1 + if(istype(S) && S.can_be_inserted(src, M, TRUE)) //see if we have box in other hand + S.handle_item_insertion(src, M) + return TRUE S = M.get_item_by_slot(SLOT_HUD_WEAR_ID) - if(istype(S) && S.can_be_inserted(src, 1)) //else we put in a wallet - S.handle_item_insertion(src) - return 1 + if(istype(S) && S.can_be_inserted(src, TRUE)) //else we put in a wallet + S.handle_item_insertion(src, M) + return TRUE S = M.get_item_by_slot(SLOT_HUD_BELT) - if(istype(S) && S.can_be_inserted(src, 1)) //else we put in belt - S.handle_item_insertion(src) - return 1 + if(istype(S) && S.can_be_inserted(src, TRUE)) //else we put in belt + S.handle_item_insertion(src, M) + return TRUE var/obj/item/O = M.get_item_by_slot(SLOT_HUD_BACK) //else we put in backpack if(istype(O, /obj/item/storage)) S = O - if(S.can_be_inserted(src, 1)) - S.handle_item_insertion(src) + if(S.can_be_inserted(src, TRUE)) + S.handle_item_insertion(src, M) playsound(loc, "rustle", 50, TRUE, -5) - return 1 + return TRUE if(ismodcontrol(O)) var/obj/item/mod/control/C = O - if(C.can_be_inserted(src, 1)) - C.handle_item_insertion(src) + if(C.can_be_inserted(src, TRUE)) + C.handle_item_insertion(src, M) playsound(loc, "rustle", 50, TRUE, -5) - return 1 + return TRUE to_chat(M, "You are unable to equip that!") - return 0 + return FALSE /mob/proc/get_all_slots() return list(wear_mask, back, l_hand, r_hand) diff --git a/code/modules/mob/living/carbon/human/human_inventory.dm b/code/modules/mob/living/carbon/human/human_inventory.dm index 76ef81a1f3a..21dc5682e50 100644 --- a/code/modules/mob/living/carbon/human/human_inventory.dm +++ b/code/modules/mob/living/carbon/human/human_inventory.dm @@ -446,12 +446,12 @@ return if(ismodcontrol(equipped_item)) // Check if the item is a MODsuit if(thing && equipped_item.can_be_inserted(thing)) // Check if the item can be inserted into the MODsuit - equipped_item.handle_item_insertion(thing) // Insert the item into the MODsuit + equipped_item.handle_item_insertion(thing, src) // Insert the item into the MODsuit playsound(loc, "rustle", 50, TRUE, -5) return if(!istype(equipped_item)) // We also let you equip things like this equip_to_slot_if_possible(thing, slot_item) return if(thing && equipped_item.can_be_inserted(thing)) // put thing in belt or bag - equipped_item.handle_item_insertion(thing) + equipped_item.handle_item_insertion(thing, src) playsound(loc, "rustle", 50, 1, -5) diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 3a8a7459958..bfd291fe9f2 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -272,7 +272,7 @@ // Convinience proc. Collects crap that fails to equip either onto the mob's back, or drops it. // Used in job equipping so shit doesn't pile up at the start loc. /mob/living/carbon/human/proc/equip_or_collect(obj/item/W, slot, initial = FALSE) - if(W.mob_can_equip(src, slot, 1)) + if(W.mob_can_equip(src, slot, TRUE)) //Mob can equip. Equip it. equip_to_slot_or_del(W, slot, initial) else @@ -280,12 +280,12 @@ if(isstorage(back)) var/obj/item/storage/S = back //Now, S represents a container we can insert W into. - S.handle_item_insertion(W, TRUE, TRUE) + S.handle_item_insertion(W, src, TRUE, TRUE) return S if(ismodcontrol(back)) var/obj/item/mod/control/C = back if(C.bag) - C.bag.handle_item_insertion(W, TRUE, TRUE) + C.bag.handle_item_insertion(W, src, TRUE, TRUE) return C.bag var/turf/T = get_turf(src) diff --git a/code/modules/mod/mod_control.dm b/code/modules/mod/mod_control.dm index fb3ffcaee37..38d5b2fbb68 100644 --- a/code/modules/mod/mod_control.dm +++ b/code/modules/mod/mod_control.dm @@ -427,9 +427,9 @@ return bag.can_be_inserted(I, stop_messages) return FALSE -/obj/item/mod/control/proc/handle_item_insertion(I, prevent_warning) +/obj/item/mod/control/proc/handle_item_insertion(I, mob/user, prevent_warning) if(bag) - bag.handle_item_insertion(I, prevent_warning) + bag.handle_item_insertion(I, user, prevent_warning) /obj/item/mod/control/get_cell() if(!open) diff --git a/code/modules/projectiles/guns/chaos_bolt.dm b/code/modules/projectiles/guns/chaos_bolt.dm index 6fed4ce7b48..93386c92055 100644 --- a/code/modules/projectiles/guns/chaos_bolt.dm +++ b/code/modules/projectiles/guns/chaos_bolt.dm @@ -80,13 +80,13 @@ var/obj/item/I = new item_to_summon(src) if(H.back && isstorage(H.back)) var/obj/item/storage/S = H.back - S.handle_item_insertion(I, TRUE) //We don't check if it can be inserted because it's magic, GET IN THERE! + S.handle_item_insertion(I, H, TRUE) //We don't check if it can be inserted because it's magic, GET IN THERE! H.visible_message("[H]'s [S.name] glows bright!", "\A [I] suddenly appears in your glowing [S.name]!") return if(H.back && ismodcontrol(H.back)) var/obj/item/mod/control/C = H.back if(C.bag) - C.handle_item_insertion(I, TRUE) + C.handle_item_insertion(I, H, TRUE) H.visible_message("[H]'s [C] glows bright!", "\A [I] suddenly appears in your glowing [C.name]!") return I.forceMove(get_turf(H)) diff --git a/code/modules/projectiles/guns/energy/special_eguns.dm b/code/modules/projectiles/guns/energy/special_eguns.dm index 98e3b6be1cc..5d552348916 100644 --- a/code/modules/projectiles/guns/energy/special_eguns.dm +++ b/code/modules/projectiles/guns/energy/special_eguns.dm @@ -125,6 +125,10 @@ empty_state = "crossbow_empty" can_holster = TRUE +/obj/item/gun/energy/kinetic_accelerator/crossbow/Initialize(mapload) + . = ..() + ADD_TRAIT(src, TRAIT_SILENT_INSERTION, ROUNDSTART_TRAIT) + /obj/item/gun/energy/kinetic_accelerator/crossbow/large name = "energy crossbow" desc = "A reverse engineered weapon using syndicate technology."