Starsector API
Loading...
Searching...
No Matches
DarkenedGazeSystemAI.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.Global;
6import com.fs.starfarer.api.combat.CombatEngineAPI;
7import com.fs.starfarer.api.combat.ShipAIPlugin;
8import com.fs.starfarer.api.combat.ShipAPI;
9import com.fs.starfarer.api.combat.ShipCommand;
10import com.fs.starfarer.api.combat.ShipSystemAIScript;
11import com.fs.starfarer.api.combat.ShipSystemAPI;
12import com.fs.starfarer.api.combat.ShipwideAIFlags;
13import com.fs.starfarer.api.combat.ShipwideAIFlags.AIFlags;
14import com.fs.starfarer.api.util.IntervalUtil;
15import com.fs.starfarer.api.util.Misc;
16
17
19
20 protected ShipAPI ship;
25 protected float systemFluxPerSecond;
26
27 protected IntervalUtil tracker = new IntervalUtil(0.75f, 1.25f);
28
30 this.ship = ship;
31 this.flags = flags;
32 this.engine = engine;
33 this.system = system;
34
36
38 }
39
40 protected ShipAPI targetOverride = null;
41
42 public void advance(float amount, Vector2f missileDangerDir, Vector2f collisionDangerDir, ShipAPI target) {
43 tracker.advance(amount);
44
45 //boolean toggle = system.getSpec().isToggle();
46
47 if (system.isActive()) {
48 if (ship.getAI() instanceof ShipAIPlugin) {
50 b.setTargetOverride(targetOverride); // needs to be set every frame
51 }
52 } else {
53 targetOverride = null;
54 }
55
56 if (tracker.intervalElapsed()) {
57
58 if (system.getCooldownRemaining() > 0) return;
59 if (system.isOutOfAmmo()) return;
61
62 if (target != null) {
63 if (target.isHulk() || !target.isAlive()) {
64 target = null;
65 }
66 }
67
68 float activeTimeRemaining = (ship.getMaxFlux() - ship.getCurrFlux()) / Math.max(1f, systemFluxPerSecond);
69
70 boolean missilesInOpenArc = false;
71 // too easy to shut it down with missiles
72 if (missileDangerDir != null && false) {
74 Misc.getAngleInDegrees(missileDangerDir));
75 }
76
77 boolean inRange = false;
78 boolean inArc = false;
79 boolean isFarFromArc = false;
80 if (target != null) {
81 float range = Misc.getDistance(ship.getLocation(), target.getLocation()) -
82 Misc.getTargetingRadius(ship.getLocation(), target, false);
83 inRange = range < script.getRange();
84 inArc = Misc.isInArc(ship.getFacing(), 5f,
86 if (!inArc) {
87 isFarFromArc = !Misc.isInArc(ship.getFacing(), Math.max(30f, 60f - range * 0.05f),
89 }
90 }
91
93 to.scale(script.getRange());
94 Vector2f.add(ship.getLocation(), to, to);
95 boolean ffDanger = false;
96 if (script.isFFAConcern() ) {
97 ffDanger = Global.getSettings().getFriendlyFireDanger(ship, null,
98 ship.getLocation(), to, Float.MAX_VALUE, 3f, script.getRange()) > 0.1f;
99 } else {
100 // pretend FF concern, so it doesn't fire right through friendlies but can clip them without
101 // worrying too much about it
102 ffDanger = Global.getSettings().getFriendlyFireDanger(ship, null,
103 ship.getLocation(), to, Float.MAX_VALUE, 3f, script.getRange()) > 0.5f;
104 }
105 if (system.isActive()) {
106 flags.setFlag(AIFlags.DO_NOT_VENT);
107
108 if (target == null || !inRange || isFarFromArc || missilesInOpenArc || ffDanger) {
109 giveCommand();
110 return;
111 }
112
113 if (activeTimeRemaining < 3f) {
114 giveCommand();
115 return;
116 }
117
118 return;
119 }
120
121 float minFireTime = system.getSpecAPI().getIn() + 6f;
122 float fluxLevel = ship.getFluxLevel();
123
124 if (fluxLevel > 0.9f || activeTimeRemaining < minFireTime) {
125 return;
126 }
127
128 if (inRange && inArc && !missilesInOpenArc && !ffDanger) {
129 giveCommand();
130 targetOverride = target;
131 }
132 }
133 }
134
135
136 public void giveCommand() {
138 }
139
140}
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
static SettingsAPI getSettings()
Definition Global.java:57
void init(ShipAPI ship, ShipSystemAPI system, ShipwideAIFlags flags, CombatEngineAPI engine)
void advance(float amount, Vector2f missileDangerDir, Vector2f collisionDangerDir, ShipAPI target)
static Vector2f getUnitVectorAtDegreeAngle(float degrees)
Definition Misc.java:1196
static float getDistance(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:599
static float getTargetingRadius(Vector2f from, CombatEntityAPI target, boolean considerShield)
Definition Misc.java:1349
static boolean isInArc(float direction, float arc, Vector2f from, Vector2f to)
Definition Misc.java:1722
static float getAngleInDegrees(Vector2f v)
Definition Misc.java:1126
float getFriendlyFireDanger(ShipAPI shooter, CombatEntityAPI target, Vector2f from, Vector2f to, float weaponSpeed, float burstFireDuration, float weaponRange)
default void setTargetOverride(ShipAPI target)
void giveCommand(ShipCommand command, Object param, int groupNumber)