Search in sources :

Example 11 with Mounted

use of megamek.common.Mounted in project megameklab by MegaMek.

the class DropTargetCriticalList method mousePressed.

public void mousePressed(MouseEvent e) {
    if (buildView) {
        if (e.getButton() == MouseEvent.BUTTON2) {
            setSelectedIndex(locationToIndex(e.getPoint()));
            removeCrit();
        } else if (e.getButton() == MouseEvent.BUTTON3) {
            setSelectedIndex(locationToIndex(e.getPoint()));
            if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) {
                removeCrit();
                return;
            }
            int location = getCritLocation();
            JPopupMenu popup = new JPopupMenu();
            CriticalSlot cs = getCrit();
            final Mounted mount = getMounted();
            if ((e.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0) {
                changeWeaponFacing(!mount.isRearMounted());
                return;
            }
            if (mount != null && (e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) {
                changeOmniMounting(!mount.isOmniPodMounted());
                return;
            }
            if (mount != null && !((getUnit().getEntityType() & Entity.ETYPE_QUADVEE) == Entity.ETYPE_QUADVEE && mount.getType() instanceof MiscType && mount.getType().hasFlag(MiscType.F_TRACKS))) {
                JMenuItem info;
                if (!UnitUtil.isFixedLocationSpreadEquipment(mount.getType())) {
                    popup.setAutoscrolls(true);
                    info = new JMenuItem("Remove " + mount.getName());
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            removeCrit();
                        }
                    });
                    popup.add(info);
                }
                info = new JMenuItem("Delete " + mount.getName());
                info.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        removeMount();
                    }
                });
                if (!((getUnit() instanceof BattleArmor) && UnitUtil.isFixedLocationSpreadEquipment(mount.getType()))) {
                    popup.add(info);
                }
                // Allow making this a sort weapon
                if ((mount.getType() instanceof WeaponType) && !mount.isSquadSupportWeapon() && mount.getLocation() == BattleArmor.LOC_SQUAD && (getUnit() instanceof BattleArmor) && ((BattleArmor) getUnit()).getChassisType() != BattleArmor.CHASSIS_TYPE_QUAD) {
                    info = new JMenuItem("Mount as squad support weapon");
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            mount.setSquadSupportWeapon(true);
                            if (refresh != null) {
                                refresh.refreshAll();
                            }
                        }
                    });
                    popup.add(info);
                }
                // Adding ammo as a squad support mount is slightly different
                if ((mount.getType() instanceof AmmoType) && !mount.getType().hasFlag(WeaponType.F_MISSILE) && !mount.isSquadSupportWeapon() && mount.getLocation() == BattleArmor.LOC_SQUAD && (getUnit() instanceof BattleArmor) && ((BattleArmor) getUnit()).getChassisType() != BattleArmor.CHASSIS_TYPE_QUAD) {
                    boolean enabled = false;
                    for (Mounted weapon : getUnit().getWeaponList()) {
                        WeaponType wtype = (WeaponType) weapon.getType();
                        if (weapon.isSquadSupportWeapon() && AmmoType.isAmmoValid(mount, wtype)) {
                            enabled = true;
                        }
                    }
                    info = new JMenuItem("Mount as squad support weapon");
                    info.setEnabled(enabled);
                    info.setToolTipText("Ammo can only be squad mounted along " + "with a weapon that uses it");
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            mount.setSquadSupportWeapon(true);
                            if (refresh != null) {
                                refresh.refreshAll();
                            }
                        }
                    });
                    popup.add(info);
                }
                // Allow removing squad support weapon
                if (mount.isSquadSupportWeapon()) {
                    info = new JMenuItem("Remove squad support weapon mount");
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            mount.setSquadSupportWeapon(false);
                            // squad support weapon
                            for (Mounted ammo : getUnit().getAmmo()) {
                                ammo.setSquadSupportWeapon(false);
                            }
                            if (refresh != null) {
                                refresh.refreshAll();
                            }
                        }
                    });
                    popup.add(info);
                }
                // Right-clicked on a DWP that has an attached weapon
                if (mount.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) && mount.getLinked() != null) {
                    info = new JMenuItem("Remove attached weapon");
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            Mounted attached = mount.getLinked();
                            attached.setDWPMounted(false);
                            mount.setLinked(null);
                            mount.setLinkedBy(null);
                            attached.setLinked(null);
                            attached.setLinkedBy(null);
                            if (refresh != null) {
                                refresh.refreshAll();
                            }
                        }
                    });
                    popup.add(info);
                }
                // Right-clicked on a AP Mount that has an attached weapon
                if (mount.getType().hasFlag(MiscType.F_AP_MOUNT) && mount.getLinked() != null) {
                    info = new JMenuItem("Remove attached weapon");
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            Mounted attached = mount.getLinked();
                            attached.setAPMMounted(false);
                            mount.setLinked(null);
                            mount.setLinkedBy(null);
                            attached.setLinked(null);
                            attached.setLinkedBy(null);
                            if (refresh != null) {
                                refresh.refreshAll();
                            }
                        }
                    });
                    popup.add(info);
                }
                if ((mount.getLocation() != Mech.LOC_LARM) && (mount.getLocation() != Mech.LOC_RARM)) {
                    if (mount.getType() instanceof WeaponType) {
                        if (getUnit().hasWorkingMisc(MiscType.F_QUAD_TURRET, -1, mount.getLocation()) || getUnit().hasWorkingMisc(MiscType.F_SHOULDER_TURRET, -1, mount.getLocation()) || (getUnit().hasWorkingMisc(MiscType.F_HEAD_TURRET, -1, Mech.LOC_CT) && (mount.getLocation() == Mech.LOC_HEAD))) {
                            if (!mount.isMechTurretMounted()) {
                                info = new JMenuItem("Mount " + mount.getName() + " in Turret");
                                info.addActionListener(new ActionListener() {

                                    public void actionPerformed(ActionEvent e) {
                                        changeTurretMount(true);
                                    }
                                });
                                popup.add(info);
                            } else {
                                info = new JMenuItem("Remove " + mount.getName() + " from Turret");
                                info.addActionListener(new ActionListener() {

                                    public void actionPerformed(ActionEvent e) {
                                        changeTurretMount(false);
                                    }
                                });
                                popup.add(info);
                            }
                        }
                    }
                    if (!(getUnit() instanceof BattleArmor) && ((mount.getType() instanceof WeaponType) || ((mount.getType() instanceof MiscType) && mount.getType().hasFlag(MiscType.F_LIFTHOIST)))) {
                        if (!mount.isRearMounted()) {
                            info = new JMenuItem("Make " + mount.getName() + " Rear Facing");
                            info.addActionListener(new ActionListener() {

                                public void actionPerformed(ActionEvent e) {
                                    changeWeaponFacing(true);
                                }
                            });
                            popup.add(info);
                        } else {
                            info = new JMenuItem("Make " + mount.getName() + " Forward Facing");
                            info.addActionListener(new ActionListener() {

                                public void actionPerformed(ActionEvent e) {
                                    changeWeaponFacing(false);
                                }
                            });
                            popup.add(info);
                        }
                    }
                }
                // Allow number of shots selection
                if ((getUnit() instanceof BattleArmor) && mount.getType() instanceof AmmoType) {
                    AmmoType at = (AmmoType) mount.getType();
                    int maxNumShots = TestBattleArmor.NUM_SHOTS_PER_CRIT;
                    int stepSize = 1;
                    if (at.getAmmoType() == AmmoType.T_BA_TUBE) {
                        maxNumShots = TestBattleArmor.NUM_SHOTS_PER_CRIT_TA;
                        stepSize = 2;
                    }
                    for (int i = at.getShots(); i <= maxNumShots; i += stepSize) {
                        if (i == mount.getBaseShotsLeft()) {
                            continue;
                        }
                        info = new JMenuItem("Set Shots: " + i);
                        final int shots = i;
                        info.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                mount.setShotsLeft(shots);
                                if (refresh != null) {
                                    refresh.refreshAll();
                                }
                            }
                        });
                        popup.add(info);
                    }
                }
                if (getUnit().isOmni() && !mount.getType().isOmniFixedOnly()) {
                    if (mount.isOmniPodMounted()) {
                        info = new JMenuItem("Change to fixed mount");
                        info.addActionListener(ev -> changeOmniMounting(false));
                        popup.add(info);
                    } else if (UnitUtil.canPodMount(getUnit(), mount)) {
                        info = new JMenuItem("Change to pod mount");
                        info.addActionListener(ev -> changeOmniMounting(true));
                        popup.add(info);
                    }
                }
            }
            if ((getUnit() instanceof BipedMech || getUnit() instanceof TripodMech) && ((location == Mech.LOC_LARM) || (location == Mech.LOC_RARM))) {
                boolean canHaveLowerArm = true;
                if (getUnit().isOmni()) {
                    int numCrits = getUnit().getNumberOfCriticals(location);
                    for (int slot = 0; slot < numCrits; slot++) {
                        CriticalSlot crit = getUnit().getCritical(location, slot);
                        if (crit == null) {
                            continue;
                        }
                        if (crit.getType() == CriticalSlot.TYPE_SYSTEM) {
                            continue;
                        }
                        Mounted m = crit.getMount();
                        if ((m.getType() instanceof GaussWeapon) || (m.getType() instanceof ACWeapon) || (m.getType() instanceof UACWeapon) || (m.getType() instanceof LBXACWeapon) || (m.getType() instanceof PPCWeapon)) {
                            canHaveLowerArm = false;
                        }
                    }
                }
                popup.addSeparator();
                popup.setAutoscrolls(true);
                if (canHaveLowerArm && ((getUnit().getCritical(location, 3) == null) || (getUnit().getCritical(location, 3).getType() != CriticalSlot.TYPE_SYSTEM))) {
                    JMenuItem info = new JMenuItem("Add Hand");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            addHand(Integer.parseInt(e.getActionCommand()));
                        }
                    });
                    popup.add(info);
                } else if ((getUnit().getCritical(location, 3) != null) && (getUnit().getCritical(location, 3).getType() == CriticalSlot.TYPE_SYSTEM)) {
                    JMenuItem info = new JMenuItem("Remove Hand");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            removeHand(Integer.parseInt(e.getActionCommand()));
                        }
                    });
                    popup.add(info);
                }
                if (canHaveLowerArm && ((getUnit().getCritical(location, 2) == null) || (getUnit().getCritical(location, 2).getType() != CriticalSlot.TYPE_SYSTEM))) {
                    JMenuItem info = new JMenuItem("Add Lower Arm");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            addArm(Integer.parseInt(e.getActionCommand()));
                        }
                    });
                    popup.add(info);
                } else if ((getUnit().getCritical(location, 2) != null) && (getUnit().getCritical(location, 2).getType() == CriticalSlot.TYPE_SYSTEM)) {
                    JMenuItem info = new JMenuItem("Remove Lower Arm");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            removeArm(Integer.parseInt(e.getActionCommand()));
                        }
                    });
                    popup.add(info);
                }
            }
            if (UnitUtil.isArmorable(cs) && !(getUnit() instanceof BattleArmor) && eSource.getTechManager().isLegal(Entity.getArmoredComponentTechAdvancement())) {
                popup.addSeparator();
                if (cs.isArmored()) {
                    JMenuItem info = new JMenuItem("Remove Armoring");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            changeArmoring();
                        }
                    });
                    popup.add(info);
                } else if (!(getUnit() instanceof Mech && ((Mech) getUnit()).isSuperHeavy())) {
                    JMenuItem info = new JMenuItem("Add Armoring");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            changeArmoring();
                        }
                    });
                    popup.add(info);
                }
            }
            if (popup.getComponentCount() > 0) {
                popup.show(this, e.getX(), e.getY());
            }
        }
    }
}
Also used : InputEvent(java.awt.event.InputEvent) ActionListener(java.awt.event.ActionListener) CritListCellRenderer(megameklab.com.util.CritListCellRenderer) CriticalSlot(megamek.common.CriticalSlot) EntityLoadingException(megamek.common.loaders.EntityLoadingException) EntitySource(megameklab.com.ui.EntitySource) Vector(java.util.Vector) BattleArmor(megamek.common.BattleArmor) JMenuItem(javax.swing.JMenuItem) BipedMech(megamek.common.BipedMech) Mounted(megamek.common.Mounted) UnitUtil(megameklab.com.util.UnitUtil) TestBattleArmor(megamek.common.verifier.TestBattleArmor) MouseListener(java.awt.event.MouseListener) MechFileParser(megamek.common.MechFileParser) AmmoType(megamek.common.AmmoType) Mech(megamek.common.Mech) GaussWeapon(megamek.common.weapons.gaussrifles.GaussWeapon) JPopupMenu(javax.swing.JPopupMenu) JList(javax.swing.JList) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) LBXACWeapon(megamek.common.weapons.autocannons.LBXACWeapon) WeaponType(megamek.common.WeaponType) PPCWeapon(megamek.common.weapons.ppc.PPCWeapon) MiscType(megamek.common.MiscType) TripodMech(megamek.common.TripodMech) ACWeapon(megamek.common.weapons.autocannons.ACWeapon) UACWeapon(megamek.common.weapons.autocannons.UACWeapon) Entity(megamek.common.Entity) RefreshListener(megameklab.com.util.RefreshListener) TripodMech(megamek.common.TripodMech) CriticalSlot(megamek.common.CriticalSlot) ActionEvent(java.awt.event.ActionEvent) MiscType(megamek.common.MiscType) UACWeapon(megamek.common.weapons.autocannons.UACWeapon) PPCWeapon(megamek.common.weapons.ppc.PPCWeapon) JPopupMenu(javax.swing.JPopupMenu) AmmoType(megamek.common.AmmoType) ActionListener(java.awt.event.ActionListener) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) GaussWeapon(megamek.common.weapons.gaussrifles.GaussWeapon) BipedMech(megamek.common.BipedMech) Mech(megamek.common.Mech) TripodMech(megamek.common.TripodMech) LBXACWeapon(megamek.common.weapons.autocannons.LBXACWeapon) JMenuItem(javax.swing.JMenuItem) BipedMech(megamek.common.BipedMech) LBXACWeapon(megamek.common.weapons.autocannons.LBXACWeapon) ACWeapon(megamek.common.weapons.autocannons.ACWeapon) UACWeapon(megamek.common.weapons.autocannons.UACWeapon) BattleArmor(megamek.common.BattleArmor) TestBattleArmor(megamek.common.verifier.TestBattleArmor)

Example 12 with Mounted

use of megamek.common.Mounted in project megameklab by MegaMek.

the class DropTargetCriticalList method changeWeaponFacing.

private void changeWeaponFacing(boolean rear) {
    Mounted mount = getMounted();
    int location = getCritLocation();
    changeMountStatus(mount, location, rear);
}
Also used : Mounted(megamek.common.Mounted)

Example 13 with Mounted

use of megamek.common.Mounted in project megameklab by MegaMek.

the class DropTargetCriticalList method getMounted.

public Mounted getMounted() {
    // so they are handled specially
    if (getUnit() instanceof BattleArmor) {
        // The names for this list should be of the form <eq>:<slot>:<eqId>
        String[] split = ((String) this.getSelectedValue()).split(":");
        if (split.length > 2) {
            int eqId = Integer.parseInt(split[2]);
            return getUnit().getEquipment(eqId);
        }
        return null;
    }
    CriticalSlot crit = getCrit();
    Mounted mount = null;
    try {
        if ((crit != null) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
            return crit.getMount();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return mount;
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) EntityLoadingException(megamek.common.loaders.EntityLoadingException) BattleArmor(megamek.common.BattleArmor) TestBattleArmor(megamek.common.verifier.TestBattleArmor)

Example 14 with Mounted

use of megamek.common.Mounted in project megameklab by MegaMek.

the class StringUtils method getEquipmentInfo.

public static String getEquipmentInfo(Dropship unit, Mounted mount, Mounted bay) {
    String info = "";
    if (mount.getType() instanceof WeaponType) {
        WeaponType weapon = (WeaponType) mount.getType();
        if (weapon.getAmmoType() == AmmoType.T_AR10) {
            int barracudaAmmo = 0;
            int killerwhaleAmmo = 0;
            int whitesharkAmmo = 0;
            for (int ammoIndex : bay.getBayAmmo()) {
                Mounted ammoMount = unit.getEquipment(ammoIndex);
                try {
                    AmmoType aType = (AmmoType) ammoMount.getType();
                    if ((mount.getLinked() != null) && (aType.getRackSize() == weapon.getRackSize()) && (aType.getAmmoType() == weapon.getAmmoType())) {
                        if (aType.hasFlag(AmmoType.F_AR10_BARRACUDA)) {
                            barracudaAmmo += ammoMount.getUsableShotsLeft();
                        } else if (aType.hasFlag(AmmoType.F_AR10_KILLER_WHALE)) {
                            killerwhaleAmmo += ammoMount.getUsableShotsLeft();
                        } else if (aType.hasFlag(AmmoType.F_AR10_WHITE_SHARK)) {
                            whitesharkAmmo += ammoMount.getUsableShotsLeft();
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            info = "";
            if (barracudaAmmo > 0) {
                info += String.format("[%1$s Barracuda misl]", barracudaAmmo);
            }
            if (killerwhaleAmmo > 0) {
                info += String.format("[%1$s Killer Whale misl]", killerwhaleAmmo);
            }
            if (whitesharkAmmo > 0) {
                info += String.format("[%1$s White Shark misl]", whitesharkAmmo);
            }
        } else if (weapon.getAmmoType() == AmmoType.T_MML) {
            int lrmAmmo = 0;
            int srmAmmo = 0;
            for (int ammoIndex : bay.getBayAmmo()) {
                Mounted ammoMount = unit.getEquipment(ammoIndex);
                try {
                    AmmoType aType = (AmmoType) ammoMount.getType();
                    if ((mount.getLinked() != null) && (aType.getRackSize() == weapon.getRackSize()) && (aType.getAmmoType() == weapon.getAmmoType())) {
                        if (aType.hasFlag(AmmoType.F_MML_LRM)) {
                            lrmAmmo += ammoMount.getUsableShotsLeft();
                        } else {
                            srmAmmo += ammoMount.getUsableShotsLeft();
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            info = String.format("[%1$s LRM rnds][%2$s SRM rnds]", lrmAmmo, srmAmmo);
        } else {
            int totalAmmo = 0;
            for (int ammoIndex : bay.getBayAmmo()) {
                Mounted ammoMount = unit.getEquipment(ammoIndex);
                try {
                    if ((mount.getLinked() != null) && (ammoMount.getType() == mount.getLinked().getType())) {
                        totalAmmo += ammoMount.getUsableShotsLeft();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            if (weapon instanceof ScreenLauncherWeapon) {
                info = String.format("[%1$s Screens]", totalAmmo);
            } else if (weapon.hasFlag(WeaponType.F_BALLISTIC) || weapon.hasFlag(WeaponType.F_MISSILE) || weapon.hasFlag(WeaponType.F_ARTILLERY) || (weapon.getAtClass() == WeaponType.CLASS_CAPITAL_MISSILE)) {
                info = String.format("[%1$s rnds]", totalAmmo);
            }
        }
    }
    return info;
}
Also used : AmmoType(megamek.common.AmmoType) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) ScreenLauncherWeapon(megamek.common.weapons.capitalweapons.ScreenLauncherWeapon)

Example 15 with Mounted

use of megamek.common.Mounted in project megameklab by MegaMek.

the class UnitUtil method updateAutoSinks.

/**
 * This will cycle through the heat sinks and make sure that enough of them
 * are set LOC_NONE based on the basechassisheat sinks
 *
 * @param unit
 */
public static void updateAutoSinks(Mech unit, boolean compact) {
    int base = UnitUtil.getCriticalFreeHeatSinks(unit, compact);
    Vector<Mounted> unassigned = new Vector<Mounted>();
    Vector<Mounted> assigned = new Vector<Mounted>();
    for (Mounted m : unit.getMisc()) {
        if (UnitUtil.isHeatSink(m)) {
            if (m.getLocation() == Entity.LOC_NONE) {
                unassigned.add(m);
            } else {
                assigned.add(m);
            }
        }
    }
    int needed = base - unassigned.size();
    if (needed <= 0) {
        return;
    }
    for (Mounted m : assigned) {
        if (needed <= 0) {
            return;
        }
        UnitUtil.removeCriticals(unit, m);
        m.setLocation(Entity.LOC_NONE);
        needed--;
    }
// There may be more crit-free heatsinks, but if the 'mech doesn't
// have that many heatsinks, the additional space is unused.
}
Also used : Mounted(megamek.common.Mounted) Vector(java.util.Vector)

Aggregations

Mounted (megamek.common.Mounted)131 MiscType (megamek.common.MiscType)38 LocationFullException (megamek.common.LocationFullException)34 AmmoType (megamek.common.AmmoType)32 CriticalSlot (megamek.common.CriticalSlot)31 EquipmentType (megamek.common.EquipmentType)27 ArrayList (java.util.ArrayList)25 WeaponType (megamek.common.WeaponType)25 Vector (java.util.Vector)21 EntityLoadingException (megamek.common.loaders.EntityLoadingException)17 Font (java.awt.Font)14 BattleArmor (megamek.common.BattleArmor)11 JMenuItem (javax.swing.JMenuItem)9 JPopupMenu (javax.swing.JPopupMenu)9 Entity (megamek.common.Entity)9 TestBattleArmor (megamek.common.verifier.TestBattleArmor)9 Dimension (java.awt.Dimension)8 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)7 List (java.util.List)6