use of megamek.common.WeaponType 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;
}
Aggregations