Starsector API
Loading...
Searching...
No Matches
GBEchoMovement.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.ghosts;
2
3import java.util.ArrayList;
4import java.util.Iterator;
5import java.util.List;
6
7import org.lwjgl.util.vector.Vector2f;
8
9import com.fs.starfarer.api.Global;
10import com.fs.starfarer.api.campaign.SectorEntityToken;
11
12
13public class GBEchoMovement extends BaseGhostBehavior {
14
15 public static class GBEchoSnapshot {
16 Vector2f vel;
17 long timestamp;
18 }
19
20 protected List<GBEchoSnapshot> snapshots = new ArrayList<GBEchoSnapshot>();
21 protected SectorEntityToken other;
22 protected float delayDays;
23
24
25 public GBEchoMovement(SectorEntityToken other, float delayDays, float duration) {
26 super(duration);
27 this.other = other;
28 this.delayDays = delayDays;
29 }
30
31 @Override
32 public void advance(float amount, SensorGhost ghost) {
33 if (other.getContainingLocation() != ghost.getEntity().getContainingLocation() || !other.isAlive()) {
34 end();
35 return;
36 }
37
38 super.advance(amount, ghost);
39
40 GBEchoSnapshot curr = new GBEchoSnapshot();
41 curr.vel = new Vector2f(other.getVelocity());
42 curr.timestamp = Global.getSector().getClock().getTimestamp();
43 snapshots.add(curr);
44
45 Iterator<GBEchoSnapshot> iter = snapshots.iterator();
46 GBEchoSnapshot use = null;
47 while (iter.hasNext()) {
48 curr = iter.next();
49 float ago = Global.getSector().getClock().getElapsedDaysSince(curr.timestamp);
50 if (ago >= delayDays) {
51 use = curr;
52 iter.remove();
53 } else {
54 break;
55 }
56 }
57
58 if (use != null) {
59 ghost.getMovement().getVelocity().set(use.vel);
60 }
61 }
62
63
64
65}
66
67
68
69
70
71
72
73
74
static SectorAPI getSector()
Definition Global.java:59
GBEchoMovement(SectorEntityToken other, float delayDays, float duration)