Starsector API
Loading...
Searching...
No Matches
BaseHullMod.java
Go to the documentation of this file.
1package com.fs.starfarer.api.combat;
2
3import java.awt.Color;
4
5import com.fs.starfarer.api.Global;
6import com.fs.starfarer.api.campaign.CampaignUIAPI.CoreUITradeMode;
7import com.fs.starfarer.api.campaign.CargoStackAPI;
8import com.fs.starfarer.api.campaign.econ.Industry;
9import com.fs.starfarer.api.campaign.econ.MarketAPI;
10import com.fs.starfarer.api.characters.PersonAPI;
11import com.fs.starfarer.api.combat.ShipAPI.HullSize;
12import com.fs.starfarer.api.fleet.FleetMemberAPI;
13import com.fs.starfarer.api.impl.campaign.HullModItemManager;
14import com.fs.starfarer.api.impl.campaign.ids.HullMods;
15import com.fs.starfarer.api.impl.campaign.ids.Industries;
16import com.fs.starfarer.api.loading.HullModSpecAPI;
17import com.fs.starfarer.api.ui.Alignment;
18import com.fs.starfarer.api.ui.TooltipMakerAPI;
19import com.fs.starfarer.api.util.Misc;
20
21public class BaseHullMod implements HullModEffect {
22
24
25 public void init(HullModSpecAPI spec) {
26 this.spec = spec;
27
28 }
29
30 public boolean isSMod(MutableShipStatsAPI stats) {
31 if (stats == null || stats.getVariant() == null || spec == null) return false;
32 return stats.getVariant().getSMods().contains(spec.getId()) ||
33 stats.getVariant().getSModdedBuiltIns().contains(spec.getId());
34 }
35 public boolean isSMod(ShipAPI ship) {
36 if (ship == null || ship.getVariant() == null || spec == null) return false;
37 return ship.getVariant().getSMods().contains(spec.getId()) ||
38 ship.getVariant().getSModdedBuiltIns().contains(spec.getId());
39 }
40 public boolean isBuiltIn(ShipAPI ship) {
41 if (ship == null || ship.getVariant() == null || spec == null) return false;
42 return ship.getHullSpec().getBuiltInMods().contains(spec.getId());
43 }
44
45
46 public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
47 }
48
49 public void applyEffectsBeforeShipCreation(HullSize hullSize,
50 MutableShipStatsAPI stats, String id) {
51 }
52
53 public String getDescriptionParam(int index, HullSize hullSize) {
54 return null;
55 }
56
57 public String getDescriptionParam(int index, HullSize hullSize, ShipAPI ship) {
58 return getDescriptionParam(index, hullSize);
59 }
60
61 public String getSModDescriptionParam(int index, HullSize hullSize) {
62 return null;
63 }
64
65 public String getSModDescriptionParam(int index, HullSize hullSize, ShipAPI ship) {
66 return getSModDescriptionParam(index, hullSize);
67 }
68
69
70 public boolean isApplicableToShip(ShipAPI ship) {
71 return true;
72 }
73
74
75 public void advanceInCampaign(FleetMemberAPI member, float amount) {
76
77 }
78
79 public void advanceInCombat(ShipAPI ship, float amount) {
80
81 }
82
83 public String getUnapplicableReason(ShipAPI ship) {
84 return null;
85 }
86
87 public boolean affectsOPCosts() {
88 return false;
89 }
90
91 public boolean canBeAddedOrRemovedNow(ShipAPI ship, MarketAPI marketOrNull, CoreUITradeMode mode) {
92 if (spec == null) return true;
93
94 boolean reqSpaceport = spec.hasTag(HullMods.TAG_REQ_SPACEPORT);
95 if (!reqSpaceport) return true;
96
97 if (marketOrNull == null) return false;
98 if (mode == CoreUITradeMode.NONE || mode == null) return false;
99
100 for (Industry ind : marketOrNull.getIndustries()) {
101 if (ind.getSpec().hasTag(Industries.TAG_STATION)) return true;
102 if (ind.getSpec().hasTag(Industries.TAG_SPACEPORT)) return true;
103 }
104
105 return false;
106 }
107
108 public String getCanNotBeInstalledNowReason(ShipAPI ship, MarketAPI marketOrNull, CoreUITradeMode mode) {
109 if (spec == null) return null;
110
111 boolean reqSpaceport = spec.hasTag(HullMods.TAG_REQ_SPACEPORT);
112 if (!reqSpaceport) return null;
113
114 boolean has = ship.getVariant().hasHullMod(spec.getId());
115
116 String verb = "installed";
117
118 // I think "or modified" was when you couldn't build in logistics mods while not at dock
119 //if (has) verb = "removed or modified";
120 if (has) verb = "removed";
121
122 return "Can only be " + verb + " at a colony with a spaceport or an orbital station";
123 }
124
125
126 public boolean shouldAddDescriptionToTooltip(HullSize hullSize, ShipAPI ship, boolean isForModSpec) {
127 return true;
128 }
129
130 public void addPostDescriptionSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec) {
131
132 }
133
134 public boolean hasSModEffectSection(HullSize hullSize, ShipAPI ship, boolean isForModSpec) {
135 if (!hasSModEffect()) return false;
136 // hope commenting this out doesn't make it crash
137 //GameState state = Global.getCurrentState();
138 //if (state == GameState.TITLE && !Global.getSettings().isDevMode()) return false;
140 return !isBuiltIn(ship) || !isSModEffectAPenalty();
141 }
142 return !isBuiltIn(ship);
143 }
144
145 public boolean isSModEffectAPenalty() {
146 return false;
147 }
148
149 public boolean hasSModEffect() {
150 return spec != null &&
151 spec.getSModEffectFormat() != null &&
152 !spec.getSModEffectFormat().trim().isEmpty() &&
153 !spec.getSModEffectFormat().startsWith("#");
154 }
155
156 public void addSModEffectSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec, boolean isForBuildInList) {
157 float opad = 10f;
158 Color h = Misc.getHighlightColor();
159 final String [] params = new String [] {
160 getSModDescriptionParam(0, hullSize, null),
161 getSModDescriptionParam(1, hullSize, null),
162 getSModDescriptionParam(2, hullSize, null),
163 getSModDescriptionParam(3, hullSize, null),
164 getSModDescriptionParam(4, hullSize, null),
165 getSModDescriptionParam(5, hullSize, null),
166 getSModDescriptionParam(6, hullSize, null),
167 getSModDescriptionParam(7, hullSize, null),
168 getSModDescriptionParam(8, hullSize, null),
169 getSModDescriptionParam(9, hullSize, null)
170 };
171 tooltip.addPara(spec.getSModDescription(hullSize).replaceAll("\\%", "%%"), opad, h, params);
172 }
173
174
175 public void addSModSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec, boolean isForBuildInList) {
176 float opad = 10f;
177 boolean sMod = isSMod(ship);
178 Color s = Misc.getStoryOptionColor();
179 Color bad = Misc.getNegativeHighlightColor();
180 Color darkBad = Misc.setAlpha(Misc.scaleColorOnly(bad, 0.4f), 175);
181 if (!sMod || hasSModEffect()) {
182// if (isForModSpec) {
183// tooltip.addSpacer(opad);
184// }
185 if (!isSModEffectAPenalty()) {
186// Color c = Misc.getStoryOptionColor();
187// if (!sMod) c = Misc.getStoryDarkColor()
188 if (isForBuildInList) {
190 } else {
192 }
193 } else {
194 if (isForBuildInList) {
195 tooltip.addSectionHeading(spec.getDisplayName() + " penalty", bad, darkBad, Alignment.MID, opad);
196 } else {
197 tooltip.addSectionHeading("S-mod penalty", bad, darkBad, Alignment.MID, opad);
198 }
199 }
200 }
201
202 if (hasSModEffect()) {
203 if (isForBuildInList) {
204 tooltip.addSpacer(-5f);
205 //tooltip.setHeightSoFar(tooltip.getHeightSoFar() - 5f);
206 }
207 addSModEffectSection(tooltip, hullSize, ship, width, isForModSpec, false);
208 if (!sMod && !isForBuildInList) {
209
210 boolean builtIn = isBuiltIn(ship);
211 if (builtIn) {
212// tooltip.addPara("This effect only applies if this built-in hullmod is enhanced using a %s. "
213// + "Doing this graints %s bonus experience - more than building in a regular hullmod.",
214// opad, s, "story point", "100%");
215// tooltip.addPara("This effect only applies if this hullmod is enhanced using a %s. "
216// + "Since it's is already built in, this graints "
217// + "%s bonus experience - more than building in a regular hullmod.",
218// opad, s, "story point", "100%");
219 tooltip.addPara("This effect only applies if this built-in hullmod is enhanced using a %s. Doing this does not count against the maximum number of s-mods a ship can have.",
220 opad, s, "story point");
221 } else {
222 String cheap = "Cheap hullmods have stronger effects.";
224 cheap = "Cheaper hullmods have stronger effects, more expensive hullmods may have penalties.";
225 }
226 tooltip.addPara("This effect only applies if this hullmod is built into the hull using a story point. " + cheap,
227 opad, s, "story point");
228 }
229// tooltip.addPara("This hullmod has the following effect when built into the hull using a story point:",
230// opad, s, "story point");
231 } else {
232// tooltip.addPara("This hullmod has the following effect from being built into the hull using a story point:",
233// opad, s, "story point");
234 }
235 } else { // no section in this case, but leaving this in case that changes
236 if (!sMod) {
237 tooltip.addPara("Aside from removing its ordnance point cost, "
238 + "this hullmod gains no extra effect from being built into the hull using "
239 + "a story point.", opad, s, "story point");
240 }
241 }
242
243
244 if (!sMod || hasSModEffect()) {
245 if (isForModSpec) {
246 tooltip.addSpacer(opad);
247 }
248 }
249
250// tooltip.addPara("Some hullmods have an additional effect"
251// + " when they're built into the hull using a story point. "
252// + "Hullmods that cost fewer ordnance points have a bonus, while "
253// + "more expensive hullmods usually have a penalty.", opad, s, "story point");
254//
255//tooltip.addPara("Hullmods that are built into the base hull do not have this effect, and neither do "
256// + "hullmods with a midrange cost.", opad);
257
258 }
259
260 public void applyEffectsToFighterSpawnedByShip(ShipAPI fighter, ShipAPI ship, String id) {
261
262 }
263
264
265 public boolean shipHasOtherModInCategory(ShipAPI ship, String currMod, String category) {
266 for (String id : ship.getVariant().getHullMods()) {
268 if (!mod.hasTag(category)) continue;
269 if (id.equals(currMod)) continue;
270 return true;
271 }
272 return false;
273 }
274
275
276 public boolean isInPlayerFleet(MutableShipStatsAPI stats) {
277 if (stats == null) return false;
278 FleetMemberAPI member = stats.getFleetMember();
279 if (member == null) return false;
281 if (fc == null) fc = member.getFleetCommander();
282 if (fc == null) return false;
283 return fc.isPlayer();
284 }
285
286 public boolean isInPlayerFleet(ShipAPI ship) {
287 if (ship == null) return false;
288 FleetMemberAPI member = ship.getFleetMember();
289 if (member == null) return false;
291 if (fc == null) fc = member.getFleetCommander();
292 if (fc == null) return false;
293 return fc.isPlayer();
294 }
295
296 public Color getBorderColor() {
297 return null;
298 //return Color.red;
299 }
300
301 public Color getNameColor() {
302 return null;
303 //return Color.red;
304 }
305
306 public int getDisplaySortOrder() {
307// if (spec.getId().equals("hiressensors")) {
308// return 200;
309// }
310 return 100;
311 }
312
314// if (spec.getId().equals("hiressensors")) {
315// return 4;
316// }
317 return -1;
318 }
319
320 public float getTooltipWidth() {
321 return 369f;
322 }
323
325 return true;
326 }
327
329 FleetMemberAPI member, ShipVariantAPI currentVariant, MarketAPI dockedAt,
330 float width, boolean isForModSpec) {
331
333 if (req != null) {
334 float opad = 10f;
335 if (isForModSpec || Global.CODEX_TOOLTIP_MODE) {
336 Color color = Misc.getBasePlayerColor();
337 if (isForModSpec) {
338 color = Misc.getHighlightColor();
339 }
340 String name = req.getDisplayName();
341 String aOrAn = Misc.getAOrAnFor(name);
342 tooltip.addPara("Requires " + aOrAn + " %s to install.",
343 opad, color, name);
344 } else if (currentVariant != null && member != null) {
345 if (currentVariant.hasHullMod(spec.getId())) {
346 if (!currentVariant.getHullSpec().getBuiltInMods().contains(spec.getId())) {
347 Color color = Misc.getPositiveHighlightColor();
348 tooltip.addPara("Using item: " + req.getDisplayName(),
349 color, opad);
350 }
351 } else {
353 member, currentVariant, dockedAt);
354 Color color = Misc.getPositiveHighlightColor();
355 if (available < 1) color = Misc.getNegativeHighlightColor();
356 if (available < 0) available = 0;
357 tooltip.addPara("Requires item: " + req.getDisplayName() + " (" + available + " available)",
358 color, opad);
359 }
360 }
361 }
362
363 }
364
365
366}
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
static SettingsAPI getSettings()
Definition Global.java:57
static boolean CODEX_TOOLTIP_MODE
Definition Global.java:15
void advanceInCombat(ShipAPI ship, float amount)
boolean isSMod(MutableShipStatsAPI stats)
void applyEffectsToFighterSpawnedByShip(ShipAPI fighter, ShipAPI ship, String id)
void addPostDescriptionSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec)
void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id)
boolean shipHasOtherModInCategory(ShipAPI ship, String currMod, String category)
boolean shouldAddDescriptionToTooltip(HullSize hullSize, ShipAPI ship, boolean isForModSpec)
void advanceInCampaign(FleetMemberAPI member, float amount)
boolean isInPlayerFleet(MutableShipStatsAPI stats)
String getDescriptionParam(int index, HullSize hullSize)
void addSModEffectSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec, boolean isForBuildInList)
boolean hasSModEffectSection(HullSize hullSize, ShipAPI ship, boolean isForModSpec)
String getDescriptionParam(int index, HullSize hullSize, ShipAPI ship)
String getSModDescriptionParam(int index, HullSize hullSize)
void addSModSection(TooltipMakerAPI tooltip, HullSize hullSize, ShipAPI ship, float width, boolean isForModSpec, boolean isForBuildInList)
String getSModDescriptionParam(int index, HullSize hullSize, ShipAPI ship)
boolean canBeAddedOrRemovedNow(ShipAPI ship, MarketAPI marketOrNull, CoreUITradeMode mode)
void applyEffectsAfterShipCreation(ShipAPI ship, String id)
boolean showInRefitScreenModPickerFor(ShipAPI ship)
void addRequiredItemSection(TooltipMakerAPI tooltip, FleetMemberAPI member, ShipVariantAPI currentVariant, MarketAPI dockedAt, float width, boolean isForModSpec)
String getCanNotBeInstalledNowReason(ShipAPI ship, MarketAPI marketOrNull, CoreUITradeMode mode)
int getNumAvailableMinusUnconfirmed(CargoStackAPI req, FleetMemberAPI member, ShipVariantAPI currentVariant, MarketAPI dockedAt)
static Color getStoryOptionColor()
Definition Misc.java:782
static Color getStoryDarkColor()
Definition Misc.java:773
static Color getNegativeHighlightColor()
Definition Misc.java:802
static Color setAlpha(Color color, int alpha)
Definition Misc.java:1316
static Color getBasePlayerColor()
Definition Misc.java:833
static String getAOrAnFor(String word)
Definition Misc.java:6160
static boolean CAN_SMOD_BUILT_IN
Definition Misc.java:190
static Color getHighlightColor()
Definition Misc.java:792
static Color scaleColorOnly(Color color, float factor)
Definition Misc.java:1302
static Color getPositiveHighlightColor()
Definition Misc.java:822
HullModSpecAPI getHullModSpec(String modId)
LinkedHashSet< String > getSMods()
LinkedHashSet< String > getSModdedBuiltIns()
String getSModDescription(HullSize hullSize)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
UIComponentAPI addSpacer(float height)
LabelAPI addSectionHeading(String str, Alignment align, float pad)