Implemented A* pathfinding. Adjusted movement node accordingly.
This commit is contained in:
@@ -18,7 +18,17 @@ public class WFC
|
||||
Down
|
||||
}
|
||||
|
||||
public static readonly Vector2I[] offsets =
|
||||
public static readonly Direction[] dirs =
|
||||
{
|
||||
Direction.Backward,
|
||||
Direction.Forward,
|
||||
Direction.Left,
|
||||
Direction.Right,
|
||||
Direction.Up,
|
||||
Direction.Down
|
||||
};
|
||||
|
||||
public static readonly Vector2I[] offsets2D =
|
||||
{
|
||||
new Vector2I(0, -1),
|
||||
new Vector2I(0, 1),
|
||||
@@ -26,12 +36,14 @@ public class WFC
|
||||
new Vector2I(1, 0)
|
||||
};
|
||||
|
||||
public static readonly Direction[] dirs =
|
||||
public static readonly Vector3I[] offsets3D =
|
||||
{
|
||||
Direction.Backward,
|
||||
Direction.Forward,
|
||||
Direction.Left,
|
||||
Direction.Right
|
||||
new Vector3I(0, 0, -1),
|
||||
new Vector3I(0, 0, 1),
|
||||
new Vector3I(-1, 0, 0),
|
||||
new Vector3I(1, 0, 0),
|
||||
new Vector3I(0, -1, 0),
|
||||
new Vector3I(0, 1, 0)
|
||||
};
|
||||
|
||||
public static Dictionary<string, HashSet<Direction>> tileConnections = new Dictionary<string, HashSet<Direction>>
|
||||
@@ -148,6 +160,51 @@ public class WFC
|
||||
return CanConnect(fromTile.collapsedMesh, toTile.collapsedMesh, dir, true);
|
||||
}
|
||||
|
||||
public static bool CanWalk3D(Vector3I from, Vector3I to)
|
||||
{
|
||||
Tile fromTile = GameData.map[from.Y].tiles[from.X, from.Z];
|
||||
Tile toTile = GameData.map[to.Y].tiles[to.X, to.Z];
|
||||
|
||||
if (fromTile == null || toTile == null)
|
||||
return false;
|
||||
|
||||
if (from.Y != to.Y)
|
||||
{
|
||||
if (Math.Abs(from.Y - to.Y) != 1)
|
||||
return false;
|
||||
|
||||
if (from.Y > to.Y)
|
||||
{
|
||||
return toTile.collapsedMesh == "gate";
|
||||
}
|
||||
else
|
||||
{
|
||||
return fromTile.collapsedMesh == "gate";
|
||||
}
|
||||
}
|
||||
|
||||
int dx = to.X - from.X;
|
||||
int dz = to.Z - from.Z;
|
||||
|
||||
if (Math.Abs(dx) + Math.Abs(dz) != 1)
|
||||
return false;
|
||||
|
||||
Direction dir;
|
||||
|
||||
if (dx == 1) dir = Direction.Right;
|
||||
else if (dx == -1) dir = Direction.Left;
|
||||
else if (dz == 1) dir = Direction.Forward;
|
||||
else if (dz == -1) dir = Direction.Backward;
|
||||
else return false;
|
||||
|
||||
return CanWalk(
|
||||
GameData.map[from.Y].tiles,
|
||||
new Vector2I(from.X, from.Z),
|
||||
new Vector2I(to.X, to.Z),
|
||||
dir
|
||||
);
|
||||
}
|
||||
|
||||
public static bool IsMapConnected(Tile[,] layer, float accessibilityThreshhold)
|
||||
{
|
||||
bool result = false;
|
||||
@@ -165,9 +222,9 @@ public class WFC
|
||||
toCheck[index] = toCheck[^1];
|
||||
toCheck.RemoveAt(toCheck.Count - 1);
|
||||
if (!visited.Add(position)) continue;
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int i = 0; i < offsets2D.Length; i++)
|
||||
{
|
||||
var next = position + offsets[i];
|
||||
var next = position + offsets2D[i];
|
||||
|
||||
if (!InBounds(next, layer.GetLength(0)))
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user