Starsector API
Loading...
Searching...
No Matches
PopulationAndInfrastructure.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.econ.impl;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import java.awt.Color;
7
8import org.json.JSONArray;
9import org.json.JSONException;
10import org.lwjgl.util.vector.Vector2f;
11
12import com.fs.starfarer.api.EveryFrameScript;
13import com.fs.starfarer.api.Global;
14import com.fs.starfarer.api.campaign.FactionDoctrineAPI;
15import com.fs.starfarer.api.campaign.SectorEntityToken;
16import com.fs.starfarer.api.campaign.SpecialItemData;
17import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin;
18import com.fs.starfarer.api.campaign.econ.CommodityMarketDataAPI;
19import com.fs.starfarer.api.campaign.econ.CommodityOnMarketAPI;
20import com.fs.starfarer.api.campaign.econ.Industry;
21import com.fs.starfarer.api.campaign.econ.MarketAPI;
22import com.fs.starfarer.api.campaign.econ.MarketImmigrationModifier;
23import com.fs.starfarer.api.campaign.listeners.ColonyOtherFactorsListener;
24import com.fs.starfarer.api.characters.MarketConditionSpecAPI;
25import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
26import com.fs.starfarer.api.combat.MutableStat;
27import com.fs.starfarer.api.combat.MutableStat.StatMod;
28import com.fs.starfarer.api.impl.campaign.econ.CommRelayCondition;
29import com.fs.starfarer.api.impl.campaign.econ.impl.ConstructionQueue.ConstructionQueueItem;
30import com.fs.starfarer.api.impl.campaign.fleets.FleetFactoryV3;
31import com.fs.starfarer.api.impl.campaign.ids.Commodities;
32import com.fs.starfarer.api.impl.campaign.ids.Conditions;
33import com.fs.starfarer.api.impl.campaign.ids.Entities;
34import com.fs.starfarer.api.impl.campaign.ids.Factions;
35import com.fs.starfarer.api.impl.campaign.ids.Industries;
36import com.fs.starfarer.api.impl.campaign.ids.Items;
37import com.fs.starfarer.api.impl.campaign.ids.Stats;
38import com.fs.starfarer.api.impl.campaign.intel.misc.HypershuntIntel;
39import com.fs.starfarer.api.impl.campaign.population.PopulationComposition;
40import com.fs.starfarer.api.impl.campaign.procgen.themes.BaseThemeGenerator;
41import com.fs.starfarer.api.impl.campaign.procgen.themes.BaseThemeGenerator.AddedEntity;
42import com.fs.starfarer.api.impl.campaign.procgen.themes.BaseThemeGenerator.EntityLocation;
43import com.fs.starfarer.api.loading.IndustrySpecAPI;
44import com.fs.starfarer.api.ui.TooltipMakerAPI;
45import com.fs.starfarer.api.ui.TooltipMakerAPI.StatModValueGetter;
46import com.fs.starfarer.api.util.Misc;
47import com.fs.starfarer.api.util.Pair;
48
49
51
52 public static float OFFICER_BASE_PROB = Global.getSettings().getFloat("officerBaseProb");
53 public static float OFFICER_PROB_PER_SIZE = Global.getSettings().getFloat("officerProbPerColonySize");
54 public static float OFFICER_ADDITIONAL_BASE_PROB = Global.getSettings().getFloat("officerAdditionalBaseProb");
55 public static float OFFICER_BASE_MERC_PROB = Global.getSettings().getFloat("officerBaseMercProb");
56 public static float ADMIN_BASE_PROB = Global.getSettings().getFloat("adminBaseProb");
57 public static float ADMIN_PROB_PER_SIZE = Global.getSettings().getFloat("adminProbPerColonySize");
58
59
60 //public static float IMPROVE_GROWTH_BONUS = 1f;
61 public static float IMPROVE_STABILITY_BONUS = 1f;
62
63 public static boolean HAZARD_INCREASES_DEFENSE = false;
64
65 public void apply() {
67
68// if (market.getId().equals("chicomoztoc")) {
69// System.out.println("wefwefwe");
70// }
71
72 super.apply(true);
73
74 int size = market.getSize();
75
76 demand(Commodities.FOOD, size);
77
79 demand(Commodities.ORGANICS, size - 1);
80 }
81
82 int luxuryThreshold = 3;
83
85 demand(Commodities.LUXURY_GOODS, size - luxuryThreshold);
86 demand(Commodities.DRUGS, size - 2);
87 demand(Commodities.ORGANS, size - 3);
88
89 demand(Commodities.SUPPLIES, Math.min(size, 3));
90
91 supply(Commodities.CREW, size - 3);
92 supply(Commodities.DRUGS, size - 4);
93 supply(Commodities.ORGANS, size - 5);
94
95
97 if (deficit.two <= 0) {
98 market.getStability().modifyFlat(getModId(0), 1, "Domestic goods demand met");
99 } else {
101 }
102
104 if (deficit.two <= 0 && size > luxuryThreshold) {
105 market.getStability().modifyFlat(getModId(1), 1, "Luxury goods demand met");
106 } else {
108 }
109
110 deficit = getMaxDeficit(Commodities.FOOD);
113 }
114 if (deficit.two > 0) {
115 market.getStability().modifyFlat(getModId(2), -deficit.two, getDeficitText(deficit.one));
116 } else {
118 }
119
120
121 boolean spaceportFirstInQueue = false;
122 for (ConstructionQueueItem item : market.getConstructionQueue().getItems()) {
125 spaceportFirstInQueue = true;
126 }
127 break;
128 }
129 if (spaceportFirstInQueue && Misc.getCurrentlyBeingConstructed(market) != null) {
130 spaceportFirstInQueue = false;
131 }
132 if (!market.hasSpaceport() && !spaceportFirstInQueue) {
133 float accessibilityNoSpaceport = Global.getSettings().getFloat("accessibilityNoSpaceport");
134 market.getAccessibilityMod().modifyFlat(getModId(0), accessibilityNoSpaceport, "No spaceport");
135 }
136
137 float sizeBonus = getAccessibilityBonus(size);
138 if (sizeBonus > 0) {
139 market.getAccessibilityMod().modifyFlat(getModId(1), sizeBonus, "Colony size");
140 }
141
142
143
144
145 float stability = market.getPrevStability();
146 float stabilityQualityMod = FleetFactoryV3.getShipQualityModForStability(stability);
147 float doctrineQualityMod = market.getFaction().getDoctrine().getShipQualityContribution();
148
150 "Stability");
151
153 Misc.ucFirst(market.getFaction().getEntityNamePrefix()) + " fleet doctrine");
154
155 //float stabilityDefenseMult = 0.5f + stability / 10f;
156 float stabilityDefenseMult = 0.25f + stability / 10f * 0.75f;
158 stabilityDefenseMult, "Stability");
159
160 float baseDef = getBaseGroundDefenses(market.getSize());
162 baseDef, "Base value for a size " + market.getSize() + " colony");
163
164
165 //if (market.getHazardValue() > 1f) {
168 Math.max(market.getHazardValue(), 1f), "Colony hazard rating");
169 }
170 //}
171
173
174// if (market.isPlayerOwned()) {
175// System.out.println("wfwefwef");
176// }
178 float doctrineShipsMult = FleetFactoryV3.getDoctrineNumShipsMult(doctrine.getNumShips());
179 float marketSizeShipsMult = FleetFactoryV3.getNumShipsMultForMarketSize(market.getSize());
180 float deficitShipsMult = FleetFactoryV3.getShipDeficitFleetSizeMult(market);
181 float stabilityShipsMult = FleetFactoryV3.getNumShipsMultForStability(stability);
182
184 "Colony size");
185
187 Misc.ucFirst(market.getFaction().getEntityNamePrefix()) + " fleet doctrine");
188
189 if (deficitShipsMult != 1f) {
192 } else {
194 getDeficitText(Commodities.SHIPS).replaceAll("shortage", "demand met"));
195 }
196
198 "Stability");
199
200
201 // chance of spawning officers and admins; some industries further modify this
204 OFFICER_PROB_PER_SIZE * Math.max(0, market.getSize() - 3));
205
208
211 ADMIN_PROB_PER_SIZE * Math.max(0, market.getSize() - 3));
212
214
216
217
218
219// // if there's no queued spaceport, setHasSpaceport() is called by Spaceport (if it's present at the market)
220// boolean spaceportFirstInQueue = false;
221// for (ConstructionQueueItem item : market.getConstructionQueue().getItems()) {
222// IndustrySpecAPI spec = Global.getSettings().getIndustrySpec(item.id);
223// if (spec.hasTag(Industries.TAG_SPACEPORT)) {
224// market.setHasSpaceport(true);
225// market.getMemoryWithoutUpdate().set("$hadQueuedSpaceport", true);
226// spaceportFirstInQueue = true;
227// }
228// break;
229// }
230// if (!spaceportFirstInQueue && market.hasSpaceport() && market.getMemoryWithoutUpdate().is("$hadQueuedSpaceport", true)) {
231// market.getMemoryWithoutUpdate().unset("$hadQueuedSpaceport");
232// boolean hasSpaceport = false;
233// for (Industry ind : market.getIndustries()) {
234// if (ind.getSpec().hasTag(Industries.TAG_SPACEPORT)) {
235// hasSpaceport = true;
236// break;
237// }
238// }
239// if (!hasSpaceport) {
240// market.setHasSpaceport(false);
241// }
242// }
243
244 }
245
246
247 public static float getAccessibilityBonus(int marketSize) {
248 if (marketSize <= 4) return 0f;
249 if (marketSize == 5) return 0.1f;
250 if (marketSize == 6) return 0.15f;
251 if (marketSize == 7) return 0.2f;
252 if (marketSize == 8) return 0.25f;
253 return 0.3f;
254 }
255 public static float getBaseGroundDefenses(int marketSize) {
256 if (marketSize <= 1) return 10;
257 if (marketSize <= 2) return 20;
258 if (marketSize <= 3) return 50;
259
260 return (marketSize - 3) * 100;
261 }
262
263 @Override
264 public void unapply() {
265 super.unapply();
266
270
273
276
281 }
282
284
289
296
298
300 }
301
302 protected boolean hasPostDemandSection(boolean hasDemand, IndustryTooltipMode mode) {
303 return true;
304 }
305
306 @Override
307 protected void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode) {
308 if (mode != IndustryTooltipMode.NORMAL || isFunctional()) {
309
310 MutableStat stabilityMods = new MutableStat(0);
311
312 float total = 0;
313 for (StatMod mod : market.getStability().getFlatMods().values()) {
314 if (mod.source.startsWith(getModId())) {
315 stabilityMods.modifyFlat(mod.source, mod.value, mod.desc);
316 total += mod.value;
317 }
318 }
319
320 String totalStr = "+" + (int)Math.round(total);
321 Color h = Misc.getHighlightColor();
322 if (total < 0) {
323 totalStr = "" + (int)Math.round(total);
325 }
326 float opad = 10f;
327 float pad = 3f;
328 if (total >= 0) {
329 tooltip.addPara("Stability bonus: %s", opad, h, totalStr);
330 } else {
331 tooltip.addPara("Stability penalty: %s", opad, h, totalStr);
332 }
333 tooltip.addStatModGrid(400, 30, opad, pad, stabilityMods, new StatModValueGetter() {
334 public String getPercentValue(StatMod mod) {
335 return null;
336 }
337 public String getMultValue(StatMod mod) {
338 return null;
339 }
340 public Color getModColor(StatMod mod) {
341 if (mod.value < 0) return Misc.getNegativeHighlightColor();
342 return null;
343 }
344 public String getFlatValue(StatMod mod) {
345 return null;
346 }
347 });
348
349 /*
350 MutableStat qualityMods = new MutableStat(0);
351
352 total = 0;
353 for (StatMod mod : market.getStats().getDynamic().getMod(Stats.FLEET_QUALITY_MOD).getFlatBonuses().values()) {
354 if (mod.source.startsWith(getModId())) {
355 qualityMods.modifyFlat(mod.source, mod.value, mod.desc);
356 total += mod.value;
357 }
358 }
359
360 totalStr = "+" + (int)Math.round(total * 100f) + "%";
361 if (total < 0) {
362 totalStr = "" + (int)Math.round(total * 100f) + "%";
363 h = Misc.getNegativeHighlightColor();
364 }
365 if (total >= 0) {
366 tooltip.addPara("Ship quality bonus: %s", opad, h, totalStr);
367 } else {
368 tooltip.addPara("Ship quality penalty: %s", opad, h, totalStr);
369 }
370 tooltip.addStatModGrid(400, 50, opad, pad, qualityMods, new StatModValueGetter() {
371 public String getPercentValue(StatMod mod) {
372 return null;
373 }
374 public String getMultValue(StatMod mod) {
375 return null;
376 }
377 public Color getModColor(StatMod mod) {
378 if (mod.value < 0) return Misc.getNegativeHighlightColor();
379 return null;
380 }
381 public String getFlatValue(StatMod mod) {
382 String prefix = mod.value >= 0 ? "+" : "";
383 return prefix + (int)Math.round(mod.value * 100f) + "%";
384 }
385 });
386 */
387
388 }
389 }
390
391
392
393 @Override
394 public String getCurrentImage() {
395 float size = market.getSize();
396 if (size <= SIZE_FOR_SMALL_IMAGE) {
397 return Global.getSettings().getSpriteName("industry", "pop_low");
398 }
399 if (size >= SIZE_FOR_LARGE_IMAGE) {
400 return Global.getSettings().getSpriteName("industry", "pop_high");
401 }
402
403 return super.getCurrentImage();
404 }
405
406
407 public static float getIncomeStabilityMult(float stability) {
408 if (stability <= 5) {
409 return Math.max(0, stability / 5f);
410 }
411 return 1f;
412 //return 1f + (stability - 5f) * .1f;
413 }
414
415// public static float getUpkeepHazardMult(float hazard) {
416// float hazardMult = hazard;
417// float min = Global.getSettings().getFloat("minUpkeepMult");
418// if (hazardMult < min) hazardMult = min;
419// return hazardMult;
420// }
421 public static float getUpkeepHazardMult(float hazard) {
422 //float hazardMult = 1f + hazard;
423 float hazardMult = hazard;
424 float min = Global.getSettings().getFloat("minUpkeepMult");
425 if (hazardMult < min) hazardMult = min;
426 return hazardMult;
427 }
428
429
430 public static int getMismanagementPenalty() {
431 int outposts = 0;
433 if (!curr.isPlayerOwned()) continue;
434
435 if (curr.getAdmin().isPlayer()) {
436 outposts++;
437 }
438 }
439
441
442 int maxOutposts = stats.getOutpostNumber().getModifiedInt();
443
444 int overOutposts = outposts - maxOutposts;
445
446 //if (overOutposts < 0) overOutposts = 0;
447
448 int penaltyOrBonus = (int) (overOutposts * Misc.getOutpostPenalty());
449
450 return penaltyOrBonus;
451 }
452
453 public static void modifyStability2(Industry industry, MarketAPI market, String modId) {
455 market.getStability().modifyFlat("_" + modId + "_overmax", -Misc.OVER_MAX_INDUSTRIES_PENALTY, "Maximum number of industries exceeded");
456 } else {
457 market.getStability().unmodifyFlat("_" + modId + "_overmax");
458 }
459 }
460
467 public static void modifyUpkeepByHazardRating(MarketAPI market, String modId) {
469 }
470
471 public static void modifyStability(Industry industry, MarketAPI market, String modId) {
473
474 market.getStability().modifyFlat("_" + modId + "_ms", Global.getSettings().getFloat("stabilityBaseValue"), "Base value");
475
476 float inFactionSupply = 0f;
477 float totalDemand = 0f;
479 if (com.isNonEcon()) continue;
480
481 int d = com.getMaxDemand();
482 if (d <= 0) continue;
483
484 totalDemand += d;
485 CommodityMarketDataAPI cmd = com.getCommodityMarketData();
486 int inFaction = Math.max(Math.min(com.getMaxSupply(), com.getAvailable()),
487 Math.min(cmd.getMaxShipping(market, true), cmd.getMaxExport(market.getFactionId())));
488 if (inFaction > d) inFaction = d;
489 if (inFaction < d) inFaction = Math.max(Math.min(com.getMaxSupply(), com.getAvailable()), 0);
490
491 //CommoditySourceType source = cmd.getMarketShareData(market).getSource();;
492 //if (source != CommoditySourceType.GLOBAL) {
493 // inFactionSupply += Math.min(d - inFaction, com.getAvailable());
494 //}
495 inFactionSupply += Math.max(0, Math.min(inFaction, com.getAvailable()));
496 }
497
498 if (totalDemand > 0) {
499 float max = Global.getSettings().getFloat("upkeepReductionFromInFactionImports");
500 float f = inFactionSupply / totalDemand;
501 if (f < 0) f = 0;
502 if (f > 1) f = 1;
503 if (f > 0) {
504 float mult = Math.round(100f - (f * max * 100f)) / 100f;
505 String desc = "Demand supplied in-faction (" + (int)Math.round(f * 100f) + "%)";
506 if (f == 1f) desc = "All demand supplied in-faction";
507 market.getUpkeepMult().modifyMultAlways(modId + "ifi", mult, desc);
508 } else {
509 market.getUpkeepMult().modifyMultAlways(modId + "ifi", 1f, "All demand supplied out-of-faction; no upkeep reduction");
510 }
511 }
512
513
515 int penalty = getMismanagementPenalty();
516 if (penalty > 0) {
517 market.getStability().modifyFlat("_" + modId + "_mm", -penalty, "Mismanagement penalty");
518 } else if (penalty < 0) {
519 market.getStability().modifyFlat("_" + modId + "_mm", -penalty, "Management bonus");
520 } else {
521 market.getStability().unmodifyFlat("_" + modId + "_mm");
522 }
523 } else {
524 market.getStability().unmodifyFlat(modId + "_mm");
525 }
526
529 }
530 }
531
532
533 public static void unmodifyStability(MarketAPI market, String modId) {
536 market.getUpkeepMult().unmodifyMult(modId + "ifi");
537
539
540// for (int i = 0; i < 30; i++) {
541// market.getStability().unmodify(modId + i);
542// }
543 market.getStability().unmodifyFlat("_" + modId + "_mm");
544 market.getStability().unmodifyFlat("_" + modId + "_ms");
545 market.getStability().unmodifyFlat("_" + modId + "_overmax");
546
549 }
550
551 }
552
553
554
555 @Override
556 public boolean showShutDown() {
557 return false;
558 }
559
560 @Override
561 public String getCanNotShutDownReason() {
562 //return "Use \"Abandon Colony\" instead.";
563 return null;
564 }
565
566 @Override
567 public boolean canShutDown() {
568 return false;
569 }
570
571 @Override
572 protected String getDescriptionOverride() {
573 int size = market.getSize();
574 String cid = null;
575 if (size >= 1 && size <= 9) {
576 cid = "population_" + size;
578 if (mcs != null) {
579 return spec.getDesc() + "\n\n" + mcs.getDesc().replaceAll("\\$marketName", market.getName())
580 .replaceAll("\\$MarketName", market.getName());
581 }
582 }
583 return super.getDescriptionOverride();
584 }
585
587// float f = buildProgress / spec.getBuildTime();
588// return "" + (int) Math.round(f * 100f) + "%";
589 if (isUpgrading()) {
590 //return "" + (int) Math.round(Misc.getMarketSizeProgress(market) * 100f) + "%";
591 return "total growth: " + Misc.getRoundedValue(Misc.getMarketSizeProgress(market) * 100f) + "%";
592 }
593
594 return super.getBuildOrUpgradeProgressText();
595 }
596
597 @Override
599 if (!super.isBuilding() && market.getSize() < Misc.getMaxMarketSize(market)) {
601 }
602 return super.getBuildOrUpgradeProgress();
603 }
604
605 @Override
606 public boolean isBuilding() {
607 if (!super.isBuilding() && market.getSize() < Misc.getMaxMarketSize(market) && getBuildOrUpgradeProgress() > 0) return true;
608
609 return super.isBuilding();
610 }
611
612 @Override
613 public boolean isUpgrading() {
614 if (!super.isBuilding() && market.getSize() < Misc.getMaxMarketSize(market)) return true;
615
616 return super.isUpgrading();
617 }
618
619
620
622 float patherLevel = 0;
623 for (Industry curr : market.getIndustries()) {
624 patherLevel += getAICoreImpact(curr.getAICoreId());
625 }
626
627 String adminCoreId = market.getAdmin().getAICoreId();
628 if (adminCoreId != null) {
629 patherLevel += 10f * getAICoreImpact(adminCoreId);
630 }
631
632 List<String> targeted = new ArrayList<String>();
633 targeted.add(Industries.TECHMINING);
634 targeted.add(Industries.HEAVYINDUSTRY);
635 targeted.add(Industries.FUELPROD);
636 targeted.add(Industries.STARFORTRESS);
637
638 for (String curr : targeted) {
639 if (market.hasIndustry(curr)) {
640 patherLevel += 10f;
641 }
642 }
643
644 if (patherLevel > 0) {
645 incoming.add(Factions.LUDDIC_PATH, patherLevel * 0.2f);
646 }
647
648// if (isImproved()) {
649// incoming.getWeight().modifyFlat(getModId(2), (int)Math.round(market.getSize() * IMPROVE_GROWTH_BONUS),
650// getImprovementsDescForModifiers() + " (" + getNameForModifier() + ")");
651// }
652 }
653
654 private float getAICoreImpact(String coreId) {
655 if (Commodities.ALPHA_CORE.equals(coreId)) return 10f;
656 if (Commodities.BETA_CORE.equals(coreId)) return 4f;
657 if (Commodities.GAMMA_CORE.equals(coreId)) return 1f;
658 return 0f;
659 }
660
661 public boolean canBeDisrupted() {
662 return false;
663 }
664
665 public int getMaxIndustries() {
667 }
668
669 public static int [] MAX_IND = null;
670 public static int getMaxIndustries(int size) {
671 if (MAX_IND == null) {
672 try {
673 MAX_IND = new int [10];
674 JSONArray a = Global.getSettings().getJSONArray("maxIndustries");
675 for (int i = 0; i < MAX_IND.length; i++) {
676 MAX_IND[i] = a.getInt(i);
677 }
678 } catch (JSONException e) {
679 throw new RuntimeException(e);
680 }
681 }
682 size--;
683 if (size < 0) size = 0;
684 if (size > 9) size = 9;
685 return MAX_IND[size];
686// if (size <= 3) return 1;
687// if (size <= 5) return 2;
688// if (size <= 7) return 3;
689// return 4;
690 }
691
692// @Override
693// public boolean canImprove() {
694// return true;
695// }
696//
697// public void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode) {
698// float opad = 10f;
699// Color highlight = Misc.getHighlightColor();
700//
701//
702// String str = "" + (int)Math.round(market.getSize() * IMPROVE_GROWTH_BONUS);
703//
704// if (mode == ImprovementDescriptionMode.INDUSTRY_TOOLTIP) {
705// info.addPara("Population growth increased by %s.", 0f, highlight,str);
706// } else {
707// info.addPara("Increases population growth by %s. Bonus is based on colony size.", 0f, highlight,str);
708// }
709//
710// info.addSpacer(opad);
711// super.addImproveDesc(info, mode);
712// }
713
714 @Override
715 public boolean canImprove() {
716 return true;
717 }
718
719 protected void applyImproveModifiers() {
720 if (isImproved()) {
723 } else {
724 market.getStability().unmodifyFlat("PAI_improve");
725 }
726 }
727
728 public void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode) {
729 float opad = 10f;
730 Color highlight = Misc.getHighlightColor();
731
732
733 if (mode == ImprovementDescriptionMode.INDUSTRY_TOOLTIP) {
734 info.addPara("Stability increased by %s.", 0f, highlight, "" + (int) IMPROVE_STABILITY_BONUS);
735 } else {
736 info.addPara("Increases stability by %s.", 0f, highlight, "" + (int) IMPROVE_STABILITY_BONUS);
737 }
738
739 info.addSpacer(opad);
740 super.addImproveDesc(info, mode);
741 }
742
743
744
745 protected static class LampRemover implements EveryFrameScript {
746 protected SectorEntityToken lamp;
747 protected MarketAPI market;
748 protected PopulationAndInfrastructure industry;
749 public LampRemover(SectorEntityToken lamp, MarketAPI market, PopulationAndInfrastructure industry) {
750 this.lamp = lamp;
751 this.market = market;
752 this.industry = industry;
753 }
754 public void advance(float amount) {
756 SpecialItemData item = ind == null ? null : ind.getSpecialItem();
757 if (item == null || !item.getId().equals(Items.ORBITAL_FUSION_LAMP)) {
758 Misc.fadeAndExpire(lamp);
759 industry.lamp = null;
760 lamp = null;
761 }
762 }
763 public boolean isDone() {
764 return lamp == null;
765 }
766 public boolean runWhilePaused() {
767 return false;
768 }
769 }
770
771 protected String addedHeatCondition = null;
772 protected String removedHeatCondition = null;
774 @Override
776 super.setSpecialItem(special);
777
778 if (addedHeatCondition != null && (special == null || !special.getId().equals(Items.ORBITAL_FUSION_LAMP))) {
780 addedHeatCondition = null;
781 if (removedHeatCondition != null) {
784 }
785 }
786
787 if (special != null && special.getId().equals(Items.ORBITAL_FUSION_LAMP)) {
788 if (lamp == null) {
790 if (focus == null) focus = market.getPrimaryEntity();
791 if (focus != null) {
792 EntityLocation loc = new EntityLocation();
793 float radius = focus.getRadius() + 100f;
794 loc.orbit = Global.getFactory().createCircularOrbit(focus, (float) Math.random() * 360f,
795 radius, radius / (10f + 10f * (float) Math.random()));
796 AddedEntity added = BaseThemeGenerator.addNonSalvageEntity(
797 market.getContainingLocation(), loc, Entities.FUSION_LAMP, getMarket().getFactionId());//Factions.NEUTRAL);
798 if (added != null) {
799 lamp = added.entity;
800 market.getContainingLocation().addScript(new LampRemover(lamp, market, this));
801 }
802 }
803 }
804 if (addedHeatCondition == null &&
811 } else {
813 }
816 }
817 }
818 }
819
820
821 @Override
823 if (special != null) return false;
824
825 if (Items.ORBITAL_FUSION_LAMP.equals(data.getId())) {
826 for (String mc : ItemEffectsRepo.FUSION_LAMP_CONDITIONS) {
827 if (market.hasCondition(mc)) return true;
828 }
829 return false;
830 }
831 return super.wantsToUseSpecialItem(data);
832 }
833
834
835 public static Pair<SectorEntityToken, Float> getNearestCoronalTap(Vector2f locInHyper, boolean usable) {
836 return getNearestCoronalTap(locInHyper, usable, false);
837 }
838 public static Pair<SectorEntityToken, Float> getNearestCoronalTap(Vector2f locInHyper, boolean usable, boolean requireDefendersDefeated) {
839 SectorEntityToken nearest = null;
840 float minDist = Float.MAX_VALUE;
841
842 //for (SectorEntityToken entity : Global.getSector().getCustomEntitiesWithTag(Tags.CORONAL_TAP)) {
844 HypershuntIntel hypershunt = (HypershuntIntel) intel;
845 if (requireDefendersDefeated && !hypershunt.defendersDefeated()) {
846 continue;
847 }
848 SectorEntityToken entity = hypershunt.getEntity();
849 if (!usable || entity.getMemoryWithoutUpdate().contains("$usable")) {
850 float dist = Misc.getDistanceLY(locInHyper, entity.getLocationInHyperspace());
852 Math.round(dist * 10f) <= ItemEffectsRepo.CORONAL_TAP_LIGHT_YEARS * 10f) {
854 }
855 if (dist < minDist) {
856 minDist = dist;
857 nearest = entity;
858 }
859 }
860 }
861
862 if (nearest == null) return null;
863
864 return new Pair<SectorEntityToken, Float>(nearest, minDist);
865 }
866
867 public static class CoronalTapFactor implements ColonyOtherFactorsListener {
868 public boolean isActiveFactorFor(SectorEntityToken entity) {
869 return getNearestCoronalTap(entity.getLocationInHyperspace(), true) != null;
870 }
871
872 public void printOtherFactors(TooltipMakerAPI text, SectorEntityToken entity) {
874 if (p != null) {
875 Color h = Misc.getHighlightColor();
876 float opad = 10f;
877
878 String dStr = "" + Misc.getRoundedValueMaxOneAfterDecimal(p.two);
879 String lights = "light-years";
880 if (dStr.equals("1")) lights = "light-year";
881
883 text.addPara("The nearest coronal tap is located in the " +
884 p.one.getContainingLocation().getNameWithLowercaseType() + ", %s " + lights + " away. The maximum " +
885 "range at a portal can connect to a tap is %s light-years.",
886 opad, h,
889 } else {
890 text.addPara("The nearest coronal tap is located in the " +
891 p.one.getContainingLocation().getNameWithLowercaseType() + ", %s " + lights + " away, allowing " +
892 "a coronal portal located here to connect to it.",
893 opad, h,
895 }
896 }
897 }
898 }
899
900}
901
902
903
904
905
906
907
static SettingsAPI getSettings()
Definition Global.java:57
static FactoryAPI getFactory()
Definition Global.java:41
static SectorAPI getSector()
Definition Global.java:65
void modifyFlat(String source, float value)
HashMap< String, StatMod > getFlatMods()
void modifyMultAlways(String source, float value, String desc)
void modifyMult(String source, float value)
void modifyMultAlways(String source, float value, String desc)
void modifyFlatAlways(String source, float value, String desc)
void modifyFlat(String source, float value)
Map< String, MutableCommodityQuantity > supply
Map< String, MutableCommodityQuantity > demand
Pair< String, Integer > getMaxDeficit(String ... commodityIds)
static Pair< SectorEntityToken, Float > getNearestCoronalTap(Vector2f locInHyper, boolean usable)
void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode)
static Pair< SectorEntityToken, Float > getNearestCoronalTap(Vector2f locInHyper, boolean usable, boolean requireDefendersDefeated)
static void modifyStability2(Industry industry, MarketAPI market, String modId)
static void modifyStability(Industry industry, MarketAPI market, String modId)
void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode)
static float getDoctrineNumShipsMult(int doctrineNumShips)
static final String OFFICER_IS_MERC_PROB_MOD
Definition Stats.java:40
static final String OFFICER_ADDITIONAL_PROB_MULT_MOD
Definition Stats.java:39
static AddedEntity addNonSalvageEntity(LocationAPI system, EntityLocation loc, String type, String faction)
static float getDistanceLY(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:602
static String ucFirst(String str)
Definition Misc.java:559
static Color getNegativeHighlightColor()
Definition Misc.java:802
static float getMarketSizeProgress(MarketAPI market)
Definition Misc.java:4270
static void fadeAndExpire(SectorEntityToken entity)
Definition Misc.java:3133
static int getNumIndustries(MarketAPI market)
Definition Misc.java:5248
static Color getHighlightColor()
Definition Misc.java:792
static int getMaxIndustries(MarketAPI market)
Definition Misc.java:5244
static int OVER_MAX_INDUSTRIES_PENALTY
Definition Misc.java:223
static Industry getCurrentlyBeingConstructed(MarketAPI market)
Definition Misc.java:5291
static int getMaxMarketSize(MarketAPI market)
Definition Misc.java:6812
static float getOutpostPenalty()
Definition Misc.java:4404
static String getRoundedValueMaxOneAfterDecimal(float value)
Definition Misc.java:673
static String getRoundedValue(float value)
Definition Misc.java:647
OrbitAPI createCircularOrbit(SectorEntityToken focus, float angle, float orbitRadius, float orbitDays)
JSONArray getJSONArray(String key)
String getSpriteName(String category, String id)
MarketConditionSpecAPI getMarketConditionSpec(String conditionId)
IndustrySpecAPI getIndustrySpec(String industryId)
void addScript(EveryFrameScript script)
int getMaxShipping(MarketAPI market, boolean inFaction)
void addTransientImmigrationModifier(MarketImmigrationModifier mod)
List< CommodityOnMarketAPI > getCommoditiesCopy()
MutableStatWithTempMods getStability()
void removeTransientImmigrationModifier(MarketImmigrationModifier mod)
MutableCharacterStatsAPI getStats()
void addStatModGrid(float width, float valueWidth, float valuePad, float pad, MutableStat stat)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
UIComponentAPI addSpacer(float height)