Beispiel #1
0
        /// <summary>
        /// Finds the nearest tile to a location without an item or a resource on it.
        /// Returns null if all tiles have an item or a resource in the entire map.
        /// Will not ever return the starting point specified.
        /// Ensures that there is a walkable path for the creature to get there from the specific map location to the returned location.
        /// </summary>
        /// <param name="mapLocation"></param>
        /// <param name="dimension"></param>
        /// <returns></returns>
        public static Point2D FindItemEmptyTile(Point2D mapLocation, int dimension)
        {
            List <Point2D> tilesChecking = WorldUtil.GetNeighboringTiles(mapLocation, dimension);

            while (tilesChecking.Count > 0)
            {
                Point2D currentlyChecking = tilesChecking[0];
                Tile    tile = World.Data.World.GetTile(dimension, currentlyChecking.X, currentlyChecking.Y);

                if (tile.Item == null &&
                    tile.Resources == null &&
                    MainPathFinder.IsRoutePossible(dimension, mapLocation, currentlyChecking))
                {
                    //Found one!
                    return(currentlyChecking);
                }

                //Add all neighbors of the tile since it wasn't free from items and resources.
                tilesChecking.AddRange(WorldUtil.GetNeighboringTiles(currentlyChecking, dimension));
                tilesChecking.RemoveAt(0);
            }

            //Didn't find anything
            return(null);
        }
        protected override void StartJob(Living living)
        {
            List <Point2D> result = WorldUtil.GetNeighboringTiles(this.Target, living.Dimension);

            result.RemoveAll(x => !World.Data.World.GetTile(living.Dimension, x.X, x.Y).IsWalkable);

            int closestIndex = Algorithms.GetClosestPoint2D(result, living.MapLocation);

            this.AdjacentLocation = result[closestIndex];
            List <PathLink> path = MainPathFinder.GetRoute(living.Dimension, living.MapLocation, result[closestIndex]);

            living.QueuedMovement.Clear();
            Extensions.EnqueueCollection(living.QueuedMovement, path);
        }
        public override void MakePreparations(Living l)
        {
            List <Point2D> result = WorldUtil.GetNeighboringTiles(this.Target, l.Dimension);

            result.RemoveAll(x => !World.Data.World.GetTile(l.Dimension, x.X, x.Y).IsWalkable);

            int closestIndex = Algorithms.GetClosestPoint2D(result, l.MapLocation);

            this.AdjacentLocation = result[closestIndex];
            List <PathLink> path = MainPathFinder.GetRoute(l.Dimension, l.MapLocation, result[closestIndex]);

            if (World.Data.World.Mode == Networking.EngineMode.ClientOnly)
            {
                ClientSendRecieve.Send(new RouteCreatedMessage(path, l.ID, l.Dimension));
            }

            l.QueuedMovement.Clear();
            Extensions.EnqueueCollection(l.QueuedMovement, path);
        }
Beispiel #4
0
        public override bool CreateDependencies(Living l)
        {
            List <Point2D> result = WorldUtil.GetNeighboringTiles(this.Target, l.Dimension);

            result.RemoveAll(x => !World.Data.World.GetTile(l.Dimension, x.X, x.Y).IsWalkable);

            ComponentSelectable entitySelected   = l.GetExactComponent <ComponentSelectable>();
            Point2D             adjacentLocation = PathUtil.GetFirstReachable(result, entitySelected.MapLocation, l.Dimension);

            if (adjacentLocation == null)
            {
                return(false);
            }
            else
            {
                MoveTask task = new MoveTask(this.BoundID, adjacentLocation);
                this.Dependencies.PreRequisite.Add(task);
                return(true);
            }
        }