public Number getBuyAmount() { return buyAmount.get(); }
@Override protected int computeValue() { return delegate.get(); }
public Number getBuyPrice() { return buyPrice.get(); }
@Override protected int computeValue() { return transferUtil.calculateAvailableAmount(movableAmount, maxAmount.get()); } };
@Override protected int computeValue() { if (buyAmount.get() > 0) { return computablePrice.buyPrice(ware, inCity, buyAmount); } else { return 0; } } };
@Override protected int computeValue() { return Math.max(0, needed.get() - stored.get()); } }
/** * Create an alderman task to help a city. If no city with less than 2000 inhabitants is found absent will be returned. * @return Optional help city alderman task */ public Optional<IHelpCity> createHelpCityAldermanTask() { ArrayList<ICity> cities = new ArrayList<>(map.getCities()); Collections.shuffle(cities); for (ICity city : cities) { final int population = city.getPopulationBinding().get(); if (population < 2000) { int duration = (2000 - population)/ 3; final IHelpCity task = (IHelpCity) context.getBean("helpCity", new Object[]{duration, city}); return Optional.of(task); } } return Optional.empty(); } /**
@Override protected String computeValue() { switch (type) { case PORT_CITY_TO_SHIP: case PORT_CITY_TO_STORAGE: if (movableAmount.get()==ETransferAmount.MAX){ return String.valueOf(ware.getMaxValueSell()); } else if (amountToSell.get() > 0){ return String.valueOf(computablePrice.sellPrice(ware, availableAmount, amountToSell)); } else { return String.valueOf(ware.getMaxValueSell()); } default: return ">"; } } };
@Override public boolean execute() { INavigableVessel vessel = getVessel(); int loaded = vessel.getLoadBinding().get(); if (loaded > maxAmount) { return super.execute(); } else { return true; } }
public int getTheoreticalProducableAmount(IWare ware, ICity city) { if (!isProducable(city, ware)) { return 0; } double adjustmentFactor = 1; if (!isEffectiveProduction(city, ware)) { adjustmentFactor = inefficiencyFactor; } int population = city.getPopulationBinding().get(); int amountWorkshops = population / populationAmountPerWorkshop + 1; // Get the max amount that is producable return (int) Math.rint(productionChain.getProduction(ware) * amountWorkshops * adjustmentFactor); }
/** * Create an alderman task to help a city. If no city with less than 2000 inhabitants is found absent will be returned. * @return optional help city alderman task */ public Optional<IHelpCity> createHelpCityAldermanTask(IAldermanOffice office) { List<IAcceptedAldermanTask> workedOnTasks = office.getWorkedOnTasks(); List<ICity> helpTasks = new ArrayList<>(); for (IAcceptedAldermanTask workedOnTask : workedOnTasks) { if (workedOnTask.getTask() instanceof IHelpCity) { helpTasks.add(((IHelpCity) workedOnTask.getTask()).getCity()); } } ArrayList<ICity> cities = new ArrayList<>(map.getCities()); Collections.shuffle(cities); for (ICity city : cities) { if (helpTasks.contains(city)) { continue; } final int population = city.getPopulationBinding().get(); if (population < 2000) { int duration = (2000 - population)/ 3; final IHelpCity task = (IHelpCity) context.getBean("helpCity", new Object[]{duration, city}); return Optional.of(task); } } return Optional.empty(); }
/** * Hire if there is storage capacity larger than 1000 barrels and 80% are occupied. */ @Override public boolean hireOrFireTradeManager(ICity city, IAIPlayer player) { Optional<ITradingOffice> optOffice = player.findTradingOffice(city); if (optOffice.isPresent()) { ITradingOffice office = optOffice.get(); if (office.getSteward().isPresent()) { return false; // never dismiss } else { int capacity = office.capacityProperty().get(); return capacity >= 1000 && capacity - office.storedAmountBinding().get() <= (int)(0.2 * capacity); } } return false; } }
@Override protected Group createFooterText() { IntegerBinding totalPriceBinding = new IntegerBinding() { { for (EWare ware : MATERIALS) { RequiredWareCityStorage requiredWare = requirementsMap.get(ware); super.bind(requiredWare.buyPriceProperty()); } } @Override protected int computeValue() { return calculateTotalBuildCosts(); } }; Group g = new Group(); String t = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.ShipyardConstructionDialogV2.totalSum", new Object[]{}, locale.getCurrentLocal()); HashMap<String, Object> parameters = new HashMap<>(); parameters.put("price", totalPriceBinding.get()); DecoratedText dt = decoratedTextFactory.createDecoratedText(t, parameters); dt.setId("totalSum"); g.getChildren().add(dt); g.setId("footerText"); return g; }
@Override protected Group createFooterText() { IntegerBinding totalPriceBinding = new IntegerBinding() { { // Bind to amount in office and in city for (EWare ware : MATERIALS) { RequiredWareCityStorage requiredWare = requirementsMap.get(ware); super.bind(requiredWare.buyPriceProperty()); } } @Override protected int computeValue() { return calculateTotalUpgradeCosts(); } }; Group g = new Group(); String t = messageSource.getMessage("ch.sahits.game.openpatrician.display.dialog.ShipyardConstructionDialogV2.totalSum", new Object[]{}, locale.getCurrentLocal()); HashMap<String, Object> parameters = new HashMap<>(); parameters.put("price", totalPriceBinding.get()); DecoratedText dt = decoratedTextFactory.createDecoratedText(t, parameters); dt.setId("totalSum"); g.getChildren().add(dt); g.setId("footerText"); return g; }
public Map<IWare, Double> calculateConsumptionByProductionChain(ICity city) { List<IWare> wares = collectProducableWares(city); Map<IWare, Double> requireWares = new HashMap<>(); for (IWare ware : wares) { double adjustmentFactor = 1; if (!isEffectiveProduction(city, ware)) { adjustmentFactor = inefficiencyFactor; } if (city.getImported().contains(ware)) { if (isEffectiveProduction(city, ware)) { adjustmentFactor = inefficiencyFactor; } else { continue; } } int population = city.getPopulationBinding().get(); int amountWorkshops = population / populationAmountPerWorkshop + 1; List<IWare> required = productionChain.getRequiredWares(ware); for (IWare requiredWare : required) { double requiredAmount = productionChain.getRequiredAmount(ware, requiredWare) * amountWorkshops * adjustmentFactor; if (requireWares.containsKey(requiredWare)) { double update = requireWares.get(requiredWare) + requiredAmount; requireWares.put(requiredWare, update); } else { requireWares.put(requiredWare, requiredAmount); } } } return requireWares; }
@Override protected int computeValue() { if (amountToSell.get() > 0) { int availableAmount = weaponsDealer.amountAvailableProperty(weapon).getValue(); // that should be the amount of the dealer return computablePrice.sellPrice(weapon, new SimpleIntegerProperty(availableAmount), amountToSell); // amountToSell is the amount stored on ship/office } else { return 0; } } };
private boolean canHaveMoreGuards() { int maxPossible = cityService.getMaxNumberOfGuards(city.getCity().getPopulationBinding().get()); return cityHallAccessor.getCityHall(city.getCity()).getCityGuard().size() < maxPossible; }
int population = city.getPopulationBinding().get(); int amountWorkshops = population / populationAmountPerWorkshop + 1;
@PostConstruct private void initializeDialog() { String letterDate = modelTranslations.toDisplayString(state.getDate()); addDecoratedText("letter.location.date", "dateLocation", Pos.CENTER_RIGHT, state.getLocation(), letterDate); addVerticalSpacer(20); IShip ship = state.getShip(); int loaded = ship.getLoadBinding().get(); String shipType = modelTranslations.getLocalDisplayName(ship.getShipType()); if (loaded > 0) { addDecoratedText("ch.sahits.game.openpatrician.display.dialog.event.DowryDialog.dowry.filled", "dowryWithLoad", shipType, loaded); } else { addDecoratedText("ch.sahits.game.openpatrician.display.dialog.event.DowryDialog.dowry.empty", "dowryWithoutLoad", shipType); } } }
private void prepareForProductionNextWeekAndMakeAvailable(ICity city, IWare ware) { double producedAmount = getExactOutputCurrentWeek(ware, city); int makeAvailableAmount = (int) Math.floor(producedAmount); double remainingAmount = producedAmount - makeAvailableAmount; ProductionStorage storage = cityProductionStorage.getStorage(city); storage.transfer(ware, remainingAmount, 0); if (storage.getStored(ware) > 1) { int fromStorage = (int) Math.floor(storage.getStored(ware)); storage.transfer(ware, -fromStorage, 0); makeAvailableAmount += fromStorage; } city.move(ware, makeAvailableAmount, null); List<IWare> requiredWares = productionChain.getRequiredWares(ware); double adjustmentFactor = 1; if (!isEffectiveProduction(city, ware) || city.getImported().contains(ware)) { adjustmentFactor = inefficiencyFactor; } int population = city.getPopulationBinding().get(); int amountWorkshops = population / populationAmountPerWorkshop + 1; for (IWare requiredWare : requiredWares) { double requiredAmount = productionChain.getRequiredAmount(ware, requiredWare) * amountWorkshops * adjustmentFactor; double storedAmount = storage.getStored(requiredWare); double removeAmount = Math.min(requiredAmount, storedAmount); storage.transfer(requiredWare, -removeAmount, 0); } } }