Starsector API
Loading...
Searching...
No Matches
GroundDefenses.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.econ.impl;
2
3import java.awt.Color;
4
5import com.fs.starfarer.api.Global;
6import com.fs.starfarer.api.campaign.PlanetAPI;
7import com.fs.starfarer.api.campaign.econ.CommodityOnMarketAPI;
8import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
9import com.fs.starfarer.api.impl.campaign.ids.Commodities;
10import com.fs.starfarer.api.impl.campaign.ids.Industries;
11import com.fs.starfarer.api.impl.campaign.ids.Stats;
12import com.fs.starfarer.api.impl.campaign.ids.Strings;
13import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.MarketCMD.RaidDangerLevel;
14import com.fs.starfarer.api.ui.TooltipMakerAPI;
15import com.fs.starfarer.api.util.Misc;
16import com.fs.starfarer.api.util.Pair;
17
18public class GroundDefenses extends BaseIndustry {
19
20 public static float DEFENSE_BONUS_BASE = 1f;
21 public static float DEFENSE_BONUS_BATTERIES = 2f;
22
23 public static float IMPROVE_DEFENSE_BONUS = 0.25f;
24
25
26 public void apply() {
27 super.apply(true);
28
29 int size = market.getSize();
30 boolean hb = Industries.HEAVYBATTERIES.equals(getId());
31
32 demand(Commodities.SUPPLIES, size);
33 demand(Commodities.MARINES, size);
34 demand(Commodities.HAND_WEAPONS, size - 2);
35
36 //supply(Commodities.MARINES, size - 2);
37
38// Pair<String, Integer> deficit = getMaxDeficit(Commodities.HAND_WEAPONS);
39// applyDeficitToProduction(1, deficit, Commodities.MARINES);
40
42
43 float mult = getDeficitMult(Commodities.SUPPLIES, Commodities.MARINES, Commodities.HAND_WEAPONS);
44 String extra = "";
45 if (mult != 1) {
46 String com = getMaxDeficit(Commodities.SUPPLIES, Commodities.MARINES, Commodities.HAND_WEAPONS).one;
47 extra = " (" + getDeficitText(com).toLowerCase() + ")";
48 }
50 market.getStats().getDynamic().getMod(Stats.GROUND_DEFENSES_MOD)
51 .modifyMult(getModId(), 1f + bonus * mult, getNameForModifier() + extra);
52// market.getStats().getDynamic().getMod(Stats.GROUND_DEFENSES_MOD)
53// .modifyPercent(getModId(), bonus * mult * 100f, getNameForModifier() + extra);
54
55
56 if (!isFunctional()) {
57 supply.clear();
58 unapply();
59 }
60
61 }
62
63 @Override
64 public void unapply() {
65 super.unapply();
66
68
69 market.getStats().getDynamic().getMod(Stats.GROUND_DEFENSES_MOD).unmodifyMult(getModId());
70 //market.getStats().getDynamic().getMod(Stats.GROUND_DEFENSES_MOD).unmodifyPercent(getModId());
71 //market.getStats().getDynamic().getMod(Stats.GROUND_DEFENSES_MOD).unmodifyFlat(getModId());
72 }
73
74 @Override
75 public String getCurrentImage() {
76 boolean batteries = Industries.HEAVYBATTERIES.equals(getId());
77 if (batteries) {
78 PlanetAPI planet = market.getPlanetEntity();
79 if (planet == null || planet.isGasGiant()) {
80 return Global.getSettings().getSpriteName("industry", "heavy_batteries_orbital");
81 }
82 }
83 return super.getCurrentImage();
84 }
85
86 public boolean isDemandLegal(CommodityOnMarketAPI com) {
87 return true;
88 }
89
90 public boolean isSupplyLegal(CommodityOnMarketAPI com) {
91 return true;
92 }
93
94
95 protected boolean hasPostDemandSection(boolean hasDemand, IndustryTooltipMode mode) {
96 //return mode == IndustryTooltipMode.NORMAL && isFunctional();
97 return mode != IndustryTooltipMode.NORMAL || isFunctional();
98 }
99
100 @Override
101 protected void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode) {
102 //if (mode == IndustryTooltipMode.NORMAL && isFunctional()) {
103 if (mode != IndustryTooltipMode.NORMAL || isFunctional()) {
104 addStabilityPostDemandSection(tooltip, hasDemand, mode);
105
106 boolean hb = Industries.HEAVYBATTERIES.equals(getId());
107 float bonus = hb ? DEFENSE_BONUS_BATTERIES : DEFENSE_BONUS_BASE;
108 addGroundDefensesImpactSection(tooltip, bonus, Commodities.SUPPLIES, Commodities.MARINES, Commodities.HAND_WEAPONS);
109 }
110 }
111
112 @Override
113 protected int getBaseStabilityMod() {
114 return 1;
115 }
116
117 @Override
118 protected Pair<String, Integer> getStabilityAffectingDeficit() {
119 return getMaxDeficit(Commodities.SUPPLIES, Commodities.MARINES, Commodities.HAND_WEAPONS);
120 }
121
122
123 public static float ALPHA_CORE_BONUS = 0.5f;
124 @Override
125 protected void applyAlphaCoreModifiers() {
126 market.getStats().getDynamic().getMod(Stats.GROUND_DEFENSES_MOD).modifyMult(
127 getModId(1), 1f + ALPHA_CORE_BONUS, "Alpha core (" + getNameForModifier() + ")");
128 }
129
130 @Override
131 protected void applyNoAICoreModifiers() {
132 market.getStats().getDynamic().getMod(Stats.GROUND_DEFENSES_MOD).unmodifyMult(getModId(1));
133 }
134
135 @Override
137 demandReduction.modifyFlat(getModId(0), DEMAND_REDUCTION, "Alpha core");
138 }
139
140 protected void addAlphaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode) {
141 float opad = 10f;
142 Color highlight = Misc.getHighlightColor();
143
144 String pre = "Alpha-level AI core currently assigned. ";
145 if (mode == AICoreDescriptionMode.MANAGE_CORE_DIALOG_LIST || mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
146 pre = "Alpha-level AI core. ";
147 }
148 float a = ALPHA_CORE_BONUS;
149 //String str = Strings.X + (int)Math.round(a * 100f) + "%";
150 String str = Strings.X + (1f + a) + "";
151
152 if (mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
153 CommoditySpecAPI coreSpec = Global.getSettings().getCommoditySpec(aiCoreId);
154 TooltipMakerAPI text = tooltip.beginImageWithText(coreSpec.getIconName(), 48);
155 text.addPara(pre + "Reduces upkeep cost by %s. Reduces demand by %s unit. " +
156 "Increases ground defenses by %s.", 0f, highlight,
157 "" + (int)((1f - UPKEEP_MULT) * 100f) + "%", "" + DEMAND_REDUCTION,
158 str);
159 tooltip.addImageWithText(opad);
160 return;
161 }
162
163 tooltip.addPara(pre + "Reduces upkeep cost by %s. Reduces demand by %s unit. " +
164 "Increases ground defenses by %s.", opad, highlight,
165 "" + (int)((1f - UPKEEP_MULT) * 100f) + "%", "" + DEMAND_REDUCTION,
166 str);
167
168 }
169
170
171 @Override
172 public boolean canImprove() {
173 return true;
174 }
175
176 protected void applyImproveModifiers() {
177 if (isImproved()) {
178 market.getStats().getDynamic().getMod(Stats.GROUND_DEFENSES_MOD).modifyMult("ground_defenses_improve",
181 } else {
182 market.getStats().getDynamic().getMod(Stats.GROUND_DEFENSES_MOD).unmodifyMult("ground_defenses_improve");
183 }
184 }
185
186 public void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode) {
187 float opad = 10f;
188 Color highlight = Misc.getHighlightColor();
189
190 float a = IMPROVE_DEFENSE_BONUS;
191 String str = Strings.X + (1f + a) + "";
192
193 if (mode == ImprovementDescriptionMode.INDUSTRY_TOOLTIP) {
194 info.addPara("Ground defenses increased by %s.", 0f, highlight, str);
195 } else {
196 info.addPara("Increases ground defenses by %s.", 0f, highlight, str);
197 }
198
199 info.addSpacer(opad);
200 super.addImproveDesc(info, mode);
201 }
202
203 @Override
204 public RaidDangerLevel adjustCommodityDangerLevel(String commodityId, RaidDangerLevel level) {
205 return level.next();
206 }
207
208 @Override
209 public RaidDangerLevel adjustItemDangerLevel(String itemId, String data, RaidDangerLevel level) {
210 return level.next();
211 }
212
213}
214
215
216
217
static SettingsAPI getSettings()
Definition Global.java:51
Map< String, MutableCommodityQuantity > supply
void addStabilityPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode)
void addGroundDefensesImpactSection(TooltipMakerAPI tooltip, float bonus, String ...commodities)
Map< String, MutableCommodityQuantity > demand
Pair< String, Integer > getMaxDeficit(String ... commodityIds)
RaidDangerLevel adjustItemDangerLevel(String itemId, String data, RaidDangerLevel level)
void addAlphaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode)
boolean hasPostDemandSection(boolean hasDemand, IndustryTooltipMode mode)
void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode)
RaidDangerLevel adjustCommodityDangerLevel(String commodityId, RaidDangerLevel level)
void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode)
String getSpriteName(String category, String id)
CommoditySpecAPI getCommoditySpec(String commodityId)