1package com.fs.starfarer.api.impl.campaign.procgen.themes;
3import java.util.ArrayList;
4import java.util.Collections;
5import java.util.Comparator;
8import org.lwjgl.util.vector.Vector2f;
10import com.fs.starfarer.api.campaign.PlanetAPI;
11import com.fs.starfarer.api.campaign.StarSystemAPI;
12import com.fs.starfarer.api.impl.campaign.ids.Entities;
13import com.fs.starfarer.api.impl.campaign.ids.Tags;
14import com.fs.starfarer.api.impl.campaign.procgen.Constellation;
15import com.fs.starfarer.api.impl.campaign.procgen.NameAssigner;
16import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator;
17import com.fs.starfarer.api.impl.campaign.procgen.themes.SalvageSpecialAssigner.SpecialCreationContext;
18import com.fs.starfarer.api.util.Misc;
19import com.fs.starfarer.api.util.WeightedRandomPicker;
39 if (total <= 0)
return;
42 if (num > total) num = (int) total;
46 Collections.reverse(constellations);
49 if (total < num / (1f - skipProb)) {
50 skipProb = 1f - (num / total);
54 List<StarSystemData> ruinSystems =
new ArrayList<StarSystemData>();
56 if (
DEBUG) System.out.println(
"\n\n\n");
57 if (
DEBUG) System.out.println(
"Generating systems with ruins");
62 for (
int i = 0; i < num && i < constellations.size(); i++) {
64 if (
random.nextFloat() < skipProb) {
65 if (
DEBUG) System.out.println(
"Skipping constellation " + c.
getName());
74 List<StarSystemData> systems =
new ArrayList<StarSystemData>();
82 int numMain = 1 +
random.nextInt(3);
83 if (numMain > mainCandidates.size()) numMain = mainCandidates.size();
85 if (
DEBUG) System.out.println(
"Skipping constellation " + c.
getName() +
", no suitable main candidates");
92 if (
DEBUG) System.out.println(
"Generating " + numMain +
" main systems in " + c.
getName());
93 for (
int j = 0; j < numMain; j++) {
94 StarSystemData data = mainCandidates.get(j);
97 data.system.addTag(Tags.THEME_INTERESTING);
98 data.system.addTag(Tags.THEME_RUINS);
99 data.system.addTag(Tags.THEME_RUINS_MAIN);
100 ruinSystems.add(data);
103 data.system.addScript(fleets);
110 for (StarSystemData data : systems) {
111 int index = mainCandidates.indexOf(data);
112 if (index >= 0 && index < numMain)
continue;
116 data.system.addTag(Tags.THEME_INTERESTING);
117 data.system.addTag(Tags.THEME_RUINS);
118 data.system.addTag(Tags.THEME_RUINS_SECONDARY);
119 ruinSystems.add(data);
128 SpecialCreationContext specialContext =
new SpecialCreationContext();
132 if (
DEBUG) System.out.println(
"Finished generating systems with ruins\n\n\n\n\n");
139 if (
DEBUG) System.out.println(
" Generating secondary ruins in " + data.system.getName());
140 boolean special = data.isBlackHole() || data.isNebula() || data.isPulsar();
145 if (
random.nextFloat() < 0.5f)
return;
147 if (!data.resourceRich.isEmpty()) {
151 if (!special && !data.habitable.isEmpty()) {
166 Entities.WEAPONS_CACHE, 4f,
167 Entities.WEAPONS_CACHE_SMALL, 10f,
168 Entities.WEAPONS_CACHE_HIGH, 4f,
169 Entities.WEAPONS_CACHE_SMALL_HIGH, 10f,
170 Entities.WEAPONS_CACHE_LOW, 4f,
171 Entities.WEAPONS_CACHE_SMALL_LOW, 10f,
172 Entities.SUPPLY_CACHE, 4f,
173 Entities.SUPPLY_CACHE_SMALL, 10f,
174 Entities.EQUIPMENT_CACHE, 4f,
175 Entities.EQUIPMENT_CACHE_SMALL, 10f
183 if (
DEBUG) System.out.println(
" Generating ruins in " + data.system.getName());
185 StarSystemAPI system = data.system;
187 int maxHabCenters = 1 +
random.nextInt(3);
189 HabitationLevel level = HabitationLevel.LOW;
190 if (maxHabCenters == 2) level = HabitationLevel.MEDIUM;
191 if (maxHabCenters >= 3) level = HabitationLevel.HIGH;
197 float probRelay = 1f;
198 float probMining = 0.5f;
199 float probResearch = 0.25f;
247 Entities.SUPPLY_CACHE, 10f,
248 Entities.SUPPLY_CACHE_SMALL, 10f,
249 Entities.EQUIPMENT_CACHE, 10f,
250 Entities.EQUIPMENT_CACHE_SMALL, 10f
254 float r =
random.nextFloat();
256 caches.add(Entities.WEAPONS_CACHE, 10f);
257 caches.add(Entities.WEAPONS_CACHE_SMALL, 10f);
258 }
else if (r < 0.67f) {
259 caches.add(Entities.WEAPONS_CACHE_LOW, 10f);
260 caches.add(Entities.WEAPONS_CACHE_SMALL_LOW, 10f);
262 caches.add(Entities.WEAPONS_CACHE_HIGH, 10f);
263 caches.add(Entities.WEAPONS_CACHE_SMALL_HIGH, 10f);
273 List<StarSystemData> result =
new ArrayList<StarSystemData>();
275 for (StarSystemData data : systems) {
276 if (data.isBlackHole() || data.isNebula() || data.isPulsar())
continue;
278 if (data.planets.size() >= 4 || data.habitable.size() >= 1) {
283 Collections.sort(systems,
new Comparator<StarSystemData>() {
284 public int compare(StarSystemData o1, StarSystemData o2) {
287 return (
int) Math.signum(s2 - s1);
296 total += data.planets.size() * 1f;
297 total += data.habitable.size() * 2f;
298 total += data.resourceRich.size() * 0.25f;
311 List<Constellation> constellations =
new ArrayList<Constellation>();
316 constellations.add(c);
319 if (exclude !=
null) {
320 constellations.removeAll(exclude);
323 Collections.sort(constellations,
new Comparator<Constellation>() {
325 float d1 = Misc.getDistance(o1.
getLocation(), sortFrom);
326 float d2 = Misc.getDistance(o2.
getLocation(), sortFrom);
327 return (
int) Math.signum(d2 - d1);
330 return constellations;
341 for (PlanetAPI p : system.getPlanets()) {
342 if (!p.isStar())
return false;
List< StarSystemAPI > getSystems()
static boolean isNameSpecial(StarSystemAPI system)
void assignSpecialNames(NamingTreeNode curr)
static float getNormalRandom(float min, float max)
void addShipGraveyard(StarSystemData data, float chanceToAddAny, int min, int max, WeightedRandomPicker< String > factions)
static StarSystemData computeSystemData(StarSystemAPI system)
void addResearchStations(StarSystemData data, float chanceToAddAny, int min, int max, WeightedRandomPicker< String > stationTypes)
List< AddedEntity > addObjectives(StarSystemData data, float prob)
void addCaches(StarSystemData data, float chanceToAddAny, int min, int max, WeightedRandomPicker< String > cacheTypes)
void addDerelictShips(StarSystemData data, float chanceToAddAny, int min, int max, WeightedRandomPicker< String > factions)
AddedEntity addInactiveGate(StarSystemData data, float prob, float probDebris, float probShips, WeightedRandomPicker< String > factions)
WeightedRandomPicker< String > createStringPicker(Object ... params)
void addHabCenters(StarSystemData data, float chanceToAddAny, int min, int max, WeightedRandomPicker< String > stationTypes)
void addDebrisFields(StarSystemData data, float chanceToAddAny, int min, int max)
void addMiningStations(StarSystemData data, float chanceToAddAny, int min, int max, WeightedRandomPicker< String > stationTypes)
void generateForSector(ThemeGenContext context, float allowedUnusedFraction)
void populateNonMain(StarSystemData data)
float getMainCenterScore(StarSystemData data)
static boolean systemIsEmpty(StarSystemAPI system)
static final int MIN_CONSTELLATIONS_WITH_RUINS
List< StarSystemData > getSortedSystemsSuitedToBePopulated(List< StarSystemData > systems)
static boolean constellationIsEmpty(Constellation c)
static final int MAX_CONSTELLATIONS_WITH_RUINS
List< Constellation > getSortedAvailableConstellations(ThemeGenContext context, boolean emptyOk, final Vector2f sortFrom, List< Constellation > exclude)
void populateMain(StarSystemData data)
static float CONSTELLATION_SKIP_PROB
static void assignSpecials(SectorEntityToken entity)
static WeightedRandomPicker< String > getNearbyFactions(Random random, SectorEntityToken entity)
List< Constellation > constellations
Map< Constellation, String > majorThemes
static final String RUINS