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