Exemple #1
0
        /// <summary>
        /// Assigns the perpendicular directions of the given direction as out variables.
        /// </summary>
        private void GetPerpendicularDirections(JumpPointDirection inDirection, out JumpPointDirection outFirstPerpendicularDirection, out JumpPointDirection outSecondPerpendicularDirection)
        {
            switch (inDirection)
            {
            case JumpPointDirection.North:
            case JumpPointDirection.South:
                outFirstPerpendicularDirection  = JumpPointDirection.East;
                outSecondPerpendicularDirection = JumpPointDirection.West;
                break;

            case JumpPointDirection.East:
            case JumpPointDirection.West:
                outFirstPerpendicularDirection  = JumpPointDirection.North;
                outSecondPerpendicularDirection = JumpPointDirection.South;
                break;

            default:
                outFirstPerpendicularDirection  = JumpPointDirection.None;
                outSecondPerpendicularDirection = JumpPointDirection.None;
                break;
            }
        }
Exemple #2
0
        /// <summary>
        /// Helper function to get the next position based on the direction and the original coordinate.
        /// </summary>
        /// <param name="inCoordinate">Coordinate being looked at.</param>
        /// <param name="inAbsJumpDistance">Absolute value of the jump distance.</param>
        /// <param name="inDirection">The direction being looked at.</param>
        /// <returns>The position based on the current coordinate and the jumpdistance in the given direction.</returns>
        private Vector2Int GetNextPosition(Vector2Int inCoordinate, int inAbsJumpDistance, JumpPointDirection inDirection)
        {
            switch (inDirection)
            {
            case JumpPointDirection.North:
                return(new Vector2Int(inCoordinate.x, inCoordinate.y + inAbsJumpDistance));

            case JumpPointDirection.East:
                return(new Vector2Int(inCoordinate.x + inAbsJumpDistance, inCoordinate.y));

            case JumpPointDirection.South:
                return(new Vector2Int(inCoordinate.x, inCoordinate.y - inAbsJumpDistance));

            case JumpPointDirection.West:
                return(new Vector2Int(inCoordinate.x - inAbsJumpDistance, inCoordinate.y));

            default:
                return(Vector2Int.zero);
            }
        }
Exemple #3
0
        /// <summary>
        /// Adds the given coordinate to the open list, or updates a node already on there with new information if necessary.
        /// </summary>
        /// <param name="inNewCoordinate">The coordinate being put on the open list.</param>
        /// <param name="inCurrentNode">The node the new coordinate led from.</param>
        /// <param name="inDirection">Direction being looked at.</param>
        /// <param name="inCost">Cost of the new node.</param>
        /// <param name="inInput">Input parameters for finding a path.</param>
        private void AddToOpenList(Vector2Int inNewCoordinate, PathfindingNode inCurrentNode, JumpPointDirection inDirection, int inCost, FindPathInput inInput)
        {
            PathfindingNode node;

            if ((node = openSet.GetExistingNode(inNewCoordinate)) != null)
            {
                node.ParentNode = inCurrentNode;
                (node.AdditionalTileData as AdditionalJPSPlusData).ParentDirection = inDirection;
                node.GCost = inCost;

                openSet.UpdateItem(node);
            }
            else if (!closedSet.Contains(inNewCoordinate))
            {
                int heuristicCost = GetManhattanDistance(inNewCoordinate, inInput.TargetCoordinate);

                node = GetNode(inNewCoordinate);

                node.ParentNode = inCurrentNode;
                (node.AdditionalTileData as AdditionalJPSPlusData).ParentDirection = inDirection;
                node.GCost = inCost;
                node.HCost = heuristicCost;

                openSet.Add(node);
            }
        }
Exemple #4
0
        /// <summary>
        /// Helper function to check whether the targetposition is on one line with the given coordinate.
        /// </summary>
        /// <param name="inCoordinate">The coordinate being checked.</param>
        /// <param name="inTargetPosition">The target coordinate.</param>
        /// <param name="inAbsJumpDistance">The absolute value of the jump distance.</param>
        /// <param name="inDirection">The direction being looked at.</param>
        /// <param name="outDiff">The difference between the two coordinates.</param>
        /// <returns>True if in line of sight, otherwise false.</returns>
        private bool InLineWithTargetPosition(Vector2Int inCoordinate, Vector2Int inTargetPosition, int inAbsJumpDistance, JumpPointDirection inDirection, out int outDiff)
        {
            switch (inDirection)
            {
            case JumpPointDirection.North:
                outDiff = Mathf.Abs(inCoordinate.y - inTargetPosition.y);
                return(inCoordinate.y < inTargetPosition.y && inCoordinate.y + inAbsJumpDistance >= inTargetPosition.y);

            case JumpPointDirection.East:
                outDiff = Mathf.Abs(inTargetPosition.x - inCoordinate.x);
                return(inCoordinate.x < inTargetPosition.x && inCoordinate.x + inAbsJumpDistance >= inTargetPosition.x);

            case JumpPointDirection.South:
                outDiff = Mathf.Abs(inTargetPosition.y - inCoordinate.y);
                return(inCoordinate.y > inTargetPosition.y && inCoordinate.y - inAbsJumpDistance <= inTargetPosition.y);

            case JumpPointDirection.West:
                outDiff = Mathf.Abs(inCoordinate.x - inTargetPosition.x);
                return(inCoordinate.x > inTargetPosition.x && inCoordinate.x - inAbsJumpDistance <= inTargetPosition.x);

            default:
                outDiff = 0;
                return(false);
            }
        }