From bb54b462c152ff2cb8bddfac4c1231a4692ede35 Mon Sep 17 00:00:00 2001 From: Dominic Date: Thu, 6 Oct 2022 22:00:01 -0500 Subject: [PATCH] Transition to not sulph sea --- ILEditing/WorldgenILChanges.cs | 2 +- Tiles/Abyss/SulphurousSand.cs | 2 +- World/SulphurousSea.cs | 106 ++++++++++++++++++++++++++++++++- 3 files changed, 105 insertions(+), 5 deletions(-) diff --git a/ILEditing/WorldgenILChanges.cs b/ILEditing/WorldgenILChanges.cs index 78678e8139..9d5ca5219c 100644 --- a/ILEditing/WorldgenILChanges.cs +++ b/ILEditing/WorldgenILChanges.cs @@ -49,7 +49,7 @@ namespace CalamityMod.ILEditing cursor.EmitDelegate(() => { - WorldGen.dungeonX = Utils.Clamp(WorldGen.dungeonX, SulphurousSea.BiomeWidth + 100, Main.maxTilesX - SulphurousSea.BiomeWidth - 100); + WorldGen.dungeonX = Utils.Clamp(WorldGen.dungeonX, SulphurousSea.BiomeWidth + 167, Main.maxTilesX - SulphurousSea.BiomeWidth - 167); // Adjust the Y position of the dungeon to accomodate for the X shift. WorldUtils.Find(new Point(WorldGen.dungeonX, WorldGen.dungeonY), Searches.Chain(new Searches.Down(9001), new Conditions.IsSolid()), out Point result); diff --git a/Tiles/Abyss/SulphurousSand.cs b/Tiles/Abyss/SulphurousSand.cs index 7b2993cc2b..a19ae64783 100644 --- a/Tiles/Abyss/SulphurousSand.cs +++ b/Tiles/Abyss/SulphurousSand.cs @@ -50,7 +50,7 @@ namespace CalamityMod.Tiles.Abyss if (!Main.tile[i, tileLocationY].HasTile) { if (!CalamityPlayer.areThereAnyDamnBosses && Main.tile[i, tileLocationY].LiquidAmount == 255 && Main.tile[i, tileLocationY - 1].LiquidAmount == 255 && - Main.tile[i, tileLocationY - 2].LiquidAmount == 255 && Main.netMode != NetmodeID.MultiplayerClient) + Main.tile[i, tileLocationY - 2].LiquidAmount == 255 && !Main.tile[i, tileLocationY - 2].HasTile && Main.netMode != NetmodeID.MultiplayerClient) { Projectile.NewProjectile(new EntitySource_WorldEvent(), (float)(i * 16 + 16), (float)(tileLocationY * 16 + 16), 0f, -0.1f, ModContent.ProjectileType(), 0, 2f, Main.myPlayer, 0f, 0f); } diff --git a/World/SulphurousSea.cs b/World/SulphurousSea.cs index e6e4667696..48a374022f 100644 --- a/World/SulphurousSea.cs +++ b/World/SulphurousSea.cs @@ -169,7 +169,7 @@ namespace CalamityMod.World public static void FinishGeneratingSulphurSea() { - + CreateBeachNearSea(); } #endregion @@ -485,7 +485,7 @@ namespace CalamityMod.World int sandstoneLineOffset = (int)(FractalBrownianMotion(i * HardenedSandstoneLineMagnification, y * HardenedSandstoneLineMagnification, sandstoneSeed, 7) * 30) + (int)(depth * OpenCavernStartDepthPercentage); // Make the sandstone line descent a little bit the closer it is to the world edge, to make it look like it "warps" towards the abyss. - sandstoneLineOffset -= (int)(Math.Pow(Utils.GetLerpValue(width * 0.1f, width * 0.8f, i, true), 1.72f) * 45f); + sandstoneLineOffset -= (int)(Math.Pow(Utils.GetLerpValue(width * 0.1f, width * 0.8f, i, true), 1.72f) * 67f); Point p = new(GetActualX(i), y); Tile t = CalamityUtils.ParanoidTileRetrieval(p.X, p.Y); @@ -520,6 +520,8 @@ namespace CalamityMod.World if (t.HasTile) { float noise = FractalBrownianMotion(i * IslandLineMagnification, y * IslandLineMagnification, heightSeed, 5) * 0.5f + 0.5f; + noise = MathHelper.Lerp(noise, 0.5f, Utils.GetLerpValue(width - 13f, width - 1f, i, true)); + int heightOffset = -(int)Math.Round(MathHelper.Lerp(-MaxIslandDepth, MaxIslandHeight, noise)); for (int dy = 0; dy != heightOffset; dy += Math.Sign(heightOffset)) { @@ -555,7 +557,66 @@ namespace CalamityMod.World Main.tile[x, y].TileType = TileID.Saplings; Main.tile[x, y].Get().HasTile = true; - WorldGen.GrowPalmTree(x, y); + if (!WorldGen.GrowPalmTree(x, y)) + WorldGen.KillTile(x, y); + } + } + + public static void CreateBeachNearSea() + { + int beachWidth = WorldGen.genRand.Next(150, 190 + 1); + + var searchCondition = Searches.Chain(new Searches.Down(3000), new Conditions.IsSolid()); + WorldUtils.Find(new Point(BiomeWidth + 4, (int)WorldGen.worldSurfaceLow - 20), searchCondition, out Point determinedPoint); + Tile tileAtEdge = CalamityUtils.ParanoidTileRetrieval(determinedPoint.X, determinedPoint.Y); + + // Extend outward to encompass some of the desert, if there is one. + if (tileAtEdge.TileType is TileID.Sand or TileID.Ebonsand or TileID.Crimsand) + beachWidth += 85; + + // Transform the landscape. + for (int i = BiomeWidth - 10; i <= BiomeWidth + beachWidth; i++) + { + int x = GetActualX(i); + float xRatio = Utils.GetLerpValue(BiomeWidth - 10, BiomeWidth + beachWidth, i, true); + float ditherChance = Utils.GetLerpValue(0.92f, 0.99f, xRatio, true); + int depth = (int)(Math.Sin((1f - xRatio) * MathHelper.PiOver2) * 45f + 1f); + for (int y = YStart - 50; y < YStart + depth; y++) + { + Tile tileAtPosition = CalamityUtils.ParanoidTileRetrieval(x, y); + if (tileAtPosition.HasTile && ValidBeachDestroyTiles.Contains(tileAtPosition.TileType)) + { + // Kill trees manually so that no leftover tiles are present. + if (Main.tile[x, y].TileType == TileID.Trees) + WorldGen.KillTile(x, y); + else + Main.tile[x, y].Get().HasTile = false; + } + + else if (tileAtPosition.HasTile && ValidBeachCovertTiles.Contains(tileAtPosition.TileType) && WorldGen.genRand.NextFloat() >= ditherChance) + Main.tile[x, y].TileType = (ushort)ModContent.TileType(); + } + } + + // Plant new trees. + for (int x = BiomeWidth - 10; x <= BiomeWidth + beachWidth; x++) + { + int trueX = Abyss.AtLeftSideOfWorld ? x : Main.maxTilesX - x; + if (!WorldGen.genRand.NextBool(10)) + continue; + + int y = YStart - 30; + if (!WorldUtils.Find(new Point(trueX, y), Searches.Chain(new Searches.Down(100), new Conditions.IsTile((ushort)ModContent.TileType())), out Point treePlantPosition)) + continue; + + treePlantPosition.Y--; + + // Place the saplings and try to grow them. + WorldGen.PlaceTile(treePlantPosition.X, treePlantPosition.Y, ModContent.TileType()); + Main.tile[treePlantPosition].TileType = TileID.Saplings; + Main.tile[treePlantPosition].Get().HasTile = true; + if (!WorldGen.GrowPalmTree(treePlantPosition.X, treePlantPosition.Y)) + WorldGen.KillTile(treePlantPosition.X, treePlantPosition.Y); } } #endregion Generation Functions @@ -640,6 +701,45 @@ namespace CalamityMod.World WallID.CrimstoneUnsafe, }; + public static readonly List ValidBeachCovertTiles = new() + { + TileID.Dirt, + TileID.Stone, + TileID.Crimstone, + TileID.Ebonstone, + TileID.Sand, + TileID.Ebonsand, + TileID.Crimsand, + TileID.Grass, + TileID.CorruptGrass, + TileID.CrimsonGrass, + TileID.ClayBlock, + TileID.Mud, + }; + + public static readonly List ValidBeachDestroyTiles = new() + { + TileID.Coral, + TileID.BeachPiles, + TileID.Plants, + TileID.Plants2, + TileID.SmallPiles, + TileID.LargePiles, + TileID.LargePiles2, + TileID.CorruptThorns, + TileID.CrimsonThorns, + TileID.DyePlants, + TileID.Trees, + TileID.Sunflower, + TileID.LilyPad, + TileID.SeaOats, + TileID.ImmatureHerbs, + TileID.MatureHerbs, + TileID.BloomingHerbs, + TileID.VanityTreeSakura, + TileID.VanityTreeYellowWillow, + }; + // This method is an involutory function, meaning that applying it to the same number twice always yields the original number. public static int GetActualX(int x) {