sort intersects by CC, implement max profit search
This commit is contained in:
@@ -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<SystemModel> historySystems;
|
||||
@FXML
|
||||
private ListView<SystemModel> controlSystems;
|
||||
@@ -80,7 +85,7 @@ public class PowerPlayController {
|
||||
private PowerPlayAnalyzator analyzator;
|
||||
private final ObservableList<ResultEntry> result = FXCollections.observableArrayList();
|
||||
private final ObservableList<ResultEntry> 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<ResultEntry> collection){
|
||||
private String getCCSummText(Collection<ResultEntry> 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<PowerPlayAnalyzator.IntersectData> 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<Place> 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<PowerPlayAnalyzator.IntersectData> 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<Place> controlls = getControlSystems();
|
||||
result.clear();
|
||||
Collection<PowerPlayAnalyzator.IntersectData> near = analyzator.getMaxProfit(hq, controlls);
|
||||
result.addAll(BindingsHelper.observableList(near, ResultEntry::new));
|
||||
}
|
||||
}
|
||||
|
||||
private void getNearExpansions(){
|
||||
Collection<Place> 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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<fx:define><Insets fx:id="tablePadding" left="0" right="0" top="0" bottom="0" /></fx:define>
|
||||
<fx:define><Insets fx:id="summPadding" left="4" right="4" top="4" bottom="4" /></fx:define>
|
||||
<TitledPane text="%powerplay.analyze.title" collapsible="false">
|
||||
<HBox spacing="50" alignment="CENTER" minHeight="210" maxHeight="210">
|
||||
<HBox spacing="50" alignment="CENTER" minHeight="230" maxHeight="230">
|
||||
<VBox minWidth="250" maxWidth="250" spacing="4">
|
||||
<Label text="%powerplay.label.checked" />
|
||||
<HBox spacing="4" alignment="BASELINE_LEFT">
|
||||
@@ -47,6 +47,7 @@
|
||||
<fx:define><ToggleGroup fx:id="analyzeType" /></fx:define>
|
||||
<RadioButton fx:id="rbIntersect" text="%powerplay.analyze.intersect" selected="true" toggleGroup="$analyzeType"/>
|
||||
<RadioButton fx:id="rbNear" text="%powerplay.analyze.near" selected="false" toggleGroup="$analyzeType"/>
|
||||
<RadioButton fx:id="rbMaxProfit" text="%powerplay.analyze.maxProfit" selected="false" toggleGroup="$analyzeType"/>
|
||||
<RadioButton fx:id="rbMaxIntersect" text="%powerplay.analyze.maxIntersect" selected="false" toggleGroup="$analyzeType"/>
|
||||
<RadioButton fx:id="rbExpansions" text="%powerplay.analyze.expansions" selected="false" toggleGroup="$analyzeType"/>
|
||||
<RadioButton fx:id="rbControlling" text="%powerplay.analyze.controlling" selected="false" toggleGroup="$analyzeType"/>
|
||||
@@ -129,7 +130,7 @@
|
||||
<cellValueFactory><PropertyValueFactory property="income"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn prefWidth="60" text="%market.system.upkeep">
|
||||
<cellValueFactory><PropertyValueFactory property="upkeep"/></cellValueFactory>
|
||||
<cellValueFactory><PropertyValueFactory property="currentUpkeep"/></cellValueFactory>
|
||||
</TableColumn>
|
||||
<TableColumn prefWidth="80" text="%market.population">
|
||||
<cellFactory><TextCell><converter><CustomNumberStringConverter pattern="#,##0.##" /></converter></TextCell></cellFactory>
|
||||
|
||||
Reference in New Issue
Block a user