undergoing a shift to change movement into another action that a peg can perform and giving pegs a list of actions order by priority

This commit is contained in:
2026-06-29 02:43:25 -04:00
parent f6c54e0730
commit ebdff1b200
16 changed files with 148 additions and 110 deletions
+16 -52
View File
@@ -10,7 +10,7 @@ using System.Xml;
public partial class PegController : TurnController
{
public int _actionLoop = 0, _pegsCreated = 0, _pegsDestroyed = 0;
public int _pegsCreated = 0, _pegsDestroyed = 0;
public List<PackedScene> _hostilePegScenes;
public List<Peg> _pegs = new();
public PlayerController _playerController;
@@ -64,49 +64,30 @@ public partial class PegController : TurnController
}
}
public List<Peg> GetRemainingPegs()
{
return [.. _pegs.Where(e => e.CanMove() || e.CanAct())];
}
public void HandlePegTurn()
{
_actionLoop = 0;
_tweenStages.Clear();
Map map = _playArea._map;
_pegs.ForEach(e => e._path.Clear());
List<Peg> remainingPegs = GetRemainingPegs();
while (remainingPegs.Count > 0)
int loop = 0;
bool noPegsActed = false;
while (!noPegsActed)
{
for (int i = 0; i < remainingPegs.Count; i++)
noPegsActed = true;
for (int i = 0; i < _pegs.Count; i++)
{
Peg peg = remainingPegs[i];
HandlePegPathing(peg);
HandlePegAction(peg);
}
remainingPegs = GetRemainingPegs();
_actionLoop++;
if (_actionLoop == 10)
{
Peg peg_ = remainingPegs[0];
GD.Print("LOOPMAXEDOUT");
Peg peg = _pegs[i];
bool pegActed = peg.Act(loop);
if (pegActed)
{
noPegsActed = false;
}
}
loop++;
}
}
public void HandlePegAction(Peg PEG)
{
if (PEG.CanAct())
{
PEG.Act();
}
}
public void HandlePegClick(Node CLICKED_NODE, int CLICK_TYPE)
{
if (CLICKED_NODE is not Peg peg)
@@ -133,23 +114,6 @@ public partial class PegController : TurnController
}
}
public void HandlePegPathing(Peg PEG)
{
if (!PEG.CanMove())
{
return;
}
List<Vector2I> path = PEG.GetBestPath();
if (path?.Count == 0)
{
GD.Print(PEG._address, " PATH0");
return;
}
PEG.Move(path[0]);
}
public void HandlePegRemoval(Peg PEG_TO_REMOVE)
{
_pegs.Remove(PEG_TO_REMOVE);
@@ -160,7 +124,7 @@ public partial class PegController : TurnController
public void HandlePegSort()
{
_pegs = [.. _pegs.OrderBy(e => e._address.Y).ThenBy(e => e._path.Count).ThenBy(e => Math.Abs(e._address.X - _playArea._map._maxX / 2))];
_pegs = [.. _pegs.OrderBy(p => p._address.Y).ThenBy(p => p._distanceToGoal).ThenBy(p => Math.Abs(p._address.X - _playArea._map._maxX / 2))];
}
@@ -174,7 +138,7 @@ public partial class PegController : TurnController
public void ProcessTween()
{
_tweenStages = _tweenStages.OrderBy(s => s.Key).ToDictionary();
GD.Print(string.Join(", ", _tweenStages.Keys));
// GD.Print(string.Join(", ", _tweenStages.Keys));
if (_tweenStages.Count <= 0)
{
EndTurn();