diff --git a/Game/Dungeon/DungeonGeneratorVNext.cs b/Game/Dungeon/DungeonGeneratorVNext.cs index 71b9e9c..0b6c839 100644 --- a/Game/Dungeon/DungeonGeneratorVNext.cs +++ b/Game/Dungeon/DungeonGeneratorVNext.cs @@ -532,13 +532,24 @@ public class DungeonGeneratorVNext foreach (var cell in wallCells) { int mask8 = ComputeEightDirectionMask(layout, cell.X, cell.Y); + TileDefinition? wallDef = null; string? directionalBucket = ResolveDirectionalWallBucket(mask8); - if (string.IsNullOrEmpty(directionalBucket)) + if (!string.IsNullOrEmpty(directionalBucket)) { - continue; + wallDef = SelectWallDefinitionForBucket(tileContext, directionalBucket); + } + else + { + foreach (var fallbackBucket in ResolveDirectionalFallbackBuckets(mask8)) + { + wallDef = SelectWallDefinitionForBucket(tileContext, fallbackBucket); + if (wallDef != null) + { + break; + } + } } - TileDefinition? wallDef = SelectWallDefinitionForBucket(tileContext, directionalBucket); if (wallDef == null) { continue; @@ -823,6 +834,46 @@ public class DungeonGeneratorVNext return null; } + private static IEnumerable ResolveDirectionalFallbackBuckets(int mask8) + { + // Bit order N, NE, E, SE, S, SW, W, NW. + bool n = (mask8 & 0b1000_0000) != 0; + bool e = (mask8 & 0b0010_0000) != 0; + bool s = (mask8 & 0b0000_1000) != 0; + bool w = (mask8 & 0b0000_0010) != 0; + bool ne = (mask8 & 0b0100_0000) != 0; + bool se = (mask8 & 0b0001_0000) != 0; + bool sw = (mask8 & 0b0000_0100) != 0; + bool nw = (mask8 & 0b0000_0001) != 0; + + // Prefer large corner profiles if adjacent cardinals exist. + if (n && w) yield return "NWCornerLarge"; + if (n && e) yield return "NECornerLarge"; + if (s && e) yield return "SECornerLarge"; + if (s && w) yield return "SWCornerLarge"; + + // Cardinal fallbacks for 3-way / complex masks. + if (n) yield return "Wall_N"; + if (e) yield return "Wall_E"; + if (s) yield return "Wall_S"; + if (w) yield return "Wall_W"; + + // If no cardinal bits exist, allow single-diagonal corners. + if (!n && !e && !s && !w) + { + if (nw) yield return "NWCornerSingle"; + if (ne) yield return "NECornerSingle"; + if (se) yield return "SECornerSingle"; + if (sw) yield return "SWCornerSingle"; + } + + // Last-resort directional defaults to avoid untiled wall cells. + yield return "Wall_N"; + yield return "Wall_E"; + yield return "Wall_S"; + yield return "Wall_W"; + } + private sealed record TileBuildContext( Dictionary SheetsById, List FloorCandidates,