/** * Retrieve all cities provieded by {@link IMap}. * @return list of all cities. */ public List<ICity> getAllCities(){ return map.getCities(); }
private ICity getRandomCity() { List<ICity> cities = map.getCities(); return cities.get(rnd.nextInt(cities.size())); } @Subscribe
private List<ITradingOffice> findTradingOddices(IPlayer player) { return map.getCities().stream() .map(player::findTradingOffice) .filter(Optional::isPresent) .map(Optional::get) .collect(toList()); }
/** * Retrieve a list of all cities that are reachable for the vessel. * @param vessel for which the reachability is to be checked. * @return List of reachable cities. */ public List<ICity> getAllReachableCities(INavigableVessel vessel) { List<ICity> cities = new ArrayList<>(map.getCities()); return getReachableCities(vessel, cities); }
@PostConstruct private void init() { for (ICity city : map.getCities()) { buyWaresForNextWeek(city); } } /**
@VisibleForTesting ICity calculateCostructionCity(IAIPlayer player) { List<ICity> chosableCities = map.getCities().stream() .filter(city -> player.findTradingOffice(city).isPresent()) .collect(toList()); return chosableCities.get(rnd.nextInt(chosableCities.size())); } }
@VisibleForTesting ICity calculateCostructionCity(IAIPlayer player) { List<ICity> chosableCities = map.getCities().stream() .filter(city -> player.findTradingOffice(city).isPresent()) .collect(toList()); return chosableCities.get(rnd.nextInt(chosableCities.size())); } }
/** * Retrieve all cities provided by {@link IMap}, that are * currently not under a blockade. * @return list of all non blockaded cities. */ public List<ICity> getAllNonBlockedCities() { List<ICity> cities = new ArrayList<>(map.getCities()); for (Entry<ICity, IBlockade> entry : blockade.entrySet()) { cities.remove(entry.getKey()); } return cities; } }
@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())); } }
/** * Create the remaining players as artificial players * @param nbAIPlayers number of AI players * @param initialcash initial cash amount */ private void createAndInitAIPlayers(int nbAIPlayers, long initialcash) { List<ICity> cities = game.getMap().getCities(); int cityIndex=0; for (int i = 0; i <nbAIPlayers; i++) { gameFactory.createAIPlayer(cities.get(cityIndex++),initialcash); } }
@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())); } }
private Optional<ICity> findCity(double unscaledX, double unscaledY) { Point2D p = new Point2D(unscaledX, unscaledY); for (ICity city : map.getCities()) { double distance = p.distance(city.getCoordinates()); if (distance <= ImageUtil.CITY_RADIUS) { return Optional.of(city); } } return Optional.empty(); }
/** * Find the city the vessel is currently in. If the vessel is not * in a city <code>empty</code> will be returned. * @param vessel for which to find the city * @return optional city, present if the <code>vessel</code> is in the city. */ public Optional<ICity> findCity(INavigableVessel vessel) { final Point2D location = vessel.getLocation(); for (ICity city : map.getCities()) { if (city.getCoordinates().equals(location)) { return Optional.of(city); } } return Optional.empty(); }
@PostConstruct @IgnoreOnDeserialisation private void init() { for (ICity city : map.getCities()) { CityProductionConsumptionKnowledge cityKnoledge = context.getBean(CityProductionConsumptionKnowledge.class); for (EWare ware : EWare.values()) { int amount = productionAndConsumptionService.getProductionOutputCurrentWeek(ware, city); cityKnoledge.updateProduction(ware, amount); amount = consume.getBasicWeeklyConsumtion(ware); cityKnoledge.updateConsumption(ware, amount); } productionAndConsumption.put(city, cityKnoledge); } }
@Override protected boolean additionalJoinRequirementsMet(IAIPlayer player, ICity city, Optional<INavigableVessel> vessel) { for (ICity otherCity : map.getCities()) { Optional<ITradingOffice> optOffice = player.findTradingOffice(otherCity); if (optOffice.isPresent()) { double distance = otherCity.getCoordinates().distance(city.getCoordinates()); if (distance < maxDistanceInPixels) { return true; } } } return false; } }
/** * Check wether the ship is nearing a city. * @param vessel to be checked * @return true if the vessel is near a city. */ public boolean isNearingCity(INavigableVessel vessel) { Point2D location = vessel.getLocation(); for (ICity city : map.getCities()) { Point2D coordinates = city.getCoordinates(); double distance = coordinates.distance(location); if (distance <= CITY_RADIUS) { return true; } } return false; }
private void updateReputationDueToPirateDefeat(INavigableVessel pirateVessel, INavigableVessel playerVessel) { if (pirateVessel.getOwner() instanceof ISeaPirate && playerVessel.getOwner() instanceof IPlayer) { if (!piratesState.getAllPirates().contains(pirateVessel.getOwner())) { IPlayer player = (IPlayer) playerVessel.getOwner(); for (ICity city : map.getCities()) { city.getReputation(player).update(15); // If the distruction was a Alderman task the increase is larger } } } } }
/** * Start the engine. This should be called after all cities were added. * @param game that is started */ public void start(IGame game){ for (ICity city : game.getMap().getCities()) { CityState cityState = gameFactory.getCityState(city); city.setCityState(cityState); addCity(city); } citiesState.init(); state=STARTED; }
private void drawShipsInCities(Image mapImage, double scale, double x) { for (ICity city : map.getCities()) { if (city.getCoordinates().getX() >= x && city.getCoordinates().getX() <= x + mapImage.getWidth()) { List<INavigableVessel> ships = viewState.getPlayer().findShips(city); if (!ships.isEmpty()) { drawShipPresenceInCity(city); } } } }
private void drawCityInfo(Image mapImage, double scale, double x) { for (ICity city : map.getCities()) { if (city.getCoordinates().getX() >= x && city.getCoordinates().getX() <= x + mapImage.getWidth()) { CityIcons cityIcons = new CityIcons(city.getCityState(), imageLoader); // draw below city double xPos = (city.getCoordinates().getX() - ImageUtil.CITY_RADIUS) * scale; double yPos = (city.getCoordinates().getY() + ImageUtil.CITY_RADIUS + 5) * scale; cityIcons.setScaleX(scale); cityIcons.setScaleY(scale); cityIcons.setLayoutX(xPos); cityIcons.setLayoutY(yPos); shipCanvas.getChildren().add(0, cityIcons); } } }