/** * Do the obstruction check of a tile. So this means that all tiles are hidden in case there is a * tile above them and they are fully invisible anyway. Tiles below the level of the player are * removed, since they won't be displayed ever anyway. The tiles at or above the players location * are possibly shown in case the char steps into a building or something. * * @param tile the tile that is checked * @param key the location key of the checked tile * @return <code>true</code> in case the tile got removed */ private boolean checkObstruction(final MapTile tile, final long key) { final Location playerLoc = World.getPlayer().getLocation(); final Location tileLoc = tile.getLocation(); final int topLimit = playerLoc.getScZ() + 2; int currX = tileLoc.getScX(); int currY = tileLoc.getScY(); int currZ = tileLoc.getScZ(); while (currZ < topLimit) { currX -= MapDisplayManager.TILE_PERSPECTIVE_OFFSET; currY += MapDisplayManager.TILE_PERSPECTIVE_OFFSET; currZ++; final boolean remove = (currZ < (topLimit - 2)); final MapTile foundTile = parent.getMapAt(currX, currY, currZ); if ((foundTile != null) && foundTile.isOpaque() && !foundTile.isHidden()) { if (remove) { parent.removeTile(key); return true; } tile.setObstructed(true); return false; } } if (tile.isObstructed()) { tile.setObstructed(false); addAllBelow(tileLoc, playerLoc.getScZ() - 2); } return false; }
/** * Search all surrounding tiles and the tile below and look for a tile that is currently hidden. * * @param searchLoc the location where the search starts * @return <code>true</code> in case a hidden tile was found */ private boolean searchHiddenNeighbour(final Location searchLoc) { for (int x = -1; x < 2; x++) { for (int y = -1; y < 2; y++) { if ((x == 0) && (y == 0)) { continue; } final MapTile foundTile = parent.getMapAt(searchLoc.getScX() + x, searchLoc.getScY() + y, searchLoc.getScZ()); if ((foundTile != null) && foundTile.isHidden()) { return true; } } } MapTile foundTile = parent.getMapAt(searchLoc.getScX(), searchLoc.getScY(), searchLoc.getScZ() + 1); if ((foundTile != null) && foundTile.isHidden()) { return true; } foundTile = parent.getMapAt(searchLoc.getScX(), searchLoc.getScY(), searchLoc.getScZ() - 1); return (foundTile != null) && foundTile.isHidden(); }
/** * Check if the tile needs to be hidden because the player is inside a cave or a house or * something like this. * * @param tile the tile that is checked * @param key the location key of the checked tile * @return <code>true</code> in case the tile was handled */ @SuppressWarnings("nls") private boolean checkHidden(final MapTile tile, final long key) { final Location playerLoc = World.getPlayer().getLocation(); final Location tileLoc = tile.getLocation(); if ((playerLoc == null) || (tileLoc == null)) { // something is very wrong. Put this entry back into the unchecked // list and try it again later. reportUnchecked(key); return true; } /* * And now we start with the inside check. In case the tile is below the * level of the player its never hidden for sure. */ if (tileLoc.getScZ() <= playerLoc.getScZ()) { if (tile.isHidden()) { tile.setHidden(false); addAllBelow(tileLoc, playerLoc.getScZ() - 2); addAllNeighbours(tileLoc); } return true; } /* * Now generate the index in the list of inside states and check if the * tile is on a level that is hidden or not. If the tile is on such a * level it does not mean for sure that it really needs to be hidden. */ final int insideIndex = tileLoc.getScZ() - playerLoc.getScZ() - 1; if ((insideIndex < 0) || (insideIndex > 1)) { LOGGER.warn("Invalid inside index: " + insideIndex); return true; } /* * Tile is not on a inside level. In case its hidden, show it again. */ if (!insideStates[insideIndex]) { if (tile.isHidden()) { tile.setHidden(false); addAllBelow(tileLoc, playerLoc.getScZ() - 2); addAllAbove(tileLoc, playerLoc.getScZ() + 2); addAllNeighbours(tileLoc); } return true; } /* * Now check if the tile is directly above the player. In this case it * needs to be hidden. */ if ((tileLoc.getScX() == playerLoc.getScX()) && (tileLoc.getScY() == playerLoc.getScY()) && (tileLoc.getScZ() > playerLoc.getScZ()) && !tile.isHidden()) { tile.setHidden(true); addAllBelow(tileLoc, playerLoc.getScZ() - 2); addAllAbove(tileLoc, playerLoc.getScZ() + 2); addAllNeighbours(tileLoc); return true; } if (!tile.isHidden() && searchHiddenNeighbour(tileLoc)) { tile.setHidden(true); addAllBelow(tileLoc, playerLoc.getScZ() - 2); addAllAbove(tileLoc, playerLoc.getScZ() + 2); addAllNeighbours(tileLoc); return true; } return false; }