48 if (target ==
null)
return;
50 RouteSegment current = route.getCurrent();
51 SectorEntityToken source = route.getMarket().getPrimaryEntity();
53 TaskInterval [] intervals =
new TaskInterval[] {
54 TaskInterval.days(3f + (
float) Math.random() * 3f),
55 TaskInterval.travel(),
56 TaskInterval.remaining(1f),
57 TaskInterval.travel(),
58 TaskInterval.days(3f + (
float) Math.random() * 3f),
63 source, source, target, target, source, source);
65 fleet.clearAssignments();
68 float combinedTravelAndPatrolTime = intervals[1].value + intervals[2].value;
70 if (intervals[0].value > 0) {
71 fleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, source, intervals[0].value,
PREP_STAGE);
73 if (intervals[1].value > 0) {
74 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, target, combinedTravelAndPatrolTime,
TRAVEL_TO_STAGE,
76 combinedTravelAndPatrolTime = 0f;
78 if (intervals[2].value > 0) {
79 fleet.addAssignment(FleetAssignment.PATROL_SYSTEM, target, combinedTravelAndPatrolTime,
PATROL_STAGE,
81 target.isSystemCenter() ?
new Script() {
83 fleet.getMemoryWithoutUpdate().set(MemFlags.MEMORY_KEY_ALLOW_LONG_PURSUIT,
true);
85 target.isSystemCenter() ?
new Script() {
87 fleet.getMemoryWithoutUpdate().unset(MemFlags.MEMORY_KEY_ALLOW_LONG_PURSUIT);
93 if (intervals[3].value > 0) {
94 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, source, 1000f,
RETURN_STAGE);
99 fleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, source, intervals[4].value,
STAND_DOWN_STAGE);
100 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, source, 1000f,
103 fleet.getAI().setActionTextProvider(
this);
111 FleetAssignmentDataAPI curr = fleet.getCurrentAssignment();
112 if (curr ==
null)
return null;
114 String stage = curr.getActionText();
115 SectorEntityToken target = curr.getTarget();
118 if (target !=
null) {
119 name = target.getName();
120 if (target instanceof CustomCampaignEntityAPI) {
121 CustomCampaignEntityAPI cce = (CustomCampaignEntityAPI) target;
122 if (name.equals(cce.getCustomEntitySpec().getDefaultName())) {
124 name = cce.getCustomEntitySpec().getNameInText();
129 boolean pirate = fleet.getMemoryWithoutUpdate().getBoolean(MemFlags.MEMORY_KEY_PIRATE);
133 return "preparing for patrol duty";
134 }
else if (
TRAVEL_TO_STAGE.equals(stage) && target !=
null && !target.isSystemCenter() && !target.isInHyperspace()) {
135 return "traveling to " + name;
138 }
else if (
PATROL_STAGE.equals(stage) && target !=
null) {
139 if (target.hasTag(Tags.OBJECTIVE)) {
140 return "guarding " + name;
141 }
else if (target.hasTag(Tags.JUMP_POINT)) {
142 return "guarding " + name;
143 }
else if (target.getMarket() !=
null) {
144 return "defending " + name;
148 }
else if (
RETURN_STAGE.equals(stage) && target !=
null && !target.isSystemCenter()) {
149 return "returning to " + name;
151 return "standing down";
155 return "preparing for patrol duty";
156 }
else if (
TRAVEL_TO_STAGE.equals(stage) && target !=
null && !target.isSystemCenter() && !target.isInHyperspace()) {
157 return "traveling to " + name;
160 }
else if (
PATROL_STAGE.equals(stage) && target !=
null) {
161 if (target.hasTag(Tags.OBJECTIVE)) {
162 return "guarding " + name;
163 }
else if (target.hasTag(Tags.JUMP_POINT)) {
164 return "guarding " + name;
165 }
else if (target.getMarket() !=
null) {
166 return "patrolling around " + name;
170 }
else if (
RETURN_STAGE.equals(stage) && target !=
null && !target.isSystemCenter()) {
171 return "returning to " + name;
173 return "standing down from patrol duty";
196 Random random = route.getRandom(1);
198 PatrolFleetData custom = (PatrolFleetData) route.getCustom();
199 PatrolType type = custom.type;
201 LocationAPI loc = fleet.getContainingLocation();
202 if (loc ==
null)
return null;
204 WeightedRandomPicker<SectorEntityToken> picker =
new WeightedRandomPicker<SectorEntityToken>(random);
206 CountingMap<SectorEntityToken> existing =
new CountingMap<SectorEntityToken>();
208 CampaignFleetAPI other = data.getActiveFleet();
209 if (other ==
null)
continue;
210 FleetAssignmentDataAPI curr = other.getCurrentAssignment();
211 if (curr ==
null || curr.getTarget() ==
null ||
212 curr.getAssignment() != FleetAssignment.PATROL_SYSTEM) {
215 existing.add(curr.getTarget());
218 List<MarketAPI> markets = Misc.getMarketsInLocation(fleet.getContainingLocation());
221 for (MarketAPI market : markets) {
222 if (market.getFaction().isHostileTo(fleet.getFaction())) {
223 hostileMax = Math.max(hostileMax, market.getSize());
224 }
else if (market.getFaction() == fleet.getFaction()) {
225 ourMax = Math.max(ourMax, market.getSize());
228 boolean inControl = ourMax > hostileMax;
230 for (SectorEntityToken entity : loc.getEntitiesWithTag(Tags.OBJECTIVE)) {
231 if (entity.getFaction() != fleet.getFaction())
continue;
234 for (
int i = 0; i < existing.getCount(entity); i++) w *= 0.1f;
236 if (type == PatrolType.HEAVY) w *= 0.1f;
238 picker.add(entity, w);
242 for (SectorEntityToken entity : loc.getEntitiesWithTag(Tags.STABLE_LOCATION)) {
244 for (
int i = 0; i < existing.getCount(entity); i++) w *= 0.1f;
246 if (type == PatrolType.HEAVY) w *= 0.1f;
248 picker.add(entity, w);
252 for (SectorEntityToken entity : loc.getJumpPoints()) {
254 for (
int i = 0; i < existing.getCount(entity); i++) w *= 0.1f;
256 if (type == PatrolType.HEAVY) w *= 0.1f;
258 picker.add(entity, w);
261 if (loc instanceof StarSystemAPI && custom.type == PatrolType.HEAVY) {
262 StarSystemAPI system = (StarSystemAPI) loc;
263 if (system.getHyperspaceAnchor() !=
null) {
265 for (
int i = 0; i < existing.getCount(system.getHyperspaceAnchor()); i++) w *= 0.1f;
266 picker.add(system.getHyperspaceAnchor(), w);
271 for (MarketAPI market : markets) {
272 if (market.getFaction().isHostileTo(fleet.getFaction()))
continue;
275 if (market == route.getMarket()) {
280 if (market.getMemoryWithoutUpdate().getBoolean(MemFlags.MARKET_PATROL)) {
281 if (market.getFaction() != fleet.getFaction()) {
289 for (
int i = 0; i < existing.getCount(market.getPrimaryEntity()); i++) w *= 0.1f;
290 picker.add(market.getPrimaryEntity(), w);
293 if (fleet.getContainingLocation() instanceof StarSystemAPI && type != PatrolType.HEAVY) {
294 StarSystemAPI system = (StarSystemAPI) fleet.getContainingLocation();
296 for (
int i = 0; i < existing.getCount(system.getCenter()); i++) w *= 0.1f;
297 picker.add(system.getCenter(), w);
300 SectorEntityToken target = picker.pick();
301 if (target ==
null) {
302 target = route.market.getPrimaryEntity();