55 lines
1.9 KiB
C#
55 lines
1.9 KiB
C#
// Decompiled with JetBrains decompiler
|
|
// Type: Terraria.GameContent.Generation.ShapeFloodFill
|
|
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
|
|
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
|
|
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
|
|
|
|
using Microsoft.Xna.Framework;
|
|
using System.Collections.Generic;
|
|
using Terraria.DataStructures;
|
|
using Terraria.WorldBuilding;
|
|
|
|
namespace Terraria.GameContent.Generation
|
|
{
|
|
public class ShapeFloodFill : GenShape
|
|
{
|
|
private int _maximumActions;
|
|
|
|
public ShapeFloodFill(int maximumActions = 100) => this._maximumActions = maximumActions;
|
|
|
|
public override bool Perform(Point origin, GenAction action)
|
|
{
|
|
Queue<Point> pointQueue = new Queue<Point>();
|
|
HashSet<Point16> point16Set = new HashSet<Point16>();
|
|
pointQueue.Enqueue(origin);
|
|
int maximumActions = this._maximumActions;
|
|
while (pointQueue.Count > 0 && maximumActions > 0)
|
|
{
|
|
Point point = pointQueue.Dequeue();
|
|
if (!point16Set.Contains(new Point16(point.X, point.Y)) && this.UnitApply(action, origin, point.X, point.Y))
|
|
{
|
|
point16Set.Add(new Point16(point));
|
|
--maximumActions;
|
|
if (point.X + 1 < Main.maxTilesX - 1)
|
|
pointQueue.Enqueue(new Point(point.X + 1, point.Y));
|
|
if (point.X - 1 >= 1)
|
|
pointQueue.Enqueue(new Point(point.X - 1, point.Y));
|
|
if (point.Y + 1 < Main.maxTilesY - 1)
|
|
pointQueue.Enqueue(new Point(point.X, point.Y + 1));
|
|
if (point.Y - 1 >= 1)
|
|
pointQueue.Enqueue(new Point(point.X, point.Y - 1));
|
|
}
|
|
}
|
|
while (pointQueue.Count > 0)
|
|
{
|
|
Point point = pointQueue.Dequeue();
|
|
if (!point16Set.Contains(new Point16(point.X, point.Y)))
|
|
{
|
|
pointQueue.Enqueue(point);
|
|
break;
|
|
}
|
|
}
|
|
return pointQueue.Count == 0;
|
|
}
|
|
}
|
|
}
|