Thread: PathFinding bug.

Results 1 to 8 of 8
  1. #1 PathFinding bug. 
    Registered Member
    Serenity's Avatar
    Join Date
    Oct 2008
    Age
    32
    Posts
    2,327
    Thanks given
    43
    Thanks received
    43
    Rep Power
    389
    hello,

    i was working on making clientside walking to serverside walking.

    ive been debugging for hours and hours but i cant seem to find the problem.

    the point is this :

    the player walks to the given spot but when reached. it runs away to south-west until the mapregion changes anymore,
    my question does anyone know what the problem is of this.

    Serenity.


    Spoiler for Walking class.:

    Code:
    package sds.rs2.tools.Attempt;
    import sds.rs2.players.Player;
    import sds.rs2.Engine;
    import sds.rs2.content.Hit;
    import java.util.Arrays;
    /**
     * Created by IntelliJ IDEA.
     * User: Serenity
     * Date: 9-sep-2009
     * Time: 19:41:52
     * To change this template use File | Settings | File Templates.
     */
    public class RequestPath {
     
        public  boolean FoundPath(Player p, int targetY, int objectSizeX, int equalesOneIfDoor,
                  int objectSizeY, int startY, int targetX,
                  int walkType, int doorFacing, int startX,
                  int objectTypeRelated, boolean actionWalk) {
            for (int i = 0; i < 104; i++) {
                for (int j = 0; j < 104; j++) {
                    p.PlayerWalkingVars.directionToParent[i][j] = 0;
                    p.PlayerWalkingVars.distanceFromStart[i][j] = 99999999;
                }
            }
            p.PlayerWalkingVars.directionToParent[startX][startY] = 99;
            int x = startX;
            p.PlayerWalkingVars.routeCalculationCallCount++;
            int queueInsertPoint = 0;
            p.PlayerWalkingVars.distanceFromStart[startX][startY] = 0;
            int y = startY;
            int queueGetPoint = 0;
            p.PlayerWalkingVars.queueX[queueInsertPoint] = startX;
            boolean RouteFound = false;
            p.PlayerWalkingVars.queueY[queueInsertPoint++] = startY;
            int[][] FloorMask = LoadingTyle.Region[p.PlayerWalkingVars.RegionId].getFloorBitMask(p.PlayerWalkingVars.Heightlvl);
            while (queueGetPoint != queueInsertPoint) {
                y = p.PlayerWalkingVars.queueY[queueGetPoint];
                x = p.PlayerWalkingVars.queueX[queueGetPoint];
                queueGetPoint = 0xfff & queueGetPoint + 1;
                if ((x == targetX) && (targetY == y)) {
                    RouteFound = true;
                    break;
                }
                if (equalesOneIfDoor != 0) {
                    if (((equalesOneIfDoor ^ 0xffffffff) > -6 || (equalesOneIfDoor ^ 0xffffffff) == -11)
                            && (findRoute.method459
                            (FloorMask, doorFacing, targetX, x, 1, targetY, y, equalesOneIfDoor - 1))) {
                        RouteFound = true;
                        break;
                    }
                    if (equalesOneIfDoor < 10 &&
                            (findRoute.method462
                                    (FloorMask, targetX, x, doorFacing, (byte) -37, 1, targetY, y, equalesOneIfDoor - 1))) {
                        RouteFound = true;
                        break;
                    }
                }
                if ((objectSizeX ^ 0xffffffff) != -1 && (objectSizeY ^ 0xffffffff) != -1
                        && (findRoute.method448
                        (FloorMask, targetY, 1, y, objectSizeY, x, objectTypeRelated, objectSizeX, targetX))) {
                    RouteFound = true;
                    break;
                }
                int distanceToNextNode = p.PlayerWalkingVars.distanceFromStart[x][y] + 1;
                //Check if its possible to go west from this node
                if ((x ^ 0xffffffff) < -1 &&
                        (p.PlayerWalkingVars.directionToParent[-1 + x][y]
                                ^ 0xffffffff) == -1 &&
                        (FloorMask[-1 + x][y] & 0x12c0108 ^ 0xffffffff) == -1) {
                    p.PlayerWalkingVars.queueX[queueInsertPoint] = x + -1;
                    p.PlayerWalkingVars.queueY[queueInsertPoint] = y;
                    queueInsertPoint = 0xfff & queueInsertPoint + 1;
                    p.PlayerWalkingVars.directionToParent[x + -1][y] = 2;
                    p.PlayerWalkingVars.distanceFromStart[-1 + x][y] = distanceToNextNode;
                }
                //Check if its possible to go east from this node
                if (x < 103
                        && p.PlayerWalkingVars.directionToParent[x - -1][y] == 0
                        && (0x12c0180 & FloorMask[x - -1][y] ^ 0xffffffff) == -1) {
                    p.PlayerWalkingVars.queueX[queueInsertPoint] = 1 + x;
                    p.PlayerWalkingVars.queueY[queueInsertPoint] = y;
                    queueInsertPoint = 1 + queueInsertPoint & 0xfff;
                    p.PlayerWalkingVars.directionToParent[1 + x][y] = 8;
                    p.PlayerWalkingVars.distanceFromStart[1 + x][y] = distanceToNextNode;
                }
                //Check if its possible to go south from this node
                if ((y ^ 0xffffffff) < -1
                        && (p.PlayerWalkingVars.directionToParent[x][y - 1]
                        ^ 0xffffffff) == -1
                        && (FloorMask[x][-1 + y] & 0x12c0102) == 0) {
                    p.PlayerWalkingVars.queueX[queueInsertPoint] = x;
                    p.PlayerWalkingVars.queueY[queueInsertPoint] = -1 + y;
                    p.PlayerWalkingVars.directionToParent[x][y + -1] = 1;
                    queueInsertPoint = 0xfff & queueInsertPoint - -1;
                   p. PlayerWalkingVars.distanceFromStart[x][-1 + y] = distanceToNextNode;
                }
                //Check if its possible to go north from this node
                if (y < 103
                        && p.PlayerWalkingVars.directionToParent[x][y - -1] == 0
                        && (FloorMask[x][y - -1] & 0x12c0120) == 0) {
                    p.PlayerWalkingVars.queueX[queueInsertPoint] = x;
                    p.PlayerWalkingVars.queueY[queueInsertPoint] = y - -1;
                    p.PlayerWalkingVars.directionToParent[x][y + 1] = 4;
                    p.PlayerWalkingVars.distanceFromStart[x][y - -1] = distanceToNextNode;
                    queueInsertPoint = queueInsertPoint - -1 & 0xfff;
                }
                //Check if its possible to go south-west from this node
                if ((x ^ 0xffffffff) < -1 && y > 0
                        && (p.PlayerWalkingVars.directionToParent[-1 + x][y + -1]
                        ^ 0xffffffff) == -1
                        && (FloorMask[x - 1][-1 + y] & 0x12c010e ^ 0xffffffff) == -1
                        && (FloorMask[x - 1][y] & 0x12c0108) == 0
                        && (FloorMask[x][-1 + y] & 0x12c0102 ^ 0xffffffff) == -1) {
                   p. PlayerWalkingVars.queueX[queueInsertPoint] = -1 + x;
                    p.PlayerWalkingVars.queueY[queueInsertPoint] = y - 1;
                    queueInsertPoint = 0xfff & 1 + queueInsertPoint;
                   p. PlayerWalkingVars.directionToParent[x + -1][-1 + y] = 3;
                    p.PlayerWalkingVars.distanceFromStart[x + -1][-1 + y] = distanceToNextNode;
                }
                //Check if its possible to go south-east from this node
                if ((x ^ 0xffffffff) > -104 && (y ^ 0xffffffff) < -1
                        && p.PlayerWalkingVars.directionToParent[1 + x][y - 1] == 0
                        && (0x12c0183 & FloorMask[1 + x][y + -1]) == 0
                        && (0x12c0180 & FloorMask[1 + x][y]) == 0
                        && (0x12c0102 & FloorMask[x][y + -1] ^ 0xffffffff) == -1) {
                    p.PlayerWalkingVars.queueX[queueInsertPoint] = 1 + x;
                    p.PlayerWalkingVars.queueY[queueInsertPoint] = y + -1;
                    queueInsertPoint = 0xfff & 1 + queueInsertPoint;
                   p. PlayerWalkingVars.directionToParent[x + 1][-1 + y] = 9;
                   p. PlayerWalkingVars.distanceFromStart[1 + x][y + -1] = distanceToNextNode;
                }
                //Check if its possible to go north-west from this node
                if ((x ^ 0xffffffff) < -1 && (y ^ 0xffffffff) > -104
                        && (p.PlayerWalkingVars.directionToParent[-1 + x][1 + y]
                        ^ 0xffffffff) == -1
                        && (FloorMask[-1 + x][y + 1] & 0x12c0138) == 0
                        && (0x12c0108 & FloorMask[x + -1][y] ^ 0xffffffff) == -1
                        && (FloorMask[x][1 + y] & 0x12c0120) == 0) {
                    p.PlayerWalkingVars.queueX[queueInsertPoint] = x - 1;
                   p. PlayerWalkingVars.queueY[queueInsertPoint] = 1 + y;
                    queueInsertPoint = 0xfff & queueInsertPoint - -1;
                   p. PlayerWalkingVars.directionToParent[-1 + x][1 + y] = 6;
                   p. PlayerWalkingVars.distanceFromStart[x - 1][y - -1] = distanceToNextNode;
                }
    //Check if its possible to go north-east from this node
                if (x < 103 && y < 103
                        && p.PlayerWalkingVars.directionToParent[x - -1][1 + y] == 0
                        && (FloorMask[x + 1][y + 1] & 0x12c01e0 ^ 0xffffffff) == -1
                        && (0x12c0180 & FloorMask[1 + x][y] ^ 0xffffffff) == -1
                        && (FloorMask[x][y - -1] & 0x12c0120) == 0) {
                    p.PlayerWalkingVars.queueX[queueInsertPoint] = x - -1;
                   p. PlayerWalkingVars.queueY[queueInsertPoint] = 1 + y;
                   p. PlayerWalkingVars.directionToParent[x + 1][y - -1] = 12;
                   p. PlayerWalkingVars.distanceFromStart[1 + x][1 + y] = distanceToNextNode;
                    queueInsertPoint = 0xfff & queueInsertPoint + 1;
                }
            }
            //  Class32.anInt565 = 0;
            if (!RouteFound) {
                if (actionWalk) {
                    int allowedRouteModifier = 1000;
                    int distanceToModifiedTarget = 100;
                    int offsetToCheckForSurroundingNodes = 10;
                    for (int surroundingX = -offsetToCheckForSurroundingNodes + targetX; offsetToCheckForSurroundingNodes + targetX >= surroundingX;
                         surroundingX++) {
                        for (int surroundingY = targetY - offsetToCheckForSurroundingNodes; targetY - -offsetToCheckForSurroundingNodes >= surroundingY; surroundingY++) {
                            if (surroundingX >= 0 && (surroundingY ^ 0xffffffff) <= -1
                                    && surroundingX < 104 && surroundingY < 104
                                    && (p.PlayerWalkingVars.distanceFromStart[surroundingX][surroundingY] ^ 0xffffffff) > -101) {
                                int offsetX = 0;
                                if (surroundingX < targetX)
                                    offsetX = -surroundingX + targetX;
                                else if ((surroundingX ^ 0xffffffff)
                                        < (-1 + targetX - -objectSizeX ^ 0xffffffff))
                                    offsetX = -targetX + -objectSizeX - (-1 - surroundingX);
                                int offsetY = 0;
                                if (targetY > surroundingY)
                                    offsetY = -surroundingY + targetY;
                                else if ((-1 + objectSizeY + targetY ^ 0xffffffff)
                                        > (surroundingY ^ 0xffffffff))
                                    offsetY = -targetY + (-objectSizeY + (1 + surroundingY));
                                int distanceFromTarget = offsetX * offsetX - -(offsetY * offsetY);
                                if ((allowedRouteModifier ^ 0xffffffff) < (distanceFromTarget ^ 0xffffffff)
                                        || (distanceFromTarget == allowedRouteModifier
                                        && (((p.PlayerWalkingVars.distanceFromStart[surroundingX]
                                        [surroundingY])
                                        ^ 0xffffffff)
                                        > (distanceToModifiedTarget ^ 0xffffffff)))) {
                                    x = surroundingX;
                                    allowedRouteModifier = distanceFromTarget;
                                    distanceToModifiedTarget = (p.PlayerWalkingVars.distanceFromStart[surroundingX][surroundingY]);
                                    y = surroundingY;
                                }
                            }
                        }
                    }
                    if (allowedRouteModifier == 1000)
                        return false;
                    if (startX == x && (startY ^ 0xffffffff) == (y ^ 0xffffffff))
                        return false;
                    //      Class32.anInt565 = 1;
                } else
                    return false;
            }
            queueGetPoint = 0;
            p.PlayerWalkingVars.queueX[queueGetPoint] = x;
            p.PlayerWalkingVars.queueY[queueGetPoint++] = y;
            int previousMovingDirection;
            int movingDirection = previousMovingDirection = p.PlayerWalkingVars.directionToParent[x][y];
            while ((x ^ 0xffffffff) != (startX ^ 0xffffffff)
                    || (startY ^ 0xffffffff) != (y ^ 0xffffffff)) {
                if (previousMovingDirection != movingDirection) {
                    p.PlayerWalkingVars.queueX[queueGetPoint] = x;
                    previousMovingDirection = movingDirection;
                    p.PlayerWalkingVars.queueY[queueGetPoint++] = y;
                }
                if ((0x1 & movingDirection ^ 0xffffffff) != -1)
                    y++;
                else if ((movingDirection & 0x4 ^ 0xffffffff) != -1)
                    y--;
                if ((movingDirection & 0x2 ^ 0xffffffff) == -1) {
                    if ((0x8 & movingDirection) != 0)
                        x--;
                } else
                    x++;
                movingDirection = p.PlayerWalkingVars.directionToParent[x][y];
            }
            if (queueGetPoint > 0) {
                SendWalkingPacket(p, queueGetPoint, walkType);
                return true;
            }
            if ((walkType ^ 0xffffffff) == -2)
                return false;
            return true;
        }
        public void SendWalkingPacket(Player p, int queueGetPoint, int WalkingType) {
            int waypoint = queueGetPoint;
            if (waypoint > 25) {
                waypoint = 25;
            }
            queueGetPoint--;
            int firstX = p.PlayerWalkingVars.queueX[queueGetPoint] - (p.mapRegionX - 6) / 8;
            int firstY = p.PlayerWalkingVars.queueY[queueGetPoint] - (p.mapRegionY - 6) / 8;
            int numPath = waypoint;
            int[] pathX = new int[numPath];
            int[] pathY = new int[numPath];
            for (int i = 0; i < numPath; i++) {
                pathX[i] = p.PlayerWalkingVars.queueY[i];
                pathY[i] = p.PlayerWalkingVars.queueX[i];
            }
            Engine.playerMovement.addToWalkingQueue(p, firstX, firstY);
            for (int i = 0; i < numPath; i++) {
                Engine.playerMovement.addToWalkingQueue(p, Math.abs(p.PlayerWalkingVars.queueY[i] + (p.mapRegionY - 6) * 8), Math.abs(p.PlayerWalkingVars.queueX[i] + (p.mapRegionX - 6) * 8));
            }
            Hit.resetattack(p, null);
            p.itemPickup = false;
            p.playerOption1 = false;
            p.playerOption2 = false;
            p.playerOption3 = false;
            p.npcOption1 = false;
            p.npcOption2 = false;
            p.objectOption1 = false;
            p.objectOption2 = false;
            p.attackingPlayer = false;
            p.isInterruptable = false;
            if (WalkingType == 1) {
                if (p.interfaceId != -1)
                    p.frames.removeShownInterface(p);
                if (p.chatboxInterfaceId != -1)
                    p.frames.removeChatboxInterface(p);
            }
            if (p.faceToReq != 65535) {
                p.requestFaceTo(65535);
            }
        }
     
    }
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  2. #2  
    Renown Programmer and Respected Member
    Maxi's Avatar
    Join Date
    Jun 2008
    Posts
    3,201
    Thanks given
    281
    Thanks received
    1,093
    Rep Power
    1366
    Quickly glanced over it but could it be you are adding the base coordinate of your region to the last index of your path?
    Reply With Quote  
     

  3. #3  
    Registered Member
    Serenity's Avatar
    Join Date
    Oct 2008
    Age
    32
    Posts
    2,327
    Thanks given
    43
    Thanks received
    43
    Rep Power
    389
    instead of reaching the last tile, it turns around and runs south west till the end of the region...
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  4. #4  
    Doctor p - Sweet Shop

    Join Date
    Apr 2007
    Age
    28
    Posts
    6,835
    Thanks given
    150
    Thanks received
    584
    Rep Power
    2595
    it's weird but Paul (Hoster) gave me pathFinding and it also walks to south-west

    Reply With Quote  
     

  5. #5  
    Annexation
    Guest
    Quote Originally Posted by Nathan View Post
    it's weird but Paul (Hoster) gave me pathFinding and it also walks to south-west
    lol i helped serenity a bit, he helped paul & paul tried to help me (lol), you and probz others
    Reply With Quote  
     

  6. #6  
    Brown
    Guest
    Please fix your conventions.. :/ Its killing me.
    Reply With Quote  
     

  7. #7  
    Registered Member
    Serenity's Avatar
    Join Date
    Oct 2008
    Age
    32
    Posts
    2,327
    Thanks given
    43
    Thanks received
    43
    Rep Power
    389
    i might but that aint the point atm... im just trying to find the fault in here... it walks 1 to the 1 square near a spot. when it is in range of 1 tile it will change its direction to walk to south west..
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  8. #8  
    Renown Programmer and Respected Member
    Maxi's Avatar
    Join Date
    Jun 2008
    Posts
    3,201
    Thanks given
    281
    Thanks received
    1,093
    Rep Power
    1366
    The base of the region starts in the south west. So look if you are adding the base coords of the region to your last path index.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •