Dungeon Building -Verbose logging on Floor tiles....

This commit is contained in:
dingo
2025-12-31 13:32:27 -05:00
parent a5180eee11
commit 9c7f2cfbbe
+136 -17
View File
@@ -1221,37 +1221,141 @@ public class DungeonGeneratorV2
return pool.Count == 0 ? null : pool[_rng.Next(pool.Count)];
}
//private async Task ConnectRoomsAsync(DungeonLayoutV2 layout, DungeonRoomV2 a, DungeonRoomV2 b)
//{
// // Determine tag requirements for this connection.
// var requiredTags = new HashSet<string>(a.TemplateTags ?? new HashSet<string>(StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase);
// requiredTags.IntersectWith(b.TemplateTags ?? new HashSet<string>(StringComparer.OrdinalIgnoreCase));
// if (requiredTags.Count == 0)
// {
// requiredTags = new HashSet<string>(a.TemplateTags ?? new HashSet<string>(StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase);
// requiredTags.UnionWith(b.TemplateTags ?? new HashSet<string>(StringComparer.OrdinalIgnoreCase));
// }
// var floorTile = SelectBestFloorTileForTags(requiredTags) ?? _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor);
// int floorId = floorTile?.Id ?? 1;
// int sheetId = floorTile?.TileMapSheetId ?? 0;
// int frameIndex = floorTile?.FrameIndex ?? 0;
// // Determine best connection points based on relative positions
// string aDirection, bDirection;
// int deltaX = b.CenterX - a.CenterX;
// int deltaY = b.CenterY - a.CenterY;
// // Choose connection directions based on which room is where
// if (Math.Abs(deltaX) > Math.Abs(deltaY))
// {
// // Horizontal connection preferred
// aDirection = deltaX > 0 ? "east" : "west";
// bDirection = deltaX > 0 ? "west" : "east";
// }
// else
// {
// // Vertical connection preferred
// aDirection = deltaY > 0 ? "south" : "north";
// bDirection = deltaY > 0 ? "north" : "south";
// }
// // Get connection points (or fall back to edge center)
// var cpA = a.GetConnectionPoint(aDirection);
// var cpB = b.GetConnectionPoint(bDirection);
// Console.WriteLine($"[DungeonGenV2] Connecting {a.TemplateName ?? "room"} to {b.TemplateName ?? "room"}");
// Console.WriteLine($" A wants {aDirection}, got cp: {(cpA != null ? $"({cpA.X},{cpA.Y}) dir={cpA.Direction}" : "null")}");
// Console.WriteLine($" B wants {bDirection}, got cp: {(cpB != null ? $"({cpB.X},{cpB.Y}) dir={cpB.Direction}" : "null")}");
// int startX, startY, endX, endY;
// int corridorWidth = _rng.Next(MinCorridorWidth, MaxCorridorWidth + 1);
// if (cpA != null)
// {
// var (wx, wy) = a.GetConnectionWorldPos(cpA);
// startX = wx;
// startY = wy;
// corridorWidth = Math.Max(corridorWidth, cpA.Width);
// // Clear the connection point area (carve through template walls)
// ClearConnectionPoint(layout, wx, wy, cpA.Width, aDirection, floorId, sheetId, frameIndex);
// }
// else
// {
// startX = a.CenterX;
// startY = a.CenterY;
// }
// if (cpB != null)
// {
// var (wx, wy) = b.GetConnectionWorldPos(cpB);
// endX = wx;
// endY = wy;
// corridorWidth = Math.Max(corridorWidth, cpB.Width);
// // Clear the connection point area (carve through template walls)
// ClearConnectionPoint(layout, wx, wy, cpB.Width, bDirection, floorId, sheetId, frameIndex);
// }
// else
// {
// endX = b.CenterX;
// endY = b.CenterY;
// }
// // L-shaped corridor from connection point to connection point
// if (_rng.Next(2) == 0)
// {
// // Horizontal segment
// var hallH = SelectHallwayTemplate(requiredTags, startX <= endX ? "east" : "west");
// if (hallH == null || !TryStampHallwayRun(layout, hallH, startX, startY, endX, startY, floorId, sheetId, frameIndex))
// CarveHorizontalCorridor(layout, startX, endX, startY, floorId, sheetId, frameIndex, corridorWidth);
// // Vertical segment
// var hallV = SelectHallwayTemplate(requiredTags, startY <= endY ? "south" : "north");
// if (hallV == null || !TryStampHallwayRun(layout, hallV, endX, startY, endX, endY, floorId, sheetId, frameIndex))
// CarveVerticalCorridor(layout, startY, endY, endX, floorId, sheetId, frameIndex, corridorWidth);
// }
// else
// {
// // Vertical segment
// var hallV = SelectHallwayTemplate(requiredTags, startY <= endY ? "south" : "north");
// if (hallV == null || !TryStampHallwayRun(layout, hallV, startX, startY, startX, endY, floorId, sheetId, frameIndex))
// CarveVerticalCorridor(layout, startY, endY, startX, floorId, sheetId, frameIndex, corridorWidth);
// // Horizontal segment
// var hallH = SelectHallwayTemplate(requiredTags, startX <= endX ? "east" : "west");
// if (hallH == null || !TryStampHallwayRun(layout, hallH, startX, endY, endX, endY, floorId, sheetId, frameIndex))
// CarveHorizontalCorridor(layout, startX, endX, endY, floorId, sheetId, frameIndex, corridorWidth);
// }
//}
private async Task ConnectRoomsAsync(DungeonLayoutV2 layout, DungeonRoomV2 a, DungeonRoomV2 b)
{
// Determine tag requirements for this connection.
var requiredTags = new HashSet<string>(a.TemplateTags ?? new HashSet<string>(StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase);
var requiredTags = new HashSet<string>(
a.TemplateTags ?? new HashSet<string>(StringComparer.OrdinalIgnoreCase),
StringComparer.OrdinalIgnoreCase);
requiredTags.IntersectWith(b.TemplateTags ?? new HashSet<string>(StringComparer.OrdinalIgnoreCase));
if (requiredTags.Count == 0)
{
requiredTags = new HashSet<string>(a.TemplateTags ?? new HashSet<string>(StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase);
requiredTags = new HashSet<string>(
a.TemplateTags ?? new HashSet<string>(StringComparer.OrdinalIgnoreCase),
StringComparer.OrdinalIgnoreCase);
requiredTags.UnionWith(b.TemplateTags ?? new HashSet<string>(StringComparer.OrdinalIgnoreCase));
}
var floorTile = SelectBestFloorTileForTags(requiredTags) ?? _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor);
int floorId = floorTile?.Id ?? 1;
int sheetId = floorTile?.TileMapSheetId ?? 0;
int frameIndex = floorTile?.FrameIndex ?? 0;
// Determine best connection points based on relative positions
// Decide best connection directions based on relative positions
string aDirection, bDirection;
int deltaX = b.CenterX - a.CenterX;
int deltaY = b.CenterY - a.CenterY;
// Choose connection directions based on which room is where
if (Math.Abs(deltaX) > Math.Abs(deltaY))
{
// Horizontal connection preferred
aDirection = deltaX > 0 ? "east" : "west";
bDirection = deltaX > 0 ? "west" : "east";
}
else
{
// Vertical connection preferred
aDirection = deltaY > 0 ? "south" : "north";
bDirection = deltaY > 0 ? "north" : "south";
}
@@ -1273,9 +1377,6 @@ public class DungeonGeneratorV2
startX = wx;
startY = wy;
corridorWidth = Math.Max(corridorWidth, cpA.Width);
// Clear the connection point area (carve through template walls)
ClearConnectionPoint(layout, wx, wy, cpA.Width, aDirection, floorId, sheetId, frameIndex);
}
else
{
@@ -1289,9 +1390,6 @@ public class DungeonGeneratorV2
endX = wx;
endY = wy;
corridorWidth = Math.Max(corridorWidth, cpB.Width);
// Clear the connection point area (carve through template walls)
ClearConnectionPoint(layout, wx, wy, cpB.Width, bDirection, floorId, sheetId, frameIndex);
}
else
{
@@ -1299,6 +1397,26 @@ public class DungeonGeneratorV2
endY = b.CenterY;
}
// ---- NEW: pick a corridor floor tile via PickRandomFloorTile (family-aware) ----
// TODO: derive familyId from room tags if/when you add that convention
int familyId = 2;
// Pick based on start position (or midpoint — either is fine)
var floorTile =
PickRandomFloorTile(layout, startX, startY, familyId, varianceChance: 0.15)
?? _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor);
int floorId = floorTile?.Id ?? 1;
int sheetId = floorTile?.TileMapSheetId ?? 0;
int frameIndex = floorTile?.FrameIndex ?? 0;
Console.WriteLine($"[DungeonGenV2][Corridors] using floorId={floorId} '{floorTile?.Name}' familyId={familyId} sheet={sheetId} frame={frameIndex}");
// Clear the connection point area (carve through template walls)
// (Now uses the same chosen floor)
if (cpA != null) ClearConnectionPoint(layout, startX, startY, cpA.Width, aDirection, floorId, sheetId, frameIndex);
if (cpB != null) ClearConnectionPoint(layout, endX, endY, cpB.Width, bDirection, floorId, sheetId, frameIndex);
// L-shaped corridor from connection point to connection point
if (_rng.Next(2) == 0)
{
@@ -1326,6 +1444,7 @@ public class DungeonGeneratorV2
}
}
/// <summary>
/// Clear tiles at a connection point to allow corridor entry
/// This aggressively clears walls in both directions to ensure passage