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_PENALTY = 3f;
24
25 //protected transient CargoAPI savedCargo = null;
26 protected transient SubmarketAPI saved = null;
27
28 public void apply() {
29 super.apply(true);
30
33 if (open == null) {
34 if (saved != null) {
36 } else {
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()) {
58 }
59
60 //modifyStabilityWithBaseMod();
62
64
65 if (!isFunctional()) {
66 unapply();
67 }
68 }
69
70
71 @Override
72 public void unapply() {
73 super.unapply();
74
75 if (market.isPlayerOwned()) {
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// }
85 }
86
88
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
101 tooltip.addPara("Stability penalty: %s", opad, h, "" + -(int)STABILITY_PENALTY);
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
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() {
150 }
151
152 @Override
156
157 @Override
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) {
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
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:57
static SectorAPI getSector()
Definition Global.java:65
void modifyFlat(String source, float value)
void modifyPercent(String source, float value)
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)
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color getHighlightColor()
Definition Misc.java:792
String getSpriteName(String category, String id)
CommoditySpecAPI getCommoditySpec(String commodityId)
FactionAPI getFaction(String factionId)
SubmarketAPI getSubmarket(String specId)
MutableStatWithTempMods getStability()
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
UIComponentAPI addSpacer(float height)
TooltipMakerAPI beginImageWithText(String spriteName, float imageHeight)
UIPanelAPI addImageWithText(float pad)