1package com.fs.starfarer.api.impl.campaign.intel.events;
5import java.util.Random;
7import org.lwjgl.util.vector.Vector2f;
9import com.fs.starfarer.api.Global;
10import com.fs.starfarer.api.campaign.CampaignFleetAPI;
11import com.fs.starfarer.api.campaign.StarSystemAPI;
12import com.fs.starfarer.api.campaign.comm.CommMessageAPI.MessageClickAction;
13import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin;
14import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin.ListInfoMode;
15import com.fs.starfarer.api.campaign.econ.MarketAPI;
16import com.fs.starfarer.api.campaign.listeners.ListenerUtil;
17import com.fs.starfarer.api.campaign.listeners.PatherCellListener;
18import com.fs.starfarer.api.impl.campaign.ids.Factions;
19import com.fs.starfarer.api.impl.campaign.ids.Sounds;
20import com.fs.starfarer.api.impl.campaign.intel.MessageIntel;
21import com.fs.starfarer.api.impl.campaign.intel.bases.LuddicPathBaseIntel;
22import com.fs.starfarer.api.impl.campaign.intel.bases.LuddicPathBaseManager;
23import com.fs.starfarer.api.impl.campaign.intel.bases.LuddicPathCellsIntel;
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.FleetGroupIntel;
28import com.fs.starfarer.api.impl.campaign.intel.group.FleetGroupIntel.FGIEventListener;
29import com.fs.starfarer.api.impl.campaign.intel.group.GenericRaidFGI;
30import com.fs.starfarer.api.impl.campaign.intel.group.GenericRaidFGI.GenericRaidParams;
31import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission;
32import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission.FleetStyle;
33import com.fs.starfarer.api.impl.campaign.rulecmd.HA_CMD;
34import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.MarketCMD.BombardType;
35import com.fs.starfarer.api.ui.LabelAPI;
36import com.fs.starfarer.api.ui.TooltipMakerAPI;
37import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
38import com.fs.starfarer.api.util.Misc;
39import com.fs.starfarer.api.util.WeightedRandomPicker;
55 public static class HAPatherCellsEventData {
56 public LuddicPathCellsIntel cells;
57 public MarketAPI market;
58 public float interest;
59 public HAPatherCellsEventData(LuddicPathCellsIntel cells, MarketAPI market) {
62 interest = LuddicPathBaseManager.getLuddicPathMarketInterest(market);
81 if (first)
return "Luddic Path";
88 return Misc.getGrayColor();
90 return Global.
getSector().getFaction(Factions.LUDDIC_PATH).getBaseUIColor();
95 return Global.
getSector().getFaction(Factions.LUDDIC_PATH).getBaseUIColor();
100 public void createTooltip(TooltipMakerAPI tooltip,
boolean expanded, Object tooltipParam) {
103 tooltip.addPara(
"Advanced technology and artificial intelligence are anathema to the Luddic Path.", 0f);
104 tooltip.addPara(
"Most of the Pather fleets are small, engaging in reconnaissance and demanding tithes "
105 +
"from unwary travellers, but occasionaly a larger raiding force will make an appearance.", opad);
114 Color p = Misc.getPositiveHighlightColor();
115 Color h = Misc.getHighlightColor();
116 if (HA_CMD.playerHasPatherAgreement()) {
117 if (!HA_CMD.playerPatherAgreementIsPermanent()) {
118 float days = HA_CMD.getPlayerPatherAgreementDays();
119 if (days < 1 && days > 0) days = 1;
120 days = Math.round(days);
121 String dStr =
"days";
122 if ((
int)days == 1) dStr =
"day";
123 tooltip.addPara(
"You've %s a signficant amount to the Pathers, and their fleets and "
124 +
"ground-based cells should leave your colonies alone for another %s " + dStr +
".",
125 initPad,
new Color[] {p, h},
"tithed",
"" + (int)days);
127 tooltip.addPara(
"You've reached an understanding with the Pathers, and their fleets and "
128 +
"ground-based cells should leave your colonies alone in the future, "
129 +
"barring unexpected events.",
130 initPad, p,
"understanding");
133 tooltip.addPara(
"It's possible that you might reach some kind of understanding with the Pathers, "
134 +
"provided you find the right people to talk to.", initPad,
135 h,
"find the right people");
147 return getProgress(
intel) > 0 || (HA_CMD.playerHasPatherAgreement() && !HA_CMD.playerPatherAgreementIsPermanent());
157 public CampaignFleetAPI
createFleet(StarSystemAPI system, Random random) {
165 boolean small = random.nextFloat() < p;
170 difficulty = 1 + random.nextInt(2);
173 difficulty += (int) Math.round(f * 5f);
174 difficulty += random.nextInt(6);
178 FleetCreatorMission m =
new FleetCreatorMission(random);
181 Vector2f loc = system.getLocation();
182 String factionId = Factions.LUDDIC_PATH;
185 m.createStandardFleet(difficulty, factionId, loc);
187 m.createStandardFleet(difficulty, factionId, loc);
190 m.triggerSetPirateFleet();
191 m.triggerMakeLowRepImpact();
195 m.triggerFleetAllowLongPursuit();
198 CampaignFleetAPI fleet = m.createFleet();
214 if (stage ==
null)
return null;
215 if (stage.rollData instanceof HAERandomEventData) {
216 HAERandomEventData data = (HAERandomEventData) stage.rollData;
217 if (data.custom instanceof HAPatherCellsEventData) {
218 HAPatherCellsEventData attackData = (HAPatherCellsEventData) data.custom;
227 ListInfoMode mode,
boolean isUpdate, Color tc,
float initPad) {
230 Color c =
Global.
getSector().getFaction(Factions.LUDDIC_PATH).getBaseUIColor();
232 if (data ==
null)
return;
234 LabelAPI label = info.addPara(
"Signs of a Luddic Path attack targeting %s",
235 initPad, tc, tc, data.market.getName());
236 label.setHighlight(
"Luddic Path", data.market.getName());
237 label.setHighlightColors(c, Misc.getBasePlayerColor());
241 ListInfoMode mode,
boolean isUpdate, Color tc,
float initPad) {
242 info.addPara(
"Luddic Path attack averted", tc, initPad);
247 if (data ==
null)
return;
249 Color c =
Global.
getSector().getFaction(Factions.LUDDIC_PATH).getBaseUIColor();
256 LabelAPI label = info.addPara(
"There are signs of an impending Luddic Path attack targeting %s."
257 +
" If the attack is successful, the colony will suffer a catastrophic saturation bombardment.",
258 small, c, data.market.getName());
259 label.setHighlight(data.market.getName(),
"catastrophic saturation bombardment");
260 label.setHighlightColors(Misc.getBasePlayerColor(), Misc.getNegativeHighlightColor());
263 info.addPara(
"This attack represents a significant resource investment by the Pathers. "
264 +
"If it is defeated, Luddic Path cells Sector-wide will be disrupted.",
265 opad, Misc.getPositiveHighlightColor(),
"disrupted");
268 stage.beginResetReqList(info,
true,
"crisis", opad);
269 label = info.addPara(
"The Luddic Path cells on %s are disrupted",
270 0f, Misc.getBasePlayerColor(), data.market.getName());
271 label.setHighlight(
"Luddic Path", data.market.getName());
272 label.setHighlightColors(c, Misc.getBasePlayerColor());
274 info.addPara(
"An agreement is reached with the Luddic Path",
275 0f,
Global.
getSector().getFaction(Factions.LUDDIC_PATH).getBaseUIColor(),
"Luddic Path");
276 stage.endResetReqList(info,
false,
"crisis", -1, -1);
287 if (stage.id == Stage.HA_EVENT) {
316 if (HA_CMD.playerHasPatherAgreement())
return 0f;
318 if (stage.id == Stage.HA_EVENT) {
328 for (MarketAPI market : Misc.getPlayerMarkets(
false)) {
333 LuddicPathCellsIntel cells = LuddicPathCellsIntel.getCellsForMarket(market);
334 if (cells ==
null || cells.isSleeper())
continue;
336 float w = LuddicPathBaseManager.getLuddicPathMarketInterest(market);
337 picker.add(market, w * w);
339 return picker.pick();
354 LuddicPathCellsIntel cells = LuddicPathCellsIntel.getCellsForMarket(market);
355 if (market ==
null || cells ==
null)
return;
357 HAERandomEventData data =
new HAERandomEventData(
this, stage);
358 data.custom =
new HAPatherCellsEventData(cells, market);
359 stage.rollData = data;
367 if (data ==
null || data.market ==
null || data.cells ==
null || data.cells.isSleeper()) {
371 if (!data.market.isInEconomy())
return false;
373 LuddicPathBaseIntel base = LuddicPathCellsIntel.getClosestBase(data.market);
374 if (base ==
null)
return false;
376 StarSystemAPI system = data.market.getStarSystem();
377 if (system ==
null)
return false;
387 if (data !=
null && data.cells == cell && stage.rollData !=
null) {
398 if (
intel ==
null)
return;
402 if (data !=
null && stage.rollData !=
null) {
407 public boolean startRaid(MarketAPI source, MarketAPI target,
float interest, StarSystemAPI system, EventStageData stage, Random random) {
409 GenericRaidParams params =
new GenericRaidParams(
new Random(random.nextLong()),
true);
410 params.factionId = source.getFactionId();
411 params.source = source;
413 params.prepDays = 14f + random.nextFloat() * 14f;
414 params.payloadDays = 27f + 7f * random.nextFloat();
416 params.raidParams.where = system;
417 params.raidParams.allowedTargets.add(target);
418 params.raidParams.allowNonHostileTargets =
true;
419 params.raidParams.setBombardment(BombardType.SATURATION);
421 params.style = FleetStyle.STANDARD;
425 w += Math.max(0f, (target.getSize() - 2)) * 10f;
427 if (w > 50f) w = 50f;
430 float totalDifficulty = (0.25f + f * 0.75f) * 40f;
433 if (r.nextFloat() < 0.33f) {
434 params.style = FleetStyle.QUANTITY;
437 while (totalDifficulty > 0) {
443 int diff = (int) Math.min(10f, totalDifficulty);
444 if (diff < 2) diff = 2;
446 params.fleetSizes.add(diff);
447 totalDifficulty -= diff;
451 LuddicPathBaseIntel base = LuddicPathBaseIntel.getIntelFor(source);
453 if (Misc.isHiddenBase(source) && !base.isPlayerVisible()) {
455 base.sendUpdateIfPlayerHasIntel(LuddicPathBaseIntel.DISCOVERED_PARAM,
false);
461 GenericRaidFGI raid =
new GenericRaidFGI(params);
462 raid.setListener(
this);
472 msg.
addLine(
"Luddic Path cells disrupted", Misc.getBasePlayerColor());
475 Global.
getSector().getCampaignUI().addMessage(msg, MessageClickAction.COLONY_INFO);
477 List<IntelInfoPlugin> cells =
Global.
getSector().getIntelManager().getIntel(LuddicPathCellsIntel.class);
478 for (IntelInfoPlugin curr : cells) {
479 LuddicPathCellsIntel cell = (LuddicPathCellsIntel) curr;
483 ListenerUtil.reportCellDisrupted(cell);
static SettingsAPI getSettings()
static SectorAPI getSector()
void sendUpdateIfPlayerHasIntel(Object listInfoParam, TextPanelAPI textPanel)
void setIcon(String icon)
void addLine(String text)
void setSound(String sound)
void addBorder(TooltipMakerAPI info, Color c)
EventStageData getDataFor(Object stageId)
float getEffectMagnitude(StarSystemAPI system)
Random getRandomizedStageRandom()
TooltipCreator getDefaultEventTooltip(final String title, final HostileActivityEventIntel intel, final EventStageData stage)
HostileActivityEventIntel intel
int getProgress(BaseEventIntel intel)
static HostileActivityEventIntel get()
static void addAgreementStatus(TooltipMakerAPI tooltip, float initPad)
boolean shouldShow(BaseEventIntel intel)
void reportCellsDisrupted(LuddicPathCellsIntel cell)
float getEventFrequency(HostileActivityEventIntel intel, EventStageData stage)
void addStageDescriptionForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info)
Color getDescColor(BaseEventIntel intel)
String getProgressStr(BaseEventIntel intel)
String getNameForThreatList(boolean first)
TooltipCreator getMainRowTooltip(BaseEventIntel intel)
void addBulletPointForEventReset(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
boolean startRaid(MarketAPI source, MarketAPI target, float interest, StarSystemAPI system, EventStageData stage, Random random)
boolean fireEvent(HostileActivityEventIntel intel, EventStageData stage)
static void setPlayerDefeatedPatherExpedition()
LuddicPathHostileActivityFactor(HostileActivityEventIntel intel)
static void avertOrAbortAttack()
static HAPatherCellsEventData getPatherCellData(EventStageData stage)
void addBulletPointForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
static boolean isPlayerDefeatedPatherExpedition()
void rollEvent(HostileActivityEventIntel intel, EventStageData stage)
void notifyFactorRemoved()
TooltipCreator getStageTooltipImpl(final HostileActivityEventIntel intel, final EventStageData stage)
void reportFGIAborted(FleetGroupIntel intel)
String getEventStageIcon(HostileActivityEventIntel intel, EventStageData stage)
String getDesc(BaseEventIntel intel)
MarketAPI pickTargetMarket()
CampaignFleetAPI createFleet(StarSystemAPI system, Random random)
static String DEFEATED_PATHER_EXPEDITION
Color getNameColorForThreatList()
int getMaxNumFleets(StarSystemAPI system)
String getSpriteName(String category, String id)
float getFloat(String key)