Exemple #1
0
        private void GenerateViaRoute(float x, float y, Node target)
        {
            ViaRoute.Clear();

            var fromTri = plan.GetTriContainingPoint(x, y);
            var triPath = plan.SearchForPathBetweenTris(fromTri, target.Tri);

            for (int i = 0; i < triPath.Count - 1; ++i)
            {
                var sharedPoints = triPath[i].GetSharedPoints(triPath[i + 1]);
                GetPointBetween(sharedPoints[0], sharedPoints[1], out float xVia, out float yVia);
                ViaRoute.Enqueue(new Node(xVia, yVia, triPath[i]));
            }
        }
Exemple #2
0
        public Node GenerateViaAndTarget(float x, float y)
        {
            var target = ViaRoute.PeekOrDefault() ?? FoundNodes.PeekOrDefault() ?? Route[NextRouteIndex];

            if (!target.Tri.ContainsPoint(x, y))
            {
                // Recalculate ViaRoute.
                target = FoundNodes.PeekOrDefault() ?? Route[NextRouteIndex];
                GenerateViaRoute(x, y, target);

                if (ViaRoute.Count != 0)
                {
                    target = ViaRoute.PeekOrDefault();
                }
            }

            return(target);
        }
Exemple #3
0
        public async Task CheckCompletion(Node target, CancellationToken cancellationToken)
        {
            var x = character.GetX();
            var y = character.GetY();

            if (MathUtils.GetDistSqr(x, y, target.X, target.Y) < DistanceThresholdSquared)
            {
                // Check if we should turn in place at this node.
                IsTurningInPlace = target.ShouldTurnInPlace;
                if (IsTurningInPlace)
                {
                    input.Move(0);
                }

                // Check which target list to advance.
                if (target == ViaRoute.PeekOrDefault())
                {
                    ViaRoute.Dequeue();
                }
                else if (target == FoundNodes.PeekOrDefault())
                {
                    // Gather this node.
                    await Gather(cancellationToken);

                    lock (FoundNodes)
                    {
                        FoundNodes.Dequeue();
                    }
                }
                else if (target == Route[NextRouteIndex])
                {
                    ++NextRouteIndex;
                    if (NextRouteIndex == Route.Count)
                    {
                        NextRouteIndex = 0;
                    }
                }
                else
                {
                    throw new Exception("Completed node was not found in any list.");
                }
            }
        }