diff options
Diffstat (limited to 'arm9/src')
-rw-r--r-- | arm9/src/map_header.c | 100 | ||||
-rw-r--r-- | arm9/src/map_matrix.c | 231 |
2 files changed, 289 insertions, 42 deletions
diff --git a/arm9/src/map_header.c b/arm9/src/map_header.c index 644a590b..49f8e986 100644 --- a/arm9/src/map_header.c +++ b/arm9/src/map_header.c @@ -1,39 +1,55 @@ #include "global.h" #include "map_header.h" #include "constants/map_sections.h" +#include "pokemon.h" #pragma thumb on // Static decls u32 MapNumberBoundsCheck(u32 mapno); -const u16 UNK_020EED54[] = { - 0x01A5, 0x01AD, 0x01B4, 0x01BC, 0x01C5, 0x01CC, 0x0007, 0x0025, - 0x0031, 0x01EF, 0x0046, 0x0066, 0x007C, 0x0087, 0x0098, 0x00A9, - 0x00AE, 0x00BE +static const u16 sPokemonCenterSecondFloorMaps[] = { + 421, + 429, + 436, + 444, + 453, + 460, + 7, + 37, + 49, + 495, + 70, + 102, + 124, + 135, + 152, + 169, + 174, + 190 }; -const u16 UNK_020EED78[] = { - 0x0181, 0x001A, - 0x00CB, 0x0019, - 0x00CF, 0x0018, - 0x00D0, 0x0018, - 0x00D1, 0x0018, - 0x00D2, 0x0018, - 0x00D3, 0x0018, - 0x00D4, 0x0018, - 0x00D5, 0x0018, - 0x00D6, 0x0018, - 0x00D7, 0x0018, - 0x00D8, 0x0018, - 0x00D9, 0x0018, - 0x00DA, 0x0018, - 0x00DB, 0x0018, - 0x00DC, 0x0018, - 0x00DD, 0x0018, +static const u16 sMapEvolutionMethods[] = { + 385, EVO_ROUTE217, + 203, EVO_ETERNA, + 207, EVO_CORONET, + 208, EVO_CORONET, + 209, EVO_CORONET, + 210, EVO_CORONET, + 211, EVO_CORONET, + 212, EVO_CORONET, + 213, EVO_CORONET, + 214, EVO_CORONET, + 215, EVO_CORONET, + 216, EVO_CORONET, + 217, EVO_CORONET, + 218, EVO_CORONET, + 219, EVO_CORONET, + 220, EVO_CORONET, + 221, EVO_CORONET, }; -const struct MapHeader sMapHeaders[] = { +static const struct MapHeader sMapHeaders[] = { { 0x0, 0x0, 0x0, 0x170, 0x33b, 0x12, 0x3e8, 0x3e8, 0xffff, 0x0, MAPSEC_MYSTERY_ZONE, 0x0, 0x0, 0x2, 3, TRUE, TRUE, TRUE, FALSE }, { 0x0, 0x0, 0x0, 0x170, 0x33b, 0x12, 0x3e8, 0x3e8, 0xffff, 0x0, MAPSEC_MYSTERY_ZONE, 0x0, 0x0, 0x0, 3, FALSE, FALSE, FALSE, FALSE }, { 0x2, 0x2, 0x2, 0x413, 0x3ca, 0x236, 0x424, 0x424, 0xffff, 0x1, MAPSEC_MYSTERY_ZONE, 0x0, 0x0, 0x6, 3, FALSE, FALSE, FALSE, FALSE }, @@ -694,16 +710,16 @@ u8 MapHeader_GetCameraType(u32 mapno) return sMapHeaders[mapno].camera_type; } -u8 MapHeader_GetField17_0(u32 mapno) +u8 MapHeader_GetBattleBg(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unk17_0; + return sMapHeaders[mapno].battle_bg; } -u8 MapHeader_GetField17_6(u32 mapno) +u8 MapHeader_IsEscapeRopeAllowed(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unk17_6; + return sMapHeaders[mapno].is_escape_rope_allowed; } u8 MapHeader_IsFlyAllowed(u32 mapno) @@ -733,7 +749,7 @@ BOOL FUN_020348E4(u32 mapno) return FALSE; } -BOOL MapHeader_MapIsOnOverworldMatrix(u32 mapno) +BOOL MapHeader_MapIsOnMainMatrix(u32 mapno) { return MapHeader_GetMatrixId(mapno) == 0; } @@ -760,56 +776,56 @@ BOOL FUN_02034964(u32 mapno) BOOL FUN_02034984(u32 mapno) { - return !!FUN_0203491C(mapno); + return FUN_0203491C(mapno) != FALSE; } -BOOL FUN_02034998(u32 mapno) +BOOL MapHeader_MapIsUnionRoom(u32 mapno) { return mapno == 466; } -BOOL FUN_020349AC(u32 mapno) +BOOL MapHeader_MapIsMtCoronetFeebasRoom(u32 mapno) { return mapno == 219; } -BOOL FUN_020349B8(u32 mapno) +BOOL MapHeader_MapIsTrophyGarden(u32 mapno) { return mapno == 287; } -BOOL FUN_020349CC(u32 mapno) +BOOL MapHeader_MapIsAmitySquare(u32 mapno) { return mapno == 253; } -BOOL FUN_020349D8(u32 mapno) +BOOL MapHeader_MapIsSpearPillar(u32 mapno) { return mapno == 220; } -BOOL FUN_020349E4(u16 a0) +BOOL MapHeader_MapIsPokemonCenterSecondFloor(u32 mapno) { int i; - for (i = 0; i < NELEMS(UNK_020EED54); i++) + for (i = 0; i < NELEMS(sPokemonCenterSecondFloorMaps); i++) { - if (a0 == UNK_020EED54[i]) + if (mapno == sPokemonCenterSecondFloorMaps[i]) return TRUE; } return FALSE; } -u16 FUN_02034A04(u16 a0) +u16 MapHeader_GetMapEvolutionMethod(u32 mapno) { int i; - for (i = 0; i < NELEMS(UNK_020EED78); i += 2) + for (i = 0; i < NELEMS(sMapEvolutionMethods); i += 2) { - if (a0 == UNK_020EED78[i + 0]) - return UNK_020EED78[i + 1]; + if (mapno == sMapEvolutionMethods[i + 0]) + return sMapEvolutionMethods[i + 1]; } - return 0; + return EVO_NONE; } diff --git a/arm9/src/map_matrix.c b/arm9/src/map_matrix.c new file mode 100644 index 00000000..1808d82c --- /dev/null +++ b/arm9/src/map_matrix.c @@ -0,0 +1,231 @@ +#include "global.h" +#include "map_matrix.h" +#include "MI_memory.h" +#include "filesystem.h" +#include "heap.h" +#include "map_header.h" + +THUMB_FUNC static void MapMatrix_MapMatrixData_Load( + struct MapMatrixData *map_matrix, u16 file_id, u32 map_id) +{ + map_matrix->width = 0; + map_matrix->height = 0; + + s32 i; + for (i = 0; i < MAP_MATRIX_MAX_SIZE; i++) + { + map_matrix->headers[i] = 0; + map_matrix->altitudes[i] = 0; + map_matrix->maps.data[i] = 0; + } + + for (i = 0; i < MAP_MATRIX_MAX_NAME_LENGTH; i++) + { + map_matrix->name[i] = 0; + } + + void *buffer = + AllocAtEndAndReadWholeNarcMemberByIdPair(NARC_FIELDDATA_MAPMATRIX_MAP_MATRIX, file_id, 11); + u8 *cursor = (u8 *)buffer; + + map_matrix->width = *(cursor++); + map_matrix->height = *(cursor++); + u8 has_headers_section = *(cursor++); + u8 has_altitudes_section = *(cursor++); + u8 name_length = *(cursor++); + + GF_ASSERT(name_length <= MAP_MATRIX_MAX_NAME_LENGTH); + + MI_CpuCopy8(cursor, &map_matrix->name, name_length); + cursor += name_length; + + if (has_headers_section != 0) + { + MI_CpuCopy8( + cursor, &map_matrix->headers, map_matrix->width * map_matrix->height * sizeof(u16)); + cursor += map_matrix->width * map_matrix->height * sizeof(u16); + } + else + { + MIi_CpuClear16((u16)map_id, + &map_matrix->headers, + map_matrix->width * map_matrix->height * sizeof(u16)); + } + + if (has_altitudes_section != 0) + { + MI_CpuCopy8( + cursor, &map_matrix->altitudes, map_matrix->width * map_matrix->height * sizeof(u8)); + cursor += map_matrix->width * map_matrix->height * sizeof(u8); + } + + MI_CpuCopy8( + cursor, map_matrix->maps.data, map_matrix->width * map_matrix->height * sizeof(u16)); + FreeToHeap(buffer); +} + +THUMB_FUNC struct MapMatrix *MapMatrix_New(void) +{ + struct MapMatrix *map_matrix = AllocFromHeap(11, sizeof(struct MapMatrix)); + + map_matrix->width = 0; + map_matrix->height = 0; + map_matrix->matrix_id = 0; + + return map_matrix; +} + +THUMB_FUNC void MapMatrix_Load(u16 map_id, struct MapMatrix *map_matrix) +{ + u16 matrix_id = MapHeader_GetMatrixId(map_id); + + MapMatrix_MapMatrixData_Load(&map_matrix->data, matrix_id, map_id); + + map_matrix->matrix_id = (u8)matrix_id; + map_matrix->height = map_matrix->data.height; + map_matrix->width = map_matrix->data.width; +} + +THUMB_FUNC void MapMatrix_Free(struct MapMatrix *map_matrix) +{ + FreeToHeap(map_matrix); +} + +THUMB_FUNC u16 MapMatrix_GetMapData(s32 map_id, struct MapMatrix *map_matrix) +{ + GF_ASSERT(map_id < map_matrix->width * map_matrix->height); + + return map_matrix->data.maps.data[map_id]; +} + +THUMB_FUNC u8 MapMatrix_GetWidth(struct MapMatrix *map_matrix) +{ + GF_ASSERT(map_matrix != NULL); + + return map_matrix->width; +} + +THUMB_FUNC u8 MapMatrix_GetHeight(struct MapMatrix *map_matrix) +{ + GF_ASSERT(map_matrix != NULL); + + return map_matrix->height; +} + +THUMB_FUNC u16 MapMatrix_GetMapHeader(struct MapMatrix *map_matrix, s32 x, s32 y) +{ + s32 width = map_matrix->width; + s32 height = map_matrix->height; + + GF_ASSERT(x >= 0 && x < width); + GF_ASSERT(y >= 0 && y < height); + + return map_matrix->data.headers[y * width + x]; +} + +THUMB_FUNC u16 MapMatrix_GetMapHeaderFromID(struct MapMatrix *map_matrix, s32 map_id) +{ + s32 max_map_id = map_matrix->width * map_matrix->height; + + GF_ASSERT(0 <= map_id && map_id < max_map_id); + + return map_matrix->data.headers[map_id]; +} + +THUMB_FUNC u8 MapMatrix_GetMatrixID(struct MapMatrix *map_matrix) +{ + return map_matrix->matrix_id; +} + +THUMB_FUNC u32 MapMatrix_GetMapAltitude( + struct MapMatrix *map_matrix, u8 param1, s16 x, s16 y, int matrix_width) +{ +#pragma unused(param1) + GF_ASSERT(x < matrix_width); + GF_ASSERT(y * matrix_width + x < MAP_MATRIX_MAX_SIZE); + + return map_matrix->data.altitudes[y * matrix_width + x]; +} + +THUMB_FUNC struct MapData *MapMatrix_MapData_New(u32 heap_id) +{ + struct MapData *map_data = AllocFromHeap(heap_id, sizeof(struct MapData)); + void *buffer = + AllocAtEndAndReadWholeNarcMemberByIdPair(NARC_FIELDDATA_MAPMATRIX_MAP_MATRIX, 0, heap_id); + u8 *cursor = (u8 *)buffer; + + cursor += 4; + u8 name_length = *cursor; + cursor++; + cursor += name_length; + + MI_CpuCopy8(cursor, map_data, sizeof(struct MapData)); + FreeToHeap(buffer); + + return map_data; +} + +THUMB_FUNC void MapMatrix_MapData_Free(struct MapData *map_data) +{ + GF_ASSERT(map_data != NULL); + FreeToHeap(map_data); +} + +THUMB_FUNC u16 MapMatrix_MapData_GetData(struct MapData *map_data, s32 x, s32 y) +{ + return map_data->data[MAP_MATRIX_MAX_WIDTH * y + x]; +} + +THUMB_FUNC u16 GetMapHeader(u32 file_id, u16 x, u16 y) +{ + struct MapMatrixData map_matrix; + + MapMatrix_MapMatrixData_Load(&map_matrix, (u16)file_id, 0); + GF_ASSERT(x < map_matrix.width); + GF_ASSERT(y < map_matrix.height); + + return map_matrix.headers[y * map_matrix.width + x]; +} + +THUMB_FUNC u16 GetMapData(s32 map_id, struct MapMatrix *map_matrix) +{ + GF_ASSERT(map_matrix != NULL); + return MapMatrix_GetMapData(map_id, map_matrix); +} + +THUMB_FUNC void FUN_02034678(struct MapMatrix *map_matrix) +{ + u16 *maps = map_matrix->data.maps.data; + u8 *altitudes = map_matrix->data.altitudes; + u8 width = map_matrix->width; + + if (map_matrix->matrix_id != 0) + { + return; + } + + maps[width * 0x15 + 0x17] = 0xB0; + maps[width * 0x15 + 0x18] = 0xB0; + maps[width * 0x16 + 0x17] = 0xB0; + maps[width * 0x16 + 0x18] = 0xB0; + altitudes[width * 0x15 + 0x17] = 2; + altitudes[width * 0x15 + 0x18] = 2; + altitudes[width * 0x16 + 0x17] = 2; + altitudes[width * 0x16 + 0x18] = 2; +} + +THUMB_FUNC void FUN_020346CC(struct MapMatrix *map_matrix) +{ + u16 *maps = map_matrix->data.maps.data; + u8 width = map_matrix->width; + + if (map_matrix->matrix_id != 0) + { + return; + } + + maps[width * 0x0F + 0x1C] = 0x77; + maps[width * 0x10 + 0x1B] = 0x78; + maps[width * 0x10 + 0x1C] = 0x79; + maps[width * 0x11 + 0x1B] = 0x7A; +} |