Exemplo n.º 1
0
  public void calcSurroundingTile(TileInfo tile, int cX, int cY) {

    // Whee integers
    int newX = tile.tileX + cX;
    int newY = tile.tileY + cY;

    // Whee out of bounds checking
    if (newX < 0 || newY < 0 || newX >= passable.length || newY >= passable[0].length) {
      return;
    }

    // Now we take that surrounding tile from the SUPER LIST.
    TileInfo surroundingTile = superList[newX][newY];
    // And calculate how much it costs to move to the surrounding tile from
    // the original tile (assuming we are taking the path that goes to the
    // TileInfo tile)
    int toTileCost = (cX != 0 && cY != 0 ? 14 : 10) * passCost[newX][newY];

    // Now if we pulled a null from the superlist, we MAKE IT NOT NULL
    // ANYMORE.
    // How? BY MAKING A NEW TILEINFO THING. YEAH. TOTALLY.
    if (surroundingTile == null) {
      // We are happy to include all tiles of all types in the superlist.
      surroundingTile =
          new TileInfo(
              newX,
              newY,
              tile,
              tile.cost + toTileCost,
              getHeuristicScore(newX, newY, destX, destY));
      superList[newX][newY] = surroundingTile;
      // But if its one of those dirty, unpassable tiles... then we don't
      // want it in the open list.
      if (passable[newX][newY]) {
        // PURE AND PASSABLE TILES ONLY.
        openList.add(surroundingTile);
      }
    } else if (surroundingTile.cost > tile.cost + toTileCost) {
      // If it so happens that the cost we calculated to this tile was
      // cheaper than the cost calculated to that tile from before,
      // then by all means, the quickest way to this tile is by the tile
      // we just came from.
      surroundingTile.parentTile = tile;
      // Resort here?
      // Nah.
    }
  }