Search in sources :

Example 51 with Mounted

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

the class StructureTab method clearCrit.

/**
 * Removes equipment placed in the given critical slot to clear the space for a system critical
 */
private void clearCrit(int loc, int slotNum) {
    final CriticalSlot crit = getMech().getCritical(loc, slotNum);
    Mounted mounted = null;
    if (crit != null && crit.getType() == CriticalSlot.TYPE_EQUIPMENT) {
        mounted = crit.getMount();
    }
    if (mounted == null) {
        return;
    }
    UnitUtil.removeCriticals(getMech(), mounted);
    if (crit.getMount2() != null) {
        UnitUtil.removeCriticals(getMech(), crit.getMount2());
    }
    // Check linkings after you remove everything.
    try {
        MechFileParser.postLoadInit(getMech());
    } catch (EntityLoadingException ele) {
    // do nothing.
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    if ((crit != null) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
        UnitUtil.changeMountStatus(getMech(), mounted, Entity.LOC_NONE, Entity.LOC_NONE, false);
        if (crit.getMount2() != null) {
            UnitUtil.changeMountStatus(getMech(), crit.getMount2(), Entity.LOC_NONE, Entity.LOC_NONE, false);
        }
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) EntityLoadingException(megamek.common.loaders.EntityLoadingException) LocationFullException(megamek.common.LocationFullException) EntityLoadingException(megamek.common.loaders.EntityLoadingException)

Example 52 with Mounted

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

the class StructureTab method jumpChanged.

@Override
public void jumpChanged(int jumpMP, EquipmentType jumpJet) {
    // Don't set jumpMP for UMU.
    if (null == jumpJet) {
        getMech().setOriginalJumpMP(0);
        jumpMP = 0;
    } else if (jumpJet.hasFlag(MiscType.F_JUMP_JET) || jumpJet.hasFlag(MiscType.F_JUMP_BOOSTER)) {
        getMech().setOriginalJumpMP(jumpMP);
    } else {
        getMech().setOriginalJumpMP(0);
    }
    List<Mounted> jjs = getMech().getMisc().stream().filter(m -> m.getType() == jumpJet).collect(Collectors.toList());
    if (jumpJet.hasFlag(MiscType.F_JUMP_BOOSTER)) {
        if (!getMech().hasWorkingMisc(MiscType.F_JUMP_BOOSTER)) {
            UnitUtil.createSpreadMounts(getMech(), jumpJet);
        }
    } else {
        while (jjs.size() > jumpMP) {
            UnitUtil.removeMounted(getMech(), jjs.remove(jjs.size() - 1));
        }
        while (jumpMP > jjs.size()) {
            try {
                UnitUtil.addMounted(getMech(), new Mounted(getMech(), jumpJet), Entity.LOC_NONE, false);
            } catch (LocationFullException e) {
            // Adding to LOC_NONE
            }
            jumpMP--;
        }
    }
    panSummary.refresh();
    refresh.refreshBuild();
    refresh.refreshStatus();
    refresh.refreshPreview();
    panMovement.setFromEntity(getMech());
}
Also used : MekBuildListener(megameklab.com.ui.view.listeners.MekBuildListener) CriticalSlot(megamek.common.CriticalSlot) EntityLoadingException(megamek.common.loaders.EntityLoadingException) SummaryView(megameklab.com.ui.Mek.views.SummaryView) SwingConstants(javax.swing.SwingConstants) TestEntity(megamek.common.verifier.TestEntity) EquipmentType(megamek.common.EquipmentType) EntitySource(megameklab.com.ui.EntitySource) ArmorAllocationView(megameklab.com.ui.view.ArmorAllocationView) QuadVee(megamek.common.QuadVee) Mounted(megamek.common.Mounted) UnitUtil(megameklab.com.util.UnitUtil) BorderLayout(java.awt.BorderLayout) MVFArmorView(megameklab.com.ui.view.MVFArmorView) MekChassisView(megameklab.com.ui.view.MekChassisView) ITechManager(megamek.common.ITechManager) BoxLayout(javax.swing.BoxLayout) JComponent(javax.swing.JComponent) MechFileParser(megamek.common.MechFileParser) TechConstants(megamek.common.TechConstants) LocationFullException(megamek.common.LocationFullException) Engine(megamek.common.Engine) Mech(megamek.common.Mech) PatchworkArmorView(megameklab.com.ui.view.PatchworkArmorView) BorderFactory(javax.swing.BorderFactory) LandAirMech(megamek.common.LandAirMech) GridBagConstraints(java.awt.GridBagConstraints) JOptionPane(javax.swing.JOptionPane) Collectors(java.util.stream.Collectors) Box(javax.swing.Box) MovementView(megameklab.com.ui.view.MovementView) ITab(megameklab.com.util.ITab) Dimension(java.awt.Dimension) List(java.util.List) HeatSinkView(megameklab.com.ui.view.HeatSinkView) BasicInfoView(megameklab.com.ui.view.BasicInfoView) JLabel(javax.swing.JLabel) SimpleTechLevel(megamek.common.SimpleTechLevel) MiscType(megamek.common.MiscType) Optional(java.util.Optional) GridBagLayout(java.awt.GridBagLayout) Entity(megamek.common.Entity) JPanel(javax.swing.JPanel) RefreshListener(megameklab.com.util.RefreshListener) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted)

Example 53 with Mounted

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

the class BuildView method mousePressed.

public void mousePressed(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON3) {
        JPopupMenu popup = new JPopupMenu();
        JMenuItem item;
        final int selectedRow = equipmentTable.rowAtPoint(e.getPoint());
        Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
        final int totalCrits = UnitUtil.getCritsUsed(getMech(), eq.getType());
        String[] locations = getMech().getLocationNames();
        String[] abbrLocations = getMech().getLocationAbbrs();
        if ((eq.getType().isSpreadable() || eq.isSplitable()) && (totalCrits > 1) && !((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_TARGCOMP)) && !(getMech() instanceof LandAirMech)) {
            int[] critSpace = UnitUtil.getHighestContinuousNumberOfCritsArray(getMech());
            if ((critSpace[Mech.LOC_RT] >= 1) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_RT)) {
                JMenu rtMenu = new JMenu(locations[Mech.LOC_RT]);
                if (critSpace[Mech.LOC_RT] >= totalCrits) {
                    item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_RT]));
                    item.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            jMenuLoadComponent_actionPerformed(Mech.LOC_RT, selectedRow);
                        }
                    });
                    rtMenu.add(item);
                }
                int[] splitLocations = new int[] { Mech.LOC_CT, Mech.LOC_RARM, Mech.LOC_RLEG };
                for (int location = 0; location < 3; location++) {
                    JMenu subMenu = new JMenu(String.format("%1$s/%2$s", abbrLocations[Mech.LOC_RT], abbrLocations[splitLocations[location]]));
                    int subCrits = critSpace[splitLocations[location]];
                    for (int slots = 1; slots <= subCrits; slots++) {
                        final int primarySlots = totalCrits - slots;
                        item = new JMenuItem(String.format("%1$s (%2$s)/%3$s (%4$s)", abbrLocations[Mech.LOC_RT], primarySlots, abbrLocations[splitLocations[location]], slots));
                        final int secondaryLocation = splitLocations[location];
                        item.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                jMenuLoadSplitComponent_actionPerformed(Mech.LOC_RT, secondaryLocation, primarySlots, selectedRow);
                            }
                        });
                        subMenu.add(item);
                    }
                    rtMenu.add(subMenu);
                }
                popup.add(rtMenu);
            }
            if ((critSpace[Mech.LOC_RARM] >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_RARM)) {
                item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_RARM]));
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        jMenuLoadSplitComponent_actionPerformed(Mech.LOC_RARM, Mech.LOC_RARM, totalCrits, selectedRow);
                    }
                });
                popup.add(item);
            }
            if ((critSpace[Mech.LOC_LT] >= 1) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_LT)) {
                JMenu ltMenu = new JMenu(locations[Mech.LOC_LT]);
                if (critSpace[Mech.LOC_LT] >= totalCrits) {
                    item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_LT]));
                    item.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            jMenuLoadComponent_actionPerformed(Mech.LOC_LT, selectedRow);
                        }
                    });
                    ltMenu.add(item);
                }
                int[] splitLocations = new int[] { Mech.LOC_CT, Mech.LOC_LARM, Mech.LOC_LLEG };
                for (int location = 0; location < 3; location++) {
                    JMenu subMenu = new JMenu(String.format("%1$s/%2$s", abbrLocations[Mech.LOC_LT], abbrLocations[splitLocations[location]]));
                    int subCrits = critSpace[splitLocations[location]];
                    for (int slots = 1; slots <= subCrits; slots++) {
                        final int primarySlots = totalCrits - slots;
                        item = new JMenuItem(String.format("%1$s (%2$s)/%3$s (%4$s)", abbrLocations[Mech.LOC_LT], primarySlots, abbrLocations[splitLocations[location]], slots));
                        final int secondaryLocation = splitLocations[location];
                        item.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                jMenuLoadSplitComponent_actionPerformed(Mech.LOC_LT, secondaryLocation, primarySlots, selectedRow);
                            }
                        });
                        subMenu.add(item);
                    }
                    ltMenu.add(subMenu);
                }
                popup.add(ltMenu);
            }
            if ((critSpace[Mech.LOC_LARM] >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_LARM)) {
                item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_LARM]));
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        jMenuLoadSplitComponent_actionPerformed(Mech.LOC_LARM, Mech.LOC_LARM, totalCrits, selectedRow);
                    }
                });
                popup.add(item);
            }
        } else {
            for (int location = 0; location < getMech().locations(); location++) {
                if ((UnitUtil.getHighestContinuousNumberOfCrits(getMech(), location) >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), location)) {
                    item = new JMenuItem("Add to " + locations[location]);
                    final int loc = location;
                    item.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            jMenuLoadComponent_actionPerformed(loc, selectedRow);
                        }
                    });
                    popup.add(item);
                }
            }
        }
        popup.show(this, e.getX(), e.getY());
    }
}
Also used : ActionListener(java.awt.event.ActionListener) Mounted(megamek.common.Mounted) ActionEvent(java.awt.event.ActionEvent) MiscType(megamek.common.MiscType) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu) JMenu(javax.swing.JMenu) LandAirMech(megamek.common.LandAirMech)

Example 54 with Mounted

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

the class BuildView method jMenuLoadSplitComponent_actionPerformed.

private void jMenuLoadSplitComponent_actionPerformed(int location, int secondaryLocation, int primarySlots, int selectedRow) {
    Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
    int crits = UnitUtil.getCritsUsed(getMech(), eq.getType());
    int openSlots = Math.min(primarySlots, UnitUtil.getHighestContinuousNumberOfCrits(getMech(), location));
    eq.setSecondLocation(secondaryLocation);
    for (int slot = 0; slot < openSlots; slot++) {
        try {
            UnitUtil.addMounted(getMech(), eq, location, false);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    crits -= openSlots;
    for (int slot = 0; slot < crits; slot++) {
        try {
            UnitUtil.addMounted(getMech(), eq, secondaryLocation, false);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    UnitUtil.changeMountStatus(getMech(), eq, location, secondaryLocation, false);
    // go back up to grandparent build tab and fire a full refresh.
    ((BuildTab) getParent().getParent()).refreshAll();
}
Also used : BuildTab(megameklab.com.ui.Mek.tabs.BuildTab) Mounted(megamek.common.Mounted)

Example 55 with Mounted

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

the class StatusBar method calculateTotalHeat.

public double calculateTotalHeat() {
    double heat = 0;
    for (Mounted mounted : getAero().getWeaponList()) {
        WeaponType wtype = (WeaponType) mounted.getType();
        double weaponHeat = wtype.getHeat();
        // only count non-damaged equipment
        if (mounted.isMissing() || mounted.isHit() || mounted.isDestroyed() || mounted.isBreached()) {
            continue;
        }
        // one shot weapons count 1/4
        if ((wtype.getAmmoType() == AmmoType.T_ROCKET_LAUNCHER) || wtype.hasFlag(WeaponType.F_ONESHOT)) {
            weaponHeat *= 0.25;
        }
        // double heat for ultras
        if ((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) || (wtype.getAmmoType() == AmmoType.T_AC_ULTRA_THB)) {
            weaponHeat *= 2;
        }
        // Six times heat for RAC
        if (wtype.getAmmoType() == AmmoType.T_AC_ROTARY) {
            weaponHeat *= 6;
        }
        // half heat for streaks
        if ((wtype.getAmmoType() == AmmoType.T_SRM_STREAK) || (wtype.getAmmoType() == AmmoType.T_MRM_STREAK) || (wtype.getAmmoType() == AmmoType.T_LRM_STREAK)) {
            weaponHeat *= 0.5;
        }
        heat += weaponHeat;
    }
    return heat;
}
Also used : Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType)

Aggregations

Mounted (megamek.common.Mounted)162 MiscType (megamek.common.MiscType)50 LocationFullException (megamek.common.LocationFullException)39 AmmoType (megamek.common.AmmoType)36 EquipmentType (megamek.common.EquipmentType)34 CriticalSlot (megamek.common.CriticalSlot)31 ArrayList (java.util.ArrayList)30 WeaponType (megamek.common.WeaponType)29 Vector (java.util.Vector)25 EntityLoadingException (megamek.common.loaders.EntityLoadingException)21 Font (java.awt.Font)14 Entity (megamek.common.Entity)13 List (java.util.List)12 Dimension (java.awt.Dimension)11 JLabel (javax.swing.JLabel)11 JMenuItem (javax.swing.JMenuItem)11 JPopupMenu (javax.swing.JPopupMenu)11 BattleArmor (megamek.common.BattleArmor)11 ActionEvent (java.awt.event.ActionEvent)10 Weapon (megamek.common.weapons.Weapon)10