continuing to set up map and pegs

This commit is contained in:
2026-07-02 22:50:21 -04:00
parent 0231c9d136
commit e6355167e3
13 changed files with 93 additions and 50 deletions
+17 -13
View File
@@ -3,14 +3,14 @@ using System;
using System.Collections.Generic;
using System.Linq;
public partial class Peg : HoverableNode
public partial class Peg : MapCellOccupant
{
[Signal]
public delegate void DeathEventHandler(Peg THIS);
public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _movement = 0, _disposition, _visibility;
public Vector2I _address;
public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _movement = 0, _visibility;
public List<Vector2I> _path = new();
public PegController _pegController;
public Map _map;
public List<PegAction> _actions;
public int _distanceToGoal
{
@@ -24,6 +24,7 @@ public partial class Peg : HoverableNode
{
base._Ready();
_actions = [.. GetNode<Node2D>("Actions").GetChildren().Cast<PegAction>()];
_map = _pegController._playArea._map;
}
public virtual PegAction SelectAction()
{
@@ -61,21 +62,24 @@ public partial class Peg : HoverableNode
return _pegController._playArea._map.GetPath(_address, Goal(), false, PARTIAL);
}
public virtual List<Peg> GetEnemies()
{
return [.. _pegController._pegs.Where(p => p._disposition == -_disposition).OrderBy(p => (p._address - _address).Length())];
}
public virtual List<Vector2I> GetVisibleCells()
public virtual Dictionary<Vector2I, MapCell> GetEnemies()
{
Map map = _pegController._playArea._map;
return [.. map._cells.Where(c => (c - _address).Length() <= _visibility)];
return map._cells.Where(c => (int)c.Value._occupant._disposition == -(int)_disposition).ToDictionary();
}
public virtual List<Peg> GetVisibleEnemies()
public virtual Dictionary<Vector2I, MapCell> GetVisibleCells()
{
List<Vector2I> visible = GetVisibleCells();
return [.. GetEnemies().Where(e => visible.Contains(e._address))];
Map map = _pegController._playArea._map;
return map._cells.Where(c => (c.Value._address - _address).Length() <= _visibility).ToDictionary();
}
public virtual Dictionary<Vector2I, MapCell> GetVisibleEnemies()
{
Dictionary<Vector2I, MapCell> visible = GetVisibleCells();
Dictionary<Vector2I, MapCell> enemies = GetEnemies();
return enemies.Keys.Intersect(visible.Keys).ToDictionary(e => e, e => enemies[e]);
}
public Vector2 GetPositionFromAddress()