diff --git a/Game/Dungeon/DungeonGeneratorV2.cs b/Game/Dungeon/DungeonGeneratorV2.cs index 2907259..3d8aaf4 100644 --- a/Game/Dungeon/DungeonGeneratorV2.cs +++ b/Game/Dungeon/DungeonGeneratorV2.cs @@ -1023,12 +1023,7 @@ public class DungeonGeneratorV2 }); } - // Corner fix-up pass: if a wall tile meets void on the outside but is adjacent to walkable - // only diagonally (common with thicker walls / multi-tile corridors), swap in the connected - // corner tile so the silhouette doesn't look "broken". - // - // Example: a boundary wall tile that is NW of a floor tile might not see floor South/East - // directly (those may be other wall tiles), but it *will* see floor at SE diagonally. + // Index existing wall visuals so we can update/replace them without duplicating TileDetails entries. var wallDetailIndex = new Dictionary<(int X, int Y), int>(); for (int i = 0; i < layout.TileDetails.Count; i++) { @@ -1037,6 +1032,78 @@ public class DungeonGeneratorV2 wallDetailIndex[(d.X, d.Y)] = i; } + // Void-corner fill pass: when corridors/walls are thicker, some corner "caps" end up as void tiles that + // only see walkable space diagonally. Fill those with the appropriate connected corner wall so we don't + // get little void bite-marks at corridor turns and room borders. + bool IsWallAt(int wx, int wy) + { + if (wx < 0 || wx >= MapWidth || wy < 0 || wy >= MapHeight) return false; + int tid = layout.Tiles[wx, wy]; + if (tid == 0) return false; + return _tileDefinitions.TryGetValue(tid, out var td) && td.Type == TileType.Wall; + } + + void PlaceWall(int wx, int wy, TileDefinition tdef) + { + layout.Tiles[wx, wy] = tdef.Id; + if (layout.Walkable != null) layout.Walkable[wx, wy] = false; + + if (wallDetailIndex.TryGetValue((wx, wy), out var existingIdx)) + { + var d = layout.TileDetails[existingIdx]; + d.TileDefinitionId = tdef.Id; + d.SheetId = tdef.TileMapSheetId; + d.FrameIndex = tdef.FrameIndex; + layout.TileDetails[existingIdx] = d; + } + else + { + wallDetailIndex[(wx, wy)] = layout.TileDetails.Count; + layout.TileDetails.Add(new PlacedTile + { + X = wx, + Y = wy, + TileDefinitionId = tdef.Id, + SheetId = tdef.TileMapSheetId, + FrameIndex = tdef.FrameIndex, + Layer = 2 + }); + } + } + + for (int x = 1; x < MapWidth - 1; x++) + { + for (int y = 1; y < MapHeight - 1; y++) + { + if (layout.Tiles[x, y] != 0) continue; // only fill void + // Don't overwrite walkable tiles (shouldn't happen because walkable implies non-zero, but safe). + if (layout.IsWalkable(x, y)) continue; + + bool floorNE = layout.IsWalkable(x + 1, y - 1); + bool floorNW = layout.IsWalkable(x - 1, y - 1); + bool floorSE = layout.IsWalkable(x + 1, y + 1); + bool floorSW = layout.IsWalkable(x - 1, y + 1); + + bool wallN = IsWallAt(x, y - 1); + bool wallS = IsWallAt(x, y + 1); + bool wallE = IsWallAt(x + 1, y); + bool wallW = IsWallAt(x - 1, y); + + // Only fill if there's "supporting" wall structure nearby; prevents random diagonal filling. + // The diagonal walkable indicates the interior corner; the adjacent walls indicate we are on the border. + if (floorSE && (wallS || wallE)) PlaceWall(x, y, wallCornerNW); + else if (floorSW && (wallS || wallW)) PlaceWall(x, y, wallCornerNE); + else if (floorNE && (wallN || wallE)) PlaceWall(x, y, wallCornerSW); + else if (floorNW && (wallN || wallW)) PlaceWall(x, y, wallCornerSE); + } + } + + // Corner fix-up pass: if a wall tile meets void on the outside but is adjacent to walkable + // only diagonally (common with thicker walls / multi-tile corridors), swap in the connected + // corner tile so the silhouette doesn't look "broken". + // + // Example: a boundary wall tile that is NW of a floor tile might not see floor South/East + // directly (those may be other wall tiles), but it *will* see floor at SE diagonally. for (int x = 1; x < MapWidth - 1; x++) { for (int y = 1; y < MapHeight - 1; y++)