Starsector API
Loading...
Searching...
No Matches
ExtractionProtocolSystemScript.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat.threat;
2
3import com.fs.starfarer.api.combat.MutableShipStatsAPI;
4import com.fs.starfarer.api.combat.ShipAPI;
5import com.fs.starfarer.api.combat.ShipCommand;
6import com.fs.starfarer.api.combat.ShipwideAIFlags.AIFlags;
7import com.fs.starfarer.api.combat.WeaponAPI;
8
10
11 public static float SPEED_BONUS = 100f;
12
13 protected boolean vented = false;
14
15 public void applyImpl(ShipAPI ship, MutableShipStatsAPI stats, String id, State state, float effectLevel) {
16 stats.getMaxSpeed().modifyFlat(id, SPEED_BONUS * effectLevel);
17 stats.getAcceleration().modifyFlat(id, 2f * SPEED_BONUS * effectLevel);
18 stats.getDeceleration().modifyFlat(id, 2f * SPEED_BONUS * effectLevel);
19
20 //stats.getFluxDissipation().modifyMult(id, 1f + (FLUX_DISSIPATION_MULT - 1f) * effectLevel);
21
22 //ship.getEngineController().fadeToOtherColor(this, color, new Color(0,0,0,0), effectLevel, 0.67f);
23 ship.getEngineController().extendFlame(ship.getSystem(), 0.01f * effectLevel, 0f * effectLevel, 1f * effectLevel);
24
25 if (effectLevel <= 0f) return;
26
27 ship.getAIFlags().setFlag(AIFlags.BACK_OFF, 1f);
28 ship.getAIFlags().setFlag(AIFlags.DO_NOT_VENT, 1f);
29 ship.getAIFlags().setFlag(AIFlags.BACK_OFF_MIN_RANGE, 10000f);
30 ship.getAIFlags().unsetFlag(AIFlags.DO_NOT_BACK_OFF);
31
32 if (state == State.IN || state == State.ACTIVE) {
33 vented = false;
35 }
36 if (state == State.OUT) {
37 if (!vented) {
38 ship.giveCommand(ShipCommand.VENT_FLUX, null, 0);
39
40 for (WeaponAPI w : ship.getAllWeapons()) {
41 if (w.isDecorative()) continue;
42 if (w.getSlot().isSystemSlot()) continue;
43 if (w.usesAmmo() && w.getAmmo() < w.getMaxAmmo()) {
44 w.setAmmo(w.getMaxAmmo());
45 }
46 }
47 }
48 }
49
50 setStandardJitter(ship, state, effectLevel);
51 }
52
53
54 public StatusData getStatusData(int index, State state, float effectLevel) {
55 if (effectLevel <= 0f) return null;
56
57 if (index == 0) {
58 return new StatusData("improved maneuverability", false);
59 } else if (index == 1) {
60 return new StatusData("+" + (int)SPEED_BONUS + " top speed", false);
61 }
62 return null;
63 }
64
65 @Override
66 public float getCurrentUsefulnessLevel(ShipAPI overseer, ShipAPI ship) {
67 if (ship.getSystem().isActive() || ship.getSystem().isChargedown() ||
68 ship.getSystem().isChargeup() || ship.getSystem().isCoolingDown()) {
69 return 0f;
70 }
71
72 float level = ship.getFluxLevel();
73
74 float needAmmo = 0f;
75 float useAmmo = 0f;
76 for (WeaponAPI w : ship.getAllWeapons()) {
77 if (w.isDecorative()) continue;
78 if (w.getSlot().isSystemSlot()) continue;
79 if (w.usesAmmo()) {
80 float op = w.getSpec().getOrdnancePointCost(null);
81 useAmmo += op;
82 // the system reloads regenerating weapons, but for this don't count them
83 if (w.getAmmo() < w.getMaxAmmo() && w.getMaxAmmo() > 0 && w.getAmmoPerSecond() > 0) {
84 needAmmo += (1f - (float)w.getAmmo() / (float) w.getMaxAmmo()) * op;
85 }
86 }
87 }
88 if (useAmmo > 0f) {
89 level += 0.25f * needAmmo / useAmmo;
90 if (level > 1f) level = 1f;
91 }
92
93
94 float threshold = 0.7f;
95 Object test = ship.getAIFlags().getCustom(AIFlags.MANEUVER_TARGET);
96 if (test instanceof ShipAPI) {
97 ShipAPI target = (ShipAPI) test;
98 if (target.getFluxLevel() > ship.getFluxLevel()) {
99 threshold = 0.9f;
100 }
101 //threshold = Math.max(0.7f, level + 0.05f);
102 }
103
104 if (ship.getAIFlags().hasFlag(AIFlags.BACKING_OFF) && level > threshold) {
105 return (level - threshold) / (1f - threshold);
106 }
107
108 return 0f;
109 }
110
111
112}
113
114
115
116
117
118
119
120
void modifyFlat(String source, float value)
void applyImpl(ShipAPI ship, MutableShipStatsAPI stats, String id, State state, float effectLevel)
List< WeaponAPI > getAllWeapons()
ShipEngineControllerAPI getEngineController()
void giveCommand(ShipCommand command, Object param, int groupNumber)
void extendFlame(Object key, float extendLengthFraction, float extendWidthFraction, float extendGlowFraction)