@PostConstruct @IgnoreOnDeserialisation private void init() { for (EWare ware : EWare.values()) { if (!storedAmounts.containsKey(ware)) { storedAmounts.put(ware, 0); } } }
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; }
@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(); } }
.append(":\n"); ITradingOffice office = optOffice.get(); for (EWare ware : EWare.values()) { AmountablePrice<IWare> amountable = office.getWare(ware); if (amountable.getAmount() > 0) { sb.append("\t\t") .append(ware.name()) .append(": ") .append(amountable.getAmount()) for (EWare ware : EWare.values()) { AmountablePrice<IWare> amountable = ship.getWare(ware); if (amountable.getAmount() > 0) { sb.append("\t\t") .append(ware.name()) .append(": ") .append(amountable.getAmount())
EWare ware = EWare.values()[rnd.nextInt(EWare.values().length)]; int amount; if (ware.isBarrelSizedWare()) { amount = rnd.nextInt(ship.getCapacity()/2); } else {
private void addAmountCell(final EWare ware, TableRow row, int popConsumption) { if (ware.isBarrelSizedWare()) { BarrelAmount barrelAmount = new BarrelAmount(); barrelAmount.setAmount(popConsumption); row.add(new ControlTableCell(barrelAmount)); } else { BaleAmount baleAmount = new BaleAmount(); baleAmount.setAmount(popConsumption); row.add(new ControlTableCell(baleAmount)); } }
if (ware.isBarrelSizedWare()) { BarrelAmountAlwaysVisible barrelAmount = new BarrelAmountAlwaysVisible(); barrelAmount.amountProperty().bind(stored.asString()); if (ware.isBarrelSizedWare()) { BarrelAmountAlwaysVisible barrelAmount = new BarrelAmountAlwaysVisible(); barrelAmount.setAmount(0); availableMap.addListener((MapChangeListener<IWare, IntegerProperty>) change -> { final IntegerProperty valueAdded = change.getValueAdded(); if (ware.equals(change.getKey()) && valueAdded != null) { barrelAmount.amountProperty().setValue(String.valueOf(valueAdded.get())); availableMap.addListener((MapChangeListener<IWare, IntegerProperty>) change -> { final IntegerProperty valueAdded = change.getValueAdded(); if (ware.equals(change.getKey()) && valueAdded != null) { baleAmount.amountProperty().setValue(String.valueOf(valueAdded.get()));
Set<IWare> waresToBuy = new HashSet<>(); for (String wareName : wareNames) { IWare ware = EWare.valueOf(wareName); waresToBuy.add(ware);
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))); if (ware.isBarrelSizedWare()) { BarrelAmount barrelAmount = new BarrelAmount(); barrelAmount.amountProperty().bind(storedAmountProperty.asString());
private void setupCurrentContent() { removeDecoratedContent(); if (notices.size() > 0) { final ICityHallNotice notice = notices.get(currentIndex.get()); EWare ware = (EWare) notice.getRequiredWare(); ICity destination = notice.getDestination(); setTitle(messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.cityhall.PublicNoticeDialog.title", new Object[]{modelTranslator.getLocalDisplayName(ware), destination.getName()}, locale.getCurrentLocal())); String key; if (ware.isBarrelSizedWare()) { key = "ch.sahits.game.openpatrician.display.dialog.cityhall.PublicNoticeDialog.barrelMessage"; } else { key = "ch.sahits.game.openpatrician.display.dialog.cityhall.PublicNoticeDialog.baleMessage"; } AmountablePrice<IWare> amountPrice = notice.getWareAndAmount(); final LocalDateTime dueDate1 = notice.getDueDate(); String dueDate = modelTranslator.toDisplayString(dueDate1); int premium = amountPrice.getAVGPrice() * amountPrice.getAmount(); Object[] args = new Object[]{modelTranslator.getLocalDisplayName(ware), amountPrice.getAmount(), dueDate, premium, amountPrice.getAVGPrice(), 1}; String template = messageSource.getMessage(key, args, locale.getCurrentLocal()); DecoratedText text = textFactory.createDecoratedText(template, new HashMap<>()); getContent().add(text); } }
@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; }
model.setColumnWidth(70, 60, 60, 60, 60, 60, 60); for (final EWare ware : EWare.values()) { TableRow row = new TableRow(); if (ware.isBarrelSizedWare()) { BarrelAmount barrelAmount = new BarrelAmount(); barrelAmount.amountProperty().bind(amountAvailableProp.asString());
} else if (person instanceof ITrader) { ITrader trader = (ITrader) person; EWare ware = EWare.values()[rnd.nextInt(EWare.values().length)]; final AmountablePrice<IWare> amountablePrice = city.getWare(ware); int availableAmount = amountablePrice.getAmount(); while (availableAmount == 0) { ware = EWare.values()[rnd.nextInt(EWare.values().length)]; availableAmount = city.getWare(ware).getAmount(); if (ware.getSizeAsBarrels() == 1) { amount = rnd.nextInt(100); } else {
if (ware.isBarrelSizedWare()) { BarrelAmountAlwaysVisible barrelAmount = new BarrelAmountAlwaysVisible(); barrelAmount.amountProperty().bind(needed.asString()); if (ware.isBarrelSizedWare()) { BarrelAmountAlwaysVisible barrelAmount = new BarrelAmountAlwaysVisible(); barrelAmount.amountProperty().bind(stored.asString()); if (ware.isBarrelSizedWare()) { BarrelAmountAlwaysVisible barrelAmount = new BarrelAmountAlwaysVisible(); barrelAmount.amountProperty().bind(buyAmount.asString());
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; }
Optional<ITradingOffice> optOffice = cityProxy.getPlayer().findTradingOffice(city); INavigableVessel ship = cityProxy.getActiveShip(); for (final EWare ware : EWare.values()) { TableRow row = new TableRow(); row.add(new StaticTextTableCell(translator.getLocalDisplayName(ware))); ReadOnlyIntegerProperty amountAvailableProp = getAvailableAmountProperty(city, ware, optOffice); IntegerBinding amountToTransfer = getAmountProperty(city.getWare(ware).amountProperty()); if (ware.isBarrelSizedWare()) { BarrelAmount barrelAmount = new BarrelAmount(); barrelAmount.amountProperty().bind(amountAvailableProp.asString()); row.add(new ControlTableCell(sellBtn)); ReadOnlyIntegerProperty storedAmountProperty = getStoredAmountProperty(ware, ship, optOffice); if (ware.isBarrelSizedWare()) { BarrelAmount barrelAmount = new BarrelAmount(); barrelAmount.amountProperty().bind(storedAmountProperty.asString());
if (ware.isBarrelSizedWare()) { BarrelAmountAlwaysVisible barrelAmount = new BarrelAmountAlwaysVisible(); barrelAmount.amountProperty().bind(needed.asString()); if (ware.isBarrelSizedWare()) { BarrelAmountAlwaysVisible barrelAmount = new BarrelAmountAlwaysVisible(); barrelAmount.amountProperty().bind(stored.asString()); if (ware.isBarrelSizedWare()) { BarrelAmountAlwaysVisible barrelAmount = new BarrelAmountAlwaysVisible(); barrelAmount.amountProperty().bind(buyAmount.asString());
@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
final Image checked = imageLoader.getImage("icons/waxseal_checked_icon"); for (final EWare ware : EWare.values()) { TableRow row = new TableRow(); row.add(new StaticTextTableCell(translator.getLocalDisplayName(ware))); row.add(new ControlTableCell(reduceAmountLbl)); if (ware.isBarrelSizedWare()) { BarrelAmountAlwaysVisible amount = new BarrelAmountAlwaysVisible(); amount.amountProperty().bind(autoTrading.amountProperty(ware).asString());
/** * 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()); }