Starsector API
Loading...
Searching...
No Matches
EscortPackage.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.hullmods;
2
3import java.util.Iterator;
4
5import com.fs.starfarer.api.Global;
6import com.fs.starfarer.api.combat.BaseHullMod;
7import com.fs.starfarer.api.combat.CombatEngineAPI;
8import com.fs.starfarer.api.combat.MutableShipStatsAPI;
9import com.fs.starfarer.api.combat.ShipAPI;
10import com.fs.starfarer.api.combat.ShipAPI.HullSize;
11import com.fs.starfarer.api.util.IntervalUtil;
12import com.fs.starfarer.api.util.Misc;
13
14public class EscortPackage extends BaseHullMod {
15
16 public static float MANEUVER_BONUS = 25f;
17 public static float SPEED_BONUS = 10f;
18 public static float RANGE_BONUS = 20f;
19 public static float SHIELD_BONUS = 10f;
20
21 public static float EFFECT_RANGE = 700f;
22 public static float EFFECT_FADE = 500f;
23
24 public static Object STATUS_KEY = new Object();
25
26
27 public String getDescriptionParam(int index, HullSize hullSize) {
28 if (index == 0) return "1000";
29 if (index == 1) return "" + (int)Math.round(MANEUVER_BONUS) + "%";
30 if (index == 2) return "" + (int)Math.round(SPEED_BONUS) + "%";
31 if (index == 3) return "" + (int)Math.round(RANGE_BONUS) + "%";
32 if (index == 4) return "doubled";
33 return null;
34 }
35
36 public String getSModDescriptionParam(int index, HullSize hullSize) {
37 if (index == 0) return "" + (int)Math.round(SHIELD_BONUS) + "%";
38 return null;
39 }
40
41
42 @Override
43 public boolean isApplicableToShip(ShipAPI ship) {
44 return getUnapplicableReason(ship) == null;
45 }
46
47 @Override
48 public String getUnapplicableReason(ShipAPI ship) {
49 if (ship != null && ship.isFrigate()) {
50 return "Can not be installed on frigates";
51 }
52 if (ship != null && ship.isCapital()) {
53 return "Can not be installed on capital ships";
54 }
55 return super.getUnapplicableReason(ship);
56 }
57
58
59 public static String EP_DATA_KEY = "core_escort_package_data_key";
60 public static class EscortPackageData {
61 IntervalUtil interval = new IntervalUtil(0.9f, 1.1f);
62 float mag = 0;
63 }
64
65 public void applyEPEffect(ShipAPI ship, ShipAPI other, float mag) {
66 String id = "escort_package_bonus" + ship.getId();
67 MutableShipStatsAPI stats = ship.getMutableStats();
68
69 if (mag > 0) {
70 boolean sMod = isSMod(ship);
71
72 float maneuver = MANEUVER_BONUS * mag;
73 stats.getAcceleration().modifyPercent(id, maneuver);
74 stats.getDeceleration().modifyPercent(id, maneuver);
75 stats.getTurnAcceleration().modifyPercent(id, maneuver * 2f);
76 stats.getMaxTurnRate().modifyPercent(id, maneuver);
77
78 float speed = SPEED_BONUS * mag;
79 stats.getMaxSpeed().modifyPercent(id, speed);
80
81 float range = RANGE_BONUS * mag;
82 stats.getBallisticWeaponRangeBonus().modifyPercent(id, range);
83 stats.getEnergyWeaponRangeBonus().modifyPercent(id, range);
84
85 if (sMod && ship.isDestroyer()) {
86 float shields = SHIELD_BONUS * mag;
87 stats.getShieldDamageTakenMult().modifyMult(id, 1f - shields / 100f);
88 }
89 } else {
90 stats.getAcceleration().unmodify(id);
91 stats.getDeceleration().unmodify(id);
92 stats.getTurnAcceleration().unmodify(id);
93 stats.getMaxTurnRate().unmodify(id);
94
95 stats.getMaxSpeed().unmodify(id);
96
97 stats.getBallisticWeaponRangeBonus().unmodify(id);
98 stats.getEnergyWeaponRangeBonus().unmodify(id);
99
100 stats.getShieldDamageTakenMult().unmodify(id);
101 }
102
103 }
104
105 @Override
106 public void advanceInCombat(ShipAPI ship, float amount) {
107 super.advanceInCombat(ship, amount);
108
109 if (!ship.isAlive()) return;
110
111 CombatEngineAPI engine = Global.getCombatEngine();
112
113 String key = EP_DATA_KEY + "_" + ship.getId();
114 EscortPackageData data = (EscortPackageData) engine.getCustomData().get(key);
115 if (data == null) {
116 data = new EscortPackageData();
117 engine.getCustomData().put(key, data);
118 }
119
120 boolean playerShip = ship == Global.getCombatEngine().getPlayerShip();
121
122 data.interval.advance(amount * 4f);
123 if (data.interval.intervalElapsed() || playerShip) {
124 float checkSize = EFFECT_RANGE + EFFECT_FADE + ship.getCollisionRadius() + 300f;
125 checkSize *= 2f;
126
127 Iterator<Object> iter = Global.getCombatEngine().getShipGrid().getCheckIterator(
128 ship.getLocation(), checkSize, checkSize);
129
130 ShipAPI best = null;
131 float bestMag = 0f;
132 while (iter.hasNext()) {
133 Object next = iter.next();
134 if (!(next instanceof ShipAPI)) continue;
135
136 ShipAPI other = (ShipAPI) next;
137
138 if (ship == other) continue;
139 if (other.getOwner() != ship.getOwner()) continue;
140 if (other.isHulk()) continue;
141
142 if (other.getHullSize().ordinal() <= ship.getHullSize().ordinal()) continue;
143
144 float radSum = ship.getShieldRadiusEvenIfNoShield() + other.getShieldRadiusEvenIfNoShield();
145 radSum *= 0.75f;
146 float dist = Misc.getDistance(ship.getShieldCenterEvenIfNoShield(), other.getShieldCenterEvenIfNoShield());
147 dist -= radSum;
148
149 float mag = 0f;
150 if (dist < EFFECT_RANGE) {
151 mag = 1f;
152 } else if (dist < EFFECT_RANGE + EFFECT_FADE) {
153 mag = 1f - (dist - EFFECT_RANGE) / EFFECT_FADE;
154 }
155
156 if (ship.isDestroyer() && other.isCapital()) {
157 mag *= 2f;
158 }
159
160 if (mag > bestMag) {
161 best = other;
162 bestMag = mag;
163 }
164 }
165
166 //if (best != null && bestMag > 0) {
167 applyEPEffect(ship, best, bestMag);
168 //}
169
170 data.mag = bestMag;
171 }
172
173 if (playerShip) {
174 if (data.mag > 0.005f) {
175 String icon = Global.getSettings().getSpriteName("ui", "icon_tactical_escort_package");
176 String percent = "" + (int) Math.round(data.mag * 100f) + "%";
177 Global.getCombatEngine().maintainStatusForPlayerShip(
178 STATUS_KEY, icon, "Escort package", percent + " telemetry quality", false);
179 } else {
180 String icon = Global.getSettings().getSpriteName("ui", "icon_tactical_escort_package");
181 Global.getCombatEngine().maintainStatusForPlayerShip(
182 STATUS_KEY, icon, "Escort package", "no connection", true);
183 }
184 }
185
186 }
187
188}
189
190
191
192
193
194
195
196
197
198
199
200
201
202
static SettingsAPI getSettings()
Definition Global.java:51
static CombatEngineAPI getCombatEngine()
Definition Global.java:63
String getSModDescriptionParam(int index, HullSize hullSize)
String getDescriptionParam(int index, HullSize hullSize)
void advanceInCombat(ShipAPI ship, float amount)
void applyEPEffect(ShipAPI ship, ShipAPI other, float mag)
String getSpriteName(String category, String id)