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