From fc18b6459167e2f2919bd89a3d9fd088e2ed8bbc Mon Sep 17 00:00:00 2001 From: DominicKarma42 <51094361+DominicKarma@users.noreply.github.com> Date: Thu, 16 Jul 2020 17:14:03 -0500 Subject: [PATCH] Added more Arsenal structure checks --- World/CalamityWorld.cs | 9 ++++- World/DraedonStructures.cs | 77 ++++++++++++++++++++------------------ 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/World/CalamityWorld.cs b/World/CalamityWorld.cs index e94980b85f..cf29374c75 100644 --- a/World/CalamityWorld.cs +++ b/World/CalamityWorld.cs @@ -907,12 +907,17 @@ namespace CalamityMod.World tasks.Insert(FinalIndex + 3, new PassLegacy("Rust and Dust", (GenerationProgress progress) => { List workshopPositions = new List(); - for (int i = 0; i < 10; i++) + int workshopCount = Main.maxTilesX / 600; + int labCount = Main.maxTilesX / 1100; + DraedonStructures.DraedonsLogWorkshopIndex = WorldGen.genRand.Next(workshopCount); + + for (int i = 0; i < workshopCount; i++) { DraedonStructures.PlaceWorkshop(out Point placementPosition, workshopPositions); + DraedonStructures.CurrentWorkshopIndex = i; workshopPositions.Add(placementPosition); } - for (int i = 0; i < 4; i++) + for (int i = 0; i < labCount; i++) { DraedonStructures.PlacePlagueLab(out Point placementPosition2, workshopPositions); workshopPositions.Add(placementPosition2); diff --git a/World/DraedonStructures.cs b/World/DraedonStructures.cs index 5895edb45c..5eb9c57144 100644 --- a/World/DraedonStructures.cs +++ b/World/DraedonStructures.cs @@ -22,10 +22,11 @@ namespace CalamityMod.World } public static class DraedonStructures { - public static bool DraedonsLogPresentInWorld = false; + public static int CurrentWorkshopIndex; + public static int DraedonsLogWorkshopIndex; public static void FillWorkshopChest(Chest chest) { - int potionType = Utils.SelectRandom(Main.rand, ItemID.EndurancePotion, ItemID.GravitationPotion, ItemID.HeartreachPotion, ItemID.LifeforcePotion); + int potionType = Utils.SelectRandom(WorldGen.genRand, ItemID.EndurancePotion, ItemID.GravitationPotion, ItemID.HeartreachPotion, ItemID.LifeforcePotion); List contents = new List() { new ChestItem(ModContent.ItemType(), WorldGen.genRand.Next(8, 14 + 1)), @@ -36,11 +37,8 @@ namespace CalamityMod.World new ChestItem(ItemID.Bomb, WorldGen.genRand.Next(6, 7 + 1)), new ChestItem(potionType, WorldGen.genRand.Next(3, 5 + 1)), }; - if (!DraedonsLogPresentInWorld) - { + if (CurrentWorkshopIndex == DraedonsLogWorkshopIndex) contents.Insert(0, new ChestItem(ModContent.ItemType(), 1)); - DraedonsLogPresentInWorld = true; - } for (int i = 0; i < contents.Count; i++) { chest.item[i].SetDefaults(contents[i].Type); @@ -49,7 +47,7 @@ namespace CalamityMod.World } public static void FillLaboratoryChest(Chest chest) { - int potionType = Utils.SelectRandom(Main.rand, ItemID.EndurancePotion, ItemID.GravitationPotion, ItemID.HeartreachPotion, ItemID.LifeforcePotion); + int potionType = Utils.SelectRandom(WorldGen.genRand, ItemID.EndurancePotion, ItemID.GravitationPotion, ItemID.HeartreachPotion, ItemID.LifeforcePotion); List contents = new List() { new ChestItem(ModContent.ItemType(), WorldGen.genRand.Next(10, 17 + 1)), @@ -66,6 +64,31 @@ namespace CalamityMod.World chest.item[i].stack = contents[i].Stack; } } + public static bool ShouldAvoidLocation(Point placementPoint) + { + Tile tile = CalamityUtils.ParanoidTileRetrieval(placementPoint.X, placementPoint.Y); + if (tile.lava()) + return true; + if (tile.type == TileID.BlueDungeonBrick || + tile.type == TileID.GreenDungeonBrick || + tile.type == TileID.PinkDungeonBrick) + { + return true; + } + if (tile.type == TileID.LihzahrdBrick || + tile.wall == WallID.LihzahrdBrickUnsafe) + { + return true; + } + if (tile.type == TileID.Crimstone || + tile.wall == WallID.CrimstoneUnsafe || + tile.type == TileID.Ebonstone || + tile.wall == WallID.EbonstoneUnsafe) + { + return true; + } + return false; + } public static void PlaceWorkshop(out Point placementPoint, List workshopPoints) { int tries = 0; @@ -79,8 +102,7 @@ namespace CalamityMod.World Vector2 schematicSize = new Vector2(SchematicLoader.TileMaps["Workshop"].GetLength(0), SchematicLoader.TileMaps["Workshop"].GetLength(1)); int activeTilesInArea = 0; int xCheckArea = 40; - bool anyDungeonBricks = false; - bool anyLihzardBricks = false; + bool canGenerateInLocation = true; // new Vector2 is used here since a lambda expression cannot capture a ref, out, or in parameter. bool nearbyOtherWorkshop = workshopPoints.Any(point => Vector2.Distance(point.ToVector2(), new Vector2(placementPositionX, placementPositionY)) < 240f); @@ -92,25 +114,16 @@ namespace CalamityMod.World Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); if (tile.active()) { - if (tile.type == TileID.BlueDungeonBrick || - tile.type == TileID.GreenDungeonBrick || - tile.type == TileID.PinkDungeonBrick) - { - anyDungeonBricks = true; - } - if (tile.type == TileID.LihzahrdBrick || - tile.wall == WallID.LihzahrdBrickUnsafe) - { - anyLihzardBricks = true; - } + if (ShouldAvoidLocation(new Point(x, y))) + canGenerateInLocation = false; activeTilesInArea++; } } } - if (anyDungeonBricks || anyLihzardBricks || nearbyOtherWorkshop || activeTilesInArea / totalTiles > 0.35f) + if (!canGenerateInLocation || nearbyOtherWorkshop || activeTilesInArea / totalTiles > 0.35f) { tries++; - if (tries > 2500) + if (tries > 25000) return; goto TryAgain; // Try again elsewhere if the correct conditions are not met. (Yes, I'm using a goto. Please don't kill me) } @@ -129,8 +142,7 @@ namespace CalamityMod.World Vector2 schematicSize = new Vector2(SchematicLoader.TileMaps["Plague Research Facility"].GetLength(0), SchematicLoader.TileMaps["Plague Research Facility"].GetLength(1)); int activeTilesInArea = 0; int xCheckArea = 30; - bool anyDungeonBricks = false; - bool anyLihzardBricks = false; + bool canGenerateInLocation = true; // new Vector2 is used here since a lambda expression cannot capture a ref, out, or in parameter. bool nearbyOtherWorkshop = workshopPoints.Any(point => Vector2.Distance(point.ToVector2(), new Vector2(placementPositionX, placementPositionY)) < 240f); @@ -142,25 +154,16 @@ namespace CalamityMod.World Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); if (tile.active()) { - if (tile.type == TileID.BlueDungeonBrick || - tile.type == TileID.GreenDungeonBrick || - tile.type == TileID.PinkDungeonBrick) - { - anyDungeonBricks = true; - } - if (tile.type == TileID.LihzahrdBrick || - tile.wall == WallID.LihzahrdBrickUnsafe) - { - anyLihzardBricks = true; - } + if (ShouldAvoidLocation(new Point(x, y))) + canGenerateInLocation = false; activeTilesInArea++; } } } - if (anyLihzardBricks || anyDungeonBricks || nearbyOtherWorkshop || activeTilesInArea / totalTiles > 0.3f) + if (!canGenerateInLocation || nearbyOtherWorkshop || activeTilesInArea / totalTiles > 0.35f) { tries++; - if (tries > 6000) + if (tries > 25000) return; goto TryAgain; // Try again elsewhere if the correct conditions are not met. (Yes, I'm using a goto. Please don't kill me) }