示例#1
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);
            }
        }
示例#2
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));
        }
示例#3
0
		public static PathSearch FromPoint(World world, MobileInfo mi, Actor self, CPos from, CPos target, bool checkForBlocked)
		{
			var search = new PathSearch(world, mi, self)
			{
				Heuristic = DefaultEstimator(target),
				CheckForBlocked = checkForBlocked
			};

			search.AddInitialCell(from);
			return search;
		}
示例#4
0
		public static PathSearch FromPoints(World world, MobileInfo mi, Actor self, IEnumerable<CPos> froms, CPos target, bool checkForBlocked)
		{
			var search = new PathSearch(world, mi, self)
			{
				Heuristic = DefaultEstimator(target),
				CheckForBlocked = checkForBlocked
			};

			foreach (var sl in froms)
				search.AddInitialCell(sl);

			return search;
		}
示例#5
0
        void FindMoreResource(Actor self)
        {
            var res = self.World.WorldActor.traits.Get<ResourceLayer>();
            var harv = self.Info.Traits.Get<HarvesterInfo>();

            self.QueueActivity(new Move(
                () =>
                {
                    var search = new PathSearch(self.World)
                    {
                        heuristic = loc => (res.GetResource(loc) != null
                            && harv.Resources.Contains( res.GetResource(loc).Name )) ? 0 : 1,
                        umt = UnitMovementType.Wheel,
                        checkForBlocked = true
                    };
                    search.AddInitialCell(self.World, self.Location);
                    return self.World.PathFinder.FindPath(search);
                }));
            self.QueueActivity(new Harvest());
        }