implemented visibility, so pegs can only scope out as far as they can see.

This commit is contained in:
2026-06-30 18:24:11 -04:00
parent c8e81e4f48
commit b1625b15a0
8 changed files with 53 additions and 32 deletions
+20 -8
View File
@@ -7,7 +7,7 @@ public partial class Peg : HoverableNode
{
[Signal]
public delegate void DeathEventHandler(Peg THIS);
public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _visibility = 4, _movement = 0, _disposition;
public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _movement = 0, _disposition, _visibility;
public Vector2I _address;
public List<Vector2I> _path = new();
public PegController _pegController;
@@ -36,12 +36,6 @@ public partial class Peg : HoverableNode
break;
}
}
if (action == null)
{
return null;
}
_staminaRemaining -= action._cost;
return action;
}
@@ -68,10 +62,28 @@ public partial class Peg : HoverableNode
return pathsOverZeroCount.OrderBy(p => p.Count).ToList()[0];
}
public virtual List<Vector2I> GetVisibleCells()
{
Map map = _pegController._playArea._map;
return [.. map._cells.Where(c => (c - _address).Length() <= _visibility)];
}
public virtual List<Vector2I> GetGoals()
{
Map map = _pegController._playArea._map;
return [.. map._cells.Where(c => c.Y == (_disposition == 1 ? map._lastOpenRow : map._firstOpenRow)).Where(c => !map._astar.IsPointSolid(c))];
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))];
return closest;
}
public Vector2 GetPositionFromAddress()