Starsector API
Loading...
Searching...
No Matches
ReversePolarityToggle.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.abilities;
2
3import java.awt.Color;
4
5import com.fs.starfarer.api.Global;
6import com.fs.starfarer.api.campaign.CampaignFleetAPI;
7import com.fs.starfarer.api.fleet.FleetMemberViewAPI;
8import com.fs.starfarer.api.ui.Alignment;
9import com.fs.starfarer.api.ui.LabelAPI;
10import com.fs.starfarer.api.ui.TooltipMakerAPI;
11import com.fs.starfarer.api.util.Misc;
12
14
15 public static String REVERSED_POLARITY = "$reversedPolarity";
16 public static String POLARITY_SPEED_MULT = "$polaritySpeedMult";
17 public static String POLARITY_WIND_GLOW_COLOR_KEY = "$polarityWindGlowColor";
18 public static Color POLARITY_WIND_GLOW_COLOR = new Color(1f, 0.25f, 1f, 0.75f);
19
20 public static float SLIPSTREAM_SPEED_MULT = 0.75f;
21
22 public static float CR_COST_MULT = 0.25f;
23 public static float FUEL_COST_MULT = 1f;
24
25 public static float ACTIVATION_DAMAGE_PROB = 0.33f;
26
27 @Override
28 public float getFuelCostMult(boolean forTooltip) {
29 if (!forTooltip && !isFleetInSlipstream()) return 0f;
30 return FUEL_COST_MULT;
31 }
32
33 @Override
34 public float getCRCostMult(boolean forTooltip) {
35 if (!forTooltip && !isFleetInSlipstream()) return 0f;
36 return CR_COST_MULT;
37 }
38
39 @Override
40 public boolean canRecoverCRWhileActive(boolean forTooltip) {
41 return true;
42 }
43
44 @Override
45 protected String getActivationText() {
46 return "Drive field polarity reversed";
47 }
48
49
50 @Override
51 public boolean isUsable() {
52 if (!super.isUsable()) return false;
53 if (getFleet() == null) return false;
54
55 CampaignFleetAPI fleet = getFleet();
56
57 if (!fleet.isInHyperspace()) return false;
58
59 return true;
60 }
61
62 @Override
63 protected void applyStatsEffect(float amount, float level) {
64 CampaignFleetAPI fleet = getFleet();
65 if (fleet == null) return;
66
67 if (fleet.getContainingLocation() == null || !fleet.getContainingLocation().isHyperspace()) {
68 deactivate();
69 return;
70 }
71
72 if (level >= 1f && turnedOn) {
73 fleet.getMemoryWithoutUpdate().set(REVERSED_POLARITY, true, getDeactivationDays());
74 float speedMult = SLIPSTREAM_SPEED_MULT;
75 fleet.getMemoryWithoutUpdate().set(POLARITY_SPEED_MULT, speedMult, getDeactivationDays());
77 }
78 if (level <= 0) {
80 }
81 }
82
83
84 @Override
85 protected void applyFleetVisual(float amount, float level) {
86 CampaignFleetAPI fleet = getFleet();
87 if (fleet == null) return;
88
89 Color c = new Color(255,0,255,255);
90 Color cDim = new Color(255,0,255,50);
91 Color cDim2 = new Color(255,0,255,120);
92 for (FleetMemberViewAPI view : fleet.getViews()) {
93 //view.getContrailColor().shift(getModId(), view.getEngineColor().getBase(), 1f, 1f, 0.25f);
94 view.getContrailColor().shift(getModId(), cDim2, 1f, 1f, .75f);
95 view.getEngineGlowColor().shift(getModId(), cDim, 1f, 1f, .5f);
96 view.getEngineGlowSizeMult().shift(getModId(), 3f, 1f, 1f, 1f);
97 //view.getEngineHeightMult().shift(getModId(), 5f, 1f, 1f, 1f);
98 //view.getEngineWidthMult().shift(getModId(), 10f, 1f, 1f, 1f);
99 }
100 }
101
102
103 public boolean isFleetInSlipstream() {
104 CampaignFleetAPI fleet = getFleet();
105 if (fleet == null) return false;
106 return Misc.isInsideSlipstream(fleet);
107 }
108
109 @Override
110 public void createTooltip(TooltipMakerAPI tooltip, boolean expanded) {
111 CampaignFleetAPI fleet = getFleet();
112 if (fleet == null) return;
113
114 Color gray = Misc.getGrayColor();
115 Color highlight = Misc.getHighlightColor();
116
117 String status = " (off)";
118 if (turnedOn) {
119 status = " (on)";
120 }
121
122 LabelAPI title = tooltip.addTitle("Reverse Polarity" + status);
123 title.highlightLast(status);
124 title.setHighlightColor(gray);
125
126 float pad = 10f;
127
128
129 tooltip.addPara("Reverse the polarity of the drive field, causing the fleet to travel "
130 + "against the current of slipstreams.", pad);
131
132 if (SLIPSTREAM_SPEED_MULT != 1f) {
133 tooltip.addPara("Going against the current is less efficient and results in "
134 + "the slipstream current's effect being reduced by %s.", pad,
135 highlight,
136 "" + Math.round(100f * (1f - SLIPSTREAM_SPEED_MULT))+ "%"
137 );
138 }
139
140 tooltip.addPara("When used outside a slipstream, incurs no cost, penalty, or risk of ship damage.", pad);
141
142 tooltip.addSectionHeading("Use inside slipstreams", Alignment.MID, pad);
143 addCostTooltipSection(tooltip, expanded, "An emergency maneuver when performed inside a slipstream, "
144 + "reversing drive field polarity");
145
146
147 addIncompatibleToTooltip(tooltip, expanded);
148 }
149
150
151 @Override
152 public void addOtherNotUsableReason(TooltipMakerAPI tooltip, boolean expanded) {
153 CampaignFleetAPI fleet = getFleet();
154 if (fleet == null) return;
155
156 Color bad = Misc.getNegativeHighlightColor();
157 if (!fleet.isInHyperspace()) {
158 tooltip.addPara("Can only be used in hyperspace.", bad, 10f);
159 }
160 }
161
162 protected boolean showAlarm() {
163 if (!isFleetInSlipstream()) return false;
164 return super.showAlarm() || isFleetInSlipstream();
165 }
166
167
168 @Override
169 public Color getCooldownColor() {
170 if (showAlarm()) {
171 Color color = Misc.getNegativeHighlightColor();
172 if (!super.showAlarm()) { // fleet is inside slipstream, but good CR
173 color = Misc.getHighlightColor();
174 }
175 return Misc.scaleAlpha(color, Global.getSector().getCampaignUI().getSharedFader().getBrightness() * 0.5f);
176 }
177 return super.getCooldownColor();
178 }
179//
180
181// public void setFuelUseModifier(CampaignFleetAPI fleet, boolean on) {
182// if (!WITH_FUEL_USE_MULT) return;
183//
184// String id1 = "reverse_polarity_1";
185//
186// MutableStat stat = fleet.getStats().getDynamic().getStat(Stats.FUEL_USE_NOT_SHOWN_ON_MAP_MULT);
187// stat.unmodifyMult(id1);
188//
189// for (StatMod mod : stat.getMultMods().values()) {
190// if (SlipstreamTerrainPlugin2.FUEL_USE_MODIFIER_DESC.equals(mod.desc)) {
191// if (on) {
192// stat.modifyMult(id1, FUEL_USE_MULT,
193// SlipstreamTerrainPlugin2.FUEL_USE_MODIFIER_DESC + " (reversed polarity)");
194// } else {
195// stat.unmodifyMult(id1);
196// }
197// break;
198// }
199// }
200// }
201}
202
203
204
205
206
static SectorAPI getSector()
Definition Global.java:59
void addIncompatibleToTooltip(TooltipMakerAPI tooltip, boolean expanded)
void addOtherNotUsableReason(TooltipMakerAPI tooltip, boolean expanded)
void addCostTooltipSection(TooltipMakerAPI tooltip, boolean expanded, String prefix)