Skip to content

Commit

Permalink
Merge pull request MegaMek#5828 from SJuliez/5811-illegal-design-quirk
Browse files Browse the repository at this point in the history
MegaMek#5811 Some validation rules and illegal design quirk
  • Loading branch information
IllianiCBT authored Jul 31, 2024
2 parents c1de637 + 083f37f commit b1b389f
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ source:XTR: Caveat Emptor
rules level:5
role:Ambusher

quirk:illegal_design
quirk:gas_hog
quirk:stable
quirk:exp_actuator
quirk:no_twist

mass:30
engine:90 ICE Engine(IS)
structure:IS Industrial
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ engine:300 XXL (Clan) Engine(IS)
structure:IS Industrial
myomer:Standard

quirk:illegal_design
quirk:hard_pilot

heat sinks:11 Single
walk mp:10
jump mp:0
Expand Down
3 changes: 2 additions & 1 deletion megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2343,7 +2343,8 @@ MechView.Pod=Pod
MechView.Fixed=Fixed
MechView.Quirks=Quirks
MechView.WeaponQuirks=Weapon Quirks
MechView.InvalidReasons=Invalid Reasons
MechView.InvalidReasons=Invalid because:
MechView.InvalidButIllegalQuirk=Illegal Design Quirk, would be invalid because:

#Minelaying
MineDensityDialog.title=Mine Density
Expand Down
19 changes: 10 additions & 9 deletions megamek/src/megamek/common/MechView.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,16 @@ public MechView(final Entity entity, final boolean showDetail, final boolean use
TestEntity testEntity = TestEntity.getEntityVerifier(entity);

if (testEntity != null) {
testEntity.correctEntity(sb, entity.getTechLevel());

if (!sb.toString().isEmpty()) {
testEntity.correctEntity(sb);
if (!sb.isEmpty()) {
sInvalid.add(new SingleLine());
sInvalid.add(new LabeledElement(Messages.getString("MechView.InvalidReasons"), "\n" + sb));
String[] errorLines = sb.toString().split("\n");
String label = entity.hasQuirk(OptionsConstants.QUIRK_NEG_ILLEGAL_DESIGN) ?
Messages.getString("MechView.InvalidButIllegalQuirk") :
Messages.getString("MechView.InvalidReasons");
ItemList errorList = new ItemList(label);
Arrays.stream(errorLines).forEach(errorList::addItem);
sInvalid.add(errorList);
}
}
}
Expand Down Expand Up @@ -659,21 +664,17 @@ public String getMechReadout() {
public String getMechReadout(@Nullable String fontName) {
String docStart = "";
String docEnd = "";
String preStart = "";
String preEnd = "";

if (formatting == ViewFormatting.HTML && (fontName != null)) {
docStart = "<div style=\"font-family:" + fontName + ";\">";
docEnd = "</div>";
preStart = "<PRE style=\"font-family:" + fontName + ";\">";
preEnd = "</PRE>";
} else if (formatting == ViewFormatting.DISCORD) {
docStart = "```ansi\n";
docEnd = "```";
}
return docStart + getMechReadoutHead()
+ getMechReadoutBasic() + getMechReadoutLoadout()
+ getMechReadoutFluff() + preStart + getMechReadoutInvalid() + preEnd + docEnd;
+ getMechReadoutFluff() + getMechReadoutInvalid() + docEnd;
}

private List<ViewElement> getInternalAndArmor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import megamek.common.equipment.AmmoMounted;
import megamek.common.equipment.ArmorType;
import megamek.common.equipment.WeaponMounted;
import megamek.common.options.OptionsConstants;
import megamek.common.util.StringUtil;
import megamek.common.weapons.bayweapons.BayWeapon;
import megamek.common.weapons.capitalweapons.ScreenLauncherWeapon;
Expand Down Expand Up @@ -630,7 +631,9 @@ public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
correct &= correctGravDecks(buff);
correct &= correctBays(buff);
correct &= correctCriticals(buff);

if (getEntity().hasQuirk(OptionsConstants.QUIRK_NEG_ILLEGAL_DESIGN)) {
correct = true;
}
return correct;
}

Expand Down
9 changes: 3 additions & 6 deletions megamek/src/megamek/common/verifier/TestAero.java
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,6 @@ public boolean correctHeatSinks(StringBuffer buff) {
return true;
}

@Override
public boolean correctEntity(StringBuffer buff) {
return correctEntity(buff, aero.getTechLevel());
}

@Override
public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
boolean correct = true;
Expand Down Expand Up @@ -750,7 +745,9 @@ public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
correct &= !hasIllegalEquipmentCombinations(buff);
correct &= !hasMismatchedLateralWeapons(buff);
correct &= correctHeatSinks(buff);

if (getEntity().hasQuirk(OptionsConstants.QUIRK_NEG_ILLEGAL_DESIGN)) {
correct = true;
}
return correct;
}

Expand Down
10 changes: 4 additions & 6 deletions megamek/src/megamek/common/verifier/TestBattleArmor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.equipment.ArmorType;
import megamek.common.options.OptionsConstants;
import megamek.common.util.StringUtil;
import megamek.common.weapons.infantry.InfantryWeapon;

Expand Down Expand Up @@ -1020,11 +1021,6 @@ public boolean correctWeight(StringBuffer buff, boolean showO, boolean showU) {
return correct;
}

@Override
public boolean correctEntity(StringBuffer buff) {
return correctEntity(buff, getEntity().getTechLevel());
}

@Override
public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
boolean correct = true;
Expand Down Expand Up @@ -1059,7 +1055,9 @@ public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
correct &= correctManipulators(buff);

correct &= correctMovement(buff);

if (getEntity().hasQuirk(OptionsConstants.QUIRK_NEG_ILLEGAL_DESIGN)) {
correct = true;
}
return correct;
}

Expand Down
24 changes: 12 additions & 12 deletions megamek/src/megamek/common/verifier/TestEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import megamek.common.annotations.Nullable;
import megamek.common.enums.MPBoosters;
import megamek.common.equipment.ArmorType;
import megamek.common.equipment.WeaponMounted;
import megamek.common.util.StringUtil;

import java.io.File;
Expand Down Expand Up @@ -74,7 +75,9 @@ private Ceil(double mult) {

public abstract String printWeightControls();

public abstract boolean correctEntity(StringBuffer buff);
public boolean correctEntity(StringBuffer buff) {
return correctEntity(buff, getEntity().getTechLevel());
}

public abstract boolean correctEntity(StringBuffer buff, int ammoTechLvl);

Expand Down Expand Up @@ -1474,19 +1477,16 @@ public boolean hasIllegalEquipmentCombinations(StringBuffer buff) {
}
}
}
if ((isMech() || isTank() || isAero())
&& (!getEntity().hasEngine()
|| (!getEntity().getEngine().isFusion()
&& (getEntity().getEngine().getEngineType() != Engine.FISSION)))) {
for (Mounted m : getEntity().getWeaponList()) {
if (((WeaponType) m.getType()).getAmmoType() == AmmoType.T_IGAUSS_HEAVY) {
buff.append("Improved Heavy Gauss requires a fusion or fission engine.\n");
Engine engine = getEntity().getEngine();
if (!getEntity().hasEngine() || !(engine.isFusion() || engine.isFission())) {
for (WeaponMounted m : getEntity().getWeaponList()) {
if ((m.getType().getAmmoType() == AmmoType.T_GAUSS_HEAVY)
|| (m.getType().getAmmoType() == AmmoType.T_IGAUSS_HEAVY)) {
buff.append("Heavy Gauss Rifles require a fusion or fission engine\n");
illegal = true;
} else if (m.getType().hasFlag(WeaponType.F_FLAMER)
&& (((WeaponType) m.getType()).getAmmoType() == AmmoType.T_NA)
&& (!getEntity().hasEngine() || (!getEntity().getEngine().isFusion()
&& (getEntity().getEngine().getEngineType() != Engine.FISSION)))) {
buff.append("Standard flamers require a fusion or fission engine.\n");
&& (m.getType().getAmmoType() == AmmoType.T_NA)) {
buff.append("Standard flamers require a fusion or fission engine\n");
illegal = true;
}
}
Expand Down
9 changes: 3 additions & 6 deletions megamek/src/megamek/common/verifier/TestInfantry.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ public String printWeightArmor() {
return "";
}

@Override
public boolean correctEntity(StringBuffer buff) {
return correctEntity(buff, getEntity().getTechLevel());
}

@Override
public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
Infantry inf = (Infantry) getEntity();
Expand Down Expand Up @@ -198,7 +193,9 @@ public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
buff.append("Infantry may not have more than one armor kit!\n");
correct = false;
}

if (getEntity().hasQuirk(OptionsConstants.QUIRK_NEG_ILLEGAL_DESIGN)) {
correct = true;
}
return correct;
}

Expand Down
47 changes: 25 additions & 22 deletions megamek/src/megamek/common/verifier/TestMech.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import megamek.common.annotations.Nullable;
import megamek.common.equipment.ArmorType;
import megamek.common.equipment.WeaponMounted;
import megamek.common.options.OptionsConstants;
import megamek.common.options.Quirks;
import megamek.common.util.StringUtil;
import megamek.common.weapons.artillery.ArtilleryWeapon;
import megamek.common.weapons.autocannons.ACWeapon;
Expand Down Expand Up @@ -680,11 +682,6 @@ public boolean correctMovement(StringBuffer buff) {
return true;
}

@Override
public boolean correctEntity(StringBuffer buff) {
return correctEntity(buff, getEntity().getTechLevel());
}

@Override
public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
boolean correct = true;
Expand Down Expand Up @@ -732,6 +729,9 @@ public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
correct = correct && checkMiscSpreadAllocation(mech, misc, buff);
}
correct = correct && correctMovement(buff);
if (getEntity().hasQuirk(OptionsConstants.QUIRK_NEG_ILLEGAL_DESIGN)) {
correct = true;
}
return correct;
}

Expand Down Expand Up @@ -1047,23 +1047,6 @@ && countCriticalSlotsFromEquipInLocation(mech, m, loc) != 1) {
}

if (mech.isSuperHeavy()) {
switch (mech.hasEngine() ? mech.getEngine().getEngineType() : Engine.NONE) {
case Engine.NORMAL_ENGINE:
case Engine.LARGE_ENGINE:
break;
case Engine.XL_ENGINE:
case Engine.XXL_ENGINE:
case Engine.COMPACT_ENGINE:
case Engine.LIGHT_ENGINE:
if (mech.isIndustrial()) {
buff.append("Superheavy industrialMechs can only use standard or large fusion engine\n");
illegal = true;
}
break;
default:
buff.append("Superheavy Mechs must use some type of fusion engine\n");
illegal = true;
}
if (mech.getGyroType() != Mech.GYRO_SUPERHEAVY) {
buff.append("Superheavy Mechs must use a superheavy gyro.\n");
illegal = true;
Expand Down Expand Up @@ -1099,6 +1082,26 @@ && countCriticalSlotsFromEquipInLocation(mech, m, loc) != 1) {
buff.append("industrial mechs can only mount standard gyros\n");
illegal = true;
}
if (hasDoubleHeatSinks()) {
buff.append("Industrial Meks cannot mount double heat sinks\n");
illegal = true;
}
switch (mech.hasEngine() ? engine.getEngineType() : Engine.NONE) {
case Engine.NORMAL_ENGINE:
break;
case Engine.COMBUSTION_ENGINE:
case Engine.FUEL_CELL:
case Engine.FISSION:
if (mech.isSuperHeavy()) {
buff.append("Superheavy Industrial Meks can only use standard or large fusion engines\n");
illegal = true;
}
break;
default:
buff.append("Industrial Meks can only use standard and large fusion engines, ICEs, fuel cells or fission\n");
illegal = true;
break;
}
}

if (mech.isPrimitive()) {
Expand Down
9 changes: 4 additions & 5 deletions megamek/src/megamek/common/verifier/TestProtomech.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.equipment.ArmorType;
import megamek.common.options.OptionsConstants;
import megamek.common.util.StringUtil;

import java.util.HashMap;
Expand Down Expand Up @@ -213,11 +214,6 @@ public double getWeightCarryingSpace() {
return 0.0;
}

@Override
public boolean correctEntity(StringBuffer buff) {
return correctEntity(buff, getEntity().getTechLevel());
}

@Override
public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
boolean correct = true;
Expand Down Expand Up @@ -249,6 +245,9 @@ public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
correct = false;
}
correct = correct && correctMovement(buff);
if (getEntity().hasQuirk(OptionsConstants.QUIRK_NEG_ILLEGAL_DESIGN)) {
correct = true;
}
return correct;
}

Expand Down
5 changes: 4 additions & 1 deletion megamek/src/megamek/common/verifier/TestSmallCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import megamek.common.equipment.AmmoMounted;
import megamek.common.equipment.ArmorType;
import megamek.common.equipment.WeaponMounted;
import megamek.common.options.OptionsConstants;
import megamek.common.util.StringUtil;

import java.math.BigInteger;
Expand Down Expand Up @@ -510,7 +511,9 @@ public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
correct &= correctHeatSinks(buff);
correct &= correctCrew(buff);
correct &= correctCriticals(buff);

if (getEntity().hasQuirk(OptionsConstants.QUIRK_NEG_ILLEGAL_DESIGN)) {
correct = true;
}
return correct;
}

Expand Down
9 changes: 4 additions & 5 deletions megamek/src/megamek/common/verifier/TestSupportVehicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.equipment.ArmorType;
import megamek.common.options.OptionsConstants;
import megamek.common.util.StringUtil;
import megamek.common.weapons.flamers.VehicleFlamerWeapon;
import megamek.common.weapons.infantry.InfantryWeapon;
Expand Down Expand Up @@ -919,11 +920,6 @@ public boolean canUsePintleTurret() {
getEntity().getWeightClass() == EntityWeightClass.WEIGHT_SMALL_SUPPORT);
}

@Override
public boolean correctEntity(StringBuffer buff) {
return correctEntity(buff, getEntity().getTechLevel());
}

@Override
public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
boolean correct = true;
Expand Down Expand Up @@ -1119,6 +1115,9 @@ public boolean correctEntity(StringBuffer buff, int ammoTechLvl) {
if (!correctCriticals(buff)) {
correct = false;
}
if (getEntity().hasQuirk(OptionsConstants.QUIRK_NEG_ILLEGAL_DESIGN)) {
correct = true;
}
return correct;
}

Expand Down
Loading

0 comments on commit b1b389f

Please sign in to comment.