Dungeon simulation changes2

This commit is contained in:
dingo
2025-12-28 21:40:48 -05:00
parent 2c8e336828
commit bb25336752
+28 -19
View File
@@ -527,47 +527,51 @@ public class DungeonGeneratorV2
/// <summary> /// <summary>
/// Clear tiles at a connection point to allow corridor entry /// Clear tiles at a connection point to allow corridor entry
/// This aggressively clears walls in both directions to ensure passage
/// </summary> /// </summary>
private void ClearConnectionPoint(DungeonLayoutV2 layout, int x, int y, int width, string direction, int floorId, int sheetId, int frameIndex) 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 int depth = 5; // How far to clear in each direction
// Connection points are at the room edge, we need to clear a path through int halfWidth = Math.Max(width, 2);
int depth = 2; // How far into the room to clear
for (int w = 0; w < width; w++) Console.WriteLine($"[DungeonGenV2] Clearing connection at ({x},{y}) direction={direction} width={width}");
int clearedCount = 0;
// Clear in a cross/plus pattern centered on the connection point
// This ensures we punch through walls regardless of direction
for (int d = -depth; d <= depth; d++)
{ {
for (int d = -1; d <= depth; d++) // -1 to go slightly outside, depth to go inside for (int w = -halfWidth; w <= halfWidth; w++)
{ {
int cx, cy; int cx, cy;
switch (direction.ToLower()) switch (direction.ToLower())
{ {
case "north": case "north":
cx = x + w - width / 2; case "south":
// Vertical corridor - d goes vertical, w goes horizontal
cx = x + w;
cy = y + d; cy = y + d;
break; break;
case "south":
cx = x + w - width / 2;
cy = y - d;
break;
case "east": case "east":
cx = x - d;
cy = y + w - width / 2;
break;
case "west": case "west":
cx = x + d;
cy = y + w - width / 2;
break;
default: default:
continue; // Horizontal corridor - d goes horizontal, w goes vertical
cx = x + d;
cy = y + w;
break;
} }
if (cx >= 0 && cx < MapWidth && cy >= 0 && cy < MapHeight) if (cx >= 0 && cx < MapWidth && cy >= 0 && cy < MapHeight)
{ {
// Remove any existing tile detail at this position // Track if we're actually changing something
bool hadTile = layout.Tiles[cx, cy] != 0;
bool wasBlocked = layout.Walkable != null && !layout.Walkable[cx, cy];
// Remove existing tile visuals
layout.TileDetails.RemoveAll(t => t.X == cx && t.Y == cy); layout.TileDetails.RemoveAll(t => t.X == cx && t.Y == cy);
// Set as floor // Set as walkable floor
layout.Tiles[cx, cy] = floorId; layout.Tiles[cx, cy] = floorId;
if (layout.Walkable != null) if (layout.Walkable != null)
{ {
@@ -586,9 +590,14 @@ public class DungeonGeneratorV2
Layer = 0 Layer = 0
}); });
} }
if (hadTile && wasBlocked)
clearedCount++;
} }
} }
} }
Console.WriteLine($"[DungeonGenV2] Cleared {clearedCount} wall tiles at connection");
} }
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)