Starsector API
Loading...
Searching...
No Matches
LuddicChurchHostileActivityFactor.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.intel.events;
2
3import java.awt.Color;
4import java.util.Random;
5
6import org.lwjgl.util.vector.Vector2f;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.campaign.CargoAPI;
11import com.fs.starfarer.api.campaign.InteractionDialogAPI;
12import com.fs.starfarer.api.campaign.StarSystemAPI;
13import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin.ListInfoMode;
14import com.fs.starfarer.api.campaign.econ.Industry;
15import com.fs.starfarer.api.campaign.econ.MarketAPI;
16import com.fs.starfarer.api.campaign.listeners.ColonyPlayerHostileActListener;
17import com.fs.starfarer.api.campaign.listeners.ColonySizeChangeListener;
18import com.fs.starfarer.api.impl.campaign.NPCHassler;
19import com.fs.starfarer.api.impl.campaign.econ.LuddicMajority;
20import com.fs.starfarer.api.impl.campaign.ids.Conditions;
21import com.fs.starfarer.api.impl.campaign.ids.Factions;
22import com.fs.starfarer.api.impl.campaign.ids.FleetTypes;
23import com.fs.starfarer.api.impl.campaign.ids.Industries;
24import com.fs.starfarer.api.impl.campaign.intel.events.BaseEventIntel.EventStageData;
25import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel.HAERandomEventData;
26import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel.Stage;
27import com.fs.starfarer.api.impl.campaign.intel.group.FGBlockadeAction.FGBlockadeParams;
28import com.fs.starfarer.api.impl.campaign.intel.group.FleetGroupIntel;
29import com.fs.starfarer.api.impl.campaign.intel.group.FleetGroupIntel.FGIEventListener;
30import com.fs.starfarer.api.impl.campaign.intel.group.GenericRaidFGI.GenericRaidParams;
31import com.fs.starfarer.api.impl.campaign.intel.group.KnightsOfLuddTakeoverExpedition;
32import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission;
33import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission.FleetStyle;
34import com.fs.starfarer.api.impl.campaign.missions.hub.HubMissionWithTriggers.FleetQuality;
35import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.MarketCMD.TempData;
36import com.fs.starfarer.api.ui.LabelAPI;
37import com.fs.starfarer.api.ui.TooltipMakerAPI;
38import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
39import com.fs.starfarer.api.util.Misc;
40import com.fs.starfarer.api.util.WeightedRandomPicker;
41
43 FGIEventListener, ColonyPlayerHostileActListener, ColonySizeChangeListener {
44
45 public static final String HASSLE_REASON = "sacredProtectors";
46
47 // in $player memory
48 public static final String DEFEATED_LUDDIC_CHURCH_EXPEDITION = "$defeatedLuddicChurchExpedition";
49 public static final String MADE_IMMIGRATION_DEAL_WITH_LUDDIC_CHURCH = "$madeImmigrationDealWithLuddicChurch";
50 public static final String BROKE_LUDDIC_CHURCH_DEAL = "$brokeLuddicChurchDeal";
51
52 public static boolean isDefeatedExpedition() {
53 //if (true) return true;
54 return Global.getSector().getPlayerMemoryWithoutUpdate().getBoolean(DEFEATED_LUDDIC_CHURCH_EXPEDITION);
55 }
56 public static void setDefeatedExpedition(boolean value) {
57 Global.getSector().getPlayerMemoryWithoutUpdate().set(DEFEATED_LUDDIC_CHURCH_EXPEDITION, value);
58 }
59
60 public static boolean isMadeDeal() {
61 return Global.getSector().getPlayerMemoryWithoutUpdate().getBoolean(MADE_IMMIGRATION_DEAL_WITH_LUDDIC_CHURCH);
62 }
63 public static void setMadeDeal(boolean value) {
64 Global.getSector().getPlayerMemoryWithoutUpdate().set(MADE_IMMIGRATION_DEAL_WITH_LUDDIC_CHURCH, value);
65 }
66
67
68 public static boolean brokeDeal() {
69 return Global.getSector().getPlayerMemoryWithoutUpdate().getBoolean(BROKE_LUDDIC_CHURCH_DEAL);
70 }
71 public static void setBrokeDeal(boolean broke) {
72 Global.getSector().getPlayerMemoryWithoutUpdate().set(BROKE_LUDDIC_CHURCH_DEAL, broke);
73 }
74
75
76
77
78
79
80
82 super(intel);
83
84 Global.getSector().getListenerManager().addListener(this);
85 }
86
88 return "";
89 }
90
91 @Override
93 if (!checkFactionExists(Factions.LUDDIC_CHURCH, true)) {
94 return 0;
95 }
96 return super.getProgress(intel);
97 }
98
99 public String getDesc(BaseEventIntel intel) {
100 return "Luddic Church";
101 }
102
103 public String getNameForThreatList(boolean first) {
104 return "Knights of Ludd";
105 }
106
107
109 if (getProgress(intel) <= 0) {
110 return Misc.getGrayColor();
111 }
112 return Global.getSector().getFaction(Factions.LUDDIC_CHURCH).getBaseUIColor();
113 }
114
115 public TooltipCreator getMainRowTooltip(BaseEventIntel intel) {
116 return new BaseFactorTooltip() {
117 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
118 float opad = 10f;
119 tooltip.addPara("A large community of the faithful -"
120 + " not under their direct control, and with potential to emerge as a major cultural center - "
121 + "is a growing source of concern to the Church. "
122 + "\"Protector\" fleets operated by the Knights of Ludd can be found in your systems, "
123 + "ostensibly there to protect the "
124 + "interests of the local Luddic population.", 0f);
125 }
126 };
127 }
128
130 return getProgress(intel) > 0;
131 }
132
133
134 public Color getNameColor(float mag) {
135 if (mag <= 0f) {
136 return Misc.getGrayColor();
137 }
138 return Global.getSector().getFaction(Factions.LUDDIC_CHURCH).getBaseUIColor();
139 }
140
141
142 @Override
143 public int getMaxNumFleets(StarSystemAPI system) {
144 return Global.getSettings().getInt("luddicChurchMaxFleets");
145 }
146
147
148 @Override
149 public float getSpawnInHyperProbability(StarSystemAPI system) {
150 return 0f;
151 }
152
153 public CampaignFleetAPI createFleet(StarSystemAPI system, Random random) {
154
155 //float f = intel.getMarketPresenceFactor(system);
156
157 int maxSize = 0;
158 for (MarketAPI curr : Misc.getMarketsInLocation(system, Factions.PLAYER)) {
159 maxSize = Math.max(curr.getSize(), maxSize);
160 }
161
162 //int difficulty = 0 + (int) Math.max(1f, Math.round(f * 6f));
163 int difficulty = maxSize + 1;
164 difficulty += random.nextInt(4);
165 if (difficulty > 10) difficulty = 10;
166
167 FleetCreatorMission m = new FleetCreatorMission(random);
168 m.beginFleet();
169
170 Vector2f loc = system.getLocation();
171 String factionId = Factions.LUDDIC_CHURCH;
172
173 m.createStandardFleet(difficulty, factionId, loc);
174 m.triggerSetFleetQuality(FleetQuality.HIGHER);
175 m.triggerSetFleetType(FleetTypes.SACRED_PROTECTORS);
176 m.triggerSetPatrol();
177 m.triggerSetFleetHasslePlayer(HASSLE_REASON);
178 m.triggerSetFleetFlag("$sacredProtectors");
179
180 m.triggerFleetAllowLongPursuit();
181 m.triggerMakeLowRepImpact();
182
183 //m.triggerMakeHostile();
184 //m.triggerMakeHostileWhileTransponderOff();
185
186 CampaignFleetAPI fleet = m.createFleet();
187
188 if (fleet != null) {
189 fleet.setName("Knights of Ludd " + fleet.getName());
190 fleet.setNoFactionInName(true);
191 NPCHassler hassle = new NPCHassler(fleet, system);
192 hassle.getParams().crDamageMult = 0f;
193 fleet.addScript(hassle);
194 }
195
196 return fleet;
197 }
198
199
200 public void addBulletPointForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info,
201 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
202 Color c = Global.getSector().getFaction(Factions.LUDDIC_CHURCH).getBaseUIColor();
203 info.addPara("Impending Luddic Church takeover operation", initPad, tc, c, "Luddic Church");
204 }
205
206 public void addBulletPointForEventReset(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info,
207 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
208 info.addPara("Luddic Church takeover averted", tc, initPad);
209 }
210
211 public void addStageDescriptionForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info) {
212 float small = 0f;
213 float opad = 10f;
214
215 small = 8f;
216
217 LabelAPI label = info.addPara("You've received intel that the Knights of Ludd, under the aegis of the Luddic Church, "
218 + "are planning an operation to take over one of your colonies that has a Luddic Majority "
219 + "population.",
220 small, Misc.getNegativeHighlightColor(), "take over one of your colonies");
221 label.setHighlight("take over one of your colonies", "Luddic Majority");
222 label.setHighlightColors(Misc.getNegativeHighlightColor(),
223 Global.getSector().getFaction(Factions.LUDDIC_CHURCH).getBaseUIColor());
224
225 label = info.addPara("If the expedition is defeated, the Luddic faithful leaving the Church worlds "
226 + "will feel more secure, resulting in increased immigration, stability, and productivity, "
227 + "and the Luddic Church will likely abandon further efforts of this sort.",
228 opad);
229 label.setHighlight("increased immigration, stability, and productivity", "Luddic Church");
230 label.setHighlightColors(Misc.getPositiveHighlightColor(),
231 Global.getSector().getFaction(Factions.LUDDIC_CHURCH).getBaseUIColor());
232
233 Color c = Global.getSector().getFaction(Factions.LUDDIC_CHURCH).getBaseUIColor();
234 stage.beginResetReqList(info, true, "crisis", opad);
235 info.addPara("You make an agreement with the Church", 0f);
236 info.addPara("%s is tactically bombarded", 0f, c, "Hesperus");
237 stage.endResetReqList(info, false, "crisis", -1, -1);
238
239 addBorder(info, Global.getSector().getFaction(Factions.LUDDIC_CHURCH).getBaseUIColor());
240 }
241
242
243 public String getEventStageIcon(HostileActivityEventIntel intel, EventStageData stage) {
244 return Global.getSector().getFaction(Factions.LUDDIC_CHURCH).getCrest();
245 }
246
247 public TooltipCreator getStageTooltipImpl(final HostileActivityEventIntel intel, final EventStageData stage) {
248 if (stage.id == Stage.HA_EVENT) {
249 return getDefaultEventTooltip("Luddic Church expedition", intel, stage);
250 }
251 return null;
252 }
253
254
255 public float getEventFrequency(HostileActivityEventIntel intel, EventStageData stage) {
256 if (stage.id == Stage.HA_EVENT) {
257 if (isDefeatedExpedition() || getHesperus(true) == null) {
258 return 0f;
259 }
260
261 if (KnightsOfLuddTakeoverExpedition.get() != null) {
262 return 0f;
263 }
264
265 MarketAPI target = findExpeditionTarget(intel, stage);
266 MarketAPI source = getExpeditionSource(intel, stage, target);
267 if (target != null && source != null) {
268 return 20f;
269 }
270 }
271 return 0;
272 }
273
274
275 public void rollEvent(HostileActivityEventIntel intel, EventStageData stage) {
276 HAERandomEventData data = new HAERandomEventData(this, stage);
277 stage.rollData = data;
279 }
280
281 public boolean fireEvent(HostileActivityEventIntel intel, EventStageData stage) {
282 MarketAPI target = findExpeditionTarget(intel, stage);
283 MarketAPI source = getExpeditionSource(intel, stage, target);
284 if (source == null || target == null) {
285 return false;
286 }
287
288 stage.rollData = null;
289 return startExpedition(source, target, stage, getRandomizedStageRandom(3));
290 }
291
292
293 public MarketAPI findExpeditionTarget(HostileActivityEventIntel intel, EventStageData stage) {
294 WeightedRandomPicker<MarketAPI> picker = new WeightedRandomPicker<MarketAPI>(getRandomizedStageRandom());
295 for (MarketAPI market : Misc.getPlayerMarkets(false)) {
296 if (market.getStarSystem() == null) continue;
297 if (market.hasCondition(Conditions.LUDDIC_MAJORITY)) {
298 float size = market.getSize();
299 float w = Math.max(size - 3f, 1f);
300 w = w * w * w;
301 picker.add(market, w);
302 }
303 }
304 return picker.pick();
305 }
306
307 public MarketAPI getExpeditionSource(HostileActivityEventIntel intel, EventStageData stage, final MarketAPI target) {
308 return getHesperus(true);
309 }
310
311 public static MarketAPI getHesperus(boolean requireMilitaryBase) {
312 MarketAPI kazeron = Global.getSector().getEconomy().getMarket("hesperus");
313 if (kazeron == null || kazeron.hasCondition(Conditions.DECIVILIZED)) {
314 return null;
315 }
316 if (requireMilitaryBase) {
317 Industry b = kazeron.getIndustry(Industries.MILITARYBASE);
318 if (b == null) b = kazeron.getIndustry(Industries.HIGHCOMMAND);
319 if (b == null || b.isDisrupted() || !b.isFunctional()) {
320 return null;
321 }
322 }
323 return kazeron;
324 }
325
326
327 public boolean startExpedition(MarketAPI source, MarketAPI target, EventStageData stage, Random random) {
328
329 GenericRaidParams params = new GenericRaidParams(new Random(random.nextLong()), true);
330 params.factionId = source.getFactionId();
331 params.source = source;
332
333 params.prepDays = 7f + random.nextFloat() * 14f;
334 params.payloadDays = 180f;
335
336 params.makeFleetsHostile = false;
337
338 FGBlockadeParams bParams = new FGBlockadeParams();
339 bParams.where = target.getStarSystem();
340 bParams.targetFaction = Factions.PLAYER;
341 bParams.specificMarket = target;
342
343 params.noun = "takeover";
344 params.forcesNoun = "Luddic forces";
345
346 params.style = FleetStyle.STANDARD;
347
348
349 params.fleetSizes.add(10); // first size 10 pick becomes the Armada
350
351 // and a few smaller picket forces
352 params.fleetSizes.add(4);
353 params.fleetSizes.add(4);
354 params.fleetSizes.add(3);
355 params.fleetSizes.add(3);
356
357
358 KnightsOfLuddTakeoverExpedition blockade = new KnightsOfLuddTakeoverExpedition(params, bParams);
359 blockade.setListener(this);
360 Global.getSector().getIntelManager().addIntel(blockade);
361
362 return true;
363 }
364
365 public void reportFGIAborted(FleetGroupIntel intel) {
367 }
368
369
370
371 @Override
372 public void notifyFactorRemoved() {
373 Global.getSector().getListenerManager().removeListener(this);
374 }
375
376 public void notifyEventEnding() {
378 }
379
380
381 public void reportRaidForValuablesFinishedBeforeCargoShown(InteractionDialogAPI dialog, MarketAPI market,
382 TempData actionData, CargoAPI cargo) {
383
384 }
385
386 public void reportRaidToDisruptFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData, Industry industry) {
387
388 }
389
390 public void reportTacticalBombardmentFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData) {
391 MarketAPI hesperus = getHesperus(false);
392 if (market != null && market == hesperus) {
393 EventStageData stage = intel.getDataFor(Stage.HA_EVENT);
394 if (stage != null) {
395 boolean thisEvent = stage.rollData instanceof HAERandomEventData &&
396 ((HAERandomEventData)stage.rollData).factor == this;
397 // no points if takeover expedition is the event since it'll lead to a reset anyway
398 if (!thisEvent) {
399 int points = Global.getSettings().getInt("HA_tacBombardHesperus");
400 if (points > 0) {
402 }
403 }
404 }
405
406 }
407 }
408
409 public void reportSaturationBombardmentFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData) {
410
411 }
412
413 @Override
414 public void advance(float amount) {
415 super.advance(amount);
416
417// if (!Global.getSector().getListenerManager().hasListener(this)) {
418// Global.getSector().getListenerManager().addListener(this);
419// }
420
421 EventStageData stage = intel.getDataFor(Stage.HA_EVENT);
422 if (stage != null && stage.rollData instanceof HAERandomEventData &&
423 ((HAERandomEventData)stage.rollData).factor == this) {
424 MarketAPI hesperus = getHesperus(true);
425
426 if (hesperus == null) {
428 }
429 }
430 }
431 public void reportColonySizeChanged(MarketAPI market, int prevSize) {
432 if (!market.isPlayerOwned()) return;
433
434 boolean matches = LuddicMajority.matchesBonusConditions(market);
435
436 if (market.hasCondition(Conditions.LUDDIC_MAJORITY) && !matches) {
437 market.removeCondition(Conditions.LUDDIC_MAJORITY);
438 } else if (!market.hasCondition(Conditions.LUDDIC_MAJORITY) && matches) {
439 market.addCondition(Conditions.LUDDIC_MAJORITY);
440 }
441
442 }
443
444
445
446}
447
448
449
450
static SettingsAPI getSettings()
Definition Global.java:51
static SectorAPI getSector()
Definition Global.java:59
void sendUpdateIfPlayerHasIntel(Object listInfoParam, TextPanelAPI textPanel)
static boolean checkFactionExists(String factionId, boolean requireMilitary)
TooltipCreator getDefaultEventTooltip(final String title, final HostileActivityEventIntel intel, final EventStageData stage)
void reportSaturationBombardmentFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData)
MarketAPI getExpeditionSource(HostileActivityEventIntel intel, EventStageData stage, final MarketAPI target)
boolean startExpedition(MarketAPI source, MarketAPI target, EventStageData stage, Random random)
void reportTacticalBombardmentFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData)
void reportRaidForValuablesFinishedBeforeCargoShown(InteractionDialogAPI dialog, MarketAPI market, TempData actionData, CargoAPI cargo)
void reportRaidToDisruptFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData, Industry industry)
void addBulletPointForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
void addBulletPointForEventReset(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
MarketAPI findExpeditionTarget(HostileActivityEventIntel intel, EventStageData stage)
TooltipCreator getStageTooltipImpl(final HostileActivityEventIntel intel, final EventStageData stage)
void addStageDescriptionForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info)