Starsector API
Loading...
Searching...
No Matches
DistressCallPirateAmbushTrapAssignmentAI.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.events.nearby;
2
3import org.lwjgl.util.vector.Vector2f;
4
5import com.fs.starfarer.api.Global;
6import com.fs.starfarer.api.campaign.CampaignFleetAPI;
7import com.fs.starfarer.api.campaign.FleetAssignment;
8import com.fs.starfarer.api.campaign.SectorEntityToken;
9import com.fs.starfarer.api.campaign.StarSystemAPI;
10import com.fs.starfarer.api.impl.campaign.procgen.themes.BaseAssignmentAI;
11import com.fs.starfarer.api.util.Misc;
12
13public class DistressCallPirateAmbushTrapAssignmentAI extends BaseAssignmentAI {
14
15 protected StarSystemAPI system;
16 protected SectorEntityToken jumpPoint;
17
18 protected float elapsed = 0f;
19 protected float dur = 30f + (float) Math.random() * 20f;
20
21 public DistressCallPirateAmbushTrapAssignmentAI(CampaignFleetAPI fleet, StarSystemAPI system, SectorEntityToken jumpPoint) {
22 super();
23 this.fleet = fleet;
24 this.system = system;
25 this.jumpPoint = jumpPoint;
26
28 }
29
30 @Override
31 protected void giveInitialAssignments() {
32 pickNext();
33 }
34
35 @Override
36 protected void pickNext() {
37 float angle = Misc.getAngleInDegrees(system.getCenter().getLocation(), jumpPoint.getLocation());
38 float dist = Misc.getDistance(system.getCenter().getLocation(), jumpPoint.getLocation()) + 3000f;
39
40 angle += (float) Math.random() * 10f - 20f;
41 dist += (float) Math.random() * 500f;
42
43 Vector2f loc = Misc.getUnitVectorAtDegreeAngle(angle);
44 loc.scale(dist);
45 Vector2f.add(system.getCenter().getLocation(), loc, loc);
46
47 SectorEntityToken token = system.createToken(loc.x, loc.y);
48 fleet.addAssignment(FleetAssignment.ORBIT_AGGRESSIVE, token, 3f, "laying in wait");
49 }
50
51 @Override
52 public void advance(float amount) {
53 super.advance(amount);
54
55 float days = Global.getSector().getClock().convertToDays(amount);
56
57 elapsed += days;
58
59 if (elapsed >= dur) {
60 Misc.giveStandardReturnToSourceAssignments(fleet);
61 }
62 }
63
64}
65
66
67
68
69
70
71
72
73
74
75
76
static SectorAPI getSector()
Definition Global.java:59
DistressCallPirateAmbushTrapAssignmentAI(CampaignFleetAPI fleet, StarSystemAPI system, SectorEntityToken jumpPoint)