diff --git a/include/dungeon_generation_fixed.h b/include/dungeon_generation_fixed.h index 12a3a3b93..fefa4cee7 100644 --- a/include/dungeon_generation_fixed.h +++ b/include/dungeon_generation_fixed.h @@ -4,7 +4,7 @@ #include "structs/dungeon_entity.h" #include "structs/map.h" -bool8 PlaceFixedRoomTile(Tile *tile, u8 a1, s32 x, s32 y, u8 a5); +bool8 PlaceFixedRoomTile(Tile *tile, u8 fixedRoomActionId, s32 x, s32 y, bool8 spawnTrapOrItem); void sub_8051E3C(void); void sub_8051E7C(Entity *pokemon); diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index c77234019..c31355867 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -5887,11 +5887,11 @@ static u8 sub_80511F0(void) return gUnknown_202F1E0; } -static bool8 sub_805124C(Tile *tile, u8 a1, s32 x, s32 y, u8 a5) +static bool8 sub_805124C(Tile *tile, u8 a1, s32 x, s32 y, bool8 spawnTrapOrItem) { tile->terrainType |= TERRAIN_TYPE_UNBREAKABLE; tile->unkE = 0; - return PlaceFixedRoomTile(tile, a1, x, y, a5); + return PlaceFixedRoomTile(tile, a1, x, y, spawnTrapOrItem); } static void sub_8051288(s32 fixedRoomNumber) @@ -5909,7 +5909,7 @@ static void sub_8051288(s32 fixedRoomNumber) for (y = 5; y < fixedRoomSizeY + 5; y++) { for (x = 5; x < fixedRoomSizeX + 5; x++) { u8 unk = sub_80511F0(); - if (sub_805124C(GetTileMut(x, y), unk, x, y, 1)) { + if (sub_805124C(GetTileMut(x, y), unk, x, y, TRUE)) { dungeon->stairsSpawn.x = x; dungeon->stairsSpawn.y = y; } @@ -5980,7 +5980,7 @@ static void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber) Tile *tile = GetTileMut(x, y); dungeon->unkE87C[xIndex][yIndex] = unk; - sub_805124C(&dungeon->unkE27C[xIndex][yIndex], unk, x, y, 0); + sub_805124C(&dungeon->unkE27C[xIndex][yIndex], unk, x, y, FALSE); roomId = tile->room; *tile = dungeon->unkE27C[xIndex][yIndex]; if (x >= gridCell->start.x + 2 && x < gridCell->end.x - 2 && y >= gridCell->start.y + 2 && y < gridCell->end.y - 2) { @@ -6001,7 +6001,7 @@ static void sub_8051438(struct GridCell *gridCell, s32 fixedRoomNumber) Tile *tile = GetTileMut(x, y); u8 roomId = tile->room; - sub_805124C(tile, unk, x, y, 1); + sub_805124C(tile, unk, x, y, TRUE); tile->room = roomId; dungeon->unkE8BC = roomId; } diff --git a/src/dungeon_generation_fixed.c b/src/dungeon_generation_fixed.c index cc12b79dd..58fa57278 100644 --- a/src/dungeon_generation_fixed.c +++ b/src/dungeon_generation_fixed.c @@ -11,13 +11,16 @@ #include "dungeon_message.h" #include "code_803E668.h" #include "structs/str_806B7F8.h" +#include "constants/monster.h" +#include "constants/trap.h" +#include "constants/item.h" extern s32 sub_803DA20(s16 species); extern void sub_80429FC(DungeonPos *r0); static bool8 sub_805210C(u8 itemId); -static void sub_805193C(u8 itemId, s32 x, s32 y, s32 quantity, u32 itemFlags) +static void SpawnItemAtPos(u8 itemId, s32 x, s32 y, s32 quantity, u32 itemFlags) { Item item; DungeonPos pos = {x, y}; @@ -38,7 +41,7 @@ static void sub_805193C(u8 itemId, s32 x, s32 y, s32 quantity, u32 itemFlags) } // s16 species memes strike again. Will the fix ever be discovered? -static void sub_8051998(s16 species_, s32 x, s32 y, u32 unk2_, u32 UNUSED unused) +static void SpawnSpeciesAtPos(s16 species_, s32 x, s32 y, u32 unk2_, u32 UNUSED unused) { struct unkStruct_806B7F8 unkStruct; s32 species = SpeciesId(species_); @@ -83,21 +86,21 @@ static void SpawnEnemyTrapAtPos(u8 trapId, s32 x, s32 y, bool8 isVisible) struct UnkStruct_80F6D20 { - u8 unk0; + u8 itemId; s16 unk2; u32 unk4; - s16 unk8; + s16 speciesId; u8 unkA; - u8 unkB; - u8 unkC; - u8 unkD; - u8 unkE; + u8 trapId; + u8 roomId; + bool8 trapVisible; + bool8 setTerrainToSecondary; }; extern const struct UnkStruct_80F6D20 gUnknown_80F6E20[]; // Used to spawn a single tile when generating a fixed room. The tile might contain an item or a monster. -bool8 PlaceFixedRoomTile(Tile *tile, u8 fixedRoomActionId, s32 x, s32 y, bool8 a5) +bool8 PlaceFixedRoomTile(Tile *tile, u8 fixedRoomActionId, s32 x, s32 y, bool8 spawnTrapOrItem) { if (fixedRoomActionId > 0xF) { SetTerrainNormal(tile); @@ -182,13 +185,13 @@ bool8 PlaceFixedRoomTile(Tile *tile, u8 fixedRoomActionId, s32 x, s32 y, bool8 a default: if (fixedRoomActionId >= 16 && fixedRoomActionId <= 219) { const struct UnkStruct_80F6D20 *ptr = &gUnknown_80F6E20[fixedRoomActionId - 16]; - tile->room = ptr->unkC; - if (ptr->unk0 != 0) { - if (a5) { - sub_805193C(ptr->unk0, x, y, ptr->unk2, ptr->unk4); + tile->room = ptr->roomId; + if (ptr->itemId != 0) { + if (spawnTrapOrItem) { + SpawnItemAtPos(ptr->itemId, x, y, ptr->unk2, ptr->unk4); } else { - gDungeon->unk644.unk47 = ptr->unk0; + gDungeon->unk644.unk47 = ptr->itemId; } } else { @@ -198,15 +201,15 @@ bool8 PlaceFixedRoomTile(Tile *tile, u8 fixedRoomActionId, s32 x, s32 y, bool8 a } } - if (ptr->unk8 != 0) { - sub_8051998(ptr->unk8, x, y, ptr->unkA, fixedRoomActionId); + if (ptr->speciesId != 0) { + SpawnSpeciesAtPos(ptr->speciesId, x, y, ptr->unkA, fixedRoomActionId); } - if (ptr->unkB != 20 && a5) { - SpawnEnemyTrapAtPos(ptr->unkB, x, y, ptr->unkD); + if (ptr->trapId != NUM_TRAPS && spawnTrapOrItem) { + SpawnEnemyTrapAtPos(ptr->trapId, x, y, ptr->trapVisible); } - if (ptr->unkE != 0) { + if (ptr->setTerrainToSecondary) { SetTerrainSecondary(tile); } }