Skip to content

Commit

Permalink
Merge pull request #5101 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 34c4647 + 05e5ce3 commit 358bcb5
Show file tree
Hide file tree
Showing 18 changed files with 1,682 additions and 2,039 deletions.
13 changes: 5 additions & 8 deletions megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import megamek.common.annotations.Nullable;
import megamek.common.battlevalue.BVCalculator;
import megamek.common.enums.*;
import megamek.common.equipment.ArmorType;
import megamek.common.event.GameEntityChangeEvent;
import megamek.common.force.Force;
import megamek.common.icons.Camouflage;
Expand Down Expand Up @@ -10808,10 +10809,8 @@ public boolean removePartialCoverHits(int location, int cover, int side) {
* @return The weight of the armor in the location in tons.
*/
public double getArmorWeight(int loc) {
double armorPerTon = 16.0 * EquipmentType.getArmorPointMultiplier(
armorType[loc], armorTechLevel[loc]);
double points = getOArmor(loc)
+ (hasRearArmor(loc) ? getOArmor(loc, true) : 0);
double armorPerTon = ArmorType.forEntity(this, loc).getPointsPerTon(this);
double points = getOArmor(loc) + (hasRearArmor(loc) ? getOArmor(loc, true) : 0);
return points / armorPerTon;
}

Expand All @@ -10836,8 +10835,7 @@ && getArmorType(firstArmorIndex()) == EquipmentType.T_ARMOR_STANDARD) {
} else {
// this roundabout method is actually necessary to avoid rounding
// weirdness. Yeah, it's dumb.
double armorPerTon = 16.0 * EquipmentType.getArmorPointMultiplier(
armorType[0], armorTechLevel[0]);
double armorPerTon = ArmorType.forEntity(this).getPointsPerTon(this);
return RoundWeight.standard(getTotalOArmor() / armorPerTon, this);
}
}
Expand Down Expand Up @@ -14131,8 +14129,7 @@ public int getLabTotalArmorPoints() {
/ EquipmentType.getSupportVehicleArmorWeightPerPoint(getBARRating(firstArmorIndex()),
getArmorTechRating()));
}
double armorPerTon = 16.0 * EquipmentType.getArmorPointMultiplier(
armorType[0], armorTechLevel[0]);
double armorPerTon = ArmorType.forEntity(this).getPointsPerTon(this);
return (int) Math.floor(armorPerTon * armorTonnage);
}

Expand Down
164 changes: 20 additions & 144 deletions megamek/src/megamek/common/EquipmentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package megamek.common;

import megamek.common.annotations.Nullable;
import megamek.common.equipment.ArmorType;
import megamek.common.options.GameOptions;
import megamek.common.weapons.autocannons.HVACWeapon;
import megamek.common.weapons.defensivepods.BPodWeapon;
Expand Down Expand Up @@ -130,17 +131,6 @@ public class EquipmentType implements ITechnology {
12500, 12000, 15000, 20000, 50000, 10000, 15000, 37000, 37000, 5000,
5000, 10000};

public static final double[] armorPointMultipliers = {
1, 1.12, 1, 1, 0.5, 1.06, 1.24, 1, 1, 1.12,
1.5, 1.52, 1.72, 1.32, 0.67, 1.0, 0.875, 0.67, 1, 1.12,
1.24, 1.06, 1, 0.75, 0.625, 0.875, 0.75, 1.12, 0.8, 1.6,
0.64, 0.48, 0.96, 0.96, 1.6, 0.48, 0.8, 0.88, 0.96, 0.67,
0.66, 1 };

public static final double POINT_MULTIPLIER_UNKNOWN = 1;
public static final double POINT_MULTIPLIER_CLAN_FF = 1.2;
public static final double POINT_ADDITION_CLAN_FF = 0.08;

protected String name = null;

// Short name for RS Printing
Expand Down Expand Up @@ -729,6 +719,7 @@ public static void initializeTypes() {
MiscType.initializeTypes();
BombType.initializeTypes();
SmallWeaponAmmoType.initializeTypes();
ArmorType.initializeTypes();
for (EquipmentType et : allTypes) {
if (et.getTechAdvancement().getStaticTechLevel() == null) {
et.getTechAdvancement().setStaticTechLevel(et.getTechAdvancement()
Expand Down Expand Up @@ -761,43 +752,42 @@ protected static void addType(EquipmentType type) {
}

public static int getArmorType(EquipmentType et) {
if (null == et) {
if (et instanceof ArmorType) {
return ((ArmorType) et).getArmorType();
} else {
return T_ARMOR_UNKNOWN;
}
for (int x = 0; x < armorNames.length; x++) {
// Some armor names (Industrial), have a space in the name, so trim
if (armorNames[x].trim().equals(et.getName().trim())) {
return x;
}
}
return T_ARMOR_UNKNOWN;
}

public static String getArmorTypeName(int armorType) {
if ((armorType < 0) || (armorType >= armorNames.length)) {
ArmorType armor = ArmorType.of(armorType, false);
if (armor == null) {
armor = ArmorType.of(armorType, true);
}
if (armor != null) {
return armor.getName();
} else {
return "UNKNOWN";
}
return armorNames[armorType];
}

public static String getArmorTypeName(int armorType, boolean clan) {
if ((armorType < 0) || (armorType >= armorNames.length)) {
ArmorType armor = ArmorType.of(armorType, clan);
if (armor != null) {
return clan ? "Clan " + armor.getName() : "IS " + armor.getName();
} else {
return "UNKNOWN";
}
return clan ? "Clan " + armorNames[armorType] : "IS "
+ armorNames[armorType];
}

/**
* Convenience method to test whether an EquipmentType instance is armor. This works
* by comparing the results of {@link #getName()} to the armor names array and returning
* {@code true} if there is a match.
* Convenience method to test whether an EquipmentType instance is armor.
*
* @param et The equipment instance to test
* @return Whether the equipment is an armor type
*/
public static boolean isArmorType(EquipmentType et) {
return getArmorType(et) != T_ARMOR_UNKNOWN;
return et instanceof ArmorType;
}

public static int getStructureType(EquipmentType et) {
Expand Down Expand Up @@ -839,75 +829,6 @@ public static boolean isStructureType(EquipmentType et) {
return getStructureType(et) != T_STRUCTURE_UNKNOWN;
}

public static String getBaArmorTypeName(int armorType) {
return getArmorTypeName(armorType);
}

public static String getBaArmorTypeName(int armorType, boolean clan) {
return getArmorTypeName(armorType, clan);
}

public static double getBaArmorWeightPerPoint(int type, boolean isClan) {
switch (type) {
case T_ARMOR_BA_STANDARD_PROTOTYPE:
return 0.1;
case T_ARMOR_BA_STANDARD_ADVANCED:
return 0.04;
case T_ARMOR_BA_STEALTH:
if (isClan) {
return 0.035;
}
return 0.06;
case T_ARMOR_BA_STEALTH_BASIC:
if (isClan) {
return 0.03;
}
return 0.055;
case T_ARMOR_BA_STEALTH_IMP:
if (isClan) {
return 0.035;
}
return 0.06;
case T_ARMOR_BA_STEALTH_PROTOTYPE:
return 0.1;
case T_ARMOR_BA_FIRE_RESIST:
return 0.03;
case T_ARMOR_BA_MIMETIC:
return 0.05;
case T_ARMOR_BA_REFLECTIVE:
if (isClan) {
return 0.03;
} else {
return 0.055;
}
case T_ARMOR_BA_REACTIVE:
if (isClan) {
return 0.035;
} else {
return 0.06;
}
case T_ARMOR_BA_STANDARD:
default:
if (isClan) {
return 0.025;
}
return 0.05;
}
}

/**
* Computes protomech armor weight by point.
*
* @param type The armor type
* @return The weight of a point of armor in kg
*/
public static double getProtomechArmorWeightPerPoint(int type) {
if (type == T_ARMOR_EDP) {
return 0.075;
}
return 0.05;
}

/**
* Lookup method for protomech armor cost
* @param type The type of armor.
Expand Down Expand Up @@ -977,10 +898,6 @@ public static double getSupportVehicleArmorCostPerPoint(int bar) {
* does not have its own TechAdvancement.
*/

protected static final TechAdvancement TA_STANDARD_ARMOR = new TechAdvancement(TECH_BASE_ALL)
.setAdvancement(2460, 2470, 2470).setApproximate(true, false, false)
.setTechRating(RATING_D).setAvailability(RATING_C, RATING_C, RATING_C, RATING_B)
.setStaticTechLevel(SimpleTechLevel.INTRO);
protected static final TechAdvancement TA_STANDARD_STRUCTURE = new TechAdvancement(TECH_BASE_ALL)
.setAdvancement(2430, 2439, 2505).setApproximate(true, false, false).setIntroLevel(true)
.setTechRating(RATING_D).setAvailability(RATING_C, RATING_C, RATING_C, RATING_C)
Expand Down Expand Up @@ -1037,15 +954,8 @@ public static double getSupportVehicleArmorCostPerPoint(int bar) {
* @return The tech advancement for the armor
*/
public static TechAdvancement getArmorTechAdvancement(int at, boolean clan) {
if (at == T_ARMOR_STANDARD) {
return TA_STANDARD_ARMOR;
}
String armorName = EquipmentType.getArmorTypeName(at, clan);
EquipmentType armor = EquipmentType.get(armorName);
if (armor != null) {
return armor.getTechAdvancement();
}
return TA_NONE;
ArmorType armor = ArmorType.of(at, clan);
return (armor == null) ? TA_NONE : armor.getTechAdvancement();
}

/**
Expand Down Expand Up @@ -1232,40 +1142,6 @@ public static double getStructureCost(int inStructure) {
return structureCosts[inStructure];
}

public static double getArmorPointMultiplier(int inArmor) {
return EquipmentType.getArmorPointMultiplier(inArmor,
TechConstants.T_IS_TW_NON_BOX);
}

public static double getArmorPointMultiplier(int inArmor, int inTechLevel) {
return EquipmentType
.getArmorPointMultiplier(
inArmor,
((inTechLevel == TechConstants.T_CLAN_TW) || (inTechLevel == TechConstants.T_CLAN_ADVANCED))
|| (inTechLevel == TechConstants.T_CLAN_EXPERIMENTAL)
|| (inTechLevel == TechConstants.T_CLAN_UNOFFICIAL));
}

public static double getArmorPointMultiplier(int inArmor, boolean clanArmor) {
if ((inArmor < 0) || (inArmor >= armorPointMultipliers.length)) {
return POINT_MULTIPLIER_UNKNOWN;
}
/*
* now handled in a single if statement
if ((inArmor == T_ARMOR_FERRO_FIBROUS) && clanArmor) {
return POINT_MULTIPLIER_CLAN_FF;
}
if ((inArmor == T_ARMOR_ALUM) && clanArmor) {
return POINT_MULTIPLIER_CLAN_FF;
}*/
// Clan armors of these types have a multiplier exactly 0.08 higher than the I.S. variety
if (clanArmor && ((inArmor == T_ARMOR_ALUM) || (inArmor == T_ARMOR_FERRO_FIBROUS))) {
return armorPointMultipliers[inArmor] + POINT_ADDITION_CLAN_FF;

}
return armorPointMultipliers[inArmor];
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand Down
20 changes: 2 additions & 18 deletions megamek/src/megamek/common/Jumpship.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import megamek.client.ui.swing.calculationReport.CalculationReport;
import megamek.common.cost.JumpShipCostCalculator;
import megamek.common.equipment.ArmorType;
import megamek.common.options.OptionsConstants;

import java.util.ArrayList;
Expand Down Expand Up @@ -1144,26 +1145,9 @@ public double getArmorWeight(int locCount) {
armorPoints -= Math.round(get0SI() / 10.0) * locCount;
} else {
armorPoints -= Math.floor(Math.round(get0SI() / 10.0) * locCount * 0.66);
armorPoints = Math.ceil(armorPoints / 0.66);
}

// now I need to determine base armor points by type and weight
boolean clan = TechConstants.isClan(getArmorTechLevel(firstArmorIndex()));
double baseArmor = clan ? 1.0 : 0.8;

if (weight >= 250000) {
baseArmor = clan ? 0.5 : 0.4;
} else if (weight >= 150000) {
baseArmor = clan ? 0.7 : 0.6;
}

if (armorType[0] == EquipmentType.T_ARMOR_LC_FERRO_IMP) {
baseArmor += 0.2;
} else if (armorType[0] == EquipmentType.T_ARMOR_LC_FERRO_CARBIDE) {
baseArmor += 0.4;
} else if (armorType[0] == EquipmentType.T_ARMOR_LC_LAMELLOR_FERRO_CARBIDE) {
baseArmor += 0.6;
}
double baseArmor = ArmorType.forEntity(this).getPointsPerTon(this);

return RoundWeight.standard(armorPoints / baseArmor, this);
}
Expand Down
3 changes: 1 addition & 2 deletions megamek/src/megamek/common/MechView.java
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,7 @@ private List<ViewElement> getInternalAndArmor() {
.trim());
}
if (isBA) {
armor += " " + EquipmentType.getBaArmorTypeName(entity.getArmorType(1))
.trim();
armor += " " + EquipmentType.getArmorTypeName(entity.getArmorType(1)).trim();
}
retVal.add(new LabeledElement(Messages.getString("MechView.Armor"),
armor));
Expand Down
Loading

0 comments on commit 358bcb5

Please sign in to comment.