public static DungeonGenerator GetTestDungeonGenerator() { AlgorithmRandom r = new AlgorithmRandom(1337); int width = 51; int height = 51; DungeonGenerator generator = new DungeonGenerator(); generator.Options = new DungeonGenerator.DungeonGeneratorOptions() { DoReset = true, EgressConnections = null, Width = width, Height = height, InfestationLibrary = TestHelpers.GetTestLibrary(), AlgRuns = new List <AlgorithmRun> { new AlgorithmRun() { Alg = new MonteCarloRoomCarver() { GroupForDebug = false, WallStrategy = TerrainGenAlgorithmBase.WallFormation.Boundaries, RoomWidthMin = 4, RoomWidthMax = 10, RoomHeightMin = 4, RoomHeightMax = 10, Attempts = 500, TargetRoomCount = 6 }, Context = new AlgorithmContextBase() { R = r } }, new AlgorithmRun() { Alg = new RecursiveBacktracker() { BorderPadding = 0, Momentum = 0.25, OpenTilesStrategy = RecursiveBacktracker.OpenTilesHandling.ConnectToRooms, WallStrategy = TerrainGenAlgorithmBase.WallFormation.Boundaries }, Context = new AlgorithmContextBase() { R = r } }, new AlgorithmRun() { Alg = new BasicInfester(), Context = new AlgorithmContextBase() { R = r } } }, }; return(generator); }
public static Dungeon Generate(DungeonGeneratorOptions options, Dungeon starterDungeon = null) { List <AlgorithmRun> algRuns = new List <AlgorithmRun>(); AlgorithmRandom r = AlgorithmRandom.RandomInstance(); if (null != options) { if (options.Width == 0 || options.Height == 0) { throw new ArgumentException("Neither Width nor Height can be 0"); } algRuns.AddRange(options.AlgRuns); } // Input validation if (null == algRuns) { throw new ArgumentNullException(); } // Prepare context for each algorithm run appropriately. Dungeon workingDungeon = PrepareWorkingDungeon(options, starterDungeon); // Prepare algorithm runs to work on the dungeon foreach (var run in algRuns) { run.PrepareFor(workingDungeon); } // Generate terrain DungeonTiles tiles = workingDungeon.Tiles; for (int i = 0; i < algRuns.Count; ++i) { bool canSkip = true; ISet <Tile> algTiles = new HashSet <Tile>(); for (int y = 0; y < tiles.Height; ++y) { for (int x = 0; x < tiles.Width; ++x) { if (algRuns[i].Context.Mask[y, x]) { algTiles.Add(tiles[y, x]); canSkip = false; } } } // If this algorithm is totally masked out, don't bother running it if (canSkip) { continue; } if (null != options.Callbacks && options.Callbacks.Count > 0) { foreach (var cb in options.Callbacks) { algRuns[i].Alg.AttachCallback(cb); } } algRuns[i].RunAlgorithm(); workingDungeon.Runs.Add(algRuns[i].ToInfo()); } // TODO Generate infestations return(workingDungeon); }