Starsector API
Loading...
Searching...
No Matches
TechMining.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.econ.impl;
2
3import java.awt.Color;
4import java.util.ArrayList;
5import java.util.List;
6import java.util.Random;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CargoAPI;
10import com.fs.starfarer.api.campaign.CargoStackAPI;
11import com.fs.starfarer.api.campaign.FactionAPI;
12import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
13import com.fs.starfarer.api.campaign.econ.MarketAPI;
14import com.fs.starfarer.api.campaign.econ.MarketImmigrationModifier;
15import com.fs.starfarer.api.campaign.impl.items.BlueprintProviderItem;
16import com.fs.starfarer.api.campaign.impl.items.ModSpecItemPlugin;
17import com.fs.starfarer.api.campaign.rules.MemoryAPI;
18import com.fs.starfarer.api.impl.campaign.ids.Conditions;
19import com.fs.starfarer.api.impl.campaign.ids.Factions;
20import com.fs.starfarer.api.impl.campaign.ids.Stats;
21import com.fs.starfarer.api.impl.campaign.population.PopulationComposition;
22import com.fs.starfarer.api.impl.campaign.procgen.SalvageEntityGenDataSpec.DropData;
23import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.SalvageEntity;
24import com.fs.starfarer.api.ui.TooltipMakerAPI;
25import com.fs.starfarer.api.util.Misc;
26
27
28public class TechMining extends BaseIndustry implements MarketImmigrationModifier {
29
30 public static final String TECH_MINING_MULT = "$core_techMiningMult";
31
32 public static float ALPHA_CORE_FINDS_BONUS = 0.25f;
33 public static float IMPROVE_FINDS_BONUS = 0.25f;
34
35 public void apply() {
36 super.apply(false);
37
38 int size = market.getSize();
39
40 int max = 0;
41 if (market.hasCondition(Conditions.RUINS_VAST)) {
42 //max = 7;
43 max = 4;
44 } else if (market.hasCondition(Conditions.RUINS_EXTENSIVE)) {
45 //max = 6;
46 max = 3;
47 } else if (market.hasCondition(Conditions.RUINS_WIDESPREAD)) {
48 //max = 5;
49 max = 2;
50 } else if (market.hasCondition(Conditions.RUINS_SCATTERED)) {
51 //max = 4;
52 max = 1;
53 }
54
55 size = Math.min(size, max);
56
58
59// supply(Commodities.METALS, size + 2);
60// supply(Commodities.HEAVY_MACHINERY, size);
61// supply(Commodities.FUEL, size);
62// supply(Commodities.SUPPLIES, size);
63
64// supply(Commodities.HAND_WEAPONS, size);
65// supply(Commodities.RARE_METALS, size - 2);
66// supply(Commodities.VOLATILES, size - 2);
67
68 if (!isFunctional()) {
69 supply.clear();
70 }
71
72 market.addTransientImmigrationModifier(this);
73 }
74
75
76 @Override
77 public void unapply() {
78 market.removeTransientImmigrationModifier(this);
79 }
80
81
82 @Override
83 public boolean isAvailableToBuild() {
84 if (!super.isAvailableToBuild()) return false;
85 if (market.hasCondition(Conditions.RUINS_VAST) ||
86 market.hasCondition(Conditions.RUINS_EXTENSIVE) ||
87 market.hasCondition(Conditions.RUINS_WIDESPREAD) ||
88 market.hasCondition(Conditions.RUINS_SCATTERED)) {
89 return true;
90 }
91 return false;
92 }
93
94 @Override
95 public String getUnavailableReason() {
96 if (!super.isAvailableToBuild()) return super.getUnavailableReason();
97 return "Requires ruins";
98 }
99
100
101 public void modifyIncoming(MarketAPI market, PopulationComposition incoming) {
102 incoming.add(Factions.TRITACHYON, 10f);
103 }
104
105 public float getPatherInterest() {
106 float base = 1f;
107 if (market.hasCondition(Conditions.RUINS_VAST)) {
108 base = 8;
109 } else if (market.hasCondition(Conditions.RUINS_EXTENSIVE)) {
110 base = 6;
111 } else if (market.hasCondition(Conditions.RUINS_WIDESPREAD)) {
112 base = 4;
113 } else if (market.hasCondition(Conditions.RUINS_SCATTERED)) {
114 base = 2;
115 }
116 return base + super.getPatherInterest();
117 }
118
119
120 protected boolean hasPostDemandSection(boolean hasDemand, IndustryTooltipMode mode) {
121 return true;
122 }
123
124 @Override
125 protected void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode) {
126 float opad = 10f;
127 tooltip.addPara("In addition to extracting basic resources, " +
128 "there's also a chance to find blueprints and other rare items. Anything " +
129 "found will be delivered to the designated production gathering point.", opad);
130
131 boolean hasRuins = true;
132 if (market.hasCondition(Conditions.RUINS_VAST)) {
133 tooltip.addPara("The vast ruins here offer incredible potential for valuable finds.", opad);
134 } else if (market.hasCondition(Conditions.RUINS_EXTENSIVE)) {
135 tooltip.addPara("The extensive ruins here offer the opportunity for valuable finds.", opad);
136 } else if (market.hasCondition(Conditions.RUINS_WIDESPREAD)) {
137 tooltip.addPara("The widespread ruins here offer a solid chance of finding something valuable, given time.", opad);
138 } else if (market.hasCondition(Conditions.RUINS_SCATTERED)) {
139 tooltip.addPara("The scattered ruins here offer only a slight chance of finding something valuable, though one never knows what might be located given enough time.", opad);
140 } else {
141 hasRuins = false;
142 }
143
144 if (hasRuins) {
145 float mult = getTechMiningMult();
146 if (mult >= .9f) {
147 tooltip.addPara("These ruins are largely untapped.", opad);
148 } else if (mult >= .5f) {
149 tooltip.addPara("These ruins have been stripped of easy pickings, but the more difficult areas remain, filled with promise.", opad);
150 } else if (mult >= 0.25f) {
151 tooltip.addPara("These ruins have been combed through, though the chance for a few new finds still remains.", opad);
152 } else {
153 tooltip.addPara("These ruins have been comprehensively combed over multiple times, and there is little chance of a new valuable find.", opad);
154 }
155 }
156 // add something re: size of ruins and chance to find stuff
157
158 }
159
160 protected float getEffectivenessMult() {
161 float mult = market.getStats().getDynamic().getStat(Stats.TECH_MINING_MULT).getModifiedValue();
162 return mult;
163 }
164
165 public float getTechMiningMult() {
166
167 MemoryAPI mem = market.getMemoryWithoutUpdate();
168 if (mem.contains(TECH_MINING_MULT)) {
169 return mem.getFloat(TECH_MINING_MULT);
170 }
171 mem.set(TECH_MINING_MULT, 1f);
172 return 1f;
173 }
174
175 public void setTechMiningMult(float value) {
176 MemoryAPI mem = market.getMemoryWithoutUpdate();
177 mem.set(TECH_MINING_MULT, value);
178 }
179
183
184 public static float getTechMiningRuinSizeModifier(MarketAPI market) {
185 float mod = 0f;
186 if (market.hasCondition(Conditions.RUINS_VAST)) {
187 mod = 1;
188 } else if (market.hasCondition(Conditions.RUINS_EXTENSIVE)) {
189 mod = 0.6f;
190 } else if (market.hasCondition(Conditions.RUINS_WIDESPREAD)) {
191 mod = 0.35f;
192 } else if (market.hasCondition(Conditions.RUINS_SCATTERED)) {
193 mod = 0.2f;
194 }
195 return mod;
196 }
197
198 public CargoAPI generateCargoForGatheringPoint(Random random) {
199 if (!isFunctional()) return null;
200
201 float mult = getTechMiningMult();
202 float decay = Global.getSettings().getFloat("techMiningDecay");
203 float base = getTechMiningRuinSizeModifier();
204
205 setTechMiningMult(mult * decay);
206
207 base *= getEffectivenessMult();
208
209
210 List<DropData> dropRandom = new ArrayList<DropData>();
211 List<DropData> dropValue = new ArrayList<DropData>();
212
213 DropData d = new DropData();
214 d.chances = 1;
215 d.group = "blueprints_low";
216 //d.addCustom("item_:{tags:[single_bp], p:{tags:[rare_bp]}}", 1f);
217 dropRandom.add(d);
218
219 d = new DropData();
220 d.chances = 1;
221 d.group = "rare_tech_low";
222 d.valueMult = 0.1f;
223 dropRandom.add(d);
224
225 d = new DropData();
226 d.chances = 1;
227 d.group = "ai_cores3";
228 //d.valueMult = 0.1f; // already a high chance to get nothing due to group setup, so don't reduce further
229 dropRandom.add(d);
230
231 d = new DropData();
232 d.chances = 1;
233 d.group = "any_hullmod_low";
234 dropRandom.add(d);
235
236 d = new DropData();
237 d.chances = 5;
238 d.group = "weapons2";
239 dropRandom.add(d);
240
241 d = new DropData();
242 //d.chances = 100;
243 d.group = "basic";
244 d.value = 10000;
245 dropValue.add(d);
246
247 if (mult >= 1) {
248 float num = base * (5f + random.nextFloat() * 2f);
249 if (num < 1) num = 1;
250
251 d = new DropData();
252 d.chances = (int) Math.round(num);
253 d.group = "techmining_first_find";
254 dropRandom.add(d);
255 }
256
257 CargoAPI result = SalvageEntity.generateSalvage(random, 1f, 1f, base * mult, 1f, dropValue, dropRandom);
258
259 FactionAPI pf = Global.getSector().getPlayerFaction();
260 OUTER: for (CargoStackAPI stack : result.getStacksCopy()) {
261 if (stack.getPlugin() instanceof BlueprintProviderItem) {
262 BlueprintProviderItem bp = (BlueprintProviderItem) stack.getPlugin();
263 List<String> list = bp.getProvidedShips();
264 if (list != null) {
265 for (String id : list) {
266 if (!pf.knowsShip(id)) continue OUTER;
267 }
268 }
269
270 list = bp.getProvidedWeapons();
271 if (list != null) {
272 for (String id : list) {
273 if (!pf.knowsWeapon(id)) continue OUTER;
274 }
275 }
276
277 list = bp.getProvidedFighters();
278 if (list != null) {
279 for (String id : list) {
280 if (!pf.knowsFighter(id)) continue OUTER;
281 }
282 }
283
284 list = bp.getProvidedIndustries();
285 if (list != null) {
286 for (String id : list) {
287 if (!pf.knowsIndustry(id)) continue OUTER;
288 }
289 }
290 result.removeStack(stack);
291 } else if (stack.getPlugin() instanceof ModSpecItemPlugin) {
292 ModSpecItemPlugin mod = (ModSpecItemPlugin) stack.getPlugin();
293 if (!pf.knowsHullMod(mod.getModId())) continue OUTER;
294 result.removeStack(stack);
295 }
296 }
297
298 //result.addMothballedShip(FleetMemberType.SHIP, "hermes_d_Hull", null);
299
300 return result;
301 }
302
303
304
305 @Override
306 protected void applyAlphaCoreModifiers() {
307 market.getStats().getDynamic().getStat(Stats.TECH_MINING_MULT).modifyMult(getModId(0), 1f + ALPHA_CORE_FINDS_BONUS);
308 }
309
310 @Override
311 protected void applyNoAICoreModifiers() {
312 market.getStats().getDynamic().getStat(Stats.TECH_MINING_MULT).unmodifyMult(getModId(0));
313 }
314
315 @Override
317 demandReduction.modifyFlat(getModId(0), DEMAND_REDUCTION, "Alpha core");
318 }
319
320 protected void addAlphaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode) {
321 float opad = 10f;
322 Color highlight = Misc.getHighlightColor();
323
324 String pre = "Alpha-level AI core currently assigned. ";
325 if (mode == AICoreDescriptionMode.MANAGE_CORE_DIALOG_LIST || mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
326 pre = "Alpha-level AI core. ";
327 }
328 float a = ALPHA_CORE_FINDS_BONUS;
329 String aStr = "" + (int)Math.round(a * 100f) + "%";
330
331 if (mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
332 CommoditySpecAPI coreSpec = Global.getSettings().getCommoditySpec(aiCoreId);
333 TooltipMakerAPI text = tooltip.beginImageWithText(coreSpec.getIconName(), 48);
334 text.addPara(pre + "Reduces upkeep cost by %s. Reduces demand by %s unit. " +
335 "Increases finds by %s.", 0f, highlight,
336 "" + (int)((1f - UPKEEP_MULT) * 100f) + "%", "" + DEMAND_REDUCTION,
337 aStr);
338 tooltip.addImageWithText(opad);
339 return;
340 }
341
342 tooltip.addPara(pre + "Reduces upkeep cost by %s. Reduces demand by %s unit. " +
343 "Increases finds by %s.", opad, highlight,
344 "" + (int)((1f - UPKEEP_MULT) * 100f) + "%", "" + DEMAND_REDUCTION,
345 aStr);
346
347 }
348
349 @Override
350 public boolean canImprove() {
351 return true;
352 }
353
354 protected void applyImproveModifiers() {
355 if (isImproved()) {
356 market.getStats().getDynamic().getStat(Stats.TECH_MINING_MULT).modifyMult(getModId(1), 1f + IMPROVE_FINDS_BONUS);
357 } else {
358 market.getStats().getDynamic().getStat(Stats.TECH_MINING_MULT).unmodifyMult(getModId(1));
359 }
360 }
361
362 public void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode) {
363 float opad = 10f;
364 Color highlight = Misc.getHighlightColor();
365
366 float a = IMPROVE_FINDS_BONUS;
367 String aStr = "" + (int)Math.round(a * 100f) + "%";
368
369 if (mode == ImprovementDescriptionMode.INDUSTRY_TOOLTIP) {
370 info.addPara("Finds increased by %s.", 0f, highlight, aStr);
371 } else {
372 info.addPara("Increases finds by %s.", 0f, highlight, aStr);
373 }
374
375 info.addSpacer(opad);
376 super.addImproveDesc(info, mode);
377 }
378}
379
380
381
382
383
384
385
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
Map< String, MutableCommodityQuantity > supply
void modifyIncoming(MarketAPI market, PopulationComposition incoming)
static float getTechMiningRuinSizeModifier(MarketAPI market)
void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode)
void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode)
void addAlphaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode)
boolean hasPostDemandSection(boolean hasDemand, IndustryTooltipMode mode)
CommoditySpecAPI getCommoditySpec(String commodityId)