private static SectorEntityToken buildEntity(StarSystemAPI pickedSystem, FactionAPI faction, int minMarketSize, int maxMarketSize, boolean isCapital){
int marketSize = MathUtils.getRandomNumberInRange(minMarketSize, maxMarketSize);
if(isCapital) marketSize = maxMarketSize;
float orbit = pickOrbitalRadius(pickedSystem);
float orbitalPeriod = ((orbit / 4500f) * 200f) * MathUtils.getRandomNumberInRange(0.5f, 1.5f);
SectorEntityToken ezColony;
String starName = pickedSystem.getStar().getName();
String factionID = faction.getId();
String denomination = pickDenomination(pickedSystem,false,true);
try{
ezColony = pickedSystem.addPlanet(starName + factionID + "planet" + denomination + MathUtils.getRandom(),//Attempts to build a random numbered location id; needs improving
pickedSystem.getStar(), //Orbital focus
starName + " Colony " + denomination,//Probably needs improving
planetType(faction),//Pulls a string at random
MathUtils.getRandomNumberInRange(30f,60f),//Planet angle
MathUtils.getRandomNumberInRange(50f,300f),//Planet radius
orbit,//Orbital radius
orbitalPeriod);//Orbital period
}catch (Throwable ex) {
return null;
}
ezColony.setFaction(faction.getId());
ezColony.setInteractionImage("illustrations", ILLUSTRATIONS.get((int)MathUtils.getRandomNumberInRange(0, ILLUSTRATIONS.size()-1)));
ezColony.addTag("customPlanet");
//Sets up the Market and attaches to the ezColony SectorEntityAPI
MarketAPI market = Global.getFactory().createMarket(faction.getId() + ezColony.getId() +"_market"+MathUtils.getRandom(), ezColony.getName(), marketSize);
market.setHidden(false);
market.setSurveyLevel(SurveyLevel.FULL);
market.setFactionId(faction.getId());
market.setPrimaryEntity(ezColony);
//Set the market's size and population here
market.setSize(marketSize);
assignPopulation(market,marketSize);
//Set up all of the Market Conditions here
if(isCapital == true || MathUtils.getRandomNumberInRange(0f, 100f) > 66f) {
int thisStationType = MathUtils.getRandomNumberInRange(0, 2);
switch (thisStationType){
case 0:
market.addIndustry(Industries.BATTLESTATION);
market.addIndustry(Industries.MILITARYBASE);
market.addIndustry(Industries.HEAVYINDUSTRY);
break;
case 1:
market.addIndustry(Industries.BATTLESTATION_MID);
market.addIndustry(Industries.MILITARYBASE);
market.addIndustry(Industries.HEAVYINDUSTRY);
break;
case 2:
market.addIndustry(Industries.BATTLESTATION_HIGH);
market.addIndustry(Industries.MILITARYBASE);
market.addIndustry(Industries.HEAVYINDUSTRY);
break;
default:
market.addIndustry(Industries.BATTLESTATION);
market.addIndustry(Industries.MILITARYBASE);
market.addIndustry(Industries.HEAVYINDUSTRY);
break;
}
}
//Sets up the Market with Conditions and some Industries.
market.addIndustry(Industries.SPACEPORT);
setMarketConditions(market, ezColony, false, false);
if(market.hasIndustry(Industries.HEAVYINDUSTRY) && market.hasIndustry(Industries.MILITARYBASE)){
market.addSubmarket(Submarkets.GENERIC_MILITARY);
}
market.addSubmarket(Submarkets.SUBMARKET_OPEN);
market.addSubmarket(Submarkets.LOCAL_RESOURCES);
market.addSubmarket(Submarkets.SUBMARKET_BLACK);
market.addSubmarket(Submarkets.SUBMARKET_STORAGE);
market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.FOOD, 1000);
market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.DOMESTIC_GOODS, 100);
market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.ORGANICS, 3000);
market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.VOLATILES, 3000);
market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.HEAVY_MACHINERY, 1000);
market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.METALS, 1000);
market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCommodity(Commodities.RARE_METALS, 1000);
market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addCrew(300);
market.getSubmarket(Submarkets.SUBMARKET_OPEN).getCargo().addFuel(5000);
Misc.getLocalResourcesCargo(market).addSupplies(4000f);
Misc.getLocalResourcesCargo(market).addFuel(10000f);
Misc.getLocalResourcesCargo(market).addItems(CargoItemType.RESOURCES, Commodities.HEAVY_MACHINERY, 500f);
Misc.getLocalResourcesCargo(market).addItems(CargoItemType.RESOURCES, Commodities.FOOD, 8000f);
market.setUseStockpilesForShortages(true);
market.setEconGroup(market.getId());
buildCommRelayIfNeeded(pickedSystem,faction);
//Logger log = Global.getLogger(CoreScript.class);
//log.info("Created EZ Faction Colony " + ezColony.getName() + " for Faction " + faction.getDisplayName() + " at System " +pickedSystem.getBaseName());
ezColony.setMarket(market);
Global.getSector().getEconomy().addMarket(market,true);
//PICKED_SYSTEMS.add(pickedSystem.getName());
return ezColony;
}
All of the above should mean the Market's populated, has all the bits and pieces and has a Spaceport. Not sure what triggers the visibility thing in the UI, though. At one point, it worked; then, after I fixed the crash-bug above... somewhere along the way, it's stopped working.