Starsector API
Loading...
Searching...
No Matches
StandardPirateActivityCause2.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.List;
5
6import com.fs.starfarer.api.campaign.StarSystemAPI;
7import com.fs.starfarer.api.campaign.econ.MarketAPI;
8import com.fs.starfarer.api.impl.campaign.ids.Factions;
9import com.fs.starfarer.api.impl.campaign.rulecmd.KantaCMD;
10import com.fs.starfarer.api.ui.MapParams;
11import com.fs.starfarer.api.ui.TooltipMakerAPI;
12import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
13import com.fs.starfarer.api.ui.UIPanelAPI;
14import com.fs.starfarer.api.util.Misc;
15
17
18 public static float MAX_MAG = 0.5f;
19
23
24 @Override
25 public TooltipCreator getTooltip() {
26 return new BaseFactorTooltip() {
27 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
28 float opad = 10f;
29 tooltip.addPara("Any colony, especially one outside the core, attracts some degree of piracy."
30 + " %s and %s colonies attract more pirates.", 0f,
31 Misc.getHighlightColor(), "Larger", "less stable");
32 tooltip.addPara("Event progress value is based on the size and stability of the largest colony "
33 + "under your control. If multiple colonies have the same size, the one with higher "
34 + "stability is used.", opad);
35
36 MarketAPI biggest = getBiggestColony();
37 if (biggest != null && biggest.getStarSystem() != null) {
38 tooltip.addPara("Biggest colony: %s, size: %s, stability: %s", opad, Misc.getHighlightColor(),
39 biggest.getName(),
40 "" + biggest.getSize(),
41 "" + (int) biggest.getStabilityValue());
42
43 MapParams params = new MapParams();
44 params.showSystem(biggest.getStarSystem());
45 float w = tooltip.getWidthSoFar();
46 float h = Math.round(w / 1.6f);
47 params.positionToShowAllMarkersAndSystems(true, Math.min(w, h));
48 UIPanelAPI map = tooltip.createSectorMap(w, h, params, biggest.getStarSystem().getNameWithLowercaseTypeShort());
49 tooltip.addCustom(map, opad);
50 }
51 }
52 };
53 }
54
55 public MarketAPI getBiggestColony() {
56 List<MarketAPI> markets = Misc.getPlayerMarkets(false);
57 MarketAPI biggest = null;
58 float max = 0;
59 for (MarketAPI market : markets) {
60 float size = market.getSize();
61 if (size >= max) {
62 if (size == max && biggest != null) {
63 if (biggest.getStabilityValue() > market.getStabilityValue()) {
64 continue;
65 }
66 }
67 max = size;
68 biggest = market;
69 }
70 }
71 return biggest;
72 }
73
74 @Override
75 public boolean shouldShow() {
76 return getProgress() != 0 || KantaCMD.playerHasProtection();
77 }
78
79 @Override
80 public String getProgressStr() {
81 if (KantaCMD.playerHasProtection()) return EventFactor.NEGATED_FACTOR_PROGRESS;
82 return super.getProgressStr();
83 }
84
85 @Override
87 if (KantaCMD.playerHasProtection()) return Misc.getPositiveHighlightColor();
88 // TODO Auto-generated method stub
89 return super.getProgressColor(intel);
90 }
91
92 public int getProgress() {
93 if (KantaCMD.playerHasProtection()) return 0;
94
95 MarketAPI biggest = getBiggestColony();
96 if (biggest == null) return 0;
97 int progress = (int) (biggest.getSize() + (10 - biggest.getStabilityValue()));
98 return progress;
99 }
100
101 public String getDesc() {
102 return "Colony presence and instability";
103 }
104
105 public float getMagForMarket(MarketAPI market) {
106 float val = market.getSize() * (0.33f + 0.67f * (1f - market.getStabilityValue() / 10f));
107 val *= 0.1f;
108 if (val > MAX_MAG) val = MAX_MAG;
109 return val;
110 }
111
112 public float getMagnitudeContribution(StarSystemAPI system) {
113 if (KantaCMD.playerHasProtection()) return 0f;
114
115 if (getProgress() <= 0) return 0f;
116
117 List<MarketAPI> markets = Misc.getMarketsInLocation(system, Factions.PLAYER);
118
119 float max = 0.1f;
120 for (MarketAPI market : markets) {
121 float val = getMagForMarket(market);
122 //float val = market.getSize() * 0.01f * 5f;
123 max = Math.max(val, max);
124 }
125
126 if (max > MAX_MAG) max = MAX_MAG;
127
128 max = Math.round(max * 100f) / 100f;
129
130 //if (true) return 0.79f;
131 return max;
132 }
133
134}
135
136
137
138