Search in sources :

Example 16 with EquipmentType

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

the class EquipmentTab method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(ADD_COMMAND)) {
        int view = masterEquipmentTable.getSelectedRow();
        if (view < 0) {
            // selection got filtered away
            return;
        }
        int selected = masterEquipmentTable.convertRowIndexToModel(view);
        EquipmentType equip = masterEquipmentList.getType(selected);
        addEquipment(equip);
    } else if (e.getActionCommand().equals(REMOVE_COMMAND)) {
        int[] selectedRows = equipmentTable.getSelectedRows();
        for (Integer row : selectedRows) {
            equipmentList.removeMounted(row);
        }
        equipmentList.removeCrits(selectedRows);
        UnitUtil.compactCriticals(getTank());
    } else if (e.getActionCommand().equals(REMOVEALL_COMMAND)) {
        removeAllEquipment();
    } else {
        return;
    }
    fireTableRefresh();
}
Also used : EquipmentType(megamek.common.EquipmentType)

Example 17 with EquipmentType

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

the class EquipmentTab method removeHeatSinks.

private void removeHeatSinks() {
    int location = 0;
    for (; location < equipmentList.getRowCount(); ) {
        Mounted mount = (Mounted) equipmentList.getValueAt(location, CriticalTableModel.EQUIPMENT);
        EquipmentType eq = mount.getType();
        if ((eq instanceof MiscType) && (UnitUtil.isHeatSink(mount))) {
            try {
                equipmentList.removeCrit(location);
            } catch (ArrayIndexOutOfBoundsException aioobe) {
                return;
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else {
            location++;
        }
    }
}
Also used : Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) EquipmentType(megamek.common.EquipmentType) LocationFullException(megamek.common.LocationFullException)

Example 18 with EquipmentType

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

the class WeaponView method loadWeaponCombos.

private void loadWeaponCombos() {
    subLaserWeaponList.removeAllElements();
    subMissileWeaponList.removeAllElements();
    subBallisticWeaponList.removeAllElements();
    subArtilleryWeaponList.removeAllElements();
    Vector<String> equipmentList = new Vector<String>();
    for (EquipmentType eq : masterLaserWeaponList) {
        if (UnitUtil.isLegal(getTank(), eq)) {
            subLaserWeaponList.add(eq);
            equipmentList.add(eq.getInternalName());
        }
    }
    laserWeaponCombo.setListData(equipmentList);
    equipmentList = new Vector<String>();
    for (EquipmentType eq : masterMissileWeaponList) {
        if (UnitUtil.isLegal(getTank(), eq)) {
            subMissileWeaponList.add(eq);
            equipmentList.add(eq.getInternalName());
        }
    }
    missileWeaponCombo.setListData(equipmentList);
    equipmentList = new Vector<String>();
    for (EquipmentType eq : masterBallisticWeaponList) {
        if (UnitUtil.isLegal(getTank(), eq)) {
            subBallisticWeaponList.add(eq);
            equipmentList.add(eq.getInternalName());
        }
    }
    ballisticWeaponCombo.setListData(equipmentList);
    equipmentList = new Vector<String>();
    for (EquipmentType eq : masterArtilleryWeaponList) {
        if (UnitUtil.isLegal(getTank(), eq)) {
            subArtilleryWeaponList.add(eq);
            equipmentList.add(eq.getInternalName());
        }
    }
    artilleryWeaponCombo.setListData(equipmentList);
}
Also used : Vector(java.util.Vector) EquipmentType(megamek.common.EquipmentType)

Example 19 with EquipmentType

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

the class BayWeaponCriticalTree method addToBay.

/**
 * Adds an equipment mount to a bay. Changes the equipment mount's location and updates the bay's
 * weapon or ammo list if necessary.
 *
 * @param bay
 * @param eq
 */
public void addToBay(@Nullable Mounted bay, Mounted eq) {
    // Check that we have a bay
    if ((null == bay) || !canTakeEquipment(bay, eq)) {
        if (eq.getType() instanceof WeaponType) {
            EquipmentType bayType = ((WeaponType) eq.getType()).getBayType();
            addToNewBay(bayType, eq);
        } else {
            addToLocation(eq);
        }
        return;
    } else if (eq.getType() instanceof MiscType) {
        if (eq.getType().hasFlag(MiscType.F_ARTEMIS) || eq.getType().hasFlag(MiscType.F_ARTEMIS_PROTO) || eq.getType().hasFlag(MiscType.F_ARTEMIS_V)) {
            for (Integer eqNum : bay.getBayWeapons()) {
                final Mounted weapon = eSource.getEntity().getEquipment(eqNum);
                final WeaponType wtype = (WeaponType) weapon.getType();
                if ((weapon.getLinkedBy() == null) && ((wtype.getAmmoType() == AmmoType.T_LRM) || (wtype.getAmmoType() == AmmoType.T_SRM) || (wtype.getAmmoType() == AmmoType.T_MML) || (wtype.getAmmoType() == AmmoType.T_NLRM))) {
                    moveToArc(eq);
                    eq.setLinked(weapon);
                    break;
                }
            }
        } else if (eq.getType().hasFlag(MiscType.F_APOLLO) || eq.getType().hasFlag(MiscType.F_PPC_CAPACITOR)) {
            for (Integer eqNum : bay.getBayWeapons()) {
                final Mounted weapon = eSource.getEntity().getEquipment(eqNum);
                if (weapon.getLinkedBy() == null) {
                    moveToArc(eq);
                    eq.setLinked(weapon);
                    break;
                }
            }
        }
    } else {
        // there.
        if (eq.getType() instanceof AmmoType) {
            Optional<Mounted> addMount = bay.getBayAmmo().stream().map(n -> eSource.getEntity().getEquipment(n)).filter(m -> m.getType() == eq.getType()).findFirst();
            if (addMount.isPresent()) {
                addMount.get().setShotsLeft(addMount.get().getBaseShotsLeft() + eq.getBaseShotsLeft());
                UnitUtil.removeMounted(eSource.getEntity(), eq);
                refresh.refreshEquipment();
                refresh.refreshBuild();
                refresh.refreshPreview();
                refresh.refreshStatus();
                refresh.refreshSummary();
                return;
            }
        }
        EquipmentNode bayNode = null;
        for (Enumeration<?> e = ((TreeNode) model.getRoot()).children(); e.hasMoreElements(); ) {
            final EquipmentNode node = (EquipmentNode) e.nextElement();
            if (node.getMounted() == bay) {
                bayNode = node;
                break;
            }
        }
        if (null != bayNode) {
            moveToArc(eq);
            EquipmentNode eqNode = new EquipmentNode(eq);
            model.insertNodeInto(eqNode, bayNode, bayNode.getChildCount());
            eqNode.setParent(bayNode);
            if (eq.getType() instanceof WeaponType) {
                bay.addWeaponToBay(eSource.getEntity().getEquipmentNum(eq));
                if (eq.getLinkedBy() != null) {
                    moveToArc(eq.getLinkedBy());
                }
            } else if (eq.getType() instanceof AmmoType) {
                bay.addAmmoToBay(eSource.getEntity().getEquipmentNum(eq));
            }
        } else {
            // $NON-NLS-1$
            MegaMekLab.getLogger().log(// $NON-NLS-1$
            BayWeaponCriticalTree.class, // $NON-NLS-1$
            "addToBay(Mounted,Mounted)", LogLevel.DEBUG, // $NON-NLS-1$
            bay.getName() + "[" + eSource.getEntity().getEquipmentNum(bay) + "] not found in " + // $NON-NLS-1$
            getLocationName());
        }
    }
    refresh.refreshEquipment();
    refresh.refreshBuild();
    refresh.refreshPreview();
    refresh.refreshStatus();
    refresh.refreshSummary();
}
Also used : AmmoType(megamek.common.AmmoType) Color(java.awt.Color) Enumeration(java.util.Enumeration) EntitySource(megameklab.com.ui.EntitySource) Vector(java.util.Vector) MouseAdapter(java.awt.event.MouseAdapter) SmallCraft(megamek.common.SmallCraft) TestAero(megamek.common.verifier.TestAero) MouseListener(java.awt.event.MouseListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ToolTipManager(javax.swing.ToolTipManager) TreePath(javax.swing.tree.TreePath) LocationFullException(megamek.common.LocationFullException) Set(java.util.Set) JMenu(javax.swing.JMenu) Component(java.awt.Component) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Dimension(java.awt.Dimension) List(java.util.List) WeaponType(megamek.common.WeaponType) Graphics(java.awt.Graphics) MiscType(megamek.common.MiscType) Optional(java.util.Optional) Entity(megamek.common.Entity) RefreshListener(megameklab.com.util.RefreshListener) InputEvent(java.awt.event.InputEvent) Rectangle(java.awt.Rectangle) LogLevel(megamek.common.logging.LogLevel) TreeNode(javax.swing.tree.TreeNode) ArrayList(java.util.ArrayList) PPCBayWeapon(megamek.common.weapons.bayweapons.PPCBayWeapon) HashSet(java.util.HashSet) EquipmentType(megamek.common.EquipmentType) JMenuItem(javax.swing.JMenuItem) MegaMekLab(megameklab.com.MegaMekLab) CConfig(megameklab.com.util.CConfig) Mounted(megamek.common.Mounted) UnitUtil(megameklab.com.util.UnitUtil) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) BayWeapon(megamek.common.weapons.bayweapons.BayWeapon) AmmoType(megamek.common.AmmoType) JPopupMenu(javax.swing.JPopupMenu) Nullable(megamek.common.annotations.Nullable) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) JTree(javax.swing.JTree) MouseEvent(java.awt.event.MouseEvent) JLabel(javax.swing.JLabel) StringJoiner(java.util.StringJoiner) PPCWeapon(megamek.common.weapons.ppc.PPCWeapon) Collections(java.util.Collections) Enumeration(java.util.Enumeration) Optional(java.util.Optional) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) MiscType(megamek.common.MiscType) EquipmentType(megamek.common.EquipmentType)

Example 20 with EquipmentType

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

the class CriticalTransferHandler method importData.

/**
 */
@Override
public boolean importData(TransferSupport info) {
    if (!info.isDrop() || !((getUnit() instanceof Mech) || (getUnit() instanceof Aero) || (getUnit() instanceof BattleArmor))) {
        return false;
    }
    int trooper = 0;
    if (info.getComponent() instanceof DropTargetCriticalList) {
        DropTargetCriticalList<?> list = (DropTargetCriticalList<?>) info.getComponent();
        if (getUnit() instanceof BattleArmor) {
            String[] split = list.getName().split(":");
            if (split.length != 2) {
                return false;
            }
            location = Integer.parseInt(split[0]);
            trooper = Integer.parseInt(split[1]);
        } else {
            location = Integer.parseInt(list.getName());
        }
        Transferable t = info.getTransferable();
        int slotNumber = list.getDropLocation().getIndex();
        try {
            Mounted eq = getUnit().getEquipment(Integer.parseInt((String) t.getTransferData(DataFlavor.stringFlavor)));
            if (getUnit() instanceof BattleArmor) {
                if ((location == eq.getBaMountLoc()) && (trooper == eq.getLocation())) {
                    return false;
                }
            } else {
                // the criticals its mounted in
                if (eq.getLocation() != Entity.LOC_NONE || eq.getSecondLocation() != Entity.LOC_NONE) {
                    UnitUtil.removeCriticals(getUnit(), eq);
                    changeMountStatus(eq, Entity.LOC_NONE, false);
                } else {
                    eq.setOmniPodMounted(UnitUtil.canPodMount(getUnit(), eq));
                }
            }
            if (!UnitUtil.isValidLocation(getUnit(), eq.getType(), location)) {
                JOptionPane.showMessageDialog(null, eq.getName() + " can't be placed in " + getUnit().getLocationName(location) + "!", "Invalid Location", JOptionPane.INFORMATION_MESSAGE);
                return false;
            }
            if (getUnit() instanceof Aero) {
                return addEquipmentAero((Aero) getUnit(), eq);
            } else if (getUnit() instanceof Mech) {
                // superheavies can put 2 ammobins or heatsinks in one crit
                if ((getUnit() instanceof Mech) && ((Mech) getUnit()).isSuperHeavy()) {
                    CriticalSlot cs = getUnit().getCritical(location, slotNumber);
                    if ((cs != null) && (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) && (cs.getMount2() == null)) {
                        EquipmentType etype = cs.getMount().getType();
                        EquipmentType etype2 = eq.getType();
                        boolean canDouble = false;
                        if ((etype instanceof AmmoType) && (etype2 instanceof AmmoType)) {
                            canDouble = (((AmmoType) etype).getAmmoType() == ((AmmoType) etype2).getAmmoType()) && (((AmmoType) etype).getRackSize() == ((AmmoType) etype2).getRackSize());
                        } else if (etype.equals(etype2) && UnitUtil.isHeatSink(etype)) {
                            canDouble = etype.getCriticals(getUnit()) == 1;
                        }
                        if (canDouble) {
                            cs.setMount2(eq);
                            changeMountStatus(eq, location, false);
                            return true;
                        }
                    }
                }
                return addEquipmentMech((Mech) getUnit(), eq, slotNumber);
            } else if (getUnit() instanceof BattleArmor) {
                return addEquipmentBA((BattleArmor) getUnit(), eq, trooper);
            }
        } catch (LocationFullException lfe) {
            JOptionPane.showMessageDialog(null, lfe.getMessage(), "Location Full", JOptionPane.INFORMATION_MESSAGE);
            return false;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return true;
    }
    return false;
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Transferable(java.awt.datatransfer.Transferable) EquipmentType(megamek.common.EquipmentType) EntityLoadingException(megamek.common.loaders.EntityLoadingException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) LocationFullException(megamek.common.LocationFullException) IOException(java.io.IOException) AmmoType(megamek.common.AmmoType) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) Mech(megamek.common.Mech) LandAirMech(megamek.common.LandAirMech) Aero(megamek.common.Aero) TestAero(megamek.common.verifier.TestAero) BattleArmor(megamek.common.BattleArmor) TestBattleArmor(megamek.common.verifier.TestBattleArmor)

Aggregations

EquipmentType (megamek.common.EquipmentType)49 Mounted (megamek.common.Mounted)24 MiscType (megamek.common.MiscType)14 LocationFullException (megamek.common.LocationFullException)10 ArrayList (java.util.ArrayList)8 JLabel (javax.swing.JLabel)6 AmmoType (megamek.common.AmmoType)6 CriticalSlot (megamek.common.CriticalSlot)6 WeaponType (megamek.common.WeaponType)5 Dimension (java.awt.Dimension)4 List (java.util.List)4 Vector (java.util.Vector)4 BattleArmor (megamek.common.BattleArmor)4 Mech (megamek.common.Mech)4 EntitySource (megameklab.com.ui.EntitySource)4 RefreshListener (megameklab.com.util.RefreshListener)4 GridBagConstraints (java.awt.GridBagConstraints)3 GridBagLayout (java.awt.GridBagLayout)3 ActionEvent (java.awt.event.ActionEvent)3 StringJoiner (java.util.StringJoiner)3