still working out movement

This commit is contained in:
2026-07-04 03:04:56 -04:00
parent 336b72e4cb
commit dbafefd660
16 changed files with 136 additions and 71 deletions
+10 -23
View File
@@ -1,6 +1,7 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
public partial class Peg : MapCellOccupant
@@ -8,7 +9,7 @@ public partial class Peg : MapCellOccupant
[Signal]
public delegate void DeathEventHandler(Peg THIS);
public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _movement = 0, _visibility;
public List<Vector2I> _path = new();
public List<MapCell> _path = new();
public PegController _pegController;
public Map _map;
public List<PegAction> _actions;
@@ -45,28 +46,15 @@ public partial class Peg : MapCellOccupant
}
public virtual List<Vector2I> GetBestPath(bool PARTIAL = false)
public virtual List<MapCell> GetBestPath(bool PARTIAL = false)
{
// Map map = _pegController._playArea._map;
// List<Vector2I> goals = Target();
// for (int i = 0; i < goals.Count; i++)
// {
// List<Vector2I> path = map.GetPath(_address, goals[i], false, PARTIAL);
// if (path.Count > 0)
// {
// return path;
// }
// }
MapCell goal = Goal();
return _pegController._playArea._map.GetPath(_address, goal._address, false, PARTIAL);
return [.. _map.GetPath(_address, goal._address, false, PARTIAL).Select(a => _map._cells[a])];
}
public virtual Dictionary<Vector2I, MapCell> GetEnemies()
{
Map map = _pegController._playArea._map;
return map._cells.Where(c => (int)c.Value._occupant._disposition == -(int)_disposition).ToDictionary();
return _map._cells.Where(c => (int)(c.Value._occupant?._disposition ?? Disposition.NONE) == -(int)_disposition).ToDictionary();
}
public virtual Dictionary<Vector2I, MapCell> GetVisibleCells()
@@ -83,17 +71,16 @@ public partial class Peg : MapCellOccupant
return enemies.Keys.Intersect(visible.Keys).ToDictionary(e => e, e => enemies[e]);
}
public Vector2 GetPositionFromAddress()
{
return _pegController._playArea._map.GetCellPositionFromAddress(_address);
}
public virtual MapCell Goal()
{
Map map = _pegController._playArea._map;
Dictionary<Vector2I, MapCell> visible = GetVisibleCells();
Dictionary<Vector2I, MapCell> unoccupied = visible.Where(c => !map._astar.IsPointSolid(c.Key)).ToDictionary();
Dictionary<Vector2I, MapCell> closest = unoccupied.OrderByDescending(c => c.Value._address.Y * (int)_disposition).ThenByDescending(c => Math.Abs(c.Value._address.X - _address.X)).ToDictionary();
Dictionary<Vector2I, MapCell> enemyTerritory = map._cells.Where(c => _map.GetCellDisposition(c.Value._address) == -(int)_disposition).ToDictionary();
Dictionary<Vector2I, MapCell> closest = enemyTerritory.OrderByDescending(c => c.Value._address.Y).ThenByDescending(c => Math.Abs(c.Value._address.X - _address.X)).ToDictionary();
// Dictionary<Vector2I, MapCell> closest = unoccupied.OrderByDescending(c => c.Value._address.Y * -(int)_disposition).ThenByDescending(c => Math.Abs(c.Value._address.X - _address.X)).ToDictionary();
// Dictionary<Vector2I, MapCell> closest = furthest.Where(c => _map.GetCellDisposition(c.Value._address) == -(int)_disposition).ToDictionary();
return closest.ElementAt(0).Value;
}