private void RoseQuartzGeneration(GenerationProgress progress) { progress.Message = "Rose quartz-ifying the sky"; progress.Start(0f); for (int k = 0; k < (int)((Main.maxTilesX * Main.maxTilesY) * 0.005); k++) { int x = WorldGen.genRand.Next(0, Main.maxTilesX); int y = WorldGen.genRand.Next(0, (int)(Main.maxTilesY * 0.15f)); Tile tile = Framing.GetTileSafely(x, y); if (tile.active() && tile.type == TileID.Dirt) { //3rd and 4th values are strength and steps, adjust later if needed WorldGen.TileRunner(x, y, WorldGen.genRand.Next(3, 5), WorldGen.genRand.Next(2, 4), TileType <RoseQuartzTile>()); } } progress.Set(1f); progress.End(); }
private void CustomSpiderCavernGenTask(GenerationProgress progress) { //Message name should probably change progress.Message = "Spawning Extra Spider Caves Tiles"; progress.Start(0f); int tileArray1D = Main.maxTilesX * Main.maxTilesY; for (int k = 0; k < tileArray1D; k++) { progress.Set((float)k / tileArray1D); int i = k % Main.maxTilesX; int j = k / Main.maxTilesX; if (CanSpawnSpiderSac(i, j)) { WorldGen.PlaceTile(i, j, TileType <SpiderSacTile>(), forced: true); } } progress.Set(1f); progress.End(); }
private void SkyVillageGenTask(GenerationProgress progress) { progress.Message = "Generating Structures... Sky Village"; progress.Start(0f); #region Mapping Floating Islands List <FloatingIsland> islands = new List <FloatingIsland>(); int islandsZone = (int)(Main.maxTilesY * 0.18f); bool[] visitedCoords = new bool[Main.maxTilesX * islandsZone]; bool validCoordinate(Point16 pos) { //Making sure the coordinate is within the visitedCoords array if (pos.Y >= islandsZone) { return(false); } Tile tile = Framing.GetTileSafely(pos); if (tile.type != TileID.Cloud && tile.type != TileID.RainCloud) { return(false); } return(true); } //left top most visible screen coord is (41, 41)? for (int i = 41; i < Main.maxTilesX; i++) { for (int j = 41; j < islandsZone; j++) { Point16 currentPos = new Point16(i, j); if (!validCoordinate(currentPos)) { continue; } List <Point16> currentIsland = new List <Point16>(); //Simple BFS Algorithm implementation Queue <TileNode> queue = new Queue <TileNode>(); TileNode startingNode = new TileNode(currentPos); queue.Enqueue(startingNode); while (queue.Count != 0) { TileNode activeNode = queue.Dequeue(); if (!validCoordinate(activeNode.position)) { continue; } //1D array that holds values of 2D coordinates needs a special formula for the index int index = activeNode.position.Y * Main.maxTilesX + activeNode.position.X; //index = row * maxColumns + column if (visitedCoords[index]) { continue; } else { visitedCoords[index] = true; } //If current coord wasn't visited yet, add it to the current island list currentIsland.Add(activeNode.position); List <TileNode> childNodes = activeNode.GetChildren(); childNodes.ForEach(child => queue.Enqueue(child)); } //300 tiles? I should probably make some tests and define an average/2 if (currentIsland.Count > 300) { islands.Add(new FloatingIsland(currentIsland)); } progress.Set((i * j / visitedCoords.Length) * 0.80f); } } #endregion #region Finding Suitable Spot and Generating it int structureWidth = 160; int structureHeight = 92; //TODO: MAKE IT CHOOSE SPOTS THAT ARE NOT IN BETWEEN ISLANDS IF THEY'RE CLOSER TO THE CENTER (can happen in small worlds) //X int worldCenter = Main.maxTilesX / 2; int biggestDistanceBetweenIslands = 0; int smallestDistanceToWorldCenter = Main.maxTilesX; int xCoord = 0; for (int i = 0; i < islands.Count; i++) { //Can't do islands[i + 1] on last element if (i != islands.Count - 1) { //Finding the biggest distance between two islands where the middle spot between the two is the closest to the world center int distanceBetweenIslands = Math.Abs(islands[i + 1].xMin - islands[i].xMax); //Math.Abs not needed since they're ordered? int theoricalXCoord = islands[i].xMax + distanceBetweenIslands / 2 - structureWidth / 2; if (distanceBetweenIslands > biggestDistanceBetweenIslands && Math.Abs(theoricalXCoord - worldCenter) < smallestDistanceToWorldCenter) { biggestDistanceBetweenIslands = distanceBetweenIslands; smallestDistanceToWorldCenter = Math.Abs(theoricalXCoord - worldCenter); xCoord = theoricalXCoord; } } } progress.Set(0.85f); //Y int yAverage = 0; foreach (FloatingIsland island in islands) { yAverage += island.GetYAverage(); } yAverage /= islands.Count; //Make sure structure y value doesn't go below 41 (world border) yAverage = yAverage - structureHeight > 41 ? yAverage - structureHeight : 42; progress.Set(0.90f); StructureHelper.StructureHelper.GenerateStructure("Structures/SkyVillageStructure", new Point16(xCoord, yAverage), mod); #endregion progress.End(); }