Starsector API
Loading...
Searching...
No Matches
GBLeviathanCalfRun.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.CustomCampaignEntityAPI;
8import com.fs.starfarer.api.campaign.SectorEntityToken;
9import com.fs.starfarer.api.characters.AbilityPlugin;
10import com.fs.starfarer.api.impl.campaign.ghosts.GBIGenerateSlipstream.GhostBehaviorWithSlipstream;
11import com.fs.starfarer.api.impl.campaign.ids.Abilities;
12import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
13import com.fs.starfarer.api.impl.campaign.velfield.SlipstreamTerrainPlugin2;
14import com.fs.starfarer.api.util.Misc;
15
16
17public class GBLeviathanCalfRun extends BaseGhostBehavior implements GhostBehaviorWithSlipstream {
18
19 public static float SENSOR_BURST_TURN_RATE = 30f;
20 public static float PULSE_BURN_BONUS = 10;
21 public static float PULSE_BURN_BONUS_DECAY = 0.25f;
22
23 protected boolean dirSet = false;
24 protected float dir;
25 protected float burnBonus;
26 protected int origPluginBurn;
27 protected SectorEntityToken from;
28 protected float phase = (float) Math.random();
29 protected int maxBurn;
30 protected SlipstreamTerrainPlugin2 plugin;
31 protected boolean affectedByPulse = false;
32 protected float wobbleRate;
33 protected float maxWobble;
34
35 public GBLeviathanCalfRun(float duration, SectorEntityToken from, float wobbleRate, float maxWobble,
36 int maxBurn, boolean affectedByPulse) {
37 super(duration);
38 this.from = from;
39 this.wobbleRate = wobbleRate;
40 this.maxWobble = maxWobble;
41 this.maxBurn = maxBurn;
42 this.affectedByPulse = affectedByPulse;
43 }
44
45
46
47 @Override
48 public void advance(float amount, SensorGhost ghost) {
49 if (from.getContainingLocation() != ghost.getEntity().getContainingLocation() ||
50 ghost.getEntity().getContainingLocation() == null || !from.isAlive()) {
51 end();
52 return;
53 }
54 super.advance(amount, ghost);
55
56 if (!dirSet || ghost.getEntity().getVelocity().length() < 10f) {
57 dir = Misc.getAngleInDegrees(from.getLocation(), ghost.getEntity().getLocation());
58 dirSet = true;
59 } else {
60 //dir = Misc.getAngleInDegrees(ghost.getEntity().getVelocity());
61 }
62
63 float pi = (float) Math.PI;
64 float sin = (float) Math.sin(phase * pi * 2f);
65 phase += amount * wobbleRate;
66
67 float maxAngleOffset = maxWobble;
68 float angle = dir + sin * maxAngleOffset;
69
70// float maxSteeringOffset = 30f;
71// maxSteeringOffset = 0f;
72// if (maxSteeringOffset > 0f && plugin != null && plugin.containsEntity(from)) {
73// float [] coords = plugin.getLengthAndWidthFractionWithinStream(from.getLocation());
74// if (coords != null) {
75// float dist = Misc.getDistance(ghost.getEntity(), from);
76// if (dist < 2000f) {
77// float mag = (1f - Math.max(0f, dist - 1000f) / 1000f) *
78// Math.signum(coords[1]) * Math.max(0f, Math.abs(coords[1]) - 0.3f) *
79// maxSteeringOffset;
80// angle += mag;
81// }
82// }
83// }
84
85 if (affectedByPulse) {
87 }
88 //checkSensorBursts(ghost, amount);
89
90 int useBonus = 0;
91 if (plugin != null) {
93 if (burnBonus < 0) burnBonus = 0;
94
95 useBonus = (int) burnBonus;
96 plugin.getParams().burnLevel = origPluginBurn + useBonus;
97 }
98
99 Vector2f loc = Misc.getUnitVectorAtDegreeAngle(angle);
100 loc.scale(10000f);
101 Vector2f.add(loc, ghost.getEntity().getLocation(), loc);
102 ghost.moveTo(loc, maxBurn + useBonus);
103
104 }
105
107 if (!Global.getSector().getMemoryWithoutUpdate().getBoolean(MemFlags.GLOBAL_INTERDICTION_PULSE_JUST_USED_IN_CURRENT_LOCATION)) {
108 return;
109 }
110 CustomCampaignEntityAPI entity = ghost.getEntity();
111 if (entity == null || entity.getContainingLocation() == null || plugin == null) return;
112 for (CampaignFleetAPI fleet : entity.getContainingLocation().getFleets()) {
113// float range = InterdictionPulseAbility.getRange(fleet);
114// float dist = Misc.getDistance(fleet.getLocation(), entity.getLocation());
115// if (dist > range) continue;
116 // anywhere inside the stream is fine, actually
117 if (!plugin.containsEntity(fleet)) continue;
118
119 if (fleet.getMemoryWithoutUpdate().getBoolean(MemFlags.JUST_DID_INTERDICTION_PULSE)) {
121 if (fleet.isPlayerFleet()) {
122 String key = "$leviathanCalvesPulsed";
123 int count = Global.getSector().getMemoryWithoutUpdate().getInt(key);
124 Global.getSector().getMemoryWithoutUpdate().set(key, count + 1);
125 }
126 return;
127 }
128 }
129 }
130 public void checkSensorBursts(SensorGhost ghost, float amount) {
131 CustomCampaignEntityAPI entity = ghost.getEntity();
132 if (entity == null || entity.getContainingLocation() == null || plugin == null) return;
133 for (CampaignFleetAPI fleet : entity.getContainingLocation().getFleets()) {
134 // anywhere inside the stream is fine, actually
135 if (!plugin.containsEntity(fleet)) continue;
136
137 AbilityPlugin asb = fleet.getAbility(Abilities.SENSOR_BURST);
138 if (asb.isInProgress()) {// && asb.getLevel() == 1f) {
139 float [] coords = plugin.getLengthAndWidthFractionWithinStream(fleet.getLocation());
140 if (coords != null) {
141 dir += coords[1] * SENSOR_BURST_TURN_RATE * amount;
142 ((BaseSensorGhost)ghost).setAccelMult(1f);
143 }
144// float velDir = Misc.getAngleInDegrees(entity.getVelocity());
145// float toFleet = Misc.getAngleInDegrees(entity.getLocation(), fleet.getLocation());
146// float turnDir = Misc.getClosestTurnDirection(toFleet, velDir);
147// dir += turnDir * SENSOR_BURST_TURN_RATE * amount;
148 }
149 }
150 }
151
152
153 public void setSlipstream(SlipstreamTerrainPlugin2 plugin) {
154 this.plugin = plugin;
155 origPluginBurn = plugin.getParams().burnLevel;
156 }
157
158
159
160}
161
162
163
164
165
166
167
168
169
170
171
172
173
static SectorAPI getSector()
Definition Global.java:59
GBLeviathanCalfRun(float duration, SectorEntityToken from, float wobbleRate, float maxWobble, int maxBurn, boolean affectedByPulse)
void moveTo(Vector2f dest, float maxBurn)