Esempio n. 1
0
        private void Run()
        {
            IsRunning = true;
#if DEBUG
            Started?.Invoke(this, EventArgs.Empty);
#endif
            while (!_terminated)
            {
                while (!_requests.IsEmpty)
                {
                    if (_terminated)
                    {
                        break;
                    }
                    if (_requests.TryDequeue(out PathRequest? request))
                    {
#if DEBUG
                        Debug.WriteLine("PathfindingManager::Run: Request Found");
#endif
                        Route path = _pathfinder.GetPath(
                            request.Map,
                            ref request.Map.GetCell(request.StartColumn, request.StartRow),
                            ref request.Map.GetCell(request.GoalColumn, request.GoalRow),
                            request.Locomotion);
                        request.Callback.PathFound(path, request.CallbackContext);
                    }
                }
                _gate.WaitOne(1000);                   // Automatically unlock after 1s just in case
            }
            IsRunning = false;
#if DEBUG
            Stopped?.Invoke(this, EventArgs.Empty);
#endif
        }
Esempio n. 2
0
        protected IEnumerator PathfindThenTakeTurn(NavNode destination)
        {
            //Wait for pathfinder to finish its search.
            _pathfinder.Search(_node, destination);
            while (_pathfinder.Running)
            {
                yield return(null);
            }

            if (_pathfinder.PathStatus == PathStatus.success)
            {
                List <NavNode> path = _pathfinder.GetPath();               //0 is our current position, so position 1 is the next.

                if (path.Count > 1)
                {
                    NavNode    next = path[1];
                    Vector3Int dir  = next.cellPos - _node.cellPos;
                    Move       m    = new Move(puzzleManager, false);
                    m.AddAgentToMove(this, dir, true, null, null, 50);
                    puzzleManager.ExecuteAICommand(m);
                    if (m.IsValid)
                    {
                        puzzleManager.HoldPlayerForAI(this);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Coroutine to search for the destination, simply waiting until destination is found.
        /// </summary>

        private IEnumerator FindPathToDestination(NavNode final)
        {
            _pathfinder.Search(_player.CurrentNode, final);
            //Wait for pathfinder to finish its search.
            while (_pathfinder.Running)
            {
                yield return(null);
            }

            if (_pathfinder.PathStatus == PathStatus.success)
            {
                _moveChainCoroutine = StartCoroutine(MoveToDestination(_pathfinder.GetPath()));
            }
        }
        public void GoTo(Point destination)
        {
            if (destination == Location)
            {
                return;
            }

            var chunks = GameSystem.Chunks.GetLoaded();

            List <Block> blocks = new List <Block>();

            foreach (var chunk in chunks)
            {
                blocks.AddRange(chunk.Blocks);
            }

            Pathfinder.UpdateWorld(blocks);
            currentPath = Pathfinder.GetPath(Location, destination);
            if (currentPath != null && currentPath.Any())
            {
                isMoving = true;
                Debug.Log(string.Format("{0} Entity is moving from {1},{2} to {3},{4}", Type.Name, Location.X.ToString(), Location.Y.ToString(), destination.X.ToString(), destination.Y.ToString()));
            }
        }
Esempio n. 5
0
 public static UnitPath GetFullPath(Vector2 start, Vector2 target, bool hasToReachTarget = false, bool strict = true)
 {
     return(new UnitPath(sPathfinder.GetPath(start, target, GameGraph.GameGraph.Graph, strict), hasToReachTarget));
 }
Esempio n. 6
0
 /// <summary>Calculates an <see cref="IDirectedPath"/> asynchronously for the optimal path from coordinates .</summary>
 /// <param name="this"></param>
 /// <param name="source">Coordinates for the <c>first</c> step on the desired path.</param>
 /// <param name="target">Coordinates for the <c>last</c> step on the desired path.</param>
 public static async Task <Maybe <IDirectedPath> > GetPathAsync(this IPathfinder @this, HexCoords source, HexCoords target)
 => await Task.Run(() => @this.GetPath(source, target));
Esempio n. 7
0
 /// <inheritdoc/>>
 public static Maybe <IDirectedPath> GetPath(this IPathfinder @this, IHex target, IHex source)
 => @this.GetPath(target.Coords, source.Coords);