Starsector API
Loading...
Searching...
No Matches
RemoteSurveyAbility.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.abilities;
2
3import java.awt.Color;
4
5import com.fs.starfarer.api.Global;
6import com.fs.starfarer.api.campaign.CampaignFleetAPI;
7import com.fs.starfarer.api.campaign.PlanetAPI;
8import com.fs.starfarer.api.campaign.SectorEntityToken.VisibilityLevel;
9import com.fs.starfarer.api.campaign.StarSystemAPI;
10import com.fs.starfarer.api.campaign.econ.MarketAPI;
11import com.fs.starfarer.api.campaign.econ.MarketAPI.SurveyLevel;
12import com.fs.starfarer.api.impl.campaign.ids.Pings;
13import com.fs.starfarer.api.impl.campaign.intel.misc.RemoteSurveyDataForPlanetIntel;
14import com.fs.starfarer.api.plugins.SurveyPlugin;
15import com.fs.starfarer.api.ui.LabelAPI;
16import com.fs.starfarer.api.ui.TooltipMakerAPI;
17import com.fs.starfarer.api.util.Misc;
18
20
21 public static final String ALREADY_DID_IN_SYSTEM = "$core_didRemoteSurveyInSystem";
22
23 public static final float SURVEY_RANGE = 10000f;
24 public static final float DETECTABILITY_RANGE_BONUS = 5000f;
25 public static final float ACCELERATION_MULT = 4f;
26
27
28 protected boolean performed = false;
29
30 @Override
31 protected void activateImpl() {
32// CampaignFleetAPI fleet = getFleet();
33// if (fleet == null) return;
34
35// PlanetAPI target = getTargetPlanet();
36// if (target != null) {
37// GenericProbeParams params = new GenericProbeParams();
38// params.travelInDir(fleet.getFacing(), 2f);
39// params.travelTo(target);
40// params.assumeOrbit(target, 200f, 10f);
41// params.emitPing(Pings.REMOTE_SURVEY);
42// params.wait(3f);
43// params.performAction(new Script() {
44// @Override
45// public void run() {
46// if (target.getMarket() != null &&
47// target.getMarket().getSurveyLevel() != SurveyLevel.FULL) {
48// Misc.setFullySurveyed(target.getMarket(), null, false);
49// String text = "Remote survey telemery received.";
50// new SurveyDataForPlanetIntel(target, text, null);
51// }
52// }
53// });
54// CustomCampaignEntityAPI entity = fleet.getContainingLocation().addCustomEntity(null,
55// "Remote Survey Probe", Entities.GENERIC_PROBE_ACTIVE, Factions.PLAYER, params);
56// entity.setLocation(fleet.getLocation().x, fleet.getLocation().y);
57// entity.setFacing(fleet.getFacing());
58//
59// GenericProbeEntityPlugin plugin = (GenericProbeEntityPlugin) entity.getCustomPlugin();
60// plugin.getMovement().setLocation(entity.getLocation());
61// plugin.getMovement().setFacing(entity.getFacing());
62// Vector2f vel = Misc.getUnitVectorAtDegreeAngle(entity.getFacing());
66//
67// Misc.fadeIn(entity, 1f);
68// }
69
72 if (level != VisibilityLevel.NONE) {
74 }
75
76 performed = false;
77 }
78 }
79
80
81 @Override
82 protected void applyEffect(float amount, float level) {
83 CampaignFleetAPI fleet = getFleet();
84 if (fleet == null) return;
85
86 //float b = fleet.getStats().getDynamic().getValue(Stats.SENSOR_BURST_BURN_PENALTY_MULT);
87 //float b = 1f;
88 //fleet.getStats().getFleetwideMaxBurnMod().modifyMult(getModId(), 1f + (0f - 1f * level) * b, "Remote survey");
89 fleet.getStats().getFleetwideMaxBurnMod().modifyMult(getModId(), 0f, "Remote survey");
92
93 if (!performed && level >= 1f) {
94 // do the actual survey stuff
95 PlanetAPI planet = findBestPlanet();
96 if (planet != null && planet.getMarket() != null) {
97 MarketAPI market = planet.getMarket();
98 market.setSurveyLevel(SurveyLevel.PRELIMINARY);
99 //Misc.setPreliminarySurveyed(market, null, true);
100
102
103 if (planet.getStarSystem() != null) {
105 }
106
107 }
108 performed = true;
109 }
110 }
111
112
113 public boolean isUsable() {
114 if (!super.isUsable()) return false;
115 if (getFleet() == null) return false;
116
117 CampaignFleetAPI fleet = getFleet();
118 if (fleet.isInHyperspace() || fleet.isInHyperspaceTransition()) return false;
119
120 if (findBestPlanet() == null) return false;
121
122 return true;
123 }
124
126
127 CampaignFleetAPI fleet = getFleet();
128 if (fleet == null || fleet.isInHyperspace() || fleet.getStarSystem() == null) return null;
129
130 StarSystemAPI system = fleet.getStarSystem();
131 if (system.getMemoryWithoutUpdate().contains(ALREADY_DID_IN_SYSTEM)) return null;
132
134
135 int bestScore = 0;
136 PlanetAPI best = null;
137 for (PlanetAPI planet : system.getPlanets()) {
138 if (planet.isStar()) continue;
139 if (planet.getMarket() == null) continue;
140
141 SurveyLevel level = planet.getMarket().getSurveyLevel();
142 if (level == SurveyLevel.FULL) continue;
143
144 int score = plugin.getSurveyDataScore(planet);
145 if (score > bestScore) {
146 bestScore = score;
147 best = planet;
148 }
149 }
150
151 return best;
152 }
153
154
155 @Override
156 protected void deactivateImpl() {
157 cleanupImpl();
158 }
159
160 @Override
161 protected void cleanupImpl() {
162 CampaignFleetAPI fleet = getFleet();
163 if (fleet == null) return;
164
168 }
169
170
171 @Override
172 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded) {
173
174 CampaignFleetAPI fleet = getFleet();
175 if (fleet == null) return;
176
177 Color gray = Misc.getGrayColor();
178 Color highlight = Misc.getHighlightColor();
179 Color bad = Misc.getNegativeHighlightColor();
180
182 LabelAPI title = tooltip.addTitle(spec.getName());
183 } else {
184 tooltip.addSpacer(-10f);
185 }
186
187 float pad = 10f;
188 tooltip.addPara("Coordinate the fleet's active sensor network to scan all the planets in the system and "
189 + "identify the most promising candidate for a full survey operation.",
190 pad, highlight,
191 "" + (int)SURVEY_RANGE);
192
193 tooltip.addPara("Increases the range at which the fleet can be detected by %s* units and brings the fleet to a near-stop as drives are powered down to reduce interference.",
194 pad, highlight,
196 );
197
199 //List<PlanetAPI> planets = getAllPlanetsInRange();
200 PlanetAPI planet = findBestPlanet();
201 if (planet == null) {
202 if (fleet.isInHyperspace()) {
203 tooltip.addPara("Can not be used in hyperspace.", bad, pad);
204 } else if (fleet.getStarSystem() != null &&
206 tooltip.addPara("Remote survey already performed in this star system.", bad, pad);
207 } else {
208 tooltip.addPara("No suitable planets in the star system.", bad, pad);
209 }
210 }
211 }
212
213 tooltip.addPara("*2000 units = 1 map grid cell", gray, pad);
214
215
216 addIncompatibleToTooltip(tooltip, expanded);
217
218 }
219
220 public boolean hasTooltip() {
221 return true;
222 }
223
224}
225
226
227
228
229
static SettingsAPI getSettings()
Definition Global.java:57
static boolean CODEX_TOOLTIP_MODE
Definition Global.java:15
static SectorAPI getSector()
Definition Global.java:65
void modifyMult(String source, float value)
void modifyMult(String source, float value)
void modifyFlat(String source, float value)
void addIncompatibleToTooltip(TooltipMakerAPI tooltip, boolean expanded)
void createTooltip(TooltipMakerAPI tooltip, boolean expanded)
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color getGrayColor()
Definition Misc.java:826
static Color getHighlightColor()
Definition Misc.java:792
Object getNewPluginInstance(String id)
EveryFrameScript addPing(SectorEntityToken entity, String pingType)
void setSurveyLevel(SurveyLevel surveyLevel)
void set(String key, Object value)
default int getSurveyDataScore(PlanetAPI planet)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
UIComponentAPI addSpacer(float height)