Starsector API
Loading...
Searching...
No Matches
TriggerFleetTravelAssignmentAI.java
Go to the documentation of this file.
1
package
com.fs.starfarer.api.impl.campaign.missions.hub;
2
3
import
com.fs.starfarer.api.EveryFrameScript;
4
5
public
class
TriggerFleetTravelAssignmentAI
implements
EveryFrameScript
{
6
7
/*
8
protected enum Stage {
9
ORBITING_FROM,
10
TRAVELING,
11
ORBITING_TO,
12
}
13
14
protected CampaignFleetAPI fleet;
15
protected SectorEntityToken from;
16
protected SectorEntityToken to;
17
18
protected Stage stage = Stage.ORBITING_FROM;
19
protected float elapsedInStage;
20
21
protected float daysOrbitFrom;
22
protected float daysOrbitTo;
23
24
protected String textOrbitingFrom;
25
protected String textTravel;
26
protected String textOrbitingTo;
27
28
29
public TriggerFleetTravelAssignmentAI(String travelText, String patrolText, HubMission mission, LocationAPI system, boolean randomLocation, CampaignFleetAPI fleet, SectorEntityToken ... patrolPoints) {
30
this.travelText = travelText;
31
this.patrolText = patrolText;
32
this.mission = mission;
33
this.fleet = fleet;
34
this.system = system;
35
36
if (patrolPoints != null) {
37
for (SectorEntityToken curr : patrolPoints) {
38
if (curr == null) continue;
39
if (curr == fleet) continue;
40
this.patrolPoints.add(curr);
41
}
42
}
43
44
if (!fleet.hasScriptOfClass(MissionFleetAutoDespawn.class)) {
45
fleet.addScript(new MissionFleetAutoDespawn(mission, fleet));
46
}
47
48
// moving this to CreateFleetAction, since most mission fleets are likely to want to ignore WarSimScript
49
//fleet.getMemoryWithoutUpdate().set(MemFlags.FLEET_BUSY, true);
50
51
giveInitialAssignments(randomLocation);
52
}
53
54
protected void giveInitialAssignments(boolean randomLocation) {
55
if (randomLocation) {
56
// start at random location
57
SectorEntityToken target = pickPatrolPoint();
58
if (target != null) {
59
Vector2f loc = Misc.getPointAtRadius(target.getLocation(), target.getRadius() + 100f);
60
fleet.setLocation(loc.x, loc.y);
61
} else {
62
Vector2f loc = Misc.getPointAtRadius(new Vector2f(), 5000f);
63
fleet.setLocation(loc.x, loc.y);
64
}
65
}
66
pickNext();
67
}
68
69
protected SectorEntityToken pickPatrolPoint() {
70
if (patrolPoints != null) {
71
Random random = null;
72
if (mission instanceof BaseHubMission) random = ((BaseHubMission)mission).getGenRandom();
73
WeightedRandomPicker<SectorEntityToken> picker = new WeightedRandomPicker<SectorEntityToken>(random);
74
for (SectorEntityToken curr : patrolPoints) {
75
if (!curr.isAlive()) continue;
76
picker.addAll(patrolPoints);
77
}
78
return picker.pick();
79
}
80
return null;
81
}
82
83
protected SectorEntityToken currTarget;
84
protected void pickNext() {
85
currTarget = pickPatrolPoint();
86
if (currTarget != null) {
87
float speed = Misc.getSpeedForBurnLevel(8);
88
float dist = Misc.getDistance(fleet.getLocation(), currTarget.getLocation());
89
float seconds = dist / speed;
90
float days = seconds / Global.getSector().getClock().getSecondsPerDay();
91
days += 5f + 5f * (float) Math.random();
92
fleet.addAssignment(FleetAssignment.PATROL_SYSTEM, currTarget, days, patrolText == null ? "patrolling" : patrolText);
93
return;
94
} else if (system instanceof StarSystemAPI) {
95
float days = 5f + 5f * (float) Math.random();
96
fleet.addAssignment(FleetAssignment.PATROL_SYSTEM, ((StarSystemAPI)system).getCenter(), days, patrolText == null ? "patrolling" : patrolText);
97
}
98
}
99
100
public void advance(float amount) {
101
if (fleet.getCurrentAssignment() == null) {
102
pickNext();
103
} else {
104
String travel = travelText;
105
if (travel == null) {
106
if (Misc.isPatrol(fleet)) {
107
travel = "patrolling";
108
} else {
109
travel = "traveling";
110
}
111
}
112
if (fleet.getAI() != null &&
113
travel != null && currTarget != null && fleet.getCurrentAssignment().getTarget() == currTarget &&
114
fleet.getCurrentAssignment().getAssignment() == FleetAssignment.PATROL_SYSTEM) {
115
float dist = Misc.getDistance(fleet, currTarget);
116
if (dist > 1500 || fleet.getContainingLocation() != currTarget.getContainingLocation()) {
117
boolean standingDown = fleet.getAI() instanceof ModularFleetAIAPI &&
118
((ModularFleetAIAPI) fleet.getAI()).getTacticalModule() != null &&
119
((ModularFleetAIAPI) fleet.getAI()).getTacticalModule().isStandingDown();
120
if (standingDown) {
121
fleet.getAI().setActionTextOverride(null);
122
} else {
123
fleet.getAI().setActionTextOverride(travel);
124
}
125
} else {
126
fleet.getAI().setActionTextOverride(null);
127
}
128
}
129
}
130
131
132
133
// replaced with separate MissionFleetAutoDespawn script
134
//despawnIfNeeded(amount);
135
}
136
137
// protected void despawnIfNeeded(float amount) {
138
// if (isMissionEnded()) {
139
// if (!fleet.isInCurrentLocation()) {
140
// elapsedWaitingForDespawn += Global.getSector().getClock().convertToDays(amount);
141
// if (elapsedWaitingForDespawn > 30f && fleet.getBattle() == null) {
142
// fleet.despawn(FleetDespawnReason.PLAYER_FAR_AWAY, null);
143
// elapsedWaitingForDespawn = 0f;
144
// }
145
// } else {
146
// elapsedWaitingForDespawn = 0f;
147
// }
148
// }
149
// }
150
151
public boolean isMissionEnded() {
152
return mission instanceof IntelInfoPlugin && ((IntelInfoPlugin)mission).isEnded();
153
}
154
155
*/
156
157
public
void
advance
(
float
amount) {
158
159
}
160
161
public
boolean
isDone
() {
162
return
false
;
163
}
164
165
public
boolean
runWhilePaused
() {
166
return
false
;
167
}
168
169
170
171
}
172
173
174
175
176
177
178
179
180
181
com.fs.starfarer.api.impl.campaign.missions.hub.TriggerFleetTravelAssignmentAI
Definition
TriggerFleetTravelAssignmentAI.java:5
com.fs.starfarer.api.impl.campaign.missions.hub.TriggerFleetTravelAssignmentAI.advance
void advance(float amount)
Definition
TriggerFleetTravelAssignmentAI.java:157
com.fs.starfarer.api.impl.campaign.missions.hub.TriggerFleetTravelAssignmentAI.runWhilePaused
boolean runWhilePaused()
Definition
TriggerFleetTravelAssignmentAI.java:165
com.fs.starfarer.api.impl.campaign.missions.hub.TriggerFleetTravelAssignmentAI.isDone
boolean isDone()
Definition
TriggerFleetTravelAssignmentAI.java:161
com.fs.starfarer.api.EveryFrameScript
Definition
EveryFrameScript.java:3
src
com
fs
starfarer
api
impl
campaign
missions
hub
TriggerFleetTravelAssignmentAI.java
Generated by
1.9.8