Search in sources :

Example 31 with MiscType

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

the class SummaryView method runThroughEquipment.

private void runThroughEquipment(TestMech testMech) {
    double weightJJ = 0.0f;
    double weightEnhance = 0.0f;
    double weightEquip = 0.0f;
    int critJJ = 0;
    int critEquip = 0;
    int critEnhance = 0;
    for (Mounted m : getMech().getMisc()) {
        MiscType mt = (MiscType) m.getType();
        if (UnitUtil.isArmorOrStructure(mt)) {
            continue;
        } else if (mt.hasFlag(MiscType.F_TSM) || mt.hasFlag(MiscType.F_INDUSTRIAL_TSM) || mt.hasFlag(MiscType.F_MASC)) {
            weightEnhance += mt.getTonnage(getMech(), m.getLocation());
            critEnhance += UnitUtil.getCritsUsed(getMech(), mt);
        } else if (mt.hasFlag(MiscType.F_JUMP_JET) || mt.hasFlag(MiscType.F_JUMP_BOOSTER)) {
            weightJJ += mt.getTonnage(getMech(), m.getLocation());
            critJJ += mt.getCriticals(getMech());
        } else if (mt.hasFlag(MiscType.F_HEAT_SINK) || mt.hasFlag(MiscType.F_DOUBLE_HEAT_SINK)) {
            continue;
        } else {
            weightEquip += mt.getTonnage(getMech(), m.getLocation());
            critEquip += mt.getCriticals(getMech());
        }
    }
    for (Mounted m : getMech().getWeaponList()) {
        EquipmentType et = m.getType();
        weightEquip += et.getTonnage(getMech());
        critEquip += et.getCriticals(getMech());
    }
    for (Mounted m : getMech().getAmmo()) {
        EquipmentType et = m.getType();
        weightEquip += et.getTonnage(getMech());
        critEquip += et.getCriticals(getMech());
    }
    txtJumpTon.setText(Double.toString(weightJJ));
    txtEnhanceTon.setText(Double.toString(weightEnhance));
    txtEquipTon.setText(Double.toString(weightEquip));
    txtJumpCrit.setText(Integer.toString(critJJ));
    txtEnhanceCrit.setText(Integer.toString(critEnhance));
    txtEquipCrit.setText(Integer.toString(critEquip));
}
Also used : Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) EquipmentType(megamek.common.EquipmentType)

Example 32 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 : getTank().getMisc()) {
        if (mount.getLocation() == Entity.LOC_NONE) {
            masterEquipmentList.add(mount);
        }
    }
    for (Mounted mount : getTank().getWeaponList()) {
        if (mount.getLocation() == Entity.LOC_NONE) {
            masterEquipmentList.add(mount);
        }
    }
    for (Mounted mount : getTank().getAmmo()) {
        int ammoType = ((AmmoType) mount.getType()).getAmmoType();
        if ((mount.getLocation() == Entity.LOC_NONE) && (mount.getUsableShotsLeft() > 1 || ammoType == AmmoType.T_CRUISE_MISSILE)) {
            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())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // structure
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if ((masterEquipmentList.get(pos).getType() instanceof MiscType) && masterEquipmentList.get(pos).getType().hasFlag(MiscType.F_ENDO_STEEL)) {
            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
    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 33 with MiscType

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

the class EquipmentView method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(ADD_COMMAND)) {
        EquipmentType equip = (EquipmentType) equipmentCombo.getSelectedItem();
        Mounted mount = null;
        boolean isMisc = equip instanceof MiscType;
        if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
            if (!UnitUtil.hasTargComp(getTank())) {
                mount = UnitUtil.updateTC(getTank(), equip);
            }
        } else {
            try {
                mount = getTank().addEquipment(equip, Entity.LOC_NONE, false);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        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 : Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) EquipmentType(megamek.common.EquipmentType)

Example 34 with MiscType

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

the class SummaryView method runThroughEquipment.

private void runThroughEquipment(TestTank testTank) {
    double weightJJ = 0.0f;
    double weightEquip = 0.0f;
    double weightSponson = 0.0f;
    for (Mounted m : getTank().getMisc()) {
        MiscType mt = (MiscType) m.getType();
        if (UnitUtil.isArmorOrStructure(mt)) {
            continue;
        } else if (mt.hasFlag(MiscType.F_SPONSON_TURRET)) {
            weightSponson = mt.getTonnage(getTank());
        } else if (mt.hasFlag(MiscType.F_JUMP_JET)) {
            weightJJ += mt.getTonnage(getTank(), m.getLocation());
        } else if (mt.hasFlag(MiscType.F_HEAT_SINK) || mt.hasFlag(MiscType.F_DOUBLE_HEAT_SINK)) {
            continue;
        } else {
            weightEquip += mt.getTonnage(getTank(), m.getLocation());
        }
    }
    for (Mounted m : getTank().getWeaponList()) {
        EquipmentType et = m.getType();
        weightEquip += et.getTonnage(getTank());
    }
    for (Mounted m : getTank().getAmmo()) {
        EquipmentType et = m.getType();
        weightEquip += et.getTonnage(getTank());
    }
    txtJumpTon.setText(Double.toString(weightJJ));
    txtEquipTon.setText(Double.toString(weightEquip));
    txtSponsonTon.setText(Double.toString(weightSponson));
    if (weightJJ > 0) {
        txtJumpCrit.setText(Integer.toString(1));
    } else {
        txtJumpCrit.setText(Integer.toString(0));
    }
}
Also used : Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) EquipmentType(megamek.common.EquipmentType)

Example 35 with MiscType

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

the class BayWeaponCriticalTree method isValidDropLocation.

/**
 * Determines whether the equipment can be dropped here. In the case of ammo or weapon
 * enhancement, there must be a matching weapon in the bay. A weapon that doesn't fit the
 * bay will be placed in a new bay.
 *
 * @param loc The drop location from the TransferSupport object passed to the TransferHandler
 * @param eq  The equipment to be dropped
 * @return    Whether the equipment can be dropped in the location
 */
public boolean isValidDropLocation(JTree.DropLocation loc, Mounted eq) {
    if (!eSource.getEntity().usesWeaponBays()) {
        return true;
    }
    Mounted bay = null;
    TreePath path = loc.getPath();
    if (null != path) {
        // without a capacitor.
        if ((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_PPC_CAPACITOR) && (path.getLastPathComponent() instanceof EquipmentNode)) {
            EquipmentNode node = (EquipmentNode) path.getLastPathComponent();
            if (node.getMounted().getType() instanceof PPCWeapon) {
                return node.getMounted().getLinkedBy() == null;
            } else if (node.getMounted().getType() instanceof PPCBayWeapon) {
                for (Integer eqNum : node.getMounted().getBayWeapons()) {
                    if (eSource.getEntity().getEquipment(eqNum).getLinkedBy() == null) {
                        return true;
                    }
                }
                return false;
            }
        }
        bay = getBayFromPath(path);
    }
    // disallow dropping a bay into its current arc or a weapon or ammo into its current bay
    if (null != bay) {
        if ((eq == bay) || ((eq.getType() instanceof WeaponType) && (bay.getBayWeapons().contains(eSource.getEntity().getEquipmentNum(eq)))) || ((eq.getType() instanceof AmmoType) && (bay.getBayAmmo().contains(eSource.getEntity().getEquipmentNum(eq))))) {
            return false;
        }
    }
    if (eq.getType() instanceof AmmoType) {
        return (null != bay) && canTakeEquipment(bay, eq);
    }
    if (UnitUtil.isWeaponEnhancement(eq.getType())) {
        if ((null != bay) && canTakeEquipment(bay, eq)) {
            for (Integer eqNum : bay.getBayWeapons()) {
                if (eSource.getEntity().getEquipment(eqNum) == eq.getLinked()) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }
    return true;
}
Also used : AmmoType(megamek.common.AmmoType) TreePath(javax.swing.tree.TreePath) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) WeaponType(megamek.common.WeaponType) PPCWeapon(megamek.common.weapons.ppc.PPCWeapon) PPCBayWeapon(megamek.common.weapons.bayweapons.PPCBayWeapon)

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