From 6a321e8db11ac6435d88658a5bcd96908a1aaece Mon Sep 17 00:00:00 2001 From: spookerton Date: Mon, 14 Nov 2022 11:09:42 +0000 Subject: [PATCH 1/3] hoist storage/Initialize to its rightful place --- .../objects/items/weapons/storage/storage.dm | 127 ++++++++---------- 1 file changed, 59 insertions(+), 68 deletions(-) diff --git a/code/game/objects/items/weapons/storage/storage.dm b/code/game/objects/items/weapons/storage/storage.dm index 4dab1c99a7..42fffd2737 100644 --- a/code/game/objects/items/weapons/storage/storage.dm +++ b/code/game/objects/items/weapons/storage/storage.dm @@ -38,17 +38,70 @@ var/list/starts_with //Things to spawn on the box on spawn var/empty //Mapper override to spawn an empty version of a container that usually has stuff + /obj/item/storage/Destroy() close_all() QDEL_NULL(boxes) - QDEL_NULL(src.storage_start) - QDEL_NULL(src.storage_continue) - QDEL_NULL(src.storage_end) - QDEL_NULL(src.stored_start) - QDEL_NULL(src.stored_continue) - QDEL_NULL(src.stored_end) + QDEL_NULL(storage_start) + QDEL_NULL(storage_continue) + QDEL_NULL(storage_end) + QDEL_NULL(stored_start) + QDEL_NULL(stored_continue) + QDEL_NULL(stored_end) QDEL_NULL(closer) + return ..() + + +/obj/item/storage/Initialize() . = ..() + if (allow_quick_empty) + verbs += /obj/item/storage/verb/quick_empty + else + verbs -= /obj/item/storage/verb/quick_empty + if (allow_quick_gather) + verbs += /obj/item/storage/verb/toggle_gathering_mode + else + verbs -= /obj/item/storage/verb/toggle_gathering_mode + boxes = new /obj/screen/storage + boxes.name = "storage" + boxes.master = src + boxes.icon_state = "block" + boxes.screen_loc = "7,7 to 10,8" + storage_start = new /obj/screen/storage + storage_start.name = "storage" + storage_start.master = src + storage_start.icon_state = "storage_start" + storage_start.screen_loc = "7,7 to 10,8" + storage_continue = new /obj/screen/storage + storage_continue.name = "storage" + storage_continue.master = src + storage_continue.icon_state = "storage_continue" + storage_continue.screen_loc = "7,7 to 10,8" + storage_end = new /obj/screen/storage + storage_end.name = "storage" + storage_end.master = src + storage_end.icon_state = "storage_end" + storage_end.screen_loc = "7,7 to 10,8" + stored_start = new /obj //we just need these to hold the icon + stored_start.icon_state = "stored_start" + stored_continue = new /obj + stored_continue.icon_state = "stored_continue" + stored_end = new /obj + stored_end.icon_state = "stored_end" + closer = new /obj/screen/close + closer.master = src + closer.icon_state = "storage_close" + closer.hud_layerise() + orient2hud() + if (length(starts_with) && !empty) + for (var/newtype in starts_with) + var/count = starts_with[newtype] || 1 + while (count) + count-- + new newtype (src) + starts_with = null //Reduce list count. + calibrate_size() + /obj/item/storage/MouseDrop(obj/over_object as obj) if(!canremove) @@ -534,68 +587,6 @@ for(var/obj/item/I in contents) remove_from_storage(I, T) -/obj/item/storage/Initialize() - . = ..() - - if(allow_quick_empty) - verbs += /obj/item/storage/verb/quick_empty - else - verbs -= /obj/item/storage/verb/quick_empty - - if(allow_quick_gather) - verbs += /obj/item/storage/verb/toggle_gathering_mode - else - verbs -= /obj/item/storage/verb/toggle_gathering_mode - - src.boxes = new /obj/screen/storage( ) - src.boxes.name = "storage" - src.boxes.master = src - src.boxes.icon_state = "block" - src.boxes.screen_loc = "7,7 to 10,8" - - src.storage_start = new /obj/screen/storage( ) - src.storage_start.name = "storage" - src.storage_start.master = src - src.storage_start.icon_state = "storage_start" - src.storage_start.screen_loc = "7,7 to 10,8" - - src.storage_continue = new /obj/screen/storage( ) - src.storage_continue.name = "storage" - src.storage_continue.master = src - src.storage_continue.icon_state = "storage_continue" - src.storage_continue.screen_loc = "7,7 to 10,8" - - src.storage_end = new /obj/screen/storage( ) - src.storage_end.name = "storage" - src.storage_end.master = src - src.storage_end.icon_state = "storage_end" - src.storage_end.screen_loc = "7,7 to 10,8" - - src.stored_start = new /obj //we just need these to hold the icon - src.stored_start.icon_state = "stored_start" - - src.stored_continue = new /obj - src.stored_continue.icon_state = "stored_continue" - - src.stored_end = new /obj - src.stored_end.icon_state = "stored_end" - - src.closer = new /obj/screen/close( ) - src.closer.master = src - src.closer.icon_state = "storage_close" - src.closer.hud_layerise() - orient2hud() - - if(LAZYLEN(starts_with) && !empty) - for(var/newtype in starts_with) - var/count = starts_with[newtype] || 1 //Could have left it blank. - while(count) - count-- - new newtype(src) - starts_with = null //Reduce list count. - - calibrate_size() - /obj/item/storage/proc/calibrate_size() var/total_storage_space = 0 for(var/obj/item/I in contents) From d0ca6c36b86933529f75786c8c2090a5379f8713 Mon Sep 17 00:00:00 2001 From: spookerton Date: Mon, 14 Nov 2022 11:24:26 +0000 Subject: [PATCH 2/3] -storage init explicit types, -storage/empty var storage init also nulls starts_with if it was an empty list --- .../objects/items/weapons/storage/misc.dm | 19 +++++++----- .../objects/items/weapons/storage/storage.dm | 31 ++++++++----------- maps/cynosure/cynosure-3.dmm | 12 +++---- maps/northern_star/polaris-1.dmm | 2 +- maps/southern_cross/southern_cross-1.dmm | 12 +++---- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/code/game/objects/items/weapons/storage/misc.dm b/code/game/objects/items/weapons/storage/misc.dm index 39c4907e8a..03259d0cf4 100644 --- a/code/game/objects/items/weapons/storage/misc.dm +++ b/code/game/objects/items/weapons/storage/misc.dm @@ -38,16 +38,13 @@ var/global/list/random_weighted_donuts = list( max_storage_space = ITEMSIZE_COST_SMALL * 6 can_hold = list(/obj/item/reagent_containers/food/snacks/donut) foldable = /obj/item/stack/material/cardboard - //starts_with = list(/obj/item/reagent_containers/food/snacks/donut/normal = 6) /obj/item/storage/box/donut/Initialize() - if(!empty) - for(var/i in 1 to 6) - var/type_to_spawn = pickweight(random_weighted_donuts) - new type_to_spawn(src) + PopulateDonutSelection() . = ..() update_icon() + /obj/item/storage/box/donut/update_icon() cut_overlays() var/x_offset = 0 @@ -57,8 +54,16 @@ var/global/list/random_weighted_donuts = list( add_overlay(ma) x_offset += 3 -/obj/item/storage/box/donut/empty - empty = TRUE + +/obj/item/storage/box/donut/proc/PopulateDonutSelection() + starts_with = list() + for (var/i = 1 to 6) + starts_with += pickweight(random_weighted_donuts) + + +/obj/item/storage/box/donut/empty/PopulateDonutSelection() + return + /obj/item/storage/box/wormcan icon = 'icons/obj/food.dmi' diff --git a/code/game/objects/items/weapons/storage/storage.dm b/code/game/objects/items/weapons/storage/storage.dm index 42fffd2737..d06eb6a109 100644 --- a/code/game/objects/items/weapons/storage/storage.dm +++ b/code/game/objects/items/weapons/storage/storage.dm @@ -25,9 +25,9 @@ var/obj/screen/storage/storage_start = null //storage UI var/obj/screen/storage/storage_continue = null var/obj/screen/storage/storage_end = null - var/obj/screen/storage/stored_start = null - var/obj/screen/storage/stored_continue = null - var/obj/screen/storage/stored_end = null + var/obj/stored_start = null + var/obj/stored_continue = null + var/obj/stored_end = null var/obj/screen/close/closer = null var/use_to_pickup //Set this to make it possible to use this item in an inverse way, so you can have the item in your hand and click items on the floor to pick them up. var/display_contents_with_number //Set this to make the storage item group contents of the same type and display them as a number. @@ -36,7 +36,6 @@ var/collection_mode = 1; //0 = pick one at a time, 1 = pick all on tile var/use_sound = "rustle" //sound played when used. null for no sound. var/list/starts_with //Things to spawn on the box on spawn - var/empty //Mapper override to spawn an empty version of a container that usually has stuff /obj/item/storage/Destroy() @@ -62,44 +61,40 @@ verbs += /obj/item/storage/verb/toggle_gathering_mode else verbs -= /obj/item/storage/verb/toggle_gathering_mode - boxes = new /obj/screen/storage - boxes.name = "storage" + boxes = new boxes.master = src boxes.icon_state = "block" boxes.screen_loc = "7,7 to 10,8" - storage_start = new /obj/screen/storage - storage_start.name = "storage" + storage_start = new storage_start.master = src storage_start.icon_state = "storage_start" storage_start.screen_loc = "7,7 to 10,8" - storage_continue = new /obj/screen/storage - storage_continue.name = "storage" + storage_continue = new storage_continue.master = src storage_continue.icon_state = "storage_continue" storage_continue.screen_loc = "7,7 to 10,8" - storage_end = new /obj/screen/storage - storage_end.name = "storage" + storage_end = new storage_end.master = src storage_end.icon_state = "storage_end" storage_end.screen_loc = "7,7 to 10,8" - stored_start = new /obj //we just need these to hold the icon + stored_start = new stored_start.icon_state = "stored_start" - stored_continue = new /obj + stored_continue = new stored_continue.icon_state = "stored_continue" - stored_end = new /obj + stored_end = new stored_end.icon_state = "stored_end" - closer = new /obj/screen/close + closer = new closer.master = src closer.icon_state = "storage_close" closer.hud_layerise() orient2hud() - if (length(starts_with) && !empty) + if (islist(starts_with)) for (var/newtype in starts_with) var/count = starts_with[newtype] || 1 while (count) count-- new newtype (src) - starts_with = null //Reduce list count. + starts_with = null calibrate_size() diff --git a/maps/cynosure/cynosure-3.dmm b/maps/cynosure/cynosure-3.dmm index 3f549a15a3..d90da3188c 100644 --- a/maps/cynosure/cynosure-3.dmm +++ b/maps/cynosure/cynosure-3.dmm @@ -29750,16 +29750,16 @@ /obj/item/assembly/prox_sensor, /obj/item/assembly/prox_sensor, /obj/item/storage/firstaid/regular{ - empty = 1; - name = "First-Aid (empty)" + name = "First-Aid (empty)"; + starts_with = null }, /obj/item/storage/firstaid/regular{ - empty = 1; - name = "First-Aid (empty)" + name = "First-Aid (empty)"; + starts_with = null }, /obj/item/storage/firstaid/regular{ - empty = 1; - name = "First-Aid (empty)" + name = "First-Aid (empty)"; + starts_with = null }, /obj/item/healthanalyzer, /obj/item/healthanalyzer, diff --git a/maps/northern_star/polaris-1.dmm b/maps/northern_star/polaris-1.dmm index 6a749f2ff3..ba71c6bd3e 100644 --- a/maps/northern_star/polaris-1.dmm +++ b/maps/northern_star/polaris-1.dmm @@ -4510,7 +4510,7 @@ "bIL" = (/obj/structure/cable/green{d1 = 1; d2 = 2; icon_state = "1-2"},/obj/machinery/atmospherics/pipe/simple/hidden/supply,/obj/machinery/atmospherics/pipe/simple/hidden/scrubbers,/obj/structure/table/standard,/obj/machinery/computer/med_data/laptop,/turf/simulated/floor/tiled/white,/area/assembly/robotics) "bIM" = (/obj/structure/disposalpipe/segment,/turf/simulated/floor/tiled/white,/area/assembly/robotics) "bIN" = (/obj/structure/cable/green{d1 = 1; d2 = 2; icon_state = "1-2"},/turf/simulated/floor/tiled/white,/area/assembly/robotics) -"bIO" = (/obj/structure/closet{name = "robotics parts"},/obj/item/cell/high{charge = 100; maxcharge = 15000; pixel_x = 5; pixel_y = -5},/obj/item/assembly/prox_sensor{pixel_x = -8; pixel_y = 4},/obj/item/assembly/prox_sensor{pixel_x = -8; pixel_y = 4},/obj/item/cell/high{charge = 100; maxcharge = 15000; pixel_x = 5; pixel_y = -5},/obj/item/cell/high{charge = 100; maxcharge = 15000; pixel_x = 5; pixel_y = -5},/obj/item/cell/high{charge = 100; maxcharge = 15000; pixel_x = 5; pixel_y = -5},/obj/item/storage/firstaid/regular{empty = 1; name = "First-Aid (empty)"},/obj/item/storage/firstaid/regular{empty = 1; name = "First-Aid (empty)"},/obj/item/storage/firstaid/regular{empty = 1; name = "First-Aid (empty)"},/obj/item/healthanalyzer,/obj/item/healthanalyzer,/obj/item/healthanalyzer,/obj/effect/floor_decal/corner/pink{dir = 6},/obj/item/flash/synthetic,/obj/item/flash/synthetic,/obj/item/flash/synthetic,/obj/item/flash/synthetic,/obj/item/flash/synthetic,/obj/item/flash/synthetic,/obj/item/stack/cable_coil,/obj/item/stack/cable_coil,/turf/simulated/floor/tiled/white,/area/assembly/robotics) +"bIO" = (/obj/structure/closet{name = "robotics parts"},/obj/item/cell/high{charge = 100; maxcharge = 15000; pixel_x = 5; pixel_y = -5},/obj/item/assembly/prox_sensor{pixel_x = -8; pixel_y = 4},/obj/item/assembly/prox_sensor{pixel_x = -8; pixel_y = 4},/obj/item/cell/high{charge = 100; maxcharge = 15000; pixel_x = 5; pixel_y = -5},/obj/item/cell/high{charge = 100; maxcharge = 15000; pixel_x = 5; pixel_y = -5},/obj/item/cell/high{charge = 100; maxcharge = 15000; pixel_x = 5; pixel_y = -5},/obj/item/storage/firstaid/regular{name = "First-Aid (empty)"; starts_with = null},/obj/item/storage/firstaid/regular{name = "First-Aid (empty)"; starts_with = null},/obj/item/storage/firstaid/regular{name = "First-Aid (empty)"; starts_with = null},/obj/item/healthanalyzer,/obj/item/healthanalyzer,/obj/item/healthanalyzer,/obj/effect/floor_decal/corner/pink{dir = 6},/obj/item/flash/synthetic,/obj/item/flash/synthetic,/obj/item/flash/synthetic,/obj/item/flash/synthetic,/obj/item/flash/synthetic,/obj/item/flash/synthetic,/obj/item/stack/cable_coil,/obj/item/stack/cable_coil,/turf/simulated/floor/tiled/white,/area/assembly/robotics) "bIP" = (/obj/structure/grille,/obj/structure/window/reinforced{dir = 4},/obj/machinery/door/firedoor/border_only,/obj/structure/window/reinforced{dir = 8},/obj/machinery/door/blast/regular{density = 0; icon_state = "pdoor0"; id = "Biohazard"; name = "Biohazard Shutter"; opacity = 0},/turf/simulated/floor/plating,/area/assembly/robotics) "bIQ" = (/obj/structure/grille,/obj/structure/window/reinforced{dir = 4},/obj/machinery/door/firedoor/border_only,/obj/structure/window/reinforced{dir = 8},/turf/simulated/floor/plating,/area/hallway/primary/central_four) "bIR" = (/obj/structure/grille,/obj/structure/window/reinforced{dir = 4},/obj/structure/window/reinforced{dir = 8},/turf/simulated/floor/plating,/area/hallway/primary/central_four) diff --git a/maps/southern_cross/southern_cross-1.dmm b/maps/southern_cross/southern_cross-1.dmm index 920a26f2d5..a6aa89f53d 100644 --- a/maps/southern_cross/southern_cross-1.dmm +++ b/maps/southern_cross/southern_cross-1.dmm @@ -112977,16 +112977,16 @@ pixel_y = 4 }, /obj/item/storage/firstaid/regular{ - empty = 1; - name = "First-Aid (empty)" + name = "First-Aid (empty)"; + starts_with = null }, /obj/item/storage/firstaid/regular{ - empty = 1; - name = "First-Aid (empty)" + name = "First-Aid (empty)"; + starts_with = null }, /obj/item/storage/firstaid/regular{ - empty = 1; - name = "First-Aid (empty)" + name = "First-Aid (empty)"; + starts_with = null }, /obj/item/healthanalyzer, /obj/item/healthanalyzer, From be93f20599538e3582e8622088f08c769a91bdc3 Mon Sep 17 00:00:00 2001 From: spookerton Date: Mon, 14 Nov 2022 11:35:26 +0000 Subject: [PATCH 3/3] storage gets LateInitializeName LateInitializeName allows storage items to set their name flexibly after normal initialization is completed, allowing it to be based on holder, contents, location, etc. Also hoisted storage/internal/Destroy to its rightful place. --- .../objects/items/weapons/storage/internal.dm | 22 ++++++++++++------- .../objects/items/weapons/storage/storage.dm | 10 +++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/code/game/objects/items/weapons/storage/internal.dm b/code/game/objects/items/weapons/storage/internal.dm index 4e37c50928..3d84dd9475 100644 --- a/code/game/objects/items/weapons/storage/internal.dm +++ b/code/game/objects/items/weapons/storage/internal.dm @@ -4,18 +4,24 @@ preserve_item = 1 var/atom/movable/master_atom -/obj/item/storage/internal/Initialize() - . = ..() - master_atom = loc - if(!istype(master_atom)) - return INITIALIZE_HINT_QDEL - loc = master_atom - name = master_atom.name - verbs -= /obj/item/verb/verb_pickup //make sure this is never picked up. /obj/item/storage/internal/Destroy() master_atom = null + return ..() + + +/obj/item/storage/internal/Initialize() . = ..() + master_atom = loc + if (!istype(master_atom)) + return INITIALIZE_HINT_QDEL + loc = master_atom + verbs -= /obj/item/verb/verb_pickup + + +/obj/item/storage/internal/LateInitializeName() + name = master_atom.name + /obj/item/storage/internal/attack_hand() return //make sure this is never picked up diff --git a/code/game/objects/items/weapons/storage/storage.dm b/code/game/objects/items/weapons/storage/storage.dm index d06eb6a109..74526d373f 100644 --- a/code/game/objects/items/weapons/storage/storage.dm +++ b/code/game/objects/items/weapons/storage/storage.dm @@ -96,6 +96,11 @@ new newtype (src) starts_with = null calibrate_size() + return INITIALIZE_HINT_LATELOAD + + +/obj/item/storage/LateInitialize() + LateInitializeName() /obj/item/storage/MouseDrop(obj/over_object as obj) @@ -666,6 +671,11 @@ max_w_class = max(I.w_class, max_w_class) max_storage_space += I.get_storage_cost() + +/obj/item/storage/proc/LateInitializeName() + return + + /* * Trinket Box - READDING SOON */