From eaa26ef0e6962be1d13b46bf588f78d4a41eac3a Mon Sep 17 00:00:00 2001 From: Ozzatron Date: Sat, 24 Oct 2020 13:46:29 -0400 Subject: [PATCH] fixed placement anchors & floating astral beacon --- Schematics/SchematicDataTypes.cs | 21 ++++++++++---- Schematics/SchematicManager.cs | 49 ++++++++++++++++++++------------ World/DraedonStructures.cs | 12 ++++---- World/Planets/MainPlanet.cs | 3 +- World/WorldGenerationMethods.cs | 25 ++++++++-------- 5 files changed, 67 insertions(+), 43 deletions(-) diff --git a/Schematics/SchematicDataTypes.cs b/Schematics/SchematicDataTypes.cs index 9fa54511cd..8a1d8c7097 100644 --- a/Schematics/SchematicDataTypes.cs +++ b/Schematics/SchematicDataTypes.cs @@ -11,12 +11,21 @@ } } - public enum PlacementAnchorType + // The numbers assigned to these anchor types correspond to the layout of a numpad: + // 7 8 9 + // 4 5 6 + // 1 2 3 + public enum SchematicAnchor { - TopLeft, - TopRight, - Center, - BottomLeft, - BottomRight, + Default = 0, // default is treated as equivalent to top left, but top left can be explicitly specified + TopLeft = 7, + TopCenter = 8, + TopRight = 9, + CenterLeft = 4, + Center = 5, + CenterRight = 6, + BottomLeft = 1, + BottomCenter = 2, + BottomRight = 3, } } diff --git a/Schematics/SchematicManager.cs b/Schematics/SchematicManager.cs index 4084705ff7..0dda76c2b1 100644 --- a/Schematics/SchematicManager.cs +++ b/Schematics/SchematicManager.cs @@ -43,7 +43,7 @@ namespace CalamityMod.Schematics #endregion #region Place Schematic - public static void PlaceSchematic(string name, Point pos, PlacementAnchorType anchorType, ref bool specialCondition, T chestDelegate = null) where T : Delegate + public static void PlaceSchematic(string name, Point pos, SchematicAnchor anchorType, ref bool specialCondition, T chestDelegate = null) where T : Delegate { // If no schematic exists with this name, cancel with a helpful log message. if (!TileMaps.ContainsKey(name)) @@ -67,29 +67,42 @@ namespace CalamityMod.Schematics int height = schematic.GetLength(1); // Calculate the appropriate location to start laying down schematic tiles. - // TopLeft is the default because anchoring things at their top-left corner is the default Terraria behavior. - // This is why it does nothing. int cornerX = pos.X; int cornerY = pos.Y; switch (anchorType) { - case PlacementAnchorType.TopRight: - cornerX += width; - break; - case PlacementAnchorType.Center: - cornerX += width / 2; - cornerY += height / 2; - break; - case PlacementAnchorType.BottomLeft: - cornerY += height; - break; - case PlacementAnchorType.BottomRight: - cornerX += width; - cornerY += height; - break; - case PlacementAnchorType.TopLeft: + case SchematicAnchor.TopLeft: // Provided point is top-left corner = No change + case SchematicAnchor.Default: // This is also default behavior default: break; + case SchematicAnchor.TopCenter: // Provided point is top center = Top-left corner is 1/2 width to the left + cornerX -= width / 2; + break; + case SchematicAnchor.TopRight: // Provided point is top-right corner = Top-left corner is 1 width to the left + cornerX -= width; + break; + case SchematicAnchor.CenterLeft: // Provided point is left center: Top-left corner is 1/2 height above + cornerY -= height / 2; + break; + case SchematicAnchor.Center: // Provided point is center = Top-left corner is 1/2 width and 1/2 height up-left + cornerX -= width / 2; + cornerY -= height / 2; + break; + case SchematicAnchor.CenterRight: // Provided point is right center: Top-left corner is 1 width and 1/2 height up-left + cornerX -= width; + cornerY -= height / 2; + break; + case SchematicAnchor.BottomLeft: // Provided point is bottom-left corner = Top-left corner is 1 height above + cornerY -= height; + break; + case SchematicAnchor.BottomCenter: // Provided point is bottom center: Top-left corner is 1/2 width and 1 height up-left + cornerX -= width / 2; + cornerY -= height; + break; + case SchematicAnchor.BottomRight: // Provided point is bottom-right corner = Top-left corner is 1 width to the left and 1 height above + cornerX -= width; + cornerY -= height; + break; } // Make sure that all four corners of the target area are actually in the world. diff --git a/World/DraedonStructures.cs b/World/DraedonStructures.cs index c54aba2b55..9edc6a776e 100644 --- a/World/DraedonStructures.cs +++ b/World/DraedonStructures.cs @@ -105,7 +105,7 @@ namespace CalamityMod.World else { bool _ = true; - PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), PlacementAnchorType.TopLeft, ref _, new Action(FillWorkshopChest)); + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action(FillWorkshopChest)); break; } @@ -170,7 +170,7 @@ namespace CalamityMod.World else { bool _ = true; - PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), PlacementAnchorType.TopLeft, ref _, new Action(FillLaboratoryChest)); + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action(FillLaboratoryChest)); break; } } @@ -241,7 +241,7 @@ namespace CalamityMod.World else { bool hasPlacedMurasama = false; - PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), PlacementAnchorType.TopLeft, ref hasPlacedMurasama, new Action(FillHellLaboratoryChest)); + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref hasPlacedMurasama, new Action(FillHellLaboratoryChest)); break; } } @@ -313,7 +313,7 @@ namespace CalamityMod.World while (tries < 50000); bool hasPlacedLogAndSchematic = false; - PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), PlacementAnchorType.TopLeft, ref hasPlacedLogAndSchematic, new Action(FillSunkenSeaLaboratoryChest)); + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref hasPlacedLogAndSchematic, new Action(FillSunkenSeaLaboratoryChest)); } #endregion @@ -392,7 +392,7 @@ namespace CalamityMod.World else { bool hasPlacedLogAndSchematic = false; - PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), PlacementAnchorType.TopLeft, ref hasPlacedLogAndSchematic, new Action(FillIceLaboratoryChest)); + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref hasPlacedLogAndSchematic, new Action(FillIceLaboratoryChest)); break; } } @@ -471,7 +471,7 @@ namespace CalamityMod.World else { bool hasPlacedLogAndSchematic = false; - PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), PlacementAnchorType.TopLeft, ref hasPlacedLogAndSchematic, new Action(FillPlagueLaboratoryChest)); + PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref hasPlacedLogAndSchematic, new Action(FillPlagueLaboratoryChest)); break; } } diff --git a/World/Planets/MainPlanet.cs b/World/Planets/MainPlanet.cs index ec69cdfd63..24c5787857 100644 --- a/World/Planets/MainPlanet.cs +++ b/World/Planets/MainPlanet.cs @@ -105,8 +105,9 @@ namespace CalamityMod.World.Planets new Actions.SetFrames(true) })); + // TODO -- This should probably use PlacementAnchor.Center and just provide the center of the planetoid... bool hasPlacedLogAndSchematic = false; - SchematicManager.PlaceSchematic("Planetoid Laboratory", new Point(origin.X - 33, origin.Y - 17), PlacementAnchorType.TopLeft, ref hasPlacedLogAndSchematic, new Action(DraedonStructures.FillPlanetoidLaboratoryChest)); + SchematicManager.PlaceSchematic("Planetoid Laboratory", new Point(origin.X - 33, origin.Y - 17), SchematicAnchor.TopLeft, ref hasPlacedLogAndSchematic, new Action(DraedonStructures.FillPlanetoidLaboratoryChest)); //PLACE BREAKABLE GRASS AND TREES WorldUtils.Gen(origin, new ModShapes.OuterOutline(mainShape, true, true), Actions.Chain(new GenAction[] diff --git a/World/WorldGenerationMethods.cs b/World/WorldGenerationMethods.cs index eafd4a556b..bcb93f68f7 100644 --- a/World/WorldGenerationMethods.cs +++ b/World/WorldGenerationMethods.cs @@ -190,10 +190,10 @@ namespace CalamityMod.World PutItemInChest(ref chest, ItemID.GoldCoin, 1, 2); } } - #endregion + #endregion - #region Place Rox Shrine - public static void PlaceRoxShrine() + #region Place Rox Shrine + public static void PlaceRoxShrine() { while (!CalamityWorld.roxShrinePlaced) { @@ -316,8 +316,8 @@ namespace CalamityMod.World Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || - Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || - Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType())) + Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType() || + Main.tile[x, y].type == ModContent.TileType() || Main.tile[x, y].type == ModContent.TileType())) { astralTileCount++; if (astralTileCount > astralTilesAllowed) @@ -646,7 +646,7 @@ namespace CalamityMod.World // Gauge the bumpiness of various potential locations. // The least bumpy one will be selected as the place to spawn the monolith. for (int tries = 0; tries < 30; tries++) - { + { int x = i + Main.rand.Next(-60, 61); // Don't attempt to add duplicate keys. @@ -655,7 +655,7 @@ namespace CalamityMod.World float averageRelativeHeight = 0f; for (int dx = -30; dx <= 30; dx++) - { + { WorldUtils.Find(new Point(x + dx, j - 180), Searches.Chain(new Searches.Down(360), new Conditions.IsSolid()), out Point result); averageRelativeHeight += Math.Abs(result.Y - j); } @@ -692,7 +692,8 @@ namespace CalamityMod.World // WorldGen.gen prevents NewItem from working, and thus prevents a bunch of dumb items from being spawned immediately and deleting the WoF/Aureus loot in the process. WorldGen.gen = true; bool _ = true; - SchematicManager.PlaceSchematic>("Astral Beacon", new Point(i, (int)height - 30), PlacementAnchorType.Center, ref _); + int finalVerticalOffset = -8; + SchematicManager.PlaceSchematic>("Astral Beacon", new Point(i, (int)height + finalVerticalOffset), SchematicAnchor.Center, ref _); WorldGen.gen = false; } } @@ -907,10 +908,10 @@ namespace CalamityMod.World case TileID.LeafBlock: case TileID.Sunflower: WorldGen.KillTile(x, y); - if (Main.netMode == NetmodeID.MultiplayerClient) - { - NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, x, y); - } + if (Main.netMode == NetmodeID.MultiplayerClient) + { + NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, x, y); + } break; case TileID.LargePiles: if (tile.frameX <= 1170)