/** * 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 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; }
/** * 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; } }
private boolean isWaterSafe(int x, int y) { return isInBounds(x, y) && landscapeGrid.getLandscapeTypeAt(x, y).isWater(); }
@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()); }