diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index e28d7f172..4cc3e1232 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -120,12 +120,12 @@ typedef struct UnkDungeonGlobal_unk181E8_sub typedef struct FloorProperties { u8 layout; - s8 roomDensity; + s8 roomDensity; // If positive, allow variance. If negative, use exact value of abs(roomDensity). u8 tileset; u8 bgMusic; u8 weather; // Uses the weather constants in weather.h. u8 floorConnectivity; - u8 enemyDensity; + u8 enemyDensity; // Game treats this as signed. See SpawnEnemies in src/dungeon_generation.asm for details. u8 kecleonShopChance; // Percentage chance 0-100% u8 monsterHouseChance; // Percentage chance 0-100% u8 mazeRoomChance; // Percentage chance 0-100% diff --git a/src/dungeon_generation.c b/src/dungeon_generation.c index 8e5a6d298..8e36ec2e1 100644 --- a/src/dungeon_generation.c +++ b/src/dungeon_generation.c @@ -4423,6 +4423,9 @@ static void SpawnEnemies(FloorProperties *floorProps, bool8 isEmptyMonsterHouse) s32 numEnemies, numMonsterHouseEnemies; s32 enemyDensity = floorProps->enemyDensity; + // BUG: Game assumes floorProps->enemyDensity is a signed byte, but in reality it's unsigned. + // Attempting to use a negative density will instead produce a very large positive density up to 255. + // This only matters for unused dungeons, as Deoxys has its own logic despite Meteor Cave having an effective enemy density of 255. if (enemyDensity > 0) { // Positive means value with variance numEnemies = DungeonRandRange(enemyDensity / 2, enemyDensity);