public static void Run() { Console.Clear(); const string title = "6: A Map with Randomly Placed Items/Mobs"; var layout = new MapGen <MapGenContext>(); // Initialize a 6x4 grid of 10x10 cells. var startGen = new InitGridPlanStep <MapGenContext>(1) { CellX = 6, CellY = 4, CellWidth = 9, CellHeight = 9, }; layout.GenSteps.Add(-4, startGen); // Create a path that is composed of a ring around the edge var path = new GridPathBranch <MapGenContext> { RoomRatio = new RandRange(70), BranchRatio = new RandRange(0, 50), }; var genericRooms = new SpawnList <RoomGen <MapGenContext> > { { new RoomGenSquare <MapGenContext>(new RandRange(4, 8), new RandRange(4, 8)), 10 }, // cross { new RoomGenRound <MapGenContext>(new RandRange(5, 9), new RandRange(5, 9)), 10 }, // round }; path.GenericRooms = genericRooms; var genericHalls = new SpawnList <PermissiveRoomGen <MapGenContext> > { { new RoomGenAngledHall <MapGenContext>(50), 10 }, }; path.GenericHalls = genericHalls; layout.GenSteps.Add(-4, path); // Output the rooms into a FloorPlan layout.GenSteps.Add(-2, new DrawGridToFloorStep <MapGenContext>()); // Draw the rooms of the FloorPlan onto the tiled map, with 1 TILE padded on each side layout.GenSteps.Add(0, new DrawFloorToTileStep <MapGenContext>(1)); // Add the stairs up and down layout.GenSteps.Add(2, new FloorStairsStep <MapGenContext, StairsUp, StairsDown>(new StairsUp(), new StairsDown())); // Generate water (specified by user as Terrain 2) with a frequency of 35%, using Perlin Noise in an order of 3, softness 1. const int terrain = 2; var waterPostProc = new PerlinWaterStep <MapGenContext>(new RandRange(35), 3, new Tile(terrain), 1, false); layout.GenSteps.Add(3, waterPostProc); // Remove walls where diagonals of water exist and replace with water layout.GenSteps.Add(4, new DropDiagonalBlockStep <MapGenContext>(new Tile(terrain))); // Remove water stuck in the walls layout.GenSteps.Add(4, new EraseIsolatedStep <MapGenContext>(new Tile(terrain))); // Apply Items var itemSpawns = new SpawnList <Item> { { new Item((int)'!'), 10 }, { new Item((int)']'), 10 }, { new Item((int)'='), 10 }, { new Item((int)'?'), 10 }, { new Item((int)'$'), 10 }, { new Item((int)'/'), 10 }, { new Item((int)'*'), 50 }, }; RandomSpawnStep <MapGenContext, Item> itemPlacement = new RandomSpawnStep <MapGenContext, Item>(new PickerSpawner <MapGenContext, Item>(new LoopedRand <Item>(itemSpawns, new RandRange(10, 19)))); layout.GenSteps.Add(6, itemPlacement); // Apply Mobs var mobSpawns = new SpawnList <Mob> { { new Mob((int)'r'), 20 }, { new Mob((int)'T'), 10 }, { new Mob((int)'D'), 5 }, }; RandomSpawnStep <MapGenContext, Mob> mobPlacement = new RandomSpawnStep <MapGenContext, Mob>(new PickerSpawner <MapGenContext, Mob>(new LoopedRand <Mob>(mobSpawns, new RandRange(10, 19)))); layout.GenSteps.Add(6, mobPlacement); // Run the generator and print MapGenContext context = layout.GenMap(MathUtils.Rand.NextUInt64()); Print(context.Map, title); }
void createMap() { MapGen <MapGenContext> layout = new MapGen <MapGenContext>(); //Initialize a 6x4 grid of 10x10 cells. InitGridPlanStep <MapGenContext> startGen = new InitGridPlanStep <MapGenContext>(1); startGen.CellX = 6; startGen.CellY = 4; startGen.CellWidth = 9; startGen.CellHeight = 9; layout.GenSteps.Add(-4, startGen); //Create a path that is composed of a ring around the edge GridPathBranch <MapGenContext> path = new GridPathBranch <MapGenContext>(); path.RoomRatio = new RandRange(70); path.BranchRatio = new RandRange(0, 50); SpawnList <RoomGen <MapGenContext> > genericRooms = new SpawnList <RoomGen <MapGenContext> >(); //cross genericRooms.Add(new RoomGenSquare <MapGenContext>(new RandRange(4, 8), new RandRange(4, 8))); //round genericRooms.Add(new RoomGenRound <MapGenContext>(new RandRange(5, 9), new RandRange(5, 9))); path.GenericRooms = genericRooms; SpawnList <PermissiveRoomGen <MapGenContext> > genericHalls = new SpawnList <PermissiveRoomGen <MapGenContext> >(); genericHalls.Add(new RoomGenAngledHall <MapGenContext>(50)); path.GenericHalls = genericHalls; layout.GenSteps.Add(-4, path); //Output the rooms into a FloorPlan layout.GenSteps.Add(-2, new DrawGridToFloorStep <MapGenContext>()); //Draw the rooms of the FloorPlan onto the tiled map, with 1 TILE padded on each side layout.GenSteps.Add(0, new DrawFloorToTileStep <MapGenContext>(10)); //Add the stairs up and down layout.GenSteps.Add(2, new FloorStairsStep <MapGenContext, StairsUp, StairsDown>(new StairsUp(), new StairsDown())); //Generate water (specified by user as Terrain 2) with a frequency of 35%, using Perlin Noise in an order of 3, softness 1. int terrain = 2; PerlinWaterStep <MapGenContext> waterPostProc = new PerlinWaterStep <MapGenContext>(new RandRange(35), 3, new TileTest(terrain), 1, false); layout.GenSteps.Add(3, waterPostProc); //Remove walls where diagonals of water exist and replace with water layout.GenSteps.Add(4, new DropDiagonalBlockStep <MapGenContext>(new TileTest(terrain))); //Remove water stuck in the walls layout.GenSteps.Add(4, new EraseIsolatedStep <MapGenContext>(new TileTest(terrain))); //Apply Items SpawnList <Item> itemSpawns = new SpawnList <Item>(); for (int i = 0; i < items.Count; i++) { itemSpawns.Add(new Item(i), items[i].percentage); } RandomSpawnStep <MapGenContext, Item> itemPlacement = new RandomSpawnStep <MapGenContext, Item>(new PickerSpawner <MapGenContext, Item>(new LoopedRand <Item>(itemSpawns, new RandRange(8, 17)))); layout.GenSteps.Add(6, itemPlacement); //Apply Mobs /*SpawnList<Mob> mobSpawns = new SpawnList<Mob>(); * mobSpawns.Add(new Mob((int)'r'), 20); * mobSpawns.Add(new Mob((int)'T'), 10); * mobSpawns.Add(new Mob((int)'D'), 5); * RandomSpawnStep<MapGenContext, Mob> mobPlacement = new RandomSpawnStep<MapGenContext, Mob>(new PickerSpawner<MapGenContext, Mob>(new LoopedRand<Mob>(mobSpawns, new RandRange(10, 19)))); * layout.GenSteps.Add(6, mobPlacement);*/ //Run the generator and print MapGenContext context = layout.GenMap(RogueElements.MathUtils.Rand.NextUInt64()); Print(context.Map); }