Exemple #1
0
 public BlockDiagonalNeighborProvider(CachedBlockAccess level, int startY, Dictionary <ImprovedTile, Block> blockCache, Entity entity)
 {
     _level      = level;
     _startY     = startY;
     _blockCache = blockCache;
     _entity     = entity;
 }
Exemple #2
0
        public List <ImprovedTile> FindPath(Entity source, BlockCoordinates target, double distance)
        {
            try
            {
                //new EmptyBlockedProvider(), // Instance of: IBockedProvider
                var blockAccess = new CachedBlockAccess(source.Level);

                var navigator = new ImprovedTileNavigator(
                    new LevelNavigator(source, blockAccess, distance, _blockCache),
                    new BlockDiagonalNeighborProvider(blockAccess, (int)Math.Truncate(source.KnownPosition.Y), _blockCache, source),                     // Instance of: INeighborProvider
                    new FastBlockDistanceAlgorithm(_blockCache)
                    );

                BlockCoordinates targetPos = target;
                BlockCoordinates sourcePos = (BlockCoordinates)source.KnownPosition;
                var from = new ImprovedTile(sourcePos.X, sourcePos.Z);
                var to   = new ImprovedTile(targetPos.X, targetPos.Z);

                return(navigator.Navigate(from, to).ToList() ?? new List <ImprovedTile>());
            }
            catch (Exception e)
            {
                Log.Error("Navigate", e);
            }

            return(new List <ImprovedTile>());
        }
Exemple #3
0
        public Path FindPath(Entity source, BlockCoordinates target, double distance)
        {
            try
            {
                var blockAccess = new CachedBlockAccess(source.Level);

                var navigator = new TileNavigator(
                    new LevelNavigator(source, blockAccess, distance, _blockCache),
                    new BlockDiagonalNeighborProvider(blockAccess, (int)Math.Truncate(source.KnownPosition.Y), _blockCache, source), // Instance of: INeighborProvider
                    new BlockDistanceAlgorithm(_blockCache),                                                                         // Instance of: IDistanceAlgorithm
                    new ManhattanHeuristicAlgorithm()                                                                                // Instance of: IDistanceAlgorithm
                    );

                BlockCoordinates targetPos = target;
                BlockCoordinates sourcePos = (BlockCoordinates)source.KnownPosition;
                var from = new Tile(sourcePos.X, sourcePos.Z);
                var to   = new Tile(targetPos.X, targetPos.Z);

                var path = navigator.Navigate(from, to, 200)?.ToList() ?? new List <Tile>();

                //Log.Debug($"{source.GetType()} finding path within {distance} blocks. Did {blockAccess.NumberOfBlockGet} block-gets");

                return(new Path(_blockCache)
                {
                    Current = path
                });
            }
            catch (Exception e)
            {
                Log.Error("Navigate", e);
            }

            return(new Path());
        }