diff --git a/megamek/i18n/megamek/client/messages.properties b/megamek/i18n/megamek/client/messages.properties index 729906b54eb..a0905aaeb6a 100644 --- a/megamek/i18n/megamek/client/messages.properties +++ b/megamek/i18n/megamek/client/messages.properties @@ -4675,14 +4675,18 @@ Gamemaster.KillUnit=Kill Unit Gamemaster.KillUnit.text=Kill Unit {0} Gamemaster.KillUnit.confirmation=Are you sure you want to kill {0}? Gamemaster.SpecialCommands=Special Actions + #Gamemaster Chat Commands Gamemaster.cmd.missingUnit=Specified unit is not on the board. Gamemaster.cmd.error.integerparse=must be between the min and max values: +Gamemaster.cmd.error.outofbounds=Specified hex is not on the board. Gamemaster.cmd.help=Usage: Gamemaster.cmd.params.required=Required. Gamemaster.cmd.params.optional=Optional. Gamemaster.cmd.x=The x coordinate of the hex. Gamemaster.cmd.y=The y coordinate of the hex. +Gamemaster.cmd.playerID=The ID of the player that is going to be held as responsible. + # Rescue cmd Gamemaster.cmd.rescue.longName=Rescue Unit Gamemaster.cmd.rescue.unitID=ID of the unit to rescue. @@ -4721,7 +4725,7 @@ Gamemaster.cmd.changeweather.blowsand=Blowing Sand Gamemaster.cmd.changeweather.emi=EMI Gamemaster.cmd.changeweather.weather=Weather # Disaster cmd -Gamemaster.cmd.disaster.longName=Disaster +Gamemaster.cmd.disaster.longName=Disaster! Gamemaster.cmd.disaster.help=Causes a disaster on the board. Gamemaster.cmd.disaster.type=Type of disaster. Beware, some disasters are very destructive! Gamemaster.cmd.changeweather.fog.success=The fog has changed. @@ -4740,7 +4744,7 @@ Gamemaster.cmd.firestarter.longName=Start a Fire Gamemaster.cmd.fire.type=Type of fire. They are 1=Normal, 2=Inferno, 3=Inferno Bomb or 4=Inferno IV. Gamemaster.cmd.fire.help=Starts a fire on the board. # Firestorm cmd -Gamemaster.cmd.firestorm.longName=Firestorm +Gamemaster.cmd.firestorm.longName=Start a Firestorm Gamemaster.cmd.firestorm.help=Starts fire in the entire board. Gamemaster.cmd.fire.failed=Failed to ignite fire. Gamemaster.cmd.fire.percent=Percentage of the board hexes to ignite. @@ -4751,13 +4755,30 @@ Gamemaster.cmd.orbitalbombardment.dmg=Total damage at target hex. Gamemaster.cmd.orbitalbombardment.radius=Radius of the bombardment. Gamemaster.cmd.orbitalbombardment.error.outofbounds=Specified hex is not on the board. Gamemaster.cmd.orbitalbombardment.success=Orbital bombardment incoming! + +#Nuclear strike +Gamemaster.cmd.nuke.longName=Nuclear Strike +Gamemaster.cmd.nuke.help=Calls a Nuclear Strike onto the board, to be exploded at the end of the next weapons attack phase. +Gamemaster.cmd.nuke.type=The type of nuke to drop. +Gamemaster.cmd.nuke.error.disabled=Command-line nukes are not enabled in this game. + +Gamemaster.cmd.nuke.success=A nuke is incoming! Take cover! + +#Nuclear strike custom +Gamemaster.cmd.nukec.longName=Nuclear Strike (Custom) +Gamemaster.cmd.nukec.help=Calls a Nuclear Strike onto the board with a custom bomb, to be exploded at the end of the next weapons attack phase. +Gamemaster.cmd.nukec.dmg=Total damage at target hex. +Gamemaster.cmd.nukec.radius=Radius of the secondary explosion of the nuclear strike. +Gamemaster.cmd.nukec.deg=Degradation of the nuclear strike. +Gamemaster.cmd.nukec.depth=Crater depth of the nuclear strike. + # Firefight -Gamemaster.cmd.firefight.longName=Firefight +Gamemaster.cmd.firefight.longName=Extinguish a Fire Gamemaster.cmd.firefight.reason=Fire extinguished Gamemaster.cmd.firefight.help=Extinguishes a fire on the board. # No Fire -Gamemaster.cmd.nofire.longName=No Fires +Gamemaster.cmd.nofire.longName=Extinguish All Fires Gamemaster.cmd.nofire.help=Extinguishes all fires on the board. # Change player team diff --git a/megamek/src/megamek/client/ui/swing/MapMenu.java b/megamek/src/megamek/client/ui/swing/MapMenu.java index eb974ae5acc..8244e28812b 100644 --- a/megamek/src/megamek/client/ui/swing/MapMenu.java +++ b/megamek/src/megamek/client/ui/swing/MapMenu.java @@ -696,7 +696,8 @@ private JMenu createGMSpecialCommandsMenu() { new RemoveSmokeCommand(null, null), new OrbitalBombardmentCommand(null, null), new DisasterCommand(null, null), - new NukeCommand(null, null), + new NuclearStrikeCommand(null, null), + new NuclearStrikeCustomCommand(null, null), new EndGameCommand(null, null) ).forEach(cmd -> { JMenuItem item = new JMenuItem(cmd.getLongName()); diff --git a/megamek/src/megamek/client/ui/swing/commands/ClientCommandPanel.java b/megamek/src/megamek/client/ui/swing/commands/ClientCommandPanel.java index b50abd4e844..ac4150f70ea 100644 --- a/megamek/src/megamek/client/ui/swing/commands/ClientCommandPanel.java +++ b/megamek/src/megamek/client/ui/swing/commands/ClientCommandPanel.java @@ -1,3 +1,16 @@ +/* + * MegaMek - Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ package megamek.client.ui.swing.commands; import megamek.client.ui.swing.ClientGUI; @@ -15,11 +28,13 @@ /** * Dialog for executing a client command. + * @author Luana Coppio */ public class ClientCommandPanel extends JDialog { private final ClientServerCommand command; private final ClientGUI client; private final Coords coords; + private int yPosition = 0; /** * Constructor for the dialog for executing a client command. @@ -29,7 +44,7 @@ public class ClientCommandPanel extends JDialog { * @param command The command to render. */ public ClientCommandPanel(JFrame parent, ClientGUI client, ClientServerCommand command, @Nullable Coords coords) { - super(parent, command.getName(), true); + super(parent, command.getLongName() + " /" + command.getName(), true); this.command = command; this.client = client; this.coords = coords; @@ -37,7 +52,7 @@ public ClientCommandPanel(JFrame parent, ClientGUI client, ClientServerCommand c } private void initializeUI(JFrame parent) { - setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); + setLayout(new GridBagLayout()); addTitleAndDescription(); Map argumentComponents = addArgumentComponents(); addExecuteButton(argumentComponents); @@ -46,18 +61,43 @@ private void initializeUI(JFrame parent) { } private void addTitleAndDescription() { - JPanel titlePanel = new JPanel(); - titlePanel.setLayout(new BoxLayout(titlePanel, BoxLayout.Y_AXIS)); - JLabel titleLabel = new JLabel(command.getLongName()); - titleLabel.setFont(new Font("Arial", Font.BOLD, 16)); - titlePanel.add(titleLabel); + var title = new JLabel(command.getLongName()); + title.setFont(new Font("Arial", Font.BOLD, 18)); + var gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = yPosition++; + gridBagConstraints.gridwidth = 2; + gridBagConstraints.gridheight = 1; + gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; + add(title, gridBagConstraints); + + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = yPosition++; + gridBagConstraints.gridwidth = 4; + gridBagConstraints.gridheight = 1; + gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; + + add(new JSeparator(), gridBagConstraints); + + var helpLabel = new JLabel(command.getHelpHtml()); + helpLabel.setFont(new Font("Arial", Font.PLAIN, 14)); + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = yPosition++; + gridBagConstraints.gridwidth = 4; + gridBagConstraints.gridheight = 3; + yPosition += 2; - JLabel helpLabel = new JLabel(command.getHelpHtml()); - helpLabel.setFont(new Font("Arial", Font.PLAIN, 12)); - titlePanel.add(helpLabel); + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = yPosition++; + gridBagConstraints.gridwidth = 4; + gridBagConstraints.gridheight = 1; + add(new JSeparator(), gridBagConstraints); - add(titlePanel); + add(helpLabel, gridBagConstraints); } private Map addArgumentComponents() { @@ -65,96 +105,221 @@ private Map addArgumentComponents() { Map argumentComponents = new HashMap<>(); for (Argument argument : arguments) { - JPanel argumentPanel = createArgumentPanel(argument); - add(argumentPanel); - argumentComponents.put(argument.getName(), getArgumentComponent(argument, argumentPanel)); + argumentComponents.put(argument.getName(), getArgumentComponent(argument)); } return argumentComponents; } - private JPanel createArgumentPanel(Argument argument) { - JPanel argumentPanel = new JPanel(); - argumentPanel.setLayout(new FlowLayout()); - JLabel label = new JLabel(argument.getName() + ":"); - argumentPanel.add(label); - return argumentPanel; - } - - private JComponent getArgumentComponent(Argument argument, JPanel argumentPanel) { - if (argument instanceof IntegerArgument intArg) { + private JComponent getArgumentComponent(Argument argument) { + if (argument instanceof CoordXArgument intArg) { + JLabel label = new JLabel(argument.getName() + ":"); + var labelConstraintBag = getGridBagConstraints(0, yPosition); + add(label, labelConstraintBag); + JSpinner spinner = createSpinner(intArg); + spinner.setToolTipText(argument.getHelp()); + var gridBagConstraints = getGridBagConstraints(1, yPosition); + add(spinner, gridBagConstraints); + return spinner; + } else if (argument instanceof CoordYArgument intArg) { + JLabel label = new JLabel(argument.getName() + ":"); + var labelConstraintBag = getGridBagConstraints(2, yPosition); + add(label, labelConstraintBag); + JSpinner spinner = createSpinner(intArg); + spinner.setToolTipText(argument.getHelp()); + var gridBagConstraints = getGridBagConstraints(3, yPosition++); + add(spinner, gridBagConstraints); + return spinner; + } else if (argument instanceof PlayerArgument playerArg) { + JLabel label = new JLabel(argument.getName() + ":"); + var labelConstraintBag = getGridBagConstraints(0, yPosition); + add(label, labelConstraintBag); + JComboBox comboBox = createPlayerComboBox(playerArg); + comboBox.setToolTipText(argument.getHelp()); + var gridBagConstraints = getGridBagConstraints(1, yPosition++); + add(comboBox, gridBagConstraints); + return comboBox; + } else if (argument instanceof UnitArgument unitArg) { + JLabel label = new JLabel(argument.getName() + ":"); + var labelConstraintBag = getGridBagConstraints(0, yPosition); + add(label, labelConstraintBag); + JComboBox comboBox = createUnitComboBox(unitArg); + comboBox.setToolTipText(argument.getHelp()); + var gridBagConstraints = getGridBagConstraints(1, yPosition++); + add(comboBox, gridBagConstraints); + return comboBox; + } else if (argument instanceof TeamArgument teamArg) { + JLabel label = new JLabel(argument.getName() + ":"); + var labelConstraintBag = getGridBagConstraints(0, yPosition); + add(label, labelConstraintBag); + JComboBox comboBox = createTeamsComboBox(teamArg); + comboBox.setToolTipText(argument.getHelp()); + var gridBagConstraints = getGridBagConstraints(1, yPosition++); + add(comboBox, gridBagConstraints); + return comboBox; + } else if (argument instanceof IntegerArgument intArg) { + JLabel label = new JLabel(argument.getName() + ":"); + var labelConstraintBag = getGridBagConstraints(0, yPosition); + add(label, labelConstraintBag); JSpinner spinner = createSpinner(intArg); - argumentPanel.add(spinner); + spinner.setToolTipText(argument.getHelp()); + var gridBagConstraints = getGridBagConstraints(1, yPosition++); + add(spinner, gridBagConstraints); return spinner; } else if (argument instanceof OptionalIntegerArgument intArg) { + JLabel label = new JLabel(argument.getName() + ":"); + var labelConstraintBag = getGridBagConstraints(0, yPosition); + add(label, labelConstraintBag); JSpinner spinner = createSpinner(intArg); - argumentPanel.add(spinner); + spinner.setToolTipText(argument.getHelp()); + var gridBagConstraints = getGridBagConstraints(1, yPosition++); + add(spinner, gridBagConstraints); return spinner; } else if (argument instanceof OptionalEnumArgument enumArg) { + JLabel label = new JLabel(argument.getName() + ":"); + var labelConstraintBag = getGridBagConstraints(0, yPosition); + add(label, labelConstraintBag); JComboBox comboBox = createOptionalEnumComboBox(enumArg); - argumentPanel.add(comboBox); + comboBox.setToolTipText(argument.getHelp()); + var gridBagConstraints = getGridBagConstraints(1, yPosition++); + add(comboBox, gridBagConstraints); return comboBox; } else if (argument instanceof EnumArgument enumArg) { + JLabel label = new JLabel(argument.getName() + ":"); + var labelConstraintBag = getGridBagConstraints(0, yPosition); + add(label, labelConstraintBag); JComboBox comboBox = createEnumComboBox(enumArg); - argumentPanel.add(comboBox); + comboBox.setToolTipText(argument.getHelp()); + var gridBagConstraints = getGridBagConstraints(1, yPosition++); + add(comboBox, gridBagConstraints); return comboBox; } else if (argument instanceof OptionalPasswordArgument) { + JLabel label = new JLabel(argument.getName() + ":"); + var labelConstraintBag = getGridBagConstraints(0, yPosition); + add(label, labelConstraintBag); JPasswordField passwordField = new JPasswordField(); - argumentPanel.add(passwordField); + passwordField.setToolTipText(argument.getHelp()); + var gridBagConstraints = getGridBagConstraints(1, yPosition++); + add(passwordField, gridBagConstraints); return passwordField; } else if (argument instanceof StringArgument stringArg) { + JLabel label = new JLabel(argument.getName() + ":"); + var labelConstraintBag = getGridBagConstraints(0, yPosition); + add(label, labelConstraintBag); JTextField textField = new JTextField(); + textField.setToolTipText(argument.getHelp()); if (stringArg.hasDefaultValue()) { textField.setText(stringArg.getValue()); } - argumentPanel.add(textField); + var gridBagConstraints = getGridBagConstraints(1, yPosition++); + add(textField, gridBagConstraints); return textField; } else if (argument instanceof OptionalStringArgument stringArg) { + JLabel label = new JLabel(argument.getName() + ":"); + var labelConstraintBag = getGridBagConstraints(0, yPosition); + add(label, labelConstraintBag); JTextField textField = new JTextField(); + textField.setToolTipText(argument.getHelp()); if (stringArg.getValue().isPresent()) { textField.setText(stringArg.getValue().get()); } - argumentPanel.add(textField); + var gridBagConstraints = getGridBagConstraints(1, yPosition++); + add(textField, gridBagConstraints); return textField; } else if (argument instanceof BooleanArgument boolArg) { + JLabel label = new JLabel(argument.getName() + ":"); + var labelConstraintBag = getGridBagConstraints(0, yPosition); + add(label, labelConstraintBag); JCheckBox checkBox = new JCheckBox(); + checkBox.setToolTipText(argument.getHelp()); if (boolArg.hasDefaultValue()) { checkBox.setSelected(boolArg.getValue()); } - argumentPanel.add(checkBox); + var gridBagConstraints = getGridBagConstraints(1, yPosition++); + add(checkBox, gridBagConstraints); return checkBox; } return null; } - private boolean isArgumentX(Argument argument) { - return argument.getName().equals("x"); + private GridBagConstraints getGridBagConstraints(int x, int y) { + var gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = x; + gridBagConstraints.gridy = y; + gridBagConstraints.gridwidth = 1; + gridBagConstraints.gridheight = 1; + gridBagConstraints.fill = GridBagConstraints.NONE; + gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; + return gridBagConstraints; } - private boolean isArgumentY(Argument argument) { - return argument.getName().equals("y"); + private JSpinner createSpinner(OptionalIntegerArgument intArg) { + return new JSpinner(new SpinnerNumberModel( + Math.max(intArg.getMinValue(), 0), + intArg.getMinValue(), + intArg.getMaxValue(), + 1)); } - private int getIntArgumentDefaultValue(IntegerArgument intArg) { - return intArg.hasDefaultValue() ? intArg.getValue() : isArgumentX(intArg) ? coords.getX()+1 : - isArgumentY(intArg) ? coords.getY()+1 : 0; + private JSpinner createSpinner(CoordXArgument coordX) { + return new JSpinner(new SpinnerNumberModel( + coords.getX()+1, + 0, + 1_000_000, + 1)); } - private JSpinner createSpinner(OptionalIntegerArgument intArg) { + private JSpinner createSpinner(CoordYArgument coordY) { return new JSpinner(new SpinnerNumberModel( - (int) intArg.getValue().orElse(0), - intArg.getMinValue(), - intArg.getMaxValue(), + coords.getY()+1, + 0, + 1_000_000, 1)); } private JSpinner createSpinner(IntegerArgument intArg) { return new JSpinner(new SpinnerNumberModel( - getIntArgumentDefaultValue(intArg), + intArg.hasDefaultValue() ? intArg.getValue() : 0, intArg.getMinValue(), intArg.getMaxValue(), 1)); } + private JComboBox createPlayerComboBox(PlayerArgument playerArgument) { + JComboBox comboBox = new JComboBox<>(); + var players = client.getClient().getGame().getPlayersList(); + for (var player : players) { + comboBox.addItem(player.getId() + ":" + player.getName()); + } + + return comboBox; + } + + private JComboBox createUnitComboBox(UnitArgument unitArgument) { + JComboBox comboBox = new JComboBox<>(); + var entities = client.getClient().getGame().getEntitiesVector(); + for (var entity : entities) { + comboBox.addItem(entity.getId() + ":" + entity.getDisplayName()); + } + + var entitiesAtSpot = client.getClient().getGame().getEntities(coords); + if (entitiesAtSpot.hasNext()) { + var selectedEntity = entitiesAtSpot.next(); + comboBox.setSelectedItem(selectedEntity.getId() + ":" + selectedEntity.getDisplayName()); + } + + return comboBox; + } + + private JComboBox createTeamsComboBox(TeamArgument teamArgument) { + JComboBox comboBox = new JComboBox<>(); + var teams = client.getClient().getGame().getTeams(); + for (var team : teams) { + comboBox.addItem(team.getId() + ""); + } + + return comboBox; + } + private JComboBox createOptionalEnumComboBox(OptionalEnumArgument enumArg) { JComboBox comboBox = new JComboBox<>(); if (enumArg.getValue() == null) { @@ -182,16 +347,21 @@ private JComboBox createEnumComboBox(EnumArgument enumArg) { } private void addExecuteButton(Map argumentComponents) { - add(getExecuteButton(argumentComponents)); + var gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = yPosition; + gridBagConstraints.gridwidth = 2; + gridBagConstraints.gridheight = 1; + add(getExecuteButton(argumentComponents), gridBagConstraints); } private JButton getExecuteButton(Map argumentComponents) { - JButton executeButton = new JButton("Execute Command"); + JButton executeButton = new JButton("Execute"); executeButton.addActionListener(e -> { int response = JOptionPane.showConfirmDialog( this, "Are you sure you want to execute this command?", - "Execute Command", + "Execute?", JOptionPane.YES_NO_OPTION ); if (response == JOptionPane.YES_OPTION) { @@ -226,6 +396,19 @@ private void executeCommand(Map argumentComponents) { args[i] = argument.getName() + "=" + (((JCheckBox) component).isSelected() ? "true" : "false"); } else if (component instanceof JComboBox) { if (argument instanceof OptionalEnumArgument) { + String selectedItem = (String) ((JComboBox) component).getSelectedItem(); + if (selectedItem == null || selectedItem.equals("-")) { + // If it is null we just set it to an empty string and move on + args[i] = ""; + continue; + } + var selectedItemValue = selectedItem.split(":")[0].trim(); + args[i] = argument.getName() + "=" + selectedItemValue; + } else if ( + (argument instanceof PlayerArgument) || + (argument instanceof UnitArgument) || + (argument instanceof TeamArgument)) { + String selectedItem = (String) ((JComboBox) component).getSelectedItem(); if (selectedItem == null || selectedItem.equals("-")) { // If it is null we just set it to an empty string and move on diff --git a/megamek/src/megamek/common/Entity.java b/megamek/src/megamek/common/Entity.java index 9ec423ce322..4b4dbf61637 100644 --- a/megamek/src/megamek/common/Entity.java +++ b/megamek/src/megamek/common/Entity.java @@ -6789,15 +6789,15 @@ public void assignAMS(final List attacks) { .forEach(ams -> { // make a new list of only incoming attacks in arc final List attacksInArc = attacks.stream() - .filter(weaponHandler -> (weaponHandler.getWaa() != null) - && !targets.contains(weaponHandler.getWaa()) + .filter(weaponHandler -> (weaponHandler.getWeaponAttackAction() != null) + && !targets.contains(weaponHandler.getWeaponAttackAction()) && Compute.isInArc(getGame(), getId(), getEquipmentNum(ams), (weaponHandler instanceof CapitalMissileBearingsOnlyHandler) ? getGame().getTarget( - weaponHandler.getWaa().getOriginalTargetType(), - weaponHandler.getWaa().getOriginalTargetId()) - : getGame().getEntity(weaponHandler.getWaa().getEntityId()))) - .map(WeaponHandler::getWaa) + weaponHandler.getWeaponAttackAction().getOriginalTargetType(), + weaponHandler.getWeaponAttackAction().getOriginalTargetId()) + : getGame().getEntity(weaponHandler.getWeaponAttackAction().getEntityId()))) + .map(WeaponHandler::getWeaponAttackAction) .collect(Collectors.toList()); if (attacksInArc.isEmpty()) { diff --git a/megamek/src/megamek/common/Game.java b/megamek/src/megamek/common/Game.java index 1e072fb41a8..c80c8da72c1 100644 --- a/megamek/src/megamek/common/Game.java +++ b/megamek/src/megamek/common/Game.java @@ -459,7 +459,7 @@ private boolean isOffboardPlayable() { // aerospace // unit having left the field already, for example return getAttacksVector().stream() - .map(AttackHandler::getWaa) + .map(AttackHandler::getWeaponAttackAction) .filter(Objects::nonNull) .anyMatch(waa -> waa.getAmmoMunitionType().contains(AmmoType.Munitions.M_HOMING)); } @@ -1121,6 +1121,22 @@ public int getNoOfEntities() { return (possibleEntity instanceof Entity) ? (Entity) possibleEntity : null; } + /** + * When it has to exist, the entity HAS to exists. If it doesn't, throw a no such element exception. + * This is to be used in place of the previous getEntity method when the entity is expected to exist and the following actions + * will cause a null pointer exception if the entity does not exist. + * @param id The id number of the entity to get. + * @return The entity with the given id number or throw a no such element exception. + */ + public Entity getEntityOrThrow(final int id) { + InGameObject possibleEntity = inGameObjects.get(id); + var entity = (possibleEntity instanceof Entity) ? (Entity) possibleEntity : null; + if (entity == null) { + throw new NoSuchElementException("No value present"); + } + return entity; + } + /** * looks for an entity by id number even if out of the game */ diff --git a/megamek/src/megamek/common/Player.java b/megamek/src/megamek/common/Player.java index acfd02920c4..4b3bda1e1dc 100644 --- a/megamek/src/megamek/common/Player.java +++ b/megamek/src/megamek/common/Player.java @@ -19,20 +19,20 @@ */ package megamek.common; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Vector; - import megamek.client.ui.swing.util.PlayerColour; import megamek.common.hexarea.BorderHexArea; import megamek.common.hexarea.HexArea; import megamek.common.icons.Camouflage; import megamek.common.options.OptionsConstants; +import java.io.Serial; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Vector; + /** * Represents a player in the game. - * * Note that Player should be usable for any type of game (TW, AS, BF, SBF) and therefore should not * make any direct use of Game, Entity, AlphaStrikeElement etc., instead using IGame and InGameObject if necessary. * Note that two Players are equal if their ID is equal. @@ -40,6 +40,7 @@ public final class Player extends TurnOrdered { //region Variable Declarations + @Serial private static final long serialVersionUID = 6828849559007455761L; public static final int PLAYER_NONE = -1; @@ -85,6 +86,10 @@ public final class Player extends TurnOrdered { private int initialEntityCount; private int initialBV; + // Battlefield Support Points + private float initialBSP; + private float currentBSP; + // initiative bonuses go here because we don't know if teams are rolling // initiative collectively // if they are then we pick the best non-zero bonuses @@ -146,7 +151,7 @@ public boolean containsMinefield(Minefield mf) { public boolean hasMinefields() { return (numMfCmd > 0) || (numMfConv > 0) || (numMfVibra > 0) || (numMfActive > 0) || (numMfInferno > 0) - || getGroundObjectsToPlace().size() > 0; + || !getGroundObjectsToPlace().isEmpty(); } public void setNbrMFConventional(int nbrMF) { @@ -270,7 +275,7 @@ public boolean isGameMaster() { } /** - * If you are checking to see this player is a Game Master, use {@link #isGameMaster()} ()} instead + * If you are checking to see this player is a Game Master, use {@link #isGameMaster()} instead * @return the value of gameMaster flag, without checking if it is permitted. */ public boolean getGameMaster() { @@ -348,7 +353,7 @@ public void setSingleBlind(boolean singleBlind) { } /** - * If you are checking to see this player can ignore double-blind, use {@link #canIgnoreDoubleBlind()} ()} instead + * If you are checking to see this player can ignore double-blind, use {@link #canIgnoreDoubleBlind()} instead * @return the value of singleBlind flag, without checking if it is permitted. */ public boolean getSingleBlind() { @@ -554,6 +559,35 @@ public boolean isMyUnit(InGameObject unit) { return unit.getOwnerId() == id; } + public float getInitialBSP() { + return initialBSP; + } + + public void setInitialBSP(final int initialBSP) { + this.initialBSP = initialBSP; + } + + public float getCurrentBSP() { + return currentBSP; + } + + public void setCurrentBSP(final float currentBSP) { + this.currentBSP = currentBSP; + } + + /** + * Changes the current BSP by the given amount. Returns false if the change would result in a negative value. + * @param amountToChange The amount to change the current BSP by (negative for decrease) + * @return True if the change was successful, false if the change was canceled because it does not have enough BSP + */ + public boolean changeCurrentBSP(final float amountToChange) { + if (currentBSP + amountToChange < 0) { + return false; + } + this.currentBSP += amountToChange; + return true; + } + public int getInitialBV() { return initialBV; } @@ -594,8 +628,7 @@ public int getTurnInitBonus() { int bonus = 0; for (InGameObject object : game.getInGameObjects()) { - if (object instanceof Entity && ((Entity) object).getOwner().equals(this)) { - Entity entity = (Entity) object; + if (object instanceof Entity entity && entity.getOwner().equals(this)) { if (game.getOptions().booleanOption(OptionsConstants.ADVANCED_TACOPS_MOBILE_HQS)) { bonus = Math.max(entity.getHQIniBonus(), bonus); } @@ -616,8 +649,7 @@ public int getCommandBonus() { } int commandb = 0; for (InGameObject unit : game.getInGameObjects()) { - if (unit instanceof Entity) { - Entity entity = (Entity) unit; + if (unit instanceof Entity entity) { if ((null != entity.getOwner()) && entity.getOwner().equals(this) && !entity.isDestroyed() @@ -727,6 +759,9 @@ public Player copy() { copy.initialEntityCount = initialEntityCount; copy.initialBV = initialBV; + copy.initialBSP = initialBSP; + copy.currentBSP = currentBSP; + copy.constantInitBonus = constantInitBonus; copy.streakCompensationBonus = streakCompensationBonus; diff --git a/megamek/src/megamek/common/actions/NukeDetonatedAction.java b/megamek/src/megamek/common/actions/NukeDetonatedAction.java new file mode 100644 index 00000000000..af8c779bfd1 --- /dev/null +++ b/megamek/src/megamek/common/actions/NukeDetonatedAction.java @@ -0,0 +1,38 @@ +/** + * MegaMek - Copyright (C) 2000-2002 Ben Mazur (bmazur@sev.org) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +package megamek.common.actions; + +import megamek.common.AmmoType; + +import java.io.Serial; + +public class NukeDetonatedAction extends AbstractEntityAction { + + @Serial + private static final long serialVersionUID = 918785269096319255L; + + private final AmmoType.Munitions nukeType; + private final int playerID; + + public NukeDetonatedAction(int entityId, int playerID, AmmoType.Munitions nukeType) { + super(entityId); + this.nukeType = nukeType; + this.playerID = playerID; + } + + public AmmoType.Munitions typeOfNuke() { + return nukeType; + } +} diff --git a/megamek/src/megamek/common/actions/TeleMissileAttackAction.java b/megamek/src/megamek/common/actions/TeleMissileAttackAction.java index f3b15000737..46aff64fdcc 100644 --- a/megamek/src/megamek/common/actions/TeleMissileAttackAction.java +++ b/megamek/src/megamek/common/actions/TeleMissileAttackAction.java @@ -103,7 +103,7 @@ private boolean checkPDConditions(Game game, Targetable target) { * Returns the heat generated by a large craft's weapons fire declarations * during the round * Used to determine whether point defenses can engage. - * + * * @param e the entity you wish to get heat data from * Since this normally only applies to weaponhandlers, we must recreate * it to deal with telemissile @@ -115,7 +115,7 @@ protected int getLargeCraftHeat(Entity e) { if (e.usesWeaponBays()) { for (Enumeration i = e.getGame().getAttacks(); i.hasMoreElements();) { AttackHandler ah = i.nextElement(); - WeaponAttackAction prevAttack = ah.getWaa(); + WeaponAttackAction prevAttack = ah.getWeaponAttackAction(); if (prevAttack.getEntityId() == e.getId()) { WeaponMounted prevWeapon = (WeaponMounted) e.getEquipment(prevAttack.getWeaponId()); for (WeaponMounted bayW : prevWeapon.getBayWeapons()) { @@ -126,7 +126,7 @@ protected int getLargeCraftHeat(Entity e) { } else { for (Enumeration i = e.getGame().getAttacks(); i.hasMoreElements();) { AttackHandler ah = i.nextElement(); - WeaponAttackAction prevAttack = ah.getWaa(); + WeaponAttackAction prevAttack = ah.getWeaponAttackAction(); if (prevAttack.getEntityId() == e.getId()) { Mounted prevWeapon = e.getEquipment(prevAttack.getWeaponId()); totalheat += prevWeapon.getCurrentHeat(); diff --git a/megamek/src/megamek/common/equipment/WeaponMounted.java b/megamek/src/megamek/common/equipment/WeaponMounted.java index 390b0e9aaf3..15020b927b8 100644 --- a/megamek/src/megamek/common/equipment/WeaponMounted.java +++ b/megamek/src/megamek/common/equipment/WeaponMounted.java @@ -344,11 +344,11 @@ public WeaponAttackAction assignAPDS(List vAttacks) { for (WeaponHandler wr : vAttacks) { boolean isInArc = Compute.isInArc(getEntity().getGame(), getEntity().getId(), getEntity().getEquipmentNum(this), - getEntity().getGame().getEntity(wr.waa.getEntityId())); + getEntity().getGame().getEntity(wr.weaponAttackAction.getEntityId())); boolean isInRange = getEntity().getPosition().distance( - wr.getWaa().getTarget(getEntity().getGame()).getPosition()) <= 3; + wr.getWeaponAttackAction().getTarget(getEntity().getGame()).getPosition()) <= 3; if (isInArc && isInRange) { - vAttacksInArc.add(wr.waa); + vAttacksInArc.add(wr.weaponAttackAction); } } // find the most dangerous salvo by expected damage diff --git a/megamek/src/megamek/common/event/GameListener.java b/megamek/src/megamek/common/event/GameListener.java index cc33f7ba769..7522fe99126 100644 --- a/megamek/src/megamek/common/event/GameListener.java +++ b/megamek/src/megamek/common/event/GameListener.java @@ -66,6 +66,8 @@ public interface GameListener extends java.util.EventListener { void gameVictory(PostGameResolution e); + default void gamePlayerStrategicAction(GamePlayerStrategicActionEvent e) { } + default void gameScriptedEvent(GameScriptedEvent event) { } /** diff --git a/megamek/src/megamek/common/event/GamePlayerStrategicActionEvent.java b/megamek/src/megamek/common/event/GamePlayerStrategicActionEvent.java new file mode 100644 index 00000000000..75b0d9a52cc --- /dev/null +++ b/megamek/src/megamek/common/event/GamePlayerStrategicActionEvent.java @@ -0,0 +1,59 @@ +/* + * MegaMek - Copyright (C) 2005 Ben Mazur (bmazur@sev.org) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +package megamek.common.event; + +import megamek.common.actions.EntityAction; + +import java.io.Serial; + +/** + * Instances of this class are sent when an strategic action is created in the game + * + * @see GameListener + */ +public class GamePlayerStrategicActionEvent extends GameEvent { + + @Serial + private static final long serialVersionUID = 928848699583079097L; + protected EntityAction action; + + /** + * Construct new GameNewActionEvent + * + * @param source sender + * @param action + */ + public GamePlayerStrategicActionEvent(Object source, EntityAction action) { + super(source); + this.action = action; + } + + /** + * @return the action. + */ + public EntityAction getAction() { + return action; + } + + @Override + public void fireEvent(GameListener gl) { + gl.gamePlayerStrategicAction(this); + } + + @Override + public String getEventName() { + return "Game New Action"; + } +} diff --git a/megamek/src/megamek/common/weapons/ACAPHandler.java b/megamek/src/megamek/common/weapons/ACAPHandler.java index 6fb486339c2..daca2e6a910 100644 --- a/megamek/src/megamek/common/weapons/ACAPHandler.java +++ b/megamek/src/megamek/common/weapons/ACAPHandler.java @@ -44,11 +44,11 @@ protected void handleEntityDamage(Entity entityTarget, Vector vPhaseRepo Building bldg, int hits, int nCluster, int bldgAbsorbs) { AmmoType atype = (AmmoType) weapon.getLinked().getType(); HitData hit = entityTarget.rollHitLocation(toHit.getHitTable(), toHit.getSideTable(), - waa.getAimedLocation(), waa.getAimingMode(), toHit.getCover()); + weaponAttackAction.getAimedLocation(), weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setGeneralDamageType(generalDamageType); hit.setAttackerId(getAttackerId()); if (entityTarget.removePartialCoverHits(hit.getLocation(), toHit.getCover(), - Compute.targetSideTable(ae, entityTarget, weapon.getCalledShot().getCall()))) { + Compute.targetSideTable(attackerEntity, entityTarget, weapon.getCalledShot().getCall()))) { // Weapon strikes Partial Cover. handlePartialCoverHit(entityTarget, vPhaseReport, hit, bldg, hits, nCluster, bldgAbsorbs); return; @@ -82,7 +82,7 @@ protected void handleEntityDamage(Entity entityTarget, Vector vPhaseRepo // damage absorption by the partial cover, if it would have already happened Hex targetHex = game.getBoard().getHex(target.getPosition()); boolean targetStickingOutOfBuilding = unitStickingOutOfBuilding(targetHex, entityTarget); - + nDamage = absorbBuildingDamage(nDamage, entityTarget, bldgAbsorbs, vPhaseReport, bldg, targetStickingOutOfBuilding); @@ -119,7 +119,7 @@ protected void handleEntityDamage(Entity entityTarget, Vector vPhaseRepo } hit.makeArmorPiercing(atype, critModifier); vPhaseReport.addAll(gameManager.damageEntity(entityTarget, hit, nDamage, false, - ae.getSwarmTargetId() == entityTarget.getId() ? DamageType.IGNORE_PASSENGER : damageType, + attackerEntity.getSwarmTargetId() == entityTarget.getId() ? DamageType.IGNORE_PASSENGER : damageType, false, false, throughFront, underWater)); } } diff --git a/megamek/src/megamek/common/weapons/ACCaselessHandler.java b/megamek/src/megamek/common/weapons/ACCaselessHandler.java index f969f58357f..3f178391cc4 100644 --- a/megamek/src/megamek/common/weapons/ACCaselessHandler.java +++ b/megamek/src/megamek/common/weapons/ACCaselessHandler.java @@ -43,7 +43,7 @@ protected boolean doChecks(Vector vPhaseReport) { return true; } - if ((roll.getIntValue() <= 2) && !ae.isConventionalInfantry()) { + if ((roll.getIntValue() <= 2) && !attackerEntity.isConventionalInfantry()) { Roll diceRoll = Compute.rollD6(2); Report r = new Report(3164); diff --git a/megamek/src/megamek/common/weapons/ACFlakHandler.java b/megamek/src/megamek/common/weapons/ACFlakHandler.java index 831c71306ab..eb3d3a721c8 100644 --- a/megamek/src/megamek/common/weapons/ACFlakHandler.java +++ b/megamek/src/megamek/common/weapons/ACFlakHandler.java @@ -39,7 +39,7 @@ public class ACFlakHandler extends LBXHandler { */ public ACFlakHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " fragment(s) "; + salvoType = " fragment(s) "; } /* diff --git a/megamek/src/megamek/common/weapons/ACFlechetteHandler.java b/megamek/src/megamek/common/weapons/ACFlechetteHandler.java index 696c826d2cd..5bc282ab3e2 100644 --- a/megamek/src/megamek/common/weapons/ACFlechetteHandler.java +++ b/megamek/src/megamek/common/weapons/ACFlechetteHandler.java @@ -50,22 +50,22 @@ public ACFlechetteHandler(ToHitData t, WeaponAttackAction w, Game g, */ @Override protected int calcDamagePerHit() { - double toReturn = wtype.getDamage(); + double toReturn = weaponType.getDamage(); if (bDirect) { toReturn += toHit.getMoS() / 3; } - + toReturn = applyGlancingBlowModifier(toReturn, false); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG])) { toReturn = (int) Math.floor(toReturn * .75); } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { toReturn = (int) Math.floor(toReturn * .5); - } + } return (int) Math.ceil(toReturn); } @@ -94,7 +94,7 @@ protected void handleClearDamage(Vector vPhaseReport, Building bldg, int // Buildings can't be accidentally ignited. if ((bldg != null) && gameManager.tryIgniteHex(target.getPosition(), subjectId, false, false, - new TargetRoll(wtype.getFireTN(), wtype.getName()), 5, vPhaseReport)) { + new TargetRoll(weaponType.getFireTN(), weaponType.getName()), 5, vPhaseReport)) { return; } diff --git a/megamek/src/megamek/common/weapons/ACWeaponHandler.java b/megamek/src/megamek/common/weapons/ACWeaponHandler.java index 4c5a59f1c7e..a7e81d280ba 100644 --- a/megamek/src/megamek/common/weapons/ACWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/ACWeaponHandler.java @@ -39,32 +39,32 @@ public ACWeaponHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager @Override protected int calcDamagePerHit() { - double toReturn = wtype.getDamage(); + double toReturn = weaponType.getDamage(); // during a swarm, all damage gets applied as one block to one location - if ((ae instanceof BattleArmor) + if ((attackerEntity instanceof BattleArmor) && (weapon.getLocation() == BattleArmor.LOC_SQUAD) && !(weapon.isSquadSupportWeapon()) - && (ae.getSwarmTargetId() == target.getId())) { - toReturn *= ((BattleArmor) ae).getShootingStrength(); + && (attackerEntity.getSwarmTargetId() == target.getId())) { + toReturn *= ((BattleArmor) attackerEntity).getShootingStrength(); } // we default to direct fire weapons for anti-infantry damage if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage(toReturn, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), toHit.getThruBldg() != null, - ae.getId(), calcDmgPerHitReport); + attackerEntity.getId(), calcDmgPerHitReport); } else if (bDirect) { toReturn = Math.min(toReturn + (toHit.getMoS() / 3), toReturn * 2); } toReturn = applyGlancingBlowModifier(toReturn, target.isConventionalInfantry()); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG]) { + && nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG]) { toReturn = (int) Math.floor(toReturn * .75); } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { toReturn = (int) Math.floor(toReturn * .5); } diff --git a/megamek/src/megamek/common/weapons/AR10Handler.java b/megamek/src/megamek/common/weapons/AR10Handler.java index f845d264fa8..ffa43cf44be 100644 --- a/megamek/src/megamek/common/weapons/AR10Handler.java +++ b/megamek/src/megamek/common/weapons/AR10Handler.java @@ -65,21 +65,21 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { : null; if (entityTarget != null) { - ae.setLastTarget(entityTarget.getId()); - ae.setLastTargetDisplayName(entityTarget.getDisplayName()); + attackerEntity.setLastTarget(entityTarget.getId()); + attackerEntity.setLastTargetDisplayName(entityTarget.getDisplayName()); } // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); - String number = nweapons > 1 ? " (" + nweapons + ")" : ""; + String number = numberOfWeapons > 1 ? " (" + numberOfWeapons + ")" : ""; for (int i = numAttacks; i > 0; i--) { // Report weapon attack and its to-hit value. Report r = new Report(3115); r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + number); + r.add(weaponType.getName() + number); if (entityTarget != null) { - if ((wtype.getAmmoType() != AmmoType.T_NA) + if ((weaponType.getAmmoType() != AmmoType.T_NA) && (weapon.getLinked() != null) && (weapon.getLinked().getType() instanceof AmmoType)) { AmmoType atype = (AmmoType) weapon.getLinked().getType(); @@ -177,7 +177,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -215,7 +215,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { int id = vPhaseReport.size(); int hits = calcHits(vPhaseReport); - if (target.isAirborne() || game.getBoard().inSpace() || ae.usesWeaponBays()) { + if (target.isAirborne() || game.getBoard().inSpace() || attackerEntity.usesWeaponBays()) { // if we added a line to the phase report for calc hits, remove // it now while (vPhaseReport.size() > id) { @@ -251,7 +251,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (!bMissed && (entityTarget != null)) { handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - gameManager.creditKill(entityTarget, ae); + gameManager.creditKill(entityTarget, attackerEntity); } else if (!bMissed) { // Hex is targeted, need to report a hit r = new Report(3390); r.subject = subjectId; diff --git a/megamek/src/megamek/common/weapons/ASEWMissileWeaponHandler.java b/megamek/src/megamek/common/weapons/ASEWMissileWeaponHandler.java index 1b883cfc01d..9bcb9b7a9fc 100644 --- a/megamek/src/megamek/common/weapons/ASEWMissileWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/ASEWMissileWeaponHandler.java @@ -52,10 +52,10 @@ protected void handleEntityDamage(Entity entityTarget, missed = false; hit = entityTarget.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setGeneralDamageType(generalDamageType); - hit.setCapital(wtype.isCapital()); + hit.setCapital(weaponType.isCapital()); hit.setBoxCars(roll.getIntValue() == 12); hit.setCapMisCritMod(getCapMisMod()); hit.setFirstHit(firstHit); @@ -69,13 +69,13 @@ protected void handleEntityDamage(Entity entityTarget, r.add(toHit.getTableDesc()); r.add(entityTarget.getLocationAbbr(hit)); vPhaseReport.addElement(r); - if (nweaponsHit > 1) { + if (numberOfWeaponHits > 1) { //If the target is hit by multiple ASEW missiles, report it here, even if the effects don't stack r.newlines = 1; r = new Report(3471); r.subject = subjectId; r.addDesc(entityTarget); - r.add(nweaponsHit); + r.add(numberOfWeaponHits); vPhaseReport.add(r); } else { //Otherwise, report a single ASEW missile hit diff --git a/megamek/src/megamek/common/weapons/ATMHandler.java b/megamek/src/megamek/common/weapons/ATMHandler.java index 374e0cf6121..ef8badecee2 100644 --- a/megamek/src/megamek/common/weapons/ATMHandler.java +++ b/megamek/src/megamek/common/weapons/ATMHandler.java @@ -62,20 +62,20 @@ protected int calcDamagePerHit() { double toReturn; AmmoType atype = (AmmoType) ammo.getType(); if (atype.getMunitionType().contains(AmmoType.Munitions.M_HIGH_EXPLOSIVE)) { - sSalvoType = " high-explosive missile(s) "; + salvoType = " high-explosive missile(s) "; toReturn = 3; } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_EXTENDED_RANGE)) { - sSalvoType = " extended-range missile(s) "; + salvoType = " extended-range missile(s) "; toReturn = 1; } else { toReturn = 2; } if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage( - wtype.getRackSize(), bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getRackSize(), bDirect ? toHit.getMoS() / 3 : 0, + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); toReturn = applyGlancingBlowModifier(toReturn, true); } @@ -112,24 +112,24 @@ protected int calcHits(Vector vPhaseReport) { protected int calcAttackValue() { int av = 0; int counterAV; - int range = RangeType.rangeBracket(nRange, wtype.getATRanges(), true, false); + int range = RangeType.rangeBracket(nRange, weaponType.getATRanges(), true, false); AmmoType atype = (AmmoType) ammo.getType(); if (atype.getMunitionType().contains(AmmoType.Munitions.M_HIGH_EXPLOSIVE)) { if (range == WeaponType.RANGE_SHORT) { - av = wtype.getRoundShortAV(); + av = weaponType.getRoundShortAV(); av = av + (int) Math.ceil(av / 2.0); } } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_EXTENDED_RANGE)) { - av = (int) Math.ceil(wtype.getRoundMedAV() / 2.0); + av = (int) Math.ceil(weaponType.getRoundMedAV() / 2.0); } else { if (range == WeaponType.RANGE_SHORT) { - av = wtype.getRoundShortAV(); + av = weaponType.getRoundShortAV(); } else if (range == WeaponType.RANGE_MED) { - av = wtype.getRoundMedAV(); + av = weaponType.getRoundMedAV(); } else if (range == WeaponType.RANGE_LONG) { - av = wtype.getRoundLongAV(); + av = weaponType.getRoundLongAV(); } else if (range == WeaponType.RANGE_EXT) { - av = wtype.getRoundExtAV(); + av = weaponType.getRoundExtAV(); } } @@ -149,21 +149,21 @@ protected int calcStandardAndExtendedAmmoHits(Vector vPhaseReport) { // conventional infantry gets hit in one lump // BAs do one lump of damage per BA suit if (target.isConventionalInfantry()) { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { bSalvo = true; Report r = new Report(3325); r.subject = subjectId; - r.add(wtype.getRackSize() - * ((BattleArmor) ae).getShootingStrength()); - r.add(sSalvoType); + r.add(weaponType.getRackSize() + * ((BattleArmor) attackerEntity).getShootingStrength()); + r.add(salvoType); r.add(toHit.getTableDesc()); vPhaseReport.add(r); - return ((BattleArmor) ae).getShootingStrength(); + return ((BattleArmor) attackerEntity).getShootingStrength(); } Report r = new Report(3325); r.subject = subjectId; - r.add(wtype.getRackSize()); - r.add(sSalvoType); + r.add(weaponType.getRackSize()); + r.add(salvoType); r.add(toHit.getTableDesc()); vPhaseReport.add(r); return 1; @@ -173,8 +173,8 @@ protected int calcStandardAndExtendedAmmoHits(Vector vPhaseReport) { int missilesHit; boolean bMekTankStealthActive = false; - if ((ae instanceof Mek) || (ae instanceof Tank)) { - bMekTankStealthActive = ae.isStealthActive(); + if ((attackerEntity instanceof Mek) || (attackerEntity instanceof Tank)) { + bMekTankStealthActive = attackerEntity.isStealthActive(); } Mounted mLinker = weapon.getLinkedBy(); AmmoType atype = (AmmoType) ammo.getType(); @@ -183,7 +183,7 @@ protected int calcStandardAndExtendedAmmoHits(Vector vPhaseReport) { atype.getMunitionType().contains(AmmoType.Munitions.M_HIGH_EXPLOSIVE)); // is any hex in the flight path of the missile ECM affected? - boolean bECMAffected = ComputeECM.isAffectedByECM(ae, ae.getPosition(), target.getPosition()); + boolean bECMAffected = ComputeECM.isAffectedByECM(attackerEntity, attackerEntity.getPosition(), target.getPosition()); // if the attacker is affected by ECM or the target is protected by ECM // then act as if affected. @@ -224,14 +224,14 @@ protected int calcStandardAndExtendedAmmoHits(Vector vPhaseReport) { nMissilesModifier += 2; } } else if ((entityTarget != null) - && (entityTarget.isNarcedBy(ae.getOwner().getTeam()) || entityTarget - .isINarcedBy(ae.getOwner().getTeam()))) { + && (entityTarget.isNarcedBy(attackerEntity.getOwner().getTeam()) || entityTarget + .isINarcedBy(attackerEntity.getOwner().getTeam()))) { // only apply Narc bonus if we're not suffering ECM effect // and we are using narc ammo, and we're not firing indirectly. // narc capable missiles are only affected if the narc pod, which // sits on the target, is ECM affected boolean bTargetECMAffected = false; - bTargetECMAffected = ComputeECM.isAffectedByECM(ae, + bTargetECMAffected = ComputeECM.isAffectedByECM(attackerEntity, target.getPosition(), target.getPosition()); if (((atype.getAmmoType() == AmmoType.T_LRM) || (atype .getAmmoType() == AmmoType.T_SRM)) @@ -262,17 +262,17 @@ protected int calcStandardAndExtendedAmmoHits(Vector vPhaseReport) { if (allShotsHit()) { // We want buildings and large craft to be able to affect this number with AMS // treat as a Streak launcher (cluster roll 11) to make this happen - missilesHit = Compute.missilesHit(wtype.getRackSize(), + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier, weapon.isHotLoaded(), true, isAdvancedAMS()); } else { - if (ae instanceof BattleArmor) { - missilesHit = Compute.missilesHit(wtype.getRackSize() - * ((BattleArmor) ae).getShootingStrength(), + if (attackerEntity instanceof BattleArmor) { + missilesHit = Compute.missilesHit(weaponType.getRackSize() + * ((BattleArmor) attackerEntity).getShootingStrength(), nMissilesModifier, weapon.isHotLoaded(), false, isAdvancedAMS()); } else { - missilesHit = Compute.missilesHit(wtype.getRackSize(), + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier, weapon.isHotLoaded(), false, isAdvancedAMS()); } @@ -282,7 +282,7 @@ protected int calcStandardAndExtendedAmmoHits(Vector vPhaseReport) { Report r = new Report(3325); r.subject = subjectId; r.add(missilesHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); @@ -319,7 +319,7 @@ protected boolean specialResolution(Vector vPhaseReport, Entity entityTa ArrayList mfRemoved = new ArrayList<>(); while (minefields.hasMoreElements()) { Minefield mf = minefields.nextElement(); - if (gameManager.clearMinefield(mf, ae, + if (gameManager.clearMinefield(mf, attackerEntity, Minefield.CLEAR_NUMBER_WEAPON, vPhaseReport)) { mfRemoved.add(mf); } diff --git a/megamek/src/megamek/common/weapons/AmmoBayWeaponHandler.java b/megamek/src/megamek/common/weapons/AmmoBayWeaponHandler.java index f2c61c518be..a5cf47eff28 100644 --- a/megamek/src/megamek/common/weapons/AmmoBayWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/AmmoBayWeaponHandler.java @@ -55,21 +55,21 @@ public AmmoBayWeaponHandler(ToHitData t, WeaponAttackAction w, Game g, protected int calcAttackValue() { double av = 0; - int range = RangeType.rangeBracket(nRange, wtype.getATRanges(), true, false); + int range = RangeType.rangeBracket(nRange, weaponType.getATRanges(), true, false); for (WeaponMounted bayW : weapon.getBayWeapons()) { // check the currently loaded ammo AmmoMounted bayWAmmo = bayW.getLinkedAmmo(); if (null == bayWAmmo || bayWAmmo.getUsableShotsLeft() < 1) { // try loading something else - ae.loadWeaponWithSameAmmo(bayW); + attackerEntity.loadWeaponWithSameAmmo(bayW); bayWAmmo = bayW.getLinkedAmmo(); } if (!bayW.isBreached() && !bayW.isDestroyed() && !bayW.isJammed() && bayWAmmo != null - && ae.getTotalAmmoOfType(bayWAmmo.getType()) >= bayW.getCurrentShots()) { + && attackerEntity.getTotalAmmoOfType(bayWAmmo.getType()) >= bayW.getCurrentShots()) { WeaponType bayWType = bayW.getType(); // need to cycle through weapons and add av double current_av = 0; @@ -94,7 +94,7 @@ protected int calcAttackValue() { if (null == bayWAmmo || bayWAmmo.getUsableShotsLeft() < 1) { // try loading something else - ae.loadWeaponWithSameAmmo(bayW); + attackerEntity.loadWeaponWithSameAmmo(bayW); bayWAmmo = bayW.getLinkedAmmo(); } if (null != bayWAmmo) { diff --git a/megamek/src/megamek/common/weapons/AmmoWeaponHandler.java b/megamek/src/megamek/common/weapons/AmmoWeaponHandler.java index 6e8e58226e1..97466f956a4 100644 --- a/megamek/src/megamek/common/weapons/AmmoWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/AmmoWeaponHandler.java @@ -62,13 +62,13 @@ protected void useAmmo() { } if (ammo.getUsableShotsLeft() <= 0) { - ae.loadWeaponWithSameAmmo(weapon); + attackerEntity.loadWeaponWithSameAmmo(weapon); ammo = weapon.getLinked(); } ammo.setShotsLeft(ammo.getBaseShotsLeft() - 1); if (weapon.isInternalBomb()) { - ((IBomber) ae).increaseUsedInternalBombs(1); + ((IBomber) attackerEntity).increaseUsedInternalBombs(1); } super.useAmmo(); @@ -77,7 +77,7 @@ protected void useAmmo() { protected void checkAmmo() { ammo = weapon.getLinked(); if (ammo == null) { - ae.loadWeapon(weapon); + attackerEntity.loadWeapon(weapon); ammo = weapon.getLinked(); } } @@ -93,7 +93,7 @@ protected int getNumberWeapons() { // shouldn't happen return weapon.getNWeapons(); } - int totalShots = ae.getTotalAmmoOfType(ammo.getType()); + int totalShots = attackerEntity.getTotalAmmoOfType(ammo.getType()); return Math.min(weapon.getNWeapons(), (int) Math.floor((double) totalShots / (double) weapon.getCurrentShots())); } @@ -110,7 +110,7 @@ protected boolean doAmmoFeedProblemCheck(Vector vPhaseReport) { // don't have neg ammo feed problem quirk if (!weapon.hasQuirk(OptionsConstants.QUIRK_WEAP_NEG_AMMO_FEED_PROBLEMS)) { return false; - } else if ((roll.getIntValue() <= 2) && !ae.isConventionalInfantry()) { + } else if ((roll.getIntValue() <= 2) && !attackerEntity.isConventionalInfantry()) { // attack roll was a 2, may explode Roll diceRoll = Compute.rollD6(2); @@ -156,19 +156,19 @@ protected void explodeRoundInBarrel(Vector vPhaseReport) { weapon.setHit(true); int wloc = weapon.getLocation(); - for (int i = 0; i < ae.getNumberOfCriticals(wloc); i++) { - CriticalSlot slot1 = ae.getCritical(wloc, i); + for (int i = 0; i < attackerEntity.getNumberOfCriticals(wloc); i++) { + CriticalSlot slot1 = attackerEntity.getCritical(wloc, i); if ((slot1 == null) || (slot1.getType() == CriticalSlot.TYPE_SYSTEM)) { continue; } Mounted mounted = slot1.getMount(); if (mounted.equals(weapon)) { - ae.hitAllCriticals(wloc, i); + attackerEntity.hitAllCriticals(wloc, i); break; } } // if we're here, the weapon is going to explode whether it's flagged as explosive or not - vPhaseReport.addAll(gameManager.explodeEquipment(ae, wloc, weapon, true)); + vPhaseReport.addAll(gameManager.explodeEquipment(attackerEntity, wloc, weapon, true)); } } diff --git a/megamek/src/megamek/common/weapons/ArtilleryBayWeaponIndirectFireHandler.java b/megamek/src/megamek/common/weapons/ArtilleryBayWeaponIndirectFireHandler.java index d90e6b4558f..9a4700b292c 100644 --- a/megamek/src/megamek/common/weapons/ArtilleryBayWeaponIndirectFireHandler.java +++ b/megamek/src/megamek/common/weapons/ArtilleryBayWeaponIndirectFireHandler.java @@ -13,34 +13,35 @@ */ package megamek.common.weapons; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - import megamek.common.*; import megamek.common.actions.ArtilleryAttackAction; +import megamek.common.actions.NukeDetonatedAction; import megamek.common.actions.WeaponAttackAction; import megamek.common.enums.GamePhase; import megamek.common.equipment.AmmoMounted; import megamek.common.equipment.WeaponMounted; +import megamek.common.event.GamePlayerStrategicActionEvent; import megamek.common.options.OptionsConstants; import megamek.logging.MMLogger; import megamek.server.totalwarfare.TWGameManager; +import java.io.Serial; +import java.util.*; + /** * @author Sebastian Brocks */ public class ArtilleryBayWeaponIndirectFireHandler extends AmmoBayWeaponHandler { private static final MMLogger logger = MMLogger.create(ArtilleryBayWeaponIndirectFireHandler.class); + @Serial private static final long serialVersionUID = -1277649123562229298L; boolean handledAmmoAndReport = false; /** * This constructor can only be used for deserialization. */ + @SuppressWarnings("unused") protected ArtilleryBayWeaponIndirectFireHandler() { super(); } @@ -56,7 +57,7 @@ public boolean cares(final GamePhase phase) { @Override protected void useAmmo() { - nweaponsHit = weapon.getBayWeapons().size(); + numberOfWeaponHits = weapon.getBayWeapons().size(); for (WeaponMounted bayW : weapon.getBayWeapons()) { // check the currently loaded ammo AmmoMounted bayWAmmo = bayW.getLinkedAmmo(); @@ -72,19 +73,19 @@ protected void useAmmo() { // fire rounds that we have. if (game.getOptions().booleanOption(OptionsConstants.ADVAERORULES_AERO_ARTILLERY_MUNITIONS)) { if (bayWAmmo.getUsableShotsLeft() < 1) { - nweaponsHit--; + numberOfWeaponHits--; } else { bayWAmmo.setShotsLeft(bayWAmmo.getBaseShotsLeft() - 1); } } else { - // By default rules, we have just one ammo bin with at least 10 shots for each + // By default, rules, we have just one ammo bin with at least 10 shots for each // weapon in the bay, // so we'll track ammo normally and need to resolve attacks for all bay weapons. for (int i = 0; i < shots; i++) { if (null == bayWAmmo || bayWAmmo.getUsableShotsLeft() < 1) { // try loading something else - ae.loadWeaponWithSameAmmo(bayW); + attackerEntity.loadWeaponWithSameAmmo(bayW); bayWAmmo = bayW.getLinkedAmmo(); } if (null != bayWAmmo) { @@ -106,7 +107,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { return true; } String artyMsg; - ArtilleryAttackAction aaa = (ArtilleryAttackAction) waa; + ArtilleryAttackAction aaa = (ArtilleryAttackAction) weaponAttackAction; if (phase.isTargeting()) { if (!handledAmmoAndReport) { addHeat(); @@ -115,7 +116,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + (atype != null ? " (" + atype.getShortName() + ")" : "")); + r.add(weaponType.getName() + (ammoType != null ? " (" + ammoType.getShortName() + ")" : "")); r.add(aaa.getTurnsTilHit()); vPhaseReport.addElement(r); Report.addNewline(vPhaseReport); @@ -152,7 +153,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { Report r = new Report(3158); r.indent(); r.subject = subjectId; - r.add(wtype.getName()); + r.add(weaponType.getName()); vPhaseReport.add(r); return true; } @@ -161,39 +162,34 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { Coords targetPos = target.getPosition(); final int playerId = aaa.getPlayerId(); boolean targetIsEntity = target.getTargetType() == Targetable.TYPE_ENTITY; - boolean isFlak = targetIsEntity && Compute.isFlakAttack(ae, (Entity) target); + boolean isFlak = targetIsEntity && Compute.isFlakAttack(attackerEntity, (Entity) target); boolean asfFlak = isFlak && target.isAirborne(); boolean mineClear = target.getTargetType() == Targetable.TYPE_MINEFIELD_CLEAR; Entity bestSpotter = null; - if (ae == null) { + if (attackerEntity == null) { logger.error("Artillery Entity is null!"); return true; } - Mounted ammoUsed = ae.getEquipment(aaa.getAmmoId()); - final AmmoType atype = (AmmoType) ammoUsed.getType(); + Mounted ammoUsed = attackerEntity.getEquipment(aaa.getAmmoId()); + final AmmoType ammoUsedType = (AmmoType) ammoUsed.getType(); // Are there any valid spotters? if ((null != spottersBefore) && !isFlak) { // fetch possible spotters now Iterator spottersAfter = game.getSelectedEntities(new EntitySelector() { - public int player = playerId; - - public Targetable targ = target; + public final int player = playerId; + public final Targetable targetable = target; @Override public boolean accept(Entity entity) { - Integer id = entity.getId(); - if ((player == entity.getOwnerId()) - && spottersBefore.contains(id) - && !LosEffects.calculateLOS(game, entity, targ, true).isBlocked() - && entity.isActive() - // airborne aeros can't spot for arty - && !(entity.isAero() && entity.isAirborne()) - && !entity.isINarcedWith(INarcPod.HAYWIRE)) { - return true; - } - return false; + return (player == entity.getOwnerId()) + && spottersBefore.contains(entity.getId()) + && !LosEffects.calculateLOS(game, entity, targetable, true).isBlocked() + && entity.isActive() + // airborne aerospace can't spot for arty + && !(entity.isAero() && entity.isAirborne()) + && !entity.isINarcedWith(INarcPod.HAYWIRE); } }); @@ -228,13 +224,13 @@ public boolean accept(Entity entity) { toHit.addModifier(mod, "Spotting modifier"); } - // Is the attacker still alive and we're not shooting FLAK? + // Is the attacker still alive, and we're not shooting FLAK? // then adjust the target if (!isFlak) { // If the shot hit the target hex, then all subsequent // fire will hit the hex automatically. if (roll.getIntValue() >= toHit.getValue()) { - ae.aTracker.setModifier(TargetRoll.AUTOMATIC_SUCCESS, targetPos); + attackerEntity.aTracker.setModifier(TargetRoll.AUTOMATIC_SUCCESS, targetPos); } else if (null != bestSpotter) { // If the shot missed, but was adjusted by a spotter, future shots are more // likely @@ -250,11 +246,11 @@ public boolean accept(Entity entity) { // appear to be correct. // only add mods if it's not an automatic success - if (ae.aTracker.getModifier(weapon, targetPos) != TargetRoll.AUTOMATIC_SUCCESS) { + if (attackerEntity.aTracker.getModifier(weapon, targetPos) != TargetRoll.AUTOMATIC_SUCCESS) { if (bestSpotter.hasAbility(OptionsConstants.MISC_FORWARD_OBSERVER)) { - ae.aTracker.setSpotterHasForwardObs(true); + attackerEntity.aTracker.setSpotterHasForwardObs(true); } - ae.aTracker.setModifier(ae.aTracker.getModifier(weapon, targetPos) - 1, targetPos); + attackerEntity.aTracker.setModifier(attackerEntity.aTracker.getModifier(weapon, targetPos) - 1, targetPos); } } } @@ -264,8 +260,8 @@ public boolean accept(Entity entity) { r.indent(); r.newlines = 0; r.subject = subjectId; - if (wtype != null) { - r.add(wtype.getName()); + if (weaponType != null) { + r.add(weaponType.getName()); } else { r.add("Error: From Nowhere"); } @@ -322,9 +318,9 @@ public boolean accept(Entity entity) { if (!bMissed) { r = new Report(3199); r.subject = subjectId; - r.add(nweaponsHit); + r.add(numberOfWeaponHits); r.add(targetPos.getBoardNum()); - r.add(atype.getShortName()); + r.add(ammoUsedType.getShortName()); // Mine clearance has its own report which will get added if (!mineClear) { vPhaseReport.addElement(r); @@ -337,7 +333,7 @@ public boolean accept(Entity entity) { game.getRoundCount(), game.getPlayer(aaa.getPlayerId()), artyMsg)); } else { int moF = toHit.getMoS(); - if (ae.hasAbility(OptionsConstants.GUNNERY_OBLIQUE_ARTILLERY)) { + if (attackerEntity.hasAbility(OptionsConstants.GUNNERY_OBLIQUE_ARTILLERY)) { // getMoS returns a negative MoF // simple math is better so lets make it positive if ((-moF - 2) < 1) { @@ -355,7 +351,7 @@ public boolean accept(Entity entity) { game.getBoard().addSpecialHexDisplay(origPos, new SpecialHexDisplay(SpecialHexDisplay.Type.ARTILLERY_MISS, game.getRoundCount(), game.getPlayer(aaa.getPlayerId()), artyMsg)); - while (nweaponsHit > 0) { + while (numberOfWeaponHits > 0) { // We'll generate a new report and scatter for each weapon fired targetPos = Compute.scatterDirectArty(origPos, moF); if (game.getBoard().contains(targetPos)) { @@ -365,16 +361,14 @@ public boolean accept(Entity entity) { r = new Report(3202); r.subject = subjectId; r.newlines = 1; - r.add(atype.getShortName()); - r.add(targetPos.getBoardNum()); - vPhaseReport.addElement(r); + r.add(ammoUsedType.getShortName()); } else { r = new Report(3192); r.subject = subjectId; r.newlines = 1; - r.add(targetPos.getBoardNum()); - vPhaseReport.addElement(r); } + r.add(targetPos.getBoardNum()); + vPhaseReport.addElement(r); } else { // misses and scatters off-board r = new Report(3200); @@ -382,20 +376,20 @@ public boolean accept(Entity entity) { r.newlines = 1; vPhaseReport.addElement(r); } - nweaponsHit--; + numberOfWeaponHits--; } // If we managed to land everything off the board, stop if (targets.isEmpty()) { return !bMissed; } } - if (atype.getMunitionType().contains(AmmoType.Munitions.M_FLARE)) { + if (ammoUsedType.getMunitionType().contains(AmmoType.Munitions.M_FLARE)) { int radius; - if (atype.getAmmoType() == AmmoType.T_ARROW_IV) { + if (ammoUsedType.getAmmoType() == AmmoType.T_ARROW_IV) { radius = 4; - } else if (atype.getAmmoType() == AmmoType.T_LONG_TOM) { + } else if (ammoUsedType.getAmmoType() == AmmoType.T_LONG_TOM) { radius = 3; - } else if (atype.getAmmoType() == AmmoType.T_SNIPER) { + } else if (ammoUsedType.getAmmoType() == AmmoType.T_SNIPER) { radius = 2; } else { radius = 1; @@ -412,65 +406,73 @@ public boolean accept(Entity entity) { } return false; } - if (atype.getMunitionType().contains(AmmoType.Munitions.M_DAVY_CROCKETT_M)) { + if (ammoUsedType.getMunitionType().contains(AmmoType.Munitions.M_DAVY_CROCKETT_M)) { // The appropriate term here is "Bwahahahahaha..." if (!bMissed) { // Keep blasting the target hex with each weapon in the bay that fired - while (nweaponsHit > 0) { + while (numberOfWeaponHits > 0) { + gameManager.drawNukeHitOnBoard(targetPos); + gameManager.getGame().processGameEvent( + new GamePlayerStrategicActionEvent(gameManager, + new NukeDetonatedAction(attackerEntity.getId(), attackerEntity.getOwnerId(), AmmoType.Munitions.M_DAVY_CROCKETT_M))); gameManager.doNuclearExplosion(targetPos, 1, vPhaseReport); - nweaponsHit--; + numberOfWeaponHits--; } } else { // Deliver a round to each target hex for (Coords c : targets) { + gameManager.drawNukeHitOnBoard(targetPos); + gameManager.getGame().processGameEvent( + new GamePlayerStrategicActionEvent(gameManager, + new NukeDetonatedAction(attackerEntity.getId(), attackerEntity.getOwnerId(), AmmoType.Munitions.M_DAVY_CROCKETT_M))); gameManager.doNuclearExplosion(c, 1, vPhaseReport); } } return false; } - if (atype.getMunitionType().contains(AmmoType.Munitions.M_FASCAM)) { + if (ammoUsedType.getMunitionType().contains(AmmoType.Munitions.M_FASCAM)) { if (!bMissed) { // If we hit, only one effect will stack in the target hex - gameManager.deliverFASCAMMinefield(targetPos, ae.getOwner().getId(), - atype.getRackSize(), ae.getId()); + gameManager.deliverFASCAMMinefield(targetPos, attackerEntity.getOwner().getId(), + ammoUsedType.getRackSize(), attackerEntity.getId()); } else { // Deliver a round to each target hex for (Coords c : targets) { - gameManager.deliverFASCAMMinefield(c, ae.getOwner().getId(), - atype.getRackSize(), ae.getId()); + gameManager.deliverFASCAMMinefield(c, attackerEntity.getOwner().getId(), + ammoUsedType.getRackSize(), attackerEntity.getId()); } } return false; } - if (atype.getMunitionType().contains(AmmoType.Munitions.M_INFERNO_IV)) { + if (ammoUsedType.getMunitionType().contains(AmmoType.Munitions.M_INFERNO_IV)) { if (!bMissed) { // If we hit, only one effect will stack in the target hex - gameManager.deliverArtilleryInferno(targetPos, ae, subjectId, vPhaseReport); + gameManager.deliverArtilleryInferno(targetPos, attackerEntity, subjectId, vPhaseReport); } else { // Deliver a round to each target hex for (Coords c : targets) { handleArtilleryDriftMarker(origPos, c, aaa, - gameManager.deliverArtilleryInferno(c, ae, subjectId, vPhaseReport)); + gameManager.deliverArtilleryInferno(c, attackerEntity, subjectId, vPhaseReport)); } } return false; } - if (atype.getMunitionType().contains(AmmoType.Munitions.M_VIBRABOMB_IV)) { + if (ammoUsedType.getMunitionType().contains(AmmoType.Munitions.M_VIBRABOMB_IV)) { if (!bMissed) { // If we hit, only one effect will stack in the target hex - gameManager.deliverThunderVibraMinefield(targetPos, ae.getOwner().getId(), - atype.getRackSize(), waa.getOtherAttackInfo(), ae.getId()); + gameManager.deliverThunderVibraMinefield(targetPos, attackerEntity.getOwner().getId(), + ammoUsedType.getRackSize(), weaponAttackAction.getOtherAttackInfo(), attackerEntity.getId()); } else { // Deliver a round to each target hex for (Coords c : targets) { - gameManager.deliverThunderVibraMinefield(c, ae.getOwner().getId(), - atype.getRackSize(), waa.getOtherAttackInfo(), ae.getId()); + gameManager.deliverThunderVibraMinefield(c, attackerEntity.getOwner().getId(), + ammoUsedType.getRackSize(), weaponAttackAction.getOtherAttackInfo(), attackerEntity.getId()); } } return false; } - if (atype.getMunitionType().contains(AmmoType.Munitions.M_SMOKE)) { + if (ammoUsedType.getMunitionType().contains(AmmoType.Munitions.M_SMOKE)) { if (!bMissed) { // If we hit, only one effect will stack in the target hex gameManager.deliverArtillerySmoke(targetPos, vPhaseReport); @@ -482,7 +484,7 @@ public boolean accept(Entity entity) { } return false; } - if (atype.getMunitionType().contains(AmmoType.Munitions.M_LASER_INHIB)) { + if (ammoUsedType.getMunitionType().contains(AmmoType.Munitions.M_LASER_INHIB)) { if (!bMissed) { // If we hit, only one effect will stack in the target hex gameManager.deliverLIsmoke(targetPos, vPhaseReport); @@ -512,7 +514,7 @@ public boolean accept(Entity entity) { ArrayList mfRemoved = new ArrayList<>(); while (minefields.hasMoreElements()) { Minefield mf = minefields.nextElement(); - if (gameManager.clearMinefield(mf, ae, Minefield.CLEAR_NUMBER_WEAPON, vPhaseReport)) { + if (gameManager.clearMinefield(mf, attackerEntity, Minefield.CLEAR_NUMBER_WEAPON, vPhaseReport)) { mfRemoved.add(mf); } } @@ -529,7 +531,7 @@ public boolean accept(Entity entity) { ArrayList mfRemoved = new ArrayList<>(); while (minefields.hasMoreElements()) { Minefield mf = minefields.nextElement(); - if (gameManager.clearMinefield(mf, ae, 10, vPhaseReport)) { + if (gameManager.clearMinefield(mf, attackerEntity, 10, vPhaseReport)) { mfRemoved.add(mf); } } @@ -539,11 +541,11 @@ public boolean accept(Entity entity) { } } // Here we're doing damage for each hit with more standard artillery shells - while (nweaponsHit > 0) { - gameManager.artilleryDamageArea(targetPos, aaa.getCoords(), atype, - subjectId, ae, isFlak, altitude, mineClear, vPhaseReport, + while (numberOfWeaponHits > 0) { + gameManager.artilleryDamageArea(targetPos, aaa.getCoords(), ammoUsedType, + subjectId, attackerEntity, isFlak, altitude, mineClear, vPhaseReport, asfFlak, -1); - nweaponsHit--; + numberOfWeaponHits--; } } else { // Now if we missed, resolve a strike on each scatter hex @@ -554,7 +556,7 @@ public boolean accept(Entity entity) { ArrayList mfRemoved = new ArrayList<>(); while (minefields.hasMoreElements()) { Minefield mf = minefields.nextElement(); - if (gameManager.clearMinefield(mf, ae, 10, vPhaseReport)) { + if (gameManager.clearMinefield(mf, attackerEntity, 10, vPhaseReport)) { mfRemoved.add(mf); } } @@ -563,7 +565,7 @@ public boolean accept(Entity entity) { } } handleArtilleryDriftMarker(origPos, c, aaa, - gameManager.artilleryDamageArea(c, aaa.getCoords(), atype, subjectId, ae, isFlak, + gameManager.artilleryDamageArea(c, aaa.getCoords(), ammoUsedType, subjectId, attackerEntity, isFlak, altitude, mineClear, vPhaseReport, asfFlak, -1)); } @@ -571,14 +573,9 @@ public boolean accept(Entity entity) { return false; } - /* - * (non-Javadoc) - * - * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() - */ @Override protected int calcDamagePerHit() { - double toReturn = wtype.getDamage(); + double toReturn = weaponType.getDamage(); // area effect damage is double if (target.isConventionalInfantry()) { toReturn /= 0.5; diff --git a/megamek/src/megamek/common/weapons/ArtilleryBayWeaponIndirectHomingHandler.java b/megamek/src/megamek/common/weapons/ArtilleryBayWeaponIndirectHomingHandler.java index a1231947131..8541143b805 100644 --- a/megamek/src/megamek/common/weapons/ArtilleryBayWeaponIndirectHomingHandler.java +++ b/megamek/src/megamek/common/weapons/ArtilleryBayWeaponIndirectHomingHandler.java @@ -60,7 +60,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (!cares(phase)) { return true; } - ArtilleryAttackAction aaa = (ArtilleryAttackAction) waa; + ArtilleryAttackAction aaa = (ArtilleryAttackAction) weaponAttackAction; if (phase.isTargeting()) { if (!handledAmmoAndReport) { addHeat(); @@ -69,7 +69,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + " (" + atype.getShortName() + ")"); + r.add(weaponType.getName() + " (" + ammoType.getShortName() + ")"); r.add(aaa.getTurnsTilHit()); vPhaseReport.addElement(r); Report.addNewline(vPhaseReport); @@ -96,21 +96,21 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { entityTarget); final boolean bldgDamagedOnMiss = targetInBuilding && !(target instanceof Infantry) - && ae.getPosition().distance(target.getPosition()) <= 1; + && attackerEntity.getPosition().distance(target.getPosition()) <= 1; // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); // Determine what ammo we're firing for reporting and (later) damage - Mounted ammoUsed = ae.getEquipment(aaa.getAmmoId()); + Mounted ammoUsed = attackerEntity.getEquipment(aaa.getAmmoId()); final AmmoType atype = (AmmoType) ammoUsed.getType(); // Report weapon attack and its to-hit value. Report r = new Report(3124); r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName()); - r.add(nweaponsHit); + r.add(weaponType.getName()); + r.add(numberOfWeaponHits); r.add(atype.getShortName()); if (entityTarget != null) { r.addDesc(entityTarget); @@ -166,7 +166,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && ((toHit.getMoS() / 3) >= 1) && (entityTarget != null); if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -207,7 +207,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && atype.getAmmoType() == AmmoType.T_ARROW_IV) { gameManager.assignAMS(); } - while (nweaponsHit > 0) { + while (numberOfWeaponHits > 0) { int hits = 1; int nCluster = 1; if ((entityTarget != null) && (entityTarget.getTaggedBy() != -1)) { @@ -265,7 +265,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (!bMissed && (entityTarget != null)) { handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - gameManager.creditKill(entityTarget, ae); + gameManager.creditKill(entityTarget, attackerEntity); } else if (!bMissed && // The attack is targeting a specific building (target.getTargetType() == Targetable.TYPE_BLDG_TAG)) { r = new Report(3390); @@ -305,8 +305,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { } toHit.setSideTable(entity.sideTable(aaa.getCoords())); HitData hit = entity.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setAttackerId(getAttackerId()); // BA gets damage to all troopers if (entity instanceof BattleArmor) { @@ -322,11 +322,11 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { ratedDamage, false, DamageType.NONE, false, true, throughFront, underWater)); } - gameManager.creditKill(entity, ae); + gameManager.creditKill(entity, attackerEntity); } } Report.addNewline(vPhaseReport); - nweaponsHit--; + numberOfWeaponHits--; } return false; } @@ -336,7 +336,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { * Uses a CFR to let the player choose from eligible TAGs */ public void convertHomingShotToEntityTarget() { - ArtilleryAttackAction aaa = (ArtilleryAttackAction) waa; + ArtilleryAttackAction aaa = (ArtilleryAttackAction) weaponAttackAction; final Coords tc = target.getPosition(); Targetable newTarget = null; @@ -351,7 +351,7 @@ public void convertHomingShotToEntityTarget() { allowed.add(ti); break; case Targetable.TYPE_ENTITY: - if (ae.isEnemyOf((Entity) ti.target) + if (attackerEntity.isEnemyOf((Entity) ti.target) || game.getOptions().booleanOption(OptionsConstants.BASE_FRIENDLY_FIRE)) { allowed.add(ti); } @@ -410,7 +410,7 @@ public void convertHomingShotToEntityTarget() { targetIds.add(target.target.getId()); targetTypes.add(target.target.getTargetType()); } - int choice = gameManager.processTAGTargetCFR(ae.getOwnerId(), targetIds, targetTypes); + int choice = gameManager.processTAGTargetCFR(attackerEntity.getOwnerId(), targetIds, targetTypes); newTarget = allowed.get(choice).target; target = newTarget; aaa.setTargetId(target.getId()); @@ -437,7 +437,7 @@ protected boolean handleSpecialMiss(Entity entityTarget, * against Arrow IV homing missiles * Artillery bays resolve each weapon individually and don't use Aero AV, so we * can safely do this - * + * * @param vPhaseReport The report for this game phase, be it offboard (Indirect) * or firing (Direct) * @param ammoUsed The ammoType used by this bay - as only homing shots can @@ -542,7 +542,7 @@ protected boolean checkPDConditions() { || target.getTargetType() != Targetable.TYPE_ENTITY || !advancedPD || !advancedAMS - || waa.getCounterEquipment() == null) { + || weaponAttackAction.getCounterEquipment() == null) { return false; } return true; diff --git a/megamek/src/megamek/common/weapons/ArtilleryCannonWeaponHandler.java b/megamek/src/megamek/common/weapons/ArtilleryCannonWeaponHandler.java index f020e3811d6..938cedfed5a 100644 --- a/megamek/src/megamek/common/weapons/ArtilleryCannonWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/ArtilleryCannonWeaponHandler.java @@ -17,8 +17,10 @@ import java.util.Vector; import megamek.common.*; +import megamek.common.actions.NukeDetonatedAction; import megamek.common.actions.WeaponAttackAction; import megamek.common.enums.GamePhase; +import megamek.common.event.GamePlayerStrategicActionEvent; import megamek.logging.MMLogger; import megamek.server.totalwarfare.TWGameManager; @@ -40,16 +42,16 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (!cares(phase)) { return true; } - if (ae == null) { + if (attackerEntity == null) { logger.error("Artillery Entity is null!"); return true; } Coords targetPos = target.getPosition(); boolean targetIsEntity = target.getTargetType() == Targetable.TYPE_ENTITY; - boolean isFlak = targetIsEntity && Compute.isFlakAttack(ae, (Entity) target); + boolean isFlak = targetIsEntity && Compute.isFlakAttack(attackerEntity, (Entity) target); boolean asfFlak = isFlak && target.isAirborne(); - Mounted ammoUsed = ae.getEquipment(waa.getAmmoId()); + Mounted ammoUsed = attackerEntity.getEquipment(weaponAttackAction.getAmmoId()); final AmmoType ammoType = (ammoUsed == null) ? null : (AmmoType) ammoUsed.getType(); // Report weapon attack and its to-hit value. @@ -57,8 +59,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - if (wtype != null) { - r.add(wtype.getName()); + if (weaponType != null) { + r.add(weaponType.getName()); } else { r.add("Error: From Nowhere"); } @@ -169,11 +171,16 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { return false; } else if (ammoType.getMunitionType().contains(AmmoType.Munitions.M_DAVY_CROCKETT_M)) { // The appropriate term here is "Bwahahahahaha..." + + gameManager.drawNukeHitOnBoard(targetPos); + gameManager.getGame().processGameEvent( + new GamePlayerStrategicActionEvent(gameManager, + new NukeDetonatedAction(attackerEntity.getId(), attackerEntity.getOwnerId(), AmmoType.Munitions.M_DAVY_CROCKETT_M))); gameManager.doNuclearExplosion(targetPos, 1, vPhaseReport); return false; } else if (ammoType.getMunitionType().contains(AmmoType.Munitions.M_FASCAM)) { - gameManager.deliverFASCAMMinefield(targetPos, ae.getOwner().getId(), - ammoType.getRackSize(), ae.getId()); + gameManager.deliverFASCAMMinefield(targetPos, attackerEntity.getOwner().getId(), + ammoType.getRackSize(), attackerEntity.getId()); return false; } else if (ammoType.getMunitionType().contains(AmmoType.Munitions.M_SMOKE)) { gameManager.deliverArtillerySmoke(targetPos, vPhaseReport); @@ -185,11 +192,11 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (asfFlak) { AreaEffectHelper.artilleryDamageEntity((Entity) target, ammoType.getRackSize(), null, 0, false, asfFlak, isFlak, target.getElevation(), - targetPos, atype, targetPos, false, ae, null, target.getElevation(), + targetPos, this.ammoType, targetPos, false, attackerEntity, null, target.getElevation(), vPhaseReport, gameManager); } else { AreaEffectHelper.processFuelAirDamage(targetPos, - ammoType, ae, vPhaseReport, gameManager); + ammoType, attackerEntity, vPhaseReport, gameManager); } return false; @@ -212,19 +219,19 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.subject = subjectId; vPhaseReport.addElement(r); - AreaEffectHelper.clearMineFields(targetPos, Minefield.CLEAR_NUMBER_WEAPON, ae, vPhaseReport, game, + AreaEffectHelper.clearMineFields(targetPos, Minefield.CLEAR_NUMBER_WEAPON, attackerEntity, vPhaseReport, game, gameManager); } - gameManager.artilleryDamageArea(targetPos, ae.getPosition(), ammoType, - subjectId, ae, isFlak, altitude, mineClear, vPhaseReport, + gameManager.artilleryDamageArea(targetPos, attackerEntity.getPosition(), ammoType, + subjectId, attackerEntity, isFlak, altitude, mineClear, vPhaseReport, asfFlak, -1); // artillery may unintentionally clear minefields, but only if it wasn't trying // to // TODO : Does this apply to arty cannons? if (!mineClear) { - AreaEffectHelper.clearMineFields(targetPos, Minefield.CLEAR_NUMBER_WEAPON_ACCIDENT, ae, vPhaseReport, game, + AreaEffectHelper.clearMineFields(targetPos, Minefield.CLEAR_NUMBER_WEAPON_ACCIDENT, attackerEntity, vPhaseReport, game, gameManager); } @@ -233,7 +240,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { @Override protected int calcDamagePerHit() { - double toReturn = wtype.getDamage(); + double toReturn = weaponType.getDamage(); // area effect damage is double if (target.isConventionalInfantry()) { toReturn /= 0.5; diff --git a/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectFireHandler.java b/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectFireHandler.java index e8e2c29d5f1..41ae7492486 100644 --- a/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectFireHandler.java +++ b/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectFireHandler.java @@ -20,8 +20,10 @@ import megamek.common.AmmoType.Munitions; import megamek.common.SpecialHexDisplay.Type; import megamek.common.actions.ArtilleryAttackAction; +import megamek.common.actions.NukeDetonatedAction; import megamek.common.actions.WeaponAttackAction; import megamek.common.enums.GamePhase; +import megamek.common.event.GamePlayerStrategicActionEvent; import megamek.common.options.OptionsConstants; import megamek.common.weapons.AreaEffectHelper.DamageFalloff; import megamek.common.weapons.capitalweapons.CapitalMissileWeapon; @@ -57,7 +59,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { return true; } String artyMsg; - ArtilleryAttackAction aaa = (ArtilleryAttackAction) waa; + ArtilleryAttackAction aaa = (ArtilleryAttackAction) weaponAttackAction; if (phase.isTargeting()) { if (!handledAmmoAndReport) { addHeat(); @@ -66,7 +68,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + " (" + atype.getShortName() + ')'); + r.add(weaponType.getName() + " (" + ammoType.getShortName() + ')'); r.add(aaa.getTurnsTilHit()); vPhaseReport.addElement(r); Report.addNewline(vPhaseReport); @@ -105,7 +107,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { Report r = new Report(3158); r.indent(); r.subject = subjectId; - r.add(wtype.getName()); + r.add(weaponType.getName()); vPhaseReport.add(r); return true; } @@ -117,16 +119,16 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { // Handle counter-battery on fleeing/fled off-board targets. if (null == targetPos) { logger - .error(String.format("Artillery Target %s is missing; off-board target fled?", waa.getTargetId())); + .error(String.format("Artillery Target %s is missing; off-board target fled?", weaponAttackAction.getTargetId())); return false; } final int playerId = aaa.getPlayerId(); boolean targetIsEntity = target.getTargetType() == Targetable.TYPE_ENTITY; - boolean isFlak = targetIsEntity && Compute.isFlakAttack(ae, (Entity) target); + boolean isFlak = targetIsEntity && Compute.isFlakAttack(attackerEntity, (Entity) target); boolean asfFlak = isFlak && target.isAirborne(); Entity bestSpotter = null; - if (ae == null) { + if (attackerEntity == null) { logger.error("Artillery Entity is null!"); return true; } @@ -136,9 +138,9 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { // the firing entity, so we get the specific ammo used from the ammo carrier // However, we only bother with this if the ammo carrier is actually different // from the attacker - Entity ammoCarrier = ae; + Entity ammoCarrier = attackerEntity; - if (aaa.getAmmoCarrier() != ae.getId()) { + if (aaa.getAmmoCarrier() != attackerEntity.getId()) { ammoCarrier = aaa.getEntity(game, aaa.getAmmoCarrier()); } @@ -211,7 +213,7 @@ public boolean accept(Entity entity) { // This should only happen for indirect shots if (roll.getIntValue() >= toHit.getValue() && !(this instanceof ArtilleryWeaponDirectFireHandler)) { - ae.aTracker.setModifier(TargetRoll.AUTOMATIC_SUCCESS, targetPos); + attackerEntity.aTracker.setModifier(TargetRoll.AUTOMATIC_SUCCESS, targetPos); } // If the shot missed, but was adjusted by a // spotter, future shots are more likely to hit. @@ -225,11 +227,11 @@ public boolean accept(Entity entity) { // Only apply these modifiers to indirect artillery else if ((null != bestSpotter) && !(this instanceof ArtilleryWeaponDirectFireHandler)) { // only add mods if it's not an automatic success - if (ae.aTracker.getModifier(weapon, targetPos) != TargetRoll.AUTOMATIC_SUCCESS) { + if (attackerEntity.aTracker.getModifier(weapon, targetPos) != TargetRoll.AUTOMATIC_SUCCESS) { if (bestSpotter.hasAbility(OptionsConstants.MISC_FORWARD_OBSERVER)) { - ae.aTracker.setSpotterHasForwardObs(true); + attackerEntity.aTracker.setSpotterHasForwardObs(true); } - ae.aTracker.setModifier(ae.aTracker.getModifier(weapon, targetPos) - 1, targetPos); + attackerEntity.aTracker.setModifier(attackerEntity.aTracker.getModifier(weapon, targetPos) - 1, targetPos); } } } @@ -239,8 +241,8 @@ else if ((null != bestSpotter) && !(this instanceof ArtilleryWeaponDirectFireHan r.indent(); r.newlines = 0; r.subject = subjectId; - if (wtype != null) { - r.add(wtype.getName() + " (" + atype.getShortName() + ')'); + if (weaponType != null) { + r.add(weaponType.getName() + " (" + ammoType.getShortName() + ')'); } else { r.add("Error: From Nowhere"); } @@ -306,26 +308,26 @@ else if ((null != bestSpotter) && !(this instanceof ArtilleryWeaponDirectFireHan // if we have no ammo for this attack then don't bother doing anything else, but // log the error - if (atype == null) { + if (ammoType == null) { logger .error("Artillery weapon fired with no ammo.\n\n" + Thread.currentThread().getStackTrace()); return false; } - if (atype.getMunitionType().contains(Munitions.M_FAE)) { + if (ammoType.getMunitionType().contains(Munitions.M_FAE)) { handleArtilleryDriftMarker(targetPos, finalPos, aaa, AreaEffectHelper.processFuelAirDamage( - finalPos, atype, aaa.getEntity(game), vPhaseReport, gameManager)); + finalPos, ammoType, aaa.getEntity(game), vPhaseReport, gameManager)); return false; } - if (atype.getMunitionType().contains(Munitions.M_FLARE)) { + if (ammoType.getMunitionType().contains(Munitions.M_FLARE)) { int radius; - if (atype.getAmmoType() == AmmoType.T_ARROW_IV) { + if (ammoType.getAmmoType() == AmmoType.T_ARROW_IV) { radius = 4; - } else if (atype.getAmmoType() == AmmoType.T_LONG_TOM) { + } else if (ammoType.getAmmoType() == AmmoType.T_LONG_TOM) { radius = 3; - } else if (atype.getAmmoType() == AmmoType.T_SNIPER) { + } else if (ammoType.getAmmoType() == AmmoType.T_SNIPER) { radius = 2; } else { radius = 1; @@ -333,39 +335,43 @@ else if ((null != bestSpotter) && !(this instanceof ArtilleryWeaponDirectFireHan gameManager.deliverArtilleryFlare(finalPos, radius); return false; } - if (atype.getMunitionType().contains(Munitions.M_DAVY_CROCKETT_M)) { + if (ammoType.getMunitionType().contains(Munitions.M_DAVY_CROCKETT_M)) { // The appropriate term here is "Bwahahahahaha..." if (target.isOffBoard()) { AreaEffectHelper.doNuclearExplosion((Entity) aaa.getTarget(game), finalPos, 1, vPhaseReport, gameManager); } else { + gameManager.drawNukeHitOnBoard(targetPos); gameManager.doNuclearExplosion(finalPos, 1, vPhaseReport); } + gameManager.getGame().processGameEvent( + new GamePlayerStrategicActionEvent(gameManager, + new NukeDetonatedAction(attackerEntity.getId(), attackerEntity.getOwnerId(), AmmoType.Munitions.M_DAVY_CROCKETT_M))); return false; } - if (atype.getMunitionType().contains(Munitions.M_FASCAM)) { - int rackSize = atype.getRackSize(); - if (atype.getAmmoType() == AmmoType.T_ARROW_IV) { - rackSize = atype.isClan() ? 30 : 20; + if (ammoType.getMunitionType().contains(Munitions.M_FASCAM)) { + int rackSize = ammoType.getRackSize(); + if (ammoType.getAmmoType() == AmmoType.T_ARROW_IV) { + rackSize = ammoType.isClan() ? 30 : 20; } - gameManager.deliverFASCAMMinefield(finalPos, ae.getOwner().getId(), rackSize, ae.getId()); + gameManager.deliverFASCAMMinefield(finalPos, attackerEntity.getOwner().getId(), rackSize, attackerEntity.getId()); return false; } - if (atype.getMunitionType().contains(Munitions.M_INFERNO_IV)) { + if (ammoType.getMunitionType().contains(Munitions.M_INFERNO_IV)) { handleArtilleryDriftMarker(targetPos, finalPos, aaa, - gameManager.deliverArtilleryInferno(finalPos, ae, subjectId, vPhaseReport)); + gameManager.deliverArtilleryInferno(finalPos, attackerEntity, subjectId, vPhaseReport)); return false; } - if (atype.getMunitionType().contains(Munitions.M_VIBRABOMB_IV)) { - gameManager.deliverThunderVibraMinefield(finalPos, ae.getOwner().getId(), 30, - waa.getOtherAttackInfo(), ae.getId()); + if (ammoType.getMunitionType().contains(Munitions.M_VIBRABOMB_IV)) { + gameManager.deliverThunderVibraMinefield(finalPos, attackerEntity.getOwner().getId(), 30, + weaponAttackAction.getOtherAttackInfo(), attackerEntity.getId()); return false; } - if (atype.getMunitionType().contains(Munitions.M_SMOKE)) { + if (ammoType.getMunitionType().contains(Munitions.M_SMOKE)) { gameManager.deliverArtillerySmoke(finalPos, vPhaseReport); return false; } - if (atype.getMunitionType().contains(Munitions.M_LASER_INHIB)) { + if (ammoType.getMunitionType().contains(Munitions.M_LASER_INHIB)) { gameManager.deliverLIsmoke(finalPos, vPhaseReport); return false; } @@ -385,7 +391,7 @@ else if ((null != bestSpotter) && !(this instanceof ArtilleryWeaponDirectFireHan r.subject = subjectId; vPhaseReport.addElement(r); - AreaEffectHelper.clearMineFields(finalPos, Minefield.CLEAR_NUMBER_WEAPON, ae, vPhaseReport, game, + AreaEffectHelper.clearMineFields(finalPos, Minefield.CLEAR_NUMBER_WEAPON, attackerEntity, vPhaseReport, game, gameManager); } @@ -396,7 +402,7 @@ else if ((null != bestSpotter) && !(this instanceof ArtilleryWeaponDirectFireHan // so we need to carry out offboard/null checks against the "current" version of // the target. if ((updatedTarget != null) && updatedTarget.isOffBoard()) { - DamageFalloff df = AreaEffectHelper.calculateDamageFallOff(atype, shootingBA, mineClear); + DamageFalloff df = AreaEffectHelper.calculateDamageFallOff(ammoType, shootingBA, mineClear); int actualDamage = df.damage - (df.falloff * finalPos.distance(target.getPosition())); Coords effectiveTargetPos = aaa.getCoords(); @@ -407,13 +413,13 @@ else if ((null != bestSpotter) && !(this instanceof ArtilleryWeaponDirectFireHan if (actualDamage > 0) { AreaEffectHelper.artilleryDamageEntity((Entity) updatedTarget, actualDamage, null, 0, false, asfFlak, isFlak, altitude, - effectiveTargetPos, atype, finalPos, false, ae, null, altitude, + effectiveTargetPos, ammoType, finalPos, false, attackerEntity, null, altitude, vPhaseReport, gameManager); } } else { handleArtilleryDriftMarker(targetPos, finalPos, aaa, - gameManager.artilleryDamageArea(finalPos, aaa.getCoords(), atype, - subjectId, ae, isFlak, altitude, mineClear, vPhaseReport, + gameManager.artilleryDamageArea(finalPos, aaa.getCoords(), ammoType, + subjectId, attackerEntity, isFlak, altitude, mineClear, vPhaseReport, asfFlak, shootingBA)); } @@ -421,7 +427,7 @@ else if ((null != bestSpotter) && !(this instanceof ArtilleryWeaponDirectFireHan // artillery may unintentionally clear minefields, but only if it wasn't trying // to if (!mineClear) { - AreaEffectHelper.clearMineFields(finalPos, Minefield.CLEAR_NUMBER_WEAPON_ACCIDENT, ae, vPhaseReport, game, + AreaEffectHelper.clearMineFields(finalPos, Minefield.CLEAR_NUMBER_WEAPON_ACCIDENT, attackerEntity, vPhaseReport, game, gameManager); } @@ -481,7 +487,7 @@ private Coords handleReportsAndDirectScatter(boolean isFlak, Coords targetPos, V // in the ArtilleryWeaponDirectFireHandler Coords origPos = targetPos; int moF = toHit.getMoS(); - if (ae.hasAbility("oblique_artillery")) { + if (attackerEntity.hasAbility("oblique_artillery")) { // getMoS returns a negative MoF // simple math is better so lets make it positive moF = Math.max(moF + 2, 0); @@ -597,13 +603,13 @@ private void handleCounterBatteryObservation(WeaponAttackAction aaa, Coords targ */ @Override protected int calcDamagePerHit() { - double toReturn = wtype.rackSize; - if (wtype instanceof CapitalMissileWeapon) { - toReturn = wtype.getRoundShortAV(); + double toReturn = weaponType.rackSize; + if (weaponType instanceof CapitalMissileWeapon) { + toReturn = weaponType.getRoundShortAV(); } // BA Tube artillery is the only artillery that can be mounted by BA // so we do the multiplication here - if (ae instanceof BattleArmor ba) { + if (attackerEntity instanceof BattleArmor ba) { toReturn *= ba.getNumberActiverTroopers(); } // area effect damage is double diff --git a/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectHomingHandler.java b/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectHomingHandler.java index a5dd62249f7..2cee46ee826 100644 --- a/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectHomingHandler.java +++ b/megamek/src/megamek/common/weapons/ArtilleryWeaponIndirectHomingHandler.java @@ -63,7 +63,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (!cares(phase)) { return true; } - ArtilleryAttackAction aaa = (ArtilleryAttackAction) waa; + ArtilleryAttackAction aaa = (ArtilleryAttackAction) weaponAttackAction; if (phase.isTargeting()) { if (!handledAmmoAndReport) { addHeat(); @@ -72,7 +72,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + " (" + atype.getShortName() + ")"); + r.add(weaponType.getName() + " (" + ammoType.getShortName() + ")"); r.add(aaa.getTurnsTilHit()); vPhaseReport.addElement(r); Report.addNewline(vPhaseReport); @@ -98,7 +98,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { entityTarget); final boolean bldgDamagedOnMiss = targetInBuilding && !(target instanceof Infantry) - && ae.getPosition().distance(target.getPosition()) <= 1; + && attackerEntity.getPosition().distance(target.getPosition()) <= 1; // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); @@ -108,7 +108,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + " (" + atype.getShortName() + ")"); + r.add(weaponType.getName() + " (" + ammoType.getShortName() + ")"); if (entityTarget != null) { r.addDesc(entityTarget); } else { @@ -163,7 +163,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && ((toHit.getMoS() / 3) >= 1) && (entityTarget != null); if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -181,7 +181,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (missReported) { bMissed = true; } - nDamPerHit = wtype.getRackSize(); + nDamPerHit = weaponType.getRackSize(); AmmoType ammoType = (AmmoType) ammo.getType(); @@ -253,7 +253,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (!bMissed && (entityTarget != null)) { handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - gameManager.creditKill(entityTarget, ae); + gameManager.creditKill(entityTarget, attackerEntity); } else if (!bMissed && // The attack is targeting a specific building (target.getTargetType() == Targetable.TYPE_BLDG_TAG)) { r = new Report(3390); @@ -279,7 +279,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { // homing artillery splash damage is area effect. // do damage to woods, 2 * normal damage (TW page 112) // on the other hand, if the hex *is* the target, do full damage - int hexDamage = targetingHex ? wtype.getRackSize() : ratedDamage * 2; + int hexDamage = targetingHex ? weaponType.getRackSize() : ratedDamage * 2; bldg = null; bldg = game.getBoard().getBuildingAt(coords); @@ -311,7 +311,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { */ public void convertHomingShotToEntityTarget() { boolean debug = logger.isDebugEnabled(); - ArtilleryAttackAction aaa = (ArtilleryAttackAction) waa; + ArtilleryAttackAction aaa = (ArtilleryAttackAction) weaponAttackAction; final Coords tc = target.getPosition(); Targetable newTarget = null; @@ -333,7 +333,7 @@ public void convertHomingShotToEntityTarget() { allowed.add(ti); break; case Targetable.TYPE_ENTITY: - if (ae.isEnemyOf((Entity) ti.target) + if (attackerEntity.isEnemyOf((Entity) ti.target) || game.getOptions().booleanOption(OptionsConstants.BASE_FRIENDLY_FIRE)) { allowed.add(ti); } @@ -398,7 +398,7 @@ public void convertHomingShotToEntityTarget() { targetIds.add(target.target.getId()); targetTypes.add(target.target.getTargetType()); } - int choice = gameManager.processTAGTargetCFR(ae.getOwnerId(), targetIds, targetTypes); + int choice = gameManager.processTAGTargetCFR(attackerEntity.getOwnerId(), targetIds, targetTypes); newTarget = allowed.get(choice).target; target = newTarget; aaa.setTargetId(target.getId()); @@ -488,7 +488,7 @@ protected int handleAMS(Vector vPhaseReport) { } // PD/AMS bays should engage using AV and missile armor per SO Errata if (amsBayEngagedCap || pdBayEngagedCap) { - CapMissileArmor = wtype.getMissileArmor() - CounterAV; + CapMissileArmor = weaponType.getMissileArmor() - CounterAV; CapMissileAMSMod = calcCapMissileAMSMod(); Report r = new Report(3235); r.subject = subjectId; diff --git a/megamek/src/megamek/common/weapons/AttackHandler.java b/megamek/src/megamek/common/weapons/AttackHandler.java index a1d5cf6c00a..1f9e190cda0 100644 --- a/megamek/src/megamek/common/weapons/AttackHandler.java +++ b/megamek/src/megamek/common/weapons/AttackHandler.java @@ -1,14 +1,14 @@ /* * MegaMek - Copyright (C) 2004, 2005 Ben Mazur (bmazur@sev.org) * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ package megamek.common.weapons; @@ -22,49 +22,43 @@ /** * Describes a set of methods a class can use to represent an attack from some weapon. - * + * * @author Andrew Hunter * @since May 10, 2004 */ public interface AttackHandler { // Does it care? - public boolean cares(GamePhase phase); + boolean cares(GamePhase phase); // If it cares, call this. If it needs to remain in queue, returns true, // else false. - public boolean handle(GamePhase phase, Vector vPhaseReports); + boolean handle(GamePhase phase, Vector vPhaseReports); + + int getAttackerId(); + + Entity getAttacker(); - // Frankly, wish I could get rid of this, but I think certain things - // occasionally need to know the firer. - public int getAttackerId(); - - public Entity getAttacker(); + boolean announcedEntityFiring(); - public boolean announcedEntityFiring(); + void setAnnouncedEntityFiring(boolean announcedEntityFiring); - public void setAnnouncedEntityFiring(boolean announcedEntityFiring); + WeaponAttackAction getWeaponAttackAction(); - public WeaponAttackAction getWaa(); - /** * Used to determine if the AttackHandler is handling a strafing run. - * - * @return */ - public boolean isStrafing(); - - public void setStrafing(boolean isStrafing); - + boolean isStrafing(); + + void setStrafing(boolean isStrafing); + /** * Used to determine if this is the firt time a weapon is firing as part of * a strafing run. This is used for handling heat, to prevent shots after * the first one from generating heat. - * - * @return */ - public boolean isStrafingFirstShot(); - - public void setStrafingFirstShot(boolean isFirstShotStrafing); + boolean isStrafingFirstShot(); + + void setStrafingFirstShot(boolean isFirstShotStrafing); } diff --git a/megamek/src/megamek/common/weapons/BayWeaponHandler.java b/megamek/src/megamek/common/weapons/BayWeaponHandler.java index 4260e99e1d7..e688e2f6cd8 100644 --- a/megamek/src/megamek/common/weapons/BayWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/BayWeaponHandler.java @@ -49,7 +49,7 @@ public BayWeaponHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager @Override protected int calcAttackValue() { double av = 0; - int range = RangeType.rangeBracket(nRange, wtype.getATRanges(), true, false); + int range = RangeType.rangeBracket(nRange, weaponType.getATRanges(), true, false); for (WeaponMounted m : weapon.getBayWeapons()) { if (!m.isBreached() && !m.isDestroyed() && !m.isJammed()) { @@ -83,14 +83,14 @@ protected void addHeat() { if (!(toHit.getValue() == TargetRoll.IMPOSSIBLE)) { if (game.getOptions().booleanOption(OptionsConstants.ADVAERORULES_HEAT_BY_BAY)) { for (WeaponMounted m : weapon.getBayWeapons()) { - ae.heatBuildup += m.getCurrentHeat(); + attackerEntity.heatBuildup += m.getCurrentHeat(); } } else { int loc = weapon.getLocation(); boolean rearMount = weapon.isRearMounted(); - if (!ae.hasArcFired(loc, rearMount)) { - ae.heatBuildup += ae.getHeatInArc(loc, rearMount); - ae.setArcFired(loc, rearMount); + if (!attackerEntity.hasArcFired(loc, rearMount)) { + attackerEntity.heatBuildup += attackerEntity.getHeatInArc(loc, rearMount); + attackerEntity.setArcFired(loc, rearMount); } } } @@ -121,8 +121,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && target.getTargetType() != Targetable.TYPE_BUILDING)) || game.getBoard().inSpace() // Capital missile launchers should return the root handler... - || (wtype.getAtClass() == (WeaponType.CLASS_CAPITAL_MISSILE)) - || (wtype.getAtClass() == (WeaponType.CLASS_AR10))) { + || (weaponType.getAtClass() == (WeaponType.CLASS_CAPITAL_MISSILE)) + || (weaponType.getAtClass() == (WeaponType.CLASS_AR10))) { return super.handle(phase, vPhaseReport); } @@ -134,23 +134,23 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { entityTarget); final boolean bldgDamagedOnMiss = targetInBuilding && !(target instanceof Infantry) - && ae.getPosition().distance(target.getPosition()) <= 1; + && attackerEntity.getPosition().distance(target.getPosition()) <= 1; if (entityTarget != null) { - ae.setLastTarget(entityTarget.getId()); - ae.setLastTargetDisplayName(entityTarget.getDisplayName()); + attackerEntity.setLastTarget(entityTarget.getId()); + attackerEntity.setLastTargetDisplayName(entityTarget.getDisplayName()); } // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); - String number = nweapons > 1 ? " (" + nweapons + ")" : ""; + String number = numberOfWeapons > 1 ? " (" + numberOfWeapons + ")" : ""; // Report weapon attack and its to-hit value. Report r = new Report(3115); r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + number); + r.add(weaponType.getName() + number); if (entityTarget != null) { r.addDesc(entityTarget); } else { @@ -206,7 +206,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && ((toHit.getMoS() / 3) >= 1) && (entityTarget != null); if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -263,7 +263,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { Report.addNewline(vPhaseReport); // loop through weapons in bay and do damage - int range = RangeType.rangeBracket(nRange, wtype.getATRanges(), true, false); + int range = RangeType.rangeBracket(nRange, weaponType.getATRanges(), true, false); int hits = 1; int nCluster = 1; for (WeaponMounted m : weapon.getBayWeapons()) { @@ -300,8 +300,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && (toHit.getThruBldg() != null) && (entityTarget instanceof Infantry)) { // If elevation is the same, building doesn't absorb - if (ae.getElevation() != entityTarget.getElevation()) { - int dmgClass = wtype.getInfantryDamageClass(); + if (attackerEntity.getElevation() != entityTarget.getElevation()) { + int dmgClass = weaponType.getInfantryDamageClass(); int nDamage; if (dmgClass < WeaponType.WEAPON_BURST_1D6) { nDamage = nDamPerHit * Math.min(nCluster, hits); @@ -310,7 +310,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { // absorbed damage shouldn't reduce incoming damage, // since the incoming damage was reduced in // Compute.directBlowInfantryDamage - nDamage = -wtype.getDamage(nRange) * Math.min(nCluster, hits); + nDamage = -weaponType.getDamage(nRange) * Math.min(nCluster, hits); } bldgAbsorbs = (int) Math.round(nDamage * bldg.getInfDmgFromInside()); } else { @@ -320,7 +320,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { } handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - gameManager.creditKill(entityTarget, ae); + gameManager.creditKill(entityTarget, attackerEntity); } // Handle the next weapon in the bay Report.addNewline(vPhaseReport); return false; @@ -347,11 +347,11 @@ public boolean handleAeroSanity(GamePhase phase, Vector vPhaseReport) { entityTarget); final boolean bldgDamagedOnMiss = targetInBuilding && !(target instanceof Infantry) - && ae.getPosition().distance(target.getPosition()) <= 1; + && attackerEntity.getPosition().distance(target.getPosition()) <= 1; if (entityTarget != null) { - ae.setLastTarget(entityTarget.getId()); - ae.setLastTargetDisplayName(entityTarget.getDisplayName()); + attackerEntity.setLastTarget(entityTarget.getId()); + attackerEntity.setLastTargetDisplayName(entityTarget.getDisplayName()); } // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); @@ -360,7 +360,7 @@ public boolean handleAeroSanity(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName()); + r.add(weaponType.getName()); if (entityTarget != null) { r.addDesc(entityTarget); } else { @@ -454,7 +454,7 @@ public boolean handleAeroSanity(GamePhase phase, Vector vPhaseReport) { && ((toHit.getMoS() / 3) >= 1) && (entityTarget != null); if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -550,8 +550,8 @@ public boolean handleAeroSanity(GamePhase phase, Vector vPhaseReport) { WeaponType bayWType = m.getType(); if (bayWType instanceof Weapon) { replaceReport = vPhaseReport.size(); - WeaponAttackAction bayWaa = new WeaponAttackAction(waa.getEntityId(), waa.getTargetType(), - waa.getTargetId(), m.getEquipmentNum()); + WeaponAttackAction bayWaa = new WeaponAttackAction(weaponAttackAction.getEntityId(), weaponAttackAction.getTargetType(), + weaponAttackAction.getTargetId(), m.getEquipmentNum()); AttackHandler bayWHandler = ((Weapon) bayWType).getCorrectHandler(autoHit, bayWaa, game, gameManager); bayWHandler.setAnnouncedEntityFiring(false); diff --git a/megamek/src/megamek/common/weapons/BombAttackHandler.java b/megamek/src/megamek/common/weapons/BombAttackHandler.java index 3d79f684935..88343a773fe 100644 --- a/megamek/src/megamek/common/weapons/BombAttackHandler.java +++ b/megamek/src/megamek/common/weapons/BombAttackHandler.java @@ -52,20 +52,20 @@ protected boolean usesClusterTable() { @Override protected void useAmmo() { - int[] payload = waa.getBombPayload(); - if (!ae.isBomber() || (null == payload)) { + int[] payload = weaponAttackAction.getBombPayload(); + if (!attackerEntity.isBomber() || (null == payload)) { return; } for (int type = 0; type < payload.length; type++) { for (int i = 0; i < payload[type]; i++) { // find the first mounted bomb of this type and drop it - for (Mounted bomb : ae.getBombs()) { + for (Mounted bomb : attackerEntity.getBombs()) { if (!bomb.isDestroyed() && (bomb.getUsableShotsLeft() > 0) && (((BombType) bomb.getType()).getBombType() == type)) { bomb.setShotsLeft(0); if (bomb.isInternalBomb()) { - ((IBomber) ae).increaseUsedInternalBombs(1); + ((IBomber) attackerEntity).increaseUsedInternalBombs(1); } break; } @@ -82,10 +82,10 @@ protected void useAmmo() { */ @Override public boolean handle(GamePhase phase, Vector vPhaseReport) { - int[] payload = waa.getBombPayload(); + int[] payload = weaponAttackAction.getBombPayload(); Coords coords = target.getPosition(); Coords drop; - Player player = game.getEntity(waa.getEntityId()).getOwner(); + Player player = game.getEntity(weaponAttackAction.getEntityId()).getOwner(); String bombMsg; Vector hitIds = null; @@ -103,7 +103,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { boolean laserGuided = false; if (type == BombType.B_LG) { for (TagInfo ti : game.getTagInfo()) { - if (ti.missed || game.getEntity(waa.getEntityId()).isEnemyOf(game.getEntity(ti.attackerId))) { + if (ti.missed || game.getEntity(weaponAttackAction.getEntityId()).isEnemyOf(game.getEntity(ti.attackerId))) { // Not a usable friendly TAG continue; } @@ -134,8 +134,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - if (wtype != null) { - r.add(wtype.getName()); + if (weaponType != null) { + r.add(weaponType.getName()); } else { r.add("Error: From Nowhere"); } @@ -210,23 +210,23 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { player, bombMsg)); } else { int moF = -typeModifiedToHit.getMoS(); - if (ae.hasAbility(OptionsConstants.GUNNERY_GOLDEN_GOOSE)) { + if (attackerEntity.hasAbility(OptionsConstants.GUNNERY_GOLDEN_GOOSE)) { if ((-typeModifiedToHit.getMoS() - 2) < 1) { moF = 0; } else { moF = -typeModifiedToHit.getMoS() - 2; } } - if (wtype.hasFlag(WeaponType.F_ALT_BOMB)) { + if (weaponType.hasFlag(WeaponType.F_ALT_BOMB)) { // Need to determine location in flight path int idx = 0; - for (; idx < ae.getPassedThrough().size(); idx++) { - if (ae.getPassedThrough().get(idx).equals(coords)) { + for (; idx < attackerEntity.getPassedThrough().size(); idx++) { + if (attackerEntity.getPassedThrough().get(idx).equals(coords)) { break; } } // Retrieve facing at current step in flight path - int facing = ae.getPassedThroughFacing().get(idx); + int facing = attackerEntity.getPassedThroughFacing().get(idx); // Scatter, based on location and facing drop = Compute.scatterAltitudeBombs(coords, facing, moF); } else { @@ -266,18 +266,18 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { } } if (type == BombType.B_INFERNO) { - hitIds = gameManager.deliverBombInferno(drop, ae, subjectId, vPhaseReport); + hitIds = gameManager.deliverBombInferno(drop, attackerEntity, subjectId, vPhaseReport); } else if (type == BombType.B_THUNDER) { - gameManager.deliverThunderMinefield(drop, ae.getOwner().getId(), 20, ae.getId()); + gameManager.deliverThunderMinefield(drop, attackerEntity.getOwner().getId(), 20, attackerEntity.getId()); List hexes = drop.allAdjacent(); for (Coords c : hexes) { - gameManager.deliverThunderMinefield(c, ae.getOwner().getId(), 20, ae.getId()); + gameManager.deliverThunderMinefield(c, attackerEntity.getOwner().getId(), 20, attackerEntity.getId()); } } else if (type == BombType.B_FAE_SMALL || type == BombType.B_FAE_LARGE) { hitIds = AreaEffectHelper.processFuelAirDamage(drop, - EquipmentType.get(BombType.getBombInternalName(type)), ae, vPhaseReport, gameManager); + EquipmentType.get(BombType.getBombInternalName(type)), attackerEntity, vPhaseReport, gameManager); } else { - hitIds = gameManager.deliverBombDamage(drop, type, subjectId, ae, vPhaseReport); + hitIds = gameManager.deliverBombDamage(drop, type, subjectId, attackerEntity, vPhaseReport); } // Display drifts that hit nothing separately from drifts that dealt damage diff --git a/megamek/src/megamek/common/weapons/CLIATMHandler.java b/megamek/src/megamek/common/weapons/CLIATMHandler.java index c3cb84b9a79..491dfe697c4 100644 --- a/megamek/src/megamek/common/weapons/CLIATMHandler.java +++ b/megamek/src/megamek/common/weapons/CLIATMHandler.java @@ -34,7 +34,7 @@ public class CLIATMHandler extends ATMHandler { public CLIATMHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - isAngelECMAffected = ComputeECM.isAffectedByAngelECM(ae, ae.getPosition(), target.getPosition()); + isAngelECMAffected = ComputeECM.isAffectedByAngelECM(attackerEntity, attackerEntity.getPosition(), target.getPosition()); } @Override @@ -42,16 +42,16 @@ protected int calcDamagePerHit() { double toReturn; AmmoType atype = (AmmoType) ammo.getType(); if (atype.getMunitionType().contains(AmmoType.Munitions.M_HIGH_EXPLOSIVE)) { - sSalvoType = " high-explosive missile(s) "; + salvoType = " high-explosive missile(s) "; toReturn = 3; } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_EXTENDED_RANGE)) { - sSalvoType = " extended-range missile(s) "; + salvoType = " extended-range missile(s) "; toReturn = 1; } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_IATM_IMP)) { - sSalvoType = " IMP missile(s) "; + salvoType = " IMP missile(s) "; toReturn = 1; } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_IATM_IIW)) { - sSalvoType = " IIW missile(s) "; + salvoType = " IIW missile(s) "; toReturn = 2; } else { toReturn = 2; @@ -59,10 +59,10 @@ protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage( - wtype.getRackSize(), bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getRackSize(), bDirect ? toHit.getMoS() / 3 : 0, + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); // some question here about "partial streak missiles" if (streakInactive()) { @@ -118,22 +118,22 @@ protected int calcMissileHits(Vector vPhaseReport) { // conventional infantry gets hit in one lump // BAs do one lump of damage per BA suit if (target.isConventionalInfantry()) { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { bSalvo = true; Report r = new Report(3325); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getRackSize() * ((BattleArmor) ae).getShootingStrength()); - r.add(sSalvoType); + r.add(weaponType.getRackSize() * ((BattleArmor) attackerEntity).getShootingStrength()); + r.add(salvoType); r.add(toHit.getTableDesc()); vPhaseReport.add(r); - return ((BattleArmor) ae).getShootingStrength(); + return ((BattleArmor) attackerEntity).getShootingStrength(); } Report r = new Report(3325); r.subject = subjectId; r.newlines = 0; - r.add(wtype.getRackSize()); - r.add(sSalvoType); + r.add(weaponType.getRackSize()); + r.add(salvoType); r.add(toHit.getTableDesc()); vPhaseReport.add(r); return 1; @@ -153,7 +153,7 @@ protected int calcMissileHits(Vector vPhaseReport) { // gets affected by this rule. // However, IMP is done in its own function - i think. Also if we have // the streak system enabled, this is not used - int[] ranges = wtype.getRanges(weapon); + int[] ranges = weaponType.getRanges(weapon); boolean tacopscluster = game.getOptions().booleanOption( OptionsConstants.ADVCOMBAT_TACOPS_CLUSTERHITPEN); @@ -174,7 +174,7 @@ protected int calcMissileHits(Vector vPhaseReport) { // ////// // This applies even with streaks. if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG])) { nMissilesModifier -= 2; } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) @@ -193,7 +193,7 @@ protected int calcMissileHits(Vector vPhaseReport) { // Fusillade doesn't have streak effect, but has the built-in Artemis IV of the // ATM. if (weapon.getType().hasFlag(WeaponType.F_PROTO_WEAPON)) { - if (ComputeECM.isAffectedByECM(ae, ae.getPosition(), target.getPosition())) { + if (ComputeECM.isAffectedByECM(attackerEntity, attackerEntity.getPosition(), target.getPosition())) { Report r = new Report(3330); r.subject = subjectId; r.newlines = 0; @@ -240,17 +240,17 @@ protected int calcMissileHits(Vector vPhaseReport) { if (allShotsHit()) { // We want buildings and large craft to be able to affect this number with AMS // treat as a Streak launcher (cluster roll 11) to make this happen - missilesHit = Compute.missilesHit(wtype.getRackSize(), + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier, weapon.isHotLoaded(), true, isAdvancedAMS()); } else { - if (ae instanceof BattleArmor) { - missilesHit = Compute.missilesHit(wtype.getRackSize() - * ((BattleArmor) ae).getShootingStrength(), + if (attackerEntity instanceof BattleArmor) { + missilesHit = Compute.missilesHit(weaponType.getRackSize() + * ((BattleArmor) attackerEntity).getShootingStrength(), nMissilesModifier, weapon.isHotLoaded(), false, isAdvancedAMS()); } else { - missilesHit = Compute.missilesHit(wtype.getRackSize(), + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier, weapon.isHotLoaded(), false, isAdvancedAMS()); } @@ -260,7 +260,7 @@ protected int calcMissileHits(Vector vPhaseReport) { Report r = new Report(3325); r.subject = subjectId; r.add(missilesHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); @@ -299,7 +299,7 @@ protected boolean specialResolution(Vector vPhaseReport, Entity entityTa ArrayList mfRemoved = new ArrayList<>(); while (minefields.hasMoreElements()) { Minefield mf = minefields.nextElement(); - if (gameManager.clearMinefield(mf, ae, Minefield.CLEAR_NUMBER_WEAPON, vPhaseReport)) { + if (gameManager.clearMinefield(mf, attackerEntity, Minefield.CLEAR_NUMBER_WEAPON, vPhaseReport)) { mfRemoved.add(mf); } } @@ -352,12 +352,12 @@ protected void useAmmo() { System.out.println("Handler can't find any ammo! Oh no!"); } if (ammo.getUsableShotsLeft() <= 0) { - ae.loadWeaponWithSameAmmo(weapon); + attackerEntity.loadWeaponWithSameAmmo(weapon); ammo = weapon.getLinked(); } if (roll.getIntValue() >= toHit.getValue()) { ammo.setShotsLeft(ammo.getBaseShotsLeft() - 1); - if (wtype.hasFlag(WeaponType.F_ONESHOT)) { + if (weaponType.hasFlag(WeaponType.F_ONESHOT)) { weapon.setFired(true); } setDone(); @@ -421,14 +421,14 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (!cares(phase)) { return true; } - sSalvoType = " IIW missile(s) "; + salvoType = " IIW missile(s) "; Entity entityTarget = (target.getTargetType() == Targetable.TYPE_ENTITY) ? (Entity) target : null; final boolean targetInBuilding = Compute.isInBuilding(game, entityTarget); final boolean bldgDamagedOnMiss = targetInBuilding && !(target instanceof Infantry) - && ae.getPosition().distance(target.getPosition()) <= 1; + && attackerEntity.getPosition().distance(target.getPosition()) <= 1; // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); @@ -438,7 +438,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + " (" + atype.getShortName() + ")"); + r.add(weaponType.getName() + " (" + atype.getShortName() + ")"); if (entityTarget != null) { r.addDesc(entityTarget); } else { @@ -493,7 +493,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && ((toHit.getMoS() / 3) >= 1) && (entityTarget != null); if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -531,7 +531,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (!bMissed) { // light inferno missiles all at once, if not missed - vPhaseReport.addAll(gameManager.deliverInfernoMissiles(ae, target, + vPhaseReport.addAll(gameManager.deliverInfernoMissiles(attackerEntity, target, hits, weapon.getCalledShot().getCall())); } return false; @@ -545,23 +545,23 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { entityTarget); final boolean bldgDamagedOnMiss = targetInBuilding && !(target instanceof Infantry) - && ae.getPosition().distance(target.getPosition()) <= 1; + && attackerEntity.getPosition().distance(target.getPosition()) <= 1; boolean bNemesisConfusable = isNemesisConfusable(); if (entityTarget != null) { - ae.setLastTarget(entityTarget.getId()); - ae.setLastTargetDisplayName(entityTarget.getDisplayName()); + attackerEntity.setLastTarget(entityTarget.getId()); + attackerEntity.setLastTargetDisplayName(entityTarget.getDisplayName()); } // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); - String number = nweapons > 1 ? " (" + nweapons + ")" : ""; + String number = numberOfWeapons > 1 ? " (" + numberOfWeapons + ")" : ""; // Report weapon attack and its to-hit value. Report r = new Report(3115); r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + number); + r.add(weaponType.getName() + number); if (entityTarget != null) { r.addDesc(entityTarget); } else { @@ -571,9 +571,9 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { vPhaseReport.addElement(r); // check for nemesis boolean shotAtNemesisTarget = false; - if (bNemesisConfusable && !waa.isNemesisConfused()) { + if (bNemesisConfusable && !weaponAttackAction.isNemesisConfused()) { // loop through nemesis targets - for (Enumeration e = game.getNemesisTargets(ae, + for (Enumeration e = game.getNemesisTargets(attackerEntity, target.getPosition()); e.hasMoreElements();) { Entity entity = e.nextElement(); // friendly unit with attached iNarc Nemesis pod standing in @@ -584,9 +584,9 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { vPhaseReport.addElement(r); weapon.setUsedThisRound(false); WeaponAttackAction newWaa = new WeaponAttackAction( - ae.getId(), entity.getId(), waa.getWeaponId()); + attackerEntity.getId(), entity.getId(), weaponAttackAction.getWeaponId()); newWaa.setNemesisConfused(true); - Mounted m = ae.getEquipment(waa.getWeaponId()); + Mounted m = attackerEntity.getEquipment(weaponAttackAction.getWeaponId()); Weapon w = (Weapon) m.getType(); AttackHandler ah = w.fire(newWaa, game, gameManager); // increase ammo by one, because we just incorrectly used @@ -663,7 +663,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && ((toHit.getMoS() / 3) >= 1) && (entityTarget != null); if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -720,20 +720,20 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { nDamPerHit = 1; hits = attackValue; } else { - if (ae.isCapitalFighter()) { + if (attackerEntity.isCapitalFighter()) { bSalvo = true; - if (nweapons > 1) { - nweaponsHit = Compute.missilesHit(nweapons, - ((Aero) ae).getClusterMods()); + if (numberOfWeapons > 1) { + numberOfWeaponHits = Compute.missilesHit(numberOfWeapons, + ((Aero) attackerEntity).getClusterMods()); r = new Report(3325); r.subject = subjectId; - r.add(nweaponsHit); + r.add(numberOfWeaponHits); r.add(" weapon(s) "); r.add(" "); r.newlines = 0; vPhaseReport.add(r); } - nDamPerHit = attackValue * nweaponsHit; + nDamPerHit = attackValue * numberOfWeaponHits; hits = 1; nCluster = 1; } else { @@ -763,8 +763,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && (toHit.getThruBldg() != null) && (entityTarget instanceof Infantry)) { // If elevation is the same, building doesn't absorb - if (ae.getElevation() != entityTarget.getElevation()) { - int dmgClass = wtype.getInfantryDamageClass(); + if (attackerEntity.getElevation() != entityTarget.getElevation()) { + int dmgClass = weaponType.getInfantryDamageClass(); int nDamage; if (dmgClass < WeaponType.WEAPON_BURST_1D6) { nDamage = nDamPerHit * Math.min(nCluster, hits); @@ -773,7 +773,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { // absorbed damage shouldn't reduce incoming damage, // since the incoming damage was reduced in // Compute.directBlowInfantryDamage - nDamage = -wtype.getDamage(nRange) + nDamage = -weaponType.getDamage(nRange) * Math.min(nCluster, hits); } bldgAbsorbs = (int) Math.round(nDamage @@ -818,7 +818,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (entityTarget != null) { handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - gameManager.creditKill(entityTarget, ae); + gameManager.creditKill(entityTarget, attackerEntity); hits -= nCluster; firstHit = false; // do IMP stuff here! diff --git a/megamek/src/megamek/common/weapons/CLLBXPrototypeHandler.java b/megamek/src/megamek/common/weapons/CLLBXPrototypeHandler.java index 02df71a799e..c508b3ab145 100644 --- a/megamek/src/megamek/common/weapons/CLLBXPrototypeHandler.java +++ b/megamek/src/megamek/common/weapons/CLLBXPrototypeHandler.java @@ -41,7 +41,7 @@ public CLLBXPrototypeHandler(ToHitData t, WeaponAttackAction w, Game g, /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcHits(Vector * vPhaseReport) */ @@ -57,26 +57,26 @@ protected int calcHits(Vector vPhaseReport) { int nHitsModifier = getClusterModifiers(true); if (allShotsHit()) { - shotsHit = wtype.getRackSize(); + shotsHit = weaponType.getRackSize(); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG])) { shotsHit = (int) Math.ceil(shotsHit * .75); } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { shotsHit = (int) Math.ceil(shotsHit * .5); - } + } } else { // flat modifier of -1, because of prototype nHitsModifier -= 1; PlanetaryConditions conditions = game.getPlanetaryConditions(); - shotsHit = Compute.missilesHit(wtype.getRackSize(), nHitsModifier, conditions.getEMI().isEMI()); + shotsHit = Compute.missilesHit(weaponType.getRackSize(), nHitsModifier, conditions.getEMI().isEMI()); } Report r = new Report(3325); r.subject = subjectId; r.add(shotsHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); diff --git a/megamek/src/megamek/common/weapons/CapitalMissileBayHandler.java b/megamek/src/megamek/common/weapons/CapitalMissileBayHandler.java index 509f4b48153..43bdf0dc161 100644 --- a/megamek/src/megamek/common/weapons/CapitalMissileBayHandler.java +++ b/megamek/src/megamek/common/weapons/CapitalMissileBayHandler.java @@ -63,21 +63,21 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { : null; if (entityTarget != null) { - ae.setLastTarget(entityTarget.getId()); - ae.setLastTargetDisplayName(entityTarget.getDisplayName()); + attackerEntity.setLastTarget(entityTarget.getId()); + attackerEntity.setLastTargetDisplayName(entityTarget.getDisplayName()); } // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); - String number = nweapons > 1 ? " (" + nweapons + ")" : ""; + String number = numberOfWeapons > 1 ? " (" + numberOfWeapons + ")" : ""; for (int i = numAttacks; i > 0; i--) { // Report weapon attack and its to-hit value. Report r = new Report(3115); r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + number); + r.add(weaponType.getName() + number); if (entityTarget != null) { - if ((wtype.getAmmoType() != AmmoType.T_NA) + if ((weaponType.getAmmoType() != AmmoType.T_NA) && (weapon.getLinked() != null) && (weapon.getLinked().getType() instanceof AmmoType)) { AmmoType atype = (AmmoType) weapon.getLinked().getType(); @@ -177,7 +177,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -217,7 +217,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { int id = vPhaseReport.size(); int hits = calcHits(vPhaseReport); - if (target.isAirborne() || game.getBoard().inSpace() || ae.usesWeaponBays()) { + if (target.isAirborne() || game.getBoard().inSpace() || attackerEntity.usesWeaponBays()) { // if we added a line to the phase report for calc hits, remove // it now while (vPhaseReport.size() > id) { @@ -254,7 +254,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (!bMissed && (entityTarget != null)) { handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - gameManager.creditKill(entityTarget, ae); + gameManager.creditKill(entityTarget, attackerEntity); } else if (!bMissed) { // Hex is targeted, need to report a hit r = new Report(3390); r.subject = subjectId; @@ -272,21 +272,21 @@ protected int calcAttackValue() { double counterAV = calcCounterAV(); int armor = 0; int weaponarmor = 0; - int range = RangeType.rangeBracket(nRange, wtype.getATRanges(), true, false); + int range = RangeType.rangeBracket(nRange, weaponType.getATRanges(), true, false); for (WeaponMounted bayW : weapon.getBayWeapons()) { // check the currently loaded ammo AmmoMounted bayWAmmo = bayW.getLinkedAmmo(); if (null == bayWAmmo || bayWAmmo.getUsableShotsLeft() < 1) { // try loading something else - ae.loadWeaponWithSameAmmo(bayW); + attackerEntity.loadWeaponWithSameAmmo(bayW); bayWAmmo = bayW.getLinkedAmmo(); } if (!bayW.isBreached() && !bayW.isDestroyed() && !bayW.isJammed() && bayWAmmo != null - && ae.getTotalAmmoOfType(bayWAmmo.getType()) >= bayW.getCurrentShots()) { + && attackerEntity.getTotalAmmoOfType(bayWAmmo.getType()) >= bayW.getCurrentShots()) { WeaponType bayWType = ((WeaponType) bayW.getType()); // need to cycle through weapons and add av double current_av = 0; @@ -331,7 +331,7 @@ protected int calcAttackValue() { if (null == bayWAmmo || bayWAmmo.getUsableShotsLeft() < 1) { // try loading something else - ae.loadWeaponWithSameAmmo(bayW); + attackerEntity.loadWeaponWithSameAmmo(bayW); bayWAmmo = bayW.getLinkedAmmo(); } if (null != bayWAmmo) { @@ -482,9 +482,9 @@ protected void insertAttacks(GamePhase phase, Vector vPhaseReport) { } for (int wId : insertedAttacks) { - Mounted bayW = ae.getEquipment(wId); - WeaponAttackAction newWaa = new WeaponAttackAction(ae.getId(), - waa.getTargetId(), wId); + Mounted bayW = attackerEntity.getEquipment(wId); + WeaponAttackAction newWaa = new WeaponAttackAction(attackerEntity.getId(), + weaponAttackAction.getTargetId(), wId); Weapon w = (Weapon) bayW.getType(); // increase ammo by one, we'll use one that we shouldn't use // in the next line @@ -539,11 +539,11 @@ public boolean handleAeroSanity(GamePhase phase, Vector vPhaseReport) { entityTarget); final boolean bldgDamagedOnMiss = targetInBuilding && !(target instanceof Infantry) - && ae.getPosition().distance(target.getPosition()) <= 1; + && attackerEntity.getPosition().distance(target.getPosition()) <= 1; if (entityTarget != null) { - ae.setLastTarget(entityTarget.getId()); - ae.setLastTargetDisplayName(entityTarget.getDisplayName()); + attackerEntity.setLastTarget(entityTarget.getId()); + attackerEntity.setLastTargetDisplayName(entityTarget.getDisplayName()); } // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); @@ -552,9 +552,9 @@ public boolean handleAeroSanity(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName()); + r.add(weaponType.getName()); if (entityTarget != null) { - if ((wtype.getAmmoType() != AmmoType.T_NA) + if ((weaponType.getAmmoType() != AmmoType.T_NA) && (weapon.getLinked() != null) && (weapon.getLinked().getType() instanceof AmmoType)) { AmmoType atype = (AmmoType) weapon.getLinked().getType(); @@ -658,7 +658,7 @@ public boolean handleAeroSanity(GamePhase phase, Vector vPhaseReport) { if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -719,8 +719,8 @@ public boolean handleAeroSanity(GamePhase phase, Vector vPhaseReport) { WeaponType bayWType = ((WeaponType) m.getType()); if (bayWType instanceof Weapon) { replaceReport = vPhaseReport.size(); - WeaponAttackAction bayWaa = new WeaponAttackAction(waa.getEntityId(), waa.getTargetType(), - waa.getTargetId(), m.getEquipmentNum()); + WeaponAttackAction bayWaa = new WeaponAttackAction(weaponAttackAction.getEntityId(), weaponAttackAction.getTargetType(), + weaponAttackAction.getTargetId(), m.getEquipmentNum()); AttackHandler bayWHandler = ((Weapon) bayWType).getCorrectHandler(autoHit, bayWaa, game, gameManager); bayWHandler.setAnnouncedEntityFiring(false); diff --git a/megamek/src/megamek/common/weapons/CapitalMissileBearingsOnlyHandler.java b/megamek/src/megamek/common/weapons/CapitalMissileBearingsOnlyHandler.java index 10b88deebf9..8864db33e80 100644 --- a/megamek/src/megamek/common/weapons/CapitalMissileBearingsOnlyHandler.java +++ b/megamek/src/megamek/common/weapons/CapitalMissileBearingsOnlyHandler.java @@ -88,7 +88,7 @@ protected void useAmmo() { for (int i = 0; i < shots; i++) { if ((null == bayWAmmo) || bayWAmmo.getUsableShotsLeft() < 1) { // try loading something else - ae.loadWeaponWithSameAmmo(bayW); + attackerEntity.loadWeaponWithSameAmmo(bayW); bayWAmmo = bayW.getLinkedAmmo(); } if (null != bayWAmmo) { @@ -102,7 +102,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (!cares(phase)) { return true; } - ArtilleryAttackAction aaa = (ArtilleryAttackAction) waa; + ArtilleryAttackAction aaa = (ArtilleryAttackAction) weaponAttackAction; if (phase.isTargeting()) { if (!handledAmmoAndReport) { addHeat(); @@ -111,7 +111,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName()); + r.add(weaponType.getName()); r.add(aaa.getTurnsTilHit()); vPhaseReport.addElement(r); Report.addNewline(vPhaseReport); @@ -241,7 +241,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -294,8 +294,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { WeaponType bayWType = m.getType(); if (bayWType instanceof Weapon) { replaceReport = vPhaseReport.size(); - WeaponAttackAction bayWaa = new WeaponAttackAction(waa.getEntityId(), waa.getTargetType(), - waa.getTargetId(), bayWAmmo.getEquipmentNum()); + WeaponAttackAction bayWaa = new WeaponAttackAction(weaponAttackAction.getEntityId(), weaponAttackAction.getTargetType(), + weaponAttackAction.getTargetId(), bayWAmmo.getEquipmentNum()); AttackHandler bayWHandler = ((Weapon) bayWType).getCorrectHandler(autoHit, bayWaa, game, gameManager); bayWHandler.setAnnouncedEntityFiring(false); @@ -346,7 +346,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { toHit.setSideTable(entityTarget.sideTable(aaa.getOldTargetCoords())); } } - if (target.isAirborne() || game.getBoard().inSpace() || ae.usesWeaponBays()) { + if (target.isAirborne() || game.getBoard().inSpace() || attackerEntity.usesWeaponBays()) { // if we added a line to the phase report for calc hits, remove // it now while (vPhaseReport.size() > id) { @@ -383,7 +383,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { } if (!bMissed && (entityTarget != null)) { handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - gameManager.creditKill(entityTarget, ae); + gameManager.creditKill(entityTarget, attackerEntity); } else if (!bMissed) { // Hex is targeted, need to report a hit r = new Report(3390); r.subject = subjectId; @@ -400,7 +400,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { * small craft. */ public void convertHexTargetToEntityTarget(Vector vPhaseReport) { - ArtilleryAttackAction aaa = (ArtilleryAttackAction) waa; + ArtilleryAttackAction aaa = (ArtilleryAttackAction) weaponAttackAction; final Coords tc = target.getPosition(); targetCoords = tc; @@ -409,12 +409,12 @@ public void convertHexTargetToEntityTarget(Vector vPhaseReport) { aaa.setOldTargetCoords(tc); aaa.setOriginalTargetId(target.getId()); aaa.setOriginalTargetType(target.getTargetType()); - int missileFacing = ae.getPosition().direction(tc); + int missileFacing = attackerEntity.getPosition().direction(tc); Targetable newTarget = null; Vector targets = new Vector<>(); // get all entities on the opposing side - for (Iterator enemies = game.getAllEnemyEntities(ae); enemies.hasNext();) { + for (Iterator enemies = game.getAllEnemyEntities(attackerEntity); enemies.hasNext();) { Entity e = enemies.next(); // Narrow the list to small craft and larger if (((e.getEntityType() & (Entity.ETYPE_SMALL_CRAFT)) != 0)) { @@ -498,7 +498,7 @@ public void convertHexTargetToEntityTarget(Vector vPhaseReport) { targetIds.add(target.getId()); toHitValues.add(toHit.getValue()); } - int choice = gameManager.processTeleguidedMissileCFR(ae.getOwnerId(), targetIds, toHitValues); + int choice = gameManager.processTeleguidedMissileCFR(attackerEntity.getOwnerId(), targetIds, toHitValues); newTarget = targets.get(choice); target = newTarget; aaa.setTargetId(target.getId()); @@ -649,7 +649,7 @@ private void setToHit(Targetable target) { // Space ECM if (game.getBoard().inSpace() && game.getOptions().booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_ECM)) { - int ecm = ComputeECM.getLargeCraftECM(ae, targetCoords, target.getPosition()); + int ecm = ComputeECM.getLargeCraftECM(attackerEntity, targetCoords, target.getPosition()); ecm = Math.min(4, ecm); if (ecm > 0) { toHit.addModifier(ecm, "ECM"); @@ -707,14 +707,14 @@ protected int calcAttackValue() { AmmoMounted bayWAmmo = bayW.getLinkedAmmo(); if (null == bayWAmmo || bayWAmmo.getUsableShotsLeft() < 1) { // try loading something else - ae.loadWeaponWithSameAmmo(bayW); + attackerEntity.loadWeaponWithSameAmmo(bayW); bayWAmmo = bayW.getLinkedAmmo(); } if (!bayW.isBreached() && !bayW.isDestroyed() && !bayW.isJammed() && bayWAmmo != null - && ae.getTotalAmmoOfType(bayWAmmo.getType()) >= bayW.getCurrentShots()) { + && attackerEntity.getTotalAmmoOfType(bayWAmmo.getType()) >= bayW.getCurrentShots()) { WeaponType bayWType = ((WeaponType) bayW.getType()); // need to cycle through weapons and add av double current_av = 0; @@ -774,7 +774,7 @@ protected int calcAttackValue() { @Override protected int calcDamagePerHit() { AmmoType atype = (AmmoType) ammo.getType(); - double toReturn = wtype.getDamage(nRange); + double toReturn = weaponType.getDamage(nRange); // AR10 munitions if (atype != null) { diff --git a/megamek/src/megamek/common/weapons/CapitalMissileHandler.java b/megamek/src/megamek/common/weapons/CapitalMissileHandler.java index 765f39eeda7..d00dd2980cd 100644 --- a/megamek/src/megamek/common/weapons/CapitalMissileHandler.java +++ b/megamek/src/megamek/common/weapons/CapitalMissileHandler.java @@ -72,21 +72,21 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { : null; if (entityTarget != null) { - ae.setLastTarget(entityTarget.getId()); - ae.setLastTargetDisplayName(entityTarget.getDisplayName()); + attackerEntity.setLastTarget(entityTarget.getId()); + attackerEntity.setLastTargetDisplayName(entityTarget.getDisplayName()); } // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); - String number = nweapons > 1 ? " (" + nweapons + ")" : ""; + String number = numberOfWeapons > 1 ? " (" + numberOfWeapons + ")" : ""; for (int i = numAttacks; i > 0; i--) { // Report weapon attack and its to-hit value. Report r = new Report(3115); r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + number); + r.add(weaponType.getName() + number); if (entityTarget != null) { - if ((wtype.getAmmoType() != AmmoType.T_NA) + if ((weaponType.getAmmoType() != AmmoType.T_NA) && (weapon.getLinked() != null) && (weapon.getLinked().getType() instanceof AmmoType)) { AmmoType atype = (AmmoType) weapon.getLinked().getType(); @@ -210,7 +210,7 @@ && getParentBayHandler() != null) { if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -250,7 +250,7 @@ && getParentBayHandler() != null) { int id = vPhaseReport.size(); int hits = calcHits(vPhaseReport); - if (target.isAirborne() || game.getBoard().inSpace() || ae.usesWeaponBays()) { + if (target.isAirborne() || game.getBoard().inSpace() || attackerEntity.usesWeaponBays()) { // if we added a line to the phase report for calc hits, remove // it now while (vPhaseReport.size() > id) { @@ -311,7 +311,7 @@ && getParentBayHandler() != null) { if (entityTarget != null) { handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - gameManager.creditKill(entityTarget, ae); + gameManager.creditKill(entityTarget, attackerEntity); hits -= nCluster; firstHit = false; } @@ -336,7 +336,7 @@ protected int calcAttackValue() { AmmoType atype = (AmmoType) ammo.getType(); int av = 0; double counterAV = calcCounterAV(); - int armor = wtype.getMissileArmor(); + int armor = weaponType.getMissileArmor(); //AR10 munitions if (atype != null) { if (atype.getAmmoType() == AmmoType.T_AR10) { @@ -357,16 +357,16 @@ protected int calcAttackValue() { armor = 20; } } else { - int range = RangeType.rangeBracket(nRange, wtype.getATRanges(), + int range = RangeType.rangeBracket(nRange, weaponType.getATRanges(), true, false); if (range == WeaponType.RANGE_SHORT) { - av = wtype.getRoundShortAV(); + av = weaponType.getRoundShortAV(); } else if (range == WeaponType.RANGE_MED) { - av = wtype.getRoundMedAV(); + av = weaponType.getRoundMedAV(); } else if (range == WeaponType.RANGE_LONG) { - av = wtype.getRoundLongAV(); + av = weaponType.getRoundLongAV(); } else if (range == WeaponType.RANGE_EXT) { - av = wtype.getRoundExtAV(); + av = weaponType.getRoundExtAV(); } } //Nuclear Warheads for non-AR10 missiles @@ -378,8 +378,8 @@ protected int calcAttackValue() { nukeS2S = atype.hasFlag(AmmoType.F_NUCLEAR); } // For squadrons, total the missile armor for the launched volley - if (ae.isCapitalFighter()) { - armor = armor * nweapons; + if (attackerEntity.isCapitalFighter()) { + armor = armor * numberOfWeapons; } CapMissileArmor = armor - (int) counterAV; CapMissileAMSMod = calcCapMissileAMSMod(); @@ -402,7 +402,7 @@ protected int calcAttackValue() { @Override protected int calcDamagePerHit() { AmmoType atype = (AmmoType) ammo.getType(); - double toReturn = wtype.getDamage(nRange); + double toReturn = weaponType.getDamage(nRange); //AR10 munitions if (atype != null) { diff --git a/megamek/src/megamek/common/weapons/ChemicalLaserHandler.java b/megamek/src/megamek/common/weapons/ChemicalLaserHandler.java index 48292993c0e..a46e1342564 100644 --- a/megamek/src/megamek/common/weapons/ChemicalLaserHandler.java +++ b/megamek/src/megamek/common/weapons/ChemicalLaserHandler.java @@ -46,7 +46,7 @@ public ChemicalLaserHandler(ToHitData toHit, WeaponAttackAction waa, Game g, TWG /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override @@ -55,38 +55,38 @@ protected int calcDamagePerHit() { * ((AmmoType) ammo.getType()).getDamagePerShot(); // during a swarm, all damage gets applied as one block to one location - if ((ae instanceof BattleArmor) + if ((attackerEntity instanceof BattleArmor) && (weapon.getLocation() == BattleArmor.LOC_SQUAD) && !(weapon.isSquadSupportWeapon()) - && (ae.getSwarmTargetId() == target.getId())) { - toReturn *= ((BattleArmor) ae).getShootingStrength(); + && (attackerEntity.getSwarmTargetId() == target.getId())) { + toReturn *= ((BattleArmor) attackerEntity).getShootingStrength(); } // Check for Altered Damage from Energy Weapons (TacOp, pg.83) if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_ALTDMG)) { if (nRange <= 1) { toReturn++; - } else if (nRange <= wtype.getMediumRange()) { + } else if (nRange <= weaponType.getMediumRange()) { // Do Nothing for Short and Medium Range - } else if (nRange <= wtype.getLongRange()) { + } else if (nRange <= weaponType.getLongRange()) { toReturn--; } } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG])) { toReturn -= 1; } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { toReturn = (int) Math.floor(toReturn * .75); - } + } if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage( toReturn, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); } else if (bDirect) { toReturn = Math.min(toReturn + (toHit.getMoS() / 3), toReturn * 2); } diff --git a/megamek/src/megamek/common/weapons/EnergyWeaponHandler.java b/megamek/src/megamek/common/weapons/EnergyWeaponHandler.java index 7cba45a99bc..7436fe92aa2 100644 --- a/megamek/src/megamek/common/weapons/EnergyWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/EnergyWeaponHandler.java @@ -46,55 +46,55 @@ public EnergyWeaponHandler(ToHitData toHit, WeaponAttackAction waa, Game g, TWGa /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override protected int calcDamagePerHit() { - double toReturn = wtype.getDamage(nRange); + double toReturn = weaponType.getDamage(nRange); if ((game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_ENERGY_WEAPONS) - && weapon.hasModes()) || wtype.hasFlag(WeaponType.F_BOMBAST_LASER)) { - toReturn = Compute.dialDownDamage(weapon, wtype, nRange); + && weapon.hasModes()) || weaponType.hasFlag(WeaponType.F_BOMBAST_LASER)) { + toReturn = Compute.dialDownDamage(weapon, weaponType, nRange); } // during a swarm, all damage gets applied as one block to one location - if ((ae instanceof BattleArmor) + if ((attackerEntity instanceof BattleArmor) && (weapon.getLocation() == BattleArmor.LOC_SQUAD) && !(weapon.isSquadSupportWeapon()) - && (ae.getSwarmTargetId() == target.getId())) { - toReturn *= ((BattleArmor) ae).getShootingStrength(); + && (attackerEntity.getSwarmTargetId() == target.getId())) { + toReturn *= ((BattleArmor) attackerEntity).getShootingStrength(); } // Check for Altered Damage from Energy Weapons (TacOp, pg.83) if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_ALTDMG)) { if (nRange <= 1) { toReturn++; - } else if (nRange <= wtype.getMediumRange()) { + } else if (nRange <= weaponType.getMediumRange()) { // Do Nothing for Short and Medium Range - } else if (nRange <= wtype.getLongRange()) { + } else if (nRange <= weaponType.getLongRange()) { toReturn--; } } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG])) { toReturn -= 1; } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { toReturn = (int) Math.floor(toReturn * .75); } - + if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage( toReturn, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); } else if (bDirect) { toReturn = Math.min(toReturn + (toHit.getMoS() / 3), toReturn * 2); } - + toReturn = applyGlancingBlowModifier(toReturn, target.isConventionalInfantry()); return (int) Math.ceil(toReturn); } diff --git a/megamek/src/megamek/common/weapons/FlamerHandler.java b/megamek/src/megamek/common/weapons/FlamerHandler.java index dc6d6aa7a70..6c56529d5e3 100644 --- a/megamek/src/megamek/common/weapons/FlamerHandler.java +++ b/megamek/src/megamek/common/weapons/FlamerHandler.java @@ -36,27 +36,27 @@ public FlamerHandler(ToHitData toHit, WeaponAttackAction waa, Game g, TWGameMana protected void handleEntityDamage(Entity entityTarget, Vector vPhaseReport, Building bldg, int hits, int nCluster, int bldgAbsorbs) { boolean bmmFlamerDamage = game.getOptions().booleanOption(OptionsConstants.BASE_FLAMER_HEAT); - EquipmentMode currentWeaponMode = game.getEntity(waa.getEntityId()).getEquipment(waa.getWeaponId()).curMode(); - + EquipmentMode currentWeaponMode = game.getEntity(weaponAttackAction.getEntityId()).getEquipment(weaponAttackAction.getWeaponId()).curMode(); + boolean flamerDoesHeatOnlyDamage = currentWeaponMode != null && currentWeaponMode.equals(Weapon.MODE_FLAMER_HEAT); boolean flamerDoesOnlyDamage = currentWeaponMode != null && currentWeaponMode.equals(Weapon.MODE_FLAMER_DAMAGE); - + if (bmmFlamerDamage || flamerDoesOnlyDamage || (flamerDoesHeatOnlyDamage && !entityTarget.tracksHeat())) { super.handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - + if (bmmFlamerDamage && entityTarget.tracksHeat() && !entityTarget.removePartialCoverHits(hit.getLocation(), toHit.getCover(), - Compute.targetSideTable(ae, entityTarget, weapon.getCalledShot().getCall()))) { - FlamerHandlerHelper.doHeatDamage(entityTarget, vPhaseReport, wtype, subjectId, hit); + Compute.targetSideTable(attackerEntity, entityTarget, weapon.getCalledShot().getCall()))) { + FlamerHandlerHelper.doHeatDamage(entityTarget, vPhaseReport, weaponType, subjectId, hit); } } else if (flamerDoesHeatOnlyDamage) { hit = entityTarget.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setAttackerId(getAttackerId()); if (entityTarget.removePartialCoverHits(hit.getLocation(), toHit.getCover(), - Compute.targetSideTable(ae, entityTarget, weapon.getCalledShot().getCall()))) { + Compute.targetSideTable(attackerEntity, entityTarget, weapon.getCalledShot().getCall()))) { // Weapon strikes Partial Cover. handlePartialCoverHit(entityTarget, vPhaseReport, hit, bldg, hits, nCluster, bldgAbsorbs); return; @@ -66,8 +66,8 @@ protected void handleEntityDamage(Entity entityTarget, Vector vPhaseRepo r.add(toHit.getTableDesc()); r.add(entityTarget.getLocationAbbr(hit)); vPhaseReport.addElement(r); - - FlamerHandlerHelper.doHeatDamage(entityTarget, vPhaseReport, wtype, subjectId, hit); + + FlamerHandlerHelper.doHeatDamage(entityTarget, vPhaseReport, weaponType, subjectId, hit); } } @@ -94,7 +94,7 @@ protected void handleIgnitionDamage(Vector vPhaseReport, Building bldg, r.newlines = 0; vPhaseReport.addElement(r); } - TargetRoll tn = new TargetRoll(wtype.getFireTN(), wtype.getName()); + TargetRoll tn = new TargetRoll(weaponType.getFireTN(), weaponType.getName()); if (tn.getValue() != TargetRoll.IMPOSSIBLE) { Report.addNewline(vPhaseReport); gameManager.tryIgniteHex(target.getPosition(), subjectId, true, false, @@ -126,7 +126,7 @@ protected void handleClearDamage(Vector vPhaseReport, Building bldg, int if ((bldg != null) && gameManager.tryIgniteHex(target.getPosition(), subjectId, true, false, - new TargetRoll(wtype.getFireTN(), wtype.getName()), 5, + new TargetRoll(weaponType.getFireTN(), weaponType.getName()), 5, vPhaseReport)) { return; } @@ -136,4 +136,4 @@ protected void handleClearDamage(Vector vPhaseReport, Building bldg, int } vPhaseReport.addAll(clearReports); } -} \ No newline at end of file +} diff --git a/megamek/src/megamek/common/weapons/GRHandler.java b/megamek/src/megamek/common/weapons/GRHandler.java index 160de537d53..e38ac4aa968 100644 --- a/megamek/src/megamek/common/weapons/GRHandler.java +++ b/megamek/src/megamek/common/weapons/GRHandler.java @@ -41,32 +41,32 @@ public GRHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override protected int calcDamagePerHit() { - double toReturn = wtype.getDamage(nRange); + double toReturn = weaponType.getDamage(nRange); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG]) { + && nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG]) { toReturn -= 1; } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { toReturn = (int) Math.floor(toReturn * .75); } if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage( toReturn, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); } else if (bDirect) { toReturn = Math.min(toReturn + (toHit.getMoS() / 3.0), toReturn * 2); } - + toReturn = applyGlancingBlowModifier(toReturn, false); return (int) Math.ceil(toReturn); } diff --git a/megamek/src/megamek/common/weapons/HAGWeaponHandler.java b/megamek/src/megamek/common/weapons/HAGWeaponHandler.java index 9186c26bf47..59f27393781 100644 --- a/megamek/src/megamek/common/weapons/HAGWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/HAGWeaponHandler.java @@ -37,12 +37,12 @@ public class HAGWeaponHandler extends AmmoWeaponHandler { */ public HAGWeaponHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " projectiles "; + salvoType = " projectiles "; } /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcnCluster() */ @Override @@ -52,18 +52,18 @@ protected int calcnCluster() { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { - double toReturn = wtype.getRackSize(); + double toReturn = weaponType.getRackSize(); toReturn = Compute.directBlowInfantryDamage( toReturn, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); toReturn = applyGlancingBlowModifier(toReturn, true); return (int) toReturn; } @@ -72,7 +72,7 @@ protected int calcDamagePerHit() { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcHits(java.util.Vector) */ @Override @@ -84,21 +84,21 @@ protected int calcHits(Vector vPhaseReport) { } int nHits; int nHitsModifier = getClusterModifiers(true); - if (nRange <= wtype.getShortRange()) { + if (nRange <= weaponType.getShortRange()) { nHitsModifier += 2; - } else if (nRange > wtype.getMediumRange()) { + } else if (nRange > weaponType.getMediumRange()) { nHitsModifier -= 2; } if (allShotsHit()) { - nHits = wtype.getRackSize(); + nHits = weaponType.getRackSize(); } else { - nHits = Compute.missilesHit(wtype.getRackSize(), nHitsModifier); + nHits = Compute.missilesHit(weaponType.getRackSize(), nHitsModifier); } Report r = new Report(3325); r.subject = subjectId; r.add(nHits); - r.add(sSalvoType); + r.add(salvoType); r.newlines = 0; r.add(toHit.getTableDesc()); vPhaseReport.addElement(r); diff --git a/megamek/src/megamek/common/weapons/HGRHandler.java b/megamek/src/megamek/common/weapons/HGRHandler.java index db0a6bcdef4..003511bad43 100644 --- a/megamek/src/megamek/common/weapons/HGRHandler.java +++ b/megamek/src/megamek/common/weapons/HGRHandler.java @@ -47,21 +47,21 @@ protected boolean doChecks(Vector vPhaseReport) { return true; } - if ((ae.mpUsed > 0) && (ae instanceof Mek) && ae.canFall() + if ((attackerEntity.mpUsed > 0) && (attackerEntity instanceof Mek) && attackerEntity.canFall() // Only check up to assault class, superheavies do not roll. - && ae.getWeightClass() <= EntityWeightClass.WEIGHT_ASSAULT) { + && attackerEntity.getWeightClass() <= EntityWeightClass.WEIGHT_ASSAULT) { // Modifier is weight-based. int nMod; - if (ae.getWeightClass() <= EntityWeightClass.WEIGHT_LIGHT) { + if (attackerEntity.getWeightClass() <= EntityWeightClass.WEIGHT_LIGHT) { nMod = 2; - } else if (ae.getWeightClass() <= EntityWeightClass.WEIGHT_MEDIUM) { + } else if (attackerEntity.getWeightClass() <= EntityWeightClass.WEIGHT_MEDIUM) { nMod = 1; - } else if (ae.getWeightClass() <= EntityWeightClass.WEIGHT_HEAVY) { + } else if (attackerEntity.getWeightClass() <= EntityWeightClass.WEIGHT_HEAVY) { nMod = 0; } else { nMod = -1; } - PilotingRollData psr = new PilotingRollData(ae.getId(), nMod, + PilotingRollData psr = new PilotingRollData(attackerEntity.getId(), nMod, "fired HeavyGauss unbraced", false); game.addPSR(psr); } diff --git a/megamek/src/megamek/common/weapons/HVACWeaponHandler.java b/megamek/src/megamek/common/weapons/HVACWeaponHandler.java index 302f77fab9d..2227bb89a2d 100644 --- a/megamek/src/megamek/common/weapons/HVACWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/HVACWeaponHandler.java @@ -46,8 +46,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { PlanetaryConditions conditions = game.getPlanetaryConditions(); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_START_FIRE) && !conditions.getAtmosphere().isVacuum()) { - int rear = (ae.getFacing() + 3 + (weapon.isMekTurretMounted() ? weapon.getFacing() : 0)) % 6; - Coords src = ae.getPosition(); + int rear = (attackerEntity.getFacing() + 3 + (weapon.isMekTurretMounted() ? weapon.getFacing() : 0)) % 6; + Coords src = attackerEntity.getPosition(); Coords rearCoords = src.translated(rear); Board board = game.getBoard(); Hex currentHex = board.getHex(src); @@ -75,25 +75,25 @@ protected boolean doChecks(Vector vPhaseReport) { return true; } - if ((roll.getIntValue() == 2) && !ae.isConventionalInfantry()) { + if ((roll.getIntValue() == 2) && !attackerEntity.isConventionalInfantry()) { Report r = new Report(3162); r.subject = subjectId; weapon.setJammed(true); weapon.setHit(true); int wloc = weapon.getLocation(); - for (int i = 0; i < ae.getNumberOfCriticals(wloc); i++) { - CriticalSlot slot1 = ae.getCritical(wloc, i); + for (int i = 0; i < attackerEntity.getNumberOfCriticals(wloc); i++) { + CriticalSlot slot1 = attackerEntity.getCritical(wloc, i); if ((slot1 == null) || (slot1.getType() == CriticalSlot.TYPE_SYSTEM)) { continue; } Mounted mounted = slot1.getMount(); if (mounted.equals(weapon)) { - ae.hitAllCriticals(wloc, i); + attackerEntity.hitAllCriticals(wloc, i); break; } } - vPhaseReport.addAll(gameManager.explodeEquipment(ae, wloc, weapon)); + vPhaseReport.addAll(gameManager.explodeEquipment(attackerEntity, wloc, weapon)); r.choose(false); vPhaseReport.addElement(r); return true; diff --git a/megamek/src/megamek/common/weapons/HyperLaserHandler.java b/megamek/src/megamek/common/weapons/HyperLaserHandler.java index 7a8a1ae0a8d..84930dffcf5 100644 --- a/megamek/src/megamek/common/weapons/HyperLaserHandler.java +++ b/megamek/src/megamek/common/weapons/HyperLaserHandler.java @@ -55,21 +55,21 @@ protected boolean doChecks(Vector vPhaseReport) { r.newlines = 1; weapon.setHit(true); int wloc = weapon.getLocation(); - for (int i = 0; i < ae.getNumberOfCriticals(wloc); i++) { - CriticalSlot slot1 = ae.getCritical(wloc, i); + for (int i = 0; i < attackerEntity.getNumberOfCriticals(wloc); i++) { + CriticalSlot slot1 = attackerEntity.getCritical(wloc, i); if ((slot1 == null) || (slot1.getType() == CriticalSlot.TYPE_SYSTEM)) { continue; } Mounted mounted = slot1.getMount(); if (mounted.equals(weapon)) { - ae.hitAllCriticals(wloc, i); + attackerEntity.hitAllCriticals(wloc, i); break; } } r.choose(false); vPhaseReport.addElement(r); - vPhaseReport.addAll(gameManager.explodeEquipment(ae, wloc, weapon)); + vPhaseReport.addAll(gameManager.explodeEquipment(attackerEntity, wloc, weapon)); return true; } return false; @@ -82,21 +82,21 @@ protected boolean doChecks(Vector vPhaseReport) { */ @Override protected int calcDamagePerHit() { - int[] nRanges = wtype.getRanges(weapon); - double toReturn = wtype.getDamage(nRange); + int[] nRanges = weaponType.getRanges(weapon); + double toReturn = weaponType.getDamage(nRange); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_ENERGY_WEAPONS) && weapon.hasModes()) { - toReturn = Compute.dialDownDamage(weapon, wtype, nRange); + toReturn = Compute.dialDownDamage(weapon, weaponType, nRange); } // Check for Altered Damage from Energy Weapons (TacOp, pg.83) if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_ALTDMG)) { if (nRange <= 1) { toReturn++; - } else if (nRange <= wtype.getMediumRange()) { + } else if (nRange <= weaponType.getMediumRange()) { // Do Nothing for Short and Medium Range - } else if (nRange <= wtype.getLongRange()) { + } else if (nRange <= weaponType.getLongRange()) { toReturn--; } } @@ -104,9 +104,9 @@ protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage(toReturn, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); if (nRange <= nRanges[RangeType.RANGE_SHORT]) { toReturn += 3; } else if (nRange <= nRanges[RangeType.RANGE_MEDIUM]) { diff --git a/megamek/src/megamek/common/weapons/LBXHandler.java b/megamek/src/megamek/common/weapons/LBXHandler.java index d48cb20fafe..75ec5297668 100644 --- a/megamek/src/megamek/common/weapons/LBXHandler.java +++ b/megamek/src/megamek/common/weapons/LBXHandler.java @@ -36,7 +36,7 @@ public class LBXHandler extends AmmoWeaponHandler { */ public LBXHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " pellet(s) "; + salvoType = " pellet(s) "; } /* @@ -48,10 +48,10 @@ public LBXHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { double toReturn = Compute.directBlowInfantryDamage( - wtype.getDamage(), bDirect ? toHit.getMoS() / 3 : 0, + weaponType.getDamage(), bDirect ? toHit.getMoS() / 3 : 0, WeaponType.WEAPON_CLUSTER_BALLISTIC, ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); toReturn = applyGlancingBlowModifier(toReturn, true); return (int) toReturn; } @@ -91,24 +91,24 @@ protected int calcHits(Vector vPhaseReport) { int nHitsModifier = getClusterModifiers(true); if (allShotsHit()) { - shotsHit = wtype.getRackSize(); + shotsHit = weaponType.getRackSize(); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG])) { shotsHit = (int) Math.ceil(shotsHit * .75); } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { shotsHit = (int) Math.ceil(shotsHit * .5); } } else { PlanetaryConditions conditions = game.getPlanetaryConditions(); - shotsHit = Compute.missilesHit(wtype.getRackSize(), nHitsModifier, conditions.getEMI().isEMI()); + shotsHit = Compute.missilesHit(weaponType.getRackSize(), nHitsModifier, conditions.getEMI().isEMI()); } Report r = new Report(3325); r.subject = subjectId; r.add(shotsHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); diff --git a/megamek/src/megamek/common/weapons/LRMAntiTSMHandler.java b/megamek/src/megamek/common/weapons/LRMAntiTSMHandler.java index 927bfe6c53f..16bb7176561 100644 --- a/megamek/src/megamek/common/weapons/LRMAntiTSMHandler.java +++ b/megamek/src/megamek/common/weapons/LRMAntiTSMHandler.java @@ -36,7 +36,7 @@ public class LRMAntiTSMHandler extends LRMSmokeWarheadHandler { public LRMAntiTSMHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " anti-TSM missile(s) "; + salvoType = " anti-TSM missile(s) "; damageType = DamageType.ANTI_TSM; } @@ -45,9 +45,9 @@ protected int calcHits(Vector vPhaseReport) { // conventional infantry gets hit in one lump // BAs do one lump of damage per BA suit if (target.isConventionalInfantry()) { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { bSalvo = true; - return ((BattleArmor) ae).getShootingStrength(); + return ((BattleArmor) attackerEntity).getShootingStrength(); } return 1; } @@ -55,8 +55,8 @@ protected int calcHits(Vector vPhaseReport) { int nMissilesModifier = getClusterModifiers(false); boolean bMekTankStealthActive = false; - if ((ae instanceof Mek) || (ae instanceof Tank)) { - bMekTankStealthActive = ae.isStealthActive(); + if ((attackerEntity instanceof Mek) || (attackerEntity instanceof Tank)) { + bMekTankStealthActive = attackerEntity.isStealthActive(); } // AMS mod @@ -73,19 +73,19 @@ protected int calcHits(Vector vPhaseReport) { if (allShotsHit()) { // We want buildings and large craft to be able to affect this number with AMS // treat as a Streak launcher (cluster roll 11) to make this happen - missilesHit = Compute.missilesHit(wtype.getRackSize(), + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier, weapon.isHotLoaded(), true, isAdvancedAMS()); } else { // anti tsm hit with half the normal number, round up - missilesHit = Compute.missilesHit(wtype.getRackSize(), + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier, weapon.isHotLoaded(), false, isAdvancedAMS()); missilesHit = (int) Math.ceil((double) missilesHit / 2); } Report r = new Report(3325); r.subject = subjectId; r.add(missilesHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); diff --git a/megamek/src/megamek/common/weapons/LRMDeadFireHandler.java b/megamek/src/megamek/common/weapons/LRMDeadFireHandler.java index 310a35fa802..babeecf72b1 100644 --- a/megamek/src/megamek/common/weapons/LRMDeadFireHandler.java +++ b/megamek/src/megamek/common/weapons/LRMDeadFireHandler.java @@ -37,7 +37,7 @@ public class LRMDeadFireHandler extends LRMHandler { public LRMDeadFireHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " dead fire missile(s) "; + salvoType = " dead fire missile(s) "; } @Override diff --git a/megamek/src/megamek/common/weapons/LRMFollowTheLeaderHandler.java b/megamek/src/megamek/common/weapons/LRMFollowTheLeaderHandler.java index 26a4aaca46e..96a440eebd0 100644 --- a/megamek/src/megamek/common/weapons/LRMFollowTheLeaderHandler.java +++ b/megamek/src/megamek/common/weapons/LRMFollowTheLeaderHandler.java @@ -36,13 +36,13 @@ public class LRMFollowTheLeaderHandler extends LRMHandler { public LRMFollowTheLeaderHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " FTL missile(s) "; + salvoType = " FTL missile(s) "; nSalvoBonus = 1; } @Override public int getSalvoBonus() { - if (ComputeECM.isAffectedByECM(ae, ae.getPosition(), target.getPosition())) { + if (ComputeECM.isAffectedByECM(attackerEntity, attackerEntity.getPosition(), target.getPosition())) { return 0; } else { return nSalvoBonus; @@ -51,7 +51,7 @@ public int getSalvoBonus() { @Override protected int calcnCluster() { - if (ComputeECM.isAffectedByECM(ae, ae.getPosition(), target.getPosition())) { + if (ComputeECM.isAffectedByECM(attackerEntity, attackerEntity.getPosition(), target.getPosition())) { return super.calcnCluster(); } else { return Integer.MAX_VALUE; diff --git a/megamek/src/megamek/common/weapons/LRMFragHandler.java b/megamek/src/megamek/common/weapons/LRMFragHandler.java index e0d8876b96f..9b83129c784 100644 --- a/megamek/src/megamek/common/weapons/LRMFragHandler.java +++ b/megamek/src/megamek/common/weapons/LRMFragHandler.java @@ -35,7 +35,7 @@ public class LRMFragHandler extends LRMHandler { public LRMFragHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " fragmentation missile(s) "; + salvoType = " fragmentation missile(s) "; damageType = DamageType.FRAGMENTATION; } @@ -48,15 +48,15 @@ public LRMFragHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m protected int calcDamagePerHit() { double toReturn = 1; // during a swarm, all damage gets applied as one block to one location - if ((ae instanceof BattleArmor) + if ((attackerEntity instanceof BattleArmor) && (weapon.getLocation() == BattleArmor.LOC_SQUAD) && !(weapon.isSquadSupportWeapon()) - && (ae.getSwarmTargetId() == target.getId())) { - toReturn *= ((BattleArmor) ae).getShootingStrength(); + && (attackerEntity.getSwarmTargetId() == target.getId())) { + toReturn *= ((BattleArmor) attackerEntity).getShootingStrength(); } // against infantry, we have 1 hit if (target.isConventionalInfantry()) { - toReturn = wtype.getRackSize(); + toReturn = weaponType.getRackSize(); if (bDirect) { toReturn += toHit.getMoS() / 3.0; } @@ -96,7 +96,7 @@ protected void handleClearDamage(Vector vPhaseReport, if ((bldg != null) && gameManager.tryIgniteHex(target.getPosition(), subjectId, false, false, - new TargetRoll(wtype.getFireTN(), wtype.getName()), 5, + new TargetRoll(weaponType.getFireTN(), weaponType.getName()), 5, vPhaseReport)) { return; } diff --git a/megamek/src/megamek/common/weapons/LRMHandler.java b/megamek/src/megamek/common/weapons/LRMHandler.java index 43b2ac615a7..6b4b4e218e9 100644 --- a/megamek/src/megamek/common/weapons/LRMHandler.java +++ b/megamek/src/megamek/common/weapons/LRMHandler.java @@ -77,7 +77,7 @@ protected boolean specialResolution(Vector vPhaseReport, ArrayList mfRemoved = new ArrayList<>(); while (minefields.hasMoreElements()) { Minefield mf = minefields.nextElement(); - if (gameManager.clearMinefield(mf, ae, + if (gameManager.clearMinefield(mf, attackerEntity, Minefield.CLEAR_NUMBER_WEAPON, vPhaseReport)) { mfRemoved.add(mf); } @@ -96,22 +96,22 @@ protected int calcHits(Vector vPhaseReport) { // conventional infantry gets hit in one lump // BAs do one lump of damage per BA suit if (target.isConventionalInfantry()) { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { bSalvo = true; Report r = new Report(3325); r.subject = subjectId; - r.add(wtype.getRackSize() - * ((BattleArmor) ae).getShootingStrength()); - r.add(sSalvoType); + r.add(weaponType.getRackSize() + * ((BattleArmor) attackerEntity).getShootingStrength()); + r.add(salvoType); r.add(toHit.getTableDesc()); vPhaseReport.add(r); - return ((BattleArmor) ae).getShootingStrength(); + return ((BattleArmor) attackerEntity).getShootingStrength(); } Report r = new Report(3326); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getRackSize()); - r.add(sSalvoType); + r.add(weaponType.getRackSize()); + r.add(salvoType); vPhaseReport.add(r); return 1; } @@ -121,8 +121,8 @@ protected int calcHits(Vector vPhaseReport) { int nMissilesModifier = getClusterModifiers(false); boolean bMekTankStealthActive = false; - if ((ae instanceof Mek) || (ae instanceof Tank)) { - bMekTankStealthActive = ae.isStealthActive(); + if ((attackerEntity instanceof Mek) || (attackerEntity instanceof Tank)) { + bMekTankStealthActive = attackerEntity.isStealthActive(); } Mounted mLinker = weapon.getLinkedBy(); AmmoType atype = (AmmoType) ammo.getType(); @@ -130,7 +130,7 @@ protected int calcHits(Vector vPhaseReport) { boolean bECMAffected = false; // if the attacker is affected by ECM or the target is protected by ECM // then act as if affected. - if (ComputeECM.isAffectedByECM(ae, ae.getPosition(), target.getPosition())) { + if (ComputeECM.isAffectedByECM(attackerEntity, attackerEntity.getPosition(), target.getPosition())) { bECMAffected = true; } @@ -216,14 +216,14 @@ protected int calcHits(Vector vPhaseReport) { nMissilesModifier += 2; } } else if ((entityTarget != null) - && (entityTarget.isNarcedBy(ae.getOwner().getTeam()) || entityTarget - .isINarcedBy(ae.getOwner().getTeam()))) { + && (entityTarget.isNarcedBy(attackerEntity.getOwner().getTeam()) || entityTarget + .isINarcedBy(attackerEntity.getOwner().getTeam()))) { // only apply Narc bonus if we're not suffering ECM effect // and we are using narc ammo, and we're not firing indirectly. // narc capable missiles are only affected if the narc pod, which // sits on the target, is ECM affected boolean bTargetECMAffected = false; - bTargetECMAffected = ComputeECM.isAffectedByECM(ae, + bTargetECMAffected = ComputeECM.isAffectedByECM(attackerEntity, target.getPosition(), target.getPosition()); if (((atype.getAmmoType() == AmmoType.T_LRM) || (atype.getAmmoType() == AmmoType.T_LRM_IMP) @@ -254,14 +254,14 @@ protected int calcHits(Vector vPhaseReport) { nMissilesModifier -= getAeroSanityAMSHitsMod(); } - int rackSize = wtype.getRackSize(); + int rackSize = weaponType.getRackSize(); boolean minRangeELRMAttack = false; // ELRMs only hit with half their rack size rounded up at minimum range. // Ignore this for space combat. 1 hex is 18km across. - if (wtype instanceof ExtendedLRMWeapon + if (weaponType instanceof ExtendedLRMWeapon && !game.getBoard().inSpace() - && (nRange <= wtype.getMinimumRange())) { + && (nRange <= weaponType.getMinimumRange())) { rackSize = rackSize / 2 + rackSize % 2; minRangeELRMAttack = true; } @@ -273,9 +273,9 @@ protected int calcHits(Vector vPhaseReport) { nMissilesModifier, weapon.isHotLoaded(), true, isAdvancedAMS()); } else { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { missilesHit = Compute.missilesHit(rackSize - * ((BattleArmor) ae).getShootingStrength(), + * ((BattleArmor) attackerEntity).getShootingStrength(), nMissilesModifier, weapon.isHotLoaded(), false, isAdvancedAMS()); } else { @@ -289,7 +289,7 @@ protected int calcHits(Vector vPhaseReport) { Report r = new Report(3325); r.subject = subjectId; r.add(missilesHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); diff --git a/megamek/src/megamek/common/weapons/LRMScatterableHandler.java b/megamek/src/megamek/common/weapons/LRMScatterableHandler.java index cd8fc114e02..4c944341073 100644 --- a/megamek/src/megamek/common/weapons/LRMScatterableHandler.java +++ b/megamek/src/megamek/common/weapons/LRMScatterableHandler.java @@ -67,7 +67,7 @@ protected boolean specialResolution(Vector vPhaseReport, if (!bMissed) { Report r = new Report(3190, whoReport); r.subject = subjectId; - r.player = ae.getOwnerId(); + r.player = attackerEntity.getOwnerId(); r.add(coords.getBoardNum()); vPhaseReport.addElement(r); } else { @@ -81,7 +81,7 @@ protected boolean specialResolution(Vector vPhaseReport, if (density <= 0) { Report r = new Report(3198, whoReport); r.subject = subjectId; - r.player = ae.getOwnerId(); + r.player = attackerEntity.getOwnerId(); vPhaseReport.addElement(r); return true; } @@ -91,14 +91,14 @@ protected boolean specialResolution(Vector vPhaseReport, int reportNr = mineDelivery ? 3197 : 3195; Report r = new Report(reportNr, whoReport); r.subject = subjectId; - r.player = ae.getOwnerId(); + r.player = attackerEntity.getOwnerId(); r.add(coords.getBoardNum()); vPhaseReport.addElement(r); } else { // misses and scatters off-board Report r = new Report(3200); r.subject = subjectId; - r.player = ae.getOwnerId(); + r.player = attackerEntity.getOwnerId(); vPhaseReport.addElement(r); return true; } @@ -106,15 +106,15 @@ protected boolean specialResolution(Vector vPhaseReport, // Handle the thunder munitions. if (atype.getMunitionType().contains(AmmoType.Munitions.M_THUNDER_AUGMENTED)) { - gameManager.deliverThunderAugMinefield(coords, ae.getOwner().getId(), density, ae.getId()); + gameManager.deliverThunderAugMinefield(coords, attackerEntity.getOwner().getId(), density, attackerEntity.getId()); } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_THUNDER)) { - gameManager.deliverThunderMinefield(coords, ae.getOwner().getId(), density, ae.getId()); + gameManager.deliverThunderMinefield(coords, attackerEntity.getOwner().getId(), density, attackerEntity.getId()); } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_THUNDER_INFERNO)) { - gameManager.deliverThunderInfernoMinefield(coords, ae.getOwner().getId(), density, ae.getId()); + gameManager.deliverThunderInfernoMinefield(coords, attackerEntity.getOwner().getId(), density, attackerEntity.getId()); } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_THUNDER_VIBRABOMB)) { - gameManager.deliverThunderVibraMinefield(coords, ae.getOwner().getId(), density, waa.getOtherAttackInfo(), ae.getId()); + gameManager.deliverThunderVibraMinefield(coords, attackerEntity.getOwner().getId(), density, weaponAttackAction.getOtherAttackInfo(), attackerEntity.getId()); } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_THUNDER_ACTIVE)) { - gameManager.deliverThunderActiveMinefield(coords, ae.getOwner().getId(), density, ae.getId()); + gameManager.deliverThunderActiveMinefield(coords, attackerEntity.getOwner().getId(), density, attackerEntity.getId()); } return true; } diff --git a/megamek/src/megamek/common/weapons/LRMSmokeWarheadHandler.java b/megamek/src/megamek/common/weapons/LRMSmokeWarheadHandler.java index bbae3a0fde8..3a8971dc9b9 100644 --- a/megamek/src/megamek/common/weapons/LRMSmokeWarheadHandler.java +++ b/megamek/src/megamek/common/weapons/LRMSmokeWarheadHandler.java @@ -48,7 +48,7 @@ protected boolean specialResolution(Vector vPhaseReport, Entity entityTa if (!bMissed) { Report r = new Report(3190); r.subject = subjectId; - r.player = ae.getOwnerId(); + r.player = attackerEntity.getOwnerId(); r.add(coords.getBoardNum()); vPhaseReport.addElement(r); } else { @@ -71,7 +71,7 @@ protected boolean specialResolution(Vector vPhaseReport, Entity entityTa // Handle munitions. if (atype.getMunitionType().contains(AmmoType.Munitions.M_SMOKE_WARHEAD)) { - int damage = wtype.getRackSize() * calcDamagePerHit(); + int damage = weaponType.getRackSize() * calcDamagePerHit(); int smokeType = SmokeCloud.SMOKE_LIGHT; if (damage > 5) { smokeType = SmokeCloud.SMOKE_HEAVY; diff --git a/megamek/src/megamek/common/weapons/LRMSwarmHandler.java b/megamek/src/megamek/common/weapons/LRMSwarmHandler.java index 4f88de95f51..dbeed005f55 100644 --- a/megamek/src/megamek/common/weapons/LRMSwarmHandler.java +++ b/megamek/src/megamek/common/weapons/LRMSwarmHandler.java @@ -52,7 +52,7 @@ public class LRMSwarmHandler extends LRMHandler { public LRMSwarmHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " swarm missile(s) "; + salvoType = " swarm missile(s) "; } @Override @@ -66,11 +66,11 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { entityTarget); final boolean bldgDamagedOnMiss = targetInBuilding && !(target instanceof Infantry) - && ae.getPosition().distance(target.getPosition()) <= 1; + && attackerEntity.getPosition().distance(target.getPosition()) <= 1; if (entityTarget != null) { - ae.setLastTarget(entityTarget.getId()); - ae.setLastTargetDisplayName(entityTarget.getDisplayName()); + attackerEntity.setLastTarget(entityTarget.getId()); + attackerEntity.setLastTargetDisplayName(entityTarget.getDisplayName()); } // Which building takes the damage? @@ -81,11 +81,11 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + " (" + atype.getShortName() + ")"); + r.add(weaponType.getName() + " (" + ammoType.getShortName() + ")"); if (entityTarget != null) { r.addDesc(entityTarget); // record which launcher targeted the target - entityTarget.addTargetedBySwarm(ae.getId(), waa.getWeaponId()); + entityTarget.addTargetedBySwarm(attackerEntity.getId(), weaponAttackAction.getWeaponId()); } else { r.messageId = 3120; r.add(target.getDisplayName(), true); @@ -138,7 +138,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && ((toHit.getMoS() / 3) >= 1) && (entityTarget != null); if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -196,8 +196,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && (toHit.getThruBldg() != null) && (entityTarget instanceof Infantry)) { // If elevation is the same, building doesn't absorb - if (ae.getElevation() != entityTarget.getElevation()) { - int dmgClass = wtype.getInfantryDamageClass(); + if (attackerEntity.getElevation() != entityTarget.getElevation()) { + int dmgClass = weaponType.getInfantryDamageClass(); int nDamage; if (dmgClass < WeaponType.WEAPON_BURST_1D6) { nDamage = nDamPerHit * Math.min(nCluster, hits); @@ -206,7 +206,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { // absorbed damage shouldn't reduce incoming damage, // since the incoming damage was reduced in // Compute.directBlowInfantryDamage - nDamage = -wtype.getDamage(nRange) + nDamage = -weaponType.getDamage(nRange) * Math.min(nCluster, hits); } bldgAbsorbs = (int) Math.round(nDamage @@ -250,7 +250,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (entityTarget != null) { handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - gameManager.creditKill(entityTarget, ae); + gameManager.creditKill(entityTarget, attackerEntity); hits -= nCluster; firstHit = false; } @@ -258,8 +258,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { Report.addNewline(vPhaseReport); if (swarmMissilesNowLeft > 0) { Entity swarmTarget = Compute.getSwarmMissileTarget(game, - ae.getId(), target.getPosition(), waa.getWeaponId()); - boolean stoppedByECM = ComputeECM.isAffectedByECM(ae, + attackerEntity.getId(), target.getPosition(), weaponAttackAction.getWeaponId()); + boolean stoppedByECM = ComputeECM.isAffectedByECM(attackerEntity, target.getPosition(), target.getPosition()) && !(this instanceof LRMSwarmIHandler); if (swarmTarget != null && !stoppedByECM) { @@ -269,18 +269,18 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.add(swarmMissilesNowLeft); vPhaseReport.addElement(r); weapon.setUsedThisRound(false); - WeaponAttackAction newWaa = new WeaponAttackAction(ae.getId(), - swarmTarget.getId(), waa.getWeaponId()); + WeaponAttackAction newWaa = new WeaponAttackAction(attackerEntity.getId(), + swarmTarget.getId(), weaponAttackAction.getWeaponId()); newWaa.setSwarmingMissiles(true); newWaa.setSwarmMissiles(swarmMissilesNowLeft); newWaa.setOldTargetId(target.getId()); newWaa.setOldTargetType(target.getTargetType()); - newWaa.setOriginalTargetId(waa.getOriginalTargetId()); - newWaa.setOriginalTargetType(waa.getOriginalTargetType()); - newWaa.setAmmoId(waa.getAmmoId()); - newWaa.setAmmoMunitionType(waa.getAmmoMunitionType()); - newWaa.setAmmoCarrier(waa.getAmmoCarrier()); - Mounted m = ae.getEquipment(waa.getWeaponId()); + newWaa.setOriginalTargetId(weaponAttackAction.getOriginalTargetId()); + newWaa.setOriginalTargetType(weaponAttackAction.getOriginalTargetType()); + newWaa.setAmmoId(weaponAttackAction.getAmmoId()); + newWaa.setAmmoMunitionType(weaponAttackAction.getAmmoMunitionType()); + newWaa.setAmmoCarrier(weaponAttackAction.getAmmoCarrier()); + Mounted m = attackerEntity.getEquipment(weaponAttackAction.getWeaponId()); Weapon w = (Weapon) m.getType(); // increase ammo by one, we'll use one that we shouldn't use // in the next line @@ -321,13 +321,13 @@ protected int calcDamagePerHit() { // the damage to adjacent infantry should be based on the missiles left over, // not the total rack size. if (target.isConventionalInfantry()) { - int missiles = waa.isSwarmingMissiles() ? waa.getSwarmMissiles() - : wtype.getRackSize(); + int missiles = weaponAttackAction.isSwarmingMissiles() ? weaponAttackAction.getSwarmMissiles() + : weaponType.getRackSize(); double toReturn = Compute.directBlowInfantryDamage( missiles, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); toReturn = applyGlancingBlowModifier(toReturn, true); return (int) toReturn; @@ -340,18 +340,18 @@ protected boolean handleSpecialMiss(Entity entityTarget, Vector vPhaseReport, GamePhase phase) { super.handleSpecialMiss(entityTarget, bldgDamagedOnMiss, bldg, vPhaseReport); - int swarmMissilesNowLeft = waa.getSwarmMissiles(); + int swarmMissilesNowLeft = weaponAttackAction.getSwarmMissiles(); if (swarmMissilesNowLeft == 0) { - swarmMissilesNowLeft = wtype.getRackSize(); + swarmMissilesNowLeft = weaponType.getRackSize(); } if (entityTarget != null) { - ae.setLastTarget(entityTarget.getId()); - ae.setLastTargetDisplayName(entityTarget.getDisplayName()); + attackerEntity.setLastTarget(entityTarget.getId()); + attackerEntity.setLastTargetDisplayName(entityTarget.getDisplayName()); } - Entity swarmTarget = Compute.getSwarmMissileTarget(game, ae.getId(), - target.getPosition(), waa.getWeaponId()); - boolean stoppedByECM = ComputeECM.isAffectedByECM(ae, + Entity swarmTarget = Compute.getSwarmMissileTarget(game, attackerEntity.getId(), + target.getPosition(), weaponAttackAction.getWeaponId()); + boolean stoppedByECM = ComputeECM.isAffectedByECM(attackerEntity, target.getPosition(), target.getPosition()) && !(this instanceof LRMSwarmIHandler); if (swarmTarget != null && !stoppedByECM) { @@ -361,18 +361,18 @@ protected boolean handleSpecialMiss(Entity entityTarget, r.add(swarmMissilesNowLeft); vPhaseReport.addElement(r); weapon.setUsedThisRound(false); - WeaponAttackAction newWaa = new WeaponAttackAction(ae.getId(), - swarmTarget.getId(), waa.getWeaponId()); + WeaponAttackAction newWaa = new WeaponAttackAction(attackerEntity.getId(), + swarmTarget.getId(), weaponAttackAction.getWeaponId()); newWaa.setSwarmingMissiles(true); newWaa.setSwarmMissiles(swarmMissilesNowLeft); newWaa.setOldTargetId(target.getId()); newWaa.setOldTargetType(target.getTargetType()); - newWaa.setOriginalTargetId(waa.getOriginalTargetId()); - newWaa.setOriginalTargetType(waa.getOriginalTargetType()); - newWaa.setAmmoId(waa.getAmmoId()); - newWaa.setAmmoMunitionType(waa.getAmmoMunitionType()); - newWaa.setAmmoCarrier(waa.getAmmoCarrier()); - Mounted m = ae.getEquipment(waa.getWeaponId()); + newWaa.setOriginalTargetId(weaponAttackAction.getOriginalTargetId()); + newWaa.setOriginalTargetType(weaponAttackAction.getOriginalTargetType()); + newWaa.setAmmoId(weaponAttackAction.getAmmoId()); + newWaa.setAmmoMunitionType(weaponAttackAction.getAmmoMunitionType()); + newWaa.setAmmoCarrier(weaponAttackAction.getAmmoCarrier()); + Mounted m = attackerEntity.getEquipment(weaponAttackAction.getWeaponId()); Weapon w = (Weapon) m.getType(); // increase ammo by one, we'll use one that we shouldn't use // in the next line @@ -406,9 +406,9 @@ protected int calcHits(Vector vPhaseReport) { // conventional infantry gets hit in one lump // BAs do one lump of damage per BA suit if (target.isConventionalInfantry()) { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { bSalvo = true; - return ((BattleArmor) ae).getShootingStrength(); + return ((BattleArmor) attackerEntity).getShootingStrength(); } return 1; } @@ -427,7 +427,7 @@ protected int calcHits(Vector vPhaseReport) { } nMissilesModifier += amsMod; - int swarmMissilesLeft = waa.getSwarmMissiles(); + int swarmMissilesLeft = weaponAttackAction.getSwarmMissiles(); // swarm or swarm-I shots may just hit with the remaining missiles if (swarmMissilesLeft > 0) { if (allShotsHit()) { @@ -438,17 +438,17 @@ protected int calcHits(Vector vPhaseReport) { isAdvancedAMS()); } } else { - missilesHit = allShotsHit() ? wtype.getRackSize() + missilesHit = allShotsHit() ? weaponType.getRackSize() : Compute - .missilesHit(wtype.getRackSize(), nMissilesModifier, + .missilesHit(weaponType.getRackSize(), nMissilesModifier, weapon.isHotLoaded(), false, isAdvancedAMS()); - swarmMissilesLeft = wtype.getRackSize(); + swarmMissilesLeft = weaponType.getRackSize(); } swarmMissilesNowLeft = swarmMissilesLeft - missilesHit; Report r = new Report(3325); r.subject = subjectId; r.add(missilesHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); diff --git a/megamek/src/megamek/common/weapons/LRMSwarmIHandler.java b/megamek/src/megamek/common/weapons/LRMSwarmIHandler.java index b4059fac4cc..d78fbee0f78 100644 --- a/megamek/src/megamek/common/weapons/LRMSwarmIHandler.java +++ b/megamek/src/megamek/common/weapons/LRMSwarmIHandler.java @@ -35,6 +35,6 @@ public class LRMSwarmIHandler extends LRMSwarmHandler { public LRMSwarmIHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " swarm-i missile(s) "; + salvoType = " swarm-i missile(s) "; } } diff --git a/megamek/src/megamek/common/weapons/LegAttackHandler.java b/megamek/src/megamek/common/weapons/LegAttackHandler.java index 5e400d43bac..7be21ff3c97 100644 --- a/megamek/src/megamek/common/weapons/LegAttackHandler.java +++ b/megamek/src/megamek/common/weapons/LegAttackHandler.java @@ -61,8 +61,8 @@ protected void handleEntityDamage(Entity entityTarget, Vector vPhaseReport, Building bldg, int hits, int nCluster, int bldgAbsorbs) { HitData hit = entityTarget.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setAttackerId(getAttackerId()); // If a leg attacks hit a leg that isn't // there, then hit the other leg. @@ -82,10 +82,10 @@ protected void handleEntityDamage(Entity entityTarget, vPhaseReport.addElement(r); int damage = 4; - if (ae instanceof BattleArmor) { - damage += ((BattleArmor) ae).getVibroClaws(); - if (((BattleArmor) ae).hasMyomerBooster()) { - damage += ((BattleArmor) ae).getTroopers() * 2; + if (attackerEntity instanceof BattleArmor) { + damage += ((BattleArmor) attackerEntity).getVibroClaws(); + if (((BattleArmor) attackerEntity).hasMyomerBooster()) { + damage += ((BattleArmor) attackerEntity).getTroopers() * 2; } } @@ -98,7 +98,7 @@ protected void handleEntityDamage(Entity entityTarget, if (entityTarget.getArmorType(hit.getLocation()) == EquipmentType.T_ARMOR_HARDENED) { critMod -= 2; } - if (ae.hasAbility(OptionsConstants.MISC_HUMAN_TRO,Crew.HUMANTRO_MEK)) { + if (attackerEntity.hasAbility(OptionsConstants.MISC_HUMAN_TRO,Crew.HUMANTRO_MEK)) { critMod += 1; } vPhaseReport.addAll(gameManager.criticalEntity(entityTarget, hit.getLocation(), hit.isRear(), critMod, damage)); diff --git a/megamek/src/megamek/common/weapons/MGAWeaponHandler.java b/megamek/src/megamek/common/weapons/MGAWeaponHandler.java index b6570a59b78..a649a149a16 100644 --- a/megamek/src/megamek/common/weapons/MGAWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/MGAWeaponHandler.java @@ -43,15 +43,15 @@ protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { calcDmgPerHitReport.add(new Report(950)); int damage = Compute.directBlowInfantryDamage( - wtype.getDamage(), bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getDamage(), bDirect ? toHit.getMoS() / 3 : 0, + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport, howManyShots); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport, howManyShots); damage = applyGlancingBlowModifier(damage, true); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE)) { - if (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG]) { + if (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG]) { damage = (int) Math.floor(damage * 0.75); - } else if (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME]) { + } else if (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME]) { damage = (int) Math.floor(damage * 0.5); } } @@ -63,7 +63,7 @@ protected int calcDamagePerHit() { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#addHeatUseAmmo() */ @Override @@ -72,13 +72,13 @@ protected void useAmmo() { setDone(); checkAmmo(); howManyShots = weapon.getCurrentShots(); - int total = ae.getTotalAmmoOfType(ammo.getType()); + int total = attackerEntity.getTotalAmmoOfType(ammo.getType()); if (total <= howManyShots) { howManyShots = total; } shotsNeedFiring = howManyShots; if (ammo.getUsableShotsLeft() == 0) { - ae.loadWeapon(weapon); + attackerEntity.loadWeapon(weapon); ammo = weapon.getLinked(); // there will be some ammo somewhere, otherwise shot will not have // been fired. @@ -86,7 +86,7 @@ protected void useAmmo() { while (shotsNeedFiring > ammo.getUsableShotsLeft()) { shotsNeedFiring -= ammo.getBaseShotsLeft(); ammo.setShotsLeft(0); - ae.loadWeapon(weapon); + attackerEntity.loadWeapon(weapon); ammo = weapon.getLinked(); } ammo.setShotsLeft(ammo.getBaseShotsLeft() - shotsNeedFiring); @@ -94,7 +94,7 @@ protected void useAmmo() { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcHits(java.util.Vector) */ @Override @@ -124,7 +124,7 @@ protected int calcHits(Vector vPhaseReport) { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#addHeat() */ @Override @@ -136,7 +136,7 @@ protected void addHeat() { /* * (non-Javadoc) - * + * * @see * megamek.common.weapons.WeaponHandler#handleEntityDamage(megamek.common * .Entity, java.util.Vector, megamek.common.Building, int, int, int, int) @@ -148,13 +148,13 @@ protected void handleEntityDamage(Entity entityTarget, int nDamage; if (hit == null) { hit = entityTarget.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setAttackerId(getAttackerId()); } if (entityTarget.removePartialCoverHits(hit.getLocation(), toHit - .getCover(), Compute.targetSideTable(ae, entityTarget, weapon + .getCover(), Compute.targetSideTable(attackerEntity, entityTarget, weapon .getCalledShot().getCall()))) { // Weapon strikes Partial Cover. handlePartialCoverHit(entityTarget, vPhaseReport, hit, bldg, hits, @@ -191,8 +191,8 @@ protected void handleEntityDamage(Entity entityTarget, // damage absorption by the partial cover, if it would have happened Hex targetHex = game.getBoard().getHex(target.getPosition()); boolean targetStickingOutOfBuilding = unitStickingOutOfBuilding(targetHex, entityTarget); - - nDamage = absorbBuildingDamage(nDamage, entityTarget, bldgAbsorbs, + + nDamage = absorbBuildingDamage(nDamage, entityTarget, bldgAbsorbs, vPhaseReport, bldg, targetStickingOutOfBuilding); nDamage = checkTerrain(nDamage, entityTarget, vPhaseReport); @@ -215,13 +215,13 @@ protected void handleEntityDamage(Entity entityTarget, if (bGlancing) { hit.makeGlancingBlow(); } - + if (bLowProfileGlancing) { hit.makeGlancingBlow(); } vPhaseReport .addAll(gameManager.damageEntity(entityTarget, hit, nDamage, - false, ae.getSwarmTargetId() == entityTarget + false, attackerEntity.getSwarmTargetId() == entityTarget .getId() ? DamageType.IGNORE_PASSENGER : damageType, false, false, throughFront, underWater)); diff --git a/megamek/src/megamek/common/weapons/MGHandler.java b/megamek/src/megamek/common/weapons/MGHandler.java index 832ce68f9fe..77096037e7e 100644 --- a/megamek/src/megamek/common/weapons/MGHandler.java +++ b/megamek/src/megamek/common/weapons/MGHandler.java @@ -49,7 +49,7 @@ public MGHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override @@ -59,7 +59,7 @@ protected int calcDamagePerHit() { // Check for rapid fire Option. Only MGs can be rapidfire. // nDamPerHit was already set in useAmmo toReturn = applyGlancingBlowModifier(toReturn, false); - + if (bDirect) { toReturn = Math.min(toReturn + (toHit.getMoS() / 3), toReturn * 2); @@ -67,29 +67,29 @@ protected int calcDamagePerHit() { } else { if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage( - wtype.getDamage(), bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getDamage(), bDirect ? toHit.getMoS() / 3 : 0, + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); - + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); + toReturn = applyGlancingBlowModifier(toReturn, true); } else { - toReturn = wtype.getDamage(); + toReturn = weaponType.getDamage(); if (bDirect) { toReturn = Math.min(toReturn + (toHit.getMoS() / 3), toReturn * 2); } - + toReturn = applyGlancingBlowModifier(toReturn, false); } } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG])) { toReturn *= .75; toReturn = (int) Math.floor(toReturn); } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { toReturn = (int) Math.floor(toReturn * .5); } nDamPerHit = (int) toReturn; @@ -99,14 +99,14 @@ protected int calcDamagePerHit() { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#addHeat() */ @Override protected void addHeat() { if (!(toHit.getValue() == TargetRoll.IMPOSSIBLE)) { if (weapon.isRapidfire()) { - ae.heatBuildup += nRapidDamHeatPerHit; + attackerEntity.heatBuildup += nRapidDamHeatPerHit; } else { super.addHeat(); } @@ -115,7 +115,7 @@ protected void addHeat() { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#reportMiss(java.util.Vector) */ @Override @@ -135,7 +135,7 @@ protected void reportMiss(Vector vPhaseReport) { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#useAmmo() */ @Override @@ -143,7 +143,7 @@ protected void useAmmo() { if (weapon.isRapidfire()) { // TacOps p.102 Rapid Fire MG Rules - switch (wtype.getAmmoType()) { + switch (weaponType.getAmmoType()) { case AmmoType.T_MG: nDamPerHit = Compute.d6(); break; @@ -155,13 +155,13 @@ protected void useAmmo() { break; } - numRapidFireHits = nDamPerHit; + numberOfRapidFireHits = nDamPerHit; nRapidDamHeatPerHit = nDamPerHit; checkAmmo(); int ammoUsage = 3 * nRapidDamHeatPerHit; for (int i = 0; i < ammoUsage; i++) { if (ammo.getUsableShotsLeft() <= 0) { - ae.loadWeapon(weapon); + attackerEntity.loadWeapon(weapon); ammo = weapon.getLinked(); } ammo.setShotsLeft(ammo.getBaseShotsLeft() - 1); diff --git a/megamek/src/megamek/common/weapons/MPodHandler.java b/megamek/src/megamek/common/weapons/MPodHandler.java index f4280842328..b0db876d990 100644 --- a/megamek/src/megamek/common/weapons/MPodHandler.java +++ b/megamek/src/megamek/common/weapons/MPodHandler.java @@ -35,12 +35,12 @@ public class MPodHandler extends LBXHandler { */ public MPodHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " pellet(s) "; + salvoType = " pellet(s) "; } /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcHits(Vector * vPhaseReport) */ @@ -64,7 +64,7 @@ protected int calcHits(Vector vPhaseReport) { if (bGlancing) { hitMod -= 4; } - + if (bLowProfileGlancing) { hitMod -= 4; } @@ -80,7 +80,7 @@ protected int calcHits(Vector vPhaseReport) { Report r = new Report(3325); r.subject = subjectId; r.add(shotsHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); diff --git a/megamek/src/megamek/common/weapons/MRMHandler.java b/megamek/src/megamek/common/weapons/MRMHandler.java index 69dc19ca2c0..8f3b6c4d4ce 100644 --- a/megamek/src/megamek/common/weapons/MRMHandler.java +++ b/megamek/src/megamek/common/weapons/MRMHandler.java @@ -1,14 +1,14 @@ /** * MegaMek - Copyright (C) 2005 Ben Mazur (bmazur@sev.org) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ package megamek.common.weapons; @@ -33,7 +33,7 @@ public class MRMHandler extends MissileWeaponHandler { /** - * + * */ private static final long serialVersionUID = 38852986607304997L; @@ -49,7 +49,7 @@ public MRMHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { /* * (non-Javadoc) - * + * * @see * megamek.common.weapons.WeaponHandler#specialResolution(java.util.Vector, * megamek.common.Entity, boolean) @@ -70,7 +70,7 @@ protected boolean specialResolution(Vector vPhaseReport, ArrayList mfRemoved = new ArrayList<>(); while (minefields.hasMoreElements()) { Minefield mf = minefields.nextElement(); - if (gameManager.clearMinefield(mf, ae, + if (gameManager.clearMinefield(mf, attackerEntity, Minefield.CLEAR_NUMBER_WEAPON, vPhaseReport)) { mfRemoved.add(mf); } diff --git a/megamek/src/megamek/common/weapons/MekMortarAirburstHandler.java b/megamek/src/megamek/common/weapons/MekMortarAirburstHandler.java index bf113a1eed8..53bd41f17be 100644 --- a/megamek/src/megamek/common/weapons/MekMortarAirburstHandler.java +++ b/megamek/src/megamek/common/weapons/MekMortarAirburstHandler.java @@ -41,7 +41,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { Coords targetPos = target.getPosition(); - Mounted ammoUsed = ae.getEquipment(waa.getAmmoId()); + Mounted ammoUsed = attackerEntity.getEquipment(weaponAttackAction.getAmmoId()); final AmmoType ammoType = (ammoUsed == null) ? null : (AmmoType) ammoUsed.getType(); if ((ammoType == null) || (!ammoType.getMunitionType().contains(AmmoType.Munitions.M_AIRBURST))) { logger.error("Not using airburst ammo!"); @@ -53,8 +53,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - if (wtype != null) { - r.add(wtype.getName() + ' ' + ammoType.getSubMunitionName()); + if (weaponType != null) { + r.add(weaponType.getName() + ' ' + ammoType.getSubMunitionName()); } else { r.add("Error: From Nowhere"); } @@ -120,12 +120,12 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.subject = subjectId; r.indent(2); r.newlines++; - r.add(wtype.getName() + " " + ammoType.getSubMunitionName()); - r.add(wtype.getRackSize()); + r.add(weaponType.getName() + " " + ammoType.getSubMunitionName()); + r.add(weaponType.getRackSize()); vPhaseReport.addElement(r); Vector newReports; - int numRounds = wtype.getRackSize(); + int numRounds = weaponType.getRackSize(); // Damage building directly Building bldg = game.getBoard().getBuildingAt(targetPos); if (bldg != null) { @@ -178,10 +178,10 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { damage += (int) Math.ceil(Compute.d6() / 2.0); } hit = target.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setGeneralDamageType(generalDamageType); - hit.setCapital(wtype.isCapital()); + hit.setCapital(weaponType.isCapital()); hit.setBoxCars(roll.getIntValue() == 12); hit.setCapMisCritMod(getCapMisMod()); hit.setFirstHit(firstHit); @@ -207,10 +207,10 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { // Each round deals 1 damage for (int i = 0; i < numRounds; i++) { hit = target.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setGeneralDamageType(generalDamageType); - hit.setCapital(wtype.isCapital()); + hit.setCapital(weaponType.isCapital()); hit.setBoxCars(roll.getIntValue() == 12); hit.setCapMisCritMod(getCapMisMod()); hit.setFirstHit(firstHit); diff --git a/megamek/src/megamek/common/weapons/MekMortarAntiPersonnelHandler.java b/megamek/src/megamek/common/weapons/MekMortarAntiPersonnelHandler.java index eb211a19bd2..fda9c2791d1 100644 --- a/megamek/src/megamek/common/weapons/MekMortarAntiPersonnelHandler.java +++ b/megamek/src/megamek/common/weapons/MekMortarAntiPersonnelHandler.java @@ -30,7 +30,7 @@ */ public class MekMortarAntiPersonnelHandler extends AmmoWeaponHandler { private static final long serialVersionUID = -2073773899108954657L; - + String sSalvoType = " shell(s) "; /** @@ -46,7 +46,7 @@ public MekMortarAntiPersonnelHandler(ToHitData t, WeaponAttackAction w, /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcHits(java.util.Vector) */ @Override @@ -57,9 +57,9 @@ protected int calcHits(Vector vPhaseReport) { int nMissilesModifier = getClusterModifiers(true); if (targetHex) { - missilesHit = wtype.getRackSize(); + missilesHit = weaponType.getRackSize(); } else { - missilesHit = Compute.missilesHit(wtype.getRackSize(), + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier); } @@ -96,7 +96,7 @@ protected int calcHits(Vector vPhaseReport) { /** * Calculate the clustering of the hits - * + * * @return a int value saying how much hits are in each cluster * of damage. */ @@ -107,7 +107,7 @@ protected int calcnCluster() { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override @@ -125,13 +125,13 @@ protected int calcDamagePerHit() { } return 1; } - + @Override protected void handleEntityDamage(Entity entityTarget, Vector vPhaseReport, Building bldg, int hits, int nCluster, int bldgAbsorbs) { super.handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - + // We need to roll damage for each hit against infantry if (target.isConventionalInfantry()) { nDamPerHit = calcDamagePerHit(); diff --git a/megamek/src/megamek/common/weapons/MekMortarFlareHandler.java b/megamek/src/megamek/common/weapons/MekMortarFlareHandler.java index 24fcc9a256c..f90c2023ce8 100644 --- a/megamek/src/megamek/common/weapons/MekMortarFlareHandler.java +++ b/megamek/src/megamek/common/weapons/MekMortarFlareHandler.java @@ -53,7 +53,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { Coords targetPos = target.getPosition(); - Mounted ammoUsed = ae.getEquipment(waa.getAmmoId()); + Mounted ammoUsed = attackerEntity.getEquipment(weaponAttackAction.getAmmoId()); final AmmoType ammoType = (ammoUsed == null) ? null : (AmmoType) ammoUsed.getType(); if ((ammoType == null) || !ammoType.getMunitionType().contains(AmmoType.Munitions.M_FLARE)) { logger.error("Trying to use a Mek Mortar Flare with non-flare ammo"); @@ -65,8 +65,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - if (wtype != null) { - r.add(wtype.getName() + ' ' + ammoType.getSubMunitionName()); + if (weaponType != null) { + r.add(weaponType.getName() + ' ' + ammoType.getSubMunitionName()); } else { r.add("Error: From Nowhere"); } @@ -111,7 +111,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { bMissed = roll.getIntValue() < toHit.getValue(); // Set Margin of Success/Failure. toHit.setMoS(roll.getIntValue() - Math.max(2, toHit.getValue())); - int duration = wtype.getRackSize() * 2; + int duration = weaponType.getRackSize() * 2; if (!bMissed) { r = new Report(3190); diff --git a/megamek/src/megamek/common/weapons/MekMortarHandler.java b/megamek/src/megamek/common/weapons/MekMortarHandler.java index d24ea9b5731..f64093bdec0 100644 --- a/megamek/src/megamek/common/weapons/MekMortarHandler.java +++ b/megamek/src/megamek/common/weapons/MekMortarHandler.java @@ -45,7 +45,7 @@ public MekMortarHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcHits(java.util.Vector) */ @Override @@ -62,9 +62,9 @@ protected int calcHits(Vector vPhaseReport) { int nMissilesModifier = getClusterModifiers(true); if (targetHex) { - missilesHit = wtype.getRackSize(); + missilesHit = weaponType.getRackSize(); } else { - missilesHit = Compute.missilesHit(wtype.getRackSize(), + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier); } @@ -97,7 +97,7 @@ protected int calcHits(Vector vPhaseReport) { /** * Calculate the clustering of the hits - * + * * @return a int value saying how much hits are in each cluster * of damage. */ @@ -108,18 +108,18 @@ protected int calcnCluster() { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { double toReturn = Compute.directBlowInfantryDamage( - wtype.getRackSize(), bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getRackSize(), bDirect ? toHit.getMoS() / 3 : 0, + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); - + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); + toReturn = applyGlancingBlowModifier(toReturn, true); return (int) toReturn; } diff --git a/megamek/src/megamek/common/weapons/MekMortarSmokeHandler.java b/megamek/src/megamek/common/weapons/MekMortarSmokeHandler.java index f7dc3b43c55..e9b7f244cf2 100644 --- a/megamek/src/megamek/common/weapons/MekMortarSmokeHandler.java +++ b/megamek/src/megamek/common/weapons/MekMortarSmokeHandler.java @@ -53,7 +53,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { Coords targetPos = target.getPosition(); - Mounted ammoUsed = ae.getEquipment(waa.getAmmoId()); + Mounted ammoUsed = attackerEntity.getEquipment(weaponAttackAction.getAmmoId()); final AmmoType ammoType = (ammoUsed == null) ? null : (AmmoType) ammoUsed.getType(); if ((ammoType == null) || (!ammoType.getMunitionType().contains(AmmoType.Munitions.M_SMOKE_WARHEAD))) { @@ -66,8 +66,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - if (wtype != null) { - r.add(wtype.getName() + ' ' + ammoType.getSubMunitionName()); + if (weaponType != null) { + r.add(weaponType.getName() + ' ' + ammoType.getSubMunitionName()); } else { r.add("Error: From Nowhere"); } @@ -112,7 +112,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { bMissed = roll.getIntValue() < toHit.getValue(); // Set Margin of Success/Failure. toHit.setMoS(roll.getIntValue() - Math.max(2, toHit.getValue())); - int duration = wtype.getRackSize() * 2; + int duration = weaponType.getRackSize() * 2; if (!bMissed) { r = new Report(3190); diff --git a/megamek/src/megamek/common/weapons/MicroBombHandler.java b/megamek/src/megamek/common/weapons/MicroBombHandler.java index 4b04f9a9182..624f7c171fc 100644 --- a/megamek/src/megamek/common/weapons/MicroBombHandler.java +++ b/megamek/src/megamek/common/weapons/MicroBombHandler.java @@ -45,7 +45,7 @@ public MicroBombHandler(ToHitData toHit, WeaponAttackAction waa, Game g, TWGameM /* * (non-Javadoc) - * + * * @see * megamek.common.weapons.WeaponHandler#specialResolution(java.util.Vector, * megamek.common.Entity, boolean) @@ -60,7 +60,7 @@ protected boolean specialResolution(Vector vPhaseReport, Entity entityTa vPhaseReport.add(r); } else { int moF = -toHit.getMoS(); - if (ae.hasAbility(OptionsConstants.GUNNERY_GOLDEN_GOOSE)) { + if (attackerEntity.hasAbility(OptionsConstants.GUNNERY_GOLDEN_GOOSE)) { if ((-toHit.getMoS() - 2) < 1) { moF = 0; } else { @@ -82,11 +82,11 @@ protected boolean specialResolution(Vector vPhaseReport, Entity entityTa return !bMissed; } } - Infantry ba = (Infantry) ae; + Infantry ba = (Infantry) attackerEntity; int ratedDamage = ba.getShootingStrength(); - gameManager.artilleryDamageArea(coords, ae.getPosition(), - (AmmoType) ammo.getType(), subjectId, ae, ratedDamage * 2, + gameManager.artilleryDamageArea(coords, attackerEntity.getPosition(), + (AmmoType) ammo.getType(), subjectId, attackerEntity, ratedDamage * 2, ratedDamage, false, 0, vPhaseReport, false); return true; } -} \ No newline at end of file +} diff --git a/megamek/src/megamek/common/weapons/MissileBayWeaponHandler.java b/megamek/src/megamek/common/weapons/MissileBayWeaponHandler.java index 32bab7a1b16..c559d9f5bb0 100644 --- a/megamek/src/megamek/common/weapons/MissileBayWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/MissileBayWeaponHandler.java @@ -73,21 +73,21 @@ protected int calcAttackValue() { double av = 0; double counterAV = 0; int weaponarmor = 0; - int range = RangeType.rangeBracket(nRange, wtype.getATRanges(), true, false); + int range = RangeType.rangeBracket(nRange, weaponType.getATRanges(), true, false); for (WeaponMounted bayW : weapon.getBayWeapons()) { // check the currently loaded ammo AmmoMounted bayWAmmo = bayW.getLinkedAmmo(); if (null == bayWAmmo || bayWAmmo.getUsableShotsLeft() < 1) { // try loading something else - ae.loadWeaponWithSameAmmo(bayW); + attackerEntity.loadWeaponWithSameAmmo(bayW); bayWAmmo = bayW.getLinkedAmmo(); } if (!bayW.isBreached() && !bayW.isDestroyed() && !bayW.isJammed() && bayWAmmo != null - && ae.getTotalAmmoOfType(bayWAmmo.getType()) >= bayW + && attackerEntity.getTotalAmmoOfType(bayWAmmo.getType()) >= bayW .getCurrentShots()) { WeaponType bayWType = ((WeaponType) bayW.getType()); // need to cycle through weapons and add av @@ -115,7 +115,7 @@ protected int calcAttackValue() { if (null == bayWAmmo || bayWAmmo.getUsableShotsLeft() < 1) { // try loading something else - ae.loadWeaponWithSameAmmo(bayW); + attackerEntity.loadWeaponWithSameAmmo(bayW); bayWAmmo = bayW.getLinkedAmmo(); } if (null != bayWAmmo) { @@ -177,7 +177,7 @@ protected void setPDBayReportingFlag() { // Check for Thunderbolt. We'll use this for single AMS resolution @Override protected boolean isTbolt() { - return wtype.hasFlag(WeaponType.F_LARGEMISSILE); + return weaponType.hasFlag(WeaponType.F_LARGEMISSILE); } /** @@ -210,7 +210,7 @@ protected int calcCapMissileAMSMod() { @Override protected double updateAVforAmmo(double current_av, AmmoType atype, WeaponType bayWType, int range, int wId) { - Mounted bayW = ae.getEquipment(wId); + Mounted bayW = attackerEntity.getEquipment(wId); Mounted mLinker = bayW.getLinkedBy(); int bonus = 0; if ((mLinker != null && mLinker.getType() instanceof MiscType @@ -286,23 +286,23 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { entityTarget); final boolean bldgDamagedOnMiss = targetInBuilding && !(target instanceof Infantry) - && ae.getPosition().distance(target.getPosition()) <= 1; + && attackerEntity.getPosition().distance(target.getPosition()) <= 1; if (entityTarget != null) { - ae.setLastTarget(entityTarget.getId()); - ae.setLastTargetDisplayName(entityTarget.getDisplayName()); + attackerEntity.setLastTarget(entityTarget.getId()); + attackerEntity.setLastTargetDisplayName(entityTarget.getDisplayName()); } // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); - String number = nweapons > 1 ? " (" + nweapons + ")" : ""; + String number = numberOfWeapons > 1 ? " (" + numberOfWeapons + ")" : ""; // Report weapon attack and its to-hit value. Report r = new Report(3115); r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + number); + r.add(weaponType.getName() + number); if (entityTarget != null) { r.addDesc(entityTarget); } else { @@ -358,7 +358,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && ((toHit.getMoS() / 3) >= 1) && (entityTarget != null); if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -435,7 +435,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { Report.addNewline(vPhaseReport); // loop through weapons in bay and do damage - int range = RangeType.rangeBracket(nRange, wtype.getATRanges(), true, false); + int range = RangeType.rangeBracket(nRange, weaponType.getATRanges(), true, false); int hits = 1; int nCluster = 1; for (WeaponMounted m : weapon.getBayWeapons()) { @@ -473,8 +473,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && (toHit.getThruBldg() != null) && (entityTarget instanceof Infantry)) { // If elevation is the same, building doesn't absorb - if (ae.getElevation() != entityTarget.getElevation()) { - int dmgClass = wtype.getInfantryDamageClass(); + if (attackerEntity.getElevation() != entityTarget.getElevation()) { + int dmgClass = weaponType.getInfantryDamageClass(); int nDamage; if (dmgClass < WeaponType.WEAPON_BURST_1D6) { nDamage = nDamPerHit * Math.min(nCluster, hits); @@ -483,7 +483,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { // absorbed damage shouldn't reduce incoming damage, // since the incoming damage was reduced in // Compute.directBlowInfantryDamage - nDamage = -wtype.getDamage(nRange) + nDamage = -weaponType.getDamage(nRange) * Math.min(nCluster, hits); } bldgAbsorbs = (int) Math.round(nDamage @@ -496,7 +496,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - gameManager.creditKill(entityTarget, ae); + gameManager.creditKill(entityTarget, attackerEntity); } // Handle the next weapon in the bay Report.addNewline(vPhaseReport); return false; diff --git a/megamek/src/megamek/common/weapons/MissileMineClearanceHandler.java b/megamek/src/megamek/common/weapons/MissileMineClearanceHandler.java index d64bd7ea445..a8e4182189f 100644 --- a/megamek/src/megamek/common/weapons/MissileMineClearanceHandler.java +++ b/megamek/src/megamek/common/weapons/MissileMineClearanceHandler.java @@ -44,7 +44,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { Coords targetPos = target.getPosition(); - Mounted ammoUsed = ae.getEquipment(waa.getAmmoId()); + Mounted ammoUsed = attackerEntity.getEquipment(weaponAttackAction.getAmmoId()); final AmmoType ammoType = (ammoUsed == null) ? null : (AmmoType) ammoUsed.getType(); if ((ammoType == null) || (!ammoType.getMunitionType().contains(AmmoType.Munitions.M_MINE_CLEARANCE))) { logger.error("Not using mine clearance ammo!"); @@ -56,8 +56,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - if (wtype != null) { - r.add(wtype.getName() + ' ' + ammoType.getSubMunitionName()); + if (weaponType != null) { + r.add(weaponType.getName() + ' ' + ammoType.getSubMunitionName()); } else { r.add("Error: From Nowhere"); } @@ -120,8 +120,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { // Handle mine clearance List mfRemoved = new ArrayList<>(); - int missileDamage = (wtype instanceof LRMWeapon) ? 1 : 2; - int mineDamage = wtype.getRackSize() * missileDamage; + int missileDamage = (weaponType instanceof LRMWeapon) ? 1 : 2; + int mineDamage = weaponType.getRackSize() * missileDamage; boolean updateMinefields = false; for (Minefield mf : game.getMinefields(targetPos)) { int density = mf.getDensity() - mineDamage; @@ -151,12 +151,12 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { } // Report amount of damage - int damage = (wtype.getRackSize() * missileDamage) / 10; + int damage = (weaponType.getRackSize() * missileDamage) / 10; r = new Report(9940); r.subject = subjectId; r.indent(2); r.newlines++; - r.add(wtype.getName() + " " + ammoType.getSubMunitionName()); + r.add(weaponType.getName() + " " + ammoType.getSubMunitionName()); r.add(damage); vPhaseReport.addElement(r); @@ -209,11 +209,11 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { vPhaseReport.addAll(newReports); } else { hit = target.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); if (target.getBARRating(hit.getLocation()) <= 6) { hit.setGeneralDamageType(generalDamageType); - hit.setCapital(wtype.isCapital()); + hit.setCapital(weaponType.isCapital()); hit.setBoxCars(roll.getIntValue() == 12); hit.setCapMisCritMod(getCapMisMod()); hit.setFirstHit(firstHit); diff --git a/megamek/src/megamek/common/weapons/MissileWeaponHandler.java b/megamek/src/megamek/common/weapons/MissileWeaponHandler.java index cf5bd1d3caa..f5c89613f85 100644 --- a/megamek/src/megamek/common/weapons/MissileWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/MissileWeaponHandler.java @@ -47,7 +47,7 @@ public MissileWeaponHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameMan advancedAMS = g.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_AMS); advancedPD = g.getOptions().booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_ADV_POINTDEF); multiAMS = g.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_MULTI_USE_AMS); - sSalvoType = " missile(s) "; + salvoType = " missile(s) "; } @Override @@ -55,25 +55,25 @@ protected int calcHits(Vector vPhaseReport) { // conventional infantry gets hit in one lump // BAs do one lump of damage per BA suit if (target.isConventionalInfantry()) { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { bSalvo = true; Report r = new Report(3325); r.subject = subjectId; int shootingStrength = 1; if ((weapon.getLocation() == BattleArmor.LOC_SQUAD) && !(weapon.isSquadSupportWeapon())) { - shootingStrength = ((BattleArmor) ae).getShootingStrength(); + shootingStrength = ((BattleArmor) attackerEntity).getShootingStrength(); } - r.add(wtype.getRackSize() * shootingStrength); - r.add(sSalvoType); + r.add(weaponType.getRackSize() * shootingStrength); + r.add(salvoType); r.add(" "); vPhaseReport.add(r); return shootingStrength; } Report r = new Report(3325); r.subject = subjectId; - r.add(wtype.getRackSize()); - r.add(sSalvoType); + r.add(weaponType.getRackSize()); + r.add(salvoType); r.add(" "); vPhaseReport.add(r); return 1; @@ -84,8 +84,8 @@ protected int calcHits(Vector vPhaseReport) { int nMissilesModifier = getClusterModifiers(true); boolean bMekTankStealthActive = false; - if ((ae instanceof Mek) || (ae instanceof Tank)) { - bMekTankStealthActive = ae.isStealthActive(); + if ((attackerEntity instanceof Mek) || (attackerEntity instanceof Tank)) { + bMekTankStealthActive = attackerEntity.isStealthActive(); } Mounted mLinker = weapon.getLinkedBy(); AmmoType atype = (AmmoType) ammo.getType(); @@ -94,7 +94,7 @@ protected int calcHits(Vector vPhaseReport) { boolean bECMAffected = false; // if the attacker is affected by ECM or the target is protected by ECM // then act as if affected. - if (ComputeECM.isAffectedByECM(ae, ae.getPosition(), target.getPosition())) { + if (ComputeECM.isAffectedByECM(attackerEntity, attackerEntity.getPosition(), target.getPosition())) { bECMAffected = true; } @@ -181,14 +181,14 @@ protected int calcHits(Vector vPhaseReport) { nMissilesModifier += 2; } } else if ((entityTarget != null) - && (entityTarget.isNarcedBy(ae.getOwner().getTeam()) - || entityTarget.isINarcedBy(ae.getOwner().getTeam()))) { + && (entityTarget.isNarcedBy(attackerEntity.getOwner().getTeam()) + || entityTarget.isINarcedBy(attackerEntity.getOwner().getTeam()))) { // only apply Narc bonus if we're not suffering ECM effect // and we are using narc ammo, and we're not firing indirectly. // narc capable missiles are only affected if the narc pod, which // sits on the target, is ECM affected boolean bTargetECMAffected = false; - bTargetECMAffected = ComputeECM.isAffectedByECM(ae, target.getPosition(), target.getPosition()); + bTargetECMAffected = ComputeECM.isAffectedByECM(attackerEntity, target.getPosition(), target.getPosition()); if (((atype.getAmmoType() == AmmoType.T_LRM) || (atype.getAmmoType() == AmmoType.T_LRM_IMP) || (atype.getAmmoType() == AmmoType.T_SRM) @@ -220,19 +220,19 @@ protected int calcHits(Vector vPhaseReport) { if (allShotsHit()) { // We want buildings and large craft to be able to affect this number with AMS // treat as a Streak launcher (cluster roll 11) to make this happen - missilesHit = Compute.missilesHit(wtype.getRackSize(), nMissilesModifier, + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier, weapon.isHotLoaded(), true, isAdvancedAMS()); } else { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { int shootingStrength = 1; if ((weapon.getLocation() == BattleArmor.LOC_SQUAD) && !weapon.isSquadSupportWeapon()) { - shootingStrength = ((BattleArmor) ae).getShootingStrength(); + shootingStrength = ((BattleArmor) attackerEntity).getShootingStrength(); } - missilesHit = Compute.missilesHit(wtype.getRackSize() * shootingStrength, + missilesHit = Compute.missilesHit(weaponType.getRackSize() * shootingStrength, nMissilesModifier, weapon.isHotLoaded(), false, isAdvancedAMS()); } else { - missilesHit = Compute.missilesHit(wtype.getRackSize(), nMissilesModifier, + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier, weapon.isHotLoaded(), false, isAdvancedAMS()); } } @@ -241,7 +241,7 @@ protected int calcHits(Vector vPhaseReport) { Report r = new Report(3325); r.subject = subjectId; r.add(missilesHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); @@ -273,10 +273,10 @@ protected int calcnCluster() { protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { double toReturn = Compute.directBlowInfantryDamage( - wtype.getRackSize(), bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getRackSize(), bDirect ? toHit.getMoS() / 3 : 0, + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); toReturn = applyGlancingBlowModifier(toReturn, false); return (int) toReturn; } @@ -291,15 +291,15 @@ protected int calcDamagePerHit() { @Override protected int calcAttackValue() { int av = 0; - int range = RangeType.rangeBracket(nRange, wtype.getATRanges(), true, false); + int range = RangeType.rangeBracket(nRange, weaponType.getATRanges(), true, false); if (range == WeaponType.RANGE_SHORT) { - av = wtype.getRoundShortAV(); + av = weaponType.getRoundShortAV(); } else if (range == WeaponType.RANGE_MED) { - av = wtype.getRoundMedAV(); + av = weaponType.getRoundMedAV(); } else if (range == WeaponType.RANGE_LONG) { - av = wtype.getRoundLongAV(); + av = weaponType.getRoundLongAV(); } else if (range == WeaponType.RANGE_EXT) { - av = wtype.getRoundExtAV(); + av = weaponType.getRoundExtAV(); } Mounted mLinker = weapon.getLinkedBy(); AmmoType atype = (AmmoType) ammo.getType(); @@ -349,7 +349,7 @@ protected int calcAttackValue() { originalAV = av; // Point Defenses engage the missiles still aimed at us - if (ae.usesWeaponBays() || ae.isCapitalFighter()) { + if (attackerEntity.usesWeaponBays() || attackerEntity.isCapitalFighter()) { av = av - calcCounterAV(); } @@ -386,8 +386,8 @@ protected boolean handleSpecialMiss(Entity entityTarget, boolean bldgDamagedOnMi if ((entityTarget != null) && !entityTarget.isAirborne() && !entityTarget.isAirborneVTOLorWIGE() - && ((bldg == null) && (wtype.getFireTN() != TargetRoll.IMPOSSIBLE - && (atype == null || atype.getFireTN() != TargetRoll.IMPOSSIBLE)))) { + && ((bldg == null) && (weaponType.getFireTN() != TargetRoll.IMPOSSIBLE + && (ammoType == null || ammoType.getFireTN() != TargetRoll.IMPOSSIBLE)))) { gameManager.tryIgniteHex(target.getPosition(), subjectId, false, false, getFireTNRoll(), 3, vPhaseReport); } @@ -444,7 +444,7 @@ protected double getAeroSanityAMSHitsMod() { // Good for squadron missile fire. This may get divided up against too many // missile racks to produce a result. // Set a minimum -4 (default AMS mod) - return Math.max((getCounterAV() / nweaponsHit), 4); + return Math.max((getCounterAV() / numberOfWeaponHits), 4); } return 0; } @@ -459,7 +459,7 @@ protected int getAMSHitsMod(Vector vPhaseReport) { int amsMod = 0; Entity entityTarget = (Entity) target; // any AMS attacks by the target? - List lCounters = waa.getCounterEquipment(); + List lCounters = weaponAttackAction.getCounterEquipment(); if (null != lCounters) { // resolve AMS counter-fire for (WeaponMounted counter : lCounters) { @@ -481,7 +481,7 @@ protected int getAMSHitsMod(Vector vPhaseReport) { // If the defending unit is the target, use attacker for arc if (entityTarget.equals(pdEnt)) { isInArc = Compute.isInArc(game, entityTarget.getId(), - entityTarget.getEquipmentNum(counter), ae); + entityTarget.getEquipmentNum(counter), attackerEntity); } else { // Otherwise, the attack target must be in arc isInArc = Compute.isInArc(game, pdEnt.getId(), pdEnt.getEquipmentNum(counter), @@ -616,25 +616,25 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { final boolean targetInBuilding = Compute.isInBuilding(game, entityTarget); final boolean bldgDamagedOnMiss = targetInBuilding && !(target instanceof Infantry) - && ae.getPosition().distance(target.getPosition()) <= 1; + && attackerEntity.getPosition().distance(target.getPosition()) <= 1; boolean bNemesisConfusable = isNemesisConfusable(); if (entityTarget != null) { - ae.setLastTarget(entityTarget.getId()); - ae.setLastTargetDisplayName(entityTarget.getDisplayName()); + attackerEntity.setLastTarget(entityTarget.getId()); + attackerEntity.setLastTargetDisplayName(entityTarget.getDisplayName()); } // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); - String number = nweapons > 1 ? " (" + nweapons + ")" : ""; + String number = numberOfWeapons > 1 ? " (" + numberOfWeapons + ")" : ""; // Report weapon attack and its to-hit value. Report r = new Report(3115); r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + number); + r.add(weaponType.getName() + number); if (entityTarget != null) { - if (wtype.getAmmoType() != AmmoType.T_NA) { + if (weaponType.getAmmoType() != AmmoType.T_NA) { AmmoType atype = (AmmoType) ammo.getType(); if (!atype.getMunitionType().contains(AmmoType.Munitions.M_STANDARD) || atype.getAmmoType() == AmmoType.T_MML @@ -651,19 +651,19 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { vPhaseReport.addElement(r); // check for nemesis boolean shotAtNemesisTarget = false; - if (bNemesisConfusable && !waa.isNemesisConfused()) { + if (bNemesisConfusable && !weaponAttackAction.isNemesisConfused()) { // loop through nemesis targets - for (Enumeration e = game.getNemesisTargets(ae, target.getPosition()); e.hasMoreElements();) { + for (Enumeration e = game.getNemesisTargets(attackerEntity, target.getPosition()); e.hasMoreElements();) { Entity entity = e.nextElement(); // friendly unit with attached iNarc Nemesis pod standing in the way r = new Report(3125); r.subject = subjectId; vPhaseReport.addElement(r); weapon.setUsedThisRound(false); - WeaponAttackAction newWaa = new WeaponAttackAction(ae.getId(), - entity.getId(), waa.getWeaponId()); + WeaponAttackAction newWaa = new WeaponAttackAction(attackerEntity.getId(), + entity.getId(), weaponAttackAction.getWeaponId()); newWaa.setNemesisConfused(true); - Mounted m = ae.getEquipment(waa.getWeaponId()); + Mounted m = attackerEntity.getEquipment(weaponAttackAction.getWeaponId()); Weapon w = (Weapon) m.getType(); AttackHandler ah = w.fire(newWaa, game, gameManager); // increase ammo by one, because we just incorrectly used one up @@ -769,7 +769,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && ((toHit.getMoS() / 3) >= 1) && (entityTarget != null); if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -795,7 +795,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (entityTarget != null && entityTarget.hasETypeFlag(Entity.ETYPE_DROPSHIP) && !game.getOptions().booleanOption(OptionsConstants.ADVAERORULES_AERO_SANITY) - && (waa.isAirToAir(game) || (waa.isAirToGround(game) && !ae.usesWeaponBays()))) { + && (weaponAttackAction.isAirToAir(game) || (weaponAttackAction.isAirToGround(game) && !attackerEntity.usesWeaponBays()))) { nDamPerHit = attackValue; } else { // This is for all other targets in atmosphere @@ -820,7 +820,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { int nCluster = calcnCluster(); int id = vPhaseReport.size(); int hits; - if (game.getBoard().inSpace() || waa.isAirToAir(game) || waa.isAirToGround(game)) { + if (game.getBoard().inSpace() || weaponAttackAction.isAirToAir(game) || weaponAttackAction.isAirToGround(game)) { // Ensures single AMS state is properly updated getAMSHitsMod(new Vector<>()); int[] aeroResults = calcAeroDamage(entityTarget, vPhaseReport); @@ -846,11 +846,11 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { vPhaseReport.addElement(r); } - if (!bMissed && amsEngaged && isTbolt() && !ae.isCapitalFighter()) { + if (!bMissed && amsEngaged && isTbolt() && !attackerEntity.isCapitalFighter()) { // Thunderbolts are destroyed by AMS 50% of the time whether Aero Sanity is on // or not hits = calcHits(vPhaseReport); - } else if (!bMissed && nweaponsHit == 1) { + } else if (!bMissed && numberOfWeaponHits == 1) { r = new Report(3390); r.subject = subjectId; vPhaseReport.addElement(r); @@ -858,7 +858,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { // This is for aero attacks as attack value. Does not apply if Aero Sanity is on if (!game.getOptions().booleanOption(OptionsConstants.ADVAERORULES_AERO_SANITY)) { - if (!bMissed && amsEngaged && !isTbolt() && !ae.isCapitalFighter()) { + if (!bMissed && amsEngaged && !isTbolt() && !attackerEntity.isCapitalFighter()) { // handle single AMS action against standard missiles Roll diceRoll = Compute.rollD6(1); r = new Report(3352); @@ -924,8 +924,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && (toHit.getThruBldg() != null) && (entityTarget instanceof Infantry)) { // If elevation is the same, building doesn't absorb - if (ae.getElevation() != entityTarget.getElevation()) { - int dmgClass = wtype.getInfantryDamageClass(); + if (attackerEntity.getElevation() != entityTarget.getElevation()) { + int dmgClass = weaponType.getInfantryDamageClass(); int nDamage; if (dmgClass < WeaponType.WEAPON_BURST_1D6) { nDamage = nDamPerHit * Math.min(nCluster, hits); @@ -934,7 +934,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { // absorbed damage shouldn't reduce incoming damage, // since the incoming damage was reduced in // Compute.directBlowInfantryDamage - nDamage = -wtype.getDamage(nRange) * Math.min(nCluster, hits); + nDamage = -weaponType.getDamage(nRange) * Math.min(nCluster, hits); } bldgAbsorbs = (int) Math.round(nDamage * bldg.getInfDmgFromInside()); } else { @@ -979,7 +979,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (entityTarget != null) { handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - gameManager.creditKill(entityTarget, ae); + gameManager.creditKill(entityTarget, attackerEntity); hits -= nCluster; firstHit = false; } @@ -991,7 +991,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (bldgDamagedOnMiss) { r = new Report(6429); r.indent(2); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines--; vPhaseReport.add(r); int nDamage = nDamPerHit * hits; @@ -1014,7 +1014,7 @@ protected boolean isNemesisConfusable() { boolean isNemesisConfusable = false; AmmoType atype = (AmmoType) ammo.getType(); Mounted mLinker = weapon.getLinkedBy(); - if ((wtype.getAmmoType() == AmmoType.T_ATM) + if ((weaponType.getAmmoType() == AmmoType.T_ATM) || ((mLinker != null) && (mLinker.getType() instanceof MiscType) && !mLinker.isDestroyed() && !mLinker.isMissing() @@ -1037,10 +1037,10 @@ protected boolean isNemesisConfusable() { || (atype.getMunitionType().contains(AmmoType.Munitions.M_ARTEMIS_V_CAPABLE))))) { isNemesisConfusable = true; } - } else if ((wtype.getAmmoType() == AmmoType.T_LRM) - || (wtype.getAmmoType() == AmmoType.T_LRM_IMP) - || (wtype.getAmmoType() == AmmoType.T_SRM) - || (wtype.getAmmoType() == AmmoType.T_SRM_IMP)) { + } else if ((weaponType.getAmmoType() == AmmoType.T_LRM) + || (weaponType.getAmmoType() == AmmoType.T_LRM_IMP) + || (weaponType.getAmmoType() == AmmoType.T_SRM) + || (weaponType.getAmmoType() == AmmoType.T_SRM_IMP)) { if ((atype.getMunitionType().contains(AmmoType.Munitions.M_NARC_CAPABLE)) || (atype.getMunitionType().contains(AmmoType.Munitions.M_LISTEN_KILL))) { isNemesisConfusable = true; @@ -1067,6 +1067,6 @@ && getParentBayHandler() != null) { // Check for Thunderbolt. We'll use this for single AMS resolution @Override protected boolean isTbolt() { - return wtype.hasFlag(WeaponType.F_LARGEMISSILE); + return weaponType.hasFlag(WeaponType.F_LARGEMISSILE); } } diff --git a/megamek/src/megamek/common/weapons/NarcExplosiveHandler.java b/megamek/src/megamek/common/weapons/NarcExplosiveHandler.java index ff1c07440cd..9c680740102 100644 --- a/megamek/src/megamek/common/weapons/NarcExplosiveHandler.java +++ b/megamek/src/megamek/common/weapons/NarcExplosiveHandler.java @@ -34,12 +34,12 @@ public class NarcExplosiveHandler extends MissileWeaponHandler { public NarcExplosiveHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " explosive pod "; + salvoType = " explosive pod "; } /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcHits(java.util.Vector) */ @Override @@ -48,20 +48,20 @@ protected int calcHits(Vector vPhaseReport) { // conventional infantry gets hit in one lump // BAs do one lump of damage per BA suit if (target.isConventionalInfantry()) { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { bSalvo = true; - return ((BattleArmor) ae).getShootingStrength(); + return ((BattleArmor) attackerEntity).getShootingStrength(); } return 1; } bSalvo = true; - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { if (amsEngaged) { return Compute.missilesHit( - ((BattleArmor) ae).getShootingStrength(), -2); + ((BattleArmor) attackerEntity).getShootingStrength(), -2); } return Compute - .missilesHit(((BattleArmor) ae).getShootingStrength()); + .missilesHit(((BattleArmor) attackerEntity).getShootingStrength()); } if (amsEngaged) { @@ -93,7 +93,7 @@ protected int calcHits(Vector vPhaseReport) { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcnCluster() */ @Override @@ -103,7 +103,7 @@ protected int calcnCluster() { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override @@ -120,10 +120,10 @@ protected int calcDamagePerHit() { bDirect ? toHit.getMoS() / 3 : 0, WeaponType.WEAPON_DIRECT_FIRE, ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); toReturn = Math.ceil(toReturn); } - + toReturn = applyGlancingBlowModifier(toReturn, target.isConventionalInfantry()); return (int) toReturn; } diff --git a/megamek/src/megamek/common/weapons/NarcHandler.java b/megamek/src/megamek/common/weapons/NarcHandler.java index b6d97bdd0d8..ee9b399758e 100644 --- a/megamek/src/megamek/common/weapons/NarcHandler.java +++ b/megamek/src/megamek/common/weapons/NarcHandler.java @@ -156,8 +156,8 @@ protected void handleEntityDamage(Entity entityTarget, Vector vPhaseReport, Building bldg, int hits, int nCluster, int bldgAbsorbs) { HitData hit = entityTarget.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); // If our narc pod "hits" an already-missing head, reroll until we hit // somewhere else as per the errata for torso-mounted cockpits. @@ -165,8 +165,8 @@ protected void handleEntityDamage(Entity entityTarget, && !narcCanAttachTo(entityTarget, Mek.LOC_HEAD)) { while (hit.getLocation() == Mek.LOC_HEAD) { hit = entityTarget.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); } } hit.setAttackerId(getAttackerId()); @@ -183,7 +183,7 @@ protected void handleEntityDamage(Entity entityTarget, } if (entityTarget.removePartialCoverHits(hit.getLocation(), toHit - .getCover(), Compute.targetSideTable(ae, entityTarget, weapon + .getCover(), Compute.targetSideTable(attackerEntity, entityTarget, weapon .getCalledShot().getCall()))) { // Weapon strikes Partial Cover. handlePartialCoverHit(entityTarget, vPhaseReport, hit, bldg, hits, @@ -212,7 +212,7 @@ protected void handleEntityDamage(Entity entityTarget, AmmoType atype = (AmmoType) ammo.getType(); if (atype.getAmmoType() == AmmoType.T_NARC) { // narced - NarcPod pod = new NarcPod(ae.getOwner().getTeam(), + NarcPod pod = new NarcPod(attackerEntity.getOwner().getTeam(), hit.getLocation()); Report r = new Report(3250); r.subject = subjectId; @@ -224,7 +224,7 @@ protected void handleEntityDamage(Entity entityTarget, // iNarced INarcPod pod = null; if (atype.getMunitionType().contains(AmmoType.Munitions.M_ECM)) { - pod = new INarcPod(ae.getOwner().getTeam(), INarcPod.ECM, + pod = new INarcPod(attackerEntity.getOwner().getTeam(), INarcPod.ECM, hit.getLocation()); Report r = new Report(3251); r.subject = subjectId; @@ -232,7 +232,7 @@ protected void handleEntityDamage(Entity entityTarget, r.add(entityTarget.getLocationAbbr(hit)); vPhaseReport.addElement(r); } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_HAYWIRE)) { - pod = new INarcPod(ae.getOwner().getTeam(), INarcPod.HAYWIRE, + pod = new INarcPod(attackerEntity.getOwner().getTeam(), INarcPod.HAYWIRE, hit.getLocation()); Report r = new Report(3252); r.subject = subjectId; @@ -240,7 +240,7 @@ protected void handleEntityDamage(Entity entityTarget, r.add(entityTarget.getLocationAbbr(hit)); vPhaseReport.addElement(r); } else if (atype.getMunitionType().contains(AmmoType.Munitions.M_NEMESIS)) { - pod = new INarcPod(ae.getOwner().getTeam(), INarcPod.NEMESIS, + pod = new INarcPod(attackerEntity.getOwner().getTeam(), INarcPod.NEMESIS, hit.getLocation()); Report r = new Report(3253); r.add(entityTarget.getDisplayName()); @@ -248,7 +248,7 @@ protected void handleEntityDamage(Entity entityTarget, r.subject = subjectId; vPhaseReport.addElement(r); } else { - pod = new INarcPod(ae.getOwner().getTeam(), INarcPod.HOMING, + pod = new INarcPod(attackerEntity.getOwner().getTeam(), INarcPod.HOMING, hit.getLocation()); Report r = new Report(3254); r.subject = subjectId; diff --git a/megamek/src/megamek/common/weapons/PPCHandler.java b/megamek/src/megamek/common/weapons/PPCHandler.java index d23c526b06b..14d842e36b2 100644 --- a/megamek/src/megamek/common/weapons/PPCHandler.java +++ b/megamek/src/megamek/common/weapons/PPCHandler.java @@ -58,42 +58,42 @@ public PPCHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { */ @Override protected int calcDamagePerHit() { - double toReturn = wtype.getDamage(nRange); + double toReturn = weaponType.getDamage(nRange); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_ENERGY_WEAPONS) && weapon.hasModes()) { - toReturn = Compute.dialDownDamage(weapon, wtype, nRange); + toReturn = Compute.dialDownDamage(weapon, weaponType, nRange); } if (chargedCapacitor != 0) { toReturn += 5; } // during a swarm, all damage gets applied as one block to one location - if ((ae instanceof BattleArmor) + if ((attackerEntity instanceof BattleArmor) && (weapon.getLocation() == BattleArmor.LOC_SQUAD) && !(weapon.isSquadSupportWeapon()) - && (ae.getSwarmTargetId() == target.getId())) { - toReturn *= ((BattleArmor) ae).getShootingStrength(); + && (attackerEntity.getSwarmTargetId() == target.getId())) { + toReturn *= ((BattleArmor) attackerEntity).getShootingStrength(); } // Check for Altered Damage from Energy Weapons (TacOps, pg.83) if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_ALTDMG)) { if (nRange <= 1) { toReturn++; - } else if (nRange <= wtype.getMediumRange()) { + } else if (nRange <= weaponType.getMediumRange()) { // Do Nothing for Short and Medium Range - } else if (nRange <= wtype.getLongRange()) { + } else if (nRange <= weaponType.getLongRange()) { toReturn--; } } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG])) { toReturn -= 1; } if (game.getOptions().booleanOption( OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { toReturn = (int) Math.floor(toReturn * .75); } @@ -105,9 +105,9 @@ protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage(toReturn, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); } else if (bDirect) { toReturn = Math.min(toReturn + (toHit.getMoS() / 3), toReturn * 2); } @@ -130,7 +130,7 @@ protected boolean doChecks(Vector vPhaseReport) { && weapon.curMode().equals("Field Inhibitor OFF")) { int rollTarget = 0; Roll diceRoll = Compute.rollD6(2); - int distance = Compute.effectiveDistance(game, ae, target); + int distance = Compute.effectiveDistance(game, attackerEntity, target); if (distance >= 3) { rollTarget = 3; @@ -156,8 +156,8 @@ protected boolean doChecks(Vector vPhaseReport) { int wlocation = weapon.getLocation(); weapon.setHit(true); // Destroy the first unmarked critical for the PPC - for (int i = 0; i < ae.getNumberOfCriticals(wlocation); i++) { - CriticalSlot slot1 = ae.getCritical(wlocation, i); + for (int i = 0; i < attackerEntity.getNumberOfCriticals(wlocation); i++) { + CriticalSlot slot1 = attackerEntity.getCritical(wlocation, i); if ((slot1 == null) || (slot1.getType() == CriticalSlot.TYPE_SYSTEM) || slot1.isHit()) { @@ -174,7 +174,7 @@ protected boolean doChecks(Vector vPhaseReport) { r.choose(false); r.indent(2); vPhaseReport.addElement(r); - Vector newReports = gameManager.damageEntity(ae, + Vector newReports = gameManager.damageEntity(attackerEntity, new HitData(wlocation), 10, false, DamageType.NONE, true); for (Report rep : newReports) { @@ -182,7 +182,7 @@ protected boolean doChecks(Vector vPhaseReport) { } vPhaseReport.addAll(newReports); // Deal 2 damage to the pilot - vPhaseReport.addAll(gameManager.damageCrew(ae, 2, ae.getCrew().getCurrentPilotIndex())); + vPhaseReport.addAll(gameManager.damageCrew(attackerEntity, 2, attackerEntity.getCrew().getCurrentPilotIndex())); r = new Report(3185); r.subject = subjectId; vPhaseReport.addElement(r); @@ -195,14 +195,14 @@ protected boolean doChecks(Vector vPhaseReport) { if (chargedCapacitor != 0) { if (roll.getIntValue() == 2) { Report r = new Report(3178); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.indent(); vPhaseReport.add(r); // Oops, we ruined our day... int wlocation = weapon.getLocation(); weapon.setHit(true); - for (int i = 0; i < ae.getNumberOfCriticals(wlocation); i++) { - CriticalSlot slot = ae.getCritical(wlocation, i); + for (int i = 0; i < attackerEntity.getNumberOfCriticals(wlocation); i++) { + CriticalSlot slot = attackerEntity.getCritical(wlocation, i); if ((slot == null) || (slot.getType() == CriticalSlot.TYPE_SYSTEM)) { continue; diff --git a/megamek/src/megamek/common/weapons/PlasmaBayWeaponHandler.java b/megamek/src/megamek/common/weapons/PlasmaBayWeaponHandler.java index fdc2881952c..4d47a661801 100644 --- a/megamek/src/megamek/common/weapons/PlasmaBayWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/PlasmaBayWeaponHandler.java @@ -105,7 +105,7 @@ protected void handleIgnitionDamage(Vector vPhaseReport, r.newlines = 0; vPhaseReport.addElement(r); } - TargetRoll tn = new TargetRoll(wtype.getFireTN(), wtype.getName()); + TargetRoll tn = new TargetRoll(weaponType.getFireTN(), weaponType.getName()); if (tn.getValue() != TargetRoll.IMPOSSIBLE) { Report.addNewline(vPhaseReport); gameManager.tryIgniteHex(target.getPosition(), subjectId, true, false, @@ -141,7 +141,7 @@ protected void handleClearDamage(Vector vPhaseReport, if ((bldg != null) && gameManager.tryIgniteHex(target.getPosition(), subjectId, true, false, - new TargetRoll(wtype.getFireTN(), wtype.getName()), 5, + new TargetRoll(weaponType.getFireTN(), weaponType.getName()), 5, vPhaseReport)) { return; } diff --git a/megamek/src/megamek/common/weapons/PlasmaCannonHandler.java b/megamek/src/megamek/common/weapons/PlasmaCannonHandler.java index 3567b245eff..689634bee0f 100644 --- a/megamek/src/megamek/common/weapons/PlasmaCannonHandler.java +++ b/megamek/src/megamek/common/weapons/PlasmaCannonHandler.java @@ -113,11 +113,11 @@ protected void handlePartialCoverHit(Entity entityTarget, Vector vPhaseR // We need to adjust some state and then restore it later // This allows us to make a call to handleEntityDamage ToHitData savedToHit = toHit; - AimingMode savedAimingMode = waa.getAimingMode(); - waa.setAimingMode(AimingMode.NONE); + AimingMode savedAimingMode = weaponAttackAction.getAimingMode(); + weaponAttackAction.setAimingMode(AimingMode.NONE); - int savedAimedLocation = waa.getAimedLocation(); - waa.setAimedLocation(Entity.LOC_NONE); + int savedAimedLocation = weaponAttackAction.getAimedLocation(); + weaponAttackAction.setAimedLocation(Entity.LOC_NONE); boolean savedSalvo = bSalvo; bSalvo = true; Targetable origTarget = target; @@ -125,7 +125,7 @@ protected void handlePartialCoverHit(Entity entityTarget, Vector vPhaseR hits = calcHits(vPhaseReport); // Create new toHitData toHit = new ToHitData(0, "", ToHitData.HIT_NORMAL, - Compute.targetSideTable(ae, coverDropShip)); + Compute.targetSideTable(attackerEntity, coverDropShip)); // Report cover was damaged int sizeBefore = vPhaseReport.size(); r = new Report(3465); @@ -146,8 +146,8 @@ protected void handlePartialCoverHit(Entity entityTarget, Vector vPhaseR } // Restore state toHit = savedToHit; - waa.setAimingMode(savedAimingMode); - waa.setAimedLocation(savedAimedLocation); + weaponAttackAction.setAimingMode(savedAimingMode); + weaponAttackAction.setAimedLocation(savedAimedLocation); bSalvo = savedSalvo; target = origTarget; // Damage a building that blocked a shot @@ -168,7 +168,7 @@ protected void handlePartialCoverHit(Entity entityTarget, Vector vPhaseR vPhaseReport.addAll(buildingReport); // Damage any infantry in the building. Vector infantryReport = gameManager.damageInfantryIn(coverBuilding, nDamage, - coverLoc, wtype.getInfantryDamageClass()); + coverLoc, weaponType.getInfantryDamageClass()); for (Report report : infantryReport) { report.indent(2); } @@ -183,12 +183,12 @@ protected void handleEntityDamage(Entity entityTarget, Vector vPhaseRepo if (entityTarget.tracksHeat()) { hit = entityTarget.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setGeneralDamageType(generalDamageType); hit.setAttackerId(getAttackerId()); if (entityTarget.removePartialCoverHits(hit.getLocation(), toHit.getCover(), - Compute.targetSideTable(ae, entityTarget, weapon.getCalledShot().getCall()))) { + Compute.targetSideTable(attackerEntity, entityTarget, weapon.getCalledShot().getCall()))) { // Weapon strikes Partial Cover. handlePartialCoverHit(entityTarget, vPhaseReport, hit, bldg, hits, nCluster, bldgAbsorbs); return; @@ -287,7 +287,7 @@ protected void handleIgnitionDamage(Vector vPhaseReport, Building bldg, r.newlines = 0; vPhaseReport.addElement(r); } - TargetRoll tn = new TargetRoll(wtype.getFireTN(), wtype.getName()); + TargetRoll tn = new TargetRoll(weaponType.getFireTN(), weaponType.getName()); if (tn.getValue() != TargetRoll.IMPOSSIBLE) { Report.addNewline(vPhaseReport); gameManager.tryIgniteHex(target.getPosition(), subjectId, true, false, @@ -322,7 +322,7 @@ protected void handleClearDamage(Vector vPhaseReport, Building bldg, int if ((bldg != null) && gameManager.tryIgniteHex(target.getPosition(), subjectId, true, false, - new TargetRoll(wtype.getFireTN(), wtype.getName()), 5, + new TargetRoll(weaponType.getFireTN(), weaponType.getName()), 5, vPhaseReport)) { return; } diff --git a/megamek/src/megamek/common/weapons/PlasmaMFUKWeaponHandler.java b/megamek/src/megamek/common/weapons/PlasmaMFUKWeaponHandler.java index ead002a430d..c9092dbdeaa 100644 --- a/megamek/src/megamek/common/weapons/PlasmaMFUKWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/PlasmaMFUKWeaponHandler.java @@ -88,7 +88,7 @@ protected void handleIgnitionDamage(Vector vPhaseReport, Building bldg, r.newlines = 0; vPhaseReport.addElement(r); } - TargetRoll tn = new TargetRoll(wtype.getFireTN(), wtype.getName()); + TargetRoll tn = new TargetRoll(weaponType.getFireTN(), weaponType.getName()); if (tn.getValue() != TargetRoll.IMPOSSIBLE) { Report.addNewline(vPhaseReport); gameManager.tryIgniteHex(target.getPosition(), subjectId, true, false, @@ -118,7 +118,7 @@ protected void handleClearDamage(Vector vPhaseReport, Building bldg, int // TODO : you do a normal ignition as though for intentional fires if ((bldg != null) && gameManager.tryIgniteHex(target.getPosition(), subjectId, true, false, - new TargetRoll(wtype.getFireTN(), wtype.getName()), 5, vPhaseReport)) { + new TargetRoll(weaponType.getFireTN(), weaponType.getName()), 5, vPhaseReport)) { return; } Vector clearReports = gameManager.tryClearHex(target.getPosition(), nDamage, subjectId); diff --git a/megamek/src/megamek/common/weapons/PlasmaRifleHandler.java b/megamek/src/megamek/common/weapons/PlasmaRifleHandler.java index 455b8579aae..bd198b169b5 100644 --- a/megamek/src/megamek/common/weapons/PlasmaRifleHandler.java +++ b/megamek/src/megamek/common/weapons/PlasmaRifleHandler.java @@ -47,7 +47,7 @@ protected void handleEntityDamage(Entity entityTarget, Vector vPhaseRepo // if this is a fighter squadron, we need to account for number of // weapons // should default to one for non squadrons - for (int i = 0; i < nweaponsHit; i++) { + for (int i = 0; i < numberOfWeaponHits; i++) { extraHeat += Compute.d6(); } if (entityTarget.getArmor(hit) > 0 @@ -82,12 +82,12 @@ protected int calcDamagePerHit() { toReturn = applyGlancingBlowModifier(toReturn, false); if (game.getOptions().booleanOption( OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG])) { toReturn -= 1; } if (game.getOptions().booleanOption( OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { toReturn = (int) Math.floor(toReturn / 2.0); } return toReturn; @@ -144,7 +144,7 @@ protected void handleIgnitionDamage(Vector vPhaseReport, Building bldg, r.newlines = 0; vPhaseReport.addElement(r); } - TargetRoll tn = new TargetRoll(wtype.getFireTN(), wtype.getName()); + TargetRoll tn = new TargetRoll(weaponType.getFireTN(), weaponType.getName()); if (tn.getValue() != TargetRoll.IMPOSSIBLE) { Report.addNewline(vPhaseReport); gameManager.tryIgniteHex(target.getPosition(), subjectId, true, false, @@ -179,7 +179,7 @@ protected void handleClearDamage(Vector vPhaseReport, Building bldg, int if ((bldg != null) && gameManager.tryIgniteHex(target.getPosition(), subjectId, true, false, - new TargetRoll(wtype.getFireTN(), wtype.getName()), 5, + new TargetRoll(weaponType.getFireTN(), weaponType.getName()), 5, vPhaseReport)) { return; } diff --git a/megamek/src/megamek/common/weapons/PopUpMineLauncherHandler.java b/megamek/src/megamek/common/weapons/PopUpMineLauncherHandler.java index 620b7320bb3..1c7b3fbdd3b 100644 --- a/megamek/src/megamek/common/weapons/PopUpMineLauncherHandler.java +++ b/megamek/src/megamek/common/weapons/PopUpMineLauncherHandler.java @@ -33,7 +33,7 @@ public class PopUpMineLauncherHandler extends AmmoWeaponHandler { public PopUpMineLauncherHandler(ToHitData toHit, WeaponAttackAction waa, Game g, TWGameManager m) { super(toHit, waa, g, m); - sSalvoType = " mine(s) "; + salvoType = " mine(s) "; } /* @@ -46,9 +46,9 @@ protected int calcHits(Vector vPhaseReport) { // conventional infantry gets hit in one lump // BAs do one lump of damage per BA suit if (target.isConventionalInfantry()) { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { bSalvo = true; - return ((BattleArmor) ae).getShootingStrength(); + return ((BattleArmor) attackerEntity).getShootingStrength(); } return 1; } @@ -60,7 +60,7 @@ protected int calcHits(Vector vPhaseReport) { Report r = new Report(3325); r.subject = subjectId; r.add(hits); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); @@ -82,8 +82,8 @@ protected void handleEntityDamage(Entity entityTarget, Vector vPhaseReport, Building bldg, int hits, int nCluster, int bldgAbsorbs) { HitData hit = entityTarget.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setAttackerId(getAttackerId()); if (target instanceof Mek) { hit = new HitData(Mek.LOC_CT); @@ -111,7 +111,7 @@ protected void handleEntityDamage(Entity entityTarget, hit, damage, false, - ae.getSwarmTargetId() == entityTarget.getId() ? DamageType.IGNORE_PASSENGER + attackerEntity.getSwarmTargetId() == entityTarget.getId() ? DamageType.IGNORE_PASSENGER : damageType, false, false, throughFront, underWater); @@ -141,7 +141,7 @@ protected void useAmmo() { // do we need to revert to single shot? if (nShots > 1) { - int nAvail = ae.getTotalAmmoOfType(ammo.getType()); + int nAvail = attackerEntity.getTotalAmmoOfType(ammo.getType()); while (nAvail < nShots) { nShots--; } @@ -150,7 +150,7 @@ protected void useAmmo() { // use up ammo for (int i = 0; i < nShots; i++) { if (ammo.getUsableShotsLeft() <= 0) { - ae.loadWeaponWithSameAmmo(weapon); + attackerEntity.loadWeaponWithSameAmmo(weapon); ammo = weapon.getLinked(); } ammo.setShotsLeft(ammo.getBaseShotsLeft() - 1); diff --git a/megamek/src/megamek/common/weapons/PrimitiveACWeaponHandler.java b/megamek/src/megamek/common/weapons/PrimitiveACWeaponHandler.java index 0307fbdd478..76dd1d2ed0e 100644 --- a/megamek/src/megamek/common/weapons/PrimitiveACWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/PrimitiveACWeaponHandler.java @@ -45,7 +45,7 @@ protected boolean doChecks(Vector vPhaseReport) { return true; } - if ((roll.getIntValue() == 2) && !ae.isConventionalInfantry()) { + if ((roll.getIntValue() == 2) && !attackerEntity.isConventionalInfantry()) { Report r = new Report(3161); r.subject = subjectId; r.newlines = 0; diff --git a/megamek/src/megamek/common/weapons/PrototypeACWeaponHandler.java b/megamek/src/megamek/common/weapons/PrototypeACWeaponHandler.java index 5b7b3a0d043..0cb62808771 100644 --- a/megamek/src/megamek/common/weapons/PrototypeACWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/PrototypeACWeaponHandler.java @@ -45,7 +45,7 @@ protected boolean doChecks(Vector vPhaseReport) { return true; } - if ((roll.getIntValue() == 2) && !ae.isConventionalInfantry()) { + if ((roll.getIntValue() == 2) && !attackerEntity.isConventionalInfantry()) { Report r = new Report(3165); r.subject = subjectId; weapon.setJammed(true); diff --git a/megamek/src/megamek/common/weapons/PrototypeCLUltraWeaponHandler.java b/megamek/src/megamek/common/weapons/PrototypeCLUltraWeaponHandler.java index f19fc27e1fa..c087e31a460 100644 --- a/megamek/src/megamek/common/weapons/PrototypeCLUltraWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/PrototypeCLUltraWeaponHandler.java @@ -39,17 +39,17 @@ public PrototypeCLUltraWeaponHandler(ToHitData t, WeaponAttackAction w, Game g, /* * (non-Javadoc) - * + * * @see megamek.common.weapons.UltraWeaponHandler#doChecks(java.util.Vector) */ @Override protected boolean doChecks(Vector vPhaseReport) { if (doAmmoFeedProblemCheck(vPhaseReport)) { return true; - } else if (ae.isConventionalInfantry()) { + } else if (attackerEntity.isConventionalInfantry()) { return false; } - + if ((roll.getIntValue() <= 3) && (howManyShots == 2)) { Report r = new Report(3160); r.subject = subjectId; diff --git a/megamek/src/megamek/common/weapons/PrototypeGaussHandler.java b/megamek/src/megamek/common/weapons/PrototypeGaussHandler.java index 69b98a970f5..47d9e95f840 100644 --- a/megamek/src/megamek/common/weapons/PrototypeGaussHandler.java +++ b/megamek/src/megamek/common/weapons/PrototypeGaussHandler.java @@ -45,7 +45,7 @@ public PrototypeGaussHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameMa /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#doChecks(java.util.Vector) */ @Override @@ -54,7 +54,7 @@ protected boolean doChecks(Vector vPhaseReport) { return true; } - if ((roll.getIntValue() == 2) && !ae.isConventionalInfantry()) { + if ((roll.getIntValue() == 2) && !attackerEntity.isConventionalInfantry()) { Report r = new Report(3165); r.subject = subjectId; weapon.setJammed(true); diff --git a/megamek/src/megamek/common/weapons/PrototypeISUltraWeaponHandler.java b/megamek/src/megamek/common/weapons/PrototypeISUltraWeaponHandler.java index 92ae4249cae..55f706f940d 100644 --- a/megamek/src/megamek/common/weapons/PrototypeISUltraWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/PrototypeISUltraWeaponHandler.java @@ -40,23 +40,23 @@ public PrototypeISUltraWeaponHandler(ToHitData t, WeaponAttackAction w, Game g, /* * (non-Javadoc) - * + * * @see megamek.common.weapons.UltraWeaponHandler#doChecks(java.util.Vector) */ @Override protected boolean doChecks(Vector vPhaseReport) { if (doAmmoFeedProblemCheck(vPhaseReport)) { return true; - } else if (ae.isConventionalInfantry()) { + } else if (attackerEntity.isConventionalInfantry()) { return false; } - + if (((roll.getIntValue() <= 4) && (howManyShots == 2)) || ((roll.getIntValue() == 2) && (howManyShots == 1))) { Report r = new Report(); r.subject = subjectId; weapon.setJammed(true); - if (wtype.getAmmoType() == AmmoType.T_AC_ULTRA) { + if (weaponType.getAmmoType() == AmmoType.T_AC_ULTRA) { r.messageId = 3160; weapon.setHit(true); } else { diff --git a/megamek/src/megamek/common/weapons/PrototypeLBXHandler.java b/megamek/src/megamek/common/weapons/PrototypeLBXHandler.java index 14fe0d020c6..e35a95b4437 100644 --- a/megamek/src/megamek/common/weapons/PrototypeLBXHandler.java +++ b/megamek/src/megamek/common/weapons/PrototypeLBXHandler.java @@ -42,7 +42,7 @@ public PrototypeLBXHandler(ToHitData t, WeaponAttackAction w, Game g, /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcHits(Vector * vPhaseReport) */ @@ -56,13 +56,13 @@ protected int calcHits(Vector vPhaseReport) { int shotMod = getClusterModifiers(true); shotMod -= 1; - int shotsHit = allShotsHit() ? wtype.getRackSize() : Compute - .missilesHit(wtype.getRackSize(), shotMod); + int shotsHit = allShotsHit() ? weaponType.getRackSize() : Compute + .missilesHit(weaponType.getRackSize(), shotMod); Report r = new Report(3325); r.subject = subjectId; r.add(shotsHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); @@ -75,7 +75,7 @@ protected int calcHits(Vector vPhaseReport) { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#doChecks(java.util.Vector) */ @Override @@ -83,8 +83,8 @@ protected boolean doChecks(Vector vPhaseReport) { if (doAmmoFeedProblemCheck(vPhaseReport)) { return true; } - - if ((roll.getIntValue() == 2) && !ae.isConventionalInfantry()) { + + if ((roll.getIntValue() == 2) && !attackerEntity.isConventionalInfantry()) { Report r = new Report(3165); r.subject = subjectId; weapon.setJammed(true); diff --git a/megamek/src/megamek/common/weapons/PrototypeLaserHandler.java b/megamek/src/megamek/common/weapons/PrototypeLaserHandler.java index 3098bb4df32..e78a1bc73fa 100644 --- a/megamek/src/megamek/common/weapons/PrototypeLaserHandler.java +++ b/megamek/src/megamek/common/weapons/PrototypeLaserHandler.java @@ -1,14 +1,14 @@ /** * MegaMek - Copyright (C) 2005 Ben Mazur (bmazur@sev.org) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ package megamek.common.weapons; @@ -26,7 +26,7 @@ public class PrototypeLaserHandler extends EnergyWeaponHandler { /** - * + * */ private static final long serialVersionUID = 6832340682515730916L; @@ -43,7 +43,7 @@ public PrototypeLaserHandler(ToHitData t, WeaponAttackAction w, Game g, /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#addHeat() */ @Override @@ -54,11 +54,11 @@ protected void addHeat() { } if (!(toHit.getValue() == TargetRoll.IMPOSSIBLE)) { super.addHeat(); - ae.heatBuildup += Compute.d6(); + attackerEntity.heatBuildup += Compute.d6(); } - + } - + } diff --git a/megamek/src/megamek/common/weapons/PulseLaserWeaponHandler.java b/megamek/src/megamek/common/weapons/PulseLaserWeaponHandler.java index 07ce462ee3b..8d5cd3aba1d 100644 --- a/megamek/src/megamek/common/weapons/PulseLaserWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/PulseLaserWeaponHandler.java @@ -40,7 +40,7 @@ protected boolean doChecks(Vector vPhaseReport) { return true; } - WeaponMounted laser = waa.getEntity(game).getWeapon(waa.getWeaponId()); + WeaponMounted laser = weaponAttackAction.getEntity(game).getWeapon(weaponAttackAction.getWeaponId()); if ((roll.getIntValue() == 2) && laser.curMode().equals("Pulse")) { vPhaseReport.addAll(gameManager.explodeEquipment(laser.getEntity(), laser.getLocation(), laser.getLinkedBy())); @@ -50,46 +50,46 @@ protected boolean doChecks(Vector vPhaseReport) { @Override protected int calcDamagePerHit() { - double toReturn = wtype.getDamage(); + double toReturn = weaponType.getDamage(); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_ENERGY_WEAPONS) && weapon.hasModes()) { - toReturn = Compute.dialDownDamage(weapon, wtype, nRange); + toReturn = Compute.dialDownDamage(weapon, weaponType, nRange); } // during a swarm, all damage gets applied as one block to one location - if ((ae instanceof BattleArmor) + if ((attackerEntity instanceof BattleArmor) && (weapon.getLocation() == BattleArmor.LOC_SQUAD) && !(weapon.isSquadSupportWeapon()) - && (ae.getSwarmTargetId() == target.getId())) { - toReturn *= ((BattleArmor) ae).getShootingStrength(); + && (attackerEntity.getSwarmTargetId() == target.getId())) { + toReturn *= ((BattleArmor) attackerEntity).getShootingStrength(); } // Check for Altered Damage from Energy Weapons (TacOp, pg.83) if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_ALTDMG)) { if (nRange <= 1) { toReturn++; - } else if (nRange <= wtype.getMediumRange()) { + } else if (nRange <= weaponType.getMediumRange()) { // Do Nothing for Short and Medium Range - } else if (nRange <= wtype.getLongRange()) { + } else if (nRange <= weaponType.getLongRange()) { toReturn--; } } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG])) { toReturn = (int) Math.floor(toReturn / 2.0); } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { toReturn = (int) Math.floor(toReturn / 3.0); } if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage(toReturn, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); } else if (bDirect) { toReturn = Math.min(toReturn + (toHit.getMoS() / 3), toReturn * 2); } diff --git a/megamek/src/megamek/common/weapons/RACHandler.java b/megamek/src/megamek/common/weapons/RACHandler.java index d53ea81d73d..1698c3eb675 100644 --- a/megamek/src/megamek/common/weapons/RACHandler.java +++ b/megamek/src/megamek/common/weapons/RACHandler.java @@ -17,7 +17,6 @@ import megamek.common.Entity; import megamek.common.Game; -import megamek.common.Infantry; import megamek.common.Report; import megamek.common.ToHitData; import megamek.common.actions.WeaponAttackAction; @@ -49,7 +48,7 @@ public RACHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { protected boolean doChecks(Vector vPhaseReport) { if (doAmmoFeedProblemCheck(vPhaseReport)) { return true; - } else if (ae.isConventionalInfantry()) { + } else if (attackerEntity.isConventionalInfantry()) { return false; } boolean jams = false; @@ -113,7 +112,7 @@ protected void useAmmo() { } // Reduce number of allowed shots to number of remaining rounds of ammo if applicable - int total = ae.getTotalAmmoOfType(ammo.getType()); + int total = attackerEntity.getTotalAmmoOfType(ammo.getType()); if (total < 0 ) { throw new RuntimeException("Invalid total ammo value < 0!"); } else if (total < 6) { diff --git a/megamek/src/megamek/common/weapons/RLHandler.java b/megamek/src/megamek/common/weapons/RLHandler.java index 0a1baa2ed24..eba3a1b5a15 100644 --- a/megamek/src/megamek/common/weapons/RLHandler.java +++ b/megamek/src/megamek/common/weapons/RLHandler.java @@ -1,14 +1,14 @@ /** * MegaMek - Copyright (C) 2007 Ben Mazur (bmazur@sev.org) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ package megamek.common.weapons; @@ -30,7 +30,7 @@ public class RLHandler extends MissileWeaponHandler { /** - * + * */ private static final long serialVersionUID = -3848472655779311898L; @@ -46,7 +46,7 @@ public RLHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { /* * (non-Javadoc) - * + * * @see * megamek.common.weapons.WeaponHandler#specialResolution(java.util.Vector, * megamek.common.Entity, boolean) @@ -66,7 +66,7 @@ protected boolean specialResolution(Vector vPhaseReport, ArrayList mfRemoved = new ArrayList<>(); while (minefields.hasMoreElements()) { Minefield mf = minefields.nextElement(); - if (gameManager.clearMinefield(mf, ae, + if (gameManager.clearMinefield(mf, attackerEntity, Minefield.CLEAR_NUMBER_WEAPON, vPhaseReport)) { mfRemoved.add(mf); } @@ -79,4 +79,4 @@ protected boolean specialResolution(Vector vPhaseReport, } return false; } -} \ No newline at end of file +} diff --git a/megamek/src/megamek/common/weapons/RapidfireACWeaponHandler.java b/megamek/src/megamek/common/weapons/RapidfireACWeaponHandler.java index 97d852fe119..1a0aba0a064 100644 --- a/megamek/src/megamek/common/weapons/RapidfireACWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/RapidfireACWeaponHandler.java @@ -23,7 +23,6 @@ import java.util.Vector; import megamek.common.Game; -import megamek.common.Infantry; import megamek.common.Report; import megamek.common.ToHitData; import megamek.common.actions.WeaponAttackAction; @@ -52,7 +51,7 @@ protected boolean doChecks(Vector vPhaseReport) { if (kindRapidFire) { jamLevel = 2; } - if ((roll.getIntValue() <= jamLevel) && (howManyShots == 2) && !ae.isConventionalInfantry()) { + if ((roll.getIntValue() <= jamLevel) && (howManyShots == 2) && !attackerEntity.isConventionalInfantry()) { if (roll.getIntValue() > 2 || kindRapidFire) { Report r = new Report(3161); r.subject = subjectId; diff --git a/megamek/src/megamek/common/weapons/RapidfireHVACWeaponHandler.java b/megamek/src/megamek/common/weapons/RapidfireHVACWeaponHandler.java index 5bfbf6047d1..7b4a32eaa32 100644 --- a/megamek/src/megamek/common/weapons/RapidfireHVACWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/RapidfireHVACWeaponHandler.java @@ -48,8 +48,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { PlanetaryConditions conditions = game.getPlanetaryConditions(); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_START_FIRE) && !conditions.getAtmosphere().isVacuum()) { - int rear = (ae.getFacing() + 3 + (weapon.isMekTurretMounted() ? weapon.getFacing() : 0)) % 6; - Coords src = ae.getPosition(); + int rear = (attackerEntity.getFacing() + 3 + (weapon.isMekTurretMounted() ? weapon.getFacing() : 0)) % 6; + Coords src = attackerEntity.getPosition(); Coords rearCoords = src.translated(rear); Board board = game.getBoard(); Hex currentHex = board.getHex(src); @@ -77,25 +77,25 @@ protected boolean doChecks(Vector vPhaseReport) { return true; } - if ((roll.getIntValue() == 2) && !ae.isConventionalInfantry()) { + if ((roll.getIntValue() == 2) && !attackerEntity.isConventionalInfantry()) { Report r = new Report(3162); r.subject = subjectId; weapon.setJammed(true); weapon.setHit(true); int wloc = weapon.getLocation(); - for (int i = 0; i < ae.getNumberOfCriticals(wloc); i++) { - CriticalSlot slot1 = ae.getCritical(wloc, i); + for (int i = 0; i < attackerEntity.getNumberOfCriticals(wloc); i++) { + CriticalSlot slot1 = attackerEntity.getCritical(wloc, i); if ((slot1 == null) || (slot1.getType() == CriticalSlot.TYPE_SYSTEM)) { continue; } Mounted mounted = slot1.getMount(); if (mounted.equals(weapon)) { - ae.hitAllCriticals(wloc, i); + attackerEntity.hitAllCriticals(wloc, i); break; } } - vPhaseReport.addAll(gameManager.explodeEquipment(ae, wloc, weapon)); + vPhaseReport.addAll(gameManager.explodeEquipment(attackerEntity, wloc, weapon)); r.choose(false); vPhaseReport.addElement(r); return false; diff --git a/megamek/src/megamek/common/weapons/RifleWeaponHandler.java b/megamek/src/megamek/common/weapons/RifleWeaponHandler.java index 5f91392b53c..b00cdcbdf9e 100644 --- a/megamek/src/megamek/common/weapons/RifleWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/RifleWeaponHandler.java @@ -50,20 +50,20 @@ public RifleWeaponHandler(ToHitData t, WeaponAttackAction w, Game g, /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override protected int calcDamagePerHit() { - double toReturn = wtype.getDamage(); + double toReturn = weaponType.getDamage(); // we default to direct fire weapons for anti-infantry damage if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage(toReturn, bDirect ? toHit.getMoS() : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); } else if (bDirect) { toReturn = Math.min(toReturn + (toHit.getMoS() / 3.0), toReturn * 2); } @@ -71,7 +71,7 @@ protected int calcDamagePerHit() { if (target instanceof Entity) { te = (Entity) target; hit = te.rollHitLocation(toHit.getHitTable(), toHit.getSideTable(), - waa.getAimedLocation(), waa.getAimingMode(), + weaponAttackAction.getAimedLocation(), weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setAttackerId(getAttackerId()); if (!(te instanceof Infantry) @@ -83,11 +83,11 @@ protected int calcDamagePerHit() { toReturn = applyGlancingBlowModifier(toReturn, target.isConventionalInfantry()); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG])) { toReturn = (int) Math.floor(toReturn * .75); } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { toReturn = (int) Math.floor(toReturn * .5); } @@ -104,7 +104,7 @@ protected void handleEntityDamage(Entity entityTarget, hit.setBoxCars(roll.getIntValue() == 12); if (entityTarget.removePartialCoverHits(hit.getLocation(), toHit - .getCover(), Compute.targetSideTable(ae, entityTarget, weapon + .getCover(), Compute.targetSideTable(attackerEntity, entityTarget, weapon .getCalledShot().getCall()))) { // Weapon strikes Partial Cover. handlePartialCoverHit(entityTarget, vPhaseReport, hit, bldg, hits, @@ -143,8 +143,8 @@ protected void handleEntityDamage(Entity entityTarget, // damage absorption by the partial cover, if it would have happened Hex targetHex = game.getBoard().getHex(target.getPosition()); boolean targetStickingOutOfBuilding = unitStickingOutOfBuilding(targetHex, entityTarget); - - nDamage = absorbBuildingDamage(nDamage, entityTarget, bldgAbsorbs, + + nDamage = absorbBuildingDamage(nDamage, entityTarget, bldgAbsorbs, vPhaseReport, bldg, targetStickingOutOfBuilding); @@ -169,13 +169,13 @@ protected void handleEntityDamage(Entity entityTarget, if (bGlancing) { hit.makeGlancingBlow(); } - + if (bLowProfileGlancing) { hit.makeGlancingBlow(); } vPhaseReport .addAll(gameManager.damageEntity(entityTarget, hit, nDamage, - false, ae.getSwarmTargetId() == entityTarget + false, attackerEntity.getSwarmTargetId() == entityTarget .getId() ? DamageType.IGNORE_PASSENGER : damageType, false, false, throughFront, underWater, nukeS2S)); diff --git a/megamek/src/megamek/common/weapons/SRMAXHandler.java b/megamek/src/megamek/common/weapons/SRMAXHandler.java index 2276aeeb145..2a31bdec17f 100644 --- a/megamek/src/megamek/common/weapons/SRMAXHandler.java +++ b/megamek/src/megamek/common/weapons/SRMAXHandler.java @@ -36,7 +36,7 @@ public class SRMAXHandler extends SRMHandler { public SRMAXHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " acid-head missile(s) "; + salvoType = " acid-head missile(s) "; nSalvoBonus = -2; damageType = DamageType.ACID; generalDamageType = HitData.DAMAGE_IGNORES_DMG_REDUCTION; diff --git a/megamek/src/megamek/common/weapons/SRMAntiTSMHandler.java b/megamek/src/megamek/common/weapons/SRMAntiTSMHandler.java index b1d4811e56f..472fd895c7a 100644 --- a/megamek/src/megamek/common/weapons/SRMAntiTSMHandler.java +++ b/megamek/src/megamek/common/weapons/SRMAntiTSMHandler.java @@ -36,7 +36,7 @@ public class SRMAntiTSMHandler extends SRMSmokeWarheadHandler { public SRMAntiTSMHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " anti-TSM missile(s) "; + salvoType = " anti-TSM missile(s) "; damageType = DamageType.ANTI_TSM; } @@ -45,9 +45,9 @@ protected int calcHits(Vector vPhaseReport) { // conventional infantry gets hit in one lump // BAs do one lump of damage per BA suit if (target.isConventionalInfantry()) { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { bSalvo = true; - return ((BattleArmor) ae).getShootingStrength(); + return ((BattleArmor) attackerEntity).getShootingStrength(); } return 1; } @@ -68,19 +68,19 @@ protected int calcHits(Vector vPhaseReport) { if (allShotsHit()) { // We want buildings and large craft to be able to affect this number with AMS // treat as a Streak launcher (cluster roll 11) to make this happen - missilesHit = Compute.missilesHit(wtype.getRackSize(), + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier, weapon.isHotLoaded(), true, isAdvancedAMS()); } else { // anti tsm hit with half the normal number, round up - missilesHit = Compute.missilesHit(wtype.getRackSize(), + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier, weapon.isHotLoaded(), false, isAdvancedAMS()); missilesHit = (int) Math.ceil((double) missilesHit / 2); } Report r = new Report(3325); r.subject = subjectId; r.add(missilesHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); diff --git a/megamek/src/megamek/common/weapons/SRMDeadFireHandler.java b/megamek/src/megamek/common/weapons/SRMDeadFireHandler.java index aaaf7d3e250..63c0e2b441e 100644 --- a/megamek/src/megamek/common/weapons/SRMDeadFireHandler.java +++ b/megamek/src/megamek/common/weapons/SRMDeadFireHandler.java @@ -37,7 +37,7 @@ public class SRMDeadFireHandler extends SRMHandler { public SRMDeadFireHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " dead fire missile(s) "; + salvoType = " dead fire missile(s) "; } @Override @@ -49,10 +49,10 @@ protected int getClusterModifiers(boolean clusterRangePenalty) { protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { double toReturn = Compute.directBlowInfantryDamage( - wtype.getRackSize() * 3, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getRackSize() * 3, bDirect ? toHit.getMoS() / 3 : 0, + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); toReturn = applyGlancingBlowModifier(toReturn, true); return (int) toReturn; diff --git a/megamek/src/megamek/common/weapons/SRMFragHandler.java b/megamek/src/megamek/common/weapons/SRMFragHandler.java index db8ebab51ff..a4124c2ebde 100644 --- a/megamek/src/megamek/common/weapons/SRMFragHandler.java +++ b/megamek/src/megamek/common/weapons/SRMFragHandler.java @@ -35,7 +35,7 @@ public class SRMFragHandler extends SRMHandler { public SRMFragHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " fragmentation missile(s) "; + salvoType = " fragmentation missile(s) "; damageType = DamageType.FRAGMENTATION; } @@ -48,15 +48,15 @@ public SRMFragHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m protected int calcDamagePerHit() { double toReturn = 2; // during a swarm, all damage gets applied as one block to one location - if ((ae instanceof BattleArmor) + if ((attackerEntity instanceof BattleArmor) && (weapon.getLocation() == BattleArmor.LOC_SQUAD) && !(weapon.isSquadSupportWeapon()) - && (ae.getSwarmTargetId() == target.getId())) { - toReturn *= ((BattleArmor) ae).getShootingStrength(); + && (attackerEntity.getSwarmTargetId() == target.getId())) { + toReturn *= ((BattleArmor) attackerEntity).getShootingStrength(); } // against infantry, we have 1 hit if (target.isConventionalInfantry()) { - toReturn *= wtype.getRackSize(); + toReturn *= weaponType.getRackSize(); if (bDirect) { toReturn += toHit.getMoS() / 3.0; } @@ -95,7 +95,7 @@ protected void handleClearDamage(Vector vPhaseReport, Building bldg, int if ((bldg != null) && gameManager.tryIgniteHex(target.getPosition(), subjectId, false, false, - new TargetRoll(wtype.getFireTN(), wtype.getName()), 5, + new TargetRoll(weaponType.getFireTN(), weaponType.getName()), 5, vPhaseReport)) { return; } diff --git a/megamek/src/megamek/common/weapons/SRMHandler.java b/megamek/src/megamek/common/weapons/SRMHandler.java index b584912c0a5..a65c1d3b684 100644 --- a/megamek/src/megamek/common/weapons/SRMHandler.java +++ b/megamek/src/megamek/common/weapons/SRMHandler.java @@ -48,10 +48,10 @@ public SRMHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m, in protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { double toReturn = Compute.directBlowInfantryDamage( - wtype.getRackSize() * 2, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getRackSize() * 2, bDirect ? toHit.getMoS() / 3 : 0, + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); toReturn = applyGlancingBlowModifier(toReturn, true); diff --git a/megamek/src/megamek/common/weapons/SRMInfernoHandler.java b/megamek/src/megamek/common/weapons/SRMInfernoHandler.java index 506f7e5adba..feb549d3db5 100644 --- a/megamek/src/megamek/common/weapons/SRMInfernoHandler.java +++ b/megamek/src/megamek/common/weapons/SRMInfernoHandler.java @@ -47,7 +47,7 @@ public class SRMInfernoHandler extends SRMHandler { public SRMInfernoHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); damageType = DamageType.INFERNO; - sSalvoType = " inferno missile(s) "; + salvoType = " inferno missile(s) "; bSalvo = false; } @@ -67,7 +67,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { entityTarget); final boolean bldgDamagedOnMiss = targetInBuilding && !(target instanceof Infantry) - && ae.getPosition().distance(target.getPosition()) <= 1; + && attackerEntity.getPosition().distance(target.getPosition()) <= 1; // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); @@ -77,7 +77,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName() + " (" + atype.getShortName() + ")"); + r.add(weaponType.getName() + " (" + ammoType.getShortName() + ")"); if (entityTarget != null) { r.addDesc(entityTarget); } else { @@ -132,7 +132,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && ((toHit.getMoS() / 3) >= 1) && (entityTarget != null); if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -167,7 +167,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { } // End missed-target // light inferno missiles all at once, if not missed - vPhaseReport.addAll(gameManager.deliverInfernoMissiles(ae, target, hits, weapon.getCalledShot().getCall())); + vPhaseReport.addAll(gameManager.deliverInfernoMissiles(attackerEntity, target, hits, weapon.getCalledShot().getCall())); return false; } @@ -176,23 +176,23 @@ protected int calcHits(Vector vPhaseReport) { // conventional infantry gets hit with all missiles // BAs do one lump of damage per BA suit if (target.isConventionalInfantry()) { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { bSalvo = true; Report r = new Report(3325); r.subject = subjectId; - r.add(wtype.getRackSize() * ((BattleArmor) ae).getShootingStrength()); - r.add(sSalvoType); + r.add(weaponType.getRackSize() * ((BattleArmor) attackerEntity).getShootingStrength()); + r.add(salvoType); r.add(toHit.getTableDesc()); vPhaseReport.add(r); - return ((BattleArmor) ae).getShootingStrength() * wtype.getRackSize(); + return ((BattleArmor) attackerEntity).getShootingStrength() * weaponType.getRackSize(); } Report r = new Report(3325); r.subject = subjectId; - r.add(wtype.getRackSize()); - r.add(sSalvoType); + r.add(weaponType.getRackSize()); + r.add(salvoType); r.add(toHit.getTableDesc()); vPhaseReport.add(r); - return wtype.getRackSize(); + return weaponType.getRackSize(); } int missilesHit; int nMissilesModifier = getClusterModifiers(true); @@ -211,17 +211,17 @@ protected int calcHits(Vector vPhaseReport) { if (allShotsHit()) { // We want buildings and large craft to be able to affect this number with AMS // treat as a Streak launcher (cluster roll 11) to make this happen - missilesHit = Compute.missilesHit(wtype.getRackSize(), + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier, weapon.isHotLoaded(), true, isAdvancedAMS()); } else { - if (ae instanceof BattleArmor) { - missilesHit = Compute.missilesHit(wtype.getRackSize() - * ((BattleArmor) ae).getShootingStrength(), + if (attackerEntity instanceof BattleArmor) { + missilesHit = Compute.missilesHit(weaponType.getRackSize() + * ((BattleArmor) attackerEntity).getShootingStrength(), nMissilesModifier, weapon.isHotLoaded(), false, isAdvancedAMS()); } else { - missilesHit = Compute.missilesHit(wtype.getRackSize(), + missilesHit = Compute.missilesHit(weaponType.getRackSize(), nMissilesModifier, weapon.isHotLoaded(), false, isAdvancedAMS()); } @@ -231,7 +231,7 @@ protected int calcHits(Vector vPhaseReport) { Report r = new Report(3325); r.subject = subjectId; r.add(missilesHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); diff --git a/megamek/src/megamek/common/weapons/SRMSmokeWarheadHandler.java b/megamek/src/megamek/common/weapons/SRMSmokeWarheadHandler.java index 8dd559bcfd5..b73db235636 100644 --- a/megamek/src/megamek/common/weapons/SRMSmokeWarheadHandler.java +++ b/megamek/src/megamek/common/weapons/SRMSmokeWarheadHandler.java @@ -48,7 +48,7 @@ protected boolean specialResolution(Vector vPhaseReport, Entity entityTa if (!bMissed) { Report r = new Report(3190); r.subject = subjectId; - r.player = ae.getOwnerId(); + r.player = attackerEntity.getOwnerId(); r.add(coords.getBoardNum()); vPhaseReport.addElement(r); } else { @@ -71,7 +71,7 @@ protected boolean specialResolution(Vector vPhaseReport, Entity entityTa // Handle munitions. if (atype.getMunitionType().contains(AmmoType.Munitions.M_SMOKE_WARHEAD)) { - int damage = wtype.getRackSize() * calcDamagePerHit(); + int damage = weaponType.getRackSize() * calcDamagePerHit(); int smokeType = SmokeCloud.SMOKE_LIGHT; if (damage > 5) { smokeType = SmokeCloud.SMOKE_HEAVY; diff --git a/megamek/src/megamek/common/weapons/SRMTandemChargeHandler.java b/megamek/src/megamek/common/weapons/SRMTandemChargeHandler.java index f12c55246b9..82ec193d989 100644 --- a/megamek/src/megamek/common/weapons/SRMTandemChargeHandler.java +++ b/megamek/src/megamek/common/weapons/SRMTandemChargeHandler.java @@ -35,7 +35,7 @@ public class SRMTandemChargeHandler extends SRMHandler { public SRMTandemChargeHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); - sSalvoType = " tandem charge missile(s) "; + salvoType = " tandem charge missile(s) "; generalDamageType = HitData.DAMAGE_ARMOR_PIERCING_MISSILE; } @@ -46,12 +46,12 @@ protected void handleEntityDamage(Entity entityTarget, missed = false; HitData hit = entityTarget.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setGeneralDamageType(generalDamageType); hit.setAttackerId(getAttackerId()); if (entityTarget.removePartialCoverHits(hit.getLocation(), toHit - .getCover(), Compute.targetSideTable(ae, entityTarget, weapon + .getCover(), Compute.targetSideTable(attackerEntity, entityTarget, weapon .getCalledShot().getCall()))) { // Weapon strikes Partial Cover. handlePartialCoverHit(entityTarget, vPhaseReport, hit, bldg, hits, @@ -135,7 +135,7 @@ protected void handleEntityDamage(Entity entityTarget, } vPhaseReport .addAll(gameManager.damageEntity(entityTarget, hit, nDamage, - false, ae.getSwarmTargetId() == entityTarget + false, attackerEntity.getSwarmTargetId() == entityTarget .getId() ? DamageType.IGNORE_PASSENGER : DamageType.NONE, false, false, throughFront, underWater)); @@ -146,10 +146,10 @@ protected void handleEntityDamage(Entity entityTarget, protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { double toReturn = Compute.directBlowInfantryDamage( - wtype.getRackSize(), bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getRackSize(), bDirect ? toHit.getMoS() / 3 : 0, + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); toReturn = applyGlancingBlowModifier(toReturn, true); diff --git a/megamek/src/megamek/common/weapons/ScreenLauncherBayHandler.java b/megamek/src/megamek/common/weapons/ScreenLauncherBayHandler.java index 87470aa7f4a..f4ed178054b 100644 --- a/megamek/src/megamek/common/weapons/ScreenLauncherBayHandler.java +++ b/megamek/src/megamek/common/weapons/ScreenLauncherBayHandler.java @@ -1,14 +1,14 @@ /** * MegaMek - Copyright (C) 2005 Ben Mazur (bmazur@sev.org) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ package megamek.common.weapons; @@ -33,7 +33,7 @@ public class ScreenLauncherBayHandler extends AmmoBayWeaponHandler { /** - * + * */ private static final long serialVersionUID = -1618484541772117621L; @@ -51,7 +51,7 @@ public ScreenLauncherBayHandler(ToHitData t, WeaponAttackAction w, Game g, /** * handle this weapons firing - * + * * @return a boolean value indicating wether this should be * kept or not */ @@ -70,7 +70,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName()); + r.add(weaponType.getName()); r.messageId = 3120; r.add(target.getDisplayName(), true); vPhaseReport.addElement(r); @@ -112,7 +112,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { HitData hit = ent.rollHitLocation(squadronToHit.getHitTable(), ToHitData.SIDE_FRONT); hit.setCapital(false); vPhaseReport.addAll(gameManager.damageEntity(ent, hit, attackValue)); - gameManager.creditKill(ent, ae); + gameManager.creditKill(ent, attackerEntity); }); } else { ToHitData hexToHit = new ToHitData(); @@ -120,7 +120,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { HitData hit = entity.rollHitLocation(hexToHit.getHitTable(), ToHitData.SIDE_FRONT); hit.setCapital(false); vPhaseReport.addAll(gameManager.damageEntity(entity, hit, attackValue)); - gameManager.creditKill(entity, ae); + gameManager.creditKill(entity, attackerEntity); } } } diff --git a/megamek/src/megamek/common/weapons/ScreenLauncherHandler.java b/megamek/src/megamek/common/weapons/ScreenLauncherHandler.java index c1fe7b7cfa1..2e97d2ccd05 100644 --- a/megamek/src/megamek/common/weapons/ScreenLauncherHandler.java +++ b/megamek/src/megamek/common/weapons/ScreenLauncherHandler.java @@ -1,14 +1,14 @@ /** * MegaMek - Copyright (C) 2005 Ben Mazur (bmazur@sev.org) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ package megamek.common.weapons; @@ -33,7 +33,7 @@ public class ScreenLauncherHandler extends AmmoWeaponHandler { /** - * + * */ private static final long serialVersionUID = -2536312899803153911L; @@ -50,7 +50,7 @@ public ScreenLauncherHandler(ToHitData t, WeaponAttackAction w, Game g, /** * handle this weapons firing - * + * * @return a boolean value indicating wether this should be * kept or not */ @@ -65,7 +65,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.indent(); r.newlines = 0; r.subject = subjectId; - r.add(wtype.getName()); + r.add(weaponType.getName()); r.messageId = 3120; r.add(target.getDisplayName(), true); vPhaseReport.addElement(r); @@ -106,7 +106,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { HitData hit = ent.rollHitLocation(squadronToHit.getHitTable(), ToHitData.SIDE_FRONT); hit.setCapital(false); vPhaseReport.addAll(gameManager.damageEntity(ent, hit, attackValue)); - gameManager.creditKill(ent, ae); + gameManager.creditKill(ent, attackerEntity); }); } else { ToHitData hexToHit = new ToHitData(); @@ -114,7 +114,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { HitData hit = entity.rollHitLocation(hexToHit.getHitTable(), ToHitData.SIDE_FRONT); hit.setCapital(false); vPhaseReport.addAll(gameManager.damageEntity(entity, hit, attackValue)); - gameManager.creditKill(entity, ae); + gameManager.creditKill(entity, attackerEntity); } } return false; diff --git a/megamek/src/megamek/common/weapons/SmallPulseLaserPrototypeHandler.java b/megamek/src/megamek/common/weapons/SmallPulseLaserPrototypeHandler.java index 9a644334959..182911a95c7 100644 --- a/megamek/src/megamek/common/weapons/SmallPulseLaserPrototypeHandler.java +++ b/megamek/src/megamek/common/weapons/SmallPulseLaserPrototypeHandler.java @@ -1,14 +1,14 @@ /** * MegaMek - Copyright (C) 2005 Ben Mazur (bmazur@sev.org) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ package megamek.common.weapons; @@ -26,7 +26,7 @@ public class SmallPulseLaserPrototypeHandler extends EnergyWeaponHandler { /** - * + * */ private static final long serialVersionUID = 6832340682515730916L; @@ -43,7 +43,7 @@ public SmallPulseLaserPrototypeHandler(ToHitData t, WeaponAttackAction w, Game g /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#addHeat() */ @Override @@ -54,11 +54,11 @@ protected void addHeat() { } if (!(toHit.getValue() == TargetRoll.IMPOSSIBLE)) { super.addHeat(); - ae.heatBuildup += Compute.d6()/2; + attackerEntity.heatBuildup += Compute.d6()/2; } - + } - + } diff --git a/megamek/src/megamek/common/weapons/SpaceBombAttackHandler.java b/megamek/src/megamek/common/weapons/SpaceBombAttackHandler.java index edeb9d2c7d1..9a7fd05e9fd 100644 --- a/megamek/src/megamek/common/weapons/SpaceBombAttackHandler.java +++ b/megamek/src/megamek/common/weapons/SpaceBombAttackHandler.java @@ -54,7 +54,7 @@ public SpaceBombAttackHandler(ToHitData toHit, WeaponAttackAction waa, Game g, T */ @Override protected int calcAttackValue() { - int[] payload = waa.getBombPayload(); + int[] payload = weaponAttackAction.getBombPayload(); if (null == payload) { return 0; } @@ -82,18 +82,18 @@ protected boolean usesClusterTable() { @Override protected void useAmmo() { - int[] payload = waa.getBombPayload(); - if (!(ae.isAero()) || null == payload) { + int[] payload = weaponAttackAction.getBombPayload(); + if (!(attackerEntity.isAero()) || null == payload) { return; } // Need to remove ammo from fighters within a squadron - if (ae instanceof FighterSquadron) { + if (attackerEntity instanceof FighterSquadron) { // In a fighter squadron, we will haved dropped a salvo of bombs. // The salvo consists of one bomb from each fighter equipped with // a bomb of the proper type. for (int type = 0; type < payload.length; type++) { - List activeFighters = ae.getActiveSubEntities(); + List activeFighters = attackerEntity.getActiveSubEntities(); if (activeFighters.isEmpty()) { break; } @@ -125,7 +125,7 @@ protected void useAmmo() { if (payload[type] > 0) { double numSalvos = Math.ceil((payload[type] + 0.0) / activeFighters.size()); for (int salvo = 0; salvo < numSalvos; salvo++) { - for (Mounted bomb : ae.getBombs()) { + for (Mounted bomb : attackerEntity.getBombs()) { if (((BombType) bomb.getType()).getBombType() == type && !bomb.isDestroyed() && bomb.getUsableShotsLeft() > 0) { @@ -140,7 +140,7 @@ protected void useAmmo() { for (int type = 0; type < payload.length; type++) { for (int i = 0; i < payload[type]; i++) { // find the first mounted bomb of this type and drop it - for (Mounted bomb : ae.getBombs()) { + for (Mounted bomb : attackerEntity.getBombs()) { if (((BombType) bomb.getType()).getBombType() == type && !bomb.isDestroyed() && bomb.getUsableShotsLeft() > 0) { diff --git a/megamek/src/megamek/common/weapons/StopSwarmAttackHandler.java b/megamek/src/megamek/common/weapons/StopSwarmAttackHandler.java index 448d9d9696e..1604dfe866b 100644 --- a/megamek/src/megamek/common/weapons/StopSwarmAttackHandler.java +++ b/megamek/src/megamek/common/weapons/StopSwarmAttackHandler.java @@ -1,14 +1,14 @@ /* * MegaMek - Copyright (C) 2004, 2005 Ben Mazur (bmazur@sev.org) * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ package megamek.common.weapons; @@ -43,7 +43,7 @@ public StopSwarmAttackHandler(ToHitData toHit, WeaponAttackAction waa, /* * (non-Javadoc) - * + * * @see megamek.common.weapons.AttackHandler#handle(int, java.util.Vector) */ @Override @@ -62,16 +62,16 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { r.subject = subjectId; vPhaseReport.addElement(r); // Only apply the "stop swarm 'attack'" to the swarmed Mek. - if (ae.getSwarmTargetId() != target.getId()) { - Entity other = game.getEntity(ae.getSwarmTargetId()); - + if (attackerEntity.getSwarmTargetId() != target.getId()) { + Entity other = game.getEntity(attackerEntity.getSwarmTargetId()); + if (other != null) { other.setSwarmAttackerId(Entity.NONE); } } else { entityTarget.setSwarmAttackerId(Entity.NONE); } - ae.setSwarmTargetId(Entity.NONE); + attackerEntity.setSwarmTargetId(Entity.NONE); return false; } } diff --git a/megamek/src/megamek/common/weapons/StreakHandler.java b/megamek/src/megamek/common/weapons/StreakHandler.java index 73d2fe9f65a..674f84d8d48 100644 --- a/megamek/src/megamek/common/weapons/StreakHandler.java +++ b/megamek/src/megamek/common/weapons/StreakHandler.java @@ -30,7 +30,7 @@ public class StreakHandler extends MissileWeaponHandler { private static final MMLogger logger = MMLogger.create(StreakHandler.class); private static final long serialVersionUID = 4122111574368642492L; - boolean isAngelECMAffected = ComputeECM.isAffectedByAngelECM(ae, ae.getPosition(), target.getPosition()); + boolean isAngelECMAffected = ComputeECM.isAffectedByAngelECM(attackerEntity, attackerEntity.getPosition(), target.getPosition()); /** * @param t @@ -46,10 +46,10 @@ public StreakHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { return Compute.directBlowInfantryDamage( - wtype.getRackSize() * 2, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getRackSize() * 2, bDirect ? toHit.getMoS() / 3 : 0, + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); } return 2; } @@ -64,9 +64,9 @@ protected int calcHits(Vector vPhaseReport) { // conventional infantry gets hit in one lump // BAs do one lump of damage per BA suit if (target.isConventionalInfantry()) { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { bSalvo = true; - return ((BattleArmor) ae).getShootingStrength(); + return ((BattleArmor) attackerEntity).getShootingStrength(); } return 1; } @@ -88,9 +88,9 @@ protected int calcHits(Vector vPhaseReport) { } if (amsMod == 0 && allShotsHit()) { - missilesHit = wtype.getRackSize(); + missilesHit = weaponType.getRackSize(); } else { - missilesHit = Compute.missilesHit(wtype.getRackSize(), amsMod + nMissilesModifier, + missilesHit = Compute.missilesHit(weaponType.getRackSize(), amsMod + nMissilesModifier, weapon.isHotLoaded(), allShotsHit(), isAdvancedAMS()); if (amsMod != 0) { Report r; @@ -110,7 +110,7 @@ protected int calcHits(Vector vPhaseReport) { Report r = new Report(3325); r.subject = subjectId; r.add(missilesHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); @@ -133,13 +133,13 @@ protected void useAmmo() { } if (ammo.getUsableShotsLeft() <= 0) { - ae.loadWeaponWithSameAmmo(weapon); + attackerEntity.loadWeaponWithSameAmmo(weapon); ammo = weapon.getLinked(); } if (roll.getIntValue() >= toHit.getValue()) { ammo.setShotsLeft(ammo.getBaseShotsLeft() - 1); - if (wtype.hasFlag(WeaponType.F_ONESHOT)) { + if (weaponType.hasFlag(WeaponType.F_ONESHOT)) { weapon.setFired(true); } setDone(); diff --git a/megamek/src/megamek/common/weapons/StreakLRMHandler.java b/megamek/src/megamek/common/weapons/StreakLRMHandler.java index d6e6b754475..83cdd3d1142 100644 --- a/megamek/src/megamek/common/weapons/StreakLRMHandler.java +++ b/megamek/src/megamek/common/weapons/StreakLRMHandler.java @@ -44,24 +44,24 @@ public StreakLRMHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { return Compute.directBlowInfantryDamage( - wtype.getRackSize(), bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getRackSize(), bDirect ? toHit.getMoS() / 3 : 0, + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); } return 1; } /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcnCluster() */ @Override @@ -71,7 +71,7 @@ protected int calcnCluster() { /* * (non-Javadoc) - * + * * @see * megamek.common.weapons.WeaponHandler#specialResolution(java.util.Vector, * megamek.common.Entity, boolean) @@ -89,7 +89,7 @@ protected boolean specialResolution(Vector vPhaseReport, Entity entityTa ArrayList mfRemoved = new ArrayList<>(); while (minefields.hasMoreElements()) { Minefield mf = minefields.nextElement(); - if (gameManager.clearMinefield(mf, ae, + if (gameManager.clearMinefield(mf, attackerEntity, Minefield.CLEAR_NUMBER_WEAPON, vPhaseReport)) { mfRemoved.add(mf); } @@ -102,4 +102,4 @@ protected boolean specialResolution(Vector vPhaseReport, Entity entityTa } return false; } -} \ No newline at end of file +} diff --git a/megamek/src/megamek/common/weapons/SwarmAttackHandler.java b/megamek/src/megamek/common/weapons/SwarmAttackHandler.java index c8034637329..a1a13051de2 100644 --- a/megamek/src/megamek/common/weapons/SwarmAttackHandler.java +++ b/megamek/src/megamek/common/weapons/SwarmAttackHandler.java @@ -1,14 +1,14 @@ /* * MegaMek - Copyright (C) 2004, 2005 Ben Mazur (bmazur@sev.org) * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ package megamek.common.weapons; @@ -64,14 +64,14 @@ else if (entityTarget.isDoomed() || entityTarget.isDestroyed() r = new Report(3275); r.subject = subjectId; vPhaseReport.addElement(r); - ae.setSwarmTargetId(waa.getTargetId()); - entityTarget.setSwarmAttackerId(waa.getEntityId()); + attackerEntity.setSwarmTargetId(weaponAttackAction.getTargetId()); + entityTarget.setSwarmAttackerId(weaponAttackAction.getEntityId()); } } /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcHits(java.util.Vector) */ @Override diff --git a/megamek/src/megamek/common/weapons/SwarmWeaponAttackHandler.java b/megamek/src/megamek/common/weapons/SwarmWeaponAttackHandler.java index 50ce9fdcf88..13b75191b5e 100644 --- a/megamek/src/megamek/common/weapons/SwarmWeaponAttackHandler.java +++ b/megamek/src/megamek/common/weapons/SwarmWeaponAttackHandler.java @@ -1,14 +1,14 @@ /* * MegaMek - Copyright (C) 2004, 2005 Ben Mazur (bmazur@sev.org) * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) * any later version. * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. */ package megamek.common.weapons; @@ -44,8 +44,8 @@ public SwarmWeaponAttackHandler(ToHitData toHit, WeaponAttackAction waa, @Override protected int calcDamagePerHit() { int damage = 0; - if (ae instanceof BattleArmor) { - BattleArmor ba = (BattleArmor) ae; + if (attackerEntity instanceof BattleArmor) { + BattleArmor ba = (BattleArmor) attackerEntity; damage = ba.calculateSwarmDamage(); } // should this be affected by direct blows? @@ -58,7 +58,7 @@ protected int calcDamagePerHit() { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcHits(java.util.Vector) */ @Override diff --git a/megamek/src/megamek/common/weapons/TAGHandler.java b/megamek/src/megamek/common/weapons/TAGHandler.java index 8095fe217fd..3135824bb0b 100644 --- a/megamek/src/megamek/common/weapons/TAGHandler.java +++ b/megamek/src/megamek/common/weapons/TAGHandler.java @@ -47,19 +47,19 @@ protected void handleEntityDamage(Entity entityTarget, Vector vPhaseRepo vPhaseReport.addElement(r); } else { - TagInfo info = new TagInfo(ae.getId(), Targetable.TYPE_ENTITY, + TagInfo info = new TagInfo(attackerEntity.getId(), Targetable.TYPE_ENTITY, entityTarget, false); game.addTagInfo(info); - entityTarget.setTaggedBy(ae.getId()); + entityTarget.setTaggedBy(attackerEntity.getId()); if (weapon.isInternalBomb()) { // Firing an internally-mounted TAG pod counts for bomb bay explosion check - ((IBomber) ae).increaseUsedInternalBombs(1); + ((IBomber) attackerEntity).increaseUsedInternalBombs(1); } // per errata, being painted by a TAG also spots the target for indirect fire - ae.setSpotting(true); - ae.setSpotTargetId(entityTarget.getId()); + attackerEntity.setSpotting(true); + attackerEntity.setSpotTargetId(entityTarget.getId()); Report r = new Report(3188); r.subject = subjectId; @@ -71,7 +71,7 @@ protected void handleEntityDamage(Entity entityTarget, Vector vPhaseRepo protected boolean handleSpecialMiss(Entity entityTarget, boolean bldgDamagedOnMiss, Building bldg, Vector vPhaseReport) { // add even misses, as they waste homing missiles. - TagInfo info = new TagInfo(ae.getId(), target.getTargetType(), target, true); + TagInfo info = new TagInfo(attackerEntity.getId(), target.getTargetType(), target, true); game.addTagInfo(info); return false; } diff --git a/megamek/src/megamek/common/weapons/TSEMPHandler.java b/megamek/src/megamek/common/weapons/TSEMPHandler.java index a2188ac9192..f8fb87257eb 100644 --- a/megamek/src/megamek/common/weapons/TSEMPHandler.java +++ b/megamek/src/megamek/common/weapons/TSEMPHandler.java @@ -65,19 +65,19 @@ protected boolean doChecks(Vector vPhaseReport) { r.subject = subjectId; weapon.setHit(true); int wloc = weapon.getLocation(); - for (int i = 0; i < ae.getNumberOfCriticals(wloc); i++) { - CriticalSlot slot1 = ae.getCritical(wloc, i); + for (int i = 0; i < attackerEntity.getNumberOfCriticals(wloc); i++) { + CriticalSlot slot1 = attackerEntity.getCritical(wloc, i); if ((slot1 == null) || (slot1.getType() == CriticalSlot.TYPE_SYSTEM)) { continue; } Mounted mounted = slot1.getMount(); if (mounted.equals(weapon)) { - ae.hitAllCriticals(wloc, i); + attackerEntity.hitAllCriticals(wloc, i); break; } } - vPhaseReport.addAll(gameManager.explodeEquipment(ae, wloc, weapon)); + vPhaseReport.addAll(gameManager.explodeEquipment(attackerEntity, wloc, weapon)); r.choose(false); vPhaseReport.addElement(r); return true; @@ -90,11 +90,11 @@ protected boolean doChecks(Vector vPhaseReport) { public boolean handle(GamePhase phase, Vector vPhaseReport) { weapon.setFired(true); - ae.setFiredTsempThisTurn(true); - ae.setHasFiredTsemp(true); + attackerEntity.setFiredTsempThisTurn(true); + attackerEntity.setHasFiredTsemp(true); - if (ae.getTsempEffect() == MMConstants.TSEMP_EFFECT_NONE) { - ae.setTsempEffect(MMConstants.TSEMP_EFFECT_INTERFERENCE); + if (attackerEntity.getTsempEffect() == MMConstants.TSEMP_EFFECT_NONE) { + attackerEntity.setTsempEffect(MMConstants.TSEMP_EFFECT_INTERFERENCE); } return super.handle(phase, vPhaseReport); diff --git a/megamek/src/megamek/common/weapons/TeleMissileHandler.java b/megamek/src/megamek/common/weapons/TeleMissileHandler.java index 903127c9979..012ba64f9ae 100644 --- a/megamek/src/megamek/common/weapons/TeleMissileHandler.java +++ b/megamek/src/megamek/common/weapons/TeleMissileHandler.java @@ -75,7 +75,7 @@ private int calcBayDamageAndHeat() { for (WeaponMounted bayW : weapon.getBayWeapons()) { WeaponType bayWType = bayW.getType(); damage += (int) bayWType.getShortAV(); - ae.heatBuildup += bayW.getCurrentHeat(); + attackerEntity.heatBuildup += bayW.getCurrentHeat(); missileArmor = bayWType.getMissileArmor(); } return damage; @@ -96,7 +96,7 @@ protected void useAmmo() { if (null == bayWAmmo || bayWAmmo.getUsableShotsLeft() < 1) { // try loading something else - ae.loadWeaponWithSameAmmo(bayW); + attackerEntity.loadWeaponWithSameAmmo(bayW); bayWAmmo = bayW.getLinkedAmmo(); } if (null != bayWAmmo) { @@ -115,7 +115,7 @@ protected void useAmmo() { @Override public boolean handle(GamePhase phase, Vector vPhaseReport) { // just launch the tele-missile - gameManager.deployTeleMissile(ae, wtype, getBayAmmoType(), ae.getEquipmentNum(weapon), + gameManager.deployTeleMissile(attackerEntity, weaponType, getBayAmmoType(), attackerEntity.getEquipmentNum(weapon), getCapMisMod(), calcBayDamageAndHeat(), missileArmor, vPhaseReport); return false; diff --git a/megamek/src/megamek/common/weapons/ThunderBoltWeaponHandler.java b/megamek/src/megamek/common/weapons/ThunderBoltWeaponHandler.java index 5cb70038bb1..800ff030f67 100644 --- a/megamek/src/megamek/common/weapons/ThunderBoltWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/ThunderBoltWeaponHandler.java @@ -39,7 +39,7 @@ public ThunderBoltWeaponHandler(ToHitData t, WeaponAttackAction w, Game g, /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override @@ -47,10 +47,10 @@ protected int calcDamagePerHit() { AmmoType atype = (AmmoType) ammo.getType(); double toReturn = atype.getDamagePerShot(); int minRange; - if (ae.isAirborne()) { - minRange = wtype.getATRanges()[RangeType.RANGE_MINIMUM]; + if (attackerEntity.isAirborne()) { + minRange = weaponType.getATRanges()[RangeType.RANGE_MINIMUM]; } else { - minRange = wtype.getMinimumRange(); + minRange = weaponType.getMinimumRange(); } if ((nRange <= minRange) && !weapon.isHotLoaded()) { toReturn /= 2; @@ -59,15 +59,15 @@ protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage(toReturn, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); } else if (bDirect) { toReturn = Math.min(toReturn + (toHit.getMoS() / 3), toReturn * 2); } return (int) Math.ceil(toReturn); } - + /** * Calculate the attack value based on range * @@ -77,25 +77,25 @@ protected int calcDamagePerHit() { protected int calcAttackValue() { int av = 0; double counterAV = calcCounterAV(); - int armor = wtype.getMissileArmor(); - int range = RangeType.rangeBracket(nRange, wtype.getATRanges(), true, false); + int armor = weaponType.getMissileArmor(); + int range = RangeType.rangeBracket(nRange, weaponType.getATRanges(), true, false); if (range == WeaponType.RANGE_SHORT) { - av = wtype.getRoundShortAV(); + av = weaponType.getRoundShortAV(); } else if (range == WeaponType.RANGE_MED) { - av = wtype.getRoundMedAV(); + av = weaponType.getRoundMedAV(); } else if (range == WeaponType.RANGE_LONG) { - av = wtype.getRoundLongAV(); + av = weaponType.getRoundLongAV(); } else if (range == WeaponType.RANGE_EXT) { - av = wtype.getRoundExtAV(); + av = weaponType.getRoundExtAV(); } - + // For squadrons, total the missile armor for the launched volley - if (ae.isCapitalFighter()) { - armor = armor * nweapons; + if (attackerEntity.isCapitalFighter()) { + armor = armor * numberOfWeapons; } CapMissileArmor = armor - (int) counterAV; CapMissileAMSMod = calcCapMissileAMSMod(); - + if (bDirect) { av = Math.min(av + (toHit.getMoS() / 3), av * 2); } @@ -105,28 +105,28 @@ protected int calcAttackValue() { av = (int) Math.floor(getBracketingMultiplier() * av); return (av); } - + @Override protected int calcCapMissileAMSMod() { CapMissileAMSMod = (int) Math.ceil(CounterAV / 10.0); return CapMissileAMSMod; } - + @Override protected int getCapMissileAMSMod() { return CapMissileAMSMod; } - + @Override //Thunderbolts apply damage all in one block. //This was referenced incorrectly for Aero damage. protected boolean usesClusterTable() { return false; } - + /* * (non-Javadoc) - * + * * @see * megamek.common.weapons.MissileWeaponHandler#calcHits(java.util.Vector) */ @@ -148,7 +148,7 @@ protected int calcHits(Vector vPhaseReport) { } bSalvo = true; // Report AMS/Pointdefense failure due to Overheating. - if (pdOverheated + if (pdOverheated && (!(amsBayEngaged || amsBayEngagedCap || amsBayEngagedMissile @@ -159,7 +159,7 @@ protected int calcHits(Vector vPhaseReport) { r.subject = subjectId; r.indent(); vPhaseReport.addElement(r); - } + } if (amsEngaged || apdsEngaged) { Report r = new Report(3235); r.subject = subjectId; @@ -186,7 +186,7 @@ protected int calcHits(Vector vPhaseReport) { } return 1; } - + /** * Sets the appropriate AMS Bay reporting flag depending on what type of missile this is */ @@ -194,7 +194,7 @@ protected int calcHits(Vector vPhaseReport) { protected void setAMSBayReportingFlag() { amsBayEngagedCap = true; } - + /** * Sets the appropriate PD Bay reporting flag depending on what type of missile this is */ @@ -202,12 +202,12 @@ protected void setAMSBayReportingFlag() { protected void setPDBayReportingFlag() { pdBayEngagedCap = true; } - + @Override // For AntiShip missiles, which behave more like Thunderbolts than capital missiles except for this // All other thunderbolt type large missiles should be unable to score a critical hit here protected int getCapMisMod() { - if (wtype.hasFlag(WeaponType.F_ANTI_SHIP)) { + if (weaponType.hasFlag(WeaponType.F_ANTI_SHIP)) { return 11; } else { return 0; diff --git a/megamek/src/megamek/common/weapons/UltraWeaponHandler.java b/megamek/src/megamek/common/weapons/UltraWeaponHandler.java index 1796a7c8361..2371eeef4d6 100644 --- a/megamek/src/megamek/common/weapons/UltraWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/UltraWeaponHandler.java @@ -46,8 +46,8 @@ public class UltraWeaponHandler extends AmmoWeaponHandler { public UltraWeaponHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { super(t, w, g, m); twoRollsUltra = game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_UAC_TWOROLLS) - && ((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) - || (wtype.getAmmoType() == AmmoType.T_AC_ULTRA_THB)); + && ((weaponType.getAmmoType() == AmmoType.T_AC_ULTRA) + || (weaponType.getAmmoType() == AmmoType.T_AC_ULTRA_THB)); } @Override @@ -55,7 +55,7 @@ protected void useAmmo() { setDone(); checkAmmo(); howManyShots = (weapon.curMode().equals(Weapon.MODE_AC_SINGLE) ? 1 : 2); - int total = ae.getTotalAmmoOfType(ammo.getType()); + int total = attackerEntity.getTotalAmmoOfType(ammo.getType()); if (total > 1) { // No need to change howManyShots } else if (total == 1) { @@ -73,7 +73,7 @@ protected void attemptToReloadWeapon() { // We _may_ be able to reload from another ammo source, but in case // a previous attack burned through all the ammo, this attack may be SOL. if (ammo.getUsableShotsLeft() == 0) { - ae.loadWeapon(weapon); + attackerEntity.loadWeapon(weapon); ammo = weapon.getLinked(); } } @@ -109,7 +109,7 @@ protected int calcHits(Vector vPhaseReport) { Report r = new Report(3325); r.subject = subjectId; r.add(shotsHit); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.addElement(r); @@ -137,13 +137,13 @@ protected boolean doChecks(Vector vPhaseReport) { return true; } - if ((roll.getIntValue() == 2) && (howManyShots == 2) && !ae.isConventionalInfantry()) { + if ((roll.getIntValue() == 2) && (howManyShots == 2) && !attackerEntity.isConventionalInfantry()) { Report r = new Report(); r.subject = subjectId; weapon.setJammed(true); isJammed = true; - if ((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) - || (wtype.getAmmoType() == AmmoType.T_AC_ULTRA_THB)) { + if ((weaponType.getAmmoType() == AmmoType.T_AC_ULTRA) + || (weaponType.getAmmoType() == AmmoType.T_AC_ULTRA_THB)) { r.messageId = 3160; } else { r.messageId = 3170; @@ -155,24 +155,24 @@ protected boolean doChecks(Vector vPhaseReport) { @Override protected int calcDamagePerHit() { - double toReturn = wtype.getDamage(); + double toReturn = weaponType.getDamage(); // infantry get hit by all shots if (target.isConventionalInfantry()) { if (howManyShots > 1) { // Is this a cluster attack? // Compute maximum damage potential for cluster weapons - toReturn = howManyShots * wtype.getDamage(); + toReturn = howManyShots * weaponType.getDamage(); toReturn = Compute.directBlowInfantryDamage(toReturn, bDirect ? toHit.getMoS() / 3 : 0, WeaponType.WEAPON_CLUSTER_BALLISTIC, // treat as cluster ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); } else { // No - only one shot fired - toReturn = Compute.directBlowInfantryDamage(wtype.getDamage(), + toReturn = Compute.directBlowInfantryDamage(weaponType.getDamage(), bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); } // Cluster bonuses or penalties can't apply to "two rolls" UACs, so @@ -186,11 +186,11 @@ protected int calcDamagePerHit() { } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG])) { toReturn = (int) Math.floor(toReturn * .75); } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { toReturn = (int) Math.floor(toReturn * .5); } return (int) toReturn; @@ -203,7 +203,7 @@ protected boolean usesClusterTable() { @Override protected int calcnClusterAero(Entity entityTarget) { - if (usesClusterTable() && !ae.isCapitalFighter() && (entityTarget != null) + if (usesClusterTable() && !attackerEntity.isCapitalFighter() && (entityTarget != null) && !entityTarget.isCapitalScale()) { return (int) Math.ceil(attackValue / 2.0); } else { diff --git a/megamek/src/megamek/common/weapons/VGLWeaponHandler.java b/megamek/src/megamek/common/weapons/VGLWeaponHandler.java index b3411aa68c0..d5ffae0934e 100644 --- a/megamek/src/megamek/common/weapons/VGLWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/VGLWeaponHandler.java @@ -74,18 +74,18 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { AmmoType atype = (AmmoType) ammo.getType(); int facing = weapon.getFacing(); ArrayList affectedCoords = new ArrayList<>(3); - int af = ae.getFacing(); - if (ae.isSecondaryArcWeapon(ae.getEquipmentNum(weapon))) { - af = ae.getSecondaryFacing(); + int af = attackerEntity.getFacing(); + if (attackerEntity.isSecondaryArcWeapon(attackerEntity.getEquipmentNum(weapon))) { + af = attackerEntity.getSecondaryFacing(); } - affectedCoords.add(ae.getPosition().translated(af + facing)); - affectedCoords.add(ae.getPosition().translated((af + facing + 1) % 6)); - affectedCoords.add(ae.getPosition().translated((af + facing + 5) % 6)); + affectedCoords.add(attackerEntity.getPosition().translated(af + facing)); + affectedCoords.add(attackerEntity.getPosition().translated((af + facing + 1) % 6)); + affectedCoords.add(attackerEntity.getPosition().translated((af + facing + 5) % 6)); Report r = new Report(3117); r.indent(); r.subject = subjectId; - r.add(wtype.getName()); + r.add(weaponType.getName()); r.add(atype.getSubMunitionName()); r.add(affectedCoords.get(0).getBoardNum()); r.add(affectedCoords.get(1).getBoardNum()); @@ -104,7 +104,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { // Delivery an inferno to the hex Targetable grenadeTarget = new HexTarget(c, Targetable.TYPE_HEX_IGNITE); dmgReports = gameManager - .deliverInfernoMissiles(ae, grenadeTarget, 1); + .deliverInfernoMissiles(attackerEntity, grenadeTarget, 1); r = new Report(3372); r.add("Hex " + c.getBoardNum()); r.indent(); @@ -118,7 +118,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { if (bldg != null) { grenadeTarget = new BuildingTarget(c, game.getBoard(), Targetable.TYPE_BLDG_IGNITE); - dmgReports = gameManager.deliverInfernoMissiles(ae, + dmgReports = gameManager.deliverInfernoMissiles(attackerEntity, grenadeTarget, 1); r = new Report(3372); r.add(bldg.getName()); @@ -139,7 +139,7 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { continue; } dmgReports = gameManager - .deliverInfernoMissiles(ae, entTarget, 1); + .deliverInfernoMissiles(attackerEntity, entTarget, 1); r = new Report(3371); r.addDesc(entTarget); r.indent(); @@ -157,8 +157,8 @@ public boolean handle(GamePhase phase, Vector vPhaseReport) { && Compute.isInBuilding(game, entTarget, c); hit = entTarget.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setAttackerId(getAttackerId()); Vector dmgReports = new Vector<>(); diff --git a/megamek/src/megamek/common/weapons/VariableSpeedPulseLaserWeaponHandler.java b/megamek/src/megamek/common/weapons/VariableSpeedPulseLaserWeaponHandler.java index 47e2627a044..0610ca82c1e 100644 --- a/megamek/src/megamek/common/weapons/VariableSpeedPulseLaserWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/VariableSpeedPulseLaserWeaponHandler.java @@ -38,26 +38,26 @@ public VariableSpeedPulseLaserWeaponHandler(ToHitData toHit, WeaponAttackAction /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override protected int calcDamagePerHit() { - int[] nRanges = wtype.getRanges(weapon); - double toReturn = wtype.getDamage(nRange); + int[] nRanges = weaponType.getRanges(weapon); + double toReturn = weaponType.getDamage(nRange); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_ENERGY_WEAPONS) && weapon.hasModes()) { - toReturn = Compute.dialDownDamage(weapon, wtype, nRange); + toReturn = Compute.dialDownDamage(weapon, weaponType, nRange); } // Check for Altered Damage from Energy Weapons (TacOp, pg.83) if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_ALTDMG)) { if (nRange <= 1) { toReturn++; - } else if (nRange <= wtype.getMediumRange()) { + } else if (nRange <= weaponType.getMediumRange()) { // Do Nothing for Short and Medium Range - } else if (nRange <= wtype.getLongRange()) { + } else if (nRange <= weaponType.getLongRange()) { toReturn--; } } @@ -65,9 +65,9 @@ protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage(toReturn, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); if (nRange <= nRanges[RangeType.RANGE_SHORT]) { toReturn += 3; } else if (nRange <= nRanges[RangeType.RANGE_MEDIUM]) { diff --git a/megamek/src/megamek/common/weapons/VehicleFlamerHandler.java b/megamek/src/megamek/common/weapons/VehicleFlamerHandler.java index 6553ab813e5..53e39f1e1f1 100644 --- a/megamek/src/megamek/common/weapons/VehicleFlamerHandler.java +++ b/megamek/src/megamek/common/weapons/VehicleFlamerHandler.java @@ -48,10 +48,10 @@ public VehicleFlamerHandler(ToHitData toHit, WeaponAttackAction waa, super(toHit, waa, g, m); generalDamageType = HitData.DAMAGE_ENERGY; } - + /* * (non-Javadoc) - * + * * @see * megamek.common.weapons.WeaponHandler#handleEntityDamage(megamek.common * .Entity, java.util.Vector, megamek.common.Building, int, int, int, int) @@ -61,25 +61,25 @@ protected void handleEntityDamage(Entity entityTarget, Vector vPhaseReport, Building bldg, int hits, int nCluster, int bldgAbsorbs) { boolean bmmFlamerDamage = game.getOptions().booleanOption(OptionsConstants.BASE_FLAMER_HEAT); - EquipmentMode currentWeaponMode = game.getEntity(waa.getEntityId()).getEquipment(waa.getWeaponId()).curMode(); - + EquipmentMode currentWeaponMode = game.getEntity(weaponAttackAction.getEntityId()).getEquipment(weaponAttackAction.getWeaponId()).curMode(); + boolean flamerDoesHeatOnlyDamage = currentWeaponMode != null && currentWeaponMode.equals(Weapon.MODE_FLAMER_HEAT); boolean flamerDoesOnlyDamage = currentWeaponMode != null && currentWeaponMode.equals(Weapon.MODE_FLAMER_DAMAGE); - + if (bmmFlamerDamage || flamerDoesOnlyDamage || (flamerDoesHeatOnlyDamage && !entityTarget.tracksHeat())) { super.handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - + if (bmmFlamerDamage && entityTarget.tracksHeat()) { - FlamerHandlerHelper.doHeatDamage(entityTarget, vPhaseReport, wtype, subjectId, hit); + FlamerHandlerHelper.doHeatDamage(entityTarget, vPhaseReport, weaponType, subjectId, hit); } } else if (flamerDoesHeatOnlyDamage) { hit = entityTarget.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setAttackerId(getAttackerId()); if (entityTarget.removePartialCoverHits(hit.getLocation(), toHit - .getCover(), Compute.targetSideTable(ae, entityTarget, + .getCover(), Compute.targetSideTable(attackerEntity, entityTarget, weapon.getCalledShot().getCall()))) { // Weapon strikes Partial Cover. handlePartialCoverHit(entityTarget, vPhaseReport, hit, bldg, @@ -91,25 +91,25 @@ protected void handleEntityDamage(Entity entityTarget, r.add(toHit.getTableDesc()); r.add(entityTarget.getLocationAbbr(hit)); vPhaseReport.addElement(r); - - FlamerHandlerHelper.doHeatDamage(entityTarget, vPhaseReport, wtype, subjectId, hit); + + FlamerHandlerHelper.doHeatDamage(entityTarget, vPhaseReport, weaponType, subjectId, hit); } } - + /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override protected int calcDamagePerHit() { double toReturn; if (target.isConventionalInfantry()) { - if (ae instanceof BattleArmor) { + if (attackerEntity instanceof BattleArmor) { toReturn = Compute.d6(3); - } else if ((wtype instanceof ISHeavyFlamer) - || (wtype instanceof CLHeavyFlamer)) { + } else if ((weaponType instanceof ISHeavyFlamer) + || (weaponType instanceof CLHeavyFlamer)) { toReturn = Compute.d6(6); } else { toReturn = Compute.d6(4); @@ -138,7 +138,7 @@ protected void handleIgnitionDamage(Vector vPhaseReport, Building bldg, r.newlines = 0; vPhaseReport.addElement(r); } - TargetRoll tn = new TargetRoll(wtype.getFireTN(), wtype.getName()); + TargetRoll tn = new TargetRoll(weaponType.getFireTN(), weaponType.getName()); if (tn.getValue() != TargetRoll.IMPOSSIBLE) { Report.addNewline(vPhaseReport); gameManager.tryIgniteHex(target.getPosition(), subjectId, true, false, @@ -170,7 +170,7 @@ protected void handleClearDamage(Vector vPhaseReport, Building bldg, int if ((bldg != null) && gameManager.tryIgniteHex(target.getPosition(), subjectId, true, false, - new TargetRoll(wtype.getFireTN(), wtype.getName()), 5, + new TargetRoll(weaponType.getFireTN(), weaponType.getName()), 5, vPhaseReport)) { return; } @@ -180,4 +180,4 @@ protected void handleClearDamage(Vector vPhaseReport, Building bldg, int } vPhaseReport.addAll(clearReports); } -} \ No newline at end of file +} diff --git a/megamek/src/megamek/common/weapons/WeaponHandler.java b/megamek/src/megamek/common/weapons/WeaponHandler.java index dedba430824..757957ed184 100644 --- a/megamek/src/megamek/common/weapons/WeaponHandler.java +++ b/megamek/src/megamek/common/weapons/WeaponHandler.java @@ -15,15 +15,6 @@ */ package megamek.common.weapons; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; -import java.util.Vector; - import megamek.common.*; import megamek.common.actions.ArtilleryAttackAction; import megamek.common.actions.TeleMissileAttackAction; @@ -39,6 +30,12 @@ import megamek.server.SmokeCloud; import megamek.server.totalwarfare.TWGameManager; +import java.io.*; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Vector; + /** * A basic, simple attack handler. May or may not work for any particular * weapon; must be overloaded @@ -49,10 +46,11 @@ public class WeaponHandler implements AttackHandler, Serializable { private static final MMLogger logger = MMLogger.create(WeaponHandler.class); + @Serial private static final long serialVersionUID = 7137408139594693559L; public ToHitData toHit; protected HitData hit; - public WeaponAttackAction waa; + public WeaponAttackAction weaponAttackAction; public Roll roll; protected boolean isJammed = false; @@ -64,11 +62,11 @@ public class WeaponHandler implements AttackHandler, Serializable { protected boolean bDirect = false; protected boolean bLowProfileGlancing = false; protected boolean nukeS2S = false; - protected WeaponType wtype; - protected AmmoType atype; + protected WeaponType weaponType; + protected AmmoType ammoType; protected String typeName; protected WeaponMounted weapon; - protected Entity ae; + protected Entity attackerEntity; protected Targetable target; protected int subjectId; protected int nRange; @@ -81,11 +79,10 @@ public class WeaponHandler implements AttackHandler, Serializable { protected DamageType damageType; protected int generalDamageType = HitData.DAMAGE_NONE; protected Vector insertedAttacks = new Vector<>(); - protected int nweapons; // for capital fighters/fighter squadrons - protected int nweaponsHit; // for capital fighters/fighter squadrons - protected boolean secondShot = false; - protected int numRapidFireHits; - protected String sSalvoType = " shot(s) "; + protected int numberOfWeapons; // for capital fighters/fighter squadrons + protected int numberOfWeaponHits; // for capital fighters/fighter squadrons + protected int numberOfRapidFireHits; + protected String salvoType = " shot(s) "; protected int nSalvoBonus = 0; /** * Keeps track of whether we are processing the first hit in a series of @@ -94,7 +91,7 @@ public class WeaponHandler implements AttackHandler, Serializable { protected boolean firstHit = true; /** - * Boolean flag that determines whether or not this attack is part of a + * Boolean flag that determines whether this attack is part of a * strafing run. */ protected boolean isStrafing = false; @@ -159,7 +156,7 @@ protected int getLargeCraftHeat(Entity e) { if (e.usesWeaponBays()) { for (Enumeration i = game.getAttacks(); i.hasMoreElements();) { AttackHandler ah = i.nextElement(); - WeaponAttackAction prevAttack = ah.getWaa(); + WeaponAttackAction prevAttack = ah.getWeaponAttackAction(); if (prevAttack.getEntityId() == e.getId()) { WeaponMounted prevWeapon = (WeaponMounted) e.getEquipment(prevAttack.getWeaponId()); for (WeaponMounted bayW : prevWeapon.getBayWeapons()) { @@ -170,7 +167,7 @@ protected int getLargeCraftHeat(Entity e) { } else { for (Enumeration i = game.getAttacks(); i.hasMoreElements();) { AttackHandler ah = i.nextElement(); - WeaponAttackAction prevAttack = ah.getWaa(); + WeaponAttackAction prevAttack = ah.getWeaponAttackAction(); if (prevAttack.getEntityId() == e.getId()) { Mounted prevWeapon = e.getEquipment(prevAttack.getWeaponId()); totalheat += prevWeapon.getCurrentHeat(); @@ -198,12 +195,12 @@ protected boolean checkPDConditions() { // missile fire // Prevents ammo and heat being used twice for dropships defending here and with // getAMSHitsMod() - || (waa.isGroundToAir(game) && (!(wtype.isSubCapital() || wtype.isCapital())))) { + || (weaponAttackAction.isGroundToAir(game) && (!(weaponType.isSubCapital() || weaponType.isCapital())))) { return false; } if (target instanceof Dropship - && waa.isAirToGround(game) - && !ae.usesWeaponBays()) { + && weaponAttackAction.isAirToGround(game) + && !attackerEntity.usesWeaponBays()) { // Prevents a grounded dropship using individual weapons from engaging with // AMSBays unless attacked by a dropship or capital fighter // You can get some blank missile weapons fire reports due to the attackvalue / @@ -270,7 +267,7 @@ protected int calcCounterAV() { double pdAV = 0; Entity entityTarget = (Entity) target; // any AMS bay attacks by the target? - List lCounters = waa.getCounterEquipment(); + List lCounters = weaponAttackAction.getCounterEquipment(); // We need to know how much heat has been assigned to offensive weapons fire by // the defender this round int weaponHeat = getLargeCraftHeat(entityTarget) + entityTarget.heatBuildup; @@ -281,7 +278,7 @@ protected int calcCounterAV() { boolean isInArc; // If the defending unit is the target, use attacker for arc if (entityTarget.equals(pdEnt)) { - isInArc = Compute.isInArc(game, pdEnt.getId(), pdEnt.getEquipmentNum(counter), ae); + isInArc = Compute.isInArc(game, pdEnt.getId(), pdEnt.getEquipmentNum(counter), attackerEntity); } else { // Otherwise, the attack must pass through an escort unit's hex // TODO: We'll get here, eventually isInArc = Compute.isInArc(game, pdEnt.getId(), @@ -436,12 +433,12 @@ protected int getCapMissileAMSMod() { */ @Override public int getAttackerId() { - return ae.getId(); + return attackerEntity.getId(); } @Override public Entity getAttacker() { - return ae; + return attackerEntity; } /** @@ -482,9 +479,9 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE } protected TargetRoll getFireTNRoll() { - int targetNumber = (atype == null) ? wtype.getFireTN() - : Math.min(wtype.getFireTN(), atype.getFireTN()); - return new TargetRoll(targetNumber, wtype.getName()); + int targetNumber = (ammoType == null) ? weaponType.getFireTN() + : Math.min(weaponType.getFireTN(), ammoType.getFireTN()); + return new TargetRoll(targetNumber, weaponType.getName()); } /** @@ -500,8 +497,8 @@ protected boolean handleSpecialMiss(Entity entityTarget, boolean bldgDamagedOnMi if ((entityTarget != null) && !entityTarget.isAirborne() && !entityTarget.isAirborneVTOLorWIGE() - && ((bldg == null) && (wtype.getFireTN() != TargetRoll.IMPOSSIBLE - && (atype == null || atype.getFireTN() != TargetRoll.IMPOSSIBLE)))) { + && ((bldg == null) && (weaponType.getFireTN() != TargetRoll.IMPOSSIBLE + && (ammoType == null || ammoType.getFireTN() != TargetRoll.IMPOSSIBLE)))) { gameManager.tryIgniteHex(target.getPosition(), subjectId, false, false, getFireTNRoll(), 3, vPhaseReport); @@ -530,15 +527,15 @@ protected boolean handleSpecialMiss(Entity entityTarget, boolean bldgDamagedOnMi protected int calcHits(Vector vPhaseReport) { // normal BA attacks (non-swarm, non single-trooper weapons) // do more than 1 hit - if ((ae instanceof BattleArmor) + if ((attackerEntity instanceof BattleArmor) && (weapon.getLocation() == BattleArmor.LOC_SQUAD) && !(weapon.isSquadSupportWeapon()) - && !(ae.getSwarmTargetId() == target.getId())) { + && !(attackerEntity.getSwarmTargetId() == target.getId())) { bSalvo = true; - int toReturn = allShotsHit() ? ((BattleArmor) ae) + int toReturn = allShotsHit() ? ((BattleArmor) attackerEntity) .getShootingStrength() : Compute - .missilesHit(((BattleArmor) ae).getShootingStrength()); + .missilesHit(((BattleArmor) attackerEntity).getShootingStrength()); Report r = new Report(3325); r.newlines = 0; r.subject = subjectId; @@ -562,7 +559,7 @@ protected int calcnCluster() { } protected int calcnClusterAero(Entity entityTarget) { - if (usesClusterTable() && !ae.isCapitalFighter() + if (usesClusterTable() && !attackerEntity.isCapitalFighter() && (entityTarget != null) && !entityTarget.isCapitalScale()) { return 5; } else { @@ -585,18 +582,18 @@ protected int[] calcAeroDamage(Entity entityTarget, int hits = calcHits(vPhaseReport); int nCluster = calcnCluster(); int AMSHits = 0; - if (ae.isCapitalFighter()) { + if (attackerEntity.isCapitalFighter()) { Vector throwAwayReport = new Vector<>(); // for capital scale fighters, each non-cluster weapon hits a // different location bSalvo = true; hits = 1; - if (nweapons > 1) { + if (numberOfWeapons > 1) { if (allShotsHit()) { - nweaponsHit = nweapons; + numberOfWeaponHits = numberOfWeapons; } else { - nweaponsHit = Compute.missilesHit(nweapons, - ((Aero) ae).getClusterMods()); + numberOfWeaponHits = Compute.missilesHit(numberOfWeapons, + ((Aero) attackerEntity).getClusterMods()); } if (usesClusterTable()) { // remove the last reports because they showed the @@ -605,7 +602,7 @@ protected int[] calcAeroDamage(Entity entityTarget, vPhaseReport.remove(vPhaseReport.size() - 1); } hits = 0; - for (int i = 0; i < nweaponsHit; i++) { + for (int i = 0; i < numberOfWeaponHits; i++) { hits += calcHits(throwAwayReport); } // Report and apply point defense fire @@ -626,7 +623,7 @@ protected int[] calcAeroDamage(Entity entityTarget, Report r = new Report(3325); r.subject = subjectId; r.add(hits); - r.add(sSalvoType); + r.add(salvoType); r.add(toHit.getTableDesc()); r.newlines = 0; vPhaseReport.add(r); @@ -641,13 +638,13 @@ protected int[] calcAeroDamage(Entity entityTarget, AMSHits = 0; Report r = new Report(3236); r.subject = subjectId; - r.add(nweaponsHit); + r.add(numberOfWeaponHits); vPhaseReport.add(r); r = new Report(3230); r.indent(1); r.subject = subjectId; vPhaseReport.add(r); - for (int i = 0; i < nweaponsHit; i++) { + for (int i = 0; i < numberOfWeaponHits; i++) { Roll diceRoll = Compute.rollD6(1); if (diceRoll.getIntValue() <= 3) { @@ -665,7 +662,7 @@ protected int[] calcAeroDamage(Entity entityTarget, vPhaseReport.add(r); } } - nweaponsHit = nweaponsHit - AMSHits; + numberOfWeaponHits = numberOfWeaponHits - AMSHits; } else if (amsEngaged || apdsEngaged) { // remove the last reports because they showed the // number of shots that hit @@ -678,7 +675,7 @@ protected int[] calcAeroDamage(Entity entityTarget, AMSHits = 0; Report r = new Report(3236); r.subject = subjectId; - r.add(nweaponsHit); + r.add(numberOfWeaponHits); vPhaseReport.add(r); if (amsEngaged) { r = new Report(3230); @@ -708,17 +705,17 @@ protected int[] calcAeroDamage(Entity entityTarget, r.subject = subjectId; vPhaseReport.add(r); } - nweaponsHit = nweaponsHit - AMSHits; + numberOfWeaponHits = numberOfWeaponHits - AMSHits; } nCluster = 1; if (!bMissed) { Report r = new Report(3325); r.subject = subjectId; - r.add(nweaponsHit); + r.add(numberOfWeaponHits); r.add(" weapon(s) "); r.add(" "); r.newlines = 0; - hits = nweaponsHit; + hits = numberOfWeaponHits; vPhaseReport.add(r); } } @@ -731,28 +728,28 @@ protected int[] calcAeroDamage(Entity entityTarget, } else { int hits = 1; int nCluster = calcnClusterAero(entityTarget); - if (ae.isCapitalFighter()) { + if (attackerEntity.isCapitalFighter()) { bSalvo = false; - if (nweapons > 1) { - nweaponsHit = Compute.missilesHit(nweapons, - ((IAero) ae).getClusterMods()); + if (numberOfWeapons > 1) { + numberOfWeaponHits = Compute.missilesHit(numberOfWeapons, + ((IAero) attackerEntity).getClusterMods()); if (pdBayEngaged || amsBayEngaged) { // Point Defenses engage standard (cluster) missiles int counterAV = 0; counterAV = getCounterAV(); - nDamPerHit = originalAV * nweaponsHit - counterAV; + nDamPerHit = originalAV * numberOfWeaponHits - counterAV; hits = 1; nCluster = 1; } else { // If multiple large missile or non-missile weapons hit Report r = new Report(3325); r.subject = subjectId; - r.add(nweaponsHit); + r.add(numberOfWeaponHits); r.add(" weapon(s) "); r.add(" "); r.newlines = 1; vPhaseReport.add(r); - nDamPerHit = attackValue * nweaponsHit; + nDamPerHit = attackValue * numberOfWeaponHits; hits = 1; nCluster = 1; } @@ -774,7 +771,7 @@ protected int[] calcAeroDamage(Entity entityTarget, r.indent(1); r.subject = subjectId; vPhaseReport.add(r); - for (int i = 0; i < nweaponsHit; i++) { + for (int i = 0; i < numberOfWeaponHits; i++) { Roll diceRoll = Compute.rollD6(1); if (diceRoll.getIntValue() <= 3) { @@ -823,7 +820,7 @@ public boolean handle(GamePhase phase, Vector returnedReports) { boolean heatAdded = false; int numAttacks = 1; if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_UAC_TWOROLLS) - && ((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) || (wtype + && ((weaponType.getAmmoType() == AmmoType.T_AC_ULTRA) || (weaponType .getAmmoType() == AmmoType.T_AC_ULTRA_THB)) && !weapon.curMode().equals("Single")) { numAttacks = 2; @@ -835,33 +832,33 @@ public boolean handle(GamePhase phase, Vector returnedReports) { entityTarget); final boolean bldgDamagedOnMiss = targetInBuilding && !(target instanceof Infantry) - && ae.getPosition().distance(target.getPosition()) <= 1; + && attackerEntity.getPosition().distance(target.getPosition()) <= 1; if (entityTarget != null) { - ae.setLastTarget(entityTarget.getId()); - ae.setLastTargetDisplayName(entityTarget.getDisplayName()); + attackerEntity.setLastTarget(entityTarget.getId()); + attackerEntity.setLastTargetDisplayName(entityTarget.getDisplayName()); } // Which building takes the damage? Building bldg = game.getBoard().getBuildingAt(target.getPosition()); - String number = nweapons > 1 ? " (" + nweapons + ")" : ""; + String number = numberOfWeapons > 1 ? " (" + numberOfWeapons + ")" : ""; for (int i = numAttacks; i > 0; i--) { // Report weapon attack and its to-hit value. Report r = new Report(3115); r.indent(); r.newlines = 0; r.subject = subjectId; - String base = wtype.isClan() ? " (Clan)" : ""; - r.add(wtype.getName() + base + number); + String base = weaponType.isClan() ? " (Clan)" : ""; + r.add(weaponType.getName() + base + number); if (entityTarget != null) { - if ((wtype.getAmmoType() != AmmoType.T_NA) + if ((weaponType.getAmmoType() != AmmoType.T_NA) && (weapon.getLinked() != null) && (weapon.getLinked().getType() instanceof AmmoType)) { - if (!atype.getMunitionType().contains(AmmoType.Munitions.M_STANDARD) - || atype.getAmmoType() == AmmoType.T_MML - || atype.getAmmoType() == AmmoType.T_AC_LBX - || atype.getAmmoType() == AmmoType.T_ATM) { + if (!ammoType.getMunitionType().contains(AmmoType.Munitions.M_STANDARD) + || ammoType.getAmmoType() == AmmoType.T_MML + || ammoType.getAmmoType() == AmmoType.T_AC_LBX + || ammoType.getAmmoType() == AmmoType.T_ATM) { r.messageId = 3116; - r.add(atype.getSubMunitionName()); + r.add(ammoType.getSubMunitionName()); } } r.addDesc(entityTarget); @@ -979,7 +976,7 @@ public boolean handle(GamePhase phase, Vector returnedReports) { if (bDirect) { r = new Report(3189); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } @@ -1056,7 +1053,7 @@ public boolean handle(GamePhase phase, Vector returnedReports) { if (bMissed && !missReported) { if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_UAC_TWOROLLS) - && ((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) || (wtype + && ((weaponType.getAmmoType() == AmmoType.T_AC_ULTRA) || (weaponType .getAmmoType() == AmmoType.T_AC_ULTRA_THB)) && (i == 2)) { reportMiss(vPhaseReport, true); @@ -1079,7 +1076,7 @@ public boolean handle(GamePhase phase, Vector returnedReports) { int nCluster = calcnCluster(); int id = vPhaseReport.size(); int hits = calcHits(vPhaseReport); - if ((target.isAirborne() && !waa.isGroundToAir(game)) || game.getBoard().inSpace() || ae.usesWeaponBays()) { + if ((target.isAirborne() && !weaponAttackAction.isGroundToAir(game)) || game.getBoard().inSpace() || attackerEntity.usesWeaponBays()) { // if we added a line to the phase report for calc hits, remove // it now while (vPhaseReport.size() > id) { @@ -1116,8 +1113,8 @@ public boolean handle(GamePhase phase, Vector returnedReports) { && (toHit.getThruBldg() != null) && (entityTarget instanceof Infantry)) { // If elevation is the same, building doesn't absorb - if (ae.getElevation() != entityTarget.getElevation()) { - int dmgClass = wtype.getInfantryDamageClass(); + if (attackerEntity.getElevation() != entityTarget.getElevation()) { + int dmgClass = weaponType.getInfantryDamageClass(); int nDamage; if (dmgClass < WeaponType.WEAPON_BURST_1D6) { nDamage = nDamPerHit * Math.min(nCluster, hits); @@ -1126,7 +1123,7 @@ public boolean handle(GamePhase phase, Vector returnedReports) { // absorbed damage shouldn't reduce incoming damage, // since the incoming damage was reduced in // Compute.directBlowInfantryDamage - nDamage = -wtype.getDamage(nRange) + nDamage = -weaponType.getDamage(nRange) * Math.min(nCluster, hits); } bldgAbsorbs = (int) Math.round(nDamage @@ -1149,11 +1146,11 @@ public boolean handle(GamePhase phase, Vector returnedReports) { int nDamage; if ((target.getTargetType() == Targetable.TYPE_HEX_TAG) || (target.getTargetType() == Targetable.TYPE_BLDG_TAG)) { - TagInfo info = new TagInfo(ae.getId(), target.getTargetType(), target, false); + TagInfo info = new TagInfo(attackerEntity.getId(), target.getTargetType(), target, false); game.addTagInfo(info); - ae.setSpotting(true); - ae.setSpotTargetId(target.getId()); + attackerEntity.setSpotting(true); + attackerEntity.setSpotTargetId(target.getId()); r = new Report(3390); r.subject = subjectId; @@ -1177,7 +1174,7 @@ public boolean handle(GamePhase phase, Vector returnedReports) { hits = 0; } else if (entityTarget != null) { handleEntityDamage(entityTarget, vPhaseReport, bldg, hits, nCluster, bldgAbsorbs); - gameManager.creditKill(entityTarget, ae); + gameManager.creditKill(entityTarget, attackerEntity); hits -= nCluster; firstHit = false; } else { @@ -1193,7 +1190,7 @@ public boolean handle(GamePhase phase, Vector returnedReports) { if (bldgDamagedOnMiss) { r = new Report(6429); r.indent(2); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines--; vPhaseReport.add(r); int nDamage = nDamPerHit * hits; @@ -1209,23 +1206,23 @@ public boolean handle(GamePhase phase, Vector returnedReports) { } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_UAC_TWOROLLS) - && ((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) || (wtype + && ((weaponType.getAmmoType() == AmmoType.T_AC_ULTRA) || (weaponType .getAmmoType() == AmmoType.T_AC_ULTRA_THB)) && (i == 2)) { // Jammed weapon doesn't get 2nd shot... if (isJammed) { r = new Report(9905); r.indent(); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); vPhaseReport.addElement(r); i--; } else { // If not jammed, it gets the second shot... r = new Report(9900); r.indent(); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); vPhaseReport.addElement(r); - if (null != ae.getCrew()) { - roll = ae.getCrew().rollGunnerySkill(); + if (null != attackerEntity.getCrew()) { + roll = attackerEntity.getCrew().rollGunnerySkill(); } else { roll = Compute.rollD6(2); } @@ -1246,7 +1243,7 @@ public boolean handle(GamePhase phase, Vector returnedReports) { * @return an int representing the damage dealt per hit. */ protected int calcDamagePerHit() { - double toReturn = wtype.getDamage(nRange); + double toReturn = weaponType.getDamage(nRange); // Check for BA vs BA weapon effectiveness, if option is on if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_BA_VS_BA) @@ -1254,16 +1251,16 @@ protected int calcDamagePerHit() { // We don't check to make sure the attacker is BA, as most weapons // will return their normal damage. toReturn = Compute.directBlowBADamage(toReturn, - wtype.getBADamageClass(), (BattleArmor) target); + weaponType.getBADamageClass(), (BattleArmor) target); } // we default to direct fire weapons for anti-infantry damage if (target.isConventionalInfantry()) { toReturn = Compute.directBlowInfantryDamage(toReturn, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); } else if (bDirect) { toReturn = Math.min(toReturn + (toHit.getMoS() / 3.0), toReturn * 2); } @@ -1271,11 +1268,11 @@ protected int calcDamagePerHit() { toReturn = applyGlancingBlowModifier(toReturn, target.isConventionalInfantry()); if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_LONG])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_LONG])) { toReturn = (int) Math.floor(toReturn * .75); } if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_LOS_RANGE) - && (nRange > wtype.getRanges(weapon)[RangeType.RANGE_EXTREME])) { + && (nRange > weaponType.getRanges(weapon)[RangeType.RANGE_EXTREME])) { toReturn = (int) Math.floor(toReturn * .5); } return (int) toReturn; @@ -1290,27 +1287,27 @@ protected int calcAttackValue() { int av = 0; // if we have a ground firing unit, then AV should not be determined by // aero range brackets - if (!ae.isAirborne() || game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_UAC_TWOROLLS)) { + if (!attackerEntity.isAirborne() || game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_UAC_TWOROLLS)) { if (usesClusterTable()) { // for cluster weapons just use the short range AV - av = wtype.getRoundShortAV(); + av = weaponType.getRoundShortAV(); } else { // otherwise just use the full weapon damage by range - av = wtype.getDamage(nRange); + av = weaponType.getDamage(nRange); } } else { // we have an airborne attacker, so we need to use aero range // brackets - int range = RangeType.rangeBracket(nRange, wtype.getATRanges(), + int range = RangeType.rangeBracket(nRange, weaponType.getATRanges(), true, false); if (range == WeaponType.RANGE_SHORT) { - av = wtype.getRoundShortAV(); + av = weaponType.getRoundShortAV(); } else if (range == WeaponType.RANGE_MED) { - av = wtype.getRoundMedAV(); + av = weaponType.getRoundMedAV(); } else if (range == WeaponType.RANGE_LONG) { - av = wtype.getRoundLongAV(); + av = weaponType.getRoundLongAV(); } else if (range == WeaponType.RANGE_EXT) { - av = wtype.getRoundExtAV(); + av = weaponType.getRoundExtAV(); } } if (bDirect) { @@ -1382,7 +1379,7 @@ protected void handlePartialCoverHit(Entity entityTarget, r.newlines = 0; r = new Report(3225); r.subject = subjectId; - r.add(numRapidFireHits * 3); + r.add(numberOfRapidFireHits * 3); vPhaseReport.add(r); } } else { @@ -1438,15 +1435,15 @@ protected void handlePartialCoverHit(Entity entityTarget, // We need to adjust some state and then restore it later // This allows us to make a call to handleEntityDamage ToHitData savedToHit = toHit; - AimingMode savedAimingMode = waa.getAimingMode(); - waa.setAimingMode(AimingMode.NONE); - int savedAimedLocation = waa.getAimedLocation(); - waa.setAimedLocation(Entity.LOC_NONE); + AimingMode savedAimingMode = weaponAttackAction.getAimingMode(); + weaponAttackAction.setAimingMode(AimingMode.NONE); + int savedAimedLocation = weaponAttackAction.getAimedLocation(); + weaponAttackAction.setAimedLocation(Entity.LOC_NONE); boolean savedSalvo = bSalvo; bSalvo = true; // Create new toHitData toHit = new ToHitData(0, "", ToHitData.HIT_NORMAL, - Compute.targetSideTable(ae, coverDropShip)); + Compute.targetSideTable(attackerEntity, coverDropShip)); // Report cover was damaged int sizeBefore = vPhaseReport.size(); r = new Report(3465); @@ -1466,8 +1463,8 @@ protected void handlePartialCoverHit(Entity entityTarget, } // Restore state toHit = savedToHit; - waa.setAimingMode(savedAimingMode); - waa.setAimedLocation(savedAimedLocation); + weaponAttackAction.setAimingMode(savedAimingMode); + weaponAttackAction.setAimedLocation(savedAimedLocation); bSalvo = savedSalvo; // Damage a building that blocked a shot } else if (damageableCoverType == LosEffects.DAMAGABLE_COVER_BUILDING) { @@ -1482,7 +1479,7 @@ protected void handlePartialCoverHit(Entity entityTarget, vPhaseReport.addAll(buildingReport); // Damage any infantry in the building. Vector infantryReport = gameManager.damageInfantryIn(coverBuilding, nDamage, - coverLoc, wtype.getInfantryDamageClass()); + coverLoc, weaponType.getInfantryDamageClass()); for (Report report : infantryReport) { report.indent(2); } @@ -1519,7 +1516,7 @@ protected void handleEntityDamage(Entity entityTarget, if ((!isIndirect || partialCoverForIndirectFire) && entityTarget.removePartialCoverHits(hit.getLocation(), toHit .getCover(), - Compute.targetSideTable(ae, entityTarget, + Compute.targetSideTable(attackerEntity, entityTarget, weapon.getCalledShot().getCall()))) { // Weapon strikes Partial Cover. handlePartialCoverHit(entityTarget, vPhaseReport, hit, bldg, hits, @@ -1538,7 +1535,7 @@ protected void handleEntityDamage(Entity entityTarget, r.newlines = 0; r = new Report(3225); r.subject = subjectId; - r.add(numRapidFireHits * 3); + r.add(numberOfRapidFireHits * 3); vPhaseReport.add(r); } } else { @@ -1600,7 +1597,7 @@ protected void handleEntityDamage(Entity entityTarget, } vPhaseReport.addAll(gameManager.damageEntity(entityTarget, hit, nDamage, false, - ae.getSwarmTargetId() == entityTarget.getId() ? DamageType.IGNORE_PASSENGER : damageType, + attackerEntity.getSwarmTargetId() == entityTarget.getId() ? DamageType.IGNORE_PASSENGER : damageType, false, false, throughFront, underWater, nukeS2S)); if (damageType.equals(DamageType.ANTI_TSM) && (target instanceof Mek) && entityTarget.antiTSMVulnerable()) { @@ -1618,7 +1615,7 @@ protected void handleEntityDamage(Entity entityTarget, } // If a BA squad is shooting at infantry, damage may be random and need // to be rerolled for the next hit (if any) from the same attack. - if ((ae instanceof BattleArmor) && (target instanceof Infantry)) { + if ((attackerEntity instanceof BattleArmor) && (target instanceof Infantry)) { nDamPerHit = calcDamagePerHit(); } } @@ -1669,7 +1666,7 @@ protected int absorbBuildingDamage(int nDamage, Entity entityTarget, int bldgAbs } else if (bldgAbsorbs == Integer.MIN_VALUE) { Report.addNewline(vPhaseReport); Report r = new Report(9976); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.indent(2); vPhaseReport.add(r); // Cases where absorbed damage doesn't reduce incoming damage @@ -1758,7 +1755,7 @@ protected void handleBuildingDamage(Vector vPhaseReport, Building bldg, // Damage any infantry in hex, unless attack between units in same bldg if (toHit.getThruBldg() == null) { vPhaseReport.addAll(gameManager.damageInfantryIn(bldg, nDamage, coords, - wtype.getInfantryDamageClass())); + weaponType.getInfantryDamageClass())); } } @@ -1773,7 +1770,7 @@ protected boolean allShotsHit() { && target.getTargetType() == Targetable.TYPE_ENTITY && ((Entity) target).isCapitalScale() && !((Entity) target).isCapitalFighter() - && !ae.isCapitalFighter()) { + && !attackerEntity.isCapitalFighter()) { return true; } return false; @@ -1803,44 +1800,44 @@ protected WeaponHandler() { public WeaponHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { damageType = DamageType.NONE; toHit = t; - waa = w; + weaponAttackAction = w; game = g; - ae = game.getEntity(waa.getEntityId()); - weapon = (WeaponMounted) ae.getEquipment(waa.getWeaponId()); - wtype = (WeaponType) weapon.getType(); - atype = (weapon.getLinked() != null && weapon.getLinked().getType() instanceof AmmoType) + attackerEntity = game.getEntity(weaponAttackAction.getEntityId()); + weapon = (WeaponMounted) attackerEntity.getEquipment(weaponAttackAction.getWeaponId()); + weaponType = (WeaponType) weapon.getType(); + ammoType = (weapon.getLinked() != null && weapon.getLinked().getType() instanceof AmmoType) ? (AmmoType) weapon.getLinked().getType() : null; - typeName = wtype.getInternalName(); - target = game.getTarget(waa.getTargetType(), waa.getTargetId()); + typeName = weaponType.getInternalName(); + target = game.getTarget(weaponAttackAction.getTargetType(), weaponAttackAction.getTargetId()); gameManager = m; subjectId = getAttackerId(); - nRange = Compute.effectiveDistance(game, ae, target); + nRange = Compute.effectiveDistance(game, attackerEntity, target); if (target instanceof Mek) { - throughFront = Compute.isThroughFrontHex(game, ae.getPosition(), (Entity) target); + throughFront = Compute.isThroughFrontHex(game, attackerEntity.getPosition(), (Entity) target); } else { throughFront = true; } // is this an underwater attack on a surface naval vessel? underWater = toHit.getHitTable() == ToHitData.HIT_UNDERWATER; - if (null != ae.getCrew()) { - roll = ae.getCrew().rollGunnerySkill(); + if (null != attackerEntity.getCrew()) { + roll = attackerEntity.getCrew().rollGunnerySkill(); } else { roll = Compute.rollD6(2); } - nweapons = getNumberWeapons(); - nweaponsHit = 1; + numberOfWeapons = getNumberWeapons(); + numberOfWeaponHits = 1; // use ammo when creating this, so it works when shooting the last shot // a unit has and we fire multiple weapons of the same type // TODO : need to adjust this for cases where not all the ammo is available - for (int i = 0; i < nweapons; i++) { + for (int i = 0; i < numberOfWeapons; i++) { useAmmo(); } if (target instanceof Entity) { ((Entity) target).addAttackedByThisTurn(w.getEntityId()); - if (!ae.isAirborne()) { + if (!attackerEntity.isAirborne()) { ((Entity) target).addGroundAttackedByThisTurn(w.getEntityId()); } } @@ -1854,10 +1851,10 @@ public WeaponHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) */ protected void initHit(Entity entityTarget) { hit = entityTarget.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), - waa.getAimingMode(), toHit.getCover()); + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), + weaponAttackAction.getAimingMode(), toHit.getCover()); hit.setGeneralDamageType(generalDamageType); - hit.setCapital(wtype.isCapital()); + hit.setCapital(weaponType.isCapital()); hit.setBoxCars(roll.getIntValue() == 12); hit.setCapMisCritMod(getCapMisMod()); hit.setFirstHit(firstHit); @@ -1869,7 +1866,7 @@ protected void initHit(Entity entityTarget) { } protected void useAmmo() { - if (wtype.hasFlag(WeaponType.F_DOUBLE_ONESHOT)) { + if (weaponType.hasFlag(WeaponType.F_DOUBLE_ONESHOT)) { ArrayList> chain = new ArrayList<>(); for (Mounted current = weapon.getLinked(); current != null; current = current.getLinked()) { chain.add(current); @@ -1886,7 +1883,7 @@ protected void useAmmo() { weapon.setFired(true); } } - } else if (wtype.hasFlag(WeaponType.F_ONESHOT)) { + } else if (weaponType.hasFlag(WeaponType.F_ONESHOT)) { weapon.setFired(true); } @@ -1903,15 +1900,15 @@ protected void addHeat() { return; } if (!(toHit.getValue() == TargetRoll.IMPOSSIBLE)) { - if (ae.usesWeaponBays() && !game.getOptions().booleanOption(OptionsConstants.ADVAERORULES_HEAT_BY_BAY)) { + if (attackerEntity.usesWeaponBays() && !game.getOptions().booleanOption(OptionsConstants.ADVAERORULES_HEAT_BY_BAY)) { int loc = weapon.getLocation(); boolean rearMount = weapon.isRearMounted(); - if (!ae.hasArcFired(loc, rearMount)) { - ae.heatBuildup += ae.getHeatInArc(loc, rearMount); - ae.setArcFired(loc, rearMount); + if (!attackerEntity.hasArcFired(loc, rearMount)) { + attackerEntity.heatBuildup += attackerEntity.getHeatInArc(loc, rearMount); + attackerEntity.setArcFired(loc, rearMount); } } else { - ae.heatBuildup += (weapon.getCurrentHeat()); + attackerEntity.heatBuildup += (weapon.getCurrentHeat()); } } } @@ -1948,8 +1945,8 @@ public void setAnnouncedEntityFiring(boolean announcedEntityFiring) { } @Override - public WeaponAttackAction getWaa() { - return waa; + public WeaponAttackAction getWeaponAttackAction() { + return weaponAttackAction; } public int checkTerrain(int nDamage, Entity entityTarget, Vector vPhaseReport) { @@ -1963,7 +1960,7 @@ public int checkTerrain(int nDamage, Entity entityTarget, Vector vPhaseR if (game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_WOODS_COVER) && hasWoods && !isAboveWoods - && !(entityTarget.getSwarmAttackerId() == ae.getId())) { + && !(entityTarget.getSwarmAttackerId() == attackerEntity.getId())) { Terrain woodHex = hex.getTerrain(Terrains.WOODS); Terrain jungleHex = hex.getTerrain(Terrains.JUNGLE); int treeAbsorbs = 0; @@ -1980,7 +1977,7 @@ public int checkTerrain(int nDamage, Entity entityTarget, Vector vPhaseR treeAbsorbs = Math.min(nDamage, treeAbsorbs); nDamage = Math.max(0, nDamage - treeAbsorbs); - gameManager.tryClearHex(entityTarget.getPosition(), treeAbsorbs, ae.getId()); + gameManager.tryClearHex(entityTarget.getPosition(), treeAbsorbs, attackerEntity.getId()); Report.addNewline(vPhaseReport); Report terrainReport = new Report(6427); terrainReport.subject = entityTarget.getId(); @@ -1997,22 +1994,22 @@ public int checkTerrain(int nDamage, Entity entityTarget, Vector vPhaseR * Check for Laser Inhibiting smoke clouds */ public int checkLI(int nDamage, Entity entityTarget, Vector vPhaseReport) { - if ((ae.getPosition() == null) || (entityTarget.getPosition() == null)) { + if ((attackerEntity.getPosition() == null) || (entityTarget.getPosition() == null)) { return nDamage; } - weapon = ae.getWeapon(waa.getWeaponId()); - wtype = weapon.getType(); + weapon = attackerEntity.getWeapon(weaponAttackAction.getWeaponId()); + weaponType = weapon.getType(); - if (!wtype.hasFlag(WeaponType.F_ENERGY)) { + if (!weaponType.hasFlag(WeaponType.F_ENERGY)) { return nDamage; } - ArrayList coords = Coords.intervening(ae.getPosition(), entityTarget.getPosition()); + ArrayList coords = Coords.intervening(attackerEntity.getPosition(), entityTarget.getPosition()); int refrac = 0; double travel = 0; - double range = ae.getPosition().distance(target.getPosition()); - double atkLev = ae.relHeight(); + double range = attackerEntity.getPosition().distance(target.getPosition()); + double atkLev = attackerEntity.relHeight(); double tarLev = entityTarget.relHeight(); double levDif = Math.abs(atkLev - tarLev); String hexType = "LASER inhibiting smoke"; @@ -2086,12 +2083,12 @@ protected int getNumberWeapons() { */ public void restore() { if (typeName == null) { - typeName = wtype.getName(); + typeName = weaponType.getName(); } else { - wtype = (WeaponType) EquipmentType.get(typeName); + weaponType = (WeaponType) EquipmentType.get(typeName); } - if (wtype == null) { + if (weaponType == null) { logger.error("Could not restore equipment type \"" + typeName + '"'); } } @@ -2099,7 +2096,7 @@ public void restore() { protected int getClusterModifiers(boolean clusterRangePenalty) { int nMissilesModifier = getSalvoBonus(); - int[] ranges = wtype.getRanges(weapon); + int[] ranges = weaponType.getRanges(weapon); if (clusterRangePenalty && game.getOptions().booleanOption(OptionsConstants.ADVCOMBAT_TACOPS_CLUSTERHITPEN)) { if (nRange <= 1) { nMissilesModifier += 1; @@ -2136,8 +2133,8 @@ protected int getClusterModifiers(boolean clusterRangePenalty) { nMissilesModifier -= 2; } - if (null != ae.getCrew()) { - if (ae.hasAbility(OptionsConstants.GUNNERY_SANDBLASTER, wtype.getName())) { + if (null != attackerEntity.getCrew()) { + if (attackerEntity.hasAbility(OptionsConstants.GUNNERY_SANDBLASTER, weaponType.getName())) { if (nRange > ranges[RangeType.RANGE_MEDIUM]) { nMissilesModifier += 2; } else if (nRange > ranges[RangeType.RANGE_SHORT]) { @@ -2145,9 +2142,9 @@ protected int getClusterModifiers(boolean clusterRangePenalty) { } else { nMissilesModifier += 4; } - } else if (ae.hasAbility(OptionsConstants.GUNNERY_CLUSTER_MASTER)) { + } else if (attackerEntity.hasAbility(OptionsConstants.GUNNERY_CLUSTER_MASTER)) { nMissilesModifier += 2; - } else if (ae.hasAbility(OptionsConstants.GUNNERY_CLUSTER_HITTER)) { + } else if (attackerEntity.hasAbility(OptionsConstants.GUNNERY_CLUSTER_HITTER)) { nMissilesModifier += 1; } } @@ -2249,14 +2246,14 @@ protected void addGlancingBlowReports(Vector vPhaseReport) { if (bGlancing) { r = new Report(3186); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } if (bLowProfileGlancing) { r = new Report(9985); - r.subject = ae.getId(); + r.subject = attackerEntity.getId(); r.newlines = 0; vPhaseReport.addElement(r); } diff --git a/megamek/src/megamek/common/weapons/battlearmor/BALBXHandler.java b/megamek/src/megamek/common/weapons/battlearmor/BALBXHandler.java index 57b23efeb1b..4f86ef1bd51 100644 --- a/megamek/src/megamek/common/weapons/battlearmor/BALBXHandler.java +++ b/megamek/src/megamek/common/weapons/battlearmor/BALBXHandler.java @@ -43,10 +43,10 @@ public BALBXHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) protected int calcDamagePerHit() { if (target.isConventionalInfantry()) { double toReturn = Compute.directBlowInfantryDamage( - wtype.getRackSize() * 2, bDirect ? toHit.getMoS() / 3 : 0, - wtype.getInfantryDamageClass(), + weaponType.getRackSize() * 2, bDirect ? toHit.getMoS() / 3 : 0, + weaponType.getInfantryDamageClass(), ((Infantry) target).isMechanized(), - toHit.getThruBldg() != null, ae.getId(), calcDmgPerHitReport); + toHit.getThruBldg() != null, attackerEntity.getId(), calcDmgPerHitReport); toReturn = applyGlancingBlowModifier(toReturn, true); return (int) toReturn; } @@ -61,20 +61,20 @@ protected int calcHits(Vector vPhaseReport) { bSalvo = true; Report r = new Report(3325); r.subject = subjectId; - r.add(wtype.getRackSize() * ((BattleArmor) ae).getShootingStrength()); + r.add(weaponType.getRackSize() * ((BattleArmor) attackerEntity).getShootingStrength()); r.add(sSalvoType); r.add(" "); vPhaseReport.add(r); - return ((BattleArmor) ae).getShootingStrength(); + return ((BattleArmor) attackerEntity).getShootingStrength(); } int missilesHit; int nMissilesModifier = getClusterModifiers(true); if (allShotsHit()) { - missilesHit = wtype.getRackSize() * ((BattleArmor) ae).getShootingStrength(); + missilesHit = weaponType.getRackSize() * ((BattleArmor) attackerEntity).getShootingStrength(); } else { - missilesHit = Compute.missilesHit(wtype.getRackSize() - * ((BattleArmor) ae).getShootingStrength(), + missilesHit = Compute.missilesHit(weaponType.getRackSize() + * ((BattleArmor) attackerEntity).getShootingStrength(), nMissilesModifier, weapon.isHotLoaded(), false, false); } diff --git a/megamek/src/megamek/common/weapons/battlearmor/BAMGHandler.java b/megamek/src/megamek/common/weapons/battlearmor/BAMGHandler.java index 92353d75296..0d698d2a892 100644 --- a/megamek/src/megamek/common/weapons/battlearmor/BAMGHandler.java +++ b/megamek/src/megamek/common/weapons/battlearmor/BAMGHandler.java @@ -46,14 +46,14 @@ public BAMGHandler(ToHitData t, WeaponAttackAction w, Game g, TWGameManager m) { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#calcDamagePerHit() */ @Override protected int calcDamagePerHit() { if (weapon.isRapidfire() && !(target instanceof Infantry)) { // Check for rapid fire Option. Only MGs can be rapidfire. - switch (wtype.getDamage()) { + switch (weaponType.getDamage()) { case 1: nDamPerHit = Math.max(1, Compute.d6() - 1); break; @@ -64,7 +64,7 @@ protected int calcDamagePerHit() { nDamPerHit = Compute.d6(); break; } - numRapidFireHits = nDamPerHit; + numberOfRapidFireHits = nDamPerHit; if (bDirect) { nDamPerHit = Math.min(nDamPerHit + (toHit.getMoS() / 3), nDamPerHit * 2); @@ -78,14 +78,14 @@ protected int calcDamagePerHit() { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#addHeat() */ @Override protected void addHeat() { if (!(toHit.getValue() == TargetRoll.IMPOSSIBLE)) { if (weapon.isRapidfire()) { - ae.heatBuildup += nDamPerHit; + attackerEntity.heatBuildup += nDamPerHit; } else { super.addHeat(); } @@ -94,7 +94,7 @@ protected void addHeat() { /* * (non-Javadoc) - * + * * @see megamek.common.weapons.WeaponHandler#reportMiss(java.util.Vector) */ @Override @@ -109,6 +109,6 @@ protected void reportMiss(Vector vPhaseReport) { r.subject = subjectId; r.add(nDamPerHit * 3); vPhaseReport.add(r); - } + } } } diff --git a/megamek/src/megamek/common/weapons/battlearmor/BATaserHandler.java b/megamek/src/megamek/common/weapons/battlearmor/BATaserHandler.java index 1c7e3af9209..c4701c87b9e 100644 --- a/megamek/src/megamek/common/weapons/battlearmor/BATaserHandler.java +++ b/megamek/src/megamek/common/weapons/battlearmor/BATaserHandler.java @@ -113,7 +113,7 @@ protected boolean specialResolution(Vector vPhaseReport, Entity entityTa Roll diceRoll2 = Compute.rollD6(2); r = new Report(3715); - r.addDesc(ae); + r.addDesc(attackerEntity); r.add(diceRoll2); r.newlines = 0; r.indent(2); @@ -122,13 +122,13 @@ protected boolean specialResolution(Vector vPhaseReport, Entity entityTa r = new Report(3720); vPhaseReport.add(r); // +1 to-hit for 3 turns - ae.setTaserFeedback(3); + attackerEntity.setTaserFeedback(3); } else { r = new Report(3725); vPhaseReport.add(r); // kill the firing trooper // TODO: should just be shut down for remainder of scenario - vPhaseReport.addAll(gameManager.criticalEntity(ae, weapon.getLocation(), + vPhaseReport.addAll(gameManager.criticalEntity(attackerEntity, weapon.getLocation(), false, 0, false, false, 0)); } return done; diff --git a/megamek/src/megamek/common/weapons/infantry/InfantryHeatWeaponHandler.java b/megamek/src/megamek/common/weapons/infantry/InfantryHeatWeaponHandler.java index 3b21ef7afac..95a4541baf4 100644 --- a/megamek/src/megamek/common/weapons/infantry/InfantryHeatWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/infantry/InfantryHeatWeaponHandler.java @@ -30,9 +30,9 @@ */ public class InfantryHeatWeaponHandler extends InfantryWeaponHandler { - + /** - * + * */ private static final long serialVersionUID = 8430370552107061610L; @@ -46,7 +46,7 @@ public InfantryHeatWeaponHandler(ToHitData t, WeaponAttackAction w, Game g, super(t, w, g, m); bSalvo = true; } - + @Override protected void handleEntityDamage(Entity entityTarget, Vector vPhaseReport, Building bldg, int hits, int nCluster, @@ -55,7 +55,7 @@ protected void handleEntityDamage(Entity entityTarget, Report.addNewline(vPhaseReport); // heat hit = entityTarget.rollHitLocation(toHit.getHitTable(), - toHit.getSideTable(), waa.getAimedLocation(), waa + toHit.getSideTable(), weaponAttackAction.getAimedLocation(), weaponAttackAction .getAimingMode(), toHit.getCover()); hit.setAttackerId(getAttackerId()); @@ -67,8 +67,8 @@ protected void handleEntityDamage(Entity entityTarget, if ((!indirect || partialCoverForIndirectFire) && entityTarget.removePartialCoverHits(hit.getLocation(), toHit - .getCover(), Compute.targetSideTable(ae, entityTarget, weapon.getCalledShot().getCall()))) { - // Weapon strikes Partial Cover. + .getCover(), Compute.targetSideTable(attackerEntity, entityTarget, weapon.getCalledShot().getCall()))) { + // Weapon strikes Partial Cover. handlePartialCoverHit(entityTarget, vPhaseReport, hit, bldg, hits, nCluster, bldgAbsorbs); return; @@ -91,11 +91,11 @@ protected void handleEntityDamage(Entity entityTarget, // If using BMM heat option, do damage as well as heat if (game.getOptions().booleanOption(OptionsConstants.BASE_INFANTRY_DAMAGE_HEAT)) { vPhaseReport.addAll(gameManager.damageEntity(entityTarget, hit, nDamage, false, - ae.getSwarmTargetId() == entityTarget.getId() ? DamageType.IGNORE_PASSENGER : damageType, + attackerEntity.getSwarmTargetId() == entityTarget.getId() ? DamageType.IGNORE_PASSENGER : damageType, false, false, throughFront, underWater, nukeS2S)); } if (entityTarget.getArmor(hit) > 0 && - (entityTarget.getArmorType(hit.getLocation()) == + (entityTarget.getArmorType(hit.getLocation()) == EquipmentType.T_ARMOR_HEAT_DISSIPATING)) { entityTarget.heatFromExternal += nDamage / 2; r.add(nDamage / 2); diff --git a/megamek/src/megamek/common/weapons/infantry/InfantryWeaponHandler.java b/megamek/src/megamek/common/weapons/infantry/InfantryWeaponHandler.java index 9742812d0a3..14bc7ba78f2 100644 --- a/megamek/src/megamek/common/weapons/infantry/InfantryWeaponHandler.java +++ b/megamek/src/megamek/common/weapons/infantry/InfantryWeaponHandler.java @@ -1,7 +1,7 @@ /* * MegaMek - Copyright (C) 2004,2005 Ben Mazur (bmazur@sev.org) * Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. - * + * * This file is part of MegaMek. * * This program is free software; you can redistribute it and/or modify it @@ -85,25 +85,25 @@ protected int calcHits(Vector vPhaseReport) { int troopersHit = 0; // when swarming all troopers hit - if (ae.getSwarmTargetId() == target.getId()) { - troopersHit = ((Infantry) ae).getShootingStrength(); - } else if (!(ae instanceof Infantry)) { + if (attackerEntity.getSwarmTargetId() == target.getId()) { + troopersHit = ((Infantry) attackerEntity).getShootingStrength(); + } else if (!(attackerEntity instanceof Infantry)) { troopersHit = 1; } else { - troopersHit = Compute.missilesHit(((Infantry) ae) + troopersHit = Compute.missilesHit(((Infantry) attackerEntity) .getShootingStrength(), nHitMod); } - double damage = calculateBaseDamage(ae, weapon, wtype); + double damage = calculateBaseDamage(attackerEntity, weapon, weaponType); - if ((ae instanceof Infantry) && (nRange == 0) - && ae.hasAbility(OptionsConstants.MD_TSM_IMPLANT)) { + if ((attackerEntity instanceof Infantry) && (nRange == 0) + && attackerEntity.hasAbility(OptionsConstants.MD_TSM_IMPLANT)) { damage += 0.14; } int damageDealt = (int) Math.round(damage * troopersHit); - + // beast-mounted infantry get range 0 bonus damage per platoon - if ((ae instanceof Infantry) && (nRange == 0)) { - InfantryMount mount = ((Infantry) ae).getMount(); + if ((attackerEntity instanceof Infantry) && (nRange == 0)) { + InfantryMount mount = ((Infantry) attackerEntity).getMount(); if (mount != null) { if (!target.isConventionalInfantry()) { damageDealt += mount.getVehicleDamage(); @@ -116,23 +116,23 @@ protected int calcHits(Vector vPhaseReport) { // conventional infantry weapons with high damage get treated as if they have // the infantry burst mod if (target.isConventionalInfantry() && - (wtype.hasFlag(WeaponType.F_INF_BURST) || - (ae.isConventionalInfantry() && ((Infantry) ae).primaryWeaponDamageCapped()))) { + (weaponType.hasFlag(WeaponType.F_INF_BURST) || + (attackerEntity.isConventionalInfantry() && ((Infantry) attackerEntity).primaryWeaponDamageCapped()))) { damageDealt += Compute.d6(); } if ((target instanceof Infantry) && ((Infantry) target).isMechanized()) { damageDealt /= 2; } // this doesn't work... - if ((target instanceof Building) && (wtype.hasFlag(WeaponType.F_INF_NONPENETRATING))) { + if ((target instanceof Building) && (weaponType.hasFlag(WeaponType.F_INF_NONPENETRATING))) { damageDealt = 0; } - if (wtype.hasFlag(WeaponType.F_INF_NONPENETRATING)) { + if (weaponType.hasFlag(WeaponType.F_INF_NONPENETRATING)) { damageType = DamageType.NONPENETRATING; } Report r = new Report(3325); r.subject = subjectId; - if (ae instanceof Infantry) { + if (attackerEntity instanceof Infantry) { r.add(troopersHit); r.add(" troopers "); } else { // Needed for support tanks with infantry weapons @@ -165,9 +165,9 @@ protected int calcAttackValue() { int av; // Sigh, another rules oversight - nobody bothered to figure this out // To be consistent with other cluster weapons we will assume 60% hit - if (ae.isConventionalInfantry()) { - double damage = ((Infantry) ae).getDamagePerTrooper(); - av = (int) Math.round(damage * 0.6 * ((Infantry) ae).getShootingStrength()); + if (attackerEntity.isConventionalInfantry()) { + double damage = ((Infantry) attackerEntity).getDamagePerTrooper(); + av = (int) Math.round(damage * 0.6 * ((Infantry) attackerEntity).getShootingStrength()); } else { // Small fixed wing support av = super.calcAttackValue(); @@ -181,16 +181,16 @@ protected int calcAttackValue() { @Override public void useAmmo() { - if (ae.isSupportVehicle()) { + if (attackerEntity.isSupportVehicle()) { Mounted ammo = weapon.getLinked(); if (ammo == null) { - ae.loadWeapon(weapon); + attackerEntity.loadWeapon(weapon); ammo = weapon.getLinked(); } if (ammo == null) {// Can't happen. w/o legal ammo, the weapon // *shouldn't* fire. logger.error(String.format("Handler can't find any ammo for %s firing %s", - ae.getShortName(), weapon.getName())); + attackerEntity.getShortName(), weapon.getName())); return; } @@ -231,12 +231,12 @@ public static double calculateBaseDamage(Entity ae, Mounted weapon, WeaponTyp @Override protected void initHit(Entity entityTarget) { - if ((entityTarget instanceof BattleArmor) && ae.isConventionalInfantry()) { + if ((entityTarget instanceof BattleArmor) && attackerEntity.isConventionalInfantry()) { // TacOps crits against BA do not happen for infantry weapon attacks hit = ((BattleArmor) entityTarget).rollHitLocation(toHit.getSideTable(), - waa.getAimedLocation(), waa.getAimingMode(), true); + weaponAttackAction.getAimedLocation(), weaponAttackAction.getAimingMode(), true); hit.setGeneralDamageType(generalDamageType); - hit.setCapital(wtype.isCapital()); + hit.setCapital(weaponType.isCapital()); hit.setBoxCars(roll.getIntValue() == 12); hit.setCapMisCritMod(getCapMisMod()); hit.setFirstHit(firstHit); diff --git a/megamek/src/megamek/server/commands/AerialSupportCommand.java b/megamek/src/megamek/server/commands/AerialSupportCommand.java new file mode 100644 index 00000000000..2fbb7d717d6 --- /dev/null +++ b/megamek/src/megamek/server/commands/AerialSupportCommand.java @@ -0,0 +1,60 @@ +/* + * MegaMek - Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ +package megamek.server.commands; + +import megamek.client.ui.Messages; +import megamek.server.Server; +import megamek.server.commands.arguments.*; +import megamek.server.totalwarfare.TWGameManager; + +import java.util.List; + +/** + * @author Luana Coppio + */ +public class AerialSupportCommand extends ClientServerCommand { + + /** Creates new NukeCommand */ + public AerialSupportCommand(Server server, TWGameManager gameManager) { + super(server, gameManager, "as", Messages.getString("Gamemaster.cmd.aerialsupport.help"), + Messages.getString("Gamemaster.cmd.aerialsupport.longName")); + } + + @Override + public List> defineArguments() { + return List.of( + new CoordXArgument("x", Messages.getString("Gamemaster.cmd.x")), + new CoordYArgument("y", Messages.getString("Gamemaster.cmd.y")), + new EnumArgument<>("type", Messages.getString("Gamemaster.cmd.aerialsupport.type"), AerialSupportType.class) + ); + } + + public enum AerialSupportType { + LIGHT_STRIKE, + LIGHT_BOMBING, + HEAVY_STRIKE, + HEAVY_BOMBING, + STRAFING + } + + @Override + protected void runCommand(int connId, Arguments args) { + // is the hex on the board? + if (isOutsideOfBoard(connId, args)) { + return; + } + // TODO Luana : implement the Aerial Support command later + server.sendServerChat(connId, Messages.getString("Gamemaster.cmd.aerialsupport.success")); + } +} diff --git a/megamek/src/megamek/server/commands/ArtilleryStrikeCommand.java b/megamek/src/megamek/server/commands/ArtilleryStrikeCommand.java new file mode 100644 index 00000000000..2a295e1e71a --- /dev/null +++ b/megamek/src/megamek/server/commands/ArtilleryStrikeCommand.java @@ -0,0 +1,63 @@ +/* + * MegaMek - Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ +package megamek.server.commands; + +import megamek.client.ui.Messages; +import megamek.server.Server; +import megamek.server.commands.arguments.*; +import megamek.server.totalwarfare.TWGameManager; + +import java.util.List; + +/** + * @author Luana Coppio + */ +public class ArtilleryStrikeCommand extends ClientServerCommand { + + /** Creates new NukeCommand */ + public ArtilleryStrikeCommand(Server server, TWGameManager gameManager) { + super(server, gameManager, "art", Messages.getString("Gamemaster.cmd.art.help"), + Messages.getString("Gamemaster.cmd.art.longName")); + } + + public enum ArtillerySupportType { + THUMPER, + SNIPER, + LONGTOM, + ARROWIV, + FLARE, + SMOKE, + NUKE + } + + @Override + public List> defineArguments() { + return List.of( + new CoordXArgument("x", Messages.getString("Gamemaster.cmd.x")), + new CoordYArgument("y", Messages.getString("Gamemaster.cmd.y")), + new EnumArgument<>("type", Messages.getString("Gamemaster.cmd.art.type"), ArtillerySupportType.class) + ); + } + + @Override + protected void runCommand(int connId, Arguments args) { + + // is the hex on the board? + if (isOutsideOfBoard(connId, args)) { + return; + } + // TODO Luana: implement the full BSP later + server.sendServerChat(connId, Messages.getString("Gamemaster.cmd.nuke.success")); + } +} diff --git a/megamek/src/megamek/server/commands/ChangeOwnershipCommand.java b/megamek/src/megamek/server/commands/ChangeOwnershipCommand.java index ec113305ddd..9ce651baf8e 100644 --- a/megamek/src/megamek/server/commands/ChangeOwnershipCommand.java +++ b/megamek/src/megamek/server/commands/ChangeOwnershipCommand.java @@ -17,9 +17,7 @@ import megamek.common.Entity; import megamek.common.Player; import megamek.server.Server; -import megamek.server.commands.arguments.Argument; -import megamek.server.commands.arguments.Arguments; -import megamek.server.commands.arguments.IntegerArgument; +import megamek.server.commands.arguments.*; import megamek.server.totalwarfare.TWGameManager; import java.util.List; @@ -46,14 +44,14 @@ public ChangeOwnershipCommand(Server server, TWGameManager gameManager) { @Override public List> defineArguments() { return List.of( - new IntegerArgument(UNIT_ID, Messages.getString("Gamemaster.cmd.changeownership.unitID")), - new IntegerArgument(PLAYER_ID, Messages.getString("Gamemaster.cmd.changeownership.playerID"))); + new UnitArgument(UNIT_ID, Messages.getString("Gamemaster.cmd.changeownership.unitID")), + new PlayerArgument(PLAYER_ID, Messages.getString("Gamemaster.cmd.changeownership.playerID"))); } @Override protected void runCommand(int connId, Arguments args) { - IntegerArgument unitID = (IntegerArgument) args.get(UNIT_ID); - IntegerArgument playerID = (IntegerArgument) args.get(PLAYER_ID); + var unitID = (UnitArgument) args.get(UNIT_ID); + var playerID = (PlayerArgument) args.get(PLAYER_ID); Entity ent = gameManager.getGame().getEntity(unitID.getValue()); Player player = server.getGame().getPlayer(playerID.getValue()); diff --git a/megamek/src/megamek/server/commands/ChangeTeamCommand.java b/megamek/src/megamek/server/commands/ChangeTeamCommand.java index 74507dec788..bea0a71def3 100644 --- a/megamek/src/megamek/server/commands/ChangeTeamCommand.java +++ b/megamek/src/megamek/server/commands/ChangeTeamCommand.java @@ -17,9 +17,7 @@ import megamek.common.Entity; import megamek.common.Player; import megamek.server.Server; -import megamek.server.commands.arguments.Argument; -import megamek.server.commands.arguments.Arguments; -import megamek.server.commands.arguments.IntegerArgument; +import megamek.server.commands.arguments.*; import megamek.server.totalwarfare.TWGameManager; import java.util.List; @@ -45,14 +43,14 @@ public ChangeTeamCommand(Server server, TWGameManager gameManager) { @Override public List> defineArguments() { return List.of( - new IntegerArgument(PLAYER_ID, Messages.getString("Gamemaster.cmd.changeteam.playerID")), - new IntegerArgument(TEAM_ID, Messages.getString("Gamemaster.cmd.changeteam.teamID"))); + new PlayerArgument(PLAYER_ID, Messages.getString("Gamemaster.cmd.changeteam.playerID")), + new TeamArgument(TEAM_ID, Messages.getString("Gamemaster.cmd.changeteam.teamID"))); } @Override protected void runCommand(int connId, Arguments args) { - int teamID = ((IntegerArgument) args.get(TEAM_ID)).getValue(); - int playerID = ((IntegerArgument) args.get(PLAYER_ID)).getValue(); + int playerID = ((PlayerArgument) args.get(PLAYER_ID)).getValue(); + int teamID = ((TeamArgument) args.get(TEAM_ID)).getValue(); Player player = server.getGame().getPlayer(playerID); if (null == player) { diff --git a/megamek/src/megamek/server/commands/ClientServerCommand.java b/megamek/src/megamek/server/commands/ClientServerCommand.java index 7244d546853..6e278ef2ccd 100644 --- a/megamek/src/megamek/server/commands/ClientServerCommand.java +++ b/megamek/src/megamek/server/commands/ClientServerCommand.java @@ -81,6 +81,10 @@ protected boolean preRun(int connId) { return true; } + protected boolean isGM(int connId) { + return server.getGameManager().getGame().getPlayer(connId).getGameMaster(); + } + private void safeParseArgumentsAndRun(int connId, String[] args) { try { var parsedArguments = new Arguments(parseArguments(args)); @@ -98,6 +102,20 @@ public List> defineArguments() { return List.of(); } + protected boolean isOutsideOfBoard(int connId, Arguments args) { + if (!(args.hasArg("x") && args.hasArg("y"))) { + // There is nothing to check, s out of excess of caution we return false. + return true; + } + + // is the hex on the board? + if (!gameManager.getGame().getBoard().contains(((int) args.get("x").getValue()) - 1 , ((int) args.get("y").getValue()) - 1)) { + server.sendServerChat(connId, Messages.getString("Gamemaster.cmd.error.outofbounds")); + return true; + } + return false; + } + // Parses the arguments using the definition private Map> parseArguments(String[] args) { diff --git a/megamek/src/megamek/server/commands/DisasterCommand.java b/megamek/src/megamek/server/commands/DisasterCommand.java index 6150ef019b8..e3c2479c327 100644 --- a/megamek/src/megamek/server/commands/DisasterCommand.java +++ b/megamek/src/megamek/server/commands/DisasterCommand.java @@ -131,7 +131,6 @@ private void runDisasterCommand(int connId, Disaster disaster) { server.sendServerChat("The star is going supernova!"); server.sendServerChat("Everything is on fire! We are doomed!"); break; - case SANDSTORM: new ChangeWeatherCommand(server, gameManager).run(connId, new String[]{"weather", "blowsand=1", "wind=4", "winddir=6"}); server.sendServerChat("A sandstorm is approaching!"); diff --git a/megamek/src/megamek/server/commands/EndGameCommand.java b/megamek/src/megamek/server/commands/EndGameCommand.java index 2390f534435..95180ef19cc 100644 --- a/megamek/src/megamek/server/commands/EndGameCommand.java +++ b/megamek/src/megamek/server/commands/EndGameCommand.java @@ -16,10 +16,7 @@ import megamek.client.ui.Messages; import megamek.common.options.OptionsConstants; import megamek.server.Server; -import megamek.server.commands.arguments.Argument; -import megamek.server.commands.arguments.Arguments; -import megamek.server.commands.arguments.BooleanArgument; -import megamek.server.commands.arguments.IntegerArgument; +import megamek.server.commands.arguments.*; import megamek.server.totalwarfare.TWGameManager; import java.util.List; @@ -45,13 +42,13 @@ public EndGameCommand(Server server, TWGameManager gameManager) { @Override public List> defineArguments() { return List.of( - new IntegerArgument(PLAYER_ID, Messages.getString("Gamemaster.cmd.endgame.playerID")), + new PlayerArgument(PLAYER_ID, Messages.getString("Gamemaster.cmd.endgame.playerID")), new BooleanArgument(FORCE, Messages.getString("Gamemaster.cmd.endgame.force"), false)); } @Override protected void runCommand(int connId, Arguments args) { - int playerID = ((IntegerArgument) args.get(PLAYER_ID)).getValue(); + int playerID = ((PlayerArgument) args.get(PLAYER_ID)).getValue(); boolean force = ((BooleanArgument) args.get(FORCE)).getValue(); var player = server.getGame().getPlayer(playerID); diff --git a/megamek/src/megamek/server/commands/FirefightCommand.java b/megamek/src/megamek/server/commands/FirefightCommand.java index 1e1ba0d6254..50c830ab629 100644 --- a/megamek/src/megamek/server/commands/FirefightCommand.java +++ b/megamek/src/megamek/server/commands/FirefightCommand.java @@ -19,11 +19,11 @@ import megamek.server.Server; import megamek.server.commands.arguments.Argument; import megamek.server.commands.arguments.Arguments; -import megamek.server.commands.arguments.IntegerArgument; +import megamek.server.commands.arguments.CoordXArgument; +import megamek.server.commands.arguments.CoordYArgument; import megamek.server.totalwarfare.TWGameManager; import java.util.List; -import java.util.Map; import java.util.Objects; /** @@ -36,7 +36,6 @@ public class FirefightCommand extends GamemasterServerCommand { private static final String FIRESTARTER = "firefight"; private static final String X = "x"; private static final String Y = "y"; - private static final String TYPE = "type"; public FirefightCommand(Server server, TWGameManager gameManager) { super(server, @@ -49,8 +48,8 @@ public FirefightCommand(Server server, TWGameManager gameManager) { @Override public List> defineArguments() { return List.of( - new IntegerArgument(X, Messages.getString("Gamemaster.cmd.x")), - new IntegerArgument(Y, Messages.getString("Gamemaster.cmd.y")) + new CoordXArgument(X, Messages.getString("Gamemaster.cmd.x")), + new CoordYArgument(Y, Messages.getString("Gamemaster.cmd.y")) ); } diff --git a/megamek/src/megamek/server/commands/FirestarterCommand.java b/megamek/src/megamek/server/commands/FirestarterCommand.java index 702f57b02ca..8d860cdfceb 100644 --- a/megamek/src/megamek/server/commands/FirestarterCommand.java +++ b/megamek/src/megamek/server/commands/FirestarterCommand.java @@ -17,9 +17,7 @@ import megamek.common.Coords; import megamek.common.Hex; import megamek.server.Server; -import megamek.server.commands.arguments.Argument; -import megamek.server.commands.arguments.Arguments; -import megamek.server.commands.arguments.IntegerArgument; +import megamek.server.commands.arguments.*; import megamek.server.totalwarfare.TWGameManager; import java.util.List; @@ -49,8 +47,8 @@ public FirestarterCommand(Server server, TWGameManager gameManager) { @Override public List> defineArguments() { return List.of( - new IntegerArgument(X, Messages.getString("Gamemaster.cmd.x")), - new IntegerArgument(Y, Messages.getString("Gamemaster.cmd.y")), + new CoordXArgument(X, Messages.getString("Gamemaster.cmd.x")), + new CoordYArgument(Y, Messages.getString("Gamemaster.cmd.y")), new IntegerArgument(TYPE, Messages.getString("Gamemaster.cmd.fire.type"), 1, 4, 1)); } diff --git a/megamek/src/megamek/server/commands/GamemasterServerCommand.java b/megamek/src/megamek/server/commands/GamemasterServerCommand.java index e4e5a82a7ec..2bdfc58f1e9 100644 --- a/megamek/src/megamek/server/commands/GamemasterServerCommand.java +++ b/megamek/src/megamek/server/commands/GamemasterServerCommand.java @@ -44,10 +44,6 @@ public GamemasterServerCommand(Server server, TWGameManager gameManager, String super(server, gameManager, name, helpText, longName); } - private boolean isGM(int connId) { - return server.getGameManager().getGame().getPlayer(connId).getGameMaster(); - } - @Override protected boolean preRun(int connId) { // Override to add pre-run checks diff --git a/megamek/src/megamek/server/commands/KillCommand.java b/megamek/src/megamek/server/commands/KillCommand.java index d727f9d487e..af84148780d 100644 --- a/megamek/src/megamek/server/commands/KillCommand.java +++ b/megamek/src/megamek/server/commands/KillCommand.java @@ -18,6 +18,7 @@ import megamek.server.commands.arguments.Argument; import megamek.server.commands.arguments.Arguments; import megamek.server.commands.arguments.IntegerArgument; +import megamek.server.commands.arguments.UnitArgument; import megamek.server.totalwarfare.TWGameManager; import java.util.List; @@ -38,7 +39,7 @@ public KillCommand(Server server, TWGameManager gameManager) { @Override public List> defineArguments() { - return List.of(new IntegerArgument(UNIT_ID, Messages.getString("Gamemaster.cmd.kill.unitID"))); + return List.of(new UnitArgument(UNIT_ID, Messages.getString("Gamemaster.cmd.kill.unitID"))); } /** diff --git a/megamek/src/megamek/server/commands/NuclearStrikeCommand.java b/megamek/src/megamek/server/commands/NuclearStrikeCommand.java new file mode 100644 index 00000000000..e572df5dc48 --- /dev/null +++ b/megamek/src/megamek/server/commands/NuclearStrikeCommand.java @@ -0,0 +1,94 @@ +/* + * MegaMek - Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ +package megamek.server.commands; + +import megamek.client.ui.Messages; +import megamek.common.AmmoType; +import megamek.common.Entity; +import megamek.common.Player; +import megamek.common.actions.NukeDetonatedAction; +import megamek.common.event.GamePlayerStrategicActionEvent; +import megamek.common.options.OptionsConstants; +import megamek.server.Server; +import megamek.server.commands.arguments.*; +import megamek.server.totalwarfare.TWGameManager; + +import java.util.List; +import java.util.Optional; + +/** + * @author Luana Coppio + */ +public class NuclearStrikeCommand extends ClientServerCommand { + + /** Creates new NukeCommand */ + public NuclearStrikeCommand(Server server, TWGameManager gameManager) { + super(server, gameManager, "ns", Messages.getString("Gamemaster.cmd.nuke.help"), + Messages.getString("Gamemaster.cmd.nuke.longName")); + } + + public enum NukeType { + DAVY_CROCKETT_I, + DAVY_CROCKETT_M, + ALAMO, + SANTA_ANA, + PEACEMAKER + } + + @Override + public List> defineArguments() { + return List.of( + new CoordXArgument("x", Messages.getString("Gamemaster.cmd.x")), + new CoordYArgument("y", Messages.getString("Gamemaster.cmd.y")), + new EnumArgument<>("type", Messages.getString("Gamemaster.cmd.nuke.type"), NukeType.class, NukeType.DAVY_CROCKETT_M), + new OptionalIntegerArgument("playerID", Messages.getString("Gamemaster.cmd.playerID")) + ); + } + + @Override + @SuppressWarnings("unchecked") + protected void runCommand(int connId, Arguments args) { + // Check to make sure nuking is allowed by game options! + if (!isGM(connId)) { + if (!(server.getGame().getOptions().booleanOption(OptionsConstants.ALLOWED_REALLY_ALLOW_NUKES) + && server.getGame().getOptions().booleanOption(OptionsConstants.ALLOWED_ALLOW_NUKES))) { + server.sendServerChat(connId, Messages.getString("Gamemaster.cmd.nuke.error.disabled")); + return; + } + } + + if (isOutsideOfBoard(connId, args)) { + return; + } + + var nukeType = (NukeType) args.get("type").getValue(); + int[] nuke = { + ((IntegerArgument) args.get("x")).getValue() - 1, + ((IntegerArgument) args.get("y")).getValue() - 1, + nukeType.ordinal() + }; + + var playerID = (Optional) args.get("playerID").getValue(); + var player = getGameManager().getGame().getPlayer(playerID.orElse(Player.PLAYER_NONE)); + if (player != null) { + gameManager.getGame().processGameEvent( + new GamePlayerStrategicActionEvent(gameManager, + new NukeDetonatedAction(Entity.NONE, Player.PLAYER_NONE, AmmoType.Munitions.M_DAVY_CROCKETT_M))); + } + + gameManager.addScheduledNuke(nuke); + server.sendServerChat(connId, Messages.getString("Gamemaster.cmd.nuke.success")); + + } +} diff --git a/megamek/src/megamek/server/commands/NuclearStrikeCustomCommand.java b/megamek/src/megamek/server/commands/NuclearStrikeCustomCommand.java new file mode 100644 index 00000000000..a46a87d859e --- /dev/null +++ b/megamek/src/megamek/server/commands/NuclearStrikeCustomCommand.java @@ -0,0 +1,93 @@ +/* + * MegaMek - Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ +package megamek.server.commands; + +import megamek.client.ui.Messages; +import megamek.common.AmmoType; +import megamek.common.Entity; +import megamek.common.Player; +import megamek.common.actions.NukeDetonatedAction; +import megamek.common.event.GamePlayerStrategicActionEvent; +import megamek.common.options.OptionsConstants; +import megamek.server.Server; +import megamek.server.commands.arguments.*; +import megamek.server.totalwarfare.TWGameManager; + +import java.util.List; +import java.util.Optional; + +/** + * @author Luana Coppio + */ +public class NuclearStrikeCustomCommand extends ClientServerCommand { + + /** Creates new NukeCommand */ + public NuclearStrikeCustomCommand(Server server, TWGameManager gameManager) { + super(server, gameManager, "nsc", Messages.getString("Gamemaster.cmd.nukec.help"), + Messages.getString("Gamemaster.cmd.nukec.longName")); + } + + @Override + public List> defineArguments() { + return List.of( + new CoordXArgument("x", Messages.getString("Gamemaster.cmd.x")), + new CoordYArgument("y", Messages.getString("Gamemaster.cmd.y")), + new IntegerArgument("dmg", Messages.getString("Gamemaster.cmd.nukec.dmg"), 0, 1_000_000), + new IntegerArgument("deg", Messages.getString("Gamemaster.cmd.nukec.deg"), 0, 1_000_000), + new IntegerArgument("radius", Messages.getString("Gamemaster.cmd.nukec.radius"), 1, 1000), + new IntegerArgument("depth", Messages.getString("Gamemaster.cmd.nukec.depth"), 0, 9), + new OptionalIntegerArgument("playerID", Messages.getString("Gamemaster.cmd.playerID")) + ); + } + + @Override + @SuppressWarnings("unchecked") + protected void runCommand(int connId, Arguments args) { + + // The GM can ignore the rules and nuke at will + if (!isGM(connId)) { + // Check to make sure nuking is allowed by game options! + if (!(server.getGame().getOptions().booleanOption(OptionsConstants.ALLOWED_REALLY_ALLOW_NUKES) + && server.getGame().getOptions().booleanOption(OptionsConstants.ALLOWED_ALLOW_NUKES))) { + server.sendServerChat(connId, Messages.getString("Gamemaster.cmd.nuke.error.disabled")); + return; + } + } + + // is the hex on the board? + if (isOutsideOfBoard(connId, args)) { + return; + } + + int[] nuke = { + (int) args.get("x").getValue() - 1, + (int) args.get("y").getValue() - 1, + (int) args.get("dmg").getValue(), + (int) args.get("deg").getValue(), + (int) args.get("radius").getValue(), + (int) args.get("depth").getValue() + }; + + var playerID = (Optional) args.get("playerID").getValue(); + var player = getGameManager().getGame().getPlayer(playerID.orElse(Player.PLAYER_NONE)); + if (player != null) { + gameManager.getGame().processGameEvent( + new GamePlayerStrategicActionEvent(gameManager, + new NukeDetonatedAction(Entity.NONE, Player.PLAYER_NONE, AmmoType.Munitions.M_DAVY_CROCKETT_M))); + } + + gameManager.addScheduledNuke(nuke); + server.sendServerChat(connId, Messages.getString("Gamemaster.cmd.nuke.success")); + } +} diff --git a/megamek/src/megamek/server/commands/NukeCommand.java b/megamek/src/megamek/server/commands/NukeCommand.java index 07800d5729a..a79cc61b437 100644 --- a/megamek/src/megamek/server/commands/NukeCommand.java +++ b/megamek/src/megamek/server/commands/NukeCommand.java @@ -15,10 +15,7 @@ package megamek.server.commands; import megamek.common.options.OptionsConstants; -import megamek.server.commands.arguments.Argument; -import megamek.server.commands.arguments.Arguments; -import megamek.server.commands.arguments.IntegerArgument; -import megamek.server.commands.arguments.OptionalIntegerArgument; +import megamek.server.commands.arguments.*; import megamek.server.totalwarfare.TWGameManager; import megamek.server.Server; @@ -40,15 +37,15 @@ public NukeCommand(Server server, TWGameManager gameManager) { "/nuke and" + "/nuke " + "where type is 0-4 (0: Davy-Crockett-I, 1: Davy-Crockett-M, 2: Alamo, 3: Santa Ana, 4: Peacemaker)" + - "and hex x, y is x=column number and y=row number (hex 0923 would be x=9 and y=23)", "Nuclear Strike"); + "and hex x, y is x=column number and y=row number (hex 0923 would be x=9 and y=23)", "Nuclear Strike (old)"); this.gameManager = gameManager; } @Override public List> defineArguments() { return List.of( - new IntegerArgument("x", "The x-coordinate of the hex to nuke."), - new IntegerArgument("y", "The y-coordinate of the hex to nuke."), + new CoordXArgument("x", "The x-coordinate of the hex to nuke."), + new CoordYArgument("y", "The y-coordinate of the hex to nuke."), new OptionalIntegerArgument("type", "The type of nuke to drop. " + "(0: Davy-Crockett-I, 1: Davy-Crockett-M, 2: Alamo, 3: Santa Ana, 4: Peacemaker)", 0, 4), new OptionalIntegerArgument("dmg", "The damage of the nuke.", 0, 1_000_000), diff --git a/megamek/src/megamek/server/commands/OrbitalBombardmentCommand.java b/megamek/src/megamek/server/commands/OrbitalBombardmentCommand.java index b3e4cd530b6..47ab7e377ba 100644 --- a/megamek/src/megamek/server/commands/OrbitalBombardmentCommand.java +++ b/megamek/src/megamek/server/commands/OrbitalBombardmentCommand.java @@ -15,9 +15,7 @@ import megamek.client.ui.Messages; import megamek.server.Server; -import megamek.server.commands.arguments.Argument; -import megamek.server.commands.arguments.Arguments; -import megamek.server.commands.arguments.IntegerArgument; +import megamek.server.commands.arguments.*; import megamek.server.props.OrbitalBombardment; import megamek.server.totalwarfare.TWGameManager; @@ -42,9 +40,9 @@ public OrbitalBombardmentCommand(Server server, TWGameManager gameManager) { @Override public List> defineArguments() { return List.of( - new IntegerArgument(X, Messages.getString("Gamemaster.cmd.x")), - new IntegerArgument(Y, Messages.getString("Gamemaster.cmd.y")), - new IntegerArgument(DMG, Messages.getString("Gamemaster.cmd.orbitalbombardment.dmg"), 10, Integer.MAX_VALUE, 100), + new CoordXArgument(X, Messages.getString("Gamemaster.cmd.x")), + new CoordYArgument(Y, Messages.getString("Gamemaster.cmd.y")), + new IntegerArgument(DMG, Messages.getString("Gamemaster.cmd.orbitalbombardment.dmg"), 10, 1_000_000, 100), new IntegerArgument(RADIUS, Messages.getString("Gamemaster.cmd.orbitalbombardment.radius"), 1, 10, 4)); } diff --git a/megamek/src/megamek/server/commands/RequestSupportCommand.java b/megamek/src/megamek/server/commands/RequestSupportCommand.java new file mode 100644 index 00000000000..e90845d0b79 --- /dev/null +++ b/megamek/src/megamek/server/commands/RequestSupportCommand.java @@ -0,0 +1,157 @@ +/* + * MegaMek - Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ +package megamek.server.commands; + +import megamek.client.ui.Messages; +import megamek.common.Compute; +import megamek.common.Coords; +import megamek.common.options.OptionsConstants; +import megamek.server.Server; +import megamek.server.commands.arguments.*; +import megamek.server.totalwarfare.TWGameManager; + +import java.util.List; + +/** + * @author Luana Coppio + */ +public class RequestSupportCommand extends ClientServerCommand { + + private final TWGameManager gameManager; + + public RequestSupportCommand(Server server, TWGameManager gameManager) { + super(server, gameManager, "hq", Messages.getString("Gamemaster.cmd.support.help"), + Messages.getString("Gamemaster.cmd.support.longName")); + this.gameManager = gameManager; + } + + private enum SupportType { + OAS_LightStrike(5, 2), + OAS_LightBombing(3, 3), + OAS_HeavyStrike(6, 3), + OAS_HeavyBombing(7, 4), + OAS_Strafing(7, 5), +// implement the full BSP later +// DAS_LAC_LightStrike(3, 1), +// DAS_LAC_LightBombing(4, 1), +// DAS_LAC_HeavyStrike(9, 1), +// DAS_LAC_HeavyBombing(11, 1), +// DAS_LAC_Strafing(11, 1), +// DAS_HAC_LightStrike(9, 2), +// DAS_HAC_LightBombing(9, 2), +// DAS_HAC_HeavyStrike(5, 2), +// DAS_HAC_HeavyBombing(6, 2), +// DAS_HAC_Strafing(6, 2), +// MINES_LightDensity(9, 0.5f), +// MINES_MediumDensity(8, 2), +// MINES_HeavyDensity(7, 4); + ART_Thumper(8, 3), + ART_Sniper(8, 4), + ART_LongTom(8, 6), + ART_ArrowIV(8, 4), // copperhead :P + + ART_Illumination(8, 1.5f), + ART_Smoke(8, 1.5f), + + ART_Nuke(8, 22), + + ORT_bombardment(8, 15); + + + private int targetNumber; + private float bspCost; + + SupportType(int targetNumber, float bspCost) { + this.bspCost = bspCost; + this.targetNumber = targetNumber; + } + + public float bspCost() { + return this.bspCost; + } + + public int targetNumber() { + return this.targetNumber; + } + } + + @Override + public List> defineArguments() { + return List.of( + new CoordXArgument("x", Messages.getString("Gamemaster.cmd.x")), + new CoordYArgument("y", Messages.getString("Gamemaster.cmd.y")), + new EnumArgument<>("type", Messages.getString("Gamemaster.cmd.support.type"), SupportType.class, null) + ); + } + + @Override + protected void runCommand(int connId, Arguments args) { + var player = server.getPlayer(connId); + SupportType supportType = (SupportType) args.get("type").getValue(); + + if (player.changeCurrentBSP(-supportType.bspCost())) { + + var hitTheCorrectLocation = Compute.d6(2); + var x = (int) args.get("x").getValue(); + var y = (int) args.get("y").getValue(); + + var coord = getScatter(hitTheCorrectLocation, supportType, x, y); + + switch (supportType) { + case OAS_LightStrike -> new AerialSupportCommand(this.server, this.gameManager) + .run(connId, new String[]{"/as", coord.getX()+ "", coord.getY() + "", "light_strike"}); + case OAS_LightBombing -> new AerialSupportCommand(this.server, this.gameManager) + .run(connId, new String[]{"/as", coord.getX()+ "", coord.getY() + "", "light_bombing"}); + case OAS_HeavyStrike -> new AerialSupportCommand(this.server, this.gameManager) + .run(connId, new String[]{"/as", coord.getX()+ "", coord.getY() + "", "heavy_strike"}); + case OAS_HeavyBombing -> new AerialSupportCommand(this.server, this.gameManager) + .run(connId, new String[]{"/as", coord.getX()+ "", coord.getY() + "", "heavy_bombing"}); + case OAS_Strafing -> new AerialSupportCommand(this.server, this.gameManager) + .run(connId, new String[]{"/as", coord.getX()+ "", coord.getY() + "", "strafing"}); + + case ART_Thumper -> new ArtilleryStrikeCommand(this.server, this.gameManager) + .run(connId, new String[]{"/art", coord.getX()+ "", coord.getY() + "", "thumper"}); + case ART_Sniper -> new ArtilleryStrikeCommand(this.server, this.gameManager) + .run(connId, new String[]{"/art", coord.getX()+ "", coord.getY() + "", "sniper"}); + case ART_LongTom -> new ArtilleryStrikeCommand(this.server, this.gameManager) + .run(connId, new String[]{"/art", coord.getX()+ "", coord.getY() + "", "longtom"}); + case ART_ArrowIV -> new ArtilleryStrikeCommand(this.server, this.gameManager) + .run(connId, new String[]{"/art", coord.getX()+ "", coord.getY() + "", "arrowiv"}); + case ART_Illumination -> new ArtilleryStrikeCommand(this.server, this.gameManager) + .run(connId, new String[]{"/art", coord.getX()+ "", coord.getY() + "", "flare"}); + case ART_Smoke -> new ArtilleryStrikeCommand(this.server, this.gameManager) + .run(connId, new String[]{"/art", coord.getX()+ "", coord.getY() + "", "smoke"}); + case ART_Nuke -> new ArtilleryStrikeCommand(this.server, this.gameManager) + .run(connId, new String[]{"/art", coord.getX()+ "", coord.getY() + "", "nuke"}); + + case ORT_bombardment -> new OrbitalBombardmentCommand(this.server, this.gameManager) + .run(connId, new String[]{"/ob", coord.getX()+ "", coord.getY() + ""}); + } + + server.sendServerChat(connId, Messages.getString("Gamemaster.cmd.bsp.success")); + } else { + server.sendServerChat(connId, Messages.getString("Gamemaster.cmd.bsp.fail")); + } + } + + private Coords getScatter(int hitTheCorrectLocation, SupportType supportType, int x, int y) { + var coords = new Coords(x, y); + if (hitTheCorrectLocation < supportType.targetNumber()) { + var delta = supportType.targetNumber() - hitTheCorrectLocation; + return coords.translated(Compute.d6(), delta); + } else { + return new Coords(x, y); + } + } +} diff --git a/megamek/src/megamek/server/commands/RescueCommand.java b/megamek/src/megamek/server/commands/RescueCommand.java index efabdebad47..2d97769c6e2 100644 --- a/megamek/src/megamek/server/commands/RescueCommand.java +++ b/megamek/src/megamek/server/commands/RescueCommand.java @@ -19,6 +19,7 @@ import megamek.server.commands.arguments.Argument; import megamek.server.commands.arguments.Arguments; import megamek.server.commands.arguments.IntegerArgument; +import megamek.server.commands.arguments.UnitArgument; import megamek.server.totalwarfare.TWGameManager; import java.util.List; @@ -39,7 +40,7 @@ public RescueCommand(Server server, TWGameManager gameManager) { @Override public List> defineArguments() { - return List.of(new IntegerArgument(UNIT_ID, Messages.getString("Gamemaster.cmd.rescue.unitID"))); + return List.of(new UnitArgument(UNIT_ID, Messages.getString("Gamemaster.cmd.rescue.unitID"))); } /** diff --git a/megamek/src/megamek/server/commands/arguments/CoordXArgument.java b/megamek/src/megamek/server/commands/arguments/CoordXArgument.java new file mode 100644 index 00000000000..93e6c921cfb --- /dev/null +++ b/megamek/src/megamek/server/commands/arguments/CoordXArgument.java @@ -0,0 +1,40 @@ +package megamek.server.commands.arguments; + +import megamek.client.ui.Messages; + +/** + * Argument for an Integer type. + * @author Luana Coppio + */ +public class CoordXArgument extends Argument { + + public CoordXArgument(String name, String description) { + super(name, description); + } + + @Override + public Integer getValue() { + return value; + } + + @Override + public void parse(String input) throws IllegalArgumentException { + if (input == null) { + throw new IllegalArgumentException(getName() + " is required."); + } + try { + int parsedValue = Integer.parseInt(input); + if (parsedValue < 0) { + throw new IllegalArgumentException(getName() + " must be an integer of an X hex coordinate."); + } + value = parsedValue; + } catch (NumberFormatException e) { + throw new IllegalArgumentException(getName() + " must be an integer of an X hex coordinate."); + } + } + + @Override + public String getHelp() { + return getDescription() + " " + Messages.getString("Gamemaster.cmd.params.required"); + } +} diff --git a/megamek/src/megamek/server/commands/arguments/CoordYArgument.java b/megamek/src/megamek/server/commands/arguments/CoordYArgument.java new file mode 100644 index 00000000000..fa895ee2085 --- /dev/null +++ b/megamek/src/megamek/server/commands/arguments/CoordYArgument.java @@ -0,0 +1,40 @@ +package megamek.server.commands.arguments; + +import megamek.client.ui.Messages; + +/** + * Argument for an Integer type. + * @author Luana Coppio + */ +public class CoordYArgument extends Argument { + + public CoordYArgument(String name, String description) { + super(name, description); + } + + @Override + public Integer getValue() { + return value; + } + + @Override + public void parse(String input) throws IllegalArgumentException { + if (input == null) { + throw new IllegalArgumentException(getName() + " is required."); + } + try { + int parsedValue = Integer.parseInt(input); + if (parsedValue < 0) { + throw new IllegalArgumentException(getName() + " must be an integer of an Y hex coordinate."); + } + value = parsedValue; + } catch (NumberFormatException e) { + throw new IllegalArgumentException(getName() + " must be an integer of an Y hex coordinate."); + } + } + + @Override + public String getHelp() { + return getDescription() + " " + Messages.getString("Gamemaster.cmd.params.required"); + } +} diff --git a/megamek/src/megamek/server/commands/arguments/EnumArgument.java b/megamek/src/megamek/server/commands/arguments/EnumArgument.java index cdaae3e7b0d..fe5bc7559e2 100644 --- a/megamek/src/megamek/server/commands/arguments/EnumArgument.java +++ b/megamek/src/megamek/server/commands/arguments/EnumArgument.java @@ -1,8 +1,11 @@ package megamek.server.commands.arguments; import megamek.client.ui.Messages; +import org.apache.commons.lang3.math.NumberUtils; import java.util.Arrays; +import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * Argument for an Enum type. @@ -19,6 +22,10 @@ public EnumArgument(String name, String description, Class enumType, E defaul this.defaultValue = defaultValue; } + public EnumArgument(String name, String description, Class enumType) { + this(name, description, enumType, null); + } + public Class getEnumType() { return enumType; } @@ -34,7 +41,11 @@ public void parse(String input) throws IllegalArgumentException { } } try { - value = Enum.valueOf(enumType, input.toUpperCase()); + if (NumberUtils.isCreatable(input)) { + value = enumType.getEnumConstants()[Integer.parseInt(input)]; + } else { + value = Enum.valueOf(enumType, input.toUpperCase()); + } } catch (IllegalArgumentException e) { throw new IllegalArgumentException(getName() + " must be one of: " + String.join(", ", Arrays.toString(enumType.getEnumConstants()))); @@ -49,10 +60,16 @@ public E getValue() { return value; } + private String getEnumConstantsString() { + return IntStream.range(0, enumType.getEnumConstants().length) + .mapToObj(i -> i + ": " + enumType.getEnumConstants()[i]) + .collect(Collectors.joining(", ")); + } + @Override public String getHelp() { return getDescription() + - " (" + String.join(", ", Arrays.toString(enumType.getEnumConstants())) + ")" + + " [" + getEnumConstantsString() + "] " + (defaultValue != null ? " [default: " + defaultValue + "]. " + Messages.getString("Gamemaster.cmd.params.optional") : " " + Messages.getString("Gamemaster.cmd.params.required")); diff --git a/megamek/src/megamek/server/commands/arguments/OptionalEnumArgument.java b/megamek/src/megamek/server/commands/arguments/OptionalEnumArgument.java index 5e7fcd78630..a3f1c0e6fb2 100644 --- a/megamek/src/megamek/server/commands/arguments/OptionalEnumArgument.java +++ b/megamek/src/megamek/server/commands/arguments/OptionalEnumArgument.java @@ -1,8 +1,11 @@ package megamek.server.commands.arguments; import megamek.client.ui.Messages; +import org.apache.commons.lang3.math.NumberUtils; import java.util.Arrays; +import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * Nullable Argument for an Enum type. @@ -21,7 +24,11 @@ public void parse(String input) throws IllegalArgumentException { return; } try { - value = enumType.getEnumConstants()[Integer.parseInt(input)]; + if (NumberUtils.isCreatable(input)) { + value = enumType.getEnumConstants()[Integer.parseInt(input)]; + } else { + value = Enum.valueOf(enumType, input.toUpperCase()); + } } catch (IllegalArgumentException e) { throw new IllegalArgumentException(getName() + " must be one of: " + getEnumConstantsString()); } @@ -36,14 +43,9 @@ public boolean isEmpty() { } private String getEnumConstantsString() { - var sb = new StringBuilder(); - for (int i = 0; i < enumType.getEnumConstants().length; i++) { - sb.append(i).append(": ").append(enumType.getEnumConstants()[i]); - if (i < enumType.getEnumConstants().length - 1) { - sb.append(", "); - } - } - return sb.toString(); + return IntStream.range(0, enumType.getEnumConstants().length) + .mapToObj(i -> i + ": " + enumType.getEnumConstants()[i]) + .collect(Collectors.joining(", ")); } @Override diff --git a/megamek/src/megamek/server/commands/arguments/PlayerArgument.java b/megamek/src/megamek/server/commands/arguments/PlayerArgument.java new file mode 100644 index 00000000000..526eff06495 --- /dev/null +++ b/megamek/src/megamek/server/commands/arguments/PlayerArgument.java @@ -0,0 +1,40 @@ +package megamek.server.commands.arguments; + +import megamek.client.ui.Messages; + +/** + * Argument for an Integer type. + * @author Luana Coppio + */ +public class PlayerArgument extends Argument { + + public PlayerArgument(String name, String description) { + super(name, description); + } + + @Override + public Integer getValue() { + return value; + } + + @Override + public void parse(String input) throws IllegalArgumentException { + if (input == null) { + throw new IllegalArgumentException(getName() + " is required."); + } + try { + int parsedValue = Integer.parseInt(input); + if (parsedValue < 0) { + throw new IllegalArgumentException(getName() + " must be an integer ID of a player."); + } + value = parsedValue; + } catch (NumberFormatException e) { + throw new IllegalArgumentException(getName() + " must be an integer ID of a player."); + } + } + + @Override + public String getHelp() { + return getDescription() + " " + Messages.getString("Gamemaster.cmd.params.required"); + } +} diff --git a/megamek/src/megamek/server/commands/arguments/TeamArgument.java b/megamek/src/megamek/server/commands/arguments/TeamArgument.java new file mode 100644 index 00000000000..9c54530e33e --- /dev/null +++ b/megamek/src/megamek/server/commands/arguments/TeamArgument.java @@ -0,0 +1,40 @@ +package megamek.server.commands.arguments; + +import megamek.client.ui.Messages; + +/** + * Argument for an Integer type. + * @author Luana Coppio + */ +public class TeamArgument extends Argument { + + public TeamArgument(String name, String description) { + super(name, description); + } + + @Override + public Integer getValue() { + return value; + } + + @Override + public void parse(String input) throws IllegalArgumentException { + if (input == null) { + throw new IllegalArgumentException(getName() + " is required."); + } + try { + int parsedValue = Integer.parseInt(input); + if (parsedValue < 0 || parsedValue > 5) { + throw new IllegalArgumentException(getName() + " must be an integer ID of a team."); + } + value = parsedValue; + } catch (NumberFormatException e) { + throw new IllegalArgumentException(getName() + " must be an integer ID of a team."); + } + } + + @Override + public String getHelp() { + return getDescription() + " " + Messages.getString("Gamemaster.cmd.params.required"); + } +} diff --git a/megamek/src/megamek/server/commands/arguments/UnitArgument.java b/megamek/src/megamek/server/commands/arguments/UnitArgument.java new file mode 100644 index 00000000000..dedd89077dd --- /dev/null +++ b/megamek/src/megamek/server/commands/arguments/UnitArgument.java @@ -0,0 +1,40 @@ +package megamek.server.commands.arguments; + +import megamek.client.ui.Messages; + +/** + * Argument for an Integer type. + * @author Luana Coppio + */ +public class UnitArgument extends Argument { + + public UnitArgument(String name, String description) { + super(name, description); + } + + @Override + public Integer getValue() { + return value; + } + + @Override + public void parse(String input) throws IllegalArgumentException { + if (input == null) { + throw new IllegalArgumentException(getName() + " is required."); + } + try { + int parsedValue = Integer.parseInt(input); + if (parsedValue < 0) { + throw new IllegalArgumentException(getName() + " must be an integer ID of a unit."); + } + value = parsedValue; + } catch (NumberFormatException e) { + throw new IllegalArgumentException(getName() + " must be an integer ID of a unit."); + } + } + + @Override + public String getHelp() { + return getDescription() + " " + Messages.getString("Gamemaster.cmd.params.required"); + } +} diff --git a/megamek/src/megamek/server/totalwarfare/TWGameManager.java b/megamek/src/megamek/server/totalwarfare/TWGameManager.java index 069ea437082..654abcce5fc 100644 --- a/megamek/src/megamek/server/totalwarfare/TWGameManager.java +++ b/megamek/src/megamek/server/totalwarfare/TWGameManager.java @@ -170,7 +170,7 @@ public List getCommandList(Server server) { commands.add(new FixElevationCommand(server, this)); commands.add(new HelpCommand(server)); commands.add(new BotHelpCommand(server)); - commands.add(new KickCommand(server)); + commands.add(new KickCommand(server, this)); commands.add(new ListSavesCommand(server)); commands.add(new LocalSaveGameCommand(server)); commands.add(new LocalLoadGameCommand(server)); @@ -212,6 +212,9 @@ public List getCommandList(Server server) { commands.add(new GameMasterCommand(server)); commands.add(new ChangeTeamCommand(server, this)); commands.add(new EndGameCommand(server, this)); + commands.add(new NuclearStrikeCommand(server, this)); + commands.add(new NuclearStrikeCustomCommand(server, this)); + commands.add(new RequestSupportCommand(server, this)); return commands; } @@ -9663,8 +9666,8 @@ private void processAttack(Entity entity, Vector vector) { for (Enumeration j = game.getAttacks(); !firingAtNewHex && j.hasMoreElements();) { WeaponHandler wh = (WeaponHandler) j.nextElement(); - if (wh.waa instanceof ArtilleryAttackAction) { - ArtilleryAttackAction oaaa = (ArtilleryAttackAction) wh.waa; + if (wh.weaponAttackAction instanceof ArtilleryAttackAction) { + ArtilleryAttackAction oaaa = (ArtilleryAttackAction) wh.weaponAttackAction; if ((oaaa.getEntityId() == aaa.getEntityId()) && !Targetable.areAtSamePosition(oaaa.getTarget(game), attackTarget)) { @@ -9798,7 +9801,7 @@ public void assignAMS() { for (AttackHandler ah : game.getAttacksVector()) { WeaponHandler wh = (WeaponHandler) ah; - WeaponAttackAction waa = wh.waa; + WeaponAttackAction waa = wh.weaponAttackAction; // for artillery attacks, the attacking entity might no longer be in the game. // TODO : Yeah, I know there's an exploit here, but better able to shoot some ArrowIVs than none, right? @@ -9889,7 +9892,7 @@ public void assignAMS() { // Ensure we only target each attack once List targetsToRemove = new ArrayList<>(); for (WeaponHandler wh : potentialTargets) { - if (targetedAttacks.contains(wh.getWaa())) { + if (targetedAttacks.contains(wh.getWeaponAttackAction())) { targetsToRemove.add(wh); } } @@ -9927,10 +9930,10 @@ private WeaponAttackAction manuallyAssignAPDSTarget(WeaponMounted apds, // Create a list of valid assignments for this APDS List vAttacksInArc = new ArrayList<>(vAttacks.size()); for (WeaponHandler wr : vAttacks) { - boolean isInArc = Compute.isInArc(e.getGame(), e.getId(), e.getEquipmentNum(apds), game.getEntity(wr.waa.getEntityId())); - boolean isInRange = e.getPosition().distance(wr.getWaa().getTarget(game).getPosition()) <= 3; + boolean isInArc = Compute.isInArc(e.getGame(), e.getId(), e.getEquipmentNum(apds), game.getEntity(wr.weaponAttackAction.getEntityId())); + boolean isInRange = e.getPosition().distance(wr.getWeaponAttackAction().getTarget(game).getPosition()) <= 3; if (isInArc && isInRange) { - vAttacksInArc.add(wr.waa); + vAttacksInArc.add(wr.weaponAttackAction); } } @@ -10005,9 +10008,9 @@ private void manuallyAssignAMSTarget(Entity e, Vector vAttacks) { // Create a list of valid assignments for this AMS List vAttacksInArc = new ArrayList<>(vAttacks.size()); for (WeaponHandler wr : vAttacks) { - if (!amsTargets.contains(wr.waa) - && Compute.isInArc(game, e.getId(), e.getEquipmentNum(ams), game.getEntity(wr.waa.getEntityId()))) { - vAttacksInArc.add(wr.waa); + if (!amsTargets.contains(wr.weaponAttackAction) + && Compute.isInArc(game, e.getId(), e.getEquipmentNum(ams), game.getEntity(wr.weaponAttackAction.getEntityId()))) { + vAttacksInArc.add(wr.weaponAttackAction); } } @@ -10157,11 +10160,11 @@ void detectSpacecraft() { // If we successfully detect the enemy, add it to the appropriate detector's // sensor contacts list if (Compute.calcSensorContact(game, detector, target)) { - game.getEntity(detector.getId()).addSensorContact(target.getId()); + game.getEntityOrThrow(detector.getId()).addSensorContact(target.getId()); // If detector is part of a C3 network, share the contact if (detector.hasNavalC3()) { for (Entity c3NetMate : game.getC3NetworkMembers(detector)) { - game.getEntity(c3NetMate.getId()).addSensorContact(target.getId()); + game.getEntityOrThrow(c3NetMate.getId()).addSensorContact(target.getId()); } } } @@ -10205,7 +10208,7 @@ void detectSpacecraft() { // If we successfully lock up the enemy, add it to the appropriate detector's // firing solutions list if (Compute.calcFiringSolution(game, detector, target)) { - game.getEntity(detector.getId()).addFiringSolution(targetId); + game.getEntityOrThrow(detector.getId()).addFiringSolution(targetId); } } } @@ -20645,6 +20648,11 @@ void resolveScheduledOrbitalBombardments() { getvPhaseReport().add(r); } + public void drawNukeHitOnBoard(Coords coord) { + int[] position = {coord.getX(), coord.getY()}; + drawNukeHitOnBoard(position); + } + public void drawNukeHitOnBoard(int[] nukeArgs) { // Turns out this object can be used here var nuke = new OrbitalBombardment.Builder().x(nukeArgs[0] - 1).y(nukeArgs[1] -1).radius(4).damage(0).build(); @@ -20711,6 +20719,7 @@ public void doNuclearExplosion(Coords position, int nukeType, Vector vDe if (nukeStats == null) { logger.error("Illegal nuke not listed in HS:3070"); + return; } doNuclearExplosion(position, nukeStats.baseDamage, nukeStats.degradation, nukeStats.secondaryRadius, @@ -27531,8 +27540,8 @@ Packet createArtilleryPacket(Player p) { int team = p.getTeam(); for (Enumeration i = game.getAttacks(); i.hasMoreElements();) { WeaponHandler wh = (WeaponHandler) i.nextElement(); - if (wh.waa instanceof ArtilleryAttackAction) { - ArtilleryAttackAction aaa = (ArtilleryAttackAction) wh.waa; + if (wh.weaponAttackAction instanceof ArtilleryAttackAction) { + ArtilleryAttackAction aaa = (ArtilleryAttackAction) wh.weaponAttackAction; if ((aaa.getPlayerId() == p.getId()) || ((team != Player.TEAM_NONE) && (team == game.getPlayer(aaa.getPlayerId()).getTeam())) @@ -29123,10 +29132,10 @@ private void receiveUnloadStranded(Packet packet, int connId) { private void clearArtillerySpotters(int entityID, int weaponID) { for (Enumeration i = game.getAttacks(); i.hasMoreElements();) { WeaponHandler wh = (WeaponHandler) i.nextElement(); - if ((wh.waa instanceof ArtilleryAttackAction) - && (wh.waa.getEntityId() == entityID) - && (wh.waa.getWeaponId() == weaponID)) { - ArtilleryAttackAction aaa = (ArtilleryAttackAction) wh.waa; + if ((wh.weaponAttackAction instanceof ArtilleryAttackAction) + && (wh.weaponAttackAction.getEntityId() == entityID) + && (wh.weaponAttackAction.getWeaponId() == weaponID)) { + ArtilleryAttackAction aaa = (ArtilleryAttackAction) wh.weaponAttackAction; aaa.setSpotterIds(null); } }