diff --git a/megameklab/src/megameklab/printing/PrintBattleArmor.java b/megameklab/src/megameklab/printing/PrintBattleArmor.java index 8807e2771..0c510ca98 100644 --- a/megameklab/src/megameklab/printing/PrintBattleArmor.java +++ b/megameklab/src/megameklab/printing/PrintBattleArmor.java @@ -96,7 +96,7 @@ protected void writeTextFields() { @Override protected void drawArmor() { - final String armorName = EquipmentType.getBaArmorTypeName(battleArmor.getArmorType(BattleArmor.LOC_SQUAD)); + final String armorName = EquipmentType.getArmorTypeName(battleArmor.getArmorType(BattleArmor.LOC_SQUAD)); setTextField(ARMOR_TYPE, armorName.replace("BA ", "")); for (int i = 0; i < 6; i++) { if (i < battleArmor.getTroopers()) { diff --git a/megameklab/src/megameklab/ui/generalUnit/ArmorAllocationView.java b/megameklab/src/megameklab/ui/generalUnit/ArmorAllocationView.java index 72aa049f4..b2244a8d4 100644 --- a/megameklab/src/megameklab/ui/generalUnit/ArmorAllocationView.java +++ b/megameklab/src/megameklab/ui/generalUnit/ArmorAllocationView.java @@ -31,6 +31,7 @@ import javax.swing.UIManager; import megamek.common.*; +import megamek.common.equipment.ArmorType; import megamek.common.verifier.TestSupportVehicle; import megameklab.ui.generalUnit.ArmorLocationView.ArmorLocationListener; import megameklab.ui.listeners.ArmorAllocationListener; @@ -261,8 +262,7 @@ public void setFromEntity(Entity en) { txtPointsPerTon.setToolTipText(resourceMap.getString("ArmorAllocationView.txtKgPerPoint.tooltip")); } else if (en instanceof Protomech) { txtPointsPerTon.setText(String.format("%d", - (int) (EquipmentType.getProtomechArmorWeightPerPoint(en.getArmorType(Protomech.LOC_BODY)) - * 1000))); + (int) (ArmorType.forEntity(en).getWeightPerPoint() * 1000))); lblPointsPerTon.setText(resourceMap.getString("ArmorAllocationView.txtKgPerPoint.text")); txtPointsPerTon.setToolTipText(resourceMap.getString("ArmorAllocationView.txtKgPerPoint.tooltip")); } else { diff --git a/megameklab/src/megameklab/ui/generalUnit/summary/ArmorSummaryItem.java b/megameklab/src/megameklab/ui/generalUnit/summary/ArmorSummaryItem.java index 6d09409d5..53e101f98 100644 --- a/megameklab/src/megameklab/ui/generalUnit/summary/ArmorSummaryItem.java +++ b/megameklab/src/megameklab/ui/generalUnit/summary/ArmorSummaryItem.java @@ -19,6 +19,7 @@ package megameklab.ui.generalUnit.summary; import megamek.common.*; +import megamek.common.equipment.ArmorType; import megamek.common.verifier.TestAero; import megamek.common.verifier.TestEntity; import megamek.common.verifier.TestSmallCraft; @@ -72,62 +73,34 @@ public void refresh(Entity entity) { } private int getTankArmorCrits(Entity entity) { - //TODO this should be implemented in EquipmentType armor.getCriticals(entity) - int usedSlots = 0; - if (!entity.hasPatchworkArmor()) { - int type = entity.getArmorType(1); - switch (type) { - case EquipmentType.T_ARMOR_FERRO_FIBROUS: - case EquipmentType.T_ARMOR_REACTIVE: - if (TechConstants.isClan(entity.getArmorTechLevel(1))) { - usedSlots++; - } else { - usedSlots += 2; - } - break; - case EquipmentType.T_ARMOR_HEAVY_FERRO: - usedSlots += 3; - break; - case EquipmentType.T_ARMOR_LIGHT_FERRO: - case EquipmentType.T_ARMOR_FERRO_LAMELLOR: - case EquipmentType.T_ARMOR_REFLECTIVE: - case EquipmentType.T_ARMOR_HARDENED: - case EquipmentType.T_ARMOR_ANTI_PENETRATIVE_ABLATION: - case EquipmentType.T_ARMOR_BALLISTIC_REINFORCED: - usedSlots++; - break; - case EquipmentType.T_ARMOR_STEALTH: - usedSlots += 2; - break; - default: - break; - } + if (entity.hasPatchworkArmor()) { + return 0; + } else { + return getArmorType(entity, entity.firstArmorIndex()).getTankSlots(entity); } - - return usedSlots; } private String getFighterCrits(Entity entity) { if (entity.hasPatchworkArmor()) { int slots = 0; for (int loc = 0; loc < Aero.LOC_WINGS; loc++) { - TestAero.AeroArmor aeroArmor = getArmorType(entity, loc); + ArmorType aeroArmor = getArmorType(entity, loc); if (aeroArmor == null) { return "?"; } - slots += aeroArmor.patchworkSpace; + slots += aeroArmor.getPatchworkSlotsCVFtr(); } return formatCrits(slots); } else { - TestAero.AeroArmor aeroArmor = getArmorType(entity, Aero.LOC_NOSE); + ArmorType aeroArmor = getArmorType(entity, Aero.LOC_NOSE); if (aeroArmor == null) { return "?"; } - return formatCrits(aeroArmor.space); + return formatCrits(aeroArmor.getFighterSlots()); } } - private TestAero.AeroArmor getArmorType(Entity entity, int location) { - return TestAero.AeroArmor.getArmor(entity.getArmorType(location), entity.isClanArmor(location)); + private ArmorType getArmorType(Entity entity, int location) { + return ArmorType.of(entity.getArmorType(location), entity.isClanArmor(location)); } } diff --git a/megameklab/src/megameklab/ui/protoMek/PMStructureTab.java b/megameklab/src/megameklab/ui/protoMek/PMStructureTab.java index a7b257128..2ab5926be 100644 --- a/megameklab/src/megameklab/ui/protoMek/PMStructureTab.java +++ b/megameklab/src/megameklab/ui/protoMek/PMStructureTab.java @@ -33,6 +33,7 @@ import megamek.codeUtilities.MathUtility; import megamek.common.*; +import megamek.common.equipment.ArmorType; import megamek.common.verifier.TestEntity; import megamek.common.verifier.TestProtomech; import megamek.common.verifier.TestProtomech.ProtomechArmor; @@ -459,9 +460,7 @@ public void armorTypeChanged(EquipmentType armor) { @Override public void armorFactorChanged(int points) { - double tonnage = EquipmentType.getProtomechArmorWeightPerPoint( - getProtomech().getArmorType(Protomech.LOC_TORSO)) - * points; + double tonnage = ArmorType.forEntity(getProtomech()).getWeightPerPoint() * points; getProtomech().setArmorTonnage(tonnage); panArmorAllocation.setFromEntity(getProtomech()); panSummary.refresh(); @@ -493,7 +492,7 @@ public void useRemainingTonnageArmor() { totalTonnage - currentTonnage, TestEntity.Ceil.KILO); // We can only use remaining tonnage equal to whole points of armor. remainingTonnage = (int) UnitUtil.getRawArmorPoints(getProtomech(), remainingTonnage) - * EquipmentType.getProtomechArmorWeightPerPoint(getProtomech().getArmorType(Protomech.LOC_TORSO)); + * ArmorType.forEntity(getProtomech()).getWeightPerPoint(); double maxArmor = MathUtility.clamp(getProtomech().getLabArmorTonnage() + remainingTonnage, 0, UnitUtil.getMaximumArmorTonnage(getProtomech())); getProtomech().setArmorTonnage(maxArmor); diff --git a/megameklab/src/megameklab/util/UnitUtil.java b/megameklab/src/megameklab/util/UnitUtil.java index cb7a441c2..7c2d9a3ec 100644 --- a/megameklab/src/megameklab/util/UnitUtil.java +++ b/megameklab/src/megameklab/util/UnitUtil.java @@ -20,6 +20,7 @@ import megamek.common.*; import megamek.common.annotations.Nullable; +import megamek.common.equipment.ArmorType; import megamek.common.verifier.*; import megamek.common.verifier.TestEntity.Ceil; import megamek.common.verifier.TestProtomech.ProtomechArmor; @@ -843,8 +844,7 @@ public static double getMaximumArmorTonnage(Entity unit) { return TestAdvancedAerospace.maxArmorWeight((Jumpship) unit); } - double armorPerTon = 16.0 * EquipmentType.getArmorPointMultiplier( - unit.getArmorType(1), unit.getArmorTechLevel(1)); + double armorPerTon = ArmorType.forEntity(unit).getPointsPerTon(unit); double armorWeight = 0; if (unit.getArmorType(1) == EquipmentType.T_ARMOR_HARDENED) { @@ -902,8 +902,7 @@ public static double getMaximumArmorTonnage(Entity unit) { */ public static double getRawArmorPoints(Entity unit, double armorTons) { if (unit.hasETypeFlag(Entity.ETYPE_PROTOMECH)) { - return Math.round(armorTons / - EquipmentType.getProtomechArmorWeightPerPoint(unit.getArmorType(Protomech.LOC_TORSO))); + return Math.round(armorTons / ArmorType.forEntity(unit).getWeightPerPoint()); } else if (unit.isSupportVehicle()) { return Math.floor(armorTons / TestSupportVehicle.armorWeightPerPoint(unit)); } else if ((unit instanceof Jumpship) @@ -934,7 +933,7 @@ public static double getSIBonusArmorPoints(Entity entity) { points = Math.round(((Jumpship) entity).getSI() / 10.0) * 6; } if (entity.isPrimitive()) { - return points * EquipmentType.getArmorPointMultiplier(EquipmentType.T_ARMOR_PRIMITIVE_AERO); + return points * ArmorType.of(EquipmentType.T_ARMOR_PRIMITIVE_AERO, false).getArmorPointsMultiplier(); } else { return points; } @@ -953,23 +952,6 @@ public static int getArmorPoints(Entity unit, double armorTons) { return Math.min(raw, UnitUtil.getMaximumArmorPoints(unit)); } - /** - * NOTE: only use for non-patchwork armor - * - * @param unit The entity - * @param armorTons - * @return - */ - public static int getArmorPoints(Entity unit, int loc, double armorTons) { - double armorPerTon = 16.0 * EquipmentType.getArmorPointMultiplier( - unit.getArmorType(loc), unit.getArmorTechLevel(loc)); - if (unit.getArmorType(loc) == EquipmentType.T_ARMOR_HARDENED) { - armorPerTon = 8.0; - } - return Math.min((int) Math.floor(armorPerTon * armorTons), - UnitUtil.getMaximumArmorPoints(unit, loc)); - } - /** * Calculate the number of armor points per ton of armor for the given unit. * @@ -980,15 +962,7 @@ public static int getArmorPoints(Entity unit, int loc, double armorTons) { */ // TODO: aerospace and support vehicle armor public static double getArmorPointsPerTon(Entity en, int at, boolean clanArmor) { - if (at == EquipmentType.T_ARMOR_HARDENED) { - return 8.0; - } else if (en.hasETypeFlag(Entity.ETYPE_JUMPSHIP)) { - return TestAdvancedAerospace.armorPointsPerTon((Jumpship) en, at, clanArmor); - } else if (en.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) { - return SmallCraft.armorPointsPerTon(en.getWeight(), ((Aero) en).isSpheroid(), at, clanArmor); - } else { - return 16.0 * EquipmentType.getArmorPointMultiplier(at, clanArmor); - } + return ArmorType.of(at, clanArmor).getPointsPerTon(en); } /**