Search in sources :

Example 46 with EquipmentType

use of megamek.common.EquipmentType 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 47 with EquipmentType

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

the class EquipmentView method loadEquipmentCombo.

private void loadEquipmentCombo() {
    equipmentCombo.setRenderer(new EquipmentListCellRenderer(getTank()));
    equipmentCombo.setKeySelectionManager(new EquipmentListCellKeySelectionManager());
    equipmentCombo.removeAllItems();
    equipmentTypes = new Vector<EquipmentType>();
    for (EquipmentType eq : masterEquipmentList) {
        if (UnitUtil.isLegal(getTank(), eq)) {
            equipmentTypes.add(eq);
            equipmentCombo.addItem(eq);
        }
    }
}
Also used : EquipmentListCellKeySelectionManager(megameklab.com.util.EquipmentListCellKeySelectionManager) EquipmentListCellRenderer(megameklab.com.util.EquipmentListCellRenderer) EquipmentType(megamek.common.EquipmentType)

Example 48 with EquipmentType

use of megamek.common.EquipmentType 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 49 with EquipmentType

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

the class UnitUtil method getShieldDamageAbsorption.

public static int getShieldDamageAbsorption(Mech mech, int location) {
    final String METHOD_NAME = "getShieldDamageAbsorption(Mech, int)";
    for (int slot = 0; slot < mech.getNumberOfCriticals(location); slot++) {
        CriticalSlot cs = mech.getCritical(location, slot);
        if (cs == null) {
            continue;
        }
        if (cs.getType() != CriticalSlot.TYPE_EQUIPMENT) {
            continue;
        }
        Mounted m = cs.getMount();
        if (m == null) {
            getLogger().log(UnitUtil.class, METHOD_NAME, LogLevel.ERROR, "Null Mount index: " + cs.getIndex());
            m = cs.getMount();
        }
        EquipmentType type = m.getType();
        if ((type instanceof MiscType) && ((MiscType) type).isShield()) {
            return m.getBaseDamageAbsorptionRate();
        }
    }
    return 0;
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) EquipmentType(megamek.common.EquipmentType)

Aggregations

EquipmentType (megamek.common.EquipmentType)49 Mounted (megamek.common.Mounted)24 MiscType (megamek.common.MiscType)14 LocationFullException (megamek.common.LocationFullException)10 ArrayList (java.util.ArrayList)8 JLabel (javax.swing.JLabel)6 AmmoType (megamek.common.AmmoType)6 CriticalSlot (megamek.common.CriticalSlot)6 WeaponType (megamek.common.WeaponType)5 Dimension (java.awt.Dimension)4 List (java.util.List)4 Vector (java.util.Vector)4 BattleArmor (megamek.common.BattleArmor)4 Mech (megamek.common.Mech)4 EntitySource (megameklab.com.ui.EntitySource)4 RefreshListener (megameklab.com.util.RefreshListener)4 GridBagConstraints (java.awt.GridBagConstraints)3 GridBagLayout (java.awt.GridBagLayout)3 ActionEvent (java.awt.event.ActionEvent)3 StringJoiner (java.util.StringJoiner)3