From 32ec4d79755d2953415bf16b3067f508643e4344 Mon Sep 17 00:00:00 2001 From: Dominic Date: Wed, 29 Jun 2022 20:21:40 -0500 Subject: [PATCH] Tree worldgen --- Tiles/PerennialTree.cs | 4 +- World/Minibiomes/FloralParadiseMinibiome.cs | 42 +++++++++++++++++++-- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/Tiles/PerennialTree.cs b/Tiles/PerennialTree.cs index 9085b08cde..be23fc7a9d 100644 --- a/Tiles/PerennialTree.cs +++ b/Tiles/PerennialTree.cs @@ -25,7 +25,7 @@ namespace CalamityMod.Tiles public override float TrunkWidth => 16f; - public override float ChanceToCreateNewBranches => 0.9f; + public override float ChanceToCreateNewBranches => 0.8f; public override float VerticalStretchFactor => 12f; @@ -86,7 +86,7 @@ namespace CalamityMod.Tiles public override void DrawThingAtEndOfBranch(Branch branch) { - int totalVinesToDraw = RNG.Next(5, 9); + int totalVinesToDraw = RNG.Next(4, 7); float swayFactor = Main.windSpeedCurrent + (float)Math.Sin(Main.GlobalTimeWrappedHourly * 1.87f + RNG.NextFloat(0.94f)) * 0.4f; Vector2 top = branch.EndOfCurve + Vector2.UnitY * 12f; Vector2 bottom = top + Vector2.UnitY * totalVinesToDraw * 30f; diff --git a/World/Minibiomes/FloralParadiseMinibiome.cs b/World/Minibiomes/FloralParadiseMinibiome.cs index 03e1e24a93..abf3bd6bc0 100644 --- a/World/Minibiomes/FloralParadiseMinibiome.cs +++ b/World/Minibiomes/FloralParadiseMinibiome.cs @@ -1,4 +1,5 @@ -using CalamityMod.Tiles.DraedonStructures; +using CalamityMod.Tiles; +using CalamityMod.Tiles.DraedonStructures; using CalamityMod.Tiles.FloralParadise; using CalamityMod.Tiles.SunkenSea; using Microsoft.Xna.Framework; @@ -7,6 +8,7 @@ using System.Linq; using Terraria; using Terraria.ID; using Terraria.ModLoader; +using Terraria.ObjectData; namespace CalamityMod.World.Minibiomes { @@ -84,13 +86,13 @@ namespace CalamityMod.World.Minibiomes // This exists primarily due to potential issues in small worlds. // This will likely never be hit in typical circumstances, but it's better to be safe than sorry. infiniteLoopPreventerIncrement++; - if (infiniteLoopPreventerIncrement >= 1000) + if (infiniteLoopPreventerIncrement >= 3000) break; int x = Main.maxTilesX / 2 + WorldGen.genRand.Next(-MaxHorizontalDistanceFromWorldCenter, MaxHorizontalDistanceFromWorldCenter); int y = (int)WorldGen.worldSurface + WorldGen.genRand.Next(MinSurfaceDepth, MaxSurfaceDepth); - int width = (int)(WorldGen.genRand.Next(80, 100) * worldSize); - int height = (int)(WorldGen.genRand.Next(70, 95) * worldSize); + int width = (int)(WorldGen.genRand.Next(95, 110) * worldSize); + int height = (int)(WorldGen.genRand.Next(80, 104) * worldSize); Rectangle caveArea = Utils.CenteredRectangle(new Vector2(x, y), new Vector2(width, height)); // Try again if this selected location is near blacklisted tiles. @@ -133,6 +135,7 @@ namespace CalamityMod.World.Minibiomes int smallVineCount = WorldGen.genRand.Next(MinSmallVineCount, MaxSmallVineCount); int waterTileCount = WorldGen.genRand.Next(MinPondWaterTileCount, MaxPondWaterTileCount); int smallFlowerCount = WorldGen.genRand.Next(150, 200); + int bigTreeCount = WorldGen.genRand.Next(2, 5); CutOutCave(placementArea, seed, out bool[,] grassDirtMap); GenerateDirtBehindGrass(placementArea, grassDirtMap); @@ -140,6 +143,7 @@ namespace CalamityMod.World.Minibiomes GenerateVines(placementArea, vigorousVineCount, smallVineCount); GeneratePonds(placementArea, waterTileCount, pondCount); CreateScenicPlants(placementArea, smallFlowerCount); + CreateTrees(placementArea, bigTreeCount); // Place a blood orange. THIS IS FOR TESTING PURPOSES. for (int i = 0; i < 1; i++) @@ -436,6 +440,36 @@ namespace CalamityMod.World.Minibiomes } } + public static void CreateTrees(Rectangle placementArea, int treeCount) + { + int tries = 0; + int treeID = ModContent.TileType(); + + for (int i = 0; i < treeCount; i++) + { + tries++; + + int x = placementArea.X + WorldGen.genRand.Next(16, placementArea.Width - 16); + int y = placementArea.Y + WorldGen.genRand.Next(12, placementArea.Height - 12); + Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); + Vector2 checkTopLeft = new Vector2(x, y).ToWorldCoordinates() - new Vector2(120f, 300f); + Vector2 checkArea = new Vector2(240f, 200f); + + if (tries >= 2500) + break; + + if (tile.HasTile || tile.LiquidAmount > 0 || !WorldGen.SolidTile(x, y + 1) || + !TileObject.CanPlace(x, y, treeID, 0, 0, out _, true, true) || + Collision.SolidCollision(checkTopLeft, (int)checkArea.X, (int)checkArea.Y)) + { + i--; + continue; + } + + WorldGen.PlaceTile(x, y, treeID); + } + } + #region Biome-Specific Utilities public static bool GenerateVigorousVine(int x, int y, int length)