Starsector API
Loading...
Searching...
No Matches
GBCircle.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.Misc;
7
8
9public class GBCircle extends BaseGhostBehavior {
10
11 protected SectorEntityToken other;
12 protected int maxBurn;
13 protected float desiredRange;
14 protected float circleDir;
15
16 public GBCircle(SectorEntityToken other, float duration, int maxBurn, float desiredRange, float circleDir) {
17 super(duration);
18 this.other = other;
19 this.maxBurn = maxBurn;
20 this.desiredRange = desiredRange;
21 this.circleDir = circleDir;
22 }
23
24 @Override
25 public void advance(float amount, SensorGhost ghost) {
26 if (other.getContainingLocation() != ghost.getEntity().getContainingLocation() || !other.isAlive()) {
27 end();
28 return;
29 }
30 super.advance(amount, ghost);
31
32 float dist = Misc.getDistance(ghost.getEntity(), other) - ghost.getEntity().getRadius() - other.getRadius();
33
34 float dirToOther = Misc.getAngleInDegrees(ghost.getEntity().getLocation(), other.getLocation());
35 //Vector2f toOther = Misc.getUnitVectorAtDegreeAngle(dirToOther);
36
37 float clockwiseDir = dirToOther + 90f;
38
39 float bandRadius = desiredRange * 0.25f;
40 float distOffset = (dist - desiredRange);
41 if (distOffset > bandRadius) distOffset = bandRadius;
42 if (distOffset < -bandRadius) distOffset = -bandRadius;
43
44 float angleOffset = distOffset / bandRadius * -60f;
45 //if (angleOffset > 30f) angleOffset = 30f;
46
47
48 float useCircleDir = circleDir;
49 if (Misc.isReversePolarity(other)) {
50 useCircleDir = -useCircleDir;
51 }
52 if (useCircleDir == 0f) {
53 float velDir = Misc.getAngleInDegrees(ghost.getEntity().getVelocity());
54 float angleDiffCW = Misc.getAngleDiff(dirToOther + 90f, velDir);
55 float angleDiffCCW = Misc.getAngleDiff(dirToOther - 90f, velDir);
56 if (angleDiffCW > angleDiffCCW) {
57 useCircleDir = 1f;
58 } else {
59 useCircleDir = -1f;
60 }
61 }
62
63
64 float moveDir = clockwiseDir;
65 if (useCircleDir > 0) {
66 moveDir += 180f;
67 angleOffset = -angleOffset;
68 }
69
70 moveDir += angleOffset;
71 moveDir = Misc.normalizeAngle(moveDir);
72
73 Vector2f dest = Misc.getUnitVectorAtDegreeAngle(moveDir);
74 dest.scale(10000f);
75 Vector2f.add(dest, ghost.getEntity().getLocation(), dest);
76
77 ghost.moveTo(dest, maxBurn);
78 }
79
80}
81
82
83
84
85
86
87
88
89
90
91
92
93
void advance(float amount, SensorGhost ghost)
Definition GBCircle.java:25
GBCircle(SectorEntityToken other, float duration, int maxBurn, float desiredRange, float circleDir)
Definition GBCircle.java:16
void moveTo(Vector2f dest, float maxBurn)