Starsector API
Loading...
Searching...
No Matches
BulkTransport.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.skills;
2
3import com.fs.starfarer.api.campaign.FleetDataAPI;
4import com.fs.starfarer.api.characters.MutableCharacterStatsAPI;
5import com.fs.starfarer.api.characters.ShipSkillEffect;
6import com.fs.starfarer.api.characters.SkillSpecAPI;
7import com.fs.starfarer.api.combat.MutableShipStatsAPI;
8import com.fs.starfarer.api.combat.MutableStat.StatMod;
9import com.fs.starfarer.api.combat.ShipAPI.HullSize;
10import com.fs.starfarer.api.combat.StatBonus;
11import com.fs.starfarer.api.fleet.FleetMemberAPI;
12import com.fs.starfarer.api.ui.TooltipMakerAPI;
13
14public class BulkTransport {
15
16 public static float CARGO_CAPACITY_MAX_PERCENT = 50;
17 public static float CARGO_CAPACITY_THRESHOLD = 2000;
18
19 public static float FUEL_CAPACITY_MAX_PERCENT = 50;
20 public static float FUEL_CAPACITY_THRESHOLD = 2000;
21
22 public static float PERSONNEL_CAPACITY_MAX_PERCENT = 50;
23 public static float PERSONNEL_CAPACITY_THRESHOLD = 5000;
24
25 public static float BURN_BONUS = 2;
26
27 public static class Level4 extends BaseSkillEffectDescription implements ShipSkillEffect {
28 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
29 if (isCivilian(stats)) {
30 stats.getMaxBurnLevel().modifyFlat(id, BURN_BONUS);
31 }
32 }
33
34 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
35 stats.getMaxBurnLevel().unmodifyFlat(id);
36 }
37
38 @Override
39 public boolean hasCustomDescription() {
40 return false;
41 }
42
43 public String getEffectDescription(float level) {
44 return "Increases the burn level of all non-militarized civilian-grade ships by " + (int) BURN_BONUS;
45 }
46
47 public ScopeDescription getScopeDescription() {
48 return ScopeDescription.ALL_SHIPS;
49 }
50 }
51
52 public abstract static class BaseCapacityModifierEffect extends BaseSkillEffectDescription implements ShipSkillEffect {
53 protected abstract String getModifierId();
54 protected abstract String getCacheKey();
55 protected abstract String getCapacityString();
56 protected abstract float getCapacity(FleetMemberAPI member);
57 protected abstract float getMaxPercent();
58 protected abstract float getThreshold();
59 protected abstract StatBonus getShipStat(MutableShipStatsAPI stats);
60 protected abstract boolean withSpacerAfter();
61
62 public void apply(MutableShipStatsAPI stats, HullSize hullSize, String id, float level) {
63 id = getModifierId();
64 float capBonus = getCapacityBonus(id, getFleetData(stats));
65 getShipStat(stats).modifyMult(id, 1f + (capBonus / 100f));
66 }
67
68 public void unapply(MutableShipStatsAPI stats, HullSize hullSize, String id) {
69 id = getModifierId();
70 getShipStat(stats).unmodifyMult(id);
71 }
72
73 public String getEffectDescription(float level) {
74 return null;
75 }
76
77 protected float getCapacityBase(String id, FleetDataAPI data) {
78 if (data == null) return 0f;
79
80 float cap = 0;
81 for (FleetMemberAPI curr : data.getMembersListCopy()) {
82 cap += getCapacityBase(id, curr);
83 }
84 return cap;
85 }
86
87 protected float getCapacityBase(String id, FleetMemberAPI curr) {
88 StatBonus stat = getShipStat(curr.getStats());
89 StatMod mod = stat.getMultBonus(id);
90 if (mod != null) {
91 stat.unmodifyMult(mod.source);
92 }
93 float cap = getCapacity(curr);
94 if (mod != null) {
95 stat.modifyMult(mod.source, mod.value, mod.desc);
96 }
97 return cap;
98 }
99
100 protected float getCapacityBonus(String id, FleetDataAPI data) {
101 if (data == null) return getMaxPercent();
102
103 String key = getCacheKey();
104 Float bonus = (Float) data.getCacheClearedOnSync().get(key);
105 if (bonus != null) return bonus;
106
107 float base = getCapacityBase(id, data);
108
109 bonus = getThresholdBasedRoundedBonus(getMaxPercent(), base, getThreshold());
110 //float capMult = 0f;
111// if (base > 0) {
112// float addCapacity = Math.min(base * (getMaxPercent() * 0.01f), getMaxUnits());
113// capMult = 1f + addCapacity / base;
114// capMult = Math.round(capMult * 100f) / 100f;
115// }
116
117 data.getCacheClearedOnSync().put(key, bonus);
118 return bonus;
119 }
120
121 public void createCustomDescription(MutableCharacterStatsAPI stats, SkillSpecAPI skill,
122 TooltipMakerAPI info, float width) {
123 init(stats, skill);
124
125// //info.addSpacer(5f);
126// info.addPara(getCapacityString() + " increased by %s or %s units, whichever is lower",
127// 0f, hc, hc,
128// "" + (int) getMaxPercent() + "%",
129// "" + (int) getThreshold()
130// );
131
132 FleetDataAPI data = getFleetData(null);
133 float capBonus = getCapacityBonus(getModifierId(), data);;
134
135 info.addPara("+%s " + getCapacityString().toLowerCase() + " (maximum: %s)", 0f, hc, hc,
136 "" + (int)(Math.round(capBonus)) + "%",
137 "" + (int) getMaxPercent() + "%");
138
139
140 if (isInCampaign()) {
141 float baseCap = getCapacityBase(getModifierId(), data);
142 info.addPara(indent + "Maximum at %s or less base " + getCapacityString().toLowerCase() +
143 " in fleet, your fleet has %s base " + getCapacityString().toLowerCase(),
144 0f, tc, hc,
145 "" + (int) getThreshold(),
146 "" + (int)Math.round(baseCap));
147 } else {
148 info.addPara(indent + "Maximum at %s or less base " + getCapacityString().toLowerCase() +
149 " in fleet",
150 0f, tc, hc,
151 "" + (int) getThreshold());
152 }
153
154 if (withSpacerAfter()) {
155 info.addSpacer(5f);
156 }
157
158// if (isInCampaign()) {
159// FleetDataAPI data = Global.getSector().getPlayerFleet().getFleetData();
160// String id = getModifierId();
161// float baseCap = getCapacityBase(id, data);
162// float capMult = getCapacityMult(id, data);
163//
164// float increase = baseCap * (capMult - 1f);
165// float actual = increase;
166// boolean approximate = false;
167//
171// if (data != null) {
172// actual = 0f;
173//
174// for (FleetMemberAPI curr : data.getMembersListCopy()) {
175// float base = getCapacityBase(id, curr);
176// float add = (int)(base * capMult - base);
177// actual += add;
178// }
179// if (actual != increase) {
180// approximate = true;
181// }
182// }
183//
184// boolean has = stats.getSkillLevel(skill.getId()) > 0;
185// String is = "is";
186// if (!has) is = "would be";
187// String by = "by";
188// String units = "%s units";
189// if (approximate) {
190// //units = "approximately %s units";
191// by = "by approximately";
192// increase = actual;
193// }
194// info.addPara(indent + "Your fleet has a base " + getCapacityString().toLowerCase() +
195// " of %s, which " + is + " increased " + by + " %s, or " + units,
196// 0f, tc, hc,
197// "" + Misc.getRoundedValueMaxOneAfterDecimal(baseCap),
198// "" + (int)(Math.round((capMult - 1f) * 100f)) + "%",
199// "" + (int)increase
200// );
201// if (withSpacerAfter()) {
202// info.addSpacer(5f);
203// }
204// }
205 }
206
207 public ScopeDescription getScopeDescription() {
208 return ScopeDescription.FLEET;
209 }
210 }
211
212
213
214 public static class Level1 extends BaseCapacityModifierEffect {
215 public String getModifierId() {
216 return "bt_cargo_cap_mod";
217 }
218 public String getCacheKey() {
219 return "bt_cargo_cap";
220 }
221 public StatBonus getShipStat(MutableShipStatsAPI stats) {
222 return stats.getCargoMod();
223 }
224 public float getCapacity(FleetMemberAPI member) {
225 return member.getCargoCapacity();
226 }
227 @Override
228 public String getCapacityString() {
229 return "Cargo capacity";
230 }
231 @Override
232 public float getMaxPercent() {
234 }
235 @Override
236 public float getThreshold() {
238 }
239 @Override
240 public boolean withSpacerAfter() {
241 return true;
242 }
243 }
244
245 public static class Level2 extends BaseCapacityModifierEffect {
246 public String getModifierId() {
247 return "bt_fuel_cap_mod";
248 }
249 public String getCacheKey() {
250 return "bt_fuel_cap";
251 }
252 public StatBonus getShipStat(MutableShipStatsAPI stats) {
253 return stats.getFuelMod();
254 }
255 public float getCapacity(FleetMemberAPI member) {
256 return member.getFuelCapacity();
257 }
258 @Override
259 public String getCapacityString() {
260 return "Fuel capacity";
261 }
262 @Override
263 public float getMaxPercent() {
265 }
266 @Override
267 public float getThreshold() {
269 }
270 @Override
271 public boolean withSpacerAfter() {
272 return true;
273 }
274 }
275
276 public static class Level3 extends BaseCapacityModifierEffect {
277 public String getModifierId() {
278 return "bt_crew_cap_mod";
279 }
280 public String getCacheKey() {
281 return "bt_crew_cap";
282 }
283 public StatBonus getShipStat(MutableShipStatsAPI stats) {
284 return stats.getMaxCrewMod();
285 }
286 public float getCapacity(FleetMemberAPI member) {
287 return member.getMaxCrew();
288 }
289 @Override
290 public String getCapacityString() {
291 return "Personnel capacity";
292 }
293 @Override
294 public float getMaxPercent() {
296 }
297 @Override
298 public float getThreshold() {
300 }
301 @Override
302 public boolean withSpacerAfter() {
303 return true;
304 }
305 }
306
307}
308
309
310
void init(MutableCharacterStatsAPI stats, SkillSpecAPI skill)
float getThresholdBasedRoundedBonus(float maxBonus, float value, float threshold)