Starsector API
Loading...
Searching...
No Matches
SustainedBurnAbility.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.abilities;
2
3import java.awt.Color;
4
5import org.lwjgl.util.vector.Vector2f;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.campaign.BattleAPI;
9import com.fs.starfarer.api.campaign.CampaignFleetAPI;
10import com.fs.starfarer.api.fleet.FleetMemberViewAPI;
11import com.fs.starfarer.api.impl.campaign.ids.Stats;
12import com.fs.starfarer.api.ui.LabelAPI;
13import com.fs.starfarer.api.ui.TooltipMakerAPI;
14import com.fs.starfarer.api.util.Misc;
15
17
18 public static String SB_NO_STOP = "$sb_active";
19 public static String SB_NO_SLOW = "$sb_no_slow";
20 //public static float SENSOR_RANGE_MULT = 0.75f;
21 public static float DETECTABILITY_PERCENT = 100f;
22 //public static float MAX_BURN_MOD = 10f;
23 public static float MAX_BURN_PERCENT = 100f;
24 public static float ACCELERATION_MULT = 0.2f;
25
26// public String getSpriteName() {
27// return Global.getSettings().getSpriteName("abilities", Abilities.SUSTAINED_BURN);
28// }
29
30
31 @Override
32 protected String getActivationText() {
33 return super.getActivationText();
34 //return "Engaging sustained burn";
35 }
36
37
38 @Override
39 protected void activateImpl() {
40 CampaignFleetAPI fleet = getFleet();
41 if (fleet == null) return;
42
43 if (!fleet.getMemoryWithoutUpdate().is(SB_NO_STOP, true)) {
44 fleet.setVelocity(0, 0);
45 }
46 }
47
48 @Override
49 protected void applyEffect(float amount, float level) {
50 CampaignFleetAPI fleet = getFleet();
51 if (fleet == null) return;
52
53 //System.out.println("Level: " + level);
54 //level = 0.01f;
55
56 if (level > 0 && !fleet.isAIMode() && fleet.getCargo().getFuel() <= 0 &&
57 fleet.getContainingLocation() != null && fleet.getContainingLocation().isHyperspace()) {
58 deactivate();
59 return;
60 }
61
62 fleet.getMemoryWithoutUpdate().set(SB_NO_STOP, true, 0.3f);
63
64 if (level > 0 && level < 1 && amount > 0 && !fleet.getMemoryWithoutUpdate().is(SB_NO_SLOW, true)) {
65 float activateSeconds = getActivationDays() * Global.getSector().getClock().getSecondsPerDay();
66 float speed = fleet.getVelocity().length();
67 float acc = Math.max(speed, 200f)/activateSeconds + fleet.getAcceleration();
68 float ds = acc * amount;
69 if (ds > speed) ds = speed;
71 dv.scale(ds);
72 fleet.setVelocity(fleet.getVelocity().x - dv.x, fleet.getVelocity().y - dv.y);
73 return;
74 }
75
76 //fleet.getStats().getSensorRangeMod().modifyMult(getModId(), 1f + (SENSOR_RANGE_MULT - 1f) * level, "Sustained burn");
78
79 //int burnModifier = (int)(MAX_BURN_MOD * level) - (int)(INITIAL_BURN_PENALTY * (1f - level));
80 //int burnModifier = (int)(MAX_BURN_MOD * level);
81 int burnModifier = 0;
82 float burnMult = 1f;
83
84 float b = fleet.getStats().getDynamic().getValue(Stats.SUSTAINED_BURN_BONUS, 0f);
85 //burnModifier = (int)((MAX_BURN_MOD + b) * level);
86 burnModifier = (int)((b) * level);
87
88// if (level > 0.5f) {
89// burnModifier = (int)(MAX_BURN_MOD * (level - 0.5f) / 0.5f);
90// } else {
91// //burnModifier = -1 * (int)(INITIAL_BURN_PENALTY * (1f - level / 0.5f));
92// burnMult = 1f + ((INITIAL_BURN_PENALTY - 1f) * (1f - level / 0.5f));
93// }
94 fleet.getStats().getFleetwideMaxBurnMod().modifyFlat(getModId(), burnModifier, "Sustained burn");
95 fleet.getStats().getFleetwideMaxBurnMod().modifyMult(getModId(), burnMult, "Sustained burn");
97
98
99 float accImpact = 0f;
100 float burn = Misc.getBurnLevelForSpeed(fleet.getVelocity().length());
101 if (burn > 1) {
102 float dir = Misc.getDesiredMoveDir(fleet);
103// if (fleet.isPlayerFleet()) {
104// System.out.println("DIR: " + dir);
105// }
106 float velDir = Misc.getAngleInDegrees(fleet.getVelocity());
107 float diff = Misc.getAngleDiff(dir, velDir);
108 //float pad = 90f;
109 float pad = 120f;
110 diff -= pad;
111 if (diff < 0) diff = 0;
112 accImpact = 1f - 0.5f * Math.min(1f, (diff / (180f - pad)));
113 }
114
115// if (fleet.isPlayerFleet()) {
116// System.out.println("Acc mult: " + (1f - (1f - ACCELERATION_MULT) * accImpact));
117// }
118 fleet.getStats().getAccelerationMult().modifyMult(getModId(), 1f - (1f - ACCELERATION_MULT) * accImpact);
119 //fleet.getStats().getAccelerationMult().modifyMult(getModId(), 1f + (ACCELERATION_MULT - 1f) * level);
120
121 for (FleetMemberViewAPI view : fleet.getViews()) {
122 //view.getContrailColor().shift(getModId(), new Color(50,50,50,155), 1f, 1f, .5f);
123 view.getContrailColor().shift(getModId(), view.getEngineColor().getBase(), 1f, 1f, 0.5f * level);
124 view.getEngineGlowSizeMult().shift(getModId(), 1.5f, 1f, 1f, 1f * level);
125 view.getEngineHeightMult().shift(getModId(), 3f, 1f, 1f, 1f * level);
126 view.getEngineWidthMult().shift(getModId(), 2f, 1f, 1f, 1f * level);
127 }
128
129
130 if (level <= 0) {
131 cleanupImpl();
132 }
133 }
134
135 @Override
136 protected void deactivateImpl() {
137 //cleanupImpl();
138 }
139
140 @Override
141 protected void cleanupImpl() {
142 CampaignFleetAPI fleet = getFleet();
143 if (fleet == null) return;
144
145 //fleet.getStats().getSensorRangeMod().unmodify(getModId());
149 }
150
151 @Override
152 public boolean showProgressIndicator() {
153 return super.showProgressIndicator();
154 //return false;
155 }
156
157 @Override
158 public boolean showActiveIndicator() {
159 //super.showActiveIndicator()
160 return isActive();
161 }
162
163 @Override
164 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded) {
165 Color gray = Misc.getGrayColor();
166 Color highlight = Misc.getHighlightColor();
167
168 String status = " (off)";
169 if (turnedOn) {
170 status = " (on)";
171 }
172
174 LabelAPI title = tooltip.addTitle("Sustained Burn" + status);
175 title.highlightLast(status);
176 title.setHighlightColor(gray);
177 } else {
178 tooltip.addSpacer(-10f);
179 }
180
181 float pad = 10f;
182
183
184 tooltip.addPara("Switch the drives of all ships in the fleet to a mode suited for long-distance travel. " +
185 "The fleet has to stop briefly to make the switch-over. ", pad);
186
187// public static final float SENSOR_RANGE_MULT = 0.75f;
188// public static final float DETECTABILITY_PERCENT = 50f;
189// public static final float MAX_BURN_MOD = 10f;
190// private static final float ACCELERATION_MULT = 0.25f;
191 tooltip.addPara("Increases the maximum burn level by %s, at the expense of lower acceleration, " +
192 "especially in the direction of the fleet's movement. " +
193 "Also increases the range at which the fleet can be detected by %s.", pad,
194 highlight,
195 //"" + (int) MAX_BURN_MOD,
196 "" + (int) Math.round(MAX_BURN_PERCENT) + "%",
197 "" + (int)(DETECTABILITY_PERCENT) + "%"
198 );
199
200 tooltip.addPara("The burn level increase does not apply to flat burn bonuses, " +
201 "such as those from Nav Buoys or tugs.", pad);
202
204 CampaignFleetAPI fleet = getFleet();
205 if (fleet != null) {
206 if (!fleet.isAIMode() && fleet.getCargo().getFuel() <= 0 &&
207 fleet.getContainingLocation() != null && fleet.getContainingLocation().isHyperspace()) {
208 tooltip.addPara("Out of fuel.", Misc.getNegativeHighlightColor(), pad);
209 }
210 }
211 }
212
213// tooltip.addPara("Increases the maximum burn level by %s, Acceleration is greatly reduced, and " +
214// "higher drive emissions interfere with sensors, decreasing their range by %s. " +
215// "The fleet is also %s easier to detect.", pad,
216// highlight,
217// "" + (int) MAX_BURN_MOD,
218// "" + (int)((1f - SENSOR_RANGE_MULT) * 100f) + "%",
219// "" + (int)(DETECTABILITY_PERCENT) + "%"
220// );
221 //tooltip.addPara("Disables the transponder when activated.", pad);
222 addIncompatibleToTooltip(tooltip, expanded);
223 }
224
225 public boolean isUsable() {
226 if (!super.isUsable()) return false;
227 if (getFleet() == null) return false;
228
229 CampaignFleetAPI fleet = getFleet();
230 if (!fleet.isAIMode() && fleet.getCargo().getFuel() <= 0 &&
231 fleet.getContainingLocation() != null && fleet.getContainingLocation().isHyperspace()) {
232 return false;
233 }
234
235 return true;
236 }
237
238 public boolean hasTooltip() {
239 return true;
240 }
241
242
243 @Override
244 public void fleetLeftBattle(BattleAPI battle, boolean engagedInHostilities) {
245// if (battle.isPlayerInvolved() && engagedInHostilities) {
246// deactivate();
247// }
248 }
249
250
251 @Override
252 public void fleetJoinedBattle(BattleAPI battle) {
253 if (!battle.isPlayerInvolved()) {
254 deactivate();
255 }
256 }
257
258}
259
260
261
262
263
static boolean CODEX_TOOLTIP_MODE
Definition Global.java:15
static SectorAPI getSector()
Definition Global.java:65
void modifyMult(String source, float value)
void modifyMult(String source, float value)
void modifyPercent(String source, float value)
void modifyFlat(String source, float value)
void addIncompatibleToTooltip(TooltipMakerAPI tooltip, boolean expanded)
void createTooltip(TooltipMakerAPI tooltip, boolean expanded)
void fleetLeftBattle(BattleAPI battle, boolean engagedInHostilities)
static Vector2f getUnitVectorAtDegreeAngle(float degrees)
Definition Misc.java:1196
static float getDesiredMoveDir(CampaignFleetAPI fleet)
Definition Misc.java:4191
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color getGrayColor()
Definition Misc.java:826
static float getAngleDiff(float from, float to)
Definition Misc.java:1716
static Color getHighlightColor()
Definition Misc.java:792
static float getBurnLevelForSpeed(float speed)
Definition Misc.java:1652
static float getAngleInDegrees(Vector2f v)
Definition Misc.java:1126
List< FleetMemberViewAPI > getViews()
void set(String key, Object value)
boolean is(String key, Object value)
void setHighlightColor(Color color)
void highlightLast(String substring)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
UIComponentAPI addSpacer(float height)