From 40ab73f3f84bed3d334dfc91c523d1ea59268f9d Mon Sep 17 00:00:00 2001 From: dingo Date: Fri, 2 Jan 2026 10:30:58 -0500 Subject: [PATCH] Tile fixes --- Game/Dungeon/DungeonGeneratorV2.cs | 58 ++++++++++++++++++------------ 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/Game/Dungeon/DungeonGeneratorV2.cs b/Game/Dungeon/DungeonGeneratorV2.cs index 64e2cf5..e037c85 100644 --- a/Game/Dungeon/DungeonGeneratorV2.cs +++ b/Game/Dungeon/DungeonGeneratorV2.cs @@ -86,7 +86,7 @@ public class DungeonGeneratorV2 /// /// Whether to use strict column-based sockets (true) or legacy tag-based (false) /// - private bool _useStrictSockets = true; + private bool _useStrictSockets = false; private static HashSet ParseTags(string? tags) { @@ -495,6 +495,17 @@ public class DungeonGeneratorV2 // STRICT SOCKET MATCHING METHODS (Column-based) // ========================================================================= + /// + /// Check if a neighbor cell has an actually placed tile (not just marked walkable) + /// This is critical because CarveBasicRoom marks cells walkable BEFORE placing tiles + /// + private bool HasPlacedTile(DungeonLayoutV2 layout, int x, int y) + { + if (x < 0 || x >= layout.Width || y < 0 || y >= layout.Height) + return false; + return layout.Tiles[x, y] > 0; // Actually has a tile ID assigned + } + /// /// Get socket ID for a tile edge using column-based system /// @@ -520,11 +531,12 @@ public class DungeonGeneratorV2 /// /// Check if a tile is compatible with all placed neighbors using strict matching + /// Uses HasPlacedTile to only check neighbors that actually have tiles assigned /// private bool IsCompatibleWithNeighborsStrict(DungeonLayoutV2 layout, int x, int y, int tileId) { // Check North neighbor (their S edge vs our N edge) - if (y > 0 && layout.IsWalkable(x, y - 1)) + if (y > 0 && HasPlacedTile(layout, x, y - 1)) { int neighborId = layout.Tiles[x, y - 1]; if (!AreSocketsCompatibleStrict(tileId, "N", neighborId, "S")) @@ -532,7 +544,7 @@ public class DungeonGeneratorV2 } // Check South neighbor (their N edge vs our S edge) - if (y < layout.Height - 1 && layout.IsWalkable(x, y + 1)) + if (y < layout.Height - 1 && HasPlacedTile(layout, x, y + 1)) { int neighborId = layout.Tiles[x, y + 1]; if (!AreSocketsCompatibleStrict(tileId, "S", neighborId, "N")) @@ -540,7 +552,7 @@ public class DungeonGeneratorV2 } // Check West neighbor (their E edge vs our W edge) - if (x > 0 && layout.IsWalkable(x - 1, y)) + if (x > 0 && HasPlacedTile(layout, x - 1, y)) { int neighborId = layout.Tiles[x - 1, y]; if (!AreSocketsCompatibleStrict(tileId, "W", neighborId, "E")) @@ -548,7 +560,7 @@ public class DungeonGeneratorV2 } // Check East neighbor (their W edge vs our E edge) - if (x < layout.Width - 1 && layout.IsWalkable(x + 1, y)) + if (x < layout.Width - 1 && HasPlacedTile(layout, x + 1, y)) { int neighborId = layout.Tiles[x + 1, y]; if (!AreSocketsCompatibleStrict(tileId, "E", neighborId, "W")) @@ -560,31 +572,32 @@ public class DungeonGeneratorV2 /// /// Build required socket types from neighbors using strict matching + /// Uses HasPlacedTile to only consider neighbors that actually have tiles assigned /// private Dictionary GetRequiredSocketsStrict(DungeonLayoutV2 layout, int x, int y) { var required = new Dictionary(StringComparer.OrdinalIgnoreCase); // North neighbor's S edge determines our N requirement - if (y > 0 && layout.IsWalkable(x, y - 1)) + if (y > 0 && HasPlacedTile(layout, x, y - 1)) { required["N"] = GetSocketIdStrict(layout.Tiles[x, y - 1], "S"); } // South neighbor's N edge determines our S requirement - if (y < layout.Height - 1 && layout.IsWalkable(x, y + 1)) + if (y < layout.Height - 1 && HasPlacedTile(layout, x, y + 1)) { required["S"] = GetSocketIdStrict(layout.Tiles[x, y + 1], "N"); } // West neighbor's E edge determines our W requirement - if (x > 0 && layout.IsWalkable(x - 1, y)) + if (x > 0 && HasPlacedTile(layout, x - 1, y)) { required["W"] = GetSocketIdStrict(layout.Tiles[x - 1, y], "E"); } // East neighbor's W edge determines our E requirement - if (x < layout.Width - 1 && layout.IsWalkable(x + 1, y)) + if (x < layout.Width - 1 && HasPlacedTile(layout, x + 1, y)) { required["E"] = GetSocketIdStrict(layout.Tiles[x + 1, y], "W"); } @@ -1004,7 +1017,8 @@ public class DungeonGeneratorV2 if (x < 0 || x >= MapWidth || y < 0 || y >= MapHeight) continue; - if (!layout.IsWalkable(x, y)) + // Only repair cells that have placed tiles + if (!HasPlacedTile(layout, x, y)) continue; int id = layout.Tiles[x, y]; @@ -1057,28 +1071,28 @@ public class DungeonGeneratorV2 { var req = new List(); - if (y > 0 && layout.IsWalkable(x, y - 1)) + if (y > 0 && HasPlacedTile(layout, x, y - 1)) { int nid = layout.Tiles[x, y - 1]; var r = GetRequiredSocketTagFromNeighbor(nid, neighborEdgeFacingUs: "S", ourDir: "N"); if (r != null) req.Add(r); } - if (y < MapHeight - 1 && layout.IsWalkable(x, y + 1)) + if (y < MapHeight - 1 && HasPlacedTile(layout, x, y + 1)) { int sid = layout.Tiles[x, y + 1]; var r = GetRequiredSocketTagFromNeighbor(sid, neighborEdgeFacingUs: "N", ourDir: "S"); if (r != null) req.Add(r); } - if (x > 0 && layout.IsWalkable(x - 1, y)) + if (x > 0 && HasPlacedTile(layout, x - 1, y)) { int wid = layout.Tiles[x - 1, y]; var r = GetRequiredSocketTagFromNeighbor(wid, neighborEdgeFacingUs: "E", ourDir: "W"); if (r != null) req.Add(r); } - if (x < MapWidth - 1 && layout.IsWalkable(x + 1, y)) + if (x < MapWidth - 1 && HasPlacedTile(layout, x + 1, y)) { int eid = layout.Tiles[x + 1, y]; var r = GetRequiredSocketTagFromNeighbor(eid, neighborEdgeFacingUs: "W", ourDir: "E"); @@ -1126,19 +1140,19 @@ public class DungeonGeneratorV2 private bool CompatibleWithAllNeighbors( DungeonLayoutV2 layout, int x, int y, TileDefinition t) { - if (y > 0 && layout.IsWalkable(x, y - 1)) + if (y > 0 && HasPlacedTile(layout, x, y - 1)) if (!EdgeSocketsCompatible(t.Id, "N", layout.Tiles[x, y - 1], "S")) return false; - if (y < layout.Height - 1 && layout.IsWalkable(x, y + 1)) + if (y < layout.Height - 1 && HasPlacedTile(layout, x, y + 1)) if (!EdgeSocketsCompatible(t.Id, "S", layout.Tiles[x, y + 1], "N")) return false; - if (x > 0 && layout.IsWalkable(x - 1, y)) + if (x > 0 && HasPlacedTile(layout, x - 1, y)) if (!EdgeSocketsCompatible(t.Id, "W", layout.Tiles[x - 1, y], "E")) return false; - if (x < layout.Width - 1 && layout.IsWalkable(x + 1, y)) + if (x < layout.Width - 1 && HasPlacedTile(layout, x + 1, y)) if (!EdgeSocketsCompatible(t.Id, "E", layout.Tiles[x + 1, y], "W")) return false; @@ -1841,14 +1855,14 @@ public class DungeonGeneratorV2 private bool CompatibleWithPlacedNeighbors(DungeonLayoutV2 layout, int x, int y, TileDefinition t) { - if (y > 0 && layout.IsWalkable(x, y - 1)) + if (y > 0 && HasPlacedTile(layout, x, y - 1)) { int nId = layout.Tiles[x, y - 1]; if (!EdgeSocketsCompatible(t.Id, "N", nId, "S")) return false; } - if (x > 0 && layout.IsWalkable(x - 1, y)) + if (x > 0 && HasPlacedTile(layout, x - 1, y)) { int wId = layout.Tiles[x - 1, y]; if (!EdgeSocketsCompatible(t.Id, "W", wId, "E")) @@ -1894,14 +1908,14 @@ public class DungeonGeneratorV2 { var req = new List(); - if (y > 0 && layout.IsWalkable(x, y - 1)) + if (y > 0 && HasPlacedTile(layout, x, y - 1)) { int nid = layout.Tiles[x, y - 1]; var r = GetRequiredSocketTagFromNeighbor(nid, neighborEdgeFacingUs: "S", ourDir: "N"); if (r != null) req.Add(r); } - if (x > 0 && layout.IsWalkable(x - 1, y)) + if (x > 0 && HasPlacedTile(layout, x - 1, y)) { int wid = layout.Tiles[x - 1, y]; var r = GetRequiredSocketTagFromNeighbor(wid, neighborEdgeFacingUs: "E", ourDir: "W");