From fdbd4ba3a61345d2657b3655e62b196d4d4ef18f Mon Sep 17 00:00:00 2001 From: iMoHax Date: Thu, 1 Dec 2016 17:42:02 +0300 Subject: [PATCH] sort intersects by CC, implement max profit search --- .../controllers/PowerPlayController.java | 53 +++++++++++++---- .../resources/lang/locale_en_US.properties | 3 +- .../resources/lang/locale_ru_RU.properties | 3 +- client/src/main/resources/view/powerplay.fxml | 5 +- .../trader/analysis/PowerPlayAnalyzator.java | 58 ++++++++++++++++++- .../src/main/java/ru/trader/core/Profile.java | 2 +- 6 files changed, 106 insertions(+), 18 deletions(-) diff --git a/client/src/main/java/ru/trader/controllers/PowerPlayController.java b/client/src/main/java/ru/trader/controllers/PowerPlayController.java index 8f6913e..973f7ee 100644 --- a/client/src/main/java/ru/trader/controllers/PowerPlayController.java +++ b/client/src/main/java/ru/trader/controllers/PowerPlayController.java @@ -12,6 +12,8 @@ import javafx.scene.input.*; import javafx.util.converter.NumberStringConverter; import org.controlsfx.control.CheckComboBox; import org.controlsfx.control.MasterDetailPane; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import ru.trader.Main; import ru.trader.analysis.PowerPlayAnalyzator; import ru.trader.core.*; @@ -31,6 +33,7 @@ import java.util.Optional; import java.util.stream.Collectors; public class PowerPlayController { + private final static Logger LOG = LoggerFactory.getLogger(PowerPlayController.class); @FXML private TextField checkedSystemText; @@ -56,6 +59,8 @@ public class PowerPlayController { @FXML private RadioButton rbControlling; @FXML + private RadioButton rbMaxProfit; + @FXML private ListView historySystems; @FXML private ListView controlSystems; @@ -80,7 +85,7 @@ public class PowerPlayController { private PowerPlayAnalyzator analyzator; private final ObservableList result = FXCollections.observableArrayList(); private final ObservableList detail = FXCollections.observableArrayList(); - + private Place detailSystem; @FXML private void initialize(){ @@ -181,12 +186,12 @@ public class PowerPlayController { NumberStringConverter converter = new NumberStringConverter("#,##0.##"); result.addListener((InvalidationListener) i -> { resultPopSumm.setText(converter.toString(getPopulationSumm(result))); - resultCCSumm.setText(getCCSummText(result)); + resultCCSumm.setText(getCCSummText(result, getCheckedSystem())); } ); detail.addListener((InvalidationListener) i -> { detailPopSumm.setText(converter.toString(getPopulationSumm(detail))); - detailCCSumm.setText(getCCSummText(detail)); + detailCCSumm.setText(getCCSummText(detail, detailSystem)); } ); } @@ -195,7 +200,7 @@ public class PowerPlayController { return collection.stream().mapToLong(ResultEntry::getPopulation).sum(); } - private String getCCSummText(Collection collection){ + private String getCCSummText(Collection collection, Place starSystem){ String ccFormat = Localization.getString("powerplay.label.summcc"); String pwCCFormat = Localization.getString("powerplay.label.cc"); PowerStringConverter converter = new PowerStringConverter(); @@ -218,8 +223,13 @@ public class PowerPlayController { } } } + double upkeep = 0; + if (hqSystem.isPresent() && starSystem != null){ + upkeep = starSystem.computeUpkeep(ModelFabric.get(hqSystem.get())); + } + StringBuilder builder = new StringBuilder(); - builder.append(String.format(ccFormat, summCc, contested, summCc - contested)); + builder.append(String.format(ccFormat, summCc, contested, upkeep, summCc - contested - upkeep)); for (int i = 0; i < POWER.values().length; i++) { if (totalCc[i] > 0 || contestedCc[i] > 0){ builder.append("\n"); @@ -231,6 +241,7 @@ public class PowerPlayController { private void fillDetail(SystemModel detailSystem) { final Place starSystem = ModelFabric.get(detailSystem); + this.detailSystem = starSystem; detail.clear(); if (starSystem != null){ Collection controllings = analyzator.getControlling(starSystem); @@ -239,9 +250,12 @@ public class PowerPlayController { } } + private Place getCheckedSystem(){ + return ModelFabric.get(checkedSystem.getValue()); + } private void getIntersects(){ - Place starSystem = ModelFabric.get(checkedSystem.getValue()); + Place starSystem = getCheckedSystem(); Collection controlls = getControlSystems(); result.clear(); if (starSystem != null && !controlls.isEmpty()){ @@ -251,7 +265,7 @@ public class PowerPlayController { } private void getControlling(){ - final Place starSystem = ModelFabric.get(checkedSystem.getValue()); + final Place starSystem = getCheckedSystem(); result.clear(); if (starSystem != null){ Collection controllings = analyzator.getControlling(starSystem); @@ -269,6 +283,16 @@ public class PowerPlayController { } } + private void getMaxProfit(){ + final Place hq = ModelFabric.get(hqSystem.get()); + if (hq != null){ + Collection controlls = getControlSystems(); + result.clear(); + Collection near = analyzator.getMaxProfit(hq, controlls); + result.addAll(BindingsHelper.observableList(near, ResultEntry::new)); + } + } + private void getNearExpansions(){ Collection controlls = getControlSystems(); result.clear(); @@ -323,6 +347,9 @@ public class PowerPlayController { if (rbMaxIntersect.isSelected()){ getMaxIntersect(); } + if (rbMaxProfit.isSelected()){ + getMaxProfit(); + } } @@ -410,8 +437,9 @@ public class PowerPlayController { private final ReadOnlyStringProperty intersecting; private final ReadOnlyStringProperty controlling; private final ReadOnlyLongProperty population; - private final ReadOnlyLongProperty upkeep; + private final ReadOnlyLongProperty currentUpkeep; private final ReadOnlyLongProperty income; + private final ReadOnlyDoubleProperty upkeep; private final ReadOnlyLongProperty cc; public ResultEntry(PowerPlayAnalyzator.IntersectData data) { @@ -428,7 +456,8 @@ public class PowerPlayController { Place hq = ModelFabric.get(hqSystem.orElse(null)); distanceHQ = new SimpleDoubleProperty(hq != null ? hq.getDistance(data.getStarSystem()) : Double.NaN); population = new SimpleLongProperty(data.getStarSystem().getPopulation()); - upkeep = new SimpleLongProperty(data.getStarSystem().getUpkeep()); + currentUpkeep = new SimpleLongProperty(data.getStarSystem().getUpkeep()); + upkeep = new SimpleDoubleProperty(hq != null ? data.getStarSystem().computeUpkeep(hq) : Double.NaN); income = new SimpleLongProperty(data.getStarSystem().getIncome()); cc = new SimpleLongProperty(data.getStarSystem().computeCC(ModelFabric.get(profile).getCCgroups())); } @@ -529,10 +558,14 @@ public class PowerPlayController { return population; } - public ReadOnlyLongProperty upkeepProperty() { + public ReadOnlyDoubleProperty upkeepProperty() { return upkeep; } + public ReadOnlyLongProperty currentUpkeepProperty() { + return currentUpkeep; + } + public ReadOnlyLongProperty incomeProperty() { return income; } diff --git a/client/src/main/resources/lang/locale_en_US.properties b/client/src/main/resources/lang/locale_en_US.properties index b532083..025abfd 100644 --- a/client/src/main/resources/lang/locale_en_US.properties +++ b/client/src/main/resources/lang/locale_en_US.properties @@ -274,6 +274,7 @@ missions.supply.text=Supply %d %s to %s at %s powerplay.analyze.title=Analyze parameters powerplay.analyze.intersect=Intersect search powerplay.analyze.near=Near search without intersect +powerplay.analyze.maxProfit=Max profit search powerplay.analyze.maxIntersect=Max intersection search powerplay.analyze.expansions=Near expansions powerplay.analyze.controlling=Systems in controlled radius @@ -285,7 +286,7 @@ powerplay.label.power.systems=Systems of Power: powerplay.label.power.state=State: powerplay.label.populationSumm=Summ populations: powerplay.label.cc=%s: %4d CC Contested: %4d CC -powerplay.label.summcc=Summ: %6d CC Contested: %6d CC Total: %6dCC +powerplay.label.summcc=Summ: %6d CC Contested: %6d CC Upkeep: %6.1f CC Total: %6.1f CC powerplay.result.title=Analyze result powerplay.column.intersecting=Intersect powerplay.column.intersectCount=Intersect count diff --git a/client/src/main/resources/lang/locale_ru_RU.properties b/client/src/main/resources/lang/locale_ru_RU.properties index 050e2f4..cf5e45c 100644 --- a/client/src/main/resources/lang/locale_ru_RU.properties +++ b/client/src/main/resources/lang/locale_ru_RU.properties @@ -274,6 +274,7 @@ missions.supply.text=\u041A\u0443\u043F\u0438\u0442\u044C \u0438 \u0434\u043E\u0 powerplay.analyze.title=\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B \u0430\u043D\u0430\u043B\u0438\u0437\u0430 powerplay.analyze.intersect=\u041F\u043E\u0438\u0441\u043A \u043F\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043D\u0438\u0439 powerplay.analyze.near=\u041F\u043E\u0438\u0441\u043A \u0431\u043B\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u0431\u0435\u0437 \u043F\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043D\u0438\u0439 +powerplay.analyze.maxProfit=\u041F\u043E\u0438\u0441\u043A \u043F\u0440\u0438\u0431\u044B\u043B\u044C\u043D\u044B\u0445 \u0441\u0438\u0441\u0442\u0435\u043C powerplay.analyze.maxIntersect=\u041F\u043E\u0438\u0441\u043A \u0441 \u043C\u0430\u043A\u0441\u0438\u043C\u0430\u043B\u044C\u043D\u044B\u043C \u043F\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043D\u0438\u0435\u043C powerplay.analyze.expansions=\u0411\u043B\u0438\u0436\u0430\u0439\u0448\u0438\u0435 \u044D\u043A\u0441\u043F\u0430\u043D\u0441\u0438\u0438 powerplay.analyze.controlling=\u0421\u0438\u0441\u0442\u0435\u043C\u044B \u0432 \u043F\u043E\u0434\u043A\u043E\u043D\u0442\u0440\u043E\u043B\u044C\u043D\u043E\u043C \u0440\u0430\u0434\u0438\u0443\u0441\u0435 @@ -285,7 +286,7 @@ powerplay.label.power.systems=C\u0438\u0441\u0442\u0435\u043C\u044B \u0441\u0438 powerplay.label.power.state=\u0421\u043E\u0441\u0442\u043E\u044F\u043D\u0438\u0435: powerplay.label.populationSumm=\u0421\u0443\u043C\u043C\u0430 \u043D\u0430\u0441\u0435\u043B\u0435\u043D\u0438\u044F: powerplay.label.cc=%s: %4d \u041A\u041A \u041E\u0441\u043F\u0430\u0440\u0438\u0432\u0430\u0435\u043C\u044B\u0445: %4d \u041A\u041A -powerplay.label.summcc=\u0421\u0443\u043C\u043C\u0430: %6d \u041A\u041A \u041E\u0441\u043F\u0430\u0440\u0438\u0432\u0430\u0435\u043C\u044B\u0445: %6d \u041A\u041A \u0418\u0442\u043E\u0433\u043E: %6d\u041A\u041A +powerplay.label.summcc=\u0421\u0443\u043C\u043C\u0430: %6d \u041A\u041A \u041E\u0441\u043F\u0430\u0440\u0438\u0432\u0430\u0435\u043C\u044B\u0445: %6d \u041A\u041A \u0420\u0430\u0441\u0445\u043E\u0434\u044B: %6.1f \u041A\u041A \u0418\u0442\u043E\u0433\u043E: %6.1f \u041A\u041A powerplay.result.title=\u0420\u0435\u0437\u0443\u043B\u044C\u0442\u0430\u0442\u044B \u0430\u043D\u0430\u043B\u0438\u0437\u0430 powerplay.column.intersecting=\u041F\u0435\u0440\u0435\u0441\u0435\u043A\u0430\u0435\u0442\u0441\u044F \u0441 powerplay.column.intersectCount=\u041F\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043D\u0438\u0439 diff --git a/client/src/main/resources/view/powerplay.fxml b/client/src/main/resources/view/powerplay.fxml index beab677..566c959 100644 --- a/client/src/main/resources/view/powerplay.fxml +++ b/client/src/main/resources/view/powerplay.fxml @@ -15,7 +15,7 @@ - +