1package com.fs.starfarer.api.impl.campaign.terrain;
4import java.util.ArrayList;
6import java.util.Random;
8import org.lwjgl.util.vector.Vector2f;
10import com.fs.starfarer.api.Global;
11import com.fs.starfarer.api.campaign.SectorEntityToken;
12import com.fs.starfarer.api.util.FaderUtil;
13import com.fs.starfarer.api.util.IntervalUtil;
14import com.fs.starfarer.api.util.Misc;
18 public static interface FlareManagerDelegate {
21 List<Color> getFlareColorRange();
22 float getFlareProbability();
23 float getFlareSkipLargeProbability();
24 int getFlareMinSmallCount();
25 int getFlareMaxSmallCount();
28 float getFlareOccurrenceAngle();
29 float getFlareOccurrenceArc();
31 float getFlareArcMin();
32 float getFlareArcMax();
33 float getFlareFadeInMin();
34 float getFlareFadeInMax();
35 float getFlareFadeOutMin();
36 float getFlareFadeOutMax();
37 float getFlareExtraLengthMultMin();
38 float getFlareExtraLengthMultMax();
39 float getFlareExtraLengthFlatMin();
40 float getFlareExtraLengthFlatMax();
41 float getFlareShortenFlatModMin();
42 float getFlareShortenFlatModMax();
44 float getFlareSmallArcMin();
45 float getFlareSmallArcMax();
46 float getFlareSmallFadeInMin();
47 float getFlareSmallFadeInMax();
48 float getFlareSmallFadeOutMin();
49 float getFlareSmallFadeOutMax();
50 float getFlareSmallExtraLengthMultMin();
51 float getFlareSmallExtraLengthMultMax();
52 float getFlareSmallExtraLengthFlatMin();
53 float getFlareSmallExtraLengthFlatMax();
54 float getFlareSmallShortenFlatModMin();
55 float getFlareSmallShortenFlatModMax();
58 public static class Flare {
59 public float direction;
61 public float extraLengthMult;
62 public float extraLengthFlat;
63 public float shortenFlatMod;
64 transient public List<Color> colors =
new ArrayList<Color>();
65 public String c =
null;
68 Object readResolve() {
72 colors =
new ArrayList<Color>();
77 Object writeReplace() {
84 private List<Flare> flares =
new ArrayList<Flare>();
85 private FlareManagerDelegate delegate;
89 this.delegate = delegate;
92 Object readResolve() {
96 Object writeReplace() {
97 if (flares !=
null && flares.isEmpty()) flares =
null;
102 if (flares ==
null) {
103 flares =
new ArrayList<Flare>();
127 if (flareTracker.intervalElapsed() &&
getFlares().isEmpty()) {
128 if (Math.random() < delegate.getFlareProbability()) {
151 if (curr ==
null)
return false;
152 return Misc.
isInArc(curr.direction, curr.arc, angle);
157 if (curr ==
null)
return baseColor;
159 if (!
Misc.
isInArc(curr.direction, curr.arc, angle))
return baseColor;
163 float arcStart = curr.direction - curr.arc / 2f;
164 float arcEnd = curr.direction + curr.arc / 2f;
167 if (angle < 0) angle += 360f;
169 float progress = angle / (arcEnd - arcStart);
170 if (progress < 0) progress = 0;
171 if (progress > 1) progress = 1;
173 float numColors = curr.colors.size();
175 float fractionalIndex = ((numColors - 1f) * progress);
176 int colorOne = (int) fractionalIndex;
177 int colorTwo = (int) Math.ceil(fractionalIndex);
179 float interpProgress = fractionalIndex - (int)fractionalIndex;
180 Color one = curr.colors.get(colorOne);
181 Color two = curr.colors.get(colorTwo);
192 if (curr ==
null)
return 0f;
194 if (!
Misc.
isInArc(curr.direction, curr.arc, angle))
return 0f;
196 return curr.extraLengthFlat * (float)Math.sqrt(curr.fader.
getBrightness());
201 if (curr ==
null)
return 1f;
203 if (!
Misc.
isInArc(curr.direction, curr.arc, angle))
return 1f;
205 return 1f + (curr.extraLengthMult - 1f) * (
float)Math.sqrt(curr.fader.
getBrightness());
210 if (curr ==
null)
return 0f;
212 if (!
Misc.
isInArc(curr.direction, curr.arc, angle))
return 0f;
214 return curr.shortenFlatMod * (float)Math.sqrt(curr.fader.
getBrightness());
219 if (curr ==
null)
return 0f;
221 if (!
Misc.
isInArc(curr.direction, curr.arc, angle))
return 0f;
230 int numSmall = delegate.getFlareMinSmallCount() +
231 (int)Math.ceil((
float) (delegate.getFlareMaxSmallCount() - delegate.getFlareMinSmallCount()) * (
float) Math.random());
234 for (
int i = 0; i < numSmall; i++) {
238 if (Math.random() > delegate.getFlareSkipLargeProbability()) {
248 Flare flare =
new Flare();
249 flare.direction = dir -
251 (float) Math.random() * arc;
252 flare.arc = delegate.getFlareSmallArcMin() +
253 (delegate.getFlareSmallArcMax() - delegate.getFlareSmallArcMin()) * (float) Math.random();
254 flare.extraLengthFlat = delegate.getFlareSmallExtraLengthFlatMin() +
255 (delegate.getFlareSmallExtraLengthFlatMax() - delegate.getFlareSmallExtraLengthFlatMin()) * (float) Math.random();
256 flare.extraLengthMult = delegate.getFlareSmallExtraLengthMultMin() +
257 (delegate.getFlareSmallExtraLengthMultMax() - delegate.getFlareSmallExtraLengthMultMin()) * (float) Math.random();
258 flare.shortenFlatMod = delegate.getFlareSmallShortenFlatModMin() +
259 (delegate.getFlareSmallShortenFlatModMax() - delegate.getFlareSmallShortenFlatModMin()) * (float) Math.random();
262 delegate.getFlareSmallFadeInMin() +
263 (delegate.getFlareSmallFadeInMax() - delegate.getFlareSmallFadeInMin()) * (
float) Math.random(),
264 delegate.getFlareSmallFadeOutMin() +
265 (delegate.getFlareSmallFadeOutMax() - delegate.getFlareSmallFadeOutMin()) * (
float) Math.random(),
273 Flare flare =
new Flare();
274 flare.direction = delegate.getFlareOccurrenceAngle() -
275 delegate.getFlareOccurrenceArc() / 2f +
276 (float) Math.random() * delegate.getFlareOccurrenceArc();
277 flare.arc = delegate.getFlareArcMin() +
278 (delegate.getFlareArcMax() - delegate.getFlareArcMin()) * (float) Math.random();
279 flare.extraLengthFlat = delegate.getFlareExtraLengthFlatMin() +
280 (delegate.getFlareExtraLengthFlatMax() - delegate.getFlareExtraLengthFlatMin()) * (float) Math.random();
281 flare.extraLengthMult = delegate.getFlareExtraLengthMultMin() +
282 (delegate.getFlareExtraLengthMultMax() - delegate.getFlareExtraLengthMultMin()) * (float) Math.random();
283 flare.shortenFlatMod = delegate.getFlareShortenFlatModMin() +
284 (delegate.getFlareShortenFlatModMax() - delegate.getFlareShortenFlatModMin()) * (float) Math.random();
287 delegate.getFlareFadeInMin() +
288 (delegate.getFlareFadeInMax() - delegate.getFlareFadeInMin()) * (
float) Math.random(),
289 delegate.getFlareFadeOutMin() +
290 (delegate.getFlareFadeOutMax() - delegate.getFlareFadeOutMin()) * (
float) Math.random(),
301 float colorRangeFraction = flare.arc / delegate.getFlareArcMax();
302 int totalColors = delegate.getFlareColorRange().size();
303 int numColors = Math.round(colorRangeFraction * totalColors);
304 if (numColors < 1) numColors = 1;
306 flare.colors.clear();
307 Random r =
new Random();
309 if (numColors < totalColors) {
310 start = r.nextInt(totalColors - numColors);
312 for (
int i = start; i < totalColors; i++) {
313 flare.colors.add(delegate.getFlareColorRange().get(i));
static SectorAPI getSector()
boolean isInActiveFlareArc(SectorEntityToken other)
float getExtraLengthFlat(float angle)
void setColors(Flare flare)
float getExtraLengthMult(float angle)
Flare genSmallFlare(float dir, float arc)
List< Flare > getFlares()
float getInnerOffsetMult(float angle)
void advance(float amount)
FlareManager(FlareManagerDelegate delegate)
void initNewFlareSequence()
boolean isInActiveFlareArc(float angle)
float getShortenMod(float angle)
Color getColorForAngle(Color baseColor, float angle)
boolean isInActiveFlareArc(Vector2f point)
void advance(float amount)
void advance(float amount)
static String colorsToString(List< Color > colors)
static List< Color > colorsFromString(String in)
static float normalizeAngle(float angleDeg)
static Color interpolateColor(Color from, Color to, float progress)
static boolean isInArc(float direction, float arc, Vector2f from, Vector2f to)
static float getAngleInDegrees(Vector2f v)
float convertToDays(float realSeconds)
CampaignClockAPI getClock()