Starsector API
Loading...
Searching...
No Matches
AbyssalRogueStellarObjectEPEC.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.enc;
2
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.Collections;
6import java.util.Comparator;
7import java.util.List;
8import java.util.Random;
9
10import com.fs.starfarer.api.Global;
11import com.fs.starfarer.api.campaign.JumpPointAPI;
12import com.fs.starfarer.api.campaign.NascentGravityWellAPI;
13import com.fs.starfarer.api.campaign.PlanetAPI;
14import com.fs.starfarer.api.campaign.SectorAPI;
15import com.fs.starfarer.api.campaign.SectorEntityToken;
16import com.fs.starfarer.api.campaign.StarSystemAPI;
17import com.fs.starfarer.api.impl.campaign.ids.Conditions;
18import com.fs.starfarer.api.impl.campaign.ids.Planets;
19import com.fs.starfarer.api.impl.campaign.ids.StarTypes;
20import com.fs.starfarer.api.impl.campaign.ids.Tags;
21import com.fs.starfarer.api.impl.campaign.ids.Terrain;
22import com.fs.starfarer.api.impl.campaign.procgen.AccretionDiskGenPlugin;
23import com.fs.starfarer.api.impl.campaign.procgen.PlanetGenDataSpec;
24import com.fs.starfarer.api.impl.campaign.procgen.StarAge;
25import com.fs.starfarer.api.impl.campaign.procgen.StarGenDataSpec;
26import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator;
27import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator.CustomConstellationParams;
28import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator.GenContext;
29import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator.GenResult;
30import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator.GeneratedPlanet;
31import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator.StarSystemType;
32import com.fs.starfarer.api.impl.campaign.procgen.TerrainGenDataSpec;
33import com.fs.starfarer.api.impl.campaign.terrain.HyperspaceAbyssPluginImpl;
34import com.fs.starfarer.api.impl.campaign.terrain.HyperspaceAbyssPluginImpl.AbyssalEPData;
35import com.fs.starfarer.api.impl.campaign.terrain.HyperspaceTerrainPlugin;
36import com.fs.starfarer.api.impl.campaign.terrain.StarCoronaTerrainPlugin;
37import com.fs.starfarer.api.impl.campaign.terrain.StarCoronaTerrainPlugin.CoronaParams;
38import com.fs.starfarer.api.impl.campaign.world.GateHaulerLocation;
39import com.fs.starfarer.api.util.Misc;
40import com.fs.starfarer.api.util.Misc.CatalogEntryType;
41import com.fs.starfarer.api.util.WeightedRandomPicker;
42
44
45 public static enum RogueStellarObjectType {
46 PLANETOID,
47 GAS_GIANT,
48 BLACK_HOLE
49 }
50
51 public static float PROB_BLACK_HOLE_ORBITERS = 0.1f;
52
53 public static WeightedRandomPicker<RogueStellarObjectType> STELLAR_OBJECT_TYPES = new WeightedRandomPicker<RogueStellarObjectType>();
54 static {
55 STELLAR_OBJECT_TYPES.add(RogueStellarObjectType.PLANETOID, 100f);
56 STELLAR_OBJECT_TYPES.add(RogueStellarObjectType.GAS_GIANT, 20f);
57 STELLAR_OBJECT_TYPES.add(RogueStellarObjectType.BLACK_HOLE, 7f);
58 }
59
60 public static WeightedRandomPicker<String> PLANETOID_TYPES = new WeightedRandomPicker<String>();
61 static {
62 PLANETOID_TYPES.add(Planets.CRYOVOLCANIC, 5f);
63 PLANETOID_TYPES.add(Planets.FROZEN, 2.5f);
64 PLANETOID_TYPES.add(Planets.FROZEN1, 2.5f);
65 PLANETOID_TYPES.add(Planets.FROZEN2, 2.5f);
66 PLANETOID_TYPES.add(Planets.FROZEN3, 2.5f);
67 PLANETOID_TYPES.add(Planets.BARREN, 2.5f);
68 PLANETOID_TYPES.add(Planets.BARREN2, 2.5f);
69 PLANETOID_TYPES.add(Planets.BARREN3, 2.5f);
70 PLANETOID_TYPES.add(Planets.BARREN_CASTIRON, 2.5f);
71 PLANETOID_TYPES.add(Planets.BARREN_BOMBARDED, 5f);
72 PLANETOID_TYPES.add(Planets.ROCKY_METALLIC, 5f);
73 PLANETOID_TYPES.add(Planets.ROCKY_ICE, 5f);
74 }
75 public static WeightedRandomPicker<String> GAS_GIANT_TYPES = new WeightedRandomPicker<String>();
76 static {
77 GAS_GIANT_TYPES.add(Planets.ICE_GIANT, 10f);
78 GAS_GIANT_TYPES.add(Planets.GAS_GIANT, 5f);
79 }
80
81 public static WeightedRandomPicker<String> BLACK_HOLE_TYPES = new WeightedRandomPicker<String>();
82 static {
83 BLACK_HOLE_TYPES.add(StarTypes.BLACK_HOLE, 10f);
84 }
85
89
90
91 @Override
92 public void createEncounter(EncounterManager manager, EncounterPoint point) {
93
94 AbyssalEPData data = (AbyssalEPData) point.custom;
95 SectorAPI sector = Global.getSector();
96
97 StarSystemAPI system = sector.createStarSystem("Deep Space");
98 system.setProcgen(true);
99 //system.setType(StarSystemType.NEBULA);
100 system.setName("Deep Space"); // to get rid of "Star System" at the end of the name
101 system.setOptionalUniqueId(Misc.genUID());
102 system.setType(StarSystemType.DEEP_SPACE);
103 system.addTag(Tags.THEME_HIDDEN);
104 system.addTag(Tags.THEME_SPECIAL);
105 system.addTag(Tags.TEMPORARY_LOCATION);
106 system.addTag(Tags.SYSTEM_ABYSSAL);
107
108 if (data.random.nextFloat() < 0.5f) {
109 system.setBackgroundTextureFilename("graphics/backgrounds/background4.jpg");
110 } else {
111 system.setBackgroundTextureFilename("graphics/backgrounds/background5.jpg");
112 }
113
114 system.getLocation().set(point.loc.x, point.loc.y);
115
116 SectorEntityToken center = system.initNonStarCenter();
117
118 system.setLightColor(GateHaulerLocation.ABYSS_AMBIENT_LIGHT_COLOR);
119 center.addTag(Tags.AMBIENT_LS);
120
121 RogueStellarObjectType objectType = STELLAR_OBJECT_TYPES.pick(data.random);
122 if (objectType == null) return;
123
124 WeightedRandomPicker<StarAge> agePicker = new WeightedRandomPicker<StarAge>(data.random);
125 agePicker.add(StarAge.OLD, 10f);
126 agePicker.add(StarAge.AVERAGE, 5f);
127 agePicker.add(StarAge.YOUNG, 3f);
128
129 StarAge age = agePicker.pick();
130 String nebulaId = Planets.NEBULA_CENTER_OLD;
131 if (age == StarAge.AVERAGE) {
132 nebulaId = Planets.NEBULA_CENTER_AVERAGE;
133 } else if (age == StarAge.YOUNG) {
134 nebulaId = Planets.NEBULA_CENTER_YOUNG;
135 }
136
137
138 StarGenDataSpec starData = (StarGenDataSpec)
139 Global.getSettings().getSpec(StarGenDataSpec.class, nebulaId, false);
140
141 CustomConstellationParams params = new CustomConstellationParams(age);
142 Random prev = StarSystemGenerator.random;
143 StarSystemGenerator.random = data.random;
144
145 StarSystemGenerator gen = new StarSystemGenerator(params);
146 gen.init(system, age);
147
148 GenContext context = new GenContext(gen, system, system.getCenter(), starData,
149 null, 0, age.name(), 0, 1000, null, -1);
150 // just so it doesn't try to add things at the planet's lagrange points
151 context.lagrangeParent = new GeneratedPlanet(null, null, false, 0, 0, 0);
152
153 context.excludeCategories.add(StarSystemGenerator.CAT_HAB5);
154 context.excludeCategories.add(StarSystemGenerator.CAT_HAB4);
155 context.excludeCategories.add(StarSystemGenerator.CAT_HAB3);
156 context.excludeCategories.add(StarSystemGenerator.CAT_HAB2);
157
158 PlanetAPI main = null;
159
160
161 if (objectType == RogueStellarObjectType.BLACK_HOLE) {
162 main = addBlackHole(system, context, data);
163
164 if (main != null) {
165 system.setStar(main);
166 system.setCenter(main);
167 system.removeEntity(center);
168 center = main;
169
170 if (data.random.nextFloat() < PROB_BLACK_HOLE_ORBITERS || true) {
171 context.starData = (StarGenDataSpec)
172 Global.getSettings().getSpec(StarGenDataSpec.class, StarTypes.BLACK_HOLE, false);
173 StarSystemGenerator.addOrbitingEntities(system, main, age, 1, 3, 500, 0, false, false);
174 }
175 }
176 } else {
177 String planetType;
178 if (objectType == RogueStellarObjectType.PLANETOID) {
179 planetType = PLANETOID_TYPES.pick(data.random);
180 } else {
181 planetType = GAS_GIANT_TYPES.pick(data.random);
182 }
183 //planetType = Planets.CRYOVOLCANIC;
184 //planetType = Planets.GAS_GIANT;
185 PlanetGenDataSpec planetData = (PlanetGenDataSpec) Global.getSettings().getSpec(PlanetGenDataSpec.class, planetType, false);
186
187 GenResult result = gen.addPlanet(context, planetData, false, true);
188 if (result == null || result.entities.isEmpty() ||
189 !(result.entities.get(0) instanceof PlanetAPI)) return;
190 main = (PlanetAPI) result.entities.get(0);
191 }
192
193 if (main == null) return;
194
195 main.setOrbit(null);
196 main.setLocation(0, 0);
197
198 boolean multiple = context.generatedPlanets.size() > 1;
199 int index = data.random.nextInt(20);
200
201// List<GeneratedPlanet> sorted = new ArrayList<GeneratedPlanet>(context.generatedPlanets);
202// Collections.sort(sorted, new Comparator<GeneratedPlanet>() {
203// public int compare(GeneratedPlanet o1, GeneratedPlanet o2) {
204// return (int) Math.signum(o2.planet.getRadius() - o1.planet.getRadius());
205// }
206// });
207 List<PlanetAPI> sorted = new ArrayList<PlanetAPI>(system.getPlanets());
208 Collections.sort(sorted, new Comparator<PlanetAPI>() {
209 public int compare(PlanetAPI o1, PlanetAPI o2) {
210 return (int) Math.signum(o2.getRadius() - o1.getRadius());
211 }
212 });
213
214// for (GeneratedPlanet curr : sorted) {
215// PlanetAPI planet = curr.planet;
216 for (PlanetAPI planet : sorted) {
217 CatalogEntryType type = CatalogEntryType.PLANET;
218 if (planet.isGasGiant()) type = CatalogEntryType.GIANT;
219 if (planet.getSpec().isBlackHole()) type = CatalogEntryType.BLACK_HOLE;
220
221 String firstChar = null;
222 if (multiple) {
223 firstChar = "" + Character.valueOf((char) ('A' + (index % 26)));
224 index++;
225 }
226
227 String name = Misc.genEntityCatalogId(firstChar, -1, -1, -1, type);
228 planet.setName(name);
229 if (planet.getMarket() != null) {
230 planet.getMarket().setName(name);
231
232 planet.getMarket().removeCondition(Conditions.RUINS_SCATTERED);
233 planet.getMarket().removeCondition(Conditions.RUINS_WIDESPREAD);
234 planet.getMarket().removeCondition(Conditions.RUINS_EXTENSIVE);
235 planet.getMarket().removeCondition(Conditions.RUINS_VAST);
236 planet.getMarket().removeCondition(Conditions.DECIVILIZED);
237 planet.getMarket().removeCondition(Conditions.DECIVILIZED_SUBPOP);
238 planet.getMarket().removeCondition(Conditions.POLLUTION);
239 }
240
241 // the standard "barren" description mentions a primary star
242 if (planet.getSpec().getDescriptionId().equals(Planets.BARREN)) {
243 planet.setDescriptionIdOverride("barren_deep_space");
244 }
245
246 }
247
248
249 StarSystemGenerator.random = prev;
250
251 system.autogenerateHyperspaceJumpPoints(true, false, false);
252
254
255 system.addScript(new AbyssalLocationDespawner(system));
256
257 addSpecials(system, manager, point, data);
258 }
259
260 protected void addSpecials(StarSystemAPI system, EncounterManager manager, EncounterPoint point, AbyssalEPData data) {
261
262 }
263
264 public static void setAbyssalDetectedRanges(StarSystemAPI system) {
265 if (system.getAutogeneratedJumpPointsInHyper() != null) {
266 for (JumpPointAPI jp : system.getAutogeneratedJumpPointsInHyper()) {
267 if (jp.isStarAnchor()) {
268 jp.addTag(Tags.STAR_HIDDEN_ON_MAP);
269 }
270 float range = HyperspaceAbyssPluginImpl.JUMP_POINT_DETECTED_RANGE;
271 if (jp.isGasGiantAnchor()) {
272 range = HyperspaceAbyssPluginImpl.GAS_GIANT_DETECTED_RANGE;
273 } else if (jp.isStarAnchor()) {
274 range = HyperspaceAbyssPluginImpl.STAR_DETECTED_RANGE;
275 }
276
277 setAbyssalDetectedRange(jp, range);
278 }
279 }
280
281 if (system.getAutogeneratedNascentWellsInHyper() != null) {
282 for (NascentGravityWellAPI well : system.getAutogeneratedNascentWellsInHyper()) {
283 setAbyssalDetectedRange(well, HyperspaceAbyssPluginImpl.NASCENT_WELL_DETECTED_RANGE);
284 }
285 }
286 }
287
288 public static void setAbyssalDetectedRange(SectorEntityToken entity, float range) {
289 float detectedRange = range / HyperspaceTerrainPlugin.ABYSS_SENSOR_RANGE_MULT;
290
291 float maxSensorRange = Global.getSettings().getSensorRangeMaxHyper();
292 float desired = detectedRange * HyperspaceTerrainPlugin.ABYSS_SENSOR_RANGE_MULT;
293 if (desired > maxSensorRange) {
294 entity.setExtendedDetectedAtRange(desired - maxSensorRange);
295 }
296
297 entity.setSensorProfile(1f);
298 entity.setDiscoverable(false);
299 entity.getDetectedRangeMod().modifyFlat("jpDetRange", detectedRange);
300
301 float mult = Math.min(0.5f, 400f / range);
302 entity.setDetectionRangeDetailsOverrideMult(mult);
303
304 //getMemoryWithoutUpdate().set(MemFlags.EXTRA_SENSOR_INDICATORS, 3)
305 }
306
307 public PlanetAPI addBlackHole(StarSystemAPI system, GenContext context, AbyssalEPData data) {
308
309 StarGenDataSpec starData = (StarGenDataSpec)
310 Global.getSettings().getSpec(StarGenDataSpec.class, StarTypes.BLACK_HOLE, false);
311
312 system.setLightColor(starData.getLightColorMin());
313
314 float radius = starData.getMinRadius() +
315 (starData.getMaxRadius() - starData.getMinRadius()) * data.random.nextFloat();
316
317 PlanetAPI planet = system.addPlanet(null, null, null, StarTypes.BLACK_HOLE, 0, radius, 0, 0);
318
319
320 // convert corona to Event Horizon
321 StarCoronaTerrainPlugin coronaPlugin = Misc.getCoronaFor(planet);
322 if (coronaPlugin != null) {
323 system.removeEntity(coronaPlugin.getEntity());
324 }
325
326 starData = (StarGenDataSpec) Global.getSettings().getSpec(StarGenDataSpec.class, planet.getSpec().getPlanetType(), false);
327 float corona = planet.getRadius() * (starData.getCoronaMult() + starData.getCoronaVar() * (data.random.nextFloat() - 0.5f));
328 if (corona < starData.getCoronaMin()) corona = starData.getCoronaMin();
329
330 SectorEntityToken eventHorizon = system.addTerrain(Terrain.EVENT_HORIZON,
331 new CoronaParams(planet.getRadius() + corona, (planet.getRadius() + corona) / 2f,
332 planet, starData.getSolarWind(),
333 (float) (starData.getMinFlare() + (starData.getMaxFlare() - starData.getMinFlare()) * data.random.nextFloat()),
334 starData.getCrLossMult()));
335 eventHorizon.setCircularOrbit(planet, 0, 0, 100);
336
337
338
339 // add accretion disk
340 Collection<TerrainGenDataSpec> terrainDataSpecs = Global.getSettings().getAllSpecs(TerrainGenDataSpec.class);
341 TerrainGenDataSpec terrainData = null;
342 for (TerrainGenDataSpec curr : terrainDataSpecs) {
343 if (curr.getId().equals(Tags.ACCRETION_DISK)) {
344 terrainData = curr;
345 break;
346 }
347 }
348
349 if (terrainData != null) {
350 AccretionDiskGenPlugin diskGen = new AccretionDiskGenPlugin();
351 context.parent = planet;
352 context.currentRadius = 500f + data.random.nextFloat() * 1000f;
353 diskGen.generate(terrainData, context);
354 }
355
356 GeneratedPlanet p = new GeneratedPlanet(null, planet, false, 0, 0, 0);
357 context.generatedPlanets.add(p);
358
359 return planet;
360 }
361
362
363// if (planet.getSpec().getAtmosphereThickness() > 0) {
364// Color atmosphereColor = Misc.interpolateColor(planet.getSpec().getAtmosphereColor(), color, 0.25f);
365// atmosphereColor = Misc.setAlpha(atmosphereColor, planet.getSpec().getAtmosphereColor().getAlpha());
366// planet.getSpec().setAtmosphereColor(atmosphereColor);
367//
368// if (planet.getSpec().getCloudTexture() != null) {
369// Color cloudColor = Misc.interpolateColor(planet.getSpec().getCloudColor(), color, 0.25f);
370// cloudColor = Misc.setAlpha(cloudColor, planet.getSpec().getCloudColor().getAlpha());
371// planet.getSpec().setAtmosphereColor(atmosphereColor);
372// }
373// }
374
375 //planet.getMemoryWithoutUpdate().set("$gateHaulerIceGiant", true);
376
377// StarGenDataSpec starData = (StarGenDataSpec)
378// Global.getSettings().getSpec(StarGenDataSpec.class, Planets.NEBULA_CENTER_OLD, false);
379// GenContext context = new GenContext(null, system, system.getCenter(), starData,
380// null, 0, StarAge.ANY.name(), 0, 1000, null, -1);
381
382 //PlanetConditionGenerator.generateConditionsForPlanet(context, planet, StarAge.ANY);
383
384// StarGenDataSpec starData1 = (StarGenDataSpec) Global.getSettings().getSpec(StarGenDataSpec.class, StarTypes.BLACK_HOLE, false);
385// float radius = starData1.getMinRadius() +
386// (starData1.getMaxRadius() - starData1.getMinRadius()) * data.random.nextFloat();
387//
388// float corona = radius * (starData1.getCoronaMult() + starData1.getCoronaVar() * (data.random.nextFloat() - 0.5f));
389// if (corona < starData1.getCoronaMin()) corona = starData1.getCoronaMin();
390// SectorEntityToken center = system.initStar(null, StarTypes.BLACK_HOLE, 150, corona);
391
392}
393
394
395
396
397
398
399
400
401
402
403
404
405
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
static float getAbyssalRogueStellarObjectFrequency(EncounterManager manager, EncounterPoint point)
void addSpecials(StarSystemAPI system, EncounterManager manager, EncounterPoint point, AbyssalEPData data)
PlanetAPI addBlackHole(StarSystemAPI system, GenContext context, AbyssalEPData data)
static WeightedRandomPicker< RogueStellarObjectType > STELLAR_OBJECT_TYPES
float getFrequencyForPoint(EncounterManager manager, EncounterPoint point)
< T > Collection< T > getAllSpecs(Class< T > c)
Object getSpec(Class c, String id, boolean nullOnNotFound)