Starsector API
Loading...
Searching...
No Matches
Waystation.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.SubmarketPlugin;
7import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
8import com.fs.starfarer.api.combat.MutableStat;
9import com.fs.starfarer.api.impl.campaign.ids.Commodities;
10import com.fs.starfarer.api.impl.campaign.ids.Stats;
11import com.fs.starfarer.api.impl.campaign.intel.events.ht.HyperspaceTopographyEventIntel;
12import com.fs.starfarer.api.impl.campaign.intel.events.ht.HyperspaceTopographyEventIntel.Stage;
13import com.fs.starfarer.api.impl.campaign.submarkets.LocalResourcesSubmarketPlugin;
14import com.fs.starfarer.api.ui.TooltipMakerAPI;
15import com.fs.starfarer.api.util.Misc;
16import com.fs.starfarer.api.util.Pair;
17
18
19
20public class Waystation extends BaseIndustry {
21
22 public static float UPKEEP_MULT_PER_DEFICIT = 0.1f;
23 public static float BASE_ACCESSIBILITY = 0.1f;
24
25 public static float IMPROVE_ACCESSIBILITY = 0.2f;
26
27 public static float ALPHA_CORE_ACCESSIBILITY = 0.2f;
28
29
30 public void apply() {
31 super.apply(true);
32
33 int size = market.getSize();
34
35 demand(Commodities.FUEL, size);
36 demand(Commodities.SUPPLIES, size);
37 demand(Commodities.CREW, size);
38
39 demand(Commodities.VOLATILES, 1);
40 demand(Commodities.RARE_METALS, 1);
41
42 String desc = getNameForModifier();
43
44// Pair<String, Integer> deficit = getUpkeepAffectingDeficit();
45// if (deficit.two > 0) {
46// float loss = getUpkeepPenalty(deficit);
47// getUpkeep().modifyMult("deficit", 1f + loss, getDeficitText(deficit.one));
48// } else {
49// getUpkeep().unmodifyMult("deficit");
50// }
51
52 market.setHasWaystation(true);
53
54 float a = BASE_ACCESSIBILITY;
55 if (a > 0) {
56 market.getAccessibilityMod().modifyFlat(getModId(0), a, desc);
57 }
58
59 if (market.isPlayerOwned()) {
60 SubmarketPlugin sub = Misc.getLocalResources(market);
61 if (sub instanceof LocalResourcesSubmarketPlugin) {
62 LocalResourcesSubmarketPlugin lr = (LocalResourcesSubmarketPlugin) sub;
63 float mult = Global.getSettings().getFloat("stockpileMultExcess");
64 lr.getStockpilingBonus(Commodities.FUEL).modifyFlat(getModId(0), size * mult);
65 lr.getStockpilingBonus(Commodities.SUPPLIES).modifyFlat(getModId(0), size * mult);
66 lr.getStockpilingBonus(Commodities.CREW).modifyFlat(getModId(0), size * mult);
67 lr.getStockpilingBonus(Commodities.VOLATILES).modifyFlat(getModId(0), 1f * mult);
68 lr.getStockpilingBonus(Commodities.RARE_METALS).modifyFlat(getModId(0), 1f * mult);
69 }
70 }
71
72 HyperspaceTopographyEventIntel intel = HyperspaceTopographyEventIntel.get();
73 if (intel != null && intel.isStageActive(Stage.SLIPSTREAM_DETECTION)) {
74 market.getStats().getDynamic().getMod(Stats.SLIPSTREAM_REVEAL_RANGE_LY_MOD).modifyFlat(
75 getModId(0), HyperspaceTopographyEventIntel.WAYSTATION_BONUS, getNameForModifier());
76 }
77
78
79 if (!isFunctional()) {
80 supply.clear();
81 unapply();
82 }
83 }
84
85 @Override
86 public void unapply() {
87 super.unapply();
88
89 market.setHasWaystation(false);
90 market.getAccessibilityMod().unmodifyFlat(getModId(0));
91 market.getAccessibilityMod().unmodifyFlat(getModId(1));
92 market.getAccessibilityMod().unmodifyFlat(getModId(2));
93
94 market.getStats().getDynamic().getMod(Stats.SLIPSTREAM_REVEAL_RANGE_LY_MOD).unmodifyFlat(getModId(0));
95
96 if (market.isPlayerOwned()) {
97 SubmarketPlugin sub = Misc.getLocalResources(market);
98 if (sub instanceof LocalResourcesSubmarketPlugin) {
99 LocalResourcesSubmarketPlugin lr = (LocalResourcesSubmarketPlugin) sub;
100 // base bonuses
101 lr.getStockpilingBonus(Commodities.FUEL).unmodifyFlat(getModId(0));
102 lr.getStockpilingBonus(Commodities.SUPPLIES).unmodifyFlat(getModId(0));
103 lr.getStockpilingBonus(Commodities.CREW).unmodifyFlat(getModId(0));
104 lr.getStockpilingBonus(Commodities.VOLATILES).unmodifyFlat(getModId(0));
105 lr.getStockpilingBonus(Commodities.RARE_METALS).unmodifyFlat(getModId(0));
106 }
107 }
108 }
109
110 protected float getUpkeepPenalty(Pair<String, Integer> deficit) {
111 float loss = deficit.two * UPKEEP_MULT_PER_DEFICIT;
112 if (loss < 0) loss = 0;
113 return loss;
114 }
115
116 protected Pair<String, Integer> getUpkeepAffectingDeficit() {
117 return getMaxDeficit(Commodities.FUEL, Commodities.SUPPLIES, Commodities.CREW);
118 }
119
120
121 @Override
122 protected void addPostDescriptionSection(TooltipMakerAPI tooltip, IndustryTooltipMode mode) {
123 if (!market.isPlayerOwned()) return;
124
125 float opad = 10f;
126
127 tooltip.addPara("Increases the range at which slipstreams are detected around the colony by %s, once "
128 + "the capability to do so is available.", opad, Misc.getHighlightColor(),
129 "" + (int)HyperspaceTopographyEventIntel.WAYSTATION_BONUS);
130
131// tooltip.addPara("As long as demand is met, allows the colony to stockpile fuel, supplies, and crew, even " +
132// "if it does not produce them locally.", opad);
133 }
134
135 protected boolean hasPostDemandSection(boolean hasDemand, IndustryTooltipMode mode) {
136 return mode != IndustryTooltipMode.NORMAL || isFunctional();
137 }
138
139 @Override
140 protected void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode) {
141 if (mode != IndustryTooltipMode.NORMAL || isFunctional()) {
142 MutableStat fake = new MutableStat(0);
143
144 String desc = getNameForModifier();
145 float a = BASE_ACCESSIBILITY;
146 if (a > 0) {
147 fake.modifyFlat(getModId(0), a, desc);
148 }
149 float total = a;
150 String totalStr = "+" + (int)Math.round(total * 100f) + "%";
151 Color h = Misc.getHighlightColor();
152 if (total < 0) {
153 h = Misc.getNegativeHighlightColor();
154 totalStr = "" + (int)Math.round(total * 100f) + "%";
155 }
156 float opad = 10f;
157 float pad = 3f;
158 if (total >= 0) {
159 tooltip.addPara("Accessibility bonus: %s", opad, h, totalStr);
160 } else {
161 tooltip.addPara("Accessibility penalty: %s", opad, h, totalStr);
162 }
163
164 tooltip.addPara("As long as demand is met, allows the colony to stockpile fuel, supplies, and crew, even " +
165 "if it does not produce them locally. The stockpile levels exceed those generated by equivalent local production.", opad);
166 }
167 }
168
169 @Override
170 protected void applyAlphaCoreModifiers() {
171 if (market.isPlayerOwned()) {
172 SubmarketPlugin sub = Misc.getLocalResources(market);
173 if (sub instanceof LocalResourcesSubmarketPlugin) {
174 float bonus = market.getSize() * Global.getSettings().getFloat("stockpileMultExcess");
175 LocalResourcesSubmarketPlugin lr = (LocalResourcesSubmarketPlugin) sub;
176 lr.getStockpilingBonus(Commodities.FUEL).modifyFlat(getModId(1), bonus);
177 lr.getStockpilingBonus(Commodities.SUPPLIES).modifyFlat(getModId(1), bonus);
178 lr.getStockpilingBonus(Commodities.CREW).modifyFlat(getModId(1), bonus);
179 }
180 }
181 }
182
183 @Override
184 protected void applyNoAICoreModifiers() {
185 if (market.isPlayerOwned()) {
186 SubmarketPlugin sub = Misc.getLocalResources(market);
187 if (sub instanceof LocalResourcesSubmarketPlugin) {
188 LocalResourcesSubmarketPlugin lr = (LocalResourcesSubmarketPlugin) sub;
189 lr.getStockpilingBonus(Commodities.FUEL).unmodifyFlat(getModId(1));
190 lr.getStockpilingBonus(Commodities.SUPPLIES).unmodifyFlat(getModId(1));
191 lr.getStockpilingBonus(Commodities.CREW).unmodifyFlat(getModId(1));
192 }
193 }
194 }
195
196 @Override
198 demandReduction.modifyFlat(getModId(0), DEMAND_REDUCTION, "Alpha core");
199 }
200
201 protected void addAlphaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode) {
202 float opad = 10f;
203 Color highlight = Misc.getHighlightColor();
204
205 String pre = "Alpha-level AI core currently assigned. ";
206 if (mode == AICoreDescriptionMode.MANAGE_CORE_DIALOG_LIST || mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
207 pre = "Alpha-level AI core. ";
208 }
209 float a = ALPHA_CORE_ACCESSIBILITY;
210 String aStr = "" + (int)Math.round(a * 100f) + "%";
211
212 if (mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
213 CommoditySpecAPI coreSpec = Global.getSettings().getCommoditySpec(aiCoreId);
214 TooltipMakerAPI text = tooltip.beginImageWithText(coreSpec.getIconName(), 48);
215 text.addPara(pre + "Reduces upkeep cost by %s. Reduces demand by %s unit. " +
216 "Greatly increases stockpiles.", 0f, highlight,
217 "" + (int)((1f - UPKEEP_MULT) * 100f) + "%", "" + DEMAND_REDUCTION,
218 aStr);
219 tooltip.addImageWithText(opad);
220 return;
221 }
222
223 tooltip.addPara(pre + "Reduces upkeep cost by %s. Reduces demand by %s unit. " +
224 "Greatly increases stockpiles.", opad, highlight,
225 "" + (int)((1f - UPKEEP_MULT) * 100f) + "%", "" + DEMAND_REDUCTION,
226 aStr);
227
228 }
229
230
231 public boolean isAvailableToBuild() {
232 return market.hasSpaceport();
233 }
234
235 public String getUnavailableReason() {
236 return "Requires a functional spaceport";
237 }
238
239
240 @Override
241 public boolean canImprove() {
242 return true;
243 }
244
245 protected void applyImproveModifiers() {
246 if (isImproved()) {
247 market.getAccessibilityMod().modifyFlat(getModId(3), IMPROVE_ACCESSIBILITY,
249 } else {
250 market.getAccessibilityMod().unmodifyFlat(getModId(3));
251 }
252 }
253
254 public void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode) {
255 float opad = 10f;
256 Color highlight = Misc.getHighlightColor();
257
258 float a = IMPROVE_ACCESSIBILITY;
259 String aStr = "" + (int)Math.round(a * 100f) + "%";
260
261 if (mode == ImprovementDescriptionMode.INDUSTRY_TOOLTIP) {
262 info.addPara("Accessibility increased by %s.", 0f, highlight, aStr);
263 } else {
264 info.addPara("Increases accessibility by %s.", 0f, highlight, aStr);
265 }
266
267 info.addSpacer(opad);
268 super.addImproveDesc(info, mode);
269 }
270}
271
272
273
274
static SettingsAPI getSettings()
Definition Global.java:51
Map< String, MutableCommodityQuantity > supply
Map< String, MutableCommodityQuantity > demand
Pair< String, Integer > getMaxDeficit(String ... commodityIds)
void addAlphaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode)
void addPostDescriptionSection(TooltipMakerAPI tooltip, IndustryTooltipMode mode)
void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode)
float getUpkeepPenalty(Pair< String, Integer > deficit)
boolean hasPostDemandSection(boolean hasDemand, IndustryTooltipMode mode)
void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode)
CommoditySpecAPI getCommoditySpec(String commodityId)