Skip to content

Commit

Permalink
Issue 6252: Offboard Artillery cannot unjam critted weapons
Browse files Browse the repository at this point in the history
  • Loading branch information
psikomonkie committed Dec 12, 2024
1 parent b049c9a commit 83fe08f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
1 change: 1 addition & 0 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3632,6 +3632,7 @@ TargetingPhaseDisplay.fireSkip=Skip
TargetingPhaseDisplay.fireTwist=Twist
TargetingPhaseDisplay.fireSearchlight=Searchlight
TargetingPhaseDisplay.fireDisengage=Disengage
TargetingPhaseDisplay.fireClearWeaponJam=Unjam Weapon
TargetingPhaseDisplay.Skip=Skip Firing
TargetingPhaseDisplay.waitingForFiringPhase=Waiting to begin Firing phase...
TargetingPhaseDisplay.waitingForTargetingPhase=Waiting to begin Targeting phase...
Expand Down
62 changes: 52 additions & 10 deletions megamek/src/megamek/client/ui/swing/TargetingPhaseDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.awt.event.MouseEvent;
import java.util.*;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

Expand All @@ -30,15 +31,7 @@
import megamek.client.ui.swing.widget.MegaMekButton;
import megamek.client.ui.swing.widget.MekPanelTabStrip;
import megamek.common.*;
import megamek.common.actions.ArtilleryAttackAction;
import megamek.common.actions.DisengageAction;
import megamek.common.actions.EntityAction;
import megamek.common.actions.FlipArmsAction;
import megamek.common.actions.SearchlightAttackAction;
import megamek.common.actions.TorsoTwistAction;
import megamek.common.actions.TriggerAPPodAction;
import megamek.common.actions.TriggerBPodAction;
import megamek.common.actions.WeaponAttackAction;
import megamek.common.actions.*;
import megamek.common.enums.AimingMode;
import megamek.common.enums.GamePhase;
import megamek.common.event.GamePhaseChangeEvent;
Expand Down Expand Up @@ -78,7 +71,8 @@ public enum TargetingCommand implements PhaseCommand {
FIRE_FLIP_ARMS("fireFlipArms"),
FIRE_SEARCHLIGHT("fireSearchlight"),
FIRE_CANCEL("fireCancel"),
FIRE_DISENGAGE("fireDisengage");
FIRE_DISENGAGE("fireDisengage"),
FIRE_CLEAR_WEAPON("fireClearWeaponJam");

String cmd;

Expand Down Expand Up @@ -317,6 +311,9 @@ protected ArrayList<MegaMekButton> getButtonList() {
if ((cmd == TargetingCommand.FIRE_DISENGAGE) && ((ce() == null) || !ce().isOffBoard())) {
continue;
}
if (cmd == TargetingCommand.FIRE_CLEAR_WEAPON && !(ce() instanceof Tank)) {
continue;
}
buttonList.add(buttons.get(cmd));
}
return buttonList;
Expand Down Expand Up @@ -384,6 +381,9 @@ private void selectEntity(int en) {
if (!ce().isOffBoard()) {
clientgui.showFiringSolutions(ce());
}

updateClearWeaponJam();

} else {
logger.error("Tried to select non-existent entity: " + en);
}
Expand Down Expand Up @@ -481,6 +481,7 @@ private void disableButtons() {
setFireModeEnabled(false);
setNextTargetEnabled(false);
setDisengageEnabled(false);
setFireClearWeaponJamEnabled(false);
}

/**
Expand Down Expand Up @@ -638,6 +639,8 @@ private void fire() {
}
}

updateClearWeaponJam();

updateDisplayForPendingAttack(mounted, waa);
}

Expand Down Expand Up @@ -1253,6 +1256,34 @@ public void actionPerformed(ActionEvent ev) {
clear();
addAttack(new DisengageAction(currentEntity));
ready();
} else if(ev.getActionCommand().equals(TargetingCommand.FIRE_CLEAR_WEAPON.getCmd())) {
doClearWeaponJam();
}
}

/**
* clear weapon jam
*/
protected void doClearWeaponJam() {
ArrayList<Mounted<?>> weapons = ((Tank) ce()).getJammedWeapons();
String[] names = new String[weapons.size()];
for (int loop = 0; loop < names.length; loop++) {
names[loop] = weapons.get(loop).getDesc();
}
String input = (String) JOptionPane.showInputDialog(clientgui.getFrame(),
Messages.getString("FiringDisplay.ClearWeaponJam.question"),
Messages.getString("FiringDisplay.ClearWeaponJam.title"),
JOptionPane.QUESTION_MESSAGE, null, names, null);

if (input != null) {
for (int loop = 0; loop < names.length; loop++) {
if (input.equals(names[loop])) {
RepairWeaponMalfunctionAction rwma = new RepairWeaponMalfunctionAction(
ce().getId(), ce().getEquipmentNum(weapons.get(loop)));
addAttack(rwma);
ready();
}
}
}
}

Expand Down Expand Up @@ -1280,6 +1311,11 @@ && ce().getCrew().isActive()
&& SearchlightAttackAction.isPossible(clientgui.getClient().getGame(), currentEntity, target, null));
}

private void updateClearWeaponJam(){
setFireClearWeaponJamEnabled((ce() instanceof Tank) && ((Tank) ce()).canUnjamWeapon()
&& attacks.isEmpty());
}

private void setFireEnabled(boolean enabled) {
buttons.get(TargetingCommand.FIRE_FIRE).setEnabled(enabled);
clientgui.getMenuBar().setEnabled(FiringCommand.FIRE_FIRE.getCmd(), enabled);
Expand Down Expand Up @@ -1326,6 +1362,12 @@ private void setDisengageEnabled(boolean enabled) {
}
}

private void setFireClearWeaponJamEnabled(boolean enabled) {
if (buttons.containsKey(TargetingCommand.FIRE_CLEAR_WEAPON)) {
buttons.get(TargetingCommand.FIRE_CLEAR_WEAPON).setEnabled(enabled);
}
}

@Override
public void clear() {
clearAttacks();
Expand Down

0 comments on commit 83fe08f

Please sign in to comment.