Starsector API
Loading...
Searching...
No Matches
TriTachyonStandardActivityCause.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.FactionAPI;
11import com.fs.starfarer.api.campaign.StarSystemAPI;
12import com.fs.starfarer.api.campaign.econ.CommodityOnMarketAPI;
13import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
14import com.fs.starfarer.api.campaign.econ.MarketAPI;
15import com.fs.starfarer.api.impl.campaign.ids.Commodities;
16import com.fs.starfarer.api.impl.campaign.ids.Factions;
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.UIPanelAPI;
22import com.fs.starfarer.api.util.Misc;
23
25
26 public static int MIN_TRITACH_PRODUCTION = 5;
27 public static int MIN_COMPETITOR_PRODUCTION = 4;
28
29 public static int MIN_COMPETITOR_MARKET_SIZE = 4;
30
31 public static float PROD_PROGRESS_MULT = Global.getSettings().getFloat("triTachyonProgressPerUnitProdMult");
32
33 public static Set<String> COMPETING_COMMODITIES = new LinkedHashSet<String>();
34 static {
46 }
47
48 public static class CompetitorData {
49 public String commodityId;
50 public CommoditySpecAPI spec;
51 public int factionProdTotal;
52 public int factionMaxProd;
53 public int competitorProdTotal;
54 public int competitorMaxProd;
55 public int competitorMaxMarketSize;
56 public int allProdTotal;
57 public List<MarketAPI> factionProducers = new ArrayList<MarketAPI>();
58 public List<MarketAPI> competitorProducers = new ArrayList<MarketAPI>();
59
60 public CompetitorData(String commodityId) {
61 this.commodityId = commodityId;
62 spec = Global.getSettings().getCommoditySpec(commodityId);
63 }
64
65 public int getProgress(float progMult) {
66 return (int) Math.round(competitorMaxProd * progMult);
67 }
68 }
69
70
71 public static CompetitorData computeCompetitorData(String factionId, String competitorId, String commodityId) {
72 CompetitorData data = new CompetitorData(commodityId);
73
75 CommodityOnMarketAPI com = market.getCommodityData(commodityId);
76 if (com == null) continue;
77
78 int prod = com.getMaxSupply();
79 if (prod <= 0) continue;
80
81 if (factionId.equals(market.getFactionId())) {
82 data.factionProdTotal += prod;
83 data.factionProducers.add(market);
84 data.factionMaxProd = Math.max(data.factionMaxProd, prod);
85 } else if (competitorId.equals(market.getFactionId())) {
86 data.competitorProdTotal += prod;
87 data.competitorMaxProd = Math.max(data.competitorMaxProd, prod);
88 data.competitorProducers.add(market);
89
90 data.competitorMaxMarketSize = Math.max(data.competitorMaxMarketSize, market.getSize());
91 }
92
93 data.allProdTotal += prod;
94 }
95
96 return data;
97 }
98
99 public static List<CompetitorData> computePlayerCompetitionData() {
100 String factionId = Factions.TRITACHYON;
101
102 Set<String> commodities = new LinkedHashSet<String>();
103 for (MarketAPI market : Global.getSector().getEconomy().getMarketsCopy()) {
104 if (!factionId.equals(market.getFactionId())) continue;
105
106 for (CommodityOnMarketAPI com : market.getCommoditiesCopy()) {
107 if (com.isPersonnel()) continue;
108 if (com.getId().equals(Commodities.SHIPS)) continue;
109 if (com.getId().equals(Commodities.SHIP_WEAPONS)) continue;
110 if (!COMPETING_COMMODITIES.contains(com.getId())) continue;
111 int prod = com.getMaxSupply();
112
113 if (prod >= MIN_TRITACH_PRODUCTION) {
114 commodities.add(com.getId());
115 }
116 }
117 }
118
119 List<CompetitorData> result = new ArrayList<CompetitorData>();
120
121 for (String commodityId : commodities) {
122 CompetitorData data = computeCompetitorData(factionId, Factions.PLAYER, commodityId);
123 if (data.competitorMaxProd < MIN_COMPETITOR_PRODUCTION) continue;
124 if (data.competitorMaxMarketSize < MIN_COMPETITOR_MARKET_SIZE) continue;
125 result.add(data);
126 }
127
128 return result;
129 }
130
131 public static float MAX_MAG = 0.5f;
132
133
137
138
139 @Override
141 return new BaseFactorTooltip() {
142 @Override
143 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
144 float opad = 10f;
145
146 Color h = Misc.getHighlightColor();
147 Color tc = Misc.getTextColor();
148
149 tooltip.addPara("Your colony production of certain commodities that the Tri-Tachyon corporation "
150 + "has an interest in is high enough "
151 + "to be viewed as competition.", 0f);
152
154
155// tooltip.addPara("Independent-flagged commerce raiders have been sighted in your space, "
156// + "attacking trade fleets regardless of their factional allegiance.", 0f);
157
158 List<CompetitorData> comp = computePlayerCompetitionData();
160
161 tooltip.beginTable(player, 20f, "Commodity", getTooltipWidth(tooltipParam) - 150f, "Production", 150f);
162 for (final CompetitorData data : comp) {
163 tooltip.addRow(Alignment.LMID, tc, Misc.ucFirst(data.spec.getLowerCaseName()),
164 Alignment.MID, h, "" + (int) data.competitorMaxProd);
165 }
166 tooltip.addTable("", 0, opad);
167 tooltip.addSpacer(5f);
168
169 tooltip.addPara("Event progress is based on the maximum production of each commodity. "
170 + "%s below %s per colony, or reducing the scope of the competition to a single commodity,"
171 + " should be enough to divert "
172 + "Tri-Tachyon's attention.", opad,
173 h,
174 "Reducing production levels",
176 "single commodity");
177
178 tooltip.addPara("%s are also possible.", opad,
179 h, "Reciprocal solutions");
180
182 if (system != null) {
183 tooltip.addPara("The Tri-Tachyon Corporation's base of power is in the " +
184 system.getNameWithLowercaseType() + ".", opad);
185
186 MapParams params = new MapParams();
187 params.showSystem(system);
188 float width = tooltip.getWidthSoFar();
189 float height = Math.round(width / 1.6f);
190 params.positionToShowAllMarkersAndSystems(true, Math.min(width, height));
191 UIPanelAPI map = tooltip.createSectorMap(width, height, params, system.getNameWithLowercaseTypeShort());
192 tooltip.addCustom(map, opad);
193 }
194 }
195 };
196 }
197
198 @Override
199 public boolean shouldShow() {
200 return getProgress() != 0;
201 }
202
203 public int getProgress() {
206 return 0;
207 }
208
209 int total = 0;
210 List<CompetitorData> comp = computePlayerCompetitionData();
211 if (comp.size() <= 1) return 0;
212
213 for (CompetitorData data : comp) {
214 total += data.getProgress(PROD_PROGRESS_MULT);
215 }
216
218 total = (int) Math.round(total * TriTachyonHostileActivityFactor.DEALT_WITH_MERC_PROGRESS_MULT);
219 }
220
221 return total;
222 }
223
224 public String getDesc() {
225 return "Competing exports";
226 }
227
228
230 if (getProgress() <= 0) return 0f;
231
232 List<CompetitorData> comp = computePlayerCompetitionData();
233 float mag = 0f;
234 for (CompetitorData data : comp) {
235 for (MarketAPI market : data.competitorProducers) {
236 if (market.getContainingLocation() == system) {
237 CommodityOnMarketAPI com = market.getCommodityData(data.commodityId);
238 float prod = com.getMaxSupply();
239 mag += prod * 0.05f;
240 }
241 }
242 }
243 if (mag > MAX_MAG) mag = MAX_MAG;
244
245 mag = Math.round(mag * 100f) / 100f;
246
247 return mag;
248 }
249
250}
251
252
253
254
255
256
static SettingsAPI getSettings()
Definition Global.java:57
static SectorAPI getSector()
Definition Global.java:65
static CompetitorData computeCompetitorData(String factionId, String competitorId, String commodityId)
void showSystem(StarSystemAPI system)
void positionToShowAllMarkersAndSystems(boolean showPlayerFleet, float heightOnScreen)
static Color getTextColor()
Definition Misc.java:839
static String ucFirst(String str)
Definition Misc.java:559
static Color getHighlightColor()
Definition Misc.java:792
CommoditySpecAPI getCommoditySpec(String commodityId)
FactionAPI getFaction(String factionId)
CommodityOnMarketAPI getCommodityData(String commodityId)
void addTable(String emptyText, int andMore, float pad)
UIComponentAPI addCustom(UIComponentAPI comp, float pad)
UIPanelAPI beginTable(FactionAPI faction, float itemHeight, Object ... columns)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
UIComponentAPI addSpacer(float height)
UIPanelAPI createSectorMap(float w, float h, MapParams p, String title)