minor changes, next step is to add 2-3 friendly pegs, 2 neutral pegs, 2 hostile pegs, 2 buildings and all associated actions for these additions
This commit is contained in:
@@ -44,22 +44,21 @@ public partial class Peg : HoverableNode
|
||||
|
||||
}
|
||||
|
||||
public virtual List<Vector2I> GetBestPath()
|
||||
public virtual List<Vector2I> GetBestPath(bool PARTIAL = false)
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
List<Vector2I> goals = GetGoals();
|
||||
List<List<Vector2I>> paths = new();
|
||||
|
||||
for (int i = 0; i < goals.Count; i++)
|
||||
{
|
||||
paths.Add(map.GetPath(_address, goals[i]));
|
||||
List<Vector2I> path = map.GetPath(_address, goals[i], false, PARTIAL);
|
||||
if (path.Count > 0)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
List<List<Vector2I>> pathsOverZeroCount = [.. paths.Where(p => p.Count > 0)];
|
||||
if (pathsOverZeroCount.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
return pathsOverZeroCount.OrderBy(p => p.Count).ToList()[0];
|
||||
return [];
|
||||
}
|
||||
|
||||
public virtual List<Vector2I> GetVisibleCells()
|
||||
@@ -71,18 +70,9 @@ public partial class Peg : HoverableNode
|
||||
public virtual List<Vector2I> GetGoals()
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
TileMapLayer pathLayer = _pegController._playArea.GetNode<TileMapLayer>("PathLayer");
|
||||
List<Vector2I> pl = [.. pathLayer.GetUsedCells()];
|
||||
List<Vector2I> visible = GetVisibleCells();
|
||||
if (_id == 4)
|
||||
for (int i = 0; i < pl.Count; i++)
|
||||
{
|
||||
Vector2I cell = pl[i];
|
||||
pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(cell,0,Vector2I.Down + Vector2I.Right*(visible.IndexOf(cell) > -1 ? 1 : 4)));
|
||||
|
||||
}
|
||||
List<Vector2I> unoccupied = [.. visible.Where(c => !map._astar.IsPointSolid(c))];
|
||||
List<Vector2I> closest = [.. unoccupied.Where(c => c.Y == (_disposition == -1 ? unoccupied.Min(c => c.Y) : unoccupied.Max(c => c.Y))).OrderByDescending(c => Math.Abs(c.X - _address.X))];
|
||||
List<Vector2I> closest = [.. unoccupied.OrderByDescending(c => c.Y * _disposition).ThenByDescending(c => Math.Abs(c.X - _address.X))];
|
||||
return closest;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user