diff --git a/Game/Dungeon/DungeonGeneratorV2.cs b/Game/Dungeon/DungeonGeneratorV2.cs index 99dc928..b351559 100644 --- a/Game/Dungeon/DungeonGeneratorV2.cs +++ b/Game/Dungeon/DungeonGeneratorV2.cs @@ -37,6 +37,7 @@ public class DungeonGeneratorV2 private List _treasureTemplates = new(); private List _normalTemplates = new(); private List _hallwayTemplates = new(); + private Dictionary> _tileGroups = new(); // Tile definitions cache private Dictionary _tileDefinitions = new(); @@ -147,7 +148,27 @@ public class DungeonGeneratorV2 return best; } + private TileDefinition? PickRandomTile(HashSet tags) + { + // Generate a cache key based on sorted tags (e.g., "dungeon,floor,stone") + string key = string.Join(",", tags.OrderBy(t => t)); + if (!_tileGroups.ContainsKey(key)) + { + // Find all matches, not just the single best one + var matches = _tileDefinitions.Values + .Where(t => tags.All(req => ParseTags(t.Tags).Contains(req))) + .ToList(); + + _tileGroups[key] = matches; + } + + var candidates = _tileGroups[key]; + if (candidates.Count == 0) return null; + + // Return a random one from the list + return candidates[_rng.Next(candidates.Count)]; + } private bool TryStampHallwayRun( DungeonLayoutV2 layout, RoomTemplate hallway, @@ -638,8 +659,8 @@ public class DungeonGeneratorV2 private void CarveBasicRoom(DungeonLayoutV2 layout, DungeonRoomV2 room) { // Find floor tile from default sheet - var floorTile = SelectBestFloorTileForTags(room.TemplateTags) ?? _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor); - int floorId = floorTile?.Id ?? -1; // -1 means no visual tile, just walkable + //var floorTile = SelectBestFloorTileForTags(room.TemplateTags) ?? _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor); + //int floorId = floorTile?.Id ?? -1; // -1 means no visual tile, just walkable for (int x = room.X; x < room.X + room.Width; x++) { @@ -647,6 +668,8 @@ public class DungeonGeneratorV2 { if (x >= 0 && x < MapWidth && y >= 0 && y < MapHeight) { + var floorTile = PickRandomTile(room.TemplateTags) ?? _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor); + int floorId = floorTile?.Id ?? -1; // -1 means no visual tile, just walkable layout.Tiles[x, y] = floorId > 0 ? floorId : 1; // 1 = walkable but no visual // Set walkability - basic carved rooms are always walkable @@ -654,9 +677,10 @@ public class DungeonGeneratorV2 { layout.Walkable[x, y] = true; } - + if (floorId > 0 && floorTile != null) { + layout.TileDetails.Add(new PlacedTile { X = x,