diff --git a/BiomeManagers/AbyssLayer1Biome.cs b/BiomeManagers/AbyssLayer1Biome.cs index 9e299f96e9..80842c3696 100644 --- a/BiomeManagers/AbyssLayer1Biome.cs +++ b/BiomeManagers/AbyssLayer1Biome.cs @@ -36,7 +36,7 @@ namespace CalamityMod.BiomeManagers if (WeakReferenceSupport.InAnySubworld()) return false; - return point.Y > (Main.rockLayer - y * 0.05) && + return point.Y > SulphurousSea.YStart + SulphurousSea.BlockDepth - 78 && !player.lavaWet && !player.honeyWet && abyssPosY && diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 61c3691905..653b0bf2a3 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -80,6 +80,7 @@ namespace CalamityMod.CalPlayer public static bool areThereAnyDamnEvents = false; public bool drawBossHPBar = true; public float stealthUIAlpha = 1f; + public float SulphWaterUIOpacity = 1f; public bool shouldDrawSmallText = true; public int projTypeJustHitBy; public int sCalDeathCount = 0; @@ -195,7 +196,6 @@ namespace CalamityMod.CalPlayer public int modStealthTimer; public int dashTimeMod; public int hInfernoBoost = 0; - public int pissWaterBoost = 0; public int packetTimer = 0; public int navyRodAuraTimer = 0; public int brimLoreInfernoTimer = 0; @@ -226,6 +226,7 @@ namespace CalamityMod.CalPlayer public int spiritOriginBullseyeShootCountdown = 0; public int spiritOriginConvertedCrit = 0; public int RustyMedallionCooldown = 0; + public float SulphWaterPoisoningLevel; private const int DashDisableCooldown = 12; @@ -776,6 +777,9 @@ namespace CalamityMod.CalPlayer public bool banishingFire = false; public bool wither = false; public bool ManaBurn = false; + + public const int SulphSeaWaterSafetyTime = 720; + public const int SulphSeaWaterRecoveryTime = 150; #endregion #region Buff @@ -2120,6 +2124,7 @@ namespace CalamityMod.CalPlayer fungalSymbioteTimer = 0; aBulwarkRareTimer = 0; RustyMedallionCooldown = 0; + SulphWaterPoisoningLevel = 0f; spiritOriginConvertedCrit = 0; rage = 0f; adrenaline = 0f; @@ -2212,6 +2217,8 @@ namespace CalamityMod.CalPlayer stealthUIAlpha -= 0.035f; stealthUIAlpha = MathHelper.Clamp(stealthUIAlpha, 0f, 1f); } + if (SulphWaterUIOpacity > 0f) + SulphWaterUIOpacity = MathHelper.Clamp(SulphWaterUIOpacity - 0.035f, 0f, 1f); #endregion #region Buffs diff --git a/CalPlayer/CalamityPlayerLifeRegen.cs b/CalPlayer/CalamityPlayerLifeRegen.cs index 08e23f7e7a..eefa9b0d24 100644 --- a/CalPlayer/CalamityPlayerLifeRegen.cs +++ b/CalPlayer/CalamityPlayerLifeRegen.cs @@ -9,6 +9,9 @@ using Microsoft.Xna.Framework; using System; using Terraria; using Terraria.ModLoader; +using Terraria.DataStructures; +using CalamityMod.Systems; +using System.Linq; namespace CalamityMod.CalPlayer { @@ -156,39 +159,31 @@ namespace CalamityMod.CalPlayer lifeRegenLost += 4; } - if (ZoneSulphur && Player.IsUnderwater() && !decayEffigy && !abyssalDivingSuit && !Player.lavaWet && !Player.honeyWet) + // Slowly increase the sulphuric water poisoning effect. Once it's high enough, the player starts taking damage over time. + bool nearSafeZone = false; + if (SulphuricWaterSafeZoneSystem.NearbySafeTiles.Count >= 1) { - Player.AddBuff(ModContent.BuffType(), 2, true); - pissWaterBoost++; + Point closestSafeZone = SulphuricWaterSafeZoneSystem.NearbySafeTiles.Keys.OrderBy(t => t.ToVector2().DistanceSQ(Player.Center / 16f)).First(); + if (Vector2.Distance(Player.Center.ToTileCoordinates().ToVector2(), closestSafeZone.ToVector2()) < SulphuricWaterSafeZoneSystem.NearbySafeTiles[closestSafeZone] * 17f) + nearSafeZone = true; + } + if (ZoneSulphur && Player.IsUnderwater() && !decayEffigy && !abyssalDivingSuit && !Player.lavaWet && !Player.honeyWet && !nearSafeZone) + { + float increment = 1f / SulphSeaWaterSafetyTime; + if (sulphurskin) + increment *= 0.5f; + if (sulfurSet) + increment *= 0.5f; - if (Player.lifeRegen > 0) - Player.lifeRegen = 0; - - Player.lifeRegenTime = 0; - int waterDivisor = 250; - int minimumRegenLost = 8; - if (sulfurSet && sulphurskin) + SulphWaterPoisoningLevel = MathHelper.Clamp(SulphWaterPoisoningLevel + increment, 0f, 1f); + if (SulphWaterPoisoningLevel >= 1f) { - waterDivisor = 500; - minimumRegenLost = 1; + SulphWaterPoisoningLevel = 0f; + Player.Hurt(PlayerDeathReason.ByCustomReason($"{Player.name}'s flesh was dissolved by sulphuric water."), Math.Min(Player.statLifeMax2 / 2, 200), 0); } - else if (sulfurSet) - { - waterDivisor = 400; - minimumRegenLost = 3; - } - else if (sulphurskin) - { - waterDivisor = 350; - minimumRegenLost = 2; - } - int sulphurWater = pissWaterBoost / waterDivisor; - if (sulphurWater < minimumRegenLost) - sulphurWater = minimumRegenLost; - lifeRegenLost += sulphurWater; } else - pissWaterBoost = 0; + SulphWaterPoisoningLevel = MathHelper.Clamp(SulphWaterPoisoningLevel - 1f / SulphSeaWaterRecoveryTime, 0f, 1f); if (sulphurPoison) { diff --git a/CalamityConfig.cs b/CalamityConfig.cs index f5553c1b85..a5dfabdaa3 100644 --- a/CalamityConfig.cs +++ b/CalamityConfig.cs @@ -17,6 +17,7 @@ using Terraria.ModLoader.Config; using CalamityMod.Items.PermanentBoosters; using CalamityMod.UI.Rippers; using CalamityMod.UI.DraedonsArsenal; +using CalamityMod.UI.SulphurousWaterMeter; namespace CalamityMod { @@ -140,6 +141,22 @@ namespace CalamityMod [Tooltip("$Mods.CalamityMod.Config.EntryTooltip.StealthMeterPosY")] public float StealthMeterPosY { get; set; } + [Label("$Mods.CalamityMod.Config.EntryTitle.SulphuricWaterMeterPosX")] + [BackgroundColor(192, 54, 64, 192)] + [SliderColor(224, 165, 56, 128)] + [Range(0f, 100f)] + [DefaultValue(SulphurousWaterMeterUI.DefaultPosX)] + [Tooltip("$Mods.CalamityMod.Config.EntryTooltip.SulphuricWaterMeterPosX")] + public float SulphuricWaterMeterPosX { get; set; } + + [Label("$Mods.CalamityMod.Config.EntryTitle.SulphuricWaterMeterPosY")] + [BackgroundColor(192, 54, 64, 192)] + [SliderColor(224, 165, 56, 128)] + [Range(0f, 100f)] + [DefaultValue(SulphurousWaterMeterUI.DefaultPosY)] + [Tooltip("$Mods.CalamityMod.Config.EntryTooltip.SulphuricWaterMeterPosY")] + public float SulphuricWaterMeterPosY { get; set; } + [Label("$Mods.CalamityMod.Config.EntryTitle.ChargeMeter")] [BackgroundColor(192, 54, 64, 192)] [DefaultValue(true)] @@ -394,6 +411,9 @@ namespace CalamityMod new("StealthMeterPosX", ItemID.LaserRuler), new("StealthMeterPosY", ItemID.LaserRuler), + new("SulphuricWaterMeterPosX", ItemID.LaserRuler), + new("SulphuricWaterMeterPosY", ItemID.LaserRuler), + new("ChargeMeter", ModContent.ItemType()), new("ChargeMeterPosX", ItemID.LaserRuler), new("ChargeMeterPosY", ItemID.LaserRuler), diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index 66b3830167..84149f4aa9 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -54,9 +54,10 @@ namespace CalamityMod.ILEditing On.Terraria.Main.DrawInfernoRings += DrawForegroundParticles; On.Terraria.Main.SetDisplayMode += ResetRenderTargetSizes; On.Terraria.GameContent.Drawing.TileDrawing.DrawPartialLiquid += DrawCustomLava; - IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw += DrawCustomLava2; + IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw += ChangeWaterQuadColors; IL.Terraria.Main.oldDrawWater += DrawCustomLava3; IL.Terraria.Player.CollectTaxes += MakeTaxCollectorUseful; + On.Terraria.Graphics.Light.TileLightScanner.GetTileLight += MakeSulphSeaWaterBetter; On.Terraria.Main.DrawGore += DrawForegroundStuff; On.Terraria.GameContent.Drawing.TileDrawing.PreDrawTiles += ClearForegroundStuff; On.Terraria.GameContent.Drawing.TileDrawing.Draw += ClearTilePings; @@ -165,9 +166,10 @@ namespace CalamityMod.ILEditing On.Terraria.Main.DrawInfernoRings -= DrawForegroundParticles; On.Terraria.Main.SetDisplayMode -= ResetRenderTargetSizes; On.Terraria.GameContent.Drawing.TileDrawing.DrawPartialLiquid -= DrawCustomLava; - IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw -= DrawCustomLava2; + IL.Terraria.GameContent.Liquid.LiquidRenderer.InternalDraw -= ChangeWaterQuadColors; IL.Terraria.Main.oldDrawWater -= DrawCustomLava3; IL.Terraria.Player.CollectTaxes -= MakeTaxCollectorUseful; + On.Terraria.Graphics.Light.TileLightScanner.GetTileLight -= MakeSulphSeaWaterBetter; // IL.Terraria.WaterfallManager.DrawWaterfall -= DrawCustomLavafalls; On.Terraria.NPC.Collision_DecideFallThroughPlatforms -= EnableCalamityBossPlatformCollision; IL.Terraria.Wiring.HitWireSingle -= AddTwinklersToStatue; diff --git a/ILEditing/ILHelperMethods.cs b/ILEditing/ILHelperMethods.cs index 5b3f53aefa..f11c936e0a 100644 --- a/ILEditing/ILHelperMethods.cs +++ b/ILEditing/ILHelperMethods.cs @@ -5,6 +5,10 @@ using MonoMod.Cil; using Terraria; using Terraria.ID; using Terraria.Audio; +using CalamityMod.Systems; +using Terraria.Graphics; +using System.Collections.Generic; +using System.Linq; namespace CalamityMod.ILEditing { @@ -110,6 +114,41 @@ namespace CalamityMod.ILEditing return initialLightColor; } + private static void SelectSulphuricWaterColor(int x, int y, ref VertexColors initialColor) + { + if (SulphuricWaterSafeZoneSystem.NearbySafeTiles.Count >= 1) + { + Color cleanWaterColor = new(10, 62, 193); + Point closestSafeZone = SulphuricWaterSafeZoneSystem.NearbySafeTiles.Keys.OrderBy(t => t.ToVector2().DistanceSQ(new(x, y))).First(); + List points = new() + { + new Vector2(x - 0.5f, y - 0.5f), + new Vector2(x + 0.5f, y - 0.5f), + new Vector2(x - 0.5f, y + 0.5f), + new Vector2(x + 0.5f, y + 0.5f), + }; + + for (int i = 0; i < 4; i++) + { + float distanceToClosest = points[i].Distance(closestSafeZone.ToVector2()); + float acidicWaterInterpolant = Utils.GetLerpValue(12f, 20.5f, distanceToClosest + (1f - SulphuricWaterSafeZoneSystem.NearbySafeTiles[closestSafeZone]) * 21f, true); + if (i == 0) + initialColor.TopLeftColor = Color.Lerp(initialColor.TopLeftColor, cleanWaterColor, 1f - acidicWaterInterpolant); + if (i == 1) + initialColor.TopRightColor = Color.Lerp(initialColor.TopRightColor, cleanWaterColor, 1f - acidicWaterInterpolant); + if (i == 2) + initialColor.BottomLeftColor = Color.Lerp(initialColor.BottomLeftColor, cleanWaterColor, 1f - acidicWaterInterpolant); + if (i == 3) + initialColor.BottomRightColor = Color.Lerp(initialColor.BottomRightColor, cleanWaterColor, 1f - acidicWaterInterpolant); + } + } + + initialColor.TopLeftColor *= 0.4f; + initialColor.TopRightColor *= 0.4f; + initialColor.BottomLeftColor *= 0.4f; + initialColor.BottomRightColor *= 0.4f; + } + public static void DumpToLog(ILContext il) => CalamityMod.Instance.Logger.Debug(il.ToString()); public static void LogFailure(string name, string reason) => CalamityMod.Instance.Logger.Warn($"IL edit \"{name}\" failed! {reason}"); } diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index f429cc5250..da0092b722 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -42,6 +42,8 @@ using Terraria.GameContent.Events; using CalamityMod.DataStructures; using CalamityMod.Particles.Metaballs; using Terraria.GameContent.Drawing; +using CalamityMod.Tiles.Abyss; +using System.Collections.Generic; namespace CalamityMod.ILEditing { @@ -746,7 +748,7 @@ namespace CalamityMod.ILEditing } } - private static void DrawCustomLava2(ILContext il) + private static void ChangeWaterQuadColors(ILContext il) { ILCursor cursor = new ILCursor(il); @@ -778,12 +780,17 @@ namespace CalamityMod.ILEditing cursor.Emit(OpCodes.Ldloc, 8); cursor.Emit(OpCodes.Ldelem_Ref); cursor.Emit(OpCodes.Ldloc, 8); - cursor.EmitDelegate>((initialColor, initialTexture, liquidType) => + cursor.Emit(OpCodes.Ldloc, 3); + cursor.Emit(OpCodes.Ldloc, 4); + cursor.EmitDelegate>((initialColor, initialTexture, liquidType, x, y) => { initialColor.TopLeftColor = SelectLavaColor(initialTexture, initialColor.TopLeftColor, liquidType == 1); initialColor.TopRightColor = SelectLavaColor(initialTexture, initialColor.TopRightColor, liquidType == 1); initialColor.BottomLeftColor = SelectLavaColor(initialTexture, initialColor.BottomLeftColor, liquidType == 1); initialColor.BottomRightColor = SelectLavaColor(initialTexture, initialColor.BottomRightColor, liquidType == 1); + if (liquidType == ModContent.Find("CalamityMod/SulphuricWater").Slot) + SelectSulphuricWaterColor(x, y, ref initialColor); + return initialColor; }); } @@ -877,6 +884,27 @@ namespace CalamityMod.ILEditing } #endregion Custom Lava Visuals + #region Sulph Sea Water Visuals + private static void MakeSulphSeaWaterBetter(On.Terraria.Graphics.Light.TileLightScanner.orig_GetTileLight orig, TileLightScanner self, int x, int y, out Vector3 outputColor) + { + orig(self, x, y, out outputColor); + + Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); + if (tile.LiquidAmount <= 0 || tile.HasTile || Main.waterStyle != ModContent.Find("CalamityMod/SulphuricWater").Slot) + return; + + Tile above = CalamityUtils.ParanoidTileRetrieval(x, y - 1); + if (!Main.gamePaused && !above.HasTile && above.LiquidAmount <= 0 && Main.rand.NextBool(9)) + { + MediumMistParticle acidFoam = new(new(x * 16f + Main.rand.NextFloat(16f), y * 16f + 8f), -Vector2.UnitY.RotatedByRandom(0.67f) * Main.rand.NextFloat(1f, 2.4f), Color.LightSeaGreen, Color.White, 0.16f, 128f, 0.02f); + GeneralParticleHandler.SpawnParticle(acidFoam); + } + + if (tile.TileType != (ushort)ModContent.TileType()) + outputColor = Vector3.Lerp(outputColor, Color.LightSeaGreen.ToVector3(), 0.41f); + } + #endregion Sulph Sea Water Visuals + #region Statue Additions /// /// Change the following code sequence in Wiring.HitWireSingle 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/Items/Placeables/SulphurousSand.cs b/Items/Placeables/SulphurousSand.cs index 310fbdcefb..543e412329 100644 --- a/Items/Placeables/SulphurousSand.cs +++ b/Items/Placeables/SulphurousSand.cs @@ -12,7 +12,7 @@ namespace CalamityMod.Items.Placeables public override void SetDefaults() { - Item.createTile = ModContent.TileType(); + Item.createTile = ModContent.TileType(); Item.useStyle = ItemUseStyleID.Swing; Item.useTurn = true; Item.useAnimation = 15; diff --git a/Localization/enUS.hjson b/Localization/enUS.hjson index 7dfc0377d0..753cd9e2d4 100644 --- a/Localization/enUS.hjson +++ b/Localization/enUS.hjson @@ -56,6 +56,8 @@ Config: "StealthMeter": "Display Stealth Meter", "StealthMeterPosX": "Stealth Meter X Position", "StealthMeterPosY": "Stealth Meter Y Position", + "SulphuricWaterMeterPosX": "Sulphuric Water Poison Meter X Position", + "SulphuricWaterMeterPosY": "Sulphuric Water Poison Meter Y Position", "TownNPCSpawnRateMultiplier": "Town NPC Spawn Rate Multiplier", "TownNPCsSpawnAtNight": "Town NPCs Spawn at Night", "VanillaCooldownDisplay": "Display Vanilla Cooldowns", @@ -102,6 +104,8 @@ Config: "StealthMeter": "Enables the Stealth Meter UI, which shows the player's current stealth level.\nThe Stealth Meter is always hidden if not wearing Rogue armor.", "StealthMeterPosX": "The X position of the Stealth Meter, measured as a % of your screen width.\nThe meter can be dragged with the mouse if Lock Meter Positions is disabled.", "StealthMeterPosY": "The Y position of the Stealth Meter, measured as a % of your screen height.\nThe meter can be dragged with the mouse if Lock Meter Positions is disabled.", + "SulphuricWaterMeterPosX": "The X position of the Sulphuric Water Poison Meter, measured as a % of your screen width.\nThe meter can be dragged with the mouse if Lock Meter Positions is disabled.", + "SulphuricWaterMeterPosY": "The Y position of the Sulphuric Water Poison Meter, measured as a % of your screen height.\nThe meter can be dragged with the mouse if Lock Meter Positions is disabled.", "TownNPCSpawnRateMultiplier": "Directly multiply the rate at which town NPCs spawn and respawn.\nThis reduces waiting times if a boss or event wipes your whole town.", "TownNPCsSpawnAtNight": "When enabled, town NPCs can spawn and respawn at night.\nThis includes the Old Man.", "VanillaCooldownDisplay": "Adds the vanilla debuffs Potion Sickness and Chaos State to the Cooldown Rack.\nThis doesn't remove them from your buff list, but can help with visibility nontheless", diff --git a/NPCs/AcidRain/NuclearToad.cs b/NPCs/AcidRain/NuclearToad.cs index e32e79e0f8..8993909185 100644 --- a/NPCs/AcidRain/NuclearToad.cs +++ b/NPCs/AcidRain/NuclearToad.cs @@ -13,12 +13,29 @@ using Terraria.GameContent.Bestiary; using Terraria.GameContent.ItemDropRules; using Terraria.ID; using Terraria.ModLoader; +using System; namespace CalamityMod.NPCs.AcidRain { public class NuclearToad : ModNPC { public Player Target => Main.player[NPC.target]; + + public static float ExplosionStartRadius + { + get + { + float explodeDistance = DownedBossSystem.downedAquaticScourge ? 360f : 270f; + if (DownedBossSystem.downedPolterghast) + explodeDistance = 560f; + return explodeDistance; + } + } + + public ref float ExplosionTimer => ref NPC.ai[0]; + + public const float ExplosionTelegraphTime = 120f; + public override void SetStaticDefaults() { DisplayName.SetDefault("Nuclear Toad"); @@ -69,8 +86,8 @@ namespace CalamityMod.NPCs.AcidRain { bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { - // Will move to localization whenever that is cleaned up. - new FlavorTextBestiaryInfoElement("When threatened underwater they rapidly inflate and bob to the surface. As a last resort, they forcefully burst themselves. Their selfless goal is the prolonged survival of their kin.") + // Will move to localization whenever that is cleaned up. + new FlavorTextBestiaryInfoElement("When threatened underwater they rapidly inflate and bob to the surface. As a last resort, they forcefully burst themselves. Their selfless goal is the prolonged survival of their kin.") }); } @@ -97,24 +114,22 @@ namespace CalamityMod.NPCs.AcidRain NPC.velocity.Y += 0.16f; if (NPC.velocity.Y > 3f) NPC.velocity.Y = 3f; - NPC.ai[0] = 5f; } // Make a frog croak sound from time to time. if (Main.rand.NextBool(480)) SoundEngine.PlaySound(SoundID.Zombie13, NPC.Center); - float explodeDistance = DownedBossSystem.downedAquaticScourge ? 295f : 195f; - if (DownedBossSystem.downedPolterghast) - explodeDistance = 470f; - // Explode if a player gets too close. - if (NPC.WithinRange(Target.Center, explodeDistance)) + if (NPC.WithinRange(Target.Center, ExplosionStartRadius) || ExplosionTimer >= 1f) + ExplosionTimer++; + + if (ExplosionTimer >= ExplosionTelegraphTime) { if (Main.netMode != NetmodeID.MultiplayerClient) { int damage = Main.expertMode ? DownedBossSystem.downedAquaticScourge ? 21 : 8 : DownedBossSystem.downedAquaticScourge ? 27 : 10; - float speed = Main.rand.NextFloat(6f, 9f); + float speed = Main.rand.NextFloat(8f, 12f); if (DownedBossSystem.downedPolterghast) { speed *= 1.8f; @@ -122,7 +137,7 @@ namespace CalamityMod.NPCs.AcidRain } for (int i = 0; i < 7; i++) - Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center, Main.rand.NextVector2CircularEdge(speed, speed), ModContent.ProjectileType(), damage, 1f); + Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center, -Vector2.UnitY.RotatedByRandom(0.79f) * speed * Main.rand.NextFloat(0.8f, 1f), ModContent.ProjectileType(), damage, 1f); } SoundEngine.PlaySound(SoundID.DD2_KoboldExplosion, NPC.Center); NPC.life = 0; @@ -132,6 +147,14 @@ namespace CalamityMod.NPCs.AcidRain } } + public override Color? GetAlpha(Color drawColor) + { + float explosionInterpolant = ExplosionTimer / ExplosionTelegraphTime; + float fadeToRed = (float)Math.Abs(Math.Sin(MathHelper.Pi * Math.Pow(explosionInterpolant, 3D) * 6f)); + Color c = Color.Lerp(drawColor, new(232, 40, 12, 0), fadeToRed * 0.75f); + return c * NPC.Opacity; + } + public override void FindFrame(int frameHeight) { NPC.frameCounter++; diff --git a/NPCs/AcidRain/Skyfin.cs b/NPCs/AcidRain/Skyfin.cs index b8b5f5b100..f6058d0672 100644 --- a/NPCs/AcidRain/Skyfin.cs +++ b/NPCs/AcidRain/Skyfin.cs @@ -38,7 +38,7 @@ namespace CalamityMod.NPCs.AcidRain NPC.aiStyle = AIType = -1; NPC.damage = 12; - NPC.lifeMax = 70; + NPC.lifeMax = 50; NPC.defense = 6; NPC.knockBackResist = 1f; diff --git a/NPCs/AquaticScourge/AquaticUrchin.cs b/NPCs/AquaticScourge/AquaticUrchin.cs deleted file mode 100644 index 290e1c9f32..0000000000 --- a/NPCs/AquaticScourge/AquaticUrchin.cs +++ /dev/null @@ -1,101 +0,0 @@ -using CalamityMod.BiomeManagers; -using CalamityMod.Buffs.StatDebuffs; -using CalamityMod.Items.Placeables.Banners; -using CalamityMod.Items.Weapons.Rogue; -using Terraria; -using Terraria.GameContent.Bestiary; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.NPCs.AquaticScourge -{ - public class AquaticUrchin : ModNPC - { - public override void SetStaticDefaults() - { - DisplayName.SetDefault("Aquatic Urchin"); - } - - public override void SetDefaults() - { - NPC.aiStyle = -1; - AIType = -1; - NPC.damage = Main.hardMode ? 50 : 25; - NPC.width = 40; - NPC.height = 40; - NPC.defense = 10; - NPC.lifeMax = Main.hardMode ? 300 : 50; - NPC.knockBackResist = 0.8f; - NPC.value = Item.buyPrice(0, 0, 0, 80); - NPC.HitSound = SoundID.NPCHit1; - NPC.DeathSound = SoundID.NPCDeath15; - NPC.behindTiles = true; - Banner = NPC.type; - BannerItem = ModContent.ItemType(); - NPC.Calamity().VulnerableToHeat = false; - NPC.Calamity().VulnerableToSickness = false; - NPC.Calamity().VulnerableToElectricity = true; - NPC.Calamity().VulnerableToWater = false; - SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; - } - - public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) - { - bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { - - // Will move to localization whenever that is cleaned up. - new FlavorTextBestiaryInfoElement("A relative of its brethren in the far ocean, this one’s spines have been hardened by the sulphuric waters. They drip with the venom they inhabit, so it’s better to not be struck by them.") - }); - } - - public override void AI() - { - CalamityAI.UnicornAI(NPC, Mod, true, NPC.wet ? 12f : 4f, NPC.wet ? 7f : 3f, NPC.wet ? 0.12f : 0.05f, NPC.wet ? -16f : -7.5f, NPC.wet ? -14f : -6.5f, NPC.wet ? -13f : -6f, NPC.wet ? -12f : -5f, NPC.wet ? -15f : -7f); - } - - public override void OnHitPlayer(Player player, int damage, bool crit) - { - if (damage > 0) - player.AddBuff(ModContent.BuffType(), 120, true); - } - - public override float SpawnChance(NPCSpawnInfo spawnInfo) - { - if (spawnInfo.PlayerSafe) - { - return 0f; - } - if (spawnInfo.Player.Calamity().ZoneSulphur && spawnInfo.Water && NPC.CountNPCS(ModContent.NPCType()) < 2) - { - return 0.2f; - } - return 0f; - } - - public override void ModifyNPCLoot(NPCLoot npcLoot) - { - npcLoot.Add(ModContent.ItemType(), 1, 15, 25); - } - - public override void HitEffect(int hitDirection, double damage) - { - for (int k = 0; k < 5; k++) - { - Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); - } - if (NPC.life <= 0) - { - for (int k = 0; k < 20; k++) - { - Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); - } - if (Main.netMode != NetmodeID.Server) - { - Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("AquaticUrchin").Type, 1f); - Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("AquaticUrchin2").Type, 1f); - Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("AquaticUrchin3").Type, 1f); - } - } - } - } -} diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index 46b6aaf9d0..57613ad6fd 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -2435,7 +2435,7 @@ namespace CalamityMod.NPCs spriteBatch.Draw(texture, npc.Center - screenOffset + offset, npc.frame, - Color.White, + npc.GetAlpha(Color.White), npc.rotation, npc.frame.Size() * 0.5f, npc.scale, diff --git a/NPCs/CalamityGlobalNPCLoot.cs b/NPCs/CalamityGlobalNPCLoot.cs index 8cff0336db..f4a1d5f94f 100644 --- a/NPCs/CalamityGlobalNPCLoot.cs +++ b/NPCs/CalamityGlobalNPCLoot.cs @@ -866,6 +866,9 @@ namespace CalamityMod.NPCs EoWKill.Add(ModContent.ItemType(), ThankYouPainting.DropInt); npcLoot.AddNormalOnly(EoWKill); + // Would be in the bag otherwise + npcLoot.AddIf((info) => info.npc.boss, ModContent.ItemType(), ThankYouPainting.DropInt); + // Master items drop in Revengeance rev.AddIf((info) => info.npc.boss, ItemID.EaterofWorldsMasterTrophy); rev.AddIf((info) => info.npc.boss, ItemID.EaterOfWorldsPetItem, 4); @@ -887,7 +890,7 @@ namespace CalamityMod.NPCs // Expert+ drops are also available on Normal npcLoot.AddNormalOnly(DropHelper.PerPlayer(ItemID.BrainOfConfusion)); - // Would be in the bag otherwise + // Would be in the bag otherwise npcLoot.AddNormalOnly(ModContent.ItemType(), ThankYouPainting.DropInt); // Master items drop in Revengeance @@ -934,7 +937,7 @@ namespace CalamityMod.NPCs // Expert+ drops are also available on Normal npcLoot.AddNormalOnly(DropHelper.PerPlayer(ItemID.BoneHelm)); - // Would be in the bag otherwise + // Would be in the bag otherwise npcLoot.AddNormalOnly(ModContent.ItemType(), ThankYouPainting.DropInt); // Master items drop in Revengeance @@ -989,7 +992,7 @@ namespace CalamityMod.NPCs // Expert+ drops are also available on Normal npcLoot.AddNormalOnly(DropHelper.PerPlayer(ItemID.BoneGlove)); - // Would be in the bag otherwise + // Would be in the bag otherwise npcLoot.AddNormalOnly(ModContent.ItemType(), ThankYouPainting.DropInt); // Master items drop in Revengeance @@ -1068,7 +1071,7 @@ namespace CalamityMod.NPCs // However, Demon Heart does not work in Normal mode, so it's best to not drop it // npcLoot.AddNormalOnly(DropHelper.PerPlayer(ItemID.DemonHeart)); - // Would be in the bag otherwise + // Would be in the bag otherwise npcLoot.AddNormalOnly(ModContent.ItemType(), ThankYouPainting.DropInt); // WoF drops Evil Keys @@ -1089,7 +1092,7 @@ namespace CalamityMod.NPCs npcLoot.AddNormalOnly(DropHelper.PerPlayer(ItemID.VolatileGelatin)); npcLoot.AddNormalOnly(ItemID.SoulofLight, 1, 15, 20); - // Would be in the bag otherwise + // Would be in the bag otherwise npcLoot.AddNormalOnly(ModContent.ItemType(), ThankYouPainting.DropInt); // Queen Slime drops the Hallowed Key @@ -1111,7 +1114,7 @@ namespace CalamityMod.NPCs // Expert+ drops are also available on Normal npcLoot.AddNormalOnly(DropHelper.PerPlayer(ItemID.MechanicalWagonPiece)); - // Would be in the bag otherwise + // Would be in the bag otherwise npcLoot.AddNormalOnly(ModContent.ItemType(), ThankYouPainting.DropInt); // Master items drop in Revengeance @@ -1150,7 +1153,7 @@ namespace CalamityMod.NPCs npcLoot.AddIf((info) => !Main.expertMode && IsLastTwinStanding(info), ItemID.MechanicalWheelPiece); npcLoot.AddIf((info) => !Main.expertMode && IsLastTwinStanding(info), ModContent.ItemType(), 10); - // Would be in the bag otherwise + // Would be in the bag otherwise npcLoot.AddIf((info) => !Main.expertMode && IsLastTwinStanding(info), ModContent.ItemType(), ThankYouPainting.DropInt); // Master items drop in Revengeance @@ -1172,7 +1175,7 @@ namespace CalamityMod.NPCs // Expert+ drops are also available on Normal npcLoot.AddNormalOnly(DropHelper.PerPlayer(ItemID.MechanicalBatteryPiece)); - // Would be in the bag otherwise + // Would be in the bag otherwise npcLoot.AddNormalOnly(ModContent.ItemType(), ThankYouPainting.DropInt); // Master items drop in Revengeance @@ -1414,7 +1417,7 @@ namespace CalamityMod.NPCs // Expert+ drops are also available on Normal npcLoot.AddNormalOnly(DropHelper.PerPlayer(ItemID.EmpressFlightBooster)); - // Would be in the bag otherwise + // Would be in the bag otherwise npcLoot.AddNormalOnly(ModContent.ItemType(), ThankYouPainting.DropInt); // Master items drop in Revengeance diff --git a/NPCs/SulphurousSea/AquaticUrchin.cs b/NPCs/SulphurousSea/AquaticUrchin.cs new file mode 100644 index 0000000000..b7c1909dac --- /dev/null +++ b/NPCs/SulphurousSea/AquaticUrchin.cs @@ -0,0 +1,173 @@ +using CalamityMod.BiomeManagers; +using CalamityMod.Buffs.StatDebuffs; +using CalamityMod.Items.Placeables.Banners; +using CalamityMod.Items.Weapons.Rogue; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.GameContent.Bestiary; +using Terraria.ID; +using Terraria.ModLoader; +using Terraria.WorldBuilding; + +namespace CalamityMod.NPCs.SulphurousSea +{ + public class AquaticUrchin : ModNPC + { + public override void SetStaticDefaults() + { + DisplayName.SetDefault("Aquatic Urchin"); + } + + public override void SetDefaults() + { + NPC.aiStyle = -1; + AIType = -1; + NPC.damage = Main.hardMode ? 50 : 25; + NPC.width = 20; + NPC.height = 20; + NPC.defense = 10; + NPC.lifeMax = Main.hardMode ? 300 : 50; + NPC.knockBackResist = 0.8f; + NPC.value = Item.buyPrice(0, 0, 0, 80); + NPC.HitSound = SoundID.NPCHit1; + NPC.DeathSound = SoundID.NPCDeath15; + NPC.behindTiles = true; + NPC.npcSlots = 0.3333f; + Banner = NPC.type; + BannerItem = ModContent.ItemType(); + NPC.noGravity = true; + NPC.noTileCollide = true; + NPC.RemoveWaterSlowness(); + NPC.Calamity().VulnerableToHeat = false; + NPC.Calamity().VulnerableToSickness = false; + NPC.Calamity().VulnerableToElectricity = true; + NPC.Calamity().VulnerableToWater = false; + SpawnModBiomes = new int[1] { ModContent.GetInstance().Type }; + } + + public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) + { + bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { + + // Will move to localization whenever that is cleaned up. + new FlavorTextBestiaryInfoElement("A relative of its brethren in the far ocean, this one’s spines have been hardened by the sulphuric waters. They drip with the venom they inhabit, so it’s better to not be struck by them.") + }); + } + + public static void DoUrchinAI(NPC npc) + { + // Simply stick to tiles. + if (Main.netMode != NetmodeID.MultiplayerClient && npc.localAI[0] == 0f) + { + GenSearch search = Main.rand.NextBool() ? new Searches.Down(300) : new Searches.Up(300); + if (WorldUtils.Find(npc.Center.ToTileCoordinates(), Searches.Chain(search, new Conditions.IsSolid()), out Point result)) + { + npc.Center = result.ToWorldCoordinates(); + npc.netUpdate = true; + } + npc.localAI[0] = 1f; + } + + // Drift slowly over tiles. + float speedFactor = 0.018f; + + npc.collideX = MathHelper.Distance(npc.position.X, npc.oldPosition.X) < 0.01f; + npc.collideY = MathHelper.Distance(npc.position.Y, npc.oldPosition.Y) < 0.01f; + npc.noGravity = Collision.SolidCollision(npc.TopLeft - Vector2.One * 12, npc.width + 6, npc.height + 6); + if (npc.ai[1] == 0f) + { + if (npc.direction == 0) + npc.direction = 1; + + npc.rotation += npc.direction * npc.directionY * speedFactor * 0.006f; + if (npc.collideY) + npc.ai[0] = 2f; + + if (!npc.collideY && npc.ai[0] == 2f) + { + npc.direction = -npc.direction; + npc.ai[1] = 1f; + npc.ai[0] = 1f; + } + if (npc.collideX) + { + npc.directionY = -npc.directionY; + npc.ai[1] = 1f; + } + } + else + { + npc.rotation -= npc.direction * npc.directionY * 0.006f; + if (npc.collideX) + npc.ai[0] = 2f; + + if (!npc.collideX && npc.ai[0] == 2f) + { + npc.directionY = -npc.directionY; + npc.ai[1] = 0f; + npc.ai[0] = 1f; + } + if (npc.collideY) + { + npc.direction = -npc.direction; + npc.ai[1] = 0f; + } + } + npc.velocity.X = npc.direction * speedFactor; + + if (npc.noGravity) + npc.velocity.Y = npc.directionY * speedFactor; + + // Use blazing wheel movement. + Vector2 position = npc.Center - Vector2.One * 6f; + npc.velocity = Collision.noSlopeCollision(position, npc.velocity, 12, 12, true, true); + } + + public override void AI() => DoUrchinAI(NPC); + + public override void OnHitPlayer(Player player, int damage, bool crit) + { + if (damage > 0) + player.AddBuff(ModContent.BuffType(), 120, true); + } + + public override float SpawnChance(NPCSpawnInfo spawnInfo) + { + if (spawnInfo.PlayerSafe) + { + return 0f; + } + if (spawnInfo.Player.Calamity().ZoneSulphur && spawnInfo.Water && NPC.CountNPCS(ModContent.NPCType()) < 12) + { + return 1.1f; + } + return 0f; + } + + public override void ModifyNPCLoot(NPCLoot npcLoot) + { + npcLoot.Add(ModContent.ItemType(), 1, 15, 25); + } + + public override void HitEffect(int hitDirection, double damage) + { + for (int k = 0; k < 5; k++) + { + Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); + } + if (NPC.life <= 0) + { + for (int k = 0; k < 20; k++) + { + Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hitDirection, -1f, 0, default, 1f); + } + if (Main.netMode != NetmodeID.Server) + { + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("AquaticUrchin").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("AquaticUrchin2").Type, 1f); + Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("AquaticUrchin3").Type, 1f); + } + } + } + } +} diff --git a/NPCs/AquaticScourge/AquaticUrchin.png b/NPCs/SulphurousSea/AquaticUrchin.png similarity index 100% rename from NPCs/AquaticScourge/AquaticUrchin.png rename to NPCs/SulphurousSea/AquaticUrchin.png diff --git a/NPCs/SulphurousSea/Catfish.cs b/NPCs/SulphurousSea/Catfish.cs index bb1d23f13d..0e63e5102f 100644 --- a/NPCs/SulphurousSea/Catfish.cs +++ b/NPCs/SulphurousSea/Catfish.cs @@ -48,8 +48,8 @@ namespace CalamityMod.NPCs.SulphurousSea { bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { - // Will move to localization whenever that is cleaned up. - new FlavorTextBestiaryInfoElement("An animal which adapted to the toxic waters quite naturally. It uses its whiskers to find its way, and its prey in the murky depths.") + // Will move to localization whenever that is cleaned up. + new FlavorTextBestiaryInfoElement("An animal which adapted to the toxic waters quite naturally. It uses its whiskers to find its way, and its prey in the murky depths.") }); } diff --git a/Projectiles/Enemy/NuclearToadGoo.cs b/Projectiles/Enemy/NuclearToadGoo.cs index 0e500cb842..a82d9e1e4b 100644 --- a/Projectiles/Enemy/NuclearToadGoo.cs +++ b/Projectiles/Enemy/NuclearToadGoo.cs @@ -1,4 +1,4 @@ -using CalamityMod.Buffs.StatDebuffs; +using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Dusts; using Terraria; using Terraria.ModLoader; @@ -29,7 +29,7 @@ namespace CalamityMod.Projectiles.Enemy Projectile.localAI[0] = 1f; } if (Projectile.velocity.Y < 10f) - Projectile.velocity.Y += 0.175f; + Projectile.velocity.Y += 0.27f; } public override void OnHitPlayer(Player target, int damage, bool crit) diff --git a/Projectiles/Enemy/SulphuricAcidBubble.cs b/Projectiles/Enemy/SulphuricAcidBubble.cs index 71757fc8e4..2ffa4ce2c1 100644 --- a/Projectiles/Enemy/SulphuricAcidBubble.cs +++ b/Projectiles/Enemy/SulphuricAcidBubble.cs @@ -23,6 +23,7 @@ namespace CalamityMod.Projectiles.Enemy Projectile.scale = 0.01f; Projectile.hostile = true; Projectile.tileCollide = false; + Projectile.ignoreWater = true; Projectile.Opacity = 0f; Projectile.timeLeft = 360; Projectile.penetrate = 1; diff --git a/Projectiles/Environment/HotSteam.cs b/Projectiles/Environment/HotSteam.cs index 4ede545e53..1e4a674748 100644 --- a/Projectiles/Environment/HotSteam.cs +++ b/Projectiles/Environment/HotSteam.cs @@ -1,36 +1,45 @@ +using CalamityMod.DataStructures; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.GameContent; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Environment { - public class HotSteam : ModProjectile + public class HotSteam : ModProjectile, IAdditiveDrawer { - public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + public const int Lifetime = 180; + + public override string Texture => "CalamityMod/Projectiles/Summon/SmallAresArms/MinionPlasmaGas"; public override void SetStaticDefaults() { DisplayName.SetDefault("Steam"); + + // This prevents the water from creating a universal distortion wherever it lands, thus making the geysers look weird. + ProjectileID.Sets.NoLiquidDistortion[Type] = true; } public override void SetDefaults() { - Projectile.width = 40; - Projectile.height = 40; + Projectile.width = Projectile.height = 184; + Projectile.penetrate = -1; Projectile.hostile = true; - Projectile.tileCollide = true; - Projectile.ignoreWater = false; - Projectile.timeLeft = 30; + Projectile.tileCollide = false; + Projectile.ignoreWater = true; + Projectile.timeLeft = Lifetime; + Projectile.hide = true; + Projectile.localAI[0] = 1f; } + public override void AI() { - for (int i = 0; i < 6; i++) - { - Dust dust = Dust.NewDustDirect(Projectile.position, Projectile.width, Projectile.height, 4); - dust.velocity = Vector2.One.RotatedByRandom(MathHelper.TwoPi); - dust.alpha = 127; - } + Projectile.localAI[0] = 0f; + Projectile.scale = Utils.Remap(Projectile.timeLeft, Lifetime, 0.4f, 0.02f, 1.4f); + Projectile.Opacity = Utils.Remap(Projectile.timeLeft, 160f, 50f, 1.15f, 0.01f); + Projectile.velocity.Y *= 0.97f; } public override void OnHitPlayer(Player target, int damage, bool crit) @@ -40,5 +49,26 @@ namespace CalamityMod.Projectiles.Environment target.AddBuff(BuffID.Poisoned, 180); } + + public override bool? CanDamage() => Projectile.Opacity > 0.6f ? null : false; + + public override bool? Colliding(Rectangle projHitbox, Rectangle targetHitbox) + { + return CalamityUtils.CircularHitboxCollision(Projectile.Center, Projectile.scale * 92f, targetHitbox); + } + + public void AdditiveDraw(SpriteBatch spriteBatch) + { + if (Projectile.localAI[0] == 1f) + return; + + Texture2D texture = TextureAssets.Projectile[Projectile.type].Value; + Vector2 origin = texture.Size() * 0.5f; + Vector2 drawPosition = Projectile.Center - Main.screenPosition; + float opacity = Projectile.Opacity * 0.3f; + Color drawColor = new Color(159, 207, 181) * opacity; + Vector2 scale = Projectile.Size / texture.Size() * Projectile.scale * 1.35f; + spriteBatch.Draw(texture, drawPosition, null, drawColor, Projectile.rotation, origin, scale, 0, 0f); + } } } diff --git a/Schematics/CalamitySchematicIO.cs b/Schematics/CalamitySchematicIO.cs index 4f206dab30..e20262d8f9 100644 --- a/Schematics/CalamitySchematicIO.cs +++ b/Schematics/CalamitySchematicIO.cs @@ -556,6 +556,7 @@ namespace CalamityMod.Schematics { ModContent.SplitName(tileFullName, out string mod, out string tileName); Mod theMod = ModLoader.GetMod(mod); + // If that mod isn't loaded, spawn in a TML default UnloadedTile instead. smt.TileType = (ushort)(theMod is null ? ModContent.TileType() : theMod.Find(tileName).Type); } diff --git a/Systems/BiomeTileCounterSystem.cs b/Systems/BiomeTileCounterSystem.cs index b5a75c904a..2014276dcf 100644 --- a/Systems/BiomeTileCounterSystem.cs +++ b/Systems/BiomeTileCounterSystem.cs @@ -33,7 +33,7 @@ namespace CalamityMod.Systems BrimstoneCragTiles = tileCounts[ModContent.TileType()] + tileCounts[ModContent.TileType()]; SunkenSeaTiles = tileCounts[ModContent.TileType()] + tileCounts[ModContent.TileType()] + tileCounts[ModContent.TileType()]; AbyssTiles = tileCounts[ModContent.TileType()] + tileCounts[ModContent.TileType()]; - SulphurTiles = tileCounts[ModContent.TileType()] + tileCounts[ModContent.TileType()] + tileCounts[ModContent.TileType()] + tileCounts[ModContent.TileType()]; + SulphurTiles = tileCounts[ModContent.TileType()] + tileCounts[ModContent.TileType()] + tileCounts[ModContent.TileType()]; int astralDesertTiles = tileCounts[ModContent.TileType()] + tileCounts[ModContent.TileType()] + tileCounts[ModContent.TileType()] + tileCounts[ModContent.TileType()]; int astralSnowTiles = tileCounts[ModContent.TileType()] + tileCounts[ModContent.TileType()]; diff --git a/Systems/MiscWorldStateSystem.cs b/Systems/MiscWorldStateSystem.cs index 3024723608..84e7cadfb3 100644 --- a/Systems/MiscWorldStateSystem.cs +++ b/Systems/MiscWorldStateSystem.cs @@ -51,6 +51,7 @@ namespace CalamityMod BossRushEvent.HostileProjectileKillCounter = 0; CustomTemple.NewAlterPosition = Point.Zero; Abyss.AbyssChasmBottom = 0; + SulphurousSea.YStart = 0; Abyss.AtLeftSideOfWorld = false; spawnedBandit = false; @@ -130,6 +131,7 @@ namespace CalamityMod tag["downed"] = downed; tag["abyssChasmBottom"] = Abyss.AbyssChasmBottom; + tag["SulphSeaYStart"] = SulphurousSea.YStart; tag["acidRainPoints"] = AcidRainEvent.AccumulatedKillPoints; tag["Reforges"] = Reforges; tag["MoneyStolenByBandit"] = MoneyStolenByBandit; @@ -176,6 +178,7 @@ namespace CalamityMod RecipeUnlockHandler.Load(downed); Abyss.AbyssChasmBottom = tag.GetInt("abyssChasmBottom"); + SulphurousSea.YStart = tag.GetInt("SulphSeaYStart"); AcidRainEvent.AccumulatedKillPoints = tag.GetInt("acidRainPoints"); Reforges = tag.GetInt("Reforges"); MoneyStolenByBandit = tag.GetInt("MoneyStolenByBandit"); diff --git a/Systems/SulphuricWaterSafeZoneSystem.cs b/Systems/SulphuricWaterSafeZoneSystem.cs new file mode 100644 index 0000000000..6024c82d43 --- /dev/null +++ b/Systems/SulphuricWaterSafeZoneSystem.cs @@ -0,0 +1,51 @@ +using System.Collections.Generic; +using System.Linq; +using CalamityMod.Tiles; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Systems +{ + public class SulphuricWaterSafeZoneSystem : ModSystem + { + public static Dictionary NearbySafeTiles + { + get; + set; + } = new(); + + public override void PreUpdateEntities() + { + // Make the potency of the current safe tiles gradually dissipate, and eventually disappear from the dictionary once completely gone. + foreach (Point p in NearbySafeTiles.Keys) + NearbySafeTiles[p] -= 0.06f; + foreach (var key in NearbySafeTiles.Keys.Where(key => NearbySafeTiles[key] <= 0f)) + NearbySafeTiles.Remove(key); + + // TODO -- Uncomment the below code to use an actual block and not the auric tesla bar, once sprites for said blocks are created. + + /* + ushort safeTileID = (ushort)ModContent.TileType(); + Point center = Main.LocalPlayer.Center.ToTileCoordinates(); + + for (int dx = -56; dx < 56; dx++) + { + for (int dy = -56; dy < 56; dy++) + { + Point p = new(center.X + dx, center.Y + dy); + Tile t = Main.tile[p]; + + if (!t.HasTile) + continue; + + if (t.TileType != safeTileID) + continue; + + NearbySafeTiles[p] = 1f; + } + } + */ + } + } +} diff --git a/Systems/UIManagementSystem.cs b/Systems/UIManagementSystem.cs index 4d93a3799e..bb9155904d 100644 --- a/Systems/UIManagementSystem.cs +++ b/Systems/UIManagementSystem.cs @@ -5,6 +5,7 @@ using CalamityMod.UI.DraedonsArsenal; using CalamityMod.UI.DraedonSummoning; using CalamityMod.UI.ModeIndicator; using CalamityMod.UI.Rippers; +using CalamityMod.UI.SulphurousWaterMeter; using Microsoft.Xna.Framework; using Terraria; using Terraria.ModLoader; @@ -89,6 +90,13 @@ namespace CalamityMod.Systems return true; }, InterfaceScaleType.None)); + // Sulphuric water poison bar + layers.Insert(mouseIndex, new LegacyGameInterfaceLayer("Sulphuric Water Poisoning UI", () => + { + SulphurousWaterMeterUI.Draw(Main.spriteBatch, Main.LocalPlayer); + return true; + }, InterfaceScaleType.None)); + // Charge meter layers.Insert(mouseIndex, new LegacyGameInterfaceLayer("Charge UI", () => { diff --git a/Systems/WorldSyncingSystem.cs b/Systems/WorldSyncingSystem.cs index 93716eeea5..19ab8a6f40 100644 --- a/Systems/WorldSyncingSystem.cs +++ b/Systems/WorldSyncingSystem.cs @@ -140,6 +140,7 @@ namespace CalamityMod.Systems RecipeUnlockHandler.SendData(writer); writer.Write(Abyss.AbyssChasmBottom); + writer.Write(SulphurousSea.YStart); writer.Write(AcidRainEvent.AccumulatedKillPoints); writer.Write(Reforges); writer.Write(MoneyStolenByBandit); @@ -271,6 +272,7 @@ namespace CalamityMod.Systems RecipeUnlockHandler.ReceiveData(reader); Abyss.AbyssChasmBottom = reader.ReadInt32(); + SulphurousSea.YStart = reader.ReadInt32(); AcidRainEvent.AccumulatedKillPoints = reader.ReadInt32(); Reforges = reader.ReadInt32(); MoneyStolenByBandit = reader.ReadInt32(); diff --git a/Systems/WorldgenManagementSystem.cs b/Systems/WorldgenManagementSystem.cs index ab675b9354..ace6db60eb 100644 --- a/Systems/WorldgenManagementSystem.cs +++ b/Systems/WorldgenManagementSystem.cs @@ -193,7 +193,7 @@ namespace CalamityMod.Systems tasks.Insert(++currentFinalIndex, new PassLegacy("SulphurSea2", (progress, config) => { progress.Message = "Further polluting one of the oceans"; - SulphurousSea.FinishGeneratingSulphurSea(); + SulphurousSea.SulphurSeaGenerationAfterAbyss(); })); tasks.Insert(++currentFinalIndex, new PassLegacy("Roxcalibur", (progress, config) => diff --git a/Tiles/Abyss/AcidWoodTree.cs b/Tiles/Abyss/AcidWoodTree.cs index 8d962c32f2..33a3c0da10 100644 --- a/Tiles/Abyss/AcidWoodTree.cs +++ b/Tiles/Abyss/AcidWoodTree.cs @@ -20,7 +20,7 @@ namespace CalamityMod.Tiles.Abyss public override void SetStaticDefaults() { // Grows on sulphurous sand - GrowsOnTileId = new int[2] { ModContent.TileType() , ModContent.TileType()}; + GrowsOnTileId = new int[] { ModContent.TileType() }; } //Copypasted from vanilla, just as ExampleMod did, due to the lack of proper explanation diff --git a/Tiles/Abyss/AcidWoodTreeSapling.cs b/Tiles/Abyss/AcidWoodTreeSapling.cs index f663acb9af..9b918234c4 100644 --- a/Tiles/Abyss/AcidWoodTreeSapling.cs +++ b/Tiles/Abyss/AcidWoodTreeSapling.cs @@ -34,7 +34,7 @@ namespace CalamityMod.Tiles.Abyss TileObjectData.newTile.CoordinateHeights = new[] { 16, 18 }; TileObjectData.newTile.CoordinateWidth = 16; TileObjectData.newTile.CoordinatePadding = 2; - TileObjectData.newTile.AnchorValidTiles = new[] { ModContent.TileType(), ModContent.TileType(), ModContent.TileType(), ModContent.TileType() }; + TileObjectData.newTile.AnchorValidTiles = new[] { ModContent.TileType(), ModContent.TileType(), ModContent.TileType() }; TileObjectData.newTile.StyleHorizontal = true; TileObjectData.newTile.DrawFlipHorizontal = true; TileObjectData.newTile.WaterPlacement = LiquidPlacement.NotAllowed; diff --git a/Tiles/Abyss/HardenedSulphurousSandstone.cs b/Tiles/Abyss/HardenedSulphurousSandstone.cs index e934eabebf..fb6a4cd909 100644 --- a/Tiles/Abyss/HardenedSulphurousSandstone.cs +++ b/Tiles/Abyss/HardenedSulphurousSandstone.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using CalamityMod.World; +using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -57,7 +58,7 @@ namespace CalamityMod.Tiles.Abyss } } } - if (Main.tile[i, j + 1] != null && nearbyVineCount < 5) + if (Main.tile[i, j + 1] != null && nearbyVineCount < 5 && j >= SulphurousSea.VineGrowTopLimit) { if (!Main.tile[i, j + 1].HasTile && Main.tile[i, j + 1].TileType != (ushort)ModContent.TileType()) { diff --git a/Tiles/Abyss/Stalactite/SulphurousStalacmite1.png b/Tiles/Abyss/Stalactite/SulphurousStalacmite1.png index a7340e66a7..a131535693 100644 Binary files a/Tiles/Abyss/Stalactite/SulphurousStalacmite1.png and b/Tiles/Abyss/Stalactite/SulphurousStalacmite1.png differ diff --git a/Tiles/Abyss/Stalactite/SulphurousStalacmite2.png b/Tiles/Abyss/Stalactite/SulphurousStalacmite2.png index 5d297982b1..d4bf7be072 100644 Binary files a/Tiles/Abyss/Stalactite/SulphurousStalacmite2.png and b/Tiles/Abyss/Stalactite/SulphurousStalacmite2.png differ diff --git a/Tiles/Abyss/Stalactite/SulphurousStalacmite3.png b/Tiles/Abyss/Stalactite/SulphurousStalacmite3.png index 56f5f2a261..d935926115 100644 Binary files a/Tiles/Abyss/Stalactite/SulphurousStalacmite3.png and b/Tiles/Abyss/Stalactite/SulphurousStalacmite3.png differ diff --git a/Tiles/Abyss/Stalactite/SulphurousStalacmite4.png b/Tiles/Abyss/Stalactite/SulphurousStalacmite4.png index 792626edd6..d716be54c5 100644 Binary files a/Tiles/Abyss/Stalactite/SulphurousStalacmite4.png and b/Tiles/Abyss/Stalactite/SulphurousStalacmite4.png differ diff --git a/Tiles/Abyss/Stalactite/SulphurousStalacmite5.png b/Tiles/Abyss/Stalactite/SulphurousStalacmite5.png index 532fd83e59..47d6ffb3d6 100644 Binary files a/Tiles/Abyss/Stalactite/SulphurousStalacmite5.png and b/Tiles/Abyss/Stalactite/SulphurousStalacmite5.png differ diff --git a/Tiles/Abyss/Stalactite/SulphurousStalacmite6.png b/Tiles/Abyss/Stalactite/SulphurousStalacmite6.png index 2155c8ef4e..9f583a1055 100644 Binary files a/Tiles/Abyss/Stalactite/SulphurousStalacmite6.png and b/Tiles/Abyss/Stalactite/SulphurousStalacmite6.png differ diff --git a/Tiles/Abyss/Stalactite/SulphurousStalactite1.cs b/Tiles/Abyss/Stalactite/SulphurousStalactite1.cs index 9d0edcc178..6bba378e74 100644 --- a/Tiles/Abyss/Stalactite/SulphurousStalactite1.cs +++ b/Tiles/Abyss/Stalactite/SulphurousStalactite1.cs @@ -1,4 +1,4 @@ -using CalamityMod.Dusts; +using CalamityMod.Dusts; using Microsoft.Xna.Framework; using Terraria; using Terraria.DataStructures; @@ -27,7 +27,7 @@ namespace CalamityMod.Tiles.Abyss.Stalactite TileObjectData.newTile.CoordinatePadding = 2; TileObjectData.newTile.WaterDeath = false; TileObjectData.newTile.LavaDeath = true; - TileObjectData.newTile.DrawYOffset = 2; + TileObjectData.newTile.DrawYOffset = -2; TileObjectData.addTile(Type); ModTranslation name = CreateMapEntryName(); name.SetDefault("Stalactite"); diff --git a/Tiles/Abyss/Stalactite/SulphurousStalactite1.png b/Tiles/Abyss/Stalactite/SulphurousStalactite1.png index bd65323caf..7bf9f327c7 100644 Binary files a/Tiles/Abyss/Stalactite/SulphurousStalactite1.png and b/Tiles/Abyss/Stalactite/SulphurousStalactite1.png differ diff --git a/Tiles/Abyss/Stalactite/SulphurousStalactite2.cs b/Tiles/Abyss/Stalactite/SulphurousStalactite2.cs index 6edf8f9add..0ad53bb5b4 100644 --- a/Tiles/Abyss/Stalactite/SulphurousStalactite2.cs +++ b/Tiles/Abyss/Stalactite/SulphurousStalactite2.cs @@ -1,4 +1,4 @@ -using CalamityMod.Dusts; +using CalamityMod.Dusts; using Microsoft.Xna.Framework; using Terraria; using Terraria.DataStructures; @@ -27,7 +27,7 @@ namespace CalamityMod.Tiles.Abyss.Stalactite TileObjectData.newTile.CoordinatePadding = 2; TileObjectData.newTile.WaterDeath = false; TileObjectData.newTile.LavaDeath = true; - TileObjectData.newTile.DrawYOffset = 2; + TileObjectData.newTile.DrawYOffset = -2; TileObjectData.addTile(Type); ModTranslation name = CreateMapEntryName(); name.SetDefault("Stalactite"); diff --git a/Tiles/Abyss/Stalactite/SulphurousStalactite2.png b/Tiles/Abyss/Stalactite/SulphurousStalactite2.png index d85a594c34..ef28e170d4 100644 Binary files a/Tiles/Abyss/Stalactite/SulphurousStalactite2.png and b/Tiles/Abyss/Stalactite/SulphurousStalactite2.png differ diff --git a/Tiles/Abyss/Stalactite/SulphurousStalactite3.cs b/Tiles/Abyss/Stalactite/SulphurousStalactite3.cs index 56e2ad29eb..2cd9ff358b 100644 --- a/Tiles/Abyss/Stalactite/SulphurousStalactite3.cs +++ b/Tiles/Abyss/Stalactite/SulphurousStalactite3.cs @@ -1,4 +1,4 @@ -using CalamityMod.Dusts; +using CalamityMod.Dusts; using Microsoft.Xna.Framework; using Terraria; using Terraria.DataStructures; @@ -28,7 +28,7 @@ namespace CalamityMod.Tiles.Abyss.Stalactite TileObjectData.newTile.CoordinatePadding = 2; TileObjectData.newTile.WaterDeath = false; TileObjectData.newTile.LavaDeath = true; - TileObjectData.newTile.DrawYOffset = 2; + TileObjectData.newTile.DrawYOffset = -2; TileObjectData.addTile(Type); ModTranslation name = CreateMapEntryName(); name.SetDefault("Stalactite"); diff --git a/Tiles/Abyss/Stalactite/SulphurousStalactite3.png b/Tiles/Abyss/Stalactite/SulphurousStalactite3.png index 3503dcbd71..6b81d670af 100644 Binary files a/Tiles/Abyss/Stalactite/SulphurousStalactite3.png and b/Tiles/Abyss/Stalactite/SulphurousStalactite3.png differ diff --git a/Tiles/Abyss/Stalactite/SulphurousStalactite4.cs b/Tiles/Abyss/Stalactite/SulphurousStalactite4.cs index be2de66bbc..a777461a1f 100644 --- a/Tiles/Abyss/Stalactite/SulphurousStalactite4.cs +++ b/Tiles/Abyss/Stalactite/SulphurousStalactite4.cs @@ -1,4 +1,4 @@ -using CalamityMod.Dusts; +using CalamityMod.Dusts; using Microsoft.Xna.Framework; using Terraria; using Terraria.DataStructures; @@ -28,7 +28,7 @@ namespace CalamityMod.Tiles.Abyss.Stalactite TileObjectData.newTile.CoordinatePadding = 2; TileObjectData.newTile.WaterDeath = false; TileObjectData.newTile.LavaDeath = true; - TileObjectData.newTile.DrawYOffset = 2; + TileObjectData.newTile.DrawYOffset = -2; TileObjectData.addTile(Type); ModTranslation name = CreateMapEntryName(); name.SetDefault("Stalactite"); diff --git a/Tiles/Abyss/Stalactite/SulphurousStalactite4.png b/Tiles/Abyss/Stalactite/SulphurousStalactite4.png index 99e80f4efc..0335ebe4fc 100644 Binary files a/Tiles/Abyss/Stalactite/SulphurousStalactite4.png and b/Tiles/Abyss/Stalactite/SulphurousStalactite4.png differ diff --git a/Tiles/Abyss/Stalactite/SulphurousStalactite5.cs b/Tiles/Abyss/Stalactite/SulphurousStalactite5.cs index 44fcda7007..aee43c8e76 100644 --- a/Tiles/Abyss/Stalactite/SulphurousStalactite5.cs +++ b/Tiles/Abyss/Stalactite/SulphurousStalactite5.cs @@ -1,4 +1,4 @@ -using CalamityMod.Dusts; +using CalamityMod.Dusts; using Microsoft.Xna.Framework; using Terraria; using Terraria.DataStructures; @@ -29,7 +29,7 @@ namespace CalamityMod.Tiles.Abyss.Stalactite TileObjectData.newTile.CoordinatePadding = 2; TileObjectData.newTile.WaterDeath = false; TileObjectData.newTile.LavaDeath = true; - TileObjectData.newTile.DrawYOffset = 2; + TileObjectData.newTile.DrawYOffset = -2; TileObjectData.addTile(Type); ModTranslation name = CreateMapEntryName(); name.SetDefault("Stalactite"); diff --git a/Tiles/Abyss/Stalactite/SulphurousStalactite5.png b/Tiles/Abyss/Stalactite/SulphurousStalactite5.png index be82d5b48f..5b635ff2ae 100644 Binary files a/Tiles/Abyss/Stalactite/SulphurousStalactite5.png and b/Tiles/Abyss/Stalactite/SulphurousStalactite5.png differ diff --git a/Tiles/Abyss/Stalactite/SulphurousStalactite6.cs b/Tiles/Abyss/Stalactite/SulphurousStalactite6.cs index 0639322afc..465b858efe 100644 --- a/Tiles/Abyss/Stalactite/SulphurousStalactite6.cs +++ b/Tiles/Abyss/Stalactite/SulphurousStalactite6.cs @@ -1,4 +1,4 @@ -using CalamityMod.Dusts; +using CalamityMod.Dusts; using Microsoft.Xna.Framework; using Terraria; using Terraria.DataStructures; @@ -29,7 +29,7 @@ namespace CalamityMod.Tiles.Abyss.Stalactite TileObjectData.newTile.CoordinatePadding = 2; TileObjectData.newTile.WaterDeath = false; TileObjectData.newTile.LavaDeath = true; - TileObjectData.newTile.DrawYOffset = 2; + TileObjectData.newTile.DrawYOffset = -2; TileObjectData.addTile(Type); ModTranslation name = CreateMapEntryName(); name.SetDefault("Stalactite"); diff --git a/Tiles/Abyss/Stalactite/SulphurousStalactite6.png b/Tiles/Abyss/Stalactite/SulphurousStalactite6.png index 40879b24bd..dfea654465 100644 Binary files a/Tiles/Abyss/Stalactite/SulphurousStalactite6.png and b/Tiles/Abyss/Stalactite/SulphurousStalactite6.png differ diff --git a/Tiles/Abyss/SteamGeyser.cs b/Tiles/Abyss/SteamGeyser.cs index 3eac3337f8..e954255bc3 100644 --- a/Tiles/Abyss/SteamGeyser.cs +++ b/Tiles/Abyss/SteamGeyser.cs @@ -1,7 +1,7 @@ -using CalamityMod.Dusts; +using System; +using CalamityMod.Dusts; using CalamityMod.Projectiles.Environment; using Microsoft.Xna.Framework; -using System; using Terraria; using Terraria.DataStructures; using Terraria.ModLoader; @@ -16,7 +16,6 @@ namespace CalamityMod.Tiles.Abyss Main.tileFrameImportant[Type] = true; Main.tileNoAttach[Type] = true; TileObjectData.newTile.CopyFrom(TileObjectData.Style2x2); - TileObjectData.newTile.DrawYOffset = 4; TileObjectData.addTile(Type); ModTranslation name = CreateMapEntryName(); name.SetDefault("Geyser"); @@ -34,18 +33,15 @@ namespace CalamityMod.Tiles.Abyss } public override void NearbyEffects(int i, int j, bool closer) { - bool noTilesBetweenPlayer = Collision.CanHit(new Vector2(i, j) * 16, 1, 1, new Vector2(i * 16f, Main.LocalPlayer.Center.Y), 1, 1); + Tile t = CalamityUtils.ParanoidTileRetrieval(i, j); - if (WorldGen.genRand.NextBool(60) && !Main.gamePaused && noTilesBetweenPlayer) + Vector2 spawnPosition = new(i * 16f + 24f, j * 16f - 4f); + if (!Main.gamePaused && t.TileFrameX % 36 == 0 && t.TileFrameY % 36 == 0 && Collision.CanHitLine(spawnPosition, 1, 1, spawnPosition - Vector2.UnitY * 100f, 1, 1)) { - if (Math.Abs(Main.LocalPlayer.Center.X - i * 16) < 80 && - Main.LocalPlayer.Bottom.Y < j * 16 && - Main.LocalPlayer.Bottom.Y > j * 16 - 300) - { - float yeetSpeed = MathHelper.Clamp(10f - (10f * Math.Abs(Main.LocalPlayer.Bottom.Y - j * 16) / 300f), 0f, 10f); - Main.LocalPlayer.velocity.Y -= yeetSpeed; - Projectile.NewProjectile(new EntitySource_WorldEvent(), i * 16 + 8, j * 16 - 20, 0f, -10f, ModContent.ProjectileType(), Main.expertMode ? 12 : 15, 0f); - } + float positionInterpolant = (i + j) * 0.041f % 1f; + Vector2 smokeVelocity = -Vector2.UnitY.RotatedByRandom(0.11f) * MathHelper.Lerp(4.8f, 8.1f, positionInterpolant); + smokeVelocity.X += (float)Math.Cos(MathHelper.TwoPi * positionInterpolant) * 1.1f; + Projectile.NewProjectile(new EntitySource_WorldEvent(), spawnPosition, smokeVelocity, ModContent.ProjectileType(), Main.expertMode ? 12 : 15, 0f); } } } diff --git a/Tiles/Abyss/SteamGeyser.png b/Tiles/Abyss/SteamGeyser.png index ca6860255c..6d656dbcf9 100644 Binary files a/Tiles/Abyss/SteamGeyser.png and b/Tiles/Abyss/SteamGeyser.png differ diff --git a/Tiles/Abyss/SulphuricFossil1.png b/Tiles/Abyss/SulphuricFossil1.png index 719f621c0b..52bd2b67fb 100644 Binary files a/Tiles/Abyss/SulphuricFossil1.png and b/Tiles/Abyss/SulphuricFossil1.png differ diff --git a/Tiles/Abyss/SulphuricFossil2.png b/Tiles/Abyss/SulphuricFossil2.png index 9d08d9f024..bbd91f80f6 100644 Binary files a/Tiles/Abyss/SulphuricFossil2.png and b/Tiles/Abyss/SulphuricFossil2.png differ diff --git a/Tiles/Abyss/SulphuricFossil3.png b/Tiles/Abyss/SulphuricFossil3.png index 5a5a641757..fc15d7c03c 100644 Binary files a/Tiles/Abyss/SulphuricFossil3.png and b/Tiles/Abyss/SulphuricFossil3.png differ diff --git a/Tiles/Abyss/SulphurousCactus.cs b/Tiles/Abyss/SulphurousCactus.cs index 37ae76e5c4..98ad27e66f 100644 --- a/Tiles/Abyss/SulphurousCactus.cs +++ b/Tiles/Abyss/SulphurousCactus.cs @@ -9,7 +9,7 @@ namespace CalamityMod.Tiles.Abyss public override void SetStaticDefaults() { // Grows on sulphurous sand - GrowsOnTileId = new int[2] { ModContent.TileType(), ModContent.TileType() }; + GrowsOnTileId = new int[] { ModContent.TileType() }; } public override Asset GetTexture() => ModContent.Request("CalamityMod/Tiles/Abyss/SulphurousCactus"); diff --git a/Tiles/Abyss/SulphurousColumn.cs b/Tiles/Abyss/SulphurousColumn.cs index 08d49cac39..812b701766 100644 --- a/Tiles/Abyss/SulphurousColumn.cs +++ b/Tiles/Abyss/SulphurousColumn.cs @@ -20,7 +20,7 @@ namespace CalamityMod.Tiles.Abyss TileObjectData.newTile.Width = 2; TileObjectData.newTile.Height = 3; TileObjectData.newTile.Origin = new Point16(1, 2); - TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile | AnchorType.SolidWithTop | AnchorType.Table | AnchorType.SolidSide, TileObjectData.newTile.Width, 0); + TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile, TileObjectData.newTile.Width, 0); TileObjectData.newTile.UsesCustomCanPlace = true; TileObjectData.newTile.CoordinateHeights = new int[] { @@ -32,7 +32,6 @@ namespace CalamityMod.Tiles.Abyss TileObjectData.newTile.CoordinatePadding = 2; TileObjectData.newTile.WaterDeath = false; TileObjectData.newTile.LavaDeath = true; - TileObjectData.newTile.DrawYOffset = 2; TileObjectData.addTile(Type); ModTranslation name = CreateMapEntryName(); AddMapEntry(new Color(150, 100, 50), name); @@ -41,16 +40,28 @@ namespace CalamityMod.Tiles.Abyss base.SetStaticDefaults(); } + + public override void NearbyEffects(int i, int j, bool closer) + { + Tile t = CalamityUtils.ParanoidTileRetrieval(i, j); + Tile left = CalamityUtils.ParanoidTileRetrieval(i - 1, j); + Tile right = CalamityUtils.ParanoidTileRetrieval(i + 1, j); + if (t.TileFrameX % 36 == 0 && !right.HasTile) + WorldGen.KillTile(i, j); + if (t.TileFrameX % 36 == 18 && !left.HasTile) + WorldGen.KillTile(i, j); + } + public override void KillMultiTile(int i, int j, int frameX, int frameY) { - if (Main.netMode != NetmodeID.Server) + if (Main.netMode == NetmodeID.Server) + return; + + // Explode into a bunch of rocks when broken. + for (int k = 0; k < WorldGen.genRand.Next(3, 4 + 1); k++) { - for (int k = 0; k < WorldGen.genRand.Next(3, 4 + 1); k++) - { - Gore.NewGore(new EntitySource_TileBreak(i, j), new Vector2(i, j) * 16f, - Vector2.One.RotatedByRandom(MathHelper.TwoPi) * WorldGen.genRand.NextFloat(1.4f, 3.2f), - Mod.Find($"SulphurousRockGore{WorldGen.genRand.Next(3) + 1}").Type); - } + int goreID = Mod.Find($"SulphurousRockGore{WorldGen.genRand.Next(3) + 1}").Type; + Gore.NewGore(new EntitySource_TileBreak(i, j), new Vector2(i, j) * 16f, Main.rand.NextVector2Unit() * WorldGen.genRand.NextFloat(1.4f, 3.2f), goreID); } } public override void NumDust(int i, int j, bool fail, ref int num) diff --git a/Tiles/Abyss/SulphurousColumn.png b/Tiles/Abyss/SulphurousColumn.png index 7ae5f91a23..836c0668bd 100644 Binary files a/Tiles/Abyss/SulphurousColumn.png and b/Tiles/Abyss/SulphurousColumn.png differ diff --git a/Tiles/Abyss/SulphurousRib1.png b/Tiles/Abyss/SulphurousRib1.png index c504049e1e..77872bb1f8 100644 Binary files a/Tiles/Abyss/SulphurousRib1.png and b/Tiles/Abyss/SulphurousRib1.png differ diff --git a/Tiles/Abyss/SulphurousRib3.png b/Tiles/Abyss/SulphurousRib3.png index 08d87b3f8c..5a3294e3da 100644 Binary files a/Tiles/Abyss/SulphurousRib3.png and b/Tiles/Abyss/SulphurousRib3.png differ diff --git a/Tiles/Abyss/SulphurousRib4.png b/Tiles/Abyss/SulphurousRib4.png index 0a7697777c..9540391f01 100644 Binary files a/Tiles/Abyss/SulphurousRib4.png and b/Tiles/Abyss/SulphurousRib4.png differ diff --git a/Tiles/Abyss/SulphurousRib5.png b/Tiles/Abyss/SulphurousRib5.png index 491e4c63f3..1f0d06519c 100644 Binary files a/Tiles/Abyss/SulphurousRib5.png and b/Tiles/Abyss/SulphurousRib5.png differ diff --git a/Tiles/Abyss/SulphurousSand.cs b/Tiles/Abyss/SulphurousSand.cs index 72836b8cfa..807073339f 100644 --- a/Tiles/Abyss/SulphurousSand.cs +++ b/Tiles/Abyss/SulphurousSand.cs @@ -1,6 +1,6 @@ - -using CalamityMod.CalPlayer; +using CalamityMod.CalPlayer; using CalamityMod.Projectiles.Enemy; +using CalamityMod.World; using Microsoft.Xna.Framework; using Terraria; using Terraria.DataStructures; @@ -9,6 +9,10 @@ using Terraria.ModLoader; namespace CalamityMod.Tiles.Abyss { + // Old, now deleted sub-variant of sulphurous sand that was only placed by players and did not create water. + // It would create block swap issues with regular sulphurous sand and was rendered obsolete with the removal of this tile's water emission mechanic. + // For compatibility reasons (including with schematics), however, that tile is converted into this one. + [LegacyName("SulphurousSandNoWater")] public class SulphurousSand : ModTile { public override void SetStaticDefaults() @@ -32,89 +36,7 @@ namespace CalamityMod.Tiles.Abyss { num = fail ? 1 : 3; } - - public override void NearbyEffects(int i, int j, bool closer) - { - if (i < 250 && i > 150) - { - if (!closer) - { - if (Main.tile[i - 1, j] != null) - { - if (!Main.tile[i - 1, j].HasTile) - { - if (Main.tile[i - 1, j].LiquidAmount <= 128) - { - Main.tile[i - 1, j].LiquidAmount = 255; - Main.tile[i - 1, j].Get().LiquidType = LiquidID.Water; - } - } - } - if (Main.tile[i - 2, j] != null) - { - if (!Main.tile[i - 2, j].HasTile) - { - if (Main.tile[i - 2, j].LiquidAmount <= 128) - { - Main.tile[i - 2, j].LiquidAmount = 255; - Main.tile[i - 2, j].Get().LiquidType = LiquidID.Water; - } - } - } - if (Main.tile[i - 3, j] != null) - { - if (!Main.tile[i - 3, j].HasTile) - { - if (Main.tile[i - 3, j].LiquidAmount <= 128) - { - Main.tile[i - 3, j].LiquidAmount = 255; - Main.tile[i - 3, j].Get().LiquidType = LiquidID.Water; - } - } - } - } - } - else if (i > Main.maxTilesX - 250 && i < Main.maxTilesX - 150) - { - if (!closer) - { - if (Main.tile[i + 1, j] != null) - { - if (!Main.tile[i + 1, j].HasTile) - { - if (Main.tile[i + 1, j].LiquidAmount <= 128) - { - Main.tile[i + 1, j].LiquidAmount = 255; - Main.tile[i + 1, j].Get().LiquidType = LiquidID.Water; - } - } - } - if (Main.tile[i + 2, j] != null) - { - if (!Main.tile[i + 2, j].HasTile) - { - if (Main.tile[i + 2, j].LiquidAmount <= 128) - { - Main.tile[i + 2, j].LiquidAmount = 255; - Main.tile[i + 2, j].Get().LiquidType = LiquidID.Water; - } - } - } - if (Main.tile[i + 3, j] != null) - { - if (!Main.tile[i + 3, j].HasTile) - { - if (Main.tile[i + 3, j].LiquidAmount <= 128) - { - Main.tile[i + 3, j].LiquidAmount = 255; - Main.tile[i + 3, j].Get().LiquidType = LiquidID.Water; - } - } - } - } - } - } - + public override void KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem) { if (CalamityUtils.ParanoidTileRetrieval(i, j + 1).HasTile && @@ -131,7 +53,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); } @@ -210,7 +132,7 @@ namespace CalamityMod.Tiles.Abyss } } } - if (Main.tile[i, j + 1] != null && nearbyVineCount < 5) + if (Main.tile[i, j + 1] != null && nearbyVineCount < 5 && j >= SulphurousSea.VineGrowTopLimit) { if (!Main.tile[i, j + 1].HasTile && Main.tile[i, j + 1].TileType != (ushort)ModContent.TileType()) { diff --git a/Tiles/Abyss/SulphurousSandNoWater.cs b/Tiles/Abyss/SulphurousSandNoWater.cs deleted file mode 100644 index 76edcb0598..0000000000 --- a/Tiles/Abyss/SulphurousSandNoWater.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ModLoader; -using Terraria.ID; - -namespace CalamityMod.Tiles.Abyss -{ - public class SulphurousSandNoWater : ModTile - { - public override void SetStaticDefaults() - { - Main.tileSolid[Type] = true; - Main.tileBlockLight[Type] = true; - - CalamityUtils.MergeWithGeneral(Type); - CalamityUtils.MergeWithAbyss(Type); - - TileID.Sets.CanBeDugByShovel[Type] = true; - - DustType = 32; - ItemDrop = ModContent.ItemType(); - AddMapEntry(new Color(150, 100, 50)); - MineResist = 1f; - HitSound = SoundID.Dig; - } - - public override void NumDust(int i, int j, bool fail, ref int num) - { - num = fail ? 1 : 3; - } - - public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) - { - TileFraming.CustomMergeFrame(i, j, Type, ModContent.TileType(), false, false, false, false, resetFrame); - return false; - } - } -} diff --git a/Tiles/Abyss/SulphurousSandNoWater.png b/Tiles/Abyss/SulphurousSandNoWater.png deleted file mode 100644 index 180882767c..0000000000 Binary files a/Tiles/Abyss/SulphurousSandNoWater.png and /dev/null differ diff --git a/Tiles/Abyss/SulphurousSandstone.cs b/Tiles/Abyss/SulphurousSandstone.cs index b8f1c46a5b..ef03d8eda5 100644 --- a/Tiles/Abyss/SulphurousSandstone.cs +++ b/Tiles/Abyss/SulphurousSandstone.cs @@ -1,4 +1,5 @@ -using Microsoft.Xna.Framework; +using CalamityMod.World; +using Microsoft.Xna.Framework; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -57,7 +58,7 @@ namespace CalamityMod.Tiles.Abyss } } } - if (Main.tile[i, j + 1] != null && nearbyVineCount < 5) + if (Main.tile[i, j + 1] != null && nearbyVineCount < 5 && j >= SulphurousSea.VineGrowTopLimit) { if (!Main.tile[i, j + 1].HasTile && Main.tile[i, j + 1].TileType != (ushort)ModContent.TileType()) { diff --git a/UI/SulphurousWaterMeter/SulphWaterBar.png b/UI/SulphurousWaterMeter/SulphWaterBar.png new file mode 100644 index 0000000000..0ef0e181d8 Binary files /dev/null and b/UI/SulphurousWaterMeter/SulphWaterBar.png differ diff --git a/UI/SulphurousWaterMeter/SulphWaterMeter.png b/UI/SulphurousWaterMeter/SulphWaterMeter.png new file mode 100644 index 0000000000..72b6858ebf Binary files /dev/null and b/UI/SulphurousWaterMeter/SulphWaterMeter.png differ diff --git a/UI/SulphurousWaterMeter/SulphurousWaterMeterUI.cs b/UI/SulphurousWaterMeter/SulphurousWaterMeterUI.cs new file mode 100644 index 0000000000..4244b70d54 --- /dev/null +++ b/UI/SulphurousWaterMeter/SulphurousWaterMeterUI.cs @@ -0,0 +1,144 @@ +using System; +using CalamityMod.CalPlayer; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; +using ReLogic.Content; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.UI.SulphurousWaterMeter +{ + public class SulphurousWaterMeterUI : ModSystem + { + // These values were decided relative to the stealth meter positions, and are by default slightly below them. + internal const float DefaultPosX = StealthUI.DefaultStealthPosX; + internal const float DefaultPosY = StealthUI.DefaultStealthPosY + 0.0377f; + private const float MouseDragEpsilon = 0.05f; // 0.05% + + private static Vector2? dragOffset = null; + private static Texture2D edgeTexture, barTexture; + + public override void OnModLoad() + { + edgeTexture = ModContent.Request("CalamityMod/UI/SulphurousWaterMeter/SulphWaterMeter", AssetRequestMode.ImmediateLoad).Value; + barTexture = ModContent.Request("CalamityMod/UI/SulphurousWaterMeter/SulphWaterBar", AssetRequestMode.ImmediateLoad).Value; + Reset(); + } + + public override void Unload() + { + Reset(); + edgeTexture = barTexture = null; + } + + private static void Reset() => dragOffset = null; + + public static void Draw(SpriteBatch spriteBatch, Player player) + { + // Sanity check the planned position before drawing. This is done relative. + Vector2 screenRatioPosition = new Vector2(CalamityConfig.Instance.SulphuricWaterMeterPosX, CalamityConfig.Instance.SulphuricWaterMeterPosY); + if (screenRatioPosition.X < 0f || screenRatioPosition.X > 100f) + screenRatioPosition.X = DefaultPosX; + if (screenRatioPosition.Y < 0f || screenRatioPosition.Y > 100f) + screenRatioPosition.Y = DefaultPosY; + + // Convert the screen ratio position to an absolute position in pixels + // Cast to integer to prevent blurriness which results from decimal pixel positions + float uiScale = Main.UIScale; + Vector2 screenPos = screenRatioPosition; + screenPos.X = (int)(screenPos.X * 0.01f * Main.screenWidth); + screenPos.Y = (int)(screenPos.Y * 0.01f * Main.screenHeight); + + CalamityPlayer modPlayer = player.Calamity(); + + // If not drawing the water meter, save its latest position to config and leave. + if (modPlayer.SulphWaterUIOpacity > 0f) + DrawWaterBar(spriteBatch, modPlayer, screenPos); + else + { + bool changed = false; + if (CalamityConfig.Instance.SulphuricWaterMeterPosX != screenRatioPosition.X) + { + CalamityConfig.Instance.SulphuricWaterMeterPosX = screenRatioPosition.X; + changed = true; + } + if (CalamityConfig.Instance.SulphuricWaterMeterPosY != screenRatioPosition.Y) + { + CalamityConfig.Instance.SulphuricWaterMeterPosY = screenRatioPosition.Y; + changed = true; + } + + if (changed) + CalamityMod.SaveConfig(CalamityConfig.Instance); + } + + Rectangle mouseHitbox = new Rectangle((int)Main.MouseScreen.X, (int)Main.MouseScreen.Y, 8, 8); + Rectangle waterBarArea = Utils.CenteredRectangle(screenPos, edgeTexture.Size() * uiScale); + + MouseState ms = Mouse.GetState(); + Vector2 mousePos = Main.MouseScreen; + + // Handle mouse dragging + if (waterBarArea.Intersects(mouseHitbox)) + { + if (!CalamityConfig.Instance.MeterPosLock) + Main.LocalPlayer.mouseInterface = true; + + // If the mouse is on top of the meter, show the player's accumulated sulphuric poisoning. + if (modPlayer.SulphWaterPoisoningLevel > 0f && modPlayer.SulphWaterUIOpacity >= 0f) + { + string poisonText = (modPlayer.SulphWaterPoisoningLevel * 100f).ToString("n2"); + string textToDisplay = $"Sulphuric Poisoning: {poisonText}/100"; + Main.instance.MouseText(textToDisplay, 0, 0, -1, -1, -1, -1); + modPlayer.SulphWaterUIOpacity = MathHelper.Lerp(modPlayer.SulphWaterUIOpacity, 0.25f, 0.035f); + } + + Vector2 newScreenRatioPosition = screenRatioPosition; + + // As long as the mouse button is held down, drag the meter along with an offset. + if (!CalamityConfig.Instance.MeterPosLock && ms.LeftButton == ButtonState.Pressed) + { + // If the drag offset doesn't exist yet, create it. + if (!dragOffset.HasValue) + dragOffset = mousePos - screenPos; + + // Given the mouse's absolute current position, compute where the corner of the water bar should be based on the original drag offset. + Vector2 newCorner = mousePos - dragOffset.GetValueOrDefault(Vector2.Zero); + + // Convert the new corner position into a screen ratio position. + newScreenRatioPosition.X = (100f * newCorner.X) / Main.screenWidth; + newScreenRatioPosition.Y = (100f * newCorner.Y) / Main.screenHeight; + } + + // Compute the change in position. If it is large enough, actually move the meter + Vector2 delta = newScreenRatioPosition - screenRatioPosition; + if (Math.Abs(delta.X) >= MouseDragEpsilon || Math.Abs(delta.Y) >= MouseDragEpsilon) + { + CalamityConfig.Instance.SulphuricWaterMeterPosX = newScreenRatioPosition.X; + CalamityConfig.Instance.SulphuricWaterMeterPosY = newScreenRatioPosition.Y; + } + + // When the mouse is released, save the config and destroy the drag offset. + if (ms.LeftButton == ButtonState.Released) + { + dragOffset = null; + CalamityMod.SaveConfig(CalamityConfig.Instance); + } + } + else + modPlayer.SulphWaterUIOpacity = MathHelper.Clamp(modPlayer.SulphWaterUIOpacity + (modPlayer.SulphWaterPoisoningLevel > 0f).ToDirectionInt() * 0.06f, 0f, 1f); + } + + private static void DrawWaterBar(SpriteBatch spriteBatch, CalamityPlayer modPlayer, Vector2 screenPos) + { + float uiScale = Main.UIScale; + float offset = (edgeTexture.Width - barTexture.Width) * 0.5f; + spriteBatch.Draw(edgeTexture, screenPos, null, Color.White * modPlayer.SulphWaterUIOpacity, 0f, edgeTexture.Size() * 0.5f, uiScale, SpriteEffects.None, 0); + + float completionRatio = MathHelper.Clamp(modPlayer.SulphWaterPoisoningLevel, 0f, 1f); + Rectangle barRectangle = new Rectangle(0, 0, (int)(barTexture.Width * completionRatio), barTexture.Width); + spriteBatch.Draw(barTexture, screenPos + new Vector2(offset * uiScale, 0), barRectangle, Color.White * modPlayer.SulphWaterUIOpacity, 0f, edgeTexture.Size() * 0.5f, uiScale, SpriteEffects.None, 0); + } + } +} diff --git a/Utilities/MathematicalUtils.cs b/Utilities/MathematicalUtils.cs index 8e3e17d123..d920f3e259 100644 --- a/Utilities/MathematicalUtils.cs +++ b/Utilities/MathematicalUtils.cs @@ -27,7 +27,6 @@ namespace CalamityMod /// The Y position on the map. /// A metric of "instability" of the noise. The higher this is, the more unstable. Lower of bounds of 2-3 are preferable. /// The seed for the noise. - /// public static float PerlinNoise2D(float x, float y, int octaves, int seed) { float SmoothFunction(float n) => 3f * n * n - 2f * n * n * n; diff --git a/Utilities/TileUtils.cs b/Utilities/TileUtils.cs index 5739e95233..fdb6c541a3 100644 --- a/Utilities/TileUtils.cs +++ b/Utilities/TileUtils.cs @@ -229,6 +229,21 @@ namespace CalamityMod return Main.tile[x, y]; } + public static bool AnySolidTileInSelection(int x, int y, int width, int height) + { + for (int i = x; i != x + width; i += Math.Sign(width)) + { + for (int j = y; j != y + height; j += Math.Sign(height)) + { + if (WorldGen.InWorld(i, j)) + continue; + if (WorldGen.SolidTile(Framing.GetTileSafely(i, j))) + return true; + } + } + return false; + } + public static bool TileSelectionSolid(int x, int y, int width, int height) { for (int i = x; i != x + width; i += Math.Sign(width)) diff --git a/Utilities/WorldgenUtils.cs b/Utilities/WorldgenUtils.cs index 55017eec6b..e5ea6c2ca1 100644 --- a/Utilities/WorldgenUtils.cs +++ b/Utilities/WorldgenUtils.cs @@ -31,5 +31,42 @@ namespace CalamityMod } } } + + /// + /// Settles all liquids in the world. + /// + public static void SettleWater() + { + Liquid.worldGenTilesIgnoreWater(true); + Liquid.QuickWater(3); + WorldGen.WaterCheck(); + + Liquid.quickSettle = true; + + for (int i = 0; i < 10; i++) + { + int maxLiquid = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer; + int m = maxLiquid * 5; + double maxLiquidDifferencePercentage = 0D; + while (Liquid.numLiquid > 0) + { + m--; + if (m < 0) + break; + + double liquidDifferencePercentage = (maxLiquid - Liquid.numLiquid - LiquidBuffer.numLiquidBuffer) / (double)maxLiquid; + if (Liquid.numLiquid + LiquidBuffer.numLiquidBuffer > maxLiquid) + maxLiquid = Liquid.numLiquid + LiquidBuffer.numLiquidBuffer; + + if (liquidDifferencePercentage > maxLiquidDifferencePercentage) + maxLiquidDifferencePercentage = liquidDifferencePercentage; + + Liquid.UpdateLiquid(); + } + WorldGen.WaterCheck(); + } + Liquid.quickSettle = false; + Liquid.worldGenTilesIgnoreWater(false); + } } } diff --git a/Walls/SulphurousSandWall.cs b/Walls/SulphurousSandWall.cs index 4ba25cdf42..4ea9b6bf5e 100644 --- a/Walls/SulphurousSandWall.cs +++ b/Walls/SulphurousSandWall.cs @@ -13,15 +13,6 @@ namespace CalamityMod.Walls AddMapEntry(new Color(84, 71, 46)); } - public override void RandomUpdate(int i, int j) - { - if (Main.tile[i, j].LiquidAmount <= 0) - { - Main.tile[i, j].LiquidAmount = 255; - Main.tile[i, j].Get().LiquidType = LiquidID.Water; - } - } - public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; } } diff --git a/Walls/SulphurousSandstoneWall.cs b/Walls/SulphurousSandstoneWall.cs index c0b930621f..24b9f1da62 100644 --- a/Walls/SulphurousSandstoneWall.cs +++ b/Walls/SulphurousSandstoneWall.cs @@ -13,15 +13,6 @@ namespace CalamityMod.Walls AddMapEntry(new Color(57, 45, 38)); } - public override void RandomUpdate(int i, int j) - { - if (Main.tile[i, j].LiquidAmount <= 0) - { - Main.tile[i, j].LiquidAmount = 255; - Main.tile[i, j].Get().LiquidType = LiquidID.Water; - } - } - public override void NumDust(int i, int j, bool fail, ref int num) => num = fail ? 1 : 3; } } diff --git a/World/SulphurousSea.cs b/World/SulphurousSea.cs index e2a6f0fa48..41fa176641 100644 --- a/World/SulphurousSea.cs +++ b/World/SulphurousSea.cs @@ -1,5 +1,6 @@ using CalamityMod.Items; using CalamityMod.Items.Accessories; +using CalamityMod.Items.Placeables.Furniture; using CalamityMod.Items.Weapons.Summon; using CalamityMod.Schematics; using CalamityMod.Tiles.Abyss; @@ -9,6 +10,7 @@ using System; using System.Collections.Generic; using System.Linq; using Terraria; +using Terraria.GameContent.RGB; using Terraria.ID; using Terraria.ModLoader; using Terraria.WorldBuilding; @@ -18,25 +20,106 @@ namespace CalamityMod.World public class SulphurousSea { #region Fields and Properties + + public const float SandBlockEdgeDescentSmoothness = 0.24f; + + // What percentage it takes for dither effects to start appearing at the edges. + // As an example, if this value is 0.7 that would mean that tiles that are below 70% of the way down from the top of the ocean would + // start randomly dithering. + public const float DitherStartFactor = 0.9f; + + public const int DepthForWater = 12; + + public const float TopWaterDepthPercentage = 0.125f; + + public const float TopWaterDescentSmoothnessMin = 0.26f; + + public const float TopWaterDescentSmoothnessMax = 0.39f; + + public const int TotalSandTilesBeforeWaterMin = 32; + + public const int TotalSandTilesBeforeWaterMax = 45; + + public const float OpenSeaWidthPercentage = 0.53f; + + public const float IslandWidthPercentage = 0.36f; + + public const float IslandCurvatureSharpness = 0.74f; + + // 0-1 value of how jagged the small caves should be. The higher this value is, the more variance you can expect for each step when carving out caves. + public const float SmallCavesJaggedness = 0.51f; + + // How much of a tendency the small caves have to be cramped instead of large and open, with values between 0-1 emphasizing larger caves while values greater than 1 + // emphasizing more cramped caves. + public const float SmallCavesBiasTowardsTightness = 2.21f; + + // How much of a magnification is performed when calculating perlin noise for spaghetti caves. The closer to 0 this value is, the more same-y the caves will seem in + // terms of direction, size, etc. + public const float SpaghettiCaveMagnification = 0.00193f; + + // 0-1 value that determines the threshold for spaghetti caves being carved out. At 0, no tiles are carved out, at 1, all tiles are carved out. + // This is used in the formula 'abs(noise(x, y)) < r' to determine whether the cave should remove tiles. + public static readonly float[] SpaghettiCaveCarveOutThresholds = new float[] + { + 0.033f, + 0.089f + }; + + public const float CheeseCaveMagnification = 0.00237f; + + public static readonly float[] CheeseCaveCarveOutThresholds = new float[] + { + 0.32f + }; + + // Percentage of how far down a tile has to be for open caverns to appear. + public const float OpenCavernStartDepthPercentage = 0.42f; + + // The percentage of tiles on average that should be transformed into water. + // A value of 1 indicates that every tile should have water. + // This value should be close to 1, but not exactly, so that when water settles the top of caverns will be open. + public const float WaterSpreadPercentage = 0.91f; + + public const float HardenedSandstoneLineMagnification = 0.004f; + + public const int MaxIslandHeight = 16; + + public const int MaxIslandDepth = 9; + + public const float IslandLineMagnification = 0.0079f; + + public const int TreeGrowChance = 5; + + public const int MinColumnHeight = 5; + + public const int MaxColumnHeight = 50; + + public const int BeachMaxDepth = 50; + + public const int ScrapPileAnticlumpDistance = 80; + + public const float SandstoneEdgeNoiseMagnification = 0.00115f; + + public const int StalactitePairMinDistance = 6; + + public const int StalactitePairMaxDistance = 44; + + // Loop variables that are accessed via getter methods should be stored externally in local variables for performance reasons. public static int BiomeWidth { get { - // Small world - if (Main.maxTilesX == 4200) + return Main.maxTilesX switch { - return 370; - } - // Medium world - else if (Main.maxTilesX == 6400) - { - return 445; - } - // Large world - else - { - return 500; - } + // Small worlds. + 4200 => 370, + + // Medium worlds. + 6400 => 445, + + // Large worlds. This also accounts for worlds of an unknown size, such as extra large worlds. + _ => (int)(Main.maxTilesX / 16.8f), + }; } } @@ -44,778 +127,560 @@ namespace CalamityMod.World { get { - // Small world - if (Main.maxTilesX == 4200) + float depthFactor = Main.maxTilesX switch { - return (int)((Main.rockLayer + 20 - YStart) * 0.8); - } - // Medium world - else if (Main.maxTilesX == 6400) - { - return (int)((Main.rockLayer + 20 - YStart) * 0.85); - } - // Large world - else - { - return (int)((Main.rockLayer + 20 - YStart) * 0.925); - } + // Small worlds. + 4200 => 0.8f, + + // Medium worlds. + 6400 => 0.85f, + + // Large worlds. + _ => 0.925f + }; + return (int)((Main.rockLayer + 112 - YStart) * depthFactor); } } - public static int YStart = 0; + public static int TotalCavesInShallowWater => (int)Math.Ceiling(Main.maxTilesX / 2000f); + + public static int MaxTopWaterDepth => (int)(BlockDepth * TopWaterDepthPercentage); + + public static int MinCaveWidth => Main.maxTilesX / 2500; + + public static int MaxCaveWidth => (int)Math.Ceiling(Main.maxTilesX / 566f); + + public static int MinCaveMovementSteps => (int)Math.Ceiling(Main.maxTilesX / 70f); + + public static int MaxCaveMovementSteps => (int)Math.Ceiling(Main.maxTilesX / 40f); + + public static int ColumnCount => Main.maxTilesX / 96; + + public static int GeyserCount => Main.maxTilesX / 137; + + public static int YStart + { + get; + set; + } + public static readonly List SulphSeaTiles = new() { ModContent.TileType(), ModContent.TileType(), ModContent.TileType() }; + + // Vines cannot grow any higher than this. This is done to prevent vines from growing very close to the sea surface. + public static int VineGrowTopLimit => YStart + 100; #endregion #region Placement Methods public static void PlaceSulphurSea() { + // Determine which side the abyss is such that it's at the same side as the dungeon. Abyss.AtLeftSideOfWorld = Main.dungeonX < Main.maxTilesX / 2; + + // Settle the foundation for the sea. This involves creating the base sulphurous sea block, old tile cleanup, and creating water at the surface. DetermineYStart(); - CreateStartingBlock(); - CreateWater(); - GenerateHardenedSandstone(); + GenerateSandBlock(); RemoveStupidTilesAboveSea(); - GenerateLake(); - SettleWater(); // The island Y spawn position calculations are relative to water. Settling the water before doing these calculations is ideal. - GenerateIslands(); - GenerateVentsAndFossils(); - SmoothenTheEntireSea(); - } + GenerateShallowTopWater(); + GenerateIsland(); - public static void FinishGeneratingSulphurSea() + // Cave generation. Some of these borrow concepts and tricks used by Minecraft's new generation. + GenerateSmallWaterCaverns(); + GenerateSpaghettiWaterCaves(); + GenerateCheeseWaterCaves(); + + // Lay down decorations and post-processing effects after the caves are generated. + DecideHardSandstoneLine(); + MakeSurfaceLessRigid(); + LayTreesOnSurface(); + } + + public static void SulphurSeaGenerationAfterAbyss() { - PlaceStalactites(); - PlaceColumns(); CreateBeachNearSea(); - PlaceScrapPiles(); - PlaceRustyChests(); + ClearOutStrayTiles(); + ClearAloneTiles(); + var scrapPilePositions = PlaceScrapPiles(); + GenerateColumnsInCaverns(); + GenerateSteamGeysersInCaverns(); + GenerateHardenedSandstone(); + PlaceStalactites(); + GenerateChests(scrapPilePositions); } #endregion - #region Perlin Noise - public static float NoiseFunction(int seed) + #region Generation Functions + public static void DetermineYStart() { - seed = (seed << 13) ^ seed; - return 1.0f - ((seed * (seed * seed * 15731) + 1376312589) & 0x7fffffff) / 1073741824.0f; - } - public static float PerlinNoise2D(float x, float y, int octave, int seed) - { - float frequency = (float)Math.Pow(2, octave); - float xFrequency = x * frequency; - float yFrequency = y * frequency; - int flooredXFrequency = (int)xFrequency; - int flooredYFrequency = (int)yFrequency; - float fractionXFrequency = xFrequency - flooredXFrequency; - float fractionYFrequency = yFrequency - flooredYFrequency; + int xCheckPosition = GetActualX(BiomeWidth + 1); + var searchCondition = Searches.Chain(new Searches.Down(3000), new Conditions.IsSolid()); + Point determinedPoint; - float noise1 = NoiseFunction(flooredXFrequency + flooredYFrequency * 54 + seed); - float noise2 = NoiseFunction(flooredXFrequency + 1 + flooredYFrequency * 54 + seed); - float noise3 = NoiseFunction(flooredXFrequency + (1 + flooredYFrequency) * 54 + seed); - float noise4 = NoiseFunction(flooredXFrequency + 1 + (1 + flooredYFrequency) * 54 + seed); - - float lerpStart = MathHelper.Lerp(noise1, noise2, fractionXFrequency); - float lerpEnd = MathHelper.Lerp(noise3, noise4, fractionXFrequency); - return MathHelper.Lerp(lerpStart, lerpEnd, fractionYFrequency); - } - #endregion - - #region Generating Initial Block - public static void CreateStartingBlock() - { - // Set above for general performance. - ushort sandTileType = (ushort)ModContent.TileType(); - ushort sandstoneTileType = (ushort)ModContent.TileType(); - - ushort sandWallType = (ushort)ModContent.WallType(); - ushort sandstoneWallType = (ushort)ModContent.WallType(); - - - float randomValue1 = WorldGen.genRand.NextFloat(-0.4f, 0.4f); - while (Math.Abs(randomValue1) < 0.22f) + do { - randomValue1 = WorldGen.genRand.NextFloat(-0.4f, 0.4f); - } - float randomValue2 = WorldGen.genRand.NextFloat(-0.2f, 0.2f); - while (Math.Abs(randomValue2) < 0.07f) - { - randomValue2 = WorldGen.genRand.NextFloat(-0.2f, 0.2f); + WorldUtils.Find(new Point(xCheckPosition, (int)WorldGen.worldSurfaceLow - 20), searchCondition, out determinedPoint); + xCheckPosition += Abyss.AtLeftSideOfWorld.ToDirectionInt(); } + while (CalamityUtils.ParanoidTileRetrieval(determinedPoint.X, determinedPoint.Y).TileType == TileID.Ebonstone); + YStart = determinedPoint.Y; + } - float randomValue3 = WorldGen.genRand.NextFloat(0.42f, 0.96f) * WorldGen.genRand.NextBool(2).ToDirectionInt(); - float wallBoundAtPosition(float xRatio) => (float)(Math.Sin(randomValue3 * MathHelper.Pi * xRatio) + Math.Cos(randomValue3 * Math.E / 2f * xRatio)) * 0.5f * 28f; + public static void GenerateSandBlock() + { + int width = BiomeWidth + 1; + int maxDepth = BlockDepth; + ushort blockTileType = (ushort)ModContent.TileType(); + ushort wallID = (ushort)ModContent.WallType(); - for (int x = 1; x < BiomeWidth; x++) + for (int i = 1; i < width; i++) { - float xRatio = x / (float)BiomeWidth; - for (int y = YStart; y <= YStart + BlockDepth; y++) + int x = GetActualX(i); + + // Calculate the 0-1 factor that determines how far down a vertical strip of the sea should descend. + float depthFactor = (float)Math.Pow(Math.Sin((1f - i / (float)width) * MathHelper.PiOver2), SandBlockEdgeDescentSmoothness); + + // Determine the top and botton of the strip. + int top = YStart; + int bottom = top + (int)(maxDepth * depthFactor); + for (int y = top; y < bottom; y++) { - int trueX = Abyss.AtLeftSideOfWorld ? x : Main.maxTilesX - x; - float yRatio = (y - YStart) / (float)BlockDepth; - float xAngleWrap = x / (float)BiomeWidth * MathHelper.TwoPi - MathHelper.Pi; - bool generateSand = yRatio < SandstoneYMinimum(xAngleWrap, randomValue1, randomValue2); - if (WorldGen.InWorld(trueX, y)) + float ditherChance = CalculateDitherChance(width, top, bottom, i, y); + if (WorldGen.genRand.NextFloat() >= ditherChance) { - if (y - YStart < BlockDepth - (int)(BlockDepth * 0.35f) + (int)(Math.Sin(xRatio * MathHelper.Pi) * (int)(BlockDepth * 0.35f))) - { - Main.tile[trueX, y].ClearEverything(); - Main.tile[trueX, y].WallType = generateSand ? sandWallType : sandstoneWallType; - Main.tile[trueX, y].TileType = generateSand ? sandTileType : sandstoneTileType; - if (y - YStart - 6 < wallBoundAtPosition(xRatio * MathHelper.TwoPi * 4f)) - Main.tile[trueX, y].WallType = WallID.None; - - Main.tile[trueX, y].Get().HasTile = true; - } - } - } - } - } - public static float SandstoneYMinimum(float xAsAngle, float randomValue1, float randomValue2) - { - float sineSquaredRandom1 = randomValue1 * (float)Math.Cos(xAsAngle * randomValue1) * (float)Math.Cos(xAsAngle * randomValue1); - float sineSquaredRandom2 = randomValue1 * (float)Math.Sin(xAsAngle * randomValue1) * (float)Math.Sin(xAsAngle * randomValue1); - float sineSquaredRandom3 = randomValue2 * (float)Math.Sin(xAsAngle * randomValue2); - float sineSquaredRandom4 = (float)Math.Sin(randomValue1 / randomValue2 * xAsAngle) * (float)Math.Cos(randomValue1 * MathHelper.Pi); - return 0.25f * Math.Abs(sineSquaredRandom1 + 0.5f * sineSquaredRandom2 + sineSquaredRandom3 - sineSquaredRandom4) + 0.25f; - } - #endregion - - #region Generating Water - public const int PerlinIterations = 1; - public const int PerlinOctaves = 4; - public const int PerlinXEdgeClamp = 20; - public const float PerlinYDelta = 40; - public const float PerlinNoiseMax = 0.05f; - public const float PerlinThreshold = 0.1f; // Be careful with this number - - public static void GenerateLake() - { - int lakeDepthMax = WorldGen.genRand.Next(36, 52 + 1); - float lakeSteepness = WorldGen.genRand.NextFloat(1.2f, 1.5f); - for (int x = 1; x < BiomeWidth; x++) - { - int trueX = Abyss.AtLeftSideOfWorld ? x : Main.maxTilesX - x; - float xRatio = x / (float)BiomeWidth; - int lakeDepth = (int)(Math.Sin(MathHelper.Min((1f - xRatio) * MathHelper.PiOver2 * lakeSteepness * 1.2f, MathHelper.PiOver2)) * lakeDepthMax); - for (int y = YStart; y <= YStart + lakeDepth; y++) - { - ushort oldWall = Main.tile[trueX, y].WallType; - Main.tile[trueX, y].ClearEverything(); - Main.tile[trueX, y].WallType = oldWall; - Main.tile[trueX, y].LiquidAmount = 255; - } - } - } - - public static void CreateWater() - { - int[] seeds = new int[PerlinIterations]; - for (int i = 0; i < seeds.Length; i++) - { - seeds[i] = WorldGen.genRand.Next(); - } - for (int x = 1; x < BiomeWidth; x++) - { - float xRatio = x / (float)BiomeWidth; - for (int y = YStart; y <= YStart + BlockDepth; y++) - { - float yRatio = (y - YStart) / (float)BlockDepth; - int trueX = Abyss.AtLeftSideOfWorld ? x : Main.maxTilesX - x; - if (y - YStart < BlockDepth - (int)(BlockDepth * 0.35f) + (int)(Math.Sin(xRatio * MathHelper.Pi) * (int)(BlockDepth * 0.35f)) - PerlinYDelta) - { - if (x < PerlinXEdgeClamp || x > BiomeWidth - PerlinXEdgeClamp) - continue; - float perlinAverage = 0f; - for (int k = 0; k < seeds.Length; k++) - { - perlinAverage += PerlinNoise2D(xRatio, yRatio, PerlinOctaves, seeds[k]) / PerlinIterations; - } - if (perlinAverage > PerlinThreshold * WorldGen.genRand.NextFloat(1f - PerlinNoiseMax, 1f + PerlinNoiseMax)) - { - ushort oldWall = Main.tile[trueX, y].WallType; - Main.tile[trueX, y].ClearEverything(); - Main.tile[trueX, y].WallType = oldWall; - Main.tile[trueX, y].LiquidAmount = 255; - } - } - } - } - } - #endregion - - #region Generating Edge Sandstone - public const int EdgeCheckMinX = 6; - public const int EdgeCheckMaxX = 8; - public const int EdgeCheckMinY = 4; - public const int EdgeCheckMaxY = 6; - public const int MinimumEdgeScore = 4; - public const int SpotWidth = 4; - public static void GenerateHardenedSandstone() - { - for (int x = 1; x < BiomeWidth; x++) - { - for (int y = YStart; y <= YStart + BlockDepth; y++) - { - int trueX = Abyss.AtLeftSideOfWorld ? x : Main.maxTilesX - x; - int edgeScore = GetEdgeScore(trueX, y); - - if (edgeScore >= MinimumEdgeScore) - { - for (int dx = -SpotWidth / 2; dx <= SpotWidth; dx++) - { - for (int dy = -SpotWidth / 2; dy <= SpotWidth / 2; dy++) - { - if (WorldGen.InWorld(trueX + dx, y + dy)) - { - if (CalamityUtils.ParanoidTileRetrieval(trueX + dx, y + dy).TileType != (ushort)ModContent.TileType() && - SulphSeaTiles.Contains(CalamityUtils.ParanoidTileRetrieval(trueX + dx, y + dy).TileType)) - { - Main.tile[trueX + dx, y + dy].TileType = (ushort)ModContent.TileType(); - } - } - } - } - } - } - } - } - public static int GetEdgeScore(int x, int y) - { - int edgeScore = 0; - for (int dx = x - WorldGen.genRand.Next(EdgeCheckMinX, EdgeCheckMaxX + 1); dx <= x + WorldGen.genRand.Next(EdgeCheckMinX, EdgeCheckMaxX + 1); dx++) - { - if (dx == x) - continue; - if (CalamityUtils.ParanoidTileRetrieval(dx, y).LiquidAmount == 255) - edgeScore++; - } - for (int dy = y - WorldGen.genRand.Next(EdgeCheckMinY, EdgeCheckMaxY + 1); dy <= y + WorldGen.genRand.Next(EdgeCheckMinY, EdgeCheckMaxY + 1); dy++) - { - if (dy == y) - continue; - if (CalamityUtils.ParanoidTileRetrieval(x, dy).LiquidAmount == 255) - edgeScore++; - } - return edgeScore; - } - #endregion - - #region Generating Islands - public const int IslandCount = 4; - public const int IslandXPadding = 20; - - public const int IslandMinWidth = 15; - public const int IslandMaxWidth = 22; - - public const int IslandMinDepth = 5; - public const int IslandMaxDepth = 10; - public static void SettleWater() - { - Liquid.QuickWater(3, -1, -1); - WorldGen.WaterCheck(); - int counter = 0; - Liquid.quickSettle = true; - while (counter < 10) - { - counter++; - while (Liquid.numLiquid > 0) - { - Liquid.UpdateLiquid(); - } - WorldGen.WaterCheck(); - } - Liquid.quickSettle = false; - - // Remove liquid above the biome line, to prevent flooding. - for (int x = 2; x < BiomeWidth - 2; x++) - { - int trueX = x; - if (!Abyss.AtLeftSideOfWorld) - trueX = Main.maxTilesX - x; - for (int y = YStart - 300; y <= YStart; y++) - { - if (CalamityUtils.ParanoidTileRetrieval(trueX, y).LiquidAmount > 0) - Main.tile[trueX, y].LiquidAmount = 0; - } - } - } - public static void GenerateIslands() - { - for (int i = 0; i < IslandCount; i++) - { - int y = YStart - 240; - int x = WorldGen.genRand.Next(IslandMaxWidth + IslandXPadding, BiomeWidth - IslandMaxWidth - IslandXPadding); - if (!Abyss.AtLeftSideOfWorld) - x = Main.maxTilesX - x; - while (CalamityUtils.ParanoidTileRetrieval(x, y).LiquidAmount == 0) - { - y++; - if (y > Main.rockLayer - 35) - { - break; - } - } - if (y > Main.rockLayer - 35) - { - i--; - continue; // Try again - } - int height = 2 * WorldGen.genRand.Next(IslandMinDepth, IslandMaxDepth + 1); - int width = WorldGen.genRand.Next(IslandMinWidth, IslandMaxWidth + 1); - int treePosition = WorldGen.genRand.Next(-width + 4, width - 4); - - for (float theta = 0f; theta <= MathHelper.TwoPi; theta += 0.05f) - { - for (int dx = 0; dx != (int)(height * Math.Cos(theta)); dx += (height * Math.Cos(theta) > 0).ToDirectionInt()) - { - for (int dy = 0; dy != (int)(width * Math.Sin(theta)); dy += (width * Math.Sin(theta) > 0).ToDirectionInt()) - { - if (WorldGen.InWorld(x + dx, y + dy)) - { - if (dy >= -2 - WorldGen.genRand.Next(-2, 3)) - { - int extraHeight = WorldGen.genRand.Next(0, 1 + 1); - for (int y2 = 0; y2 <= extraHeight; y2++) - { - Main.tile[x + dx, y + dy - y2].TileType = (ushort)ModContent.TileType(); - Main.tile[x + dx, y + dy - y2].Get().Slope = SlopeType.Solid; - Main.tile[x + dx, y + dy - y2].Get().IsHalfBlock = false; - Main.tile[x + dx, y + dy - y2].Get().HasTile = true; - } - if (dy == -2 && dx == treePosition) - WorldGen.PlaceTile(x + dx, y + dy - extraHeight - 1, ModContent.TileType()); - } - else - { - Main.tile[x + dx, y + dy].LiquidAmount = 0; - } - } - } - } - } - } - } - #endregion - - #region Smoothening Everything - public static void SmoothenTheEntireSea() - { - for (int x = 2; x < BiomeWidth - 2; x++) - { - int trueX = x; - if (!Abyss.AtLeftSideOfWorld) - trueX = Main.maxTilesX - x; - for (int y = YStart; y <= YStart + BlockDepth; y++) - { - Tile.SmoothSlope(trueX, y); - } - } - } - #endregion - - #region Generating Scenery - public const int ColumnMinDistanceX = 8; - public const int ColumnMinHeight = 10; - public const int ColumnMaxHeight = 27; - public const int StalactitePairMinDistance = 6; - public const int StalactitePairMaxDistance = 44; - public static void GenerateVentsAndFossils() - { - for (int x = 1; x < BiomeWidth; x++) - { - int trueX = Abyss.AtLeftSideOfWorld ? x : Main.maxTilesX - x; - for (int y = YStart; y <= YStart + BlockDepth; y++) - { - // Generate vents in the top 45% - if (y - YStart < BlockDepth * 0.45f) - { - if (WorldGen.SolidTile(trueX, y + 1) && WorldGen.genRand.NextBool(20)) - { - PlaceMiscTile(trueX, y, 1, 2, (ushort)ModContent.TileType()); - } - } - // And fossils in the bottom 55% - else - { - if (WorldGen.SolidTile(trueX, y + 1)) - { - // Generate ribs such that they're all nearby - if (WorldGen.genRand.NextBool(25)) - { - ushort type = (ushort)Utils.SelectRandom(WorldGen.genRand, - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType(), - ModContent.TileType()); - int height; - if (type == ModContent.TileType() || type == ModContent.TileType()) - { - height = 3; - } - else if (type == ModContent.TileType()) - { - height = 2; - } - else if (type == ModContent.TileType()) - { - height = 4; - } - else - { - height = 1; - } - PlaceMiscTile(trueX, y, 1, height, type); - } - else if (WorldGen.genRand.NextBool(16)) - { - PlaceMiscTile(trueX, y, 3, 2, (ushort)Utils.SelectRandom(WorldGen.genRand, ModContent.TileType(), ModContent.TileType(), ModContent.TileType())); - } - } - } - } - } - } - public static void PlaceColumns() - { - int previousX = 0; - int style; - for (int x = 1; x < BiomeWidth; x++) - { - int trueX = Abyss.AtLeftSideOfWorld ? x : Main.maxTilesX - x; - for (int y = YStart; y <= YStart + BlockDepth; y++) - { - if (y - YStart > BlockDepth * 0.5f) - { - if (WorldGen.SolidTile(trueX, y + 1) && - WorldGen.SolidTile(trueX + 1, y + 1) && - SulphSeaTiles.Contains(CalamityUtils.ParanoidTileRetrieval(trueX, y + 1).TileType) && - WorldGen.genRand.NextBool(3) && - Math.Abs(trueX - previousX) >= ColumnMinDistanceX) - { - int top = y; - int height = 0; - while (!(WorldGen.SolidTile(trueX - 1, top) && WorldGen.SolidTile(trueX, top) && WorldGen.SolidTile(trueX + 1, top))) - { - top--; - height++; - if (height > ColumnMaxHeight + 1) - break; - } - if (height <= ColumnMaxHeight && height >= ColumnMinHeight) - { - for (int dy = 0; dy < height; dy++) - { - style = WorldGen.genRand.Next(3); - short yFrame = 18; - if (dy == 0) - yFrame = 36; - if (dy == height - 1) - yFrame = 0; - ushort oldWall = Main.tile[trueX, y - dy].WallType; - Main.tile[trueX, y - dy].ResetToType((ushort)ModContent.TileType()); - Main.tile[trueX, y - dy].TileFrameX = (short)(style * 36); - Main.tile[trueX, y - dy].TileFrameY = yFrame; - Main.tile[trueX, y - dy].LiquidAmount = 255; - Main.tile[trueX, y - dy].WallType = oldWall; - Main.tile[trueX, y - dy].Get().HasTile = true; - - oldWall = Main.tile[trueX + 1, y - dy].WallType; - - Main.tile[trueX + 1, y - dy].ResetToType((ushort)ModContent.TileType()); - Main.tile[trueX + 1, y - dy].TileFrameX = (short)(style * 36 + 18); - Main.tile[trueX + 1, y - dy].TileFrameY = yFrame; - Main.tile[trueX + 1, y - dy].LiquidAmount = 255; - Main.tile[trueX + 1, y - dy].WallType = oldWall; - Main.tile[trueX + 1, y - dy].Get().HasTile = true; - } - previousX = trueX; - } - } - } - } - } - } - public static void PlaceStalactites() - { - int heightFromType(int type) - { - if (type <= 2) - return 2; - else if (type <= 4) - return 3; - else - return 4; - }; - for (int x = 1; x < BiomeWidth; x++) - { - int trueX = Abyss.AtLeftSideOfWorld ? x : Main.maxTilesX - x; - for (int y = YStart; y <= YStart + BlockDepth; y++) - { - if (y - YStart > BlockDepth * 0.25f) - { - if (WorldGen.SolidTile(trueX, y - 1) && WorldGen.genRand.NextBool(10)) - { - int dy = 1; - while (!CalamityUtils.ParanoidTileRetrieval(trueX, y + dy).HasTile) - { - dy++; - if (dy > StalactitePairMaxDistance) - break; - } - if (dy <= StalactitePairMaxDistance && dy >= StalactitePairMinDistance) - { - int type = WorldGen.genRand.Next(6); - type++; - int height = heightFromType(type); - - PlaceStalactite(trueX, y, height, (ushort)CalamityMod.Instance.Find($"SulphurousStalactite{type}").Type); - if (WorldGen.SolidTile(trueX, y + dy + 1)) - PlaceStalacmite(trueX, y + dy, height, (ushort)CalamityMod.Instance.Find($"SulphurousStalacmite{type}").Type); - } - } - } - } - } - } - public static void PlaceMiscTile(int x, int y, int width, int height, ushort type, int style = 0) - { - try - { - bool canGenerate = true; - for (int i = x; i < x + width; i++) - { - for (int j = y - (int)Math.Ceiling(height / 2.0); j < y + (int)Math.Ceiling(height / 2.0); j++) - { - if (Main.tile[i, j].HasTile) - { - canGenerate = false; - } - } - if (!Main.tile[i, y + 1].HasUnactuatedTile || Main.tile[i, y + 1].IsHalfBlock || Main.tile[i, y + 1].Slope != 0 || !Main.tileSolid[Main.tile[i, y + 1].TileType]) - { - canGenerate = false; - } - } - if (canGenerate) - { - WorldGen.PlaceTile(x, y, type, style: style); - } - } - catch - { - return; // This should only ever happen from an index error, and there's really no point in continuing if that happens - } - } - public static void PlaceStalactite(int x, int y, int height, ushort type) - { - for (int dy = 0; dy < height; dy++) - { - ushort oldWall = Main.tile[x, y + dy].WallType; - Main.tile[x, y + dy].ClearEverything(); - Main.tile[x, y + dy].WallType = oldWall; - Main.tile[x, y + dy].TileType = type; - Main.tile[x, y + dy].TileFrameY = (short)(dy * 18); - Main.tile[x, y + dy].Get().HasTile = true; - } - } - public static void PlaceStalacmite(int x, int y, int height, ushort type) - { - for (int dy = height - 1; dy > 0; dy--) - { - ushort oldWall = Main.tile[x, y + dy].WallType; - Main.tile[x, y - dy].ClearEverything(); - Main.tile[x, y - dy].WallType = oldWall; - Main.tile[x, y - dy].TileType = type; - Main.tile[x, y - dy].TileFrameY = (short)(height * 18 - dy * 18); - Main.tile[x, y - dy].Get().HasTile = true; - } - } - #endregion - - #region Generating Chests - public const int CheckCutoffDistance = 15; - public static void PlaceRustyChests() - { - // Ambiguity bullshit. - int[] ItemTypes = { ModContent.ItemType(), - ModContent.ItemType(), - ModContent.ItemType(), - ModContent.ItemType() }; - - for (int i = 0; i < ItemTypes.Length; ++i) - { - Chest chest = null; - int attempts = 0; - - while (chest is null) - { - attempts++; - int x = WorldGen.genRand.Next(CheckCutoffDistance, BiomeWidth - CheckCutoffDistance); - if (!Abyss.AtLeftSideOfWorld) - { - x = Main.maxTilesX - x; - } - int y = WorldGen.genRand.Next(YStart + CheckCutoffDistance, YStart + BlockDepth - CheckCutoffDistance); - if (WorldGen.InWorld(x, y)) - { - if (!CalamityUtils.ParanoidTileRetrieval(x, y).HasTile && - SulphSeaTiles.Contains(CalamityUtils.ParanoidTileRetrieval(x, y + 1).TileType) && - CalamityUtils.ParanoidTileRetrieval(x, y + 1).HasTile) - { - chest = MiscWorldgenRoutines.AddChestWithLoot(x, y, (ushort)ModContent.TileType()); - } + Main.tile[x, y].TileType = blockTileType; + if (y >= top + 45) + Main.tile[x, y].WallType = wallID; } - if (attempts >= 5000) - break; + // Ensure that the sand pops into existence if there is no chance that dithering will occur. + // This doesn't happen if there is dithering to ensure that there aren't stray sand tiles in the middle of open + // caves that have nothing to connect to. + if (ditherChance <= 0f) + { + Main.tile[x, y].Get().Slope = SlopeType.Solid; + Main.tile[x, y].Get().IsHalfBlock = false; + Main.tile[x, y].Get().HasTile = true; + } } - if (attempts >= 5000) - continue; - - // If a chest was placed, force its first item to be the unique item. - if (chest != null) + // Obliterate old palm trees. + for (int y = top - 75; y < top + 50; y++) { - chest.item[0].SetDefaults(ItemTypes[i]); - chest.item[0].Prefix(-1); + if (Main.tile[x, y].TileType == TileID.PalmTree) + WorldGen.KillTile(x, y); } } } - #endregion - #region Removal of stupid Tiles above the Sea - - public static List OtherTilesForSulphSeaToDestroy = new() - { - TileID.PalmTree, - TileID.Sunflower, - TileID.CorruptThorns, - TileID.CrimsonThorns, - TileID.CorruptGrass, - TileID.CorruptPlants, - TileID.Stalactite, - TileID.ImmatureHerbs, - TileID.MatureHerbs, - TileID.Pots, - TileID.Pumpkins, // Happens during Halloween - TileID.FallenLog, - TileID.LilyPad, - TileID.VanityTreeSakura, - TileID.VanityTreeYellowWillow - }; - - public static List WallsForSulphSeaToDestroy = new() - { - WallID.Dirt, - WallID.DirtUnsafe, - WallID.DirtUnsafe1, - WallID.DirtUnsafe2, - WallID.DirtUnsafe3, - WallID.DirtUnsafe4, - WallID.Cave6Unsafe, // Rocky dirt wall - WallID.Grass, - WallID.GrassUnsafe, - WallID.Flower, - WallID.FlowerUnsafe, - WallID.CorruptGrassUnsafe, - WallID.EbonstoneUnsafe, - WallID.CrimstoneUnsafe, - }; public static void RemoveStupidTilesAboveSea() { - for (int x = 0; x < BiomeWidth; x++) + for (int i = 0; i < BiomeWidth; i++) { - int trueX = Abyss.AtLeftSideOfWorld ? x : Main.maxTilesX - x; + int x = GetActualX(i); for (int y = YStart - 140; y < YStart + 80; y++) { - int type = CalamityUtils.ParanoidTileRetrieval(trueX, y).TileType; + int type = CalamityUtils.ParanoidTileRetrieval(x, y).TileType; if (YStartWhitelist.Contains(type) || OtherTilesForSulphSeaToDestroy.Contains(type)) + CalamityUtils.ParanoidTileRetrieval(x, y).Get().HasTile = false; + if (WallsForSulphSeaToDestroy.Contains(CalamityUtils.ParanoidTileRetrieval(x, y).WallType)) + CalamityUtils.ParanoidTileRetrieval(x, y).WallType = 0; + } + } + } + + public static void GenerateShallowTopWater() + { + int maxDepth = MaxTopWaterDepth; + int totalSandTilesBeforeWater = WorldGen.genRand.Next(TotalSandTilesBeforeWaterMin, TotalSandTilesBeforeWaterMax); + int width = (int)((BiomeWidth - totalSandTilesBeforeWater) * OpenSeaWidthPercentage); + float descentSmoothness = WorldGen.genRand.NextFloat(TopWaterDescentSmoothnessMin, TopWaterDescentSmoothnessMax); + + for (int i = 1; i < width; i++) + { + int x = GetActualX(i); + + // Calculate the 0-1 factor that determines how far down a vertical strip of water should descend. + float depthFactor = (float)Math.Pow(Math.Sin((1f - i / (float)width) * MathHelper.PiOver2), descentSmoothness); + + // Determine the top and botton of the water strip. + int top = YStart; + int bottom = top + (int)(maxDepth * depthFactor); + for (int y = top; y < bottom; y++) + { + if (y >= top + DepthForWater) + Main.tile[x, y].LiquidAmount = byte.MaxValue; + Main.tile[x, y].Get().HasTile = false; + } + + // Clear water that's above the level for some reason. + for (int y = top - 150; y < top + DepthForWater; y++) + Main.tile[x, y].LiquidAmount = 0; + } + } + + public static void GenerateIsland() + { + int left = -32; + int right = (int)(BiomeWidth * IslandWidthPercentage); + int maxDepth = MaxTopWaterDepth; + ushort blockTileType = (ushort)ModContent.TileType(); + ushort wallID = (ushort)ModContent.WallType(); + + for (int i = left; i < right; i++) + { + if (i < 0) + continue; + + // Generate a bump at the edge of the ocean as an island. + // The inside of this is by default solid but cave generation can sometimes create a really cool "hollow" look. + int x = GetActualX(i); + float xCompletionRatio = Utils.GetLerpValue(left, right, i, true); + int islandHeight = (int)Math.Round(Math.Pow(CalamityUtils.Convert01To010(xCompletionRatio), IslandCurvatureSharpness) * (maxDepth + 4f)); + for (int dy = -30; dy <= islandHeight; dy++) + { + int y = YStart + maxDepth - dy; + Main.tile[x, y].TileType = blockTileType; + + if (dy < islandHeight) + Main.tile[x, y].WallType = wallID; + Main.tile[x, y].LiquidAmount = byte.MaxValue; + Main.tile[x, y].Get().HasTile = true; + } + } + } + + public static void GenerateSmallWaterCaverns() + { + int width = BiomeWidth; + int depth = BlockDepth; + int shallowWaterCaveCount = TotalCavesInShallowWater; + int minCaveWidth = MinCaveWidth; + int maxCaveWidth = MaxCaveWidth; + ushort wallID = (ushort)ModContent.WallType(); + + for (int i = 0; i < shallowWaterCaveCount; i++) + { + // Initialize variables for the cave. + int caveHorizontalOffset = WorldGen.genRand.Next((int)(width * 0.1f)); + int x = GetActualX((int)MathHelper.Lerp(width * 0.8f, width * 0.24f, i / (float)(shallowWaterCaveCount - 1f)) + caveHorizontalOffset); + int caveWidth = (minCaveWidth + maxCaveWidth) / 3 + WorldGen.genRand.Next(8); + int caveSteps = WorldGen.genRand.Next(MinCaveMovementSteps, MaxCaveMovementSteps); + int caveSeed = WorldGen.genRand.Next(); + Vector2 baseCaveDirection = Vector2.UnitY.RotatedBy(WorldGen.genRand.NextFloatDirection() * 0.54f); + Vector2 cavePosition = new(x, YStart + MaxTopWaterDepth + DepthForWater / 2); + + for (int j = 0; j < caveSteps; j++) + { + // Make the cave direction turn based on perlin noise. + float caveOffsetAngleAtStep = CalamityUtils.PerlinNoise2D(i / 50f, j / 50f, 4, caveSeed) * MathHelper.Pi * 1.9f; + Vector2 caveDirection = baseCaveDirection.RotatedBy(caveOffsetAngleAtStep); + + // Carve out at the current position. + if (cavePosition.X < Main.maxTilesX - 15 && cavePosition.X >= 15) { - CalamityUtils.ParanoidTileRetrieval(trueX, y).Get().HasTile = false; + WorldGen.digTunnel(cavePosition.X, cavePosition.Y, caveDirection.X, caveDirection.Y, 1, (int)(caveWidth * 1.18f), true); + WorldUtils.Gen(cavePosition.ToPoint(), new Shapes.Circle(caveWidth), Actions.Chain(new GenAction[] + { + new Actions.ClearTile(true), + new Actions.PlaceWall(wallID, true), + new Actions.SetLiquid(LiquidID.Water, (byte)(WorldGen.genRand.NextFloat() > WaterSpreadPercentage ? 0 : byte.MaxValue)) + })); } - if (WallsForSulphSeaToDestroy.Contains(CalamityUtils.ParanoidTileRetrieval(trueX, y).WallType)) + + // Update the cave position. + cavePosition += caveDirection * caveWidth; + + // Turn back if the cave position is close to leaving the sea. + if (GetActualX((int)cavePosition.X) > width * 0.8f || cavePosition.Y > YStart + depth * 0.7f) { - CalamityUtils.ParanoidTileRetrieval(trueX, y).WallType = 0; + cavePosition.X -= Abyss.AtLeftSideOfWorld.ToDirectionInt() * caveWidth; + cavePosition.Y -= caveWidth; + } + + // Update the cave width for the next update step. + float caveWidthFactorInterpolant = (float)Math.Pow(WorldGen.genRand.NextFloat(), SmallCavesBiasTowardsTightness); + caveWidth = (int)Math.Round(caveWidth * MathHelper.Lerp(1f - SmallCavesJaggedness, 1f + SmallCavesJaggedness, caveWidthFactorInterpolant)); + if (WorldGen.genRand.NextBool(12)) + caveWidth = (int)(caveWidth * 1.4f); + + caveWidth = Utils.Clamp(caveWidth, minCaveWidth, maxCaveWidth); + } + } + } + + public static void GenerateSpaghettiWaterCaves() + { + int width = BiomeWidth; + int depth = (int)(BlockDepth * 0.96f); + ushort wallID = (ushort)ModContent.WallType(); + + for (int c = 0; c < SpaghettiCaveCarveOutThresholds.Length; c++) + { + int caveSeed = WorldGen.genRand.Next(); + for (int i = 1; i < width; i++) + { + // Initialize variables for the cave. + int x = GetActualX(i); + for (int y = YStart; y < YStart + depth; y++) + { + float noise = FractalBrownianMotion(i * SpaghettiCaveMagnification, y * SpaghettiCaveMagnification, caveSeed, 5); + + // Bias noise away from 0, effectively making caves less likely to appear, based on how close it is to the bottom/horizontal edge. + // This causes caves to naturally stop as the reach ends instead of abruptly stopping like in the old Sulphurous Sea worldgen. + float distanceFromEdge = new Vector2(i / (float)width, (y - YStart) / (float)depth).Length(); + float biasAwayFrom0Interpolant = Utils.GetLerpValue(0.82f, 0.96f, distanceFromEdge * 0.8f, true); + biasAwayFrom0Interpolant += Utils.GetLerpValue(YStart + 12f, YStart, y, true) * 0.2f; + biasAwayFrom0Interpolant += Utils.GetLerpValue(width - 19f, width - 4f, i, true) * 0.6f; + + // If the noise is less than 0, bias to -1, if it's greater than 0, bias away to 1. + // This is done instead of biasing to -1 or 1 without exception to ensure that in doing so the noise does not cross into the + // cutout threshold near 0 as it interpolates. + noise = MathHelper.Lerp(noise, Math.Sign(noise), biasAwayFrom0Interpolant); + + if (Math.Abs(noise) < SpaghettiCaveCarveOutThresholds[c]) + { + WorldUtils.Gen(new(x, y), new Shapes.Rectangle(1, 1), Actions.Chain(new GenAction[] + { + new Actions.ClearTile(true), + new Actions.PlaceWall(wallID, true), + new Actions.SetLiquid(LiquidID.Water, (byte)(WorldGen.genRand.NextFloat() > WaterSpreadPercentage ? 0 : byte.MaxValue)) + })); + } } } } } - #endregion - #region Nearby Beach - public static readonly List ValidBeachCovertTiles = new() + public static void GenerateCheeseWaterCaves() { - 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() + int width = BiomeWidth; + int depth = (int)(BlockDepth * 0.96f); + ushort wallID = (ushort)ModContent.WallType(); + + for (int c = 0; c < CheeseCaveCarveOutThresholds.Length; c++) + { + int caveSeed = WorldGen.genRand.Next(); + for (int i = 1; i < width; i++) + { + // Initialize variables for the cave. + int x = GetActualX(i); + for (int y = YStart; y < YStart + depth; y++) + { + float noise = FractalBrownianMotion(i * CheeseCaveMagnification, y * CheeseCaveMagnification, caveSeed, 6); + float distanceFromEdge = new Vector2(i / (float)width, (y - YStart) / (float)depth).Length(); + + float biasToNegativeOneInterpolant = Utils.GetLerpValue(0.82f, 0.96f, distanceFromEdge * 0.8f, true); + biasToNegativeOneInterpolant += Utils.GetLerpValue(YStart + OpenCavernStartDepthPercentage * depth, YStart + OpenCavernStartDepthPercentage * depth - 25f, y, true); + biasToNegativeOneInterpolant += Utils.GetLerpValue(width - 19f, width - 4f, i, true); + if (noise - biasToNegativeOneInterpolant > CheeseCaveCarveOutThresholds[c]) + { + WorldUtils.Gen(new(x, y), new Shapes.Rectangle(1, 1), Actions.Chain(new GenAction[] + { + new Actions.ClearTile(true), + new Actions.PlaceWall(wallID, true), + new Actions.SetLiquid(LiquidID.Water, (byte)(WorldGen.genRand.NextFloat() > WaterSpreadPercentage ? 0 : byte.MaxValue)) + })); + } + } + } + } + } + + public static void ClearOutStrayTiles() { - TileID.Coral, - TileID.BeachPiles, - TileID.Plants, - TileID.Plants2, - TileID.SmallPiles, - TileID.LargePiles, - TileID.LargePiles2, - TileID.CorruptThorns, - TileID.CrimsonThorns, - TileID.DyePlants, - TileID.Trees, - TileID.Sunflower, - }; + int width = BiomeWidth; + int depth = BlockDepth; + List blockTileTypes = new() + { + (ushort)ModContent.TileType(), + (ushort)ModContent.TileType(), + (ushort)ModContent.TileType(), + }; + ushort wallID = (ushort)ModContent.WallType(); + + void getAttachedPoints(int x, int y, List points) + { + Tile t = CalamityUtils.ParanoidTileRetrieval(x, y); + Point p = new(x, y); + if (!blockTileTypes.Contains(t.TileType) || !t.HasTile || points.Count > 432 || points.Contains(p) || CalculateDitherChance(width, YStart, YStart + depth, x, y) > 0f) + return; + + points.Add(p); + + getAttachedPoints(x + 1, y, points); + getAttachedPoints(x - 1, y, points); + getAttachedPoints(x, y + 1, points); + getAttachedPoints(x, y - 1, points); + } + + // Clear out stray chunks created by caverns. + for (int i = 1; i < width; i++) + { + int x = GetActualX(i); + for (int y = YStart; y < YStart + depth; y++) + { + List chunkPoints = new(); + getAttachedPoints(x, y, chunkPoints); + + int cutoffLimit = y >= YStart + depth * OpenCavernStartDepthPercentage ? 432 : 50; + if (chunkPoints.Count >= 2 && chunkPoints.Count < cutoffLimit) + { + foreach (Point p in chunkPoints) + { + WorldUtils.Gen(p, new Shapes.Rectangle(1, 1), Actions.Chain(new GenAction[] + { + new Actions.ClearTile(true), + new Actions.PlaceWall(wallID, true), + new Actions.SetLiquid() + })); + } + } + } + } + } + + public static void DecideHardSandstoneLine() + { + int width = BiomeWidth; + int depth = BlockDepth; + + int sandstoneSeed = WorldGen.genRand.Next(); + ushort blockTypeToReplace = (ushort)ModContent.TileType(); + ushort blockTypeToPlace = (ushort)ModContent.TileType(); + ushort wallID = (ushort)ModContent.WallType(); + + for (int i = 0; i < width; i++) + { + for (int y = YStart; y < YStart + depth; y++) + { + 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) * 67f); + + Point p = new(GetActualX(i), y); + Tile t = CalamityUtils.ParanoidTileRetrieval(p.X, p.Y); + if (y >= YStart + sandstoneLineOffset && t.HasTile && t.TileType == blockTypeToReplace) + { + WorldUtils.Gen(p, new Shapes.Rectangle(1, 1), Actions.Chain(new GenAction[] + { + new Actions.SetTile(blockTypeToPlace, true), + new Actions.PlaceWall(wallID, true), + new Actions.SetLiquid() + })); + } + } + } + } + + public static void MakeSurfaceLessRigid() + { + int y = YStart; + int width = BiomeWidth; + int heightSeed = WorldGen.genRand.Next(); + ushort blockTileType = (ushort)ModContent.TileType(); + ushort wallID = (ushort)ModContent.WallType(); + + for (int i = 0; i < width; i++) + { + int x = GetActualX(i); + Tile t = CalamityUtils.ParanoidTileRetrieval(x, y); + + // If the tile below is solid, then determine how high it should rise upward. + // This is done to make the surface less unnaturally flat. + 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)) + { + WorldUtils.Gen(new(x, y + dy), new Shapes.Rectangle(1, 1), Actions.Chain(new GenAction[] + { + heightOffset > 0 ? new Actions.ClearTile() : new Actions.SetTile(blockTileType, true), + new Actions.PlaceWall(MathHelper.Distance(dy, heightOffset) >= 2f && heightOffset < 0f ? wallID : WallID.None, true), + new Actions.SetLiquid() + })); + } + } + } + } + + public static void LayTreesOnSurface() + { + int width = BiomeWidth; + + for (int i = 0; i < width - 8; i++) + { + // Only sometimes generate trees. + if (!WorldGen.genRand.NextBool(TreeGrowChance)) + continue; + + int x = GetActualX(i); + int y = YStart - 30; + + // Search downward in hopes of finding a position to generate and grow an acorn. + // If no such downward tile exists, skip this tile. + if (!WorldUtils.Find(new(x, y), Searches.Chain(new Searches.Down(MaxIslandDepth + 31), new Conditions.IsSolid()), out Point growPoint)) + continue; + + x = growPoint.X; + y = growPoint.Y - 1; + + // Ignore tiles if there's water above. + if (CalamityUtils.ParanoidTileRetrieval(x, y).LiquidAmount > 0) + continue; + + Main.tile[x, y].TileType = TileID.Saplings; + Main.tile[x, y].Get().HasTile = true; + 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); + ushort sandID = (ushort)ModContent.TileType(); + + // Stop immediately if for some strange reason a valid tile could not be located for the beach starting point. + if (!WorldUtils.Find(new Point(BiomeWidth + 4, (int)WorldGen.worldSurfaceLow - 20), searchCondition, out Point determinedPoint)) + return; + Tile tileAtEdge = CalamityUtils.ParanoidTileRetrieval(determinedPoint.X, determinedPoint.Y); - + // Extend outward to encompass some of the desert, if there is one. - if (tileAtEdge.TileType == TileID.Sand || - tileAtEdge.TileType == TileID.Ebonsand || - tileAtEdge.TileType == TileID.Crimsand) - { + if (tileAtEdge.TileType is TileID.Sand or TileID.Ebonsand or TileID.Crimsand) beachWidth += 85; - } - for (int x = BiomeWidth - 10; x <= BiomeWidth + beachWidth; x++) + // Transform the landscape. + for (int i = BiomeWidth - 10; i <= BiomeWidth + beachWidth; i++) { - float xRatio = Utils.GetLerpValue(BiomeWidth - 10, BiomeWidth + beachWidth, x, true); - int trueX = Abyss.AtLeftSideOfWorld ? x : Main.maxTilesX - x; - int depth = (int)(Math.Sin((1f - xRatio) * MathHelper.PiOver2) * 45 + 1); - for (int y = YStart - 40; y < YStart + depth; y++) + 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) * BeachMaxDepth + 1f); + for (int y = YStart - 50; y < YStart + depth; y++) { - Tile tileAtPosition = CalamityUtils.ParanoidTileRetrieval(trueX, 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[trueX, y].TileType == TileID.Trees) - WorldGen.KillTile(trueX, y); + if (Main.tile[x, y].TileType == TileID.Trees) + WorldGen.KillTile(x, y); else - Main.tile[trueX, y].Get().HasTile = false; + Main.tile[x, y].Get().HasTile = false; } - else if (tileAtPosition.HasTile && ValidBeachCovertTiles.Contains(tileAtPosition.TileType)) - { - Main.tile[trueX, y].TileType = (ushort)ModContent.TileType(); - } + else if (tileAtPosition.HasTile && ValidBeachCovertTiles.Contains(tileAtPosition.TileType) && WorldGen.genRand.NextFloat() >= ditherChance) + Main.tile[x, y].TileType = sandID; } } @@ -827,28 +692,68 @@ namespace CalamityMod.World 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)) + if (!WorldUtils.Find(new Point(trueX, y), Searches.Chain(new Searches.Down(100), new Conditions.IsTile(sandID)), out Point treePlantPosition)) continue; - WorldGen.PlaceTile(treePlantPosition.X, treePlantPosition.Y - 1, ModContent.TileType()); + 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 - #region Scrap Piles - public static void PlaceScrapPiles() + public static void ClearAloneTiles() + { + int width = BiomeWidth; + int depth = BlockDepth; + List blockTileTypes = new() + { + (ushort)ModContent.TileType(), + (ushort)ModContent.TileType(), + (ushort)ModContent.TileType(), + }; + + for (int i = 0; i < width; i++) + { + int x = GetActualX(i); + for (int y = YStart; y < YStart + depth; y++) + { + Tile t = CalamityUtils.ParanoidTileRetrieval(x, y); + if (!t.HasTile || !blockTileTypes.Contains(t.TileType)) + continue; + + // Check to see if the tile has any cardinal neighbors. If it doesn't, destroy it. + if (!CalamityUtils.ParanoidTileRetrieval(x - 1, y).HasTile && + !CalamityUtils.ParanoidTileRetrieval(x + 1, y).HasTile && + !CalamityUtils.ParanoidTileRetrieval(x, y - 1).HasTile && + !CalamityUtils.ParanoidTileRetrieval(x, y + 1).HasTile) + { + WorldUtils.Gen(new(x, y), new Shapes.Rectangle(1, 1), Actions.Chain(new GenAction[] + { + new Actions.ClearTile(true), + new Actions.ClearWall(true), + new Actions.SetLiquid() + })); + } + } + } + } + + public static List PlaceScrapPiles() { int tries = 0; - List pastPlacementPostiion = new List(); + List pastPlacementPositions = new List(); for (int i = 0; i < 3; i++) { tries++; if (tries > 20000) continue; - int x = WorldGen.genRand.Next(75, BiomeWidth - 85); - if (!Abyss.AtLeftSideOfWorld) - x = Main.maxTilesX - x; + int x = GetActualX(WorldGen.genRand.Next(75, BiomeWidth - 85)); int y = WorldGen.genRand.Next(YStart + (int)(BlockDepth * 0.3f), YStart + (int)(BlockDepth * 0.8f)); Point pilePlacementPosition = new Point(x, y); @@ -861,7 +766,7 @@ namespace CalamityMod.World } // If the selected position is close to other piles, try again. - if (pastPlacementPostiion.Any(p => Vector2.Distance(p, pilePlacementPosition.ToVector2()) < 85f)) + if (pastPlacementPositions.Any(p => Vector2.Distance(p, pilePlacementPosition.ToVector2()) < ScrapPileAnticlumpDistance)) { i--; continue; @@ -897,7 +802,7 @@ namespace CalamityMod.World } // If the placement position ended up in the abyss, try again. - if (left.Y >= YStart + BlockDepth + 5 || right.Y >= YStart + BlockDepth + 5) + if (left.Y >= YStart + BlockDepth - 50 || right.Y >= YStart + BlockDepth - 50) { i--; continue; @@ -908,14 +813,428 @@ namespace CalamityMod.World bool _ = false; SchematicManager.PlaceSchematic>(schematicName, bottomCenter, SchematicAnchor.BottomCenter, ref _); - pastPlacementPostiion.Add(bottomCenter.ToVector2()); + pastPlacementPositions.Add(bottomCenter.ToVector2()); tries = 0; } + return pastPlacementPositions; } - #endregion Scrap Piles + + public static void GenerateColumnsInCaverns() + { + int columnCount = ColumnCount; + int width = BiomeWidth; + int depth = BlockDepth; + var searchCondition = Searches.Chain(new Searches.Up(MaxColumnHeight), new Conditions.IsSolid()); + + for (int c = 0; c < columnCount; c++) + { + int x = GetActualX(WorldGen.genRand.Next(20, width - 32)); + int y = WorldGen.genRand.Next(YStart, YStart + depth - 30); + + bool tryAgain = false; + + // Try again if inside a tile. + Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); + Tile right = CalamityUtils.ParanoidTileRetrieval(x + 1, y); + Tile bottom = CalamityUtils.ParanoidTileRetrieval(x, y + 1); + Tile bottomRight = CalamityUtils.ParanoidTileRetrieval(x + 1, y + 1); + if (tile.HasTile || right.HasTile) + tryAgain = true; + + // Try again if there is no bottom tile. + if (!WorldGen.SolidTile(bottom) || !WorldGen.SolidTile(bottomRight)) + tryAgain = true; + + // Try again if there is no tile above or the ceiling is not level. + if (!WorldUtils.Find(new(x, y), searchCondition, out Point top) || + !WorldUtils.Find(new(x + 1, y), searchCondition, out Point topRight) || top.Y != topRight.Y) + { + tryAgain = true; + } + + // Try again if the distance between the top and bottom is too short. + if (MathHelper.Distance(y, top.Y) < MinColumnHeight) + tryAgain = true; + + if (tryAgain) + { + c--; + continue; + } + + GenerateColumn(x, top.Y, y); + } + } + + public static void GenerateSteamGeysersInCaverns() + { + int geyserCount = GeyserCount; + int width = BiomeWidth; + int depth = BlockDepth; + ushort geyserID = (ushort)ModContent.TileType(); + + for (int g = 0; g < geyserCount; g++) + { + int x = GetActualX(WorldGen.genRand.Next(20, width - 32)); + int y = WorldGen.genRand.Next(YStart + depth / 2, YStart + depth - 42); + + bool tryAgain = false; + + // Try again if inside a tile. + for (int dx = 0; dx < 2; dx++) + { + for (int dy = 0; dy < 2; dy++) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(x + dx, y - dy); + if (tile.HasTile) + tryAgain = true; + } + } + + // Try again if there is no ground. + for (int dx = 0; dx < 2; dx++) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(x + dx, y + 1); + if (!WorldGen.SolidTile(tile)) + tryAgain = true; + } + + if (tryAgain) + { + g--; + continue; + } + + WorldGen.PlacePot(x, y, geyserID); + } + } + + public static void GenerateHardenedSandstone() + { + int sandstoneSeed = WorldGen.genRand.Next(); + ushort sandstoneID = (ushort)ModContent.TileType(); + ushort sandstoneWallID = (ushort)ModContent.WallType(); + + // Edge score evaluation function that determines the propensity a tile has to become sandstone. + // This is based on how much nearby empty areas there are, allowing for "edges" to appear. + static int getEdgeScore(int x, int y) + { + int edgeScore = 0; + for (int dx = x - 6; dx <= x + 6; dx++) + { + if (dx == x) + continue; + + if (!CalamityUtils.ParanoidTileRetrieval(dx, y).HasTile) + edgeScore++; + } + for (int dy = y - 6; dy <= y + 6; dy++) + { + if (dy == y) + continue; + + if (!CalamityUtils.ParanoidTileRetrieval(x, dy).HasTile) + edgeScore++; + } + return edgeScore; + } + + for (int i = 1; i < BiomeWidth; i++) + { + for (int y = YStart; y <= YStart + BlockDepth; y++) + { + int x = GetActualX(i); + float sandstoneConvertChance = FractalBrownianMotion(i * SandstoneEdgeNoiseMagnification, y * SandstoneEdgeNoiseMagnification, sandstoneSeed, 7) * 0.5f + 0.5f; + + // Make the sandstone appearance chance dependant on the edge score. + sandstoneConvertChance *= Utils.GetLerpValue(4f, 11f, getEdgeScore(x, y), true); + + // Make sandstone less likely to appear on the surface. + sandstoneConvertChance *= Utils.GetLerpValue(YStart + 30f, YStart + 54f, y, true); + + if (WorldGen.genRand.NextFloat() > sandstoneConvertChance || sandstoneConvertChance < 0.5f) + continue; + + // Convert to sandstone as necessary. + for (int dx = -2; dx <= 2; dx++) + { + for (int dy = -2; dy <= 2; dy++) + { + if (WorldGen.InWorld(x + dx, y + dy)) + { + if (CalamityUtils.ParanoidTileRetrieval(x + dx, y + dy).TileType != sandstoneID && + SulphSeaTiles.Contains(CalamityUtils.ParanoidTileRetrieval(x + dx, y + dy).TileType)) + { + Main.tile[x + dx, y + dy].WallType = sandstoneWallID; + Main.tile[x + dx, y + dy].TileType = sandstoneID; + } + } + } + } + } + } + } + + public static void PlaceStalactites() + { + static int heightFromType(int type) + { + if (type <= 2) + return 2; + else if (type <= 4) + return 3; + else + return 4; + }; + + for (int i = 1; i < BiomeWidth; i++) + { + int x = GetActualX(i); + for (int y = YStart; y <= YStart + BlockDepth; y++) + { + if (y - YStart > BlockDepth * 0.25f) + { + if (WorldGen.SolidTile(x, y - 1) && WorldGen.genRand.NextBool(10)) + { + int dy = 1; + while (!CalamityUtils.ParanoidTileRetrieval(x, y + dy).HasTile) + { + dy++; + if (dy > StalactitePairMaxDistance) + break; + } + if (dy <= StalactitePairMaxDistance && dy >= StalactitePairMinDistance) + { + int type = WorldGen.genRand.Next(6); + type++; + int height = heightFromType(type); + + PlaceStalactite(x, y, height, CalamityMod.Instance.Find($"SulphurousStalactite{type}").Type); + if (WorldGen.SolidTile(x, y + dy + 1)) + PlaceStalacmite(x, y + dy, height, CalamityMod.Instance.Find($"SulphurousStalacmite{type}").Type); + } + } + } + } + } + } + + public static void GenerateChests(List scrapPilePositions) + { + GenerateTreasureChest(); + CalamityUtils.SettleWater(); + GenerateOpenAirChestChest(); + GenerateScrapPileChest(scrapPilePositions); + GenerateDeepWaterChest(); + } + + public static void GenerateTreasureChest() + { + // Generate on chest below the island to the edge as buried treasure. + static bool tryToGenerateTreasureChest(Point chestPoint) + { + WorldUtils.Find(chestPoint, Searches.Chain(new Searches.Down(300), new Conditions.IsSolid()), out Point p); + chestPoint = p; + + // Determine how far down the island chest should generate. + int minDepth = 32; + int digDepth = 0; + Point startingIslandChestPoint = chestPoint; + while (true) + { + Tile down = CalamityUtils.ParanoidTileRetrieval(chestPoint.X, chestPoint.Y + digDepth); + Tile downRight = CalamityUtils.ParanoidTileRetrieval(chestPoint.X + 1, chestPoint.Y + digDepth); + + // Stop if far down enough and either the tile to the left or right is open water. + if (((!down.HasTile && down.LiquidAmount >= 127) || (!downRight.HasTile && downRight.LiquidAmount >= 127)) && digDepth >= minDepth) + break; + + digDepth++; + if (digDepth >= 80) + return false; + } + chestPoint.Y += digDepth - 12; + + // Check the nearby area and ensure that it's not exposed to air. The treasure should be buried. + bool nearbyAreaIsClosed = false; + while (!nearbyAreaIsClosed) + { + nearbyAreaIsClosed = true; + for (int dx = -2; dx < 4; dx++) + { + for (int dy = -1; dy < 3; dy++) + { + if (!Main.tile[chestPoint.X + dx, chestPoint.Y - dy].HasTile) + nearbyAreaIsClosed = false; + } + } + + if (!nearbyAreaIsClosed) + chestPoint.Y++; + } + + // Dig up a bit and place the chest. + for (int dx = 0; dx < 2; dx++) + { + for (int dy = 0; dy < 2; dy++) + { + Main.tile[chestPoint.X + dx, chestPoint.Y - dy].LiquidAmount = 0; + Main.tile[chestPoint.X + dx, chestPoint.Y - dy].WallType = (ushort)ModContent.WallType(); + Main.tile[chestPoint.X + dx, chestPoint.Y - dy].Get().HasTile = false; + } + } + + // If a buried chest was placed, force its first item to be the effigy of decay. + Chest chest = MiscWorldgenRoutines.AddChestWithLoot(chestPoint.X + 1, chestPoint.Y + 1, (ushort)ModContent.TileType()); + if (chest != null) + { + chest.item[0].SetDefaults(ModContent.ItemType()); + chest.item[0].Prefix(-1); + } + else + return false; + + // Go back to the surface and leave a little bit of sulphurous sandstone instead of sand as a small marker of the treasure. + for (int dx = 0; dx < 2; dx++) + { + for (int dy = -1; dy < 3; dy++) + { + // Ensure that palm trees and pots are not transformed. + int oldTileType = Main.tile[startingIslandChestPoint.X + dx, startingIslandChestPoint.Y + dy].TileType; + if (oldTileType == TileID.PalmTree || !Main.tileSolid[oldTileType]) + { + WorldGen.KillTile(startingIslandChestPoint.X + dx, startingIslandChestPoint.Y + dy); + continue; + } + + Main.tile[startingIslandChestPoint.X + dx, startingIslandChestPoint.Y + dy].LiquidAmount = 0; + Main.tile[startingIslandChestPoint.X + dx, startingIslandChestPoint.Y + dy].TileType = (ushort)ModContent.TileType(); + } + } + return true; + } + + Point islandChestPoint = new(GetActualX((int)(BiomeWidth * IslandWidthPercentage * 0.5f) + WorldGen.genRand.Next(-8, 9)), YStart - 100); + while (!tryToGenerateTreasureChest(islandChestPoint)) + islandChestPoint.X += Abyss.AtLeftSideOfWorld.ToDirectionInt(); + } + + public static void GenerateOpenAirChestChest() + { + int width = BiomeWidth; + Dictionary depthMap = new(); + + for (int i = 60; i < width - 50; i++) + { + int x = GetActualX(i); + int y = YStart + MaxIslandDepth + 2; + int dy = 0; + + while (CalamityUtils.ParanoidTileRetrieval(x, y + dy).HasTile || CalamityUtils.ParanoidTileRetrieval(x, y + dy).LiquidAmount <= 0) + dy++; + + depthMap[x] = CalamityUtils.ParanoidTileRetrieval(x, y).HasTile ? y + dy : 0; + } + + // Pick a smooth place on the depth map to place the chest. This should happen close to an open air point in the caves. + for (int i = 0; i < 400; i++) + { + int x = depthMap.Keys.ElementAt(WorldGen.genRand.Next(10, depthMap.Count - 10)); + int leftY = depthMap[x - 1]; + int currentY = depthMap[x]; + int rightY = depthMap[x + 1]; + int averageY = (leftY + currentY + rightY) / 3; + + if (Math.Abs(averageY - currentY) < 3f && currentY > 0) + { + currentY += 3; + + // Ignore the current position if the chest cannot be placed due to tiles in the way. + if (CalamityUtils.AnySolidTileInSelection(x, currentY - 1, 4, -4)) + continue; + + // Place the chest and ground. + for (int dx = -1; dx < 3; dx++) + { + Main.tile[x + dx, currentY + 1].LiquidAmount = 0; + Main.tile[x + dx, currentY + 1].TileType = (ushort)ModContent.TileType(); + Main.tile[x + dx, currentY + 1].Get().HasTile = true; + } + + // If a buried chest was placed, force its first item to be the broken water filter. + Chest chest = MiscWorldgenRoutines.AddChestWithLoot(x, currentY - 2, (ushort)ModContent.TileType()); + if (chest != null) + { + chest.item[0].SetDefaults(ModContent.ItemType()); + chest.item[0].Prefix(-1); + break; + } + else + continue; + } + } + } + + public static void GenerateScrapPileChest(List scrapPilePositions) + { + // Pick a random scrap pile to generate near. + for (int i = 0; i < 400; i++) + { + Point placeToGenerateNear = WorldGen.genRand.Next(scrapPilePositions).ToPoint(); + int x = placeToGenerateNear.X + WorldGen.genRand.Next(-25 - i / 15, 25 + i / 15); + int y = placeToGenerateNear.Y + WorldGen.genRand.Next(-16, 4); + if (WorldGen.SolidTile(x, y)) + continue; + + // If a buried chest was successfully placed, force its first item to be the rusty beacon prototype. + Chest chest = MiscWorldgenRoutines.AddChestWithLoot(x, y, (ushort)ModContent.TileType()); + if (chest != null) + { + chest.item[0].SetDefaults(ModContent.ItemType()); + chest.item[0].Prefix(-1); + break; + } + } + } + + public static void GenerateDeepWaterChest() + { + // Pick a random scrap pile to generate near. + for (int i = 0; i < 400; i++) + { + int x = GetActualX(WorldGen.genRand.Next(60, BiomeWidth - 60)); + int y = YStart + WorldGen.genRand.Next(BlockDepth - 150, BlockDepth - 45); + if (WorldGen.SolidTile(x, y)) + continue; + + // Try again if too far down. + while (y < Main.maxTilesY - 210) + { + if (!WorldGen.SolidTile(x, y)) + y++; + else + { + y -= 3; + break; + } + } + if (y >= YStart + BlockDepth - 45) + continue; + + // If a buried chest was successfully placed, force its first item to be the rusty medallion. + Chest chest = MiscWorldgenRoutines.AddChestWithLoot(x, y, (ushort)ModContent.TileType()); + if (chest != null) + { + chest.item[0].SetDefaults(ModContent.ItemType()); + chest.item[0].Prefix(-1); + break; + } + } + } + #endregion Generation Functions #region Misc Functions - public static List YStartWhitelist = new() + public static readonly List YStartWhitelist = new() { TileID.Stone, TileID.Dirt, @@ -952,21 +1271,185 @@ namespace CalamityMod.World TileID.CrimsonVines, TileID.Containers, TileID.DyePlants, - TileID.JungleGrass // Yes, this can happen on rare occasion + TileID.JungleGrass, // Yes, this can happen on rare occasion. + TileID.SeaOats }; - public static void DetermineYStart() - { - int xCheckPosition = Abyss.AtLeftSideOfWorld ? BiomeWidth + 1 : Main.maxTilesX - BiomeWidth - 1; - var searchCondition = Searches.Chain(new Searches.Down(3000), new Conditions.IsSolid()); - Point determinedPoint; - do + public static readonly List OtherTilesForSulphSeaToDestroy = new() + { + TileID.PalmTree, + TileID.Sunflower, + TileID.CorruptThorns, + TileID.CrimsonThorns, + TileID.CorruptGrass, + TileID.CorruptPlants, + TileID.Stalactite, + TileID.ImmatureHerbs, + TileID.MatureHerbs, + TileID.Pots, + TileID.Pumpkins, // Happens during Halloween + TileID.FallenLog, + TileID.LilyPad, + TileID.VanityTreeSakura, + TileID.VanityTreeYellowWillow, + TileID.ShellPile + }; + + public static readonly List WallsForSulphSeaToDestroy = new() + { + WallID.Dirt, + WallID.DirtUnsafe, + WallID.DirtUnsafe1, + WallID.DirtUnsafe2, + WallID.DirtUnsafe3, + WallID.DirtUnsafe4, + WallID.Cave6Unsafe, // Rocky dirt wall + WallID.Grass, + WallID.GrassUnsafe, + WallID.Flower, + WallID.FlowerUnsafe, + WallID.CorruptGrassUnsafe, + WallID.EbonstoneUnsafe, + 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) + { + if (Abyss.AtLeftSideOfWorld) + return x; + + return Main.maxTilesX - x; + } + + public static float CalculateDitherChance(int width, int top, int bottom, int x, int y) + { + float verticalCompletion = Utils.GetLerpValue(top, bottom, y, true); + float horizontalDitherChance = Utils.GetLerpValue(DitherStartFactor, 1f, x / (float)width, true); + float verticalDitherChance = Utils.GetLerpValue(DitherStartFactor, 1f, verticalCompletion, true); + float ditherChance = horizontalDitherChance + verticalDitherChance; + if (ditherChance > 1f) + ditherChance = 1f; + + // Make the dither chance fizzle out at low vertical completion values. + // This is done so that there isn't dithering on the surface of the sea. + ditherChance -= Utils.GetLerpValue(0.56f, 0.5f, verticalCompletion, true); + if (ditherChance < 0f) + ditherChance = 0f; + return ditherChance; + } + + public static float FractalBrownianMotion(float x, float y, int seed, int octaves, float gain = 0.5f, float lacunarity = 2f) + { + float result = 0f; + float frequency = 1f; + float amplitude = 0.5f; + x += seed * 0.00489937f % 10f; + + for (int i = 0; i < octaves; i++) { - WorldUtils.Find(new Point(xCheckPosition, (int)WorldGen.worldSurfaceLow - 20), searchCondition, out determinedPoint); - xCheckPosition += Abyss.AtLeftSideOfWorld.ToDirectionInt(); + float noise = NoiseHelper.GetStaticNoise(new Vector2(x, y) * frequency) * 2f - 1f; + result += noise * amplitude; + amplitude *= gain; + frequency *= lacunarity; + } + + return result; + } + + public static void GenerateColumn(int left, int top, int bottom) + { + int depth = BlockDepth; + ushort columnID = (ushort)ModContent.TileType(); + ushort hardenedSandstoneWallID = (ushort)ModContent.WallType(); + ushort sandWallID = (ushort)ModContent.WallType(); + short variantFrameOffset = (short)(WorldGen.genRand.Next(3) * 36); + + for (int x = left; x < left + 2; x++) + { + for (int y = top; y <= bottom; y++) + { + short frameX = (short)((x - left) * 18 + variantFrameOffset); + + // Use the top frame if at the top, bottom frame if at the bottom, and the middle frame otherwise. + short frameY = 18; + if (y == top) + frameY = 0; + else if (y == bottom) + frameY = 36; + + Main.tile[x, y].TileType = columnID; + Main.tile[x, y].TileFrameX = frameX; + Main.tile[x, y].TileFrameY = frameY; + Main.tile[x, y].WallType = y >= YStart + depth * OpenCavernStartDepthPercentage ? hardenedSandstoneWallID : sandWallID; + Main.tile[x, y].Get().HasTile = true; + } + } + } + + public static void PlaceStalactite(int x, int y, int height, ushort type) + { + for (int dy = 0; dy < height; dy++) + { + ushort oldWall = Main.tile[x, y + dy].WallType; + Main.tile[x, y + dy].ClearEverything(); + Main.tile[x, y + dy].WallType = oldWall; + Main.tile[x, y + dy].TileType = type; + Main.tile[x, y + dy].TileFrameY = (short)(dy * 18); + Main.tile[x, y + dy].Get().HasTile = true; + } + } + + public static void PlaceStalacmite(int x, int y, int height, ushort type) + { + for (int dy = height - 1; dy > 0; dy--) + { + ushort oldWall = Main.tile[x, y + dy].WallType; + Main.tile[x, y - dy].ClearEverything(); + Main.tile[x, y - dy].WallType = oldWall; + Main.tile[x, y - dy].TileType = type; + Main.tile[x, y - dy].TileFrameY = (short)(height * 18 - dy * 18); + Main.tile[x, y - dy].Get().HasTile = true; } - while (CalamityUtils.ParanoidTileRetrieval(determinedPoint.X, determinedPoint.Y).TileType == TileID.Ebonstone); - YStart = determinedPoint.Y; } #endregion } diff --git a/World/WorldEvilIsland.cs b/World/WorldEvilIsland.cs index bff00076c5..438d887083 100644 --- a/World/WorldEvilIsland.cs +++ b/World/WorldEvilIsland.cs @@ -65,8 +65,8 @@ namespace CalamityMod.World do { xIslandGen = WorldGen.crimson ? - WorldGen.genRand.Next((int)(x * 0.1), (int)(x * 0.2)) : - WorldGen.genRand.Next((int)(x * 0.8), (int)(x * 0.9)); + WorldGen.genRand.Next((int)(x * 0.1), (int)(x * 0.3)) : + WorldGen.genRand.Next((int)(x * 0.7), (int)(x * 0.9)); yIslandGen = WorldGen.genRand.Next(95, 126); yIslandGen = Math.Min(yIslandGen, (int)WorldGen.worldSurfaceLow - 50);