Search in sources :

Example 11 with MiscType

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

the class BuildView method loadEquipmentTable.

private void loadEquipmentTable() {
    equipmentList.removeAllCrits();
    masterEquipmentList.clear();
    for (Mounted mount : getAero().getMisc()) {
        if ((mount.getLocation() == Entity.LOC_NONE) && !isEngineHeatSink(mount)) {
            masterEquipmentList.add(mount);
        }
    }
    for (Mounted mount : getAero().getTotalWeaponList()) {
        if (mount.getLocation() == Entity.LOC_NONE) {
            masterEquipmentList.add(mount);
        }
    }
    for (Mounted mount : getAero().getAmmo()) {
        if ((mount.getLocation() == Entity.LOC_NONE) && ((mount.getUsableShotsLeft() > 1) || (((AmmoType) mount.getType()).getAmmoType() == AmmoType.T_COOLANT_POD))) {
            masterEquipmentList.add(mount);
        }
    }
    Collections.sort(masterEquipmentList, StringUtils.mountedComparator());
    // HeatSinks first
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (UnitUtil.isHeatSink(masterEquipmentList.get(pos))) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // Jump Jets
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (UnitUtil.isJumpJet(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // weapons and ammo
    Vector<Mounted> weaponsNAmmoList = new Vector<Mounted>(10, 1);
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if ((masterEquipmentList.get(pos).getType() instanceof Weapon) || (masterEquipmentList.get(pos).getType() instanceof AmmoType)) {
            weaponsNAmmoList.add(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    Collections.sort(weaponsNAmmoList, StringUtils.mountedComparator());
    for (Mounted mount : weaponsNAmmoList) {
        equipmentList.addCrit(mount);
    }
    // Equipment
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if ((masterEquipmentList.get(pos).getType() instanceof MiscType) && !UnitUtil.isArmor(masterEquipmentList.get(pos).getType()) && !UnitUtil.isTSM(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // structure
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (UnitUtil.isStructure(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // armor
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (UnitUtil.isArmor(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // everything else that is not TSM
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (!UnitUtil.isTSM(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // TSM
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        equipmentList.addCrit(masterEquipmentList.get(pos));
    }
}
Also used : AmmoType(megamek.common.AmmoType) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) Vector(java.util.Vector) Weapon(megamek.common.weapons.Weapon)

Example 12 with MiscType

use of megamek.common.MiscType 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 13 with MiscType

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

use of megamek.common.MiscType 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 15 with MiscType

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

MiscType (megamek.common.MiscType)37 Mounted (megamek.common.Mounted)33 AmmoType (megamek.common.AmmoType)14 EquipmentType (megamek.common.EquipmentType)13 LocationFullException (megamek.common.LocationFullException)12 WeaponType (megamek.common.WeaponType)11 Vector (java.util.Vector)9 CriticalSlot (megamek.common.CriticalSlot)7 ArrayList (java.util.ArrayList)6 Weapon (megamek.common.weapons.Weapon)6 PPCWeapon (megamek.common.weapons.ppc.PPCWeapon)5 JMenuItem (javax.swing.JMenuItem)4 JPopupMenu (javax.swing.JPopupMenu)4 BattleArmor (megamek.common.BattleArmor)4 Entity (megamek.common.Entity)4 Dimension (java.awt.Dimension)3 ActionEvent (java.awt.event.ActionEvent)3 MouseEvent (java.awt.event.MouseEvent)3 MouseListener (java.awt.event.MouseListener)3 List (java.util.List)3