1package com.fs.starfarer.api.impl.campaign.econ.impl;
4import java.util.ArrayList;
5import java.util.HashSet;
6import java.util.Iterator;
7import java.util.LinkedHashMap;
10import java.util.Random;
13import com.fs.starfarer.api.Global;
14import com.fs.starfarer.api.campaign.CargoAPI;
15import com.fs.starfarer.api.campaign.FactionAPI;
16import com.fs.starfarer.api.campaign.SpecialItemData;
17import com.fs.starfarer.api.campaign.SpecialItemSpecAPI;
18import com.fs.starfarer.api.campaign.comm.CommMessageAPI.MessageClickAction;
19import com.fs.starfarer.api.campaign.econ.CommodityOnMarketAPI;
20import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
21import com.fs.starfarer.api.campaign.econ.Industry;
22import com.fs.starfarer.api.campaign.econ.InstallableIndustryItemPlugin;
23import com.fs.starfarer.api.campaign.econ.InstallableIndustryItemPlugin.InstallableItemDescriptionMode;
24import com.fs.starfarer.api.campaign.econ.MarketAPI;
25import com.fs.starfarer.api.campaign.econ.MarketAPI.MarketInteractionMode;
26import com.fs.starfarer.api.campaign.econ.MarketImmigrationModifier;
27import com.fs.starfarer.api.campaign.econ.MutableCommodityQuantity;
28import com.fs.starfarer.api.campaign.impl.items.GenericSpecialItemPlugin;
29import com.fs.starfarer.api.campaign.listeners.ListenerUtil;
30import com.fs.starfarer.api.campaign.rules.MemoryAPI;
31import com.fs.starfarer.api.combat.MutableStat;
32import com.fs.starfarer.api.combat.MutableStat.StatMod;
33import com.fs.starfarer.api.impl.campaign.DebugFlags;
34import com.fs.starfarer.api.impl.campaign.econ.impl.ConstructionQueue.ConstructionQueueItem;
35import com.fs.starfarer.api.impl.campaign.ids.Commodities;
36import com.fs.starfarer.api.impl.campaign.ids.Industries;
37import com.fs.starfarer.api.impl.campaign.ids.Items;
38import com.fs.starfarer.api.impl.campaign.ids.Sounds;
39import com.fs.starfarer.api.impl.campaign.ids.Stats;
40import com.fs.starfarer.api.impl.campaign.ids.Strings;
41import com.fs.starfarer.api.impl.campaign.ids.Tags;
42import com.fs.starfarer.api.impl.campaign.intel.BaseIntelPlugin;
43import com.fs.starfarer.api.impl.campaign.intel.MessageIntel;
44import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.MarketCMD.RaidDangerLevel;
45import com.fs.starfarer.api.loading.IndustrySpecAPI;
46import com.fs.starfarer.api.ui.Alignment;
47import com.fs.starfarer.api.ui.IconRenderMode;
48import com.fs.starfarer.api.ui.LabelAPI;
49import com.fs.starfarer.api.ui.TooltipMakerAPI;
50import com.fs.starfarer.api.ui.TooltipMakerAPI.StatModValueGetter;
51import com.fs.starfarer.api.util.Misc;
52import com.fs.starfarer.api.util.Pair;
70 }
catch (CloneNotSupportedException e) {
81 if (commodityId ==
null) {
82 return "Various shortages";
85 return Misc.ucFirst(
spec.getName().toLowerCase() +
" shortage");
90 protected Map<String, MutableCommodityQuantity>
supply =
new LinkedHashMap<String, MutableCommodityQuantity>();
91 protected Map<String, MutableCommodityQuantity>
demand =
new LinkedHashMap<String, MutableCommodityQuantity>();
93 protected MutableStat
income =
new MutableStat(0f);
94 protected MutableStat
upkeep =
new MutableStat(0f);
105 protected transient IndustrySpecAPI
spec =
null;
150 private transient String modId;
151 private transient String [] modIds;
158 modIds =
new String[10];
159 for (
int i = 0; i < modIds.length; i++) {
160 modIds[i] = modId +
"_" + i;
167 for (String
id :
new ArrayList<String>(
supply.keySet())) {
168 MutableCommodityQuantity stat =
supply.get(
id);
169 stat.getQuantity().unmodifyFlat(
"ind_sb");
173 for (String
id :
new ArrayList<String>(
demand.keySet())) {
174 MutableCommodityQuantity stat =
demand.get(
id);
175 stat.getQuantity().unmodifyFlat(
"ind_dr");
192 public void apply(
boolean withIncomeUpdate) {
195 if (withIncomeUpdate) {
202 if (
this instanceof MarketImmigrationModifier) {
203 market.addTransientImmigrationModifier((MarketImmigrationModifier)
this);
208 if (effect !=
null) {
210 if (unmet ==
null || unmet.isEmpty()) {
227 if (
this instanceof MarketImmigrationModifier) {
228 market.removeTransientImmigrationModifier((MarketImmigrationModifier)
this);
233 if (effect !=
null) {
244 boolean alpha =
aiCoreId.equals(Commodities.ALPHA_CORE);
245 boolean beta =
aiCoreId.equals(Commodities.BETA_CORE);
246 boolean gamma =
aiCoreId.equals(Commodities.GAMMA_CORE);
266 return modIds[index];
269 public void demand(String commodityId,
int quantity) {
273 public void demand(String commodityId,
int quantity, String desc) {
274 demand(0, commodityId, quantity, desc);
276 public void demand(
int index, String commodityId,
int quantity, String desc) {
279 public void demand(String modId, String commodityId,
int quantity, String desc) {
286 getDemand(commodityId).getQuantity().unmodifyFlat(modId);
288 getDemand(commodityId).getQuantity().modifyFlat(modId, quantity, desc);
295 getDemand(commodityId).getQuantity().unmodifyFlat(
"ind_dr");
300 public void supply(String commodityId,
int quantity) {
304 public void supply(String commodityId,
int quantity, String desc) {
305 supply(0, commodityId, quantity, desc);
308 public void supply(
int index, String commodityId,
int quantity, String desc) {
311 public void supply(String modId, String commodityId,
int quantity, String desc) {
320 getSupply(commodityId).getQuantity().unmodifyFlat(modId);
322 getSupply(commodityId).getQuantity().modifyFlat(modId, quantity, desc);
330 getSupply(commodityId).getQuantity().unmodifyFlat(
"ind_sb");
337 for (String commodity : commodities) {
341 if (
getSupply(commodity).getQuantity().isUnmodified())
continue;
358 float size =
market.getSize();
359 if (sizeOverride >= 0) size = sizeOverride;
361 sizeMult = Math.max(1, sizeMult - 2);
363 float stabilityMult =
market.getIncomeMult().getModifiedValue();
364 float upkeepMult =
market.getUpkeepMult().getModifiedValue();
373 getIncome().modifyMultAlways(
"ind_stability", stabilityMult,
"Market income multiplier");
376 getIncome().unmodifyMult(
"ind_stability");
383 getUpkeep().modifyMultAlways(
"ind_hazard", upkeepMult,
"Market upkeep multiplier");
393 getIncome().unmodifyMult(
"ind_stability");
407 return getSpec().getBuildTime();
423 float size =
market.getSize();
425 sizeMult = Math.max(1, sizeMult - 2);
426 return getSpec().getUpkeep() * sizeMult;
496 if (left < 1) left = 1;
497 String days =
"days";
498 if (left == 1) days =
"day";
500 return "" + left +
" " + days +
"";
504 if (left < 1) left = 1;
505 String days =
"days";
506 if (left == 1) days =
"day";
508 return left +
" " + days;
514 if (left < 1) left = 1;
515 String days =
"days";
516 if (left == 1) days =
"day";
518 return "Disrupted: " + left +
" " + days +
" left";
522 if (left < 1) left = 1;
523 String days =
"days";
524 if (left == 1) days =
"day";
532 return "Upgrading: " + left +
" " + days +
" left";
534 return "Building: " + left +
" " + days +
" left";
600 ConstructionQueueItem next =
null;
601 Iterator<ConstructionQueueItem> iter =
market.getConstructionQueue().getItems().iterator();
602 while (iter.hasNext()) {
606 Industry ind =
market.instantiateIndustry(next.id);
607 int num = Misc.getNumIndustries(
market);
608 int max = Misc.getMaxIndustries(
market);
609 if (ind.isAvailableToBuild() && (num <= max || !ind.isIndustry())) {
612 if (
market.isPlayerOwned()) {
613 MessageIntel intel =
new MessageIntel(ind.getCurrentName() +
" at " +
market.getName(), Misc.getBasePlayerColor());
614 intel.addLine(BaseIntelPlugin.BULLET +
"Construction aborted");
616 int refund = next.cost;
617 Global.
getSector().getPlayerFleet().getCargo().getCredits().add(refund);
618 intel.addLine(BaseIntelPlugin.BULLET +
"%s refunded",
620 new String [] {Misc.getDGSCredits(refund)}, Misc.getHighlightColor());
622 intel.setSound(BaseIntelPlugin.getSoundStandardUpdate());
630 market.addIndustry(next.id);
631 Industry ind =
market.getIndustry(next.id);
637 if (
market.isPlayerOwned()) {
638 MessageIntel intel =
new MessageIntel(ind.getCurrentName() +
" at " +
market.getName(), Misc.getBasePlayerColor());
639 intel.addLine(BaseIntelPlugin.BULLET +
"Construction started");
641 intel.setSound(BaseIntelPlugin.getSoundStandardUpdate());
654 if (
market.isPlayerOwned()) {
655 MessageIntel intel =
new MessageIntel(
getCurrentName() +
" at " +
market.getName(), Misc.getBasePlayerColor());
656 intel.addLine(BaseIntelPlugin.BULLET +
"Construction completed");
658 intel.setSound(BaseIntelPlugin.getSoundStandardUpdate());
664 if (
aiCoreId !=
null && !forUpgrade) {
671 if (
special !=
null && !forUpgrade) {
680 CargoAPI cargo =
null;
681 if (mode ==
null)
return null;
683 if (mode == MarketInteractionMode.REMOTE) {
684 cargo = Misc.getStorageCargo(
market);
702 for (String
id :
new ArrayList<String>(
supply.keySet())) {
703 MutableCommodityQuantity stat =
supply.get(
id);
704 if (stat !=
null && (stat.getQuantity().isUnmodified() || stat.getQuantity().getModifiedValue() <= 0)) {
710 for (String
id :
new ArrayList<String>(
demand.keySet())) {
711 MutableCommodityQuantity stat =
demand.get(
id);
712 if (stat !=
null && (stat.getQuantity().isUnmodified() || stat.getQuantity().getModifiedValue() <= 0)) {
720 List<MutableCommodityQuantity> result =
new ArrayList<MutableCommodityQuantity>();
721 for (MutableCommodityQuantity q :
demand.values()) {
722 if (q.getQuantity().getModifiedValue() > 0) {
730 List<MutableCommodityQuantity> result =
new ArrayList<MutableCommodityQuantity>();
731 for (MutableCommodityQuantity q :
supply.values()) {
732 if (q.getQuantity().getModifiedValue() > 0) {
740 MutableCommodityQuantity stat =
supply.get(
id);
742 stat =
new MutableCommodityQuantity(
id);
749 MutableCommodityQuantity stat =
demand.get(
id);
751 stat =
new MutableCommodityQuantity(
id);
800 Pair<String, Integer> result =
new Pair<String, Integer>();
802 for (String
id : commodityIds) {
804 CommodityOnMarketAPI com =
market.getCommodityData(
id);
805 int available = com.getAvailable();
807 int deficit = Math.max(
demand - available, 0);
808 if (deficit > result.two) {
810 result.two = deficit;
817 List<String> commodities =
new ArrayList<String>();
818 for (MutableCommodityQuantity curr :
demand.values()) {
819 commodities.add(curr.getCommodityId());
825 List<Pair<String, Integer>> result =
new ArrayList<Pair<String,Integer>>();
826 for (String
id : commodityIds) {
828 CommodityOnMarketAPI com =
market.getCommodityData(
id);
829 int available = com.getAvailable();
831 int deficit = Math.max(
demand - available, 0);
833 Pair<String, Integer> curr =
new Pair<String, Integer>();
846 if (size <= 0)
return 0f;
853 if (size <= 0)
return 0f;
884 supply =
new LinkedHashMap<String, MutableCommodityQuantity>();
885 demand =
new LinkedHashMap<String, MutableCommodityQuantity>();
887 income =
new MutableStat(0f);
888 upkeep =
new MutableStat(0f);
893 return getSpec().getImageName();
901 if (
market.hasTag(Tags.MARKET_NO_INDUSTRIES_ALLOWED))
return false;
902 return market.hasIndustry(Industries.POPULATION) && !
getId().equals(Industries.POPULATION);
906 if (
market.hasTag(Tags.MARKET_NO_INDUSTRIES_ALLOWED))
return false;
911 return "Can not be built";
923 public void createTooltip(IndustryTooltipMode mode, TooltipMakerAPI tooltip,
boolean expanded) {
929 FactionAPI faction =
market.getFaction();
930 Color color = faction.getBaseUIColor();
931 Color dark = faction.getDarkUIColor();
932 Color grid = faction.getGridUIColor();
933 Color bright = faction.getBrightUIColor();
935 Color gray = Misc.getGrayColor();
936 Color highlight = Misc.getHighlightColor();
937 Color bad = Misc.getNegativeHighlightColor();
940 MarketAPI copy =
market.clone();
944 copy.setSuppressedConditions(
market.getSuppressedConditions());
945 copy.setRetainSuppressedConditionsSetWhenEmpty(
true);
946 market.setRetainSuppressedConditionsSetWhenEmpty(
true);
952 boolean needToAddIndustry = !
market.hasIndustry(
getId());
954 if (needToAddIndustry)
market.getIndustries().add(
this);
956 if (mode != IndustryTooltipMode.NORMAL) {
957 market.clearCommodities();
958 for (CommodityOnMarketAPI curr :
market.getAllCommodities()) {
959 curr.getAvailableStat().setBaseValue(100);
967 market.reapplyConditions();
976 String desc =
spec.getDesc();
978 if (override !=
null) {
981 desc =
Global.
getSector().getRules().performTokenReplacement(
null, desc,
market.getPrimaryEntity(),
null);
983 tooltip.addPara(desc, opad);
994 if (
isIndustry() && (mode == IndustryTooltipMode.ADD_INDUSTRY ||
995 mode == IndustryTooltipMode.UPGRADE ||
996 mode == IndustryTooltipMode.DOWNGRADE)
999 int num = Misc.getNumIndustries(
market);
1000 int max = Misc.getMaxIndustries(
market);
1007 if (mode == IndustryTooltipMode.UPGRADE) {
1008 for (Industry curr :
market.getIndustries()) {
1009 if (
getSpec().getId().equals(curr.getSpec().getUpgrade())) {
1010 if (curr.isIndustry()) {
1016 }
else if (mode == IndustryTooltipMode.DOWNGRADE) {
1017 for (Industry curr :
market.getIndustries()) {
1018 if (
getSpec().getId().equals(curr.getSpec().getDowngrade())) {
1019 if (curr.isIndustry()) {
1029 c = Misc.getTextColor();
1030 Color h1 = highlight;
1031 Color h2 = highlight;
1037 tooltip.addPara(
"Maximum number of industries reached", bad, opad);
1051 if (left < 1) left = 1;
1052 String days =
"days";
1053 if (left == 1) days =
"day";
1055 tooltip.addPara(
"Operations disrupted! %s " + days +
" until return to normal function.",
1056 opad, Misc.getNegativeHighlightColor(), highlight,
"" + left);
1060 if (mode == IndustryTooltipMode.NORMAL) {
1062 tooltip.addPara(
"Click to manage or upgrade", Misc.getPositiveHighlightColor(), opad);
1064 tooltip.addPara(
"Click to manage", Misc.getPositiveHighlightColor(), opad);
1070 if (mode == IndustryTooltipMode.QUEUED) {
1071 tooltip.addPara(
"Click to remove or adjust position in queue", Misc.getPositiveHighlightColor(), opad);
1072 tooltip.addPara(
"Currently queued for construction. Does not have any impact on the colony.", opad);
1074 int left = (int) (
getSpec().getBuildTime());
1075 if (left < 1) left = 1;
1076 String days =
"days";
1077 if (left == 1) days =
"day";
1078 tooltip.addPara(
"Requires %s " + days +
" to build.", opad, highlight,
"" + left);
1082 tooltip.addPara(
"Currently under construction and not producing anything or providing other benefits.", opad);
1085 if (left < 1) left = 1;
1086 String days =
"days";
1087 if (left == 1) days =
"day";
1088 tooltip.addPara(
"Requires %s more " + days +
" to finish building.", opad, highlight,
"" + left);
1093 (mode == IndustryTooltipMode.ADD_INDUSTRY ||
1094 mode == IndustryTooltipMode.UPGRADE ||
1095 mode == IndustryTooltipMode.DOWNGRADE)) {
1097 if (reason !=
null) {
1098 tooltip.addPara(reason, bad, opad);
1102 boolean category =
getSpec().hasTag(Industries.TAG_PARENT);
1105 int credits = (int)
Global.
getSector().getPlayerFleet().getCargo().getCredits().get();
1106 String creditsStr = Misc.getDGSCredits(credits);
1107 if (mode == IndustryTooltipMode.UPGRADE || mode == IndustryTooltipMode.ADD_INDUSTRY) {
1109 String costStr = Misc.getDGSCredits(cost);
1112 String daysStr =
"days";
1113 if (days == 1) daysStr =
"day";
1115 LabelAPI label =
null;
1116 if (mode == IndustryTooltipMode.UPGRADE) {
1117 label = tooltip.addPara(
"%s and %s " + daysStr +
" to upgrade. You have %s.", opad,
1118 highlight, costStr,
"" + days, creditsStr);
1120 label = tooltip.addPara(
"%s and %s " + daysStr +
" to build. You have %s.", opad,
1121 highlight, costStr,
"" + days, creditsStr);
1123 label.setHighlight(costStr,
"" + days, creditsStr);
1124 if (credits >= cost) {
1125 label.setHighlightColors(highlight, highlight, highlight);
1127 label.setHighlightColors(bad, highlight, highlight);
1129 }
else if (mode == IndustryTooltipMode.DOWNGRADE) {
1130 if (
getSpec().getUpgrade() !=
null) {
1135 int cost = (int) (
spec.getCost() * refundFraction);
1136 String refundStr = Misc.getDGSCredits(cost);
1138 tooltip.addPara(
"%s refunded for downgrade.", opad, highlight, refundStr);
1147 tooltip.addPara(
"Monthly income: %s", opad, highlight, Misc.getDGSCredits(
income));
1148 tooltip.addStatModGrid(300, 65, 10, pad,
getIncome(),
true,
new StatModValueGetter() {
1149 public String getPercentValue(StatMod mod) {
return null;}
1150 public String getMultValue(StatMod mod) {
return null;}
1151 public Color getModColor(StatMod mod) {
return null;}
1152 public String getFlatValue(StatMod mod) {
1153 return Misc.getWithDGS(mod.value) + Strings.C;
1160 tooltip.addPara(
"Monthly upkeep: %s", opad, highlight, Misc.getDGSCredits(
upkeep));
1161 tooltip.addStatModGrid(300, 65, 10, pad,
getUpkeep(),
true,
new StatModValueGetter() {
1162 public String getPercentValue(StatMod mod) {
return null;}
1163 public String getMultValue(StatMod mod) {
return null;}
1164 public Color getModColor(StatMod mod) {
return null;}
1165 public String getFlatValue(StatMod mod) {
1166 return Misc.getWithDGS(mod.value) + Strings.C;
1173 boolean hasSupply =
false;
1174 for (MutableCommodityQuantity curr :
supply.values()) {
1175 int qty = curr.getQuantity().getModifiedInt();
1176 if (qty <= 0)
continue;
1180 boolean hasDemand =
false;
1181 for (MutableCommodityQuantity curr :
demand.values()) {
1182 int qty = curr.getQuantity().getModifiedInt();
1183 if (qty <= 0)
continue;
1188 float maxIconsPerRow = 10f;
1190 tooltip.addSectionHeading(
"Production", color, dark, Alignment.MID, opad);
1191 tooltip.beginIconGroup();
1192 tooltip.setIconSpacingMedium();
1194 for (MutableCommodityQuantity curr :
supply.values()) {
1195 int qty = curr.getQuantity().getModifiedInt();
1200 tooltip.addIcons(
market.getCommodityData(curr.getCommodityId()), normal, IconRenderMode.NORMAL);
1205 for (StatMod mod : curr.getQuantity().getFlatMods().values()) {
1206 if (mod.value > 0) {
1207 plus += (int) mod.value;
1208 }
else if (mod.desc !=
null && mod.desc.contains(
"shortage")) {
1209 minus += (int) Math.abs(mod.value);
1212 minus = Math.min(minus, plus);
1213 if (minus > 0 && mode == IndustryTooltipMode.NORMAL) {
1214 tooltip.addIcons(
market.getCommodityData(curr.getCommodityId()), minus, IconRenderMode.DIM_RED);
1216 icons += normal + Math.max(0, minus);
1218 int rows = (int) Math.ceil(icons / maxIconsPerRow);
1220 tooltip.addIconGroup(32, rows, opad);
1231 tooltip.addSectionHeading(
"Demand & effects", color, dark, Alignment.MID, opad);
1234 tooltip.beginIconGroup();
1235 tooltip.setIconSpacingMedium();
1237 for (MutableCommodityQuantity curr :
demand.values()) {
1238 int qty = curr.getQuantity().getModifiedInt();
1239 if (qty <= 0)
continue;
1241 CommodityOnMarketAPI com = orig.getCommodityData(curr.getCommodityId());
1242 int available = com.getAvailable();
1244 int normal = Math.min(available, qty);
1245 int red = Math.max(0, qty - available);
1247 if (mode != IndustryTooltipMode.NORMAL) {
1252 tooltip.addIcons(com, normal, IconRenderMode.NORMAL);
1255 tooltip.addIcons(com, red, IconRenderMode.DIM_RED);
1257 icons += normal + Math.max(0, red);
1259 int rows = (int) Math.ceil(icons / maxIconsPerRow);
1262 tooltip.addIconGroup(32, rows, opad);
1267 if (!needToAddIndustry) {
1272 ListenerUtil.addToIndustryTooltip(
this, mode, tooltip,
getTooltipWidth(), expanded);
1275 tooltip.addPara(
"*Shown production and demand values are already adjusted based on current market size and local conditions.", gray, opad);
1278 if (needToAddIndustry) {
1280 market.getIndustries().remove(
this);
1283 market.setRetainSuppressedConditionsSetWhenEmpty(
null);
1284 if (!needToAddIndustry) {
1292 FactionAPI faction =
market.getFaction();
1293 Color color = faction.getBaseUIColor();
1294 Color dark = faction.getDarkUIColor();
1296 LabelAPI heading = tooltip.addSectionHeading(
"Items", color, dark, Alignment.MID, opad);
1298 boolean addedSomething =
false;
1300 AICoreDescriptionMode aiCoreDescMode = AICoreDescriptionMode.INDUSTRY_TOOLTIP;
1302 addedSomething =
true;
1306 if (!addedSomething) {
1307 heading.setText(
"No items installed");
1313 if (
special ==
null)
return false;
1318 TooltipMakerAPI text = tooltip.beginImageWithText(
spec.getIconName(), 48);
1321 tooltip.addImageWithText(opad);
1331 List<SpecialItemData> result =
new ArrayList<SpecialItemData>();
1339 if (
special !=
null)
return false;
1344 String [] industries =
spec.getParams().split(
",");
1345 Set<String> all =
new HashSet<String>();
1346 for (String ind: industries) all.add(ind.trim());
1347 return all.contains(
getId());
1359 public void addAICoreSection(TooltipMakerAPI tooltip, String coreId, AICoreDescriptionMode mode) {
1362 FactionAPI faction =
market.getFaction();
1363 Color color = faction.getBaseUIColor();
1364 Color dark = faction.getDarkUIColor();
1371 if (mode == AICoreDescriptionMode.MANAGE_CORE_TOOLTIP) {
1372 if (coreId ==
null) {
1373 tooltip.addPara(
"No AI core currently assigned. Click to assign an AI core from your cargo.", opad);
1378 boolean alpha = coreId.equals(Commodities.ALPHA_CORE);
1379 boolean beta = coreId.equals(Commodities.BETA_CORE);
1380 boolean gamma = coreId.equals(Commodities.GAMMA_CORE);
1395 Color highlight = Misc.getHighlightColor();
1397 String pre =
"Alpha-level AI core currently assigned. ";
1398 if (mode == AICoreDescriptionMode.MANAGE_CORE_DIALOG_LIST || mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
1399 pre =
"Alpha-level AI core. ";
1401 if (mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP || mode == AICoreDescriptionMode.MANAGE_CORE_TOOLTIP) {
1403 TooltipMakerAPI text = tooltip.beginImageWithText(coreSpec.getIconName(), 48);
1404 text.addPara(pre +
"Reduces upkeep cost by %s. Reduces demand by %s unit. " +
1405 "Increases production by %s unit.", 0f, highlight,
1408 tooltip.addImageWithText(opad);
1412 tooltip.addPara(pre +
"Reduces upkeep cost by %s. Reduces demand by %s unit. " +
1413 "Increases production by %s unit.", opad, highlight,
1420 Color highlight = Misc.getHighlightColor();
1422 String pre =
"Beta-level AI core currently assigned. ";
1423 if (mode == AICoreDescriptionMode.MANAGE_CORE_DIALOG_LIST || mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
1424 pre =
"Beta-level AI core. ";
1426 if (mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP || mode == AICoreDescriptionMode.MANAGE_CORE_TOOLTIP) {
1428 TooltipMakerAPI text = tooltip.beginImageWithText(coreSpec.getIconName(), 48);
1429 text.addPara(pre +
"Reduces upkeep cost by %s. Reduces demand by %s unit.", opad, highlight,
1431 tooltip.addImageWithText(opad);
1435 tooltip.addPara(pre +
"Reduces upkeep cost by %s. Reduces demand by %s unit.", opad, highlight,
1440 Color highlight = Misc.getHighlightColor();
1442 String pre =
"Gamma-level AI core currently assigned. ";
1443 if (mode == AICoreDescriptionMode.MANAGE_CORE_DIALOG_LIST || mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
1444 pre =
"Gamma-level AI core. ";
1446 if (mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP || mode == AICoreDescriptionMode.MANAGE_CORE_TOOLTIP) {
1448 TooltipMakerAPI text = tooltip.beginImageWithText(coreSpec.getIconName(), 48);
1452 text.addPara(pre +
"Reduces demand by %s unit.", opad, highlight,
1454 tooltip.addImageWithText(opad);
1460 tooltip.addPara(pre +
"Reduces demand by %s unit.", opad, highlight,
1467 if (core ==
null)
return;
1470 Color highlight = Misc.getHighlightColor();
1472 String pre = core.getName() +
" currently assigned. ";
1473 if (mode == AICoreDescriptionMode.MANAGE_CORE_DIALOG_LIST || mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
1474 pre = core.getName() +
". ";
1477 if (mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP || mode == AICoreDescriptionMode.MANAGE_CORE_TOOLTIP) {
1478 TooltipMakerAPI text = tooltip.beginImageWithText(core.getIconName(), 48);
1479 text.addPara(pre +
"No effect.", opad);
1480 tooltip.addImageWithText(opad);
1484 tooltip.addPara(pre +
"No effect.", opad);
1519 String name =
"AI Core assigned";
1520 if (
aiCoreId.equals(Commodities.ALPHA_CORE)) {
1521 name =
"Alpha Core assigned";
1522 }
else if (
aiCoreId.equals(Commodities.BETA_CORE)) {
1523 name =
"Beta Core assigned";
1524 }
else if (
aiCoreId.equals(Commodities.GAMMA_CORE)) {
1525 name =
"Gamma Core assigned";
1528 getUpkeep().modifyMult(
"ind_core", mult, name);
1536 boolean alpha =
aiCoreId.equals(Commodities.ALPHA_CORE);
1537 boolean beta =
aiCoreId.equals(Commodities.BETA_CORE);
1538 boolean gamma =
aiCoreId.equals(Commodities.GAMMA_CORE);
1583 supplyBonus.modifyFlat(
getModId(1),
market.getAdmin().getStats().getDynamic().getValue(Stats.SUPPLY_BONUS_MOD, 0),
"Administrator");
1584 demandReduction.modifyFlat(
getModId(1),
market.getAdmin().getStats().getDynamic().getValue(Stats.DEMAND_REDUCTION_MOD, 0),
"Administrator");
1628 return !com.isIllegal();
1632 return !com.isIllegal();
1636 Set<String> cores =
new HashSet<String>();
1637 cores.add(Commodities.ALPHA_CORE);
1638 cores.add(Commodities.BETA_CORE);
1639 cores.add(Commodities.GAMMA_CORE);
1640 return cores.contains(str);
1644 for (String str : params) {
1651 for (String str : params) {
1656 if (
spec ==
null)
continue;
1658 String [] industries =
spec.getParams().split(
",");
1659 Set<String> all =
new HashSet<String>();
1660 for (String ind : industries) all.add(ind.trim());
1661 if (all.contains(
getId())) {
1679 if (stabilityPenalty > stabilityMod) {
1680 stabilityPenalty = stabilityMod;
1682 stabilityMod -= stabilityPenalty;
1683 if (stabilityMod > 0) {
1697 return new Pair<String, Integer>(Commodities.SUPPLIES, 0);
1701 if (deficit < 0) deficit = 0;
1702 return (
int) Math.round(deficit);
1707 Color h = Misc.getHighlightColor();
1710 MutableStat fake =
new MutableStat(0);
1714 if (stabilityPenalty > stabilityMod) {
1715 stabilityPenalty = stabilityMod;
1720 if (stabilityPenalty != 0) {
1721 fake.modifyFlat(
"2", -stabilityPenalty, str);
1724 int total = stabilityMod - stabilityPenalty;
1725 String totalStr =
"+" + total;
1727 totalStr =
"" + total;
1728 h = Misc.getNegativeHighlightColor();
1732 tooltip.addPara(
"Stability bonus: %s", opad, h, totalStr);
1734 tooltip.addPara(
"Stability penalty: %s", opad, h, totalStr);
1736 tooltip.addStatModGrid(400, 35, opad, pad, fake,
new StatModValueGetter() {
1737 public String getPercentValue(StatMod mod) {
1740 public String getMultValue(StatMod mod) {
1743 public Color getModColor(StatMod mod) {
1744 if (mod.value < 0)
return Misc.getNegativeHighlightColor();
1747 public String getFlatValue(StatMod mod) {
1764 protected transient String
dKey =
null;
1767 dKey =
"$core_disrupted_" + getClass().getSimpleName();
1780 MemoryAPI memory =
market.getMemoryWithoutUpdate();
1783 dur = Math.max(memory.getExpire(key), dur);
1789 memory.set(key,
true, dur);
1799 float dur =
market.getMemoryWithoutUpdate().getExpire(key);
1800 if (dur < 0) dur = 0;
1810 return market.getMemoryWithoutUpdate().is(key,
true);
1815 if (Commodities.ALPHA_CORE.equals(
aiCoreId)) {
1817 }
else if (Commodities.BETA_CORE.equals(
aiCoreId)) {
1819 }
else if (Commodities.GAMMA_CORE.equals(
aiCoreId)) {
1826 if (
spec.hasTag(Items.TAG_PATHER1)) interest += 1;
1827 else if (
spec.hasTag(Items.TAG_PATHER2)) interest += 2;
1828 else if (
spec.hasTag(Items.TAG_PATHER4)) interest += 4;
1829 else if (
spec.hasTag(Items.TAG_PATHER6)) interest += 6;
1830 else if (
spec.hasTag(Items.TAG_PATHER8)) interest += 8;
1831 else if (
spec.hasTag(Items.TAG_PATHER10)) interest += 10;
1854 if (this.special !=
null) {
1856 if (effect !=
null) {
1867 for (String
id : commodities) {
1871 if (deficit < 0) deficit = 0f;
1878 if (mult < 0) mult = 0;
1879 if (mult > 1) mult = 1;
1885 Color h = Misc.getHighlightColor();
1888 MutableStat fake =
new MutableStat(1);
1892 if (commodities !=
null) {
1901 float total = Misc.getRoundedValueFloat(fake.getModifiedValue());
1902 String totalStr = Strings.X + total;
1904 h = Misc.getNegativeHighlightColor();
1907 tooltip.addPara(
"Ground defense strength: %s", opad, h, totalStr);
1908 tooltip.addStatModGrid(400, 35, opad, pad, fake,
new StatModValueGetter() {
1909 public String getPercentValue(StatMod mod) {
1912 public String getMultValue(StatMod mod) {
1915 public Color getModColor(StatMod mod) {
1916 if (mod.value < 0)
return Misc.getNegativeHighlightColor();
1919 public String getFlatValue(StatMod mod) {
1920 String r = Misc.getRoundedValue(mod.value);
1921 if (mod.value >= 0)
return "+" + r;
1929 return getSpec().hasTag(Industries.TAG_INDUSTRY);
1933 return getSpec().hasTag(Industries.TAG_STRUCTURE);
1952 return "Make improvements...";
1957 return base * (int) Math.round(Math.pow(2, Misc.getNumImprovedIndustries(
market)));
1975 this.improved =
null;
1988 boolean addedSomething =
false;
1990 String unit =
"unit";
1994 if (mode == ImprovementDescriptionMode.INDUSTRY_TOOLTIP) {
1995 info.addPara(
"Production increased by %s " + unit +
".", initPad, Misc.getHighlightColor(),
1998 info.addPara(
"Increases production by %s " + unit +
".", initPad, Misc.getHighlightColor(),
2003 addedSomething =
true;
2006 if (mode != ImprovementDescriptionMode.INDUSTRY_TOOLTIP) {
2016 info.addPara(
"Each improvement made at a colony doubles the number of " +
2017 "" + Misc.STORY +
" points required to make an additional improvement.", initPad,
2018 Misc.getStoryOptionColor(), Misc.STORY +
" points");
2019 addedSomething =
true;
2021 if (!addedSomething) {
2022 info.addSpacer(-opad);
2027 return "Improving " +
getSpec().getName();
2031 return Sounds.STORY_POINT_SPEND_INDUSTRY;
2043 return "Improvements";
2051 if (bonus <= 0)
return;
2063 tooltip.addSectionHeading(
"Improvements made", Misc.getStoryOptionColor(),
2064 Misc.getStoryDarkColor(), Alignment.MID, opad);
2066 tooltip.addSpacer(opad);
2067 addImproveDesc(tooltip, ImprovementDescriptionMode.INDUSTRY_TOOLTIP);
2086 return marineTokens;
2100 boolean found =
false;
2105 if (
spec.getParams() ==
null ||
spec.getParams().isEmpty())
continue;
2106 if (
spec.getNewPluginInstance(
null) instanceof GenericSpecialItemPlugin) {
2107 for (String
id :
spec.getParams().split(
",")) {
2109 if (
id.equals(
getId())) {
2118 ArrayList<InstallableIndustryItemPlugin> list =
new ArrayList<InstallableIndustryItemPlugin>();
static SettingsAPI getSettings()
static SectorAPI getSector()
static boolean COLONY_DEBUG
float getBuildOrUpgradeProgress()
int getImproveProductionBonus()
boolean canImproveToIncreaseProduction()
void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode)
String getBuildOrUpgradeDaysText()
boolean isDemandLegal(CommodityOnMarketAPI com)
void applyBetaCoreModifiers()
IndustrySpecAPI getSpec()
static int DEMAND_REDUCTION
List< Pair< String, Integer > > getAllDeficit(String ... commodityIds)
List< InstallableIndustryItemPlugin > getInstallableItems()
RaidDangerLevel adjustCommodityDangerLevel(String commodityId, RaidDangerLevel level)
boolean isTooltipExpandable()
List< MutableCommodityQuantity > getAllSupply()
void addInstalledItemsSection(IndustryTooltipMode mode, TooltipMakerAPI tooltip, boolean expanded)
void apply(boolean withIncomeUpdate)
boolean isAICoreId(String str)
void applyAICoreModifiers()
void applyBetaCoreSupplyAndDemandModifiers()
void supply(String modId, String commodityId, int quantity, String desc)
void applyIncomeAndUpkeep(float sizeOverride)
boolean canInstallAICores()
int getImproveStoryPoints()
Map< String, MutableCommodityQuantity > supply
void applyGammaCoreModifiers()
void notifyColonyRenamed()
String getBuildOrUpgradeProgressText()
void setDisrupted(float days)
void demand(int index, String commodityId, int quantity, String desc)
MutableStat getSupplyBonusFromOther()
String getImprovementsDescForModifiers()
void upgradeFinished(Industry previous)
MutableStat getSupplyBonus()
MutableCommodityQuantity getDemand(String id)
void addRightAfterDescriptionSection(TooltipMakerAPI tooltip, IndustryTooltipMode mode)
transient Boolean hasInstallableItems
void updateAICoreToSupplyAndDemandModifiers()
static String getDeficitText(String commodityId)
void supply(String commodityId, int quantity, String desc)
void createTooltip(IndustryTooltipMode mode, TooltipMakerAPI tooltip, boolean expanded)
void finishBuildingOrUpgrading()
List< SpecialItemData > getVisibleInstalledItems()
boolean wantsToUseSpecialItem(SpecialItemData data)
static float getSizeMult(float size)
void initWithParams(List< String > params)
boolean isAvailableToBuild()
transient MutableStat demandReductionFromOther
int getStabilityPenalty()
void applyAICoreToIncomeAndUpkeep()
void applyImproveModifiers()
void addStabilityPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode)
void addAICoreSection(TooltipMakerAPI tooltip, String coreId, AICoreDescriptionMode mode)
List< Pair< String, Integer > > getAllDeficit()
void setBuildProgress(float buildProgress)
void applyAlphaCoreSupplyAndDemandModifiers()
String getUnavailableReason()
void addImprovedSection(IndustryTooltipMode mode, TooltipMakerAPI tooltip, boolean expanded)
void setDisrupted(float days, boolean useMax)
int adjustMarineTokensToRaidItem(String itemId, String data, int marineTokens)
void disruptionFinished()
boolean hasPostDemandSection(boolean hasDemand, IndustryTooltipMode mode)
void addAlphaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode)
void updateSupplyAndDemandModifiers()
void supply(int index, String commodityId, int quantity, String desc)
void unmodifyStabilityWithBaseMod()
void advance(float amount)
void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode)
static int SIZE_FOR_LARGE_IMAGE
void addUnknownCoreDescription(String coreId, TooltipMakerAPI tooltip, AICoreDescriptionMode mode)
void demand(String commodityId, int quantity)
String getModId(int index)
void modifyStabilityWithBaseMod()
String getImproveDialogTitle()
static void buildNextInQueue(MarketAPI market)
static int DEFAULT_IMPROVE_SUPPLY_BONUS
String getCanNotShutDownReason()
void setBuildCostOverride(float buildCostOverride)
boolean addNonAICoreInstalledItems(IndustryTooltipMode mode, TooltipMakerAPI tooltip, boolean expanded)
transient IndustryTooltipMode currTooltipMode
void applyAlphaCoreModifiers()
void setSpecialItem(SpecialItemData special)
void addAICoreSection(TooltipMakerAPI tooltip, AICoreDescriptionMode mode)
String getDescriptionOverride()
String getCargoTitleForGatheringPoint()
void addPostDescriptionSection(TooltipMakerAPI tooltip, IndustryTooltipMode mode)
void applyGammaCoreSupplyAndDemandModifiers()
static float getCommodityEconUnitMult(float size)
float getDeficitMult(String ... commodities)
void setHidden(boolean hidden)
CargoAPI generateCargoForGatheringPoint(Random random)
SpecialItemData getSpecialItem()
Pair< String, Integer > getStabilityAffectingDeficit()
void updateIncomeAndUpkeep()
CargoAPI getCargoForInteractionMode(MarketInteractionMode mode)
void init(String id, MarketAPI market)
MutableStat getDemandReduction()
void setImproved(boolean improved)
transient MutableStat supplyBonusFromOther
String getImproveSoundId()
void setAICoreId(String aiCoreId)
void demand(String modId, String commodityId, int quantity, String desc)
void addGammaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode)
float getImproveBonusXP()
static final String BASE_VALUE_TEXT
void addGroundDefensesImpactSection(TooltipMakerAPI tooltip, float bonus, String ...commodities)
static int SIZE_FOR_SMALL_IMAGE
float getPatherInterest()
void supply(String commodityId, int quantity)
boolean isSupplyLegal(CommodityOnMarketAPI com)
void addPostUpkeepSection(TooltipMakerAPI tooltip, IndustryTooltipMode mode)
Map< String, MutableCommodityQuantity > demand
boolean showWhenUnavailable()
MutableStat getDemandReductionFromOther()
List< MutableCommodityQuantity > getAllDemand()
void notifyBeingRemoved(MarketInteractionMode mode, boolean forUpgrade)
MutableCommodityQuantity getSupply(String id)
void updateImprovementSupplyAndDemandModifiers()
String getNameForModifier()
String getImproveMenuText()
void applyNoAICoreModifiers()
transient IndustrySpecAPI spec
MutableStat demandReduction
int getBaseStabilityMod()
void addPostSupplySection(TooltipMakerAPI tooltip, boolean hasSupply, IndustryTooltipMode mode)
void demand(String commodityId, int quantity, String desc)
void sendBuildOrUpgradeMessage()
RaidDangerLevel adjustItemDangerLevel(String itemId, String data, RaidDangerLevel level)
Pair< String, Integer > getMaxDeficit(String ... commodityIds)
void applyDeficitToProduction(int index, Pair< String, Integer > deficit, String ... commodities)
Float getBuildCostOverride()
void addBetaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode)
static Map< String, InstallableItemEffect > ITEM_EFFECTS
SpecialItemSpecAPI getSpecialItemSpec(String itemId)
IndustrySpecAPI getIndustrySpec(String industryId)
CommoditySpecAPI getCommoditySpec(String commodityId)
float getFloat(String key)
List< SpecialItemSpecAPI > getAllSpecialItemSpecs()
List< String > getUnmetRequirements(Industry industry)
void unapply(Industry industry)
void apply(Industry industry)
void addItemDescription(Industry industry, TooltipMakerAPI text, SpecialItemData data, InstallableItemDescriptionMode mode)