Starsector API
Loading...
Searching...
No Matches
BaseLogisticsHullMod.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.hullmods;
2
3import com.fs.starfarer.api.Global;
4import com.fs.starfarer.api.combat.BaseHullMod;
5import com.fs.starfarer.api.combat.ShipAPI;
6import com.fs.starfarer.api.impl.campaign.ids.HullMods;
7import com.fs.starfarer.api.impl.campaign.ids.Stats;
8import com.fs.starfarer.api.loading.HullModSpecAPI;
9
10public class BaseLogisticsHullMod extends BaseHullMod {
11
12 public static int MAX_MODS = Global.getSettings().getInt("maxLogisticsHullmods");
13
14 public int getMax(ShipAPI ship) {
15 return (int) Math.round(ship.getMutableStats().getDynamic().getMod(Stats.MAX_LOGISTICS_HULLMODS_MOD).computeEffective(MAX_MODS));
16 }
17
18 @Override
19 public String getUnapplicableReason(ShipAPI ship) {
20 boolean has = spec != null && ship.getVariant().hasHullMod(spec.getId());
21 int num = getNumLogisticsMods(ship);
22 if (has) num--;
23 int max = getMax(ship);
24 if (num >= max) {
25 String text = "many";
26 if (max == 1) text = "one";
27 else if (max == 2) text = "two";
28 else if (max == 3) text = "three";
29 else if (max == 4) text = "four";
30
31// text = "" + MAX_MODS;
32 text = "" + max;
33 if (max == MAX_MODS) {
34 return "Maximum of " + text + " non-built-in \"Logistics\" hullmods per hull";
35 } else {
36 return "Maximum of " + text + " non-built-in \"Logistics\" hullmods for this hull";
37 }
38 }
39 return super.getUnapplicableReason(ship);
40 }
41
42 @Override
43 public boolean isApplicableToShip(ShipAPI ship) {
44 boolean has = spec != null && ship.getVariant().hasHullMod(spec.getId());
45 int num = getNumLogisticsMods(ship);
46 if (has) num--;
47 int max = getMax(ship);
48 if (num >= max) {
49 return false;
50 }
51 return super.isApplicableToShip(ship);
52 }
53
54 protected int getNumLogisticsMods(ShipAPI ship) {
55 //int num = (int) Math.round(ship.getMutableStats().getDynamic().getMod(NUM_LOGISTICS_MODS).computeEffective(0));
56 int num = 0;
57 for (String id : ship.getVariant().getHullMods()) {
58 if (ship.getHullSpec().isBuiltInMod(id)) continue;
59 if (ship.getVariant().getPermaMods().contains(id)) continue;
60
61 HullModSpecAPI mod = Global.getSettings().getHullModSpec(id);
62 if (mod.hasUITag(HullMods.TAG_UI_LOGISTICS)) {
63 //if (mod.hasUITag(HullMods.TAG_REQ_SPACEPORT)) {
64 num++;
65 }
66 }
67 return num;
68 }
69
70
71}
72
73
static SettingsAPI getSettings()
Definition Global.java:51
HullModSpecAPI getHullModSpec(String modId)