From 040c664ec2eb909d5cf632785dc0a55b728f60c4 Mon Sep 17 00:00:00 2001 From: Kylerace Date: Tue, 7 Jun 2022 11:19:54 -0700 Subject: [PATCH] fixes inconsistent lighting ci failure in icebox (#67430) Fixes and adds test for get_pixel_turf returning null on tall objects on top of the map. --- code/__HELPERS/turfs.dm | 4 ++-- code/modules/unit_tests/_unit_tests.dm | 1 + code/modules/unit_tests/get_turf_pixel.dm | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 code/modules/unit_tests/get_turf_pixel.dm diff --git a/code/__HELPERS/turfs.dm b/code/__HELPERS/turfs.dm index 5da17c67f31..0d0126b48b1 100644 --- a/code/__HELPERS/turfs.dm +++ b/code/__HELPERS/turfs.dm @@ -229,8 +229,8 @@ Turf and target are separate in case you want to teleport some distance from a t var/turf/atom_turf = get_turf(checked_atom) //use checked_atom's turfs, as it's coords are the same as checked_atom's AND checked_atom's coords are lost if it is inside another atom if(!atom_turf) return null - var/final_x = atom_turf.x + rough_x - var/final_y = atom_turf.y + rough_y + var/final_x = clamp(atom_turf.x + rough_x, 1, world.maxx) + var/final_y = clamp(atom_turf.y + rough_y, 1, world.maxy) if(final_x || final_y) return locate(final_x, final_y, atom_turf.z) diff --git a/code/modules/unit_tests/_unit_tests.dm b/code/modules/unit_tests/_unit_tests.dm index 7b6defbf694..2b3918a9531 100644 --- a/code/modules/unit_tests/_unit_tests.dm +++ b/code/modules/unit_tests/_unit_tests.dm @@ -92,6 +92,7 @@ #include "emoting.dm" #include "food_edibility_check.dm" #include "gas_transfer.dm" +#include "get_turf_pixel.dm" #include "greyscale_config.dm" #include "heretic_knowledge.dm" #include "heretic_rituals.dm" diff --git a/code/modules/unit_tests/get_turf_pixel.dm b/code/modules/unit_tests/get_turf_pixel.dm new file mode 100644 index 00000000000..8cd292d3b6c --- /dev/null +++ b/code/modules/unit_tests/get_turf_pixel.dm @@ -0,0 +1,11 @@ +///ensures that get_turf_pixel() returns turfs within the bounds of the map, +///even when called on a movable with its sprite out of bounds +/datum/unit_test/get_turf_pixel + +/datum/unit_test/get_turf_pixel/Run() + //we need long larry to peek over the top edge of the earth + var/turf/north = locate(1, world.maxy, run_loc_floor_bottom_left.z) + + //hes really long, so hes really good at peaking over the edge of the map + var/mob/living/simple_animal/hostile/megafauna/colossus/long_larry = allocate(/mob/living/simple_animal/hostile/megafauna/colossus, north) + TEST_ASSERT(istype(get_turf_pixel(long_larry), /turf), "get_turf_pixel() isnt clamping a mob whos sprite is above the bounds of the world inside of the map.")