From 4f61c7f68fa042bb882be81e93cff59efcc0f669 Mon Sep 17 00:00:00 2001 From: mountaindrew10 Date: Wed, 23 Apr 2025 08:14:30 -0500 Subject: [PATCH] Better Mechanic Shed placement. --- NPCs/DevourerofGods/DevourerofGodsBody.cs | 5 +- NPCs/DevourerofGods/DevourerofGodsTail.cs | 12 +--- World/AstralBiome.cs | 2 +- World/MechanicShed.cs | 86 ++++++++++++++++++++--- 4 files changed, 82 insertions(+), 23 deletions(-) diff --git a/NPCs/DevourerofGods/DevourerofGodsBody.cs b/NPCs/DevourerofGods/DevourerofGodsBody.cs index 5e73bc5286..ce926f38ca 100644 --- a/NPCs/DevourerofGods/DevourerofGodsBody.cs +++ b/NPCs/DevourerofGods/DevourerofGodsBody.cs @@ -145,10 +145,7 @@ namespace CalamityMod.NPCs.DevourerofGods NPC.frame = frame; } - public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position) - { - return false; - } + public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position) => false; public override void AI() { diff --git a/NPCs/DevourerofGods/DevourerofGodsTail.cs b/NPCs/DevourerofGods/DevourerofGodsTail.cs index cc6792d10a..ac2e7d6dc6 100644 --- a/NPCs/DevourerofGods/DevourerofGodsTail.cs +++ b/NPCs/DevourerofGods/DevourerofGodsTail.cs @@ -146,10 +146,7 @@ namespace CalamityMod.NPCs.DevourerofGods NPC.frame = frame; } - public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position) - { - return false; - } + public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position) => false; public override void AI() { @@ -450,15 +447,10 @@ namespace CalamityMod.NPCs.DevourerofGods { // viable???, done here since it's conditional if (Main.zenithWorld && projectile.type == ModContent.ProjectileType()) - { modifiers.SourceDamage *= 40f; - } } - public override bool CheckActive() - { - return false; - } + public override bool CheckActive() => false; public override bool CheckDead() { diff --git a/World/AstralBiome.cs b/World/AstralBiome.cs index 90115f55a7..6fcb107f3b 100644 --- a/World/AstralBiome.cs +++ b/World/AstralBiome.cs @@ -500,7 +500,7 @@ namespace CalamityMod.World int distanceToCheckForCriticalTilesY = 50; int attempts = 0; - int maxAttempts = 10000; + int maxAttempts = 100000; while (!altarPlaced) { WorldGen.gen = true; diff --git a/World/MechanicShed.cs b/World/MechanicShed.cs index 653edd2d18..86d7e392ef 100644 --- a/World/MechanicShed.cs +++ b/World/MechanicShed.cs @@ -17,25 +17,95 @@ namespace CalamityMod.World string mapKey = MechanicShedKey; var schematic = TileMaps[mapKey]; - int placementPositionX = WorldGen.genRand.Next(GenVars.snowOriginLeft + 100, GenVars.snowOriginRight - 100); - int placementPositionY = (int)Main.worldSurface - (Main.maxTilesY / 12); + int leftLimit = GenVars.snowOriginLeft + 100; + int rightLimit = GenVars.snowOriginRight - 100; + int placementPositionX = WorldGen.genRand.Next(leftLimit, rightLimit); + int placementPositionY = (int)Main.worldSurface - 50; + + int distanceToCheckForSnowTilesX = 30; + int distanceToCheckForSnowTilesY = 5; + int snowTilesRequired = 100; + int emptyTilesRequired = 100; bool foundValidGround = false; int attempts = 0; - while (!foundValidGround && attempts++ < 100000) + int maxAttempts = 100000; + while (!foundValidGround && attempts <= maxAttempts) { - while (!WorldGen.SolidTile(placementPositionX, placementPositionY) && placementPositionY <= Main.worldSurface) + attempts++; + + // Check if there are enough snow tiles on the bottom of the shed's gen location + // 150 tiles checked in total + int snowTileCount = 0; + bool enoughSnowTilesOnBottom = false; + for (int shedTileCheckIndexX = placementPositionX - 15; shedTileCheckIndexX < placementPositionX - 15 + distanceToCheckForSnowTilesX; shedTileCheckIndexX++) { - placementPositionY++; + if (enoughSnowTilesOnBottom) + break; + + for (int shedTileCheckIndexY = placementPositionY - 5; shedTileCheckIndexY < placementPositionY - 5 + distanceToCheckForSnowTilesY; shedTileCheckIndexY++) + { + if (Main.tile[shedTileCheckIndexX, shedTileCheckIndexY] != null) + { + if (Main.tile[shedTileCheckIndexX, shedTileCheckIndexY].HasTile) + { + if (Main.tile[shedTileCheckIndexX, shedTileCheckIndexY].TileType == TileID.SnowBlock) + { + snowTileCount++; + if (snowTileCount >= snowTilesRequired) + { + enoughSnowTilesOnBottom = true; + break; + } + } + } + } + } } - if (Main.tile[placementPositionX, placementPositionY].HasTile || Main.tile[placementPositionX, placementPositionY].WallType > 0) + // Check if there are enough empty tiles on the top of the shed's gen location + // 150 tiles checked in total + int emptyTileCount = 0; + bool enoughEmptyTilesOnTop = false; + for (int shedTileCheckIndexX = placementPositionX - 15; shedTileCheckIndexX < placementPositionX - 15 + distanceToCheckForSnowTilesX; shedTileCheckIndexX++) { - foundValidGround = true; + if (enoughEmptyTilesOnTop) + break; + + for (int shedTileCheckIndexY = placementPositionY - 20; shedTileCheckIndexY < placementPositionY - 20 + distanceToCheckForSnowTilesY; shedTileCheckIndexY++) + { + if ((Main.tile[shedTileCheckIndexX, shedTileCheckIndexY] == null || + !Main.tile[shedTileCheckIndexX, shedTileCheckIndexY].HasTile) && + Main.tile[shedTileCheckIndexX, shedTileCheckIndexY].WallType == WallID.None) + { + emptyTileCount++; + if (emptyTileCount >= emptyTilesRequired) + { + enoughEmptyTilesOnTop = true; + break; + } + } + } + } + + if (enoughSnowTilesOnBottom && enoughEmptyTilesOnTop) + { + break; + } + else + { + placementPositionX += 5; + if (placementPositionX > rightLimit) + placementPositionX = leftLimit; + + if (!enoughEmptyTilesOnTop) + placementPositionY -= 5; + else if (!enoughSnowTilesOnBottom) + placementPositionY += 5; } } - Point placementPoint = new Point(placementPositionX, placementPositionY + 5); + Point placementPoint = new Point(placementPositionX, placementPositionY); Vector2 schematicSize = new Vector2(schematic.GetLength(0), schematic.GetLength(1)); SchematicAnchor anchorType = SchematicAnchor.BottomCenter;