From 88d31ab3b6dab54d4bc94ca035eaf6174b6fc673 Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 19 Jun 2021 10:19:07 -0700 Subject: [PATCH] Custom levels: only count inbounds trinkets/crew In the past, people have reported having glitched levels where they can't get the trinket star or can't complete the level because the number of trinkets or crewmates is one higher than what can be obtained in the level. How did this happen? Well, it turns out that if you place an entity, and then resize the level to be smaller, that entity still exists. This is inconsequential for most entities, but if the entity is a trinket or crewmate, that entity is still counted towards the number of trinkets or crewmates in the level. One fix would be to just remove entities whenever the level is downsized, but then if someone accidentally downsizes the level and wants to go back, that entity will be gone. Plus, it would be inconsistent with tiles, because tiles don't get removed when you downsize the level. Also, it wouldn't fix existing levels where people have managed to place trinkets or crewmates out of bounds. So instead, ed.numtrinkets() and ed.numcrewmates() should simply ignore trinkets and crewmates that are outside the playable area. That way, levels with glitched trinkets and crewmates can still be completed, and can still be completed with the trinket star. --- desktop_version/src/editor.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index e217e5ca..34d3e4be 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -5895,12 +5895,21 @@ Uint32 editorclass::getonewaycol(void) return graphics.getRGB(255, 255, 255); } +static bool inbounds(const edentities* entity) +{ + extern editorclass ed; + return entity->x >= 0 + && entity->y >= 0 + && entity->x < ed.mapwidth * 40 + && entity->y < ed.mapheight * 30; +} + int editorclass::numtrinkets(void) { int temp = 0; for (size_t i = 0; i < edentity.size(); i++) { - if (edentity[i].t == 9) + if (edentity[i].t == 9 && inbounds(&edentity[i])) { temp++; } @@ -5913,7 +5922,7 @@ int editorclass::numcrewmates(void) int temp = 0; for (size_t i = 0; i < edentity.size(); i++) { - if (edentity[i].t == 15) + if (edentity[i].t == 15 && inbounds(&edentity[i])) { temp++; }