Added Scrap Piles to the sulphurous sea

This commit is contained in:
Dominic authored and Cameron Ewell committed 2021-07-29 16:51:25 -04:00
1 parent 771740a40e
commit 58b7500ab6
11 files changed
+111

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+21
View File
@@ -33,6 +33,16 @@ namespace CalamityMod.Schematics
// Astral world gen structures
["Astral Beacon"] = CalamitySchematicIO.LoadSchematic("Schematics/AstralBeacon.csch"),
// Sulphurous Sea scrap world gen structures
["Sulphurous Scrap 1"] = CalamitySchematicIO.LoadSchematic("Schematics/SmallScrapPile1.csch").ShaveOffEdge(),
["Sulphurous Scrap 2"] = CalamitySchematicIO.LoadSchematic("Schematics/SmallScrapPile2.csch").ShaveOffEdge(),
["Sulphurous Scrap 3"] = CalamitySchematicIO.LoadSchematic("Schematics/SmallScrapPile3.csch").ShaveOffEdge(),
["Sulphurous Scrap 4"] = CalamitySchematicIO.LoadSchematic("Schematics/SmallScrapPile4.csch").ShaveOffEdge(),
["Large Sulphurous Scrap 1"] = CalamitySchematicIO.LoadSchematic("Schematics/LargeScrapPile1.csch").ShaveOffEdge(),
["Large Sulphurous Scrap 2"] = CalamitySchematicIO.LoadSchematic("Schematics/LargeScrapPile2.csch").ShaveOffEdge(),
["Large Sulphurous Scrap 3"] = CalamitySchematicIO.LoadSchematic("Schematics/LargeScrapPile3.csch").ShaveOffEdge(),
["Large Sulphurous Scrap 4"] = CalamitySchematicIO.LoadSchematic("Schematics/LargeScrapPile4.csch").ShaveOffEdge(),
};
}
internal static void Unload()
@@ -41,7 +51,18 @@ namespace CalamityMod.Schematics
PilePlacementMaps = null;
}
#endregion
#region Get Schematic Area
public static Vector2? GetSchematicArea(string name)
{
// If no schematic exists with this name, simply return null.
if (!TileMaps.TryGetValue(name, out SchematicMetaTile[,] schematic))
return null;
return new Vector2(schematic.GetLength(0), schematic.GetLength(1));
}
#endregion Get Schematic Area
#region Place Schematic
public static void PlaceSchematic<T>(string name, Point pos, SchematicAnchor anchorType, ref bool specialCondition, T chestDelegate = null) where T : Delegate
{
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+13
View File
@@ -44,6 +44,19 @@ namespace CalamityMod
return array;
}
public static T[,] ShaveOffEdge<T>(this T[,] array)
{
T[,] result = new T[array.GetLength(0) - 2, array.GetLength(1) - 2];
for (int i = 0; i < result.GetLength(0); i++)
{
for (int j = 0; j < result.GetLength(1); j++)
{
result[i, j] = array[i + 1, j + 1];
}
}
return result;
}
/// <summary>
/// Retrieves all the colors from a <see cref="Texture2D"/> and returns them as a 2D <see cref="Color"/> array.
/// </summary>
+77
View File
@@ -1,11 +1,13 @@
using CalamityMod.Items;
using CalamityMod.Items.Accessories;
using CalamityMod.Items.Weapons.Summon;
using CalamityMod.Schematics;
using CalamityMod.Tiles.Abyss;
using CalamityMod.Walls;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
@@ -91,6 +93,7 @@ namespace CalamityMod.World
PlaceColumns();
PlaceRustyChests();
CreateBeachNearSea();
PlaceScrapPiles();
}
#endregion
@@ -837,6 +840,80 @@ namespace CalamityMod.World
}
#endregion
#region Scrap Piles
public static void PlaceScrapPiles()
{
List<Vector2> pastPlacementPostiion = new List<Vector2>();
for (int i = 0; i < 3; i++)
{
int x = WorldGen.genRand.Next(75, BiomeWidth - 85);
if (!CalamityWorld.abyssSide)
x = Main.maxTilesX - x;
int y = WorldGen.genRand.Next(YStart + (int)(BlockDepth * 0.3f), YStart + (int)(BlockDepth * 0.8f));
Point pilePlacementPosition = new Point(x, y);
// If the selected position is sitting inside of a tile, try again.
if (WorldGen.SolidTile(pilePlacementPosition.X, pilePlacementPosition.Y))
{
i--;
continue;
}
// If the selected position is close to other piles, try again.
if (pastPlacementPostiion.Any(p => Vector2.Distance(p, pilePlacementPosition.ToVector2()) < 85f))
{
i--;
continue;
}
// Otherwise, decide which pile should be created.
bool createLargePile = WorldGen.genRand.NextBool(3);
int pileVariant = WorldGen.genRand.Next(4);
string schematicName = $"{(createLargePile ? "Large " : string.Empty)}Sulphurous Scrap {pileVariant + 1}";
Vector2? wrappedSchematicArea = SchematicManager.GetSchematicArea(schematicName);
// Create a log message if for some reason the schematic in question doesn't exist.
if (!wrappedSchematicArea.HasValue)
{
CalamityMod.Instance.Logger.Warn($"Tried to place a schematic with name \"{schematicName}\". No matching schematic file found.");
continue;
}
Vector2 schematicArea = wrappedSchematicArea.Value;
// Decide the placement position by searching downward and looking for the lowest point.
// If the position is quite steep, try again.
Vector2 left = pilePlacementPosition.ToVector2() - Vector2.UnitX * schematicArea.X * 0.5f;
Vector2 right = pilePlacementPosition.ToVector2() + Vector2.UnitX * schematicArea.X * 0.5f;
while (!WorldGen.SolidTile(CalamityUtils.ParanoidTileRetrieval((int)left.X, (int)left.Y)))
left.Y++;
while (!WorldGen.SolidTile(CalamityUtils.ParanoidTileRetrieval((int)right.X, (int)right.Y)))
right.Y++;
if (Math.Abs(left.Y - right.Y) >= 20f)
{
i--;
continue;
}
// If the placement position ended up in the abyss, try again.
if (left.Y >= YStart + BlockDepth + 5 || right.Y >= YStart + BlockDepth + 5)
{
i--;
continue;
}
// Pick the lowest point vertically.
Point bottomCenter = new Point(pilePlacementPosition.X, (int)Math.Max(left.Y, right.Y) + 6);
bool _ = false;
SchematicManager.PlaceSchematic<Action<Chest>>(schematicName, bottomCenter, SchematicAnchor.BottomCenter, ref _);
pastPlacementPostiion.Add(bottomCenter.ToVector2());
}
}
#endregion Scrap Piles
#region Misc Functions
public static List<int> YStartWhitelist = new List<int>()
{