/** * Retrieve all cities provieded by {@link IMap}. * @return list of all cities. */ public List<ICity> getAllCities(){ return map.getCities(); }
public double convertToDistenceInKm(double nbPixels) { double nbPixelsPerKilometer = map.getNumberOfPixelPerKilometer(); return nbPixels/nbPixelsPerKilometer; }
/** * Add the settlement for the player. A settlement is a new town to be founded and * cannot yet be traded with. It is only reachable for the player. * @param city to be founded * @param player for which this city is reachable */ public void buildSettlement(ICity city, IPlayer player) { map.getTownsInFounding().put(player, city); }
/** * Find trade routes with the <code>city</code> as the second stop. * @param city of the second stop of the trade route. * @return List of applicable trade routes. */ public List<ITradeRoute> findTradeRoutesSecondStop(ICity city) { List<ITradeRoute> routes = new ArrayList<>(); for (ITradeRoute route : map.getTradeRoutes()) { List<ITradeRouteStop> stops = new ArrayList<>(route.getTradeStops()); ICity stopCity = stops.get(1).getTradeStop(); if (stopCity.equals(city)) { routes.add(route); } } return routes; }
/** * {@inheritDoc}<br> * Choose the nearest city from the set defined in the trade route. * @param vessel that should travel to a city, so that the trade cycle can be reinitialized * @return */ @Override public ICity getCityToRestartTradeCycle(INavigableVessel vessel) { ITradeMissionData missionData = ((IAIPlayer)vessel.getOwner()).getTradeMission(vessel); ITradeRoute route = ((TradeRouteMissionData)missionData).getTradeRoute(); double distance = Double.MAX_VALUE; ICity destination = null; for (ITradeRouteStop stop : route.getTradeStops()) { double d = vessel.getLocation().distance(stop.getTradeStop().getCoordinates()); if (d < distance) { distance = d; destination = stop.getTradeStop(); } } return destination; }
/** 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 initialize() { mapDimension = map.getDimension(); updateSegmentSize(20); clientServerEventBus.register(this); syncServerClientEventBus.register(this); }
private MapSegmentedImage getRandomImage(List<MapSegmentedImage> imgList) { MapSegmentedImage img = imgList.get(rnd.nextInt(imgList.size())); int availableSegment = rnd.nextInt(9); img.addSegment(availableSegment); return img; } }
/** * Check if the location matches any city. * @param location to check * @return true if the <code>location</code> is in any city. */ private boolean isInCity(Point2D location) { return map.getCityCoordinates().stream().anyMatch(coord -> coord.equals(location)); }
private ICity getRandomCity() { List<ICity> cities = map.getCities(); return cities.get(rnd.nextInt(cities.size())); } @Subscribe
/** * Find trade routes with the <code>city</code> as the first stop. * @param city of the first stop of the trade route. * @return List of applicable trade routes. */ public List<ITradeRoute> findTradeRoutesFirstStop(ICity city) { List<ITradeRoute> routes = new ArrayList<>(); for (ITradeRoute route : map.getTradeRoutes()) { ITradeRouteStop stop = route.getTradeStops().iterator().next(); if (stop.getTradeStop().equals(city)) { routes.add(route); } } return routes; } /**
@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()); }
@PostConstruct void init() { maxDistanceInPixels = MAX_DISTANCE_IN_KM * map.getNumberOfPixelPerKilometer(); }
/** * 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); } } /**
/** * 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; } }
/** * 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); } }
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(); }
/** * 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; }