Skip to content

Commit

Permalink
Merge pull request #3012 from NickAragua/no_torso_twist_tag
Browse files Browse the repository at this point in the history
Fix #3002
  • Loading branch information
NickAragua authored Jul 14, 2021
2 parents 1bc2286 + 2986f94 commit 2ebbf94
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,6 @@ private void addHexDonuts(Coords coords, Set<Targetable> targetList, IGame game)
public FiringPlan calculateIndirectArtilleryPlan(Entity shooter, IGame game, Princess owner) {
FiringPlan bestPlan = calculateIndirectArtilleryPlan(shooter, game, owner, 0);

// simply loop through all possible facings and see if any of those is better than the no-turning plan
if (!shooter.isOffBoard()) {
for (int facingChange : FireControl.getValidFacingChanges(shooter)) {
FiringPlan twistPlan = calculateIndirectArtilleryPlan(shooter, game, owner, facingChange);
if (twistPlan.getUtility() > bestPlan.getUtility()) {
bestPlan = twistPlan;
}
}
}

return bestPlan;
}

Expand Down
25 changes: 0 additions & 25 deletions megamek/src/megamek/client/ui/swing/MapMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,6 @@ private boolean createMenu() {
itemCount++;
}

} else if (currentPanel instanceof TargetingPhaseDisplay) {

if (itemCount > 0) {
addSeparator();
itemCount++;
}

menu = createTorsoTwistMenu();
if (menu.getItemCount() > 0) {
this.add(menu);
itemCount++;
}

menu = createRotateTurretMenu();
if (menu.getItemCount() > 0) {
this.add(menu);
itemCount++;
}

} else if ((currentPanel instanceof FiringDisplay)) {

if (itemCount > 0) {
Expand Down Expand Up @@ -1448,9 +1429,6 @@ public void actionPerformed(ActionEvent e) {
int twistDir = Integer.parseInt(e.getActionCommand());
if (currentPanel instanceof FiringDisplay) {
((FiringDisplay) currentPanel).torsoTwist(twistDir);
} else if (currentPanel instanceof TargetingPhaseDisplay) {
((TargetingPhaseDisplay) currentPanel)
.torsoTwist(twistDir);
}
} catch (Exception ex) {
ex.printStackTrace();
Expand All @@ -1474,9 +1452,6 @@ public void actionPerformed(ActionEvent e) {
.nextToken()), Integer.parseInt(result.nextToken()));
if (currentPanel instanceof FiringDisplay) {
((FiringDisplay) currentPanel).torsoTwist(coord);
} else if (currentPanel instanceof TargetingPhaseDisplay) {
((TargetingPhaseDisplay) currentPanel)
.torsoTwist(coord);
}
} catch (Exception ex) {
ex.printStackTrace();
Expand Down
112 changes: 2 additions & 110 deletions megamek/src/megamek/client/ui/swing/TargetingPhaseDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public class TargetingPhaseDisplay extends StatusBarPhaseDisplay implements
*/
public static enum TargetingCommand implements PhaseCommand {
FIRE_NEXT("fireNext"),
FIRE_TWIST("fireTwist"),
FIRE_FIRE("fireFire"),
FIRE_SKIP("fireSkip"),
FIRE_NEXT_TARG("fireNextTarg"),
Expand Down Expand Up @@ -133,8 +132,6 @@ public String toString() {
// is the shift key held?
private boolean shiftheld;

private boolean twisting;

private final IGame.Phase phase;

private Entity[] visibleTargets;
Expand Down Expand Up @@ -206,51 +203,7 @@ public void performAction() {
removeLastFiring();
}
});
// Register the action for TWIST_LEFT
controller.registerCommandAction(KeyCommandBind.TWIST_LEFT.cmd,
new CommandAction() {

@Override
public boolean shouldPerformAction() {
if (!clientgui.getClient().isMyTurn()
|| clientgui.bv.getChatterBoxActive()
|| !display.isVisible()
|| display.isIgnoringEvents()) {
return false;
} else {
return true;
}
}

@Override
public void performAction() {
updateFlipArms(false);
torsoTwist(0);
}
});

// Register the action for TWIST_RIGHT
controller.registerCommandAction(KeyCommandBind.TWIST_RIGHT.cmd,
new CommandAction() {

@Override
public boolean shouldPerformAction() {
if (!clientgui.getClient().isMyTurn()
|| clientgui.bv.getChatterBoxActive()
|| !display.isVisible()
|| display.isIgnoringEvents()) {
return false;
} else {
return true;
}
}

@Override
public void performAction() {
updateFlipArms(false);
torsoTwist(1);
}
});
// Register the action for FIRE
controller.registerCommandAction(KeyCommandBind.FIRE.cmd,
new CommandAction() {
Expand Down Expand Up @@ -575,10 +528,7 @@ private void selectEntity(int en) {
// Update the menu bar.
clientgui.getMenuBar().setEntity(ce());

// 2003-12-29, nemchenk -- only twist if crew conscious
setTwistEnabled(ce().canChangeSecondaryFacing()
&& ce().getCrew().isActive());
setFlipArmsEnabled(ce().canFlipArms());
setFlipArmsEnabled(ce().canFlipArms() && ce().getCrew().isActive());
updateSearchlight();

setFireModeEnabled(true);
Expand Down Expand Up @@ -712,7 +662,6 @@ private void endMyTurn() {
private void disableButtons() {
setFireEnabled(false);
setSkipEnabled(false);
setTwistEnabled(false);
setNextEnabled(false);
butDone.setEnabled(false);
setFlipArmsEnabled(false);
Expand Down Expand Up @@ -1119,49 +1068,6 @@ public void updateTarget() {
updateSearchlight();
}

/**
* Torso twist in the proper direction.
*/
void torsoTwist(Coords cTarget) {
int direction = ce().getFacing();

if (null != cTarget) {
direction = ce().clipSecondaryFacing(
ce().getPosition().direction(cTarget));
}

if (direction != ce().getSecondaryFacing()) {
clearAttacks();
attacks.addElement(new TorsoTwistAction(cen, direction));
ce().setSecondaryFacing(direction);
refreshAll();
}
}

/**
* Torso twist to the left or right
*
* @param twistDirection An <code>int</code> specifying wether we're twisting left or
* right, 0 if we're twisting to the left, 1 if to the right.
*/

void torsoTwist(int twistDirection) {
int direction = ce().getSecondaryFacing();
if (twistDirection == 0) {
clearAttacks();
direction = ce().clipSecondaryFacing((direction + 5) % 6);
attacks.addElement(new TorsoTwistAction(cen, direction));
ce().setSecondaryFacing(direction);
refreshAll();
} else if (twistDirection == 1) {
clearAttacks();
direction = ce().clipSecondaryFacing((direction + 7) % 6);
attacks.addElement(new TorsoTwistAction(cen, direction));
ce().setSecondaryFacing(direction);
refreshAll();
}
}

/**
* Cache the list of visible targets. This is used for the 'next target'
* button.
Expand Down Expand Up @@ -1309,13 +1215,11 @@ public void hexMoused(BoardViewEvent b) {
}

if (b.getType() == BoardViewEvent.BOARD_HEX_DRAGGED) {
if (shiftheld || twisting) {
if (shiftheld) {
updateFlipArms(false);
torsoTwist(b.getCoords());
}
clientgui.getBoardView().cursor(b.getCoords());
} else if (b.getType() == BoardViewEvent.BOARD_HEX_CLICKED) {
twisting = false;
clientgui.getBoardView().select(b.getCoords());
}
}
Expand All @@ -1333,7 +1237,6 @@ public void hexSelected(BoardViewEvent b) {
&& (ce() != null) && !b.getCoords().equals(ce().getPosition())) {
if (shiftheld) {
updateFlipArms(false);
torsoTwist(b.getCoords());
} else if (phase == IGame.Phase.PHASE_TARGETING) {
target(new HexTarget(b.getCoords(), Targetable.TYPE_HEX_ARTILLERY));
} else {
Expand Down Expand Up @@ -1499,8 +1402,6 @@ public void actionPerformed(ActionEvent ev) {
fire();
} else if (ev.getActionCommand().equals(TargetingCommand.FIRE_SKIP.getCmd())) {
nextWeapon();
} else if (ev.getActionCommand().equals(TargetingCommand.FIRE_TWIST.getCmd())) {
twisting = true;
} else if (ev.getActionCommand().equals(TargetingCommand.FIRE_NEXT.getCmd())) {
selectEntity(clientgui.getClient().getNextEntityNum(cen));
} else if (ev.getActionCommand().equals(TargetingCommand.FIRE_NEXT_TARG.getCmd())) {
Expand All @@ -1527,10 +1428,6 @@ private void updateFlipArms(boolean armsFlipped) {
return;
}

twisting = false;

torsoTwist(null);

clearAttacks();
ce().setArmsFlipped(armsFlipped);
attacks.addElement(new FlipArmsAction(cen, armsFlipped));
Expand All @@ -1552,11 +1449,6 @@ private void setFireEnabled(boolean enabled) {
clientgui.getMenuBar().setEnabled(FiringCommand.FIRE_FIRE.getCmd(), enabled);
}

private void setTwistEnabled(boolean enabled) {
buttons.get(TargetingCommand.FIRE_TWIST).setEnabled(enabled);
clientgui.getMenuBar().setEnabled(FiringCommand.FIRE_TWIST.getCmd(), enabled);
}

private void setSkipEnabled(boolean enabled) {
buttons.get(TargetingCommand.FIRE_SKIP).setEnabled(enabled);
clientgui.getMenuBar().setEnabled(FiringCommand.FIRE_SKIP.getCmd(), enabled);
Expand Down

0 comments on commit 2ebbf94

Please sign in to comment.