Dungeon Revision2

This commit is contained in:
dingo
2025-12-29 11:14:30 -05:00
parent fe10c8f219
commit 3f53dfacd6
+71
View File
@@ -1023,6 +1023,77 @@ public class DungeonGeneratorV2
});
}
// Corner fix-up pass: if a wall tile meets void on the outside but is adjacent to walkable
// only diagonally (common with thicker walls / multi-tile corridors), swap in the connected
// corner tile so the silhouette doesn't look "broken".
//
// Example: a boundary wall tile that is NW of a floor tile might not see floor South/East
// directly (those may be other wall tiles), but it *will* see floor at SE diagonally.
var wallDetailIndex = new Dictionary<(int X, int Y), int>();
for (int i = 0; i < layout.TileDetails.Count; i++)
{
var d = layout.TileDetails[i];
if (d.Layer == 2)
wallDetailIndex[(d.X, d.Y)] = i;
}
for (int x = 1; x < MapWidth - 1; x++)
{
for (int y = 1; y < MapHeight - 1; y++)
{
int id = layout.Tiles[x, y];
if (id == 0) continue;
if (!_tileDefinitions.TryGetValue(id, out var def)) continue;
if (def.Type != TileType.Wall) continue;
bool floorN = layout.IsWalkable(x, y - 1);
bool floorS = layout.IsWalkable(x, y + 1);
bool floorE = layout.IsWalkable(x + 1, y);
bool floorW = layout.IsWalkable(x - 1, y);
bool floorNE = layout.IsWalkable(x + 1, y - 1);
bool floorNW = layout.IsWalkable(x - 1, y - 1);
bool floorSE = layout.IsWalkable(x + 1, y + 1);
bool floorSW = layout.IsWalkable(x - 1, y + 1);
TileDefinition? replace = null;
// Choose connected outer corners using diagonal floor hints.
if (floorSE && !floorS && !floorE) replace = wallCornerNW;
else if (floorSW && !floorS && !floorW) replace = wallCornerNE;
else if (floorNE && !floorN && !floorE) replace = wallCornerSW;
else if (floorNW && !floorN && !floorW) replace = wallCornerSE;
if (replace == null) continue;
if (replace.Id == id) continue;
layout.Tiles[x, y] = replace.Id;
if (layout.Walkable != null) layout.Walkable[x, y] = false;
// Update existing wall visual if present; otherwise add.
if (wallDetailIndex.TryGetValue((x, y), out var idx))
{
var d = layout.TileDetails[idx];
d.TileDefinitionId = replace.Id;
d.SheetId = replace.TileMapSheetId;
d.FrameIndex = replace.FrameIndex;
layout.TileDetails[idx] = d;
}
else
{
layout.TileDetails.Add(new PlacedTile
{
X = x,
Y = y,
TileDefinitionId = replace.Id,
SheetId = replace.TileMapSheetId,
FrameIndex = replace.FrameIndex,
Layer = 2
});
}
}
}
Console.WriteLine($"[DungeonGenV2] Generated {wallPositions.Count} auto-walls");
}