Starsector API
Loading...
Searching...
No Matches
TradeCenter.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.campaign.econ.SubmarketAPI;
10import com.fs.starfarer.api.impl.campaign.ids.Factions;
11import com.fs.starfarer.api.impl.campaign.ids.Submarkets;
12import com.fs.starfarer.api.impl.campaign.population.PopulationComposition;
13import com.fs.starfarer.api.ui.TooltipMakerAPI;
14import com.fs.starfarer.api.util.Misc;
15
16
17public class TradeCenter extends BaseIndustry implements MarketImmigrationModifier {
18
19 public static float BASE_BONUS = 25f;
20 public static float ALPHA_CORE_BONUS = 25f;
21 public static float IMPROVE_BONUS = 25f;
22
23 public static float STABILITY_PELANTY = 3f;
24
25 //protected transient CargoAPI savedCargo = null;
26 protected transient SubmarketAPI saved = null;
27
28 public void apply() {
29 super.apply(true);
30
31 if (isFunctional() && market.isPlayerOwned()) {
32 SubmarketAPI open = market.getSubmarket(Submarkets.SUBMARKET_OPEN);
33 if (open == null) {
34 if (saved != null) {
35 market.addSubmarket(saved);
36 } else {
37 market.addSubmarket(Submarkets.SUBMARKET_OPEN);
38 SubmarketAPI sub = market.getSubmarket(Submarkets.SUBMARKET_OPEN);
39 sub.setFaction(Global.getSector().getFaction(Factions.INDEPENDENT));
40 Global.getSector().getEconomy().forceStockpileUpdate(market);
41 }
42
43// if (savedCargo != null) {
44// open = market.getSubmarket(Submarkets.SUBMARKET_OPEN);
45// if (open != null) {
46// open.getCargo().clear();
47// open.getCargo().addAll(savedCargo);
48// if (open.getPlugin() instanceof BaseSubmarketPlugin) {
49// BaseSubmarketPlugin base = (BaseSubmarketPlugin) open.getPlugin();
50// base.setSinceLastCargoUpdate(0);
51// base.setSinceSWUpdate(0);
52// }
53// }
54// }
55 }
56 } else if (market.isPlayerOwned()) {
57 market.removeSubmarket(Submarkets.SUBMARKET_OPEN);
58 }
59
60 //modifyStabilityWithBaseMod();
61 market.getStability().modifyFlat(getModId(), -STABILITY_PELANTY, getNameForModifier());
62
63 market.getIncomeMult().modifyPercent(getModId(0), BASE_BONUS, getNameForModifier());
64
65 if (!isFunctional()) {
66 unapply();
67 }
68 }
69
70
71 @Override
72 public void unapply() {
73 super.unapply();
74
75 if (market.isPlayerOwned()) {
76 SubmarketAPI open = market.getSubmarket(Submarkets.SUBMARKET_OPEN);
77 saved = open;
78// if (open.getPlugin() instanceof BaseSubmarketPlugin) {
79// BaseSubmarketPlugin base = (BaseSubmarketPlugin) open.getPlugin();
80// if (base.getSinceLastCargoUpdate() < 30) {
81// savedCargo = open.getCargo();
82// }
83// }
84 market.removeSubmarket(Submarkets.SUBMARKET_OPEN);
85 }
86
87 market.getStability().unmodifyFlat(getModId());
88
89 market.getIncomeMult().unmodifyPercent(getModId(0));
90 }
91
92 protected void addStabilityPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode) {
93 Color h = Misc.getHighlightColor();
94 float opad = 10f;
95
96 float a = BASE_BONUS;
97 String aStr = "+" + (int)Math.round(a * 1f) + "%";
98 tooltip.addPara("Colony income: %s", opad, h, aStr);
99
100 h = Misc.getNegativeHighlightColor();
101 tooltip.addPara("Stability penalty: %s", opad, h, "" + -(int)STABILITY_PELANTY);
102 }
103
104 @Override
105 protected void addRightAfterDescriptionSection(TooltipMakerAPI tooltip, IndustryTooltipMode mode) {
106 if (market.isPlayerOwned() || currTooltipMode == IndustryTooltipMode.ADD_INDUSTRY) {
107 tooltip.addPara("Adds an independent \'Open Market\' that the colony's owner is able to trade with. "
108 + "A low-level semi-permanent bounty on all hostile fleets may be posted as well.", 10f);
109 }
110 }
111
112 @Override
113 protected void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode) {
114 if (mode != IndustryTooltipMode.NORMAL || isFunctional()) {
115 addStabilityPostDemandSection(tooltip, hasDemand, mode);
116 }
117 }
118
119 public void modifyIncoming(MarketAPI market, PopulationComposition incoming) {
120 incoming.add(Factions.TRITACHYON, 10f);
121 }
122
123
124 public boolean isAvailableToBuild() {
125 return market.hasSpaceport();
126 }
127
128 public String getUnavailableReason() {
129 return "Requires a functional spaceport";
130 }
131
132 @Override
133 public String getCurrentImage() {
134 float size = market.getSize();
135 if (size <= SIZE_FOR_SMALL_IMAGE) {
136 return Global.getSettings().getSpriteName("industry", "commerce_low");
137 }
138 if (size >= SIZE_FOR_LARGE_IMAGE) {
139 return Global.getSettings().getSpriteName("industry", "commerce_high");
140 }
141
142 return super.getCurrentImage();
143 }
144
145
146 //market.getIncomeMult().modifyMult(id, INCOME_MULT, "Industrial planning");
147 @Override
148 protected void applyAlphaCoreModifiers() {
149 market.getIncomeMult().modifyPercent(getModId(1), ALPHA_CORE_BONUS, "Alpha core (" + getNameForModifier() + ")");
150 }
151
152 @Override
153 protected void applyNoAICoreModifiers() {
154 market.getIncomeMult().unmodifyPercent(getModId(1));
155 }
156
157 @Override
159 demandReduction.modifyFlat(getModId(0), DEMAND_REDUCTION, "Alpha core");
160 }
161
162 protected void addAlphaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode) {
163 float opad = 10f;
164 Color highlight = Misc.getHighlightColor();
165
166 String pre = "Alpha-level AI core currently assigned. ";
167 if (mode == AICoreDescriptionMode.MANAGE_CORE_DIALOG_LIST || mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
168 pre = "Alpha-level AI core. ";
169 }
170 float a = ALPHA_CORE_BONUS;
171 String str = "" + (int) Math.round(a) + "%";
172
173 if (mode == AICoreDescriptionMode.INDUSTRY_TOOLTIP) {
174 CommoditySpecAPI coreSpec = Global.getSettings().getCommoditySpec(aiCoreId);
175 TooltipMakerAPI text = tooltip.beginImageWithText(coreSpec.getIconName(), 48);
176 text.addPara(pre + "Reduces upkeep cost by %s. Reduces demand by %s unit. " +
177 "Increases colony income by %s.", 0f, highlight,
178 "" + (int)((1f - UPKEEP_MULT) * 100f) + "%", "" + DEMAND_REDUCTION,
179 str);
180 tooltip.addImageWithText(opad);
181 return;
182 }
183
184 tooltip.addPara(pre + "Reduces upkeep cost by %s. Reduces demand by %s unit. " +
185 "Increases colony income by %s.", opad, highlight,
186 "" + (int)((1f - UPKEEP_MULT) * 100f) + "%", "" + DEMAND_REDUCTION,
187 str);
188
189 }
190
191
192 @Override
193 public boolean canImprove() {
194 return true;
195 }
196
197 protected void applyImproveModifiers() {
198 if (isImproved()) {
199 market.getIncomeMult().modifyPercent(getModId(2), IMPROVE_BONUS,
201 } else {
202 market.getIncomeMult().unmodifyPercent(getModId(2));
203 }
204 }
205
206 public void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode) {
207 float opad = 10f;
208 Color highlight = Misc.getHighlightColor();
209
210 float a = IMPROVE_BONUS;
211 String aStr = "" + (int)Math.round(a * 1f) + "%";
212
213 if (mode == ImprovementDescriptionMode.INDUSTRY_TOOLTIP) {
214 info.addPara("Colony income increased by %s.", 0f, highlight, aStr);
215 } else {
216 info.addPara("Increases colony income by %s.", 0f, highlight, aStr);
217 }
218
219 info.addSpacer(opad);
220 super.addImproveDesc(info, mode);
221 }
222}
223
224
225
226
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
void addStabilityPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode)
void addImproveDesc(TooltipMakerAPI info, ImprovementDescriptionMode mode)
void addAlphaCoreDescription(TooltipMakerAPI tooltip, AICoreDescriptionMode mode)
void modifyIncoming(MarketAPI market, PopulationComposition incoming)
void addRightAfterDescriptionSection(TooltipMakerAPI tooltip, IndustryTooltipMode mode)
void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode)
String getSpriteName(String category, String id)
CommoditySpecAPI getCommoditySpec(String commodityId)