use of megamek.common.EquipmentType in project megameklab by MegaMek.
the class EquipmentTab method actionPerformed.
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals(ADD_COMMAND)) {
int view = masterEquipmentTable.getSelectedRow();
if (view < 0) {
// selection got filtered away
return;
}
int selected = masterEquipmentTable.convertRowIndexToModel(view);
EquipmentType equip = masterEquipmentList.getType(selected);
addEquipment(equip);
} else if (e.getActionCommand().equals(REMOVE_COMMAND)) {
int[] selectedRows = equipmentTable.getSelectedRows();
for (Integer row : selectedRows) {
equipmentList.removeMounted(row);
}
equipmentList.removeCrits(selectedRows);
UnitUtil.compactCriticals(getTank());
} else if (e.getActionCommand().equals(REMOVEALL_COMMAND)) {
removeAllEquipment();
} else {
return;
}
fireTableRefresh();
}
use of megamek.common.EquipmentType 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++;
}
}
}
use of megamek.common.EquipmentType in project megameklab by MegaMek.
the class WeaponView method loadWeaponCombos.
private void loadWeaponCombos() {
subLaserWeaponList.removeAllElements();
subMissileWeaponList.removeAllElements();
subBallisticWeaponList.removeAllElements();
subArtilleryWeaponList.removeAllElements();
Vector<String> equipmentList = new Vector<String>();
for (EquipmentType eq : masterLaserWeaponList) {
if (UnitUtil.isLegal(getTank(), eq)) {
subLaserWeaponList.add(eq);
equipmentList.add(eq.getInternalName());
}
}
laserWeaponCombo.setListData(equipmentList);
equipmentList = new Vector<String>();
for (EquipmentType eq : masterMissileWeaponList) {
if (UnitUtil.isLegal(getTank(), eq)) {
subMissileWeaponList.add(eq);
equipmentList.add(eq.getInternalName());
}
}
missileWeaponCombo.setListData(equipmentList);
equipmentList = new Vector<String>();
for (EquipmentType eq : masterBallisticWeaponList) {
if (UnitUtil.isLegal(getTank(), eq)) {
subBallisticWeaponList.add(eq);
equipmentList.add(eq.getInternalName());
}
}
ballisticWeaponCombo.setListData(equipmentList);
equipmentList = new Vector<String>();
for (EquipmentType eq : masterArtilleryWeaponList) {
if (UnitUtil.isLegal(getTank(), eq)) {
subArtilleryWeaponList.add(eq);
equipmentList.add(eq.getInternalName());
}
}
artilleryWeaponCombo.setListData(equipmentList);
}
use of megamek.common.EquipmentType in project megameklab by MegaMek.
the class BayWeaponCriticalTree method addToBay.
/**
* Adds an equipment mount to a bay. Changes the equipment mount's location and updates the bay's
* weapon or ammo list if necessary.
*
* @param bay
* @param eq
*/
public void addToBay(@Nullable Mounted bay, Mounted eq) {
// Check that we have a bay
if ((null == bay) || !canTakeEquipment(bay, eq)) {
if (eq.getType() instanceof WeaponType) {
EquipmentType bayType = ((WeaponType) eq.getType()).getBayType();
addToNewBay(bayType, eq);
} else {
addToLocation(eq);
}
return;
} else if (eq.getType() instanceof MiscType) {
if (eq.getType().hasFlag(MiscType.F_ARTEMIS) || eq.getType().hasFlag(MiscType.F_ARTEMIS_PROTO) || eq.getType().hasFlag(MiscType.F_ARTEMIS_V)) {
for (Integer eqNum : bay.getBayWeapons()) {
final Mounted weapon = eSource.getEntity().getEquipment(eqNum);
final WeaponType wtype = (WeaponType) weapon.getType();
if ((weapon.getLinkedBy() == null) && ((wtype.getAmmoType() == AmmoType.T_LRM) || (wtype.getAmmoType() == AmmoType.T_SRM) || (wtype.getAmmoType() == AmmoType.T_MML) || (wtype.getAmmoType() == AmmoType.T_NLRM))) {
moveToArc(eq);
eq.setLinked(weapon);
break;
}
}
} else if (eq.getType().hasFlag(MiscType.F_APOLLO) || eq.getType().hasFlag(MiscType.F_PPC_CAPACITOR)) {
for (Integer eqNum : bay.getBayWeapons()) {
final Mounted weapon = eSource.getEntity().getEquipment(eqNum);
if (weapon.getLinkedBy() == null) {
moveToArc(eq);
eq.setLinked(weapon);
break;
}
}
}
} else {
// there.
if (eq.getType() instanceof AmmoType) {
Optional<Mounted> addMount = bay.getBayAmmo().stream().map(n -> eSource.getEntity().getEquipment(n)).filter(m -> m.getType() == eq.getType()).findFirst();
if (addMount.isPresent()) {
addMount.get().setShotsLeft(addMount.get().getBaseShotsLeft() + eq.getBaseShotsLeft());
UnitUtil.removeMounted(eSource.getEntity(), eq);
refresh.refreshEquipment();
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshStatus();
refresh.refreshSummary();
return;
}
}
EquipmentNode bayNode = null;
for (Enumeration<?> e = ((TreeNode) model.getRoot()).children(); e.hasMoreElements(); ) {
final EquipmentNode node = (EquipmentNode) e.nextElement();
if (node.getMounted() == bay) {
bayNode = node;
break;
}
}
if (null != bayNode) {
moveToArc(eq);
EquipmentNode eqNode = new EquipmentNode(eq);
model.insertNodeInto(eqNode, bayNode, bayNode.getChildCount());
eqNode.setParent(bayNode);
if (eq.getType() instanceof WeaponType) {
bay.addWeaponToBay(eSource.getEntity().getEquipmentNum(eq));
if (eq.getLinkedBy() != null) {
moveToArc(eq.getLinkedBy());
}
} else if (eq.getType() instanceof AmmoType) {
bay.addAmmoToBay(eSource.getEntity().getEquipmentNum(eq));
}
} else {
// $NON-NLS-1$
MegaMekLab.getLogger().log(// $NON-NLS-1$
BayWeaponCriticalTree.class, // $NON-NLS-1$
"addToBay(Mounted,Mounted)", LogLevel.DEBUG, // $NON-NLS-1$
bay.getName() + "[" + eSource.getEntity().getEquipmentNum(bay) + "] not found in " + // $NON-NLS-1$
getLocationName());
}
}
refresh.refreshEquipment();
refresh.refreshBuild();
refresh.refreshPreview();
refresh.refreshStatus();
refresh.refreshSummary();
}
use of megamek.common.EquipmentType in project megameklab by MegaMek.
the class CriticalTransferHandler method importData.
/**
*/
@Override
public boolean importData(TransferSupport info) {
if (!info.isDrop() || !((getUnit() instanceof Mech) || (getUnit() instanceof Aero) || (getUnit() instanceof BattleArmor))) {
return false;
}
int trooper = 0;
if (info.getComponent() instanceof DropTargetCriticalList) {
DropTargetCriticalList<?> list = (DropTargetCriticalList<?>) info.getComponent();
if (getUnit() instanceof BattleArmor) {
String[] split = list.getName().split(":");
if (split.length != 2) {
return false;
}
location = Integer.parseInt(split[0]);
trooper = Integer.parseInt(split[1]);
} else {
location = Integer.parseInt(list.getName());
}
Transferable t = info.getTransferable();
int slotNumber = list.getDropLocation().getIndex();
try {
Mounted eq = getUnit().getEquipment(Integer.parseInt((String) t.getTransferData(DataFlavor.stringFlavor)));
if (getUnit() instanceof BattleArmor) {
if ((location == eq.getBaMountLoc()) && (trooper == eq.getLocation())) {
return false;
}
} else {
// the criticals its mounted in
if (eq.getLocation() != Entity.LOC_NONE || eq.getSecondLocation() != Entity.LOC_NONE) {
UnitUtil.removeCriticals(getUnit(), eq);
changeMountStatus(eq, Entity.LOC_NONE, false);
} else {
eq.setOmniPodMounted(UnitUtil.canPodMount(getUnit(), eq));
}
}
if (!UnitUtil.isValidLocation(getUnit(), eq.getType(), location)) {
JOptionPane.showMessageDialog(null, eq.getName() + " can't be placed in " + getUnit().getLocationName(location) + "!", "Invalid Location", JOptionPane.INFORMATION_MESSAGE);
return false;
}
if (getUnit() instanceof Aero) {
return addEquipmentAero((Aero) getUnit(), eq);
} else if (getUnit() instanceof Mech) {
// superheavies can put 2 ammobins or heatsinks in one crit
if ((getUnit() instanceof Mech) && ((Mech) getUnit()).isSuperHeavy()) {
CriticalSlot cs = getUnit().getCritical(location, slotNumber);
if ((cs != null) && (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) && (cs.getMount2() == null)) {
EquipmentType etype = cs.getMount().getType();
EquipmentType etype2 = eq.getType();
boolean canDouble = false;
if ((etype instanceof AmmoType) && (etype2 instanceof AmmoType)) {
canDouble = (((AmmoType) etype).getAmmoType() == ((AmmoType) etype2).getAmmoType()) && (((AmmoType) etype).getRackSize() == ((AmmoType) etype2).getRackSize());
} else if (etype.equals(etype2) && UnitUtil.isHeatSink(etype)) {
canDouble = etype.getCriticals(getUnit()) == 1;
}
if (canDouble) {
cs.setMount2(eq);
changeMountStatus(eq, location, false);
return true;
}
}
}
return addEquipmentMech((Mech) getUnit(), eq, slotNumber);
} else if (getUnit() instanceof BattleArmor) {
return addEquipmentBA((BattleArmor) getUnit(), eq, trooper);
}
} catch (LocationFullException lfe) {
JOptionPane.showMessageDialog(null, lfe.getMessage(), "Location Full", JOptionPane.INFORMATION_MESSAGE);
return false;
} catch (Exception ex) {
ex.printStackTrace();
}
return true;
}
return false;
}
Aggregations