public int getMaxElevation() { if (maxElevation != UNDEFINED_MAX_ELEV) { return maxElevation; } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int elevation = data[(y * width) + x].getLevel(); if (maxElevation < elevation) { maxElevation = elevation; } } } return maxElevation; }
public int getMinElevation() { if (minElevation != UNDEFINED_MIN_ELEV) { return minElevation; } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int elevation = data[(y * width) + x].getLevel(); if (minElevation > elevation) { minElevation = elevation; } } } return minElevation; }
/** * Sets the hex into the location specified by the Coords. * * @param c * the Coords. * @param hex * the hex to be set into position. */ public void setHex(Coords c, IHex hex) { setHex(c.getX(), c.getY(), hex); if (hex.getLevel() < minElevation && minElevation != UNDEFINED_MIN_ELEV) { minElevation = hex.getLevel(); } if (hex.getLevel() > maxElevation && maxElevation != UNDEFINED_MAX_ELEV) { maxElevation = hex.getLevel(); } }
/** * Generates a fill gradient which is rotated and aligned properly for * the drawing area for a hex shadow effect in a lower hex. */ private final GradientPaint getElevationShadowGP(Coords src, int direction) { final IHex srcHex = game.getBoard().getHex(src); final IHex destHex = game.getBoard().getHexInDir(src, direction); if (destHex == null) return null; int ldiff = destHex.getLevel()-srcHex.getLevel(); // the shadow strength depends on the level difference, // but only to a maximum difference of 3 levels ldiff = Math.min(ldiff*5,15); Color c1 = new Color(30,30,50,255); // dark end of shadow Color c2 = new Color(50,50,70,0); // light end of shadow Point2D p1 = new Point2D.Double(41.5,-25+ldiff); Point2D p2 = new Point2D.Double(41.5,8.0+ldiff); AffineTransform t = new AffineTransform(); t.scale(scale,scale); t.rotate(Math.toRadians(direction*60),41.5,35.5); t.transform(p1,p1); t.transform(p2,p2); return(new GradientPaint(p1,c1,p2,c2)); }
/** * Generates a Shape drawing area for the hex shadow effect in a lower hex * when a higher hex is found in direction. */ private final Shape getElevationShadowArea(Coords src, int direction) { final IHex srcHex = game.getBoard().getHex(src); final IHex destHex = game.getBoard().getHexInDir(src, direction); // When at the board edge, create a shadow in hexes of level < 0 if (destHex == null) { if (srcHex.getLevel() >= 0) return null; } else { // no shadow area when the current hex is not lower than the next hex in direction if (srcHex.getLevel() >= destHex.getLevel()) return null; } return(AffineTransform.getScaleInstance(scale, scale).createTransformedShape( HexDrawUtilities.getHexBorderArea(direction, HexDrawUtilities.CUT_BORDER, 36))); }
public void changedUpdate(DocumentEvent te) { if (te.getDocument().equals(texElev.getDocument())) { int value; try { value = Integer.parseInt(texElev.getText()); } catch (NumberFormatException ex) { return; } if (value != curHex.getLevel()) { curHex.setLevel(value); repaintWorkingHex(); } } else if (te.getDocument().equals(texTheme.getDocument())) { curHex.setTheme(texTheme.getText()); repaintWorkingHex(); } }
private static void findCliffNeighbours(IBoard board, Coords c, ArrayList<Coords> candidate, HashSet<Coords> ignore) { candidate.add(c); ignore.add(c); int elevation = board.getHex(c).getLevel(); for (int dir = 0; dir < 6; dir++) { Coords t = c.translated(dir); if (board.contains(t) && !ignore.contains(t)) { if (hexCouldBeCliff(board, t)) { IHex hex = board.getHex(t); int el = hex.getLevel(); if (el == elevation) { findCliffNeighbours(board, t, candidate, ignore); } } else { ignore.add(t); } } } }
/** * Returns true if an elevation line should be drawn between the starting * hex and the hex in the direction specified. Results should be transitive, * that is, if a line is drawn in one direction, it should be drawn in the * opposite direction as well. */ private final boolean drawElevationLine(Coords src, int direction) { final IHex srcHex = game.getBoard().getHex(src); final IHex destHex = game.getBoard().getHexInDir(src, direction); if ((destHex == null) && (srcHex.getLevel() != 0)) { return true; } else if (destHex == null) { return false; } else if (srcHex.getLevel() != destHex.getLevel()) { return true; } else { return (srcHex.floor() != destHex.floor()); } }
/** * Sets the current hex * * @param hex hex to set. */ void setCurrentHex(IHex hex) { curHex = hex.duplicate(); texElev.setText(Integer.toString(curHex.getLevel())); refreshTerrainList(); if (lisTerrain.getModel().getSize() > 0) { lisTerrain.setSelectedIndex(0); refreshTerrainFromList(); } texTheme.setText(curHex.getTheme()); repaint(); repaintWorkingHex(); }
private static boolean hexCouldBeCliff(IBoard board, Coords c) { int elevation = board.getHex(c).getLevel(); boolean higher = false; boolean lower = false; int count = 0; for (int dir = 0; dir < 6; dir++) { Coords t = c.translated(dir); if (board.contains(t)) { IHex hex = board.getHex(t); int el = hex.getLevel(); if (el > elevation) { lower = true; } else if (el < elevation) { higher = true; } else { count++; } } } return higher && lower && (count <= 3) && (count > 0); }
/** * Returns the absolute position of the upper-left hand corner of the hex * graphic */ private Point getHexLocation(int x, int y, boolean ignoreElevation) { float elevationAdjust = 0.0f; IHex hex = game.getBoard().getHex(x, y); if ((hex != null) && useIsometric() && !ignoreElevation) { int level = hex.getLevel(); if (level != 0) { elevationAdjust = level * HEX_ELEV * scale * -1.0f; } } int ypos = (y * (int) (HEX_H * scale)) + ((x & 1) == 1 ? (int) ((HEX_H / 2) * scale) : 0); return new Point(x * (int) (HEX_WC * scale), ypos + (int) elevationAdjust); }
/** * Returns the highest elevation in the current path * * @return */ public int getMaxElevation() { int maxElev = 0; for (MoveStep step : steps) { maxElev = Math.max(maxElev, getGame().getBoard().getHex(step.getPosition()).getLevel()); } return maxElev; }
public static ArrayList<Coords> getAcceptableUnloadPositions( ArrayList<Coords> ring, Entity unit, IGame game, int elev) { ArrayList<Coords> acceptable = new ArrayList<Coords>(); for (Coords pos : ring) { IHex hex = game.getBoard().getHex(pos); if (null == hex) { continue; } // no stacking violations, no prohibited terrain, and within 2 // elevations if (!unit.isLocationProhibited(pos) && (null == stackingViolation(game, unit.getId(), pos)) && (Math.abs(hex.getLevel() - elev) < 3)) { acceptable.add(pos); } } return acceptable; }
/** * @param hex * @return true if it is reasonable to build on this hex */ private boolean isHexBuildable(IHex hex) { if (hex.containsTerrain(Terrains.WATER) || hex.containsTerrain(Terrains.IMPASSABLE) || hex.containsTerrain(Terrains.MAGMA) || hex.containsTerrain(Terrains.SWAMP)) { return false; // uneconomic to build here } if (hex.getLevel() >= 4) { return false; // don't build on mountaintops (aesthetics) } return true; }
/** * Returns the distance between the highest elevation in the jump path and * the elevation at the landing point. This gives the largest distance the * unit has fallen during the jump. */ public int getJumpMaxElevationChange() { return getMaxElevation() - getGame().getBoard().getHex(getFinalCoords()).getLevel(); }
/** * Apply the current Hex to the Board at the specified location. */ public void resurfaceHex(Coords c) { if (board.contains(c)) { IHex newHex = curHex.duplicate(); newHex.setLevel(board.getHex(c).getLevel()); board.resetStoredElevation(); board.setHex(c, newHex); } }
/** * Helper function that calculates the effective elevation for a unit standing there. * @param hex The hex to check * @param entity The entity to check * @return The effective elevation */ private int calculateUnitElevationInHex(IHex hex, Entity entity) { // we calculate the height of a hex as "on the ground" by default // Special exceptions: // We are a mech, which can hopping on top of some buildings // We are naval unit going under a bridge, in which case the height is the water level (naval units go on the surface, mostly) // We are non-naval going into water but not onto a bridge, in which case the height is the floor (mechs sink to the bottom) int hexElevation = hex.getLevel(); if(entity.hasETypeFlag(Entity.ETYPE_MECH) && hex.containsTerrain(Terrains.BLDG_CF)) { hexElevation = hex.ceiling(); } else if(entity.isNaval() && hex.containsTerrain(Terrains.BRIDGE)) { hexElevation = hex.getLevel(); } else if(!entity.isSurfaceNaval() && hex.containsTerrain(Terrains.WATER) && !hex.containsTerrain(Terrains.BRIDGE)) { hexElevation = hex.floor(); } return hexElevation; }
/** * Returns the highest elevation along a jump path. * * @return */ public Coords getJumpPathHighestPoint() { Coords highestCoords = null; int highestElevation = 0; for (MoveStep step : steps) { if (getGame().getBoard().getHex(step.getPosition()).getLevel() > highestElevation) { highestElevation = step.getElevation(); highestCoords = step.getPosition(); } } return highestCoords; }
private void addBridge(IHex hex, int exits, int altitude, int cf) { ITerrainFactory tf = Terrains.getTerrainFactory(); int bridgeElevation = altitude - hex.getLevel(); hex.addTerrain(tf.createTerrain(Terrains.BRIDGE, getBuildingTypeByCF(cf), true, (exits & 63))); hex.addTerrain(tf.createTerrain(Terrains.BRIDGE_ELEV, bridgeElevation)); hex.addTerrain(tf.createTerrain(Terrains.BRIDGE_CF, cf)); }
/** * Apply the current Hex to the Board at the specified location. */ public void addToHex(Coords c) { if (board.contains(c)) { IHex newHex = curHex.duplicate(); IHex oldHex = board.getHex(c); newHex.setLevel(oldHex.getLevel()); int terrainTypes[] = oldHex.getTerrainTypes(); for (int i = 0; i < terrainTypes.length; i++) { int terrainID = terrainTypes[i]; if (!newHex.containsTerrain(terrainID) && oldHex.containsTerrain(terrainID)) { newHex.addTerrain(oldHex.getTerrain(terrainID)); } } board.resetStoredElevation(); board.setHex(c, newHex); } }