Search in sources :

Example 6 with LocationFullException

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

the class EquipmentTab method addEquipment.

private void addEquipment(EquipmentType equip) {
    Mounted mount = null;
    boolean isMisc = equip instanceof MiscType;
    if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
        if (!UnitUtil.hasTargComp(getAero())) {
            mount = UnitUtil.updateTC(getAero(), equip);
            if (null != mount) {
                equipmentList.addCrit(mount);
            }
        }
    } else {
        int count = (Integer) spnAddCount.getValue();
        if (getAero().usesWeaponBays() && (equip instanceof AmmoType)) {
            Mounted aMount = UnitUtil.findUnallocatedAmmo(getAero(), equip);
            if (null != aMount) {
                aMount.setShotsLeft(aMount.getUsableShotsLeft() + ((AmmoType) equip).getShots() * count);
                return;
            } else {
                mount = new Mounted(getAero(), equip);
                mount.setShotsLeft(((AmmoType) equip).getShots() * count);
                try {
                    getAero().addEquipment(mount, Entity.LOC_NONE, false);
                    equipmentList.addCrit(mount);
                } catch (LocationFullException lfe) {
                // this can't happen, we add to Entity.LOC_NONE
                }
            }
        } else {
            try {
                for (int i = 0; i < count; i++) {
                    mount = new Mounted(getAero(), equip);
                    getAero().addEquipment(mount, Entity.LOC_NONE, false);
                    equipmentList.addCrit(mount);
                }
            } catch (LocationFullException lfe) {
            // this can't happen, we add to Entity.LOC_NONE
            }
        }
    }
}
Also used : AmmoType(megamek.common.AmmoType) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType)

Example 7 with LocationFullException

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

the class StructureTab method patchworkChanged.

@Override
public void patchworkChanged(int location, EquipmentType armor) {
    UnitUtil.resetArmor(getAero(), location);
    // TODO: move this construction data out of the ui
    int crits = 0;
    switch(EquipmentType.getArmorType(armor)) {
        case EquipmentType.T_ARMOR_STEALTH_VEHICLE:
        case EquipmentType.T_ARMOR_LIGHT_ALUM:
        case EquipmentType.T_ARMOR_ALUM:
        case EquipmentType.T_ARMOR_FERRO_ALUM_PROTO:
        case EquipmentType.T_ARMOR_FERRO_LAMELLOR:
        case EquipmentType.T_ARMOR_REFLECTIVE:
        case EquipmentType.T_ARMOR_REACTIVE:
            crits = 1;
            break;
        case EquipmentType.T_ARMOR_HEAVY_ALUM:
            crits = 2;
            break;
    }
    if (getAero().getEmptyCriticals(location) < crits) {
        JOptionPane.showMessageDialog(null, armor.getName() + " does not fit in location " + getAero().getLocationName(location) + ". Resetting to Standard Armor in this location.", "Error", JOptionPane.INFORMATION_MESSAGE);
    } else {
        getAero().setArmorType(EquipmentType.getArmorType(armor), location);
        getAero().setArmorTechLevel(armor.getTechLevel(getTechManager().getGameYear(), armor.isClan()));
        for (; crits > 0; crits--) {
            try {
                getAero().addEquipment(new Mounted(getAero(), armor), location, false);
            } catch (LocationFullException ex) {
            }
        }
    }
    panArmor.refresh();
    panArmorAllocation.setFromEntity(getAero());
    refresh.refreshBuild();
    refresh.refreshPreview();
    refresh.refreshSummary();
    refresh.refreshStatus();
}
Also used : LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted)

Example 8 with LocationFullException

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

the class EquipmentTab method addEquipment.

private void addEquipment(EquipmentType equip) {
    Mounted mount = null;
    boolean isMisc = equip instanceof MiscType;
    boolean multiMount = UnitUtil.isBAMultiMount(equip);
    if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
        if (!UnitUtil.hasTargComp(getBattleArmor())) {
            mount = UnitUtil.updateTC(getBattleArmor(), equip);
            if (mount != null) {
                equipmentList.addCrit(mount);
            }
        }
    } else {
        try {
            if (multiMount) {
                for (int t = 1; t <= getBattleArmor().getTroopers(); t++) {
                    mount = new Mounted(getBattleArmor(), equip);
                    mount.setBaMountLoc(BattleArmor.MOUNT_LOC_NONE);
                    getBattleArmor().addEquipment(mount, t, false);
                    equipmentList.addCrit(mount);
                }
            } else {
                mount = new Mounted(getBattleArmor(), equip);
                mount.setBaMountLoc(BattleArmor.MOUNT_LOC_NONE);
                getBattleArmor().addEquipment(mount, BattleArmor.LOC_SQUAD, false);
                equipmentList.addCrit(mount);
            }
        } catch (LocationFullException lfe) {
        // this can't happen, we add to Entity.LOC_NONE
        }
    }
}
Also used : LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType)

Example 9 with LocationFullException

use of megamek.common.LocationFullException 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 10 with LocationFullException

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

LocationFullException (megamek.common.LocationFullException)23 Mounted (megamek.common.Mounted)21 MiscType (megamek.common.MiscType)9 AmmoType (megamek.common.AmmoType)5 CriticalSlot (megamek.common.CriticalSlot)5 EquipmentType (megamek.common.EquipmentType)5 Dimension (java.awt.Dimension)3 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 JComboBox (javax.swing.JComboBox)3 JLabel (javax.swing.JLabel)3 BattleArmor (megamek.common.BattleArmor)3 WeaponType (megamek.common.WeaponType)3 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 BorderFactory (javax.swing.BorderFactory)2