Starsector API
Loading...
Searching...
No Matches
HTFactorTracker.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.events.ht;
2
3import java.util.LinkedHashSet;
4
5import com.fs.starfarer.api.EveryFrameScript;
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.CampaignFleetAPI;
8import com.fs.starfarer.api.campaign.CampaignTerrainAPI;
9import com.fs.starfarer.api.campaign.PlanetAPI;
10import com.fs.starfarer.api.campaign.SectorEntityToken;
11import com.fs.starfarer.api.campaign.StarSystemAPI;
12import com.fs.starfarer.api.characters.AbilityPlugin;
13import com.fs.starfarer.api.impl.campaign.ids.Abilities;
14import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
15import com.fs.starfarer.api.impl.campaign.ids.Tags;
16import com.fs.starfarer.api.impl.campaign.ids.Terrain;
17import com.fs.starfarer.api.impl.campaign.terrain.PulsarBeamTerrainPlugin;
18import com.fs.starfarer.api.impl.campaign.terrain.StarCoronaTerrainPlugin;
19import com.fs.starfarer.api.util.IntervalUtil;
20import com.fs.starfarer.api.util.Misc;
21
27public class HTFactorTracker implements EveryFrameScript {
28
29 public static float CHECK_DAYS = 0.05f;
30
31 protected IntervalUtil interval = new IntervalUtil(CHECK_DAYS * 0.8f, CHECK_DAYS * 1.2f);
32 protected float burnBasedPoints = 0f;
33 protected float daysSinceAtHighBurn = 1f;
34 protected boolean canCheckSB = true;
35
36 protected LinkedHashSet<String> scanned = new LinkedHashSet<String>();
37
38 protected Object readResolve() {
39 if (scanned == null) {
40 scanned = new LinkedHashSet<String>();
41 }
42 return this;
43 }
44
45 public boolean isDone() {
46 return false;
47 }
48
49 public boolean runWhilePaused() {
50 return false;
51 }
52
53 public void advance(float amount) {
54 float days = Global.getSector().getClock().convertToDays(amount);
55
56 interval.advance(days);
57
58 if (interval.intervalElapsed()) {
59 checkHighBurn(interval.getIntervalDuration());
61 }
62 }
63
64 protected void checkHighBurn(float days) {
65 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
66 if (pf != null && pf.isInHyperspace()) {
67 float burn = pf.getCurrBurnLevel();
68
69 if (burn > 20) {
71 } else {
72 daysSinceAtHighBurn += days;
73 }
74
75 float add = 0f;
76 float min = 0;
77 float max = 0;
78 float f = 0;
79 if (burn > 40) {
82 f = (Math.min(burn, HTPoints.MAX_BURN_FOR_POINT_GAIN) - 40) / 10f;
83 } else if (burn > 30) {
86 f = (burn - 30) / 10f;
87 } else if (burn > 20) {
90 f = (burn - 20) / 10f;
91 }
92
93 add = min + (max - min) * f;
94 add *= CHECK_DAYS;
95 //add *= 100;
96
97// if (Global.getSettings().isDevMode()) {
98// add = 100;
99// }
100
101 if (pf.getMemoryWithoutUpdate().getBoolean(MemFlags.NO_HIGH_BURN_TOPOGRAPHY_READINGS)) {
102 add = 0;
103 }
104
105 if (add > 0) {
106 burnBasedPoints += add;
107 //System.out.println("Added: " + add + ", total: " + burnBasedPoints);
108 }
110 //chunk = 1;
111 if (burnBasedPoints >= chunk && daysSinceAtHighBurn > 0.3f) {
112 int mult = (int) burnBasedPoints / chunk;
113 int points = chunk * mult;
114 burnBasedPoints -= points;
116 }
117 } else {
119 }
120 }
121
122 public void checkSensorBursts() {
123 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
124 if (pf == null) return;
125 AbilityPlugin sb = pf.getAbility(Abilities.SENSOR_BURST);
126 if (sb == null) return;
127
128 if (sb.isUsable() || sb.getLevel() <= 0) {
129 canCheckSB = true;
130 }
131
132 if (canCheckSB && !pf.isInHyperspace() && sb.isInProgress() && sb.getLevel() > 0.9f &&
133 !pf.getContainingLocation().hasTag(Tags.NO_TOPOGRAPHY_SCANS)) {
134 for (SectorEntityToken entity : pf.getContainingLocation().getAllEntities()) {
135 checkBlackHole(entity);
136 checkIonStorm(entity);
137 checkGasGiant(entity);
138 checkPulsar(entity);
139 }
140 for (CampaignTerrainAPI terrain : pf.getContainingLocation().getTerrainCopy()) {
141 checkMagneticField(terrain);
142 }
143
145
146 canCheckSB = false;
147 }
148 }
149
150 protected void checkBlackHole(SectorEntityToken entity) {
151 if (!(entity instanceof PlanetAPI)) return;
152
153 PlanetAPI planet = (PlanetAPI) entity;
154 if (!planet.getSpec().isBlackHole()) return;
155
156 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
157 float dist = Misc.getDistance(pf.getLocation(), entity.getLocation());
158
159 StarCoronaTerrainPlugin eventHorizon = Misc.getCoronaFor(planet);
160 if (eventHorizon == null) return;
161
162 String id1 = planet.getId() + "_1";
163 String id2 = planet.getId() + "_2";
164
165 float closeRange = planet.getRadius() + 300f;
166
167 if (dist < closeRange) {
168 if (scanned.contains(id2)) {
169 addMessage("Black hole already scanned at short range");
170 } else {
172 new HTScanFactor("Black hole scanned at short range (" + planet.getName() + ")", HTPoints.SCAN_BLACK_HOLE_SHORT_RANGE), null);
173 scanned.add(id2);
174 }
175 } else if (eventHorizon.containsEntity(pf)) {
176 if (scanned.contains(id1)) {
177 addMessage("Black hole already scanned at long range");
178 } else {
180 new HTScanFactor("Black hole scanned at long range (" + planet.getName() + ")", HTPoints.SCAN_BLACK_HOLE_LONG_RANGE), null);
181 scanned.add(id1);
182 }
183 }
184 }
185
186 protected void checkIonStorm(SectorEntityToken entity) {
187 if (!(entity instanceof PlanetAPI)) return;
188
189 PlanetAPI planet = (PlanetAPI) entity;
190 if (!planet.isGasGiant()) return;
191
192 StarCoronaTerrainPlugin ionStorm = Misc.getCoronaFor(planet);
193 if (ionStorm == null) return;
194
195 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
196
197 String id = ionStorm.getEntity().getId();
198
199 if (ionStorm.containsEntity(pf)) {
200 if (scanned.contains(id)) {
201 addMessage("Ion storm already scanned");
202 } else {
204 new HTScanFactor("Ion storm scanned (" + planet.getName() + ")", HTPoints.SCAN_ION_STORM), null);
205 scanned.add(id);
206 }
207 }
208 }
209
210 protected void checkMagneticField(CampaignTerrainAPI terrain) {
211 if (terrain.getPlugin() == null) return;
212 if (!Terrain.MAGNETIC_FIELD.equals(terrain.getType())) return;
213
214 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
215
216 String id = terrain.getId();
217
218 if (terrain.getPlugin().containsEntity(pf)) {
219 if (scanned.contains(id)) {
220 addMessage("Magnetic field already scanned");
221 } else {
223 new HTScanFactor("Magnetic field scanned", HTPoints.SCAN_MAGNETIC_FIELD), null);
224 scanned.add(id);
225 }
226 }
227 }
228
229 protected void checkGasGiant(SectorEntityToken entity) {
230 if (!(entity instanceof PlanetAPI)) return;
231
232 PlanetAPI planet = (PlanetAPI) entity;
233 if (!planet.isGasGiant()) return;
234
235 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
236 String id = planet.getId();
237
238 float dist = Misc.getDistance(pf.getLocation(), entity.getLocation());
239 boolean inRange = dist < 500f + planet.getRadius();
240 if (inRange) {
241 if (scanned.contains(id)) {
242 addMessage("Gas giant already scanned");
243 } else {
245 new HTScanFactor("Gas giant scanned (" + planet.getName() + ")", HTPoints.SCAN_GAS_GIANT), null);
246 scanned.add(id);
247 }
248 }
249 }
250
251 protected void checkSystemCenter() {
252 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
253 StarSystemAPI system = pf.getStarSystem();
254 if (system == null) return;
255
256 String type = null;
257 int points = 0;
258 switch (system.getType()) {
259 case BINARY_CLOSE:
260 type = "Center of binary system";
261 points = HTPoints.SCAN_BINARY;
262 break;
263 case NEBULA:
264 type = "Center of starless nebula";
265 points = HTPoints.SCAN_NEBULA;
266 break;
267 case TRINARY_1CLOSE_1FAR:
268 type = "Center of binary system";
269 points = HTPoints.SCAN_BINARY;
270 break;
271 case TRINARY_2CLOSE:
272 type = "Center of trinary system";
273 points = HTPoints.SCAN_TRINARY;
274 break;
275 default:
276 int count = 0;
277 for (PlanetAPI curr : system.getPlanets()) {
278 if (!curr.isStar()) continue;
279 float dist = Misc.getDistance(curr.getLocation(), pf.getLocation());
280 if (dist < 2000 + curr.getRadius()) {
281 count++;
282 }
283 }
284 if (count > 1) {
285 type = "Stellar conflux";
286 if (count == 2) {
287 points = HTPoints.SCAN_BINARY;
288 } else {
289 points = HTPoints.SCAN_TRINARY;
290 }
291 }
292 break;
293 }
294 if (type == null) return;
295
296 String id = "systemtypescan_" + system.getId();
297 float range = pf.getLocation().length();
298
299 if (range < 2000) {
300 if (scanned.contains(id)) {
301 addMessage("Center of star system already scanned");
302 } else {
304 new HTScanFactor(type + " scanned (" + system.getBaseName() + ")", points), null);
305 scanned.add(id);
306 }
307 }
308 }
309
310 protected void checkPulsar(SectorEntityToken entity) {
311 if (!(entity instanceof PlanetAPI)) return;
312
313 PlanetAPI planet = (PlanetAPI) entity;
314 if (!planet.getSpec().isPulsar()) return;
315
316 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
317
318 StarCoronaTerrainPlugin corona = Misc.getCoronaFor(planet);
319 if (corona == null) return;
320
321 PulsarBeamTerrainPlugin pulsar = Misc.getPulsarFor(planet);
322 if (pulsar == null) return;
323
324 String id1 = planet.getId() + "_1";
325 String id2 = planet.getId() + "_2";
326
327 if (corona.containsEntity(pf)) {
328 if (scanned.contains(id2)) {
329 addMessage("Neutron star already scanned");
330 } else {
332 new HTScanFactor("Neutron star scanned (" + planet.getName() + ")", HTPoints.SCAN_NEUTRON_STAR), null);
333 scanned.add(id2);
334 }
335 }
336
337 if (pulsar.containsEntity(pf)) {
338 if (scanned.contains(id1)) {
339 addMessage("Pulsar beam already scanned");
340 } else {
342 new HTScanFactor("Pulsar beam scanned (" + planet.getName() + ")", HTPoints.SCAN_PULSAR_BEAM), null);
343 scanned.add(id1);
344 }
345 }
346 }
347
348
349 protected void addMessage(String text) {
350 Global.getSector().getCampaignUI().getMessageDisplay().addMessage(text + ", no new topographic data acquired", Misc.getNegativeHighlightColor());
351 }
352}
353
354
355
356
static SectorAPI getSector()
Definition Global.java:59
static void addFactorCreateIfNecessary(EventFactor factor, InteractionDialogAPI dialog)