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 ); }
public override IActivity Tick( Actor self ) { if( IsCanceled || target.Destroyed || !target.IsInWorld) return NextActivity; var mobile = self.Trait<Mobile>(); var ps1 = new PathSearch( self.World, mobile.Info ) { checkForBlocked = true, heuristic = location => 0, inReverse = true }; foreach( var cell in target.Trait<IOccupySpace>().OccupiedCells() ) { ps1.AddInitialCell( cell.First ); if( ( mobile.toCell - cell.First ).LengthSquared <= 2 ) return NextActivity; } ps1.heuristic = PathSearch.DefaultEstimator( mobile.toCell ); var ps2 = PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, target.Location, true ); var ret = self.World.WorldActor.Trait<PathFinder>().FindBidiPath( ps1, ps2 ); if( ret.Count > 0 ) ret.RemoveAt( 0 ); return Util.SequenceActivities( mobile.MoveTo( () => ret ), this ); }
public static PathSearch FromPoint( World world, MobileInfo mi, int2 from, int2 target, bool checkForBlocked ) { var search = new PathSearch(world, mi) { heuristic = DefaultEstimator( target ), checkForBlocked = checkForBlocked }; search.AddInitialCell( from ); return search; }
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); }
public static PathSearch FromPoint(World world, MobileInfo mi, Player owner, int2 from, int2 target, bool checkForBlocked) { var search = new PathSearch(world, mi, owner) { heuristic = DefaultEstimator(target), checkForBlocked = checkForBlocked }; search.AddInitialCell(from); return(search); }
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); }
public static PathSearch FromPoints(World world, MobileInfo mi, Player owner, IEnumerable <int2> froms, int2 target, bool checkForBlocked) { var search = new PathSearch(world, mi, owner) { heuristic = DefaultEstimator(target), checkForBlocked = checkForBlocked }; foreach (var sl in froms) { search.AddInitialCell(sl); } return(search); }
public static PathSearch FromPoints(World world, MobileInfo mi, IEnumerable<int2> froms, int2 target, bool checkForBlocked) { var search = new PathSearch(world, mi) { heuristic = DefaultEstimator(target), checkForBlocked = checkForBlocked }; foreach( var sl in froms ) search.AddInitialCell( sl ); return search; }
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); } }