@PostConstruct @IgnoreOnDeserialisation private void init() { for (EWare ware : EWare.values()) { if (!storedAmounts.containsKey(ware)) { storedAmounts.put(ware, 0); } } }
private List<IWare> getBasicNeededWares() { List<IWare> requiredWares = new ArrayList<>(); for (EWare ware : EWare.values()) { double sum = 0; for (EPopulationClass populationClass : EPopulationClass.values()) { sum += consume.getNeed(ware, populationClass, 1000); } if (sum > 0) { requiredWares.add(ware); } } return requiredWares; }
@VisibleForTesting Set<IWare> calculateWaresToBuy(ICity city, CentralStorageHintContext context, IProductionConsumptionKnowledge globalKnowledge) { Set<IWare> buyWares = new HashSet<>(); for (ICity c : context.getSuppliedCities()) { if (c.equals(city)) { continue; } final ICityProductionConsumptionKnowledge knowledge = globalKnowledge.getKnowlege(c); asList(EWare.values()).stream() .filter(ware -> knowledge.getConsumptionAmount(ware) > 0) .forEach(buyWares::add); } return buyWares; }
@VisibleForTesting void fillRequiredWaresAvailableBased(Map<IWare, Integer> requiredWares, CentralStorageHintContext context, ITradingOffice office) { asList(EWare.values()).stream() .filter(ware -> context.getWares().contains(ware)) .filter(ware -> !office.getSteward().isPresent() || office.getOfficeTrading().isMovableToShip(ware)) .forEach(ware -> { int availableInStore = office.getWare(ware).getAmount(); requiredWares.put(ware, availableInStore); }); } @VisibleForTesting
/** * Figure out the ware that are most needed in the city. The need is calculated upon the knowledge * of the production, consumption and sotred amount. If a ware is not consumed at all it is not needed at * all, compared to wares that have more consumption than stored + produced. * @param knowledge base knowledge * @return sorted list Pair of wares and their importants. The lower the number the more important. */ public List<Pair<IWare, Number>> getMostNeededWares(ICityProductionConsumptionKnowledge knowledge) { Preconditions.checkNotNull(knowledge, "The city production knowledge may not be null"); List<Pair<IWare, Number>> need = new ArrayList<>(); for (IWare ware : EWare.values()) { int stored = knowledge.getStoredAmount(ware); int produced = knowledge.getProductionAmount(ware); int consumed = knowledge.getConsumptionAmount(ware); int value; if (consumed == 0) { value = Integer.MAX_VALUE; } else { value = stored + produced - consumed; } need.add(new Pair<>(ware, value)); } return need.stream().sorted(new WareNeedComparator()).collect(Collectors.toList()); }
@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 public Optional<INavigableVessel> selectCollectingVessel(IAIPlayer player, EShipType shipType) { int totalAmountInBarrel = 0; for (EWare ware : EWare.values()) { int amount = shipFactory.getConstructionAmount(shipType, ware); totalAmountInBarrel += amount * ware.getSizeAsBarrels(); } for (INavigableVessel vessel : player.getSelectableVessels()) { if (vessel.getCapacity() > totalAmountInBarrel) { if (isVesselEligibleForCollecting(player, vessel)) { return Optional.of(vessel); } } } if (isVesselEligibleForCollecting(player, player.getSelectableVessels().get(0))) { return Optional.of(player.getSelectableVessels().get(0)); } else { return Optional.empty(); } }
@Override public void updateKnowledge(ICity city) { CityProductionConsumptionKnowledge knowledge = (CityProductionConsumptionKnowledge) productionAndConsumption.get(city); for (EWare ware : EWare.values()) { int amount = productionAndConsumptionService.getProductionOutputCurrentWeek(ware, city); knowledge.updateProduction(ware, amount); amount = (int) Math.floor(consume.getWeeklyConsumption(ware, city)); knowledge.updateConsumption(ware, amount); amount = city.getWare(ware).getAmount(); knowledge.updateStored(ware, amount); } }
protected CollectWaresMissionData createMissionData(IAIPlayer player) { ICity where = getConstructionCity(player); CollectConstructionWaresMissionData missionData = new CollectConstructionWaresMissionData(); missionData.setCity(where); missionData.setShipType(constructionType); for (EWare ware : EWare.values()) { int amount = shipFactory.getConstructionAmount(constructionType, ware); if (amount > 0) { Optional<ITradingOffice> optOffice = player.findTradingOffice(where); if (optOffice.isPresent()) { Optional<ISteward> steward = optOffice.get().getSteward(); tradeService.buyFromCityToStorage(optOffice.get(), player, where, ware, amount, Optional.of(ware.getMaxBuyPriceModerate()), steward); amount = Math.max(0,amount - optOffice.get().getWare(ware).getAmount()); } missionData.require(ware, amount); } } return missionData; }
/** * compute the wares consumed in the last 12 hours and remove them from the city * This method is player private for testing purposes. * @param cityState city for which the wares should be consumed. */ public void consumeWares(CityState cityState) { EWare[] wares = EWare.values(); EPopulationClass[] popClasses = EPopulationClass.values(); ICity city = cityState.getCity(); for (EWare ware : wares) { double amount = cityState.getConsumedAmount(ware); for (EPopulationClass popClass : popClasses) { amount += consume.getNeed(ware, popClass, city.getPopulation(popClass))/(7.0*2); // the amount is for a whole week } cityState.replaceConsumedAmount(ware, amount); } for (Entry<IWare, Double> entry : cityState.consumedEntries()) { if (entry.getValue() > 0) { int whole = convertToWholeNumber(entry.getValue()); if (whole >= 1) { cityState.replaceConsumedAmount(entry.getKey(), entry.getValue() - whole); city.move(entry.getKey(), -whole, null); // the city consumes the ware } } } }
/** * Check weather the vessel should return to the hometown * @param player for whom to check the returnal to the hometown * @param vessel which should return to the hometown * @return true if the vessle should return to the hometown */ @VisibleForTesting boolean shouldReturnToHometown(IAIPlayer player, INavigableVessel vessel) { if (player.getCompany().getCash() < lowMoney) { return true; } else { List<IWare> waresOfInterest = ((SupplyCityMissionData) player.getTradeMission(vessel)).getRequiredWares(); if (vessel.getCapacity() == 0) { for (EWare ware : EWare.values()) { if (vessel.getWare(ware).getAmount() > 0 && !waresOfInterest.contains(ware)) { return false; } } return true; } else { return false; } } }
@Override protected boolean checkAllWaresCollected(ICity city, INavigableVessel vessel, CollectWaresMissionData tradeMission, Optional<ITradingOffice> tradingOffice) { boolean haveEverything; haveEverything = true; for (EWare ware : EWare.values()) { int amount = shipFactory.getConstructionAmount(((CollectConstructionWaresMissionData)tradeMission).getShipType(), ware); // check amount on ship and in storage and city if (amount > 0) { int availableAmount = 0; if (tradingOffice.isPresent()) { availableAmount += tradingOffice.get().getWare(ware).getAmount(); } availableAmount += vessel.getWare(ware).getAmount(); availableAmount += city.getWare(ware).getAmount(); if (availableAmount < amount) { haveEverything = false; break; } } } return haveEverything; } }
IBalanceSheet balanceSheet = office.getCurrentWeek(); for (EWare ware : EWare.values()) { if (automatedTrading.tradingTypeProperty(ware).get() == ETradeType.CITY_OFFICE) {
EWare[] wares = EWare.values(); double negativeFactor = getNegativeReputationFactor(player, city); for (EWare ware : wares){
for (EWare ware : EWare.values()) { autoTrading.setTradingType(ware, ETradeType.NONE);
List<ITradingOffice> buildings = city.findBuilding(ITradingOffice.class, Optional.empty()); for (ITradingOffice trOffice : buildings) { for (EWare ware : EWare.values()) { AmountablePrice<IWare> amountable = trOffice.getWare(ware); trOffice.move(ware, -amountable.getAmount(), amountable.getAVGPrice());
for (EWare ware : EWare.values()) { double requiredAmount = consume.getNeed(ware, EPopulationClass.POOR, city.getPopulation(EPopulationClass.POOR)); if (city.getWare(ware).getAmount() < requiredAmount) {
if (building instanceof ITradingOffice){ ITradingOffice office = (ITradingOffice) building; for (IWare ware : EWare.values()) { AmountablePrice<IWare> ap = office.getWare(ware); newCompanyValue+=ap.getAVGPrice()*ap.getAmount();
model.setColumnWidth(70, 60, 60, 60, 60, 60, 60); for (final EWare ware : EWare.values()) { TableRow row = new TableRow();
model.setAligenment(3, HPos.RIGHT); model.setColumnWidth(100, 100, 100, 100); for (EWare ware : EWare.values()) { TableRow row = new TableRow(); row.add(new StaticTextTableCell(translator.getLocalDisplayName(ware)));