/** * 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; }
/** * 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; }
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; } } } }
@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; } });
index = outer.getImageNumber(); useSecond = false; // force!
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);
final boolean isTreePlantable(int x, int y) { return landscapeGrid.getLandscapeTypeAt(x, y).isGrass() && !flagsGrid.isProtected(x, y) && !hasBlockedNeighbor((short) x, (short) y); }
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); }
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; }
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; } } }
int orientationIndex = up?0:1; if (aLandscape == leftLandscape && aLandscape == rightLandscape) { textureIndex = aLandscape.getImageNumber(); texturePos = ETextureOrientation.CONTINUOS[orientationIndex]; } else if (leftLandscape == rightLandscape) {
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++; } }
/** * 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; } }
@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); } } } }
private boolean isWaterSafe(int x, int y) { return isInBounds(x, y) && landscapeGrid.getLandscapeTypeAt(x, y).isWater(); }
} 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);
@Override public DockPosition findValidDockPosition(ShortPoint2D requestedPosition, ShortPoint2D buildingPosition, int maximumDistance) { if (!isWaterSafe(requestedPosition.x, requestedPosition.y)) { return null; // requested position is not in water } short buildingPartition = partitionsGrid.getPartitionIdAt(buildingPosition.x, buildingPosition.y); Optional<ShortPoint2D> coastPosition = HexGridArea .stream(requestedPosition.x, requestedPosition.y, 0, 10) .filterBounds(width, height) .filter((x, y) -> ShortPoint2D.getOnGridDist(buildingPosition.x, buildingPosition.y, x, y) <= maximumDistance) .filter((x, y) -> !landscapeGrid.getLandscapeTypeAt(x, y).isWater()) .filter((x, y) -> partitionsGrid.getPartitionIdAt(x, y) == buildingPartition) // ensure the dock is the same partition (accessible by worker of building) .filter((x, y) -> { // check that the dock goes from land to water EDirection direction = EDirection.getApproxDirection(x, y, requestedPosition.x, requestedPosition.y); ShortPoint2D firstDockWaterPosition = direction.getNextHexPoint(x, y); ShortPoint2D secondDockWaterPosition = direction.getNextHexPoint(firstDockWaterPosition.x, firstDockWaterPosition.y); return isWaterSafe(firstDockWaterPosition.x, firstDockWaterPosition.y) && isWaterSafe(secondDockWaterPosition.x, secondDockWaterPosition.y); }) .getFirst(); if (!coastPosition.isPresent()) { return null; } EDirection direction = EDirection.getApproxDirection(coastPosition.get(), requestedPosition); return new DockPosition(coastPosition.get(), direction); }
@Override public FerryEntrance ferryAtPosition(ShortPoint2D position, byte playerId) { Optional<ILogicMovable> ferryOptional = HexGridArea.stream(position.x, position.y, 0, Constants.MAX_FERRY_ENTRANCE_SEARCH_DISTANCE) .filterBounds(width, height) .filter((x, y) -> landscapeGrid.getLandscapeTypeAt(x, y).isWater()) .iterateForResult((x, y) -> { ILogicMovable movable = movableGrid.getMovableAt(x, y); return Optional.ofNullable(movable).filter(m -> m.getMovableType() == EMovableType.FERRY); }); if (!ferryOptional.isPresent()) { return null; } ILogicMovable ferry = ferryOptional.get(); ShortPoint2D ferryPosition = ferry.getPosition(); Optional<ShortPoint2D> entranceOptional = HexGridArea.stream(ferryPosition.x, ferryPosition.y, 0, Constants.MAX_FERRY_ENTRANCE_SEARCH_DISTANCE) .filterBounds(width, height) .filter((x, y) -> !isBlocked(x, y)) .getFirst(); if (!entranceOptional.isPresent()) { return null; } return new FerryEntrance(ferry, entranceOptional.get()); }