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
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;
55 }
59
66
67
71 public static void setBrokeDeal(boolean broke) {
73 }
74
75
76
77
78
79
80
86
88 return "";
89 }
90
91 @Override
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 }
113 }
114
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 }
139 }
140
141
142 @Override
143 public int getMaxNumFleets(StarSystemAPI system) {
144 return Global.getSettings().getInt("luddicChurchMaxFleets");
145 }
146
147
148 @Override
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
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);
178 m.triggerSetFleetFlag("$sacredProtectors");
179
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
201 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
203 info.addPara("Impending Luddic Church takeover operation", initPad, tc, c, "Luddic Church");
204 }
205
207 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
208 info.addPara("Luddic Church takeover averted", tc, initPad);
209 }
210
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");
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");
232
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
240 }
241
242
243 public String getEventStageIcon(HostileActivityEventIntel intel, EventStageData stage) {
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
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 hesperus = Global.getSector().getEconomy().getMarket("hesperus");
313 if (hesperus == null || hesperus.hasCondition(Conditions.DECIVILIZED) ||
314 !hesperus.getFactionId().equals(Factions.LUDDIC_CHURCH)) {
315 return null;
316 }
317 if (requireMilitaryBase) {
319 if (b == null) b = hesperus.getIndustry(Industries.HIGHCOMMAND);
320 if (b == null || b.isDisrupted() || !b.isFunctional()) {
321 return null;
322 }
323 }
324 return hesperus;
325 }
326
327
328 public boolean startExpedition(MarketAPI source, MarketAPI target, EventStageData stage, Random random) {
329
330 GenericRaidParams params = new GenericRaidParams(new Random(random.nextLong()), true);
331 params.factionId = source.getFactionId();
332 params.source = source;
333
334 params.prepDays = 7f + random.nextFloat() * 14f;
335 params.payloadDays = 180f;
336
337 params.makeFleetsHostile = false;
338
339 FGBlockadeParams bParams = new FGBlockadeParams();
340 bParams.where = target.getStarSystem();
341 bParams.targetFaction = Factions.PLAYER;
342 bParams.specificMarket = target;
343
344 params.noun = "takeover";
345 params.forcesNoun = "Luddic forces";
346
347 params.style = FleetStyle.STANDARD;
348
349
350 params.fleetSizes.add(10); // first size 10 pick becomes the Armada
351
352 // and a few smaller picket forces
353 params.fleetSizes.add(4);
354 params.fleetSizes.add(4);
355 params.fleetSizes.add(3);
356 params.fleetSizes.add(3);
357
358
360 blockade.setListener(this);
362
363 return true;
364 }
365
369
370
371
372 @Override
376
377 public void notifyEventEnding() {
379 }
380
381
383 TempData actionData, CargoAPI cargo) {
384
385 }
386
387 public void reportRaidToDisruptFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData, Industry industry) {
388
389 }
390
391 public void reportTacticalBombardmentFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData) {
392 MarketAPI hesperus = getHesperus(false);
393 if (market != null && market == hesperus) {
394 EventStageData stage = intel.getDataFor(Stage.HA_EVENT);
395 if (stage != null) {
396 boolean thisEvent = stage.rollData instanceof HAERandomEventData &&
397 ((HAERandomEventData)stage.rollData).factor == this;
398 // no points if takeover expedition is the event since it'll lead to a reset anyway
399 if (!thisEvent) {
400 int points = Global.getSettings().getInt("HA_tacBombardHesperus");
401 if (points > 0) {
403 }
404 }
405 }
406
407 }
408 }
409
410 public void reportSaturationBombardmentFinished(InteractionDialogAPI dialog, MarketAPI market, TempData actionData) {
411
412 }
413
414 @Override
415 public void advance(float amount) {
416 super.advance(amount);
417
418// if (!Global.getSector().getListenerManager().hasListener(this)) {
419// Global.getSector().getListenerManager().addListener(this);
420// }
421
422 EventStageData stage = intel.getDataFor(Stage.HA_EVENT);
423 if (stage != null && stage.rollData instanceof HAERandomEventData &&
424 ((HAERandomEventData)stage.rollData).factor == this) {
425 MarketAPI hesperus = getHesperus(true);
426
427 if (hesperus == null) {
429 }
430 }
431 }
432 public void reportColonySizeChanged(MarketAPI market, int prevSize) {
433 if (!market.isPlayerOwned()) return;
434
435 boolean matches = LuddicMajority.matchesBonusConditions(market);
436
437 if (market.hasCondition(Conditions.LUDDIC_MAJORITY) && !matches) {
439 } else if (!market.hasCondition(Conditions.LUDDIC_MAJORITY) && matches) {
441 }
442
443 }
444
445
446
447}
448
449
450
451
static SettingsAPI getSettings()
Definition Global.java:57
static SectorAPI getSector()
Definition Global.java:65
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)
void createStandardFleet(int difficulty, String factionId, Vector2f locInHyper)
static List< MarketAPI > getMarketsInLocation(LocationAPI location, String factionId)
Definition Misc.java:936
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color getGrayColor()
Definition Misc.java:826
static List< MarketAPI > getPlayerMarkets(boolean includeNonPlayerFaction)
Definition Misc.java:980
static Color getPositiveHighlightColor()
Definition Misc.java:822
void setNoFactionInName(boolean noFactionInName)
FactionAPI getFaction(String factionId)
ListenerManagerAPI getListenerManager()
void addScript(EveryFrameScript script)
void set(String key, Object value)
void setHighlight(int start, int end)
void setHighlightColors(Color ... colors)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)