Starsector API
Loading...
Searching...
No Matches
BaseMarketConditionPlugin.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.econ;
2
3import java.util.Arrays;
4import java.util.HashMap;
5import java.util.LinkedHashMap;
6import java.util.List;
7import java.util.Map;
8
9import java.awt.Color;
10
11import com.fs.starfarer.api.Global;
12import com.fs.starfarer.api.campaign.CampaignFleetAPI;
13import com.fs.starfarer.api.campaign.StarSystemAPI;
14import com.fs.starfarer.api.campaign.econ.MarketAPI;
15import com.fs.starfarer.api.campaign.econ.MarketConditionAPI;
16import com.fs.starfarer.api.campaign.econ.MarketConditionPlugin;
17import com.fs.starfarer.api.ui.LabelAPI;
18import com.fs.starfarer.api.ui.TooltipMakerAPI;
19import com.fs.starfarer.api.util.Misc;
20
22
23 protected MarketAPI market;
25
27 this.market = market;
28 this.condition = condition;
29 }
30
31 public void apply(String id) {
32 }
33
34 public void unapply(String id) {
35 }
36
37
38 public void advance(float amount) {
39
40 }
41
42 public String getModId() {
44 }
45
46
48 float s = market.getStabilityValue();
49 //if (true) return 1f + (10f - s) * 0.2f;
50 if (true) return 1f + (10f - s) * 0.1f;
51
52 switch ((int)market.getStabilityValue()) {
53 case 0:
54 return 3f;
55 case 1:
56 return 2.5f;
57 case 2:
58 return 2f;
59 case 3:
60 return 1.5f;
61 case 4:
62 case 5:
63 case 6:
64 case 7:
65 case 8:
66 case 9:
67 case 10:
68 return 1f;
69 default:
70 return 1f;
71 }
72 }
73
75 float s = market.getStabilityValue();
76 //if (true) return 0.1f + s * 0.09f;
77 if (true) return 0.5f + s * 0.05f;
78
79 switch ((int)market.getStabilityValue()) {
80 case 0:
81 return 0.1f;
82 case 1:
83 return 0.25f;
84 case 2:
85 return 0.5f;
86 case 3:
87 return .75f;
88 case 4:
89 case 5:
90 case 6:
91 case 7:
92 case 8:
93 case 9:
94 case 10:
95 return 1f;
96 default:
97 return 1f;
98 }
99 }
100
102 float s = market.getStabilityValue();
103 //if (true) return 1f + s * 0.2f;
104 if (true) return 1f + s * 0.1f;
105
106 switch ((int)market.getStabilityValue()) {
107 case 0:
108 case 1:
109 case 2:
110 case 3:
111 case 4:
112 case 5:
113 case 6:
114 return 1f;
115 case 7:
116 return 1.5f;
117 case 8:
118 return 2f;
119 case 9:
120 return 2.5f;
121 case 10:
122 return 3f;
123 default:
124 return 1f;
125 }
126 }
127
129 float s = market.getStabilityValue();
130 //if (true) return 0.1f + (10f - s) * 0.09f;
131 if (true) return 0.5f + (10f - s) * 0.05f;
132
133 switch ((int)market.getStabilityValue()) {
134 case 0:
135 case 1:
136 case 2:
137 case 3:
138 case 4:
139 case 5:
140 case 6:
141 return 1f;
142 case 7:
143 return .75f;
144 case 8:
145 return 0.5f;
146 case 9:
147 return 0.25f;
148 case 10:
149 return 0.1f;
150 default:
151 return 1f;
152 }
153 }
154
155 public static void main(String[] args) {
156 }
157
158
159 public List<String> getRelatedCommodities() {
160 return null;
161 }
162
163 public void setParam(Object param) {
164
165 }
166
167 public Map<String, String> getTokenReplacements() {
168 HashMap<String, String> tokens = new LinkedHashMap<String, String>();
169
170 tokens.put("$playerName", Global.getSector().getCharacterData().getName());
171 if (market != null) {
172 tokens.put("$marketFaction", market.getFaction().getDisplayName());
173 tokens.put("$TheMarketFaction", Misc.ucFirst(market.getFaction().getDisplayNameWithArticle()));
174 tokens.put("$theMarketFaction", market.getFaction().getDisplayNameWithArticle());
175
177 //tokens.put("$marketSystem", ((StarSystemAPI)eventTarget.getLocation()).getBaseName() + " star system");
178 tokens.put("$marketSystem", ((StarSystemAPI)market.getPrimaryEntity().getLocation()).getBaseName());
179 } else {
180 tokens.put("$marketSystem", "hyperspace");
181 }
182 tokens.put("$marketName", market.getName());
183 tokens.put("$MarketName", Misc.ucFirst(market.getName()));
184 tokens.put("$market", market.getName());
185 tokens.put("$Market", Misc.ucFirst(market.getName()));
186 }
187
189 if (playerFleet != null) {
190 String fleetOrShip = "fleet";
191 if (playerFleet.getFleetData().getMembersListCopy().size() == 1) {
192 fleetOrShip = "ship";
193 if (playerFleet.getFleetData().getMembersListCopy().get(0).isFighterWing()) {
194 fleetOrShip = "fighter wing";
195 }
196 }
197 tokens.put("$playerShipOrFleet", fleetOrShip);
198 }
199
200 return tokens;
201 }
202
203 public String[] getHighlights() {
204 return null;
205 }
206
207 public Color[] getHighlightColors() {
208 String [] highlights = getHighlights();
209 if (highlights != null) {
210 Color c = Global.getSettings().getColor("buttonShortcut");
211 Color [] colors = new Color[highlights.length];
212 Arrays.fill(colors, c);
213 return colors;
214 }
215 return null;
216 }
217
218
219 public void addTokensToList(List<String> list, String ... keys) {
220 Map<String, String> tokens = getTokenReplacements();
221 for (String key : keys) {
222 if (tokens.containsKey(key)) {
223 list.add(tokens.get(key));
224 }
225 }
226 }
227
228 public boolean isTransient() {
229 return true;
230 }
231
232 public boolean showIcon() {
233 return true;
234 }
235
236
237 public boolean hasCustomTooltip() {
238 return true;
239 }
240
241 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded) {
242 float opad = 10f;
243
246 tooltip.addTitle(condition.getName(), color);
247 }
248
249 String text = condition.getSpec().getDesc();
250 Map<String, String> tokens = getTokenReplacements();
251 if (tokens != null) {
252 for (String token : tokens.keySet()) {
253 String value = tokens.get(token);
254 text = text.replaceAll("(?s)\\" + token, value);
255 }
256 }
257
258 if (!text.isEmpty()) {
259 LabelAPI body = tooltip.addPara(text, opad);
260 if (getHighlights() != null) {
261 if (getHighlightColors() != null) {
263 } else {
265 }
267 }
268 }
269
270 createTooltipAfterDescription(tooltip, expanded);
271 }
272
273
274 protected void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded) {
275
276 }
277
278 public boolean isTooltipExpandable() {
279 return false;
280 }
281
282 public float getTooltipWidth() {
283 return 500f;
284 }
285
286 public boolean isPlanetary() {
287 if (condition == null) return true;
288
289 return condition.getSpec().isPlanetary();
290 }
291
292 public boolean runWhilePaused() {
293 return false;
294 }
295
296 public String getIconName() {
297 return condition.getSpec().getIcon();
298 }
299
300 public String getName() {
301 return condition.getSpec().getName();
302 }
303
304
305
306}
307
308
309
310
static SettingsAPI getSettings()
Definition Global.java:57
static boolean CODEX_TOOLTIP_MODE
Definition Global.java:15
static SectorAPI getSector()
Definition Global.java:65
void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded)
static String ucFirst(String str)
Definition Misc.java:559
static Color getHighlightColor()
Definition Misc.java:792
List< FleetMemberAPI > getMembersListCopy()
void setHighlight(int start, int end)
void setHighlightColor(Color color)
void setHighlightColors(Color ... colors)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)