From abbd9245e8669c1fcc0777e27d84ed9200e18fce Mon Sep 17 00:00:00 2001 From: Viperio19 Date: Sun, 19 Jan 2025 02:01:50 +0100 Subject: [PATCH] Adding a macro, returning an enum, and using constants --- include/map_header.h | 8 +++---- src/main.c | 2 +- src/map_header.c | 4 ++-- src/map_header_data.c | 55 +++++++++++++------------------------------ 4 files changed, 23 insertions(+), 46 deletions(-) diff --git a/include/map_header.h b/include/map_header.h index 66e25a8e4e..c261d8e5ca 100644 --- a/include/map_header.h +++ b/include/map_header.h @@ -1,5 +1,5 @@ -#ifndef POKEPLATINUM_UNK_0203A024_H -#define POKEPLATINUM_UNK_0203A024_H +#ifndef POKEPLATINUM_MAP_HEADER_H +#define POKEPLATINUM_MAP_HEADER_H typedef struct { u8 unk_00; @@ -58,6 +58,6 @@ BOOL MapHeader_IsTrophyGarden(const u32 headerID); BOOL MapHeader_IsAmitySquare(const u32 headerID); BOOL MapHeader_IsAzureFluteAllowed(const u32 headerID); BOOL MapHeader_IsPokemonCenter2F(const u32 headerID); -u32 MapHeader_GetMapEvolutionMethod(u32 headerID); +enum PokemonEvoMethod MapHeader_GetMapEvolutionMethod(u32 headerID); -#endif // POKEPLATINUM_UNK_0203A024_H +#endif // POKEPLATINUM_MAP_HEADER_H diff --git a/src/main.c b/src/main.c index f6ba02ce99..b72589c353 100644 --- a/src/main.c +++ b/src/main.c @@ -269,7 +269,7 @@ static void HeapCanaryFailed(int resetParam, int param1) if (param1 == 3) { sub_02039834(0, 3, 0); - } else if (resetParam == 0) { + } else if (resetParam == RESET_CLEAN) { if (sub_020389B8() == TRUE) { sub_02039834(0, 6, 0); } else { diff --git a/src/map_header.c b/src/map_header.c index 5bbbe39c65..1fc1507f35 100644 --- a/src/map_header.c +++ b/src/map_header.c @@ -252,7 +252,7 @@ BOOL MapHeader_IsPokemonCenter2F(const u32 headerID) return FALSE; } -u32 MapHeader_GetMapEvolutionMethod(u32 headerID) +enum PokemonEvoMethod MapHeader_GetMapEvolutionMethod(u32 headerID) { static const u16 mapEvolutionMethods[] = { MAP_HEADER_ROUTE_217, @@ -306,5 +306,5 @@ u32 MapHeader_GetMapEvolutionMethod(u32 headerID) } } - return 0; + return EVO_NONE; } diff --git a/src/map_header_data.c b/src/map_header_data.c index d63a715645..ac0cdc600a 100644 --- a/src/map_header_data.c +++ b/src/map_header_data.c @@ -191,49 +191,26 @@ BOOL MapHeaderData_SetBgEventPos(FieldSystem *fieldSystem, u16 index, u16 x, u16 return TRUE; } +#define CONSUME_EVENTS(T, dataTEvents, dataNumTEvents) \ + do { \ + (dataNumTEvents) = *(u32 *)events; \ + events += sizeof(u32); \ + if ((dataNumTEvents) != 0) { \ + (dataTEvents) = (const T *)events; \ + } else { \ + (dataTEvents) = NULL; \ + } \ + events += sizeof(T) * (dataNumTEvents); \ + } while (0) + static void MapHeaderData_ParseEvents(MapHeaderData *data) { const u8 *events = (const u8 *)data->tmpEventsBuf; - // bgEvents - data->numBgEvents = *(u32 *)events; - events += sizeof(u32); - if (data->numBgEvents != 0) { - data->bgEvents = (const BgEvent *)events; - } else { - data->bgEvents = NULL; - } - events += sizeof(BgEvent) * data->numBgEvents; - - // objectEvents - data->numObjectEvents = *(u32 *)events; - events += sizeof(u32); - if (data->numObjectEvents != 0) { - data->objectEvents = (const ObjectEvent *)events; - } else { - data->objectEvents = NULL; - } - events += sizeof(ObjectEvent) * data->numObjectEvents; - - // warpEvents - data->numWarpEvents = *(u32 *)events; - events += sizeof(u32); - if (data->numWarpEvents != 0) { - data->warpEvents = (const WarpEvent *)events; - } else { - data->warpEvents = NULL; - } - events += sizeof(WarpEvent) * data->numWarpEvents; - - // coordEvents - data->numCoordEvents = *(u32 *)events; - events += sizeof(u32); - if (data->numCoordEvents != 0) { - data->coordEvents = (const CoordEvent *)events; - } else { - data->coordEvents = NULL; - } - events += sizeof(CoordEvent) * data->numCoordEvents; + CONSUME_EVENTS(BgEvent, data->bgEvents, data->numBgEvents); + CONSUME_EVENTS(ObjectEvent, data->objectEvents, data->numObjectEvents); + CONSUME_EVENTS(WarpEvent, data->warpEvents, data->numWarpEvents); + CONSUME_EVENTS(CoordEvent, data->coordEvents, data->numCoordEvents); } void MapHeaderData_LoadWildEncounters(WildEncounters *data, int headerID)