Starsector API
Loading...
Searching...
No Matches
CoronalTapParticleScript.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign;
2
3import java.awt.Color;
4import java.util.ArrayList;
5import java.util.List;
6
7import org.lwjgl.util.vector.Vector2f;
8
9import com.fs.starfarer.api.EveryFrameScript;
10import com.fs.starfarer.api.campaign.PlanetAPI;
11import com.fs.starfarer.api.campaign.SectorEntityToken;
12import com.fs.starfarer.api.impl.campaign.world.ZigLeashAssignmentAI;
13import com.fs.starfarer.api.util.IntervalUtil;
14import com.fs.starfarer.api.util.Misc;
15
17
18 protected SectorEntityToken tap;
19
20 protected IntervalUtil spawn = new IntervalUtil(0.05f, 0.1f);
21
22 public CoronalTapParticleScript(SectorEntityToken tap) {
23 super();
24 this.tap = tap;
25 }
26
27 public void advance(float amount) {
28 if (tap.isDiscoverable()) return;
29 if (!tap.getMemoryWithoutUpdate().contains("$usable")) return;
30 if (!tap.isInCurrentLocation()) return;
31
32 if (spawn == null) { // nothing to see here, just making an older dev save work
33 spawn = new IntervalUtil(0.05f, 0.1f);
34 }
35
36 float days = Misc.getDays(amount);
37 spawn.advance(days * 5f);
38 if (spawn.intervalElapsed()) {
39
40// float minDur = 0.5f;
41// float maxDur = 0.75f;
42 float minSize = 10f;
43 float maxSize = 20f;
44
45 float sizeMult = 30f;
46
47 minSize *= sizeMult;
48 maxSize *= sizeMult;
49
50 if ((float) Math.random() < 0.01f) {
51 ZigLeashAssignmentAI.spawnMote(tap);
52 }
53
54
55
56 List<PlanetAPI> stars = new ArrayList<PlanetAPI>();
57 PlanetAPI closest = null;
58 float minDist = Float.MAX_VALUE;
59 for (PlanetAPI star : tap.getContainingLocation().getPlanets()) {
60 if (!star.isStar()) continue;
61
62 float ctcDist = Misc.getDistance(tap.getLocation(), star.getLocation());
63 float dist = ctcDist - star.getRadius() - tap.getRadius();
64 if (dist > 2000) continue;
65
66 if (ctcDist < minDist) {
67 minDist = ctcDist;
68 closest = star;
69 }
70
71 stars.add(star);
72 }
73// float minDist = Float.MAX_VALUE;
74// closest = null;
75// for (PlanetAPI star : tap.getContainingLocation().getPlanets()) {
76// if (!star.isStar()) continue;
77//
78// float dist = Misc.getDistance(tap.getLocation(), star.getLocation());
79// if (dist < minDist) {
80// minDist = dist;
81// closest = star;
82// }
83// }
84// if (closest != null) {
85// stars.add(closest);
86// }
87
88 for (PlanetAPI star : stars) {
89 float dirToTap = Misc.getAngleInDegrees(star.getLocation(), tap.getLocation());
90 Vector2f unitToTap = Misc.getUnitVectorAtDegreeAngle(dirToTap);
91 Vector2f focusLoc = new Vector2f(unitToTap);
92 focusLoc.scale(100f + star.getRadius() + tap.getRadius());
93 Vector2f.add(star.getLocation(), focusLoc, focusLoc);
94
95 //focusLoc = tap.getLocation();
96
97 float ctcDist = Misc.getDistance(focusLoc, star.getLocation());
98 float dist = ctcDist - star.getRadius() - tap.getRadius();
99
100 int glows = 3;
101 float minRadius = dist + (star.getRadius() * 0.2f);
102 float maxRadius = dist + (star.getRadius() * 0.4f);
103
104 Color color = star.getSpec().getCoronaColor();
105
106 float colorScale = 0.25f;
107 colorScale = 0.1f + 0.15f / (float) stars.size();
108 if (closest == star) colorScale = 0.25f;
109 color = Misc.scaleColor(color, colorScale);
110 //Color white = Misc.scaleColor(Color.white, colorScale);
111
112 float dirToStar = Misc.getAngleInDegrees(focusLoc, star.getLocation());
113 float arc = star.getRadius() / ((float) Math.PI * (ctcDist - tap.getRadius())) * 360f;
114
115 for (int i = 0; i < glows; i++) {
116 float radius = minRadius + (float) Math.random() * (maxRadius - minRadius);
117
118 float angle = dirToStar - arc / 2f + arc * (float) Math.random();
119
120 Vector2f unit = Misc.getUnitVectorAtDegreeAngle(angle);
121 float x = unit.x * radius + focusLoc.x;
122 float y = unit.y * radius + focusLoc.y;
123
124 Vector2f loc = new Vector2f(x, y);
125 //Vector2f loc = Misc.getPointAtRadius(focusLoc, radius);
126
127 Vector2f vel = Misc.getUnitVectorAtDegreeAngle(Misc.getAngleInDegrees(loc, focusLoc));
128 float travelDist = Misc.getDistance(loc, focusLoc) - tap.getRadius() * 0.7f - 100f;
129 travelDist = Math.min(travelDist, maxRadius - minRadius + 100f);
130// float dur = minDur + (float) Math.random() * (maxDur - minDur);
131// dur *= 2f;
132// float speed = travelDist / dur;
133 float speed = 100f + 100f * (float) Math.random();
134 float dur = travelDist / speed;
135
136 vel.scale(speed);
137
138 float size = minSize + (float) Math.random() * (maxSize - minSize);
139
140 float rampUp = 0.5f;
141 //Misc.addGlowyParticle(tap.getContainingLocation(), loc, vel, size, rampUp, dur, color);
142
143 tap.getContainingLocation().addParticle(loc, vel,
144 size, 0.4f, rampUp, dur, color);
145 tap.getContainingLocation().addParticle(loc, vel,
146 size * 0.25f, 0.4f, rampUp, dur, color);
147// tap.getContainingLocation().addParticle(loc, vel,
148// size * 0.15f, 1f, rampUp, dur, white);
149 }
150 }
151 }
152 }
153
154 public boolean isDone() {
155 return false;
156 }
157
158 public boolean runWhilePaused() {
159 return false;
160 }
161}
162
163
164
165
166
167
168
169
170
171
172
173