Starsector API
Loading...
Searching...
No Matches
RemnantAssignmentAI.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.procgen.themes;
2
3import java.util.Random;
4
5import org.lwjgl.util.vector.Vector2f;
6
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.SectorEntityToken;
12import com.fs.starfarer.api.campaign.StarSystemAPI;
13import com.fs.starfarer.api.util.Misc;
14
15public class RemnantAssignmentAI implements EveryFrameScript {
16
17 protected StarSystemAPI homeSystem;
18 protected CampaignFleetAPI fleet;
19 protected SectorEntityToken source;
20
21
22 public RemnantAssignmentAI(CampaignFleetAPI fleet, StarSystemAPI homeSystem, SectorEntityToken source) {
23 this.fleet = fleet;
24 this.homeSystem = homeSystem;
25 this.source = source;
26
28 }
29
30 protected void giveInitialAssignments() {
31 boolean playerInSameLocation = fleet.getContainingLocation() == Global.getSector().getCurrentLocation();
32
33 // launch from source if player is in-system, or sometimes
34 if ((playerInSameLocation || (float) Math.random() < 0.1f) && source != null) {
35 fleet.setLocation(source.getLocation().x, source.getLocation().y);
36 fleet.addAssignment(FleetAssignment.ORBIT_AGGRESSIVE, source, 3f + (float) Math.random() * 2f);
37 } else {
38 // start at random location
39 SectorEntityToken target = RemnantSeededFleetManager.pickEntityToGuard(new Random(), homeSystem, fleet);
40 if (target != null) {
41 Vector2f loc = Misc.getPointAtRadius(target.getLocation(), target.getRadius() + 100f);
42 fleet.setLocation(loc.x, loc.y);
43 } else {
44 Vector2f loc = Misc.getPointAtRadius(new Vector2f(), 5000f);
45 fleet.setLocation(loc.x, loc.y);
46 }
47 pickNext();
48 }
49 }
50
51 protected void pickNext() {
52 boolean standDown = source != null && (float) Math.random() < 0.2f;
53 if (!standDown) {
54 SectorEntityToken target = RemnantSeededFleetManager.pickEntityToGuard(new Random(), homeSystem, fleet);
55 if (target != null) {
56 float speed = Misc.getSpeedForBurnLevel(8);
57 float dist = Misc.getDistance(fleet.getLocation(), target.getLocation());
58 float seconds = dist / speed;
59 float days = seconds / Global.getSector().getClock().getSecondsPerDay();
60 days += 5f + 5f * (float) Math.random();
61 fleet.addAssignment(FleetAssignment.PATROL_SYSTEM, target, days, "patrolling");
62 return;
63 } else {
64 float days = 5f + 5f * (float) Math.random();
65 fleet.addAssignment(FleetAssignment.PATROL_SYSTEM, null, days, "patrolling");
66 }
67 }
68
69 if (source != null) {
70 float dist = Misc.getDistance(fleet.getLocation(), source.getLocation());
71 if (dist > 1000) {
72 fleet.addAssignment(FleetAssignment.PATROL_SYSTEM, source, 3f, "returning from patrol");
73 } else {
74 fleet.addAssignment(FleetAssignment.ORBIT_PASSIVE, source, 3f + (float) Math.random() * 2f, "standing down");
75 fleet.addAssignment(FleetAssignment.GO_TO_LOCATION_AND_DESPAWN, source, 5f);
76 }
77 }
78
79 }
80
81 public void advance(float amount) {
82 if (fleet.getCurrentAssignment() == null) {
83 pickNext();
84 }
85 }
86
87
88
89 public boolean isDone() {
90 return false;
91 }
92
93 public boolean runWhilePaused() {
94 return false;
95 }
96
97
98
99}
100
101
102
103
104
105
106
107
108
109
static SectorAPI getSector()
Definition Global.java:59
RemnantAssignmentAI(CampaignFleetAPI fleet, StarSystemAPI homeSystem, SectorEntityToken source)
static SectorEntityToken pickEntityToGuard(Random random, StarSystemAPI system, CampaignFleetAPI fleet)