Starsector API
Loading...
Searching...
No Matches
PirateBasePirateActivityCause2.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.events;
2
3import java.util.ArrayList;
4import java.util.LinkedHashSet;
5import java.util.List;
6import java.util.Set;
7
8import java.awt.Color;
9
10import com.fs.starfarer.api.Global;
11import com.fs.starfarer.api.campaign.StarSystemAPI;
12import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin;
13import com.fs.starfarer.api.campaign.econ.MarketAPI;
14import com.fs.starfarer.api.impl.campaign.enc.SlipstreamPirateEPEC;
15import com.fs.starfarer.api.impl.campaign.fleets.EconomyFleetRouteManager;
16import com.fs.starfarer.api.impl.campaign.ids.Factions;
17import com.fs.starfarer.api.impl.campaign.intel.bases.PirateBaseIntel;
18import com.fs.starfarer.api.impl.campaign.rulecmd.HA_CMD;
19import com.fs.starfarer.api.ui.Alignment;
20import com.fs.starfarer.api.ui.MapParams;
21import com.fs.starfarer.api.ui.TooltipMakerAPI;
22import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
23import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipLocation;
24import com.fs.starfarer.api.ui.UIPanelAPI;
25import com.fs.starfarer.api.util.Misc;
26import com.fs.starfarer.api.util.Range;
27
29
30 public static boolean DEAL_PROVIDES_NEGATIVE_PROGRESS = false;
31
32 public static float MAX_MAG = 0.5f;
33
34
35 public static List<MarketAPI> getColoniesAffectedBy(PirateBaseIntel base) {
36 List<MarketAPI> result = new ArrayList<MarketAPI>();
37 for (StarSystemAPI system : getSystemsAffectedBy(base)) {
38 result.addAll(Misc.getMarketsInLocation(system, Factions.PLAYER));
39 }
40 return result;
41 }
42
43 public static List<StarSystemAPI> getSystemsAffectedBy(PirateBaseIntel base) {
44 List<StarSystemAPI> result = new ArrayList<StarSystemAPI>();
45// for (IntelInfoPlugin intel : Global.getSector().getIntelManager().getIntel(HostileActivityIntel.class)) {
46// HostileActivityIntel curr = (HostileActivityIntel) intel;
47 for (StarSystemAPI system : Misc.getSystemsWithPlayerColonies(false)) {
48 if (getBaseIntel(system) == base) {
49 result.add(system);
50 }
51 }
52 return result;
53 }
54
55
57 if (system == null) return null;
59 return base;
60 }
61
62 transient boolean ignoreDeal = false;
63
67
68 @Override
70 Set<PirateBaseIntel> seen = new LinkedHashSet<PirateBaseIntel>();
71 for (final StarSystemAPI system : Misc.getSystemsWithPlayerColonies(false)) {
72 final PirateBaseIntel base = getBaseIntel(system);
73 if (base == null || seen.contains(base)) continue;
74
75
76 int numColonies = 0;
77 final List<String> affected = new ArrayList<String>();
78 for (StarSystemAPI curr : getSystemsAffectedBy(base)) {
79 affected.add(curr.getNameWithNoType());
80 numColonies += Misc.getMarketsInLocation(curr, Factions.PLAYER).size();
81 }
82 if (affected.isEmpty()) continue;
83
84 seen.add(base);
85
86
87 final String colonies = numColonies != 1 ? "colonies" : "colony";
88 final String isOrAre = numColonies != 1 ? "are" : "is";
89
90 String desc = "Hidden pirate base near your " + colonies;
91 if (base.isPlayerVisible()) {
92 desc = "Pirate base in the " + base.getSystem().getNameWithLowercaseTypeShort() + "";
93 }
94 ignoreDeal = true;
95 final int progress = getProgressForBase(base);
96 ignoreDeal = false;
97 String progressStr = "+" + progress;
98 if (progress < 0) progressStr = "" + progress;
99 Color descColor = getDescColor(intel);
100 Color progressColor = getProgressColor(intel);
101
102 //DEAL_PROVIDES_NEGATIVE_PROGRESS = true;
103 //DEAL_PROVIDES_NEGATIVE_PROGRESS = false;
104
107 int p = getProgressForBase(base);
108 progressStr = "+" + p;
109 if (p < 0) progressStr = "" + p;
110 descColor = Misc.getTextColor();
111 } else {
113 descColor = Misc.getGrayColor();
114 }
115 progressColor = Misc.getPositiveHighlightColor();
116 } else {
118 descColor = Misc.getTextColor();
119 }
120 }
121
122 info.addRowWithGlow(Alignment.LMID, descColor, " " + desc,
123 Alignment.RMID, progressColor, progressStr);
124
126 @Override
127 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
128 float opad = 10f;
129
130 String aStr = Misc.getAndJoined(affected);
131 String systems = "systems";
132 if (affected.size() == 1) systems = "system";
133
134 MapParams params = new MapParams();
135 for (StarSystemAPI curr : getSystemsAffectedBy(base)) {
136 params.showSystem(curr);
137 }
138 if (base.playerHasDealWithBaseCommander() || base.isPlayerVisible()) {
139 params.showMarket(base.getMarket(), 1f);
140// params.arrows = new ArrayList<ArrowData>();
141// for (StarSystemAPI curr : getSystemsAffectedBy(base)) {
142// if (curr != base.getEntity().getContainingLocation()) {
143// ArrowData arr = new ArrowData(base.getEntity(), curr.getHyperspaceAnchor());
144// arr.color = Global.getSector().getFaction(Factions.PIRATES).getBrightUIColor();
145// params.arrows.add(arr);
146// }
147// }
148 }
149 float w = tooltip.getWidthSoFar();
150 float h = Math.round(w / 1.6f);
151 params.positionToShowAllMarkersAndSystems(true, Math.min(w, h));
152
153 //UIPanelAPI map = tooltip.createSectorMap(w, h, params, aStr + " " + Misc.ucFirst(systems));
154 UIPanelAPI map = tooltip.createSectorMap(w, h, params, aStr + " " + systems);
155
157 String systemStr = "in the " + base.getSystem().getNameWithLowercaseTypeShort() + "";
158 tooltip.addPara("Your " + colonies + " in the " + aStr + " " + systems +
159 " " + isOrAre + " within range of a pirate base located " + systemStr + ". " +
160 "You have an agreement with "
161 + "the base commander, and fleets from this base do not, as a rule, "
162 + "harass your colonies or shipping.", 0f,
163 Misc.getPositiveHighlightColor(), "agreement");
164
166 String extra = "";
168 extra = " instead of providing a reduction in progress";
169 }
170 tooltip.addPara("Assuming current colony income levels, this agreement costs "
171 + "you %s per month. If it was not in effect, "
172 + "this base would contribute %s points of event progress per month" + extra + ".", opad,
174 Misc.getDGSCredits(payment), "" + progress);
175
176 } else {
177 String systemStr = "in a nearby system";
178 if (base.isPlayerVisible()) {
179 systemStr = "in the " + base.getSystem().getNameWithLowercaseTypeShort() + "";
180 }
181 tooltip.addPara("Your " + colonies + " in the " + aStr + " " + systems +
182 " " + isOrAre + " within range of a pirate base located " + systemStr + ". " +
183 "This results in a greater volume of pirate "
184 + "fleets preying on trade. %s should address this.", 0f,
185 Misc.getHighlightColor(), "Dealing with the base");
186 }
187
188 tooltip.addCustom(map, opad);
189 }
190 };
191 info.addTooltipToAddedRow(t, TooltipLocation.RIGHT, false);
192 }
193 }
194
195 public boolean playerHasDealWithAnyBases() {
199 return true;
200 }
201 }
202 return false;
203 }
204
205 @Override
206 public boolean shouldShow() {
207 return getProgress() != 0 || playerHasDealWithAnyBases();
208 }
209
210 public int getProgress() {
212
213 int total = 0;
216 total += getProgressForBase(curr);
217 }
218 return total;
219 }
220
221
224 if (!ignoreDeal && base.playerHasDealWithBaseCommander()) {
225 return 0;
226 }
227 }
228
229 boolean ignore = ignoreDeal;
230
231 if (!ignore && DEAL_PROVIDES_NEGATIVE_PROGRESS) {
232 ignoreDeal = true;
233 }
234 int total = 0;
235 for (StarSystemAPI system : getSystemsAffectedBy(base)) {
236 total += getProgressForSystem(system);
237 }
238
239 if (!ignore && DEAL_PROVIDES_NEGATIVE_PROGRESS) {
240 ignoreDeal = false;
241 }
242
244 if (!ignoreDeal && base.playerHasDealWithBaseCommander()) {
245 total *= -1;
246 }
247 }
248
249 return total;
250 }
251
252 protected int getProgressForSystem(StarSystemAPI system) {
253 float mag = getMagnitudeContribution(system);
254 if (mag <= 0) return 0;
255 mag /= MAX_MAG;
256 if (mag > 1f) mag = 1f;
257 Range r = new Range("pirateBaseProximityPoints");
258 return r.interpInt(mag);
259// int progress = 3 + (int) Math.round(mag * 7f);
260// return progress;
261 }
262
263
264 public String getDesc() {
265 return null;
266 }
267// protected float getMaxMag() {
268// float max = 0f;
269// for (final StarSystemAPI system : Misc.getSystemsWithPlayerColonies(false)) {
270// float mag = getMagnitudeContribution(system);
271// if (mag > max) {
272// max = mag;
273// }
274// }
275// return max;
276// }
277
278
281 return 0f;
282 }
283
284 List<MarketAPI> markets = Misc.getMarketsInLocation(system, Factions.PLAYER);
285 float maxSize = 0f;
286 for (MarketAPI market : markets) {
287 maxSize = Math.max(maxSize, market.getSize());
288 }
289
290 PirateBaseIntel base = getBaseIntel(system);
292 //mag = 0.95f;
293 mag *= 0.5f;
294 mag *= maxSize / 6f;
295 if (base != null) {
296 mag *= (float)(base.getTier().ordinal() + 1f) / 5f;
297 }
298 if (mag > MAX_MAG) mag = MAX_MAG;
299
300 mag = Math.round(mag * 100f) / 100f;
301
302 if (base != null && base.playerHasDealWithBaseCommander() && !ignoreDeal) {
303 mag = 0f;
304 }
305
306 return mag;
307 }
308
309
310}
311
312
static SectorAPI getSector()
Definition Global.java:65
static PirateBaseIntel getClosestPirateBase(Vector2f locInHyper)
static float getPirateBaseProximityFactor(PirateBaseIntel base, Vector2f locInHyper)
static int computePirateProtectionPaymentPerMonth(PirateBaseIntel intel)
Definition HA_CMD.java:136
void showSystem(StarSystemAPI system)
void positionToShowAllMarkersAndSystems(boolean showPlayerFleet, float heightOnScreen)
void showMarket(MarketAPI market)
static Color getTextColor()
Definition Misc.java:839
static String getDGSCredits(float num)
Definition Misc.java:1390
static List< StarSystemAPI > getSystemsWithPlayerColonies(boolean includeNonPlayerFaction)
Definition Misc.java:996
static List< MarketAPI > getMarketsInLocation(LocationAPI location, String factionId)
Definition Misc.java:936
static Color getGrayColor()
Definition Misc.java:826
static Color getHighlightColor()
Definition Misc.java:792
static String getAndJoined(List< String > strings)
Definition Misc.java:871
static Color getPositiveHighlightColor()
Definition Misc.java:822
UIComponentAPI addCustom(UIComponentAPI comp, float pad)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
UIPanelAPI createSectorMap(float w, float h, MapParams p, String title)
Object addRowWithGlow(Object ... data)
void addTooltipToAddedRow(TooltipCreator tc, TooltipLocation loc)