/** * 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; }
/** * 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; }
/** * Do the clipping check of a tile. * * @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 clipped away */ private boolean checkClipping(final MapTile tile, final long key) { if (!World.getPlayer().hasValidLocation()) { return false; } final Location playerLoc = World.getPlayer().getLocation(); final Location tileLoc = tile.getLocation(); /* * Start checking the clipping of the tiles. In case a tile is found * outside the clipping range, its deleted. */ if ((playerLoc.getScZ() + 2) < tileLoc.getScZ()) { parent.removeTile(key); LOGGER.debug("Removed tile at location " + tileLoc.toString() + " (tile.x > player.z + 2)"); return true; } if ((playerLoc.getScZ() - 2) > tileLoc.getScZ()) { parent.removeTile(key); LOGGER.debug("Removed tile at location " + tileLoc.toString() + " (tile.x < player.z - 2)"); return true; } final MapDimensions mapDim = MapDimensions.getInstance(); if ((playerLoc.getCol() + mapDim.getClippingOffsetLeft()) > tileLoc.getCol()) { parent.removeTile(key); LOGGER.debug( "Removed tile at location " + tileLoc.toString() + " (outside of left clipping)"); LOGGER.debug( "Ply Col: " + Integer.toString(playerLoc.getCol()) + " Clipping Left: " + Integer.toString(mapDim.getClippingOffsetLeft()) + " Tile Col: " + Integer.toString(tileLoc.getCol())); return true; } if ((playerLoc.getCol() + mapDim.getClippingOffsetRight()) < tileLoc.getCol()) { parent.removeTile(key); LOGGER.debug( "Removed tile at location " + tileLoc.toString() + " (outside of right clipping)"); LOGGER.debug( "Ply Col: " + Integer.toString(playerLoc.getCol()) + " Clipping Right: " + Integer.toString(mapDim.getClippingOffsetRight()) + " Tile Col: " + Integer.toString(tileLoc.getCol())); return true; } final int level = Math.abs(tileLoc.getScZ() - playerLoc.getScZ()) * 6; if ((playerLoc.getRow() + mapDim.getClippingOffsetTop()) < (tileLoc.getRow() - level)) { parent.removeTile(key); LOGGER.debug("Removed tile at location " + tileLoc.toString() + " (outside of top clipping)"); LOGGER.debug( "Ply Row: " + Integer.toString(playerLoc.getRow()) + " Clipping Top: " + Integer.toString(mapDim.getClippingOffsetTop()) + " Tile Row: " + Integer.toString(tileLoc.getRow())); return true; } if ((playerLoc.getRow() + mapDim.getClippingOffsetBottom()) > (tileLoc.getRow() + level)) { parent.removeTile(key); LOGGER.debug( "Removed tile at location " + tileLoc.toString() + " (outside of bottom clipping)"); LOGGER.debug( "Ply Row: " + Integer.toString(playerLoc.getRow()) + " Clipping Bottom: " + Integer.toString(mapDim.getClippingOffsetBottom()) + " Tile Row: " + Integer.toString(tileLoc.getRow())); return true; } return false; }