示例#1
0
        public override Activity Tick(Actor self)
        {
            if (IsCanceled || !target.IsValid)
            {
                return(NextActivity);
            }

            var mobile = self.Trait <Mobile>();

            var ps1 = new PathSearch(self.World, mobile.Info, self.Owner)
            {
                checkForBlocked = true,
                heuristic       = location => 0,
                inReverse       = true
            };

            foreach (var cell in Util.AdjacentCells(target))
            {
                if (cell == self.Location)
                {
                    return(NextActivity);
                }
                else
                {
                    ps1.AddInitialCell(cell);
                }
            }

            ps1.heuristic = PathSearch.DefaultEstimator(mobile.toCell);

            var ps2 = PathSearch.FromPoint(self.World, mobile.Info, self.Owner, mobile.toCell, Util.CellContaining(target.CenterLocation), true);
            var ret = self.World.WorldActor.Trait <PathFinder>().FindBidiPath(ps1, ps2);

            return(Util.SequenceActivities(mobile.MoveTo(() => ret), this));
        }
示例#2
0
        void UpdateInnerPath(Actor self)
        {
            var targetCells = Util.AdjacentCells(target);
            var searchCells = new List <CPos>();
            var loc         = self.Location;

            foreach (var cell in targetCells)
            {
                if (mobile.CanEnterCell(cell) && (domainIndex == null || domainIndex.IsPassable(loc, cell, movementClass)))
                {
                    searchCells.Add(cell);
                }
            }

            if (searchCells.Any())
            {
                var ps1 = new PathSearch(self.World, mobile.Info, self)
                {
                    checkForBlocked = true,
                    heuristic       = location => 0,
                    inReverse       = true
                };

                foreach (var cell in searchCells)
                {
                    ps1.AddInitialCell(cell);
                }

                ps1.heuristic = PathSearch.DefaultEstimator(mobile.toCell);
                var ps2 = PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, targetPosition, true);
                var ret = pathFinder.FindBidiPath(ps1, ps2);

                inner = mobile.MoveTo(() => ret);
            }
        }