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();
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;
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
99
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 if (amount <= 0f) return;
111
113
114 String key = EP_DATA_KEY + "_" + ship.getId();
115 EscortPackageData data = (EscortPackageData) engine.getCustomData().get(key);
116 if (data == null) {
117 data = new EscortPackageData();
118 engine.getCustomData().put(key, data);
119 }
120
121 boolean playerShip = ship == Global.getCombatEngine().getPlayerShip();
122
123 data.interval.advance(amount * 4f);
124 if (data.interval.intervalElapsed() || playerShip) {
125 float checkSize = EFFECT_RANGE + EFFECT_FADE + ship.getCollisionRadius() + 300f;
126 checkSize *= 2f;
127
128 Iterator<Object> iter = Global.getCombatEngine().getShipGrid().getCheckIterator(
129 ship.getLocation(), checkSize, checkSize);
130
131 ShipAPI best = null;
132 float bestMag = 0f;
133 while (iter.hasNext()) {
134 Object next = iter.next();
135 if (!(next instanceof ShipAPI)) continue;
136
137 ShipAPI other = (ShipAPI) next;
138
139 if (ship == other) continue;
140 if (other.getOwner() != ship.getOwner()) continue;
141 if (other.isHulk()) continue;
142
143 if (other.getHullSize().ordinal() <= ship.getHullSize().ordinal()) continue;
144
145 float radSum = ship.getShieldRadiusEvenIfNoShield() + other.getShieldRadiusEvenIfNoShield();
146 radSum *= 0.75f;
148 dist -= radSum;
149
150 float mag = 0f;
151 if (dist < EFFECT_RANGE) {
152 mag = 1f;
153 } else if (dist < EFFECT_RANGE + EFFECT_FADE) {
154 mag = 1f - (dist - EFFECT_RANGE) / EFFECT_FADE;
155 }
156
157 if (ship.isDestroyer() && other.isCapital()) {
158 mag *= 2f;
159 }
160
161 if (mag > bestMag) {
162 best = other;
163 bestMag = mag;
164 }
165 }
166
167 //if (best != null && bestMag > 0) {
168 applyEPEffect(ship, best, bestMag);
169 //}
170
171 data.mag = bestMag;
172 }
173
174 if (playerShip) {
175 if (data.mag > 0.005f) {
176 String icon = Global.getSettings().getSpriteName("ui", "icon_tactical_escort_package");
177 String percent = "" + (int) Math.round(data.mag * 100f) + "%";
179 STATUS_KEY, icon, "Escort package", percent + " telemetry quality", false);
180 } else {
181 String icon = Global.getSettings().getSpriteName("ui", "icon_tactical_escort_package");
183 STATUS_KEY, icon, "Escort package", "no connection", true);
184 }
185 }
186
187 }
188
189}
190
191
192
193
194
195
196
197
198
199
200
201
202
203
static SettingsAPI getSettings()
Definition Global.java:57
static CombatEngineAPI getCombatEngine()
Definition Global.java:69
boolean isSMod(MutableShipStatsAPI stats)
void modifyPercent(String source, float value)
void modifyMult(String source, float value)
void modifyPercent(String source, float value)
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)
static float getDistance(SectorEntityToken from, SectorEntityToken to)
Definition Misc.java:599
String getSpriteName(String category, String id)
Iterator< Object > getCheckIterator(Vector2f loc, float checkWidth, float checkHeight)
void maintainStatusForPlayerShip(Object key, String spriteName, String title, String data, boolean isDebuff)
MutableShipStatsAPI getMutableStats()