Starsector API
Loading...
Searching...
No Matches
RemnantHostileActivityFactor.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 com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.CampaignFleetAPI;
8import com.fs.starfarer.api.campaign.StarSystemAPI;
9import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin.ListInfoMode;
10import com.fs.starfarer.api.campaign.econ.MarketAPI;
11import com.fs.starfarer.api.impl.campaign.ids.Factions;
12import com.fs.starfarer.api.impl.campaign.ids.Stats;
13import com.fs.starfarer.api.impl.campaign.intel.events.BaseEventIntel.EventStageData;
14import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel.HAERandomEventData;
15import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel.Stage;
16import com.fs.starfarer.api.impl.campaign.intel.group.FGRaidAction.FGRaidType;
17import com.fs.starfarer.api.impl.campaign.intel.group.FleetGroupIntel;
18import com.fs.starfarer.api.impl.campaign.intel.group.FleetGroupIntel.FGIEventListener;
19import com.fs.starfarer.api.impl.campaign.intel.group.GenericRaidFGI;
20import com.fs.starfarer.api.impl.campaign.intel.group.GenericRaidFGI.GenericRaidParams;
21import com.fs.starfarer.api.impl.campaign.missions.FleetCreatorMission.FleetStyle;
22import com.fs.starfarer.api.impl.campaign.missions.hub.HubMissionWithTriggers.ComplicationRepImpact;
23import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.MarketCMD.BombardType;
24import com.fs.starfarer.api.ui.LabelAPI;
25import com.fs.starfarer.api.ui.TooltipMakerAPI;
26import com.fs.starfarer.api.ui.TooltipMakerAPI.TooltipCreator;
27import com.fs.starfarer.api.util.Misc;
28import com.fs.starfarer.api.util.WeightedRandomPicker;
29
31 implements FGIEventListener {
32
34 super(intel);
35
36 //Global.getSector().getListenerManager().addListener(this);
37 }
38
40 return "";
41 }
42
43 public String getDesc(BaseEventIntel intel) {
44 return "Remnant";
45 }
46
47 public String getNameForThreatList(boolean first) {
48 return "Remnant";
49 }
50
51
53 if (getProgress(intel) <= 0) {
54 return Misc.getGrayColor();
55 }
57 }
58
60 return new BaseFactorTooltip() {
61 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded, Object tooltipParam) {
62 float opad = 10f;
63 tooltip.addPara("Remnant fleets have been sighted in your space.", opad);
64 }
65 };
66 }
67
69 return getProgress(intel) > 0;
70 }
71
72 @Override
74 return super.getProgress(intel);
75 }
76
77 public Color getNameColor(float mag) {
78 if (mag <= 0f) {
79 return Misc.getGrayColor();
80 }
82 }
83
84
85 @Override
86 public int getMaxNumFleets(StarSystemAPI system) {
87 return 0; // being spawned normally already
88 }
89
90 public CampaignFleetAPI createFleet(StarSystemAPI system, Random random) {
91
92// float f = intel.getMarketPresenceFactor(system);
93//
94// int difficulty = 4 + (int) Math.round(f * 4f);
95//
96// FleetCreatorMission m = new FleetCreatorMission(random);
97// m.beginFleet();
98//
99// Vector2f loc = system.getLocation();
100// String factionId = Factions.REMNANTS;
101//
102// m.createQualityFleet(difficulty, factionId, loc);
103//
104// m.triggerSetFleetType(FleetTypes.RAIDER);
105//
106// m.triggerSetPirateFleet();
107// m.triggerMakeHostile();
108// m.triggerMakeNonHostileToFaction(Factions.REMNANTS);
109// m.triggerMakeHostileToAllTradeFleets();
110// m.triggerMakeNonHostileToFaction(Factions.PIRATES);
111// m.triggerMakeLowRepImpact();
112// m.triggerFleetAllowLongPursuit();
113//
114// m.triggerSetFleetFlag(RAIDER_FLEET);
115//
116// m.triggerFleetMakeFaster(true, 0, true);
117//
118// //m.triggerSetFleetMaxShipSize(3);
119//
120//
121// CampaignFleetAPI fleet = m.createFleet();
122//
123// return fleet;
124
125 return null;
126 }
127
128
129
130
132 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
134 info.addPara("Impending Remnant attack", initPad, tc, c, "Remnant");
135 }
136
138 ListInfoMode mode, boolean isUpdate, Color tc, float initPad) {
139 info.addPara("Remnant attack averted", tc, initPad);
140 }
141
143 float small = 0f;
144 float opad = 10f;
145
146 small = 8f;
147
149
150 if (!(stage.rollData instanceof HAERandomEventData)) return;
151 HAERandomEventData data = (HAERandomEventData) stage.rollData;
152 if (!(data.custom instanceof MarketAPI)) return;
153
154 MarketAPI target = (MarketAPI) data.custom;
155
156 Color h = Misc.getHighlightColor();
157 info.addPara("There are signs of activity at a Remnant Nexus in your system. Intel evaluates "
158 + "a high probability of an attack fleet being assembled to saturation-bombard " +
159 target.getName() + ".",
160 small, Misc.getNegativeHighlightColor(), "saturation-bombard");
161
162 LabelAPI label = info.addPara("Defeating the attack fleet would only put off the problem, "
163 + "but destroying the Remnant Nexus will end the threat for good.",
164 opad);
165 label.setHighlight("Remnant Nexus", "end the threat");
166 label.setHighlightColors(
169
171 stage.beginResetReqList(info, true, "crisis", opad);
172 info.addPara("The %s is destroyed", 0f, c, "Remnant Nexus");
173 stage.endResetReqList(info, false, "crisis", -1, -1);
174
176 }
177
178
179 public String getEventStageIcon(HostileActivityEventIntel intel, EventStageData stage) {
181 }
182
183 public TooltipCreator getStageTooltipImpl(final HostileActivityEventIntel intel, final EventStageData stage) {
184 if (stage.id == Stage.HA_EVENT) {
185 return getDefaultEventTooltip("Remnant attack", intel, stage);
186 }
187 return null;
188 }
189
191 if (system == null) return null;
192// if (!system.hasTag(Tags.THEME_REMNANT_MAIN)) return null;
193// if (system.hasTag(Tags.THEME_REMNANT_DESTROYED)) return null;
194
195 for (CampaignFleetAPI fleet : system.getFleets()) {
196 if (!fleet.isStationMode()) continue;
197 if (!Factions.REMNANTS.equals(fleet.getFaction().getId())) continue;
198
199 return fleet;
200 }
201 return null;
202 }
203
204
205 public float getEventFrequency(HostileActivityEventIntel intel, EventStageData stage) {
206 if (stage.id == Stage.HA_EVENT) {
207
208 MarketAPI target = findAttackTarget(intel, stage);
209 if (target == null || target.getStarSystem() == null) return 0f;
210
212 if (nexus == null) return 0f;
213
214 return 10f;
215 }
216 return 0f;
217 }
218
219
220 public void rollEvent(HostileActivityEventIntel intel, EventStageData stage) {
221 MarketAPI target = findAttackTarget(intel, stage);
222 if (target == null) return;
223
224 HAERandomEventData data = new HAERandomEventData(this, stage);
225 data.custom = target;
226 stage.rollData = data;
228 }
229
230 public boolean fireEvent(HostileActivityEventIntel intel, EventStageData stage) {
231 MarketAPI target = findAttackTarget(intel, stage);
232 if (target == null || target.getStarSystem() == null) return false;
233
235 if (nexus == null) return false;
236
237 stage.rollData = null;
238 return startAttack(nexus, target, target.getStarSystem(), stage, getRandomizedStageRandom(3));
239 }
240
241
244
245 for (StarSystemAPI system : Misc.getPlayerSystems(false)) {
246 CampaignFleetAPI nexus = getRemnantNexus(system);
247 if (nexus != null) {
248 for (MarketAPI curr : Misc.getMarketsInLocation(system, Factions.PLAYER)) {
249 picker.add(curr, curr.getSize() * curr.getSize() * curr.getSize());
250 }
251 }
252 }
253 return picker.pick();
254 }
255
256
257
258 @Override
259 public void notifyFactorRemoved() {
260 //Global.getSector().getListenerManager().removeListener(this);
261 }
262
263 public void notifyEventEnding() {
265 }
266
267 @Override
268 public void advance(float amount) {
269 super.advance(amount);
270
271 EventStageData stage = intel.getDataFor(Stage.HA_EVENT);
272 if (stage != null && stage.rollData instanceof HAERandomEventData &&
273 ((HAERandomEventData)stage.rollData).factor == this) {
274
275 HAERandomEventData data = (HAERandomEventData) stage.rollData;
276 if (data.custom instanceof MarketAPI) {
277 MarketAPI target = (MarketAPI) data.custom;
278 if (getRemnantNexus(target.getStarSystem()) == null) {
280 }
281 }
282 }
283
284 }
285
286
287
288 public boolean startAttack(CampaignFleetAPI nexus, MarketAPI target, StarSystemAPI system, EventStageData stage, Random random) {
289 //System.out.println("RANDOM: " + random.nextLong());
290
291 GenericRaidParams params = new GenericRaidParams(new Random(random.nextLong()), true);
292
293 params.makeFleetsHostile = true;
294 params.remnant = true;
295
296 params.factionId = nexus.getFaction().getId();
297
298 MarketAPI fake = Global.getFactory().createMarket(nexus.getId(), nexus.getName(), 3);
299 fake.setPrimaryEntity(nexus);
300 fake.setFactionId(params.factionId);
302 "nexus_" + nexus.getId(), 1f);
303
304 //nexus.setMarket(fake); // can actually trade etc then, no good
305
306 params.source = fake;
307
308 params.prepDays = 0f;
309 params.payloadDays = 27f + 7f * random.nextFloat();
310
311 params.raidParams.where = system;
312 params.raidParams.type = FGRaidType.SEQUENTIAL;
313 params.raidParams.tryToCaptureObjectives = false;
314 params.raidParams.allowedTargets.add(target);
315 params.raidParams.allowNonHostileTargets = true;
316 params.raidParams.setBombardment(BombardType.SATURATION);
317 params.forcesNoun = "remnant forces";
318
319 params.style = FleetStyle.STANDARD;
320 params.repImpact = ComplicationRepImpact.FULL;
321
322
323 // standard Askonia fleet size multiplier with no shortages/issues is a bit over 230%
324 float fleetSizeMult = 1f;
325 boolean damaged = nexus.getMemoryWithoutUpdate().getBoolean("$damagedStation");
326 if (damaged) {
327 fleetSizeMult = 0.5f;
328 }
329
330 float totalDifficulty = fleetSizeMult * 50f;
331
332 totalDifficulty -= 10;
333 params.fleetSizes.add(10);
334
335 while (totalDifficulty > 0) {
336 int min = 6;
337 int max = 10;
338
339 int diff = min + random.nextInt(max - min + 1);
340
341 params.fleetSizes.add(diff);
342 totalDifficulty -= diff;
343 }
344
345
346// SindrianDiktatPunitiveExpedition punex = new SindrianDiktatPunitiveExpedition(params);
347// punex.setListener(this);
348// Global.getSector().getIntelManager().addIntel(punex);
349
350 GenericRaidFGI raid = new GenericRaidFGI(params);
351 raid.setListener(this);
353
354 return true;
355 }
356
358 // TODO: anything? Nothing happens if you defeat it, it's purely avoiding a bombardment
359 }
360
361}
362
363
364
365
static FactoryAPI getFactory()
Definition Global.java:41
static SectorAPI getSector()
Definition Global.java:65
void modifyFlat(String source, float value)
void sendUpdateIfPlayerHasIntel(Object listInfoParam, TextPanelAPI textPanel)
TooltipCreator getDefaultEventTooltip(final String title, final HostileActivityEventIntel intel, final EventStageData stage)
boolean startAttack(CampaignFleetAPI nexus, MarketAPI target, StarSystemAPI system, EventStageData stage, Random random)
void addBulletPointForEventReset(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
float getEventFrequency(HostileActivityEventIntel intel, EventStageData stage)
boolean fireEvent(HostileActivityEventIntel intel, EventStageData stage)
MarketAPI findAttackTarget(HostileActivityEventIntel intel, EventStageData stage)
TooltipCreator getStageTooltipImpl(final HostileActivityEventIntel intel, final EventStageData stage)
void addStageDescriptionForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info)
void addBulletPointForEvent(HostileActivityEventIntel intel, EventStageData stage, TooltipMakerAPI info, ListInfoMode mode, boolean isUpdate, Color tc, float initPad)
String getEventStageIcon(HostileActivityEventIntel intel, EventStageData stage)
static List< MarketAPI > getMarketsInLocation(LocationAPI location, String factionId)
Definition Misc.java:936
static Color getNegativeHighlightColor()
Definition Misc.java:802
static List< StarSystemAPI > getPlayerSystems(boolean includeNonPlayerFaction)
Definition Misc.java:993
static Color getGrayColor()
Definition Misc.java:826
static Color getHighlightColor()
Definition Misc.java:792
static Color getPositiveHighlightColor()
Definition Misc.java:822
MarketAPI createMarket(String id, String name, int size)
List< CampaignFleetAPI > getFleets()
FactionAPI getFaction(String factionId)
void setPrimaryEntity(SectorEntityToken primaryEntity)
void setHighlight(int start, int end)
void setHighlightColors(Color ... colors)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)