Search in sources :

Example 46 with Mounted

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

the class BuildTab method resetCrits.

private void resetCrits() {
    for (Mounted mount : getMech().getEquipment()) {
        if (!UnitUtil.isFixedLocationSpreadEquipment(mount.getType())) {
            UnitUtil.removeCriticals(getMech(), mount);
            UnitUtil.changeMountStatus(getMech(), mount, Entity.LOC_NONE, Entity.LOC_NONE, false);
        }
    }
    refresh.refreshAll();
}
Also used : Mounted(megamek.common.Mounted)

Example 47 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()) {
        int externalEngineHS = UnitUtil.getCriticalFreeHeatSinks(getMech(), getMech().hasCompactHeatSinks());
        for (int location = Mech.LOC_HEAD; location < getMech().locations(); location++) {
            if (!UnitUtil.isValidLocation(getMech(), mount.getType(), location)) {
                continue;
            }
            int continuousNumberOfCrits = UnitUtil.getHighestContinuousNumberOfCrits(getMech(), location);
            int critsUsed = UnitUtil.getCritsUsed(getMech(), mount.getType());
            if (continuousNumberOfCrits < critsUsed) {
                continue;
            }
            if ((mount.getLocation() == Entity.LOC_NONE)) {
                if (UnitUtil.isHeatSink(mount) && (externalEngineHS-- > 0)) {
                    continue;
                }
            }
            try {
                if (mount.getType().isSpreadable() || (mount.isSplitable() && (critsUsed > 1))) {
                    for (int count = 0; count < critsUsed; count++) {
                        UnitUtil.addMounted(getMech(), mount, location, false);
                    }
                } else {
                    UnitUtil.addMounted(getMech(), mount, location, false);
                }
                UnitUtil.changeMountStatus(getMech(), mount, location, Entity.LOC_NONE, false);
                break;
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    refresh.refreshAll();
}
Also used : Mounted(megamek.common.Mounted)

Example 48 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)

Example 49 with Mounted

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

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

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