Starsector API
Loading...
Searching...
No Matches
SindrianDiktatHostileActivityFactor.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.List;
5import java.util.Random;
6
7import org.lwjgl.util.vector.Vector2f;
8
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.IntelInfoPlugin.ListInfoMode;
13import com.fs.starfarer.api.campaign.econ.Industry;
14import com.fs.starfarer.api.campaign.econ.MarketAPI;
15import com.fs.starfarer.api.impl.campaign.ids.Conditions;
16import com.fs.starfarer.api.impl.campaign.ids.Factions;
17import com.fs.starfarer.api.impl.campaign.ids.FleetTypes;
18import com.fs.starfarer.api.impl.campaign.ids.Industries;
19import com.fs.starfarer.api.impl.campaign.ids.Stats;
20import com.fs.starfarer.api.impl.campaign.intel.events.BaseEventIntel.EventStageData;
21import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel.HAERandomEventData;
22import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel.Stage;
23import com.fs.starfarer.api.impl.campaign.intel.events.TriTachyonStandardActivityCause.CompetitorData;
24import com.fs.starfarer.api.impl.campaign.intel.group.FGRaidAction.FGRaidType;
25import com.fs.starfarer.api.impl.campaign.intel.group.FleetGroupIntel;
26import com.fs.starfarer.api.impl.campaign.intel.group.FleetGroupIntel.FGIEventListener;
27import com.fs.starfarer.api.impl.campaign.intel.group.GenericRaidFGI.GenericRaidParams;
28import com.fs.starfarer.api.impl.campaign.intel.group.SindrianDiktatPunitiveExpedition;
29import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission;
30import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission.FleetStyle;
31import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.MarketCMD.BombardType;
32import com.fs.starfarer.api.ui.LabelAPI;
33import com.fs.starfarer.api.ui.TooltipMakerAPI;
34import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
35import com.fs.starfarer.api.util.CountingMap;
36import com.fs.starfarer.api.util.Misc;
37
39 implements FGIEventListener {
40
41 public static String DEFEATED_DIKTAT_ATTACK = "$defeatedDiktatAttack";
42 public static String MADE_DIKTAT_DEAL = "$makeDiktatDeal";
43 public static String BROKE_DIKTAT_DEAL = "$brokeDiktatDeal";
44
45 public static String RAIDER_FLEET = "$diktatRaider";
46
47 public static boolean isMadeDeal() {
48 return Global.getSector().getPlayerMemoryWithoutUpdate().getBoolean(MADE_DIKTAT_DEAL);
49 }
50 public static void setMadeDeal(boolean value) {
51 Global.getSector().getPlayerMemoryWithoutUpdate().set(MADE_DIKTAT_DEAL, value);
52 }
53
54 public static boolean brokeDeal() {
55 return Global.getSector().getPlayerMemoryWithoutUpdate().getBoolean(BROKE_DIKTAT_DEAL);
56 }
57 public static void setBrokeDeal(boolean broke) {
58 Global.getSector().getPlayerMemoryWithoutUpdate().set(BROKE_DIKTAT_DEAL, broke);
59 }
60
61 public static boolean isPlayerDefeatedDiktatAttack() {
62 return Global.getSector().getPlayerMemoryWithoutUpdate().getBoolean(DEFEATED_DIKTAT_ATTACK);
63 }
64 public static void setPlayerDefeatedDiktatAttack() {
65 Global.getSector().getPlayerMemoryWithoutUpdate().set(DEFEATED_DIKTAT_ATTACK, true);
66 }
67
69 super(intel);
70
71 //Global.getSector().getListenerManager().addListener(this);
72 }
73
75 return "";
76 }
77
78 public String getDesc(BaseEventIntel intel) {
79 return "Sindrian Diktat";
80 }
81
82 public String getNameForThreatList(boolean first) {
83 return "Sindrian Diktat";
84 }
85
86
88 if (getProgress(intel) <= 0) {
89 return Misc.getGrayColor();
90 }
91 return Global.getSector().getFaction(Factions.DIKTAT).getBaseUIColor();
92 }
93
94 public TooltipCreator getMainRowTooltip(BaseEventIntel intel) {
95 return new BaseFactorTooltip() {
96 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
97 float opad = 10f;
98 tooltip.addPara("You've attracted the attention of the Sindrian Diktat.", 0f);
99
100 tooltip.addPara("Sindrian raider fleets have been sighted in your space, "
101 + "attacking trade fleets regardless of their factional allegiance.", opad);
102 }
103 };
104 }
105
107 return getProgress(intel) > 0;
108 }
109
110 @Override
112 if (!checkFactionExists(Factions.DIKTAT, true)) {
113 return 0;
114 }
115 return super.getProgress(intel);
116 }
117
118 public Color getNameColor(float mag) {
119 if (mag <= 0f) {
120 return Misc.getGrayColor();
121 }
122 return Global.getSector().getFaction(Factions.DIKTAT).getBaseUIColor();
123 }
124
125
126 @Override
127 public int getMaxNumFleets(StarSystemAPI system) {
128 return Global.getSettings().getInt("diktatMaxFleets");
129 }
130
131 public CampaignFleetAPI createFleet(StarSystemAPI system, Random random) {
132
133 float f = intel.getMarketPresenceFactor(system);
134
135 int difficulty = 4 + (int) Math.round(f * 4f);
136
137 FleetCreatorMission m = new FleetCreatorMission(random);
138 m.beginFleet();
139
140 Vector2f loc = system.getLocation();
141 String factionId = Factions.DIKTAT;
142
143 m.createQualityFleet(difficulty, factionId, loc);
144
145 m.triggerSetFleetType(FleetTypes.RAIDER);
146
147 m.triggerSetPirateFleet();
148 m.triggerMakeHostile();
149 m.triggerMakeNonHostileToFaction(Factions.DIKTAT);
150 m.triggerMakeNonHostileToFaction(Factions.PIRATES);
151 m.triggerMakeLowRepImpact();
152 m.triggerFleetAllowLongPursuit();
153 m.triggerMakeHostileToAllTradeFleets();
154 m.triggerMakeEveryoneJoinBattleAgainst();
155
156 m.triggerSetFleetFlag(RAIDER_FLEET);
157
158 m.triggerFleetMakeFaster(true, 0, true);
159
160 //m.triggerSetFleetMaxShipSize(3);
161
162
163 CampaignFleetAPI fleet = m.createFleet();
164
165 return fleet;
166 }
167
168
169
170
171 public void addBulletPointForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info,
172 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
173 Color c = Global.getSector().getFaction(Factions.DIKTAT).getBaseUIColor();
174 info.addPara("Impending Sindrian Diktat attack", initPad, tc, c, "Sindrian Diktat");
175 }
176
177 public void addBulletPointForEventReset(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info,
178 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
179 info.addPara("Sindrian Diktat attack averted", tc, initPad);
180 }
181
182 public void addStageDescriptionForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info) {
183 float small = 0f;
184 float opad = 10f;
185
186 small = 8f;
187
188 Color c = Global.getSector().getFaction(Factions.DIKTAT).getBaseUIColor();
189
190 Color h = Misc.getHighlightColor();
191 info.addPara("You've received intel that the Sindrian Diktat is planning an attack to "
192 + "saturation-bombard your fuel production facilities.",
193 small, Misc.getNegativeHighlightColor(), "saturation-bombard");
194
195// LabelAPI label = info.addPara("If the attack is defeated, your standing with the Hegemony "
196// + "and the independents will increase substantially, and the Diktat will likely abandon "
197// + "further efforts against you. In addition, your ability to export fuel will be improved.",
198// opad);
199// label.setHighlight("Hegemony", "independents", "increase substantially", "Diktat",
200// "ability to export fuel will be improved");
201// label.setHighlightColors(Global.getSector().getFaction(Factions.HEGEMONY).getBaseUIColor(),
202// Global.getSector().getFaction(Factions.INDEPENDENT).getBaseUIColor(),
203// Misc.getPositiveHighlightColor(),
204// Global.getSector().getFaction(Factions.DIKTAT).getBaseUIColor(),
205// Misc.getPositiveHighlightColor());
206
207 LabelAPI label = info.addPara("If the attack is defeated the Diktat will likely abandon "
208 + "further efforts against you, and your ability to export fuel will be improved.",
209 opad);
210 label.setHighlight("Diktat",
211 "export fuel", "improved");
212 label.setHighlightColors(
213 Global.getSector().getFaction(Factions.DIKTAT).getBaseUIColor(),
214 Misc.getPositiveHighlightColor(),
215 Misc.getPositiveHighlightColor());
216
217 c = Global.getSector().getFaction(Factions.DIKTAT).getBaseUIColor();
218 stage.beginResetReqList(info, true, "crisis", opad);
219 info.addPara("You go to %s and make an agreement with the Diktat", 0f, c, "Sindria");
220 info.addPara("%s is tactically bombarded", 0f, c, "Sindria");
221 info.addPara("Fuel production on %s is significantly disrupted", 0f, c, "Sindria");
222 stage.endResetReqList(info, false, "crisis", -1, -1);
223
224 addBorder(info, Global.getSector().getFaction(Factions.DIKTAT).getBaseUIColor());
225 }
226
227
228 public String getEventStageIcon(HostileActivityEventIntel intel, EventStageData stage) {
229 return Global.getSector().getFaction(Factions.DIKTAT).getCrest();
230 }
231
232 public TooltipCreator getStageTooltipImpl(final HostileActivityEventIntel intel, final EventStageData stage) {
233 if (stage.id == Stage.HA_EVENT) {
234 return getDefaultEventTooltip("Sindrian Diktat attack", intel, stage);
235 }
236 return null;
237 }
238
239 public static Industry getSindrianFuelProd() {
240 MarketAPI sindria = getSindria(false);
241 if (sindria == null) return null;
242
243 Industry prod = sindria.getIndustry(Industries.FUELPROD);
244 return prod;
245 }
246
247 public static MarketAPI getSindria(boolean requireMilitaryBase) {
248 MarketAPI sindria = Global.getSector().getEconomy().getMarket("sindria");
249 if (sindria == null || sindria.hasCondition(Conditions.DECIVILIZED)) {
250 return null;
251 }
252 if (requireMilitaryBase) {
253 Industry b = sindria.getIndustry(Industries.MILITARYBASE);
254 if (b == null) b = sindria.getIndustry(Industries.HIGHCOMMAND);
255 if (b == null || b.isDisrupted() || !b.isFunctional()) {
256 return null;
257 }
258 }
259 return sindria;
260 }
261
262
263 public float getEventFrequency(HostileActivityEventIntel intel, EventStageData stage) {
264 if (stage.id == Stage.HA_EVENT) {
265
266 if (isPlayerDefeatedDiktatAttack() || getSindria(true) == null) {
267 return 0f;
268 }
269
270 if (isMadeDeal()) return 0f;
271
272 if (SindrianDiktatPunitiveExpedition.get() != null) {
273 return 0f;
274 }
275
276 MarketAPI target = findExpeditionTarget(intel, stage);
277 MarketAPI source = getSindria(true);
278 if (target != null && source != null) {
279 return 10f;
280 }
281 }
282 return 0;
283 }
284
285
286 public void rollEvent(HostileActivityEventIntel intel, EventStageData stage) {
287 HAERandomEventData data = new HAERandomEventData(this, stage);
288 stage.rollData = data;
290 }
291
292 public boolean fireEvent(HostileActivityEventIntel intel, EventStageData stage) {
293 MarketAPI target = findExpeditionTarget(intel, stage);
294 MarketAPI source = getSindria(true);
295
296 if (source == null || target == null) {
297 return false;
298 }
299
300 stage.rollData = null;
301 return startAttack(source, target, target.getStarSystem(), stage, getRandomizedStageRandom(3));
302 }
303
304
305 public static MarketAPI findExpeditionTarget(HostileActivityEventIntel intel, EventStageData stage) {
307 CountingMap<MarketAPI> counts = new CountingMap<MarketAPI>();
308
309 for (CompetitorData curr : data) {
310 for (MarketAPI market : curr.competitorProducers) {
311 StarSystemAPI system = market.getStarSystem();
312 if (system == null) continue;
313 int weight = market.getCommodityData(curr.commodityId).getMaxSupply();
314 counts.add(market, weight);
315 }
316 }
317
318 return counts.getLargest();
319 }
320
321
322 public void reportFGIAborted(FleetGroupIntel intel) {
324
326 }
327
328
329 @Override
330 public void notifyFactorRemoved() {
331 //Global.getSector().getListenerManager().removeListener(this);
332 }
333
334 public void notifyEventEnding() {
336 }
337
338
339 @Override
340 public void advance(float amount) {
341 super.advance(amount);
342
343// float days = Misc.getDays(amount);
344
345// if (!Global.getSector().getListenerManager().hasListener(this)) {
346// Global.getSector().getListenerManager().addListener(this);
347// }
348
349// String key = "$wdfwefwe";
350// if (!Global.getSector().getMemoryWithoutUpdate().getBoolean(key)) {
351// MarketAPI target = findExpeditionTarget(intel, null);
352// MarketAPI source = getSindria(true);
353// startAttack(source, target, target.getStarSystem(), null, new Random());
354// Global.getSector().getMemoryWithoutUpdate().set(key, true);
355// }
356
357 EventStageData stage = intel.getDataFor(Stage.HA_EVENT);
358 if (stage != null && stage.rollData instanceof HAERandomEventData &&
359 ((HAERandomEventData)stage.rollData).factor == this) {
360
361 Industry prod = getSindrianFuelProd();
362 boolean prodOk = prod != null && prod.getSpecialItem() != null && !prod.isDisrupted();
363 if (getSindria(true) == null || !prodOk) {
365 }
366 }
367
368 }
369
370
371
372 public boolean startAttack(MarketAPI source, MarketAPI target, StarSystemAPI system, EventStageData stage, Random random) {
373 GenericRaidParams params = new GenericRaidParams(new Random(random.nextLong()), true);
374
375 params.makeFleetsHostile = false; // will be made hostile when they arrive, not before
376
377 params.factionId = source.getFactionId();
378 params.source = source;
379
380 params.prepDays = 14f + random.nextFloat() * 14f;
381 params.payloadDays = 27f + 7f * random.nextFloat();
382
383 params.raidParams.where = system;
384 params.raidParams.type = FGRaidType.SEQUENTIAL;
385 params.raidParams.tryToCaptureObjectives = false;
386 params.raidParams.allowedTargets.add(target);
387 params.raidParams.allowNonHostileTargets = true;
388 params.raidParams.setBombardment(BombardType.SATURATION);
389
390 params.style = FleetStyle.STANDARD;
391
392
393 // standard Askonia fleet size multiplier with no shortages/issues is a bit over 230%
394 float fleetSizeMult = source.getStats().getDynamic().getMod(Stats.COMBAT_FLEET_SIZE_MULT).computeEffective(0f);
395
396 float f = intel.getMarketPresenceFactor(system);
397
398 float totalDifficulty = fleetSizeMult * 15f * (0.6f + 0.4f * f);
399
400 if (totalDifficulty < 15) {
401 return false;
402 }
403 if (totalDifficulty > 100) {
404 totalDifficulty = 100;
405 }
406
407 totalDifficulty -= 10;
408
409 params.fleetSizes.add(10);
410
411 while (totalDifficulty > 0) {
412 int min = 6;
413 int max = 10;
414
415 //int diff = Math.round(StarSystemGenerator.getNormalRandom(random, min, max));
416 int diff = min + random.nextInt(max - min + 1);
417
418 params.fleetSizes.add(diff);
419 totalDifficulty -= diff;
420 }
421
422
423 SindrianDiktatPunitiveExpedition punex = new SindrianDiktatPunitiveExpedition(params);
424 punex.setListener(this);
425 Global.getSector().getIntelManager().addIntel(punex);
426
427// GenericRaidFGI raid = new GenericRaidFGI(params);
428// raid.setListener(this);
429// Global.getSector().getIntelManager().addIntel(raid);
430
431 return true;
432 }
433
434}
435
436
437
438
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 addBulletPointForEventReset(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
static MarketAPI findExpeditionTarget(HostileActivityEventIntel intel, EventStageData stage)
void addBulletPointForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
boolean startAttack(MarketAPI source, MarketAPI target, StarSystemAPI system, EventStageData stage, Random random)
TooltipCreator getStageTooltipImpl(final HostileActivityEventIntel intel, final EventStageData stage)
void addStageDescriptionForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info)