示例#1
0
        // Searches from both ends toward each other. This is used to prevent blockings in case we find
        // units in the middle of the path that prevent us to continue.
        public List<CPos> FindBidiPath(IPathSearch fromSrc, IPathSearch fromDest)
        {
            List<CPos> path = null;

            while (fromSrc.CanExpand && fromDest.CanExpand)
            {
                // make some progress on the first search
                var p = fromSrc.Expand();

                if (fromDest.Graph[p].Status == CellStatus.Closed &&
                    fromDest.Graph[p].CostSoFar < int.MaxValue)
                {
                    path = MakeBidiPath(fromSrc, fromDest, p);
                    break;
                }

                // make some progress on the second search
                var q = fromDest.Expand();

                if (fromSrc.Graph[q].Status == CellStatus.Closed &&
                    fromSrc.Graph[q].CostSoFar < int.MaxValue)
                {
                    path = MakeBidiPath(fromSrc, fromDest, q);
                    break;
                }
            }

            fromSrc.Graph.Dispose();
            fromDest.Graph.Dispose();

            if (path != null)
                return path;

            return EmptyPath;
        }
示例#2
0
        // Searches from both ends toward each other. This is used to prevent blockings in case we find
        // units in the middle of the path that prevent us to continue.
        public List<CPos> FindBidiPath(IPathSearch fromSrc, IPathSearch fromDest)
        {
            List<CPos> path = null;

            while (fromSrc.CanExpand && fromDest.CanExpand)
            {
                // make some progress on the first search
                var p = fromSrc.Expand();
                if (fromDest.Graph[p].Status == CellStatus.Closed &&
                    fromDest.Graph[p].CostSoFar < int.MaxValue)
                {
                    path = MakeBidiPath(fromSrc, fromDest, p);
                    break;
                }

                // make some progress on the second search
                var q = fromDest.Expand();
                if (fromSrc.Graph[q].Status == CellStatus.Closed &&
                    fromSrc.Graph[q].CostSoFar < int.MaxValue)
                {
                    path = MakeBidiPath(fromSrc, fromDest, q);
                    break;
                }
            }

            fromSrc.Graph.Dispose();
            fromDest.Graph.Dispose();

            if (path != null)
                return path;

            return EmptyPath;
        }
示例#3
0
        // Searches from both ends toward each other. This is used to prevent blockings in case we find
        // units in the middle of the path that prevent us to continue.
        public List <CPos> FindBidiPath(IPathSearch fromSrc, IPathSearch fromDest)
        {
            List <CPos> path = null;

            var dbg = world.WorldActor.TraitOrDefault <PathfinderDebugOverlay>();

            if (dbg != null && dbg.Visible)
            {
                fromSrc.Debug  = true;
                fromDest.Debug = true;
            }

            while (fromSrc.CanExpand && fromDest.CanExpand)
            {
                // make some progress on the first search
                var p = fromSrc.Expand();

                if (fromDest.Graph[p].Status == CellStatus.Closed &&
                    fromDest.Graph[p].CostSoFar < int.MaxValue)
                {
                    path = MakeBidiPath(fromSrc, fromDest, p);
                    break;
                }

                // make some progress on the second search
                var q = fromDest.Expand();

                if (fromSrc.Graph[q].Status == CellStatus.Closed &&
                    fromSrc.Graph[q].CostSoFar < int.MaxValue)
                {
                    path = MakeBidiPath(fromSrc, fromDest, q);
                    break;
                }
            }

            if (dbg != null && dbg.Visible)
            {
                dbg.AddLayer(fromSrc.Considered, fromSrc.MaxCost, fromSrc.Owner);
                dbg.AddLayer(fromDest.Considered, fromDest.MaxCost, fromDest.Owner);
            }

            fromSrc.Graph.Dispose();
            fromDest.Graph.Dispose();

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

            return(EmptyPath);
        }
示例#4
0
        public List<CPos> FindPath(IPathSearch search)
        {
            List<CPos> path = null;

            while (search.CanExpand)
            {
                var p = search.Expand();
                if (search.IsTarget(p))
                {
                    path = MakePath(search.Graph, p);
                    break;
                }
            }

            search.Graph.Dispose();

            if (path != null)
                return path;

            // no path exists
            return EmptyPath;
        }
示例#5
0
        public List <CPos> FindPath(IPathSearch search)
        {
            var dbg = world.WorldActor.TraitOrDefault <PathfinderDebugOverlay>();

            if (dbg != null && dbg.Visible)
            {
                search.Debug = true;
            }

            List <CPos> path = null;

            while (search.CanExpand)
            {
                var p = search.Expand();
                if (search.IsTarget(p))
                {
                    path = MakePath(search.Graph, p);
                    break;
                }
            }

            if (dbg != null && dbg.Visible)
            {
                dbg.AddLayer(search.Considered, search.MaxCost, search.Owner);
            }

            search.Graph.Dispose();

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

            // no path exists
            return(EmptyPath);
        }
示例#6
0
        // Searches from both ends toward each other. This is used to prevent blockings in case we find
        // units in the middle of the path that prevent us to continue.
        public List<CPos> FindBidiPath(IPathSearch fromSrc, IPathSearch fromDest)
        {
            List<CPos> path = null;

            var dbg = world.WorldActor.TraitOrDefault<PathfinderDebugOverlay>();
            if (dbg != null && dbg.Visible)
            {
                fromSrc.Debug = true;
                fromDest.Debug = true;
            }

            while (!fromSrc.OpenQueue.Empty && !fromDest.OpenQueue.Empty)
            {
                // make some progress on the first search
                var p = fromSrc.Expand();

                if (fromDest.Graph[p].Status == CellStatus.Closed &&
                    fromDest.Graph[p].CostSoFar < int.MaxValue)
                {
                    path = MakeBidiPath(fromSrc, fromDest, p);
                    break;
                }

                // make some progress on the second search
                var q = fromDest.Expand();

                if (fromSrc.Graph[q].Status == CellStatus.Closed &&
                    fromSrc.Graph[q].CostSoFar < int.MaxValue)
                {
                    path = MakeBidiPath(fromSrc, fromDest, q);
                    break;
                }
            }

            if (dbg != null && dbg.Visible)
            {
                dbg.AddLayer(fromSrc.Considered, fromSrc.MaxCost, fromSrc.Owner);
                dbg.AddLayer(fromDest.Considered, fromDest.MaxCost, fromDest.Owner);
            }

            fromSrc.Graph.Dispose();
            fromDest.Graph.Dispose();

            if (path != null)
                return path;

            return EmptyPath;
        }
示例#7
0
        public List<CPos> FindPath(IPathSearch search)
        {
            var dbg = world.WorldActor.TraitOrDefault<PathfinderDebugOverlay>();
            if (dbg != null && dbg.Visible)
                search.Debug = true;

            List<CPos> path = null;

            while (!search.OpenQueue.Empty)
            {
                var p = search.Expand();
                if (search.IsTarget(p))
                {
                    path = MakePath(search.Graph, p);
                    break;
                }
            }

            if (dbg != null && dbg.Visible)
                dbg.AddLayer(search.Considered, search.MaxCost, search.Owner);

            search.Graph.Dispose();

            if (path != null)
                return path;

            // no path exists
            return EmptyPath;
        }
示例#8
0
        public List<CPos> FindPath(IPathSearch search)
        {
            List<CPos> path = null;

            while (search.CanExpand)
            {
                var p = search.Expand();
                if (search.IsTarget(p))
                {
                    path = MakePath(search.Graph, p);
                    break;
                }
            }

            search.Graph.Dispose();

            if (path != null)
                return path;

            // no path exists
            return EmptyPath;
        }