Starsector API
Loading...
Searching...
No Matches
HeavyIndustry.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.SpecialItemData;
7import com.fs.starfarer.api.campaign.econ.CommodityOnMarketAPI;
8import com.fs.starfarer.api.impl.campaign.ids.Commodities;
9import com.fs.starfarer.api.impl.campaign.ids.Conditions;
10import com.fs.starfarer.api.impl.campaign.ids.Industries;
11import com.fs.starfarer.api.impl.campaign.ids.Items;
12import com.fs.starfarer.api.impl.campaign.ids.Stats;
13import com.fs.starfarer.api.ui.TooltipMakerAPI;
14import com.fs.starfarer.api.util.Misc;
15import com.fs.starfarer.api.util.Pair;
16
17
18public class HeavyIndustry extends BaseIndustry {
19
20 public static float ORBITAL_WORKS_QUALITY_BONUS = 0.2f;
21
22 public static String POLLUTION_ID = Conditions.POLLUTION;
23 public static float DAYS_BEFORE_POLLUTION = 0f;
24 public static float DAYS_BEFORE_POLLUTION_PERMANENT = 90f;
25
26
27 public void apply() {
28 super.apply(true);
29
30 int size = market.getSize();
31
32 boolean works = Industries.ORBITALWORKS.equals(getId());
33 int shipBonus = 0;
34 float qualityBonus = 0;
35 if (works) {
36 //shipBonus = 2;
37 qualityBonus = ORBITAL_WORKS_QUALITY_BONUS;
38 }
39
40 demand(Commodities.METALS, size);
41 demand(Commodities.RARE_METALS, size - 2);
42
43 supply(Commodities.HEAVY_MACHINERY, size - 2);
44 supply(Commodities.SUPPLIES, size - 2);
45 supply(Commodities.HAND_WEAPONS, size - 2);
46 supply(Commodities.SHIPS, size - 2);
47 if (shipBonus > 0) {
48 supply(1, Commodities.SHIPS, shipBonus, "Orbital works");
49 }
50
51 Pair<String, Integer> deficit = getMaxDeficit(Commodities.METALS, Commodities.RARE_METALS);
52 int maxDeficit = size - 3; // to allow *some* production so economy doesn't get into an unrecoverable state
53 if (deficit.two > maxDeficit) deficit.two = maxDeficit;
54
55 applyDeficitToProduction(2, deficit,
56 Commodities.HEAVY_MACHINERY,
57 Commodities.SUPPLIES,
58 Commodities.HAND_WEAPONS,
59 Commodities.SHIPS);
60
61// if (market.getId().equals("chicomoztoc")) {
62// System.out.println("efwefwe");
63// }
64
65 if (qualityBonus > 0) {
66 market.getStats().getDynamic().getMod(Stats.PRODUCTION_QUALITY_MOD).modifyFlat(getModId(1), qualityBonus, "Orbital works");
67 }
68
69 float stability = market.getPrevStability();
70 if (stability < 5) {
71 float stabilityMod = (stability - 5f) / 5f;
72 stabilityMod *= 0.5f;
73 //market.getStats().getDynamic().getMod(Stats.PRODUCTION_QUALITY_MOD).modifyFlat(getModId(0), stabilityMod, "Low stability at production source");
74 market.getStats().getDynamic().getMod(Stats.PRODUCTION_QUALITY_MOD).modifyFlat(getModId(0), stabilityMod, getNameForModifier() + " - low stability");
75 }
76
77 if (!isFunctional()) {
78 supply.clear();
79 unapply();
80 }
81 }
82
83 @Override
84 public void unapply() {
85 super.unapply();
86
87 market.getStats().getDynamic().getMod(Stats.PRODUCTION_QUALITY_MOD).unmodifyFlat(getModId(0));
88 market.getStats().getDynamic().getMod(Stats.PRODUCTION_QUALITY_MOD).unmodifyFlat(getModId(1));
89 }
90
91
92 @Override
93 protected void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode) {
94 //if (mode == IndustryTooltipMode.NORMAL && isFunctional()) {
95 if (mode != IndustryTooltipMode.NORMAL || isFunctional()) {
96 boolean works = Industries.ORBITALWORKS.equals(getId());
97 if (works) {
98 float total = ORBITAL_WORKS_QUALITY_BONUS;
99 String totalStr = "+" + (int)Math.round(total * 100f) + "%";
100 Color h = Misc.getHighlightColor();
101 if (total < 0) {
102 h = Misc.getNegativeHighlightColor();
103 totalStr = "" + (int)Math.round(total * 100f) + "%";
104 }
105 float opad = 10f;
106 if (total >= 0) {
107 tooltip.addPara("Ship quality: %s", opad, h, totalStr);
108 tooltip.addPara("*Quality bonus only applies for the largest ship producer in the faction.",
109 Misc.getGrayColor(), opad);
110 }
111 }
112 }
113 }
114
115 public boolean isDemandLegal(CommodityOnMarketAPI com) {
116 return true;
117 }
118
119 public boolean isSupplyLegal(CommodityOnMarketAPI com) {
120 return true;
121 }
122
123 @Override
124 protected boolean canImproveToIncreaseProduction() {
125 return true;
126 }
127
128 @Override
129 public boolean wantsToUseSpecialItem(SpecialItemData data) {
130 if (special != null && Items.CORRUPTED_NANOFORGE.equals(special.getId()) &&
131 data != null && Items.PRISTINE_NANOFORGE.equals(data.getId())) {
132 return true;
133 }
134 return super.wantsToUseSpecialItem(data);
135 }
136
137 protected boolean permaPollution = false;
138 protected boolean addedPollution = false;
139 protected float daysWithNanoforge = 0f;
140
141 @Override
142 public void advance(float amount) {
143 super.advance(amount);
144
145 if (special != null) {
146 float days = Global.getSector().getClock().convertToDays(amount);
147 daysWithNanoforge += days;
148
150 }
151 }
152
153 protected void updatePollutionStatus() {
154 if (!market.hasCondition(Conditions.HABITABLE)) return;
155
156 if (special != null) {
158 if (market.hasCondition(POLLUTION_ID)) {
159 permaPollution = true;
160 } else {
161 market.addCondition(POLLUTION_ID);
162 addedPollution = true;
163 }
164 }
167 permaPollution = true;
168 }
169 }
170 } else if (addedPollution && !permaPollution) {
171 market.removeCondition(POLLUTION_ID);
172 addedPollution = false;
173 }
174 }
175
176 public boolean isPermaPollution() {
177 return permaPollution;
178 }
179
180 public void setPermaPollution(boolean permaPollution) {
181 this.permaPollution = permaPollution;
182 }
183
184 public boolean isAddedPollution() {
185 return addedPollution;
186 }
187
188 public void setAddedPollution(boolean addedPollution) {
189 this.addedPollution = addedPollution;
190 }
191
192 public float getDaysWithNanoforge() {
193 return daysWithNanoforge;
194 }
195
197 this.daysWithNanoforge = daysWithNanoforge;
198 }
199
200 @Override
201 public void setSpecialItem(SpecialItemData special) {
202 super.setSpecialItem(special);
203
205 }
206
207
208
209// @Override
210// public List<InstallableIndustryItemPlugin> getInstallableItems() {
211// ArrayList<InstallableIndustryItemPlugin> list = new ArrayList<InstallableIndustryItemPlugin>();
212// list.add(new GenericInstallableItemPlugin(this));
213// return list;
214// }
215
216
217}
218
219
220
221
222
223
224
225
226
static SectorAPI getSector()
Definition Global.java:59
Map< String, MutableCommodityQuantity > supply
Map< String, MutableCommodityQuantity > demand
Pair< String, Integer > getMaxDeficit(String ... commodityIds)
void applyDeficitToProduction(int index, Pair< String, Integer > deficit, String ... commodities)
void addPostDemandSection(TooltipMakerAPI tooltip, boolean hasDemand, IndustryTooltipMode mode)