reverting to previous version
This commit is contained in:
@@ -1,15 +1,22 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public partial class Enemy : StaticBody2D
|
||||
{
|
||||
[Signal]
|
||||
public delegate void DeathEventHandler(Enemy THIS);
|
||||
public int _damage = 1, _health = 2;
|
||||
public Vector2 _speed = Vector2.Up, _range = Vector2.Up;
|
||||
public int _damage = 1, _health = 2, _speed;
|
||||
public Vector2I _range = Vector2I.Up;
|
||||
public float _movement = 0;
|
||||
public GridMarker _gridMarker;
|
||||
public Commander _commander;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
}
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
base._PhysicsProcess(delta);
|
||||
@@ -25,6 +32,76 @@ public partial class Enemy : StaticBody2D
|
||||
|
||||
}
|
||||
|
||||
public List<GridMarker> Pathfinding(List<GridMarker> DESTINATIONS, bool INCLUDE_SELF = false)
|
||||
{
|
||||
PriorityQueue<GridMarker, float> queue = new();
|
||||
queue.Enqueue(_gridMarker, 0f);
|
||||
Dictionary<GridMarker, GridMarker> cameFrom = new(), best = new();
|
||||
Dictionary<GridMarker, float> costSoFar = new();
|
||||
cameFrom[_gridMarker] = null;
|
||||
costSoFar[_gridMarker] = 0f;
|
||||
GridMarker current;
|
||||
float newCost, priority;
|
||||
|
||||
for (int i = 0; i < DESTINATIONS.Count; i++)
|
||||
{
|
||||
GridMarker destination = DESTINATIONS[i];
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
current = queue.Dequeue();
|
||||
if (current == destination)
|
||||
{
|
||||
best = cameFrom;
|
||||
GD.Print("breaking at line 56");
|
||||
continue;
|
||||
}
|
||||
|
||||
List<GridMarker> neighbors = current.GetMarkersInRange(1.5f);
|
||||
for (int j = 0; j < neighbors.Count; j++)
|
||||
{
|
||||
GridMarker next = neighbors[j];
|
||||
if (next._occupant != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
newCost = costSoFar[current] + 1;
|
||||
if (best.Count > 0 && newCost >= best.Count)
|
||||
{
|
||||
GD.Print("breaking at line 70");
|
||||
break;
|
||||
}
|
||||
if (!costSoFar.TryGetValue(next, out float value) || newCost < value)
|
||||
{
|
||||
costSoFar[next] = newCost;
|
||||
priority = newCost;
|
||||
queue.Enqueue(next, priority);
|
||||
cameFrom[next] = current;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GD.Print(best.Last().Value._address);
|
||||
List<GridMarker> path = new();
|
||||
GridMarker pathMarker = best.Last().Value;
|
||||
|
||||
if (best.TryGetValue(pathMarker, out GridMarker marker))
|
||||
{
|
||||
while (pathMarker != null)
|
||||
{
|
||||
path.Add(pathMarker);
|
||||
pathMarker = marker;
|
||||
}
|
||||
path.Reverse();
|
||||
if (!INCLUDE_SELF)
|
||||
{
|
||||
path.Remove(_gridMarker);
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public void TakeDamage(int DAMAGE, Commander ATTACKER)
|
||||
{
|
||||
GD.Print(_health, _health - DAMAGE);
|
||||
|
||||
Reference in New Issue
Block a user