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;
4import java.util.ArrayList;
5import java.util.Iterator;
6import java.util.List;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.campaign.PlanetAPI;
11import com.fs.starfarer.api.campaign.SectorEntityToken.VisibilityLevel;
12import com.fs.starfarer.api.campaign.econ.MarketAPI;
13import com.fs.starfarer.api.campaign.econ.MarketAPI.SurveyLevel;
14import com.fs.starfarer.api.impl.campaign.ids.Pings;
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 float SURVEY_RANGE = 10000f;
22 public static final float DETECTABILITY_RANGE_BONUS = 5000f;
23 public static final float ACCELERATION_MULT = 4f;
24
25
26 protected boolean performed = false;
27
28 @Override
29 protected void activateImpl() {
30 if (entity.isInCurrentLocation()) {
31 VisibilityLevel level = entity.getVisibilityLevelToPlayerFleet();
32 if (level != VisibilityLevel.NONE) {
33 Global.getSector().addPing(entity, Pings.REMOTE_SURVEY);
34 }
35
36 performed = false;
37 }
38
39 }
40
41 @Override
42 protected void applyEffect(float amount, float level) {
43 CampaignFleetAPI fleet = getFleet();
44 if (fleet == null) return;
45
46 //float b = fleet.getStats().getDynamic().getValue(Stats.SENSOR_BURST_BURN_PENALTY_MULT);
47 //float b = 1f;
48 //fleet.getStats().getFleetwideMaxBurnMod().modifyMult(getModId(), 1f + (0f - 1f * level) * b, "Remote survey");
49 fleet.getStats().getFleetwideMaxBurnMod().modifyMult(getModId(), 0f, "Remote survey");
50 fleet.getStats().getDetectedRangeMod().modifyFlat(getModId(), DETECTABILITY_RANGE_BONUS * level, "Remote survey");
51 fleet.getStats().getAccelerationMult().modifyMult(getModId(), 1f + (ACCELERATION_MULT - 1f) * level);
52
53 if (!performed && level >= 1f) {
54 // do the actual survey stuff
55
56 for (PlanetAPI planet : getSurveyableInRange()) {
57 MarketAPI market = planet.getMarket();
58 SurveyLevel surveyLevel = market.getSurveyLevel();
59 if (market == null || (surveyLevel != SurveyLevel.SEEN && surveyLevel != SurveyLevel.NONE)) {
60 continue;
61 }
62
63 Misc.setPreliminarySurveyed(market, null, true);
64 }
65
66 performed = true;
67 }
68 }
69
70
71 public boolean isUsable() {
72 if (!super.isUsable()) return false;
73 if (getFleet() == null) return false;
74
75 CampaignFleetAPI fleet = getFleet();
76 if (fleet.isInHyperspace() || fleet.isInHyperspaceTransition()) return false;
77
78 if (getSurveyableInRange().isEmpty()) return false;
79
80 return true;
81 }
82
83 protected List<PlanetAPI> getAllPlanetsInRange() {
84 List<PlanetAPI> result = new ArrayList<PlanetAPI>();
85
86 CampaignFleetAPI fleet = getFleet();
87 if (fleet == null) return result;
88 if (fleet.isInHyperspace()) return result;
89
90
91 for (PlanetAPI planet : fleet.getContainingLocation().getPlanets()) {
92 if (planet.isStar()) continue;
93 if (planet.getMarket() == null) continue;
94
95 //SurveyLevel level = planet.getMarket().getSurveyLevel();
96
97 float dist = Misc.getDistance(fleet.getLocation(), planet.getLocation());
98 if (dist <= SURVEY_RANGE) {
99 result.add(planet);
100 }
101 }
102 return result;
103 }
104
105 protected List<PlanetAPI> getSurveyableInRange() {
106 List<PlanetAPI> result = getAllPlanetsInRange();
107
108 Iterator<PlanetAPI> iter = result.iterator();
109 while (iter.hasNext()) {
110 PlanetAPI curr = iter.next();
111 SurveyLevel level = curr.getMarket().getSurveyLevel();
112 if (level != SurveyLevel.SEEN && level != SurveyLevel.NONE) {
113 iter.remove();
114 }
115 }
116
117 return result;
118 }
119
120
121 @Override
122 protected void deactivateImpl() {
123 cleanupImpl();
124 }
125
126 @Override
127 protected void cleanupImpl() {
128 CampaignFleetAPI fleet = getFleet();
129 if (fleet == null) return;
130
131 fleet.getStats().getDetectedRangeMod().unmodify(getModId());
132 fleet.getStats().getFleetwideMaxBurnMod().unmodify(getModId());
133 fleet.getStats().getAccelerationMult().unmodify(getModId());
134 }
135
136
137 @Override
138 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded) {
139
140 CampaignFleetAPI fleet = getFleet();
141 if (fleet == null) return;
142
143 Color gray = Misc.getGrayColor();
144 Color highlight = Misc.getHighlightColor();
145 Color bad = Misc.getNegativeHighlightColor();
146
147 LabelAPI title = tooltip.addTitle(spec.getName());
148
149 float pad = 10f;
150 //tooltip.addPara("Coordinate the fleet's active sensor network to perform a preliminary survey of nearby planets.", pad);
151
152 tooltip.addPara("Coordinate the fleet's active sensor network to perform a preliminary survey of all unsurveyed planets within %s* units.",
153 pad, highlight,
154 "" + (int)SURVEY_RANGE);
155
156 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.",
157 pad, highlight,
159 );
160
161
162 //List<PlanetAPI> planets = getAllPlanetsInRange();
163 List<PlanetAPI> planets = getSurveyableInRange();
164 if (planets.isEmpty()) {
165 if (getAllPlanetsInRange().isEmpty()) {
166 tooltip.addPara("No planets in range.", bad, pad);
167 } else {
168 tooltip.addPara("You have either full or preliminary survey data for all planets in range.", bad, pad);
169 }
170 } else {
171 tooltip.addPara("The following unsurveyed planets are in range:", pad);
172
173// tooltip.beginGridFlipped(1300f, 1, 50f, 10f);
174// int j = 0;
175// for (PlanetAPI planet : planets) {
176// float dist = Misc.getDistance(fleet.getLocation(), planet.getLocation());
177// String distStr = Misc.getWithDGS(dist);
178//
179// String status = planet.getName() + ", " + planet.getTypeNameWithWorld().toLowerCase();
180// SurveyLevel level = planet.getMarket().getSurveyLevel();
181//
182// if (level == SurveyLevel.PRELIMINARY) status += " (preliminary)";
183// else if (level == SurveyLevel.FULL) status += " (full survey)";
184// else status += " (unsurveyed)";
185//
186// tooltip.addToGrid(0, j++, status, distStr);
187// }
188// tooltip.addGrid(pad);
189
190 float currPad = 3f;
191 String indent = " ";
192 for (PlanetAPI planet : planets) {
193 //String level = Misc.getSurveyLevelString(planet.getMarket().getSurveyLevel(), true);
194 LabelAPI label = tooltip.addPara(indent + planet.getName() + ", %s",
195 currPad, planet.getSpec().getIconColor(),
196 planet.getTypeNameWithWorld().toLowerCase());
197// label.setHighlightColor(highlight);
198// label.highlightLast(level);
199 currPad = 0f;
200 }
201
202// if (getSurveyableInRange().isEmpty()) {
203// tooltip.addPara("No surveyable planets in range.", bad, pad);
204// }
205 }
206
207 tooltip.addPara("*2000 units = 1 map grid cell", gray, pad);
208
209
210 addIncompatibleToTooltip(tooltip, expanded);
211
212 }
213
214 public boolean hasTooltip() {
215 return true;
216 }
217
218}
219
220
221
222
223
static SectorAPI getSector()
Definition Global.java:59
void addIncompatibleToTooltip(TooltipMakerAPI tooltip, boolean expanded)
void createTooltip(TooltipMakerAPI tooltip, boolean expanded)