コード例 #1
0
    /**
     * Determine if this Mover instance can move to a position.
     *
     * @param newPos
     *      Vector representing a desired new position.
     *
     * @return
     *      true if the desired new position is within this mover's movement
     *      range after accounting for detours around islands
     */
    protected bool CanMoveTo(Vector3 newPos)
    {
        //Debug.Log ("Navy Mover: Checking if position [" + newPos.x + "," + newPos.y + "] is a potential move.");

        bool inRange = IsInRange(newPos);

        if (inRange)
        {
            //Debug.Log ("Navy Mover: [" + newPos.x + "," + newPos.y + "] is in euclidian range.");
        }
        else
        {
            //Debug.Log ("Navy Mover: [" + newPos.x + "," + newPos.y + "] is not in euclidian range.");
            return(false);
        }

        bool validEnd = ValidPosition(newPos);

        if (validEnd)
        {
            //Debug.Log ("Navy Mover: [" + newPos.x + "," + newPos.y + "] is a valid position.");
        }
        else
        {
            //Debug.Log ("Navy Mover: [" + newPos.x + "," + newPos.y + "] is not a valid position.");
            return(false);
        }

        if (inRange && validEnd)
        {
            // check to see if line of sight path possible.
            // if not, find actual path
            Vector3 pos = gameObject.transform.position;
            return(NavyMoverSearcher.LineOfSightPathBetween(pos, newPos) ||
                   NavyMoverSearcher.CanMoveBetween(pos, newPos, GetMoveRange()));
        }
        return(false);
    }
コード例 #2
0
        public List <PathNode> Neighbors()
        {
            List <PathNode> ret = new List <PathNode>();
            // starting x, y
            int x = loc.x, y = loc.y;

            // up
            y++;
            if (NavyMoverSearcher.ValidTile(x, y))
            {
                PathNode up = new PathNode(new Location(x, y), CostSoFar + Direct, goal);
                up.last = this;
                ret.Add(up);
            }

            // up right
            x++;
            if (NavyMoverSearcher.ValidTile(x, y))
            {
                PathNode upRight = new PathNode(new Location(x, y), CostSoFar + Diagonal, goal);
                upRight.last = this;
                ret.Add(upRight);
            }

            // right
            y--;
            if (NavyMoverSearcher.ValidTile(x, y))
            {
                PathNode right = new PathNode(new Location(x, y), CostSoFar + Direct, goal);
                right.last = this;
                ret.Add(right);
            }

            // down right
            y--;
            if (NavyMoverSearcher.ValidTile(x, y))
            {
                PathNode downRight = new PathNode(new Location(x, y), CostSoFar + Diagonal, goal);
                downRight.last = this;
                ret.Add(downRight);
            }

            // down
            x--;
            if (NavyMoverSearcher.ValidTile(x, y))
            {
                PathNode down = new PathNode(new Location(x, y), CostSoFar + Direct, goal);
                down.last = this;
                ret.Add(down);
            }

            // down left
            x--;
            if (NavyMoverSearcher.ValidTile(x, y))
            {
                PathNode downLeft = new PathNode(new Location(x, y), CostSoFar + Diagonal, goal);
                downLeft.last = this;
                ret.Add(downLeft);
            }

            // left
            y++;
            if (NavyMoverSearcher.ValidTile(x, y))
            {
                PathNode left = new PathNode(new Location(x, y), CostSoFar + Direct, goal);
                left.last = this;
                ret.Add(left);
            }

            // up left
            y++;
            if (NavyMoverSearcher.ValidTile(x, y))
            {
                PathNode upLeft = new PathNode(new Location(x, y), CostSoFar + Diagonal, goal);
                upLeft.last = this;
                ret.Add(upLeft);
            }

            return(ret);
        }
コード例 #3
0
        public float CostToGoal()
        {
            Vector3 center = new Vector3(loc.x + 0.500f, loc.y + 0.500f);

            return(NavyMoverSearcher.DistanceBetween(center, goal));
        }