/** * Retrieve all cities provieded by {@link IMap}. * @return list of all cities. */ public List<ICity> getAllCities(){ return map.getCities(); }
@VisibleForTesting ICity calculateCostructionCity() { double width = map.getDimension().getWidth(); List<ICity> chosableCities = map.getCities().stream() .filter(city -> city.getCoordinates().getX() < width * 0.5) .collect(toList()); return chosableCities.get(rnd.nextInt(chosableCities.size())); } }
/** * Find up to <code>numberOfCities</code> random cities that are not the excluded one. * @param exclude city that should be ignored * @param numberOfCities number of cities in the list. If the number is bigger than the max amount of cities on the * map, only that amount minus one will be used. * @return list of cities with the specified number. */ public List<ICity> findRandomCities(ICity exclude, int numberOfCities) { int max = Math.min(map.getNumberCities() - 1, numberOfCities); List<ICity> selected = new ArrayList<>(); selected.add(exclude); while (selected.size() < max + 1) { ICity next = findRandomCity(selected); selected.add(next); } selected.remove(exclude); return selected; }
/** * A founded settlement is complete and becomes a town. Thereby it is reachable for anyone. * @param city that became a town */ public void settlementBecomesTown(ICity city) { map.add(city); Multimap<IPlayer, ICity> townsInFounding = map.getTownsInFounding(); for (Iterator<IPlayer> iterator = townsInFounding.keySet().iterator(); iterator.hasNext(); ) { IPlayer player = iterator.next(); if (townsInFounding.get(player).equals(city)) { Collection<ICity> cities = townsInFounding.get(player); cities.remove(city); if (cities.isEmpty()) { iterator.remove(); } break; } } clientServerEventBus.post(new FoundingCityBecomesAccessible(city)); }
@PostConstruct void initialize() { mapDimension = map.getDimension(); updateSegmentSize(20); clientServerEventBus.register(this); syncServerClientEventBus.register(this); }
firstName = maleFirstNameLoader.getRandomName(); ICity birthPlace = map.getCities().get(rnd.nextInt(map.getNumberCities())); LocalDateTime birthDate = state.getDate() .minusYears(rnd.nextInt(15) + 15)
if (city.getPopulationBinding().get() >= 2000) { if (updateStanding) { for (ICity iCity : map.getCities()) { if (iCity.equals(city)) { iCity.getReputation(task.getPlayer()).update(50); !city2.findBuilding(IBarn.class, Optional.empty()).isEmpty()) { if (updateStanding) { for (ICity iCity : map.getCities()) { if (iCity.equals(city1)) { iCity.getReputation(task.getPlayer()).update(70); ICity city = map.findCity(concreteTask.getName()); Optional<IPlayer> absent = Optional.empty(); if (city.getPopulationBinding().get() > 1000 && !city.findBuilding(ITradingOffice.class, Optional.of(task.getPlayer())).isEmpty()) { if (updateStanding) { for (ICity iCity : map.getCities()) { if (iCity.equals(city)) { iCity.getReputation(task.getPlayer()).update(200); for (PirateNest pirateNest : map.getPirateNests()) { if (pirateNest.getLocation().equals(concreteTask.getLocation()) && pirateNest.getDefendingShips().isEmpty()) { for (ICity iCity : map.getCities()) { iCity.getReputation(task.getPlayer()).update(80);
public double convertToDistenceInKm(double nbPixels) { double nbPixelsPerKilometer = map.getNumberOfPixelPerKilometer(); return nbPixels/nbPixelsPerKilometer; }
office.addTask(task, deadline, city.getPlayer()); PirateNest nest = new PirateNest(concreteTask.getLocation()); map.getPirateNests().add(nest); mapLocationDetectionModel.addSegment(concreteTask.getPirateNestMap());
if (oldLocation.distance(source)< ShipService.CITY_RADIUS && newLocation.distance(source) >= ShipService.CITY_RADIUS) { Optional<ICity> city = map.findCity(source); if (city.isPresent()){ clientServerEventBus.post(new ShipLeavingPort(vessel, city.get())); if (newLocation.distance(destination) <= ShipService.CITY_RADIUS && oldLocation.distance(destination) > ShipService.CITY_RADIUS) { Optional<ICity> city = map.findCity(destination); if (city.isPresent()) { clientServerEventBus.post(new ShipNearingPortEvent(vessel, city.get())); if (value.isDestinationCity()) { Optional<ICity> city = map.findCity(destination); if (city.isPresent()) { clientServerEventBus.post(new ShipEntersPortEvent(vessel, city.get()));
@Override public List<ICity> findListWithConsumptionMinimalDistance(ICity distanceToCity, IWare ware, INavigableVessel vessel) { TreeMap<Double, ICity> cityMap = new TreeMap<>(); List<ICity> reachableCities = proxy.getAllReachableNonBlockadedCities(vessel); double mapWidth = map.getDimension().getWidth(); for (ICity city : productionAndConsumption.keySet() ) { if (!city.equals(distanceToCity)) { int consumptionAmount = productionAndConsumption.get(city).getConsumptionAmount(ware); double distance = distanceToCity.getCoordinates().distance(city.getCoordinates()); double distanceFactor = distance/mapWidth; if (reachableCities.contains(city)) { cityMap.put(1 / (distanceFactor * consumptionAmount), city); } } } return cityMap.values().stream().collect(Collectors.toList()); }
msg = new DisplayMessage("ch.sahits.game.openpatrician.engine.land.city.CityHallEngine.yesViolationFine", new Object[]{violation.getCity().getName(), fine}); otherTreasury.subtractOtherCosts(fine); int cashPerCity = fine / (map.getNumberCities() - 1); for (ICity city : map.getCities()) { if (city.equals(otherCity)) { continue;
@PostConstruct void init() { maxDistanceInPixels = MAX_DISTANCE_IN_KM * map.getNumberOfPixelPerKilometer(); }
EShipType type = shipService.getShipType(vessel); if (type == EShipType.HOLK || type == EShipType.COG) { Optional<ICity> optCity = map.findCity(destination); optCity.ifPresent(iCity -> { ICity city = iCity;
private ICity getRandomCity() { List<ICity> cities = map.getCities(); return cities.get(rnd.nextInt(cities.size())); } @Subscribe
@VisibleForTesting ICity calculateCostructionCity() { double width = map.getDimension().getWidth(); List<ICity> chosableCities = map.getCities().stream() .filter(city -> city.getCoordinates().getX() < width * 0.5) .collect(toList()); return chosableCities.get(rnd.nextInt(chosableCities.size())); } }
@Override public List<ICity> findListWithProductionsMinimalDistance(ICity distanceToCity, IWare ware, INavigableVessel vessel) { TreeMap<Double, ICity> cityMap = new TreeMap<>(); List<ICity> reachableCities = proxy.getAllReachableNonBlockadedCities(vessel); double mapWidth = map.getDimension().getWidth(); for (ICity city : productionAndConsumption.keySet() ) { if (!city.equals(distanceToCity)) { int productionAmount = productionAndConsumption.get(city).getProductionAmount(ware); double distance = distanceToCity.getCoordinates().distance(city.getCoordinates()); double distanceFactor = distance/mapWidth; if (reachableCities.contains(city)) { cityMap.put(1 / (distanceFactor * productionAmount), city); } } } return cityMap.values().stream().collect(Collectors.toList()); }
/** Timer that let the game time progress */ public void startGame(IGame game, int nbHumanPlayers) { this.game = game; numberOfPlayers = game.getMap().getNumberCities() + nbHumanPlayers; if (!started) { timer.start(); } started = true; } /**
@PostConstruct void init() { maxDistanceInPixels = MAX_DISTANCE_IN_KM * map.getNumberOfPixelPerKilometer(); }
private List<ITradingOffice> findTradingOddices(IPlayer player) { return map.getCities().stream() .map(player::findTradingOffice) .filter(Optional::isPresent) .map(Optional::get) .collect(toList()); }