Dungeon Revision5
This commit is contained in:
@@ -936,11 +936,15 @@ public class DungeonGeneratorV2
|
||||
Console.WriteLine($" - {wt.Id}: {wt.Name} (tags: {wt.Tags ?? "none"})");
|
||||
}
|
||||
|
||||
// Helper to match tags (checks for exact tag match in comma-separated list)
|
||||
// Helper to match tags.
|
||||
// NOTE: Some of your data has tags separated by commas *and/or* whitespace (e.g. "corner_nw void"),
|
||||
// so we split on both to be resilient.
|
||||
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));
|
||||
if (string.IsNullOrWhiteSpace(t.Tags)) return false;
|
||||
return t.Tags
|
||||
.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Any(s => s.Equals(tag, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
// Try to find directional walls by tags, fall back to first wall
|
||||
@@ -948,10 +952,40 @@ public class DungeonGeneratorV2
|
||||
var wallSouth = wallTiles.FirstOrDefault(t => HasTag(t, "south")) ?? wallTiles[0];
|
||||
var wallEast = wallTiles.FirstOrDefault(t => HasTag(t, "east")) ?? wallTiles[0];
|
||||
var wallWest = wallTiles.FirstOrDefault(t => HasTag(t, "west")) ?? wallTiles[0];
|
||||
var wallCornerNE = wallTiles.FirstOrDefault(t => HasTag(t, "corner_ne")) ?? wallTiles[0];
|
||||
var wallCornerNW = wallTiles.FirstOrDefault(t => HasTag(t, "corner_nw")) ?? wallTiles[0];
|
||||
var wallCornerSE = wallTiles.FirstOrDefault(t => HasTag(t, "corner_se")) ?? wallTiles[0];
|
||||
var wallCornerSW = wallTiles.FirstOrDefault(t => HasTag(t, "corner_sw")) ?? wallTiles[0];
|
||||
// Corner tiles:
|
||||
// - corner_* indicates which *quadrant of the tile contains the wall mass* (tile itself lives in void space)
|
||||
// - many sets also include "void"-tagged corner variants meant specifically for outside/diagonal void corners.
|
||||
var wallCornerNE = wallTiles.FirstOrDefault(t => HasTag(t, "corner_ne") && !HasTag(t, "void"))
|
||||
?? wallTiles.FirstOrDefault(t => HasTag(t, "corner_ne"))
|
||||
?? wallTiles[0];
|
||||
var wallCornerNW = wallTiles.FirstOrDefault(t => HasTag(t, "corner_nw") && !HasTag(t, "void"))
|
||||
?? wallTiles.FirstOrDefault(t => HasTag(t, "corner_nw"))
|
||||
?? wallTiles[0];
|
||||
var wallCornerSE = wallTiles.FirstOrDefault(t => HasTag(t, "corner_se") && !HasTag(t, "void"))
|
||||
?? wallTiles.FirstOrDefault(t => HasTag(t, "corner_se"))
|
||||
?? wallTiles[0];
|
||||
var wallCornerSW = wallTiles.FirstOrDefault(t => HasTag(t, "corner_sw") && !HasTag(t, "void"))
|
||||
?? wallTiles.FirstOrDefault(t => HasTag(t, "corner_sw"))
|
||||
?? wallTiles[0];
|
||||
|
||||
// Prefer these when a corner tile borders void on TWO orthogonal sides (classic outside corner).
|
||||
var wallCornerNEVoid = wallTiles.FirstOrDefault(t => HasTag(t, "corner_ne") && HasTag(t, "void"));
|
||||
var wallCornerNWVoid = wallTiles.FirstOrDefault(t => HasTag(t, "corner_nw") && HasTag(t, "void"));
|
||||
var wallCornerSEVoid = wallTiles.FirstOrDefault(t => HasTag(t, "corner_se") && HasTag(t, "void"));
|
||||
var wallCornerSWVoid = wallTiles.FirstOrDefault(t => HasTag(t, "corner_sw") && HasTag(t, "void"));
|
||||
|
||||
TileDefinition PickCorner(string cornerTag, bool preferVoid)
|
||||
{
|
||||
// cornerTag is one of: corner_ne, corner_nw, corner_se, corner_sw
|
||||
return cornerTag.ToLowerInvariant() switch
|
||||
{
|
||||
"corner_ne" => (preferVoid ? wallCornerNEVoid : null) ?? wallCornerNE,
|
||||
"corner_nw" => (preferVoid ? wallCornerNWVoid : null) ?? wallCornerNW,
|
||||
"corner_se" => (preferVoid ? wallCornerSEVoid : null) ?? wallCornerSE,
|
||||
"corner_sw" => (preferVoid ? wallCornerSWVoid : null) ?? wallCornerSW,
|
||||
_ => wallCornerNW
|
||||
};
|
||||
}
|
||||
|
||||
Console.WriteLine($"[DungeonGenV2] Wall tile mapping: N={wallNorth.Id}, S={wallSouth.Id}, E={wallEast.Id}, W={wallWest.Id}");
|
||||
|
||||
@@ -982,14 +1016,21 @@ public class DungeonGeneratorV2
|
||||
// IMPORTANT: corner_* tags indicate the quadrant where the *wall mass* lives inside this tile.
|
||||
// That quadrant matches the direction of the interior (walkable) corner.
|
||||
// Example: if the interior is to the NW (diagonal floor at NW), use corner_nw.
|
||||
// If this is an *outside* corner (the two orthogonal sides away from the interior are void),
|
||||
// prefer a corner variant that includes the "void" tag.
|
||||
bool voidN = y > 0 && layout.Tiles[x, y - 1] == 0;
|
||||
bool voidS = y < MapHeight - 1 && layout.Tiles[x, y + 1] == 0;
|
||||
bool voidE = x < MapWidth - 1 && layout.Tiles[x + 1, y] == 0;
|
||||
bool voidW = x > 0 && layout.Tiles[x - 1, y] == 0;
|
||||
|
||||
if (hasFloorNorth && hasFloorWest)
|
||||
wallTile = wallCornerNW;
|
||||
wallTile = PickCorner("corner_nw", preferVoid: (voidS && voidE));
|
||||
else if (hasFloorNorth && hasFloorEast)
|
||||
wallTile = wallCornerNE;
|
||||
wallTile = PickCorner("corner_ne", preferVoid: (voidS && voidW));
|
||||
else if (hasFloorSouth && hasFloorWest)
|
||||
wallTile = wallCornerSW;
|
||||
wallTile = PickCorner("corner_sw", preferVoid: (voidN && voidE));
|
||||
else if (hasFloorSouth && hasFloorEast)
|
||||
wallTile = wallCornerSE;
|
||||
wallTile = PickCorner("corner_se", preferVoid: (voidN && voidW));
|
||||
else if (hasFloorSouth)
|
||||
wallTile = wallNorth; // Wall is north of floor, so it's a north-facing wall
|
||||
else if (hasFloorNorth)
|
||||
@@ -1097,10 +1138,16 @@ public class DungeonGeneratorV2
|
||||
// Diagonal-walkable indicates the interior corner. Choose the corner wall variant that visually
|
||||
// connects the two bordering wall runs (this tileset uses the opposite naming compared to the
|
||||
// earlier assumption, so NW<->SE and NE<->SW).
|
||||
if (floorSE && (wallS || wallE)) PlaceWall(x, y, wallCornerSE);
|
||||
else if (floorSW && (wallS || wallW)) PlaceWall(x, y, wallCornerSW);
|
||||
else if (floorNE && (wallN || wallE)) PlaceWall(x, y, wallCornerNE);
|
||||
else if (floorNW && (wallN || wallW)) PlaceWall(x, y, wallCornerNW);
|
||||
// Outside-void corners: if the two orthogonal tiles away from the interior are void, prefer "void" corner variants.
|
||||
bool vN = layout.Tiles[x, y - 1] == 0;
|
||||
bool vS = layout.Tiles[x, y + 1] == 0;
|
||||
bool vE = layout.Tiles[x + 1, y] == 0;
|
||||
bool vW = layout.Tiles[x - 1, y] == 0;
|
||||
|
||||
if (floorSE && (wallS || wallE)) PlaceWall(x, y, PickCorner("corner_se", preferVoid: (vN && vW)));
|
||||
else if (floorSW && (wallS || wallW)) PlaceWall(x, y, PickCorner("corner_sw", preferVoid: (vN && vE)));
|
||||
else if (floorNE && (wallN || wallE)) PlaceWall(x, y, PickCorner("corner_ne", preferVoid: (vS && vW)));
|
||||
else if (floorNW && (wallN || wallW)) PlaceWall(x, y, PickCorner("corner_nw", preferVoid: (vS && vE)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1132,10 +1179,15 @@ public class DungeonGeneratorV2
|
||||
TileDefinition? replace = null;
|
||||
|
||||
// Choose connected outer corners using diagonal floor hints.
|
||||
if (floorSE && !floorS && !floorE) replace = wallCornerSE;
|
||||
else if (floorSW && !floorS && !floorW) replace = wallCornerSW;
|
||||
else if (floorNE && !floorN && !floorE) replace = wallCornerNE;
|
||||
else if (floorNW && !floorN && !floorW) replace = wallCornerNW;
|
||||
bool vN2 = layout.Tiles[x, y - 1] == 0;
|
||||
bool vS2 = layout.Tiles[x, y + 1] == 0;
|
||||
bool vE2 = layout.Tiles[x + 1, y] == 0;
|
||||
bool vW2 = layout.Tiles[x - 1, y] == 0;
|
||||
|
||||
if (floorSE && !floorS && !floorE) replace = PickCorner("corner_se", preferVoid: (vN2 && vW2));
|
||||
else if (floorSW && !floorS && !floorW) replace = PickCorner("corner_sw", preferVoid: (vN2 && vE2));
|
||||
else if (floorNE && !floorN && !floorE) replace = PickCorner("corner_ne", preferVoid: (vS2 && vW2));
|
||||
else if (floorNW && !floorN && !floorW) replace = PickCorner("corner_nw", preferVoid: (vS2 && vE2));
|
||||
|
||||
if (replace == null) continue;
|
||||
if (replace.Id == id) continue;
|
||||
|
||||
Reference in New Issue
Block a user