Starsector API
Loading...
Searching...
No Matches
HubMissionWithTriggers.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.missions.hub;
2
3import java.util.ArrayList;
4import java.util.Arrays;
5import java.util.EnumSet;
6import java.util.List;
7import java.util.Random;
8
9import org.lwjgl.util.vector.Vector2f;
10
11import com.fs.starfarer.api.EveryFrameScript;
12import com.fs.starfarer.api.Global;
13import com.fs.starfarer.api.Script;
14import com.fs.starfarer.api.campaign.CampaignFleetAPI;
15import com.fs.starfarer.api.campaign.CargoAPI;
16import com.fs.starfarer.api.campaign.FactionAPI;
17import com.fs.starfarer.api.campaign.FactionAPI.ShipPickMode;
18import com.fs.starfarer.api.campaign.FactionAPI.ShipPickParams;
19import com.fs.starfarer.api.campaign.FactionDoctrineAPI;
20import com.fs.starfarer.api.campaign.FleetInflater;
21import com.fs.starfarer.api.campaign.LocationAPI;
22import com.fs.starfarer.api.campaign.PlanetAPI;
23import com.fs.starfarer.api.campaign.SectorEntityToken;
24import com.fs.starfarer.api.campaign.SpecialItemData;
25import com.fs.starfarer.api.campaign.StarSystemAPI;
26import com.fs.starfarer.api.campaign.econ.CommoditySpecAPI;
27import com.fs.starfarer.api.campaign.econ.MarketAPI;
28import com.fs.starfarer.api.campaign.rules.HasMemory;
29import com.fs.starfarer.api.campaign.rules.MemoryAPI;
30import com.fs.starfarer.api.characters.AbilityPlugin;
31import com.fs.starfarer.api.characters.PersonAPI;
32import com.fs.starfarer.api.combat.ShipVariantAPI;
33import com.fs.starfarer.api.fleet.FleetMemberAPI;
34import com.fs.starfarer.api.fleet.ShipRolePick;
35import com.fs.starfarer.api.impl.campaign.DerelictShipEntityPlugin.DerelictShipData;
36import com.fs.starfarer.api.impl.campaign.DerelictShipEntityPlugin.DerelictType;
37import com.fs.starfarer.api.impl.campaign.fleets.DefaultFleetInflater;
38import com.fs.starfarer.api.impl.campaign.fleets.DefaultFleetInflaterParams;
39import com.fs.starfarer.api.impl.campaign.fleets.FleetFactoryV3;
40import com.fs.starfarer.api.impl.campaign.fleets.FleetParamsV3;
41import com.fs.starfarer.api.impl.campaign.ids.Abilities;
42import com.fs.starfarer.api.impl.campaign.ids.Conditions;
43import com.fs.starfarer.api.impl.campaign.ids.Factions;
44import com.fs.starfarer.api.impl.campaign.ids.FleetTypes;
45import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
46import com.fs.starfarer.api.impl.campaign.ids.ShipRoles;
47import com.fs.starfarer.api.impl.campaign.ids.Skills;
48import com.fs.starfarer.api.impl.campaign.missions.hub.MissionTrigger.TriggerAction;
49import com.fs.starfarer.api.impl.campaign.missions.hub.MissionTrigger.TriggerActionContext;
50import com.fs.starfarer.api.impl.campaign.procgen.StarSystemGenerator;
51import com.fs.starfarer.api.impl.campaign.procgen.themes.RemnantSeededFleetManager;
52import com.fs.starfarer.api.impl.campaign.procgen.themes.SalvageSpecialAssigner;
53import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.BaseSalvageSpecial;
54import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special.TransmitterTrapSpecial;
55import com.fs.starfarer.api.impl.campaign.skills.OfficerTraining;
56import com.fs.starfarer.api.impl.campaign.terrain.StarCoronaTerrainPlugin;
57import com.fs.starfarer.api.util.Misc;
58import com.fs.starfarer.api.util.WeightedRandomPicker;
59
68public abstract class HubMissionWithTriggers extends BaseHubMission {
69
70 public static enum FleetSize {
71 TINY(0.06f),
72 VERY_SMALL(0.1f),
73 SMALL(0.2f),
74 MEDIUM(0.35f),
75 LARGE(0.5f),
76 LARGER(0.6f),
77 VERY_LARGE(0.7f),
78 HUGE(0.9f),
79 MAXIMUM(1.1f);
80
81 public float maxFPFraction;
82 private FleetSize(float maxFPFraction) {
83 this.maxFPFraction = maxFPFraction;
84 }
85
86 private static FleetSize [] vals = values();
87 public FleetSize next() {
88 int index = this.ordinal() + 1;
89 if (index >= vals.length) index = vals.length - 1;
90 return vals[index];
91 }
92 public FleetSize prev() {
93 int index = this.ordinal() - 1;
94 if (index < 0) index = 0;
95 return vals[index];
96 }
97 }
98
99 public static enum FleetQuality {
100 VERY_LOW(-1f, 0),
101 LOWER(-0.5f, 0),
102 DEFAULT(0f, 0),
103 HIGHER(0.5f, 0),
104 VERY_HIGH(1f, 0),
105 SMOD_1(1.5f, 1),
106 SMOD_2(1.5f, 2),
107 SMOD_3(1.5f, 3);
108
109
110 public float qualityMod;
111 public int numSMods;
112 private FleetQuality(float qualityMod, int numSMods) {
113 this.qualityMod = qualityMod;
114 this.numSMods = numSMods;
115 }
116
117 private static FleetQuality [] vals = values();
118 public FleetQuality next() {
119 int index = this.ordinal() + 1;
120 if (index >= vals.length) index = vals.length - 1;
121 return vals[index];
122 }
123 public FleetQuality prev() {
124 int index = this.ordinal() - 1;
125 if (index < 0) index = 0;
126 return vals[index];
127 }
128 }
129
130 public static enum OfficerNum {
131 NONE,
132 FC_ONLY,
133 FEWER,
134 DEFAULT,
135 MORE,
136 ALL_SHIPS;
137
138 private static OfficerNum [] vals = values();
139 public OfficerNum next() {
140 int index = this.ordinal() + 1;
141 if (index >= vals.length) index = vals.length - 1;
142 return vals[index];
143 }
144 public OfficerNum prev() {
145 int index = this.ordinal() - 1;
146 if (index < 0) index = 0;
147 return vals[index];
148 }
149 }
150
151 public static enum OfficerQuality {
152 LOWER,
153 DEFAULT,
154 HIGHER,
155 UNUSUALLY_HIGH,
156 AI_GAMMA,
157 AI_BETA,
158 AI_BETA_OR_GAMMA,
159 AI_ALPHA,
160 AI_OMEGA,
161 AI_MIXED;
162
163 private static OfficerQuality [] vals = values();
164 public OfficerQuality next() {
165 int index = this.ordinal() + 1;
166 if (index >= vals.length) index = vals.length - 1;
167 return vals[index];
168 }
169 public OfficerQuality prev() {
170 int index = this.ordinal() - 1;
171 if (index < 0) index = 0;
172 return vals[index];
173 }
174 }
175
176 public static class FleetAddTugs implements TriggerAction {
177 int numTugs = 0;
178 public FleetAddTugs(int numTugs) {
179 this.numTugs = numTugs;
180 }
181 public void doAction(TriggerActionContext context) {
182 if (context.fleet != null) {
183 addTugsToFleet(context.fleet, numTugs, ((BaseHubMission)context.mission).genRandom);
184 }
185 }
186 }
187
188 public static class UnhideCommListing implements TriggerAction {
189 protected PersonAPI person;
190 public UnhideCommListing(PersonAPI person) {
191 this.person = person;
192 }
193
194 public void doAction(TriggerActionContext context) {
195 if (person.getMarket() != null) {
196 MarketAPI market = person.getMarket();
197 if (market.getCommDirectory().getEntryForPerson(person) == null) {
198 market.getCommDirectory().addPerson(person);
199 }
200 if (market.getCommDirectory().getEntryForPerson(person) != null) {
201 market.getCommDirectory().getEntryForPerson(person).setHidden(false);
202 }
203 }
204 }
205 }
206
210 public static class HideCommListing implements TriggerAction {
211 protected PersonAPI person;
212 public HideCommListing(PersonAPI person) {
213 this.person = person;
214 }
215
216 public void doAction(TriggerActionContext context) {
217 if (person.getMarket() != null) {
218 MarketAPI market = person.getMarket();
219 if (market.getCommDirectory().getEntryForPerson(person) == null) {
220 market.getCommDirectory().addPerson(person);
221 }
222 if (market.getCommDirectory().getEntryForPerson(person) != null) {
223 market.getCommDirectory().getEntryForPerson(person).setHidden(true);
224 }
225 }
226 }
227 }
228
229 public static class MovePersonToMarket implements TriggerAction {
230 protected PersonAPI person;
231 protected MarketAPI market;
232 protected boolean alwaysAddToComms;
233
234 public MovePersonToMarket(PersonAPI person, MarketAPI market, boolean alwaysAddToComms) {
235 super();
236 this.person = person;
237 this.market = market;
238 this.alwaysAddToComms = alwaysAddToComms;
239 }
240
241
242 public void doAction(TriggerActionContext context) {
243 Misc.moveToMarket(person, market, alwaysAddToComms);
244 }
245 }
246
247
248 public static class DespawnEntityAction implements TriggerAction {
249 protected SectorEntityToken entity;
250 public DespawnEntityAction(SectorEntityToken entity) {
251 this.entity = entity;
252 }
253
254 public void doAction(TriggerActionContext context) {
255 Misc.fadeAndExpire(entity);
256 }
257 }
258
259 public static class MakeDiscoverableAction implements TriggerAction {
260 protected float range;
261 protected float xp;
262 public MakeDiscoverableAction(float range, float xp) {
263 this.range = range;
264 this.xp = xp;
265 }
266
267 public void doAction(TriggerActionContext context) {
268 ((BaseHubMission)context.mission).makeDiscoverable(context.entity, range, xp);
269
270 }
271 }
272
273 //public void spawnShipGraveyard(String factionId, int minShips, int maxShips, LocData data) {
274 public static class SpawnShipGraveyardAction implements TriggerAction {
275 protected String factionId;
276 protected int minShips;
277 protected int maxShips;
278 protected LocData data;
279 public SpawnShipGraveyardAction(String factionId, int minShips, int maxShips, LocData data) {
280 this.factionId = factionId;
281 this.minShips = minShips;
282 this.maxShips = maxShips;
283 this.data = data;
284 }
285
286 public void doAction(TriggerActionContext context) {
287 ((BaseHubMission)context.mission).spawnShipGraveyard(factionId, minShips, maxShips, data);
288 }
289
290 }
291 public static class SpawnDebrisFieldAction implements TriggerAction {
292 protected float radius;
293 protected float density;
294 protected LocData data;
295
296 public SpawnDebrisFieldAction(float radius, float density, LocData data) {
297 this.radius = radius;
298 this.density = density;
299 this.data = data;
300 }
301
302 public void doAction(TriggerActionContext context) {
303 SectorEntityToken entity = ((BaseHubMission)context.mission).spawnDebrisField(radius, density, data);
304 context.entity = entity;
305 }
306 }
307
308
309 public static class SpawnEntityAction implements TriggerAction {
310 protected String entityId;
311 protected LocData data;
312
313 public SpawnEntityAction(String entityId, LocData data) {
314 this.entityId = entityId;
315 this.data = data;
316 }
317
318 public void doAction(TriggerActionContext context) {
319 SectorEntityToken entity = ((BaseHubMission)context.mission).spawnEntity(entityId, data);
320 context.entity = entity;
321 }
322 }
323
324 public static class SpawnDerelictAction implements TriggerAction {
325 protected String hullId;
326 protected String factionId;
327 protected DerelictType type;
328 protected DerelictShipData shipData;
329 protected LocData data;
330
335 public SpawnDerelictAction(String hullId, String factionId, DerelictType type, LocData data) {
336 this.hullId = hullId;
337 this.factionId = factionId;
338 this.data = data;
339 this.type = type;
340 }
341
342 public SpawnDerelictAction(DerelictType type, LocData data) {
343 this.data = data;
344 this.type = type;
345 }
346 public SpawnDerelictAction(DerelictShipData shipData, LocData data) {
347 this.shipData = shipData;
348 this.data = data;
349 }
350
351 public void doAction(TriggerActionContext context) {
352 SectorEntityToken entity = null;
353 if (hullId != null) {
354 entity = ((BaseHubMission)context.mission).spawnDerelictHull(hullId, data);
355 } else if (factionId != null) {
356 entity = ((BaseHubMission)context.mission).spawnDerelict(factionId, type, data);
357 } else if (shipData != null) {
358 entity = ((BaseHubMission)context.mission).spawnDerelict(shipData, data);
359 } else {
360 entity = ((BaseHubMission)context.mission).spawnDerelictOfType(type, data);
361 }
362 context.entity = entity;
363 }
364 }
365
366
367
368 public static class SpawnFleetNearAction implements TriggerAction {
369 protected SectorEntityToken entity;
370 protected float range;
371
372 public SpawnFleetNearAction(SectorEntityToken entity, float range) {
373 this.entity = entity;
374 this.range = range;
375 }
376
377 public void doAction(TriggerActionContext context) {
378 entity.getContainingLocation().addEntity(context.fleet);
379 Vector2f loc = Misc.getPointWithinRadius(entity.getLocation(), range);
380 context.fleet.setLocation(loc.x, loc.y);
381 }
382 }
383 public static class SetFleetFactionAction implements TriggerAction {
384 protected String factionId;
385
386 public SetFleetFactionAction(String factionId) {
387 this.factionId = factionId;
388 }
389
390 public void doAction(TriggerActionContext context) {
391 context.fleet.setFaction(factionId, true);
392 }
393 }
394
395 public static class SetEntityToPickedJumpPoint implements TriggerAction {
396 public SetEntityToPickedJumpPoint() {
397 }
398
399 public void doAction(TriggerActionContext context) {
400 context.entity = context.jumpPoint;
401 }
402 }
403
404 public static class FleetMakeImportantAction implements TriggerAction {
405 protected String flag;
406 protected Enum[] stages;
407 public FleetMakeImportantAction(String flag, Enum ... stages) {
408 this.flag = flag;
409 this.stages = stages;
410 }
411 public void doAction(TriggerActionContext context) {
412 BaseHubMission bhm = (BaseHubMission) context.mission;
413 bhm.makeImportant(context.fleet, flag, stages);
414
415 if (stages != null && Arrays.asList(stages).contains(bhm.getCurrentStage())) {
416 Misc.makeImportant(context.fleet.getMemoryWithoutUpdate(), bhm.getReason());
417 bhm.changes.add(new MadeImportant(context.fleet.getMemoryWithoutUpdate(), bhm.getReason()));
418
419 if (flag != null) {
420 context.fleet.getMemoryWithoutUpdate().set(flag, true);
421 bhm.changes.add(new VariableSet(context.fleet.getMemoryWithoutUpdate(), flag, true));
422 }
423 }
424// else if (stages == null) {
425// Misc.makeImportant(context.fleet.getMemoryWithoutUpdate(), bhm.getReason());
426// }
427
428// if (context.mission instanceof BaseHubMission) {
429// Misc.makeImportant(context.fleet.getMemoryWithoutUpdate(), reason);
430// BaseHubMission bhm = (BaseHubMission) context.mission;
431// bhm.changes.add(new MadeImportant(context.fleet.getMemoryWithoutUpdate(), reason));
432// }
433 }
434 }
435
436 public static class EntityMakeImportantAction implements TriggerAction {
437 protected String flag;
438 protected Enum[] stages;
439 public EntityMakeImportantAction(String flag, Enum ... stages) {
440 this.flag = flag;
441 this.stages = stages;
442 }
443 public void doAction(TriggerActionContext context) {
444 BaseHubMission bhm = (BaseHubMission) context.mission;
445 bhm.makeImportant(context.entity, flag, stages);
446
447 if (Arrays.asList(stages).contains(bhm.getCurrentStage())) {
448 Misc.makeImportant(context.entity.getMemoryWithoutUpdate(), bhm.getReason());
449 bhm.changes.add(new MadeImportant(context.entity.getMemoryWithoutUpdate(), bhm.getReason()));
450
451 if (flag != null) {
452 context.entity.getMemoryWithoutUpdate().set(flag, true);
453 bhm.changes.add(new VariableSet(context.entity.getMemoryWithoutUpdate(), flag, true));
454 }
455 }
456
457// if (context.mission instanceof BaseHubMission) {
458// Misc.makeImportant(context.entity.getMemoryWithoutUpdate(), reason);
459// BaseHubMission bhm = (BaseHubMission) context.mission;
460// bhm.changes.add(new MadeImportant(context.entity.getMemoryWithoutUpdate(), reason));
461// }
462 }
463 }
464
465 public static class SetFleetFlagsWithReasonAction implements TriggerAction {
466 protected String[] flags;
467 protected String reason;
468 protected boolean permanent;
469
470 public SetFleetFlagsWithReasonAction(String reason, boolean permanent, String ... flags) {
471 this.permanent = permanent;
472 this.flags = flags;
473 this.reason = reason;
474 }
475
476 public void doAction(TriggerActionContext context) {
477 BaseHubMission bhm = (BaseHubMission) context.mission;
478 for (String flag : flags) {
479 Misc.setFlagWithReason(context.fleet.getMemoryWithoutUpdate(),
480 flag, reason, true, -1f);
481
482 if (context.makeAllFleetFlagsPermanent) {
483 permanent = true;
484 }
485
486 if (!permanent && bhm != null) {
487 String requiredKey = flag + "_" + reason;
488 bhm.changes.add(new VariableSet(context.fleet.getMemoryWithoutUpdate(), requiredKey, true));
489 }
490 }
491 }
492 }
493
494 public static class UnsetFleetFlagsWithReasonAction implements
495 TriggerAction {
496 protected String[] flags;
497 protected String reason;
498
499 public UnsetFleetFlagsWithReasonAction(String reason, String ... flags) {
500 this.reason = reason;
501 this.flags = flags;
502 }
503
504 public void doAction(TriggerActionContext context) {
505 for (String flag : flags) {
506 Misc.setFlagWithReason(context.fleet.getMemoryWithoutUpdate(),
507 flag, reason, false, -1f);
508 }
509 }
510 }
511
512
513 public static class SetPersonMissionRefAction implements TriggerAction {
514 protected String key;
515
516 public SetPersonMissionRefAction(String key) {
517 this.key = key;
518 }
519
520 public void doAction(TriggerActionContext context) {
521 context.person.getMemoryWithoutUpdate().set(key, context.mission);
522 }
523 }
524
525
526 public static class SetFleetMissionRefAction implements TriggerAction {
527 protected String key;
528
529 public SetFleetMissionRefAction(String key) {
530 this.key = key;
531 }
532
533 public void doAction(TriggerActionContext context) {
534 context.fleet.getMemoryWithoutUpdate().set(key, context.mission);
535 }
536 }
537
538
539 public static class SetMemoryValueAction implements TriggerAction {
540 protected String key;
541 protected Object value;
542 protected MemoryAPI memory;
543 protected boolean removeOnMissionOver;
544
545 public SetMemoryValueAction(MemoryAPI memory, String key, Object value, boolean removeOnMissionOver) {
546 this.memory = memory;
547 this.key = key;
548 this.value = value;
549 this.removeOnMissionOver = removeOnMissionOver;
550 }
551
552 public void doAction(TriggerActionContext context) {
553 memory.set(key, value);
554 BaseHubMission bhm = (BaseHubMission) context.mission;
555 bhm.changes.add(new VariableSet(memory, key, removeOnMissionOver));
556 }
557 }
558
559 public static class SetMemoryValueAfterDelay implements TriggerAction, EveryFrameScript {
560 protected String key;
561 protected Object value;
562 protected MemoryAPI memory;
563 protected float delay;
564
565 public SetMemoryValueAfterDelay(float delay, MemoryAPI memory, String key, Object value) {
566 this.memory = memory;
567 this.key = key;
568 this.value = value;
569 this.delay = delay;
570 }
571
572 public void doAction(TriggerActionContext context) {
573 if (delay <= 0) {
574 memory.set(key, value);
575 } else {
576 Global.getSector().addScript(this);
577 }
578 }
579
580 public boolean isDone() {
581 return delay < 0;
582 }
583
584 public boolean runWhilePaused() {
585 return false;
586 }
587
588 public void advance(float amount) {
589 if (delay < 0) return;
590 float days = Global.getSector().getClock().convertToDays(amount);
591 delay -= days;
592 if (delay < 0) {
593 memory.set(key, value);
594 }
595 }
596 }
597
598 public static class AddTagAfterDelay implements TriggerAction, EveryFrameScript {
599 protected String tag;
600 protected float delay;
601 protected StarSystemAPI system;
602
603 public AddTagAfterDelay(float delay, StarSystemAPI system, String tag) {
604 this.delay = delay;
605 this.system = system;
606 this.tag = tag;
607 }
608
609 public void doAction(TriggerActionContext context) {
610 Global.getSector().addScript(this);
611 }
612
613 public boolean isDone() {
614 return delay < 0;
615 }
616
617 public boolean runWhilePaused() {
618 return false;
619 }
620
621 public void advance(float amount) {
622 if (delay < 0) return;
623 float days = Global.getSector().getClock().convertToDays(amount);
624 delay -= days;
625 if (delay < 0) {
626 system.addTag(tag);
627 }
628 }
629 }
630
631 public static class RunScriptAfterDelay implements TriggerAction, EveryFrameScript {
632 protected float delay;
633 protected Script script;
634
635 public RunScriptAfterDelay(float delay, Script script) {
636 this.script = script;
637 this.delay = delay;
638 }
639
640 public void doAction(TriggerActionContext context) {
641 Global.getSector().addScript(this);
642 }
643
644 public boolean isDone() {
645 return delay < 0;
646 }
647
648 public boolean runWhilePaused() {
649 return false;
650 }
651
652 public void advance(float amount) {
653 if (delay < 0) return;
654 float days = Global.getSector().getClock().convertToDays(amount);
655 delay -= days;
656 if (delay < 0 && script != null) {
657 script.run();
658 script = null;
659 }
660 }
661 }
662
663 public static class IncreaseMarketHostileTimeout implements TriggerAction {
664 protected MarketAPI market;
665 protected float days;
666
667 public IncreaseMarketHostileTimeout(MarketAPI market, float days) {
668 this.market = market;
669 this.days = days;
670 }
671
672 public void doAction(TriggerActionContext context) {
673 Misc.increaseMarketHostileTimeout(market, days);
674 }
675 }
676
677 public static class SetFleetMemoryValueAction implements TriggerAction {
678 protected String key;
679 protected Object value;
680
681 public SetFleetMemoryValueAction(String key, Object value) {
682 this.key = key;
683 this.value = value;
684 }
685
686 public void doAction(TriggerActionContext context) {
687 context.fleet.getMemoryWithoutUpdate().set(key, value);
688 }
689 }
690
691 public static class AddFleetDefeatTriggerAction implements TriggerAction {
692 protected String trigger;
693 protected boolean permanent;
694 public AddFleetDefeatTriggerAction(String trigger, boolean permanent) {
695 this.trigger = trigger;
696 this.permanent = permanent;
697 }
698 public void doAction(TriggerActionContext context) {
699 ((BaseHubMission)context.mission).addFleetDefeatTrigger(context.fleet, trigger, permanent);
700 }
701 }
702
703 public static class MakeFleetFlagsPermanentAction implements TriggerAction {
704 protected boolean permanent;
705 public MakeFleetFlagsPermanentAction(boolean permanent) {
706 this.permanent = permanent;
707 }
708 public void doAction(TriggerActionContext context) {
709 context.makeAllFleetFlagsPermanent = permanent;
710 }
711 }
712
713
714 public static class AddTagsAction implements TriggerAction {
715 protected String [] tags;
716
717 public AddTagsAction(String ... tags) {
718 this.tags = tags;
719 }
720
721 public void doAction(TriggerActionContext context) {
722 for (String tag : tags) {
723 context.fleet.addTag(tag);
724 }
725 }
726 }
727
728 public static class AddCommanderSkillAction implements TriggerAction {
729 protected String skill;
730 protected int level;
731
732 public AddCommanderSkillAction(String skill, int level) {
733 this.skill = skill;
734 this.level = level;
735 }
736
737 public void doAction(TriggerActionContext context) {
738 context.fleet.getCommanderStats().setSkillLevel(skill, level);
739 }
740 }
741
742 public static class SetFleetFlagAction implements TriggerAction {
743 protected String flag;
744 protected Object[] stages;
745 protected boolean permanent;
746
747 public SetFleetFlagAction(String flag, boolean permanent, Object ... stages) {
748 this.flag = flag;
749 this.permanent = permanent;
750 this.stages = stages;
751 }
752
753 public void doAction(TriggerActionContext context) {
754 if (context.makeAllFleetFlagsPermanent) {
755 permanent = true;
756 }
757 ((BaseHubMission)context.mission).setFlag(context.fleet, flag, permanent, stages);
758 }
759 }
760
761 public static class SetEntityFlagAction implements TriggerAction {
762 protected String flag;
763 protected Object[] stages;
764 protected boolean permanent;
765
766 public SetEntityFlagAction(String flag, boolean permanent, Object ... stages) {
767 this.flag = flag;
768 this.permanent = permanent;
769 this.stages = stages;
770 }
771
772 public void doAction(TriggerActionContext context) {
773 ((BaseHubMission)context.mission).setFlag(context.entity, flag, permanent, stages);
774 }
775 }
776
777
778 public static class UnsetFleetFlagsAction implements TriggerAction {
779 protected String[] flags;
780
781 public UnsetFleetFlagsAction(String ... flags) {
782 this.flags = flags;
783 }
784
785 public void doAction(TriggerActionContext context) {
786 for (String flag : flags) {
787 context.fleet.getMemoryWithoutUpdate().unset(flag);
788 }
789 }
790 }
791
792 public static class UnsetEntityFlagsAction implements TriggerAction {
793 protected String[] flags;
794
795 public UnsetEntityFlagsAction(String ... flags) {
796 this.flags = flags;
797 }
798
799 public void doAction(TriggerActionContext context) {
800 for (String flag : flags) {
801 context.entity.getMemoryWithoutUpdate().unset(flag);
802 }
803 }
804 }
805
806
807 public static class SaveEntityReferenceAction implements TriggerAction {
808 protected MemoryAPI memory;
809 protected String key;
810 public SaveEntityReferenceAction(MemoryAPI memory, String key) {
811 this.memory = memory;
812 this.key = key;
813 }
814
815 public void doAction(TriggerActionContext context) {
816 memory.set(key, context.entity);
817 ((BaseHubMission) context.mission).changes.add(new VariableSet(memory, key, true));
818 }
819 }
820
821 public static class SaveFleetReferenceAction implements TriggerAction {
822 protected MemoryAPI memory;
823 protected String key;
824 public SaveFleetReferenceAction(MemoryAPI memory, String key) {
825 this.memory = memory;
826 this.key = key;
827 }
828
829 public void doAction(TriggerActionContext context) {
830 memory.set(key, context.fleet);
831 ((BaseHubMission) context.mission).changes.add(new VariableSet(memory, key, true));
832 }
833 }
834
835 public static class RemoveAbilitiesAction implements TriggerAction {
836 protected String[] abilities;
837
838 public RemoveAbilitiesAction(String ... abilities) {
839 this.abilities = abilities;
840 }
841
842 public void doAction(TriggerActionContext context) {
843 for (String ability : abilities) {
844 context.fleet.removeAbility(ability);
845 }
846 }
847 }
848
849
850 public static class AddAbilitiesAction implements TriggerAction {
851 protected String[] abilities;
852
853 public AddAbilitiesAction(String ... abilities) {
854 this.abilities = abilities;
855 }
856
857 public void doAction(TriggerActionContext context) {
858 for (String ability : abilities) {
859 context.fleet.addAbility(ability);
860 }
861 }
862 }
863
864 public static class GenericAddTagsAction implements TriggerAction {
865 protected String [] tags;
866 protected SectorEntityToken entity;
867
868 public GenericAddTagsAction(SectorEntityToken entity, String ... tags) {
869 this.tags = tags;
870 this.entity = entity;
871 }
872
873 public void doAction(TriggerActionContext context) {
874 for (String tag : tags) {
875 entity.addTag(tag);
876 }
877 }
878 }
879
880 public static class GenericRemoveTagsAction implements TriggerAction {
881 protected String [] tags;
882 protected SectorEntityToken entity;
883
884 public GenericRemoveTagsAction(SectorEntityToken entity, String ... tags) {
885 this.tags = tags;
886 this.entity = entity;
887 }
888
889 public void doAction(TriggerActionContext context) {
890 for (String tag : tags) {
891 entity.removeTag(tag);
892 }
893 }
894 }
895
896 public static class MakeNonStoryCriticalAction implements TriggerAction {
897 protected MemoryAPI [] memoryArray;
898
899 public MakeNonStoryCriticalAction(MemoryAPI ... memoryArray) {
900 this.memoryArray = memoryArray;
901 }
902 public void doAction(TriggerActionContext context) {
903 BaseHubMission bhm = (BaseHubMission) context.mission;
904 for (MemoryAPI memory : memoryArray) {
905 Misc.makeNonStoryCritical(memory, bhm.getReason());
906 }
907 }
908 }
909
910
911 public static class SetInflaterAction implements TriggerAction {
912 protected FleetInflater inflater;
913
914 public SetInflaterAction(FleetInflater inflater) {
915 this.inflater = inflater;
916 }
917
918 public void doAction(TriggerActionContext context) {
919 context.fleet.setInflater(inflater);
920 }
921 }
922
923
924 public static class SetRemnantConfigAction implements TriggerAction {
925 protected boolean dormant;
926 protected long seed;
927
928 public SetRemnantConfigAction(boolean dormant, long seed) {
929 this.dormant = dormant;
930 this.seed = seed;
931 }
932
933 public void doAction(TriggerActionContext context) {
934 Random random = new Random(seed);
935 RemnantSeededFleetManager.initRemnantFleetProperties(random, context.fleet, dormant);
936 }
937 }
938
939
940 public static class AddCustomDropAction implements TriggerAction {
941 protected CargoAPI cargo;
942
943 public AddCustomDropAction(CargoAPI cargo) {
944 this.cargo = cargo;
945 }
946
947 public void doAction(TriggerActionContext context) {
948 BaseSalvageSpecial.addExtraSalvage(context.fleet, cargo);
949 }
950 }
951
952
953 public static class AddCommodityDropAction implements TriggerAction {
954 protected int quantity;
955 protected String commodityId;
956 protected boolean dropQuantityBasedOnShipsDestroyed;
957
958 public AddCommodityDropAction(int quantity, String commodityId, boolean dropQuantityBasedOnShipsDestroyed) {
959 this.quantity = quantity;
960 this.commodityId = commodityId;
961 this.dropQuantityBasedOnShipsDestroyed = dropQuantityBasedOnShipsDestroyed;
962 }
963
964 public void doAction(TriggerActionContext context) {
965 if (dropQuantityBasedOnShipsDestroyed) {
966 context.fleet.getCargo().addCommodity(commodityId, quantity);
967 } else {
968 CargoAPI cargo = Global.getFactory().createCargo(true);
969 cargo.addCommodity(commodityId, quantity);
970 BaseSalvageSpecial.addExtraSalvage(context.fleet, cargo);
971 }
972 }
973 }
974
975 public static class AddCommodityFractionDropAction implements TriggerAction {
976 protected float fraction;
977 protected String commodityId;
978 protected boolean dropQuantityBasedOnShipsDestroyed;
979
980 public AddCommodityFractionDropAction(float fraction, String commodityId) {
981 this.fraction = fraction;
982 this.commodityId = commodityId;
983 }
984
985 public void doAction(TriggerActionContext context) {
986 CommoditySpecAPI spec = Global.getSettings().getCommoditySpec(commodityId);
987 float capacity = context.fleet.getCargo().getMaxCapacity();
988 if (spec.isFuel()) {
989 capacity = context.fleet.getCargo().getMaxFuel();
990 } else if (spec.isPersonnel()) {
991 capacity = context.fleet.getCargo().getMaxPersonnel();
992 }
993 int quantity = (int) Math.round(fraction * capacity);
994 if (quantity > 0) {
995 context.fleet.getCargo().addCommodity(commodityId, quantity);
996 }
997 }
998 }
999
1000
1001 public static class AddWeaponDropAction implements TriggerAction {
1002 protected int quantity;
1003 protected String weaponId;
1004
1005 public AddWeaponDropAction(int quantity, String weaponId) {
1006 this.quantity = quantity;
1007 this.weaponId = weaponId;
1008 }
1009
1010 public void doAction(TriggerActionContext context) {
1011 CargoAPI cargo = Global.getFactory().createCargo(true);
1012 cargo.addWeapons(weaponId, quantity);
1013 BaseSalvageSpecial.addExtraSalvage(context.fleet, cargo);
1014 }
1015 }
1016
1017
1018 public static class AddFighterLPCDropAction implements TriggerAction {
1019 protected String wingId;
1020 protected int quantity;
1021
1022 public AddFighterLPCDropAction(String wingId, int quantity) {
1023 this.wingId = wingId;
1024 this.quantity = quantity;
1025 }
1026
1027 public void doAction(TriggerActionContext context) {
1028 CargoAPI cargo = Global.getFactory().createCargo(true);
1029 cargo.addFighters(wingId, quantity);
1030 BaseSalvageSpecial.addExtraSalvage(context.fleet, cargo);
1031 }
1032 }
1033
1034
1035 public static class AddHullmodDropAction implements TriggerAction {
1036 protected String hullmodId;
1037
1038 public AddHullmodDropAction(String hullmodId) {
1039 this.hullmodId = hullmodId;
1040 }
1041
1042 public void doAction(TriggerActionContext context) {
1043 CargoAPI cargo = Global.getFactory().createCargo(true);
1044 cargo.addHullmods(hullmodId, 1);
1045 BaseSalvageSpecial.addExtraSalvage(context.fleet, cargo);
1046 }
1047 }
1048
1049
1050 public static class AddSpecialItemDropAction implements TriggerAction {
1051 protected String data;
1052 protected String itemId;
1053
1054 public AddSpecialItemDropAction(String data, String itemId) {
1055 this.data = data;
1056 this.itemId = itemId;
1057 }
1058
1059 public void doAction(TriggerActionContext context) {
1060 CargoAPI cargo = Global.getFactory().createCargo(true);
1061 cargo.addSpecial(new SpecialItemData(itemId, data), 1);
1062 BaseSalvageSpecial.addExtraSalvage(context.fleet, cargo);
1063 }
1064 }
1065
1066
1067 public static class SpawnFleetAtPickedLocationAction implements
1068 TriggerAction {
1069 protected float range;
1070
1071 public SpawnFleetAtPickedLocationAction(float range) {
1072 this.range = range;
1073 }
1074
1075 public void doAction(TriggerActionContext context) {
1076 context.containingLocation.addEntity(context.fleet);
1077 Vector2f loc = Misc.getPointWithinRadius(context.coordinates, range);
1078 context.fleet.setLocation(loc.x, loc.y);
1079 }
1080 }
1081
1082
1083 public static class PickSetLocationAction implements TriggerAction {
1084 protected Vector2f coordinates;
1085 protected LocationAPI location;
1086
1087 public PickSetLocationAction(Vector2f coordinates, LocationAPI location) {
1088 this.coordinates = coordinates;
1089 this.location = location;
1090 }
1091
1092 public void doAction(TriggerActionContext context) {
1093 context.coordinates = coordinates;
1094 context.containingLocation = location;
1095 }
1096 }
1097
1098
1099 public static class PickLocationInHyperspaceAction implements TriggerAction {
1100 protected StarSystemAPI system;
1101
1102 public PickLocationInHyperspaceAction(StarSystemAPI system) {
1103 this.system = system;
1104 }
1105
1106 public void doAction(TriggerActionContext context) {
1107 //CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
1108 Vector2f pick = pickLocationWithinArc(((BaseHubMission)context.mission).genRandom, system.getHyperspaceAnchor(), 0, 360f, 2000f, 0f, 1000f);
1109
1110 context.coordinates = pick;
1111 //context.containingLocation = playerFleet.getContainingLocation();
1112 context.containingLocation = Global.getSector().getHyperspace();
1113 }
1114 }
1115
1116
1117 public static class PickLocationTowardsPlayerAction implements TriggerAction {
1118 protected SectorEntityToken entity;
1119 protected float arc;
1120 protected float minDist;
1121 protected float maxDist;
1122 protected float minDistFromPlayer;
1123
1124 public PickLocationTowardsPlayerAction(SectorEntityToken entity,
1125 float arc, float minDist, float maxDist, float minDistFromPlayer) {
1126 this.entity = entity;
1127 this.arc = arc;
1128 this.minDist = minDist;
1129 this.maxDist = maxDist;
1130 this.minDistFromPlayer = minDistFromPlayer;
1131 }
1132
1133 public void doAction(TriggerActionContext context) {
1134 if (entity == null) entity = context.entity;
1135 if (entity == null) entity = context.jumpPoint;
1136
1137 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
1138 float dir = Misc.getAngleInDegrees(playerFleet.getLocation(), entity.getLocation());
1139 dir += 180f;
1140 if (playerFleet.getContainingLocation() != entity.getContainingLocation()) {
1141 dir = ((BaseHubMission)context.mission).genRandom.nextFloat() * 360f;
1142 }
1143
1144 Vector2f pick = pickLocationWithinArc(((BaseHubMission)context.mission).genRandom, entity, dir, arc, minDistFromPlayer, minDist, maxDist);
1145
1146 context.coordinates = pick;
1147 //context.containingLocation = playerFleet.getContainingLocation();
1148 context.containingLocation = entity.getContainingLocation();
1149 }
1150 }
1151 public static class PickLocationTowardsEntityAction implements TriggerAction {
1152 protected SectorEntityToken entity;
1153 protected float arc;
1154 protected float minDist;
1155 protected float maxDist;
1156 protected float minDistFromPlayer;
1157
1158 public PickLocationTowardsEntityAction(SectorEntityToken entity,
1159 float arc, float minDist, float maxDist, float minDistFromPlayer) {
1160 this.entity = entity;
1161 this.arc = arc;
1162 this.minDist = minDist;
1163 this.maxDist = maxDist;
1164 this.minDistFromPlayer = minDistFromPlayer;
1165 }
1166
1167 public void doAction(TriggerActionContext context) {
1168 if (entity == null) entity = context.entity;
1169 if (entity == null) entity = context.jumpPoint;
1170
1171 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
1172 float dir = Misc.getAngleInDegrees(playerFleet.getLocation(), entity.getLocation());
1173 //dir += 180f;
1174 if (playerFleet.getContainingLocation() != entity.getContainingLocation()) {
1175 dir = ((BaseHubMission)context.mission).genRandom.nextFloat() * 360f;
1176 }
1177
1178 Vector2f pick = pickLocationWithinArc(((BaseHubMission)context.mission).genRandom, playerFleet, dir, arc, minDistFromPlayer, minDist, maxDist);
1179
1180 context.coordinates = pick;
1181 //context.containingLocation = playerFleet.getContainingLocation();
1182 context.containingLocation = entity.getContainingLocation();
1183 }
1184 }
1185
1186
1187 public static class PickLocationAwayFromPlayerAction implements
1188 TriggerAction {
1189 protected float minDist;
1190 protected SectorEntityToken entity;
1191 protected float maxDist;
1192 protected float arc;
1193 protected float minDistFromPlayer;
1194
1195 public PickLocationAwayFromPlayerAction(float minDist,
1196 SectorEntityToken entity, float maxDist, float arc,
1197 float minDistFromPlayer) {
1198 this.minDist = minDist;
1199 this.entity = entity;
1200 this.maxDist = maxDist;
1201 this.arc = arc;
1202 this.minDistFromPlayer = minDistFromPlayer;
1203 }
1204
1205 public void doAction(TriggerActionContext context) {
1206 if (entity == null) entity = context.entity;
1207 if (entity == null) entity = context.jumpPoint;
1208
1209 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
1210 float dir = Misc.getAngleInDegrees(playerFleet.getLocation(), entity.getLocation());
1211 if (playerFleet.getContainingLocation() != entity.getContainingLocation()) {
1212 dir = ((BaseHubMission)context.mission).genRandom.nextFloat() * 360f;
1213 }
1214
1215 Vector2f pick = pickLocationWithinArc(((BaseHubMission)context.mission).genRandom, entity, dir, arc, minDistFromPlayer, minDist, maxDist);
1216
1217 context.coordinates = pick;
1218 //context.containingLocation = playerFleet.getContainingLocation();
1219 context.containingLocation = entity.getContainingLocation();
1220 }
1221 }
1222
1223
1224 public static class PickLocationAroundPlayerAction implements TriggerAction {
1225 protected float maxDist;
1226 protected float minDist;
1227
1228 public PickLocationAroundPlayerAction(float maxDist, float minDist) {
1229 this.maxDist = maxDist;
1230 this.minDist = minDist;
1231 }
1232
1233 public void doAction(TriggerActionContext context) {
1234 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
1235 Vector2f pick = pickLocationWithinArc(((BaseHubMission)context.mission).genRandom, playerFleet, 0, 360f, minDist, minDist, maxDist);
1236
1237 context.coordinates = pick;
1238 context.containingLocation = playerFleet.getContainingLocation();
1239 }
1240 }
1241
1242
1243 public static class PickLocationAroundEntityAction implements TriggerAction {
1244 protected float minDist;
1245 protected SectorEntityToken entity;
1246 protected float maxDist;
1247 protected float minDistFromPlayer;
1248
1249 public PickLocationAroundEntityAction(float minDist,
1250 SectorEntityToken entity, float maxDist, float minDistFromPlayer) {
1251 this.minDist = minDist;
1252 this.entity = entity;
1253 this.maxDist = maxDist;
1254 this.minDistFromPlayer = minDistFromPlayer;
1255 }
1256
1257 public void doAction(TriggerActionContext context) {
1258 if (entity == null) entity = context.entity;
1259 if (entity == null) entity = context.jumpPoint;
1260 Vector2f pick = pickLocationWithinArc(((BaseHubMission)context.mission).genRandom, entity, 0, 360f, minDistFromPlayer, minDist, maxDist);
1261
1262 context.coordinates = pick;
1263 context.containingLocation = entity.getContainingLocation();
1264 }
1265 }
1266
1267
1268 public static class PickLocationWithinArcAction implements TriggerAction {
1269 protected float arc;
1270 protected SectorEntityToken entity;
1271 protected float maxDist;
1272 protected float minDist;
1273 protected float minDistFromPlayer;
1274 protected float dir;
1275
1276 public PickLocationWithinArcAction(float arc, SectorEntityToken entity,
1277 float maxDist, float minDist, float minDistFromPlayer, float dir) {
1278 this.arc = arc;
1279 this.entity = entity;
1280 this.maxDist = maxDist;
1281 this.minDist = minDist;
1282 this.minDistFromPlayer = minDistFromPlayer;
1283 this.dir = dir;
1284 }
1285
1286 public void doAction(TriggerActionContext context) {
1287 if (entity == null) entity = context.entity;
1288 if (entity == null) entity = context.jumpPoint;
1289
1290 Vector2f pick = pickLocationWithinArc(((BaseHubMission)context.mission).genRandom, entity, dir, arc, minDistFromPlayer, minDist, maxDist);
1291
1292 context.coordinates = pick;
1293 context.containingLocation = entity.getContainingLocation();
1294 }
1295 }
1296
1297
1298 public static class FleetSetPatrolActionText implements TriggerAction {
1299 protected String text;
1300 public FleetSetPatrolActionText(String text) {
1301 this.text = text;
1302 }
1303
1304 public void doAction(TriggerActionContext context) {
1305 context.patrolText = text;
1306 }
1307 }
1308
1309 public static class FleetSetTravelActionText implements TriggerAction {
1310 protected String text;
1311 public FleetSetTravelActionText(String text) {
1312 this.text = text;
1313 }
1314
1315 public void doAction(TriggerActionContext context) {
1316 context.travelText = text;
1317 }
1318 }
1319
1320 public static class OrderFleetPatrolSystemAction implements TriggerAction {
1321 protected StarSystemAPI system;
1322
1323 public OrderFleetPatrolSystemAction(StarSystemAPI system) {
1324 this.system = system;
1325 }
1326
1327 public void doAction(TriggerActionContext context) {
1328 context.fleet.addScript(new TriggerFleetAssignmentAI(context.travelText, context.patrolText, context.mission, system, false,
1329 context.fleet, (SectorEntityToken[])null));
1330 }
1331 }
1332
1333
1334 public static class OrderFleetPatrolPointsAction implements TriggerAction {
1335 protected List<SectorEntityToken> patrolPoints;
1336 protected boolean randomizeLocation;
1337 protected StarSystemAPI system;
1338
1339 public OrderFleetPatrolPointsAction(SectorEntityToken[] patrolPoints,
1340 boolean randomizeLocation, StarSystemAPI system) {
1341 this.patrolPoints = new ArrayList<SectorEntityToken>();
1342 for (SectorEntityToken curr : patrolPoints) {
1343 this.patrolPoints.add(curr);
1344 }
1345 this.randomizeLocation = randomizeLocation;
1346 this.system = system;
1347 }
1348
1349 public void doAction(TriggerActionContext context) {
1350 context.fleet.addScript(new TriggerFleetAssignmentAI(context.travelText, context.patrolText,
1351 context.mission, system, randomizeLocation, context.fleet, patrolPoints.toArray(new SectorEntityToken[0])));
1352 }
1353 }
1354
1355 public static class OrderFleetPatrolSpawnedEntity implements TriggerAction {
1356 protected boolean moveToNearEntity;
1357
1358 public OrderFleetPatrolSpawnedEntity(boolean moveToNearEntity) {
1359 this.moveToNearEntity = moveToNearEntity;
1360 }
1361
1362 public void doAction(TriggerActionContext context) {
1363 SectorEntityToken entity = context.entity;
1364 if (entity == null) entity = context.jumpPoint;
1365 if (entity == null) entity = context.token;
1366 if (entity == null) entity = context.planet;
1367 context.fleet.addScript(
1368 new TriggerFleetAssignmentAI(context.travelText, context.patrolText, context.mission,
1369 context.entity.getContainingLocation(), moveToNearEntity, context.fleet, entity));
1370 }
1371 }
1372
1373
1374 public static class OrderFleetPatrolTagsAction implements TriggerAction {
1375 protected List<SectorEntityToken> added;
1376 protected StarSystemAPI system;
1377 protected boolean randomizeLocation;
1378 protected String[] tags;
1379
1380 public OrderFleetPatrolTagsAction(StarSystemAPI system,
1381 boolean randomizeLocation, String ... tags) {
1382 this.system = system;
1383 this.randomizeLocation = randomizeLocation;
1384 this.tags = tags;
1385 }
1386
1387 public void doAction(TriggerActionContext context) {
1388 List<SectorEntityToken> points = new ArrayList<SectorEntityToken>();
1389 for (SectorEntityToken entity : system.getAllEntities()) {
1390 for (String tag : tags) {
1391 if (entity.hasTag(tag)) {
1392 points.add(entity);
1393 break;
1394 }
1395 }
1396 }
1397 if (added != null) points.addAll(added);
1398 context.fleet.addScript(new TriggerFleetAssignmentAI(context.travelText, context.patrolText, context.mission, system, randomizeLocation, context.fleet,
1399 points.toArray(new SectorEntityToken[0])));
1400 }
1401 }
1402
1403 public static class OrderFleetStopPursuingPlayerUnlessInStage implements TriggerAction {
1404 protected List<Object> stages;
1405 protected BaseHubMission mission;
1406 public OrderFleetStopPursuingPlayerUnlessInStage(BaseHubMission mission, Object...stages) {
1407 this.mission = mission;
1408 this.stages = Arrays.asList(stages);
1409 }
1410
1411 public void doAction(TriggerActionContext context) {
1412 context.fleet.addScript(new MissionFleetStopPursuingPlayer(context.fleet, mission, stages));
1413 }
1414 }
1415
1416 public static class OrderFleetInterceptNearbyPlayerInStage implements TriggerAction {
1417 protected List<Object> stages;
1418 protected BaseHubMission mission;
1419 protected float maxRange;
1420 protected boolean repeatable;
1421 protected boolean mustBeStrongEnoughToFight;
1422 protected float repeatDelay;
1423 public OrderFleetInterceptNearbyPlayerInStage(BaseHubMission mission,
1424 boolean mustBeStrongEnoughToFight,
1425 float maxRange,
1426 boolean repeatable, float repeatDelay, Object...stages) {
1427 this.mission = mission;
1428 this.mustBeStrongEnoughToFight = mustBeStrongEnoughToFight;
1429 this.maxRange = maxRange;
1430 this.repeatable = repeatable;
1431 this.repeatDelay = repeatDelay;
1432 this.stages = Arrays.asList(stages);
1433 }
1434
1435 public void doAction(TriggerActionContext context) {
1436 context.fleet.addScript(new MissionFleetInterceptPlayerIfNearby(context.fleet, mission,
1437 mustBeStrongEnoughToFight, maxRange, repeatable, repeatDelay, stages));
1438 }
1439 }
1440
1441
1442 public static class OrderFleetInterceptPlayerAction implements TriggerAction {
1443 protected boolean makeHostile;
1444 public OrderFleetInterceptPlayerAction(boolean makeHostile) {
1445 this.makeHostile = makeHostile;
1446 }
1447
1448 public void doAction(TriggerActionContext context) {
1449 TransmitterTrapSpecial.makeFleetInterceptPlayer(context.fleet, false, false, makeHostile, 1000f);
1450 if (!context.fleet.hasScriptOfClass(MissionFleetAutoDespawn.class)) {
1451 context.fleet.addScript(new MissionFleetAutoDespawn(context.mission, context.fleet));
1452 }
1453 }
1454 }
1455
1456 public static class OrderFleetEBurn implements TriggerAction {
1457 public OrderFleetEBurn() {
1458 }
1459
1460 public void doAction(TriggerActionContext context) {
1461 AbilityPlugin eb = context.fleet.getAbility(Abilities.EMERGENCY_BURN);
1462 if (eb != null && eb.isUsable()) eb.activate();
1463 }
1464 }
1465
1466
1467 public static class FleetNoAutoDespawnAction implements TriggerAction {
1468 public void doAction(TriggerActionContext context) {
1469 context.fleet.removeScriptsOfClass(MissionFleetAutoDespawn.class);
1470 }
1471 }
1472
1473
1474 public static class PickLocationAtInSystemJumpPointAction implements TriggerAction {
1475 protected StarSystemAPI system;
1476 protected float minDistFromPlayer;
1477
1478 public PickLocationAtInSystemJumpPointAction(StarSystemAPI system,
1479 float minDistFromPlayer) {
1480 this.system = system;
1481 this.minDistFromPlayer = minDistFromPlayer;
1482 }
1483
1484 public void doAction(TriggerActionContext context) {
1485 WeightedRandomPicker<SectorEntityToken> picker = new WeightedRandomPicker<SectorEntityToken>(((BaseHubMission)context.mission).genRandom);
1486 picker.addAll(system.getJumpPoints());
1487
1488 SectorEntityToken pick = picker.pick();
1489 Vector2f loc = pickLocationWithinArc(((BaseHubMission)context.mission).genRandom, pick, 0, 360f, minDistFromPlayer, 0f, 0f);
1490
1491 context.jumpPoint = pick;
1492 context.coordinates = loc;
1493 context.containingLocation = system;
1494 }
1495 }
1496
1497 public static class PickLocationAtClosestToPlayerJumpPointAction implements TriggerAction {
1498 protected StarSystemAPI system;
1499 protected float minDistFromPlayer;
1500
1501 public PickLocationAtClosestToPlayerJumpPointAction(StarSystemAPI system, float minDistFromPlayer) {
1502 this.system = system;
1503 this.minDistFromPlayer = minDistFromPlayer;
1504 }
1505
1506 public void doAction(TriggerActionContext context) {
1507 WeightedRandomPicker<SectorEntityToken> picker = new WeightedRandomPicker<SectorEntityToken>(((BaseHubMission)context.mission).genRandom);
1508
1509 SectorEntityToken closest = null;
1510 float minDist = Float.MAX_VALUE;
1511 for (SectorEntityToken jp : system.getJumpPoints()) {
1512 if (system.isCurrentLocation()) {
1513 float dist = Misc.getDistance(jp, Global.getSector().getPlayerFleet());
1514 if (dist < minDist) {
1515 closest = jp;
1516 minDist = dist;
1517 }
1518 } else {
1519 picker.add(jp);
1520 }
1521 }
1522 if (closest != null) {
1523 picker.add(closest);
1524 }
1525
1526 SectorEntityToken pick = picker.pick();
1527 Vector2f loc = pickLocationWithinArc(((BaseHubMission)context.mission).genRandom, pick, 0, 360f, minDistFromPlayer, 0f, 0f);
1528
1529 context.jumpPoint = pick;
1530 context.coordinates = loc;
1531 context.containingLocation = system;
1532 }
1533 }
1534
1541 public static class PickLocationAtClosestToEntityJumpPointAction implements TriggerAction {
1542 protected StarSystemAPI system;
1543 protected float minDistFromEntity;
1544 protected SectorEntityToken entity;
1545
1546 public PickLocationAtClosestToEntityJumpPointAction(StarSystemAPI system, SectorEntityToken entity, float minDistFromEntity) {
1547 this.system = system;
1548 this.entity = entity;
1549 this.minDistFromEntity = minDistFromEntity;
1550 }
1551
1552 public void doAction(TriggerActionContext context) {
1553 WeightedRandomPicker<SectorEntityToken> picker = new WeightedRandomPicker<SectorEntityToken>(((BaseHubMission)context.mission).genRandom);
1554
1555 SectorEntityToken closest = null;
1556 float minDist = Float.MAX_VALUE;
1557 for (SectorEntityToken jp : system.getJumpPoints()) {
1558 if (system.isCurrentLocation()) {
1559 float dist = Misc.getDistance(jp, entity);
1560 if (dist < minDist) {
1561 closest = jp;
1562 minDist = dist;
1563 }
1564 } else {
1565 picker.add(jp);
1566 }
1567 }
1568 if (closest != null) {
1569 picker.add(closest);
1570 }
1571
1572 SectorEntityToken pick = picker.pick();
1573 Vector2f loc = pickLocationWithinArc(((BaseHubMission)context.mission).genRandom, pick, 0, 360f, minDistFromEntity, 0f, 0f);
1574
1575 context.jumpPoint = pick;
1576 context.coordinates = loc;
1577 context.containingLocation = system;
1578 }
1579 }
1580
1581 public static class CreateFleetAction implements TriggerAction {
1582 public long seed;
1583
1584 public FleetParamsV3 params;
1585 public FleetSize fSize;
1586 public Float fSizeOverride;
1587 public Float combatFleetPointsOverride;
1588 public FleetQuality fQuality;
1589 public Float fQualityMod;
1590 public Integer fQualitySMods;
1591 public OfficerNum oNum;
1592 public OfficerQuality oQuality;
1593 public Boolean doNotIntegrateAICores;
1594 public String faction = null;
1595
1596 public Float freighterMult = null;
1597 public Float tankerMult = null;
1598 public Float linerMult = null;
1599 public Float transportMult = null;
1600 public Float utilityMult = null;
1601 public Float qualityMod = null;
1602
1603 public Float damage = null;
1604
1605 public Boolean allWeapons;
1606 public ShipPickMode shipPickMode;
1607 public Boolean removeInflater;
1608
1609 public String nameOverride = null;
1610 public Boolean noFactionInName = null;
1611
1612 public CreateFleetAction(String type, Vector2f locInHyper,
1613 FleetSize fSize, FleetQuality fQuality, String factionId) {
1614 seed = Misc.genRandomSeed();
1615 params = new FleetParamsV3(locInHyper, factionId, null, type, 0f, 0f, 0f, 0f, 0f, 0f, 0f);
1616 params.ignoreMarketFleetSizeMult = true;
1617
1618 this.fSize = fSize;
1619 this.fQuality = fQuality;
1620
1621 freighterMult = 0.1f;
1622 tankerMult = 0.1f;
1623 }
1624
1625 public void doAction(TriggerActionContext context) {
1626 //Random random = new Random(seed);
1627 Random random = null;
1628 if (context.mission != null) {
1629 random = ((BaseHubMission)context.mission).genRandom;
1630 } else {
1631 random = Misc.random;
1632 }
1633 FactionAPI faction = Global.getSector().getFaction(params.factionId);
1634 float maxPoints = faction.getApproximateMaxFPPerFleet(ShipPickMode.PRIORITY_THEN_ALL);
1635
1636 //strength = FleetStrength.MAXIMUM;
1637
1638 //float fraction = fSize.maxFPFraction * (0.9f + random.nextFloat() * 0.2f);
1639 float min = fSize.maxFPFraction - (fSize.maxFPFraction - fSize.prev().maxFPFraction) / 2f;
1640 float max = fSize.maxFPFraction + (fSize.next().maxFPFraction - fSize.maxFPFraction) / 2f;
1641 float fraction = min + (max - min) * random.nextFloat();
1642
1643 float excess = 0;
1644
1645 if (fSizeOverride != null) {
1646 fraction = fSizeOverride * (0.95f + random.nextFloat() * 0.1f);
1647 }
1648 else {
1649 int numShipsDoctrine = 1;
1650 if (params.doctrineOverride != null) numShipsDoctrine = params.doctrineOverride.getNumShips();
1651 else if (faction != null) numShipsDoctrine = faction.getDoctrine().getNumShips();
1652 float doctrineMult = FleetFactoryV3.getDoctrineNumShipsMult(numShipsDoctrine);
1653 fraction *= 0.75f * doctrineMult;
1654 if (fraction > FleetSize.MAXIMUM.maxFPFraction) {
1655 excess = fraction - FleetSize.MAXIMUM.maxFPFraction;
1656 fraction = FleetSize.MAXIMUM.maxFPFraction;
1657 }
1658 }
1659
1660 //fraction = 1f;
1661
1662 float combatPoints = fraction * maxPoints;
1663 if (combatFleetPointsOverride != null) {
1664 combatPoints = combatFleetPointsOverride;
1665 }
1666
1667 FactionDoctrineAPI doctrine = params.doctrineOverride;
1668 if (excess > 0) {
1669 if (doctrine == null) {
1670 doctrine = faction.getDoctrine().clone();
1671 }
1672 int added = (int)Math.round(excess / 0.1f);
1673 if (added > 0) {
1674 doctrine.setOfficerQuality(Math.min(5, doctrine.getOfficerQuality() + added));
1675 doctrine.setShipQuality(doctrine.getShipQuality() + added);
1676 }
1677 }
1678// if (fraction > 0.5f && false) {
1679// if (doctrine == null) {
1680// doctrine = faction.getDoctrine().clone();
1681// }
1682// int added = (int)Math.round((fraction - 0.5f) / 0.1f);
1683// if (added > 0) {
1684// doctrine.setNumShips(Math.max(1, doctrine.getNumShips() - added));
1685// doctrine.setOfficerQuality(Math.min(5, doctrine.getOfficerQuality() + added));
1686// doctrine.setShipQuality(doctrine.getShipQuality() + added);
1687// }
1688// }
1689
1690 if (freighterMult == null) freighterMult = 0f;
1691 if (tankerMult == null) tankerMult = 0f;
1692 if (linerMult == null) linerMult = 0f;
1693 if (transportMult == null) transportMult = 0f;
1694 if (utilityMult == null) utilityMult = 0f;
1695 if (qualityMod == null) qualityMod = 0f;
1696
1697 params.combatPts = combatPoints;
1698 params.freighterPts = combatPoints * freighterMult;
1699 params.tankerPts = combatPoints * tankerMult;
1700 params.transportPts = combatPoints * transportMult;
1701 params.linerPts = combatPoints * linerMult;
1702 params.utilityPts = combatPoints * utilityMult;
1703 params.qualityMod = qualityMod;
1704
1705// if (damage != null && damage > 0) {
1706// if (damage > 1) damage = 1f;
1707// float mult1 = 1f - damage;
1708// float mult2 = 1f - damage * 0.5f;
1709// params.combatPts *= mult1;
1710// params.freighterPts *= mult2;
1711// params.tankerPts *= mult2;
1712// params.transportPts *= mult2;
1713// params.linerPts *= mult2;
1714// params.utilityPts *= mult2;
1715// }
1716
1717 //params.modeOverride = ShipPickMode.PRIORITY_THEN_ALL;
1718 params.doctrineOverride = doctrine;
1719 params.random = random;
1720
1721
1722 if (fQuality != null) {
1723 switch (fQuality) {
1724 case VERY_LOW:
1725 if (fQualityMod != null) {
1726 params.qualityMod += fQuality.qualityMod;
1727 } else {
1728 params.qualityOverride = 0f;
1729 }
1730 break;
1731 case LOWER:
1732 params.qualityMod += fQuality.qualityMod;
1733 break;
1734 case DEFAULT:
1735 params.qualityMod += fQuality.qualityMod;
1736 break;
1737 case HIGHER:
1738 params.qualityMod += fQuality.qualityMod;
1739 break;
1740 case VERY_HIGH:
1741 if (fQualityMod != null) {
1742 params.qualityMod += fQuality.qualityMod;
1743 } else {
1744 params.qualityMod += fQuality.qualityMod;
1745 //params.qualityOverride = 1f;
1746 }
1747 break;
1748 case SMOD_1:
1749 params.qualityMod += fQuality.qualityMod;
1750 params.averageSMods = fQuality.numSMods;
1751 break;
1752 case SMOD_2:
1753 params.qualityMod += fQuality.qualityMod;
1754 params.averageSMods = fQuality.numSMods;
1755 break;
1756 case SMOD_3:
1757 params.qualityMod += fQuality.qualityMod;
1758 params.averageSMods = fQuality.numSMods;
1759 break;
1760 }
1761 }
1762 if (fQualityMod != null) {
1763 params.qualityMod += fQualityMod;
1764 }
1765 if (fQualitySMods != null) {
1766 params.averageSMods = fQualitySMods;
1767 }
1768
1769 if (oNum != null) {
1770 switch (oNum) {
1771 case NONE:
1772 params.withOfficers = false;
1773 break;
1774 case FC_ONLY:
1775 params.officerNumberMult = 0f;
1776 break;
1777 case FEWER:
1778 params.officerNumberMult = 0.5f;
1779 break;
1780 case DEFAULT:
1781 break;
1782 case MORE:
1783 params.officerNumberMult = 1.5f;
1784 break;
1785 case ALL_SHIPS:
1786 params.officerNumberBonus = Global.getSettings().getInt("maxShipsInAIFleet");
1787 break;
1788 }
1789 }
1790
1791 if (oQuality != null) {
1792 switch (oQuality) {
1793 case LOWER:
1794 params.officerLevelBonus = -3;
1795 params.officerLevelLimit = Global.getSettings().getInt("officerMaxLevel") - 1;
1796 params.commanderLevelLimit = Global.getSettings().getInt("maxAIFleetCommanderLevel") - 2;
1797 if (params.commanderLevelLimit < params.officerLevelLimit) {
1798 params.commanderLevelLimit = params.officerLevelLimit;
1799 }
1800 break;
1801 case DEFAULT:
1802 break;
1803 case HIGHER:
1804 params.officerLevelBonus = 2;
1805 params.officerLevelLimit = Global.getSettings().getInt("officerMaxLevel") + (int) OfficerTraining.MAX_LEVEL_BONUS;
1806 break;
1807 case UNUSUALLY_HIGH:
1808 params.officerLevelBonus = 4;
1809 params.officerLevelLimit = SalvageSpecialAssigner.EXCEPTIONAL_PODS_OFFICER_LEVEL;
1810 break;
1811 case AI_GAMMA:
1812 case AI_BETA:
1813 case AI_BETA_OR_GAMMA:
1814 case AI_ALPHA:
1815 case AI_MIXED:
1816 case AI_OMEGA:
1817 params.aiCores = oQuality;
1818 break;
1819 }
1820 if (doNotIntegrateAICores != null) {
1821 params.doNotIntegrateAICores = doNotIntegrateAICores;
1822 }
1823 }
1824
1825 if (shipPickMode != null) {
1826 params.modeOverride = shipPickMode;
1827 }
1828
1829 params.updateQualityAndProducerFromSourceMarket();
1830 context.fleet = FleetFactoryV3.createFleet(params);
1831 context.fleet.setFacing(random.nextFloat() * 360f);
1832
1833 if (this.faction != null) {
1834 context.fleet.setFaction(this.faction, true);
1835 }
1836
1837 if (this.nameOverride != null) {
1838 context.fleet.setName(this.nameOverride);
1839 }
1840 if (this.noFactionInName != null && this.noFactionInName) {
1841 context.fleet.setNoFactionInName(noFactionInName);
1842 }
1843
1844 if (removeInflater != null && removeInflater) {
1845 context.fleet.setInflater(null);
1846 } else {
1847 if (context.fleet.getInflater() instanceof DefaultFleetInflater) {
1848 DefaultFleetInflater inflater = (DefaultFleetInflater) context.fleet.getInflater();
1849 if (inflater.getParams() instanceof DefaultFleetInflaterParams) {
1850 DefaultFleetInflaterParams p = (DefaultFleetInflaterParams) inflater.getParams();
1851 if (allWeapons != null) {
1852 p.allWeapons = allWeapons;
1853 }
1854 if (shipPickMode != null) {
1855 p.mode = shipPickMode;
1856 }
1857 }
1858 }
1859 }
1860
1861 context.fleet.getMemoryWithoutUpdate().set(MemFlags.FLEET_BUSY, true);
1862 //context.fleet.getMemoryWithoutUpdate().set("$LP_titheAskedFor", true);
1863
1864 context.allFleets.add(context.fleet);
1865
1866 if (!context.fleet.hasScriptOfClass(MissionFleetAutoDespawn.class)) {
1867 context.fleet.addScript(new MissionFleetAutoDespawn(context.mission, context.fleet));
1868 }
1869
1870 if (damage != null) {
1871 FleetFactoryV3.applyDamageToFleet(context.fleet, damage, false, random);
1872 }
1873
1874// if (Factions.PIRATES.equals(params.factionId)) {
1875//
1876// }
1877 }
1878 }
1879
1880
1881// public TriggerAction getPreviousAction() {
1882// if (currTrigger.getActions().isEmpty()) return null;
1883// return currTrigger.getActions().get(currTrigger.getActions().size() - 1);
1884// }
1885 public CreateFleetAction getPreviousCreateFleetAction() {
1886 for (int i = currTrigger.getActions().size() - 1; i >= 0; i--) {
1887 TriggerAction action = currTrigger.getActions().get(i);
1888 if (action instanceof CreateFleetAction) {
1889 return (CreateFleetAction) action;
1890 }
1891 }
1892 return null;
1893 }
1894
1895 public void triggerMovePersonToMarket(PersonAPI person, MarketAPI market, boolean alwaysAddToComms) {
1896 triggerCustomAction(new MovePersonToMarket(person, market, alwaysAddToComms));
1897 }
1898 public void triggerIncreaseMarketHostileTimeout(MarketAPI market, float days) {
1899 triggerCustomAction(new IncreaseMarketHostileTimeout(market, days));
1900 }
1901 public void triggerRunScriptAfterDelay(float delay, Script script) {
1902 triggerCustomAction(new RunScriptAfterDelay(delay, script));
1903 }
1904 public void triggerAddTagAfterDelay(float delay, StarSystemAPI system, String tag) {
1905 triggerCustomAction(new AddTagAfterDelay(delay, system, tag));
1906 }
1907 public void triggerSetMemoryValueAfterDelay(float delay, HasMemory hasMemory, String key, Object value) {
1908 triggerSetMemoryValueAfterDelay(delay, hasMemory.getMemory(), key, value);
1909 }
1910 public void triggerSetMemoryValueAfterDelay(float delay, MemoryAPI memory, String key, Object value) {
1911 triggerCustomAction(new SetMemoryValueAfterDelay(delay, memory, key, value));
1912 }
1913 public void triggerSetGlobalMemoryValueAfterDelay(float delay, String key, Object value) {
1914 triggerCustomAction(new SetMemoryValueAfterDelay(delay, Global.getSector().getMemory(), key, value));
1915 }
1916 public float genDelay(float base) {
1917 return base * StarSystemGenerator.getNormalRandom(genRandom, 0.75f, 1.25f);
1918 }
1919
1920 public void triggerUnhideCommListing(PersonAPI person) {
1921 triggerCustomAction(new UnhideCommListing(person));
1922 }
1923 public void triggerHideCommListing(PersonAPI person) {
1924 triggerCustomAction(new HideCommListing(person));
1925 }
1926 public void triggerSaveGlobalEntityRef(String key) {
1927 triggerSaveEntityRef(Global.getSector().getMemoryWithoutUpdate(), key);
1928 }
1929 public void triggerSaveEntityRef(MemoryAPI memory, String key) {
1930 triggerCustomAction(new SaveEntityReferenceAction(memory, key));
1931 }
1932 public void triggerSaveGlobalFleetRef(String key) {
1933 triggerSaveFleetRef(Global.getSector().getMemoryWithoutUpdate(), key);
1934 }
1935 public void triggerSaveFleetRef(MemoryAPI memory, String key) {
1936 triggerCustomAction(new SaveFleetReferenceAction(memory, key));
1937 }
1938
1939 public SectorEntityToken getEntityFromGlobal(String key) {
1940 return Global.getSector().getMemoryWithoutUpdate().getEntity(key);
1941 }
1942
1943 public void triggerCreateFleet(FleetSize size, FleetQuality quality, String factionId, String type, StarSystemAPI roughlyWhere) {
1944 triggerCustomAction(new CreateFleetAction(type, roughlyWhere.getLocation(), size, quality, factionId));
1945 }
1946 public void triggerCreateFleet(FleetSize size, FleetQuality quality, String factionId, String type, SectorEntityToken roughlyWhere) {
1947 triggerCustomAction(new CreateFleetAction(type, roughlyWhere.getLocationInHyperspace(), size, quality, factionId));
1948 }
1949 public void triggerCreateFleet(FleetSize size, FleetQuality quality, String factionId, String type, Vector2f locInHyper) {
1950 triggerCustomAction(new CreateFleetAction(type, locInHyper, size, quality, factionId));
1951 }
1952
1953 public void triggerAutoAdjustFleetSize(FleetSize min, FleetSize max) {
1954 float f = getQualityFraction();
1955 CreateFleetAction cfa = getPreviousCreateFleetAction();
1956 cfa.fSizeOverride = min.maxFPFraction + (max.maxFPFraction - min.maxFPFraction) * f;
1957
1959 }
1960
1961 public void triggerSetFleetSizeFraction(float fractionOfMax) {
1962 CreateFleetAction cfa = getPreviousCreateFleetAction();
1963 cfa.fSizeOverride = fractionOfMax;
1964 }
1965 public void triggerSetFleetCombatFleetPoints(float combatFleetPointsOverride) {
1966 CreateFleetAction cfa = getPreviousCreateFleetAction();
1967 cfa.combatFleetPointsOverride = combatFleetPointsOverride;
1968 }
1969 public void triggerAutoAdjustFleetQuality(FleetQuality min, FleetQuality max) {
1970 float f = getQualityFraction();
1971 CreateFleetAction cfa = getPreviousCreateFleetAction();
1972 cfa.fQualityMod = min.qualityMod + (max.qualityMod - min.qualityMod) * f;
1973 cfa.fQualitySMods = (int) Math.round(min.numSMods + (max.numSMods - min.numSMods) * f);
1974 if (cfa.fQualitySMods <= 0) {
1975 cfa.fQualitySMods = null;
1976 }
1977 }
1978
1979 public void triggerAutoAdjustOfficerNum(OfficerNum min, OfficerNum max) {
1980 float f = getQualityFraction();
1981 CreateFleetAction cfa = getPreviousCreateFleetAction();
1982 cfa.oNum = (OfficerNum) pickEnum(f, getEnums(min, max));
1983 }
1984 public void triggerAutoAdjustOfficerQuality(OfficerQuality min, OfficerQuality max) {
1985 float f = getQualityFraction();
1986 CreateFleetAction cfa = getPreviousCreateFleetAction();
1987 cfa.oQuality = (OfficerQuality) pickEnum(f, getEnums(min, max));
1988 }
1989
1990 public void triggerSetFleetQuality(FleetQuality quality) {
1991 CreateFleetAction cfa = getPreviousCreateFleetAction();
1992 if (cfa != null) {
1993 cfa.fQuality = quality;
1994 }
1995 }
1996 public void triggerSetFleetSize(FleetSize size) {
1997 CreateFleetAction cfa = getPreviousCreateFleetAction();
1998 if (cfa != null) {
1999 cfa.fSize= size;
2000 }
2001 }
2002
2004 CreateFleetAction cfa = getPreviousCreateFleetAction();
2005 FleetSize size = cfa.fSize;
2006 if (size == null) size = FleetSize.MEDIUM;
2007
2008 float min = size.maxFPFraction - (size.maxFPFraction - size.prev().maxFPFraction) / 2f;
2009 float max = size.maxFPFraction + (size.next().maxFPFraction - size.maxFPFraction) / 2f;
2010 cfa.fSizeOverride = min + (max - min) * genRandom.nextFloat();
2011 //triggerAutoAdjustFleetSize(size.prev(), size.next());
2012
2013 FleetQuality fq = cfa.fQuality;
2014 if (fq == null) fq = FleetQuality.DEFAULT;
2015 min = fq.qualityMod - (fq.qualityMod - fq.prev().qualityMod) / 2f;
2016 max = fq.qualityMod + (fq.next().qualityMod - fq.qualityMod) / 2f;
2017 cfa.fQualityMod = min + (max - min) * genRandom.nextFloat();
2018 //triggerAutoAdjustFleetQuality(fq.prev(), fq.next());
2019 }
2020
2022 CreateFleetAction cfa = getPreviousCreateFleetAction();
2023 FleetSize size = cfa.fSize;
2024 if (size == null) size = FleetSize.MEDIUM;
2025
2026 triggerAutoAdjustFleetSize(size.prev(), size.next());
2027
2028 FleetQuality fq = cfa.fQuality;
2029 if (fq == null) fq = FleetQuality.DEFAULT;
2030 FleetQuality limit = FleetQuality.VERY_HIGH;
2031 FleetQuality next = fq;
2032 int steps = 1;
2033 while (next.next().ordinal() <= limit.ordinal() && steps > 0) {
2034 next = next.next();
2035 steps--;
2036 }
2037 limit = FleetQuality.LOWER;
2038 FleetQuality prev = fq;
2039 steps = 1;
2040 while (prev.prev().ordinal() >= limit.ordinal() && steps > 0) {
2041 prev = prev.prev();
2042 steps--;
2043 }
2045
2046
2047 OfficerNum oNum = cfa.oNum;
2048 if (oNum == null) oNum = OfficerNum.DEFAULT;
2049 if (oNum == OfficerNum.FEWER || oNum == OfficerNum.DEFAULT) {
2050 switch (oNum) {
2051 case FEWER:
2052 triggerAutoAdjustOfficerNum(OfficerNum.FEWER, OfficerNum.DEFAULT);
2053 break;
2054 case DEFAULT:
2055 triggerAutoAdjustOfficerNum(OfficerNum.DEFAULT, OfficerNum.MORE);
2056 break;
2057 }
2058 }
2059
2060 OfficerQuality oQuality = cfa.oQuality;
2061 if (oQuality == null) oQuality = OfficerQuality.DEFAULT;
2062 if (oQuality == OfficerQuality.LOWER || oQuality == OfficerQuality.DEFAULT) {
2063 switch (oQuality) {
2064 case LOWER:
2065 triggerAutoAdjustOfficerQuality(OfficerQuality.LOWER, OfficerQuality.DEFAULT);
2066 break;
2067 case DEFAULT:
2068 triggerAutoAdjustOfficerQuality(OfficerQuality.DEFAULT, OfficerQuality.HIGHER);
2069 break;
2070 }
2071 }
2072 }
2073
2075 CreateFleetAction cfa = getPreviousCreateFleetAction();
2076 FleetSize size = cfa.fSize;
2077 if (size == null) size = FleetSize.MEDIUM;
2078
2079 triggerAutoAdjustFleetSize(size.prev().prev(), size.next().next());
2080
2081 FleetQuality fq = cfa.fQuality;
2082 if (fq == null) fq = FleetQuality.DEFAULT;
2083 FleetQuality limit = FleetQuality.VERY_HIGH;
2084 FleetQuality next = fq;
2085 int steps = 2;
2086 while (next.next().ordinal() <= limit.ordinal() && steps > 0) {
2087 next = next.next();
2088 steps--;
2089 }
2090 limit = FleetQuality.LOWER;
2091 FleetQuality prev = fq;
2092 steps = 2;
2093 while (prev.prev().ordinal() >= limit.ordinal() && steps > 0) {
2094 prev = prev.prev();
2095 steps--;
2096 }
2098
2099
2100 OfficerNum oNum = cfa.oNum;
2101 if (oNum == null) oNum = OfficerNum.DEFAULT;
2102 if (oNum == OfficerNum.FEWER || oNum == OfficerNum.DEFAULT) {
2103 switch (oNum) {
2104 case FEWER:
2105 triggerAutoAdjustOfficerNum(OfficerNum.FEWER, OfficerNum.DEFAULT);
2106 break;
2107 case DEFAULT:
2108 triggerAutoAdjustOfficerNum(OfficerNum.DEFAULT, OfficerNum.MORE);
2109 break;
2110 }
2111 }
2112
2113 OfficerQuality oQuality = cfa.oQuality;
2114 if (oQuality == null) oQuality = OfficerQuality.DEFAULT;
2115 if (oQuality == OfficerQuality.LOWER || oQuality == OfficerQuality.DEFAULT) {
2116 switch (oQuality) {
2117 case LOWER:
2118 triggerAutoAdjustOfficerQuality(OfficerQuality.LOWER, OfficerQuality.DEFAULT);
2119 break;
2120 case DEFAULT:
2121 triggerAutoAdjustOfficerQuality(OfficerQuality.DEFAULT, OfficerQuality.HIGHER);
2122 break;
2123 }
2124 }
2125 }
2126
2128 CreateFleetAction cfa = getPreviousCreateFleetAction();
2129 FleetSize size = cfa.fSize;
2130 if (size == null) size = FleetSize.MEDIUM;
2131
2132 triggerAutoAdjustFleetSize(size.prev().prev(), size.next().next().next());
2133
2134 FleetQuality fq = cfa.fQuality;
2135 if (fq == null) fq = FleetQuality.DEFAULT;
2136 FleetQuality limit = FleetQuality.SMOD_1;
2137 FleetQuality next = fq;
2138 int steps = 3;
2139 while (next.next().ordinal() <= limit.ordinal() && steps > 0) {
2140 next = next.next();
2141 steps--;
2142 }
2143 limit = FleetQuality.LOWER;
2144 FleetQuality prev = fq;
2145 steps = 2;
2146 while (prev.prev().ordinal() >= limit.ordinal() && steps > 0) {
2147 prev = prev.prev();
2148 steps--;
2149 }
2151
2152
2153 OfficerNum oNum = cfa.oNum;
2154 if (oNum == null) oNum = OfficerNum.DEFAULT;
2155 if (oNum == OfficerNum.FEWER || oNum == OfficerNum.DEFAULT || oNum == OfficerNum.MORE) {
2156 switch (oNum) {
2157 case FEWER:
2158 triggerAutoAdjustOfficerNum(OfficerNum.FEWER, OfficerNum.MORE);
2159 break;
2160 case DEFAULT:
2161 triggerAutoAdjustOfficerNum(OfficerNum.FEWER, OfficerNum.ALL_SHIPS);
2162 break;
2163 case MORE:
2164 triggerAutoAdjustOfficerNum(OfficerNum.DEFAULT, OfficerNum.ALL_SHIPS);
2165 break;
2166 }
2167 }
2168
2169 OfficerQuality oQuality = cfa.oQuality;
2170 if (oQuality == null) oQuality = OfficerQuality.DEFAULT;
2171 if (oQuality == OfficerQuality.LOWER || oQuality == OfficerQuality.DEFAULT) {
2172 switch (oQuality) {
2173 case LOWER:
2174 triggerAutoAdjustOfficerQuality(OfficerQuality.LOWER, OfficerQuality.DEFAULT);
2175 break;
2176 case DEFAULT:
2177 triggerAutoAdjustOfficerQuality(OfficerQuality.DEFAULT, OfficerQuality.HIGHER);
2178 break;
2179 }
2180 }
2181 }
2182
2183
2184 protected transient boolean useQualityInsteadOfQualityFraction = false;
2191 public void setUseQualityInsteadOfQualityFraction(boolean temporarilyUseQualityInsteadOfQualityFraction) {
2192 this.useQualityInsteadOfQualityFraction = temporarilyUseQualityInsteadOfQualityFraction;
2193 }
2194
2199 protected float getQualityFraction() {
2200 float quality = getQuality();
2202 return quality;
2203 }
2204
2205 float minQuality = getMinQuality();
2206 float maxQuality = getMaxQuality();
2207 float base = getBaseQuality();
2208
2209 float f;
2210 if (quality < base) {
2211 float range = base - minQuality;
2212 f = 0f;
2213 if (range > 0) {
2214 f = (quality - minQuality) / range;
2215 }
2216 if (f < 0) f = 0;
2217 if (f > 1) f = 1;
2218 f = f * 0.5f;
2219 } else {
2220 float range = maxQuality - base;
2221 f = 1f;
2222 if (range > 0) {
2223 f = (quality - base) / range;
2224 }
2225 if (f < 0) f = 0;
2226 if (f > 1) f = 1;
2227 f = 0.5f + f * 0.5f;
2228 }
2229 return f;
2230 }
2231
2232 @SuppressWarnings("unchecked")
2233 protected Object [] getEnums(Enum from, Enum to) {
2234 return EnumSet.range(from, to).toArray();
2235 }
2236
2237 protected Object pickEnum(float f, Object ... enums) {
2238 float num = enums.length;
2239 f *= (num - 1f);
2240
2241 float rem = (float)(f - (int) f);
2242 if (rem < 0.2f) rem = 0f;
2243 if (rem > 0.8f) rem = 1f;
2244
2245 int index = (int) f;
2246 if (genRandom.nextFloat() < rem) {
2247 index++;
2248 }
2249 if (index > enums.length - 1) index = enums.length - 1;
2250 if (index < 0) index = 0;
2251 return enums[index];
2252 }
2253
2254// defaults to this
2255// public void triggerSetFleetCompositionStandardSupportShips() {
2256// triggerSetFleetComposition(0.1f, 0.1f, 0f, 0f, 0f, 0f);
2257// }
2258
2260 triggerSetFleetComposition(0f, 0f, 0f, 0f, 0f);
2261 }
2262
2263 public void triggerSetFleetComposition(float freighterMult, float tankerMult,
2264 float transportMult, float linerMult,
2265 float utilityMult) {
2266 CreateFleetAction cfa = getPreviousCreateFleetAction();
2267 if (freighterMult > 0) cfa.freighterMult = freighterMult;
2268 else cfa.freighterMult = null;
2269
2270 if (tankerMult > 0) cfa.tankerMult = tankerMult;
2271 else cfa.tankerMult = null;
2272
2273 if (transportMult > 0) cfa.transportMult = transportMult;
2274 else cfa.transportMult = null;
2275
2276 if (linerMult > 0) cfa.linerMult = linerMult;
2277 else cfa.linerMult = null;
2278
2279 if (utilityMult > 0) cfa.utilityMult = utilityMult;
2280 else cfa.utilityMult = null;
2281 }
2282
2283 public void triggerSetFleetDoctrineComp(int warships, int carriers, int phaseShips) {
2284 CreateFleetAction cfa = getPreviousCreateFleetAction();
2285
2286 if (cfa.params.doctrineOverride == null) {
2287 FactionAPI faction = Global.getSector().getFaction(cfa.params.factionId);
2288 cfa.params.doctrineOverride = faction.getDoctrine().clone();
2289 }
2290
2291 cfa.params.doctrineOverride.setWarships(warships);
2292 cfa.params.doctrineOverride.setCarriers(carriers);
2293 cfa.params.doctrineOverride.setPhaseShips(phaseShips);
2294 }
2295
2296 public void triggerAddShips(String ...variants) {
2297 CreateFleetAction cfa = getPreviousCreateFleetAction();
2298 if (cfa.params.addShips == null) {
2299 cfa.params.addShips = new ArrayList<String>();
2300 }
2301 for (String id : variants) {
2302 cfa.params.addShips.add(id);
2303 }
2304 }
2305
2307 CreateFleetAction cfa = getPreviousCreateFleetAction();
2308 if (cfa.params.doctrineOverride == null) {
2309 FactionAPI faction = Global.getSector().getFaction(cfa.params.factionId);
2310 cfa.params.doctrineOverride = faction.getDoctrine().clone();
2311 }
2312
2313 cfa.params.doctrineOverride.setCombatFreighterProbability(prob);
2314 }
2315
2316 public void triggerSetFleetDoctrineQuality(int officerQuality, int shipQuality, int numShips) {
2317 CreateFleetAction cfa = getPreviousCreateFleetAction();
2318
2319 if (cfa.params.doctrineOverride == null) {
2320 FactionAPI faction = Global.getSector().getFaction(cfa.params.factionId);
2321 cfa.params.doctrineOverride = faction.getDoctrine().clone();
2322 }
2323
2324 if (officerQuality >= 0) {
2325 cfa.params.doctrineOverride.setOfficerQuality(officerQuality);
2326 }
2327
2328 if (shipQuality >= 0) {
2329 cfa.params.doctrineOverride.setShipQuality(shipQuality);
2330 }
2331
2332 if (numShips >= 0) {
2333 cfa.params.doctrineOverride.setNumShips(numShips);
2334 }
2335 }
2336
2337 public void triggerSetFleetDoctrineOther(int shipSize, int aggression) {
2338 CreateFleetAction cfa = getPreviousCreateFleetAction();
2339
2340 if (cfa.params.doctrineOverride == null) {
2341 FactionAPI faction = Global.getSector().getFaction(cfa.params.factionId);
2342 cfa.params.doctrineOverride = faction.getDoctrine().clone();
2343 }
2344
2345 if (shipSize >= 0) {
2346 cfa.params.doctrineOverride.setShipSize(shipSize);
2347 }
2348 if (aggression >= 0) {
2349 cfa.params.doctrineOverride.setAggression(aggression);
2350 }
2351 }
2352
2353 public void triggerSetFleetDoctrineRandomize(float randomizeProb) {
2354 CreateFleetAction cfa = getPreviousCreateFleetAction();
2355
2356 if (cfa.params.doctrineOverride == null) {
2357 FactionAPI faction = Global.getSector().getFaction(cfa.params.factionId);
2358 cfa.params.doctrineOverride = faction.getDoctrine().clone();
2359 }
2360
2361 cfa.params.doctrineOverride.setAutofitRandomizeProbability(randomizeProb);
2362 }
2363
2364 public void triggerSetFleetSizeAndQuality(FleetSize size, FleetQuality quality, String fleetType) {
2365 CreateFleetAction cfa = getPreviousCreateFleetAction();
2366 cfa.fSize = size;
2367 cfa.fQuality = quality;
2368 cfa.params.fleetType = fleetType;
2369 cfa.fSizeOverride = null;
2370 }
2371 public void triggerSetFleetType(String fleetType) {
2372 CreateFleetAction cfa = getPreviousCreateFleetAction();
2373 cfa.params.fleetType = fleetType;
2374 }
2375
2376 public void triggerSetFleetOfficers(OfficerNum num, OfficerQuality quality) {
2377 CreateFleetAction cfa = getPreviousCreateFleetAction();
2378 cfa.oNum = num;
2379 cfa.oQuality = quality;
2380 }
2381
2382 public void triggerFleetSetCommander(PersonAPI commander) {
2383 CreateFleetAction cfa = getPreviousCreateFleetAction();
2384 cfa.params.commander = commander;
2385 }
2386
2388 CreateFleetAction cfa = getPreviousCreateFleetAction();
2389 cfa.params.noCommanderSkills = true;
2390 }
2391
2392 public void triggerSetFleetMaxShipSize(int max) {
2393 CreateFleetAction cfa = getPreviousCreateFleetAction();
2394 cfa.params.maxShipSize = max;
2395 }
2396 public void triggerSetFleetMinShipSize(int min) {
2397 CreateFleetAction cfa = getPreviousCreateFleetAction();
2398 cfa.params.minShipSize = min;
2399 }
2400 public void triggerSetFleetMaxNumShips(int num) {
2401 CreateFleetAction cfa = getPreviousCreateFleetAction();
2402 cfa.params.maxNumShips = num;
2403 }
2404
2406 CreateFleetAction cfa = getPreviousCreateFleetAction();
2407 cfa.params.onlyRetainFlagship = true;
2408 }
2409 public void triggerFleetSetFlagship(String variantId) {
2410 CreateFleetAction cfa = getPreviousCreateFleetAction();
2411 cfa.params.flagshipVariantId = variantId;
2412 }
2413
2414 public void triggerFleetSetFlagship(ShipVariantAPI variant) {
2415 CreateFleetAction cfa = getPreviousCreateFleetAction();
2416 cfa.params.flagshipVariant = variant;
2417 }
2418
2420 CreateFleetAction cfa = getPreviousCreateFleetAction();
2421 cfa.removeInflater = true;
2422 }
2423
2424 public void triggerFleetSetShipPickMode(ShipPickMode mode) {
2425 CreateFleetAction cfa = getPreviousCreateFleetAction();
2426 cfa.shipPickMode = mode;
2427 }
2428
2430 CreateFleetAction cfa = getPreviousCreateFleetAction();
2431 cfa.allWeapons = true;
2432 }
2433
2434// public void triggerFleetSetFaction(String factionId) {
2435// CreateFleetAction cfa = getPreviousCreateFleetAction();
2436// cfa.faction = factionId;
2437// }
2438 public void triggerSetFleetFaction(final String factionId) {
2439// triggerCustomAction(new SetFleetFactionAction(factionId));
2440 CreateFleetAction cfa = getPreviousCreateFleetAction();
2441 cfa.faction = factionId;
2442 }
2443
2444 public void triggerFleetSetName(String name) {
2445 CreateFleetAction cfa = getPreviousCreateFleetAction();
2446 cfa.nameOverride = name;
2447 }
2449 CreateFleetAction cfa = getPreviousCreateFleetAction();
2450 cfa.noFactionInName = true;
2451 }
2453 CreateFleetAction cfa = getPreviousCreateFleetAction();
2454 cfa.doNotIntegrateAICores = true;
2455 }
2456
2457 public FleetParamsV3 triggerGetFleetParams() {
2458 CreateFleetAction cfa = getPreviousCreateFleetAction();
2459 return cfa.params;
2460 }
2461
2462
2463 public void triggerSetFleetCommander(final PersonAPI commander) {
2464 triggerCustomAction(new TriggerAction() {
2465 public void doAction(TriggerActionContext context) {
2466 context.fleet.setCommander(commander);
2467 context.fleet.getFleetData().ensureHasFlagship();
2468 }
2469 });
2470 }
2471// commander will get overriden by default inflater so uh
2472// will it? doesn't seem like it would, looking at DFI
2473// public void triggerSetFleetCommanderFlags(final String ... flags) {
2474// triggerCustomAction(new TriggerAction() {
2475// public void doAction(TriggerActionContext context) {
2476// for (String flag : flags) {
2477// context.fleet.getCommander().getMemoryWithoutUpdate().set(flag, true);
2478// }
2479// }
2480// });
2481// }
2482
2483 public void triggerFleetMakeImportantPermanent(String flag) {
2484 triggerCustomAction(new FleetMakeImportantAction(flag, (Enum[]) null));
2485 }
2486 public void triggerFleetMakeImportant(String flag, Enum ... stages) {
2487 triggerCustomAction(new FleetMakeImportantAction(flag, stages));
2488 }
2489 public void triggerEntityMakeImportant(String flag, Enum ... stages) {
2490 triggerCustomAction(new EntityMakeImportantAction(flag, stages));
2491 }
2492
2493 public void triggerSetFleetFlagsWithReasonPermanent(final String ... flags) {
2494 triggerCustomAction(new SetFleetFlagsWithReasonAction(getReason(), true, flags));
2495 }
2496 public void triggerSetFleetFlagsWithReason(final String ... flags) {
2497 triggerCustomAction(new SetFleetFlagsWithReasonAction(getReason(), false, flags));
2498 }
2499
2500// public void setFleetFlagsWithReason(final String ... flags) {
2501// new SetFleetFlagsWithReasonAction(getReason(), false, flags).doAction(null);
2502// }
2503//
2504// public void setFleetFlag(String flag) {
2505// new SetFleetFlagAction(flag, false, (Object[])null).doAction(null);;
2506// }
2507
2508 public void triggerUnsetFleetFlagsWithReason(final String ... flags) {
2509 triggerCustomAction(new UnsetFleetFlagsWithReasonAction(getReason(), flags));
2510 }
2511 public void triggerSetPersonMissionRef(final String key) {
2512 triggerCustomAction(new SetPersonMissionRefAction(key));
2513 }
2514 public void triggerSetFleetMissionRef(final String key) {
2515 triggerCustomAction(new SetFleetMissionRefAction(key));
2516 }
2517
2518 public void triggerSetFleetMemoryValue(final String key, final Object value) {
2519 triggerCustomAction(new SetFleetMemoryValueAction(key, value));
2520 }
2521
2522 public void triggerSetMemoryValue(HasMemory withMemory, String key, Object value) {
2523 triggerCustomAction(new SetMemoryValueAction(withMemory.getMemoryWithoutUpdate(), key, value, true));
2524 }
2525 public void triggerSetMemoryValuePermanent(HasMemory withMemory, String key, Object value) {
2526 triggerCustomAction(new SetMemoryValueAction(withMemory.getMemoryWithoutUpdate(), key, value, false));
2527 }
2528
2529 public void triggerSetGlobalMemoryValue(final String key, final Object value) {
2530 triggerCustomAction(new SetMemoryValueAction(Global.getSector().getMemoryWithoutUpdate(), key, value, true));
2531 }
2532 public void triggerSetGlobalMemoryValuePermanent(final String key, final Object value) {
2533 triggerCustomAction(new SetMemoryValueAction(Global.getSector().getMemoryWithoutUpdate(), key, value, false));
2534 }
2535
2536 public void triggerSetFleetFlagPermanent(String flag) {
2537 triggerCustomAction(new SetFleetFlagAction(flag, true, (Object[])null));
2538 }
2539 public void triggerSetFleetGenericHailPermanent(String commsTrigger) {
2540 triggerSetFleetGenericHail(commsTrigger, (Object[])null);
2541 }
2542 public void triggerSetFleetGenericHail(String commsTrigger, Object ...stages) {
2543 if (stages == null || stages.length <= 0) {
2544 triggerSetFleetFlagPermanent("$genericHail");
2545 } else {
2546 triggerSetFleetFlag("$genericHail", stages);
2547 }
2548 triggerSetFleetMemoryValue("$genericHail_openComms", commsTrigger);
2549 }
2550 public void triggerSetFleetGenericHailIfNonHostilePermanent(String commsTrigger) {
2551 triggerSetFleetGenericHail(commsTrigger, (Object[])null);
2552 }
2553 public void triggerSetFleetGenericHailIfNonHostile(String commsTrigger, Object ...stages) {
2554 if (stages == null || stages.length <= 0) {
2555 triggerSetFleetFlagPermanent("$genericHail_nonHostile");
2556 } else {
2557 triggerSetFleetFlag("$genericHail_nonHostile", stages);
2558 }
2559 triggerSetFleetMemoryValue("$genericHail_openComms", commsTrigger);
2560 }
2561 public void triggerSetFleetFlag(String flag) {
2562 triggerCustomAction(new SetFleetFlagAction(flag, false, (Object[])null));
2563 }
2564 public void triggerSetEntityFlagPermanent(String flag) {
2565 triggerCustomAction(new SetEntityFlagAction(flag, true, (Object[])null));
2566 }
2567 public void triggerSetEntityFlag(String flag) {
2568 triggerCustomAction(new SetEntityFlagAction(flag, false, (Object[])null));
2569 }
2570 public void triggerSetFleetFlagPermanent(String flag, Object ... stages) {
2571 triggerCustomAction(new SetFleetFlagAction(flag, true, stages));
2572 }
2573 public void triggerSetFleetFlag(String flag, Object ... stages) {
2574 triggerCustomAction(new SetFleetFlagAction(flag, false, stages));
2575 }
2576 public void triggerUnsetFleetFlag(String flag) {
2577 triggerCustomAction(new UnsetFleetFlagsAction(flag));
2578 }
2579 public void triggerSetEntityFlagPermanent(String flag, Object ... stages) {
2580 triggerCustomAction(new SetEntityFlagAction(flag, true, stages));
2581 }
2582 public void triggerSetEntityFlag(String flag, Object ... stages) {
2583 triggerCustomAction(new SetEntityFlagAction(flag, false, stages));
2584 }
2585 public void triggerUnsetEntityFlag(String flag) {
2586 triggerCustomAction(new UnsetEntityFlagsAction(flag));
2587 }
2588// public void triggerMakeHostileAndAggressiveNotPermanent(Object ... stages) {
2589// triggerSetFleetFlagsWithReason(MemFlags.MEMORY_KEY_MAKE_HOSTILE,
2590// MemFlags.MEMORY_KEY_MAKE_AGGRESSIVE);
2591// triggerSetFleetFlag(MemFlags.MEMORY_KEY_MAKE_AGGRESSIVE_ONE_BATTLE_ONLY);
2592// }
2594 triggerSetFleetFlagsWithReason(MemFlags.MEMORY_KEY_MAKE_HOSTILE,
2595 //MemFlags.MEMORY_KEY_MAKE_HOSTILE_WHILE_TOFF,
2596 MemFlags.MEMORY_KEY_MAKE_AGGRESSIVE);
2597 triggerSetFleetFlag(MemFlags.MEMORY_KEY_MAKE_AGGRESSIVE_ONE_BATTLE_ONLY);
2598 }
2599
2605 triggerSetFleetFlag(MemFlags.FLEET_DO_NOT_IGNORE_PLAYER);
2606 }
2608 triggerSetFleetFlag(MemFlags.FLEET_IGNORES_OTHER_FLEETS);
2609 }
2611 triggerSetFleetFlag(MemFlags.FLEET_IGNORED_BY_OTHER_FLEETS);
2612 }
2614 triggerSetFleetFlag(MemFlags.MEMORY_KEY_MAKE_ALLOW_DISENGAGE);
2615 }
2616
2617 public void makeHostileAndAggressive(CampaignFleetAPI fleet, boolean permanent) {
2618 setFlagWithReason(fleet, MemFlags.MEMORY_KEY_MAKE_HOSTILE, permanent);
2619 setFlagWithReason(fleet, MemFlags.MEMORY_KEY_MAKE_AGGRESSIVE, permanent);
2620 setFlag(fleet, MemFlags.MEMORY_KEY_MAKE_AGGRESSIVE_ONE_BATTLE_ONLY, permanent);
2621 }
2622
2624 triggerSetFleetFlagsWithReason(MemFlags.MEMORY_KEY_MAKE_NON_HOSTILE);
2625 }
2626 public void triggerMakeHostile() {
2627 triggerSetFleetFlagsWithReason(MemFlags.MEMORY_KEY_MAKE_HOSTILE);
2628 }
2630 triggerSetFleetFlagsWithReason(MemFlags.MEMORY_KEY_MAKE_HOSTILE_TO_PLAYER_TRADE_FLEETS);
2631 }
2633 triggerSetFleetFlagsWithReason(MemFlags.MEMORY_KEY_MAKE_HOSTILE_TO_ALL_TRADE_FLEETS);
2634 }
2636// triggerSetFleetFlagsWithReason(MemFlags.MEMORY_KEY_MAKE_HOSTILE,
2637// MemFlags.MEMORY_KEY_MAKE_HOSTILE_WHILE_TOFF);
2638 triggerSetFleetFlagsWithReason(MemFlags.MEMORY_KEY_MAKE_HOSTILE_WHILE_TOFF);
2639 }
2641 triggerSetFleetFlagsWithReason(MemFlags.MEMORY_KEY_LOW_REP_IMPACT);
2642 }
2644 triggerSetFleetFlagsWithReason(MemFlags.MEMORY_KEY_EVERYONE_JOINS_BATTLE_AGAINST);
2645 }
2646// public void triggerMakeNoOneJoinBattleToHelp() {
2647// triggerSetFleetFlagsWithReason(MemFlags.MEMORY_KEY_NO_ONE_JOINTS_BATTLE_TO_HELP);
2648// }
2650 triggerSetFleetFlagsWithReason(MemFlags.SPREAD_TOFF_HOSTILITY_IF_LOW_IMPACT);
2651 }
2653 triggerSetFleetFlagsWithReason(MemFlags.MEMORY_KEY_LOW_REP_IMPACT,
2654 MemFlags.MEMORY_KEY_NO_REP_IMPACT);
2655 }
2657 triggerSetFleetFlag(MemFlags.MEMORY_KEY_PATROL_ALLOW_TOFF);
2658 }
2660 triggerSetFleetFlagPermanent(MemFlags.MEMORY_KEY_DO_NOT_SHOW_FLEET_DESC);
2661 }
2662
2664 triggerSetFleetFlag(MemFlags.MEMORY_KEY_FORCE_AUTOFIT_ON_NO_AUTOFIT_SHIPS);
2665 }
2666
2668 triggerSetFleetFlag(MemFlags.CAN_ONLY_BE_ENGAGED_WHEN_VISIBLE_TO_PLAYER);
2669 }
2670
2671 public void triggerFleetNoJump() {
2672 triggerSetFleetFlagPermanent(MemFlags.MEMORY_KEY_NO_JUMP);
2673 }
2675 triggerUnsetFleetFlag(MemFlags.MEMORY_KEY_NO_JUMP);
2676 }
2677
2682 triggerUnsetFleetFlag(MemFlags.FLEET_BUSY);
2683 }
2684
2685 public void triggerSetPatrol() {
2686 triggerSetFleetFlagPermanent(MemFlags.MEMORY_KEY_PATROL_FLEET);
2687 }
2688 public void triggerSetFleetHasslePlayer(String hassleType) {
2689 triggerSetFleetFlag(MemFlags.WILL_HASSLE_PLAYER);
2690 triggerSetFleetMemoryValue(MemFlags.HASSLE_TYPE, hassleType);
2691 }
2692 public void triggerSetFleetExtraSmugglingSuspicion(float extraSuspicion) {
2693 triggerSetFleetMemoryValue(MemFlags.PATROL_EXTRA_SUSPICION, extraSuspicion);
2694 }
2695 public void triggerMakeNonHostileToFaction(String factionId) {
2696 String flag = MemFlags.MEMORY_KEY_MAKE_NON_HOSTILE + "_" + factionId;
2697 triggerSetFleetFlag(flag);
2698 }
2699 public void triggerMakeHostileToFaction(String factionId) {
2700 String flag = MemFlags.MEMORY_KEY_MAKE_HOSTILE + "_" + factionId;
2701 triggerSetFleetFlag(flag);
2702 }
2704 triggerSetFleetFlagPermanent(MemFlags.MEMORY_KEY_PIRATE);
2705 }
2707 triggerSetFleetFlagPermanent(MemFlags.MEMORY_KEY_TRADE_FLEET);
2708 }
2709 public void triggerSetWarFleet() {
2710 triggerSetFleetFlagPermanent(MemFlags.MEMORY_KEY_WAR_FLEET);
2711 }
2713 triggerSetFleetFlagPermanent(MemFlags.MEMORY_KEY_SMUGGLER);
2714 }
2716 triggerSetFleetFlagPermanent(MemFlags.MEMORY_KEY_ALLOW_LONG_PURSUIT);
2717 }
2719 triggerUnsetFleetFlag("$LP_titheAskedFor");
2720 }
2722 triggerSetFleetFlagPermanent("$LP_titheAskedFor");
2723 }
2724// public void triggerFleetAllowLongPursuitNotPermanent() {
2725// triggerSetFleetFlag(MemFlags.MEMORY_KEY_ALLOW_LONG_PURSUIT);
2726// }
2728 triggerUnsetFleetFlag(MemFlags.MEMORY_KEY_ALLOW_LONG_PURSUIT);
2729 }
2731 triggerSetFleetFlag(MemFlags.MEMORY_KEY_AVOID_PLAYER_SLOWLY);
2732 }
2734 triggerUnsetFleetFlag(MemFlags.MEMORY_KEY_AVOID_PLAYER_SLOWLY);
2735 }
2736
2738 triggerSetFleetFlag(MemFlags.MEMORY_KEY_MAKE_ALWAYS_PURSUE);
2739 }
2740// public void triggerSetFleetAlwaysPursueNotPermanent() {
2741// triggerSetFleetFlag(MemFlags.MEMORY_KEY_MAKE_ALWAYS_PURSUE);
2742// }
2744 triggerUnsetFleetFlag(MemFlags.MEMORY_KEY_MAKE_ALWAYS_PURSUE);
2745 }
2746
2765 public void triggerRemoveAbilities(final String ... abilities) {
2766 triggerCustomAction(new RemoveAbilitiesAction(abilities));
2767 }
2768 public void triggerAddAbilities(final String ... abilities) {
2769 triggerCustomAction(new AddAbilitiesAction(abilities));
2770 }
2771 public void triggerSetInflater(final FleetInflater inflater) {
2772 triggerCustomAction(new SetInflaterAction(inflater));
2773 }
2776 }
2780 public void triggerSetRemnantConfig(boolean dormant) {
2781 //final long seed = Misc.genRandomSeed();
2782 long seed = Misc.seedUniquifier() ^ genRandom.nextLong();
2783 triggerCustomAction(new SetRemnantConfigAction(dormant, seed));
2784 }
2785
2788 triggerAddAbilities(Abilities.EMERGENCY_BURN);
2789 triggerAddAbilities(Abilities.SENSOR_BURST);
2790 triggerAddAbilities(Abilities.GO_DARK);
2792 }
2793
2794 public void triggerAddCustomDrop(final CargoAPI cargo) {
2795 triggerCustomAction(new AddCustomDropAction(cargo));
2796 }
2797 public void triggerAddCommodityDrop(String commodityId, int quantity, boolean dropQuantityBasedOnShipsDestroyed) {
2798 triggerCustomAction(new AddCommodityDropAction(quantity, commodityId, dropQuantityBasedOnShipsDestroyed));
2799 }
2800 public void triggerAddCommodityFractionDrop(String commodityId, float fraction) {
2801 triggerCustomAction(new AddCommodityFractionDropAction(fraction, commodityId));
2802 }
2803 public void triggerAddWeaponDrop(final String weaponId, final int quantity) {
2804 triggerCustomAction(new AddWeaponDropAction(quantity, weaponId));
2805 }
2806 public void triggerAddFighterLPCDrop(final String wingId, final int quantity) {
2807 triggerCustomAction(new AddFighterLPCDropAction(wingId, quantity));
2808 }
2809 public void triggerAddHullmodDrop(final String hullmodId) {
2810 triggerCustomAction(new AddHullmodDropAction(hullmodId));
2811 }
2812 public void triggerAddSpecialItemDrop(final String itemId, final String data) {
2813 triggerCustomAction(new AddSpecialItemDropAction(data, itemId));
2814 }
2815
2816
2825 public void triggerSpawnFleetAtPickedLocation(final String flag, final String refKey) {
2826 triggerSpawnFleetAtPickedLocation(200f, flag, refKey);
2827 }
2828 public void triggerSpawnFleetAtPickedLocation(final float range, final String flag, final String refKey) {
2829 triggerCustomAction(new SpawnFleetAtPickedLocationAction(range));
2830 if (flag != null) {
2831 triggerSetFleetFlag(flag);
2832 }
2833 if (refKey != null) {
2835 }
2836 }
2837 public void triggerSpawnFleetNear(final SectorEntityToken entity, final String flag, final String refKey) {
2838 triggerSpawnFleetNear(entity, 200f, flag, refKey);
2839 }
2840 public void triggerSpawnFleetNear(final SectorEntityToken entity, final float range, final String flag, final String refKey) {
2841 triggerCustomAction(new SpawnFleetNearAction(entity, range));
2842 if (flag != null) {
2843 triggerSetFleetFlag(flag);
2844 }
2845 if (refKey != null) {
2847 }
2848 }
2849
2850 public void triggerPickSetLocation(final LocationAPI location, final Vector2f coordinates) {
2851 triggerCustomAction(new PickSetLocationAction(coordinates, location));
2852 }
2853 public void triggerPickLocationInHyperspace(final StarSystemAPI system) {
2854 triggerCustomAction(new PickLocationInHyperspaceAction(system));
2855 }
2856
2857 public void triggerPickLocationFromEntityTowardsPlayer(final float arc, final float dist) {
2859 }
2860 public void triggerPickLocationTowardsPlayer(final SectorEntityToken entity, final float arc, final float dist) {
2862 }
2864 final float minDist, final float maxDist) {
2866 }
2867 public void triggerPickLocationTowardsPlayer(final SectorEntityToken entity, final float arc,
2868 final float minDist, final float maxDist) {
2870 }
2872 final float minDistFromPlayer, final float minDist, final float maxDist) {
2873 triggerCustomAction(new PickLocationTowardsPlayerAction(null, arc, minDist, maxDist, minDistFromPlayer));
2874 }
2875 public void triggerPickLocationTowardsPlayer(final SectorEntityToken entity, final float arc,
2876 final float minDistFromPlayer, final float minDist, final float maxDist) {
2877 triggerCustomAction(new PickLocationTowardsPlayerAction(entity, arc, minDist, maxDist, minDistFromPlayer));
2878 }
2879
2880 public void triggerPickLocationTowardsEntity(SectorEntityToken entity, float arc, float dist) {
2882 }
2883 public void triggerPickLocationTowardsEntity(final SectorEntityToken entity, final float arc,
2884 final float minDistFromPlayer, final float minDist, final float maxDist) {
2885 triggerCustomAction(new PickLocationTowardsEntityAction(entity, arc, minDist, maxDist, minDistFromPlayer));
2886 }
2887
2888
2889 public void triggerPickLocationFromEntityAwayFromPlayer(final float arc, final float dist) {
2891 }
2893 final float minDist, final float maxDist) {
2895 }
2897 final float minDistFromPlayer, final float minDist, final float maxDist) {
2898 triggerCustomAction(new PickLocationAwayFromPlayerAction(minDist, null, maxDist, arc, minDistFromPlayer));
2899 }
2900 public void triggerPickLocationAwayFromPlayer(final SectorEntityToken entity, final float arc, final float dist) {
2902 }
2903 public void triggerPickLocationAwayFromPlayer(final SectorEntityToken entity, final float arc,
2904 final float minDist, final float maxDist) {
2906 }
2907 public void triggerPickLocationAwayFromPlayer(final SectorEntityToken entity, final float arc,
2908 final float minDistFromPlayer, final float minDist, final float maxDist) {
2909 triggerCustomAction(new PickLocationAwayFromPlayerAction(minDist, entity, maxDist, arc, minDistFromPlayer));
2910 }
2911
2912 public void triggerPickLocationAroundPlayer(final float dist) {
2914 }
2915 public void triggerPickLocationAroundPlayer(final float minDist, final float maxDist) {
2916 triggerCustomAction(new PickLocationAroundPlayerAction(maxDist, minDist));
2917 }
2918
2919 public static float DEFAULT_MIN_DIST_FROM_PLAYER = 3000f;
2920 public void triggerPickLocationAroundEntity(final float dist) {
2922 }
2923 public void triggerPickLocationAroundEntity(final SectorEntityToken entity, final float dist) {
2925 }
2926 public void triggerPickLocationAroundEntity(final SectorEntityToken entity, final float minDist, final float maxDist) {
2928 }
2929 public void triggerPickLocationAroundEntity(final SectorEntityToken entity, final float minDistFromPlayer, final float minDist, final float maxDist) {
2930 triggerCustomAction(new PickLocationAroundEntityAction(minDist, entity, maxDist, minDistFromPlayer));
2931 }
2932
2936 public void triggerPickLocationAtInSystemJumpPoint(final StarSystemAPI system, final float minDistFromPlayer) {
2937 triggerCustomAction(new PickLocationAtInSystemJumpPointAction(system, minDistFromPlayer));
2938 }
2939
2943 public void triggerPickLocationAtClosestToPlayerJumpPoint(final StarSystemAPI system, final float minDistFromPlayer) {
2944 triggerCustomAction(new PickLocationAtClosestToPlayerJumpPointAction(system, minDistFromPlayer));
2945 }
2946
2947 public void triggerPickLocationAtClosestToEntityJumpPoint(StarSystemAPI system, SectorEntityToken entity) {
2948 triggerCustomAction(new PickLocationAtClosestToEntityJumpPointAction(system, entity, 0f));
2949 }
2950 public void triggerPickLocationAtClosestToEntityJumpPoint(StarSystemAPI system, SectorEntityToken entity, float minDistFromEntity) {
2951 triggerCustomAction(new PickLocationAtClosestToEntityJumpPointAction(system, entity, minDistFromEntity));
2952 }
2953
2954 public void triggerPickLocationWithinArc(final float dir, final float arc,
2955 final float minDistFromPlayer, final float minDist, final float maxDist) {
2956 triggerPickLocationWithinArc(null, dir, arc, minDistFromPlayer, minDist, maxDist);
2957 }
2958 public void triggerPickLocationWithinArc(final SectorEntityToken entity, final float dir, final float arc,
2959 final float minDistFromPlayer, final float minDist, final float maxDist) {
2960 triggerCustomAction(new PickLocationWithinArcAction(arc, entity, maxDist, minDist, minDistFromPlayer, dir));
2961 }
2962
2964 triggerCustomAction(new SetEntityToPickedJumpPoint());
2965 }
2966 public void triggerFleetSetPatrolActionText(String patrolText) {
2967 triggerCustomAction(new FleetSetPatrolActionText(patrolText));
2968 }
2969
2970 public void triggerFleetSetPatrolLeashRange(float dist) {
2971 triggerSetFleetMemoryValue(MemFlags.FLEET_PATROL_DISTANCE, dist);
2972 }
2973 public void triggerFleetSetTravelActionText(String travelText) {
2974 triggerCustomAction(new FleetSetTravelActionText(travelText));
2975 }
2976
2977 public void triggerOrderFleetPatrol(final StarSystemAPI system) {
2978 triggerCustomAction(new OrderFleetPatrolSystemAction(system));
2979 }
2980 public void triggerOrderFleetPatrol(final SectorEntityToken ... patrolPoints) {
2981 triggerOrderFleetPatrol(null, false, patrolPoints);
2982 }
2983 public void triggerOrderFleetPatrol(final boolean randomizeLocation, final SectorEntityToken ... patrolPoints) {
2984 triggerOrderFleetPatrol(null, randomizeLocation, patrolPoints);
2985 }
2986 public void triggerOrderFleetPatrol(final StarSystemAPI system, final boolean randomizeLocation,
2987 final SectorEntityToken ... patrolPoints) {
2988 triggerCustomAction(new OrderFleetPatrolPointsAction(patrolPoints, randomizeLocation, system));
2989 }
2990 public void triggerOrderFleetPatrol(final StarSystemAPI system, final boolean randomizeLocation, final String ... tags) {
2991 triggerCustomAction(new OrderFleetPatrolTagsAction(system, randomizeLocation, tags));
2992 }
2993 public void triggerOrderExtraPatrolPoints(SectorEntityToken ... points) {
2994 for (int i = currTrigger.getActions().size() - 1; i >= 0; i--) {
2995 TriggerAction action = currTrigger.getActions().get(i);
2996 if (action instanceof OrderFleetPatrolTagsAction) {
2997 OrderFleetPatrolTagsAction a = (OrderFleetPatrolTagsAction) action;
2998 if (a.added == null) a.added = new ArrayList<SectorEntityToken>();
2999 for (SectorEntityToken curr : points) {
3000 if (curr != null) {
3001 a.added.add(curr);
3002 }
3003 }
3004 return;
3005 }
3006 if (action instanceof OrderFleetPatrolPointsAction) {
3007 OrderFleetPatrolPointsAction a = (OrderFleetPatrolPointsAction) action;
3008 for (SectorEntityToken curr : points) {
3009 if (curr != null) {
3010 a.patrolPoints.add(curr);
3011 }
3012 }
3013 return;
3014 }
3015 }
3016 }
3017
3018 public void triggerOrderFleetPatrolEntity(boolean moveToNearEntity) {
3019 triggerCustomAction(new OrderFleetPatrolSpawnedEntity(moveToNearEntity));
3020 }
3021
3022 public void triggerOrderFleetPatrolHyper(final StarSystemAPI system) {
3023 triggerOrderFleetPatrol(system, false, system.getHyperspaceAnchor());
3024 }
3025
3026 public void triggerFleetAddDefeatTrigger(String trigger) {
3027 triggerCustomAction(new AddFleetDefeatTriggerAction(trigger, false));
3028 }
3029
3030 public void triggerFleetAddDefeatTriggerPermanent(String trigger) {
3031 triggerCustomAction(new AddFleetDefeatTriggerAction(trigger, true));
3032 }
3033
3035 triggerCustomAction(new AddFleetDefeatTriggerAction("GoAwayAfterDefeatTrigger", true));
3036 }
3037
3041 public void triggerOrderFleetInterceptPlayer(boolean makeHostile, boolean allowLongPursuit) {
3042 triggerCustomAction(new OrderFleetInterceptPlayerAction(makeHostile));
3043 if (allowLongPursuit) {
3045 }
3046 }
3047
3050 }
3051 public void triggerOrderFleetEBurn(float probabilityToEBurn) {
3052 if (genRandom.nextFloat() < probabilityToEBurn) {
3053 triggerCustomAction(new OrderFleetEBurn());
3054 }
3055 }
3056
3057 public void triggerOrderFleetAttackLocation(final SectorEntityToken entity) {
3058 triggerOrderFleetPatrol(null, false, entity);
3059 }
3060
3062 triggerCustomAction(new FleetNoAutoDespawnAction());
3063 }
3064
3066 triggerCustomAction(new OrderFleetStopPursuingPlayerUnlessInStage(this, stages));
3067 }
3068
3069 public void triggerFleetInterceptPlayerWithinRange(boolean mustBeStrongEnoughToFight, float maxRange,
3070 boolean repeatable, float repeatDelay, Object ... stages) {
3072 new OrderFleetInterceptNearbyPlayerInStage(this, mustBeStrongEnoughToFight, maxRange, repeatable, repeatDelay, stages));
3074 }
3075
3076 public void triggerFleetInterceptPlayerNearby(boolean mustBeStrongEnoughToFight, Object ... stages) {
3077 triggerFleetInterceptPlayerWithinRange(mustBeStrongEnoughToFight, 500f, true, 5f, stages);
3078 }
3079
3080 public void triggerFleetInterceptPlayerOnSight(boolean mustBeStrongEnoughToFight,Object ... stages) {
3081 triggerFleetInterceptPlayerWithinRange(mustBeStrongEnoughToFight, 10000f, true, 5f, stages);
3082 }
3083
3084
3085 public static Vector2f pickLocationWithinArc(Random random, final SectorEntityToken entity, final float dir, final float arc,
3086 final float minDistToPlayer, final float minDist, final float maxDist) {
3087 float angleIncr = 10f;
3088 float distIncr = (maxDist - minDist) / 5f;
3089 if (distIncr < 1000f) {
3090 distIncr = (maxDist - minDist) / 2f;
3091 }
3092 if (distIncr < 1) distIncr = 1;
3093
3094
3095 WeightedRandomPicker<Vector2f> picker = new WeightedRandomPicker<Vector2f>(random);
3096 for (float currAngle = dir - arc / 2f; currAngle < dir + arc / 2f; currAngle += angleIncr) {
3097 for (float dist = minDist; dist <= maxDist; dist += distIncr) {
3098 Vector2f loc = Misc.getUnitVectorAtDegreeAngle(currAngle);
3099 loc.scale(dist);
3100 Vector2f.add(entity.getLocation(), loc, loc);
3101 picker.add(loc);
3102 }
3103 }
3104
3105 WeightedRandomPicker<Vector2f> copy = new WeightedRandomPicker<Vector2f>(random);
3106 copy.addAll(picker);
3107
3108
3109 StarSystemAPI system = entity.getStarSystem();
3110 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
3111 Vector2f pick = null;
3112 LocationAPI containingLocation = entity.getContainingLocation();
3113
3114 while (!picker.isEmpty()) {
3115 Vector2f loc = picker.pickAndRemove();
3116 if (isNearCorona(system, loc)) continue;
3117
3118 float distToPlayer = Float.MAX_VALUE;
3119 if (playerFleet != null && playerFleet.getContainingLocation() == containingLocation) {
3120 distToPlayer = Misc.getDistance(playerFleet.getLocation(), loc);
3121 if (distToPlayer < minDistToPlayer) {
3122 continue;
3123 }
3124 }
3125 pick = loc;
3126 }
3127
3128 if (pick == null) {
3129 pick = copy.pick();
3130 }
3131
3132 float distToPlayer = Float.MAX_VALUE;
3133 if (playerFleet != null && playerFleet.getContainingLocation() == containingLocation) {
3134 distToPlayer = Misc.getDistance(playerFleet.getLocation(), pick);
3135 if (distToPlayer < minDistToPlayer) {
3136 Vector2f away = Misc.getUnitVectorAtDegreeAngle(
3137 Misc.getAngleInDegrees(playerFleet.getLocation(), pick));
3138 away.scale(minDistToPlayer);
3139 Vector2f.add(playerFleet.getLocation(), away, away);
3140 pick = away;
3141 }
3142 }
3143
3144 return pick;
3145 }
3146
3147 public static boolean isNearCorona(StarSystemAPI system, Vector2f loc) {
3148 if (system == null) return false;
3149 for (PlanetAPI planet : system.getPlanets()) {
3150 if (!planet.isStar()) continue;
3151 StarCoronaTerrainPlugin corona = Misc.getCoronaFor(planet);
3152 if (corona == null) continue;
3153 float dist = Misc.getDistance(planet.getLocation(), loc);
3154 float radius = corona.getParams().middleRadius + corona.getParams().bandWidthInEngine * 0.5f;
3155 if (dist < radius + 500f) {
3156 return true;
3157 }
3158 }
3159 return false;
3160 }
3161
3162
3163 public void triggerCustomAction(TriggerAction action) {
3164 currTrigger.getActions().add(action);
3165 }
3166
3167
3168
3169
3170
3171
3172 protected transient MissionTrigger currTrigger = null;
3173 public void beginGlobalFlagTrigger(String flag, Object ... stages) {
3174 beginCustomTrigger(new GlobalBooleanChecker(flag), stages);
3175 }
3176 public void beginDaysElapsedTrigger(float days, Object ... stages) {
3177 beginCustomTrigger(new DaysElapsedChecker(days, this), stages);
3178 }
3179 public void beginDaysElapsedTrigger(float days, Object stage, Object ... stages) {
3180 beginCustomTrigger(new DaysElapsedChecker(days, getData(stage)), stages);
3181 }
3182 public void beginInCommRelayRangeTrigger(Object ... stages) {
3183 beginCustomTrigger(new InCommRelayRangeChecker(), stages);
3184 }
3185 public void beginEnteredLocationTrigger(LocationAPI location, Object ... stages) {
3186 beginCustomTrigger(new EnteredLocationChecker(location), stages);
3187 }
3188 public void beginInRangeOfEntityTrigger(SectorEntityToken entity, float range, Object ... stages) {
3189 beginCustomTrigger(new InRangeOfEntityChecker(entity, range), stages);
3190 }
3191// public void beginWithinHyperspaceRangeTrigger(SectorEntityToken entity, float rangeLY, Object ... stages) {
3192// beginWithinHyperspaceRangeTrigger(entity, rangeLY, false, stages);
3193// }
3194 public void beginWithinHyperspaceRangeTrigger(SectorEntityToken entity, float rangeLY, boolean requirePlayerInHyperspace,
3195 Object ... stages) {
3196 beginCustomTrigger(new InHyperRangeOfEntityChecker(entity, rangeLY, requirePlayerInHyperspace), stages);
3197 }
3198
3199 public void beginWithinHyperspaceRangeTrigger(StarSystemAPI system, float rangeLY, boolean requirePlayerInHyperspace,
3200 Object ... stages) {
3201 beginWithinHyperspaceRangeTrigger(system.getCenter(), rangeLY, requirePlayerInHyperspace, stages);
3202 }
3203
3204// public void beginWithinHyperspaceRangeTrigger(MarketAPI market, float rangeLY, Object ... stages) {
3205// beginWithinHyperspaceRangeTrigger(market, rangeLY, false, stages);
3206// }
3207 public void beginWithinHyperspaceRangeTrigger(MarketAPI market, float rangeLY, boolean requirePlayerInHyperspace,
3208 Object ... stages) {
3209 beginCustomTrigger(new InHyperRangeOfEntityChecker(market.getPrimaryEntity(), rangeLY, requirePlayerInHyperspace), stages);
3210 }
3211
3212 public void beginStageTrigger(Object ... stages) {
3213 beginCustomTrigger(new AlwaysTrueChecker(), stages);
3214 }
3215 public void beginCustomTrigger(ConditionChecker condition, Object ... stages) {
3217
3219 currTrigger.setCondition(condition);
3220 if (stages != null) {
3221 for (Object stage : stages) {
3222 currTrigger.getStages().add(stage);
3223 }
3224 }
3225 }
3226
3227
3228 public void endTrigger() {
3229 if (currTrigger == null) {
3230 throw new RuntimeException("endTrigger() called without a corresponding beginTrigger()");
3231 }
3232 triggers.add(currTrigger);
3233 currTrigger = null;
3234 }
3235 protected void checkExistingTrigger() {
3236 if (currTrigger != null) throw new RuntimeException("Already began a trigger, call endTrigger() to finish it");
3237 }
3238
3240 return currTrigger;
3241 }
3243 this.currTrigger = currTrigger;
3244 }
3245
3246
3247 public void triggerSpawnEntity(final String entityId, LocData data) {
3248 triggerCustomAction(new SpawnEntityAction(entityId, data));
3249 }
3250
3251 public void triggerSpawnDebrisField(float radius, float density, LocData data) {
3252 triggerCustomAction(new SpawnDebrisFieldAction(radius, density, data));
3253 }
3254
3255 public void triggerDespawnEntity(SectorEntityToken entity) {
3256 triggerCustomAction(new DespawnEntityAction(entity));
3257 }
3258
3259
3260 public void triggerSpawnDerelictHull(String hullId, LocData data) {
3261 triggerCustomAction(new SpawnDerelictAction(hullId, null, null, data));
3262 }
3263
3264 public void triggerSpawnDerelict(String factionId, DerelictType type, LocData data) {
3265 triggerCustomAction(new SpawnDerelictAction(null, factionId, type, data));
3266 }
3267 public void triggerSpawnDerelict(DerelictType type, LocData data) {
3268 triggerCustomAction(new SpawnDerelictAction(type, data));
3269 }
3270
3271 public void triggerSpawnDerelict(DerelictShipData shipData, LocData data) {
3272 triggerCustomAction(new SpawnDerelictAction(shipData, data));
3273 }
3274
3275 public void triggerSpawnShipGraveyard(String factionId, int minShips, int maxShips, LocData data) {
3276 triggerCustomAction(new SpawnShipGraveyardAction(factionId, minShips, maxShips, data));
3277 }
3278
3280 triggerCustomAction(new MakeDiscoverableAction(1000f, 200f));
3281 }
3282 public void triggerMakeDiscoverable(float range, float xp) {
3283 triggerCustomAction(new MakeDiscoverableAction(range, xp));
3284 }
3285
3286 public void triggerFleetAddTags(String ... tags) {
3287 triggerCustomAction(new AddTagsAction(tags));
3288 }
3289
3290 public void triggerAddTags(SectorEntityToken entity, String ... tags) {
3291 triggerCustomAction(new GenericAddTagsAction(entity, tags));
3292 }
3293 public void triggerRemoveTags(SectorEntityToken entity, String ... tags) {
3294 triggerCustomAction(new GenericRemoveTagsAction(entity, tags));
3295 }
3296 public void triggerMakeNonStoryCritical(MemoryAPI ... memoryArray) {
3297 triggerCustomAction(new MakeNonStoryCriticalAction(memoryArray));
3298 }
3299 public void triggerMakeNonStoryCritical(String ... markets) {
3300 for (String id : markets) {
3301 MarketAPI market = Global.getSector().getEconomy().getMarket(id);
3302 if (market != null) {
3303 triggerCustomAction(new MakeNonStoryCriticalAction(market.getMemory()));
3304 }
3305 }
3306 }
3307 public void triggerMakeNonStoryCritical(MarketAPI ... markets) {
3308 for (MarketAPI market : markets) {
3309 triggerCustomAction(new MakeNonStoryCriticalAction(market.getMemory()));
3310 }
3311 }
3312
3313 public void triggerFleetAddCommanderSkill(String skill, int level) {
3314 triggerCustomAction(new AddCommanderSkillAction(skill, level));
3315 }
3316
3323 triggerCustomAction(new MakeFleetFlagsPermanentAction(true));
3324 }
3326 triggerCustomAction(new MakeFleetFlagsPermanentAction(false));
3327 }
3328
3329
3330 public static CampaignFleetAPI createFleet(FleetSize size, FleetQuality quality,
3331 OfficerNum oNum, OfficerQuality oQuality, String factionId, String fleetFactionId, String type, Vector2f locInHyper) {
3332 CreateFleetAction action = new CreateFleetAction(type, locInHyper, size, quality, factionId);
3333 action.oNum = oNum;
3334 action.oQuality = oQuality;
3335 action.faction = fleetFactionId;
3336 TriggerActionContext context = new TriggerActionContext(null);
3337 action.doAction(context);
3338 return context.fleet;
3339 }
3340
3341
3342 public void triggerCreateSmallPatrolAroundMarket(MarketAPI market, Object stage, float extraSuspicion) {
3343 triggerCreatePatrolAroundMarket(market, null, stage, FleetSize.VERY_SMALL, FleetTypes.PATROL_MEDIUM, extraSuspicion);
3344 }
3345 public void triggerCreateMediumPatrolAroundMarket(MarketAPI market, Object stage, float extraSuspicion) {
3346 triggerCreatePatrolAroundMarket(market, null, stage, FleetSize.MEDIUM, FleetTypes.PATROL_MEDIUM, extraSuspicion);
3347 }
3348 public void triggerCreateLargePatrolAroundMarket(MarketAPI market, Object stage, float extraSuspicion) {
3349 triggerCreatePatrolAroundMarket(market, null, stage, FleetSize.LARGE, FleetTypes.PATROL_LARGE, extraSuspicion);
3350 }
3351 public void triggerCreateSmallPatrol(MarketAPI from, String factionId, SectorEntityToken entityToPatrol, Object stage, float extraSuspicion) {
3352 triggerCreatePatrolAroundMarket(from, factionId, entityToPatrol, stage, FleetSize.VERY_SMALL, FleetTypes.PATROL_MEDIUM, extraSuspicion);
3353 }
3354 public void triggerCreateMediumPatrol(MarketAPI from, String factionId, SectorEntityToken entityToPatrol, Object stage, float extraSuspicion) {
3355 triggerCreatePatrolAroundMarket(from, factionId, entityToPatrol, stage, FleetSize.MEDIUM, FleetTypes.PATROL_MEDIUM, extraSuspicion);
3356 }
3357 public void triggerCreateLargePatrol(MarketAPI from, String factionId, SectorEntityToken entityToPatrol, Object stage, float extraSuspicion) {
3358 triggerCreatePatrolAroundMarket(from, factionId, entityToPatrol, stage, FleetSize.LARGE, FleetTypes.PATROL_LARGE, extraSuspicion);
3359 }
3360 public void triggerCreatePatrolAroundMarket(MarketAPI market, SectorEntityToken entityToPatrol,
3361 Object stage, FleetSize size, String fleetType,
3362 float extraSuspicion) {
3363 triggerCreatePatrolAroundMarket(market, null, entityToPatrol, stage, size, fleetType, extraSuspicion);
3364 }
3365 public void triggerCreatePatrolAroundMarket(MarketAPI market, String factionId, SectorEntityToken entityToPatrol,
3366 Object stage, FleetSize size, String fleetType,
3367 float extraSuspicion) {
3368 if (entityToPatrol == null) entityToPatrol = market.getPrimaryEntity();
3369 if (factionId == null) factionId = market.getFactionId();
3370
3371 beginWithinHyperspaceRangeTrigger(entityToPatrol, 1f, false, stage);
3372 triggerCreateFleet(size, FleetQuality.DEFAULT, factionId, fleetType, entityToPatrol);
3375 FactionAPI faction = Global.getSector().getFaction(factionId);
3376 if (faction.getCustomBoolean(Factions.CUSTOM_PIRATE_BEHAVIOR)) {
3378 } else {
3380 }
3381 triggerPickLocationAroundEntity(entityToPatrol, 100f);
3383 triggerOrderFleetPatrol(entityToPatrol);
3385 triggerSetFleetNotBusy(); // so that it can be distracted and in general acts like a normal patrol
3386 if (market != null) {
3387 triggerSetFleetMemoryValue(MemFlags.MEMORY_KEY_SOURCE_MARKET, market.getId());
3388 }
3389 endTrigger();
3390 }
3391
3392
3393 public static enum ComplicationSpawn {
3394 APPROACHING_OR_ENTERING,
3395 APPROACHING_SYSTEM,
3396 ENTERING_SYSTEM,
3397 EXITING_SYSTEM,
3398 }
3399 public static enum ComplicationRepImpact{
3400 NONE,
3401 LOW,
3402 FULL,
3403 }
3404
3405 public ComplicationSpawn pickComplicationSpawnType() {
3406 WeightedRandomPicker<ComplicationSpawn> picker = new WeightedRandomPicker<ComplicationSpawn>(genRandom);
3407 picker.add(ComplicationSpawn.APPROACHING_SYSTEM);
3408 picker.add(ComplicationSpawn.ENTERING_SYSTEM);
3409 picker.add(ComplicationSpawn.EXITING_SYSTEM);
3410 return picker.pick();
3411 }
3412
3414 CreateFleetAction cfa = getPreviousCreateFleetAction();
3415
3416 if (genRandom.nextFloat() < 0.33f && cfa.fSize != FleetSize.TINY && getQuality() > 0.25f) {
3417 // less ships, better quality and more officers
3418 cfa.fSize = cfa.fSize.prev();
3419 if (cfa.fQuality == null) cfa.fQuality = FleetQuality.DEFAULT;
3420 cfa.fQuality = cfa.fQuality.next();
3421
3422 if (cfa.oNum == null) cfa.oNum = OfficerNum.DEFAULT;
3423 cfa.oNum = cfa.oNum.next();
3424 } else if (genRandom.nextFloat() < 0.5f && cfa.fSize != FleetSize.MAXIMUM) {
3425 // more ships, lower quality, same officers
3426 cfa.fSize = cfa.fSize.next();
3427 if (cfa.fQuality == null) cfa.fQuality = FleetQuality.DEFAULT;
3428 cfa.fQuality = cfa.fQuality.prev();
3429 }
3430
3431 }
3432
3433 @SuppressWarnings("rawtypes")
3434 public void triggerComplicationBegin(Object stage, ComplicationSpawn spawnType, StarSystemAPI system,
3435 String factionId,
3436 String thing,
3437 String thingItOrThey,
3438 String thingDesc,
3439 int paymentOffered,
3440 boolean aggressiveIfDeclined,
3441 ComplicationRepImpact repImpact,
3442 String failTrigger) {
3443 if (spawnType == ComplicationSpawn.APPROACHING_OR_ENTERING) spawnType = pickComplicationSpawnType();
3444
3445 if ("them".equals(thingItOrThey)) thingItOrThey = "they";
3446
3447 if (spawnType == ComplicationSpawn.APPROACHING_SYSTEM) {
3448 beginWithinHyperspaceRangeTrigger(system.getCenter(), 3f, true, stage);
3449 } else if (spawnType == ComplicationSpawn.ENTERING_SYSTEM) {
3450 beginEnteredLocationTrigger(system, stage);
3451 } else if (spawnType == ComplicationSpawn.EXITING_SYSTEM) {
3452 //beginEnteredLocationTrigger(Global.getSector().getHyperspace(), stage);
3453 // so that it doesn't trigger if the player exits the system through alternate means and is far away
3454 beginWithinHyperspaceRangeTrigger(system, 1f, true, stage);
3455 }
3456
3457 triggerCreateFleet(FleetSize.LARGE, FleetQuality.DEFAULT, factionId, FleetTypes.PATROL_MEDIUM, system);
3458
3459 triggerSetFleetMissionRef("$" + getMissionId() + "_ref");
3460 triggerSetFleetMissionRef("$fwt_ref");
3461
3462 FactionAPI faction = Global.getSector().getFaction(factionId);
3463 if (aggressiveIfDeclined) {
3466 }
3467
3468 if (repImpact == ComplicationRepImpact.LOW) {
3470 } else if (repImpact == ComplicationRepImpact.NONE) {
3472 }
3473
3476
3477 if (faction.getCustomBoolean(Factions.CUSTOM_SPAWNS_AS_INDEPENDENT)) {
3478 triggerSetFleetFaction(Factions.INDEPENDENT);
3479 triggerSetFleetMemoryValue("$fwt_originalFaction", factionId);
3480 }
3481
3482
3483 if (spawnType == ComplicationSpawn.APPROACHING_SYSTEM) {
3484 triggerPickLocationTowardsPlayer(system.getHyperspaceAnchor(), 90f, getUnits(1.5f));
3485 } else if (spawnType == ComplicationSpawn.ENTERING_SYSTEM) {
3486 triggerPickLocationTowardsPlayer(system.getCenter(), 90, 2000);
3487 } else if (spawnType == ComplicationSpawn.EXITING_SYSTEM) {
3489 }
3490
3493
3494 triggerSpawnFleetAtPickedLocation("$fwt_wantsThing", null);
3495 triggerSetFleetMemoryValue("$fwt_aggressive", aggressiveIfDeclined);
3496 triggerSetFleetMemoryValue("$fwt_thing", getWithoutArticle(thing));
3497 triggerSetFleetMemoryValue("$fwt_Thing", Misc.ucFirst(getWithoutArticle(thing)));
3498 triggerSetFleetMemoryValue("$fwt_theThing", thing);
3499 triggerSetFleetMemoryValue("$fwt_TheThing", Misc.ucFirst(thing));
3500 triggerSetFleetMemoryValue("$fwt_payment", Misc.getWithDGS(paymentOffered));
3501 triggerSetFleetMemoryValue("$fwt_itOrThey", thingItOrThey);
3502 triggerSetFleetMemoryValue("$fwt_ItOrThey", Misc.ucFirst(thingItOrThey));
3503
3504 String thingItOrThem = "them";
3505 if ("it".equals(thingItOrThey)) thingItOrThem = "it";
3506 triggerSetFleetMemoryValue("$fwt_itOrThem", thingItOrThem);
3507 triggerSetFleetMemoryValue("$fwt_ItOrThem", Misc.ucFirst(thingItOrThem));
3508
3509 triggerSetFleetMemoryValue("$fwt_thingDesc", thingDesc);
3510 triggerSetFleetMemoryValue("$fwt_ThingDesc", Misc.ucFirst(thingDesc));
3511
3512 if (failTrigger == null) {
3513 failTrigger = "FWTDefaultFailTrigger";
3514 }
3515 triggerSetFleetMemoryValue("$fwt_missionFailTrigger", failTrigger);
3516
3517 triggerFleetMakeImportant(null, (Enum) stage);
3518
3519 //endTrigger();
3520 }
3521
3522 public void triggerComplicationEnd(boolean randomizeAndAdjustFleetSize) {
3523 if (randomizeAndAdjustFleetSize) {
3525
3529 }
3531
3532 endTrigger();
3533 }
3534
3536 CreateFleetAction cfa = getPreviousCreateFleetAction();
3537 if (cfa.params.fleetType != null && cfa.fSizeOverride != null &&
3538 (cfa.params.fleetType.equals(FleetTypes.PATROL_SMALL) ||
3539 cfa.params.fleetType.equals(FleetTypes.PATROL_MEDIUM) ||
3540 cfa.params.fleetType.equals(FleetTypes.PATROL_LARGE))) {
3541 if (cfa.fSizeOverride <= 0.2f) {
3542 cfa.params.fleetType = FleetTypes.PATROL_SMALL;
3543 } else if (cfa.fSizeOverride < 0.7f) {
3544 cfa.params.fleetType = FleetTypes.PATROL_MEDIUM;
3545 } else {
3546 cfa.params.fleetType = FleetTypes.PATROL_LARGE;
3547 }
3548 } else if (cfa.params.fleetType != null && cfa.fSizeOverride != null &&
3549 (cfa.params.fleetType.equals(FleetTypes.SCAVENGER_SMALL) ||
3550 cfa.params.fleetType.equals(FleetTypes.SCAVENGER_MEDIUM) ||
3551 cfa.params.fleetType.equals(FleetTypes.SCAVENGER_LARGE))) {
3552 if (cfa.fSizeOverride <= 0.2f) {
3553 cfa.params.fleetType = FleetTypes.SCAVENGER_SMALL;
3554 } else if (cfa.fSizeOverride < 0.7f) {
3555 cfa.params.fleetType = FleetTypes.SCAVENGER_MEDIUM;
3556 } else {
3557 cfa.params.fleetType = FleetTypes.SCAVENGER_LARGE;
3558 }
3559 }
3560 }
3561
3562
3563 public void triggerFleetSetWarnAttack(String warnCommsTrigger, String attackCommsTrigger, Object ... stages) {
3564 triggerSetFleetFlag("$warnAttack", stages);
3565 triggerSetFleetMemoryValue("$warnAttack_warningComms", warnCommsTrigger);
3566 triggerSetFleetMemoryValue("$warnAttack_attackComms", attackCommsTrigger);
3568
3569 CreateFleetAction cfa = getPreviousCreateFleetAction();
3570 if (cfa != null && cfa.params != null && cfa.params.factionId != null) {
3571 triggerSetFleetMemoryValue("$warnAttack_factionId", cfa.params.factionId);
3572 }
3573 }
3574
3575 public void triggerFleetAddTugsFlag(int tugs) {
3576 triggerCustomAction(new FleetAddTugs(tugs));
3577 }
3578
3579 public void triggerFleetMakeFaster(boolean navigationSkill, int numTugs, boolean allowLongPursuit) {
3580 if (navigationSkill) {
3581 triggerFleetAddCommanderSkill(Skills.NAVIGATION, 1);
3582 }
3583 if (numTugs > 0) {
3584 triggerFleetAddTugsFlag(numTugs);
3585 }
3586 if (allowLongPursuit) {
3588 }
3589 }
3590
3591 public static void addTugsToFleet(CampaignFleetAPI fleet, int tugs, Random random) {
3592 //if (true) return;
3593
3594 int max = Global.getSettings().getInt("maxShipsInAIFleet");
3595 if (fleet.getNumMembersFast() + tugs > max) {
3596 FleetFactoryV3.pruneFleet(max - tugs, 0, fleet, 100000, random);
3597 }
3598
3599 FactionAPI faction = fleet.getFaction();
3600 for (int i = 0; i < tugs; i++) {
3601 ShipPickParams params = new ShipPickParams(ShipPickMode.ALL);
3602 List<ShipRolePick> picks = faction.pickShip(ShipRoles.TUG, params, null, random);
3603 for (ShipRolePick pick : picks) {
3604 FleetMemberAPI member = fleet.getFleetData().addFleetMember(pick.variantId);
3605 member.updateStats();
3606 member.getRepairTracker().setCR(member.getRepairTracker().getMaxCR());
3607 break;
3608 }
3609 }
3610 }
3611
3612 public void setFleetDamageTaken(float damage) {
3613 getPreviousCreateFleetAction().damage = damage;
3614 }
3615
3616
3617 public void setFleetSource(MarketAPI... preferred) {
3618 if (preferred == null) return;
3619
3620 for (MarketAPI market : preferred) {
3621 if (!market.hasCondition(Conditions.DECIVILIZED)) {
3622 getPreviousCreateFleetAction().params.setSource(market, true);
3623 break;
3624 }
3625 }
3626 }
3627
3628 public void setFleetSource(String ... preferred) {
3629 if (preferred == null) return;
3630
3631 for (String id : preferred) {
3632 MarketAPI market = Global.getSector().getEconomy().getMarket(id);
3633 if (market != null && !market.hasCondition(Conditions.DECIVILIZED)) {
3634 getPreviousCreateFleetAction().params.setSource(market, true);
3635 break;
3636 }
3637 }
3638 }
3639}
3640
3641
3642
3643
3644
3645
static SettingsAPI getSettings()
Definition Global.java:51
static FactoryAPI getFactory()
Definition Global.java:35
static SectorAPI getSector()
Definition Global.java:59
void makeImportant(PersonAPI person, String flag, Enum ... stages)
void setFlagWithReason(SectorEntityToken entity, String flag, boolean permanent)
void setFlag(SectorEntityToken entity, String flag, boolean permanent)
void triggerPickLocationFromEntityTowardsPlayer(final float arc, final float minDistFromPlayer, final float minDist, final float maxDist)
void triggerCreateMediumPatrolAroundMarket(MarketAPI market, Object stage, float extraSuspicion)
void triggerSetFleetComposition(float freighterMult, float tankerMult, float transportMult, float linerMult, float utilityMult)
void triggerCreatePatrolAroundMarket(MarketAPI market, SectorEntityToken entityToPatrol, Object stage, FleetSize size, String fleetType, float extraSuspicion)
void triggerCreateFleet(FleetSize size, FleetQuality quality, String factionId, String type, Vector2f locInHyper)
void triggerPickLocationFromEntityAwayFromPlayer(final float arc, final float minDist, final float maxDist)
void triggerPickLocationTowardsPlayer(final SectorEntityToken entity, final float arc, final float dist)
void triggerSetMemoryValueAfterDelay(float delay, HasMemory hasMemory, String key, Object value)
void triggerFleetMakeFaster(boolean navigationSkill, int numTugs, boolean allowLongPursuit)
void beginWithinHyperspaceRangeTrigger(StarSystemAPI system, float rangeLY, boolean requirePlayerInHyperspace, Object ... stages)
void triggerOrderFleetPatrol(final boolean randomizeLocation, final SectorEntityToken ... patrolPoints)
void triggerSetFleetSizeAndQuality(FleetSize size, FleetQuality quality, String fleetType)
void triggerAddTagAfterDelay(float delay, StarSystemAPI system, String tag)
void triggerSpawnDerelict(String factionId, DerelictType type, LocData data)
void triggerCreateLargePatrol(MarketAPI from, String factionId, SectorEntityToken entityToPatrol, Object stage, float extraSuspicion)
void setUseQualityInsteadOfQualityFraction(boolean temporarilyUseQualityInsteadOfQualityFraction)
void triggerPickLocationAroundEntity(final SectorEntityToken entity, final float minDistFromPlayer, final float minDist, final float maxDist)
void triggerCreateSmallPatrolAroundMarket(MarketAPI market, Object stage, float extraSuspicion)
static void addTugsToFleet(CampaignFleetAPI fleet, int tugs, Random random)
void triggerCreateMediumPatrol(MarketAPI from, String factionId, SectorEntityToken entityToPatrol, Object stage, float extraSuspicion)
void triggerPickLocationWithinArc(final SectorEntityToken entity, final float dir, final float arc, final float minDistFromPlayer, final float minDist, final float maxDist)
void triggerSetFleetDoctrineComp(int warships, int carriers, int phaseShips)
void triggerFleetInterceptPlayerWithinRange(boolean mustBeStrongEnoughToFight, float maxRange, boolean repeatable, float repeatDelay, Object ... stages)
void triggerPickLocationAroundEntity(final SectorEntityToken entity, final float minDist, final float maxDist)
void triggerOrderFleetInterceptPlayer(boolean makeHostile, boolean allowLongPursuit)
void beginWithinHyperspaceRangeTrigger(SectorEntityToken entity, float rangeLY, boolean requirePlayerInHyperspace, Object ... stages)
void triggerSetMemoryValue(HasMemory withMemory, String key, Object value)
static Vector2f pickLocationWithinArc(Random random, final SectorEntityToken entity, final float dir, final float arc, final float minDistToPlayer, final float minDist, final float maxDist)
void triggerPickLocationAtClosestToEntityJumpPoint(StarSystemAPI system, SectorEntityToken entity, float minDistFromEntity)
static CampaignFleetAPI createFleet(FleetSize size, FleetQuality quality, OfficerNum oNum, OfficerQuality oQuality, String factionId, String fleetFactionId, String type, Vector2f locInHyper)
void triggerComplicationBegin(Object stage, ComplicationSpawn spawnType, StarSystemAPI system, String factionId, String thing, String thingItOrThey, String thingDesc, int paymentOffered, boolean aggressiveIfDeclined, ComplicationRepImpact repImpact, String failTrigger)
void triggerPickLocationAwayFromPlayer(final SectorEntityToken entity, final float arc, final float minDist, final float maxDist)
void triggerOrderFleetPatrol(final StarSystemAPI system, final boolean randomizeLocation, final SectorEntityToken ... patrolPoints)
void triggerPickLocationTowardsPlayer(final SectorEntityToken entity, final float arc, final float minDistFromPlayer, final float minDist, final float maxDist)
void beginWithinHyperspaceRangeTrigger(MarketAPI market, float rangeLY, boolean requirePlayerInHyperspace, Object ... stages)
void triggerMovePersonToMarket(PersonAPI person, MarketAPI market, boolean alwaysAddToComms)
void triggerSetMemoryValueAfterDelay(float delay, MemoryAPI memory, String key, Object value)
void triggerOrderFleetPatrol(final StarSystemAPI system, final boolean randomizeLocation, final String ... tags)
void triggerPickSetLocation(final LocationAPI location, final Vector2f coordinates)
void triggerCreateLargePatrolAroundMarket(MarketAPI market, Object stage, float extraSuspicion)
void triggerPickLocationTowardsEntity(final SectorEntityToken entity, final float arc, final float minDistFromPlayer, final float minDist, final float maxDist)
void triggerPickLocationAwayFromPlayer(final SectorEntityToken entity, final float arc, final float dist)
void triggerFleetInterceptPlayerOnSight(boolean mustBeStrongEnoughToFight, Object ... stages)
void triggerPickLocationFromEntityTowardsPlayer(final float arc, final float minDist, final float maxDist)
void triggerSpawnFleetNear(final SectorEntityToken entity, final String flag, final String refKey)
void triggerPickLocationAwayFromPlayer(final SectorEntityToken entity, final float arc, final float minDistFromPlayer, final float minDist, final float maxDist)
void triggerSpawnShipGraveyard(String factionId, int minShips, int maxShips, LocData data)
void triggerPickLocationAtClosestToEntityJumpPoint(StarSystemAPI system, SectorEntityToken entity)
void triggerPickLocationTowardsEntity(SectorEntityToken entity, float arc, float dist)
void triggerSetFleetDoctrineQuality(int officerQuality, int shipQuality, int numShips)
void triggerPickLocationFromEntityAwayFromPlayer(final float arc, final float minDistFromPlayer, final float minDist, final float maxDist)
void triggerPickLocationAroundEntity(final SectorEntityToken entity, final float dist)
void beginCustomTrigger(ConditionChecker condition, Object ... stages)
void triggerPickLocationAtClosestToPlayerJumpPoint(final StarSystemAPI system, final float minDistFromPlayer)
void triggerSpawnFleetAtPickedLocation(final float range, final String flag, final String refKey)
void triggerPickLocationTowardsPlayer(final SectorEntityToken entity, final float arc, final float minDist, final float maxDist)
void triggerCreatePatrolAroundMarket(MarketAPI market, String factionId, SectorEntityToken entityToPatrol, Object stage, FleetSize size, String fleetType, float extraSuspicion)
void triggerCreateSmallPatrol(MarketAPI from, String factionId, SectorEntityToken entityToPatrol, Object stage, float extraSuspicion)
void triggerCreateFleet(FleetSize size, FleetQuality quality, String factionId, String type, SectorEntityToken roughlyWhere)
void beginInRangeOfEntityTrigger(SectorEntityToken entity, float range, Object ... stages)
void triggerPickLocationAtInSystemJumpPoint(final StarSystemAPI system, final float minDistFromPlayer)
void triggerCreateFleet(FleetSize size, FleetQuality quality, String factionId, String type, StarSystemAPI roughlyWhere)
void triggerFleetInterceptPlayerNearby(boolean mustBeStrongEnoughToFight, Object ... stages)
void triggerAddCommodityDrop(String commodityId, int quantity, boolean dropQuantityBasedOnShipsDestroyed)
void triggerFleetSetWarnAttack(String warnCommsTrigger, String attackCommsTrigger, Object ... stages)
void triggerSpawnFleetNear(final SectorEntityToken entity, final float range, final String flag, final String refKey)
void beginDaysElapsedTrigger(float days, Object stage, Object ... stages)
void triggerSetMemoryValuePermanent(HasMemory withMemory, String key, Object value)
void triggerPickLocationWithinArc(final float dir, final float arc, final float minDistFromPlayer, final float minDist, final float maxDist)
CargoAPI createCargo(boolean unlimitedStacks)
CommoditySpecAPI getCommoditySpec(String commodityId)