Starsector API
Loading...
Searching...
No Matches
TenebrousExpulsionSystemAI.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat.dweller;
2
3import org.lwjgl.util.vector.Vector2f;
4
5import com.fs.starfarer.api.combat.CombatEngineAPI;
6import com.fs.starfarer.api.combat.ShipAPI;
7import com.fs.starfarer.api.combat.ShipCommand;
8import com.fs.starfarer.api.combat.ShipSystemAIScript;
9import com.fs.starfarer.api.combat.ShipSystemAPI;
10import com.fs.starfarer.api.combat.ShipwideAIFlags;
11import com.fs.starfarer.api.combat.ShipwideAIFlags.AIFlags;
12import com.fs.starfarer.api.util.IntervalUtil;
13import com.fs.starfarer.api.util.Misc;
14
15
17
18 public static float HULL_LOSS_FOR_ACTIVATION = 0.25f;
19
20 protected ShipAPI ship;
25
26 protected IntervalUtil tracker = new IntervalUtil(0.75f, 1.25f);
27
28 protected float hullLevelAtPrevSystemUse = 1f;
29 protected float prevHardFluxLevel = 0f;
30
32 this.ship = ship;
33 this.flags = flags;
34 this.engine = engine;
35 this.system = system;
36
38 }
39
40 public void advance(float amount, Vector2f missileDangerDir, Vector2f collisionDangerDir, ShipAPI target) {
41 if (ship == null) return;
42
43 tracker.advance(amount);
44
45 boolean forceUse = false;
46 if (ship.getFluxLevel() > 0.95f && ship.getHullLevel() > 0.25f &&
47 ship.getShield() != null && ship.getShield().isOn()) {
48 forceUse = true;
49 }
50
51 if (tracker.intervalElapsed() || forceUse) {
52 if (system.getCooldownRemaining() > 0) return;
53 if (system.isOutOfAmmo()) return;
54 if (system.isActive()) return;
56
57 float hullLevel = ship.getHullLevel();
58 float hardFluxLevel = ship.getHardFluxLevel();
59 float fluxLevel = ship.getFluxLevel();
60
61 boolean useSystem = hullLevel <= hullLevelAtPrevSystemUse - HULL_LOSS_FOR_ACTIVATION;
62
63 if (((hardFluxLevel >= prevHardFluxLevel && hardFluxLevel >= 0.33f) || fluxLevel > 0.65f) &&
64 ship.getAIFlags().hasFlag(AIFlags.BACKING_OFF)) {// && (float) Math.random() > 0.75f) {
65 if (target != null) {
66 float dist = Misc.getDistance(ship.getLocation(), target.getLocation());
67 dist -= ship.getCollisionRadius() + target.getCollisionRadius();
68 if (dist < 1000f || hardFluxLevel > prevHardFluxLevel + 0.02f) {
69 useSystem = true;
70 }
71 }
72 }
73
74 prevHardFluxLevel = hardFluxLevel;
75
76 useSystem |= forceUse;
77
78 if (useSystem) {
79 float angle = ship.getFacing();
80 if (target != null) {
82 }
83 if (missileDangerDir != null) {
84 float angle2 = Misc.getAngleInDegrees(missileDangerDir);
85 if (target != null) {
86 angle = angle + Misc.getClosestTurnDirection(angle, angle2) * 0.5f * Misc.getAngleDiff(angle, angle2);
87 } else {
88 angle = angle2;
89 }
90 }
91
92 Vector2f point = Misc.getUnitVectorAtDegreeAngle(angle);
93 point.scale(2000f);
94 Vector2f.add(point, ship.getLocation(), point);
95
96 giveCommand(point);
97 hullLevelAtPrevSystemUse = hullLevel;
98 return;
99 }
100 }
101 }
102
103 public void giveCommand(Vector2f target) {
104 if (ship.getAIFlags() != null) {
105 ship.getAIFlags().setFlag(AIFlags.SYSTEM_TARGET_COORDS, 1f, target);
106 }
108 }
109
110}
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
void advance(float amount, Vector2f missileDangerDir, Vector2f collisionDangerDir, ShipAPI target)
void init(ShipAPI ship, ShipSystemAPI system, ShipwideAIFlags flags, CombatEngineAPI engine)
static Vector2f getUnitVectorAtDegreeAngle(float degrees)
Definition Misc.java:1196
static float getAngleDiff(float from, float to)
Definition Misc.java:1716
static float getDistance(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:599
static float getClosestTurnDirection(float facing, float desired)
Definition Misc.java:2102
static float getAngleInDegrees(Vector2f v)
Definition Misc.java:1126
void giveCommand(ShipCommand command, Object param, int groupNumber)