More Tile Fixes
This commit is contained in:
@@ -1088,7 +1088,7 @@ public class DungeonGeneratorV2
|
|||||||
|
|
||||||
int familyId = _activeFamilyId;
|
int familyId = _activeFamilyId;
|
||||||
|
|
||||||
// Pick based on start position (or midpoint — either is fine)
|
// Pick based on start position (or midpoint - either is fine)
|
||||||
var floorTile =
|
var floorTile =
|
||||||
PickRandomFloorTile(layout, startX, startY, familyId, varianceChance: 0.15)
|
PickRandomFloorTile(layout, startX, startY, familyId, varianceChance: 0.15)
|
||||||
?? _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor);
|
?? _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor);
|
||||||
@@ -1749,24 +1749,26 @@ public class DungeonGeneratorV2
|
|||||||
}
|
}
|
||||||
|
|
||||||
private TileDefinition? PickRandomFloorTile(
|
private TileDefinition? PickRandomFloorTile(
|
||||||
DungeonLayoutV2 layout,
|
DungeonLayoutV2 layout,
|
||||||
int x, int y,
|
int x, int y,
|
||||||
int familyId,
|
int familyId,
|
||||||
double varianceChance = 0.25)
|
double varianceChance = 0.25)
|
||||||
{
|
{
|
||||||
var requiredSocketTags = BuildRequiredSocketTags(layout, x, y);
|
var requiredSocketTags = BuildRequiredSocketTags(layout, x, y);
|
||||||
|
|
||||||
|
bool requiresTyped = requiredSocketTags.Any(t => t.Contains('='));
|
||||||
|
|
||||||
string primaryTag = $"TileBaseCore_{familyId}";
|
string primaryTag = $"TileBaseCore_{familyId}";
|
||||||
string varianceTag = $"TileBase_{familyId}";
|
string varianceTag = $"TileBase_{familyId}";
|
||||||
|
|
||||||
var primary = _tileDefinitions.Values
|
List<TileDefinition> primary = _tileDefinitions.Values
|
||||||
.Where(t => t.Type == TileType.Floor)
|
.Where(t => t.Type == TileType.Floor)
|
||||||
.Where(t => HasTag(t, primaryTag))
|
.Where(t => HasTag(t, primaryTag))
|
||||||
.Where(t => HasAllTags(t, requiredSocketTags))
|
.Where(t => HasAllTags(t, requiredSocketTags))
|
||||||
.Where(t => CompatibleWithPlacedNeighbors(layout, x, y, t))
|
.Where(t => CompatibleWithPlacedNeighbors(layout, x, y, t))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var variance = _tileDefinitions.Values
|
List<TileDefinition> variance = _tileDefinitions.Values
|
||||||
.Where(t => t.Type == TileType.Floor)
|
.Where(t => t.Type == TileType.Floor)
|
||||||
.Where(t => HasTag(t, varianceTag))
|
.Where(t => HasTag(t, varianceTag))
|
||||||
.Where(t => HasAllTags(t, requiredSocketTags))
|
.Where(t => HasAllTags(t, requiredSocketTags))
|
||||||
@@ -1775,7 +1777,11 @@ public class DungeonGeneratorV2
|
|||||||
|
|
||||||
if (primary.Count == 0 && variance.Count == 0)
|
if (primary.Count == 0 && variance.Count == 0)
|
||||||
{
|
{
|
||||||
// Relax socket-tag requirements, but DO NOT relax compatibility.
|
// If we require typed sockets and can't satisfy them, DO NOT relax.
|
||||||
|
if (requiresTyped)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Otherwise, relax only the socket-tag requirement but keep compatibility.
|
||||||
primary = _tileDefinitions.Values
|
primary = _tileDefinitions.Values
|
||||||
.Where(t => t.Type == TileType.Floor)
|
.Where(t => t.Type == TileType.Floor)
|
||||||
.Where(t => HasTag(t, primaryTag))
|
.Where(t => HasTag(t, primaryTag))
|
||||||
@@ -1789,17 +1795,17 @@ public class DungeonGeneratorV2
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (primary.Count == 0 && variance.Count == 0)
|
if (primary.Count == 0 && variance.Count == 0)
|
||||||
return _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor);
|
return null;
|
||||||
|
|
||||||
bool pickVar = _rng.NextDouble() < varianceChance;
|
bool pickVar = _rng.NextDouble() < varianceChance;
|
||||||
var pool = pickVar ? variance : primary;
|
var pool = pickVar ? variance : primary;
|
||||||
if (pool.Count == 0) pool = pickVar ? primary : variance;
|
if (pool.Count == 0) pool = pickVar ? primary : variance;
|
||||||
|
|
||||||
return pool.Count == 0 ? null : pool[_rng.Next(pool.Count)];
|
return pool[_rng.Next(pool.Count)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private bool CompatibleWithPlacedNeighbors(DungeonLayoutV2 layout, int x, int y, TileDefinition t)
|
private bool CompatibleWithPlacedNeighbors(DungeonLayoutV2 layout, int x, int y, TileDefinition t)
|
||||||
{
|
{
|
||||||
// North neighbor
|
// North neighbor
|
||||||
@@ -1926,44 +1932,87 @@ public class DungeonGeneratorV2
|
|||||||
_activeFamilyId = families.Count > 0 ? families.ElementAt(_rng.Next(families.Count)) : 1;
|
_activeFamilyId = families.Count > 0 ? families.ElementAt(_rng.Next(families.Count)) : 1;
|
||||||
Console.WriteLine($"[DungeonGenV2] Chosen dungeon tile familyId={_activeFamilyId}");
|
Console.WriteLine($"[DungeonGenV2] Chosen dungeon tile familyId={_activeFamilyId}");
|
||||||
}
|
}
|
||||||
|
//private bool EdgeSocketsCompatible(int aId, string aEdge, int bId, string bEdge)
|
||||||
|
//{
|
||||||
|
// _tileSocketTypes.TryGetValue(aId, out var aMap);
|
||||||
|
// _tileSocketTypes.TryGetValue(bId, out var bMap);
|
||||||
|
|
||||||
|
// aMap ??= new Dictionary<string, HashSet<string>>();
|
||||||
|
// bMap ??= new Dictionary<string, HashSet<string>>();
|
||||||
|
|
||||||
|
// aMap.TryGetValue(aEdge, out var aTypes);
|
||||||
|
// bMap.TryGetValue(bEdge, out var bTypes);
|
||||||
|
|
||||||
|
// aTypes ??= new HashSet<string>();
|
||||||
|
// bTypes ??= new HashSet<string>();
|
||||||
|
|
||||||
|
// bool aHas = aTypes.Count > 0;
|
||||||
|
// bool bHas = bTypes.Count > 0;
|
||||||
|
|
||||||
|
// if (!aHas && !bHas) return true; // neither cares
|
||||||
|
// if (aHas != bHas) return false; // one cares, other doesn't
|
||||||
|
|
||||||
|
// // both have sockets
|
||||||
|
// bool aTyped = aTypes.Any(t => !string.IsNullOrEmpty(t));
|
||||||
|
// bool bTyped = bTypes.Any(t => !string.IsNullOrEmpty(t));
|
||||||
|
|
||||||
|
// if (!aTyped && !bTyped)
|
||||||
|
// return true; // both untyped
|
||||||
|
|
||||||
|
// var aTypedSet = aTypes
|
||||||
|
// .Where(t => !string.IsNullOrEmpty(t))
|
||||||
|
// .ToHashSet(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
// var bTypedSet = bTypes
|
||||||
|
// .Where(t => !string.IsNullOrEmpty(t))
|
||||||
|
// .ToHashSet(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
// return aTypedSet.Overlaps(bTypedSet);
|
||||||
|
//}
|
||||||
private bool EdgeSocketsCompatible(int aId, string aEdge, int bId, string bEdge)
|
private bool EdgeSocketsCompatible(int aId, string aEdge, int bId, string bEdge)
|
||||||
{
|
{
|
||||||
_tileSocketTypes.TryGetValue(aId, out var aMap);
|
if (!_tileSocketTypes.TryGetValue(aId, out var aMap)) return true; // no sockets at all? treat as open?
|
||||||
_tileSocketTypes.TryGetValue(bId, out var bMap);
|
if (!_tileSocketTypes.TryGetValue(bId, out var bMap)) return true;
|
||||||
|
|
||||||
aMap ??= new Dictionary<string, HashSet<string>>();
|
|
||||||
bMap ??= new Dictionary<string, HashSet<string>>();
|
|
||||||
|
|
||||||
|
// Get socket types for each edge (default to empty if missing)
|
||||||
aMap.TryGetValue(aEdge, out var aTypes);
|
aMap.TryGetValue(aEdge, out var aTypes);
|
||||||
bMap.TryGetValue(bEdge, out var bTypes);
|
bMap.TryGetValue(bEdge, out var bTypes);
|
||||||
|
|
||||||
aTypes ??= new HashSet<string>();
|
aTypes ??= new HashSet<string>();
|
||||||
bTypes ??= new HashSet<string>();
|
bTypes ??= new HashSet<string>();
|
||||||
|
|
||||||
bool aHas = aTypes.Count > 0;
|
// If either side has no declared socket on this edge - treat as closed
|
||||||
bool bHas = bTypes.Count > 0;
|
bool aMissing = aTypes.Count == 0 && !aMap.ContainsKey(aEdge); // truly missing key
|
||||||
|
bool bMissing = bTypes.Count == 0 && !bMap.ContainsKey(bEdge);
|
||||||
|
|
||||||
if (!aHas && !bHas) return true; // neither cares
|
// But if they explicitly have "Closed", it's typed
|
||||||
if (aHas != bHas) return false; // one cares, other doesn't
|
bool aClosed = aTypes.Contains("Closed");
|
||||||
|
bool bClosed = bTypes.Contains("Closed");
|
||||||
|
|
||||||
// both have sockets
|
// Case 1: Both explicitly closed - compatible (shared wall seam)
|
||||||
bool aTyped = aTypes.Any(t => !string.IsNullOrEmpty(t));
|
if (aClosed && bClosed) return true;
|
||||||
bool bTyped = bTypes.Any(t => !string.IsNullOrEmpty(t));
|
|
||||||
|
|
||||||
if (!aTyped && !bTyped)
|
// Case 2: One closed, one not - incompatible
|
||||||
return true; // both untyped
|
if (aClosed || bClosed) return false;
|
||||||
|
|
||||||
var aTypedSet = aTypes
|
// Case 3: One or both missing (no socket declared) - treat as closed
|
||||||
.Where(t => !string.IsNullOrEmpty(t))
|
if (aMissing || bMissing) return false;
|
||||||
.ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
||||||
|
|
||||||
var bTypedSet = bTypes
|
// Case 4: Both have sockets (possibly untyped or typed)
|
||||||
.Where(t => !string.IsNullOrEmpty(t))
|
bool aTyped = aTypes.Any(t => !string.IsNullOrEmpty(t) && t != "Closed");
|
||||||
.ToHashSet(StringComparer.OrdinalIgnoreCase);
|
bool bTyped = bTypes.Any(t => !string.IsNullOrEmpty(t) && t != "Closed");
|
||||||
|
|
||||||
return aTypedSet.Overlaps(bTypedSet);
|
// If either is typed, require matching type
|
||||||
|
if (aTyped || bTyped)
|
||||||
|
{
|
||||||
|
var aTypedSet = aTypes.Where(t => !string.IsNullOrEmpty(t) && t != "Closed").ToHashSet(StringComparer.OrdinalIgnoreCase);
|
||||||
|
var bTypedSet = bTypes.Where(t => !string.IsNullOrEmpty(t) && t != "Closed").ToHashSet(StringComparer.OrdinalIgnoreCase);
|
||||||
|
return aTypedSet.Overlaps(bTypedSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Both untyped - always compatible
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user