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