public PathFind( int x, int y, int z, int destX, int destY, int destZ, L2Object obj, int instanceId) { geoIndex = instanceId; startPoint = Config.PATHFIND_BOOST == 0 ? new Location(x, y, z) : GeoEngine.moveCheckWithCollision(x, y, z, destX, destY, true, geoIndex); endPoint = Config.PATHFIND_BOOST != 2 || Math.abs(destZ - z) > 200 ? new Location(destX, destY, destZ) : GeoEngine.moveCheckBackwardWithCollision( destX, destY, destZ, startPoint.x, startPoint.y, true, geoIndex); startPoint.world2geo(); endPoint.world2geo(); startPoint.z = GeoEngine.NgetHeight(startPoint.x, startPoint.y, startPoint.z, false, geoIndex); endPoint.z = GeoEngine.NgetHeight(endPoint.x, endPoint.y, endPoint.z, false, geoIndex); int xdiff = Math.abs(endPoint.x - startPoint.x); int ydiff = Math.abs(endPoint.y - startPoint.y); if (xdiff == 0 && ydiff == 0) { if (Math.abs(endPoint.z - startPoint.z) < 32) { path = new ArrayList<Location>(); path.add(0, startPoint); } return; } int mapSize = 2 * Math.max(xdiff, ydiff); if ((buff = PathFindBuffers.alloc(mapSize)) != null) { buff.offsetX = startPoint.x - buff.mapSize / 2; buff.offsetY = startPoint.y - buff.mapSize / 2; // статистика buff.totalUses++; if (obj != null && obj.isPlayable) buff.playableUses++; findPath(); buff.free(); PathFindBuffers.recycle(buff); } }
public List<Location> findPath() { startNode = buff.nodes[startPoint.x - buff.offsetX][startPoint.y - buff.offsetY].set( startPoint.x, startPoint.y, (short) startPoint.z); GeoEngine.NgetHeightAndNSWE(startPoint.x, startPoint.y, (short) startPoint.z, hNSWE, geoIndex); startNode.z = hNSWE[0]; startNode.nswe = hNSWE[1]; startNode.costFromStart = 0f; startNode.state = GeoNode.OPENED; startNode.parent = null; endNode = buff.nodes[endPoint.x - buff.offsetX][endPoint.y - buff.offsetY].set( endPoint.x, endPoint.y, (short) endPoint.z); startNode.costToEnd = pathCostEstimate(startNode); startNode.totalCost = startNode.costFromStart + startNode.costToEnd; buff.open.add(startNode); long nanos = System.nanoTime(); long searhTime = 0; int itr = 0; while ((searhTime = System.nanoTime() - nanos) < Config.PATHFIND_MAX_TIME && (currentNode = buff.open.poll()) != null) { itr++; if (currentNode.x == endPoint.x && currentNode.y == endPoint.y && Math.abs(currentNode.z - endPoint.z) < 64) { path = tracePath(currentNode); break; } handleNode(currentNode); currentNode.state = GeoNode.CLOSED; } buff.totalTime += searhTime; buff.totalItr += itr; if (path != null) buff.successUses++; else if (searhTime > Config.PATHFIND_MAX_TIME) buff.overtimeUses++; return path; }