diff --git a/megamek/docs/history.txt b/megamek/docs/history.txt index 0a9791e28ce..cf776f6700c 100644 --- a/megamek/docs/history.txt +++ b/megamek/docs/history.txt @@ -78,6 +78,8 @@ MEGAMEK VERSION HISTORY: + PR #5845: Force destruction of out-of-control DropShips and larger (implements #770) + PR #5841: FighterSquadron updates + PR #5846: Index guard for turn lookup to prevent error messages ++ Fix #5587: Check if Edge is enabled in Game Options before using it ++ PR #5859: Use OptionsConstants instead of hard-coded strings 0.49.20 (2024-06-28 2100 UTC) (THIS IS THE LAST VERSION TO SUPPORT JAVA 11) + PR #5281, #5327, #5308, #5336, #5318, #5383, #5369, #5384, #5455, #5505, #5541: Code internals: preparatory work for supporting game types such as SBF, code cleanup for string drawing, superclass change for BoardView, diff --git a/megamek/src/megamek/common/Compute.java b/megamek/src/megamek/common/Compute.java index cf6aa33ebfe..253fecc3d49 100644 --- a/megamek/src/megamek/common/Compute.java +++ b/megamek/src/megamek/common/Compute.java @@ -2443,7 +2443,7 @@ public static ToHitData getSecondaryTargetMod(Game game, Entity attacker, if (attacker.getCrew().hasDedicatedGunner()) { maxPrimary = attacker.getCrew().getCrewType().getMaxPrimaryTargets(); } - if (game.getOptions().booleanOption("tacops_tank_crews") + if (game.getOptions().booleanOption(OptionsConstants.ADVANCED_TACOPS_TANK_CREWS) && (attacker instanceof Tank)) { // If we are a tank, and only have 1 crew then we have some special diff --git a/megamek/src/megamek/common/Entity.java b/megamek/src/megamek/common/Entity.java index ba1d09ff9ec..e28e6001338 100644 --- a/megamek/src/megamek/common/Entity.java +++ b/megamek/src/megamek/common/Entity.java @@ -16050,4 +16050,12 @@ public Base64Image getBase64Icon() { public boolean countForStrengthSum() { return !isDestroyed() && !isTrapped() && !isPartOfFighterSquadron(); } + + /** @return True if the unit should use Edge based on the current options and assigned Edge points */ + public boolean shouldUseEdge(String option) { + return (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew() != null + && getCrew().hasEdgeRemaining() + && getCrew().getOptions().booleanOption(option)); + } } \ No newline at end of file diff --git a/megamek/src/megamek/common/FighterSquadron.java b/megamek/src/megamek/common/FighterSquadron.java index 5142cb450bb..c59310071c5 100644 --- a/megamek/src/megamek/common/FighterSquadron.java +++ b/megamek/src/megamek/common/FighterSquadron.java @@ -522,7 +522,7 @@ public void computeSquadronBombLoadout() { } // Now that we know our bomb choices, load 'em - int gameTL = TechConstants.getSimpleLevel(game.getOptions().stringOption("techlevel")); + int gameTL = TechConstants.getSimpleLevel(game.getOptions().stringOption(OptionsConstants.ALLOWED_TECHLEVEL)); for (int type = 0; type < BombType.B_NUM; type++) { for (int i = 0; i < extBombChoices[type]; i++) { if ((type == BombType.B_ALAMO) diff --git a/megamek/src/megamek/common/IBomber.java b/megamek/src/megamek/common/IBomber.java index faee94b8906..ebad0334ec1 100644 --- a/megamek/src/megamek/common/IBomber.java +++ b/megamek/src/megamek/common/IBomber.java @@ -208,7 +208,7 @@ default int getBombPoints(boolean externalOnly) { */ default void applyBombs() { Game game = ((Entity) this).getGame(); - int gameTL = TechConstants.getSimpleLevel(game.getOptions().stringOption("techlevel")); + int gameTL = TechConstants.getSimpleLevel(game.getOptions().stringOption(OptionsConstants.ALLOWED_TECHLEVEL)); Integer[] iSorted = new Integer[BombType.B_NUM]; // Apply the largest bombs first because we need to fit larger bombs into a single location // in LAMs. diff --git a/megamek/src/megamek/common/Mech.java b/megamek/src/megamek/common/Mech.java index eb05b004782..83df3acb569 100644 --- a/megamek/src/megamek/common/Mech.java +++ b/megamek/src/megamek/common/Mech.java @@ -1992,8 +1992,7 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod // normal front hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -2018,9 +2017,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_LARM); case 12: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -2033,8 +2030,7 @@ && getCrew().getOptions().booleanOption( // normal left side hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() - .getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, @@ -2070,9 +2066,7 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_RLEG); case 12: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -2085,8 +2079,7 @@ && getCrew().getOptions().booleanOption( // normal right side hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() - .getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, @@ -2122,9 +2115,7 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_LLEG); case 12: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -2140,9 +2131,7 @@ && getCrew().getOptions().booleanOption( && isProne()) { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() - .getOptions() - .booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption( OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -2170,9 +2159,7 @@ && isProne()) { case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -2185,9 +2172,7 @@ && getCrew().getOptions().booleanOption( } else { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() - .getOptions() - .booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption( OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -2215,9 +2200,7 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -2260,9 +2243,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -2284,9 +2265,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_LARM); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -2308,9 +2287,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -2334,9 +2311,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM, true); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -2413,8 +2388,7 @@ && getCrew().getOptions().booleanOption( // Swarm attack locations. switch (roll) { case 2: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD, false, effects)); @@ -2440,9 +2414,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { case 11: return new HitData(Mech.LOC_CT, true, effects); case 12: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -2481,9 +2453,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM, (side == ToHitData.SIDE_REAR)); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); diff --git a/megamek/src/megamek/common/QuadMech.java b/megamek/src/megamek/common/QuadMech.java index 83bc3ca0b02..284a93514ca 100644 --- a/megamek/src/megamek/common/QuadMech.java +++ b/megamek/src/megamek/common/QuadMech.java @@ -458,9 +458,8 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod // normal front hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) - && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) + && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(tac(table, side, Mech.LOC_CT, cover, false)); @@ -484,8 +483,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_RLEG); case 12: - if ((getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD)); @@ -496,9 +494,8 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { } else if (side == ToHitData.SIDE_REAR) { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) - && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) + && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(tac(table, side, Mech.LOC_CT, cover, true)); @@ -522,8 +519,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_RARM, true); case 12: - if ((getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD, true)); @@ -534,9 +530,8 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { } else if (side == ToHitData.SIDE_LEFT) { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) - && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) + && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(tac(table, side, Mech.LOC_LT, cover, false)); @@ -560,8 +555,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_RLEG); case 12: - if ((getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD)); @@ -572,9 +566,8 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { } else if (side == ToHitData.SIDE_RIGHT) { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) - && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) + && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(tac(table, side, Mech.LOC_RT, cover, false)); @@ -598,8 +591,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_LLEG); case 12: - if ((getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD)); @@ -639,8 +631,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { case 5: return new HitData(Mech.LOC_RARM); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD, true)); @@ -661,8 +652,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { case 5: return new HitData(Mech.LOC_RLEG, true); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD, true)); @@ -682,8 +672,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { case 5: return new HitData(Mech.LOC_LLEG); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD, true)); @@ -703,8 +692,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { case 5: return new HitData(Mech.LOC_RLEG); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD, true)); @@ -773,8 +761,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { // Swarm attack locations. switch (roll) { case 2: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD, false, effects)); @@ -800,8 +787,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { case 11: return new HitData(Mech.LOC_LT, false, effects); case 12: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD, false, effects)); diff --git a/megamek/src/megamek/common/TechConstants.java b/megamek/src/megamek/common/TechConstants.java index 96351673344..7dd77db6416 100644 --- a/megamek/src/megamek/common/TechConstants.java +++ b/megamek/src/megamek/common/TechConstants.java @@ -15,6 +15,8 @@ */ package megamek.common; +import megamek.common.options.OptionsConstants; + /** * Contains some constants representing equipment/unit tech levels * @@ -166,7 +168,7 @@ public static int getTechLevel(String techLevel) { * @return the Game's tech level as an integer. */ public static int getSimpleLevel(Game game) { - return getSimpleLevel(game.getOptions().stringOption("techlevel")); + return getSimpleLevel(game.getOptions().stringOption(OptionsConstants.ALLOWED_TECHLEVEL)); } /** diff --git a/megamek/src/megamek/common/TripodMech.java b/megamek/src/megamek/common/TripodMech.java index 200e2d3a230..b95a31db876 100644 --- a/megamek/src/megamek/common/TripodMech.java +++ b/megamek/src/megamek/common/TripodMech.java @@ -1091,8 +1091,7 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod // normal front hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() - .getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, @@ -1125,9 +1124,7 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod case 11: return new HitData(Mech.LOC_LARM); case 12: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1140,8 +1137,7 @@ && getCrew().getOptions().booleanOption( // normal left side hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() - .getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, @@ -1182,9 +1178,7 @@ && getCrew().getOptions().booleanOption( case 10: return new HitData(Mech.LOC_RARM); case 12: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1197,8 +1191,7 @@ && getCrew().getOptions().booleanOption( // normal right side hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() - .getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, @@ -1239,9 +1232,7 @@ && getCrew().getOptions().booleanOption( case 10: return new HitData(Mech.LOC_LARM); case 12: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1257,9 +1248,7 @@ && getCrew().getOptions().booleanOption( && isProne()) { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() - .getOptions() - .booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption( OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -1293,9 +1282,7 @@ && isProne()) { case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1308,9 +1295,7 @@ && getCrew().getOptions().booleanOption( } else { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() - .getOptions() - .booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption( OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -1344,9 +1329,7 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1389,9 +1372,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1413,9 +1394,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_LARM); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1437,9 +1416,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1463,9 +1440,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM, true); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1553,9 +1528,7 @@ && getCrew().getOptions().booleanOption( // Swarm attack locations. switch (roll) { case 2: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1583,9 +1556,7 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_CT, true, effects); case 12: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1624,9 +1595,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM, (side == ToHitData.SIDE_REAR)); case 6: - if (getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); diff --git a/megamek/src/megamek/common/weapons/ArtilleryBayWeaponIndirectHomingHandler.java b/megamek/src/megamek/common/weapons/ArtilleryBayWeaponIndirectHomingHandler.java index 09154199ec1..b28f266f9ef 100644 --- a/megamek/src/megamek/common/weapons/ArtilleryBayWeaponIndirectHomingHandler.java +++ b/megamek/src/megamek/common/weapons/ArtilleryBayWeaponIndirectHomingHandler.java @@ -162,7 +162,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { // Set Margin of Success/Failure. toHit.setMoS(roll.getIntValue() - Math.max(2, toHit.getValue())); - bDirect = game.getOptions().booleanOption("tacops_direct_blow") + bDirect = game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_DIRECT_BLOW) && ((toHit.getMoS() / 3) >= 1) && (entityTarget != null); if (bDirect) { r = new Report(3189); diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index a3f388e17a5..8fd3e017828 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -8720,9 +8720,7 @@ private boolean checkMASCFailure(Entity entity, MovePath md) { if (entity.checkForMASCFailure(md, vReport, crits)) { boolean mascFailure = true; // Check to see if the pilot can reroll due to Edge - if (entity.getCrew().hasEdgeRemaining() - && entity.getCrew().getOptions() - .booleanOption(OptionsConstants.EDGE_WHEN_MASC_FAILS)) { + if (entity.shouldUseEdge(OptionsConstants.EDGE_WHEN_MASC_FAILS)) { entity.getCrew().decreaseEdge(); // Need to reset the MASCUsed flag entity.setMASCUsed(false); @@ -8773,9 +8771,7 @@ private boolean checkSuperchargerFailure(Entity entity, MovePath md) { if (entity.checkForSuperchargerFailure(md, vReport, crits)) { boolean superchargerFailure = true; // Check to see if the pilot can reroll due to Edge - if (entity.getCrew().hasEdgeRemaining() - && entity.getCrew().getOptions() - .booleanOption(OptionsConstants.EDGE_WHEN_MASC_FAILS)) { + if (entity.shouldUseEdge(OptionsConstants.EDGE_WHEN_MASC_FAILS)) { entity.getCrew().decreaseEdge(); // Need to reset the SuperchargerUsed flag entity.setSuperchargerUsed(false); @@ -20180,8 +20176,7 @@ private Vector resolveControl(Entity e) { if (e.getAltitude() <= 0 // Don't waste the edge if it won't help && origAltitude > 1 - && e.getCrew().hasEdgeRemaining() - && e.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_ALT_LOSS)) { + && e.shouldUseEdge(OptionsConstants.EDGE_WHEN_AERO_ALT_LOSS)) { Roll diceRoll3 = Compute.rollD6(1); int rollValue3 = diceRoll3.getIntValue(); String rollReport3 = diceRoll3.getReport(); @@ -20566,9 +20561,8 @@ private Vector resolveCrewDamage(Entity e, int damage, int crewPos) { } else { e.getCrew().setKoThisRound(true, crewPos); r.choose(false); - if (e.getCrew().hasEdgeRemaining() - && (e.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_KO) - || e.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_KO))) { + if (e.shouldUseEdge(OptionsConstants.EDGE_WHEN_KO) + || e.shouldUseEdge(OptionsConstants.EDGE_WHEN_AERO_KO)) { edgeUsed = true; vDesc.add(r); r = new Report(6520); @@ -20580,10 +20574,9 @@ private Vector resolveCrewDamage(Entity e, int damage, int crewPos) { // return true; } // else vDesc.add(r); - } while (e.getCrew().hasEdgeRemaining() - && e.getCrew().isKoThisRound(crewPos) - && (e.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_KO) - || e.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_KO))); + } while ((e.shouldUseEdge(OptionsConstants.EDGE_WHEN_KO) + && e.getCrew().isKoThisRound(crewPos)) + || e.shouldUseEdge(OptionsConstants.EDGE_WHEN_AERO_KO)); // end of do-while if (e.getCrew().isKoThisRound(crewPos)) { boolean wasPilot = e.getCrew().getCurrentPilotIndex() == crewPos; @@ -24382,9 +24375,7 @@ private Vector applyAeroCritical(Aero aero, int loc, CriticalSlot cs, in r.subject = aero.getId(); if (fuelroll >= boomTarget) { // A chance to reroll the explosion with edge - if (aero.getCrew().hasEdgeRemaining() - && aero.getCrew().getOptions().booleanOption( - OptionsConstants.EDGE_WHEN_AERO_EXPLOSION)) { + if (aero.shouldUseEdge(OptionsConstants.EDGE_WHEN_AERO_EXPLOSION)) { // Reporting this is funky because 9120 only has room for 2 choices. Replace it. r = new Report(9123); r.subject = aero.getId(); @@ -24628,8 +24619,7 @@ private Vector applyAeroCritical(Aero aero, int loc, CriticalSlot cs, in boomTarget = 10; r.choose(ammoRoll >= boomTarget); // A chance to reroll an explosion with edge - if (aero.getCrew().hasEdgeRemaining() - && aero.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_EXPLOSION) + if (aero.shouldUseEdge(OptionsConstants.EDGE_WHEN_AERO_EXPLOSION) && ammoRoll >= boomTarget) { // Report 9156 doesn't offer the right choices. Replace it. r = new Report(9158); @@ -24683,8 +24673,7 @@ private Vector applyAeroCritical(Aero aero, int loc, CriticalSlot cs, in int ammoroll = Compute.d6(2); if (ammoroll >= 10) { // A chance to reroll an explosion with edge - if (aero.getCrew().hasEdgeRemaining() - && aero.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_EXPLOSION)) { + if (aero.shouldUseEdge(OptionsConstants.EDGE_WHEN_AERO_EXPLOSION)) { aero.getCrew().decreaseEdge(); r = new Report(6530); r.subject = aero.getId(); @@ -24712,8 +24701,7 @@ private Vector applyAeroCritical(Aero aero, int loc, CriticalSlot cs, in } } // If the weapon is explosive, use edge to roll up a new one - if (aero.getCrew().hasEdgeRemaining() - && aero.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_EXPLOSION) + if (aero.shouldUseEdge(OptionsConstants.EDGE_WHEN_AERO_EXPLOSION) && (equipmentHit.getType().isExplosive(equipmentHit) && !equipmentHit.isHit() && !equipmentHit.isDestroyed())) { aero.getCrew().decreaseEdge(); @@ -24985,8 +24973,7 @@ private void applyCargoCritical(Aero aero, int damageCaused, Vector repo int roll = Compute.d6(1); // A hit on a bay filled with transported units is devastating // allow a reroll with edge - if (aero.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_UNIT_CARGO_LOST) - && aero.getCrew().hasEdgeRemaining() && roll > 3) { + if (aero.shouldUseEdge(OptionsConstants.EDGE_WHEN_AERO_UNIT_CARGO_LOST) && roll > 3) { aero.getCrew().decreaseEdge(); r = new Report(9172); r.subject = aero.getId(); @@ -26019,7 +26006,7 @@ private void checkAeroCrits(Vector vDesc, Aero a, HitData hit, if (diceRoll.getIntValue() >= capitalMissile) { // Allow a reroll with edge - if (a.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_NUKE_CRIT) + if (a.shouldUseEdge(OptionsConstants.EDGE_WHEN_AERO_NUKE_CRIT) && a.getCrew().hasEdgeRemaining()) { a.getCrew().decreaseEdge(); r = new Report(9148); @@ -26073,8 +26060,7 @@ private void checkAeroCrits(Vector vDesc, Aero a, HitData hit, if (hit.rolledBoxCars()) { if (hit.isFirstHit()) { // Allow edge use to ignore the critical roll - if (a.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_LUCKY_CRIT) - && a.getCrew().hasEdgeRemaining()) { + if (a.shouldUseEdge(OptionsConstants.EDGE_WHEN_AERO_LUCKY_CRIT)) { a.getCrew().decreaseEdge(); r = new Report(9103); r.subject = a.getId(); @@ -26440,8 +26426,7 @@ public Vector criticalEntity(Entity en, int loc, boolean isRear, } // if explosive use edge if ((en instanceof Mech) - && (en.getCrew().hasEdgeRemaining() && en.getCrew().getOptions() - .booleanOption(OptionsConstants.EDGE_WHEN_EXPLOSION)) + && en.shouldUseEdge(OptionsConstants.EDGE_WHEN_EXPLOSION) && (slot.getType() == CriticalSlot.TYPE_EQUIPMENT) && slot.getMount().getType().isExplosive(slot.getMount())) { en.getCrew().decreaseEdge();