override protected void GenerateWithAlgorithm(VirtualMap map, VirtualMap vmapBelow) { // Make sure the map is full of walls map.ResetToRocks(); //return; // Pick the cell to start from CellLocation starting_location = default(CellLocation); if (vmapBelow != null) { starting_location = vmapBelow.end; } else { starting_location = map.PickRandomUnvisitedLocation(); } //Debug.Log(starting_location); DiggingMapGeneratorAlgorithm alg = null; switch (algorithmChoice) { case DiggingMapGeneratorAlgorithmChoice.RecursiveBacktracker: alg = new RecursiveBacktrackerDiggingMapGeneratorAlgorithm(); break; case DiggingMapGeneratorAlgorithmChoice.HuntAndKill: alg = new HuntAndKillDiggingMapGeneratorAlgorithm(); break; } alg.StartDigging(map, starting_location, directionChangeModifier); Sparsify(map, vmapBelow); if (verbose) { Console.WriteLine("Sparsified!"); } OpenDeadEnds(map); if (verbose) { Console.WriteLine("Opened dead ends!"); } if (createRooms) { CreateRooms(map); if (verbose) { Console.WriteLine("Added rooms!"); } } }
override public void StartDigging(VirtualMap map, CellLocation starting_location, int directionChangeModifier) { CellLocation currentLocation = starting_location; map.MarkAsVisited(currentLocation); // Pick a previous direction VirtualMap.DirectionType previousDirection = VirtualMap.DirectionType.North; // Repeat until all cells have been visited while (!map.AllCellsVisited) { // Get a starting direction DirectionPicker directionPicker = new DirectionPicker(map, currentLocation, directionChangeModifier, previousDirection); VirtualMap.DirectionType direction = directionPicker.GetNextDirection(map, currentLocation); if (direction != VirtualMap.DirectionType.None) { // Create a corridor in the current cell and flag it as visited currentLocation = map.CreateCorridor(currentLocation, direction); map.FlagCellAsVisited(currentLocation); previousDirection = direction; } // or start from another visited cell // NOTE: This may be less performant! else { currentLocation = map.GetRandomVisitedCell(currentLocation); // No visited cell available: proceed from a random unvisited cell if (currentLocation.x == -1) { currentLocation = map.PickRandomUnvisitedLocation(); map.MarkAsVisited(currentLocation); } } } }