Exemple #1
0
 public static void Load()
 {
     MainPathFinder.Initialize();
     ClientProcessor.Initialize(GetMessageHandlers());
     EntityTicking.Initialize();
     ClientTick += Client_ClientTick;
 }
Exemple #2
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);
        }
Exemple #3
0
        public override void MakePreparations(Living living)
        {
            ComponentSelectable entityData = living.GetExactComponent <ComponentSelectable>();
            Point2D             start      = entityData.MapLocation;

            if (start != this.Destination)
            {
                List <PathLink>   pth;
                ComponentMovement movementComponent = living.GetExactComponent <ComponentMovement>();

                //Handle reroute
                if (movementComponent.QueuedMovement.Count > 0)
                {
                    //Get a path to the nearest/next tile so that path finding and the screen location sync up.
                    PathLink previous = movementComponent.QueuedMovement.Peek();
                    movementComponent.QueuedMovement.Clear();
                    movementComponent.QueuedMovement.Enqueue(previous);
                    pth = MainPathFinder.GetRoute(living.Dimension, previous.Destination, this.Destination);
                }
                //No reroute
                else
                {
                    pth = MainPathFinder.GetRoute(living.Dimension, start, this.Destination);
                }

                MagicalLifeAPI.Util.Extensions.EnqueueCollection(movementComponent.QueuedMovement, pth);
                ClientSendRecieve.Send <RouteCreatedMessage>(new RouteCreatedMessage(pth, living.ID, living.Dimension));
            }
        }
Exemple #4
0
        protected override void StartJob(Living living)
        {
            Point2D start = living.MapLocation;

            if (start != this.Destination)
            {
                List <PathLink> pth;

                //Handle reroute
                if (living.QueuedMovement.Count > 0)
                {
                    //Get a path to the nearest/next tile so that path finding and the screen location sync up.
                    PathLink previous = living.QueuedMovement.Peek();
                    living.QueuedMovement.Clear();
                    living.QueuedMovement.Enqueue(previous);
                    pth = MainPathFinder.GetRoute(living.Dimension, previous.Destination, this.Destination);
                }
                //No reroute
                else
                {
                    pth = MainPathFinder.GetRoute(living.Dimension, living.MapLocation, this.Destination);
                }

                MagicalLifeAPI.Util.Extensions.EnqueueCollection(living.QueuedMovement, pth);
                ClientSendRecieve.Send <RouteCreatedMessage>(new RouteCreatedMessage(pth, living.ID, living.Dimension));
            }
        }
Exemple #5
0
        private void Move(Selectable selectable, Microsoft.Xna.Framework.Point target)
        {
            if (World.Dimensions[RenderingPipe.Dimension][target.X, target.Y].IsWalkable)
            {
                switch (selectable)
                {
                case Living living:

                    Microsoft.Xna.Framework.Point start = selectable.MapLocation;
                    if (start != target)
                    {
                        List <PathLink> pth;

                        //Handle reroute
                        if (living.QueuedMovement.Count > 0)
                        {
                            //Get a path to the nearest/next tile so that path finding and the screen location sync up.
                            PathLink previous = living.QueuedMovement.Peek();
                            living.QueuedMovement.Clear();
                            living.QueuedMovement.Enqueue(previous);
                            pth = MainPathFinder.GetRoute(RenderingPipe.Dimension, previous.Destination, target);
                        }
                        //No reroute
                        else
                        {
                            pth = MainPathFinder.GetRoute(RenderingPipe.Dimension, living.MapLocation, target);
                        }

                        Extensions.EnqueueCollection(living.QueuedMovement, pth);
                        ClientSendRecieve.Send <RouteCreatedMessage>(new RouteCreatedMessage(pth, living.ID, living.Dimension));
                    }
                    break;
                }
            }
        }
        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);
        }
Exemple #8
0
        private void Move(HasComponents selectable, Point2D target)
        {
            if (World.Dimensions[RenderInfo.Dimension][target.X, target.Y].IsWalkable)
            {
                switch (selectable)
                {
                case Living living:
                    ComponentSelectable positionData = living.GetExactComponent <ComponentSelectable>();
                    Point2D             start        = positionData.MapLocation;
                    if (start != target)
                    {
                        List <PathLink>   pth;
                        ComponentMovement movementComponent = living.GetExactComponent <ComponentMovement>();

                        //Handle reroute
                        if (movementComponent.QueuedMovement.Count > 0)
                        {
                            //Get a path to the nearest/next tile so that path finding and the screen location sync up.
                            PathLink previous = movementComponent.QueuedMovement.Peek();
                            movementComponent.QueuedMovement.Clear();
                            movementComponent.QueuedMovement.Enqueue(previous);
                            pth = MainPathFinder.GetRoute(RenderInfo.Dimension, previous.Destination, target);
                        }
                        //No reroute
                        else
                        {
                            pth = MainPathFinder.GetRoute(RenderInfo.Dimension, positionData.MapLocation, target);
                        }

                        Extensions.EnqueueCollection(movementComponent.QueuedMovement, pth);
                    }
                    break;

                default:
                    break;
                }
            }
        }
Exemple #9
0
        public override bool IsQualified(Living living)
        {
            Point2D mapLocation = living.GetExactComponent <ComponentSelectable>().MapLocation;

            return(MainPathFinder.IsRoutePossible(living.Dimension, mapLocation, this.Destination));
        }