Starsector API
Loading...
Searching...
No Matches
Spaceport.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.econ.CommoditySpecAPI;
7import com.fs.starfarer.api.campaign.econ.MarketAPI;
8import com.fs.starfarer.api.campaign.econ.MarketImmigrationModifier;
9import com.fs.starfarer.api.combat.MutableStat;
10import com.fs.starfarer.api.impl.campaign.ids.Commodities;
11import com.fs.starfarer.api.impl.campaign.ids.Industries;
12import com.fs.starfarer.api.impl.campaign.ids.Stats;
13import com.fs.starfarer.api.impl.campaign.intel.events.ht.HyperspaceTopographyEventIntel;
14import com.fs.starfarer.api.impl.campaign.intel.events.ht.HyperspaceTopographyEventIntel.Stage;
15import com.fs.starfarer.api.impl.campaign.population.PopulationComposition;
16import com.fs.starfarer.api.ui.Alignment;
17import com.fs.starfarer.api.ui.TooltipMakerAPI;
18import com.fs.starfarer.api.util.Misc;
19import com.fs.starfarer.api.util.Pair;
20
21
22
23public class Spaceport extends BaseIndustry implements MarketImmigrationModifier {
24
25 public static float OFFICER_PROB_MOD = 0.1f;
26 public static float OFFICER_PROB_MOD_MEGA = 0.2f;
27
28 public static float UPKEEP_MULT_PER_DEFICIT = 0.1f;
29
30 public static float BASE_ACCESSIBILITY = 0.5f;
31 public static float MEGAPORT_ACCESSIBILITY = 0.8f;
32
33 public static float ALPHA_CORE_ACCESSIBILITY = 0.2f;
34 public static float IMPROVE_ACCESSIBILITY = 0.2f;
35
36// public static final float BASE_ACCESSIBILITY = 0f;
37// public static final float MEGAPORT_ACCESSIBILITY = 0.2f;
38
39
40 public void apply() {
41 super.apply(true);
42
43 int size = market.getSize();
44
45 boolean megaport = Industries.MEGAPORT.equals(getId());
46 int extraSize = 0;
47 if (megaport) extraSize = 2;
48
49 demand(Commodities.FUEL, size - 2 + extraSize);
50 demand(Commodities.SUPPLIES, size - 2 + extraSize);
51 demand(Commodities.SHIPS, size - 2 + extraSize);
52
53 supply(Commodities.CREW, size - 1 + extraSize);
54
55
56 String desc = getNameForModifier();
57
58 Pair<String, Integer> deficit = getUpkeepAffectingDeficit();
59
60 if (deficit.two > 0) {
61 float loss = getUpkeepPenalty(deficit);
62 getUpkeep().modifyMult("deficit", 1f + loss, getDeficitText(deficit.one));
63 } else {
64 getUpkeep().unmodifyMult("deficit");
65 }
66
67 market.setHasSpaceport(true);
68
69 float a = BASE_ACCESSIBILITY;
70 if (megaport) {
72 }
73 if (a > 0) {
74 market.getAccessibilityMod().modifyFlat(getModId(0), a, desc);
75 }
76
77 float officerProb = OFFICER_PROB_MOD;
78 if (megaport) officerProb = OFFICER_PROB_MOD_MEGA;
79 market.getStats().getDynamic().getMod(Stats.OFFICER_PROB_MOD).modifyFlat(getModId(0), officerProb);
80 //market.getStats().getDynamic().getMod(Stats.OFFICER_IS_MERC_PROB_MOD).modifyFlat(getModId(0), officerProb);
81
82 if (!isFunctional()) {
83// if (isDisrupted() && !isBuilding()) {
84// market.getAccessibilityMod().modifyFlat(getModId(2), -1f, "Spaceport operations disrupted");
85// supply(Commodities.CREW, size - 1 + extraSize);
86// } else {
87 supply.clear();
88 unapply();
89 market.setHasSpaceport(true);
90// }
91 }
92 }
93
94 @Override
95 public void unapply() {
96 super.unapply();
97
98 market.setHasSpaceport(false);
99 market.getAccessibilityMod().unmodifyFlat(getModId(0));
100 market.getAccessibilityMod().unmodifyFlat(getModId(1));
101 market.getAccessibilityMod().unmodifyFlat(getModId(2));
102
103 market.getStats().getDynamic().getMod(Stats.OFFICER_PROB_MOD).unmodifyFlat(getModId(0));
104 //market.getStats().getDynamic().getMod(Stats.OFFICER_IS_MERC_PROB_MOD).unmodifyFlat(getModId(0));
105 }
106
107 protected float getUpkeepPenalty(Pair<String, Integer> deficit) {
108 float loss = deficit.two * UPKEEP_MULT_PER_DEFICIT;
109 if (loss < 0) loss = 0;
110 return loss;
111 }
112
113 protected Pair<String, Integer> getUpkeepAffectingDeficit() {
114 return getMaxDeficit(Commodities.FUEL, Commodities.SUPPLIES, Commodities.SHIPS);
115 }
116
117 protected boolean hasPostDemandSection(boolean hasDemand, IndustryTooltipMode mode) {
118 //return mode == IndustryTooltipMode.NORMAL && isFunctional();
119 return mode != IndustryTooltipMode.NORMAL || isFunctional();
120 }
121
122 @Override
123 protected void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode) {
124 //if (mode == IndustryTooltipMode.NORMAL && isFunctional()) {
125 if (mode != IndustryTooltipMode.NORMAL || isFunctional()) {
126 MutableStat fake = new MutableStat(0);
127
128 boolean megaport = Industries.MEGAPORT.equals(getId());
129 String desc = getNameForModifier();
130 float a = BASE_ACCESSIBILITY;
131 if (megaport) {
133 }
134 if (a > 0) {
135 fake.modifyFlat(getModId(0), a, desc);
136 }
137 float total = a;
138// Pair<String, Integer> deficit = getAccessibilityAffectingDeficit();
139// float loss = getAccessibilityPenalty(deficit);
140// if (deficit.two > 0) {
141// fake.modifyFlat(getModId(1), -loss, getDeficitText(deficit.one));
142// }
143//
144// float total = a - loss;
145 String totalStr = "+" + (int)Math.round(total * 100f) + "%";
146 Color h = Misc.getHighlightColor();
147 if (total < 0) {
148 h = Misc.getNegativeHighlightColor();
149 totalStr = "" + (int)Math.round(total * 100f) + "%";
150 }
151 float opad = 10f;
152 float pad = 3f;
153 if (total >= 0) {
154 tooltip.addPara("Accessibility bonus: %s", opad, h, totalStr);
155 } else {
156 tooltip.addPara("Accessibility penalty: %s", opad, h, totalStr);
157 }
158
159 float bonus = getPopulationGrowthBonus();
160 tooltip.addPara("Population growth: %s", opad, h, "+" + (int)bonus);
161
162 HyperspaceTopographyEventIntel intel = HyperspaceTopographyEventIntel.get();
163 if (intel != null && intel.isStageActive(Stage.SLIPSTREAM_DETECTION)) {
164 h = Misc.getHighlightColor();
165 tooltip.addSectionHeading("Hyperspace topography", Alignment.MID, opad);
166 if (!isFunctional()) {
167 tooltip.addPara("Slipstream detection requires functional Spaceport", Misc.getNegativeHighlightColor(), opad);
168 } else {
169 int range = (int) Math.round(market.getStats().getDynamic().getMod(Stats.SLIPSTREAM_REVEAL_RANGE_LY_MOD).computeEffective(0f));
170 tooltip.addPara("Slipstream detection range: %s light-years", opad, h, "" + range);
171 tooltip.addStatModGrid(tooltip.getWidthSoFar(), 50, opad, pad, market.getStats().getDynamic().getMod(Stats.SLIPSTREAM_REVEAL_RANGE_LY_MOD));
172 }
173
174 }
175
176// tooltip.addStatModGrid(400, 50, opad, pad, fake, new StatModValueGetter() {
177// public String getPercentValue(StatMod mod) {
178// return null;
179// }
180// public String getMultValue(StatMod mod) {
181// return null;
182// }
183// public Color getModColor(StatMod mod) {
184// if (mod.value < 0) return Misc.getNegativeHighlightColor();
185// return null;
186// }
187// public String getFlatValue(StatMod mod) {
188// String prefix = mod.value >= 0 ? "+" : "";
189// return prefix + (int)Math.round(mod.value * 100f) + "%";
190// }
191// });
192
193 }
194 }
195
196
198 boolean megaport = Industries.MEGAPORT.equals(getId());
199 float bonus = 2;
200 if (megaport) {
201 bonus = market.getSize();
202 }
203 return bonus;
204 }
205
206 public void modifyIncoming(MarketAPI market, PopulationComposition incoming) {
207 float bonus = getPopulationGrowthBonus();
208
209 incoming.getWeight().modifyFlat(getModId(), bonus, getNameForModifier());
210 }
211
212
213 @Override
214 protected void applyAlphaCoreModifiers() {
215 market.getAccessibilityMod().modifyFlat(getModId(2), ALPHA_CORE_ACCESSIBILITY, "Alpha core (" + getNameForModifier() + ")");
216 }
217
218 @Override
219 protected void applyNoAICoreModifiers() {
220 market.getAccessibilityMod().unmodifyFlat(getModId(2));
221 }
222
223 @Override
225 demandReduction.modifyFlat(getModId(0), DEMAND_REDUCTION, "Alpha core");
226 }
227
228 protected void addAlphaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode) {
229 float opad = 10f;
230 Color highlight = Misc.getHighlightColor();
231
232 String pre = "Alpha-level AI core currently assigned. ";
233 if (mode == AICoreDescriptionMode.MANAGE_CORE_DIALOG_LIST || mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
234 pre = "Alpha-level AI core. ";
235 }
236 float a = ALPHA_CORE_ACCESSIBILITY;
237 String aStr = "" + (int)Math.round(a * 100f) + "%";
238
239 if (mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
240 CommoditySpecAPI coreSpec = Global.getSettings().getCommoditySpec(aiCoreId);
241 TooltipMakerAPI text = tooltip.beginImageWithText(coreSpec.getIconName(), 48);
242 text.addPara(pre + "Reduces upkeep cost by %s. Reduces demand by %s unit. " +
243 "Increases accessibility by %s.", 0f, highlight,
244 "" + (int)((1f - UPKEEP_MULT) * 100f) + "%", "" + DEMAND_REDUCTION,
245 aStr);
246 tooltip.addImageWithText(opad);
247 return;
248 }
249
250 tooltip.addPara(pre + "Reduces upkeep cost by %s. Reduces demand by %s unit. " +
251 "Increases accessibility by %s.", opad, highlight,
252 "" + (int)((1f - UPKEEP_MULT) * 100f) + "%", "" + DEMAND_REDUCTION,
253 aStr);
254
255 }
256
257 @Override
258 public boolean canImprove() {
259 return true;
260 }
261
262 protected void applyImproveModifiers() {
263 // have to use a custom id - "spaceport_improve" - so that it's the same modifier when upgraded to megaport
264 if (isImproved()) {
265 market.getAccessibilityMod().modifyFlat("spaceport_improve", IMPROVE_ACCESSIBILITY,
267 } else {
268 market.getAccessibilityMod().unmodifyFlat("spaceport_improve");
269 }
270 }
271
272 public void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode) {
273 float opad = 10f;
274 Color highlight = Misc.getHighlightColor();
275
276 float a = IMPROVE_ACCESSIBILITY;
277 String aStr = "" + (int)Math.round(a * 100f) + "%";
278
279 if (mode == ImprovementDescriptionMode.INDUSTRY_TOOLTIP) {
280 info.addPara("Accessibility increased by %s.", 0f, highlight, aStr);
281 } else {
282 info.addPara("Increases accessibility by %s.", 0f, highlight, aStr);
283 }
284
285 info.addSpacer(opad);
286 super.addImproveDesc(info, mode);
287 }
288
289
290}
291
292
293
294
static SettingsAPI getSettings()
Definition Global.java:51
Map< String, MutableCommodityQuantity > supply
Map< String, MutableCommodityQuantity > demand
Pair< String, Integer > getMaxDeficit(String ... commodityIds)
void modifyIncoming(MarketAPI market, PopulationComposition incoming)
void addAlphaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode)
float getUpkeepPenalty(Pair< String, Integer > deficit)
boolean hasPostDemandSection(boolean hasDemand, IndustryTooltipMode mode)
void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode)
void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode)
CommoditySpecAPI getCommoditySpec(String commodityId)