/// <summary>
        /// Gets a stack of nodes representing the path from the source to the destination.
        /// </summary>
        public Stack <Node> GetPath(Entity source, Entity destination, out double totalCost)
        {
            Graph graph;

            if (source.FactionOwner != Guid.Empty)
            {
                Entity faction;
                source.Manager.FindEntityByGuid(source.FactionOwner, out faction);
                graph = GetPathfindingGraph(faction);
            }
            else
            {
                graph = GetPathfindingGraph();
            }

            var sourceNode = new JPNode(source, source, new List <EdgeToNeighbor>());

            graph.AddNode(sourceNode);

            var destinationNode = new JPNode(destination, destination, new List <EdgeToNeighbor>());

            graph.AddNode(destinationNode);

            return(GetPath(sourceNode, destinationNode, graph, out totalCost));
        }
        /// <summary>
        /// Gets a pathfinding graph for the entire universe.
        /// </summary>
        public Graph GetPathfindingGraph()
        {
            var pathfindingGraph = new Graph();

            foreach (StarSystem starSystem in _game.Systems.Values)
            {
                List <Entity> jumpPoints = starSystem.GetAllEntitiesWithDataBlob <TransitableDB>();

                foreach (Entity jumpPoint in jumpPoints)
                {
                    var    thisTransitableDB = jumpPoint.GetDataBlob <TransitableDB>();
                    Entity destinationJP     = thisTransitableDB.Destination;

                    var node = new JPNode(jumpPoint, destinationJP, new List <EdgeToNeighbor>());
                    pathfindingGraph.AddNode(node);
                }
            }

            return(pathfindingGraph);
        }
        /// <summary>
        /// Gets a pathfinding graph for objects/systems known by the provided faction.
        /// </summary>
        public Graph GetPathfindingGraph(Entity faction)
        {
            var factionDB        = faction.GetDataBlob <FactionInfoDB>();
            var pathfindingGraph = new Graph();

            foreach (Guid starSystemGuid in factionDB.KnownSystems)
            {
                List <Entity> jumpPoints = factionDB.KnownJumpPoints[starSystemGuid];

                foreach (Entity jumpPoint in jumpPoints)
                {
                    var    thisTransitableDB = jumpPoint.GetDataBlob <TransitableDB>();
                    Entity destinationJP     = thisTransitableDB.Destination;

                    var node = new JPNode(jumpPoint, destinationJP, new List <EdgeToNeighbor>());
                    pathfindingGraph.AddNode(node);
                }
            }

            return(pathfindingGraph);
        }
Exemple #4
0
        /// <summary>
        /// Gets a stack of nodes representing the path from the source to the destination.
        /// </summary>
        public Stack <Node> GetPath(Entity source, Entity destination, out double totalCost)
        {
            Graph graph;

            if (source.HasDataBlob <OwnedDB>())
            {
                graph = GetPathfindingGraph(source.GetDataBlob <OwnedDB>().OwnedByFaction);
            }
            else
            {
                graph = GetPathfindingGraph();
            }

            var sourceNode = new JPNode(source, source, new List <EdgeToNeighbor>());

            graph.AddNode(sourceNode);

            var destinationNode = new JPNode(destination, destination, new List <EdgeToNeighbor>());

            graph.AddNode(destinationNode);

            return(GetPath(sourceNode, destinationNode, graph, out totalCost));
        }