70 public static enum FleetSize {
81 public float maxFPFraction;
82 private FleetSize(
float maxFPFraction) {
83 this.maxFPFraction = maxFPFraction;
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;
92 public FleetSize prev() {
93 int index = this.ordinal() - 1;
94 if (index < 0) index = 0;
99 public static enum FleetQuality {
110 public float qualityMod;
112 private FleetQuality(
float qualityMod,
int numSMods) {
113 this.qualityMod = qualityMod;
114 this.numSMods = numSMods;
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;
123 public FleetQuality prev() {
124 int index = this.ordinal() - 1;
125 if (index < 0) index = 0;
130 public static enum OfficerNum {
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;
144 public OfficerNum prev() {
145 int index = this.ordinal() - 1;
146 if (index < 0) index = 0;
151 public static enum OfficerQuality {
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;
169 public OfficerQuality prev() {
170 int index = this.ordinal() - 1;
171 if (index < 0) index = 0;
176 public static class FleetAddTugs
implements TriggerAction {
178 public FleetAddTugs(
int numTugs) {
179 this.numTugs = numTugs;
181 public void doAction(TriggerActionContext context) {
182 if (context.fleet !=
null) {
188 public static class UnhideCommListing
implements TriggerAction {
189 protected PersonAPI person;
190 public UnhideCommListing(PersonAPI person) {
191 this.person = person;
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);
200 if (market.getCommDirectory().getEntryForPerson(person) !=
null) {
201 market.getCommDirectory().getEntryForPerson(person).setHidden(
false);
210 public static class HideCommListing
implements TriggerAction {
211 protected PersonAPI person;
212 public HideCommListing(PersonAPI person) {
213 this.person = person;
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);
222 if (market.getCommDirectory().getEntryForPerson(person) !=
null) {
223 market.getCommDirectory().getEntryForPerson(person).setHidden(
true);
229 public static class MovePersonToMarket
implements TriggerAction {
230 protected PersonAPI person;
231 protected MarketAPI market;
232 protected boolean alwaysAddToComms;
234 public MovePersonToMarket(PersonAPI person, MarketAPI market,
boolean alwaysAddToComms) {
236 this.person = person;
237 this.market = market;
238 this.alwaysAddToComms = alwaysAddToComms;
242 public void doAction(TriggerActionContext context) {
243 Misc.moveToMarket(person, market, alwaysAddToComms);
248 public static class DespawnEntityAction
implements TriggerAction {
249 protected SectorEntityToken entity;
250 public DespawnEntityAction(SectorEntityToken entity) {
251 this.entity = entity;
254 public void doAction(TriggerActionContext context) {
255 Misc.fadeAndExpire(entity);
259 public static class MakeDiscoverableAction
implements TriggerAction {
260 protected float range;
262 public MakeDiscoverableAction(
float range,
float xp) {
267 public void doAction(TriggerActionContext context) {
268 ((
BaseHubMission)context.mission).makeDiscoverable(context.entity, range, xp);
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;
286 public void doAction(TriggerActionContext context) {
287 ((
BaseHubMission)context.mission).spawnShipGraveyard(factionId, minShips, maxShips, data);
291 public static class SpawnDebrisFieldAction
implements TriggerAction {
292 protected float radius;
293 protected float density;
294 protected LocData data;
296 public SpawnDebrisFieldAction(
float radius,
float density, LocData data) {
297 this.radius = radius;
298 this.density = density;
302 public void doAction(TriggerActionContext context) {
303 SectorEntityToken entity = ((
BaseHubMission)context.mission).spawnDebrisField(radius, density, data);
304 context.entity = entity;
309 public static class SpawnEntityAction
implements TriggerAction {
310 protected String entityId;
311 protected LocData data;
313 public SpawnEntityAction(String entityId, LocData data) {
314 this.entityId = entityId;
318 public void doAction(TriggerActionContext context) {
319 SectorEntityToken entity = ((
BaseHubMission)context.mission).spawnEntity(entityId, data);
320 context.entity = entity;
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;
335 public SpawnDerelictAction(String hullId, String factionId, DerelictType type, LocData data) {
336 this.hullId = hullId;
337 this.factionId = factionId;
342 public SpawnDerelictAction(DerelictType type, LocData data) {
346 public SpawnDerelictAction(DerelictShipData shipData, LocData data) {
347 this.shipData = shipData;
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);
360 entity = ((
BaseHubMission)context.mission).spawnDerelictOfType(type, data);
362 context.entity = entity;
368 public static class SpawnFleetNearAction
implements TriggerAction {
369 protected SectorEntityToken entity;
370 protected float range;
372 public SpawnFleetNearAction(SectorEntityToken entity,
float range) {
373 this.entity = entity;
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);
383 public static class SetFleetFactionAction
implements TriggerAction {
384 protected String factionId;
386 public SetFleetFactionAction(String factionId) {
387 this.factionId = factionId;
390 public void doAction(TriggerActionContext context) {
391 context.fleet.setFaction(factionId,
true);
395 public static class SetEntityToPickedJumpPoint
implements TriggerAction {
396 public SetEntityToPickedJumpPoint() {
399 public void doAction(TriggerActionContext context) {
400 context.entity = context.jumpPoint;
404 public static class FleetMakeImportantAction
implements TriggerAction {
405 protected String flag;
406 protected Enum[] stages;
407 public FleetMakeImportantAction(String flag, Enum ... stages) {
409 this.stages = stages;
411 public void doAction(TriggerActionContext context) {
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()));
420 context.fleet.getMemoryWithoutUpdate().set(flag,
true);
421 bhm.
changes.add(
new VariableSet(context.fleet.getMemoryWithoutUpdate(), flag,
true));
436 public static class EntityMakeImportantAction
implements TriggerAction {
437 protected String flag;
438 protected Enum[] stages;
439 public EntityMakeImportantAction(String flag, Enum ... stages) {
441 this.stages = stages;
443 public void doAction(TriggerActionContext context) {
448 Misc.makeImportant(context.entity.getMemoryWithoutUpdate(), bhm.
getReason());
449 bhm.
changes.add(
new MadeImportant(context.entity.getMemoryWithoutUpdate(), bhm.
getReason()));
452 context.entity.getMemoryWithoutUpdate().set(flag,
true);
453 bhm.
changes.add(
new VariableSet(context.entity.getMemoryWithoutUpdate(), flag,
true));
465 public static class SetFleetFlagsWithReasonAction
implements TriggerAction {
466 protected String[] flags;
467 protected String reason;
468 protected boolean permanent;
470 public SetFleetFlagsWithReasonAction(String reason,
boolean permanent, String ... flags) {
471 this.permanent = permanent;
473 this.reason = reason;
476 public void doAction(TriggerActionContext context) {
478 for (String flag : flags) {
479 Misc.setFlagWithReason(context.fleet.getMemoryWithoutUpdate(),
480 flag, reason,
true, -1f);
482 if (context.makeAllFleetFlagsPermanent) {
486 if (!permanent && bhm !=
null) {
487 String requiredKey = flag +
"_" + reason;
488 bhm.
changes.add(
new VariableSet(context.fleet.getMemoryWithoutUpdate(), requiredKey,
true));
494 public static class UnsetFleetFlagsWithReasonAction
implements
496 protected String[] flags;
497 protected String reason;
499 public UnsetFleetFlagsWithReasonAction(String reason, String ... flags) {
500 this.reason = reason;
504 public void doAction(TriggerActionContext context) {
505 for (String flag : flags) {
506 Misc.setFlagWithReason(context.fleet.getMemoryWithoutUpdate(),
507 flag, reason,
false, -1f);
513 public static class SetPersonMissionRefAction
implements TriggerAction {
514 protected String key;
516 public SetPersonMissionRefAction(String key) {
520 public void doAction(TriggerActionContext context) {
521 context.person.getMemoryWithoutUpdate().set(key, context.mission);
526 public static class SetFleetMissionRefAction
implements TriggerAction {
527 protected String key;
529 public SetFleetMissionRefAction(String key) {
533 public void doAction(TriggerActionContext context) {
534 context.fleet.getMemoryWithoutUpdate().set(key, context.mission);
539 public static class SetMemoryValueAction
implements TriggerAction {
540 protected String key;
541 protected Object value;
542 protected MemoryAPI memory;
543 protected boolean removeOnMissionOver;
545 public SetMemoryValueAction(MemoryAPI memory, String key, Object value,
boolean removeOnMissionOver) {
546 this.memory = memory;
549 this.removeOnMissionOver = removeOnMissionOver;
552 public void doAction(TriggerActionContext context) {
553 memory.set(key, value);
555 bhm.
changes.add(
new VariableSet(memory, key, removeOnMissionOver));
559 public static class SetMemoryValueAfterDelay
implements TriggerAction,
EveryFrameScript {
560 protected String key;
561 protected Object value;
562 protected MemoryAPI memory;
563 protected float delay;
565 public SetMemoryValueAfterDelay(
float delay, MemoryAPI memory, String key, Object value) {
566 this.memory = memory;
572 public void doAction(TriggerActionContext context) {
574 memory.set(key, value);
580 public boolean isDone() {
584 public boolean runWhilePaused() {
588 public void advance(
float amount) {
589 if (delay < 0)
return;
593 memory.set(key, value);
598 public static class AddTagAfterDelay
implements TriggerAction,
EveryFrameScript {
599 protected String tag;
600 protected float delay;
601 protected StarSystemAPI system;
603 public AddTagAfterDelay(
float delay, StarSystemAPI system, String tag) {
605 this.system = system;
609 public void doAction(TriggerActionContext context) {
613 public boolean isDone() {
617 public boolean runWhilePaused() {
621 public void advance(
float amount) {
622 if (delay < 0)
return;
631 public static class RunScriptAfterDelay
implements TriggerAction,
EveryFrameScript {
632 protected float delay;
635 public RunScriptAfterDelay(
float delay,
Script script) {
636 this.script = script;
640 public void doAction(TriggerActionContext context) {
644 public boolean isDone() {
648 public boolean runWhilePaused() {
652 public void advance(
float amount) {
653 if (delay < 0)
return;
656 if (delay < 0 && script !=
null) {
663 public static class IncreaseMarketHostileTimeout
implements TriggerAction {
664 protected MarketAPI market;
665 protected float days;
667 public IncreaseMarketHostileTimeout(MarketAPI market,
float days) {
668 this.market = market;
672 public void doAction(TriggerActionContext context) {
673 Misc.increaseMarketHostileTimeout(market, days);
677 public static class SetFleetMemoryValueAction
implements TriggerAction {
678 protected String key;
679 protected Object value;
681 public SetFleetMemoryValueAction(String key, Object value) {
686 public void doAction(TriggerActionContext context) {
687 context.fleet.getMemoryWithoutUpdate().set(key, value);
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;
698 public void doAction(TriggerActionContext context) {
699 ((
BaseHubMission)context.mission).addFleetDefeatTrigger(context.fleet, trigger, permanent);
703 public static class MakeFleetFlagsPermanentAction
implements TriggerAction {
704 protected boolean permanent;
705 public MakeFleetFlagsPermanentAction(
boolean permanent) {
706 this.permanent = permanent;
708 public void doAction(TriggerActionContext context) {
709 context.makeAllFleetFlagsPermanent = permanent;
714 public static class AddTagsAction
implements TriggerAction {
715 protected String [] tags;
717 public AddTagsAction(String ... tags) {
721 public void doAction(TriggerActionContext context) {
722 for (String tag : tags) {
723 context.fleet.addTag(tag);
728 public static class AddCommanderSkillAction
implements TriggerAction {
729 protected String skill;
732 public AddCommanderSkillAction(String skill,
int level) {
737 public void doAction(TriggerActionContext context) {
738 context.fleet.getCommanderStats().setSkillLevel(skill, level);
742 public static class SetFleetFlagAction
implements TriggerAction {
743 protected String flag;
744 protected Object[] stages;
745 protected boolean permanent;
747 public SetFleetFlagAction(String flag,
boolean permanent, Object ... stages) {
749 this.permanent = permanent;
750 this.stages = stages;
753 public void doAction(TriggerActionContext context) {
754 if (context.makeAllFleetFlagsPermanent) {
757 ((
BaseHubMission)context.mission).setFlag(context.fleet, flag, permanent, stages);
761 public static class SetEntityFlagAction
implements TriggerAction {
762 protected String flag;
763 protected Object[] stages;
764 protected boolean permanent;
766 public SetEntityFlagAction(String flag,
boolean permanent, Object ... stages) {
768 this.permanent = permanent;
769 this.stages = stages;
772 public void doAction(TriggerActionContext context) {
773 ((
BaseHubMission)context.mission).setFlag(context.entity, flag, permanent, stages);
778 public static class UnsetFleetFlagsAction
implements TriggerAction {
779 protected String[] flags;
781 public UnsetFleetFlagsAction(String ... flags) {
785 public void doAction(TriggerActionContext context) {
786 for (String flag : flags) {
787 context.fleet.getMemoryWithoutUpdate().unset(flag);
792 public static class UnsetEntityFlagsAction
implements TriggerAction {
793 protected String[] flags;
795 public UnsetEntityFlagsAction(String ... flags) {
799 public void doAction(TriggerActionContext context) {
800 for (String flag : flags) {
801 context.entity.getMemoryWithoutUpdate().unset(flag);
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;
815 public void doAction(TriggerActionContext context) {
816 memory.set(key, context.entity);
817 ((
BaseHubMission) context.mission).changes.add(
new VariableSet(memory, key,
true));
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;
829 public void doAction(TriggerActionContext context) {
830 memory.set(key, context.fleet);
831 ((
BaseHubMission) context.mission).changes.add(
new VariableSet(memory, key,
true));
835 public static class RemoveAbilitiesAction
implements TriggerAction {
836 protected String[] abilities;
838 public RemoveAbilitiesAction(String ... abilities) {
839 this.abilities = abilities;
842 public void doAction(TriggerActionContext context) {
843 for (String ability : abilities) {
844 context.fleet.removeAbility(ability);
850 public static class AddAbilitiesAction
implements TriggerAction {
851 protected String[] abilities;
853 public AddAbilitiesAction(String ... abilities) {
854 this.abilities = abilities;
857 public void doAction(TriggerActionContext context) {
858 for (String ability : abilities) {
859 context.fleet.addAbility(ability);
864 public static class GenericAddTagsAction
implements TriggerAction {
865 protected String [] tags;
866 protected SectorEntityToken entity;
868 public GenericAddTagsAction(SectorEntityToken entity, String ... tags) {
870 this.entity = entity;
873 public void doAction(TriggerActionContext context) {
874 for (String tag : tags) {
880 public static class GenericRemoveTagsAction
implements TriggerAction {
881 protected String [] tags;
882 protected SectorEntityToken entity;
884 public GenericRemoveTagsAction(SectorEntityToken entity, String ... tags) {
886 this.entity = entity;
889 public void doAction(TriggerActionContext context) {
890 for (String tag : tags) {
891 entity.removeTag(tag);
896 public static class MakeNonStoryCriticalAction
implements TriggerAction {
897 protected MemoryAPI [] memoryArray;
899 public MakeNonStoryCriticalAction(MemoryAPI ... memoryArray) {
900 this.memoryArray = memoryArray;
902 public void doAction(TriggerActionContext context) {
904 for (MemoryAPI memory : memoryArray) {
905 Misc.makeNonStoryCritical(memory, bhm.
getReason());
911 public static class SetInflaterAction
implements TriggerAction {
912 protected FleetInflater inflater;
914 public SetInflaterAction(FleetInflater inflater) {
915 this.inflater = inflater;
918 public void doAction(TriggerActionContext context) {
919 context.fleet.setInflater(inflater);
924 public static class SetRemnantConfigAction
implements TriggerAction {
925 protected boolean dormant;
928 public SetRemnantConfigAction(
boolean dormant,
long seed) {
929 this.dormant = dormant;
933 public void doAction(TriggerActionContext context) {
934 Random random =
new Random(seed);
935 RemnantSeededFleetManager.initRemnantFleetProperties(random, context.fleet, dormant);
940 public static class AddCustomDropAction
implements TriggerAction {
941 protected CargoAPI cargo;
943 public AddCustomDropAction(CargoAPI cargo) {
947 public void doAction(TriggerActionContext context) {
948 BaseSalvageSpecial.addExtraSalvage(context.fleet, cargo);
953 public static class AddCommodityDropAction
implements TriggerAction {
954 protected int quantity;
955 protected String commodityId;
956 protected boolean dropQuantityBasedOnShipsDestroyed;
958 public AddCommodityDropAction(
int quantity, String commodityId,
boolean dropQuantityBasedOnShipsDestroyed) {
959 this.quantity = quantity;
960 this.commodityId = commodityId;
961 this.dropQuantityBasedOnShipsDestroyed = dropQuantityBasedOnShipsDestroyed;
964 public void doAction(TriggerActionContext context) {
965 if (dropQuantityBasedOnShipsDestroyed) {
966 context.fleet.getCargo().addCommodity(commodityId, quantity);
969 cargo.addCommodity(commodityId, quantity);
970 BaseSalvageSpecial.addExtraSalvage(context.fleet, cargo);
975 public static class AddCommodityFractionDropAction
implements TriggerAction {
976 protected float fraction;
977 protected String commodityId;
978 protected boolean dropQuantityBasedOnShipsDestroyed;
980 public AddCommodityFractionDropAction(
float fraction, String commodityId) {
981 this.fraction = fraction;
982 this.commodityId = commodityId;
985 public void doAction(TriggerActionContext context) {
987 float capacity = context.fleet.getCargo().getMaxCapacity();
989 capacity = context.fleet.getCargo().getMaxFuel();
990 }
else if (spec.isPersonnel()) {
991 capacity = context.fleet.getCargo().getMaxPersonnel();
993 int quantity = (int) Math.round(fraction * capacity);
995 context.fleet.getCargo().addCommodity(commodityId, quantity);
1001 public static class AddWeaponDropAction
implements TriggerAction {
1002 protected int quantity;
1003 protected String weaponId;
1005 public AddWeaponDropAction(
int quantity, String weaponId) {
1006 this.quantity = quantity;
1007 this.weaponId = weaponId;
1010 public void doAction(TriggerActionContext context) {
1012 cargo.addWeapons(weaponId, quantity);
1013 BaseSalvageSpecial.addExtraSalvage(context.fleet, cargo);
1018 public static class AddFighterLPCDropAction
implements TriggerAction {
1019 protected String wingId;
1020 protected int quantity;
1022 public AddFighterLPCDropAction(String wingId,
int quantity) {
1023 this.wingId = wingId;
1024 this.quantity = quantity;
1027 public void doAction(TriggerActionContext context) {
1029 cargo.addFighters(wingId, quantity);
1030 BaseSalvageSpecial.addExtraSalvage(context.fleet, cargo);
1035 public static class AddHullmodDropAction
implements TriggerAction {
1036 protected String hullmodId;
1038 public AddHullmodDropAction(String hullmodId) {
1039 this.hullmodId = hullmodId;
1042 public void doAction(TriggerActionContext context) {
1044 cargo.addHullmods(hullmodId, 1);
1045 BaseSalvageSpecial.addExtraSalvage(context.fleet, cargo);
1050 public static class AddSpecialItemDropAction
implements TriggerAction {
1051 protected String data;
1052 protected String itemId;
1054 public AddSpecialItemDropAction(String data, String itemId) {
1056 this.itemId = itemId;
1059 public void doAction(TriggerActionContext context) {
1061 cargo.addSpecial(
new SpecialItemData(itemId, data), 1);
1062 BaseSalvageSpecial.addExtraSalvage(context.fleet, cargo);
1067 public static class SpawnFleetAtPickedLocationAction
implements
1069 protected float range;
1071 public SpawnFleetAtPickedLocationAction(
float range) {
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);
1083 public static class PickSetLocationAction
implements TriggerAction {
1084 protected Vector2f coordinates;
1085 protected LocationAPI location;
1087 public PickSetLocationAction(Vector2f coordinates, LocationAPI location) {
1088 this.coordinates = coordinates;
1089 this.location = location;
1092 public void doAction(TriggerActionContext context) {
1093 context.coordinates = coordinates;
1094 context.containingLocation = location;
1099 public static class PickLocationInHyperspaceAction
implements TriggerAction {
1100 protected StarSystemAPI system;
1102 public PickLocationInHyperspaceAction(StarSystemAPI system) {
1103 this.system = system;
1106 public void doAction(TriggerActionContext context) {
1110 context.coordinates = pick;
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;
1124 public PickLocationTowardsPlayerAction(SectorEntityToken entity,
1125 float arc,
float minDist,
float maxDist,
float minDistFromPlayer) {
1126 this.entity = entity;
1128 this.minDist = minDist;
1129 this.maxDist = maxDist;
1130 this.minDistFromPlayer = minDistFromPlayer;
1133 public void doAction(TriggerActionContext context) {
1134 if (entity ==
null) entity = context.entity;
1135 if (entity ==
null) entity = context.jumpPoint;
1138 float dir = Misc.getAngleInDegrees(playerFleet.getLocation(), entity.getLocation());
1140 if (playerFleet.getContainingLocation() != entity.getContainingLocation()) {
1141 dir = ((
BaseHubMission)context.mission).genRandom.nextFloat() * 360f;
1146 context.coordinates = pick;
1148 context.containingLocation = entity.getContainingLocation();
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;
1158 public PickLocationTowardsEntityAction(SectorEntityToken entity,
1159 float arc,
float minDist,
float maxDist,
float minDistFromPlayer) {
1160 this.entity = entity;
1162 this.minDist = minDist;
1163 this.maxDist = maxDist;
1164 this.minDistFromPlayer = minDistFromPlayer;
1167 public void doAction(TriggerActionContext context) {
1168 if (entity ==
null) entity = context.entity;
1169 if (entity ==
null) entity = context.jumpPoint;
1172 float dir = Misc.getAngleInDegrees(playerFleet.getLocation(), entity.getLocation());
1174 if (playerFleet.getContainingLocation() != entity.getContainingLocation()) {
1175 dir = ((
BaseHubMission)context.mission).genRandom.nextFloat() * 360f;
1180 context.coordinates = pick;
1182 context.containingLocation = entity.getContainingLocation();
1187 public static class PickLocationAwayFromPlayerAction
implements
1189 protected float minDist;
1190 protected SectorEntityToken entity;
1191 protected float maxDist;
1192 protected float arc;
1193 protected float minDistFromPlayer;
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;
1202 this.minDistFromPlayer = minDistFromPlayer;
1205 public void doAction(TriggerActionContext context) {
1206 if (entity ==
null) entity = context.entity;
1207 if (entity ==
null) entity = context.jumpPoint;
1210 float dir = Misc.getAngleInDegrees(playerFleet.getLocation(), entity.getLocation());
1211 if (playerFleet.getContainingLocation() != entity.getContainingLocation()) {
1212 dir = ((
BaseHubMission)context.mission).genRandom.nextFloat() * 360f;
1217 context.coordinates = pick;
1219 context.containingLocation = entity.getContainingLocation();
1224 public static class PickLocationAroundPlayerAction
implements TriggerAction {
1225 protected float maxDist;
1226 protected float minDist;
1228 public PickLocationAroundPlayerAction(
float maxDist,
float minDist) {
1229 this.maxDist = maxDist;
1230 this.minDist = minDist;
1233 public void doAction(TriggerActionContext context) {
1237 context.coordinates = pick;
1238 context.containingLocation = playerFleet.getContainingLocation();
1243 public static class PickLocationAroundEntityAction
implements TriggerAction {
1244 protected float minDist;
1245 protected SectorEntityToken entity;
1246 protected float maxDist;
1247 protected float minDistFromPlayer;
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;
1257 public void doAction(TriggerActionContext context) {
1258 if (entity ==
null) entity = context.entity;
1259 if (entity ==
null) entity = context.jumpPoint;
1262 context.coordinates = pick;
1263 context.containingLocation = entity.getContainingLocation();
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;
1276 public PickLocationWithinArcAction(
float arc, SectorEntityToken entity,
1277 float maxDist,
float minDist,
float minDistFromPlayer,
float dir) {
1279 this.entity = entity;
1280 this.maxDist = maxDist;
1281 this.minDist = minDist;
1282 this.minDistFromPlayer = minDistFromPlayer;
1286 public void doAction(TriggerActionContext context) {
1287 if (entity ==
null) entity = context.entity;
1288 if (entity ==
null) entity = context.jumpPoint;
1292 context.coordinates = pick;
1293 context.containingLocation = entity.getContainingLocation();
1298 public static class FleetSetPatrolActionText
implements TriggerAction {
1299 protected String text;
1300 public FleetSetPatrolActionText(String text) {
1304 public void doAction(TriggerActionContext context) {
1305 context.patrolText = text;
1309 public static class FleetSetTravelActionText
implements TriggerAction {
1310 protected String text;
1311 public FleetSetTravelActionText(String text) {
1315 public void doAction(TriggerActionContext context) {
1316 context.travelText = text;
1320 public static class OrderFleetPatrolSystemAction
implements TriggerAction {
1321 protected StarSystemAPI system;
1323 public OrderFleetPatrolSystemAction(StarSystemAPI system) {
1324 this.system = system;
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));
1334 public static class OrderFleetPatrolPointsAction
implements TriggerAction {
1335 protected List<SectorEntityToken> patrolPoints;
1336 protected boolean randomizeLocation;
1337 protected StarSystemAPI system;
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);
1345 this.randomizeLocation = randomizeLocation;
1346 this.system = system;
1349 public void doAction(TriggerActionContext context) {
1351 context.mission, system, randomizeLocation, context.fleet, patrolPoints.toArray(
new SectorEntityToken[0])));
1355 public static class OrderFleetPatrolSpawnedEntity
implements TriggerAction {
1356 protected boolean moveToNearEntity;
1358 public OrderFleetPatrolSpawnedEntity(
boolean moveToNearEntity) {
1359 this.moveToNearEntity = moveToNearEntity;
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(
1369 context.entity.getContainingLocation(), moveToNearEntity, context.fleet, entity));
1374 public static class OrderFleetPatrolTagsAction
implements TriggerAction {
1375 protected List<SectorEntityToken> added;
1376 protected StarSystemAPI system;
1377 protected boolean randomizeLocation;
1378 protected String[] tags;
1380 public OrderFleetPatrolTagsAction(StarSystemAPI system,
1381 boolean randomizeLocation, String ... tags) {
1382 this.system = system;
1383 this.randomizeLocation = randomizeLocation;
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)) {
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])));
1403 public static class OrderFleetStopPursuingPlayerUnlessInStage
implements TriggerAction {
1404 protected List<Object> stages;
1407 this.mission = mission;
1408 this.stages = Arrays.asList(stages);
1411 public void doAction(TriggerActionContext context) {
1416 public static class OrderFleetInterceptNearbyPlayerInStage
implements TriggerAction {
1417 protected List<Object> stages;
1419 protected float maxRange;
1420 protected boolean repeatable;
1421 protected boolean mustBeStrongEnoughToFight;
1422 protected float repeatDelay;
1423 public OrderFleetInterceptNearbyPlayerInStage(
BaseHubMission mission,
1424 boolean mustBeStrongEnoughToFight,
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);
1435 public void doAction(TriggerActionContext context) {
1437 mustBeStrongEnoughToFight, maxRange, repeatable, repeatDelay, stages));
1442 public static class OrderFleetInterceptPlayerAction
implements TriggerAction {
1443 protected boolean makeHostile;
1444 public OrderFleetInterceptPlayerAction(
boolean makeHostile) {
1445 this.makeHostile = makeHostile;
1448 public void doAction(TriggerActionContext context) {
1449 TransmitterTrapSpecial.makeFleetInterceptPlayer(context.fleet,
false,
false, makeHostile, 1000f);
1456 public static class OrderFleetEBurn
implements TriggerAction {
1457 public OrderFleetEBurn() {
1460 public void doAction(TriggerActionContext context) {
1461 AbilityPlugin eb = context.fleet.getAbility(Abilities.EMERGENCY_BURN);
1462 if (eb !=
null && eb.isUsable()) eb.activate();
1467 public static class FleetNoAutoDespawnAction
implements TriggerAction {
1468 public void doAction(TriggerActionContext context) {
1474 public static class PickLocationAtInSystemJumpPointAction
implements TriggerAction {
1475 protected StarSystemAPI system;
1476 protected float minDistFromPlayer;
1478 public PickLocationAtInSystemJumpPointAction(StarSystemAPI system,
1479 float minDistFromPlayer) {
1480 this.system = system;
1481 this.minDistFromPlayer = minDistFromPlayer;
1484 public void doAction(TriggerActionContext context) {
1485 WeightedRandomPicker<SectorEntityToken> picker =
new WeightedRandomPicker<SectorEntityToken>(((
BaseHubMission)context.mission).genRandom);
1486 picker.addAll(system.getJumpPoints());
1488 SectorEntityToken pick = picker.pick();
1491 context.jumpPoint = pick;
1492 context.coordinates = loc;
1493 context.containingLocation = system;
1497 public static class PickLocationAtClosestToPlayerJumpPointAction
implements TriggerAction {
1498 protected StarSystemAPI system;
1499 protected float minDistFromPlayer;
1501 public PickLocationAtClosestToPlayerJumpPointAction(StarSystemAPI system,
float minDistFromPlayer) {
1502 this.system = system;
1503 this.minDistFromPlayer = minDistFromPlayer;
1506 public void doAction(TriggerActionContext context) {
1507 WeightedRandomPicker<SectorEntityToken> picker =
new WeightedRandomPicker<SectorEntityToken>(((
BaseHubMission)context.mission).genRandom);
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) {
1522 if (closest !=
null) {
1523 picker.add(closest);
1526 SectorEntityToken pick = picker.pick();
1529 context.jumpPoint = pick;
1530 context.coordinates = loc;
1531 context.containingLocation = system;
1541 public static class PickLocationAtClosestToEntityJumpPointAction
implements TriggerAction {
1542 protected StarSystemAPI system;
1543 protected float minDistFromEntity;
1544 protected SectorEntityToken entity;
1546 public PickLocationAtClosestToEntityJumpPointAction(StarSystemAPI system, SectorEntityToken entity,
float minDistFromEntity) {
1547 this.system = system;
1548 this.entity = entity;
1549 this.minDistFromEntity = minDistFromEntity;
1552 public void doAction(TriggerActionContext context) {
1553 WeightedRandomPicker<SectorEntityToken> picker =
new WeightedRandomPicker<SectorEntityToken>(((
BaseHubMission)context.mission).genRandom);
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) {
1568 if (closest !=
null) {
1569 picker.add(closest);
1572 SectorEntityToken pick = picker.pick();
1575 context.jumpPoint = pick;
1576 context.coordinates = loc;
1577 context.containingLocation = system;
1581 public static class CreateFleetAction
implements TriggerAction {
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;
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;
1603 public Float damage =
null;
1605 public Boolean allWeapons;
1606 public ShipPickMode shipPickMode;
1607 public Boolean removeInflater;
1609 public String nameOverride =
null;
1610 public Boolean noFactionInName =
null;
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;
1619 this.fQuality = fQuality;
1621 freighterMult = 0.1f;
1625 public void doAction(TriggerActionContext context) {
1627 Random random =
null;
1628 if (context.mission !=
null) {
1631 random = Misc.random;
1634 float maxPoints = faction.getApproximateMaxFPPerFleet(ShipPickMode.PRIORITY_THEN_ALL);
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();
1645 if (fSizeOverride !=
null) {
1646 fraction = fSizeOverride * (0.95f + random.nextFloat() * 0.1f);
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;
1662 float combatPoints = fraction * maxPoints;
1663 if (combatFleetPointsOverride !=
null) {
1664 combatPoints = combatFleetPointsOverride;
1667 FactionDoctrineAPI doctrine = params.doctrineOverride;
1669 if (doctrine ==
null) {
1670 doctrine = faction.getDoctrine().clone();
1672 int added = (int)Math.round(excess / 0.1f);
1674 doctrine.setOfficerQuality(Math.min(5, doctrine.getOfficerQuality() + added));
1675 doctrine.setShipQuality(doctrine.getShipQuality() + added);
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;
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;
1718 params.doctrineOverride = doctrine;
1719 params.random = random;
1722 if (fQuality !=
null) {
1725 if (fQualityMod !=
null) {
1726 params.qualityMod += fQuality.qualityMod;
1728 params.qualityOverride = 0f;
1732 params.qualityMod += fQuality.qualityMod;
1735 params.qualityMod += fQuality.qualityMod;
1738 params.qualityMod += fQuality.qualityMod;
1741 if (fQualityMod !=
null) {
1742 params.qualityMod += fQuality.qualityMod;
1744 params.qualityMod += fQuality.qualityMod;
1749 params.qualityMod += fQuality.qualityMod;
1750 params.averageSMods = fQuality.numSMods;
1753 params.qualityMod += fQuality.qualityMod;
1754 params.averageSMods = fQuality.numSMods;
1757 params.qualityMod += fQuality.qualityMod;
1758 params.averageSMods = fQuality.numSMods;
1762 if (fQualityMod !=
null) {
1763 params.qualityMod += fQualityMod;
1765 if (fQualitySMods !=
null) {
1766 params.averageSMods = fQualitySMods;
1772 params.withOfficers =
false;
1775 params.officerNumberMult = 0f;
1778 params.officerNumberMult = 0.5f;
1783 params.officerNumberMult = 1.5f;
1791 if (oQuality !=
null) {
1794 params.officerLevelBonus = -3;
1797 if (params.commanderLevelLimit < params.officerLevelLimit) {
1798 params.commanderLevelLimit = params.officerLevelLimit;
1804 params.officerLevelBonus = 2;
1805 params.officerLevelLimit =
Global.
getSettings().
getInt(
"officerMaxLevel") + (int) OfficerTraining.MAX_LEVEL_BONUS;
1807 case UNUSUALLY_HIGH:
1808 params.officerLevelBonus = 4;
1809 params.officerLevelLimit = SalvageSpecialAssigner.EXCEPTIONAL_PODS_OFFICER_LEVEL;
1813 case AI_BETA_OR_GAMMA:
1817 params.aiCores = oQuality;
1820 if (doNotIntegrateAICores !=
null) {
1821 params.doNotIntegrateAICores = doNotIntegrateAICores;
1825 if (shipPickMode !=
null) {
1826 params.modeOverride = shipPickMode;
1829 params.updateQualityAndProducerFromSourceMarket();
1830 context.fleet = FleetFactoryV3.createFleet(params);
1831 context.fleet.setFacing(random.nextFloat() * 360f);
1833 if (this.faction !=
null) {
1834 context.fleet.setFaction(this.faction,
true);
1837 if (this.nameOverride !=
null) {
1838 context.fleet.setName(this.nameOverride);
1840 if (this.noFactionInName !=
null && this.noFactionInName) {
1841 context.fleet.setNoFactionInName(noFactionInName);
1844 if (removeInflater !=
null && removeInflater) {
1845 context.fleet.setInflater(
null);
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;
1854 if (shipPickMode !=
null) {
1855 p.mode = shipPickMode;
1861 context.fleet.getMemoryWithoutUpdate().set(MemFlags.FLEET_BUSY,
true);
1864 context.allFleets.add(context.fleet);
1870 if (damage !=
null) {
1871 FleetFactoryV3.applyDamageToFleet(context.fleet, damage,
false, random);
1888 if (action instanceof CreateFleetAction) {
1889 return (CreateFleetAction) action;
1917 return base * StarSystemGenerator.getNormalRandom(
genRandom, 0.75f, 1.25f);
1956 cfa.fSizeOverride = min.maxFPFraction + (max.maxFPFraction - min.maxFPFraction) * f;
1963 cfa.fSizeOverride = fractionOfMax;
1967 cfa.combatFleetPointsOverride = combatFleetPointsOverride;
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;
2005 FleetSize size = cfa.fSize;
2006 if (size ==
null) size = FleetSize.MEDIUM;
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();
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();
2023 FleetSize size = cfa.fSize;
2024 if (size ==
null) size = FleetSize.MEDIUM;
2028 FleetQuality fq = cfa.fQuality;
2029 if (fq ==
null) fq = FleetQuality.DEFAULT;
2030 FleetQuality limit = FleetQuality.VERY_HIGH;
2031 FleetQuality next = fq;
2033 while (next.next().ordinal() <= limit.ordinal() && steps > 0) {
2037 limit = FleetQuality.LOWER;
2038 FleetQuality prev = fq;
2040 while (prev.prev().ordinal() >= limit.ordinal() && steps > 0) {
2047 OfficerNum oNum = cfa.oNum;
2048 if (oNum ==
null) oNum = OfficerNum.DEFAULT;
2049 if (oNum == OfficerNum.FEWER || oNum == OfficerNum.DEFAULT) {
2060 OfficerQuality oQuality = cfa.oQuality;
2061 if (oQuality ==
null) oQuality = OfficerQuality.DEFAULT;
2062 if (oQuality == OfficerQuality.LOWER || oQuality == OfficerQuality.DEFAULT) {
2076 FleetSize size = cfa.fSize;
2077 if (size ==
null) size = FleetSize.MEDIUM;
2081 FleetQuality fq = cfa.fQuality;
2082 if (fq ==
null) fq = FleetQuality.DEFAULT;
2083 FleetQuality limit = FleetQuality.VERY_HIGH;
2084 FleetQuality next = fq;
2086 while (next.next().ordinal() <= limit.ordinal() && steps > 0) {
2090 limit = FleetQuality.LOWER;
2091 FleetQuality prev = fq;
2093 while (prev.prev().ordinal() >= limit.ordinal() && steps > 0) {
2100 OfficerNum oNum = cfa.oNum;
2101 if (oNum ==
null) oNum = OfficerNum.DEFAULT;
2102 if (oNum == OfficerNum.FEWER || oNum == OfficerNum.DEFAULT) {
2113 OfficerQuality oQuality = cfa.oQuality;
2114 if (oQuality ==
null) oQuality = OfficerQuality.DEFAULT;
2115 if (oQuality == OfficerQuality.LOWER || oQuality == OfficerQuality.DEFAULT) {
2129 FleetSize size = cfa.fSize;
2130 if (size ==
null) size = FleetSize.MEDIUM;
2134 FleetQuality fq = cfa.fQuality;
2135 if (fq ==
null) fq = FleetQuality.DEFAULT;
2136 FleetQuality limit = FleetQuality.SMOD_1;
2137 FleetQuality next = fq;
2139 while (next.next().ordinal() <= limit.ordinal() && steps > 0) {
2143 limit = FleetQuality.LOWER;
2144 FleetQuality prev = fq;
2146 while (prev.prev().ordinal() >= limit.ordinal() && steps > 0) {
2153 OfficerNum oNum = cfa.oNum;
2154 if (oNum ==
null) oNum = OfficerNum.DEFAULT;
2155 if (oNum == OfficerNum.FEWER || oNum == OfficerNum.DEFAULT || oNum == OfficerNum.MORE) {
2169 OfficerQuality oQuality = cfa.oQuality;
2170 if (oQuality ==
null) oQuality = OfficerQuality.DEFAULT;
2171 if (oQuality == OfficerQuality.LOWER || oQuality == OfficerQuality.DEFAULT) {
2192 this.useQualityInsteadOfQualityFraction = temporarilyUseQualityInsteadOfQualityFraction;
2211 float range = base - minQuality;
2214 f = (
quality - minQuality) / range;
2220 float range = maxQuality - base;
2227 f = 0.5f + f * 0.5f;
2232 @SuppressWarnings(
"unchecked")
2234 return EnumSet.range(from, to).toArray();
2238 float num = enums.length;
2241 float rem = (float)(f - (
int) f);
2242 if (rem < 0.2f) rem = 0f;
2243 if (rem > 0.8f) rem = 1f;
2245 int index = (int) f;
2249 if (index > enums.length - 1) index = enums.length - 1;
2250 if (index < 0) index = 0;
2251 return enums[index];
2264 float transportMult,
float linerMult,
2265 float utilityMult) {
2267 if (freighterMult > 0) cfa.freighterMult = freighterMult;
2268 else cfa.freighterMult =
null;
2270 if (tankerMult > 0) cfa.tankerMult = tankerMult;
2271 else cfa.tankerMult =
null;
2273 if (transportMult > 0) cfa.transportMult = transportMult;
2274 else cfa.transportMult =
null;
2276 if (linerMult > 0) cfa.linerMult = linerMult;
2277 else cfa.linerMult =
null;
2279 if (utilityMult > 0) cfa.utilityMult = utilityMult;
2280 else cfa.utilityMult =
null;
2286 if (cfa.params.doctrineOverride ==
null) {
2287 FactionAPI faction =
Global.
getSector().getFaction(cfa.params.factionId);
2288 cfa.params.doctrineOverride = faction.getDoctrine().clone();
2291 cfa.params.doctrineOverride.setWarships(warships);
2292 cfa.params.doctrineOverride.setCarriers(carriers);
2293 cfa.params.doctrineOverride.setPhaseShips(phaseShips);
2298 if (cfa.params.addShips ==
null) {
2299 cfa.params.addShips =
new ArrayList<String>();
2301 for (String
id : variants) {
2302 cfa.params.addShips.add(
id);
2308 if (cfa.params.doctrineOverride ==
null) {
2309 FactionAPI faction =
Global.
getSector().getFaction(cfa.params.factionId);
2310 cfa.params.doctrineOverride = faction.getDoctrine().clone();
2313 cfa.params.doctrineOverride.setCombatFreighterProbability(prob);
2319 if (cfa.params.doctrineOverride ==
null) {
2320 FactionAPI faction =
Global.
getSector().getFaction(cfa.params.factionId);
2321 cfa.params.doctrineOverride = faction.getDoctrine().clone();
2324 if (officerQuality >= 0) {
2325 cfa.params.doctrineOverride.setOfficerQuality(officerQuality);
2328 if (shipQuality >= 0) {
2329 cfa.params.doctrineOverride.setShipQuality(shipQuality);
2332 if (numShips >= 0) {
2333 cfa.params.doctrineOverride.setNumShips(numShips);
2340 if (cfa.params.doctrineOverride ==
null) {
2341 FactionAPI faction =
Global.
getSector().getFaction(cfa.params.factionId);
2342 cfa.params.doctrineOverride = faction.getDoctrine().clone();
2345 if (shipSize >= 0) {
2346 cfa.params.doctrineOverride.setShipSize(shipSize);
2348 if (aggression >= 0) {
2349 cfa.params.doctrineOverride.setAggression(aggression);
2356 if (cfa.params.doctrineOverride ==
null) {
2357 FactionAPI faction =
Global.
getSector().getFaction(cfa.params.factionId);
2358 cfa.params.doctrineOverride = faction.getDoctrine().clone();
2361 cfa.params.doctrineOverride.setAutofitRandomizeProbability(randomizeProb);
2368 cfa.params.fleetType = fleetType;
2369 cfa.fSizeOverride =
null;
2373 cfa.params.fleetType = fleetType;
2384 cfa.params.commander = commander;
2389 cfa.params.noCommanderSkills =
true;
2394 cfa.params.maxShipSize = max;
2398 cfa.params.minShipSize = min;
2402 cfa.params.maxNumShips = num;
2407 cfa.params.onlyRetainFlagship =
true;
2411 cfa.params.flagshipVariantId = variantId;
2416 cfa.params.flagshipVariant = variant;
2421 cfa.removeInflater =
true;
2426 cfa.shipPickMode = mode;
2431 cfa.allWeapons =
true;
2441 cfa.faction = factionId;
2446 cfa.nameOverride = name;
2450 cfa.noFactionInName =
true;
2454 cfa.doNotIntegrateAICores =
true;
2465 public void doAction(TriggerActionContext context) {
2466 context.fleet.setCommander(commander);
2467 context.fleet.getFleetData().ensureHasFlagship();
2523 triggerCustomAction(
new SetMemoryValueAction(withMemory.getMemoryWithoutUpdate(), key, value,
true));
2526 triggerCustomAction(
new SetMemoryValueAction(withMemory.getMemoryWithoutUpdate(), key, value,
false));
2596 MemFlags.MEMORY_KEY_MAKE_AGGRESSIVE);
2620 setFlag(fleet, MemFlags.MEMORY_KEY_MAKE_AGGRESSIVE_ONE_BATTLE_ONLY, permanent);
2654 MemFlags.MEMORY_KEY_NO_REP_IMPACT);
2696 String flag = MemFlags.MEMORY_KEY_MAKE_NON_HOSTILE +
"_" + factionId;
2700 String flag = MemFlags.MEMORY_KEY_MAKE_HOSTILE +
"_" + factionId;
2782 long seed = Misc.seedUniquifier() ^
genRandom.nextLong();
2798 triggerCustomAction(
new AddCommodityDropAction(quantity, commodityId, dropQuantityBasedOnShipsDestroyed));
2833 if (refKey !=
null) {
2840 public void triggerSpawnFleetNear(
final SectorEntityToken entity,
final float range,
final String flag,
final String refKey) {
2845 if (refKey !=
null) {
2864 final float minDist,
final float maxDist) {
2868 final float minDist,
final float maxDist) {
2872 final float minDistFromPlayer,
final float minDist,
final float maxDist) {
2873 triggerCustomAction(
new PickLocationTowardsPlayerAction(
null, arc, minDist, maxDist, minDistFromPlayer));
2876 final float minDistFromPlayer,
final float minDist,
final float maxDist) {
2877 triggerCustomAction(
new PickLocationTowardsPlayerAction(entity, arc, minDist, maxDist, minDistFromPlayer));
2884 final float minDistFromPlayer,
final float minDist,
final float maxDist) {
2885 triggerCustomAction(
new PickLocationTowardsEntityAction(entity, arc, minDist, maxDist, minDistFromPlayer));
2893 final float minDist,
final float maxDist) {
2897 final float minDistFromPlayer,
final float minDist,
final float maxDist) {
2898 triggerCustomAction(
new PickLocationAwayFromPlayerAction(minDist,
null, maxDist, arc, minDistFromPlayer));
2904 final float minDist,
final float maxDist) {
2908 final float minDistFromPlayer,
final float minDist,
final float maxDist) {
2909 triggerCustomAction(
new PickLocationAwayFromPlayerAction(minDist, entity, maxDist, arc, minDistFromPlayer));
2930 triggerCustomAction(
new PickLocationAroundEntityAction(minDist, entity, maxDist, minDistFromPlayer));
2937 triggerCustomAction(
new PickLocationAtInSystemJumpPointAction(system, minDistFromPlayer));
2944 triggerCustomAction(
new PickLocationAtClosestToPlayerJumpPointAction(system, minDistFromPlayer));
2948 triggerCustomAction(
new PickLocationAtClosestToEntityJumpPointAction(system, entity, 0f));
2951 triggerCustomAction(
new PickLocationAtClosestToEntityJumpPointAction(system, entity, minDistFromEntity));
2955 final float minDistFromPlayer,
final float minDist,
final float maxDist) {
2959 final float minDistFromPlayer,
final float minDist,
final float maxDist) {
2960 triggerCustomAction(
new PickLocationWithinArcAction(arc, entity, maxDist, minDist, minDistFromPlayer, dir));
2987 final SectorEntityToken ... patrolPoints) {
2988 triggerCustomAction(
new OrderFleetPatrolPointsAction(patrolPoints, randomizeLocation, system));
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) {
3006 if (action instanceof OrderFleetPatrolPointsAction) {
3007 OrderFleetPatrolPointsAction a = (OrderFleetPatrolPointsAction) action;
3008 for (SectorEntityToken curr : points) {
3010 a.patrolPoints.add(curr);
3043 if (allowLongPursuit) {
3052 if (
genRandom.nextFloat() < probabilityToEBurn) {
3070 boolean repeatable,
float repeatDelay, Object ...
stages) {
3072 new OrderFleetInterceptNearbyPlayerInStage(
this, mustBeStrongEnoughToFight, maxRange, repeatable, repeatDelay,
stages));
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;
3092 if (distIncr < 1) distIncr = 1;
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);
3100 Vector2f.add(entity.getLocation(), loc, loc);
3105 WeightedRandomPicker<Vector2f> copy =
new WeightedRandomPicker<Vector2f>(random);
3106 copy.addAll(picker);
3109 StarSystemAPI system = entity.getStarSystem();
3111 Vector2f pick =
null;
3112 LocationAPI containingLocation = entity.getContainingLocation();
3114 while (!picker.isEmpty()) {
3115 Vector2f loc = picker.pickAndRemove();
3118 float distToPlayer = Float.MAX_VALUE;
3119 if (playerFleet !=
null && playerFleet.getContainingLocation() == containingLocation) {
3120 distToPlayer = Misc.getDistance(playerFleet.getLocation(), loc);
3121 if (distToPlayer < minDistToPlayer) {
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);
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) {
3209 beginCustomTrigger(
new InHyperRangeOfEntityChecker(market.getPrimaryEntity(), rangeLY, requirePlayerInHyperspace),
stages);
3221 for (Object stage :
stages) {
3230 throw new RuntimeException(
"endTrigger() called without a corresponding beginTrigger()");
3236 if (
currTrigger !=
null)
throw new RuntimeException(
"Already began a trigger, call endTrigger() to finish it");
3300 for (String
id : markets) {
3302 if (market !=
null) {
3308 for (MarketAPI market : markets) {
3331 OfficerNum oNum, OfficerQuality oQuality, String factionId, String fleetFactionId, String type, Vector2f locInHyper) {
3332 CreateFleetAction action =
new CreateFleetAction(type, locInHyper, size,
quality, factionId);
3334 action.oQuality = oQuality;
3335 action.faction = fleetFactionId;
3336 TriggerActionContext context =
new TriggerActionContext(
null);
3337 action.doAction(context);
3338 return context.fleet;
3351 public void triggerCreateSmallPatrol(MarketAPI from, String factionId, SectorEntityToken entityToPatrol, Object stage,
float extraSuspicion) {
3354 public void triggerCreateMediumPatrol(MarketAPI from, String factionId, SectorEntityToken entityToPatrol, Object stage,
float extraSuspicion) {
3357 public void triggerCreateLargePatrol(MarketAPI from, String factionId, SectorEntityToken entityToPatrol, Object stage,
float extraSuspicion) {
3361 Object stage, FleetSize size, String fleetType,
3362 float extraSuspicion) {
3366 Object stage, FleetSize size, String fleetType,
3367 float extraSuspicion) {
3368 if (entityToPatrol ==
null) entityToPatrol = market.getPrimaryEntity();
3369 if (factionId ==
null) factionId = market.getFactionId();
3372 triggerCreateFleet(size, FleetQuality.DEFAULT, factionId, fleetType, entityToPatrol);
3376 if (faction.getCustomBoolean(Factions.CUSTOM_PIRATE_BEHAVIOR)) {
3386 if (market !=
null) {
3393 public static enum ComplicationSpawn {
3394 APPROACHING_OR_ENTERING,
3399 public static enum ComplicationRepImpact{
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();
3416 if (
genRandom.nextFloat() < 0.33f && cfa.fSize != FleetSize.TINY &&
getQuality() > 0.25f) {
3418 cfa.fSize = cfa.fSize.prev();
3419 if (cfa.fQuality ==
null) cfa.fQuality = FleetQuality.DEFAULT;
3420 cfa.fQuality = cfa.fQuality.next();
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) {
3426 cfa.fSize = cfa.fSize.next();
3427 if (cfa.fQuality ==
null) cfa.fQuality = FleetQuality.DEFAULT;
3428 cfa.fQuality = cfa.fQuality.prev();
3433 @SuppressWarnings(
"rawtypes")
3437 String thingItOrThey,
3440 boolean aggressiveIfDeclined,
3441 ComplicationRepImpact repImpact,
3442 String failTrigger) {
3445 if (
"them".equals(thingItOrThey)) thingItOrThey =
"they";
3447 if (spawnType == ComplicationSpawn.APPROACHING_SYSTEM) {
3449 }
else if (spawnType == ComplicationSpawn.ENTERING_SYSTEM) {
3451 }
else if (spawnType == ComplicationSpawn.EXITING_SYSTEM) {
3457 triggerCreateFleet(FleetSize.LARGE, FleetQuality.DEFAULT, factionId, FleetTypes.PATROL_MEDIUM, system);
3463 if (aggressiveIfDeclined) {
3468 if (repImpact == ComplicationRepImpact.LOW) {
3470 }
else if (repImpact == ComplicationRepImpact.NONE) {
3477 if (faction.getCustomBoolean(Factions.CUSTOM_SPAWNS_AS_INDEPENDENT)) {
3483 if (spawnType == ComplicationSpawn.APPROACHING_SYSTEM) {
3485 }
else if (spawnType == ComplicationSpawn.ENTERING_SYSTEM) {
3487 }
else if (spawnType == ComplicationSpawn.EXITING_SYSTEM) {
3504 String thingItOrThem =
"them";
3505 if (
"it".equals(thingItOrThey)) thingItOrThem =
"it";
3512 if (failTrigger ==
null) {
3513 failTrigger =
"FWTDefaultFailTrigger";
3523 if (randomizeAndAdjustFleetSize) {
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;
3546 cfa.params.fleetType = FleetTypes.PATROL_LARGE;
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;
3557 cfa.params.fleetType = FleetTypes.SCAVENGER_LARGE;
3570 if (cfa !=
null && cfa.params !=
null && cfa.params.factionId !=
null) {
3580 if (navigationSkill) {
3586 if (allowLongPursuit) {
3595 if (fleet.getNumMembersFast() + tugs > max) {
3596 FleetFactoryV3.pruneFleet(max - tugs, 0, fleet, 100000, random);
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());
3618 if (preferred ==
null)
return;
3620 for (MarketAPI market : preferred) {
3621 if (!market.hasCondition(Conditions.DECIVILIZED)) {
3629 if (preferred ==
null)
return;
3631 for (String
id : preferred) {
3633 if (market !=
null && !market.hasCondition(Conditions.DECIVILIZED)) {