Search in sources :

Example 66 with Mounted

use of megamek.common.Mounted 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)

Example 67 with Mounted

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

the class StructureTab method turretChanged.

@Override
public void turretChanged(int type, int size) {
    getBattleArmor().setModularTurret(type == BAChassisView.TURRET_MODULAR);
    if (type == BAChassisView.TURRET_NONE) {
        size = 0;
    } else {
        size = Math.max(1, size);
    }
    getBattleArmor().setTurretSize(size);
    if (size == 0) {
        for (Mounted mount : getBattleArmor().getEquipment()) {
            if (mount.getBaMountLoc() == BattleArmor.MOUNT_LOC_TURRET) {
                mount.setBaMountLoc(BattleArmor.MOUNT_LOC_BODY);
            }
        }
    }
    panChassis.setFromEntity(getBattleArmor());
    refresh.refreshStatus();
    refresh.refreshPreview();
    refresh.refreshBuild();
}
Also used : Mounted(megamek.common.Mounted)

Example 68 with Mounted

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

the class BuildTab method autoFillCrits.

private void autoFillCrits() {
    for (Mounted mount : buildView.getTableModel().getCrits()) {
        for (int location = 0; location < getTank().locations(); location++) {
            try {
                getTank().addEquipment(mount, location, false);
                UnitUtil.changeMountStatus(getTank(), mount, location, Entity.LOC_NONE, false);
                break;
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    refresh.refreshAll();
}
Also used : Mounted(megamek.common.Mounted) EntityLoadingException(megamek.common.loaders.EntityLoadingException)

Example 69 with Mounted

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

the class EquipmentTab method addEquipment.

private void addEquipment(EquipmentType equip) {
    boolean success = false;
    Mounted mount = null;
    boolean isMisc = equip instanceof MiscType;
    if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
        if (!UnitUtil.hasTargComp(getTank())) {
            mount = UnitUtil.updateTC(getTank(), equip);
            success = mount != null;
        }
    } else {
        try {
            mount = new Mounted(getTank(), equip);
            int loc = Entity.LOC_NONE;
            if (isMisc && equip.hasFlag(MiscType.F_MAST_MOUNT)) {
                loc = VTOL.LOC_ROTOR;
            }
            getTank().addEquipment(mount, loc, false);
            success = true;
        } catch (LocationFullException lfe) {
        // this can't happen, we add to Entity.LOC_NONE
        }
    }
    if (success) {
        equipmentList.addCrit(mount);
    }
}
Also used : LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType)

Example 70 with Mounted

use of megamek.common.Mounted 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)

Aggregations

Mounted (megamek.common.Mounted)162 MiscType (megamek.common.MiscType)50 LocationFullException (megamek.common.LocationFullException)39 AmmoType (megamek.common.AmmoType)36 EquipmentType (megamek.common.EquipmentType)34 CriticalSlot (megamek.common.CriticalSlot)31 ArrayList (java.util.ArrayList)30 WeaponType (megamek.common.WeaponType)29 Vector (java.util.Vector)25 EntityLoadingException (megamek.common.loaders.EntityLoadingException)21 Font (java.awt.Font)14 Entity (megamek.common.Entity)13 List (java.util.List)12 Dimension (java.awt.Dimension)11 JLabel (javax.swing.JLabel)11 JMenuItem (javax.swing.JMenuItem)11 JPopupMenu (javax.swing.JPopupMenu)11 BattleArmor (megamek.common.BattleArmor)11 ActionEvent (java.awt.event.ActionEvent)10 Weapon (megamek.common.weapons.Weapon)10