Starsector API
Loading...
Searching...
No Matches
MagFieldGenPlugin.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.procgen;
2
3import java.awt.Color;
4
5import com.fs.starfarer.api.campaign.PlanetAPI;
6import com.fs.starfarer.api.campaign.SectorEntityToken;
7import com.fs.starfarer.api.campaign.StarSystemAPI;
8import com.fs.starfarer.api.impl.campaign.ids.Terrain;
9import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator.GenContext;
10import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator.GenResult;
11import com.fs.starfarer.api.impl.campaign.terrain.MagneticFieldTerrainPlugin.MagneticFieldParams;
12
13public class MagFieldGenPlugin implements TerrainGenPlugin {
14
15 public static Color [] baseColors = {
16 new Color(50, 25, 100, 70),
17 //new Color(50, 30, 100, 30),
18 //new Color(75, 105, 165, 75)
19 };
20
21 public static Color [][] auroraColors = {
22 {new Color(140, 100, 235),
23 new Color(180, 110, 210),
24 new Color(150, 140, 190),
25 new Color(140, 190, 210),
26 new Color(90, 200, 170),
27 new Color(65, 230, 160),
28 new Color(20, 220, 70) },
29 {new Color(50, 20, 110, 130),
30 new Color(150, 30, 120, 150),
31 new Color(200, 50, 130, 190),
32 new Color(250, 70, 150, 240),
33 new Color(200, 80, 130, 255),
34 new Color(75, 0, 160),
35 new Color(127, 0, 255) },
36 {new Color(90, 180, 140),
37 new Color(130, 145, 190),
38 new Color(165, 110, 225),
39 new Color(95, 55, 240),
40 new Color(45, 0, 250),
41 new Color(20, 0, 240),
42 new Color(10, 0, 150) },
43 {new Color(90, 180, 40),
44 new Color(130, 145, 90),
45 new Color(165, 110, 145),
46 new Color(95, 55, 160),
47 new Color(45, 0, 130),
48 new Color(20, 0, 130),
49 new Color(10, 0, 150) },
50 {new Color(50, 20, 110, 130),
51 new Color(150, 30, 120, 150),
52 new Color(200, 50, 130, 190),
53 new Color(250, 70, 150, 240),
54 new Color(200, 80, 130, 255),
55 new Color(75, 0, 160),
56 new Color(127, 0, 255) },
57 {new Color(55, 60, 140),
58 new Color(65, 85, 155),
59 new Color(175, 105, 165),
60 new Color(90, 130, 180),
61 new Color(105, 150, 190),
62 new Color(120, 175, 205),
63 new Color(135, 200, 220)},
64 };
65
66 public static final float WIDTH_PLANET = 200f;
67 public static final float WIDTH_STAR = 400f;
68
69 public GenResult generate(TerrainGenDataSpec terrainData, GenContext context) {
70 //if (!(context.star instanceof PlanetAPI)) return null;
71
72 StarSystemAPI system = context.system;
73 SectorEntityToken parent = context.center;
74 if (context.parent != null) parent = context.parent;
75
76 boolean isStar = false;
77 boolean hasAtmosphere = false;
78 if (parent instanceof PlanetAPI) {
79 PlanetAPI planet = (PlanetAPI) parent;
80 isStar = planet.isStar();
81 hasAtmosphere = planet.getSpec().getAtmosphereThickness() > 0;
82 } else if (parent == context.system.getCenter()) {
83 isStar = true;
84 }
85
86 if (context.parent != null) parent = context.parent;
87
88 //System.out.println("GENERATING MAG FIELD AROUND " + parent.getId());
89
90 int baseIndex = (int) (baseColors.length * StarSystemGenerator.random.nextDouble());
91 int auroraIndex = (int) (auroraColors.length * StarSystemGenerator.random.nextDouble());
92
93
94 float bandWidth = parent.getRadius() + WIDTH_PLANET;
95 float midRadius = (parent.getRadius() + WIDTH_PLANET) / 2f;
96// float visStartRadius = parent.getRadius() + 50f;
97// float visEndRadius = parent.getRadius() + 50f + WIDTH_PLANET + 50f;
98 float visStartRadius = parent.getRadius();
99 float visEndRadius = parent.getRadius() + WIDTH_PLANET + 50f;
100 float auroraProbability = 0f;
101
102 float orbitalWidth = WIDTH_PLANET;
103
104 if (isStar || context.orbitIndex > 0) {
105 bandWidth = WIDTH_STAR;
106 midRadius = context.currentRadius + bandWidth / 2f;
107 visStartRadius = context.currentRadius;
108 visEndRadius = context.currentRadius + bandWidth;
109
110 orbitalWidth = WIDTH_STAR;
111
112 if (isStar) {
113 auroraProbability = 1f;
114 } else {
115 auroraProbability = 0.25f + 0.75f * StarSystemGenerator.random.nextFloat();
116 }
117 } else if (hasAtmosphere) {
118 auroraProbability = 0.25f + 0.75f * StarSystemGenerator.random.nextFloat();
119 }
120
121 SectorEntityToken magField = system.addTerrain(Terrain.MAGNETIC_FIELD,
122 new MagneticFieldParams(bandWidth, // terrain effect band width
123 midRadius, // terrain effect middle radius
124 parent, // entity that it's around
125 visStartRadius, // visual band start
126 visEndRadius, // visual band end
127 baseColors[baseIndex], // base color
128 auroraProbability, // probability to spawn aurora sequence, checked once/day when no aurora in progress
129 auroraColors[auroraIndex]
130 ));
131 magField.setCircularOrbit(parent, 0, 0, 100);
132
133 GenResult result = new GenResult();
134 result.onlyIncrementByWidth = !isStar;
135 result.orbitalWidth = orbitalWidth;
136 result.entities.add(magField);
137 return result;
138 }
139
140 public boolean wantsToHandle(TerrainGenDataSpec terrainData, GenContext context) {
141 return terrainData != null && terrainData.getId().equals("magnetic_field");
142 }
143
144}
boolean wantsToHandle(TerrainGenDataSpec terrainData, GenContext context)
GenResult generate(TerrainGenDataSpec terrainData, GenContext context)