예제 #1
0
  private void handleNeighbour(int x, int y, GeoNode from, boolean d) {
    int nX = x - buff.offsetX, nY = y - buff.offsetY;
    if (nX >= buff.mapSize || nX < 0 || nY >= buff.mapSize || nY < 0) return;

    GeoNode n = buff.nodes[nX][nY];
    float newCost;

    if (!n.isSet()) {
      n = n.set(x, y, from.z);
      GeoEngine.NgetHeightAndNSWE(x, y, from.z, hNSWE, geoIndex);
      n.z = hNSWE[0];
      n.nswe = hNSWE[1];
    }

    int height = Math.abs(n.z - from.z);
    if (height > Config.PATHFIND_MAX_Z_DIFF || n.nswe == NSWE_NONE) return;

    newCost = from.costFromStart + traverseCost(from, n, d);
    if (n.state == GeoNode.OPENED || n.state == GeoNode.CLOSED) {
      if (n.costFromStart <= newCost) return;
    }

    if (n.state == GeoNode.NONE) n.costToEnd = pathCostEstimate(n);

    n.parent = from;
    n.costFromStart = newCost;
    n.totalCost = n.costFromStart + n.costToEnd;

    if (n.state == GeoNode.OPENED) return;

    n.state = GeoNode.OPENED;
    buff.open.add(n);
  }
예제 #2
0
  private void getHeightAndNSWE(int x, int y, short z) {
    int nX = x - buff.offsetX, nY = y - buff.offsetY;
    if (nX >= buff.mapSize || nX < 0 || nY >= buff.mapSize || nY < 0) {
      hNSWE[1] = NSWE_NONE; // Затычка
      return;
    }

    GeoNode n = buff.nodes[nX][nY];
    if (!n.isSet()) {
      n = n.set(x, y, z);
      GeoEngine.NgetHeightAndNSWE(x, y, z, hNSWE, geoIndex);
      n.z = hNSWE[0];
      n.nswe = hNSWE[1];
    } else {
      hNSWE[0] = n.z;
      hNSWE[1] = n.nswe;
    }
  }