From 74ead353dcecfa8ff6d08359800fcc3e2df0eb0a Mon Sep 17 00:00:00 2001 From: algebro Date: Sun, 4 Aug 2024 21:30:19 -0400 Subject: [PATCH 1/9] check if Edge is enabled in Game Options before using it --- megamek/src/megamek/common/Mech.java | 51 ++++++++++++------ megamek/src/megamek/common/QuadMech.java | 58 +++++++++++++-------- megamek/src/megamek/common/TripodMech.java | 48 +++++++++++------ megamek/src/megamek/server/GameManager.java | 35 +++++++++---- 4 files changed, 126 insertions(+), 66 deletions(-) diff --git a/megamek/src/megamek/common/Mech.java b/megamek/src/megamek/common/Mech.java index d9425f84968..3062516158e 100644 --- a/megamek/src/megamek/common/Mech.java +++ b/megamek/src/megamek/common/Mech.java @@ -1971,7 +1971,8 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod // normal front hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -1997,7 +1998,8 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_LARM); case 12: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); @@ -2012,7 +2014,8 @@ && getCrew().getOptions().booleanOption( // normal left side hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew() .getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -2049,7 +2052,8 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_RLEG); case 12: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); @@ -2064,7 +2068,8 @@ && getCrew().getOptions().booleanOption( // normal right side hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew() .getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -2101,7 +2106,8 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_LLEG); case 12: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); @@ -2119,7 +2125,8 @@ && getCrew().getOptions().booleanOption( && isProne()) { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew() .getOptions() .booleanOption(OptionsConstants.EDGE_WHEN_TAC)) && !game.getOptions().booleanOption( @@ -2149,7 +2156,8 @@ && isProne()) { case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); @@ -2164,7 +2172,8 @@ && getCrew().getOptions().booleanOption( } else { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew() .getOptions() .booleanOption(OptionsConstants.EDGE_WHEN_TAC)) && !game.getOptions().booleanOption( @@ -2194,7 +2203,8 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); @@ -2239,7 +2249,8 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM); case 6: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); @@ -2263,7 +2274,8 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_LARM); case 6: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); @@ -2287,7 +2299,8 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM); case 6: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); @@ -2313,7 +2326,8 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM, true); case 6: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); @@ -2392,7 +2406,8 @@ && getCrew().getOptions().booleanOption( // Swarm attack locations. switch (roll) { case 2: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -2419,7 +2434,8 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { case 11: return new HitData(Mech.LOC_CT, true, effects); case 12: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); @@ -2460,7 +2476,8 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM, (side == ToHitData.SIDE_REAR)); case 6: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); diff --git a/megamek/src/megamek/common/QuadMech.java b/megamek/src/megamek/common/QuadMech.java index 83bc3ca0b02..a432f9d7d1c 100644 --- a/megamek/src/megamek/common/QuadMech.java +++ b/megamek/src/megamek/common/QuadMech.java @@ -458,9 +458,10 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod // normal front hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) - && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_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,7 +485,8 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_RLEG); case 12: - if ((getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -496,9 +498,10 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { } else if (side == ToHitData.SIDE_REAR) { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) - && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_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,7 +525,8 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_RARM, true); case 12: - if ((getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -534,9 +538,10 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { } else if (side == ToHitData.SIDE_LEFT) { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) - && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_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,7 +565,8 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_RLEG); case 12: - if ((getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -572,9 +578,10 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { } else if (side == ToHitData.SIDE_RIGHT) { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) - && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_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,7 +605,8 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_LLEG); case 12: - if ((getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -639,8 +647,9 @@ && 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 (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() + && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD, true)); @@ -661,8 +670,9 @@ && 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 (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() + && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD, true)); @@ -682,8 +692,9 @@ && 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 (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() + && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD, true)); @@ -703,8 +714,9 @@ && 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 (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() + && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); result.setUndoneLocation(new HitData(Mech.LOC_HEAD, true)); @@ -773,7 +785,8 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { // Swarm attack locations. switch (roll) { case 2: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -800,7 +813,8 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { case 11: return new HitData(Mech.LOC_LT, false, effects); case 12: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); diff --git a/megamek/src/megamek/common/TripodMech.java b/megamek/src/megamek/common/TripodMech.java index 92ee039874d..2e7b7a504a6 100644 --- a/megamek/src/megamek/common/TripodMech.java +++ b/megamek/src/megamek/common/TripodMech.java @@ -1029,7 +1029,8 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod // normal front hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew() .getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -1063,7 +1064,8 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod case 11: return new HitData(Mech.LOC_LARM); case 12: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( "edge_when_headhit")) { getCrew().decreaseEdge(); @@ -1078,7 +1080,8 @@ && getCrew().getOptions().booleanOption( // normal left side hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew() .getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -1135,7 +1138,8 @@ && getCrew().getOptions().booleanOption( // normal right side hits switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew() .getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) && !game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -1177,7 +1181,8 @@ && getCrew().getOptions().booleanOption( case 10: return new HitData(Mech.LOC_LARM); case 12: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( "edge_when_headhit")) { getCrew().decreaseEdge(); @@ -1195,7 +1200,8 @@ && getCrew().getOptions().booleanOption( && isProne()) { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew() .getOptions() .booleanOption(OptionsConstants.EDGE_WHEN_TAC)) && !game.getOptions().booleanOption( @@ -1231,7 +1237,8 @@ && isProne()) { case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( "edge_when_headhit")) { getCrew().decreaseEdge(); @@ -1246,7 +1253,8 @@ && getCrew().getOptions().booleanOption( } else { switch (roll) { case 2: - if ((getCrew().hasEdgeRemaining() && getCrew() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && (getCrew().hasEdgeRemaining() && getCrew() .getOptions() .booleanOption(OptionsConstants.EDGE_WHEN_TAC)) && !game.getOptions().booleanOption( @@ -1282,7 +1290,8 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( "edge_when_headhit")) { getCrew().decreaseEdge(); @@ -1327,7 +1336,8 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM); case 6: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( "edge_when_headhit")) { getCrew().decreaseEdge(); @@ -1351,7 +1361,8 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_LARM); case 6: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( "edge_when_headhit")) { getCrew().decreaseEdge(); @@ -1375,7 +1386,8 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM); case 6: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( "edge_when_headhit")) { getCrew().decreaseEdge(); @@ -1401,7 +1413,8 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM, true); case 6: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( "edge_when_headhit")) { getCrew().decreaseEdge(); @@ -1491,7 +1504,8 @@ && getCrew().getOptions().booleanOption( // Swarm attack locations. switch (roll) { case 2: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( "edge_when_headhit")) { getCrew().decreaseEdge(); @@ -1521,7 +1535,8 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_CT, true, effects); case 12: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( "edge_when_headhit")) { getCrew().decreaseEdge(); @@ -1562,7 +1577,8 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM, (side == ToHitData.SIDE_REAR)); case 6: - if (getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( "edge_when_headhit")) { getCrew().decreaseEdge(); diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index 2eca511c570..b26c347746d 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -8612,7 +8612,8 @@ 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() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && entity.getCrew().hasEdgeRemaining() && entity.getCrew().getOptions() .booleanOption(OptionsConstants.EDGE_WHEN_MASC_FAILS)) { entity.getCrew().decreaseEdge(); @@ -8665,7 +8666,8 @@ 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() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && entity.getCrew().hasEdgeRemaining() && entity.getCrew().getOptions() .booleanOption(OptionsConstants.EDGE_WHEN_MASC_FAILS)) { entity.getCrew().decreaseEdge(); @@ -20057,6 +20059,7 @@ private Vector resolveControl(Entity e) { if (e.getAltitude() <= 0 // Don't waste the edge if it won't help && origAltitude > 1 + && game.getOptions().booleanOption(OptionsConstants.EDGE) && e.getCrew().hasEdgeRemaining() && e.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_ALT_LOSS)) { Roll diceRoll3 = Compute.rollD6(1); @@ -20443,7 +20446,8 @@ private Vector resolveCrewDamage(Entity e, int damage, int crewPos) { } else { e.getCrew().setKoThisRound(true, crewPos); r.choose(false); - if (e.getCrew().hasEdgeRemaining() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && e.getCrew().hasEdgeRemaining() && (e.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_KO) || e.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_KO))) { edgeUsed = true; @@ -20457,7 +20461,8 @@ private Vector resolveCrewDamage(Entity e, int damage, int crewPos) { // return true; } // else vDesc.add(r); - } while (e.getCrew().hasEdgeRemaining() + } while (game.getOptions().booleanOption(OptionsConstants.EDGE) + && e.getCrew().hasEdgeRemaining() && e.getCrew().isKoThisRound(crewPos) && (e.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_KO) || e.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_KO))); @@ -24222,7 +24227,8 @@ 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() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && aero.getCrew().hasEdgeRemaining() && aero.getCrew().getOptions().booleanOption( OptionsConstants.EDGE_WHEN_AERO_EXPLOSION)) { // Reporting this is funky because 9120 only has room for 2 choices. Replace it. @@ -24468,7 +24474,8 @@ 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() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && aero.getCrew().hasEdgeRemaining() && aero.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_EXPLOSION) && ammoRoll >= boomTarget) { // Report 9156 doesn't offer the right choices. Replace it. @@ -24523,7 +24530,8 @@ 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() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && aero.getCrew().hasEdgeRemaining() && aero.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_EXPLOSION)) { aero.getCrew().decreaseEdge(); r = new Report(6530); @@ -24552,7 +24560,8 @@ 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() + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && aero.getCrew().hasEdgeRemaining() && aero.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_EXPLOSION) && (equipmentHit.getType().isExplosive(equipmentHit) && !equipmentHit.isHit() && !equipmentHit.isDestroyed())) { @@ -24825,7 +24834,8 @@ 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) + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && aero.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_UNIT_CARGO_LOST) && aero.getCrew().hasEdgeRemaining() && roll > 3) { aero.getCrew().decreaseEdge(); r = new Report(9172); @@ -25859,7 +25869,8 @@ 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 (game.getOptions().booleanOption(OptionsConstants.EDGE) + && a.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_NUKE_CRIT) && a.getCrew().hasEdgeRemaining()) { a.getCrew().decreaseEdge(); r = new Report(9148); @@ -25913,7 +25924,8 @@ 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) + if (game.getOptions().booleanOption(OptionsConstants.EDGE) + && a.getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_AERO_LUCKY_CRIT) && a.getCrew().hasEdgeRemaining()) { a.getCrew().decreaseEdge(); r = new Report(9103); @@ -26280,6 +26292,7 @@ public Vector criticalEntity(Entity en, int loc, boolean isRear, } // if explosive use edge if ((en instanceof Mech) + && game.getOptions().booleanOption(OptionsConstants.EDGE) && (en.getCrew().hasEdgeRemaining() && en.getCrew().getOptions() .booleanOption(OptionsConstants.EDGE_WHEN_EXPLOSION)) && (slot.getType() == CriticalSlot.TYPE_EQUIPMENT) From d240884eaace2aa13d1e0897ba152682131c1717 Mon Sep 17 00:00:00 2001 From: algebro Date: Mon, 5 Aug 2024 11:07:38 -0400 Subject: [PATCH 2/9] add shouldUseEdge() method to simplify repeated conditionals for rolling edge --- megamek/src/megamek/common/Entity.java | 7 ++ megamek/src/megamek/common/Mech.java | 78 +++++---------------- megamek/src/megamek/common/QuadMech.java | 56 ++++----------- megamek/src/megamek/common/TripodMech.java | 70 +++++------------- megamek/src/megamek/server/GameManager.java | 59 ++++------------ 5 files changed, 69 insertions(+), 201 deletions(-) diff --git a/megamek/src/megamek/common/Entity.java b/megamek/src/megamek/common/Entity.java index 69f2a5a276f..e0aff5cf1c5 100644 --- a/megamek/src/megamek/common/Entity.java +++ b/megamek/src/megamek/common/Entity.java @@ -15903,4 +15903,11 @@ 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().hasEdgeRemaining() + && getCrew().getOptions().booleanOption(option)); + } } \ No newline at end of file diff --git a/megamek/src/megamek/common/Mech.java b/megamek/src/megamek/common/Mech.java index 3062516158e..09d83515073 100644 --- a/megamek/src/megamek/common/Mech.java +++ b/megamek/src/megamek/common/Mech.java @@ -1971,9 +1971,7 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod // normal front hits switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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); @@ -1998,10 +1996,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_LARM); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -2014,9 +2009,7 @@ && getCrew().getOptions().booleanOption( // normal left side hits switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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, @@ -2052,7 +2045,7 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_RLEG); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) + if (shouldUseEdge(OptionsConstants.EDGE) && getCrew().hasEdgeRemaining() && getCrew().getOptions().booleanOption( OptionsConstants.EDGE_WHEN_HEADHIT)) { @@ -2068,9 +2061,7 @@ && getCrew().getOptions().booleanOption( // normal right side hits switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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, @@ -2106,10 +2097,7 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_LLEG); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -2125,10 +2113,7 @@ && getCrew().getOptions().booleanOption( && isProne()) { switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (getCrew().hasEdgeRemaining() && getCrew() - .getOptions() - .booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption( OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -2156,10 +2141,7 @@ && isProne()) { case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -2172,10 +2154,7 @@ && getCrew().getOptions().booleanOption( } else { switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (getCrew().hasEdgeRemaining() && getCrew() - .getOptions() - .booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption( OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -2203,10 +2182,7 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -2249,10 +2225,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -2274,10 +2247,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_LARM); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -2299,10 +2269,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -2326,10 +2293,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM, true); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -2406,9 +2370,7 @@ && getCrew().getOptions().booleanOption( // Swarm attack locations. switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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)); @@ -2434,10 +2396,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { case 11: return new HitData(Mech.LOC_CT, true, effects); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -2476,10 +2435,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM, (side == ToHitData.SIDE_REAR)); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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 a432f9d7d1c..284a93514ca 100644 --- a/megamek/src/megamek/common/QuadMech.java +++ b/megamek/src/megamek/common/QuadMech.java @@ -458,9 +458,7 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod // normal front hits switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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); @@ -485,9 +483,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_RLEG); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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)); @@ -498,9 +494,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { } else if (side == ToHitData.SIDE_REAR) { switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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); @@ -525,9 +519,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_RARM, true); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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)); @@ -538,9 +530,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { } else if (side == ToHitData.SIDE_LEFT) { switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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); @@ -565,9 +555,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_RLEG); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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)); @@ -578,9 +566,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { } else if (side == ToHitData.SIDE_RIGHT) { switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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); @@ -605,9 +591,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_TAC)) case 11: return new HitData(Mech.LOC_LLEG); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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)); @@ -647,9 +631,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT))) { case 5: return new HitData(Mech.LOC_RARM); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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)); @@ -670,9 +652,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { case 5: return new HitData(Mech.LOC_RLEG, true); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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)); @@ -692,9 +672,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { case 5: return new HitData(Mech.LOC_LLEG); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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)); @@ -714,9 +692,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { case 5: return new HitData(Mech.LOC_RLEG); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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)); @@ -785,9 +761,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { // Swarm attack locations. switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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)); @@ -813,9 +787,7 @@ && getCrew().getOptions().booleanOption(OptionsConstants.EDGE_WHEN_HEADHIT)) { case 11: return new HitData(Mech.LOC_LT, false, effects); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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/TripodMech.java b/megamek/src/megamek/common/TripodMech.java index 2e7b7a504a6..7bd07297896 100644 --- a/megamek/src/megamek/common/TripodMech.java +++ b/megamek/src/megamek/common/TripodMech.java @@ -1029,9 +1029,7 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod // normal front hits switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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, @@ -1064,9 +1062,7 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod case 11: return new HitData(Mech.LOC_LARM); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( + if (shouldUseEdge( "edge_when_headhit")) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, @@ -1080,9 +1076,7 @@ && getCrew().getOptions().booleanOption( // normal left side hits switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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, @@ -1138,9 +1132,7 @@ && getCrew().getOptions().booleanOption( // normal right side hits switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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, @@ -1181,9 +1173,7 @@ && getCrew().getOptions().booleanOption( case 10: return new HitData(Mech.LOC_LARM); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( + if (shouldUseEdge( "edge_when_headhit")) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, @@ -1200,10 +1190,7 @@ && getCrew().getOptions().booleanOption( && isProne()) { switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (getCrew().hasEdgeRemaining() && getCrew() - .getOptions() - .booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption( OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -1237,9 +1224,7 @@ && isProne()) { case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( + if (shouldUseEdge( "edge_when_headhit")) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, @@ -1253,10 +1238,7 @@ && getCrew().getOptions().booleanOption( } else { switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && (getCrew().hasEdgeRemaining() && getCrew() - .getOptions() - .booleanOption(OptionsConstants.EDGE_WHEN_TAC)) + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_TAC) && !game.getOptions().booleanOption( OptionsConstants.ADVCOMBAT_NO_TAC)) { getCrew().decreaseEdge(); @@ -1290,9 +1272,7 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( + if (shouldUseEdge( "edge_when_headhit")) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, @@ -1336,9 +1316,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( + if (shouldUseEdge( "edge_when_headhit")) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, @@ -1361,9 +1339,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_LARM); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( + if (shouldUseEdge( "edge_when_headhit")) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, @@ -1386,9 +1362,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( + if (shouldUseEdge( "edge_when_headhit")) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, @@ -1413,10 +1387,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM, true); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge("edge_when_headhit")) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1504,10 +1475,7 @@ && getCrew().getOptions().booleanOption( // Swarm attack locations. switch (roll) { case 2: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge("edge_when_headhit")) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1535,10 +1503,7 @@ && getCrew().getOptions().booleanOption( case 11: return new HitData(Mech.LOC_CT, true, effects); case 12: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge("edge_when_headhit")) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1577,10 +1542,7 @@ && getCrew().getOptions().booleanOption( case 5: return new HitData(Mech.LOC_RARM, (side == ToHitData.SIDE_REAR)); case 6: - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && getCrew().hasEdgeRemaining() - && getCrew().getOptions().booleanOption( - "edge_when_headhit")) { + if (shouldUseEdge("edge_when_headhit")) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index b26c347746d..75173c6768f 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -8612,10 +8612,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 (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -8666,10 +8663,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 (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -20059,9 +20053,7 @@ private Vector resolveControl(Entity e) { if (e.getAltitude() <= 0 // Don't waste the edge if it won't help && origAltitude > 1 - && game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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(); @@ -20446,10 +20438,8 @@ private Vector resolveCrewDamage(Entity e, int damage, int crewPos) { } else { e.getCrew().setKoThisRound(true, crewPos); r.choose(false); - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -20461,11 +20451,8 @@ private Vector resolveCrewDamage(Entity e, int damage, int crewPos) { // return true; } // else vDesc.add(r); - } while (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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.shouldUseEdge(OptionsConstants.EDGE_WHEN_AERO_KO)); // end of do-while if (e.getCrew().isKoThisRound(crewPos)) { boolean wasPilot = e.getCrew().getCurrentPilotIndex() == crewPos; @@ -24227,10 +24214,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 (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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(); @@ -24474,9 +24458,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 (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -24530,9 +24512,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 (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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(); @@ -24560,9 +24540,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 (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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(); @@ -24834,9 +24812,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 (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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(); @@ -25869,8 +25845,7 @@ private void checkAeroCrits(Vector vDesc, Aero a, HitData hit, if (diceRoll.getIntValue() >= capitalMissile) { // Allow a reroll with edge - if (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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); @@ -25924,9 +25899,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 (game.getOptions().booleanOption(OptionsConstants.EDGE) - && 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(); @@ -26292,9 +26265,7 @@ public Vector criticalEntity(Entity en, int loc, boolean isRear, } // if explosive use edge if ((en instanceof Mech) - && game.getOptions().booleanOption(OptionsConstants.EDGE) - && (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(); From 62ec6e86674d96f963f851021d511b36fe5f2f1d Mon Sep 17 00:00:00 2001 From: algebro Date: Mon, 5 Aug 2024 11:11:31 -0400 Subject: [PATCH 3/9] switch hardcoded string to OptionsConstants --- megamek/src/megamek/common/TripodMech.java | 33 ++++++++-------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/megamek/src/megamek/common/TripodMech.java b/megamek/src/megamek/common/TripodMech.java index 7bd07297896..c5bcac64763 100644 --- a/megamek/src/megamek/common/TripodMech.java +++ b/megamek/src/megamek/common/TripodMech.java @@ -1062,8 +1062,7 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod case 11: return new HitData(Mech.LOC_LARM); case 12: - if (shouldUseEdge( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1117,9 +1116,7 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod 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); @@ -1173,8 +1170,7 @@ && getCrew().getOptions().booleanOption( case 10: return new HitData(Mech.LOC_LARM); case 12: - if (shouldUseEdge( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1224,8 +1220,7 @@ && isProne()) { case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (shouldUseEdge( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1272,8 +1267,7 @@ && isProne()) { case 11: return new HitData(Mech.LOC_LARM, true); case 12: - if (shouldUseEdge( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1316,8 +1310,7 @@ && isProne()) { case 5: return new HitData(Mech.LOC_RARM); case 6: - if (shouldUseEdge( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1339,8 +1332,7 @@ && isProne()) { case 5: return new HitData(Mech.LOC_LARM); case 6: - if (shouldUseEdge( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1362,8 +1354,7 @@ && isProne()) { case 5: return new HitData(Mech.LOC_RARM); case 6: - if (shouldUseEdge( - "edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1387,7 +1378,7 @@ && isProne()) { case 5: return new HitData(Mech.LOC_RARM, true); case 6: - if (shouldUseEdge("edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1475,7 +1466,7 @@ && isProne()) { // Swarm attack locations. switch (roll) { case 2: - if (shouldUseEdge("edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1503,7 +1494,7 @@ && isProne()) { case 11: return new HitData(Mech.LOC_CT, true, effects); case 12: - if (shouldUseEdge("edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); @@ -1542,7 +1533,7 @@ && isProne()) { case 5: return new HitData(Mech.LOC_RARM, (side == ToHitData.SIDE_REAR)); case 6: - if (shouldUseEdge("edge_when_headhit")) { + if (shouldUseEdge(OptionsConstants.EDGE_WHEN_HEADHIT)) { getCrew().decreaseEdge(); HitData result = rollHitLocation(table, side, aimedLocation, aimingMode, cover); From 0821323ba87ec8bb00c3174c7819d78d4b9696eb Mon Sep 17 00:00:00 2001 From: algebro Date: Mon, 5 Aug 2024 11:34:27 -0400 Subject: [PATCH 4/9] fix incorrect edge conditional --- megamek/src/megamek/common/Mech.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/megamek/src/megamek/common/Mech.java b/megamek/src/megamek/common/Mech.java index 09d83515073..f7ab1efbc9f 100644 --- a/megamek/src/megamek/common/Mech.java +++ b/megamek/src/megamek/common/Mech.java @@ -2045,10 +2045,7 @@ public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMod case 11: return new HitData(Mech.LOC_RLEG); case 12: - if (shouldUseEdge(OptionsConstants.EDGE) - && 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); From 16d2e9c4025612c6b7bc962d53dffa8a94ae4207 Mon Sep 17 00:00:00 2001 From: algebro Date: Mon, 5 Aug 2024 11:37:11 -0400 Subject: [PATCH 5/9] check if getCrew() is null before checking edge --- megamek/src/megamek/common/Entity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/megamek/src/megamek/common/Entity.java b/megamek/src/megamek/common/Entity.java index e0aff5cf1c5..b51eb326d0d 100644 --- a/megamek/src/megamek/common/Entity.java +++ b/megamek/src/megamek/common/Entity.java @@ -15907,6 +15907,7 @@ public boolean countForStrengthSum() { /** @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)); } From c470153c7fd798b383cb92cf8cd905e3630ba66e Mon Sep 17 00:00:00 2001 From: algebro Date: Mon, 5 Aug 2024 11:55:18 -0400 Subject: [PATCH 6/9] re-add check to see if crew is KO'ed when rerolling pilot KOs --- megamek/src/megamek/server/GameManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/megamek/src/megamek/server/GameManager.java b/megamek/src/megamek/server/GameManager.java index 75173c6768f..4b5e9c3166d 100644 --- a/megamek/src/megamek/server/GameManager.java +++ b/megamek/src/megamek/server/GameManager.java @@ -20451,7 +20451,8 @@ private Vector resolveCrewDamage(Entity e, int damage, int crewPos) { // return true; } // else vDesc.add(r); - } while (e.shouldUseEdge(OptionsConstants.EDGE_WHEN_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)) { From 4e1e176398549ab5e64c4e1f4848a82378a07228 Mon Sep 17 00:00:00 2001 From: Sleet01 Date: Mon, 5 Aug 2024 09:26:45 -0700 Subject: [PATCH 7/9] Update history.txt --- megamek/docs/history.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/megamek/docs/history.txt b/megamek/docs/history.txt index 0a9791e28ce..7983bfc0e04 100644 --- a/megamek/docs/history.txt +++ b/megamek/docs/history.txt @@ -78,6 +78,7 @@ 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 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, From cab504fa95f7107b26b0e2e3f3e14982988b8a7b Mon Sep 17 00:00:00 2001 From: algebro Date: Mon, 5 Aug 2024 12:34:28 -0400 Subject: [PATCH 8/9] use OptionsConstants instead of hard-coded strings --- megamek/src/megamek/common/Compute.java | 2 +- megamek/src/megamek/common/FighterSquadron.java | 2 +- megamek/src/megamek/common/IBomber.java | 2 +- megamek/src/megamek/common/TechConstants.java | 4 +++- .../weapons/ArtilleryBayWeaponIndirectHomingHandler.java | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) 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/FighterSquadron.java b/megamek/src/megamek/common/FighterSquadron.java index a975daf6524..28e0571b125 100644 --- a/megamek/src/megamek/common/FighterSquadron.java +++ b/megamek/src/megamek/common/FighterSquadron.java @@ -529,7 +529,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/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/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); From f0895fd7eb64a7cf8c30994011c03b20e6d035b7 Mon Sep 17 00:00:00 2001 From: Sleet01 Date: Mon, 5 Aug 2024 09:51:57 -0700 Subject: [PATCH 9/9] Update history.txt --- megamek/docs/history.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/megamek/docs/history.txt b/megamek/docs/history.txt index 7983bfc0e04..cf776f6700c 100644 --- a/megamek/docs/history.txt +++ b/megamek/docs/history.txt @@ -79,6 +79,7 @@ MEGAMEK VERSION HISTORY: + 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,