Search in sources :

Example 11 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 12 with EquipmentType

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

the class EquipmentTab method loadEquipmentTable.

private void loadEquipmentTable() {
    for (Mounted mount : getBattleArmor().getWeaponList()) {
        if (UnitUtil.isBattleArmorWeapon(mount.getType(), getBattleArmor()) || UnitUtil.isBattleArmorAPWeapon(mount.getType())) {
            equipmentList.addCrit(mount);
        }
    }
    for (Mounted mount : getBattleArmor().getAmmo()) {
        // Ignore ammo for one-shot launchers
        if (mount.getLinkedBy() != null && mount.getLinkedBy().isOneShot()) {
            continue;
        }
        equipmentList.addCrit(mount);
    }
    List<EquipmentType> spreadAlreadyAdded = new ArrayList<EquipmentType>();
    for (Mounted mount : getBattleArmor().getMisc()) {
        EquipmentType etype = mount.getType();
        if (UnitUtil.isHeatSink(mount) || etype.hasFlag(MiscType.F_JUMP_JET) || etype.hasFlag(MiscType.F_JUMP_BOOSTER) || etype.hasFlag(MiscType.F_TSM) || etype.hasFlag(MiscType.F_INDUSTRIAL_TSM) || (etype.hasFlag(MiscType.F_MASC) && !etype.hasSubType(MiscType.S_SUPERCHARGER)) || UnitUtil.isArmorOrStructure(etype)) {
            continue;
        }
        // if (UnitUtil.isUnitEquipment(mount.getType(), unit) || UnitUtil.isUn) {
        if (UnitUtil.isFixedLocationSpreadEquipment(etype) && !spreadAlreadyAdded.contains(etype)) {
            equipmentList.addCrit(mount);
            // keep track of spreadable equipment here, so it doesn't
            // show up multiple times in the table
            spreadAlreadyAdded.add(etype);
        } else {
            equipmentList.addCrit(mount);
        }
    // }
    }
}
Also used : Mounted(megamek.common.Mounted) ArrayList(java.util.ArrayList) EquipmentType(megamek.common.EquipmentType)

Example 13 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 14 with EquipmentType

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

the class StructureTab method enhancementChanged.

@Override
public void enhancementChanged(EquipmentType eq, boolean selected) {
    if (selected) {
        try {
            int loc = BattleArmor.MOUNT_LOC_BODY;
            if (eq.hasFlag(MiscType.F_MASC)) {
                loc = BattleArmor.MOUNT_LOC_NONE;
            }
            int numTimesToAdd = 1;
            // for each critical
            if (eq.isSpreadable()) {
                numTimesToAdd = eq.getCriticals(getBattleArmor());
            }
            for (int i = 0; i < numTimesToAdd; i++) {
                Mounted newMount = new Mounted(getBattleArmor(), eq);
                newMount.setBaMountLoc(loc);
                getBattleArmor().addEquipment(newMount, BattleArmor.LOC_SQUAD, false);
            }
        } catch (LocationFullException exc) {
            // Shouldn't happen with BA
            exc.printStackTrace();
        }
    } else {
        List<Mounted> mounts = getBattleArmor().getMisc().stream().filter(m -> m.getType().equals(eq)).collect(Collectors.toList());
        for (Mounted mount : mounts) {
            UnitUtil.removeMounted(getBattleArmor(), mount);
        }
    }
    panMovement.setFromEntity(getBattleArmor());
    refresh.refreshSummary();
    refresh.refreshBuild();
    refresh.refreshPreview();
}
Also used : Insets(java.awt.Insets) MechViewPanel(megamek.client.ui.swing.MechViewPanel) ActionListener(java.awt.event.ActionListener) CriticalSlot(megamek.common.CriticalSlot) SwingConstants(javax.swing.SwingConstants) EquipmentType(megamek.common.EquipmentType) EntitySource(megameklab.com.ui.EntitySource) BattleArmor(megamek.common.BattleArmor) BAChassisView(megameklab.com.ui.view.BAChassisView) CustomComboBox(megameklab.com.ui.util.CustomComboBox) Mounted(megamek.common.Mounted) UnitUtil(megameklab.com.util.UnitUtil) JComboBox(javax.swing.JComboBox) MechView(megamek.common.MechView) BAManipulator(megamek.common.verifier.TestBattleArmor.BAManipulator) ITechManager(megamek.common.ITechManager) BoxLayout(javax.swing.BoxLayout) JComponent(javax.swing.JComponent) LocationFullException(megamek.common.LocationFullException) BorderFactory(javax.swing.BorderFactory) EntityMovementMode(megamek.common.EntityMovementMode) GridBagConstraints(java.awt.GridBagConstraints) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) BAProtoArmorView(megameklab.com.ui.view.BAProtoArmorView) Box(javax.swing.Box) MovementView(megameklab.com.ui.view.MovementView) ITab(megameklab.com.util.ITab) Dimension(java.awt.Dimension) List(java.util.List) BAEnhancementView(megameklab.com.ui.view.BAEnhancementView) BasicInfoView(megameklab.com.ui.view.BasicInfoView) JLabel(javax.swing.JLabel) SimpleTechLevel(megamek.common.SimpleTechLevel) MiscType(megamek.common.MiscType) GridBagLayout(java.awt.GridBagLayout) BABuildListener(megameklab.com.ui.view.listeners.BABuildListener) JPanel(javax.swing.JPanel) RefreshListener(megameklab.com.util.RefreshListener) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted)

Example 15 with EquipmentType

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

the class StructureTab method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    removeAllListeners();
    if (e.getSource() instanceof JComboBox) {
        @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) e.getSource();
        if (combo.equals(leftManipSelect)) {
            // If the BA already had a manipulator here, we'll need to
            // remove it
            Mounted leftManip = getBattleArmor().getLeftManipulator();
            BAManipulator manipType;
            if (leftManip != null) {
                UnitUtil.removeMounted(getBattleArmor(), leftManip);
                manipType = BAManipulator.getManipulator(leftManip.getType().getInternalName());
                // remove the paired manipulator
                if (manipType.pairMounted) {
                    Mounted rightManip = getBattleArmor().getRightManipulator();
                    if (rightManip != null) {
                        UnitUtil.removeMounted(getBattleArmor(), rightManip);
                        rightManipSelect.setSelectedIndex(0);
                    }
                }
            }
            // If we selected something other than "None", mount it
            if (leftManipSelect.getSelectedIndex() != 0) {
                String manipName = (String) leftManipSelect.getSelectedItem();
                manipType = BAManipulator.getManipulator(manipName);
                EquipmentType et = EquipmentType.get(manipType.internalName);
                leftManip = new Mounted(getBattleArmor(), et);
                leftManip.setBaMountLoc(BattleArmor.MOUNT_LOC_LARM);
                try {
                    // Add the manipulator
                    getBattleArmor().addEquipment(leftManip, BattleArmor.LOC_SQUAD, false);
                    // Check to see if we need to add its mate
                    manipType = BAManipulator.getManipulator(leftManip.getType().getInternalName());
                    // remove the paired manipulator
                    if (manipType.pairMounted) {
                        Mounted rightManip = new Mounted(getBattleArmor(), et);
                        rightManip.setBaMountLoc(BattleArmor.MOUNT_LOC_RARM);
                        getBattleArmor().addEquipment(rightManip, BattleArmor.LOC_SQUAD, false);
                    }
                } catch (LocationFullException ex) {
                    // This shouldn't happen
                    ex.printStackTrace();
                }
            }
        } else if (combo.equals(rightManipSelect)) {
            // If the BA already had a manipulator here, we'll need to
            // remove it
            Mounted rightManip = getBattleArmor().getRightManipulator();
            BAManipulator manipType;
            if (rightManip != null) {
                UnitUtil.removeMounted(getBattleArmor(), rightManip);
                manipType = BAManipulator.getManipulator(rightManip.getType().getInternalName());
                // remove the paired manipulator
                if (manipType.pairMounted) {
                    Mounted leftManip = getBattleArmor().getLeftManipulator();
                    if (leftManip != null) {
                        UnitUtil.removeMounted(getBattleArmor(), leftManip);
                        leftManipSelect.setSelectedIndex(0);
                    }
                }
            }
            // If we selected something other than "None", mount it
            if (rightManipSelect.getSelectedIndex() != 0) {
                String manipName = (String) rightManipSelect.getSelectedItem();
                manipType = BAManipulator.getManipulator(manipName);
                EquipmentType et = EquipmentType.get(manipType.internalName);
                rightManip = new Mounted(getBattleArmor(), et);
                rightManip.setBaMountLoc(BattleArmor.MOUNT_LOC_RARM);
                try {
                    // Add the manipulator
                    getBattleArmor().addEquipment(rightManip, BattleArmor.LOC_SQUAD, false);
                    // Check to see if we need to add its mate
                    manipType = BAManipulator.getManipulator(rightManip.getType().getInternalName());
                    // remove the paired manipulator
                    if (manipType.pairMounted) {
                        Mounted leftManip = new Mounted(getBattleArmor(), et);
                        leftManip.setBaMountLoc(BattleArmor.MOUNT_LOC_LARM);
                        getBattleArmor().addEquipment(leftManip, BattleArmor.LOC_SQUAD, false);
                    }
                } catch (LocationFullException ex) {
                    // This shouldn't happen
                    ex.printStackTrace();
                }
            }
        }
    }
    refresh.refreshAll();
}
Also used : LocationFullException(megamek.common.LocationFullException) JComboBox(javax.swing.JComboBox) Mounted(megamek.common.Mounted) BAManipulator(megamek.common.verifier.TestBattleArmor.BAManipulator) EquipmentType(megamek.common.EquipmentType)

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