35 public static Map<String, ConditionGenerator>
generators =
new HashMap<String, ConditionGenerator>();
57 if (context ==
null) {
65 List<ConditionGenDataSpec> specs =
new ArrayList<ConditionGenDataSpec>();
70 Collections.sort(specs,
new Comparator<ConditionGenDataSpec>() {
76 Map<String, List<String>> groupsInOrder =
new LinkedHashMap<String, List<String>>();
77 float prevGroup = -100000;
78 List<String> currList =
null;
80 float currGroup = spec.getOrder();
81 if (prevGroup != currGroup) {
82 currList =
new ArrayList<String>();
83 groupsInOrder.put(spec.getGroup(), currList);
85 prevGroup = currGroup;
87 if (!currList.contains(spec.getGroup())) {
88 currList.add(spec.getGroup());
105 Set<String> conditionsSoFar =
new HashSet<String>();
112 for (String key : groupsInOrder.keySet()) {
113 List<String> groups = groupsInOrder.get(key);
114 for (String group : groups) {
115 WeightedRandomPicker<String> picker =
getGroupPicker(group, conditionsSoFar, context, planet);
116 String pick = picker.pick();
118 conditionsSoFar.add(pick);
122 for (String group : groups) {
123 ConditionGenerator generator =
generators.get(group);
124 if (generator !=
null) {
125 generator.addConditions(conditionsSoFar, context, planet);
132 MarketAPI market = planet.getMarket();
133 if (market ==
null) {
136 market.setPlanetConditionMarketOnly(
true);
137 market.setPrimaryEntity(planet);
138 market.setFactionId(Factions.NEUTRAL);
139 planet.setMarket(market);
142 for (String cid : conditionsSoFar) {
146 MarketConditionAPI mc = market.getSpecificCondition(market.addCondition(cid));
152 market.reapplyConditions();
156 public static WeightedRandomPicker<String>
getGroupPicker(String group, Set<String> conditionsSoFar,
157 GenContext context, PlanetAPI planet) {
163 String planetType = planet.getSpec().getPlanetType();
174 if (data.hasMultiplier(planetType)) {
175 weight = data.getMultiplier(planetType);
176 }
else if (data.hasMultiplier(category)) {
177 weight = data.getMultiplier(category);
182 for (String cid : conditionsSoFar) {
183 if (data.hasMultiplier(cid)) {
184 weight *= data.getMultiplier(cid);
188 if (weight <= 0)
continue;
192 picker.add(data.getId(), weight);
249 if (!(planet.getContainingLocation() instanceof StarSystemAPI))
return null;
251 StarSystemAPI system = (StarSystemAPI) planet.getContainingLocation();
253 CustomConstellationParams p =
new CustomConstellationParams(age);
258 gen.constellationAge = age;
260 gen.star = system.getStar();
263 gen.systemCenter = system.getCenter();
266 PlanetAPI parentPlanet =
null;
267 PlanetAPI parentStar =
null;
268 if (planet.getOrbitFocus() instanceof PlanetAPI) {
269 PlanetAPI p1 = (PlanetAPI) planet.getOrbitFocus();
271 if (p1.getOrbitFocus() instanceof PlanetAPI) {
272 p2 = (PlanetAPI) p1.getOrbitFocus();
278 if (p2 !=
null && p2.isStar()) {
281 parentStar = system.getStar();
285 parentStar = system.getStar();
290 if (parentStar !=
null) {
293 if (parentPlanet !=
null) {
297 int parentOrbitIndex = -1;
301 if (parentPlanet ==
null) {
302 orbitIndex = Misc.getEstimatedOrbitIndex(planet);
303 parentOrbitIndex = -1;
304 float dist = Misc.getDistance(parentStar.getLocation(), planet.getLocation());
307 parentOrbitIndex = Misc.getEstimatedOrbitIndex(planet);
309 if (parentPlanet.getOrbitFocus() !=
null) {
310 dist = Misc.getDistance(parentPlanet.getLocation(), parentPlanet.getOrbitFocus().getLocation());
322 GenContext context =
new GenContext(gen, system, gen.
systemCenter, starData,
324 planetData !=
null ? planetData.
getCategory() :
null, parentOrbitIndex);
325 context.orbitIndex = orbitIndex;