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();
}
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);
}
}
}
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));
}
}
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;
}
Aggregations