Starsector API
Loading...
Searching...
No Matches
AnalyzeEntityIntelCreator.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel;
2
3import java.util.ArrayList;
4
5import com.fs.starfarer.api.EveryFrameScript;
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.SectorEntityToken;
8import com.fs.starfarer.api.campaign.StarSystemAPI;
9import com.fs.starfarer.api.impl.campaign.ids.Tags;
10import com.fs.starfarer.api.impl.campaign.intel.GenericMissionManager.GenericMissionCreator;
11import com.fs.starfarer.api.util.Misc;
12import com.fs.starfarer.api.util.WeightedRandomPicker;
13
14public class AnalyzeEntityIntelCreator implements GenericMissionCreator {
15
17 SectorEntityToken entity = pickEntity();
18 if (entity == null) return null;
19 return new AnalyzeEntityMissionIntel(entity);
20 }
21
23 return 15f;
24 }
25
26
27 protected transient WeightedRandomPicker<SectorEntityToken> entityPicker = null;
28
29 protected void initPicker() {
30 entityPicker = new WeightedRandomPicker<SectorEntityToken>();
31 for (StarSystemAPI system : Global.getSector().getStarSystems()) {
32 if (system.hasTag(Tags.THEME_DERELICT_MOTHERSHIP)) continue;
33 if (system.hasTag(Tags.THEME_DERELICT_CRYOSLEEPER)) continue;
34
35 if (system.hasTag(Tags.THEME_DERELICT_PROBES) ||
36 system.hasTag(Tags.THEME_RUINS) ||
37 system.hasTag(Tags.THEME_REMNANT_DESTROYED)) {
38
39 float w = 1f;
40 if (system.hasTag(Tags.THEME_DERELICT_PROBES)) {
41 w = 3f;
42 if (Global.getSector().isInNewGameAdvance()) {
43 w = 5f;
44 }
45 }
46 for (SectorEntityToken entity : system.getEntitiesWithTag(Tags.SALVAGEABLE)) {
47 // skip derelict ships etc that will expire
48 if (entity.hasTag(Tags.EXPIRES)) continue;
49 if (Misc.isImportantForReason(entity.getMemoryWithoutUpdate(), "aem")) continue;
50 if (entity.hasTag(Tags.NOT_RANDOM_MISSION_TARGET)) continue;
51 if (entity.getMemoryWithoutUpdate() != null && entity.getMemoryWithoutUpdate().getBoolean("$ttWeaponsCache")) continue;
52 if (entity.getCircularOrbitRadius() > 10000f) continue;
53 if (entity.getContainingLocation() != null && entity.getContainingLocation().hasTag(Tags.THEME_HIDDEN)) continue;
54 entityPicker.add(entity, w);
55 }
56
57 }
58 }
59 }
60
61 protected void prunePicker() {
62 for (SectorEntityToken item : new ArrayList<SectorEntityToken>(entityPicker.getItems())) {
63 if (!item.isAlive()) {
64 entityPicker.remove(item);
65 }
66 }
67 }
68
69 protected SectorEntityToken pickEntity() {
70 if (entityPicker == null) {
71 initPicker();
72 }
74
75 SectorEntityToken entity = entityPicker.pick();
76
78 if (s instanceof AnalyzeEntityMissionIntel) {
80 if (entity == intel.getEntity()) {
81 return null;
82 }
83 }
84 }
85
86 return entity;
87 }
88
89
90}
91
92
93
static SectorAPI getSector()
Definition Global.java:59
transient WeightedRandomPicker< SectorEntityToken > entityPicker