add new fields to star system class
This commit is contained in:
@@ -317,6 +317,7 @@ public class PowerPlayController {
|
|||||||
private final ReadOnlyDoubleProperty distanceHQ;
|
private final ReadOnlyDoubleProperty distanceHQ;
|
||||||
private final ReadOnlyStringProperty maxSizePad;
|
private final ReadOnlyStringProperty maxSizePad;
|
||||||
private final ReadOnlyIntegerProperty intersectCount;
|
private final ReadOnlyIntegerProperty intersectCount;
|
||||||
|
private final ReadOnlyStringProperty intersecting;
|
||||||
private final ReadOnlyStringProperty controlling;
|
private final ReadOnlyStringProperty controlling;
|
||||||
|
|
||||||
public ResultEntry(PowerPlayAnalyzator.IntersectData data) {
|
public ResultEntry(PowerPlayAnalyzator.IntersectData data) {
|
||||||
@@ -328,7 +329,8 @@ public class PowerPlayController {
|
|||||||
maxSizePad = new SimpleStringProperty(starSystem.getMaxSizePad());
|
maxSizePad = new SimpleStringProperty(starSystem.getMaxSizePad());
|
||||||
intersectCount = new SimpleIntegerProperty(data.getCount());
|
intersectCount = new SimpleIntegerProperty(data.getCount());
|
||||||
nearStation = starSystem.getNear();
|
nearStation = starSystem.getNear();
|
||||||
controlling = new SimpleStringProperty(getControllingString(data.getControllingSystems()));
|
intersecting = new SimpleStringProperty(getControllingString(data.getControllingSystems()));
|
||||||
|
controlling = new SimpleStringProperty(getControllingString(data.getStarSystem()));
|
||||||
distance = new SimpleDoubleProperty(from != null ? from.getDistance(data.getStarSystem()) : Double.NaN);
|
distance = new SimpleDoubleProperty(from != null ? from.getDistance(data.getStarSystem()) : Double.NaN);
|
||||||
Place hq = ModelFabric.get(hqSystem.orElse(null));
|
Place hq = ModelFabric.get(hqSystem.orElse(null));
|
||||||
distanceHQ = new SimpleDoubleProperty(hq != null ? hq.getDistance(data.getStarSystem()) : Double.NaN);
|
distanceHQ = new SimpleDoubleProperty(hq != null ? hq.getDistance(data.getStarSystem()) : Double.NaN);
|
||||||
@@ -344,6 +346,15 @@ public class PowerPlayController {
|
|||||||
return res.toString();
|
return res.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getControllingString(Place place) {
|
||||||
|
StringBuilder res = new StringBuilder();
|
||||||
|
for (Place system : place.getControllingSystems()) {
|
||||||
|
if (res.length() != 0) res.append("\n");
|
||||||
|
res.append(system.getName());
|
||||||
|
res.append(" (").append(ViewUtils.distanceToString(system.getDistance(place))).append(")");
|
||||||
|
}
|
||||||
|
return res.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public ReadOnlyStringProperty stationProperty(){
|
public ReadOnlyStringProperty stationProperty(){
|
||||||
return new SimpleStringProperty(String.format("%s (%.0f Ls)", nearStation.getName(), nearStation.getDistance()));
|
return new SimpleStringProperty(String.format("%s (%.0f Ls)", nearStation.getName(), nearStation.getDistance()));
|
||||||
@@ -388,5 +399,9 @@ public class PowerPlayController {
|
|||||||
public ReadOnlyStringProperty controllingProperty() {
|
public ReadOnlyStringProperty controllingProperty() {
|
||||||
return controlling;
|
return controlling;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ReadOnlyStringProperty intersectingProperty() {
|
||||||
|
return intersecting;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,6 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class PowerPlayAnalyzator {
|
public class PowerPlayAnalyzator {
|
||||||
private final static Logger LOG = LoggerFactory.getLogger(PowerPlayAnalyzator.class);
|
private final static Logger LOG = LoggerFactory.getLogger(PowerPlayAnalyzator.class);
|
||||||
private final static double CONTROLLING_RADIUS = 15;
|
|
||||||
|
|
||||||
private final Market market;
|
private final Market market;
|
||||||
private StarSystemFilter starSystemFilter;
|
private StarSystemFilter starSystemFilter;
|
||||||
@@ -33,25 +32,25 @@ public class PowerPlayAnalyzator {
|
|||||||
|
|
||||||
public Collection<IntersectData> getControlling(Place starSystem){
|
public Collection<IntersectData> getControlling(Place starSystem){
|
||||||
Stream<Place> candidates = market.get().stream().filter(p -> p.getFaction() != FACTION.NONE);
|
Stream<Place> candidates = market.get().stream().filter(p -> p.getFaction() != FACTION.NONE);
|
||||||
return getControlling(starSystem, candidates, CONTROLLING_RADIUS).collect(Collectors.toList());
|
return getControlling(starSystem, candidates, Market.CONTROLLING_RADIUS).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<IntersectData> getIntersects(Collection<Place> starSystems){
|
public Collection<IntersectData> getIntersects(Collection<Place> starSystems){
|
||||||
return getIntersects(market.get(), starSystems, CONTROLLING_RADIUS);
|
return getIntersects(market.get(), starSystems, Market.CONTROLLING_RADIUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<IntersectData> getIntersects(Place starSystem, Collection<Place> starSystems){
|
public Collection<IntersectData> getIntersects(Place starSystem, Collection<Place> starSystems){
|
||||||
Stream<Place> candidates = market.get().stream().filter(p -> p.getFaction() != FACTION.NONE);
|
Stream<Place> candidates = market.get().stream().filter(p -> p.getFaction() != FACTION.NONE);
|
||||||
return getIntersects(starSystem, candidates, starSystems, CONTROLLING_RADIUS).collect(Collectors.toList());
|
return getIntersects(starSystem, candidates, starSystems, Market.CONTROLLING_RADIUS).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<IntersectData> getNear(Collection<Place> starSystems){
|
public Collection<IntersectData> getNear(Collection<Place> starSystems){
|
||||||
Stream<Place> candidates = market.get().stream().filter(p -> p.getFaction() != FACTION.NONE);
|
Stream<Place> candidates = market.get().stream().filter(p -> p.getFaction() != FACTION.NONE);
|
||||||
return getNear(candidates, starSystems, CONTROLLING_RADIUS, CONTROLLING_RADIUS*2).collect(Collectors.toList());
|
return getNear(candidates, starSystems, Market.CONTROLLING_RADIUS, Market.CONTROLLING_RADIUS*2).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<IntersectData> getNearExpansions(Collection<Place> starSystems){
|
public Collection<IntersectData> getNearExpansions(Collection<Place> starSystems){
|
||||||
return getNearExpansions(market.get(), starSystems, CONTROLLING_RADIUS * 2);
|
return getNearExpansions(market.get(), starSystems, Market.CONTROLLING_RADIUS * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<IntersectData> getControlling(Place starSystem, Collection<Place> starSystems, double radius){
|
public static Collection<IntersectData> getControlling(Place starSystem, Collection<Place> starSystems, double radius){
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ public abstract class AbstractItemStat implements ItemStat {
|
|||||||
throw new UnsupportedOperationException("Is fake place, change unsupported");
|
throw new UnsupportedOperationException("Is fake place, change unsupported");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FACTION getFaction() {
|
public FACTION getFaction() {
|
||||||
return FACTION.NONE;
|
return FACTION.NONE;
|
||||||
@@ -155,6 +157,41 @@ public abstract class AbstractItemStat implements ItemStat {
|
|||||||
public int compareTo(Connectable<Place> o) {
|
public int compareTo(Connectable<Place> o) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getPopulation() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPopulation(long population) {
|
||||||
|
throw new UnsupportedOperationException("Is fake place, change unsupported");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Place> getControllingSystems() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getUpkeep() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUpkeep(long upkeep) {
|
||||||
|
throw new UnsupportedOperationException("Is fake place, change unsupported");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getIncome() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setIncome(long income) {
|
||||||
|
throw new UnsupportedOperationException("Is fake place, change unsupported");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static Vendor NONE_VENDOR = new Vendor() {
|
private static Vendor NONE_VENDOR = new Vendor() {
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ package ru.trader.core;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public abstract class AbstractMarket implements Market {
|
public abstract class AbstractMarket implements Market {
|
||||||
private final static Logger LOG = LoggerFactory.getLogger(AbstractMarket.class);
|
private final static Logger LOG = LoggerFactory.getLogger(AbstractMarket.class);
|
||||||
|
|
||||||
@@ -10,15 +13,25 @@ public abstract class AbstractMarket implements Market {
|
|||||||
private boolean batch;
|
private boolean batch;
|
||||||
|
|
||||||
protected abstract Place createPlace(String name, double x, double y, double z);
|
protected abstract Place createPlace(String name, double x, double y, double z);
|
||||||
|
|
||||||
protected abstract Group createGroup(String name, GROUP_TYPE type);
|
protected abstract Group createGroup(String name, GROUP_TYPE type);
|
||||||
|
|
||||||
protected abstract Item createItem(String name, Group group);
|
protected abstract Item createItem(String name, Group group);
|
||||||
|
|
||||||
protected abstract void addGroup(Group group);
|
protected abstract void addGroup(Group group);
|
||||||
|
|
||||||
protected abstract void removeGroup(Group group);
|
protected abstract void removeGroup(Group group);
|
||||||
|
|
||||||
protected abstract void addPlace(Place place);
|
protected abstract void addPlace(Place place);
|
||||||
|
|
||||||
protected abstract void removePlace(Place place);
|
protected abstract void removePlace(Place place);
|
||||||
|
|
||||||
protected abstract void addItem(Item item);
|
protected abstract void addItem(Item item);
|
||||||
|
|
||||||
protected abstract void removeItem(Item item);
|
protected abstract void removeItem(Item item);
|
||||||
protected void executeBatch(){}
|
|
||||||
|
protected void executeBatch() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startBatch() {
|
public void startBatch() {
|
||||||
@@ -30,6 +43,7 @@ public abstract class AbstractMarket implements Market {
|
|||||||
public final void doBatch() {
|
public final void doBatch() {
|
||||||
LOG.debug("End batch, updated");
|
LOG.debug("End batch, updated");
|
||||||
executeBatch();
|
executeBatch();
|
||||||
|
updateControllings();
|
||||||
batch = false;
|
batch = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,6 +58,9 @@ public abstract class AbstractMarket implements Market {
|
|||||||
change = true;
|
change = true;
|
||||||
if (place instanceof AbstractPlace) {
|
if (place instanceof AbstractPlace) {
|
||||||
((AbstractPlace) place).setMarket(this);
|
((AbstractPlace) place).setMarket(this);
|
||||||
|
if (!isBatch()) {
|
||||||
|
updateControlling((AbstractPlace) place);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
addPlace(place);
|
addPlace(place);
|
||||||
}
|
}
|
||||||
@@ -60,6 +77,9 @@ public abstract class AbstractMarket implements Market {
|
|||||||
LOG.debug("Remove place {} from market {}", place, this);
|
LOG.debug("Remove place {} from market {}", place, this);
|
||||||
change = true;
|
change = true;
|
||||||
removePlace(place);
|
removePlace(place);
|
||||||
|
if (!isBatch()) {
|
||||||
|
removeControlling(place);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -121,15 +141,26 @@ public abstract class AbstractMarket implements Market {
|
|||||||
this.change = change;
|
this.change = change;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onAdd(Vendor vendor){}
|
protected void onAdd(Vendor vendor) {
|
||||||
protected void onRemove(Vendor vendor){}
|
}
|
||||||
protected void onAdd(Offer offer){}
|
|
||||||
protected void onRemove(Offer offer){}
|
protected void onRemove(Vendor vendor) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onAdd(Offer offer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onRemove(Offer offer) {
|
||||||
|
}
|
||||||
|
|
||||||
protected void updateName(AbstractPlace place, String name) {
|
protected void updateName(AbstractPlace place, String name) {
|
||||||
place.updateName(name);
|
place.updateName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void updatePopulation(AbstractPlace place, long population) {
|
||||||
|
place.updatePopulation(population);
|
||||||
|
}
|
||||||
|
|
||||||
protected void updateFaction(AbstractPlace place, FACTION faction) {
|
protected void updateFaction(AbstractPlace place, FACTION faction) {
|
||||||
place.updateFaction(faction);
|
place.updateFaction(faction);
|
||||||
}
|
}
|
||||||
@@ -138,6 +169,14 @@ public abstract class AbstractMarket implements Market {
|
|||||||
place.updateGovernment(government);
|
place.updateGovernment(government);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void updateUpkeep(AbstractPlace place, long upkeep) {
|
||||||
|
place.updateUpkeep(upkeep);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateIncome(AbstractPlace place, long income) {
|
||||||
|
place.updateIncome(income);
|
||||||
|
}
|
||||||
|
|
||||||
protected void updatePosition(AbstractPlace place, double x, double y, double z) {
|
protected void updatePosition(AbstractPlace place, double x, double y, double z) {
|
||||||
place.updatePosition(x, y, z);
|
place.updatePosition(x, y, z);
|
||||||
}
|
}
|
||||||
@@ -154,5 +193,51 @@ public abstract class AbstractMarket implements Market {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void updateControlling(AbstractPlace place) {
|
||||||
|
POWER_STATE state = place.getPowerState();
|
||||||
|
if (state != null && state.isControl()) {
|
||||||
|
getInControllingRadius(place).forEach(p -> {
|
||||||
|
if (p instanceof AbstractPlace) {
|
||||||
|
((AbstractPlace) p).addControlling(place);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
getInControllingRadius(place).forEach(p -> {
|
||||||
|
if (p.getPowerState() != null && p.getPowerState().isControl()) {
|
||||||
|
place.addControlling(p);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void removeControlling(Place place) {
|
||||||
|
POWER_STATE state = place.getPowerState();
|
||||||
|
if (state != null && state.isControl()) {
|
||||||
|
getInControllingRadius(place).forEach(p -> {
|
||||||
|
if (p instanceof AbstractPlace) {
|
||||||
|
((AbstractPlace) p).removeControlling(place);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateControllings() {
|
||||||
|
LOG.debug("Update all controlling");
|
||||||
|
Collection<Place> places = get();
|
||||||
|
Collection<Place> controllings = places.stream()
|
||||||
|
.filter(place -> place.getPowerState() != null && place.getPowerState().isControl())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
for (Place place : places) {
|
||||||
|
if (place instanceof AbstractPlace) {
|
||||||
|
((AbstractPlace)place).clearControlling();
|
||||||
|
for (Place controlling : controllings) {
|
||||||
|
if (place != controlling && controlling.getDistance(place) <= CONTROLLING_RADIUS) {
|
||||||
|
((AbstractPlace)place).addControlling(controlling);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,17 +5,25 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.trader.analysis.graph.Connectable;
|
import ru.trader.analysis.graph.Connectable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class AbstractPlace implements Place {
|
public abstract class AbstractPlace implements Place {
|
||||||
private final static Logger LOG = LoggerFactory.getLogger(AbstractPlace.class);
|
private final static Logger LOG = LoggerFactory.getLogger(AbstractPlace.class);
|
||||||
private AbstractMarket market;
|
private AbstractMarket market;
|
||||||
|
|
||||||
|
private Collection<Place> controlling;
|
||||||
|
|
||||||
protected abstract Vendor createVendor(String name);
|
protected abstract Vendor createVendor(String name);
|
||||||
protected abstract void updateName(String name);
|
protected abstract void updateName(String name);
|
||||||
|
protected abstract void updatePopulation(long population);
|
||||||
protected abstract void updateFaction(FACTION faction);
|
protected abstract void updateFaction(FACTION faction);
|
||||||
protected abstract void updateGovernment(GOVERNMENT government);
|
protected abstract void updateGovernment(GOVERNMENT government);
|
||||||
protected abstract void updatePower(POWER power, POWER_STATE state);
|
protected abstract void updatePower(POWER power, POWER_STATE state);
|
||||||
|
protected abstract void updateUpkeep(long upkeep);
|
||||||
|
protected abstract void updateIncome(long income);
|
||||||
protected abstract void updatePosition(double x, double y, double z);
|
protected abstract void updatePosition(double x, double y, double z);
|
||||||
protected abstract void addVendor(Vendor vendor);
|
protected abstract void addVendor(Vendor vendor);
|
||||||
protected abstract void removeVendor(Vendor vendor);
|
protected abstract void removeVendor(Vendor vendor);
|
||||||
@@ -29,6 +37,11 @@ public abstract class AbstractPlace implements Place {
|
|||||||
return market;
|
return market;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<Place> getControllingSystems() {
|
||||||
|
return controlling != null ? controlling : Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void setName(String name){
|
public final void setName(String name){
|
||||||
if (market != null){
|
if (market != null){
|
||||||
@@ -51,6 +64,17 @@ public abstract class AbstractPlace implements Place {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void setPopulation(long population) {
|
||||||
|
if (market != null){
|
||||||
|
LOG.debug("Change population of place {} to {}", this, population);
|
||||||
|
market.updatePopulation(this, population);
|
||||||
|
market.setChange(true);
|
||||||
|
} else {
|
||||||
|
updatePopulation(population);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void setFaction(FACTION faction){
|
public final void setFaction(FACTION faction){
|
||||||
if (market != null){
|
if (market != null){
|
||||||
@@ -75,12 +99,39 @@ public abstract class AbstractPlace implements Place {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void setPower(POWER power, POWER_STATE state){
|
public final void setPower(POWER power, POWER_STATE state){
|
||||||
|
POWER_STATE old = getPowerState();
|
||||||
if (market != null){
|
if (market != null){
|
||||||
LOG.debug("Change power of place {} to {} of {}", this, state, power);
|
LOG.debug("Change power of place {} to {} of {}", this, state, power);
|
||||||
updatePower(power, state);
|
updatePower(power, state);
|
||||||
|
if (!market.isBatch()) {
|
||||||
|
updateControlling(old, state);
|
||||||
|
}
|
||||||
market.setChange(true);
|
market.setChange(true);
|
||||||
} else {
|
} else {
|
||||||
updatePower(power, state);
|
updatePower(power, state);
|
||||||
|
updateControlling(old, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void setUpkeep(long upkeep) {
|
||||||
|
if (market != null){
|
||||||
|
LOG.debug("Change upkeep of place {} to {}", this, upkeep);
|
||||||
|
market.updateUpkeep(this, upkeep);
|
||||||
|
market.setChange(true);
|
||||||
|
} else {
|
||||||
|
updateUpkeep(upkeep);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void setIncome(long income) {
|
||||||
|
if (market != null){
|
||||||
|
LOG.debug("Change income of place {} to {}", this, income);
|
||||||
|
market.updateIncome(this, income);
|
||||||
|
market.setChange(true);
|
||||||
|
} else {
|
||||||
|
updateIncome(income);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,6 +166,42 @@ public abstract class AbstractPlace implements Place {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void updateControlling(POWER_STATE oldState, POWER_STATE newState){
|
||||||
|
LOG.debug("Update controlling systems, place {}, old = {}, new = {} ", this, oldState, newState);
|
||||||
|
if (market == null) return;
|
||||||
|
if (oldState == null) oldState = POWER_STATE.NONE;
|
||||||
|
if (newState == null) newState = POWER_STATE.NONE;
|
||||||
|
if (oldState.isControl() && !newState.isControl()){
|
||||||
|
market.getInControllingRadius(this).forEach(p -> {
|
||||||
|
if (p instanceof AbstractPlace) ((AbstractPlace)p).removeControlling(this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!oldState.isControl() && newState.isControl()){
|
||||||
|
market.getInControllingRadius(this).forEach(p -> {
|
||||||
|
if (p instanceof AbstractPlace) ((AbstractPlace)p).addControlling(this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addControlling(Place controllingSystem){
|
||||||
|
if (controlling == null){
|
||||||
|
controlling = new ArrayList<>();
|
||||||
|
}
|
||||||
|
controlling.add(controllingSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void removeControlling(Place controllingSystem){
|
||||||
|
if (controlling != null) {
|
||||||
|
controlling.remove(controllingSystem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void clearControlling() {
|
||||||
|
if (controlling != null){
|
||||||
|
controlling.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getName();
|
return getName();
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import java.util.Collection;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public interface Market {
|
public interface Market {
|
||||||
|
double CONTROLLING_RADIUS = 15;
|
||||||
|
|
||||||
void startBatch();
|
void startBatch();
|
||||||
void doBatch();
|
void doBatch();
|
||||||
@@ -74,6 +76,10 @@ public interface Market {
|
|||||||
.findFirst();
|
.findFirst();
|
||||||
return place.isPresent() ? place.get() : null;
|
return place.isPresent() ? place.get() : null;
|
||||||
}
|
}
|
||||||
|
default Stream<Place> getInControllingRadius(Place controllingSystem){
|
||||||
|
return get().stream().filter(p -> p != controllingSystem && p.getDistance(controllingSystem) <= CONTROLLING_RADIUS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
default Collection<Vendor> getVendors(){
|
default Collection<Vendor> getVendors(){
|
||||||
return getVendors(false);
|
return getVendors(false);
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package ru.trader.core;
|
package ru.trader.core;
|
||||||
|
|
||||||
public enum POWER_STATE {
|
public enum POWER_STATE {
|
||||||
CONTROL, EXPLOITED, EXPANSION, NONE, CONTESTED, HEADQUARTERS;
|
CONTROL, EXPLOITED, EXPANSION, NONE, CONTESTED, HEADQUARTERS, BLOCKED, TURMOIL;
|
||||||
|
|
||||||
boolean isControl(){
|
boolean isControl(){
|
||||||
return this == CONTROL || this == HEADQUARTERS;
|
return this == CONTROL || this == HEADQUARTERS || this == TURMOIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isExploited(){
|
boolean isExploited(){
|
||||||
return this == EXPLOITED;
|
return this == EXPLOITED || this == BLOCKED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ public interface Place extends Connectable<Place> {
|
|||||||
double getZ();
|
double getZ();
|
||||||
void setPosition(double x, double y, double z);
|
void setPosition(double x, double y, double z);
|
||||||
|
|
||||||
|
long getPopulation();
|
||||||
|
void setPopulation(long population);
|
||||||
|
|
||||||
FACTION getFaction();
|
FACTION getFaction();
|
||||||
void setFaction(FACTION faction);
|
void setFaction(FACTION faction);
|
||||||
|
|
||||||
@@ -26,6 +29,12 @@ public interface Place extends Connectable<Place> {
|
|||||||
POWER getPower();
|
POWER getPower();
|
||||||
POWER_STATE getPowerState();
|
POWER_STATE getPowerState();
|
||||||
void setPower(POWER power, POWER_STATE state);
|
void setPower(POWER power, POWER_STATE state);
|
||||||
|
Collection<Place> getControllingSystems();
|
||||||
|
long getUpkeep();
|
||||||
|
void setUpkeep(long upkeep);
|
||||||
|
long getIncome();
|
||||||
|
void setIncome(long income);
|
||||||
|
|
||||||
|
|
||||||
Collection<Vendor> get();
|
Collection<Vendor> get();
|
||||||
default Collection<Vendor> get(boolean withTransit){
|
default Collection<Vendor> get(boolean withTransit){
|
||||||
|
|||||||
@@ -44,6 +44,12 @@ public class PlaceProxy extends AbstractPlace {
|
|||||||
store.getPlaceAccessor().update(place);
|
store.getPlaceAccessor().update(place);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updatePopulation(long population) {
|
||||||
|
place.setPopulation(population);
|
||||||
|
store.getPlaceAccessor().update(place);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateFaction(FACTION faction) {
|
protected void updateFaction(FACTION faction) {
|
||||||
place.setFaction(faction);
|
place.setFaction(faction);
|
||||||
@@ -62,6 +68,18 @@ public class PlaceProxy extends AbstractPlace {
|
|||||||
store.getPlaceAccessor().update(place);
|
store.getPlaceAccessor().update(place);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateUpkeep(long upkeep) {
|
||||||
|
place.setUpkeep(upkeep);
|
||||||
|
store.getPlaceAccessor().update(place);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateIncome(long income) {
|
||||||
|
place.setIncome(income);
|
||||||
|
store.getPlaceAccessor().update(place);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updatePosition(double x, double y, double z) {
|
protected void updatePosition(double x, double y, double z) {
|
||||||
place.setPosition(x, y, z);
|
place.setPosition(x, y, z);
|
||||||
@@ -97,6 +115,11 @@ public class PlaceProxy extends AbstractPlace {
|
|||||||
return place.getName();
|
return place.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getPopulation() {
|
||||||
|
return place.getPopulation();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FACTION getFaction() {
|
public FACTION getFaction() {
|
||||||
return place.getFaction();
|
return place.getFaction();
|
||||||
@@ -117,6 +140,16 @@ public class PlaceProxy extends AbstractPlace {
|
|||||||
return place.getPowerState();
|
return place.getPowerState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getUpkeep() {
|
||||||
|
return place.getUpkeep();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getIncome() {
|
||||||
|
return place.getIncome();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getX() {
|
public double getX() {
|
||||||
return place.getX();
|
return place.getX();
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import ru.trader.core.POWER_STATE;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Entity(version = 4)
|
@Entity(version = 5)
|
||||||
public class BDBPlace {
|
public class BDBPlace {
|
||||||
|
|
||||||
@PrimaryKey(sequence = "P_ID")
|
@PrimaryKey(sequence = "P_ID")
|
||||||
@@ -25,12 +25,16 @@ public class BDBPlace {
|
|||||||
private double x;
|
private double x;
|
||||||
private double y;
|
private double y;
|
||||||
private double z;
|
private double z;
|
||||||
|
private long population;
|
||||||
|
|
||||||
private FACTION faction;
|
private FACTION faction;
|
||||||
private GOVERNMENT government;
|
private GOVERNMENT government;
|
||||||
private POWER power;
|
private POWER power;
|
||||||
private POWER_STATE powerState;
|
private POWER_STATE powerState;
|
||||||
|
|
||||||
|
private long upkeep;
|
||||||
|
private long income;
|
||||||
|
|
||||||
private BDBPlace() {
|
private BDBPlace() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +55,14 @@ public class BDBPlace {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getPopulation() {
|
||||||
|
return population;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPopulation(long population) {
|
||||||
|
this.population = population;
|
||||||
|
}
|
||||||
|
|
||||||
public FACTION getFaction() {
|
public FACTION getFaction() {
|
||||||
return faction;
|
return faction;
|
||||||
}
|
}
|
||||||
@@ -80,6 +92,22 @@ public class BDBPlace {
|
|||||||
this.powerState = state;
|
this.powerState = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getUpkeep() {
|
||||||
|
return upkeep;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpkeep(long upkeep) {
|
||||||
|
this.upkeep = upkeep;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getIncome() {
|
||||||
|
return income;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIncome(long income) {
|
||||||
|
this.income = income;
|
||||||
|
}
|
||||||
|
|
||||||
public double getX() {
|
public double getX() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ public class MarketDocHandler extends DefaultHandler {
|
|||||||
protected final static String ECONOMIC_ATTR = "economic1";
|
protected final static String ECONOMIC_ATTR = "economic1";
|
||||||
protected final static String SUB_ECONOMIC_ATTR = "economic2";
|
protected final static String SUB_ECONOMIC_ATTR = "economic2";
|
||||||
protected final static String MODIFIED_ATTR = "modified";
|
protected final static String MODIFIED_ATTR = "modified";
|
||||||
|
protected final static String POPULATION_ATTR = "population";
|
||||||
|
protected final static String UPKEEP_ATTR = "upkeep";
|
||||||
|
protected final static String INCOME_ATTR = "income";
|
||||||
|
|
||||||
protected SimpleMarket world;
|
protected SimpleMarket world;
|
||||||
protected Vendor curVendor;
|
protected Vendor curVendor;
|
||||||
@@ -108,14 +111,16 @@ public class MarketDocHandler extends DefaultHandler {
|
|||||||
String faction = attributes.getValue(FACTION_ATTR);
|
String faction = attributes.getValue(FACTION_ATTR);
|
||||||
String government = attributes.getValue(GOVERNMENT_ATTR);
|
String government = attributes.getValue(GOVERNMENT_ATTR);
|
||||||
LOG.debug("parse place {} position ({};{};{}), faction {}, government {}", name, x, y, z, faction, government);
|
LOG.debug("parse place {} position ({};{};{}), faction {}, government {}", name, x, y, z, faction, government);
|
||||||
onPlace(name, x != null ? Double.valueOf(x) : 0, y != null ? Double.valueOf(y) : 0, z != null ? Double.valueOf(z) : 0,
|
onPlace(name, asDouble(x), asDouble(y), asDouble(z),
|
||||||
faction != null ? FACTION.valueOf(faction) : null, government != null ? GOVERNMENT.valueOf(government) : null
|
asEnum(faction, FACTION.class), asEnum(government, GOVERNMENT.class)
|
||||||
);
|
);
|
||||||
String power = attributes.getValue(POWER_ATTR);
|
String power = attributes.getValue(POWER_ATTR);
|
||||||
String powerState = attributes.getValue(POWER_STATE_ATTR);
|
String powerState = attributes.getValue(POWER_STATE_ATTR);
|
||||||
if (powerState != null && power != null){
|
String population = attributes.getValue(POPULATION_ATTR);
|
||||||
updatePlace(POWER.valueOf(power), POWER_STATE.valueOf(powerState));
|
String income = attributes.getValue(INCOME_ATTR);
|
||||||
}
|
String upkeep = attributes.getValue(UPKEEP_ATTR);
|
||||||
|
updatePlace(asEnum(power, POWER.class), asEnum(powerState, POWER_STATE.class),
|
||||||
|
asLong(population), asLong(upkeep), asLong(income));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseVendor(Attributes attributes) throws SAXException {
|
protected void parseVendor(Attributes attributes) throws SAXException {
|
||||||
@@ -129,9 +134,9 @@ public class MarketDocHandler extends DefaultHandler {
|
|||||||
String modifiedTime = attributes.getValue(MODIFIED_ATTR);
|
String modifiedTime = attributes.getValue(MODIFIED_ATTR);
|
||||||
modified = modifiedTime != null ? LocalDateTime.parse(modifiedTime) : null;
|
modified = modifiedTime != null ? LocalDateTime.parse(modifiedTime) : null;
|
||||||
LOG.debug("parse vendor {}, type {}, distance {}, faction {}, government {}", name, type, distance, faction, government);
|
LOG.debug("parse vendor {}, type {}, distance {}, faction {}, government {}", name, type, distance, faction, government);
|
||||||
onVendor(name, type != null ? STATION_TYPE.valueOf(type) : null, distance != null ? Double.valueOf(distance) : 0,
|
onVendor(name, asEnum(type, STATION_TYPE.class), asDouble(distance),
|
||||||
faction != null ? FACTION.valueOf(faction) : null, government != null ? GOVERNMENT.valueOf(government) : null);
|
asEnum(faction, FACTION.class), asEnum(government, GOVERNMENT.class));
|
||||||
updateVendor(economic != null ? ECONOMIC_TYPE.valueOf(economic) : null, subEconomic != null ? ECONOMIC_TYPE.valueOf(subEconomic) : null);
|
updateVendor(asEnum(economic, ECONOMIC_TYPE.class), asEnum(subEconomic, ECONOMIC_TYPE.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseService(Attributes attributes) throws SAXException {
|
protected void parseService(Attributes attributes) throws SAXException {
|
||||||
@@ -206,9 +211,14 @@ public class MarketDocHandler extends DefaultHandler {
|
|||||||
curPlace.setGovernment(government);
|
curPlace.setGovernment(government);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updatePlace(POWER power, POWER_STATE powerState){
|
protected void updatePlace(POWER power, POWER_STATE powerState, long population, long upkeep, long income){
|
||||||
|
if (power != null && powerState != null) {
|
||||||
curPlace.setPower(power, powerState);
|
curPlace.setPower(power, powerState);
|
||||||
}
|
}
|
||||||
|
curPlace.setPopulation(population);
|
||||||
|
curPlace.setUpkeep(upkeep);
|
||||||
|
curPlace.setIncome(income);
|
||||||
|
}
|
||||||
|
|
||||||
protected void onVendor(String name, STATION_TYPE type, double distance, FACTION faction, GOVERNMENT government){
|
protected void onVendor(String name, STATION_TYPE type, double distance, FACTION faction, GOVERNMENT government){
|
||||||
curVendor = curPlace.addVendor(name);
|
curVendor = curPlace.addVendor(name);
|
||||||
@@ -271,4 +281,18 @@ public class MarketDocHandler extends DefaultHandler {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long asLong(String attr){
|
||||||
|
if (attr != null) return Long.valueOf(attr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double asDouble(String attr){
|
||||||
|
if (attr != null) return Double.valueOf(attr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends Enum<T>> T asEnum(String attr, Class<T> enumClass){
|
||||||
|
if (attr != null) return Enum.valueOf(enumClass, attr);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,11 @@ public class MarketStreamWriter {
|
|||||||
out.writeAttribute(MarketDocHandler.X_ATTR, String.valueOf(place.getX()));
|
out.writeAttribute(MarketDocHandler.X_ATTR, String.valueOf(place.getX()));
|
||||||
out.writeAttribute(MarketDocHandler.Y_ATTR, String.valueOf(place.getY()));
|
out.writeAttribute(MarketDocHandler.Y_ATTR, String.valueOf(place.getY()));
|
||||||
out.writeAttribute(MarketDocHandler.Z_ATTR, String.valueOf(place.getZ()));
|
out.writeAttribute(MarketDocHandler.Z_ATTR, String.valueOf(place.getZ()));
|
||||||
|
|
||||||
|
out.writeAttribute(MarketDocHandler.POPULATION_ATTR, String.valueOf(place.getPopulation()));
|
||||||
|
out.writeAttribute(MarketDocHandler.UPKEEP_ATTR, String.valueOf(place.getUpkeep()));
|
||||||
|
out.writeAttribute(MarketDocHandler.INCOME_ATTR, String.valueOf(place.getIncome()));
|
||||||
|
|
||||||
for (Vendor vendor : place.get()) {
|
for (Vendor vendor : place.get()) {
|
||||||
writeVendor(vendor);
|
writeVendor(vendor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,13 @@ public class SimplePlace extends AbstractPlace {
|
|||||||
private double y;
|
private double y;
|
||||||
private double z;
|
private double z;
|
||||||
|
|
||||||
|
private long population;
|
||||||
private FACTION faction;
|
private FACTION faction;
|
||||||
private GOVERNMENT government;
|
private GOVERNMENT government;
|
||||||
private POWER power;
|
private POWER power;
|
||||||
private POWER_STATE powerState;
|
private POWER_STATE powerState;
|
||||||
|
private long upkeep;
|
||||||
|
private long income;
|
||||||
|
|
||||||
|
|
||||||
public SimplePlace(String name) {
|
public SimplePlace(String name) {
|
||||||
@@ -45,6 +48,11 @@ public class SimplePlace extends AbstractPlace {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getPopulation() {
|
||||||
|
return population;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FACTION getFaction() {
|
public FACTION getFaction() {
|
||||||
return faction;
|
return faction;
|
||||||
@@ -65,6 +73,16 @@ public class SimplePlace extends AbstractPlace {
|
|||||||
return powerState;
|
return powerState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getUpkeep() {
|
||||||
|
return upkeep;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getIncome() {
|
||||||
|
return income;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getX() {
|
public double getX() {
|
||||||
return x;
|
return x;
|
||||||
@@ -90,6 +108,21 @@ public class SimplePlace extends AbstractPlace {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updatePopulation(long population) {
|
||||||
|
this.population = population;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateUpkeep(long upkeep) {
|
||||||
|
this.upkeep = upkeep;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateIncome(long income) {
|
||||||
|
this.income = income;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateFaction(FACTION faction) {
|
protected void updateFaction(FACTION faction) {
|
||||||
this.faction = faction;
|
this.faction = faction;
|
||||||
|
|||||||
@@ -66,6 +66,9 @@
|
|||||||
<xs:attribute name="x" type="xs:double" use="optional"/>
|
<xs:attribute name="x" type="xs:double" use="optional"/>
|
||||||
<xs:attribute name="y" type="xs:double" use="optional"/>
|
<xs:attribute name="y" type="xs:double" use="optional"/>
|
||||||
<xs:attribute name="z" type="xs:double" use="optional"/>
|
<xs:attribute name="z" type="xs:double" use="optional"/>
|
||||||
|
<xs:attribute name="population" type="xs:long" use="optional"/>
|
||||||
|
<xs:attribute name="upkeep" type="xs:long" use="optional"/>
|
||||||
|
<xs:attribute name="income" type="xs:long" use="optional"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
|
||||||
<xs:complexType name="vendorType" mixed="true">
|
<xs:complexType name="vendorType" mixed="true">
|
||||||
@@ -151,6 +154,8 @@
|
|||||||
<xs:enumeration value="EXPANSION"/>
|
<xs:enumeration value="EXPANSION"/>
|
||||||
<xs:enumeration value="CONTESTED"/>
|
<xs:enumeration value="CONTESTED"/>
|
||||||
<xs:enumeration value="HEADQUARTERS"/>
|
<xs:enumeration value="HEADQUARTERS"/>
|
||||||
|
<xs:enumeration value="TURMOIL"/>
|
||||||
|
<xs:enumeration value="BLOCKED"/>
|
||||||
<xs:enumeration value="NONE"/>
|
<xs:enumeration value="NONE"/>
|
||||||
</xs:restriction>
|
</xs:restriction>
|
||||||
</xs:simpleType>
|
</xs:simpleType>
|
||||||
|
|||||||
Reference in New Issue
Block a user