Skip to content

Commit

Permalink
Randpixel initialize (#20239)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
FluffyGhoster authored Dec 12, 2024
1 parent f481c4e commit 4337e6c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
3 changes: 3 additions & 0 deletions code/game/machinery/pipe/construction.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 21 additions & 6 deletions code/game/objects/items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1078,15 +1078,30 @@ 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)
attack_self(user)
Expand Down
4 changes: 2 additions & 2 deletions code/game/objects/items/stacks/tiles/tile_types.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
item_flags = 0
obj_flags = 0

/obj/item/stack/tile/New()
..()
/obj/item/stack/tile/Initialize(mapload, amount)
. = ..()
randpixel_xy()

/*
Expand Down
3 changes: 2 additions & 1 deletion code/modules/mining/coins.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4337e6c

Please sign in to comment.