Skip to content

Commit

Permalink
Merge pull request #1402 from MegaMek/armor_rework
Browse files Browse the repository at this point in the history
Armor rework, part 1a
  • Loading branch information
SJuliez authored Feb 1, 2024
2 parents 43e80e1 + e3cc82f commit 0c417f0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 76 deletions.
2 changes: 1 addition & 1 deletion megameklab/src/megameklab/printing/PrintBattleArmor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
7 changes: 3 additions & 4 deletions megameklab/src/megameklab/ui/protoMek/PMStructureTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 5 additions & 31 deletions megameklab/src/megameklab/util/UnitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand All @@ -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.
*
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 0c417f0

Please sign in to comment.