Search in sources :

Example 16 with AmmoType

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

the class EquipmentTab method addEquipment.

private void addEquipment(EquipmentType equip) {
    Mounted mount = null;
    boolean isMisc = equip instanceof MiscType;
    if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
        if (!UnitUtil.hasTargComp(getAero())) {
            mount = UnitUtil.updateTC(getAero(), equip);
            if (null != mount) {
                equipmentList.addCrit(mount);
            }
        }
    } else {
        int count = (Integer) spnAddCount.getValue();
        if (getAero().usesWeaponBays() && (equip instanceof AmmoType)) {
            Mounted aMount = UnitUtil.findUnallocatedAmmo(getAero(), equip);
            if (null != aMount) {
                aMount.setShotsLeft(aMount.getUsableShotsLeft() + ((AmmoType) equip).getShots() * count);
                return;
            } else {
                mount = new Mounted(getAero(), equip);
                mount.setShotsLeft(((AmmoType) equip).getShots() * count);
                try {
                    getAero().addEquipment(mount, Entity.LOC_NONE, false);
                    equipmentList.addCrit(mount);
                } catch (LocationFullException lfe) {
                // this can't happen, we add to Entity.LOC_NONE
                }
            }
        } else {
            try {
                for (int i = 0; i < count; i++) {
                    mount = new Mounted(getAero(), equip);
                    getAero().addEquipment(mount, Entity.LOC_NONE, false);
                    equipmentList.addCrit(mount);
                }
            } catch (LocationFullException lfe) {
            // this can't happen, we add to Entity.LOC_NONE
            }
        }
    }
}
Also used : AmmoType(megamek.common.AmmoType) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType)

Example 17 with AmmoType

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

the class BuildView method loadEquipmentTable.

private void loadEquipmentTable() {
    equipmentList.removeAllCrits();
    masterEquipmentList.clear();
    for (Mounted mount : getAero().getMisc()) {
        if ((mount.getLocation() == Entity.LOC_NONE) && !isEngineHeatSink(mount)) {
            masterEquipmentList.add(mount);
        }
    }
    for (Mounted mount : getAero().getTotalWeaponList()) {
        if (mount.getLocation() == Entity.LOC_NONE) {
            masterEquipmentList.add(mount);
        }
    }
    for (Mounted mount : getAero().getAmmo()) {
        if ((mount.getLocation() == Entity.LOC_NONE) && ((mount.getUsableShotsLeft() > 1) || (((AmmoType) mount.getType()).getAmmoType() == AmmoType.T_COOLANT_POD))) {
            masterEquipmentList.add(mount);
        }
    }
    Collections.sort(masterEquipmentList, StringUtils.mountedComparator());
    // HeatSinks first
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (UnitUtil.isHeatSink(masterEquipmentList.get(pos))) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // Jump Jets
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (UnitUtil.isJumpJet(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // weapons and ammo
    Vector<Mounted> weaponsNAmmoList = new Vector<Mounted>(10, 1);
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if ((masterEquipmentList.get(pos).getType() instanceof Weapon) || (masterEquipmentList.get(pos).getType() instanceof AmmoType)) {
            weaponsNAmmoList.add(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    Collections.sort(weaponsNAmmoList, StringUtils.mountedComparator());
    for (Mounted mount : weaponsNAmmoList) {
        equipmentList.addCrit(mount);
    }
    // Equipment
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if ((masterEquipmentList.get(pos).getType() instanceof MiscType) && !UnitUtil.isArmor(masterEquipmentList.get(pos).getType()) && !UnitUtil.isTSM(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // structure
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (UnitUtil.isStructure(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // armor
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (UnitUtil.isArmor(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // everything else that is not TSM
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        if (!UnitUtil.isTSM(masterEquipmentList.get(pos).getType())) {
            equipmentList.addCrit(masterEquipmentList.get(pos));
            masterEquipmentList.remove(pos);
            pos--;
        }
    }
    // TSM
    for (int pos = 0; pos < masterEquipmentList.size(); pos++) {
        equipmentList.addCrit(masterEquipmentList.get(pos));
    }
}
Also used : AmmoType(megamek.common.AmmoType) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) Vector(java.util.Vector) Weapon(megamek.common.weapons.Weapon)

Example 18 with AmmoType

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

the class WeaponView method loadAmmo.

private void loadAmmo(Component o) {
    if (o instanceof JList) {
        JList<?> list = (JList<?>) o;
        if (list.equals(laserWeaponCombo)) {
            subLaserAmmoList.removeAllElements();
            WeaponType weapon = (WeaponType) subLaserWeaponList.elementAt(list.getSelectedIndex());
            if (weapon.hasFlag(WeaponType.F_ONESHOT)) {
                return;
            }
            Vector<String> equipmentList = new Vector<String>();
            if (weapon.getAmmoType() != AmmoType.T_NA) {
                for (AmmoType ammo : AmmoType.getMunitionsFor(weapon.getAmmoType())) {
                    if ((ammo.getRackSize() == weapon.getRackSize()) && UnitUtil.isLegal(getTank(), ammo) && !ammo.hasFlag(AmmoType.F_BATTLEARMOR)) {
                        subLaserAmmoList.add(ammo);
                        equipmentList.add(ammo.getInternalName());
                    }
                }
            }
            laserAmmoCombo.setListData(equipmentList);
        } else if (list.equals(missileWeaponCombo)) {
            subMissileAmmoList.removeAllElements();
            WeaponType weapon = (WeaponType) subMissileWeaponList.elementAt(list.getSelectedIndex());
            if (weapon.hasFlag(WeaponType.F_ONESHOT)) {
                return;
            }
            Vector<String> equipmentList = new Vector<String>();
            for (AmmoType ammo : AmmoType.getMunitionsFor(weapon.getAmmoType())) {
                if ((ammo.getRackSize() == weapon.getRackSize()) && UnitUtil.isLegal(getTank(), ammo) && !ammo.hasFlag(AmmoType.F_BATTLEARMOR) && !weapon.hasFlag(WeaponType.F_ONESHOT)) {
                    subMissileAmmoList.add(ammo);
                    equipmentList.add(ammo.getInternalName());
                }
            }
            missileAmmoCombo.setListData(equipmentList);
        } else if (list.equals(ballisticWeaponCombo)) {
            subBallisticAmmoList.removeAllElements();
            WeaponType weapon = (WeaponType) subBallisticWeaponList.elementAt(list.getSelectedIndex());
            if (weapon.hasFlag(WeaponType.F_ONESHOT)) {
                return;
            }
            Vector<String> equipmentList = new Vector<String>();
            for (AmmoType ammo : AmmoType.getMunitionsFor(weapon.getAmmoType())) {
                if ((ammo.getRackSize() == weapon.getRackSize()) && UnitUtil.isLegal(getTank(), ammo) && !ammo.hasFlag(AmmoType.F_BATTLEARMOR)) {
                    subBallisticAmmoList.add(ammo);
                    equipmentList.add(ammo.getInternalName());
                }
            }
            ballisticAmmoCombo.setListData(equipmentList);
        } else if (list.equals(artilleryWeaponCombo)) {
            subArtilleryAmmoList.removeAllElements();
            WeaponType weapon = (WeaponType) subArtilleryWeaponList.elementAt(list.getSelectedIndex());
            if (weapon.hasFlag(WeaponType.F_ONESHOT)) {
                return;
            }
            Vector<String> equipmentList = new Vector<String>();
            for (AmmoType ammo : AmmoType.getMunitionsFor(weapon.getAmmoType())) {
                if ((ammo.getRackSize() == weapon.getRackSize()) && UnitUtil.isLegal(getTank(), ammo) && !ammo.hasFlag(AmmoType.F_BATTLEARMOR)) {
                    subArtilleryAmmoList.add(ammo);
                    equipmentList.add(ammo.getInternalName());
                }
            }
            artilleryAmmoCombo.setListData(equipmentList);
        }
    }
}
Also used : AmmoType(megamek.common.AmmoType) WeaponType(megamek.common.WeaponType) Vector(java.util.Vector) JList(javax.swing.JList)

Example 19 with AmmoType

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

the class AeroBayTransferHandler method importData.

@Override
public boolean importData(TransferSupport support) {
    if (!support.isDrop()) {
        return false;
    }
    // Fields are equipmentNum, node child index, bay child index
    String[] source = null;
    List<Mounted> eqList = new ArrayList<>();
    try {
        source = ((String) support.getTransferable().getTransferData(DataFlavor.stringFlavor)).split(":");
        for (String field : source[0].split(",")) {
            int eqNum = Integer.parseInt(field);
            Mounted m = eSource.getEntity().getEquipment(eqNum);
            if (null != m) {
                eqList.add(m);
            }
        }
    } catch (Exception ex) {
        MegaMekLab.getLogger().log(AeroBayTransferHandler.class, // $NON-NLS-1$
        "importData(TransferSupport)", ex);
        return false;
    }
    if (eqList.isEmpty()) {
        return false;
    }
    if ((support.getComponent() instanceof BayWeaponCriticalTree)) {
        final BayWeaponCriticalTree tree = (BayWeaponCriticalTree) support.getComponent();
        if (eSource.getEntity().usesWeaponBays() && (eqList.size() == 1)) {
            // If it's a bay we move it and its entire contents. Otherwise we find the bay that was
            // dropped on and add it there. A weapon dropped on an illegal bay will create a new one
            // and non-bay equipment will be added at the top level regardless of the drop location.
            // Non-weapon bay equipment cannot be dropped on an illegal bay.
            final Mounted mount = eqList.get(0);
            if (mount.getType() instanceof BayWeapon) {
                tree.addBay(mount);
            } else if ((mount.getType() instanceof AmmoType) && (support.getUserDropAction() == AMMO_SINGLE)) {
                // Default action for ammo is to move a single slot. Holding the ctrl key when dropping
                // will create a AMMO_ALL command, which adds all the ammo of the type.
                tree.addAmmo(mount, ((AmmoType) mount.getType()).getShots(), ((JTree.DropLocation) support.getDropLocation()).getPath());
            } else {
                tree.addToArc(mount, ((JTree.DropLocation) support.getDropLocation()).getPath());
            }
        } else {
            // Small craft don't use bays.
            tree.addToLocation(eqList);
        }
    } else {
        // Target is unallocated bay table.
        for (Mounted mount : eqList) {
            if (mount.getType() instanceof AmmoType) {
                AmmoType at = (AmmoType) mount.getType();
                // Check whether we are moving one of multiple slots.
                if ((support.getUserDropAction() == AMMO_SINGLE) && (mount.getUsableShotsLeft() > at.getShots())) {
                    mount.setShotsLeft(mount.getUsableShotsLeft() - at.getShots());
                }
                Mounted addMount = UnitUtil.findUnallocatedAmmo(eSource.getEntity(), at);
                if (null != addMount) {
                    if (support.getUserDropAction() == AMMO_SINGLE) {
                        addMount.setShotsLeft(addMount.getUsableShotsLeft() + at.getShots());
                    } else {
                        addMount.setShotsLeft(addMount.getUsableShotsLeft() + mount.getUsableShotsLeft());
                    }
                } else {
                    try {
                        Mounted m = eSource.getEntity().addEquipment(at, Entity.LOC_NONE);
                        if (support.getUserDropAction() == AMMO_ALL) {
                            m.setShotsLeft(mount.getUsableShotsLeft());
                        }
                    } catch (LocationFullException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            } else {
                List<Mounted> toRemove;
                if (mount.getType() instanceof BayWeapon) {
                    toRemove = new ArrayList<>();
                    for (Integer num : mount.getBayWeapons()) {
                        toRemove.add(eSource.getEntity().getEquipment(num));
                    }
                    for (Integer num : mount.getBayAmmo()) {
                        toRemove.add(eSource.getEntity().getEquipment(num));
                    }
                } else {
                    toRemove = Collections.singletonList(mount);
                }
                for (Mounted m : toRemove) {
                    if (m.getType() instanceof AmmoType) {
                        Mounted aMount = UnitUtil.findUnallocatedAmmo(eSource.getEntity(), m.getType());
                        if (null != aMount) {
                            aMount.setShotsLeft(aMount.getUsableShotsLeft() + m.getUsableShotsLeft());
                            m.setShotsLeft(0);
                            continue;
                        }
                    }
                    UnitUtil.removeCriticals(eSource.getEntity(), m);
                    UnitUtil.changeMountStatus(eSource.getEntity(), m, Entity.LOC_NONE, Entity.LOC_NONE, false);
                    if ((mount.getType() instanceof WeaponType) && (m.getLinkedBy() != null)) {
                        UnitUtil.removeCriticals(eSource.getEntity(), m.getLinkedBy());
                        UnitUtil.changeMountStatus(eSource.getEntity(), m.getLinkedBy(), Entity.LOC_NONE, Entity.LOC_NONE, false);
                        m.getLinkedBy().setLinked(null);
                        m.setLinkedBy(null);
                    }
                }
                UnitUtil.compactCriticals(eSource.getEntity());
            }
            if (mount.getType() instanceof BayWeapon) {
                mount.getBayWeapons().clear();
                mount.getBayAmmo().clear();
                UnitUtil.removeMounted(eSource.getEntity(), mount);
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) BayWeapon(megamek.common.weapons.bayweapons.BayWeapon) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) LocationFullException(megamek.common.LocationFullException) IOException(java.io.IOException) AmmoType(megamek.common.AmmoType) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType)

Example 20 with AmmoType

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

the class BayWeaponCriticalTree method canTakeEquipment.

/**
 * Determines whether the equipment can be added to the bay. For a weapon this is determined
 * by bay type and AV limit. For ammo this is determined by the presence of a weapon in that location
 * that can use the ammo. For weapon enhancements this is determined by the presence of a weapon
 * that can use the enhancement that doesn't already have one.
 *
 * @param bay
 * @param eq
 * @return
 */
private boolean canTakeEquipment(Mounted bay, Mounted eq) {
    if (eq.getType() instanceof WeaponType) {
        if (((WeaponType) eq.getType()).getBayType() != bay.getType()) {
            return false;
        }
        // find current av
        double av = 0;
        for (Integer wNum : bay.getBayWeapons()) {
            final Mounted w = eSource.getEntity().getEquipment(wNum);
            // That's 1d6 for rifle and 2d6 for canon.
            if (w.getType().hasFlag(WeaponType.F_PLASMA)) {
                if (((WeaponType) w.getType()).getDamage() == WeaponType.DAMAGE_VARIABLE) {
                    av += 7;
                } else {
                    av += 13.5;
                }
            } else {
                av += ((WeaponType) w.getType()).getShortAV();
            }
            // Capacitors in bays are always considered charged.
            if ((w.getLinkedBy() != null) && (w.getLinkedBy().getType().hasFlag(MiscType.F_PPC_CAPACITOR))) {
                av += 5;
            }
        }
        if (((WeaponType) eq.getType()).isCapital()) {
            return av + ((WeaponType) eq.getType()).getShortAV() <= 70;
        } else {
            return av + ((WeaponType) eq.getType()).getShortAV() <= 700;
        }
    } else if (eq.getType() instanceof AmmoType) {
        for (int eqNum : bay.getBayWeapons()) {
            final WeaponType weapon = (WeaponType) eSource.getEntity().getEquipment(eqNum).getType();
            if ((weapon.getAmmoType() == ((AmmoType) eq.getType()).getAmmoType()) && (weapon.getRackSize() == ((AmmoType) eq.getType()).getRackSize())) {
                return true;
            }
        }
    } else if ((eq.getType() instanceof MiscType) && ((eq.getType().hasFlag(MiscType.F_ARTEMIS) || eq.getType().hasFlag(MiscType.F_ARTEMIS_V)) || eq.getType().hasFlag(MiscType.F_ARTEMIS_PROTO))) {
        for (int 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))) {
                return true;
            }
        }
    } else if ((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_APOLLO)) {
        for (int eqNum : bay.getBayWeapons()) {
            final Mounted weapon = eSource.getEntity().getEquipment(eqNum);
            final WeaponType wtype = (WeaponType) weapon.getType();
            if ((weapon.getLinkedBy() == null) && (wtype.getAmmoType() == AmmoType.T_MRM)) {
                return true;
            }
        }
    } else if ((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_PPC_CAPACITOR) && (bay.getType() instanceof PPCBayWeapon)) {
        for (int eqNum : bay.getBayWeapons()) {
            if (eSource.getEntity().getEquipment(eqNum).getLinkedBy() == null) {
                return true;
            }
        }
    }
    return false;
}
Also used : AmmoType(megamek.common.AmmoType) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) MiscType(megamek.common.MiscType) PPCBayWeapon(megamek.common.weapons.bayweapons.PPCBayWeapon)

Aggregations

AmmoType (megamek.common.AmmoType)34 Mounted (megamek.common.Mounted)32 ArrayList (java.util.ArrayList)15 MiscType (megamek.common.MiscType)15 WeaponType (megamek.common.WeaponType)15 Vector (java.util.Vector)13 Font (java.awt.Font)9 EquipmentType (megamek.common.EquipmentType)8 LocationFullException (megamek.common.LocationFullException)7 BattleArmor (megamek.common.BattleArmor)6 Weapon (megamek.common.weapons.Weapon)6 Dimension (java.awt.Dimension)5 JMenuItem (javax.swing.JMenuItem)5 JPopupMenu (javax.swing.JPopupMenu)5 InfantryWeapon (megamek.common.weapons.infantry.InfantryWeapon)5 PPCWeapon (megamek.common.weapons.ppc.PPCWeapon)5 MouseEvent (java.awt.event.MouseEvent)4 MouseListener (java.awt.event.MouseListener)4 HashMap (java.util.HashMap)4 Hashtable (java.util.Hashtable)4