/** * Get diff between two landscapes * * @param landscape * To compare * @param landscape2 * To compare * @return diff */ public static int getMaxHeightDiff(ELandscapeType landscape, ELandscapeType landscape2) { return landscape.isWater() || landscape == ELandscapeType.MOOR || landscape == ELandscapeType.MOORINNER || landscape2.isWater() || landscape2 == ELandscapeType.MOOR || landscape2 == ELandscapeType.MOORINNER ? 0 : MAX_HEIGHT_DIFF; }
private void computeLandscapesFrom(ELandscapeType l1) { System.out.println("Starting to compute fades from " + l1.toString()); ELandscapeType[][] ways = fadeLandscapesBuffer[l1.ordinal()]; ways[l1.ordinal()] = new ELandscapeType[] { l1 }; boolean foundnew = true; while (foundnew) { foundnew = false; for (FadableLandscapes f : allowed) { int ordinal1 = f.getL1().ordinal(); int ordinal2 = f.getL2().ordinal(); if (ways[ordinal1] == null && ways[ordinal2] != null) { ways[ordinal1] = add(ways[ordinal2], f.getL1()); foundnew = true; } if (ways[ordinal2] == null && ways[ordinal1] != null) { ways[ordinal2] = add(ways[ordinal1], f.getL2()); foundnew = true; } } } }
index = outer.getImageNumber(); useSecond = false; // force!
/** * Gets an array of landscapes that can be used to fade between one landscape type and the other. Contains the first and last landscape (or only * one element if the landscape is the same. * <p> * Returns null if there is no way the landscapes can be faded. * * @param l1 * @param l2 * @return */ public ELandscapeType[] getLandscapesBetween(ELandscapeType l1, ELandscapeType l2) { ELandscapeType[] buffered = fadeLandscapesBuffer[l1.ordinal()][l2.ordinal()]; if (buffered == null) { computeLandscapesFrom(l1); buffered = fadeLandscapesBuffer[l1.ordinal()][l2.ordinal()]; // int length = buffered.length; // ELandscapeType[] reverse = new ELandscapeType[length]; // for (int i = 0; i < length; i++) { // reverse[i] = buffered[length - 1 - i]; // } // fadeLandscapesBuffer[l2.ordinal()][l1.ordinal()] = reverse; } return buffered; }
@Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); ELandscapeType type = (ELandscapeType) value; setIcon(new RectIcon(22, new Color(type.color.getARGB()), Color.GRAY)); setText(EditorLabels.getLabel("landscape." + type.name())); return this; } });
final boolean isTreePlantable(int x, int y) { return landscapeGrid.getLandscapeTypeAt(x, y).isGrass() && !flagsGrid.isProtected(x, y) && !hasBlockedNeighbor((short) x, (short) y); }
private void updateFreeLand(short x, short y) { if (objectsGrid.hasCuttableObject(x, y, TREE_ADULT)) { AiPositions trees = sortedCuttableObjectsInDefaultPartition.get(TREE_ADULT); if (trees == null) { trees = new AiPositions(); sortedCuttableObjectsInDefaultPartition.put(TREE_ADULT, trees); } trees.addNoCollission(x, y); } if (objectsGrid.hasCuttableObject(x, y, STONE)) { AiPositions stones = sortedCuttableObjectsInDefaultPartition.get(STONE); if (stones == null) { stones = new AiPositions(); sortedCuttableObjectsInDefaultPartition.put(STONE, stones); } stones.addNoCollission(x, y); updateNearStones(x, y); } ELandscapeType landscape = landscapeGrid.getLandscapeTypeAt(x, y); if (landscape.isRiver()) { sortedRiversInDefaultPartition.addNoCollission(x, y); } }
buildmarks.add(readRelativeTile(attributes)); } else if (TAG_GROUNDTYE.equals(tagName)) { groundtypes.add(ELandscapeType.valueOf(attributes.getValue("groundtype"))); } else if (TAG_OCCUPYER.equals(tagName)) { addOccupyer(attributes);
private short getColor(short x, short y) { ShortPoint2D current = new ShortPoint2D(x, y); final int dheight = getLandscapeHeightAround(current, false) - getLandscapeHeightAround(current, true); final float basecolor = .8f + .15f * dheight; return dataSupplier.getLandscape(x, y).getColor().toShortColor(basecolor); }
stream.writeByte(data.getLandscape(x, y).ordinal());
private void testLandscape(int x, int y, int x2, int y2) { ELandscapeType l2 = data.getLandscape(x2, y2); ELandscapeType l1 = data.getLandscape(x, y); int maxHeightDiff = getMaxHeightDiff(l1, l2); if (Math.abs(data.getLandscapeHeight(x2, y2) - data.getLandscapeHeight(x, y)) > maxHeightDiff) { ShortPoint2D p = new ShortPoint2D(x, y); addErrorMessage("landscape.height", p); landscapeFix.addPosition(p); } if (!fader.canFadeTo(l2, l1)) { String landscapeName1 = EditorLabels.getLabel("landscape." + l2.name()); String landscapeName2 = EditorLabels.getLabel("landscape." + l1.name()); addErrorMessage("landscape.wrong-pair", new ShortPoint2D(x, y), landscapeName1, landscapeName2); // this cannot be automatically fixed } if (players[x][y] != players[x2][y2]) { if (players[x][y] != -1) { borders[x][y] = true; } if (players[x2][y2] != -1) { borders[x2][y2] = true; } } }
if (landscapeGrid.getLandscapeTypeAt(x, y).isGrass()) { aiMapInformation.resourceAndGrassCount[mapInformationPlayerId][AiMapInformation.GRASS_INDEX]++;
private void updatePlayerLand(short x, short y, Player player) { byte playerId = player.playerId; PlayerStatistic playerStatistic = playerStatistics[playerId]; if (mainGrid.getFlagsGrid().isProtected(x, y)) { AbstractHexMapObject o = objectsGrid.getObjectsAt(x, y); if (o != null) { if (o.hasCuttableObject(STONE) && isCuttableByPlayer(x, y, player.playerId)) { playerStatistic.stones.addNoCollission(x, y); } else if (o.hasMapObjectTypes(TREE_GROWING, TREE_ADULT) && isCuttableByPlayer(x, y, player.playerId)) { playerStatistic.trees.addNoCollission(x, y); } } } else { playerStatistic.landToBuildOn.addNoCollission(x, y); } ELandscapeType landscape = landscapeGrid.getLandscapeTypeAt(x, y); if (landscape.isRiver()) { playerStatistic.rivers.addNoCollission(x, y); } if (objectsGrid.hasMapObjectType(x, y, EMapObjectType.WINE_GROWING, EMapObjectType.WINE_HARVESTABLE)) { playerStatistic.wineCount++; } }
private static boolean landscapeAllowsObjects(ELandscapeType type) { return !type.isWater() && type != ELandscapeType.SNOW && type != ELandscapeType.RIVER1 && type != ELandscapeType.RIVER2 && type != ELandscapeType.RIVER3 && type != ELandscapeType.RIVER4 && type != ELandscapeType.MOOR; }
@Override public void doTest() { InvalidResourceFix fix = new InvalidResourceFix(); addHeader("resource.header", fix); for (short x = 0; x < data.getWidth(); x++) { for (short y = 0; y < data.getHeight(); y++) { ELandscapeType landacape = data.getLandscape(x, y); EResourceType resource = data.getResourceType(x, y); if (data.getResourceAmount(x, y) > 0 && !mayHoldResource(landacape, resource)) { String landscapeName = EditorLabels.getLabel("landscape." + landacape.name()); String resourceName = Labels.getName(resource); ShortPoint2D p = new ShortPoint2D(x, y); addErrorMessage("resource.text", p, landscapeName, resourceName); fix.addInvalidResource(p); } } } }
int orientationIndex = up?0:1; if (aLandscape == leftLandscape && aLandscape == rightLandscape) { textureIndex = aLandscape.getImageNumber(); texturePos = ETextureOrientation.CONTINUOS[orientationIndex]; } else if (leftLandscape == rightLandscape) {
/** * Check resource type on landacape * * @param landscape * Landacape * @param resourceType * Resource * @return true if valid */ public static boolean mayHoldResource(ELandscapeType landscape, EResourceType resourceType) { if (resourceType == EResourceType.FISH) { return landscape.isWater(); } else { return landscape == ELandscapeType.MOUNTAIN || landscape == ELandscapeType.MOUNTAINBORDER; } }
} else if (!type.getGroundTypes().contains(data.getLandscape(pos.x, pos.y))) { ELandscapeType landscape = data.getLandscape(pos.x, pos.y); String landscapeName = EditorLabels.getLabel("landscape." + landscape.name()); addErrorMessage("building.wrong-landscape", pos, Labels.getName(type), landscapeName); fix.addInvalidObject(pos);
private boolean isWaterSafe(int x, int y) { return isInBounds(x, y) && landscapeGrid.getLandscapeTypeAt(x, y).isWater(); }