Dungeon Builder, Still working on floor tiling
This commit is contained in:
@@ -651,114 +651,7 @@ public class DungeonGeneratorV2
|
||||
return room;
|
||||
}
|
||||
|
||||
//private void CarveBasicRoom(DungeonLayoutV2 layout, DungeonRoomV2 room)
|
||||
//{
|
||||
// // Find floor tile from default sheet
|
||||
// //var floorTile = SelectBestFloorTileForTags(room.TemplateTags) ?? _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor);
|
||||
// //int floorId = floorTile?.Id ?? -1; // -1 means no visual tile, just walkable
|
||||
|
||||
// for (int x = room.X; x < room.X + room.Width; x++)
|
||||
// {
|
||||
// for (int y = room.Y; y < room.Y + room.Height; y++)
|
||||
// {
|
||||
// if (x >= 0 && x < MapWidth && y >= 0 && y < MapHeight)
|
||||
// {
|
||||
// var floorTile = PickRandomTile(room.TemplateTags) ?? _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor);
|
||||
// int floorId = floorTile?.Id ?? -1; // -1 means no visual tile, just walkable
|
||||
// layout.Tiles[x, y] = floorId > 0 ? floorId : 1; // 1 = walkable but no visual
|
||||
|
||||
// // Set walkability - basic carved rooms are always walkable
|
||||
// if (layout.Walkable != null)
|
||||
// {
|
||||
// layout.Walkable[x, y] = true;
|
||||
// }
|
||||
|
||||
// if (floorId > 0 && floorTile != null)
|
||||
// {
|
||||
|
||||
// layout.TileDetails.Add(new PlacedTile
|
||||
// {
|
||||
// X = x,
|
||||
// Y = y,
|
||||
// TileDefinitionId = floorId,
|
||||
// SheetId = floorTile.TileMapSheetId,
|
||||
// FrameIndex = floorTile.FrameIndex,
|
||||
// Layer = 0
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//private void CarveBasicRoom(DungeonLayoutV2 layout, DungeonRoomV2 room)
|
||||
//{
|
||||
// // 1) Decide which TileBase family to use for this room.
|
||||
// // For now: default to family 1 unless the room tags explicitly choose another.
|
||||
// // You can extend this to read "TileBaseFamily_2" etc. from room.TemplateTags.
|
||||
// int familyId = 1;
|
||||
|
||||
// // 2) Optional: choose a single "primary" tile for the room to reduce speckle.
|
||||
// // We'll still enforce sockets per-tile; if the chosen primary doesn't fit a spot,
|
||||
// // we'll fall back to the general picker for that cell.
|
||||
// TileDefinition? roomPrimary = PickRandomFloorTile(layout, room.X, room.Y, familyId, varianceChance: 0.0);
|
||||
|
||||
// for (int x = room.X; x < room.X + room.Width; x++)
|
||||
// {
|
||||
// for (int y = room.Y; y < room.Y + room.Height; y++)
|
||||
// {
|
||||
// if (x < 0 || x >= MapWidth || y < 0 || y >= MapHeight)
|
||||
// continue;
|
||||
|
||||
// // Always carve as walkable space.
|
||||
// if (layout.Walkable != null)
|
||||
// layout.Walkable[x, y] = true;
|
||||
|
||||
// // Remove any previous visuals at this location (safety, consistent with corridors)
|
||||
// layout.TileDetails.RemoveAll(t => t.X == x && t.Y == y);
|
||||
|
||||
// // 3) Pick a tile using: TileBaseCore/TileBase variance + hard socket requirements from neighbors (N/W scan order)
|
||||
// // 85% primary, 15% variance, BUT constrained by required socket tags.
|
||||
// TileDefinition? floorTile = null;
|
||||
|
||||
// // Try room primary first most of the time to keep consistent "material"
|
||||
// // (still must satisfy socket constraints for this cell).
|
||||
// if (roomPrimary != null && SatisfiesSocketRequirements(layout, x, y, roomPrimary))
|
||||
// {
|
||||
// // Small variance chance to break up repetition
|
||||
// if (_rng.NextDouble() < 0.15)
|
||||
// floorTile = PickRandomFloorTile(layout, x, y, familyId, varianceChance: 1.0); // force variance pool
|
||||
// else
|
||||
// floorTile = roomPrimary;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// floorTile = PickRandomFloorTile(layout, x, y, familyId, varianceChance: 0.15);
|
||||
// }
|
||||
|
||||
// // Hard fallback: any floor
|
||||
// floorTile ??= _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor);
|
||||
|
||||
// int floorId = floorTile?.Id ?? -1; // -1 means no visual tile, just walkable
|
||||
// layout.Tiles[x, y] = floorId > 0 ? floorId : 1; // 1 = walkable but no visual
|
||||
|
||||
// if (floorId > 0 && floorTile != null)
|
||||
// {
|
||||
// layout.TileDetails.Add(new PlacedTile
|
||||
// {
|
||||
// X = x,
|
||||
// Y = y,
|
||||
// TileDefinitionId = floorId,
|
||||
// SheetId = floorTile.TileMapSheetId,
|
||||
// FrameIndex = floorTile.FrameIndex,
|
||||
// Layer = 0
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Optional but recommended: repair pass to fix E/S mismatches after scan-order placement.
|
||||
// RepairRoomFloorSockets(layout, room);
|
||||
//}
|
||||
|
||||
private void CarveBasicRoom(DungeonLayoutV2 layout, DungeonRoomV2 room)
|
||||
{
|
||||
// Toggle this if you want to silence per-cell spam quickly.
|
||||
@@ -1120,110 +1013,7 @@ public class DungeonGeneratorV2
|
||||
|
||||
return true;
|
||||
}
|
||||
//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)
|
||||
{
|
||||
@@ -1985,17 +1775,21 @@ public class DungeonGeneratorV2
|
||||
|
||||
if (primary.Count == 0 && variance.Count == 0)
|
||||
{
|
||||
// Fallback: relax socket requirements (so you don't dead-end)
|
||||
// You can also log this so you know your tileset is missing variants.
|
||||
// Relax socket-tag requirements, but DO NOT relax compatibility.
|
||||
primary = _tileDefinitions.Values
|
||||
.Where(t => t.Type == TileType.Floor && HasTag(t, primaryTag))
|
||||
.Where(t => t.Type == TileType.Floor)
|
||||
.Where(t => HasTag(t, primaryTag))
|
||||
.Where(t => CompatibleWithPlacedNeighbors(layout, x, y, t))
|
||||
.ToList();
|
||||
|
||||
variance = _tileDefinitions.Values
|
||||
.Where(t => t.Type == TileType.Floor && HasTag(t, varianceTag))
|
||||
.Where(t => t.Type == TileType.Floor)
|
||||
.Where(t => HasTag(t, varianceTag))
|
||||
.Where(t => CompatibleWithPlacedNeighbors(layout, x, y, t))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
|
||||
if (primary.Count == 0 && variance.Count == 0)
|
||||
return _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user