using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PathNode : IComparable
{
readonly GridPosition gridPosition;
private int gCost;
private int hCost;
private int fCost;
private PathNode cameFromPathNode;
private bool isWalkable = true;
public PathNode(GridPosition gridPosition) {
this.gridPosition = gridPosition;
}
public int CompareTo(object incomingobject)
{
PathNode node = incomingobject as PathNode;
if (gridPosition.x > node.gridPosition.x) {
return 1;
}
if (gridPosition.x < node.gridPosition.x) {
return -1;
}
if (gridPosition.z > node.gridPosition.z) {
return 1;
}
if (gridPosition.z < node.gridPosition.z) {
return -1;
}
return 0;
}
public override string ToString() {
return gridPosition.ToString();
}
public int GetGCost() => gCost;
public int GetHCost() => hCost;
public int GetFCost() => fCost;
public void SetGCost(int gCost)
{
this.gCost = gCost;
}
public void SetHCost(int hCost)
{
this.hCost = hCost;
}
public void CalculateFCost()
{
fCost = gCost + hCost;
}
public void ResetCameFromPathNode()
{
cameFromPathNode = null;
}
public void SetCameFromPathNode(PathNode pathNode)
{
cameFromPathNode = pathNode;
}
public PathNode GetCameFromPathNode()
{
return cameFromPathNode;
}
public IEnumerable<PathNode> GetNextCameFromPathNode()
{
PathNode currentNode = this;
while (currentNode != null) {
yield return currentNode;
currentNode = currentNode.cameFromPathNode;
}
}
public GridPosition GetGridPosition()
{
return gridPosition;
}
public bool IsWalkable() => isWalkable;
public void SetIsWalkable(bool isWalkable) {
this.isWalkable = isWalkable;
}
}