fixed placement anchors & floating astral beacon

This commit is contained in:
Ozzatron committed 2020-10-24 13:46:29 -04:00
1 parent 913427050f
commit eaa26ef0e6
5 files changed
+67 -43

No files matched your search

+15 -6
View File
@@ -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,
}
}
+31 -18
View File
@@ -43,7 +43,7 @@ namespace CalamityMod.Schematics
#endregion
#region Place Schematic
public static void PlaceSchematic<T>(string name, Point pos, PlacementAnchorType anchorType, ref bool specialCondition, T chestDelegate = null) where T : Delegate
public static void PlaceSchematic<T>(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.
+6 -6
View File
@@ -105,7 +105,7 @@ namespace CalamityMod.World
else
{
bool _ = true;
PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), PlacementAnchorType.TopLeft, ref _, new Action<Chest>(FillWorkshopChest));
PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action<Chest>(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<Chest>(FillLaboratoryChest));
PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref _, new Action<Chest>(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<Chest, int, bool>(FillHellLaboratoryChest));
PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref hasPlacedMurasama, new Action<Chest, int, bool>(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<Chest, int, bool>(FillSunkenSeaLaboratoryChest));
PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref hasPlacedLogAndSchematic, new Action<Chest, int, bool>(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<Chest, int, bool>(FillIceLaboratoryChest));
PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref hasPlacedLogAndSchematic, new Action<Chest, int, bool>(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<Chest, int, bool>(FillPlagueLaboratoryChest));
PlaceSchematic(mapKey, new Point(placementPoint.X, placementPoint.Y), SchematicAnchor.TopLeft, ref hasPlacedLogAndSchematic, new Action<Chest, int, bool>(FillPlagueLaboratoryChest));
break;
}
}
+2 -1
View File
@@ -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<Chest, int, bool>(DraedonStructures.FillPlanetoidLaboratoryChest));
SchematicManager.PlaceSchematic("Planetoid Laboratory", new Point(origin.X - 33, origin.Y - 17), SchematicAnchor.TopLeft, ref hasPlacedLogAndSchematic, new Action<Chest, int, bool>(DraedonStructures.FillPlanetoidLaboratoryChest));
//PLACE BREAKABLE GRASS AND TREES
WorldUtils.Gen(origin, new ModShapes.OuterOutline(mainShape, true, true), Actions.Chain(new GenAction[]
+13 -12
View File
@@ -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<HardenedAstralSand>() || Main.tile[x, y].type == ModContent.TileType<AstralIce>() ||
Main.tile[x, y].type == ModContent.TileType<AstralDirt>() || Main.tile[x, y].type == ModContent.TileType<AstralStone>() ||
Main.tile[x, y].type == ModContent.TileType<AstralGrass>() || Main.tile[x, y].type == ModContent.TileType<AstralSilt>() ||
Main.tile[x, y].type == ModContent.TileType<AstralFossil>() || Main.tile[x, y].type == ModContent.TileType<AstralSnow>() ||
Main.tile[x, y].type == ModContent.TileType<AstralClay>() || Main.tile[x, y].type == ModContent.TileType<AstralStone>()))
Main.tile[x, y].type == ModContent.TileType<AstralFossil>() || Main.tile[x, y].type == ModContent.TileType<AstralSnow>() ||
Main.tile[x, y].type == ModContent.TileType<AstralClay>() || Main.tile[x, y].type == ModContent.TileType<AstralStone>()))
{
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<Action<Chest>>("Astral Beacon", new Point(i, (int)height - 30), PlacementAnchorType.Center, ref _);
int finalVerticalOffset = -8;
SchematicManager.PlaceSchematic<Action<Chest>>("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)