Dungeon Building p11
This commit is contained in:
@@ -463,7 +463,7 @@ public class DungeonGeneratorV2
|
|||||||
bDirection = deltaY > 0 ? "north" : "south";
|
bDirection = deltaY > 0 ? "north" : "south";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get connection points (or fall back to center)
|
// Get connection points (or fall back to edge center)
|
||||||
var cpA = a.GetConnectionPoint(aDirection);
|
var cpA = a.GetConnectionPoint(aDirection);
|
||||||
var cpB = b.GetConnectionPoint(bDirection);
|
var cpB = b.GetConnectionPoint(bDirection);
|
||||||
|
|
||||||
@@ -476,6 +476,9 @@ public class DungeonGeneratorV2
|
|||||||
startX = wx;
|
startX = wx;
|
||||||
startY = wy;
|
startY = wy;
|
||||||
corridorWidth = Math.Max(corridorWidth, cpA.Width);
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -489,6 +492,9 @@ public class DungeonGeneratorV2
|
|||||||
endX = wx;
|
endX = wx;
|
||||||
endY = wy;
|
endY = wy;
|
||||||
corridorWidth = Math.Max(corridorWidth, cpB.Width);
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -509,6 +515,72 @@ public class DungeonGeneratorV2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clear tiles at a connection point to allow corridor entry
|
||||||
|
/// </summary>
|
||||||
|
private void ClearConnectionPoint(DungeonLayoutV2 layout, int x, int y, int width, string direction, int floorId, int sheetId, int frameIndex)
|
||||||
|
{
|
||||||
|
// Determine which tiles to clear based on direction
|
||||||
|
// Connection points are at the room edge, we need to clear a path through
|
||||||
|
int depth = 2; // How far into the room to clear
|
||||||
|
|
||||||
|
for (int w = 0; w < width; w++)
|
||||||
|
{
|
||||||
|
for (int d = -1; d <= depth; d++) // -1 to go slightly outside, depth to go inside
|
||||||
|
{
|
||||||
|
int cx, cy;
|
||||||
|
|
||||||
|
switch (direction.ToLower())
|
||||||
|
{
|
||||||
|
case "north":
|
||||||
|
cx = x + w - width / 2;
|
||||||
|
cy = y + d;
|
||||||
|
break;
|
||||||
|
case "south":
|
||||||
|
cx = x + w - width / 2;
|
||||||
|
cy = y - d;
|
||||||
|
break;
|
||||||
|
case "east":
|
||||||
|
cx = x - d;
|
||||||
|
cy = y + w - width / 2;
|
||||||
|
break;
|
||||||
|
case "west":
|
||||||
|
cx = x + d;
|
||||||
|
cy = y + w - width / 2;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cx >= 0 && cx < MapWidth && cy >= 0 && cy < MapHeight)
|
||||||
|
{
|
||||||
|
// Remove any existing tile detail at this position
|
||||||
|
layout.TileDetails.RemoveAll(t => t.X == cx && t.Y == cy);
|
||||||
|
|
||||||
|
// Set as floor
|
||||||
|
layout.Tiles[cx, cy] = floorId;
|
||||||
|
if (layout.Walkable != null)
|
||||||
|
{
|
||||||
|
layout.Walkable[cx, cy] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add floor tile visual
|
||||||
|
if (floorId > 0 && sheetId > 0)
|
||||||
|
{
|
||||||
|
layout.TileDetails.Add(new PlacedTile
|
||||||
|
{
|
||||||
|
X = cx, Y = cy,
|
||||||
|
TileDefinitionId = floorId,
|
||||||
|
SheetId = sheetId,
|
||||||
|
FrameIndex = frameIndex,
|
||||||
|
Layer = 0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void CarveHorizontalCorridor(DungeonLayoutV2 layout, int x1, int x2, int y, int floorId, int sheetId, int frameIndex, int width = 2)
|
private void CarveHorizontalCorridor(DungeonLayoutV2 layout, int x1, int x2, int y, int floorId, int sheetId, int frameIndex, int width = 2)
|
||||||
{
|
{
|
||||||
int minX = Math.Min(x1, x2);
|
int minX = Math.Min(x1, x2);
|
||||||
@@ -594,15 +666,30 @@ public class DungeonGeneratorV2
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console.WriteLine($"[DungeonGenV2] Found {wallTiles.Count} wall tiles for auto-wall generation");
|
||||||
|
foreach (var wt in wallTiles)
|
||||||
|
{
|
||||||
|
Console.WriteLine($" - {wt.Id}: {wt.Name} (tags: {wt.Tags ?? "none"})");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper to match tags (checks for exact tag match in comma-separated list)
|
||||||
|
bool HasTag(TileDefinition t, string tag)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(t.Tags)) return false;
|
||||||
|
return t.Tags.Split(',').Any(s => s.Trim().Equals(tag, StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
|
||||||
// Try to find directional walls by tags, fall back to first wall
|
// Try to find directional walls by tags, fall back to first wall
|
||||||
var wallNorth = wallTiles.FirstOrDefault(t => t.Tags?.Contains("north") == true) ?? wallTiles[0];
|
var wallNorth = wallTiles.FirstOrDefault(t => HasTag(t, "north")) ?? wallTiles[0];
|
||||||
var wallSouth = wallTiles.FirstOrDefault(t => t.Tags?.Contains("south") == true) ?? wallTiles[0];
|
var wallSouth = wallTiles.FirstOrDefault(t => HasTag(t, "south")) ?? wallTiles[0];
|
||||||
var wallEast = wallTiles.FirstOrDefault(t => t.Tags?.Contains("east") == true) ?? wallTiles[0];
|
var wallEast = wallTiles.FirstOrDefault(t => HasTag(t, "east")) ?? wallTiles[0];
|
||||||
var wallWest = wallTiles.FirstOrDefault(t => t.Tags?.Contains("west") == true) ?? wallTiles[0];
|
var wallWest = wallTiles.FirstOrDefault(t => HasTag(t, "west")) ?? wallTiles[0];
|
||||||
var wallCornerNE = wallTiles.FirstOrDefault(t => t.Tags?.Contains("corner_ne") == true) ?? wallTiles[0];
|
var wallCornerNE = wallTiles.FirstOrDefault(t => HasTag(t, "corner_ne")) ?? wallTiles[0];
|
||||||
var wallCornerNW = wallTiles.FirstOrDefault(t => t.Tags?.Contains("corner_nw") == true) ?? wallTiles[0];
|
var wallCornerNW = wallTiles.FirstOrDefault(t => HasTag(t, "corner_nw")) ?? wallTiles[0];
|
||||||
var wallCornerSE = wallTiles.FirstOrDefault(t => t.Tags?.Contains("corner_se") == true) ?? wallTiles[0];
|
var wallCornerSE = wallTiles.FirstOrDefault(t => HasTag(t, "corner_se")) ?? wallTiles[0];
|
||||||
var wallCornerSW = wallTiles.FirstOrDefault(t => t.Tags?.Contains("corner_sw") == true) ?? wallTiles[0];
|
var wallCornerSW = wallTiles.FirstOrDefault(t => HasTag(t, "corner_sw")) ?? wallTiles[0];
|
||||||
|
|
||||||
|
Console.WriteLine($"[DungeonGenV2] Wall tile mapping: N={wallNorth.Id}, S={wallSouth.Id}, E={wallEast.Id}, W={wallWest.Id}");
|
||||||
|
|
||||||
// Track positions that need walls
|
// Track positions that need walls
|
||||||
var wallPositions = new List<(int X, int Y, TileDefinition Tile)>();
|
var wallPositions = new List<(int X, int Y, TileDefinition Tile)>();
|
||||||
|
|||||||
Reference in New Issue
Block a user