Starsector API
Loading...
Searching...
No Matches
EnergyLashSystemAI.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat.threat;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import org.lwjgl.util.vector.Vector2f;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.combat.CombatEngineAPI;
10import com.fs.starfarer.api.combat.ShieldAPI;
11import com.fs.starfarer.api.combat.ShipAPI;
12import com.fs.starfarer.api.combat.ShipCommand;
13import com.fs.starfarer.api.combat.ShipSystemAIScript;
14import com.fs.starfarer.api.combat.ShipSystemAPI;
15import com.fs.starfarer.api.combat.ShipwideAIFlags;
16import com.fs.starfarer.api.combat.ShipwideAIFlags.AIFlags;
17import com.fs.starfarer.api.util.IntervalUtil;
18import com.fs.starfarer.api.util.Misc;
19import com.fs.starfarer.api.util.WeightedRandomPicker;
20
21
22public class EnergyLashSystemAI implements ShipSystemAIScript {
23
24 protected ShipAPI ship;
29
30 protected IntervalUtil tracker = new IntervalUtil(0.5f, 1f);
31
33 this.ship = ship;
34 this.flags = flags;
35 this.engine = engine;
36 this.system = system;
37
39 }
40
41 public void advance(float amount, Vector2f missileDangerDir, Vector2f collisionDangerDir, ShipAPI target) {
42 tracker.advance(amount);
43
44 if (tracker.intervalElapsed()) {
45 if (system.getCooldownRemaining() > 0) return;
46 if (system.isOutOfAmmo()) return;
47 if (system.isActive()) return;
49
50 ShipAPI pick = getWeightedTargets(target).getItemWithHighestWeight();
51 if (pick != null) {
52 ship.getAIFlags().setFlag(AIFlags.CUSTOM1, 1.5f, pick);
54 //System.out.println("Lash target: " + pick);
55 }
56 }
57 }
58
59 public List<ShipAPI> getPossibleTargets() {
60 List<ShipAPI> result = new ArrayList<>();
62
63 List<ShipAPI> ships = engine.getShips();
64 for (ShipAPI other : ships) {
65 if (other == ship) continue;
66 if (!script.isValidLashTarget(ship, other)) continue;
67 if (!script.isInRange(ship, other)) continue;
68 result.add(other);
69 }
70 return result;
71 }
72
75
76 for (ShipAPI other : getPossibleTargets()) {
77 float w = 0f;
78 if (ship.getOwner() == other.getOwner()) {
79 if (ThreatSwarmAI.isAttackSwarm(other)) {
81 if (swarm != null && !VoltaicDischargeOnFireEffect.isSwarmPhaseMode(other)) {
82 w = 0.5f;
83 } else {
84 continue;
85 }
86 } else {
87 if (other.getSystem() == null) continue;
88 if (!(other.getSystem().getScript() instanceof EnergyLashActivatedSystem)) continue;
89 if (other.getSystem().getCooldownRemaining() > 0) continue;
90 if (other.getSystem().isActive()) continue;
91 if (other.getFluxTracker().isOverloadedOrVenting()) continue;
92
93 EnergyLashActivatedSystem otherSystem = (EnergyLashActivatedSystem) other.getSystem().getScript();
94 w = otherSystem.getCurrentUsefulnessLevel(ship, other);
95 }
96// if (other.getSystem().getSpecAPI().hasTag(Tags.SHIP_SYSTEM_MOVEMENT)) {
97// }
98// if (other.getSystem().getSpecAPI().hasTag(Tags.SHIP_SYSTEM_OFFENSIVE)) {
99// Object test = ship.getAIFlags().getCustom(AIFlags.MANEUVER_TARGET);
100// if (test instanceof ShipAPI) {
101// ShipAPI otherTarget = (ShipAPI) test;
102// float dist = Misc.getDistance(other.getLocation(), otherTarget.getLocation());
103// dist -= other.getCollisionRadius() + otherTarget.getCollisionRadius();
104// if (dist < 1500f) {
105// }
106// }
107// }
108 } else {
109 ShieldAPI targetShield = other.getShield();
110 boolean targetShieldsFacingUs = targetShield != null &&
111 targetShield.isOn() &&
112 Misc.isInArc(targetShield.getFacing(), Math.max(30f, targetShield.getActiveArc()),
113 other.getLocation(), ship.getLocation());
114 if (targetShieldsFacingUs && EnergyLashSystemScript.DAMAGE <= 0) continue;
115
116 float dist = Misc.getDistance(ship.getLocation(), other.getLocation());
117 dist -= ship.getCollisionRadius() + other.getCollisionRadius();
118 if (dist < 0) dist = 0;
119 if (other == shipTarget) {
120 w += 0.25f;
121 }
122 if (dist < 1000f) {
123 w += (1f - (dist / 1000f)) * 0.5f;
124 }
125 if (other.isPhased()) {
126 w += 0.5f;
127 }
128 w += 0.01f;
129 }
130 picker.add(other, w);
131 }
132 return picker;
133 }
134
135}
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
static CombatEngineAPI getCombatEngine()
Definition Global.java:69
void init(ShipAPI ship, ShipSystemAPI system, ShipwideAIFlags flags, CombatEngineAPI engine)
WeightedRandomPicker< ShipAPI > getWeightedTargets(ShipAPI shipTarget)
void advance(float amount, Vector2f missileDangerDir, Vector2f collisionDangerDir, ShipAPI target)
static RoilingSwarmEffect getSwarmFor(CombatEntityAPI entity)
static float getDistance(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:599
static boolean isInArc(float direction, float arc, Vector2f from, Vector2f to)
Definition Misc.java:1722
void giveCommand(ShipCommand command, Object param, int groupNumber)
float getCurrentUsefulnessLevel(ShipAPI overseer, ShipAPI ship)