Skip to content

Commit

Permalink
Code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Oct 1, 2023
1 parent e685195 commit 75e9ca7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 129 deletions.
62 changes: 15 additions & 47 deletions megamek/src/megamek/common/verifier/TestAdvancedAerospace.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TestAdvancedAerospace extends TestAero {

private final Jumpship vessel;

public enum CapitalArmor{
public enum CapitalArmor {
PRIMITIVE(EquipmentType.T_ARMOR_PRIMITIVE_AERO, false),
STANDARD(EquipmentType.T_ARMOR_AEROSPACE, false),
CLAN_STANDARD(EquipmentType.T_ARMOR_AEROSPACE, true),
Expand All @@ -47,12 +47,12 @@ public enum CapitalArmor{
* The type, corresponding to types defined in
* <code>EquipmentType</code>.
*/
public int type;
public final int type;

/**
* Denotes whether this armor is Clan or not.
*/
public boolean isClan;
public final boolean isClan;

CapitalArmor(int t, boolean c) {
type = t;
Expand Down Expand Up @@ -405,26 +405,6 @@ public Entity getEntity() {
return vessel;
}

@Override
public boolean isTank() {
return false;
}

@Override
public boolean isMech() {
return false;
}

@Override
public boolean isAero() {
return true;
}

@Override
public boolean isSmallCraft() {
return false;
}

@Override
public boolean isAdvancedAerospace() {
return true;
Expand Down Expand Up @@ -657,20 +637,14 @@ public boolean hasDoubleHeatSinks() {

@Override
public String printWeightControls() {
StringBuffer retVal = new StringBuffer(StringUtil.makeLength(
"Control Systems:", getPrintSize() - 5));
retVal.append(makeWeightString(getWeightControls()));
retVal.append("\n");
return retVal.toString();
return StringUtil.makeLength("Control Systems:", getPrintSize() - 5)
+ makeWeightString(getWeightControls()) + "\n";
}

@Override
public String printWeightFuel() {
StringBuffer retVal = new StringBuffer(StringUtil.makeLength(
"Fuel: ", getPrintSize() - 5));
retVal.append(makeWeightString(getWeightFuel()));
retVal.append("\n");
return retVal.toString();
return StringUtil.makeLength("Fuel: ", getPrintSize() - 5)
+ makeWeightString(getWeightFuel()) + "\n";
}

@Override
Expand All @@ -682,16 +656,11 @@ public Jumpship getAdvancedAerospace() {
return vessel;
}

@Override
public String printArmorLocProp(int loc, int wert) {
return " is greater than " + wert + "!";
}

/**
* Checks to see if this unit has valid armor assignment.
*
* @param buff
* @return
* @param buff The StringBuffer to receive error descriptions
* @return False when something is invalid, true otherwise
*/
@Override
public boolean correctArmor(StringBuffer buff) {
Expand All @@ -711,16 +680,16 @@ public boolean correctArmor(StringBuffer buff) {
/**
* Checks that the heatsink type is a legal value.
*
* @param buff
* @return
* @param buff The StringBuffer to receive error descriptions
* @return False when something is invalid, true otherwise
*/
@Override
public boolean correctHeatSinks(StringBuffer buff) {
if ((vessel.getHeatType() != Aero.HEAT_SINGLE)
&& (vessel.getHeatType() != Aero.HEAT_DOUBLE)) {
buff.append("Invalid heatsink type! Valid types are "
+ Aero.HEAT_SINGLE + " and " + Aero.HEAT_DOUBLE
+ ". Found " + vessel.getHeatType() + ".");
buff.append("Invalid heatsink type! Valid types are " + Aero.HEAT_SINGLE + " and "
+ Aero.HEAT_DOUBLE + ". Found ")
.append(vessel.getHeatType()).append(".");
return false;
}
return true;
Expand All @@ -741,8 +710,7 @@ public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
if (getCountHeatSinks() < weightFreeHeatSinks(vessel)) {
buff.append("Heat Sinks:\n");
buff.append(" Total " + getCountHeatSinks() + "\n");
buff.append(" Required " + weightFreeHeatSinks(vessel)
+ "\n");
buff.append(" Required " + weightFreeHeatSinks(vessel) + "\n");
correct = false;
}

Expand Down
41 changes: 14 additions & 27 deletions megamek/src/megamek/common/verifier/TestAero.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* @author Reinhard Vicinus
*/
public class TestAero extends TestEntity {
private Aero aero = null;
private Aero aero;

/**
* An enumeration that keeps track of the legal armors for Aerospace and
Expand All @@ -50,7 +50,7 @@ public class TestAero extends TestEntity {
*
* @author arlith
*/
public static enum AeroArmor {
public enum AeroArmor {
STANDARD(EquipmentType.T_ARMOR_STANDARD, 0, 0, false),
CLAN_FERRO_ALUM(EquipmentType.T_ARMOR_ALUM, 1, 1, true),
FERRO_LAMELLOR(EquipmentType.T_ARMOR_FERRO_LAMELLOR, 2, 1, true),
Expand Down Expand Up @@ -580,19 +580,13 @@ public String printWeightMisc() {

@Override
public String printWeightControls() {
StringBuffer retVal = new StringBuffer(StringUtil.makeLength(
aero.getCockpitTypeString() + ":", getPrintSize() - 5));
retVal.append(makeWeightString(getWeightControls()));
retVal.append("\n");
return retVal.toString();
return StringUtil.makeLength(aero.getCockpitTypeString() + ":", getPrintSize() - 5)
+ makeWeightString(getWeightControls()) + "\n";
}

public String printWeightFuel() {
StringBuffer retVal = new StringBuffer(StringUtil.makeLength(
"Fuel: ", getPrintSize() - 5));
retVal.append(makeWeightString(getWeightFuel()));
retVal.append("\n");
return retVal.toString();
return StringUtil.makeLength("Fuel: ", getPrintSize() - 5)
+ makeWeightString(getWeightFuel()) + "\n";
}

public Aero getAero() {
Expand Down Expand Up @@ -936,11 +930,12 @@ public boolean hasMismatchedLateralWeapons(StringBuffer buff) {
* conventional fighter, or fixed wing support vehicle
*/
public static boolean isValidAeroLocation(EquipmentType eq, int location, @Nullable StringBuffer buffer) {
if (buffer == null) {
buffer = new StringBuffer();
}
if (eq instanceof AmmoType) {
if (location != Aero.LOC_FUSELAGE) {
if (buffer != null) {
buffer.append(eq.getName()).append(" must be mounted in the fuselage.\n");
}
buffer.append(eq.getName()).append(" must be mounted in the fuselage.\n");
return false;
}
} else if (eq instanceof MiscType) {
Expand All @@ -952,31 +947,23 @@ public static boolean isValidAeroLocation(EquipmentType eq, int location, @Nulla
|| eq.hasFlag(MiscType.F_PPC_CAPACITOR)
|| eq.hasFlag(MiscType.F_RISC_LASER_PULSE_MODULE)) && (location >= Aero.LOC_WINGS)) {
if (location != Aero.LOC_FUSELAGE) {
if (buffer != null) {
buffer.append(eq.getName()).append(" must be mounted in a location with a firing arc.\n");
}
buffer.append(eq.getName()).append(" must be mounted in a location with a firing arc.\n");
return false;
}
} else if ((eq.hasFlag(MiscType.F_BLUE_SHIELD) || eq.hasFlag(MiscType.F_LIFTHOIST)
|| (eq.hasFlag(MiscType.F_CASE) && !eq.isClan())) && (location != Aero.LOC_FUSELAGE)) {
if (buffer != null) {
buffer.append(eq.getName()).append(" must be mounted in the fuselage.\n");
}
buffer.append(eq.getName()).append(" must be mounted in the fuselage.\n");
return false;
}
} else if (eq instanceof WeaponType) {
if ((((WeaponType) eq).getAmmoType() == AmmoType.T_GAUSS_HEAVY)
&& (location != Aero.LOC_NOSE) && (location != Aero.LOC_AFT)) {
if (buffer != null) {
buffer.append(eq.getName()).append(" must be mounted in the nose or aft.\n");
}
buffer.append(eq.getName()).append(" must be mounted in the nose or aft.\n");
return false;
}
if (!eq.hasFlag(WeaponType.F_C3M) && !eq.hasFlag(WeaponType.F_C3MBS)
&& !eq.hasFlag(WeaponType.F_TAG) && (location == Aero.LOC_FUSELAGE)) {
if (buffer != null) {
buffer.append(eq.getName()).append(" must be mounted in a location with a firing arc.\n");
}
buffer.append(eq.getName()).append(" must be mounted in a location with a firing arc.\n");
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions megamek/src/megamek/common/verifier/TestMech.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static List<EquipmentType> legalArmorsFor(long etype, boolean industrial,
return legalArmors;
}

private Mech mech = null;
private Mech mech;

public TestMech(Mech mech, TestEntityOption option, String fileString) {
super(option, mech.getEngine(), getArmor(mech), getStructure(mech));
Expand Down Expand Up @@ -483,7 +483,7 @@ public boolean criticalSlotsAllocated(Entity entity, Mounted mounted,
Vector<Serializable> allocation, StringBuffer buff) {
int location = mounted.getLocation();
EquipmentType et = mounted.getType();
int criticals = 0;
int criticals;
if (et instanceof MiscType) {
criticals = calcMiscCrits((MiscType) et, mounted.getSize());
} else {
Expand All @@ -506,7 +506,7 @@ public boolean criticalSlotsAllocated(Entity entity, Mounted mounted,
}

if ((et instanceof WeaponType) && mounted.isSplit()) {
int secCound = 0;
int secCound;
for (int locations = 0; locations < entity.locations(); locations++) {
if (locations == location) {
continue;
Expand Down
Loading

0 comments on commit 75e9ca7

Please sign in to comment.