Search in sources :

Example 1 with LocationFullException

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

the class UnitUtil method replaceMainWeapon.

public static void replaceMainWeapon(Infantry unit, InfantryWeapon weapon, boolean secondary) {
    Mounted existingInfantryMount = null;
    for (Mounted m : unit.getWeaponList()) {
        if ((m.getType() instanceof InfantryWeapon) && (m.getLocation() == Infantry.LOC_INFANTRY)) {
            existingInfantryMount = m;
            break;
        }
    }
    if (null != existingInfantryMount) {
        UnitUtil.removeMounted(unit, existingInfantryMount);
    }
    if (secondary) {
        unit.setSecondaryWeapon(weapon);
    } else {
        unit.setPrimaryWeapon(weapon);
    }
    // is TAG, in which case both are added.
    if (unit.getSecondaryWeapon() != null && unit.getSecondaryWeapon().hasFlag(WeaponType.F_TAG)) {
        try {
            unit.addEquipment(unit.getPrimaryWeapon(), Infantry.LOC_INFANTRY);
            unit.addEquipment(unit.getSecondaryWeapon(), Infantry.LOC_INFANTRY);
        } catch (LocationFullException ex) {
        }
    } else if ((unit.getSecondaryN() < 2) || (null == unit.getSecondaryWeapon())) {
        try {
            unit.addEquipment(unit.getPrimaryWeapon(), Infantry.LOC_INFANTRY);
        } catch (LocationFullException ex) {
        }
    } else {
        try {
            unit.addEquipment(unit.getSecondaryWeapon(), Infantry.LOC_INFANTRY);
        } catch (LocationFullException ex) {
        }
    }
}
Also used : LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) InfantryWeapon(megamek.common.weapons.infantry.InfantryWeapon)

Example 2 with LocationFullException

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

the class EquipmentView method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(ADD_COMMAND)) {
        boolean success = false;
        Mounted mount = null;
        try {
            mount = getBattleArmor().addEquipment(equipmentTypes.elementAt(equipmentCombo.getSelectedIndex()), Entity.LOC_NONE, false);
            success = mount != null;
        } catch (LocationFullException lfe) {
        // this can't happen, we add to Entity.LOC_NONE
        }
        if (success) {
            equipmentList.addCrit(mount);
        }
    } else if (e.getActionCommand().equals(REMOVE_COMMAND)) {
        int startRow = equipmentTable.getSelectedRow();
        int count = equipmentTable.getSelectedRowCount();
        for (; count > 0; count--) {
            if (startRow > -1) {
                equipmentList.removeMounted(startRow);
                equipmentList.removeCrit(startRow);
            }
        }
    } else if (e.getActionCommand().equals(REMOVEALL_COMMAND)) {
        removeAllEquipment();
    } else {
        return;
    }
    fireTableRefresh();
}
Also used : LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted)

Example 3 with LocationFullException

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

the class StructureTab method enhancementChanged.

@Override
public void enhancementChanged(EquipmentType enhancement) {
    UnitUtil.removeEnhancements(getMech());
    if (null != enhancement) {
        if (enhancement.hasFlag(MiscType.F_MASC)) {
            Mounted mount = new Mounted(getMech(), enhancement);
            try {
                getMech().addEquipment(mount, Entity.LOC_NONE, false);
            } catch (LocationFullException lfe) {
            // this can't happen, we add to Entity.LOC_NONE
            }
        } else {
            UnitUtil.createSpreadMounts(getMech(), enhancement);
        }
    }
    refresh.refreshBuild();
    refresh.refreshPreview();
    refresh.refreshStatus();
}
Also used : LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted)

Example 4 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(getMech(), location);
    // TODO: move this construction data out of the ui
    int crits = 0;
    switch(EquipmentType.getArmorType(armor)) {
        case EquipmentType.T_ARMOR_STEALTH:
        case EquipmentType.T_ARMOR_FERRO_LAMELLOR:
            crits = 2;
            break;
        case EquipmentType.T_ARMOR_HEAVY_FERRO:
            crits = 3;
            break;
        case EquipmentType.T_ARMOR_LIGHT_FERRO:
            crits = 1;
            break;
        case EquipmentType.T_ARMOR_FERRO_FIBROUS:
        case EquipmentType.T_ARMOR_REFLECTIVE:
        case EquipmentType.T_ARMOR_REACTIVE:
            if (armor.isClan()) {
                crits = 1;
            } else {
                crits = 2;
            }
            break;
    }
    if (getMech().getEmptyCriticals(location) < crits) {
        JOptionPane.showMessageDialog(null, armor.getName() + " does not fit in location " + getMech().getLocationName(location) + ". Resetting to Standard Armor in this location.", "Error", JOptionPane.INFORMATION_MESSAGE);
    } else {
        getMech().setArmorType(EquipmentType.getArmorType(armor), location);
        getMech().setArmorTechLevel(armor.getTechLevel(getTechManager().getGameYear(), armor.isClan()));
        for (; crits > 0; crits--) {
            try {
                getMech().addEquipment(new Mounted(getMech(), armor), location, false);
            } catch (LocationFullException ex) {
            }
        }
    }
    panArmor.refresh();
    panArmorAllocation.setFromEntity(getMech());
    refresh.refreshBuild();
    refresh.refreshPreview();
    refresh.refreshSummary();
    refresh.refreshStatus();
}
Also used : LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted)

Example 5 with LocationFullException

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

the class StructureTab method jumpChanged.

@Override
public void jumpChanged(int jumpMP, EquipmentType jumpJet) {
    // Don't set jumpMP for UMU.
    if (null == jumpJet) {
        getMech().setOriginalJumpMP(0);
        jumpMP = 0;
    } else if (jumpJet.hasFlag(MiscType.F_JUMP_JET) || jumpJet.hasFlag(MiscType.F_JUMP_BOOSTER)) {
        getMech().setOriginalJumpMP(jumpMP);
    } else {
        getMech().setOriginalJumpMP(0);
    }
    List<Mounted> jjs = getMech().getMisc().stream().filter(m -> m.getType() == jumpJet).collect(Collectors.toList());
    if (jumpJet.hasFlag(MiscType.F_JUMP_BOOSTER)) {
        if (!getMech().hasWorkingMisc(MiscType.F_JUMP_BOOSTER)) {
            UnitUtil.createSpreadMounts(getMech(), jumpJet);
        }
    } else {
        while (jjs.size() > jumpMP) {
            UnitUtil.removeMounted(getMech(), jjs.remove(jjs.size() - 1));
        }
        while (jumpMP > jjs.size()) {
            try {
                UnitUtil.addMounted(getMech(), new Mounted(getMech(), jumpJet), Entity.LOC_NONE, false);
            } catch (LocationFullException e) {
            // Adding to LOC_NONE
            }
            jumpMP--;
        }
    }
    panSummary.refresh();
    refresh.refreshBuild();
    refresh.refreshStatus();
    refresh.refreshPreview();
    panMovement.setFromEntity(getMech());
}
Also used : MekBuildListener(megameklab.com.ui.view.listeners.MekBuildListener) CriticalSlot(megamek.common.CriticalSlot) EntityLoadingException(megamek.common.loaders.EntityLoadingException) SummaryView(megameklab.com.ui.Mek.views.SummaryView) SwingConstants(javax.swing.SwingConstants) TestEntity(megamek.common.verifier.TestEntity) EquipmentType(megamek.common.EquipmentType) EntitySource(megameklab.com.ui.EntitySource) ArmorAllocationView(megameklab.com.ui.view.ArmorAllocationView) QuadVee(megamek.common.QuadVee) Mounted(megamek.common.Mounted) UnitUtil(megameklab.com.util.UnitUtil) BorderLayout(java.awt.BorderLayout) MVFArmorView(megameklab.com.ui.view.MVFArmorView) MekChassisView(megameklab.com.ui.view.MekChassisView) ITechManager(megamek.common.ITechManager) BoxLayout(javax.swing.BoxLayout) JComponent(javax.swing.JComponent) MechFileParser(megamek.common.MechFileParser) TechConstants(megamek.common.TechConstants) LocationFullException(megamek.common.LocationFullException) Engine(megamek.common.Engine) Mech(megamek.common.Mech) PatchworkArmorView(megameklab.com.ui.view.PatchworkArmorView) BorderFactory(javax.swing.BorderFactory) LandAirMech(megamek.common.LandAirMech) GridBagConstraints(java.awt.GridBagConstraints) JOptionPane(javax.swing.JOptionPane) Collectors(java.util.stream.Collectors) Box(javax.swing.Box) MovementView(megameklab.com.ui.view.MovementView) ITab(megameklab.com.util.ITab) Dimension(java.awt.Dimension) List(java.util.List) HeatSinkView(megameklab.com.ui.view.HeatSinkView) BasicInfoView(megameklab.com.ui.view.BasicInfoView) JLabel(javax.swing.JLabel) SimpleTechLevel(megamek.common.SimpleTechLevel) MiscType(megamek.common.MiscType) Optional(java.util.Optional) GridBagLayout(java.awt.GridBagLayout) Entity(megamek.common.Entity) JPanel(javax.swing.JPanel) RefreshListener(megameklab.com.util.RefreshListener) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted)

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