Starsector API
Loading...
Searching...
No Matches
GBFollowStream.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.ghosts;
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.impl.campaign.velfield.SlipstreamTerrainPlugin2;
8import com.fs.starfarer.api.util.Misc;
9
10
11public class GBFollowStream extends BaseGhostBehavior {
12
13 protected int maxBurn;
14 protected SlipstreamTerrainPlugin2 plugin;
15 protected float phase = 0f;
16 protected float preferredYOff = -100f;
17 protected boolean courseCorrecting = false;
18
19 public GBFollowStream(float duration, int maxBurn, SlipstreamTerrainPlugin2 plugin) {
20 super(duration);
21 this.maxBurn = maxBurn;
22 this.plugin = plugin;
23
24 phase = Misc.random.nextFloat();
25 }
26
27 @Override
28 public void advance(float amount, SensorGhost ghost) {
29 if (!ghost.getEntity().isInCurrentLocation()) {
30 end();
31 return;
32 }
33 super.advance(amount, ghost);
34
35 float [] coords = plugin.getLengthAndWidthFractionWithinStream(ghost.getEntity().getLocation());
36 if (coords == null) {
37 end();
38 return;
39 }
40 float distAlong = coords[0];
41 float yOff = coords[1];
42 if (preferredYOff < -10f) preferredYOff = yOff;
43 float yOffDest = preferredYOff;
44 boolean closeToPreferred = Math.abs(yOff - preferredYOff) < 0.25f;
45 boolean veryCloseToPreferred = Math.abs(yOff - preferredYOff) < 0.05f;
46 if (!closeToPreferred) {
47 courseCorrecting = true;
48 }
49 if (veryCloseToPreferred) {
50 courseCorrecting = false;
51 }
52 if (!courseCorrecting) {
53 yOffDest = yOff;
54 }
55 Vector2f p1 = plugin.getPointAt(distAlong, yOff);
56
57 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
58 //pf = null;
59 float dist = Float.MAX_VALUE;
60 if (pf != null) {
61 dist = Misc.getDistance(ghost.getEntity(), pf);
62 }
63 if (pf != null && dist < 500f) {
64 float angleDiff = Misc.getAngleDiff(Misc.getAngleInDegrees(ghost.getEntity().getVelocity()),
65 Misc.getAngleInDegrees(ghost.getEntity().getLocation(), pf.getLocation()));
66 coords = plugin.getLengthAndWidthFractionWithinStream(pf.getLocation());
67 if (coords != null && angleDiff < 90f) {
68 float yOffPlayer = coords[1];
69 float test1 = yOffPlayer - 0.4f;
70 float test2 = yOffPlayer + 0.4f;
71 if (Math.abs(test1) > 0.67f) test1 = Math.signum(test1) * 0.67f;
72 if (Math.abs(test2) > 0.67f) test2 = Math.signum(test2) * 0.67f;
73 float diff1 = Math.abs(test1 - yOff);
74 float diff2 = Math.abs(test2 - yOff);
75// float diff1 = Math.abs(test1);
76// float diff2 = Math.abs(test2);
77 float diff3 = Math.abs(yOff - yOffPlayer);
78 if (diff3 < 0.4f) {
79 if (diff1 < diff2) {
80 yOffDest = test1;
81 } else {
82 yOffDest = test2;
83 }
84 }
85 }
86 }
87
88 Vector2f p2 = plugin.getPointAt(distAlong + 200f, yOffDest);
89 if (p1 == null || p2 == null) {
90 end();
91 return;
92 }
93 Vector2f dest = Misc.getUnitVectorAtDegreeAngle(Misc.getAngleInDegrees(p1, p2));
94
95 dest.scale(1000f);
96 Vector2f.add(dest, ghost.getEntity().getLocation(), dest);
97
98 ghost.moveTo(dest, new Vector2f(), maxBurn);
99 }
100
101
102
103}
104
105
106
107
108
109
110
111
112
113
114
115
116
static SectorAPI getSector()
Definition Global.java:59
GBFollowStream(float duration, int maxBurn, SlipstreamTerrainPlugin2 plugin)
void moveTo(Vector2f dest, float maxBurn)