Fix type for offset in MapConnection

This commit is contained in:
GriffinR 2024-07-01 15:51:15 -04:00 committed by Philipp AUER
parent 312749dd31
commit a3d5f54b75
3 changed files with 23 additions and 26 deletions

View file

@ -131,7 +131,7 @@ struct MapEvents
struct MapConnection
{
u8 direction;
u32 offset;
s32 offset;
u8 mapGroup;
u8 mapNum;
};

View file

@ -144,7 +144,7 @@ static void InitBackupMapLayoutConnections(struct MapHeader *mapHeader)
for (i = 0; i < count; i++, connection++)
{
struct MapHeader const *cMap = GetMapHeaderFromConnection(connection);
u32 offset = connection->offset;
s32 offset = connection->offset;
switch (connection->direction)
{
case CONNECTION_SOUTH:

View file

@ -393,46 +393,43 @@ static bool8 IsHiddenItemPresentAtCoords(const struct MapEvents *events, s16 x,
static bool8 IsHiddenItemPresentInConnection(const struct MapConnection *connection, int x, int y)
{
s16 connectionX, connectionY;
struct MapHeader const *const connectionHeader = GetMapHeaderFromConnection(connection);
u16 localX, localY;
u32 localOffset;
s32 localLength;
struct MapHeader const *const mapHeader = GetMapHeaderFromConnection(connection);
// To convert our x/y into coordinates that are relative to the connected map, we must:
// - Subtract the virtual offset used for the border buffer (MAP_OFFSET).
// - Subtract the horizontal offset between North/South connections, or the vertical offset for East/West
// - Account for map size. (0,0) is in the NW corner of our map, so when looking North/West we have to add the height/width of the connected map,
// and when looking South/East we have to subtract the height/width of our current map.
#define localX (x - MAP_OFFSET)
#define localY (y - MAP_OFFSET)
switch (connection->direction)
{
// same weird temp variable behavior seen in IsHiddenItemPresentAtCoords
case CONNECTION_NORTH:
localOffset = connection->offset + MAP_OFFSET;
localX = x - localOffset;
localLength = mapHeader->mapLayout->height - MAP_OFFSET;
localY = localLength + y; // additions are reversed for some reason
connectionX = localX - connection->offset;
connectionY = connectionHeader->mapLayout->height + localY;
break;
case CONNECTION_SOUTH:
localOffset = connection->offset + MAP_OFFSET;
localX = x - localOffset;
localLength = gMapHeader.mapLayout->height + MAP_OFFSET;
localY = y - localLength;
connectionX = localX - connection->offset;
connectionY = localY - gMapHeader.mapLayout->height;
break;
case CONNECTION_WEST:
localLength = mapHeader->mapLayout->width - MAP_OFFSET;
localX = localLength + x; // additions are reversed for some reason
localOffset = connection->offset + MAP_OFFSET;
localY = y - localOffset;
connectionX = connectionHeader->mapLayout->width + localX;
connectionY = localY - connection->offset;
break;
case CONNECTION_EAST:
localLength = gMapHeader.mapLayout->width + MAP_OFFSET;
localX = x - localLength;
localOffset = connection->offset + MAP_OFFSET;
localY = y - localOffset;
connectionX = localX - gMapHeader.mapLayout->width;
connectionY = localY - connection->offset;
break;
default:
return FALSE;
}
return IsHiddenItemPresentAtCoords(mapHeader->events, localX, localY);
return IsHiddenItemPresentAtCoords(connectionHeader->events, connectionX, connectionY);
}
#undef localX
#undef localY
static void CheckForHiddenItemsInMapConnection(u8 taskId)
{
s16 playerX, playerY;