Tile fixes
This commit is contained in:
@@ -86,7 +86,7 @@ public class DungeonGeneratorV2
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether to use strict column-based sockets (true) or legacy tag-based (false)
|
/// Whether to use strict column-based sockets (true) or legacy tag-based (false)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool _useStrictSockets = true;
|
private bool _useStrictSockets = false;
|
||||||
|
|
||||||
private static HashSet<string> ParseTags(string? tags)
|
private static HashSet<string> ParseTags(string? tags)
|
||||||
{
|
{
|
||||||
@@ -495,6 +495,17 @@ public class DungeonGeneratorV2
|
|||||||
// STRICT SOCKET MATCHING METHODS (Column-based)
|
// STRICT SOCKET MATCHING METHODS (Column-based)
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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
|
||||||
|
/// </summary>
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get socket ID for a tile edge using column-based system
|
/// Get socket ID for a tile edge using column-based system
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -520,11 +531,12 @@ public class DungeonGeneratorV2
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if a tile is compatible with all placed neighbors using strict matching
|
/// Check if a tile is compatible with all placed neighbors using strict matching
|
||||||
|
/// Uses HasPlacedTile to only check neighbors that actually have tiles assigned
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool IsCompatibleWithNeighborsStrict(DungeonLayoutV2 layout, int x, int y, int tileId)
|
private bool IsCompatibleWithNeighborsStrict(DungeonLayoutV2 layout, int x, int y, int tileId)
|
||||||
{
|
{
|
||||||
// Check North neighbor (their S edge vs our N edge)
|
// 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];
|
int neighborId = layout.Tiles[x, y - 1];
|
||||||
if (!AreSocketsCompatibleStrict(tileId, "N", neighborId, "S"))
|
if (!AreSocketsCompatibleStrict(tileId, "N", neighborId, "S"))
|
||||||
@@ -532,7 +544,7 @@ public class DungeonGeneratorV2
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check South neighbor (their N edge vs our S edge)
|
// 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];
|
int neighborId = layout.Tiles[x, y + 1];
|
||||||
if (!AreSocketsCompatibleStrict(tileId, "S", neighborId, "N"))
|
if (!AreSocketsCompatibleStrict(tileId, "S", neighborId, "N"))
|
||||||
@@ -540,7 +552,7 @@ public class DungeonGeneratorV2
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check West neighbor (their E edge vs our W edge)
|
// 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];
|
int neighborId = layout.Tiles[x - 1, y];
|
||||||
if (!AreSocketsCompatibleStrict(tileId, "W", neighborId, "E"))
|
if (!AreSocketsCompatibleStrict(tileId, "W", neighborId, "E"))
|
||||||
@@ -548,7 +560,7 @@ public class DungeonGeneratorV2
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check East neighbor (their W edge vs our E edge)
|
// 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];
|
int neighborId = layout.Tiles[x + 1, y];
|
||||||
if (!AreSocketsCompatibleStrict(tileId, "E", neighborId, "W"))
|
if (!AreSocketsCompatibleStrict(tileId, "E", neighborId, "W"))
|
||||||
@@ -560,31 +572,32 @@ public class DungeonGeneratorV2
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Build required socket types from neighbors using strict matching
|
/// Build required socket types from neighbors using strict matching
|
||||||
|
/// Uses HasPlacedTile to only consider neighbors that actually have tiles assigned
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private Dictionary<string, string> GetRequiredSocketsStrict(DungeonLayoutV2 layout, int x, int y)
|
private Dictionary<string, string> GetRequiredSocketsStrict(DungeonLayoutV2 layout, int x, int y)
|
||||||
{
|
{
|
||||||
var required = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
var required = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
// North neighbor's S edge determines our N requirement
|
// 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");
|
required["N"] = GetSocketIdStrict(layout.Tiles[x, y - 1], "S");
|
||||||
}
|
}
|
||||||
|
|
||||||
// South neighbor's N edge determines our S requirement
|
// 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");
|
required["S"] = GetSocketIdStrict(layout.Tiles[x, y + 1], "N");
|
||||||
}
|
}
|
||||||
|
|
||||||
// West neighbor's E edge determines our W requirement
|
// 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");
|
required["W"] = GetSocketIdStrict(layout.Tiles[x - 1, y], "E");
|
||||||
}
|
}
|
||||||
|
|
||||||
// East neighbor's W edge determines our E requirement
|
// 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");
|
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)
|
if (x < 0 || x >= MapWidth || y < 0 || y >= MapHeight)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!layout.IsWalkable(x, y))
|
// Only repair cells that have placed tiles
|
||||||
|
if (!HasPlacedTile(layout, x, y))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int id = layout.Tiles[x, y];
|
int id = layout.Tiles[x, y];
|
||||||
@@ -1057,28 +1071,28 @@ public class DungeonGeneratorV2
|
|||||||
{
|
{
|
||||||
var req = new List<string>();
|
var req = new List<string>();
|
||||||
|
|
||||||
if (y > 0 && layout.IsWalkable(x, y - 1))
|
if (y > 0 && HasPlacedTile(layout, x, y - 1))
|
||||||
{
|
{
|
||||||
int nid = layout.Tiles[x, y - 1];
|
int nid = layout.Tiles[x, y - 1];
|
||||||
var r = GetRequiredSocketTagFromNeighbor(nid, neighborEdgeFacingUs: "S", ourDir: "N");
|
var r = GetRequiredSocketTagFromNeighbor(nid, neighborEdgeFacingUs: "S", ourDir: "N");
|
||||||
if (r != null) req.Add(r);
|
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];
|
int sid = layout.Tiles[x, y + 1];
|
||||||
var r = GetRequiredSocketTagFromNeighbor(sid, neighborEdgeFacingUs: "N", ourDir: "S");
|
var r = GetRequiredSocketTagFromNeighbor(sid, neighborEdgeFacingUs: "N", ourDir: "S");
|
||||||
if (r != null) req.Add(r);
|
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];
|
int wid = layout.Tiles[x - 1, y];
|
||||||
var r = GetRequiredSocketTagFromNeighbor(wid, neighborEdgeFacingUs: "E", ourDir: "W");
|
var r = GetRequiredSocketTagFromNeighbor(wid, neighborEdgeFacingUs: "E", ourDir: "W");
|
||||||
if (r != null) req.Add(r);
|
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];
|
int eid = layout.Tiles[x + 1, y];
|
||||||
var r = GetRequiredSocketTagFromNeighbor(eid, neighborEdgeFacingUs: "W", ourDir: "E");
|
var r = GetRequiredSocketTagFromNeighbor(eid, neighborEdgeFacingUs: "W", ourDir: "E");
|
||||||
@@ -1126,19 +1140,19 @@ public class DungeonGeneratorV2
|
|||||||
private bool CompatibleWithAllNeighbors(
|
private bool CompatibleWithAllNeighbors(
|
||||||
DungeonLayoutV2 layout, int x, int y, TileDefinition t)
|
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"))
|
if (!EdgeSocketsCompatible(t.Id, "N", layout.Tiles[x, y - 1], "S"))
|
||||||
return false;
|
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"))
|
if (!EdgeSocketsCompatible(t.Id, "S", layout.Tiles[x, y + 1], "N"))
|
||||||
return false;
|
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"))
|
if (!EdgeSocketsCompatible(t.Id, "W", layout.Tiles[x - 1, y], "E"))
|
||||||
return false;
|
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"))
|
if (!EdgeSocketsCompatible(t.Id, "E", layout.Tiles[x + 1, y], "W"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -1841,14 +1855,14 @@ public class DungeonGeneratorV2
|
|||||||
|
|
||||||
private bool CompatibleWithPlacedNeighbors(DungeonLayoutV2 layout, int x, int y, TileDefinition t)
|
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];
|
int nId = layout.Tiles[x, y - 1];
|
||||||
if (!EdgeSocketsCompatible(t.Id, "N", nId, "S"))
|
if (!EdgeSocketsCompatible(t.Id, "N", nId, "S"))
|
||||||
return false;
|
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];
|
int wId = layout.Tiles[x - 1, y];
|
||||||
if (!EdgeSocketsCompatible(t.Id, "W", wId, "E"))
|
if (!EdgeSocketsCompatible(t.Id, "W", wId, "E"))
|
||||||
@@ -1894,14 +1908,14 @@ public class DungeonGeneratorV2
|
|||||||
{
|
{
|
||||||
var req = new List<string>();
|
var req = new List<string>();
|
||||||
|
|
||||||
if (y > 0 && layout.IsWalkable(x, y - 1))
|
if (y > 0 && HasPlacedTile(layout, x, y - 1))
|
||||||
{
|
{
|
||||||
int nid = layout.Tiles[x, y - 1];
|
int nid = layout.Tiles[x, y - 1];
|
||||||
var r = GetRequiredSocketTagFromNeighbor(nid, neighborEdgeFacingUs: "S", ourDir: "N");
|
var r = GetRequiredSocketTagFromNeighbor(nid, neighborEdgeFacingUs: "S", ourDir: "N");
|
||||||
if (r != null) req.Add(r);
|
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];
|
int wid = layout.Tiles[x - 1, y];
|
||||||
var r = GetRequiredSocketTagFromNeighbor(wid, neighborEdgeFacingUs: "E", ourDir: "W");
|
var r = GetRequiredSocketTagFromNeighbor(wid, neighborEdgeFacingUs: "E", ourDir: "W");
|
||||||
|
|||||||
Reference in New Issue
Block a user