From f184a6750d8a23866090eb3536a8342f4ad301ec Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 23 Feb 2025 23:26:54 +0100 Subject: [PATCH] more documentation of friend areas map --- include/friend_areas_map.h | 27 ++-- src/friend_areas_map.c | 309 ++++++++++++++++++------------------ src/friend_areas_map_util.c | 36 ++--- sym_ewram.txt | 6 +- 4 files changed, 188 insertions(+), 190 deletions(-) diff --git a/include/friend_areas_map.h b/include/friend_areas_map.h index 2c217a061..85420d0cc 100644 --- a/include/friend_areas_map.h +++ b/include/friend_areas_map.h @@ -10,33 +10,35 @@ #define MAX_AREAS_PER_LOCATION 8 -struct FriendAreaLocation +struct FriendAreaLocationInfo { const u8 *name; DungeonPos pos; u8 areasIds[MAX_AREAS_PER_LOCATION]; - s16 unk10[8]; + s16 adjacentLocations[NUM_DIRECTIONS]; }; struct MapLocation { bool8 isShown; - s16 unk2[8]; - axdata unk14; + s16 locationsByDirection[NUM_DIRECTIONS]; + axdata sprite; }; +#define NUM_FRIEND_AREA_LOCATIONS 32 + // size: 0x4DD8 struct FriendAreasMap { OpenedFile *unk0[5]; u16 unk14[64][64]; u16 unk2014[64][64]; - const struct FriendAreaLocation *locations; - struct MapLocation mapLocations[32]; - s32 unk4A18; + const struct FriendAreaLocationInfo *locationsInfo; + struct MapLocation mapLocations[NUM_FRIEND_AREA_LOCATIONS]; + s32 currLocationId; s32 unk4A1C; - s32 unk4A20; - s32 unk4A24; + s32 locationIdOnBPress; + s32 teamBaseLocationId; s32 unk4A28; u8 unk4A2C; axdata arrowSprites[NUM_DIRECTIONS]; @@ -51,7 +53,7 @@ struct FriendAreasMap s32 unk4DE4; s32 unk4DE8; u8 displayedAreas[MAX_AREAS_PER_LOCATION]; - u8 unk4DF4; + u8 chosenFriendAreaId; s32 unk4DF8; MenuInputStruct menu; }; @@ -61,7 +63,7 @@ extern struct FriendAreasMap *gFriendAreasMapPtr; struct struct_unk800F990 { u32 unk0; - u8 unk4; + u8 startingFriendAreaId; u8 unk5; struct FriendAreasMap *unk8; u8 unkC; @@ -71,7 +73,6 @@ void ShowFriendAreasMap(struct struct_unk800F990 *param_1); void PrintFriendAreaNameInMap(u8 *strBuffer, u8 index); bool8 IsFriendAreaShownOnMap(u8 friendAreaId); - void FriendAreasMap_UpdateMonSpritePosition(void); void FriendAreasMap_UpdateBg(void); void FriendAreasMap_HideTextWindowAndArrows(void); @@ -80,6 +81,6 @@ void FriendAreasMap_ShowDirectionArrows(void); void FriendAreasMap_PrintCurrAreaName(void); void FriendAreasMap_PrintAvailableSubAreas(void); void FriendAreasMap_CloseFiles(void); -void sub_8010DA4(void); +void FriendAreasMap_InitGfx(void); #endif diff --git a/src/friend_areas_map.c b/src/friend_areas_map.c index 8cadad48b..83b6520c5 100644 --- a/src/friend_areas_map.c +++ b/src/friend_areas_map.c @@ -33,20 +33,20 @@ extern void sub_80117AC(void); extern void sub_8011760(void); EWRAM_INIT struct FriendAreasMap *gFriendAreasMapPtr = NULL; +EWRAM_DATA static u8 sCurrDirection = 0; +EWRAM_DATA static u8 sHeldDpadCounter = 0; extern const FileArchive gTitleMenuFileArchive; extern const FileArchive gMonsterFileArchive; -static void MoveToNewArea(s32 a0, s32 a1, s32 count); -static u8 GetNewSelectedArea(void); -static s32 ChooseArea(s32 *a0, s32 *newAreaId); -static bool8 ChooseSubArea(void); +static void MoveToNewLocation(s32 a0, s32 a1, s32 count); +static u8 GetChosenDirection(void); +static s32 ChooseLocation(s32 *a0, s32 *newDirection); +static bool8 ChooseAreaInLocation(void); static void FadeFromFriendAreasMap(void); -static void sub_800FC5C(u8 a0); +static void InitMapLocations(u8 startingFriendAreaId); extern u16 gUnknown_2026E4E; -extern u8 gUnknown_202DE18; -extern u8 gUnknown_202DE19; #define NO_AREA NUM_FRIEND_AREAS + 5 @@ -56,178 +56,178 @@ extern u8 gUnknown_202DE19; .name = _("ななし"), \ .pos = {0, 0}, \ .areasIds = {NO_AREA, NO_AREA, NO_AREA, NO_AREA, NO_AREA, NO_AREA, NO_AREA, NO_AREA}, \ - .unk10 = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}, \ + .adjacentLocations = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}, \ } -static const struct FriendAreaLocation gFriendAreaLocations[64] = +static const struct FriendAreaLocationInfo gFriendAreaLocations[64] = { { .name = "Mountain Range", .pos = {0x1C5, 0x71}, .areasIds = {8, 9, 0xA, 0x27, 0x2F, 0xB, 0x3F, 0x3F}, - .unk10 = {5, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xC, 2, 7}, + .adjacentLocations = {5, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xC, 2, 7}, }, { .name = "Glacier", .pos = {0x1CD, 0x1C}, .areasIds = {0x30, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xA, 0xC}, + .adjacentLocations = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xA, 0xC}, }, { .name = "Plains", .pos = {0x161, 0x78}, .areasIds = {0xD, 0xE, 0x11, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0x1B, 7, 0, 0xC, 0xD, 0xFFFF, 9, 0xFFFF}, + .adjacentLocations = {0x1B, 7, 0, 0xC, 0xD, 0xFFFF, 9, 0xFFFF}, }, { .name = "South Plains", .pos = {0x162, 0x12D}, .areasIds = {0xF, 0xC, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 0xFFFF, 0xFFFF, 4, 0xE, 0x12, 0xFFFF, 0xFFFF}, + .adjacentLocations = {0xFFFF, 0xFFFF, 0xFFFF, 4, 0xE, 0x12, 0xFFFF, 0xFFFF}, }, { .name = "Badlands", .pos = {0x194, 0x102}, .areasIds = {0x34, 0x35, 0x28, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 0x11, 0xFFFF, 0xB, 8, 0xFFFF, 0xE, 3}, + .adjacentLocations = {0xFFFF, 0x11, 0xFFFF, 0xB, 8, 0xFFFF, 0xE, 3}, }, { .name = "Eastern Forest", .pos = {0x1C7, 0x9D}, .areasIds = {0x12, 0x13, 0x14, 0x15, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xB, 0xFFFF, 0xFFFF, 0xFFFF, 0, 0xFFFF, 7, 8}, + .adjacentLocations = {0xB, 0xFFFF, 0xFFFF, 0xFFFF, 0, 0xFFFF, 7, 8}, }, { .name = "Western Forest", .pos = {0x108, 0x9D}, .areasIds = {0x16, 0x17, 0x18, 0x19, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0x10, 0xFFFF, 0x1B, 9, 0x14, 0x1A, 0xFFFF, 0xFFFF}, + .adjacentLocations = {0x10, 0xFFFF, 0x1B, 9, 0x14, 0x1A, 0xFFFF, 0xFFFF}, }, { .name = "River", .pos = {0x197, 0xA0}, .areasIds = {0x1A, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {8, 0xB, 5, 0, 0xC, 2, 0x1B, 0xFFFF}, + .adjacentLocations = {8, 0xB, 5, 0, 0xC, 2, 0x1B, 0xFFFF}, }, { .name = "Eastern Ponds", .pos = {0x198, 0xCF}, .areasIds = {0x1B, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {4, 0xFFFF, 0xB, 5, 7, 0x1B, 0xFFFF, 0xE}, + .adjacentLocations = {4, 0xFFFF, 0xB, 5, 7, 0x1B, 0xFFFF, 0xE}, }, { .name = "Pond", .pos = {0x133, 0x79}, .areasIds = {0x1C, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 0x1B, 2, 0xD, 0xF, 0x14, 0xFFFF, 6}, + .adjacentLocations = {0xFFFF, 0x1B, 2, 0xD, 0xF, 0x14, 0xFFFF, 6}, }, { .name = "Northern Lakes", .pos = {0x182, 0x1D}, .areasIds = {0x1D, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 0xC, 1, 0xFFFF, 0xFFFF, 0xFFFF, 0xF, 0xD}, + .adjacentLocations = {0xFFFF, 0xC, 1, 0xFFFF, 0xFFFF, 0xFFFF, 0xF, 0xD}, }, { .name = "Eastern Lakes", .pos = {0x1C6, 0xD0}, .areasIds = {0x1E, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 5, 7, 8, 4}, + .adjacentLocations = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 5, 7, 8, 4}, }, { .name = "Marsh", .pos = {0x1A2, 0x46}, .areasIds = {0x1F, 0x20, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {7, 0, 0xFFFF, 1, 0xFFFF, 0xA, 0xD, 2}, + .adjacentLocations = {7, 0, 0xFFFF, 1, 0xFFFF, 0xA, 0xD, 2}, }, { .name = "Cave", .pos = {0x160, 0x47}, .areasIds = {0x21, 0x23, 0x24, 0x22, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {2, 0xFFFF, 0xC, 0xA, 0xFFFF, 0xF, 0x14, 9}, + .adjacentLocations = {2, 0xFFFF, 0xC, 0xA, 0xFFFF, 0xF, 0x14, 9}, }, { .name = "Jungle", .pos = {0x163, 0x104}, .areasIds = {0x25, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {3, 0xFFFF, 4, 8, 0x1B, 0xFFFF, 0x12, 0xFFFF}, + .adjacentLocations = {3, 0xFFFF, 4, 8, 0x1B, 0xFFFF, 0x12, 0xFFFF}, }, { .name = "Ruins", .pos = {0x136, 0x1C}, .areasIds = {0x26, 0x29, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {9, 0xD, 0xA, 0xFFFF, 0xFFFF, 0xFFFF, 0x18, 0x14}, + .adjacentLocations = {9, 0xD, 0xA, 0xFFFF, 0xFFFF, 0xFFFF, 0x18, 0x14}, }, { .name = "Volcano", .pos = {0x107, 0xCB}, .areasIds = {0x10, 0x2A, 0x32, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 0x12, 0xFFFF, 0x1B, 6, 0xFFFF, 0xFFFF, 0x19}, + .adjacentLocations = {0xFFFF, 0x12, 0xFFFF, 0x1B, 6, 0xFFFF, 0xFFFF, 0x19}, }, { .name = "Desert", .pos = {0x1C4, 0x12D}, .areasIds = {0x2B, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 4, 0xFFFF, 0xFFFF}, + .adjacentLocations = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 4, 0xFFFF, 0xFFFF}, }, { .name = "Relics", .pos = {0x131, 0x105}, .areasIds = {0x2E, 0x2C, 0x2D, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 3, 0xE, 0xFFFF, 0xFFFF, 0x10, 0x19, 0xFFFF}, + .adjacentLocations = {0xFFFF, 3, 0xE, 0xFFFF, 0xFFFF, 0x10, 0x19, 0xFFFF}, }, { .name = "Sky", .pos = {0x2F, 0x15}, .areasIds = {0x33, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0x17, 0x1A, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}, + .adjacentLocations = {0x17, 0x1A, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}, }, { .name = "Northern Isles", .pos = {0x107, 0x47}, .areasIds = {0x36, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {6, 9, 0xD, 0xF, 0xFFFF, 0x18, 0xFFFF, 0xFFFF}, + .adjacentLocations = {6, 9, 0xD, 0xF, 0xFFFF, 0x18, 0xFFFF, 0xFFFF}, }, { .name = "Southern Isles", .pos = {0x5D, 0x10C}, .areasIds = {0x37, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 0xFFFF, 0x19, 0xFFFF, 0xFFFF, 0x16, 0xFFFF, 0xFFFF}, + .adjacentLocations = {0xFFFF, 0xFFFF, 0x19, 0xFFFF, 0xFFFF, 0x16, 0xFFFF, 0xFFFF}, }, { .name = "Southwest Isles", .pos = {0x2D, 0xCB}, .areasIds = {0x38, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 0x15, 0xFFFF, 0xFFFF, 0x17, 0xFFFF, 0xFFFF, 0xFFFF}, + .adjacentLocations = {0xFFFF, 0x15, 0xFFFF, 0xFFFF, 0x17, 0xFFFF, 0xFFFF, 0xFFFF}, }, { .name = "Western Isles", .pos = {0x2D, 0x70}, .areasIds = {0x39, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0x16, 0xFFFF, 0xFFFF, 0x1A, 0x13, 0xFFFF, 0xFFFF, 0xFFFF}, + .adjacentLocations = {0x16, 0xFFFF, 0xFFFF, 0x1A, 0x13, 0xFFFF, 0xFFFF, 0xFFFF}, }, { .name = "Northern Sea", .pos = {0xD0, 0x16}, .areasIds = {1, 3, 5, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 0x14, 0xF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x1A}, + .adjacentLocations = {0xFFFF, 0x14, 0xF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x1A}, }, { .name = "Southern Sea", .pos = {0xB2, 0x10D}, .areasIds = {2, 4, 6, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 0xFFFF, 0x12, 0x10, 0xFFFF, 0xFFFF, 0x15, 0xFFFF}, + .adjacentLocations = {0xFFFF, 0xFFFF, 0x12, 0x10, 0xFFFF, 0xFFFF, 0x15, 0xFFFF}, }, { - .name = "Beach", - .pos = {0x81, 0x42}, - .areasIds = {7, 0x31, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xFFFF, 6, 0xFFFF, 0x18, 0xFFFF, 0x13, 0xFFFF, 0x17}, + .name = "Beach", + .pos = {0x81, 0x42}, + .areasIds = {7, 0x31, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, + .adjacentLocations = {0xFFFF, 6, 0xFFFF, 0x18, 0xFFFF, 0x13, 0xFFFF, 0x17}, }, { - .name = _("$t"), - .pos = {0x163, 0xA1}, - .areasIds = {0, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, - .unk10 = {0xE, 8, 7, 0xFFFF, 2, 9, 6, 0x10}, + .name = _("$t"), + .pos = {0x163, 0xA1}, + .areasIds = {0, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F}, + .adjacentLocations = {0xE, 8, 7, 0xFFFF, 2, 9, 6, 0x10}, }, DUMMY_LOCATION, DUMMY_LOCATION, @@ -273,36 +273,36 @@ void ShowFriendAreasMap(struct struct_unk800F990 *param_1) gUnknown_2026E4E = 0x1010; sub_80095CC(0,0x14); UpdateFadeInTile(2); - gFriendAreasMapPtr->locations = gFriendAreaLocations; + gFriendAreasMapPtr->locationsInfo = gFriendAreaLocations; gFriendAreasMapPtr->unk4A2C = param_1->unk5; - sub_8010DA4(); + FriendAreasMap_InitGfx(); gFriendAreasMapPtr->unk4A28 = -1; gFriendAreasMapPtr->unk4A1C = -1; - sub_800FC5C(param_1->unk4); - gFriendAreasMapPtr->unk4A20 = gFriendAreasMapPtr->unk4A24; - gUnknown_202DE18 = 0xff; - gUnknown_202DE19 = 0; + InitMapLocations(param_1->startingFriendAreaId); + gFriendAreasMapPtr->locationIdOnBPress = gFriendAreasMapPtr->teamBaseLocationId; + sCurrDirection = 0xff; + sHeldDpadCounter = 0; sub_8011760(); while (1) { - s32 local_1c = 0; - s32 newAreaId = 0; - s32 iVar2 = ChooseArea(&local_1c, &newAreaId); + s32 newLocationId = 0; + s32 newDirection = 0; + s32 iVar2 = ChooseLocation(&newLocationId, &newDirection); if (iVar2 == 1) { - MoveToNewArea(local_1c, newAreaId, 0x32); + MoveToNewLocation(newLocationId, newDirection, 50); } else if (iVar2 == 2) { - if (!ChooseSubArea()) + if (!ChooseAreaInLocation()) continue; - param_1->unkC = gFriendAreasMapPtr->unk4DF4; + param_1->unkC = gFriendAreasMapPtr->chosenFriendAreaId; break; } else if (iVar2 == 3) { - if (gFriendAreasMapPtr->unk4A18 == gFriendAreasMapPtr->unk4A20) { + if (gFriendAreasMapPtr->currLocationId == gFriendAreasMapPtr->locationIdOnBPress) { param_1->unkC = 0; break; } - MoveToNewArea(gFriendAreasMapPtr->unk4A20,0,10); + MoveToNewLocation(gFriendAreasMapPtr->locationIdOnBPress,0,10); } } @@ -311,31 +311,31 @@ void ShowFriendAreasMap(struct struct_unk800F990 *param_1) nullsub_16(); } -static s32 ChooseArea(s32 *a0, s32 *newAreaId) +static s32 ChooseLocation(s32 *newLocationId, s32 *newDirection) { s32 ret = 0; FriendAreasMap_ShowDirectionArrows(); FriendAreasMap_PrintCurrAreaName(); while (ret == 0) { - s32 areaId; + s32 direction; FriendAreasMap_RunFrameActions(); - areaId = GetNewSelectedArea(); - if (areaId != 0xFF) { - s32 r4 = gFriendAreasMapPtr->unk4A18; - struct MapLocation *ptr = &gFriendAreasMapPtr->mapLocations[r4]; + direction = GetChosenDirection(); + if (direction != 0xFF) { + s32 currLocationId = gFriendAreasMapPtr->currLocationId; + struct MapLocation *currLocation = &gFriendAreasMapPtr->mapLocations[currLocationId]; - if (ptr->unk2[areaId] >= 0) { - s32 id = ptr->unk2[areaId]; - struct MapLocation *ptr2 = &gFriendAreasMapPtr->mapLocations[id]; + if (currLocation->locationsByDirection[direction] >= 0) { + s32 newlocId = currLocation->locationsByDirection[direction]; + struct MapLocation *newLocation = &gFriendAreasMapPtr->mapLocations[newlocId]; - if (ptr2->isShown != 0) { + if (newLocation->isShown) { ret = 1; - *a0 = id; - *newAreaId = areaId; - gFriendAreasMapPtr->unk4A28 = areaId; - gFriendAreasMapPtr->unk4A1C = r4; + *newLocationId = newlocId; + *newDirection = direction; + gFriendAreasMapPtr->unk4A28 = direction; + gFriendAreasMapPtr->unk4A1C = currLocationId; } } } @@ -352,7 +352,7 @@ static s32 ChooseArea(s32 *a0, s32 *newAreaId) return ret; } -static bool8 ChooseSubArea(void) +static bool8 ChooseAreaInLocation(void) { bool8 ret = FALSE; @@ -373,7 +373,7 @@ static bool8 ChooseSubArea(void) if ((gRealInputs.pressed & A_BUTTON) || menuPtr->unk28.a_button) { PlayAcceptSoundEffect(); - gFriendAreasMapPtr->unk4DF4 = gFriendAreasMapPtr->displayedAreas[menuPtr->menuIndex]; + gFriendAreasMapPtr->chosenFriendAreaId = gFriendAreasMapPtr->displayedAreas[menuPtr->menuIndex]; ret = TRUE; break; } @@ -404,7 +404,7 @@ struct MaxMin s16 max; }; -static const struct MaxMin sAtanRanges[] = +static const struct MaxMin sDistanceRanges[] = { {0x380, 0x480}, {0x80, 0x380}, @@ -416,27 +416,27 @@ static const struct MaxMin sAtanRanges[] = {0x480, 0x780}, }; -static void sub_800FC5C(u8 a0) +static void InitMapLocations(u8 startingFriendAreaId) { - s32 var_48 = 0; + s32 startingLocationId = 0; s32 i, j, k; - for (i = 0; i < 32; i++) { + for (i = 0; i < NUM_FRIEND_AREA_LOCATIONS; i++) { bool8 locationShown = FALSE; bool8 areaIsBase = FALSE; struct MapLocation *mapLocation = &gFriendAreasMapPtr->mapLocations[i]; - const struct FriendAreaLocation *location = &gFriendAreasMapPtr->locations[i]; + const struct FriendAreaLocationInfo *locationInfo = &gFriendAreasMapPtr->locationsInfo[i]; - for (j = 0; j < 8; j++) { - mapLocation->unk2[j] = -1; + for (j = 0; j < NUM_DIRECTIONS; j++) { + mapLocation->locationsByDirection[j] = -1; } for (j = 0; j < MAX_AREAS_PER_LOCATION; j++) { - if (IsFriendAreaShownOnMap(location->areasIds[j])) { - if (location->areasIds[j] == a0) { - var_48 = i; + if (IsFriendAreaShownOnMap(locationInfo->areasIds[j])) { + if (locationInfo->areasIds[j] == startingFriendAreaId) { + startingLocationId = i; } - if (location->areasIds[j] == 0) { - gFriendAreasMapPtr->unk4A24 = i; + if (locationInfo->areasIds[j] == 0) { + gFriendAreasMapPtr->teamBaseLocationId = i; areaIsBase = TRUE; } locationShown = TRUE; @@ -445,28 +445,29 @@ static void sub_800FC5C(u8 a0) if (locationShown) { mapLocation->isShown = TRUE; - AxResInitFile(&mapLocation->unk14, gFriendAreasMapPtr->unk0[2], (areaIsBase) ? 12 : 1, 0, 0x40, 0, 1); + AxResInitFile(&mapLocation->sprite, gFriendAreasMapPtr->unk0[2], (areaIsBase) ? 12 : 1, 0, 0x40, 0, 1); } else { mapLocation->isShown = FALSE; } } - for (i = 0; i < 32; i++) { + for (i = 0; i < NUM_FRIEND_AREA_LOCATIONS; i++) { s32 var1, var2; - struct MapLocation *r3 = &gFriendAreasMapPtr->mapLocations[i]; - const struct FriendAreaLocation *location = &gFriendAreasMapPtr->locations[i]; + struct MapLocation *mapLocation = &gFriendAreasMapPtr->mapLocations[i]; + const struct FriendAreaLocationInfo *locationInfo = &gFriendAreasMapPtr->locationsInfo[i]; - if (!r3->isShown) { + if (!mapLocation->isShown) { continue; } - for (j = 0; j < 8; j++) { - r3->unk2[j] = -1; - if (location->unk10[j] >= 0) { - struct MapLocation *ptr = &gFriendAreasMapPtr->mapLocations[location->unk10[j]]; + // Grab locations which are next to each other. + for (j = 0; j < NUM_DIRECTIONS; j++) { + mapLocation->locationsByDirection[j] = -1; + if (locationInfo->adjacentLocations[j] >= 0) { + struct MapLocation *ptr = &gFriendAreasMapPtr->mapLocations[locationInfo->adjacentLocations[j]]; if (ptr->isShown) { - r3->unk2[j] = location->unk10[j]; + mapLocation->locationsByDirection[j] = locationInfo->adjacentLocations[j]; } } } @@ -478,31 +479,32 @@ static void sub_800FC5C(u8 a0) if (ptr->isShown) { var1 += 4; var1 &= 7; - r3->unk2[var1] = var2; + mapLocation->locationsByDirection[var1] = var2; } } - for (j = 0; j < 8; j++) { - s32 var_40 = -1; - s32 var_3C = 999999; + // Find locations which are the closest from each other. + for (j = 0; j < NUM_DIRECTIONS; j++) { + s32 foundLocationId = -1; + s32 biggestDistance = 999999; - if (r3->unk2[j] >= 0) + if (mapLocation->locationsByDirection[j] >= 0) continue; - for (k = 0; k < 32; k++) { - bool8 r7; + for (k = 0; k < NUM_FRIEND_AREA_LOCATIONS; k++) { + bool8 valid; PixelPos pixelPos; s32 atanVal; - struct MapLocation *ptr2_18 = &gFriendAreasMapPtr->mapLocations[k]; - const struct FriendAreaLocation *location2 = &gFriendAreasMapPtr->locations[k]; + struct MapLocation *mapLocation2Info = &gFriendAreasMapPtr->mapLocations[k]; + const struct FriendAreaLocationInfo *location2Info = &gFriendAreasMapPtr->locationsInfo[k]; if (k == i) continue; - if (ptr2_18->isShown == 0) + if (!mapLocation2Info->isShown) continue; - pixelPos.x = (location2->pos.x - location->pos.x) << 8; - pixelPos.y = (location2->pos.y - location->pos.y) << 8; + pixelPos.x = (location2Info->pos.x - locationInfo->pos.x) << 8; + pixelPos.y = (location2Info->pos.y - locationInfo->pos.y) << 8; atanVal = Atan2_4096(&pixelPos); pixelPos.x /= 4; pixelPos.y /= 4; @@ -515,42 +517,42 @@ static void sub_800FC5C(u8 a0) pixelPos.y = 1; } - r7 = FALSE; - if (j == 2) { + valid = FALSE; + if (j == DIRECTION_EAST) { while (atanVal >= 0x1000) { atanVal -= 0x1000; } while (atanVal < 0) { atanVal += 0x1000; } - if (sAtanRanges[j].min < atanVal || sAtanRanges[j].max > atanVal) { - r7 = TRUE; + if (sDistanceRanges[j].min < atanVal || sDistanceRanges[j].max > atanVal) { + valid = TRUE; } } else { - if (sAtanRanges[j].min <= atanVal && sAtanRanges[j].max > atanVal) { - r7 = TRUE; + if (sDistanceRanges[j].min <= atanVal && sDistanceRanges[j].max > atanVal) { + valid = TRUE; } } - if (r7) { + if (valid) { s32 sum = (pixelPos.x * pixelPos.x) + (pixelPos.y * pixelPos.y); - if (var_3C > sum) { - var_3C = sum; - var_40 = k; + if (biggestDistance > sum) { + biggestDistance = sum; + foundLocationId = k; } } } - if (var_40 >= 0) { - r3->unk2[j] = var_40; + if (foundLocationId >= 0) { + mapLocation->locationsByDirection[j] = foundLocationId; } } } AxResInitFile(&gFriendAreasMapPtr->monAxSprite, gFriendAreasMapPtr->unk0[3], 0, 0, 0, 0, TRUE); - gFriendAreasMapPtr->unk4A18 = var_48; - gFriendAreasMapPtr->monSpritePos = gFriendAreasMapPtr->locations[var_48].pos; + gFriendAreasMapPtr->currLocationId = startingLocationId; + gFriendAreasMapPtr->monSpritePos = gFriendAreasMapPtr->locationsInfo[startingLocationId].pos; gFriendAreasMapPtr->bgPos.x = gFriendAreasMapPtr->monSpritePos.x - 120; gFriendAreasMapPtr->bgPos.y = gFriendAreasMapPtr->monSpritePos.y - 80; FriendAreasMap_UpdateMonSpritePosition(); @@ -566,62 +568,62 @@ bool8 IsFriendAreaShownOnMap(u8 friendAreaId) return FALSE; } -static u8 GetNewSelectedArea(void) +static u8 GetChosenDirection(void) { - u8 sp1[16] = {0xff, 0x00, 0x02, 0x01, 0x04, 0xff, 0x03, 0xff, 0x06, 0x07, 0xff, 0xff, 0x05, 0xff, 0xff, 0xff}; - u8 sp2[16] = {0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0x03, 0xff, 0xff, 0x07, 0xff, 0xff, 0x05, 0xff, 0xff, 0xff}; - u32 flag = 0; - u8 *table = (gRealInputs.held & R_BUTTON) ? sp2 : sp1; + u8 dirsAll[] = {0xff, DIRECTION_SOUTH, DIRECTION_EAST, DIRECTION_SOUTHEAST, DIRECTION_NORTH, 0xff, DIRECTION_NORTHEAST, 0xff, DIRECTION_WEST, DIRECTION_SOUTHWEST, 0xff, 0xff, DIRECTION_NORTHWEST, 0xff, 0xff, 0xff}; + u8 dirsDiagonal[] = {0xff, 0xff, 0xff, DIRECTION_SOUTHEAST, 0xff, 0xff, DIRECTION_NORTHEAST, 0xff, 0xff, DIRECTION_SOUTHWEST, 0xff, 0xff, DIRECTION_NORTHWEST, 0xff, 0xff, 0xff}; + u32 id = 0; + u8 *dirs = (gRealInputs.held & R_BUTTON) ? dirsDiagonal : dirsAll; if (gRealInputs.held & DPAD_DOWN) { - flag |= 1; + id |= 1; } if (gRealInputs.held & DPAD_RIGHT) { - flag |= 2; + id |= 2; } if (gRealInputs.held & DPAD_UP) { - flag |= 4; + id |= 4; } if (gRealInputs.held & DPAD_LEFT) { - flag |= 8; + id |= 8; } - if (gUnknown_202DE18 == table[flag]) { - if (++gUnknown_202DE19 >= 3) { - return table[flag]; + if (sCurrDirection == dirs[id]) { + if (++sHeldDpadCounter >= 3) { // It'll only choose a New Area, if the DPAD was held for more than 3 frames. + return dirs[id]; } } else { - gUnknown_202DE18 = table[flag]; - gUnknown_202DE19 = 0; + sCurrDirection = dirs[id]; + sHeldDpadCounter = 0; } return 0xFF; } -static void MoveToNewArea(s32 a0, s32 a1, s32 count) +static void MoveToNewLocation(s32 destLocationId, s32 a1, s32 nFrames) { - s32 i, arrayId; - DungeonPos pos1, pos2; + s32 i, currLocationId; + DungeonPos startingPos, dstPos; AxResInitFile(&gFriendAreasMapPtr->monAxSprite, gFriendAreasMapPtr->unk0[3], 0, a1 & 7, 0, 0, TRUE); FriendAreasMap_HideTextWindowAndArrows(); - arrayId = gFriendAreasMapPtr->unk4A18; - pos1 = gFriendAreasMapPtr->locations[arrayId].pos; - pos2 = gFriendAreasMapPtr->locations[a0].pos; + currLocationId = gFriendAreasMapPtr->currLocationId; + startingPos = gFriendAreasMapPtr->locationsInfo[currLocationId].pos; + dstPos = gFriendAreasMapPtr->locationsInfo[destLocationId].pos; PlayCursorUpDownSoundEffect(); - for (i = 0; i < count; i++) { - gFriendAreasMapPtr->monSpritePos.x = ((((pos2.x - pos1.x) * (i << 8)) / count) / 256) + pos1.x; - gFriendAreasMapPtr->monSpritePos.y = ((((pos2.y - pos1.y) * (i << 8)) / count) / 256) + pos1.y; + for (i = 0; i < nFrames; i++) { + gFriendAreasMapPtr->monSpritePos.x = ((((dstPos.x - startingPos.x) * (i << 8)) / nFrames) / 256) + startingPos.x; + gFriendAreasMapPtr->monSpritePos.y = ((((dstPos.y - startingPos.y) * (i << 8)) / nFrames) / 256) + startingPos.y; FriendAreasMap_UpdateMonSpritePosition(); FriendAreasMap_UpdateBg(); FriendAreasMap_RunFrameActions(); } - gFriendAreasMapPtr->unk4A18 = a0; - gFriendAreasMapPtr->monSpritePos = gFriendAreasMapPtr->locations[a0].pos; + gFriendAreasMapPtr->currLocationId = destLocationId; + gFriendAreasMapPtr->monSpritePos = gFriendAreasMapPtr->locationsInfo[destLocationId].pos; FriendAreasMap_UpdateMonSpritePosition(); FriendAreasMap_UpdateBg(); FriendAreasMap_RunFrameActions(); @@ -638,16 +640,16 @@ void PrintFriendAreaNameInMap(u8 *strBuffer, u8 index) } } -static UNUSED void sub_8010224(u8 areaId, DungeonPos *dst) +static UNUSED void GetAreaMapPosition(u8 areaId, DungeonPos *dst) { s32 i, j; - for (i = 0; i < 32; i++) { - const struct FriendAreaLocation *location = &gFriendAreaLocations[i]; - for (j = 0; j < 8; j++) { - if (location->areasIds[j] == areaId) { - dst->x = location->pos.x; - dst->y = location->pos.y; + for (i = 0; i < NUM_FRIEND_AREA_LOCATIONS; i++) { + const struct FriendAreaLocationInfo *locationInfo = &gFriendAreaLocations[i]; + for (j = 0; j < MAX_AREAS_PER_LOCATION; j++) { + if (locationInfo->areasIds[j] == areaId) { + dst->x = locationInfo->pos.x; + dst->y = locationInfo->pos.y; return; } } @@ -655,4 +657,3 @@ static UNUSED void sub_8010224(u8 areaId, DungeonPos *dst) dst->x = 0; dst->y = 0; } - diff --git a/src/friend_areas_map_util.c b/src/friend_areas_map_util.c index baf3d0648..0585052f2 100644 --- a/src/friend_areas_map_util.c +++ b/src/friend_areas_map_util.c @@ -57,7 +57,7 @@ static const DungeonPos gUnknown_80D40C4[] = {-24, 24}, }; -void sub_8010DA4(void) +void FriendAreasMap_InitGfx(void) { u8 filename[0xC]; s32 i, size; @@ -116,12 +116,12 @@ static void AnimateSprites(void) RunAxAnimationFrame(&gFriendAreasMapPtr->monAxSprite); DoAxFrame_800558C(&gFriendAreasMapPtr->monAxSprite, gFriendAreasMapPtr->monSpritePos.x - bgPos.x, gFriendAreasMapPtr->monSpritePos.y - bgPos.y, 3, gFriendAreasMapPtr->unk4DD0, &var_30); - for (i = 0; i < 32; i++) { - struct MapLocation *r0 = &gFriendAreasMapPtr->mapLocations[i]; - const struct FriendAreaLocation *location = &gFriendAreasMapPtr->locations[i]; - if (r0->isShown) { - RunAxAnimationFrame(&r0->unk14); - DoAxFrame_800558C(&r0->unk14, location->pos.x - bgPos.x, location->pos.y- bgPos.y, 1, 0, &var_30); + for (i = 0; i < NUM_FRIEND_AREA_LOCATIONS; i++) { + struct MapLocation *mapLocation = &gFriendAreasMapPtr->mapLocations[i]; + const struct FriendAreaLocationInfo *locationInfo = &gFriendAreasMapPtr->locationsInfo[i]; + if (mapLocation->isShown) { + RunAxAnimationFrame(&mapLocation->sprite); + DoAxFrame_800558C(&mapLocation->sprite, locationInfo->pos.x - bgPos.x, locationInfo->pos.y- bgPos.y, 1, 0, &var_30); } } @@ -241,13 +241,13 @@ void FriendAreasMap_UpdateMonSpritePosition(void) void FriendAreasMap_ShowDirectionArrows(void) { s32 i; - struct MapLocation *r9 = &gFriendAreasMapPtr->mapLocations[gFriendAreasMapPtr->unk4A18]; + struct MapLocation *currLocation = &gFriendAreasMapPtr->mapLocations[gFriendAreasMapPtr->currLocationId]; for (i = 0; i < NUM_DIRECTIONS; i++) { ResetFlags(&gFriendAreasMapPtr->arrowSprites[i]); - if (r9->unk2[i] >= 0) { - struct MapLocation *ptr = &gFriendAreasMapPtr->mapLocations[r9->unk2[i]]; - if (ptr->isShown != 0) { + if (currLocation->locationsByDirection[i] >= 0) { + struct MapLocation *ptr = &gFriendAreasMapPtr->mapLocations[currLocation->locationsByDirection[i]]; + if (ptr->isShown) { AxResInitFile(&gFriendAreasMapPtr->arrowSprites[i], gFriendAreasMapPtr->unk0[2], i + 4, 0, 0x40, 0, TRUE); } } @@ -257,8 +257,8 @@ void FriendAreasMap_ShowDirectionArrows(void) void FriendAreasMap_PrintCurrAreaName(void) { u8 txt[200]; - s32 id = gFriendAreasMapPtr->unk4A18; - const struct FriendAreaLocation *location = &gFriendAreasMapPtr->locations[id]; + s32 id = gFriendAreasMapPtr->currLocationId; + const struct FriendAreaLocationInfo *locationInfo = &gFriendAreasMapPtr->locationsInfo[id]; Windows windows = {0}; windows.id[0].type = WINDOW_TYPE_NORMAL; @@ -280,7 +280,7 @@ void FriendAreasMap_PrintCurrAreaName(void) ShowWindows(&windows, TRUE, TRUE); sub_80073B8(0); - sprintfStatic(txt, _("{CENTER_ALIGN}%s"), location->name); + sprintfStatic(txt, _("{CENTER_ALIGN}%s"), locationInfo->name); PrintFormattedStringOnWindow(12, 2, txt, 0, '\0'); sub_80073E0(0); gFriendAreasMapPtr->unk4DDC = (windows.id[0].pos.x * 8) - 5; @@ -292,8 +292,8 @@ void FriendAreasMap_PrintCurrAreaName(void) void FriendAreasMap_PrintAvailableSubAreas(void) { s32 i, count, var; - s32 id = gFriendAreasMapPtr->unk4A18; - const struct FriendAreaLocation *location = &gFriendAreasMapPtr->locations[id]; + s32 id = gFriendAreasMapPtr->currLocationId; + const struct FriendAreaLocationInfo *locationInfo = &gFriendAreasMapPtr->locationsInfo[id]; MenuInputStruct *menuInput = &gFriendAreasMapPtr->menu; WindowHeader header; Windows windows = { @@ -320,8 +320,8 @@ void FriendAreasMap_PrintAvailableSubAreas(void) count = 0; for (i = 0; i < MAX_AREAS_PER_LOCATION; i++) { - if (IsFriendAreaShownOnMap(location->areasIds[i])) { - gFriendAreasMapPtr->displayedAreas[count] = location->areasIds[i]; + if (IsFriendAreaShownOnMap(locationInfo->areasIds[i])) { + gFriendAreasMapPtr->displayedAreas[count] = locationInfo->areasIds[i]; count++; } } diff --git a/sym_ewram.txt b/sym_ewram.txt index 7e5738f9f..cd558365f 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -116,11 +116,7 @@ gUnknown_202DBB8: /* 202DBB8 (sub_800D6AC / data_80B9BB8) */ gUnknown_202DCF8: /* 202DCF8 (sub_80001E8 - sub_800D9B8) */ .space 0x120 -gUnknown_202DE18: /* 202DE18 (sub_800F990 - sub_8010014) */ - .space 0x1 -gUnknown_202DE19: /* 202DE19 (sub_800F990 - sub_8010014) */ - .space 0x3 - + .include "src/friend_areas_map.o" .include "src/code_80118A4.o" .space 0x2