Starsector API
Loading...
Searching...
No Matches
ResourceDepositsCondition.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.econ;
2
3import java.util.HashMap;
4import java.util.HashSet;
5import java.util.Map;
6import java.util.Set;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
10import com.fs.starfarer.api.campaign.econ.Industry;
11import com.fs.starfarer.api.campaign.econ.MarketAPI;
12import com.fs.starfarer.api.campaign.econ.MarketImmigrationModifier;
13import com.fs.starfarer.api.impl.campaign.econ.impl.BaseIndustry;
14import com.fs.starfarer.api.impl.campaign.ids.Commodities;
15import com.fs.starfarer.api.impl.campaign.ids.Conditions;
16import com.fs.starfarer.api.impl.campaign.ids.Factions;
17import com.fs.starfarer.api.impl.campaign.ids.Industries;
18import com.fs.starfarer.api.impl.campaign.population.PopulationComposition;
19import com.fs.starfarer.api.loading.IndustrySpecAPI;
20import com.fs.starfarer.api.ui.TooltipMakerAPI;
21import com.fs.starfarer.api.util.Misc;
22
23
25
26 public static Map<String, String> COMMODITY = new HashMap<String, String>();
27 public static Map<String, Integer> MODIFIER = new HashMap<String, Integer>();
28 public static Map<String, String> INDUSTRY = new HashMap<String, String>();
29 public static Map<String, Integer> BASE_MODIFIER = new HashMap<String, Integer>();
30 public static Set<String> BASE_ZERO = new HashSet<String>();
31 static {
37
43
48
53
58
60
62 //COMMODITY.put(Conditions.POLLUTION, Commodities.FOOD);
63
64
70
71
77
82
87
92
94 //MODIFIER.put(Conditions.POLLUTION, -2);
96
97
102
105
111
114 }
115
116// public static int getProduction(MarketAPI market, String industryId, String commodityId) {
117// for (MarketConditionAPI mc : market.getConditions()) {
118// String currCommodity = COMMODITY.get(mc.getId());
119// if (currCommodity == null) continue;
120// if (!currCommodity.equals(commodityId)) continue;
121//
122// Integer mod = MODIFIER.get(mc.getId());
123// if (mod == null) continue;
124//
125// Integer baseMod = BASE_MODIFIER.get(currCommodity);
126// if (baseMod == null) continue;
127//
128// String currIndustry = INDUSTRY.get(currCommodity);
129// if (currIndustry == null) continue;
130// if (!industryId.equals(currIndustry)) {
131// if (Industries.FARMING.equals(currIndustry)) {
132// if (!industryId.equals(Industries.AQUACULTURE)) {
133// continue;
134// }
135// } else {
136// continue;
137// }
138// }
139//
140// int size = market.getSize();
141// if (BASE_ZERO.contains(commodityId)) {
142// size = 0;
143// }
144//
145// int base = size + baseMod;
146//
147// return base + mod;
148// }
149// return 0;
150// }
151
152
153
154 public void apply(String id) {
155 super.apply(id);
156
157 String commodityId = COMMODITY.get(condition.getId());
158 if (commodityId == null) return;
159
160// if (commodityId.equals(Commodities.LOBSTER)) {
161// System.out.println("ewfwefwe");
162// }
163
164 Integer mod = MODIFIER.get(condition.getId());
165 if (mod == null) return;
166
167 Integer baseMod = BASE_MODIFIER.get(commodityId);
168 if (baseMod == null) return;
169
170 String industryId = INDUSTRY.get(commodityId);
171 if (industryId == null) return;
172
173 Industry industry = market.getIndustry(industryId);
174 if (industry == null) {
175 if (Industries.FARMING.equals(industryId)) {
176 industryId = Industries.AQUACULTURE;
177 industry = market.getIndustry(industryId);
178 }
179 if (industry == null) return;
180 }
181
182 int size = market.getSize();
183 if (BASE_ZERO.contains(commodityId)) {
184 size = 0;
185 }
186
187 int base = size + baseMod;
188
189 if (industry.isFunctional()) {
190// industry.getSupply(commodityId).getQuantity().modifyFlat(id + "_0", base, BaseIndustry.BASE_VALUE_TEXT);
191// industry.getSupply(commodityId).getQuantity().modifyFlat(id + "_1", mod, Misc.ucFirst(condition.getName().toLowerCase()));
192
193 industry.supply(id + "_0", commodityId, base, BaseIndustry.BASE_VALUE_TEXT);
194 industry.supply(id + "_1", commodityId, mod, Misc.ucFirst(condition.getName().toLowerCase()));
195 } else {
196 industry.getSupply(commodityId).getQuantity().unmodifyFlat(id + "_0");
197 industry.getSupply(commodityId).getQuantity().unmodifyFlat(id + "_1");
198 }
199
200 if (Commodities.FOOD.equals(commodityId)) {
202 }
203
204// uncomment to make farming provide organics
205// also need to adjust Farming to apply machinery deficit penalty
206// if ((Industries.FARMING.equals(industryId) ||
207// Industries.AQUACULTURE.equals(industryId) && Commodities.FOOD.equals(commodityId))) {
208// industry.getSupply(Commodities.ORGANICS).getQuantity().modifyFlat(id + "_0", size - 2, BaseIndustry.BASE_VALUE_TEXT);
209// industry.getSupply(Commodities.ORGANICS).getQuantity().modifyFlat(id + "_1", mod, Misc.ucFirst(condition.getName().toLowerCase()));
210// }
211 }
212
213 public void unapply(String id) {
214 super.unapply(id);
216 }
217
218 @Override
219 public Map<String, String> getTokenReplacements() {
220 if (true) return super.getTokenReplacements();
221
222 Map<String, String> map = super.getTokenReplacements();
223
224 String commodityId = COMMODITY.get(condition.getId());
225 if (commodityId == null) return map;
226
227 Integer mod = MODIFIER.get(condition.getId());
228 if (mod == null) return map;
229
231
232 String str = "" + mod;
233 if (mod > 0) str = "+" + mod;
234 if (mod == 0) {
235 map.put("$resourceModText", "No bonuses or penalties to " + spec.getName().toLowerCase() + " production.");
236 } else {
237 map.put("$resourceModText", "" + str + " to " + spec.getName().toLowerCase() + " production.");
238 }
239
240 //map.put("$resourceMod", Misc.ucFirst(spec.getName().toLowerCase()) )
241
242
243 return map;
244 }
245
246 @Override
247 public String[] getHighlights() {
248 if (true) return super.getHighlights();
249
250 String commodityId = COMMODITY.get(condition.getId());
251 if (commodityId == null) return super.getHighlights();
252
253 Integer mod = MODIFIER.get(condition.getId());
254 if (mod == null) return super.getHighlights();
255
256 String str = "" + mod;
257 if (mod > 0) str = "+" + mod;
258
259 if (mod == 0) {
260 return super.getHighlights();
261 }
262
263 return new String[] {str};
264 }
265
266 protected void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded) {
267 super.createTooltipAfterDescription(tooltip, expanded);
268
269 String commodityId = COMMODITY.get(condition.getId());
270 if (commodityId != null) {
271
272// boolean hasHazard = false;
273// Object test = Global.getSettings().getSpec(ConditionGenDataSpec.class, condition.getId(), true);
274// if (test instanceof ConditionGenDataSpec) {
275// ConditionGenDataSpec spec = (ConditionGenDataSpec) test;
276// float hazard = spec.getHazard();
277// //hazard = 0.25f;
278// hasHazard = hazard != 0;
279// }
280
281 Integer mod = MODIFIER.get(condition.getId());
282 if (mod != null) {
284
285 String industryId = INDUSTRY.get(commodityId);
286 if (commodityId.equals(Commodities.FOOD) && condition.getId().equals(Conditions.WATER_SURFACE) &&
287 industryId.equals(Industries.FARMING)) {
288 industryId = Industries.AQUACULTURE;
289 } else if (commodityId.equals(Commodities.LOBSTER) && condition.getId().equals(Conditions.VOLTURNIAN_LOBSTER_PENS) &&
290 industryId.equals(Industries.FARMING)) {
291 industryId = Industries.AQUACULTURE;
292 }
294
295
296 String str = "" + mod;
297 if (mod > 0) str = "+" + mod;
298 String text = "";
299 if (mod == 0) {
300 text = "No bonuses or penalties to " + spec.getName().toLowerCase() + " production (" + ind.getName() + ")";
301 } else {
302 //text = "" + str + " to " + spec.getName().toLowerCase() + " production.";
303 text = "" + str + " " + spec.getName().toLowerCase() + " production (" + ind.getName() + ")";
304 }
305 float pad = 10f;
306 tooltip.addPara(text, pad, Misc.getHighlightColor(), str);
307 }
308 }
309 }
310
311
313 float qty = 0f;
314 if (Conditions.FARMLAND_POOR.equals(condition.getId())) {
315 qty = 5f;
316 } else if (Conditions.FARMLAND_ADEQUATE.equals(condition.getId())) {
317 qty = 10f;
318 } else if (Conditions.FARMLAND_RICH.equals(condition.getId())) {
319 qty = 20f;
320 } else if (Conditions.FARMLAND_BOUNTIFUL.equals(condition.getId())) {
321 qty = 30f;
322 } else if (Conditions.WATER_SURFACE.equals(condition.getId())) {
323 qty = 10f;
324 }
325 if (qty > 0) {
326 incoming.add(Factions.LUDDIC_CHURCH, qty);
327 }
328 }
329
330
331
332
333}
334
335
336
337
static SettingsAPI getSettings()
Definition Global.java:57
void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded)
void modifyIncoming(MarketAPI market, PopulationComposition incoming)
static String ucFirst(String str)
Definition Misc.java:559
static Color getHighlightColor()
Definition Misc.java:792
IndustrySpecAPI getIndustrySpec(String industryId)
CommoditySpecAPI getCommoditySpec(String commodityId)
void supply(String modId, String commodityId, int quantity, String desc)
MutableCommodityQuantity getSupply(String id)
void removeImmigrationModifier(MarketImmigrationModifier mod)
void addImmigrationModifier(MarketImmigrationModifier mod)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)