Starsector API
Loading...
Searching...
No Matches
GBFollowClosely.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.campaign.SectorEntityToken;
6import com.fs.starfarer.api.util.IntervalUtil;
7import com.fs.starfarer.api.util.Misc;
8
9
10public class GBFollowClosely extends BaseGhostBehavior {
11
12 protected SectorEntityToken other;
13 protected int maxBurn;
14 protected float desiredRangeMin;
15 protected float desiredRangeMax;
16 protected IntervalUtil interval = new IntervalUtil(5f, 10f);
17 protected float angleOffset = 0f;
18
19 public GBFollowClosely(SectorEntityToken other, float duration, int maxBurn, float desiredRangeMin, float desiredRangeMax) {
20 super(duration);
21 this.other = other;
22 this.maxBurn = maxBurn;
23 this.desiredRangeMin = desiredRangeMin;
24 this.desiredRangeMax = desiredRangeMax;
25 interval.forceIntervalElapsed();
26 }
27
28 @Override
29 public void advance(float amount, SensorGhost ghost) {
30 if (other.getContainingLocation() != ghost.getEntity().getContainingLocation() || !other.isAlive()) {
31 end();
32 return;
33 }
34 super.advance(amount, ghost);
35
36 interval.advance(amount * 1f);
37 if (interval.intervalElapsed()) {
38 angleOffset = 60f - Misc.random.nextFloat() * 120f;
39 }
40
41 float dist = Misc.getDistance(ghost.getEntity(), other);
42 dist -= other.getRadius() + ghost.getEntity().getRadius();
43 if (dist > desiredRangeMax) {
44 ghost.moveTo(other.getLocation(), new Vector2f(), maxBurn);
45 } else if (dist < desiredRangeMin) {
46 float angle = Misc.getAngleInDegrees(other.getLocation(), ghost.getEntity().getLocation());
47 angle += angleOffset;
48 Vector2f dest = Misc.getUnitVectorAtDegreeAngle(angle);
49 dest.scale(desiredRangeMin + (desiredRangeMax - desiredRangeMin) * 0.5f);
50 Vector2f.add(other.getLocation(), dest, dest);
51 ghost.moveTo(dest, new Vector2f(), maxBurn);
52 } else if (other.getVelocity().length() > 10f) {
53 int burn = (int) Misc.getBurnLevelForSpeed(other.getVelocity().length());
54 if (burn < 1) burn = 1;
55 Vector2f dest = Misc.getUnitVectorAtDegreeAngle(Misc.getAngleInDegrees(other.getVelocity()) + angleOffset);
56 dest.negate();
57 dest.scale(desiredRangeMin + (desiredRangeMax - desiredRangeMin) * 0.5f);
58 Vector2f.add(other.getLocation(), dest, dest);
59 ghost.moveTo(dest, new Vector2f(), burn);
60 }
61 }
62}
63
64
65
66
67
68
69
70
71
72
73
74
75
GBFollowClosely(SectorEntityToken other, float duration, int maxBurn, float desiredRangeMin, float desiredRangeMax)
void moveTo(Vector2f dest, float maxBurn)