Starsector API
Loading...
Searching...
No Matches
LuddicMajority.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.econ;
2
3import java.util.LinkedHashMap;
4import java.util.Map;
5
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.econ.Industry;
8import com.fs.starfarer.api.campaign.econ.MarketAPI;
9import com.fs.starfarer.api.campaign.econ.MarketImmigrationModifier;
10import com.fs.starfarer.api.impl.campaign.ids.Conditions;
11import com.fs.starfarer.api.impl.campaign.ids.Factions;
12import com.fs.starfarer.api.impl.campaign.ids.Industries;
13import com.fs.starfarer.api.impl.campaign.intel.events.LuddicChurchHostileActivityFactor;
14import com.fs.starfarer.api.impl.campaign.population.PopulationComposition;
15import com.fs.starfarer.api.ui.TooltipMakerAPI;
16import com.fs.starfarer.api.util.Misc;
17
18public class LuddicMajority extends BaseMarketConditionPlugin implements MarketImmigrationModifier {
19
20 public static float STABILITY = 1f;
21 public static float IMMIGRATION_BASE = 5f;
22
23 public static float PRODUCTION_BASE_RURAL = 1f;
24 public static Map<String, Integer> PRODUCTION_OVERRIDES = new LinkedHashMap<String, Integer>();
25 // makes explaining the effect more complicated; don't do it
26 static {
27 //PRODUCTION_OVERRIDES.put(Industries.FARMING, 2);
28 }
29
30 public static int BONUS_MULT_DEFEATED_EXPEDITION = 2;
31
32
33 @Deprecated
34 public static String [] luddicFactions = new String [] {
35 "knights_of_ludd",
36 "luddic_church",
37 "luddic_path",
38 };
39
40
41 public void apply(String id) {
43 unapply(id);
44 return;
45 }
46
47 market.addTransientImmigrationModifier(this);
48
49 int stability = (int) Math.round(STABILITY * getEffectMult());
50 if (stability != 0) {
51 market.getStability().modifyFlat(id, stability, "Luddic majority");
52 }
53
54 float mult = getEffectMult();
55 for (Industry ind : market.getIndustries()) {
56 if (ind.getSpec().hasTag(Industries.TAG_RURAL) || PRODUCTION_OVERRIDES.containsKey(ind.getId())) {
57 int production = (int) Math.round(PRODUCTION_BASE_RURAL * mult);
58 if (PRODUCTION_OVERRIDES.containsKey(ind.getId())) {
59 production = (int) Math.round(PRODUCTION_OVERRIDES.get(ind.getId()) * mult);
60 }
61 if (production != 0) {
62 ind.getSupplyBonusFromOther().modifyFlat(id, production, "Luddic majority");
63 }
64 }
65 }
66 }
67
68 public void unapply(String id) {
69 market.removeTransientImmigrationModifier(this);
70
71 market.getStability().unmodify(id);
72
73 for (Industry ind : market.getIndustries()) {
74 if (ind.getSpec().hasTag(Industries.TAG_RURAL) || PRODUCTION_OVERRIDES.containsKey(ind.getId())) {
75 ind.getSupplyBonusFromOther().unmodifyFlat(id);
76 }
77 }
78 }
79
80 public void modifyIncoming(MarketAPI market, PopulationComposition incoming) {
81 float bonus = getImmigrationBonus(true);
82 if (bonus > 0) {
83 incoming.add(Factions.LUDDIC_CHURCH, bonus);
84 incoming.getWeight().modifyFlat(getModId(), bonus, "Luddic immigration (Luddic majority)");
85 }
86 }
87
88 public float getImmigrationBonus(boolean withEffectMult) {
89 float bonus = IMMIGRATION_BASE * market.getSize();
90 if (withEffectMult) bonus *= getEffectMult();
91 return bonus;
92 }
93
94 public float getEffectMult() {
95 if (market.isPlayerOwned() &&
96 LuddicChurchHostileActivityFactor.isDefeatedExpedition()) {
98 }
99 return 1f;
100
101 }
102
103 protected void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded) {
104 super.createTooltipAfterDescription(tooltip, expanded);
105
106 String name = market.getName();
107 float opad = 10f;
108
109 tooltip.addPara("A majority of the population of " + name + " are Luddic faithful. "
110 + "This may result in a substantial boost "
111 + "to stability and productivity.", opad);
112
113 tooltip.addPara("For colonies outside the core, it may also result in increased population growth, "
114 + "from Luddic immigrants seeking to escape the sometimes oppressive influence of the Luddic Church.", opad);
115
116 tooltip.addPara("%s stability",
117 opad, Misc.getHighlightColor(),
118 "+" + (int)STABILITY);
119
120 tooltip.addPara("%s production for Farming, Light Industry, and similar",
121 opad, Misc.getHighlightColor(),
122 "+" + (int)PRODUCTION_BASE_RURAL);
123
124 if (market.isPlayerOwned()) {
125 tooltip.addPara("%s population growth",
126 opad, Misc.getHighlightColor(),
127 "+" + (int) getImmigrationBonus(false));
128 }
129
130 addConditions(tooltip, market, opad);
131// if (!matchesBonusConditions(market)) {
132// tooltip.addPara("The bonus is negated due to the colony not meeting certain conditions.", opad,
133// Misc.getNegativeHighlightColor(), "negated");
134// } else if (market.isPlayerOwned() && LuddicChurchHostileActivityFactor.isDefeatedExpedition()) {
135// tooltip.addPara("The bonus is doubled due to the population feeling securely out from under the direct "
136// + "influence of the Luddic Church.", opad, Misc.getPositiveHighlightColor(), "doubled");
137// }
138 }
139
140 public static void addConditions(TooltipMakerAPI tooltip, MarketAPI market, float opad) {
141 boolean madeDeal = LuddicChurchHostileActivityFactor.isMadeDeal() && market.isPlayerOwned();
142 boolean freePort = market.isFreePort();
143 freePort = false;
144 boolean habitable = market.hasCondition(Conditions.HABITABLE);
145
146 boolean hasRural = false;
147 boolean hasIndustrial = false;
148 boolean hasMilitary = false;
149 String heavy = null;
150 String military = null;
151 String rural = null;
152
153
154 for (Industry ind : market.getIndustries()) {
155 if (ind.getSpec().hasTag(Industries.TAG_INDUSTRIAL)) {
156 if (heavy == null) heavy = ind.getCurrentName();
157 hasIndustrial = true;
158 }
159 if (ind.getSpec().hasTag(Industries.TAG_MILITARY) || ind.getSpec().hasTag(Industries.TAG_COMMAND)) {
160 if (military == null) military = ind.getCurrentName();
161 hasMilitary = true;
162 }
163
164 if (ind.getSpec().hasTag(Industries.TAG_RURAL)) {
165 if (rural == null) rural = ind.getCurrentName();
166 hasRural = true;
167 }
168 }
169
170 boolean matches = matchesBonusConditions(market);
171
172 if (!matches) {
173 if (market.isPlayerOwned()) {
174 tooltip.addPara("The following factors result in these bonuses being negated, and, "
175 + "unless addressed, will result in the \"Luddic Majority\" condition "
176 + "being removed if the colony increases in size:", opad,
177 Misc.getNegativeHighlightColor(), "negated", "removed");
178 } else {
179 tooltip.addPara("The following factors result in these bonuses being negated:", opad,
180 Misc.getNegativeHighlightColor(), "negated", "removed");
181 }
182 //opad = 5f;
183 tooltip.setBulletedListMode(" - ");
184 if (madeDeal) {
185 tooltip.addPara("Deal made with Luddic Church to curtail immigration", opad);
186 opad = 0f;
187 }
188 if (freePort) {
189 tooltip.addPara("The colony is a free port", opad);
190 opad = 0f;
191 }
192 if (!habitable) {
193 tooltip.addPara("The colony is not habitable", opad);
194 opad = 0f;
195 }
196 if (!hasRural) {
197 tooltip.addPara("The colony has no suitable employment for the faithful, such as farming or light industry", opad);
198 opad = 0f;
199 }
200 if (hasIndustrial) {
201 tooltip.addPara("The colony has heavy industrial facilities (" + heavy + ")", opad);
202 opad = 0f;
203 }
204 if (hasMilitary) {
205 tooltip.addPara("The colony has military facilities (" + military + ")", opad);
206 opad = 0f;
207 }
208 tooltip.setBulletedListMode(null);
209 } else {
210 if (market.isPlayerOwned() && LuddicChurchHostileActivityFactor.isDefeatedExpedition()) {
211 tooltip.addPara("The bonus is doubled due to the faithful " + market.getOnOrAt() + " " +
212 market.getName() + " feeling securely out from under the direct "
213 + "influence of the Luddic Church.", opad, Misc.getPositiveHighlightColor(), "doubled");
214 }
215 }
216
217 tooltip.setBulletedListMode(" - ");
218 tooltip.setBulletedListMode(null);
219 }
220
221
222 public static boolean matchesBonusConditions(MarketAPI market) {
223 if (market.isPlayerOwned() && LuddicChurchHostileActivityFactor.isMadeDeal()) return false;
224
225 // feels a bit too restrictive
226 //if (market.isFreePort()) return false;
227
228 if (!market.hasCondition(Conditions.HABITABLE)) return false;
229
230 boolean hasRural = false;
231 for (Industry ind : market.getIndustries()) {
232 if (ind.getSpec().hasTag(Industries.TAG_INDUSTRIAL)) return false;
233 if (ind.getSpec().hasTag(Industries.TAG_MILITARY)) return false;
234 if (ind.getSpec().hasTag(Industries.TAG_COMMAND)) return false;
235
236 hasRural |= ind.getSpec().hasTag(Industries.TAG_RURAL);
237 }
238 return hasRural;
239 }
240
241 public String getIconName() {
242 if (!matchesBonusConditions(market)) {// && market.isPlayerOwned()) {
243 return Global.getSettings().getSpriteName("events", "luddic_majority_unhappy");
244 }
245 return super.getIconName();
246 }
247}
248
249
250
251
252
253
254
255
static SettingsAPI getSettings()
Definition Global.java:51
void modifyIncoming(MarketAPI market, PopulationComposition incoming)
void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded)
static void addConditions(TooltipMakerAPI tooltip, MarketAPI market, float opad)
String getSpriteName(String category, String id)