/// <summary> /// Given the specified input options, and optional input dungeon, prepares and returns a /// Dungeon object that is ready to work on. /// </summary> private static Dungeon PrepareWorkingDungeon(DungeonGeneratorOptions options, Dungeon d = null) { if (null == options) { return(new Dungeon()); } if (null == d) { d = new Dungeon(); } if ((d.Tiles.Width != options.Width || d.Tiles.Height != options.Height) || options.DoReset) { d.Tiles.ResetTiles(options.Width, options.Height); } d.InfestationLibrary = options.InfestationLibrary; return(d); }
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); }