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) {
74 float speedMult = SLIPSTREAM_SPEED_MULT;
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
123 LabelAPI title = tooltip.addTitle("Reverse Polarity" + status);
124 title.highlightLast(status);
125 title.setHighlightColor(gray);
126 } else {
127 tooltip.addSpacer(-10f);
128 }
129
130 float pad = 10f;
131
132
133 tooltip.addPara("Reverse the polarity of the drive field, causing the fleet to travel "
134 + "against the current of slipstreams.", pad);
135
136 if (SLIPSTREAM_SPEED_MULT != 1f) {
137 tooltip.addPara("Going against the current is less efficient and results in "
138 + "the slipstream current's effect being reduced by %s.", pad,
139 highlight,
140 "" + Math.round(100f * (1f - SLIPSTREAM_SPEED_MULT))+ "%"
141 );
142 }
143
144 tooltip.addPara("When used outside a slipstream, incurs no cost, penalty, or risk of ship damage.", pad);
145
146 tooltip.addSectionHeading("Use inside slipstreams", Alignment.MID, pad);
147 addCostTooltipSection(tooltip, expanded, "An emergency maneuver when performed inside a slipstream, "
148 + "reversing drive field polarity");
149
150
151 addIncompatibleToTooltip(tooltip, expanded);
152 }
153
154
155 @Override
156 public void addOtherNotUsableReason(TooltipMakerAPI tooltip, boolean expanded) {
157 CampaignFleetAPI fleet = getFleet();
158 if (fleet == null) return;
159
160 Color bad = Misc.getNegativeHighlightColor();
161 if (!fleet.isInHyperspace()) {
162 tooltip.addPara("Can only be used in hyperspace.", bad, 10f);
163 }
164 }
165
166 protected boolean showAlarm() {
167 if (!isFleetInSlipstream()) return false;
168 return super.showAlarm() || isFleetInSlipstream();
169 }
170
171
172 @Override
173 public Color getCooldownColor() {
174 if (showAlarm()) {
175 Color color = Misc.getNegativeHighlightColor();
176 if (!super.showAlarm()) { // fleet is inside slipstream, but good CR
177 color = Misc.getHighlightColor();
178 }
180 }
181 return super.getCooldownColor();
182 }
183//
184
185// public void setFuelUseModifier(CampaignFleetAPI fleet, boolean on) {
186// if (!WITH_FUEL_USE_MULT) return;
187//
188// String id1 = "reverse_polarity_1";
189//
190// MutableStat stat = fleet.getStats().getDynamic().getStat(Stats.FUEL_USE_NOT_SHOWN_ON_MAP_MULT);
191// stat.unmodifyMult(id1);
192//
193// for (StatMod mod : stat.getMultMods().values()) {
194// if (SlipstreamTerrainPlugin2.FUEL_USE_MODIFIER_DESC.equals(mod.desc)) {
195// if (on) {
196// stat.modifyMult(id1, FUEL_USE_MULT,
197// SlipstreamTerrainPlugin2.FUEL_USE_MODIFIER_DESC + " (reversed polarity)");
198// } else {
199// stat.unmodifyMult(id1);
200// }
201// break;
202// }
203// }
204// }
205}
206
207
208
209
210
static boolean CODEX_TOOLTIP_MODE
Definition Global.java:15
static SectorAPI getSector()
Definition Global.java:65
void addIncompatibleToTooltip(TooltipMakerAPI tooltip, boolean expanded)
void addOtherNotUsableReason(TooltipMakerAPI tooltip, boolean expanded)
void addCostTooltipSection(TooltipMakerAPI tooltip, boolean expanded, String prefix)
static boolean isInsideSlipstream(Vector2f loc, float radius)
Definition Misc.java:6408
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color getGrayColor()
Definition Misc.java:826
static Color scaleAlpha(Color color, float factor)
Definition Misc.java:1309
static Color getHighlightColor()
Definition Misc.java:792
List< FleetMemberViewAPI > getViews()
void set(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)
LabelAPI addSectionHeading(String str, Alignment align, float pad)