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