Starsector API
Loading...
Searching...
No Matches
GBLeadPlayerTo.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.campaign.SectorEntityToken;
8import com.fs.starfarer.api.util.Misc;
9
10
11public class GBLeadPlayerTo extends BaseGhostBehavior {
12
13 protected SectorEntityToken to;
14 protected int maxBurn;
15 protected float maxDistAhead;
16 protected boolean returningToPlayer = false;
17
18 public GBLeadPlayerTo(float duration, SectorEntityToken to, float maxDistAhead, int maxBurn) {
19 super(duration);
20 this.to = to;
21 this.maxDistAhead = maxDistAhead;
22 this.maxBurn = maxBurn;
23 }
24
25
26
27 @Override
28 public void advance(float amount, SensorGhost ghost) {
29 CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
30 if (pf.getContainingLocation() != ghost.getEntity().getContainingLocation() || !pf.isAlive()) {
31 end();
32 return;
33 }
34 super.advance(amount, ghost);
35
36
37 float goBackThreshold = maxDistAhead * 2f;
39 goBackThreshold = maxDistAhead * 1.5f;
40 }
41 Vector2f dir = Misc.getUnitVector(pf.getLocation(), to.getLocation());
42 Vector2f diff = Vector2f.sub(ghost.getEntity().getLocation(), pf.getLocation(), new Vector2f());
43
44 float distAheadOfPlayer = Vector2f.dot(dir, diff);
45 float distFromPlayer = Misc.getDistance(pf, ghost.getEntity());
46 if (distFromPlayer >= goBackThreshold) {
47 ghost.moveTo(pf.getLocation(), pf.getVelocity(), maxBurn);
48 returningToPlayer = true;
49 } else if (distAheadOfPlayer > maxDistAhead) {
50 int burn = (int) (maxBurn * maxDistAhead / distAheadOfPlayer * 0.5f);
51 ghost.moveTo(to.getLocation(), new Vector2f(), burn);
52 returningToPlayer = false;
53 } else {
54 ghost.moveTo(to.getLocation(), new Vector2f(), maxBurn);
55 returningToPlayer = false;
56 }
57
58
59
60 float dist = Misc.getDistance(ghost.getEntity(), to);
61 if (dist < ghost.getEntity().getRadius() + to.getRadius()) {
62 end();
63 return;
64 }
65
66 }
67
68
69
70}
71
72
73
74
75
76
77
78
79
80
81
82
83
static SectorAPI getSector()
Definition Global.java:59
GBLeadPlayerTo(float duration, SectorEntityToken to, float maxDistAhead, int maxBurn)
void moveTo(Vector2f dest, float maxBurn)