Starsector API
Loading...
Searching...
No Matches
IncursionModeSystemScript.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.ShipAIConfig;
5import com.fs.starfarer.api.combat.ShipAPI;
6import com.fs.starfarer.api.combat.ShipwideAIFlags.AIFlags;
7import com.fs.starfarer.api.combat.WeaponAPI;
8import com.fs.starfarer.api.combat.WeaponAPI.WeaponType;
9import com.fs.starfarer.api.impl.campaign.ids.Personalities;
10import com.fs.starfarer.api.util.Misc;
11
13
14 public static float SPEED_BONUS = 100f;
15 public static float FLUX_DISSIPATION_MULT = 3f;
16 public static float AMMO_REGEN_MULT = 5f;
17
18
20
21 protected void init(ShipAPI ship) {
22 super.init(ship);
23 if (ship.getShipAI() != null && ship.getShipAI().getConfig() != null) {
24 ShipAIConfig config = ship.getShipAI().getConfig();
25 origConfig = config.clone();
26 }
27 }
28
29 public void applyImpl(ShipAPI ship, MutableShipStatsAPI stats, String id, State state, float effectLevel) {
30 stats.getMaxSpeed().modifyFlat(id, SPEED_BONUS * effectLevel);
31 stats.getAcceleration().modifyFlat(id, 2f * SPEED_BONUS * effectLevel);
32 stats.getDeceleration().modifyFlat(id, 2f * SPEED_BONUS * effectLevel);
33 stats.getEnergyAmmoRegenMult().modifyMult(id, 1f + (AMMO_REGEN_MULT - 1f) * effectLevel);
34 stats.getBallisticAmmoRegenMult().modifyMult(id, 1f + (AMMO_REGEN_MULT - 1f) * effectLevel);
35 //stats.getMissileAmmoRegenMult().modifyMult(id, AMMO_REGEN_MULT * effectLevel);
36 stats.getFluxDissipation().modifyMult(id, 1f + (FLUX_DISSIPATION_MULT - 1f) * effectLevel);
37
38 if (ship.getShipAI() != null && ship.getShipAI().getConfig() != null) {
39 ShipAIConfig config = ship.getShipAI().getConfig();
40 if (effectLevel > 0) {
41 config.personalityOverride = Personalities.RECKLESS;
42 config.alwaysStrafeOffensively = true;
43 config.backingOffWhileNotVentingAllowed = false;
44 config.turnToFaceWithUndamagedArmor = false;
45 config.burnDriveIgnoreEnemies = true;
46 } else {
47 config.copyFrom(origConfig);
48 }
49 }
50
51 //if (state != State.IDLE && state != State.OUT) return;
52 if (effectLevel <= 0f) return;
53
54 ship.getEngineController().extendFlame(ship.getSystem(), 1f * effectLevel, 0f * effectLevel, 0.5f * effectLevel);
55
56 ship.getAIFlags().setFlag(AIFlags.DO_NOT_BACK_OFF, 1f);
57 ship.getAIFlags().setFlag(AIFlags.DO_NOT_VENT, 1f);
58 ship.getAIFlags().setFlag(AIFlags.IGNORES_ORDERS, 1f);
59
61
62 setStandardJitter(ship, state, effectLevel);
63 }
64
65
66 public StatusData getStatusData(int index, State state, float effectLevel) {
67 if (effectLevel <= 0f) return null;
68
69 if (index == 0) {
70 return new StatusData("improved maneuverability", false);
71 } else if (index == 1) {
72 return new StatusData("+" + (int)SPEED_BONUS + " top speed", false);
73 } else if (index == 2) {
74 return new StatusData("x" + (int)FLUX_DISSIPATION_MULT+ " flux dissipation", false);
75 } else if (index == 3) {
76 return new StatusData("rapid charge regen", false);
77 }
78 return null;
79 }
80
81 @Override
82 public float getCurrentUsefulnessLevel(ShipAPI overseer, ShipAPI ship) {
83 if (ship.getSystem().isActive() || ship.getSystem().isChargedown() ||
84 ship.getSystem().isChargeup() || ship.getSystem().isCoolingDown()) {
85 return 0f;
86 }
87
88 Object test = ship.getAIFlags().getCustom(AIFlags.MANEUVER_TARGET);
89 if (test instanceof ShipAPI) {
90 ShipAPI target = (ShipAPI) test;
91
92 float dist = Misc.getDistance(ship.getLocation(), target.getLocation());
93 dist -= ship.getCollisionRadius() + target.getCollisionRadius();
94
95 float range = getNonMissileWeaponRange(ship);
96 float extra = 750f;
97 if (dist < range + extra) {
98 float distToOverseer = Misc.getDistance(ship.getLocation(), overseer.getLocation());
99 distToOverseer -= ship.getCollisionRadius() + overseer.getCollisionRadius();
100 float overseerDistFactor = 0f;
101 if (distToOverseer < 1000f) {
102 float min = 500f;
103 overseerDistFactor = (1f - Math.max(0f, distToOverseer - min) / (1000f - min)) * 0.25f;
104 }
105 return Math.min(1f, 0.5f + Math.min(0.5f, ship.getFluxLevel() * 1f) + overseerDistFactor);
106 }
107 }
108
109 return 0f;
110 }
111
112
113 public static float getNonMissileWeaponRange(ShipAPI ship) {
114 float max = 0f;
115 for (WeaponAPI w : ship.getAllWeapons()) {
116 if (w.isDecorative()) continue;
117 if (w.getType() == WeaponType.MISSILE) continue;
118 max = Math.max(max, w.getRange());
119 }
120 return max;
121 }
122
123}
124
125
126
127
128
129
130
131
void modifyFlat(String source, float value)
void modifyMult(String source, float value)
StatusData getStatusData(int index, State state, float effectLevel)
void applyImpl(ShipAPI ship, MutableShipStatsAPI stats, String id, State state, float effectLevel)
static float getDistance(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:599
List< WeaponAPI > getAllWeapons()
ShipEngineControllerAPI getEngineController()
void extendFlame(Object key, float extendLengthFraction, float extendWidthFraction, float extendGlowFraction)