Hi Guys,
Just an update on the addMarket method I've been helping people with. There is a small change to it in the latter part, this ensure that the faction entity is set for planet SectorEntityTokens when they are processed. You may have already observed issues with assigning rules.csv to a planet market dialogue with the rule $faction.id == [faction], and too many independents spawning.
//to prevent certain issues, make sure the faction is also set for the primary entity
primaryEntity.setFaction(factionID);
//get all associated entities and associate it back to the market we've created
if (null != connectedEntities) {
for (SectorEntityToken entity : connectedEntities) {
entity.setMarket(newMarket);
entity.setFaction(factionID);
}
}
Here is complete method. There have been no changes to the method signature. If you encounter any further issues, please send me a ping.
private void addMarketplace(String factionID, SectorEntityToken primaryEntity, ArrayList<SectorEntityToken> connectedEntities, String name, int size, ArrayList<String> marketConditions, ArrayList<String> submarkets, float tarrif) {
EconomyAPI globalEconomy = Global.getSector().getEconomy();
String planetID = primaryEntity.getId();
//generate the market ID
String marketID = planetID + "_market";
//generate the market
MarketAPI newMarket = Global.getFactory().createMarket(marketID, name, size);
//set the faction associated with the market
newMarket.setFactionId(factionID);
//set the primary entity related to the market
newMarket.setPrimaryEntity(primaryEntity);
//set the base smuggling value (starting value)
newMarket.setBaseSmugglingStabilityValue(0);
//set the starting tarrif, could also make this value an input
newMarket.getTariff().modifyFlat("generator", tarrif);
//add each sub-market types to the mark
if (null != submarkets) {
for (String market : submarkets) {
newMarket.addSubmarket(market);
}
}
//add each market conditions
for (String condition : marketConditions) {
newMarket.addCondition(condition);
}
//add all connected entities to this marketplace, moons/stations etc.
if (null != connectedEntities) {
for (SectorEntityToken entity : connectedEntities) {
newMarket.getConnectedEntities().add(entity);
}
}
//add the market to the global market place
globalEconomy.addMarket(newMarket);
//get the primary entity and associate it back to the market that we've created
primaryEntity.setMarket(newMarket);
//to prevent certain issues, make sure the faction is also set for the primary entity
primaryEntity.setFaction(factionID);
//get all associated entities and associate it back to the market we've created
if (null != connectedEntities) {
for (SectorEntityToken entity : connectedEntities) {
entity.setMarket(newMarket);
entity.setFaction(factionID);
}
}
}