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

Check equipment compatibility with motive type when validating vehicles #1690

Merged
merged 3 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions megamek/src/megamek/common/verifier/TestSupportVehicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,15 @@ public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
buff.append("Omni configuration exceeds weapon capacity of base chassis fire control system.\n");
correct = false;
}
if (supportVee instanceof Tank) {
for (Mounted m : supportVee.getEquipment()) {
if (!TestTank.legalForMotiveType(m.getType(), supportVee.getMovementMode())) {
buff.append(m.getType().getName()).append(" is incompatible with ")
.append(supportVee.getMovementModeAsString());
correct = false;
}
}
}
for (int loc = 0; loc < supportVee.locations(); loc++) {
int count = 0;
for (Mounted misc : supportVee.getMisc()) {
Expand Down
72 changes: 72 additions & 0 deletions megamek/src/megamek/common/verifier/TestTank.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,13 @@ public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
correct = false;
}
}
for (Mounted m : tank.getEquipment()) {
if (!legalForMotiveType(m.getType(), tank.getMovementMode())) {
buff.append(m.getType().getName()).append(" is incompatible with ")
.append(tank.getMovementModeAsString());
correct = false;
}
}
for (Mounted m : tank.getMisc()) {
if (m.getType().hasFlag(MiscType.F_COMBAT_VEHICLE_ESCAPE_POD)) {
if (m.getLocation() != (tank instanceof SuperHeavyTank?SuperHeavyTank.LOC_REAR:Tank.LOC_REAR)) {
Expand Down Expand Up @@ -451,6 +458,71 @@ public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
return correct;
}

/**
* Checks whether the equipment is compatible with the vehicle's motive type
*
* @param eq The equipment to check
* @param mode The vehicle's motive type
* @return Whether the equipment and motive type are compatible
*/
public static boolean legalForMotiveType(EquipmentType eq, EntityMovementMode mode) {
final boolean isNaval = mode.equals(EntityMovementMode.NAVAL)
|| mode.equals(EntityMovementMode.HYDROFOIL)
|| mode.equals(EntityMovementMode.SUBMARINE);
if (eq instanceof MiscType) {
if (eq.hasFlag(MiscType.F_FLOTATION_HULL)) {
// Per errata, WiGE vehicles automatically include flotation hull
return mode.equals(EntityMovementMode.HOVER) || mode.equals(EntityMovementMode.VTOL);
}
if (eq.hasFlag(MiscType.F_FULLY_AMPHIBIOUS)
|| eq.hasFlag(MiscType.F_LIMITED_AMPHIBIOUS)
|| eq.hasFlag(MiscType.F_BULLDOZER)
|| (eq.hasFlag(MiscType.F_CLUB) && eq.hasSubType(MiscType.S_COMBINE))) {
return mode.equals(EntityMovementMode.WHEELED) || mode.equals(EntityMovementMode.TRACKED);
}
if (eq.hasFlag(MiscType.F_DUNE_BUGGY)) {
return mode.equals(EntityMovementMode.WHEELED);
}
if (eq.hasFlag(MiscType.F_CLUB)
&& eq.hasSubType(MiscType.S_CHAINSAW | MiscType.S_DUAL_SAW | MiscType.S_MINING_DRILL)) {
return mode.equals(EntityMovementMode.WHEELED) || mode.equals(EntityMovementMode.TRACKED)
|| mode.equals(EntityMovementMode.HOVER) || mode.equals(EntityMovementMode.WIGE);
}
if (eq.hasFlag(MiscType.F_MINESWEEPER)) {
return mode.equals(EntityMovementMode.WHEELED) || mode.equals(EntityMovementMode.TRACKED)
|| isNaval;
}
if (eq.hasFlag(MiscType.F_LIFEBOAT)) {
// Need to filter out atmospheric lifeboat
return isNaval && (eq.hasFlag(MiscType.F_TANK_EQUIPMENT) || eq.hasFlag(MiscType.F_SUPPORT_TANK_EQUIPMENT));
}
if (eq.hasFlag(MiscType.F_HEAVY_BRIDGE_LAYER)
|| eq.hasFlag(MiscType.F_MEDIUM_BRIDGE_LAYER)
|| eq.hasFlag(MiscType.F_LIGHT_BRIDGE_LAYER)
|| (eq.hasFlag(MiscType.F_CLUB)
&& eq.hasSubType(MiscType.S_BACKHOE | MiscType.S_ROCK_CUTTER
| MiscType.S_SPOT_WELDER | MiscType.S_WRECKING_BALL))) {
return !mode.equals(EntityMovementMode.VTOL);
}
if (eq.hasFlag(MiscType.F_CLUB) && eq.hasSubType(MiscType.S_PILE_DRIVER)) {
return !mode.equals(EntityMovementMode.VTOL)
&& !mode.equals(EntityMovementMode.HOVER)
&& !mode.equals(EntityMovementMode.WIGE);
}
if (eq.hasFlag(MiscType.F_AP_POD)) {
return !isNaval;
}
} else if (eq instanceof WeaponType) {
if (((WeaponType) eq).getAmmoType() == AmmoType.T_BPOD) {
return !isNaval;
}
if (((WeaponType) eq).getAmmoType() == AmmoType.T_NAIL_RIVET_GUN) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What? VTOLs can't mount rivet guns? That's BS, I demand a refund! ::monocle::

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a total crock that submarines can't have combines. Hello? Kelp forests?

return !mode.equals(EntityMovementMode.VTOL);
}
}
return true;
}

@Override
public boolean correctWeight(StringBuffer buff, boolean showO, boolean showU) {
boolean correct = super.correctWeight(buff, showO, showU);
Expand Down