Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if Edge is enabled in Game Options before using it #5855

Merged
merged 6 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Sleet01 marked this conversation as resolved.
Show resolved Hide resolved
&& getCrew().getOptions().booleanOption(option));
}
}
78 changes: 17 additions & 61 deletions megamek/src/megamek/common/Mech.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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)) {
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading