/// <summary> /// Pathfinding function /// </summary> /// <param name="currentX">Fleet's Galaxy X</param> /// <param name="currentY">Fleet's Galaxy Y</param> /// <param name="currentDestination">Fleet's current destination for when empire don't have hyperspace communications</param> /// <param name="newDestination">New destination</param> /// <param name="hasExtended"></param> /// <param name="whichEmpire">For fuel range and other info</param> /// <returns></returns> public List <TravelNode> GetPath(float currentX, float currentY, StarSystem currentDestination, StarSystem newDestination, bool hasExtended, Empire whichEmpire) { // TODO: When Hyperspace communication is implemented, add this /* * if (whichEmpire.HasHyperspaceCommunications()) * { * * } * else * { * } */ // TODO: When adding stargates and wormholes, add actual pathfinding List <TravelNode> nodes = new List <TravelNode>(); if (currentDestination != null) { TravelNode newNode = GenerateTravelNode(currentX, currentY, currentDestination); newNode.IsValid = true; nodes.Add(newNode); newNode = GenerateTravelNode(currentDestination, newDestination); newNode.IsValid = IsDestinationValid(newDestination, hasExtended, whichEmpire); nodes.Add(newNode); } else { TravelNode newNode = GenerateTravelNode(currentX, currentY, newDestination); newNode.IsValid = IsDestinationValid(newDestination, hasExtended, whichEmpire); nodes.Add(newNode); } return(nodes); }
public bool ConfirmPath() { if (_tentativeNodes != null) { foreach (var node in _tentativeNodes) { if (!node.IsValid) { return(false); } } TravelNode[] nodes = new TravelNode[_tentativeNodes.Count]; _tentativeNodes.CopyTo(nodes); _tentativeNodes = null; _travelNodes = new List <TravelNode>(nodes); } else { //Null because target is either invalid or the system the fleet is currently adjacent _travelNodes = null; _tentativeNodes = null; } return(true); }
public TravelNode GenerateTravelNode(float xPos, float yPos, StarSystem destination) { TravelNode newNode = new TravelNode(); newNode.StarSystem = destination; float x = destination.X - xPos; float y = destination.Y - yPos; newNode.Length = (float)Math.Sqrt((x * x) + (y * y)); newNode.Angle = (float)(Math.Atan2(y, x) * (180 / Math.PI)); return newNode; }
public TravelNode GenerateTravelNode(float xPos, float yPos, StarSystem destination) { TravelNode newNode = new TravelNode(); newNode.StarSystem = destination; float x = destination.X - xPos; float y = destination.Y - yPos; newNode.Length = (float)Math.Sqrt((x * x) + (y * y)); newNode.Angle = (float)(Math.Atan2(y, x) * (180 / Math.PI)); return(newNode); }
public bool ConfirmPath() { if (_tentativeNodes != null) { foreach (var node in _tentativeNodes) { if (!node.IsValid) { return false; } } TravelNode[] nodes = new TravelNode[_tentativeNodes.Count]; _tentativeNodes.CopyTo(nodes); _tentativeNodes = null; _travelNodes = new List<TravelNode>(nodes); } else { //Null because target is either invalid or the system the fleet is currently adjacent _travelNodes = null; _tentativeNodes = null; } return true; }