1package com.fs.starfarer.api.impl.campaign.procgen;
3import java.util.ArrayList;
4import java.util.EnumSet;
6import java.util.Random;
8import org.lwjgl.util.vector.Vector2f;
10import com.fs.starfarer.api.Global;
11import com.fs.starfarer.api.campaign.SectorGenProgress;
12import com.fs.starfarer.api.campaign.SectorProcGenPlugin;
13import com.fs.starfarer.api.campaign.StarSystemAPI;
14import com.fs.starfarer.api.characters.CharacterCreationData;
15import com.fs.starfarer.api.impl.campaign.ids.StarTypes;
16import com.fs.starfarer.api.impl.campaign.ids.Tags;
17import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator.CustomConstellationParams;
18import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator.StarSystemType;
19import com.fs.starfarer.api.impl.campaign.procgen.themes.SectorThemeGenerator;
20import com.fs.starfarer.api.impl.campaign.procgen.themes.ThemeGenContext;
21import com.fs.starfarer.api.impl.campaign.terrain.HyperspaceAbyssPlugin;
22import com.fs.starfarer.api.impl.campaign.terrain.HyperspaceTerrainPlugin;
23import com.fs.starfarer.api.util.Misc;
24import com.fs.starfarer.api.util.Pair;
25import com.fs.starfarer.api.util.WeightedRandomPicker;
60 if (sectorAge ==
null) {
68 boolean [][] cells =
new boolean [cellsWide][cellsHigh];
78 for (
int i = 0; i < cells.length; i++) {
79 for (
int j = 0; j < cells[0].length; j++) {
80 if (i <= hPad || j <= vPad || i >= cellsWide - hPad || j >= cellsHigh - vPad) {
88 int [] index =
getIndex(system.getLocation());
93 if (x > cellsWide - 1) x = cellsWide - 1;
94 if (y > cellsHigh - 1) y = cellsHigh - 1;
112 progress.
render(
"Generating sector...", 0.1f);
116 List<Constellation> constellations =
new ArrayList<Constellation>();
117 for (
int k = 0; k < count; k++) {
119 for (
int i = 0; i < cells.length; i++) {
120 for (
int j = 0; j < cells[0].length; j++) {
121 if (cells[i][j])
continue;
129 if (pick ==
null)
continue;
136 CustomConstellationParams params =
new CustomConstellationParams(
StarAge.
ANY);
137 if (!custom.isEmpty()) params = custom.remove(0);
152 age = agePicker.
pick();
157 params.location =
new Vector2f(x, y);
159 constellations.add(c);
161 progress.
render(
"Generating constellations...", 0.1f + 0.8f * (
float)k / (
float) count);
176 float angleOffset = random.nextFloat() * 360f;
177 editor.
clearArc(0f, 0f, w / 2f, w / 2f + 3000,
178 angleOffset + 0f, angleOffset + 360f * (2f + random.nextFloat() * 2f), 0.01f, 0.33f);
181 int numArcs = (int) (20f + 8f * random.nextFloat());
183 for (
int i = 0; i < numArcs; i++) {
184 float dist = w/2f + w/2f * random.nextFloat();
185 float angle = random.nextFloat() * 360f;
188 dir.scale(dist - (w/12f + w/3f * random.nextFloat()));
192 float width = 800f * (1f + 2f * random.nextFloat());
194 float clearThreshold = 0f + 0.5f * random.nextFloat();
197 editor.
clearArc(dir.x, dir.y, dist - width/2f, dist + width/2f, 0, 360f, clearThreshold);
202 progress.
render(
"Generating objects...", 0.9f);
206 context.constellations = constellations;
209 progress.
render(
"Finishing generation...", 1f);
232 for (
float x = -w/2f; x < w/2f; x += ts * 0.8f) {
233 for (
float y = -h/2f; y < h/2f; y += ts * 0.8f) {
249 public static void blotOut(
boolean [][] cells,
int x,
int y,
int c) {
251 for (
int i = Math.max(0, x - c / 2); i <= x + c / 2 && i < cells.length; i++) {
252 for (
int j = Math.max(0, y - c / 2); j <= y + c / 2 && j < cells[0].length; j++) {
262 int x = (int) ((loc.x + w / 2f) /
CELL_SIZE);
263 int y = (int) ((loc.y + h / 2f) /
CELL_SIZE);
265 return new int []{x, y};
270 List<CustomConstellationParams> result =
new ArrayList<CustomConstellationParams>();
272 for (StarSystemType type : EnumSet.allOf(StarSystemType.class)) {
273 if (type == StarSystemType.DEEP_SPACE || type == StarSystemType.DEEP_SPACE_GAS_GIANT)
continue;
274 CustomConstellationParams params =
new CustomConstellationParams(
StarAge.
ANY);
275 params.systemTypes.add(type);
276 if (type == StarSystemType.NEBULA) params.forceNebula =
true;
280 CustomConstellationParams params =
new CustomConstellationParams(
StarAge.
ANY);
284 params =
new CustomConstellationParams(
StarAge.
ANY);
static SettingsAPI getSettings()
static SectorAPI getSector()
static final String NEUTRON_STAR
static final String BLACK_HOLE
static void loadIfNeeded()
void noisePrune(float fractionKeep)
void clearArc(float x, float y, float innerRadius, float outerRadius, float startAngle, float endAngle)
void setTileAt(float x, float y, int value)
void prepare(CharacterCreationData data)
static final float CELL_SIZE
static final int CONSTELLATION_CELLS
void generate(CharacterCreationData data, SectorGenProgress progress)
static int[] getIndex(Vector2f loc)
static void clearAbyssalHyperspaceAndSetSystemTags()
static void blotOut(boolean[][] cells, int x, int y, int c)
static List< CustomConstellationParams > getCustomConstellations()
static void updateBackgroundPickers()
static void generate(ThemeGenContext context)
HyperspaceAbyssPlugin getAbyssPlugin()
static Vector2f getUnitVectorAtDegreeAngle(float degrees)
static List< StarSystemAPI > getAbyssalSystems()
static CampaignTerrainAPI getHyperspaceTerrain()
float getFloat(String key)
CampaignTerrainPlugin getPlugin()
List< StarSystemAPI > getStarSystems()
void render(String text, float progress)
boolean isInAbyss(Vector2f loc)