public void ApplyOverlayTest() { var map = new ArrayMap <bool>(100, 100); QuickGenerators.GenerateCellularAutomataMap(map); var duplicateMap = new ArrayMap <bool>(map.Width, map.Height); duplicateMap.ApplyOverlay(map); foreach (var pos in map.Positions()) { Assert.AreEqual(map[pos], duplicateMap[pos]); } }
/// <summary> /// Generates the areas. Floor tiles will be set to true in the provided map, and wall tiles /// will be set to false. /// </summary> /// <param name="map">The map to fill with values when generate is called.</param> /// <param name="rng"> /// The RNG to use to initially fill the map. If null is specified, the default RNG is used. /// </param> /// <param name="fillProbability"> /// Represents the percent chance that a given cell will be a floor cell when the map is /// initially randomly filled. Recommended to be in range [40, 60] (40 is used in the /// roguebasin article). /// </param> /// <param name="totalIterations"> /// Total number of times the cellular automata-based smoothing algorithm is executed. /// Recommended to be in range [2, 10] (7 is used on roguebasin article). /// </param> /// <param name="cutoffBigAreaFill"> /// Total number of times the cellular automata smoothing variation that is more likely to /// result in "breaking up" large areas will be run before switching to the more standard /// nearest neighbors version. Recommended to be in range [2, 7] (4 is used in roguebasin article). /// </param> static public void Generate(ISettableMapView <bool> map, IGenerator rng = null, int fillProbability = 40, int totalIterations = 7, int cutoffBigAreaFill = 4) { if (rng == null) { rng = SingletonRandom.DefaultRNG; } // We must allocate a new one to avoid messing up other map gen features that happened on // the original var tempMap = new ArrayMap <bool>(map.Width, map.Height); tempMap.ApplyOverlay(map); // Sets each cell so as of this point, tempMap is in a clean state randomlyFillCells(tempMap, rng, fillProbability); for (int i = 0; i < totalIterations; i++) { if (i < cutoffBigAreaFill) { cellAutoBigAreaAlgo(tempMap); } else { cellAutoNearestNeighborsAlgo(tempMap); } } // Ensure it's enclosed before we try to connect, so we can't possibly connect a path // that ruins the enclosure. Doing this before connection ensures that filling it can't // kill the path to an area. fillToRectangle(tempMap); // Set rooms to true, but do NOT enforce where walls (false values) are -- this is done // by making sure the blank slate passed in is all false. foreach (var pos in tempMap.Positions()) { if (tempMap[pos]) { map[pos] = true; } } }
public void ApplyTerrainOverlay() { var grMap = new ArrayMap <bool>(10, 10); QuickGenerators.GenerateRectangleMap(grMap); var translationMap = new LambdaTranslationMap <bool, IGameObject>(grMap, (pos, val) => val ? new GameObject(pos, 0, null, true, true, true) : new GameObject(pos, 0, null, true, false, false)); var map = new Map(grMap.Width, grMap.Height, 1, Distance.CHEBYSHEV); // Normally you shouldn't need tempMap, could just use translationMap directly. But we want ref equality comparison // capability for testing var tempMap = new ArrayMap <IGameObject>(grMap.Width, grMap.Height); tempMap.ApplyOverlay(translationMap); map.ApplyTerrainOverlay(tempMap); Assert.AreEqual(grMap.Width, map.Width); Assert.AreEqual(grMap.Height, map.Height); foreach (var pos in map.Positions()) { Assert.AreEqual(tempMap[pos], map.GetTerrain(pos)); } }