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);
}
}
}