/** * 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; }
/** * 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; } /**
/** * {@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; }
ICity firstCity = ((TradeRouteMissionData) missionData).getTradeRoute().getTradeStops().iterator().next().getTradeStop(); if (firstCity.equals(city)){ AggregatesDumpTradeStep dumpStep = createAggregatedDumpStep(vessel, city, loadedWares); for (Iterator<ITradeRouteStop> iterator = route.getTradeStops().iterator(); iterator.hasNext(); ) { ITradeRouteStop routeStop = iterator.next(); if (routeStop.getTradeStop().equals(city)){ stop = routeStop; if (iterator.hasNext()) { routeStop = iterator.next(); nextStop = routeStop.getTradeStop(); } else { nextStop = route.getTradeStops().iterator().next().getTradeStop(); // first