From 4337e6cef546c9e66afd95e38800f2d6c5bbf2e6 Mon Sep 17 00:00:00 2001 From: Fluffy <65877598+FluffyGhoster@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:29:59 +0100 Subject: [PATCH] Randpixel initialize (#20239) Moved all calls of randpixel_xy in Initialize() (if they were in New()) Some tweaks of the proc This should avoid some random CI failures due to it matching shifted pixels as dirty vars No player facing changes --- code/game/machinery/pipe/construction.dm | 3 +++ code/game/objects/items.dm | 27 ++++++++++++++----- .../objects/items/stacks/tiles/tile_types.dm | 4 +-- code/modules/mining/coins.dm | 3 ++- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/code/game/machinery/pipe/construction.dm b/code/game/machinery/pipe/construction.dm index 2b9a53ea343..68a06f45290 100644 --- a/code/game/machinery/pipe/construction.dm +++ b/code/game/machinery/pipe/construction.dm @@ -229,6 +229,9 @@ connect_types = CONNECT_TYPE_REGULAR|CONNECT_TYPE_SUPPLY|CONNECT_TYPE_SCRUBBER|CONNECT_TYPE_FUEL|CONNECT_TYPE_AUX //src.pipe_dir = get_pipe_dir() update() + +/obj/item/pipe/Initialize(mapload) + . = ..() randpixel_xy() //update the name and icon of the pipe item depending on the type diff --git a/code/game/objects/items.dm b/code/game/objects/items.dm index 0ddfedb2214..027b4a6dfd3 100644 --- a/code/game/objects/items.dm +++ b/code/game/objects/items.dm @@ -1078,14 +1078,29 @@ modules/mob/living/carbon/human/life.dm if you die, you will be zoomed out. return TRUE return FALSE -//Used for selecting a random pixel placement, usually on initialize. Checks for pixel_x/y to not interfere with mapped in items. +/** + * Randomizes the pixel_x and pixel_y variables of the item if they are not already set, based on `randpixel` + * + * Returns `TRUE` if the item was randomized, `FALSE` otherwise + * + * This should _not_ be called from `New()`, only from `Initialize()` or other procs that are called after the maploader has already finished loading the item + */ /obj/item/proc/randpixel_xy() - if(!pixel_x && !pixel_y) - pixel_x = rand(-randpixel, randpixel) - pixel_y = rand(-randpixel, randpixel) - return TRUE - else + SHOULD_NOT_SLEEP(TRUE) + + #if defined(TESTING) + if(!(src.flags_1 & INITIALIZED_1)) + stack_trace("Item [src] was not initialized before calling randpixel_xy()!") return FALSE + #endif + + // If the item is qdel'd, has already been randomized or has already a pixel_x or pixel_y set, don't do anything and return FALSE + if(QDELETED(src) || pixel_x || pixel_y) + return FALSE + + pixel_x = rand(-randpixel, randpixel) + pixel_y = rand(-randpixel, randpixel) + return TRUE /obj/item/do_simple_ranged_interaction(var/mob/user) if(user) diff --git a/code/game/objects/items/stacks/tiles/tile_types.dm b/code/game/objects/items/stacks/tiles/tile_types.dm index ccdb839614c..299558baabd 100644 --- a/code/game/objects/items/stacks/tiles/tile_types.dm +++ b/code/game/objects/items/stacks/tiles/tile_types.dm @@ -26,8 +26,8 @@ item_flags = 0 obj_flags = 0 -/obj/item/stack/tile/New() - ..() +/obj/item/stack/tile/Initialize(mapload, amount) + . = ..() randpixel_xy() /* diff --git a/code/modules/mining/coins.dm b/code/modules/mining/coins.dm index 90ab4ed233d..d32e6d7f45a 100644 --- a/code/modules/mining/coins.dm +++ b/code/modules/mining/coins.dm @@ -18,7 +18,8 @@ var/cmineral = null var/last_flip = 0 //Spam limiter -/obj/item/coin/New() +/obj/item/coin/Initialize(mapload) + . = ..() randpixel_xy() /obj/item/coin/gold