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.econ.impl.ConstructionQueue.ConstructionQueueItem;
11import com.fs.starfarer.api.impl.campaign.ids.Conditions;
12import com.fs.starfarer.api.impl.campaign.ids.Factions;
13import com.fs.starfarer.api.impl.campaign.ids.Industries;
14import com.fs.starfarer.api.impl.campaign.ids.People;
15import com.fs.starfarer.api.impl.campaign.intel.events.LuddicChurchHostileActivityFactor;
16import com.fs.starfarer.api.impl.campaign.population.PopulationComposition;
17import com.fs.starfarer.api.loading.IndustrySpecAPI;
18import com.fs.starfarer.api.ui.TooltipMakerAPI;
19import com.fs.starfarer.api.util.Misc;
20
22
23 public static float STABILITY = 1f;
24 public static float IMMIGRATION_BASE = 5f;
25
26 public static float PRODUCTION_BASE_RURAL = 1f;
27 public static Map<String, Integer> PRODUCTION_OVERRIDES = new LinkedHashMap<String, Integer>();
28 // makes explaining the effect more complicated; don't do it
29 static {
30 //PRODUCTION_OVERRIDES.put(Industries.FARMING, 2);
31 }
32
33 public static int BONUS_MULT_DEFEATED_EXPEDITION = 2;
34
35
36 @Deprecated
37 public static String [] luddicFactions = new String [] {
38 "knights_of_ludd",
39 "luddic_church",
40 "luddic_path",
41 };
42
43
44 public void apply(String id) {
46 unapply(id);
47 return;
48 }
49
51
52 int stability = (int) Math.round(STABILITY * getEffectMult());
53 if (stability != 0) {
54 market.getStability().modifyFlat(id, stability, "Luddic majority");
55 }
56
57 float mult = getEffectMult();
58 for (Industry ind : market.getIndustries()) {
59 if (ind.getSpec().hasTag(Industries.TAG_RURAL) || PRODUCTION_OVERRIDES.containsKey(ind.getId())) {
60 int production = (int) Math.round(PRODUCTION_BASE_RURAL * mult);
61 if (PRODUCTION_OVERRIDES.containsKey(ind.getId())) {
62 production = (int) Math.round(PRODUCTION_OVERRIDES.get(ind.getId()) * mult);
63 }
64 if (production != 0) {
65 ind.getSupplyBonusFromOther().modifyFlat(id, production, "Luddic majority");
66 }
67 }
68 }
69 }
70
71 public void unapply(String id) {
73
75
76 for (Industry ind : market.getIndustries()) {
77 if (ind.getSpec().hasTag(Industries.TAG_RURAL) || PRODUCTION_OVERRIDES.containsKey(ind.getId())) {
78 ind.getSupplyBonusFromOther().unmodifyFlat(id);
79 }
80 }
81 }
82
84 float bonus = getImmigrationBonus(true);
85 if (bonus > 0) {
86 incoming.add(Factions.LUDDIC_CHURCH, bonus);
87 incoming.getWeight().modifyFlat(getModId(), bonus, "Luddic immigration (Luddic majority)");
88 }
89 }
90
91 public float getImmigrationBonus(boolean withEffectMult) {
92 float bonus = IMMIGRATION_BASE * market.getSize();
93 if (withEffectMult) bonus *= getEffectMult();
94 return bonus;
95 }
96
97 public float getEffectMult() {
98 if (market.isPlayerOwned() &&
101 }
102 return 1f;
103
104 }
105
106 protected void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded) {
107 super.createTooltipAfterDescription(tooltip, expanded);
108
109 String name = market.getName();
110 float opad = 10f;
111
112 tooltip.addPara("A majority of the population of " + name + " are Luddic faithful. "
113 + "This may result in a substantial boost "
114 + "to stability and productivity.", opad);
115
116 tooltip.addPara("For colonies outside the core, it may also result in increased population growth, "
117 + "from Luddic immigrants seeking to escape the sometimes oppressive influence of the Luddic Church.", opad);
118
119 tooltip.addPara("%s stability",
120 opad, Misc.getHighlightColor(),
121 "+" + (int)STABILITY);
122
123 tooltip.addPara("%s production for Farming, Light Industry, and similar",
124 opad, Misc.getHighlightColor(),
125 "+" + (int)PRODUCTION_BASE_RURAL);
126
127 if (market.isPlayerOwned()) {
128 tooltip.addPara("%s population growth",
129 opad, Misc.getHighlightColor(),
130 "+" + (int) getImmigrationBonus(false));
131 }
132
134 addConditions(tooltip, market, opad);
135 }
136 }
137
138 public static void addConditions(TooltipMakerAPI tooltip, MarketAPI market, float opad) {
140 boolean freePort = market.isFreePort();
141 freePort = false;
142 boolean habitable = market.hasCondition(Conditions.HABITABLE);
143
144 boolean hasRural = false;
145 boolean hasIndustrial = false;
146 boolean hasMilitary = false;
147 String heavy = null;
148 String military = null;
149 String rural = null;
150
151 for (Industry ind : market.getIndustries()) {
152 if (ind.getSpec().hasTag(Industries.TAG_INDUSTRIAL)) {
153 if (heavy == null) heavy = ind.getCurrentName();
154 hasIndustrial = true;
155 }
156 if (ind.getSpec().hasTag(Industries.TAG_MILITARY) || ind.getSpec().hasTag(Industries.TAG_COMMAND)) {
157 if (military == null) military = ind.getCurrentName();
158 hasMilitary = true;
159 }
160
161 if (ind.getSpec().hasTag(Industries.TAG_RURAL)) {
162 if (rural == null) rural = ind.getCurrentName();
163 hasRural = true;
164 }
165 }
166
167 if (market.getConstructionQueue() != null) {
168 for (ConstructionQueueItem item : market.getConstructionQueue().getItems()) {
170 if (spec != null) {
171 if (spec.hasTag(Industries.TAG_INDUSTRIAL)) {
172 if (heavy == null) heavy = spec.getName();
173 hasIndustrial = true;
174 }
176 if (military == null) military = spec.getName();
177 hasMilitary = true;
178 }
179
180 if (spec.hasTag(Industries.TAG_RURAL)) {
181 if (rural == null) rural = spec.getName();
182 hasRural = true;
183 }
184 }
185 break;
186 }
187 }
188
189 boolean matches = matchesBonusConditions(market);
190
191 if (!matches) {
192 if (market.isPlayerOwned()) {
193 tooltip.addPara("The following factors result in these bonuses being negated, and, "
194 + "unless addressed, will result in the \"Luddic Majority\" condition "
195 + "being removed if the colony increases in size:", opad,
196 Misc.getNegativeHighlightColor(), "negated", "removed");
197 } else {
198 tooltip.addPara("The following factors result in these bonuses being negated:", opad,
199 Misc.getNegativeHighlightColor(), "negated", "removed");
200 }
201 //opad = 5f;
202 tooltip.setBulletedListMode(" - ");
203 if (market.getAdmin() != null && market.getAdmin().getId().equals(People.DARDAN_KATO)) {
204 tooltip.addPara("Dardan Kato's \"policies\"", opad);
205 opad = 0f;
206 }
207 if (madeDeal) {
208 tooltip.addPara("Deal made with Luddic Church to curtail immigration", opad);
209 opad = 0f;
210 }
211 if (freePort) {
212 tooltip.addPara("The colony is a free port", opad);
213 opad = 0f;
214 }
215 if (!habitable) {
216 tooltip.addPara("The colony is not habitable", opad);
217 opad = 0f;
218 }
219 if (!hasRural) {
220 tooltip.addPara("The colony has no suitable employment for the faithful, such as farming or light industry", opad);
221 opad = 0f;
222 }
223 if (hasIndustrial) {
224 tooltip.addPara("The colony has heavy industrial facilities (" + heavy + ")", opad);
225 opad = 0f;
226 }
227 if (hasMilitary) {
228 tooltip.addPara("The colony has military facilities (" + military + ")", opad);
229 opad = 0f;
230 }
231 tooltip.setBulletedListMode(null);
232 } else {
234 tooltip.addPara("The bonus is doubled due to the faithful " + market.getOnOrAt() + " " +
235 market.getName() + " feeling securely out from under the direct "
236 + "influence of the Luddic Church.", opad, Misc.getPositiveHighlightColor(), "doubled");
237 }
238 }
239
240 tooltip.setBulletedListMode(" - ");
241 tooltip.setBulletedListMode(null);
242 }
243
244
245 public static boolean matchesBonusConditions(MarketAPI market) {
247
248 // feels a bit too restrictive
249 //if (market.isFreePort()) return false;
250
251 if (!market.hasCondition(Conditions.HABITABLE)) return false;
252
253 if (market.getAdmin() != null && market.getAdmin().getId().equals(People.DARDAN_KATO)) {
254 // he's that dumb about it
255 return false;
256 }
257
258 boolean hasRural = false;
259 for (Industry ind : market.getIndustries()) {
260 if (ind.getSpec().hasTag(Industries.TAG_INDUSTRIAL)) return false;
261 if (ind.getSpec().hasTag(Industries.TAG_MILITARY)) return false;
262 if (ind.getSpec().hasTag(Industries.TAG_COMMAND)) return false;
263
264 hasRural |= ind.getSpec().hasTag(Industries.TAG_RURAL);
265 }
266
267 if (market.getConstructionQueue() != null) {
268 for (ConstructionQueueItem item : market.getConstructionQueue().getItems()) {
270 if (spec != null) {
271 if (spec.hasTag(Industries.TAG_INDUSTRIAL)) return false;
272 if (spec.hasTag(Industries.TAG_MILITARY) || spec.hasTag(Industries.TAG_COMMAND)) return false;
273 }
274 break;
275 }
276 }
277
278 return hasRural;
279 }
280
281 public String getIconName() {
282 if (!matchesBonusConditions(market)) {// && market.isPlayerOwned()) {
283 return Global.getSettings().getSpriteName("events", "luddic_majority_unhappy");
284 }
285 return super.getIconName();
286 }
287}
288
289
290
291
292
293
294
295
static SettingsAPI getSettings()
Definition Global.java:57
static boolean CODEX_TOOLTIP_MODE
Definition Global.java:15
void modifyFlat(String source, float value)
void modifyIncoming(MarketAPI market, PopulationComposition incoming)
void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded)
static void addConditions(TooltipMakerAPI tooltip, MarketAPI market, float opad)
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color getHighlightColor()
Definition Misc.java:792
static Color getPositiveHighlightColor()
Definition Misc.java:822
String getSpriteName(String category, String id)
IndustrySpecAPI getIndustrySpec(String industryId)
void addTransientImmigrationModifier(MarketImmigrationModifier mod)
MutableStatWithTempMods getStability()
void removeTransientImmigrationModifier(MarketImmigrationModifier mod)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
void setBulletedListMode(String itemPrefix)