1package com.fs.starfarer.api.impl.campaign.fleets;
3import java.util.Random;
5import org.lwjgl.util.vector.Vector2f;
7import com.fs.starfarer.api.EveryFrameScript;
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.campaign.FleetAssignment;
11import com.fs.starfarer.api.campaign.LocationAPI;
12import com.fs.starfarer.api.campaign.PlanetAPI;
13import com.fs.starfarer.api.campaign.SectorEntityToken;
14import com.fs.starfarer.api.campaign.StarSystemAPI;
15import com.fs.starfarer.api.campaign.econ.MarketAPI;
16import com.fs.starfarer.api.util.Misc;
17import com.fs.starfarer.api.util.WeightedRandomPicker;
22 protected CampaignFleetAPI
fleet;
36 boolean playerInSameLocation =
fleet.getContainingLocation() ==
Global.
getSector().getCurrentLocation();
38 SectorEntityToken target =
null;
39 if (!playerInSameLocation && !
fleet.isInHyperspace()) {
42 Vector2f loc = Misc.getPointAtRadius(target.getLocation(), target.getRadius() + 100f);
43 fleet.setLocation(loc.x, loc.y);
45 Vector2f loc = Misc.getPointAtRadius(
new Vector2f(), 5000f);
46 fleet.setLocation(loc.x, loc.y);
48 }
else if (
fleet.isInHyperspace()) {
49 SectorEntityToken from = Misc.getSourceEntity(
fleet);
50 if (from !=
null &&
system !=
null) {
51 float angle = Misc.getAngleInDegrees(
system.getLocation(), from.getLocationInHyperspace());
53 angle = angle - arc / 2f + arc * (float) Math.random();
56 Vector2f loc = Misc.getUnitVectorAtDegreeAngle(angle);
58 Vector2f.add(loc,
system.getLocation(), loc);
62 fleet.setLocation(loc.x, loc.y);
65 fleet.setLocation(loc.x, loc.y);
69 Vector2f loc =
new Vector2f(5000, 0);
71 Vector2f from = target.getLocation();
72 loc = Misc.pickLocationNotNearPlayer(
system, from,
75 loc = Misc.pickLocationNotNearPlayer(
system,
76 Misc.getPointAtRadius(
new Vector2f(0, 0), 8000),
79 fleet.setLocation(loc.x, loc.y);
84 protected void pickNext(SectorEntityToken target,
float probStayInHyper) {
85 if (
fleet.isInHyperspace()) {
86 Vector2f dest = Misc.getPointAtRadius(
system.getLocation(), 1000);
88 SectorEntityToken token = hyper.createToken(dest.x, dest.y);
89 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION, token, 1000,
93 if (
fleet.isInHyperspace() && (
float) Math.random() < probStayInHyper) {
94 fleet.addAssignment(FleetAssignment.RAID_SYSTEM,
system.getHyperspaceAnchor(), 10000,
99 float speed = Misc.getSpeedForBurnLevel(8);
100 float dist = Misc.getDistance(
fleet.getLocation(), target.getLocation());
101 float seconds = dist / speed;
102 float days = seconds /
Global.
getSector().getClock().getSecondsPerDay();
103 days += 30f + 10f * (float) Math.random();
104 fleet.addAssignment(FleetAssignment.PATROL_SYSTEM, target, days,
108 float days = 5f + 5f * (float) Math.random();
109 fleet.addAssignment(FleetAssignment.PATROL_SYSTEM,
null, days,
116 if (
fleet.getCurrentAssignment() ==
null) {
130 WeightedRandomPicker<SectorEntityToken> picker =
new WeightedRandomPicker<SectorEntityToken>(random);
132 for (SectorEntityToken entity :
system.getJumpPoints()) {
134 picker.add(entity, 5f * mult);
138 for (PlanetAPI planet :
system.getPlanets()) {
139 if (planet.isGasGiant()) {
141 picker.add(planet, 5f * mult);
146 if (market.getFaction() !=
fleet.getFaction())
continue;
149 picker.add(market.getPrimaryEntity(), 5f * mult);
152 return picker.pick();
157 return 1f / (count * 10f + 1f);
162 for (CampaignFleetAPI other :
system.getFleets()) {
163 float dist = Misc.getDistance(other, entity);
164 if (dist > 3000)
continue;
166 if (!Misc.isPatrol(other))
continue;
168 if (
fleet.isHostileTo(other)) {
static SettingsAPI getSettings()
static SectorAPI getSector()
static float countNearbyPatrols(StarSystemAPI system, CampaignFleetAPI fleet, SectorEntityToken entity)
void pickNext(SectorEntityToken target, float probStayInHyper)
static SectorEntityToken pickEntityToGuard(Random random, StarSystemAPI system, CampaignFleetAPI fleet)
DisposableFleetManager manager
void advance(float amount)
void giveInitialAssignments(float probStayInHyper)
DisposableAggroAssignmentAI(CampaignFleetAPI fleet, StarSystemAPI system, DisposableFleetManager manager, float probStayInHyper)
static float getWeightMultForPatrols(StarSystemAPI system, CampaignFleetAPI fleet, SectorEntityToken entity)
String getActionOutsideText(StarSystemAPI system, CampaignFleetAPI fleet)
String getActionInsideText(StarSystemAPI system, CampaignFleetAPI fleet)
String getTravelText(StarSystemAPI system, CampaignFleetAPI fleet)
int getMaxSensorRangeHyper()