Search in sources :

Example 31 with WeaponType

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;
}
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

WeaponType (megamek.common.WeaponType)31 Mounted (megamek.common.Mounted)24 AmmoType (megamek.common.AmmoType)14 MiscType (megamek.common.MiscType)12 Vector (java.util.Vector)8 InfantryWeapon (megamek.common.weapons.infantry.InfantryWeapon)8 ArrayList (java.util.ArrayList)7 JMenuItem (javax.swing.JMenuItem)6 JPopupMenu (javax.swing.JPopupMenu)6 BattleArmor (megamek.common.BattleArmor)6 CriticalSlot (megamek.common.CriticalSlot)6 Entity (megamek.common.Entity)6 EquipmentType (megamek.common.EquipmentType)6 PPCWeapon (megamek.common.weapons.ppc.PPCWeapon)6 ActionEvent (java.awt.event.ActionEvent)5 LocationFullException (megamek.common.LocationFullException)5 TestBattleArmor (megamek.common.verifier.TestBattleArmor)5 Dimension (java.awt.Dimension)4 ActionListener (java.awt.event.ActionListener)4 MouseEvent (java.awt.event.MouseEvent)4