Skip to content

Commit

Permalink
Merge pull request #5855 from Algebro7/ignore-edge-when-disabled
Browse files Browse the repository at this point in the history
Check if Edge is enabled in Game Options before using it
  • Loading branch information
Sleet01 authored Aug 5, 2024
2 parents cce83da + c470153 commit 51f7dea
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 158 deletions.
8 changes: 8 additions & 0 deletions megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
64 changes: 17 additions & 47 deletions megamek/src/megamek/common/Mech.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 51f7dea

Please sign in to comment.