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;
70 Vector2f dv = Misc.getUnitVectorAtDegreeAngle(Misc.getAngleInDegrees(fleet.getVelocity()));
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");
77 fleet.getStats().getDetectedRangeMod().modifyPercent(getModId(), DETECTABILITY_PERCENT * 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");
96 fleet.getStats().getFleetwideMaxBurnMod().modifyPercent(getModId(), MAX_BURN_PERCENT, "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());
146 fleet.getStats().getDetectedRangeMod().unmodify(getModId());
147 fleet.getStats().getFleetwideMaxBurnMod().unmodify(getModId());
148 fleet.getStats().getAccelerationMult().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
173 LabelAPI title = tooltip.addTitle("Sustained Burn" + status);
174 title.highlightLast(status);
175 title.setHighlightColor(gray);
176
177 float pad = 10f;
178
179
180 tooltip.addPara("Switch the drives of all ships in the fleet to a mode suited for long-distance travel. " +
181 "The fleet has to stop briefly to make the switch-over. ", pad);
182
183// public static final float SENSOR_RANGE_MULT = 0.75f;
184// public static final float DETECTABILITY_PERCENT = 50f;
185// public static final float MAX_BURN_MOD = 10f;
186// private static final float ACCELERATION_MULT = 0.25f;
187 tooltip.addPara("Increases the maximum burn level by %s, at the expense of lower acceleration, " +
188 "especially in the direction of the fleet's movement. " +
189 "Also increases the range at which the fleet can be detected by %s.", pad,
190 highlight,
191 //"" + (int) MAX_BURN_MOD,
192 "" + (int) Math.round(MAX_BURN_PERCENT) + "%",
193 "" + (int)(DETECTABILITY_PERCENT) + "%"
194 );
195
196 tooltip.addPara("The burn level increase does not apply to flat burn bonuses, " +
197 "such as those from Nav Buoys or tugs.", pad);
198
199 CampaignFleetAPI fleet = getFleet();
200 if (fleet != null) {
201 if (!fleet.isAIMode() && fleet.getCargo().getFuel() <= 0 &&
202 fleet.getContainingLocation() != null && fleet.getContainingLocation().isHyperspace()) {
203 tooltip.addPara("Out of fuel.", Misc.getNegativeHighlightColor(), pad);
204 }
205 }
206
207// tooltip.addPara("Increases the maximum burn level by %s, Acceleration is greatly reduced, and " +
208// "higher drive emissions interfere with sensors, decreasing their range by %s. " +
209// "The fleet is also %s easier to detect.", pad,
210// highlight,
211// "" + (int) MAX_BURN_MOD,
212// "" + (int)((1f - SENSOR_RANGE_MULT) * 100f) + "%",
213// "" + (int)(DETECTABILITY_PERCENT) + "%"
214// );
215 //tooltip.addPara("Disables the transponder when activated.", pad);
216 addIncompatibleToTooltip(tooltip, expanded);
217 }
218
219 public boolean isUsable() {
220 if (!super.isUsable()) return false;
221 if (getFleet() == null) return false;
222
223 CampaignFleetAPI fleet = getFleet();
224 if (!fleet.isAIMode() && fleet.getCargo().getFuel() <= 0 &&
225 fleet.getContainingLocation() != null && fleet.getContainingLocation().isHyperspace()) {
226 return false;
227 }
228
229 return true;
230 }
231
232 public boolean hasTooltip() {
233 return true;
234 }
235
236
237 @Override
238 public void fleetLeftBattle(BattleAPI battle, boolean engagedInHostilities) {
239// if (battle.isPlayerInvolved() && engagedInHostilities) {
240// deactivate();
241// }
242 }
243
244
245 @Override
246 public void fleetJoinedBattle(BattleAPI battle) {
247 if (!battle.isPlayerInvolved()) {
248 deactivate();
249 }
250 }
251
252}
253
254
255
256
257
static SectorAPI getSector()
Definition Global.java:59
void addIncompatibleToTooltip(TooltipMakerAPI tooltip, boolean expanded)
void createTooltip(TooltipMakerAPI tooltip, boolean expanded)
void fleetLeftBattle(BattleAPI battle, boolean engagedInHostilities)