From 1bc1149ab519df55f9eacae02080936651e089af Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 27 Oct 2021 16:49:57 -0700 Subject: [PATCH] Fix regression with counting out-of-bounds custom entities My latest rebase of #624 (refactoring/splitting editor.cpp) accidentally overwrote #787 and essentially reverted it entirely. So, add it back in. This is the same as #787 except it uses the new names, uses SDL_INLINE to inline the function, and uses named constants. --- desktop_version/src/CustomLevels.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/CustomLevels.cpp b/desktop_version/src/CustomLevels.cpp index 6aabccbb..5f73732f 100644 --- a/desktop_version/src/CustomLevels.cpp +++ b/desktop_version/src/CustomLevels.cpp @@ -1746,12 +1746,21 @@ Uint32 customlevelclass::getonewaycol(void) return graphics.getRGB(255, 255, 255); } +static SDL_INLINE bool inbounds(const CustomEntity* entity) +{ + extern customlevelclass cl; + return entity->x >= 0 + && entity->y >= 0 + && entity->x < cl.mapwidth * SCREEN_WIDTH_TILES + && entity->y < cl.mapheight * SCREEN_HEIGHT_TILES; +} + int customlevelclass::numtrinkets(void) { int temp = 0; for (size_t i = 0; i < customentities.size(); i++) { - if (customentities[i].t == 9) + if (customentities[i].t == 9 && inbounds(&customentities[i])) { temp++; } @@ -1764,7 +1773,7 @@ int customlevelclass::numcrewmates(void) int temp = 0; for (size_t i = 0; i < customentities.size(); i++) { - if (customentities[i].t == 15) + if (customentities[i].t == 15 && inbounds(&customentities[i])) { temp++; }