From fda25beae46f82c16444fe6a18d3ece63ac48130 Mon Sep 17 00:00:00 2001 From: "Wowzewow (Wezzy)" <42310821+alsoandanswer@users.noreply.github.com> Date: Thu, 27 Feb 2025 21:33:46 +0800 Subject: [PATCH] Storage z-fighting bugfix (#20518) Fixes this shit from happening. dreamseeker_siriznpX2I --- code/__DEFINES/inventory.dm | 12 ++++ .../objects/items/weapons/storage/backpack.dm | 2 +- .../objects/items/weapons/storage/belt.dm | 10 ++-- .../objects/items/weapons/storage/boxes.dm | 6 +- .../objects/items/weapons/storage/lockbox.dm | 2 +- .../objects/items/weapons/storage/storage.dm | 51 ++++++---------- .../objects/items/weapons/storage/toolbox.dm | 2 +- code/game/objects/structures/inflatable.dm | 2 +- code/modules/psionics/equipment/psipower.dm | 4 +- html/changelogs/wezzy_Storage-Fixes.yml | 59 +++++++++++++++++++ 10 files changed, 103 insertions(+), 47 deletions(-) create mode 100644 html/changelogs/wezzy_Storage-Fixes.yml diff --git a/code/__DEFINES/inventory.dm b/code/__DEFINES/inventory.dm index a28ca02106c..02ae001efeb 100644 --- a/code/__DEFINES/inventory.dm +++ b/code/__DEFINES/inventory.dm @@ -13,3 +13,15 @@ #define WEIGHT_CLASS_HUGE 5 /// Essentially means it cannot be picked up or placed in an inventory, (e.g. mech parts, safe) #define WEIGHT_CLASS_GIGANTIC 6 +// Use this to forbid item from being placed in a container. +#define WEIGHT_CLASS_NO_CONTAINER INFINITY + +#define BASE_STORAGE_COST(w_class) (2**(w_class-1)) //1,2,4,8,16,... + +//linear increase. Using many small storage containers is more space-efficient than using large ones, +//in exchange for being limited in the w_class of items that will fit +#define BASE_STORAGE_CAPACITY(w_class) (7*(w_class-1)) + +#define DEFAULT_BACKPACK_STORAGE BASE_STORAGE_CAPACITY(5) +#define DEFAULT_LARGEBOX_STORAGE BASE_STORAGE_CAPACITY(4) +#define DEFAULT_BOX_STORAGE BASE_STORAGE_CAPACITY(3) diff --git a/code/game/objects/items/weapons/storage/backpack.dm b/code/game/objects/items/weapons/storage/backpack.dm index b260c6f85c6..2265d1c6909 100644 --- a/code/game/objects/items/weapons/storage/backpack.dm +++ b/code/game/objects/items/weapons/storage/backpack.dm @@ -17,7 +17,7 @@ w_class = WEIGHT_CLASS_BULKY slot_flags = SLOT_BACK max_w_class = WEIGHT_CLASS_NORMAL - max_storage_space = 28 + max_storage_space = DEFAULT_BACKPACK_STORAGE var/species_restricted = list("exclude",BODYTYPE_VAURCA_BREEDER,BODYTYPE_VAURCA_WARFORM) drop_sound = 'sound/items/drop/backpack.ogg' pickup_sound = 'sound/items/pickup/backpack.ogg' diff --git a/code/game/objects/items/weapons/storage/belt.dm b/code/game/objects/items/weapons/storage/belt.dm index 9ba57e3bc4d..4215679b180 100644 --- a/code/game/objects/items/weapons/storage/belt.dm +++ b/code/game/objects/items/weapons/storage/belt.dm @@ -7,7 +7,7 @@ force = 2 storage_slots = 7 max_w_class = WEIGHT_CLASS_NORMAL - max_storage_space = 28 + max_storage_space = DEFAULT_BACKPACK_STORAGE slot_flags = SLOT_BELT attack_verb = list("whipped", "lashed", "disciplined") drop_sound = 'sound/items/drop/toolbelt.ogg' @@ -251,7 +251,7 @@ name = "tactical medical belt" desc = "A sturdy black webbing belt with attached pouches. This one is designed for medical professionals who expect to enter conflict zones on the daily. It has increased storage and utility." storage_slots = 9 - max_storage_space = 28 + max_storage_space = DEFAULT_BACKPACK_STORAGE can_hold = list( /obj/item/device/breath_analyzer, /obj/item/device/healthanalyzer, @@ -414,7 +414,7 @@ item_state = "swatbelt" storage_slots = 9 max_w_class = WEIGHT_CLASS_NORMAL - max_storage_space = 28 + max_storage_space = DEFAULT_BACKPACK_STORAGE /obj/item/storage/belt/military name = "military belt" @@ -587,7 +587,7 @@ item_state = "security" storage_slots = 9 max_w_class = WEIGHT_CLASS_BULKY - max_storage_space = 28 + max_storage_space = DEFAULT_BACKPACK_STORAGE can_hold = list( /obj/item/grenade, @@ -643,7 +643,7 @@ name = "component pouch" desc = "A dorky fannypack for keeping small items in. Also stores magickal components!" starts_with = list(/obj/item/toy/snappop/syndi = 3, /obj/item/reagent_containers/glass/beaker/vial/random/toxin = 2, /obj/item/storage/pill_bottle/dice = 1) - max_storage_space = 14 + max_storage_space = DEFAULT_BOX_STORAGE /obj/item/storage/belt/shumaila_buckle name = "hammer buckle belt" diff --git a/code/game/objects/items/weapons/storage/boxes.dm b/code/game/objects/items/weapons/storage/boxes.dm index 3e3ba2b6540..b300d0b2c6a 100644 --- a/code/game/objects/items/weapons/storage/boxes.dm +++ b/code/game/objects/items/weapons/storage/boxes.dm @@ -152,7 +152,7 @@ desc = "A faithful box that will remain with you, no matter where you go, and probably save you." icon_state = "redbox" illustration = "survival" - max_storage_space = 14 + max_storage_space = DEFAULT_BOX_STORAGE can_hold = list( /obj/item/clothing/mask, /obj/item/tank/emergency_oxygen, @@ -200,7 +200,7 @@ name = "box of sterile gloves" desc = "Contains sterile gloves." illustration = "latex" - max_storage_space = 14 + max_storage_space = DEFAULT_BOX_STORAGE starts_with = list(/obj/item/clothing/gloves/latex = 2, /obj/item/clothing/gloves/latex/nitrile = 2, /obj/item/clothing/gloves/latex/nitrile/unathi = 1, @@ -800,7 +800,7 @@ icon_state = "portafreezer" item_state = "medicalpack" max_w_class = WEIGHT_CLASS_NORMAL - max_storage_space = 21 + max_storage_space = DEFAULT_LARGEBOX_STORAGE use_to_pickup = FALSE // for picking up broken bulbs, not that most people will try chewable = FALSE diff --git a/code/game/objects/items/weapons/storage/lockbox.dm b/code/game/objects/items/weapons/storage/lockbox.dm index e2858551933..34e32dcf4ab 100644 --- a/code/game/objects/items/weapons/storage/lockbox.dm +++ b/code/game/objects/items/weapons/storage/lockbox.dm @@ -9,7 +9,7 @@ contained_sprite = TRUE w_class = WEIGHT_CLASS_BULKY max_w_class = WEIGHT_CLASS_NORMAL - max_storage_space = 14 //The sum of the w_classes of all the items in this storage item. + max_storage_space = DEFAULT_BOX_STORAGE //The sum of the w_classes of all the items in this storage item. req_access = list(ACCESS_ARMORY) var/locked = 1 var/broken = 0 diff --git a/code/game/objects/items/weapons/storage/storage.dm b/code/game/objects/items/weapons/storage/storage.dm index f81554baa04..f51d4f53ef9 100644 --- a/code/game/objects/items/weapons/storage/storage.dm +++ b/code/game/objects/items/weapons/storage/storage.dm @@ -395,20 +395,21 @@ /obj/item/storage/proc/space_orient_objs(list/obj/item/display_contents, defer_overlays = FALSE) - var/baseline_max_storage_space = 16 //should be equal to default backpack capacity + // Don't touch these numbers. This works on literal pixel measurements. Unless you want to fix this shit. + var/baseline_max_storage_space = DEFAULT_BACKPACK_STORAGE //should be equal to default backpack capacity var/storage_cap_width = 2 //length of sprite for start and end of the box representing total storage space var/stored_cap_width = 4 //length of sprite for start and end of the box representing the stored item - var/storage_width = min( round( 224 * max_storage_space/baseline_max_storage_space ,1) ,284) //length of sprite for the box representing total storage space + var/storage_width = min(round(DEFAULT_BACKPACK_STORAGE*8*max_storage_space/baseline_max_storage_space ,1) , DEFAULT_BACKPACK_STORAGE*10) //length of sprite for the box representing total storage space storage_start.ClearOverlays() var/matrix/M = matrix() - M.Scale((storage_width-storage_cap_width*2+3)/32,1) + M.Scale((storage_width-storage_cap_width*2+11)/32,1) storage_continue.transform = M storage_start.screen_loc = "4:16,2:16" - storage_continue.screen_loc = "4:[storage_cap_width+(storage_width-storage_cap_width*2)/2+2],2:16" - storage_end.screen_loc = "4:[19+storage_width-storage_cap_width],2:16" + storage_continue.screen_loc = "4:[round(storage_cap_width+(storage_width-storage_cap_width*2)/2+6)],2:16" + storage_end.screen_loc = "4:[27+storage_width-storage_cap_width],2:16" var/startpoint = 0 var/endpoint = 1 @@ -419,34 +420,35 @@ for(var/obj/item/O in contents) startpoint = endpoint + 1 - endpoint += storage_width * O.get_storage_cost()/max_storage_space + endpoint = startpoint + storage_width * O.get_storage_cost()/max_storage_space var/atom/movable/screen/storage/background/stored_start = new /atom/movable/screen/storage/background(null, O, "stored_start") - var/atom/movable/screen/storage/background/stored_continue = new /atom/movable/screen/storage/background(null, O, "stored_continue") - var/atom/movable/screen/storage/background/stored_end = new /atom/movable/screen/storage/background(null, O, "stored_end") - var/matrix/M_start = matrix() + M_start.Translate(startpoint, 0) + stored_start.transform = M_start + + var/atom/movable/screen/storage/background/stored_continue = new /atom/movable/screen/storage/background(null, O, "stored_continue") var/matrix/M_continue = matrix() - var/matrix/M_end = matrix() - M_start.Translate(startpoint,0) M_continue.Scale((endpoint-startpoint-stored_cap_width*2)/32,1) M_continue.Translate(startpoint+stored_cap_width+(endpoint-startpoint-stored_cap_width*2)/2 - 16,0) - M_end.Translate(endpoint-stored_cap_width,0) - stored_start.transform = M_start stored_continue.transform = M_continue + + var/atom/movable/screen/storage/background/stored_end = new /atom/movable/screen/storage/background(null, O, "stored_end") + var/matrix/M_end = matrix() + M_end.Translate(endpoint-stored_cap_width, 0) stored_end.transform = M_end storage_screens += list(stored_start, stored_continue, stored_end) storage_start.add_vis_contents(list(stored_start, stored_continue, stored_end)) - O.screen_loc = "4:[round((startpoint+endpoint)/2)+2],2:16" + O.screen_loc = "4:[round((startpoint+endpoint)/2)],2:16" O.maptext = "" O.hud_layerise() if (!defer_overlays) storage_start.UpdateOverlays() - closer.screen_loc = "4:[storage_width+19],2:16" + closer.screen_loc = "4:[storage_width+27],2:16" return /datum/numbered_display @@ -964,22 +966,7 @@ return depth /obj/item/proc/get_storage_cost() - if (storage_cost) - return storage_cost - else - if(w_class == WEIGHT_CLASS_TINY) - return 1 - if(w_class == WEIGHT_CLASS_SMALL) - return 2 - if(w_class == WEIGHT_CLASS_NORMAL) - return 4 - if(w_class == WEIGHT_CLASS_BULKY) - return 8 - if(w_class == WEIGHT_CLASS_HUGE) - return 16 - else - return 1000 - - //return 2**(w_class-1) //1,2,4,8,16,... + //If you want to prevent stuff above a certain w_class from being stored, use max_w_class + return BASE_STORAGE_COST(w_class) #undef STORAGE_SPACE_CAP diff --git a/code/game/objects/items/weapons/storage/toolbox.dm b/code/game/objects/items/weapons/storage/toolbox.dm index cfadb6c2322..847a4b6f8a6 100644 --- a/code/game/objects/items/weapons/storage/toolbox.dm +++ b/code/game/objects/items/weapons/storage/toolbox.dm @@ -13,7 +13,7 @@ throw_range = 7 w_class = WEIGHT_CLASS_BULKY max_w_class = WEIGHT_CLASS_NORMAL - max_storage_space = 14 //enough to hold all starting contents + max_storage_space = DEFAULT_BOX_STORAGE //enough to hold all starting contents origin_tech = list(TECH_COMBAT = 1) attack_verb = list("robusted") use_sound = 'sound/items/storage/toolbox.ogg' diff --git a/code/game/objects/structures/inflatable.dm b/code/game/objects/structures/inflatable.dm index 9bdb7e496d5..9697c9c5421 100644 --- a/code/game/objects/structures/inflatable.dm +++ b/code/game/objects/structures/inflatable.dm @@ -297,7 +297,7 @@ contained_sprite = TRUE w_class = WEIGHT_CLASS_NORMAL display_contents_with_number = TRUE - max_storage_space = 28 + max_storage_space = DEFAULT_BACKPACK_STORAGE force_column_number = 3 // we want 4 slots to appear, so 3 columns + 1 free (to insert stuff) storage_slots = 14 can_hold = list(/obj/item/inflatable) diff --git a/code/modules/psionics/equipment/psipower.dm b/code/modules/psionics/equipment/psipower.dm index b1c0cc10d87..8afa7dbffe9 100644 --- a/code/modules/psionics/equipment/psipower.dm +++ b/code/modules/psionics/equipment/psipower.dm @@ -8,6 +8,7 @@ throw_speed = 0 var/maintain_cost = 3 var/mob/living/owner + w_class = WEIGHT_CLASS_NO_CONTAINER /obj/item/psychic_power/New(var/mob/living/_owner) owner = _owner @@ -24,9 +25,6 @@ STOP_PROCESSING(SSprocessing, src) . = ..() -/obj/item/psychic_power/get_storage_cost() - return 5 - /obj/item/psychic_power/attack_self(var/mob/user) sound_to(owner, 'sound/effects/psi/power_fail.ogg') user.drop_from_inventory(src) diff --git a/html/changelogs/wezzy_Storage-Fixes.yml b/html/changelogs/wezzy_Storage-Fixes.yml new file mode 100644 index 00000000000..7e61dca1d27 --- /dev/null +++ b/html/changelogs/wezzy_Storage-Fixes.yml @@ -0,0 +1,59 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# - (fixes bugs) +# wip +# - (work in progress) +# qol +# - (quality of life) +# soundadd +# - (adds a sound) +# sounddel +# - (removes a sound) +# rscadd +# - (adds a feature) +# rscdel +# - (removes a feature) +# imageadd +# - (adds an image or sprite) +# imagedel +# - (removes an image or sprite) +# spellcheck +# - (fixes spelling or grammar) +# experiment +# - (experimental change) +# balance +# - (balance changes) +# code_imp +# - (misc internal code change) +# refactor +# - (refactors code) +# config +# - (makes a change to the config files) +# admin +# - (makes changes to administrator tools) +# server +# - (miscellaneous changes to server) +################################# + +# Your name. +author: Wowzewow (Wezzy) + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, this gets changed to [] after reading. Just remove the brackets when you add new shit. +# Please surround your changes in double quotes ("). It works without them, but if you use certain characters it screws up compiling. The quotes will not show up in the changelog. +changes: + - bugfix: "Fixes inventory sprite z-fighting." + - refactor: "Adds some storage defines."