boolean isOldNull = GeoNode.isNull(buff.nodes[nX][nY]);
if(!isOldNull && buff.nodes[nX][nY].closed)
{
return null;
}
GeoNode n = isOldNull ? GeoNode.initNode(buff, nX, nY, x, y, from._z, from, refIndex) : buff.tempNode.reuse(buff.nodes[nX][nY], from);
int height = Math.abs(n._z - from._z);
if(height > Config.PATHFIND_MAX_Z_DIFF || n._nswe == NSWE_NONE)
{
return null;
}
double weight = d ? 1.414213562373095 * Config.WEIGHT0 : Config.WEIGHT0;
if(n._nswe != NSWE_ALL || height > 16)
{
weight = Config.WEIGHT1;
}
else
// Цикл только для удобства
{
while(buff.isPlayer || Config.SIMPLE_PATHFIND_FOR_MOBS)
{
getHeightAndNSWE(x + 1, y, n._z);
if(buff.hNSWE[1] != NSWE_ALL || Math.abs(n._z - buff.hNSWE[0]) > 16)
{
weight = Config.WEIGHT2;
break;
}
getHeightAndNSWE(x - 1, y, n._z);
if(buff.hNSWE[1] != NSWE_ALL || Math.abs(n._z - buff.hNSWE[0]) > 16)
{
weight = Config.WEIGHT2;
break;
}
getHeightAndNSWE(x, y + 1, n._z);
if(buff.hNSWE[1] != NSWE_ALL || Math.abs(n._z - buff.hNSWE[0]) > 16)
{
weight = Config.WEIGHT2;
break;
}
getHeightAndNSWE(x, y - 1, n._z);
if(buff.hNSWE[1] != NSWE_ALL || Math.abs(n._z - buff.hNSWE[0]) > 16)
{
weight = Config.WEIGHT2;
break;
}
break;
}
}
int diffx = buff.endpoint.x - x;
int diffy = buff.endpoint.y - y;
//int diffx = Math.abs(buff.endpoint.x - x);
//int diffy = Math.abs(buff.endpoint.y - y);
int dz = Math.abs(buff.endpoint.z - n._z);
n.moveCost += from.moveCost + weight;
n.score = n.moveCost + (Config.PATHFIND_DIAGONAL ? Math.sqrt(diffx * diffx + diffy * diffy + dz * dz / 256) : Math.abs(diffx) + Math.abs(diffy) + dz / 16); // 256 = 16*16
//n.score = n.moveCost + diffx + diffy + dz / 16;
if(x == buff.endpoint.x && y == buff.endpoint.y && dz < 64)
{
return n;
} // ура, мы дошли до точки назначения :)
if(isOldNull)
{
if(buff.currentNode == null)
{
buff.firstNode.link = n;
}
else
{
buff.currentNode.link = n;
}
buff.currentNode = n;
if(custom_debug && Config.PATHFIND_DEBUG)
{
addDebugItem(57, 1, n.getLoc().geo2world());
}
} // если !isOldNull, значит эта клетка уже присутствует, в n находится временный Node содержимое которого нужно скопировать
else if(n.moveCost < buff.nodes[nX][nY].moveCost)
{
buff.nodes[nX][nY].copy(n);