Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protomech armor validation #1509

Merged
merged 2 commits into from
Oct 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions megamek/src/megamek/common/verifier/TestProtomech.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,14 @@ public static List<EquipmentType> allJJs() {
*
*/
public static enum ProtomechArmor {
STANDARD (EquipmentType.T_ARMOR_STANDARD, true, 0),
EDP (EquipmentType.T_ARMOR_EDP, true, 1);
STANDARD (EquipmentType.T_ARMOR_STANDARD, 0),
EDP (EquipmentType.T_ARMOR_EDP, 1);

private final int type;
private final boolean isClan;
private final int torsoSlots;

ProtomechArmor(int t, boolean c, int slots) {
ProtomechArmor(int t, int slots) {
type = t;
isClan = c;
torsoSlots = slots;
}

Expand All @@ -113,42 +111,54 @@ public static int armorCount() {
}

/**
* Given an armor type, return the {@link ProtomechArmor} instance that
* represents that type.
* Given a protomech, return the {@link ProtomechArmor} instance that
* represents the type installed
*
* @param t The armor type.
* @param c Whether this armor type is Clan or not.
* @return The {@link ProtomechArmor} that corresponds to the given type
* or null if no match was found.
* @param proto The protomech
* @return The {@link ProtomechArmor} that corresponds to the given type
* or null if no match was found.
*/
public static @Nullable ProtomechArmor getArmor(Protomech proto) {
return getArmor(proto.getArmorType(Protomech.LOC_TORSO),
TechConstants.isClan(proto.getArmorTechLevel(Protomech.LOC_TORSO)));
return getArmor(proto.getArmorType(Protomech.LOC_TORSO));
}

/**
* Given an armor type, return the {@link ProtomechArmor} instance that
* represents that type.
*
* @param t The armor type.
* @param c Whether this armor type is Clan or not.
* @return The {@link ProtomechArmor} that corresponds to the given type
* or null if no match was found.
*/
public static @Nullable ProtomechArmor getArmor(int t, boolean c) {
public static @Nullable ProtomechArmor getArmor(int t) {
for (ProtomechArmor a : values()) {
if ((a.type == t) && (a.isClan == c)) {
if (a.type == t) {
return a;
}
}
return null;
}

/**
* Given an armor type, return the {@link ProtomechArmor} instance that
* represents that type.
* @deprecated Use {@link #getArmor(int)} instead

* @param t The armor type.
* @param c Whether the armor has a Clan tech base
* @return The {@link ProtomechArmor} that corresponds to the given type
* or null if no match was found.
*/
@Deprecated
public static @Nullable ProtomechArmor getArmor(int t, boolean c) {
return getArmor(t);
}

/**
* @return The {@link MiscType} for this armor.
*/
public EquipmentType getArmorEqType() {
String name = EquipmentType.getArmorTypeName(type, isClan);
String name = EquipmentType.getArmorTypeName(type, true);
return EquipmentType.get(name);
}

Expand All @@ -158,11 +168,7 @@ public int getType() {

public int getArmorTech() {
EquipmentType eq = getArmorEqType();
return eq.getStaticTechLevel().getCompoundTechLevel(isClan);
}

public boolean isClan() {
return isClan;
return eq.getStaticTechLevel().getCompoundTechLevel(true);
}

public int getTorsoSlots() {
Expand Down