Beyond_Beyaan.Galaxy.GetPath C# (CSharp) Метод

GetPath() публичный Метод

Pathfinding function
public GetPath ( float currentX, float currentY, StarSystem currentDestination, StarSystem newDestination, bool hasExtended, Empire whichEmpire ) : List
currentX float Fleet's Galaxy X
currentY float Fleet's Galaxy Y
currentDestination StarSystem Fleet's current destination for when empire don't have hyperspace communications
newDestination StarSystem New destination
hasExtended bool
whichEmpire Empire For fuel range and other info
Результат List
        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;
        }

Usage Example

Пример #1
0
        public void SetTentativePath(StarSystem destination, bool hasExtendedFuelTanks, Galaxy galaxy)
        {
            if (destination == null || destination == _adjacentSystem)
            {
                //if destination is same as origin, or nowhere, clear the tentative path
                TentativeNodes = null;
                return;
            }
            if (_travelNodes != null && _travelNodes[_travelNodes.Count - 1].StarSystem == destination)
            {
                //Same path as current path
                TentativeNodes = null;
                return;
            }
            if (TentativeNodes != null && TentativeNodes[_tentativeNodes.Count - 1].StarSystem == destination)
            {
                // Existing tentative path
                return;
            }

            StarSystem currentDestination = null;

            if (_adjacentSystem == null)             //Has left a system
            {
                currentDestination = _travelNodes[0].StarSystem;
            }
            List <TravelNode> path = galaxy.GetPath(_galaxyX, _galaxyY, currentDestination, destination, hasExtendedFuelTanks, _empire);

            if (path == null)
            {
                TentativeNodes = null;
                return;
            }

            TentativeNodes = path;
            if (TentativeNodes.Count == 0)
            {
                TentativeNodes = null;
            }
        }
All Usage Examples Of Beyond_Beyaan.Galaxy::GetPath