Search in sources :

Example 16 with Mounted

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

the class UnitUtil method expandUnitMounts.

/**
 * Expands crits that are a single mount by have multiple spreadable crits
 * Such as TSM, Endo Steel, Reactive armor.
 *
 * @param unit
 */
public static void expandUnitMounts(Mech unit) {
    for (int location = 0; location <= Mech.LOC_LLEG; location++) {
        for (int slot = 0; slot < unit.getNumberOfCriticals(location); slot++) {
            CriticalSlot cs = unit.getCritical(location, slot);
            if ((cs == null) || (cs.getType() == CriticalSlot.TYPE_SYSTEM)) {
                continue;
            }
            Mounted mount = cs.getMount();
            if (!UnitUtil.isFixedLocationSpreadEquipment(mount.getType()) && (UnitUtil.isTSM(mount.getType()) || UnitUtil.isArmorOrStructure(mount.getType()))) {
                Mounted newMount = new Mounted(unit, mount.getType());
                newMount.setLocation(location, mount.isRearMounted());
                newMount.setArmored(mount.isArmored());
                cs.setMount(newMount);
                cs.setArmored(mount.isArmored());
                unit.getEquipment().remove(mount);
                unit.getMisc().remove(mount);
                unit.getEquipment().add(newMount);
                unit.getMisc().add(newMount);
            }
        }
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted)

Example 17 with Mounted

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

the class UnitUtil method updateJumpJets.

/**
 * updates the Jump Jets.
 *
 * @param unit
 * @param jjAmount
 * @param jjType
 */
public static void updateJumpJets(Mech unit, int jjAmount, int jjType) {
    final String METHOD_NAME = "updateJumpJets(Mech, int, int)";
    unit.setOriginalJumpMP(jjAmount);
    int ctype = unit.getJumpType();
    if (jjType == ctype) {
        int currentJJ = (int) unit.getMisc().stream().filter(m -> m.getType().hasFlag(MiscType.F_JUMP_JET)).count();
        if (jjAmount < currentJJ) {
            UnitUtil.removeJumpJets(unit, currentJJ - jjAmount);
            return;
        } else if (jjAmount > currentJJ) {
            jjAmount = jjAmount - currentJJ;
        } else {
            // No change, get the fuck outta here!
            return;
        }
    } else {
        UnitUtil.removeJumpJets(unit, unit.getJumpMP());
    }
    // and add if too low
    if (jjType == Mech.JUMP_BOOSTER) {
        UnitUtil.removeJumpJets(unit, unit.getJumpMP());
        createSpreadMounts(unit, EquipmentType.get(UnitUtil.getJumpJetType(jjType, unit.isClan())));
    } else {
        while (jjAmount > 0) {
            try {
                unit.addEquipment(new Mounted(unit, EquipmentType.get(UnitUtil.getJumpJetType(jjType, unit.isClan()))), Entity.LOC_NONE, false);
            } catch (Exception ex) {
                getLogger().log(UnitUtil.class, METHOD_NAME, ex);
            }
            jjAmount--;
        }
    }
}
Also used : Mounted(megamek.common.Mounted) LocationFullException(megamek.common.LocationFullException)

Example 18 with Mounted

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

the class UnitUtil method removeMounted.

public static void removeMounted(Entity unit, Mounted mount) {
    UnitUtil.removeCriticals(unit, mount);
    // Some special checks for BA
    if (unit instanceof BattleArmor) {
        // to detach the weapon
        if (mount.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) && (mount.getLinked() != null)) {
            Mounted link = mount.getLinked();
            link.setDWPMounted(false);
            link.setLinked(null);
            link.setLinkedBy(null);
        }
        // to clear the mounted status of the DWP
        if ((mount.getLinkedBy() != null) && mount.getLinkedBy().getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK)) {
            Mounted dwp = mount.getLinkedBy();
            dwp.setLinked(null);
            dwp.setLinkedBy(null);
        }
        // to detach the weapon
        if (mount.getType().hasFlag(MiscType.F_AP_MOUNT) && (mount.getLinked() != null)) {
            Mounted link = mount.getLinked();
            link.setAPMMounted(false);
            link.setLinked(null);
            link.setLinkedBy(null);
        }
        // to clear the mounted status of the AP Mount
        if ((mount.getLinkedBy() != null) && mount.getLinkedBy().getType().hasFlag(MiscType.F_AP_MOUNT)) {
            Mounted apm = mount.getLinkedBy();
            apm.setLinked(null);
            apm.setLinkedBy(null);
        }
    }
    // Some special checks for Aeros
    if (unit instanceof Aero) {
        if (mount.getType() instanceof WeaponType) {
            // Aeros have additional weapon lists that need to be cleared
            ((Aero) unit).getTotalWeaponList().remove(mount);
            ((Aero) unit).getWeaponBayList().remove(mount);
            ((Aero) unit).getWeaponGroupList().remove(mount);
        }
    }
    // We will need to reset the equipment numbers of the bay ammo and weapons
    Map<Mounted, List<Mounted>> bayWeapons = new HashMap<>();
    Map<Mounted, List<Mounted>> bayAmmo = new HashMap<>();
    for (Mounted bay : unit.getWeaponBayList()) {
        List<Mounted> list = bay.getBayWeapons().stream().map(n -> unit.getEquipment(n)).collect(Collectors.toList());
        bayWeapons.put(bay, list);
        list = bay.getBayAmmo().stream().map(n -> unit.getEquipment(n)).collect(Collectors.toList());
        bayAmmo.put(bay, list);
    }
    unit.getEquipment().remove(mount);
    if (mount.getType() instanceof MiscType) {
        unit.getMisc().remove(mount);
    } else if (mount.getType() instanceof AmmoType) {
        unit.getAmmo().remove(mount);
    } else {
        unit.getWeaponList().remove(mount);
        unit.getTotalWeaponList().remove(mount);
    }
    for (Mounted bay : bayWeapons.keySet()) {
        bay.getBayWeapons().clear();
        for (Mounted w : bayWeapons.get(bay)) {
            if (mount != w) {
                bay.getBayWeapons().add(unit.getEquipmentNum(w));
            }
        }
    }
    for (Mounted bay : bayAmmo.keySet()) {
        bay.getBayAmmo().clear();
        for (Mounted a : bayAmmo.get(bay)) {
            if (mount != a) {
                bay.getBayAmmo().add(unit.getEquipmentNum(a));
            }
        }
    }
    // An example of this would be removing a linked Artemis IV FCS
    for (Mounted m : unit.getEquipment()) {
        if (mount.equals(m.getLinkedBy())) {
            m.setLinkedBy(null);
        }
    }
}
Also used : CapitalMissileWeapon(megamek.common.weapons.capitalweapons.CapitalMissileWeapon) Arrays(java.util.Arrays) Dropship(megamek.common.Dropship) RLWeapon(megamek.common.weapons.missiles.RLWeapon) CriticalSlot(megamek.common.CriticalSlot) TestTank(megamek.common.verifier.TestTank) StopSwarmAttack(megamek.common.weapons.StopSwarmAttack) Vector(java.util.Vector) BattleArmor(megamek.common.BattleArmor) HVACWeapon(megamek.common.weapons.autocannons.HVACWeapon) Map(java.util.Map) SRTWeapon(megamek.common.weapons.srms.SRTWeapon) BigInteger(java.math.BigInteger) SmallCraft(megamek.common.SmallCraft) AmmoWeapon(megamek.common.weapons.AmmoWeapon) JFrame(javax.swing.JFrame) Infantry(megamek.common.Infantry) LegAttack(megamek.common.weapons.LegAttack) StreakLRMWeapon(megamek.common.weapons.lrms.StreakLRMWeapon) EnergyWeapon(megamek.common.weapons.lasers.EnergyWeapon) Mech(megamek.common.Mech) GaussWeapon(megamek.common.weapons.gaussrifles.GaussWeapon) VTOL(megamek.common.VTOL) ISAPDS(megamek.common.weapons.other.ISAPDS) Protomech(megamek.common.Protomech) WeaponType(megamek.common.WeaponType) MPodWeapon(megamek.common.weapons.defensivepods.MPodWeapon) Tank(megamek.common.Tank) Entity(megamek.common.Entity) ISC3M(megamek.common.weapons.other.ISC3M) HAGWeapon(megamek.common.weapons.gaussrifles.HAGWeapon) LogLevel(megamek.common.logging.LogLevel) ThunderBoltWeapon(megamek.common.weapons.missiles.ThunderBoltWeapon) VehicleFlamerWeapon(megamek.common.weapons.flamers.VehicleFlamerWeapon) ArrayList(java.util.ArrayList) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) EquipmentType(megamek.common.EquipmentType) MegaMekLab(megameklab.com.MegaMekLab) JEditorPane(javax.swing.JEditorPane) JTextPane(javax.swing.JTextPane) ITechManager(megamek.common.ITechManager) TechConstants(megamek.common.TechConstants) TestMech(megamek.common.verifier.TestMech) Nullable(megamek.common.annotations.Nullable) ISC3MBS(megamek.common.weapons.other.ISC3MBS) SwarmAttack(megamek.common.weapons.SwarmAttack) File(java.io.File) JScrollPane(javax.swing.JScrollPane) PPCWeapon(megamek.common.weapons.ppc.PPCWeapon) EntityVerifier(megamek.common.verifier.EntityVerifier) JDialog(javax.swing.JDialog) DecimalFormatSymbols(java.text.DecimalFormatSymbols) Aero(megamek.common.Aero) ISAMS(megamek.common.weapons.other.ISAMS) EntityWeightClass(megamek.common.EntityWeightClass) ISTAG(megamek.common.weapons.tag.ISTAG) ISLaserAMS(megamek.common.weapons.other.ISLaserAMS) ISBALightTAG(megamek.common.weapons.battlearmor.ISBALightTAG) CLLightTAG(megamek.common.weapons.tag.CLLightTAG) TestEntity(megamek.common.verifier.TestEntity) StreakSRMWeapon(megamek.common.weapons.srms.StreakSRMWeapon) Bay(megamek.common.Bay) TestAero(megamek.common.verifier.TestAero) TestBattleArmor(megamek.common.verifier.TestBattleArmor) SwarmWeaponAttack(megamek.common.weapons.SwarmWeaponAttack) CLBALightTAG(megamek.common.weapons.battlearmor.CLBALightTAG) ScrollPaneConstants(javax.swing.ScrollPaneConstants) LocationFullException(megamek.common.LocationFullException) Font(java.awt.Font) MRMWeapon(megamek.common.weapons.missiles.MRMWeapon) TestInfantry(megamek.common.verifier.TestInfantry) BPodWeapon(megamek.common.weapons.defensivepods.BPodWeapon) TestSmallCraft(megamek.common.verifier.TestSmallCraft) Collectors(java.util.stream.Collectors) LBXACWeapon(megamek.common.weapons.autocannons.LBXACWeapon) Dimension(java.awt.Dimension) List(java.util.List) MiscType(megamek.common.MiscType) TripodMech(megamek.common.TripodMech) Optional(java.util.Optional) UACWeapon(megamek.common.weapons.autocannons.UACWeapon) SRMWeapon(megamek.common.weapons.srms.SRMWeapon) CLBALBX(megamek.common.weapons.battlearmor.CLBALBX) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CLChemicalLaserWeapon(megamek.common.weapons.lasers.CLChemicalLaserWeapon) CLTAG(megamek.common.weapons.tag.CLTAG) ISPlasmaRifle(megamek.common.weapons.ppc.ISPlasmaRifle) TestSupportVehicle(megamek.common.verifier.TestSupportVehicle) InfantryRifleAutoRifleWeapon(megamek.common.weapons.infantry.InfantryRifleAutoRifleWeapon) MGWeapon(megamek.common.weapons.mgs.MGWeapon) HashMap(java.util.HashMap) CLAMS(megamek.common.weapons.other.CLAMS) CLLaserAMS(megamek.common.weapons.other.CLLaserAMS) Graphics2D(java.awt.Graphics2D) BipedMech(megamek.common.BipedMech) Mounted(megamek.common.Mounted) MechView(megamek.common.MechView) AmmoType(megamek.common.AmmoType) ITechnology(megamek.common.ITechnology) CLPlasmaCannon(megamek.common.weapons.ppc.CLPlasmaCannon) LRTWeapon(megamek.common.weapons.lrms.LRTWeapon) DecimalFormat(java.text.DecimalFormat) LRMWeapon(megamek.common.weapons.lrms.LRMWeapon) FileInputStream(java.io.FileInputStream) LandAirMech(megamek.common.LandAirMech) JOptionPane(javax.swing.JOptionPane) InfantryWeapon(megamek.common.weapons.infantry.InfantryWeapon) ACWeapon(megamek.common.weapons.autocannons.ACWeapon) MMLogger(megamek.common.logging.MMLogger) DefaultCaret(javax.swing.text.DefaultCaret) QuadMech(megamek.common.QuadMech) InputStream(java.io.InputStream) AmmoType(megamek.common.AmmoType) HashMap(java.util.HashMap) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) MiscType(megamek.common.MiscType) ArrayList(java.util.ArrayList) List(java.util.List) Aero(megamek.common.Aero) TestAero(megamek.common.verifier.TestAero) BattleArmor(megamek.common.BattleArmor) TestBattleArmor(megamek.common.verifier.TestBattleArmor)

Example 19 with Mounted

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

the class UnitUtil method replaceMainWeapon.

public static void replaceMainWeapon(Infantry unit, InfantryWeapon weapon, boolean secondary) {
    Mounted existingInfantryMount = null;
    for (Mounted m : unit.getWeaponList()) {
        if ((m.getType() instanceof InfantryWeapon) && (m.getLocation() == Infantry.LOC_INFANTRY)) {
            existingInfantryMount = m;
            break;
        }
    }
    if (null != existingInfantryMount) {
        UnitUtil.removeMounted(unit, existingInfantryMount);
    }
    if (secondary) {
        unit.setSecondaryWeapon(weapon);
    } else {
        unit.setPrimaryWeapon(weapon);
    }
    // is TAG, in which case both are added.
    if (unit.getSecondaryWeapon() != null && unit.getSecondaryWeapon().hasFlag(WeaponType.F_TAG)) {
        try {
            unit.addEquipment(unit.getPrimaryWeapon(), Infantry.LOC_INFANTRY);
            unit.addEquipment(unit.getSecondaryWeapon(), Infantry.LOC_INFANTRY);
        } catch (LocationFullException ex) {
        }
    } else if ((unit.getSecondaryN() < 2) || (null == unit.getSecondaryWeapon())) {
        try {
            unit.addEquipment(unit.getPrimaryWeapon(), Infantry.LOC_INFANTRY);
        } catch (LocationFullException ex) {
        }
    } else {
        try {
            unit.addEquipment(unit.getSecondaryWeapon(), Infantry.LOC_INFANTRY);
        } catch (LocationFullException ex) {
        }
    }
}
Also used : LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) InfantryWeapon(megamek.common.weapons.infantry.InfantryWeapon)

Example 20 with Mounted

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

the class MovementView method setMovementModToolTips.

private void setMovementModToolTips(Entity en) {
    StringJoiner walkTooltip = new StringJoiner(", ");
    StringJoiner runTooltip = new StringJoiner(", ");
    StringJoiner jumpTooltip = new StringJoiner(", ");
    if (en.hasModularArmor()) {
        walkTooltip.add("-1 (Modular armor)");
        jumpTooltip.add("-1 (Modular armor)");
    }
    if (en instanceof Mech) {
        if (((Mech) en).hasMPReducingHardenedArmor()) {
            runTooltip.add("-1 (Hardened armor)");
        }
        if (((Mech) en).hasArmedMASC()) {
            runTooltip.add("MASC/Supercharger");
        }
        int medShields = ((Mech) en).getNumberOfShields(MiscType.S_SHIELD_MEDIUM);
        int lgShields = ((Mech) en).getNumberOfShields(MiscType.S_SHIELD_LARGE);
        if (lgShields + medShields > 0) {
            walkTooltip.add(String.format("-%d (Shield)", lgShields + medShields));
        }
        if (lgShields > 0) {
            jumpTooltip.add("No Jump (Large Shield)");
        }
    } else if (en.hasWorkingMisc(MiscType.F_MASC)) {
        runTooltip.add("Supercharger");
    } else if (en.hasWorkingMisc(MiscType.F_JET_BOOSTER)) {
        runTooltip.add("Jet Booster");
    }
    Optional<Mounted> partialWing = en.getMisc().stream().filter(m -> m.getType().hasFlag(MiscType.F_PARTIAL_WING)).findAny();
    if (partialWing.isPresent()) {
        int bonus = 2;
        if (en instanceof Mech) {
            bonus = ((Mech) en).getPartialWingJumpBonus(partialWing.get());
        }
        jumpTooltip.add(String.format("+%d (Partial wing)", bonus));
    }
    txtWalkFinal.setToolTipText(walkTooltip.length() > 0 ? walkTooltip.toString() : null);
    txtRunFinal.setToolTipText(runTooltip.length() > 0 ? runTooltip.toString() : null);
    txtJumpFinal.setToolTipText(jumpTooltip.length() > 0 && en.getOriginalJumpMP(true) > 0 ? jumpTooltip.toString() : null);
}
Also used : ActionListener(java.awt.event.ActionListener) JTextField(javax.swing.JTextField) SpinnerNumberModel(javax.swing.SpinnerNumberModel) SwingConstants(javax.swing.SwingConstants) TestEntity(megamek.common.verifier.TestEntity) EquipmentType(megamek.common.EquipmentType) BattleArmor(megamek.common.BattleArmor) ResourceBundle(java.util.ResourceBundle) Mounted(megamek.common.Mounted) ChangeListener(javax.swing.event.ChangeListener) TestBattleArmor(megamek.common.verifier.TestBattleArmor) ITechManager(megamek.common.ITechManager) ChangeEvent(javax.swing.event.ChangeEvent) JSpinner(javax.swing.JSpinner) TechComboBox(megameklab.com.ui.util.TechComboBox) TestMech(megamek.common.verifier.TestMech) Mech(megamek.common.Mech) EntityMovementMode(megamek.common.EntityMovementMode) GridBagConstraints(java.awt.GridBagConstraints) EncodeControl(megamek.common.util.EncodeControl) ActionEvent(java.awt.event.ActionEvent) List(java.util.List) JLabel(javax.swing.JLabel) StringJoiner(java.util.StringJoiner) MiscType(megamek.common.MiscType) Tank(megamek.common.Tank) Optional(java.util.Optional) BuildListener(megameklab.com.ui.view.listeners.BuildListener) GridBagLayout(java.awt.GridBagLayout) Entity(megamek.common.Entity) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Mounted(megamek.common.Mounted) TestMech(megamek.common.verifier.TestMech) Mech(megamek.common.Mech) StringJoiner(java.util.StringJoiner)

Aggregations

Mounted (megamek.common.Mounted)131 MiscType (megamek.common.MiscType)38 LocationFullException (megamek.common.LocationFullException)34 AmmoType (megamek.common.AmmoType)32 CriticalSlot (megamek.common.CriticalSlot)31 EquipmentType (megamek.common.EquipmentType)27 ArrayList (java.util.ArrayList)25 WeaponType (megamek.common.WeaponType)25 Vector (java.util.Vector)21 EntityLoadingException (megamek.common.loaders.EntityLoadingException)17 Font (java.awt.Font)14 BattleArmor (megamek.common.BattleArmor)11 JMenuItem (javax.swing.JMenuItem)9 JPopupMenu (javax.swing.JPopupMenu)9 Entity (megamek.common.Entity)9 TestBattleArmor (megamek.common.verifier.TestBattleArmor)9 Dimension (java.awt.Dimension)8 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)7 List (java.util.List)6