001package com.fs.starfarer.api.impl.hullmods; 002 003import com.fs.starfarer.api.Global; 004import com.fs.starfarer.api.combat.BaseHullMod; 005import com.fs.starfarer.api.combat.ShipAPI; 006import com.fs.starfarer.api.impl.campaign.ids.HullMods; 007import com.fs.starfarer.api.impl.campaign.ids.Stats; 008import com.fs.starfarer.api.loading.HullModSpecAPI; 009 010public class BaseLogisticsHullMod extends BaseHullMod { 011 012 public static int MAX_MODS = Global.getSettings().getInt("maxLogisticsHullmods"); 013 014 public int getMax(ShipAPI ship) { 015 return (int) Math.round(ship.getMutableStats().getDynamic().getMod(Stats.MAX_LOGISTICS_HULLMODS_MOD).computeEffective(MAX_MODS)); 016 } 017 018 @Override 019 public String getUnapplicableReason(ShipAPI ship) { 020 boolean has = spec != null && ship.getVariant().hasHullMod(spec.getId()); 021 int num = getNumLogisticsMods(ship); 022 if (has) num--; 023 int max = getMax(ship); 024 if (num >= max) { 025 String text = "many"; 026 if (max == 1) text = "one"; 027 else if (max == 2) text = "two"; 028 else if (max == 3) text = "three"; 029 else if (max == 4) text = "four"; 030 031// text = "" + MAX_MODS; 032 text = "" + max; 033 if (max == MAX_MODS) { 034 return "Maximum of " + text + " non-built-in \"Logistics\" hullmods per hull"; 035 } else { 036 return "Maximum of " + text + " non-built-in \"Logistics\" hullmods for this hull"; 037 } 038 } 039 return super.getUnapplicableReason(ship); 040 } 041 042 @Override 043 public boolean isApplicableToShip(ShipAPI ship) { 044 boolean has = spec != null && ship.getVariant().hasHullMod(spec.getId()); 045 int num = getNumLogisticsMods(ship); 046 if (has) num--; 047 int max = getMax(ship); 048 if (num >= max) { 049 return false; 050 } 051 return super.isApplicableToShip(ship); 052 } 053 054 protected int getNumLogisticsMods(ShipAPI ship) { 055 //int num = (int) Math.round(ship.getMutableStats().getDynamic().getMod(NUM_LOGISTICS_MODS).computeEffective(0)); 056 int num = 0; 057 for (String id : ship.getVariant().getHullMods()) { 058 if (ship.getHullSpec().isBuiltInMod(id)) continue; 059 if (ship.getVariant().getPermaMods().contains(id)) continue; 060 061 HullModSpecAPI mod = Global.getSettings().getHullModSpec(id); 062 if (mod.hasUITag(HullMods.TAG_UI_LOGISTICS)) { 063 //if (mod.hasUITag(HullMods.TAG_REQ_SPACEPORT)) { 064 num++; 065 } 066 } 067 return num; 068 } 069 070 071} 072 073