Starsector API
Loading...
Searching...
No Matches
EventTestPluginImpl.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.procgen;
2
3import java.util.ArrayList;
4import java.util.LinkedHashMap;
5import java.util.List;
6import java.util.Map;
7import java.util.Random;
8
9import java.awt.Color;
10
11import org.lwjgl.util.vector.Vector2f;
12
13import com.fs.starfarer.api.Global;
14import com.fs.starfarer.api.campaign.CampaignClockAPI;
15import com.fs.starfarer.api.campaign.CampaignFleetAPI;
16import com.fs.starfarer.api.campaign.FactionAPI;
17import com.fs.starfarer.api.campaign.InteractionDialogAPI;
18import com.fs.starfarer.api.campaign.InteractionDialogPlugin;
19import com.fs.starfarer.api.campaign.LocationAPI;
20import com.fs.starfarer.api.campaign.OptionPanelAPI;
21import com.fs.starfarer.api.campaign.PlanetAPI;
22import com.fs.starfarer.api.campaign.SectorEntityToken;
23import com.fs.starfarer.api.campaign.StarSystemAPI;
24import com.fs.starfarer.api.campaign.TextPanelAPI;
25import com.fs.starfarer.api.campaign.VisualPanelAPI;
26import com.fs.starfarer.api.campaign.comm.IntelInfoPlugin;
27import com.fs.starfarer.api.campaign.econ.Industry;
28import com.fs.starfarer.api.campaign.econ.MarketAPI;
29import com.fs.starfarer.api.campaign.rules.MemoryAPI;
30import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
31import com.fs.starfarer.api.characters.PersonAPI;
32import com.fs.starfarer.api.combat.EngagementResultAPI;
33import com.fs.starfarer.api.combat.ShipAPI.HullSize;
34import com.fs.starfarer.api.combat.ShipHullSpecAPI;
35import com.fs.starfarer.api.combat.WeaponAPI.AIHints;
36import com.fs.starfarer.api.impl.campaign.AbyssalLightEntityPlugin.AbyssalLightParams;
37import com.fs.starfarer.api.impl.campaign.DebugFlags;
38import com.fs.starfarer.api.impl.campaign.eventide.DuelDialogDelegate;
39import com.fs.starfarer.api.impl.campaign.eventide.DuelPanel;
40import com.fs.starfarer.api.impl.campaign.ids.Entities;
41import com.fs.starfarer.api.impl.campaign.ids.Factions;
42import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
43import com.fs.starfarer.api.impl.campaign.ids.Tags;
44import com.fs.starfarer.api.impl.campaign.intel.PromoteOfficerIntel;
45import com.fs.starfarer.api.impl.campaign.intel.bases.PirateBaseIntel;
46import com.fs.starfarer.api.impl.campaign.intel.events.HostileActivityEventIntel;
47import com.fs.starfarer.api.impl.campaign.intel.events.ht.HTScanFactor;
48import com.fs.starfarer.api.impl.campaign.intel.events.ht.HyperspaceTopographyEventIntel;
49import com.fs.starfarer.api.impl.campaign.intel.inspection.HegemonyInspectionManager;
50import com.fs.starfarer.api.impl.campaign.intel.misc.LuddicShrineIntel;
51import com.fs.starfarer.api.impl.campaign.intel.punitive.PunitiveExpeditionManager;
52import com.fs.starfarer.api.impl.campaign.intel.punitive.PunitiveExpeditionManager.PunExData;
53import com.fs.starfarer.api.impl.campaign.plog.PLEntry;
54import com.fs.starfarer.api.impl.campaign.plog.PLIntel;
55import com.fs.starfarer.api.impl.campaign.plog.PlaythroughLog;
56import com.fs.starfarer.api.impl.campaign.population.CoreImmigrationPluginImpl;
57import com.fs.starfarer.api.loading.FighterWingSpecAPI;
58import com.fs.starfarer.api.loading.WeaponSpecAPI;
59import com.fs.starfarer.api.util.Misc;
60
62
63 protected static enum OptionId {
64 INIT,
65 PIRATE_RAID,
66 PUNITIVE_EXPEDITION,
67 INSPECTION,
68 PICK_STRENGTH,
69 PRINT_LOG,
70 TOPOGRAPHY_POINTS,
71 HAEI_POINTS,
72 ADD_LOG_INTEL,
73 INCREASE_COLONY_SIZE,
74 FINISH_CONSTRUCTION,
75 FIGHT,
76 TUTORIAL,
77 LEAVE,
78 }
79
84
86 protected PlanetAPI planet;
87
88 protected PunExData punExData = null;
89 protected boolean sendInspection = false;
90
91 protected static final Color HIGHLIGHT_COLOR = Global.getSettings().getColor("buttonShortcut");
92
94 this.dialog = dialog;
95
99
102
103 visual.setVisualFade(0.25f, 0.25f);
104
105 //visual.showImageVisual(planet.getCustomInteractionDialogImageVisual());
106
108
109 dialog.setOptionOnEscape("Leave", OptionId.LEAVE);
110 optionSelected(null, OptionId.INIT);
111 }
112
113 public Map<String, MemoryAPI> getMemoryMap() {
114 return null;
115 }
116
118 // no combat here, so this won't get called
119 }
120
121
122 public void optionSelected(String text, Object optionData) {
123 if (optionData == null) return;
124
125 if (optionData instanceof Integer) {
126 DebugFlags.FAST_RAIDS = true;
127 Integer str = (Integer) optionData;
128 if (punExData != null) {
130 } else if (sendInspection) {
132 }
133 optionSelected(null, OptionId.LEAVE);
134 return;
135 }
136
137 if (optionData instanceof PunExData) {
138 punExData = (PunExData) optionData;
139 optionSelected(null, OptionId.PICK_STRENGTH);
140 return;
141 }
142
143 OptionId option = (OptionId) optionData;
144
145 if (text != null) {
146 //textPanel.addParagraph(text, Global.getSettings().getColor("buttonText"));
148 //textPanel.addParagraph("");
149 }
150
151 switch (option) {
152 case INIT:
154
155
157 MutableCharacterStatsAPI stats = player.getStats();
158// stats.addXP((long) (6000f * (float) Math.random() + 100f), textPanel, true);
159// stats.spendStoryPoints(2, true, textPanel, false, 1f, null);
160
161 break;
162 case TUTORIAL:
163 final DuelPanel duelPanel = DuelPanel.createTutorial(true, "soe_ambience");
164 dialog.showCustomVisualDialog(1024, 700, new DuelDialogDelegate(null, duelPanel, dialog, null, true));
165 break;
166 case FIGHT:
167 final DuelPanel duelPanel2 = DuelPanel.createDefault(true, true, "soe_ambience");
168 dialog.showCustomVisualDialog(1024, 700, new DuelDialogDelegate("music_soe_fight", duelPanel2, dialog, null, true));
169
170 //Global.getSector().getIntelManager().addIntel(new TestFleetGroupIntel());
171
172 //new PerseanLeagueBlockade(params, blockadeParams)
173
174// new GensHannanMachinations(dialog);
175
176// dialog.showCustomVisualDialog(1024, 700, new CustomVisualDialogDelegate() {
177// public CustomUIPanelPlugin getCustomPanelPlugin() {
178// return duelPanel2;
179// }
180// public void init(CustomPanelAPI panel, DialogCallbacks callbacks) {
181// duelPanel2.init(panel, callbacks, dialog);
182// }
183// public float getNoiseAlpha() {
184// return 0;
185// }
186// public void advance(float amount) {
187//
188// }
189// public void reportDismissed(int option) {
190// }
191// });
192 //dialog.hideTextPanel();
193 break;
194 case PIRATE_RAID:
195 MarketAPI market = getNearestMarket(false);
197 if (base != null && market != null && market.getStarSystem() != null) {
198 base.startRaid(market.getStarSystem(), 500f);
199 base.makeKnown(textPanel);
200 //print("Attempted to start raid; likely succeeded, see if there's new intel.");
201 optionSelected(null, OptionId.LEAVE);
202 }
203 //addText("")
204 break;
205 case INCREASE_COLONY_SIZE:
206 market = getNearestMarket(false);
207 if (market != null) {
208 int was = market.getSize();
210 plugin.increaseMarketSize();
211 textPanel.addPara("Size of " + market.getName() + " increased from " + was + " to " + market.getSize());
212 }
213 break;
214 case FINISH_CONSTRUCTION:
215 market = getNearestMarket(false);
216 if (market != null) {
217 for (Industry curr : new ArrayList<Industry>(market.getIndustries())) {
218 if (curr.isBuilding()) {
219 curr.finishBuildingOrUpgrading();
220 textPanel.addPara("Finished building or upgrading " + curr.getCurrentName());
221 }
222 }
223 }
224 break;
225 case PUNITIVE_EXPEDITION:
227 for (PunExData data : PunitiveExpeditionManager.getInstance().getData().values()) {
229 options.addOption("Punitive expedition: " + data.faction.getDisplayName(), data);
230 }
231 }
232 options.addOption("Leave", OptionId.LEAVE, null);
233 break;
234 case INSPECTION:
235 sendInspection = true;
236 optionSelected(null, OptionId.PICK_STRENGTH);
237 break;
238 case PICK_STRENGTH:
239 textPanel.addPara("Select strength");
241 options.addOption("100", 100);
242 options.addOption("200", 200);
243 options.addOption("300", 300);
244 options.addOption("400", 400);
245 options.addOption("500", 500);
246 options.addOption("600", 600);
247 options.addOption("800", 800);
248 options.addOption("1000", 1000);
249 options.addOption("Leave", OptionId.LEAVE, null);
250 break;
251 case TOPOGRAPHY_POINTS:
253 new HTScanFactor("Dev mode point increase", 50), dialog);
254 break;
255 case HAEI_POINTS:
256 if (HostileActivityEventIntel.get() != null) {
258 intel.setRandom(new Random());
259 int p = intel.getProgress();
260 if (p < 500 || p == 599) p = 500;
261 else if (p < 550) p = 550;
262 else p = 599;
263 intel.setProgress(p);
264 textPanel.addPara("Progress set to " + p);
265 }
266 //HostileActivityEventIntel.get().addFactor(new BaseOneTimeFactor(50), dialog);
267 break;
268 case PRINT_LOG:
269
270
271 for (int i = 0; i < 10; i++) {
272 Vector2f loc = Misc.getPointWithinRadius(playerFleet.getLocation(), 10000f);
273 //Vector2f loc = Misc.getPointWithinRadius(playerFleet.getLocation(), 2000f);
274 if (Misc.getAbyssalDepth(loc) >= 1f) {
275 AbyssalLightParams params = new AbyssalLightParams();
277
278 if ((float) Math.random() > 0.5f) {
279 params.color = new Color(225,200,255,255);
280 //params.color = new Color(255,200,200,255);
282 long seed = Misc.random.nextLong();
284 }
285 e2.setLocation(loc.x, loc.y);
286 }
287 }
288
289// SectorEntityToken e2 = Global.getSector().getHyperspace().addCustomEntity(Misc.genUID(), null, Entities.ABYSSAL_LIGHT, Factions.NEUTRAL);
290// e2.setLocation(playerFleet.getLocation().x, playerFleet.getLocation().y);
291
292
293 //new GensHannanMachinations(dialog);
294
295// if (Global.getSector().getCurrentLocation() instanceof StarSystemAPI) {
296// new HostileActivityIntel((StarSystemAPI) Global.getSector().getCurrentLocation());
297// }
298
299 //BaseEventIntel event = new BaseEventIntel();
300 //HyperspaceTopographyEventIntel event = new HyperspaceTopographyEventIntel(dialog.getTextPanel(), true);
301 //Global.getSector().addScript(this);
302 //Global.getSector().getIntelManager().addIntel(event);
303 //Global.getSector().getListenerManager().addListener(this);
304
306
307 textPanel.addPara("Player log:");
308 String log = "";
310 CampaignClockAPI clock = Global.getSector().getClock().createClock(e.getTimestamp());
311 log += clock.getShortDate() + " " + e.getText() + "\n";
312 }
314 textPanel.addPara(log);
316
318 String tags = "";
319 for (String tag : Global.getSector().getCurrentLocation().getTags()) {
320 tags += " " + tag + "\n";
321 }
322 textPanel.addPara("\nTags for " + loc.getName() + ":\n" + tags);
323 if (loc instanceof StarSystemAPI) {
324 textPanel.addPara("\nSystem type: " + ((StarSystemAPI)loc).getType());
325 }
326
327 break;
328 case ADD_LOG_INTEL:
329 PLIntel intel = new PLIntel();
331
338
341
342// dialog.showCustomProductionPicker(new BaseCustomProductionPickerDelegateImpl());
343
344 //Global.getSector().getIntelManager().addIntel(intel, false, textPanel);
345
346// for (int i = 0; i < 12 * 3; i++) {
347// for (int j = 0; j < 10; j++) {
348// PlaythroughLog.getInstance().reportEconomyTick(i);
349// }
350// PlaythroughLog.getInstance().reportEconomyMonthEnd();
351// }
352 break;
353 case LEAVE:
354 //Global.getSector().setPaused(false);
355 dialog.dismiss();
356 break;
357 }
358 }
359
360 protected MarketAPI getNearestMarket(boolean playerOnly) {
361 MarketAPI nearest = null;
362 float minDist = Float.MAX_VALUE;
365 if (curr.isHidden()) continue;
366 if (playerOnly && !curr.isPlayerOwned()) continue;
367
368 float dist = Misc.getDistanceLY(pf, curr.getPrimaryEntity());
369 boolean nearer = dist < minDist;
370 if (dist == minDist && dist == 0 && nearest != null) {
371 float d1 = Misc.getDistance(pf, curr.getPrimaryEntity());
372 float d2 = Misc.getDistance(pf, nearest.getPrimaryEntity());
373 nearer = d1 < d2;
374 }
375 if (nearer) {
376 nearest = curr;
377 minDist = dist;
378 }
379 }
380 return nearest;
381 }
382
383 protected void print(String str) {
385 System.out.println(str);
386 }
387
388 protected void createInitialOptions() {
390
391 options.addOption("Fight!", OptionId.FIGHT);
392// options.addOption("Fight tutorial", OptionId.TUTORIAL);
393
394 MarketAPI market = getNearestMarket(false);
395 if (market != null) {
396 options.addOption("Send pirate raid to " + market.getContainingLocation().getName(), OptionId.PIRATE_RAID, null);
397 }
398 options.addOption("Send a punitive expedition", OptionId.PUNITIVE_EXPEDITION);
399 options.addOption("Send an AI inspection", OptionId.INSPECTION);
400 options.addOption("Hyperspace Topography +50 points", OptionId.TOPOGRAPHY_POINTS);
401 options.addOption("Hostile Activity: reseed RNG and cycle progress through 400/450/499", OptionId.HAEI_POINTS);
402 options.addOption("Print player log", OptionId.PRINT_LOG);
403 options.addOption("Add player log intel", OptionId.ADD_LOG_INTEL);
404
405 if (market != null) {
406 options.addOption("Increase size of " + market.getName() + " to " + (market.getSize() + 1), OptionId.INCREASE_COLONY_SIZE);
407 options.addOption("Finish construction on " + market.getName(), OptionId.FINISH_CONSTRUCTION);
408 }
409
410 options.addOption("Leave", OptionId.LEAVE, null);
411 }
412
413
414 protected OptionId lastOptionMousedOver = null;
415 public void optionMousedOver(String optionText, Object optionData) {
416
417 }
418
419 public void advance(float amount) {
420
421 }
422
423 public Object getContext() {
424 return null;
425 }
426
430 if (intel.isEnded() || intel.isEnding()) continue;
431 return intel;
432 }
433 return null;
434 }
435
436
438 List<FactionAPI> factions = Global.getSector().getAllFactions();
439
440 System.out.println();
441 System.out.println("----------------------- FIGHTERS -----------------------");
442 System.out.println();
443
444 Map<String, String> oneFactionFighters = new LinkedHashMap<String, String>();
446 if (spec.hasTag(Tags.RESTRICTED)) continue;
447 int count = 0;
448 String id = spec.getId();
449 String fId = null;
450 List<String> all = new ArrayList<String>();
451 for (FactionAPI f : factions) {
452 if (f.isPlayerFaction()) continue;
453 if (f.getKnownFighters().contains(id)) {
454 count++;
455 fId = f.getId();
456 all.add(fId);
457 }
458 }
459 if (count == 0) {
460 //System.out.println("Fighter wing [" + id + "] has no increased sell frequency anywhere");
461 System.out.println("FIGHTER WING [" + id + "] IS NOT USED BY ANY FACTION");
462 }
463 if (count == 1) {
464 oneFactionFighters.put(id, fId);
465 }
466
467 if (count != 0) {
468 System.out.println("Fighter wing [" + id + "] is known by: [" + Misc.getAndJoined(all) + "]");
469 }
470 }
471
472 System.out.println();
473 System.out.println("----------------------- WEAPONS -----------------------");
474 System.out.println();
475
477 if (spec.hasTag(Tags.RESTRICTED)) continue;
478 if (spec.hasTag(Tags.NO_SELL)) continue;
479 if (spec.getAIHints().contains(AIHints.SYSTEM)) continue;
480 String id = spec.getWeaponId();
481 int count = 0;
482 List<String> all = new ArrayList<String>();
483 for (FactionAPI f : factions) {
484 if (f.isPlayerFaction()) continue;
485 Float p = f.getWeaponSellFrequency().get(id);
486 if (p != null && p > 1f) {
487 count++;
488 }
489 if (f.knowsWeapon(id)) {
490 all.add(f.getId());
491 }
492 }
493 if (count <= 0) {
494 System.out.println("Weapon [" + id + "] is not sold with higher frequency; known by: [" + Misc.getAndJoined(all) + "]");
495 }
496 }
497
498
499 System.out.println();
500 System.out.println("----------------------- SHIPS -----------------------");
501 System.out.println();
502
503 Map<String, String> oneFactionShips = new LinkedHashMap<String, String>();
505 if (spec.hasTag(Tags.RESTRICTED)) continue;
506 if (spec.hasTag(Tags.NO_SELL)) continue;
507 if (spec.getHullSize() == HullSize.FIGHTER) continue;
508 String id = spec.getHullId();
509 if (id.endsWith("_default_D")) continue;
510 if (id.endsWith("_default_D")) continue;
511 if (id.startsWith("module_")) continue;
512 int count = 0;
513 String fId = null;
514 List<String> all = new ArrayList<String>();
515 for (FactionAPI f : factions) {
516 if (f.isPlayerFaction()) continue;
517 if (f.getKnownShips().contains(id)) {
518 count++;
519 fId = f.getId();
520 all.add(fId);
521 }
522 }
523// if (count <= 0) {
524// System.out.println("SHIP [" + id + "] IS NOT USED BY ANY FACTION");
525// }
526
527 if (count == 1) {
528 oneFactionShips.put(id, fId);
529 }
530
531 if (count > 0) {
532 System.out.println("Ship [" + id + "] is known by: [" + Misc.getAndJoined(all) + "]");
533 }
534 }
535
536// System.out.println();
537//
538// for (String id : oneFactionShips.keySet()) {
539// System.out.println("Ship [" + id + "] is only known by [" + oneFactionShips.get(id) + "]");
540// }
541 }
542
543}
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
static SettingsAPI getSettings()
Definition Global.java:57
static SectorAPI getSector()
Definition Global.java:65
static DuelPanel createTutorial(boolean playerSkilled, String ambienceLoopId)
static DuelPanel createDefault(boolean playerSkilled, boolean enemySkilled, String ambienceLoopId)
static void addFactorCreateIfNecessary(EventFactor factor, InteractionDialogAPI dialog)
static void addShrineIntelIfNeeded(String id, TextPanelAPI text)
static float getDistanceLY(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:602
static float getDistance(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:599
static String getAndJoined(List< String > strings)
Definition Misc.java:871
static float getAbyssalDepth(Vector2f loc)
Definition Misc.java:2330
static Vector2f getPointWithinRadius(Vector2f from, float r)
Definition Misc.java:711
List< WeaponSpecAPI > getAllWeaponSpecs()
List< ShipHullSpecAPI > getAllShipHullSpecs()
List< FighterWingSpecAPI > getAllFighterWingSpecs()
CampaignClockAPI createClock(long timestamp)
void showCustomVisualDialog(float customPanelWidth, float customPanelHeight, CustomVisualDialogDelegate delegate)
void setOptionOnEscape(String text, Object optionId)
CustomCampaignEntityAPI addCustomEntity(String id, String name, String type, String factionId)
void addOption(String text, Object data)
SectorEntityToken getEntityById(String id)
void setVisualFade(float in, float out)
void showLargePlanet(SectorEntityToken planet)
void set(String key, Object value)
MutableCharacterStatsAPI getStats()