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 ReadOnlyStringProperty maxSizePad;
|
||||
private final ReadOnlyIntegerProperty intersectCount;
|
||||
private final ReadOnlyStringProperty intersecting;
|
||||
private final ReadOnlyStringProperty controlling;
|
||||
|
||||
public ResultEntry(PowerPlayAnalyzator.IntersectData data) {
|
||||
@@ -328,7 +329,8 @@ public class PowerPlayController {
|
||||
maxSizePad = new SimpleStringProperty(starSystem.getMaxSizePad());
|
||||
intersectCount = new SimpleIntegerProperty(data.getCount());
|
||||
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);
|
||||
Place hq = ModelFabric.get(hqSystem.orElse(null));
|
||||
distanceHQ = new SimpleDoubleProperty(hq != null ? hq.getDistance(data.getStarSystem()) : Double.NaN);
|
||||
@@ -344,6 +346,15 @@ public class PowerPlayController {
|
||||
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(){
|
||||
return new SimpleStringProperty(String.format("%s (%.0f Ls)", nearStation.getName(), nearStation.getDistance()));
|
||||
@@ -388,5 +399,9 @@ public class PowerPlayController {
|
||||
public ReadOnlyStringProperty controllingProperty() {
|
||||
return controlling;
|
||||
}
|
||||
|
||||
public ReadOnlyStringProperty intersectingProperty() {
|
||||
return intersecting;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ import java.util.stream.Stream;
|
||||
|
||||
public class PowerPlayAnalyzator {
|
||||
private final static Logger LOG = LoggerFactory.getLogger(PowerPlayAnalyzator.class);
|
||||
private final static double CONTROLLING_RADIUS = 15;
|
||||
|
||||
private final Market market;
|
||||
private StarSystemFilter starSystemFilter;
|
||||
@@ -33,25 +32,25 @@ public class PowerPlayAnalyzator {
|
||||
|
||||
public Collection<IntersectData> getControlling(Place starSystem){
|
||||
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){
|
||||
return getIntersects(market.get(), starSystems, CONTROLLING_RADIUS);
|
||||
return getIntersects(market.get(), starSystems, Market.CONTROLLING_RADIUS);
|
||||
}
|
||||
|
||||
public Collection<IntersectData> getIntersects(Place starSystem, Collection<Place> starSystems){
|
||||
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){
|
||||
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){
|
||||
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){
|
||||
|
||||
@@ -76,6 +76,8 @@ public abstract class AbstractItemStat implements ItemStat {
|
||||
throw new UnsupportedOperationException("Is fake place, change unsupported");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public FACTION getFaction() {
|
||||
return FACTION.NONE;
|
||||
@@ -155,6 +157,41 @@ public abstract class AbstractItemStat implements ItemStat {
|
||||
public int compareTo(Connectable<Place> o) {
|
||||
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() {
|
||||
|
||||
@@ -3,6 +3,9 @@ package ru.trader.core;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class AbstractMarket implements Market {
|
||||
private final static Logger LOG = LoggerFactory.getLogger(AbstractMarket.class);
|
||||
|
||||
@@ -10,15 +13,25 @@ public abstract class AbstractMarket implements Market {
|
||||
private boolean batch;
|
||||
|
||||
protected abstract Place createPlace(String name, double x, double y, double z);
|
||||
|
||||
protected abstract Group createGroup(String name, GROUP_TYPE type);
|
||||
|
||||
protected abstract Item createItem(String name, Group group);
|
||||
|
||||
protected abstract void addGroup(Group group);
|
||||
|
||||
protected abstract void removeGroup(Group group);
|
||||
|
||||
protected abstract void addPlace(Place place);
|
||||
|
||||
protected abstract void removePlace(Place place);
|
||||
|
||||
protected abstract void addItem(Item item);
|
||||
|
||||
protected abstract void removeItem(Item item);
|
||||
protected void executeBatch(){}
|
||||
|
||||
protected void executeBatch() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startBatch() {
|
||||
@@ -30,6 +43,7 @@ public abstract class AbstractMarket implements Market {
|
||||
public final void doBatch() {
|
||||
LOG.debug("End batch, updated");
|
||||
executeBatch();
|
||||
updateControllings();
|
||||
batch = false;
|
||||
}
|
||||
|
||||
@@ -39,11 +53,14 @@ public abstract class AbstractMarket implements Market {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void add(Place place){
|
||||
public final void add(Place place) {
|
||||
LOG.debug("Add place {} to market {}", place, this);
|
||||
change = true;
|
||||
if (place instanceof AbstractPlace){
|
||||
if (place instanceof AbstractPlace) {
|
||||
((AbstractPlace) place).setMarket(this);
|
||||
if (!isBatch()) {
|
||||
updateControlling((AbstractPlace) place);
|
||||
}
|
||||
}
|
||||
addPlace(place);
|
||||
}
|
||||
@@ -56,14 +73,17 @@ public abstract class AbstractMarket implements Market {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void remove(Place place){
|
||||
public final void remove(Place place) {
|
||||
LOG.debug("Remove place {} from market {}", place, this);
|
||||
change = true;
|
||||
removePlace(place);
|
||||
if (!isBatch()) {
|
||||
removeControlling(place);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void add(Group group){
|
||||
public final void add(Group group) {
|
||||
LOG.debug("Add group {} to market {}", group, this);
|
||||
change = true;
|
||||
addGroup(group);
|
||||
@@ -84,10 +104,10 @@ public abstract class AbstractMarket implements Market {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void add(Item item){
|
||||
public final void add(Item item) {
|
||||
LOG.debug("Add item {} to market {}", item, this);
|
||||
change = true;
|
||||
if (item instanceof AbstractItem){
|
||||
if (item instanceof AbstractItem) {
|
||||
((AbstractItem) item).setMarket(this);
|
||||
}
|
||||
addItem(item);
|
||||
@@ -101,7 +121,7 @@ public abstract class AbstractMarket implements Market {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void remove(Item item){
|
||||
public final void remove(Item item) {
|
||||
LOG.debug("Remove item {} from market {}", item, this);
|
||||
change = true;
|
||||
removeItem(item);
|
||||
@@ -121,38 +141,103 @@ public abstract class AbstractMarket implements Market {
|
||||
this.change = change;
|
||||
}
|
||||
|
||||
protected void onAdd(Vendor vendor){}
|
||||
protected void onRemove(Vendor vendor){}
|
||||
protected void onAdd(Offer offer){}
|
||||
protected void onRemove(Offer offer){}
|
||||
protected void onAdd(Vendor vendor) {
|
||||
}
|
||||
|
||||
protected void updateName(AbstractPlace place, String name){
|
||||
protected void onRemove(Vendor vendor) {
|
||||
}
|
||||
|
||||
protected void onAdd(Offer offer) {
|
||||
}
|
||||
|
||||
protected void onRemove(Offer offer) {
|
||||
}
|
||||
|
||||
protected void updateName(AbstractPlace place, String name) {
|
||||
place.updateName(name);
|
||||
}
|
||||
|
||||
protected void updateFaction(AbstractPlace place, FACTION faction){
|
||||
protected void updatePopulation(AbstractPlace place, long population) {
|
||||
place.updatePopulation(population);
|
||||
}
|
||||
|
||||
protected void updateFaction(AbstractPlace place, FACTION faction) {
|
||||
place.updateFaction(faction);
|
||||
}
|
||||
|
||||
protected void updateGovernment(AbstractPlace place, GOVERNMENT government){
|
||||
protected void updateGovernment(AbstractPlace place, GOVERNMENT government) {
|
||||
place.updateGovernment(government);
|
||||
}
|
||||
|
||||
protected void updatePosition(AbstractPlace place, double x, double y, double z){
|
||||
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) {
|
||||
place.updatePosition(x, y, z);
|
||||
}
|
||||
|
||||
protected void updatePrice(AbstractOffer offer, double price){
|
||||
protected void updatePrice(AbstractOffer offer, double price) {
|
||||
ItemStat itemStat = getStat(offer);
|
||||
if (itemStat instanceof AbstractItemStat){
|
||||
((AbstractItemStat)itemStat).updatePrice(offer, price);
|
||||
if (itemStat instanceof AbstractItemStat) {
|
||||
((AbstractItemStat) itemStat).updatePrice(offer, price);
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateName(AbstractItem item, String name){
|
||||
protected void updateName(AbstractItem item, String name) {
|
||||
item.updateName(name);
|
||||
}
|
||||
|
||||
|
||||
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 ru.trader.analysis.graph.Connectable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class AbstractPlace implements Place {
|
||||
private final static Logger LOG = LoggerFactory.getLogger(AbstractPlace.class);
|
||||
private AbstractMarket market;
|
||||
|
||||
private Collection<Place> controlling;
|
||||
|
||||
protected abstract Vendor createVendor(String name);
|
||||
protected abstract void updateName(String name);
|
||||
protected abstract void updatePopulation(long population);
|
||||
protected abstract void updateFaction(FACTION faction);
|
||||
protected abstract void updateGovernment(GOVERNMENT government);
|
||||
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 addVendor(Vendor vendor);
|
||||
protected abstract void removeVendor(Vendor vendor);
|
||||
@@ -29,6 +37,11 @@ public abstract class AbstractPlace implements Place {
|
||||
return market;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Place> getControllingSystems() {
|
||||
return controlling != null ? controlling : Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setName(String name){
|
||||
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
|
||||
public final void setFaction(FACTION faction){
|
||||
if (market != null){
|
||||
@@ -75,12 +99,39 @@ public abstract class AbstractPlace implements Place {
|
||||
|
||||
@Override
|
||||
public final void setPower(POWER power, POWER_STATE state){
|
||||
POWER_STATE old = getPowerState();
|
||||
if (market != null){
|
||||
LOG.debug("Change power of place {} to {} of {}", this, state, power);
|
||||
updatePower(power, state);
|
||||
if (!market.isBatch()) {
|
||||
updateControlling(old, state);
|
||||
}
|
||||
market.setChange(true);
|
||||
} else {
|
||||
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
|
||||
public String toString() {
|
||||
return getName();
|
||||
|
||||
@@ -5,8 +5,10 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public interface Market {
|
||||
double CONTROLLING_RADIUS = 15;
|
||||
|
||||
void startBatch();
|
||||
void doBatch();
|
||||
@@ -74,6 +76,10 @@ public interface Market {
|
||||
.findFirst();
|
||||
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(){
|
||||
return getVendors(false);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package ru.trader.core;
|
||||
|
||||
public enum POWER_STATE {
|
||||
CONTROL, EXPLOITED, EXPANSION, NONE, CONTESTED, HEADQUARTERS;
|
||||
CONTROL, EXPLOITED, EXPANSION, NONE, CONTESTED, HEADQUARTERS, BLOCKED, TURMOIL;
|
||||
|
||||
boolean isControl(){
|
||||
return this == CONTROL || this == HEADQUARTERS;
|
||||
return this == CONTROL || this == HEADQUARTERS || this == TURMOIL;
|
||||
}
|
||||
|
||||
boolean isExploited(){
|
||||
return this == EXPLOITED;
|
||||
return this == EXPLOITED || this == BLOCKED;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ public interface Place extends Connectable<Place> {
|
||||
double getZ();
|
||||
void setPosition(double x, double y, double z);
|
||||
|
||||
long getPopulation();
|
||||
void setPopulation(long population);
|
||||
|
||||
FACTION getFaction();
|
||||
void setFaction(FACTION faction);
|
||||
|
||||
@@ -26,6 +29,12 @@ public interface Place extends Connectable<Place> {
|
||||
POWER getPower();
|
||||
POWER_STATE getPowerState();
|
||||
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();
|
||||
default Collection<Vendor> get(boolean withTransit){
|
||||
|
||||
@@ -44,6 +44,12 @@ public class PlaceProxy extends AbstractPlace {
|
||||
store.getPlaceAccessor().update(place);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updatePopulation(long population) {
|
||||
place.setPopulation(population);
|
||||
store.getPlaceAccessor().update(place);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateFaction(FACTION faction) {
|
||||
place.setFaction(faction);
|
||||
@@ -62,6 +68,18 @@ public class PlaceProxy extends AbstractPlace {
|
||||
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
|
||||
protected void updatePosition(double x, double y, double z) {
|
||||
place.setPosition(x, y, z);
|
||||
@@ -70,7 +88,7 @@ public class PlaceProxy extends AbstractPlace {
|
||||
|
||||
@Override
|
||||
protected void addVendor(Vendor vendor) {
|
||||
store.getVendorAccessor().put(((VendorProxy)vendor).getEntity());
|
||||
store.getVendorAccessor().put(((VendorProxy) vendor).getEntity());
|
||||
if (vendors != null || lock.isLocked()) {
|
||||
unsafe( (v) -> {
|
||||
if (vendors != null){
|
||||
@@ -82,7 +100,7 @@ public class PlaceProxy extends AbstractPlace {
|
||||
|
||||
@Override
|
||||
protected void removeVendor(Vendor vendor) {
|
||||
store.getVendorAccessor().delete(((VendorProxy)vendor).getEntity());
|
||||
store.getVendorAccessor().delete(((VendorProxy) vendor).getEntity());
|
||||
if (vendors != null || lock.isLocked()) {
|
||||
unsafe( (v) -> {
|
||||
if (vendors != null){
|
||||
@@ -97,6 +115,11 @@ public class PlaceProxy extends AbstractPlace {
|
||||
return place.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPopulation() {
|
||||
return place.getPopulation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FACTION getFaction() {
|
||||
return place.getFaction();
|
||||
@@ -117,6 +140,16 @@ public class PlaceProxy extends AbstractPlace {
|
||||
return place.getPowerState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUpkeep() {
|
||||
return place.getUpkeep();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getIncome() {
|
||||
return place.getIncome();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getX() {
|
||||
return place.getX();
|
||||
|
||||
@@ -11,7 +11,7 @@ import ru.trader.core.POWER_STATE;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity(version = 4)
|
||||
@Entity(version = 5)
|
||||
public class BDBPlace {
|
||||
|
||||
@PrimaryKey(sequence = "P_ID")
|
||||
@@ -25,12 +25,16 @@ public class BDBPlace {
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
private long population;
|
||||
|
||||
private FACTION faction;
|
||||
private GOVERNMENT government;
|
||||
private POWER power;
|
||||
private POWER_STATE powerState;
|
||||
|
||||
private long upkeep;
|
||||
private long income;
|
||||
|
||||
private BDBPlace() {
|
||||
}
|
||||
|
||||
@@ -51,6 +55,14 @@ public class BDBPlace {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getPopulation() {
|
||||
return population;
|
||||
}
|
||||
|
||||
public void setPopulation(long population) {
|
||||
this.population = population;
|
||||
}
|
||||
|
||||
public FACTION getFaction() {
|
||||
return faction;
|
||||
}
|
||||
@@ -80,6 +92,22 @@ public class BDBPlace {
|
||||
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() {
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -48,6 +48,9 @@ public class MarketDocHandler extends DefaultHandler {
|
||||
protected final static String ECONOMIC_ATTR = "economic1";
|
||||
protected final static String SUB_ECONOMIC_ATTR = "economic2";
|
||||
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 Vendor curVendor;
|
||||
@@ -108,14 +111,16 @@ public class MarketDocHandler extends DefaultHandler {
|
||||
String faction = attributes.getValue(FACTION_ATTR);
|
||||
String government = attributes.getValue(GOVERNMENT_ATTR);
|
||||
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,
|
||||
faction != null ? FACTION.valueOf(faction) : null, government != null ? GOVERNMENT.valueOf(government) : null
|
||||
onPlace(name, asDouble(x), asDouble(y), asDouble(z),
|
||||
asEnum(faction, FACTION.class), asEnum(government, GOVERNMENT.class)
|
||||
);
|
||||
String power = attributes.getValue(POWER_ATTR);
|
||||
String powerState = attributes.getValue(POWER_STATE_ATTR);
|
||||
if (powerState != null && power != null){
|
||||
updatePlace(POWER.valueOf(power), POWER_STATE.valueOf(powerState));
|
||||
}
|
||||
String population = attributes.getValue(POPULATION_ATTR);
|
||||
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 {
|
||||
@@ -129,9 +134,9 @@ public class MarketDocHandler extends DefaultHandler {
|
||||
String modifiedTime = attributes.getValue(MODIFIED_ATTR);
|
||||
modified = modifiedTime != null ? LocalDateTime.parse(modifiedTime) : null;
|
||||
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,
|
||||
faction != null ? FACTION.valueOf(faction) : null, government != null ? GOVERNMENT.valueOf(government) : null);
|
||||
updateVendor(economic != null ? ECONOMIC_TYPE.valueOf(economic) : null, subEconomic != null ? ECONOMIC_TYPE.valueOf(subEconomic) : null);
|
||||
onVendor(name, asEnum(type, STATION_TYPE.class), asDouble(distance),
|
||||
asEnum(faction, FACTION.class), asEnum(government, GOVERNMENT.class));
|
||||
updateVendor(asEnum(economic, ECONOMIC_TYPE.class), asEnum(subEconomic, ECONOMIC_TYPE.class));
|
||||
}
|
||||
|
||||
protected void parseService(Attributes attributes) throws SAXException {
|
||||
@@ -206,8 +211,13 @@ public class MarketDocHandler extends DefaultHandler {
|
||||
curPlace.setGovernment(government);
|
||||
}
|
||||
|
||||
protected void updatePlace(POWER power, POWER_STATE powerState){
|
||||
curPlace.setPower(power, 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.setPopulation(population);
|
||||
curPlace.setUpkeep(upkeep);
|
||||
curPlace.setIncome(income);
|
||||
}
|
||||
|
||||
protected void onVendor(String name, STATION_TYPE type, double distance, FACTION faction, GOVERNMENT government){
|
||||
@@ -271,4 +281,18 @@ public class MarketDocHandler extends DefaultHandler {
|
||||
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.Y_ATTR, String.valueOf(place.getY()));
|
||||
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()) {
|
||||
writeVendor(vendor);
|
||||
}
|
||||
|
||||
@@ -14,10 +14,13 @@ public class SimplePlace extends AbstractPlace {
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
private long population;
|
||||
private FACTION faction;
|
||||
private GOVERNMENT government;
|
||||
private POWER power;
|
||||
private POWER_STATE powerState;
|
||||
private long upkeep;
|
||||
private long income;
|
||||
|
||||
|
||||
public SimplePlace(String name) {
|
||||
@@ -45,6 +48,11 @@ public class SimplePlace extends AbstractPlace {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPopulation() {
|
||||
return population;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FACTION getFaction() {
|
||||
return faction;
|
||||
@@ -65,6 +73,16 @@ public class SimplePlace extends AbstractPlace {
|
||||
return powerState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUpkeep() {
|
||||
return upkeep;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getIncome() {
|
||||
return income;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getX() {
|
||||
return x;
|
||||
@@ -90,6 +108,21 @@ public class SimplePlace extends AbstractPlace {
|
||||
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
|
||||
protected void updateFaction(FACTION faction) {
|
||||
this.faction = faction;
|
||||
|
||||
@@ -66,6 +66,9 @@
|
||||
<xs:attribute name="x" 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="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 name="vendorType" mixed="true">
|
||||
@@ -151,6 +154,8 @@
|
||||
<xs:enumeration value="EXPANSION"/>
|
||||
<xs:enumeration value="CONTESTED"/>
|
||||
<xs:enumeration value="HEADQUARTERS"/>
|
||||
<xs:enumeration value="TURMOIL"/>
|
||||
<xs:enumeration value="BLOCKED"/>
|
||||
<xs:enumeration value="NONE"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
|
||||
Reference in New Issue
Block a user