Search in sources :

Example 86 with Mounted

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

the class PMCriticalView method refresh.

public void refresh() {
    mainGunPanel.setVisible(getProtoMek().hasMainGun());
    leftArmPanel.setVisible(!getProtoMek().isQuad());
    rightArmPanel.setVisible(!getProtoMek().isQuad());
    mainGunList.refreshContents();
    torsoList.refreshContents();
    leftList.refreshContents();
    rightList.refreshContents();
    bodyList.refreshContents();
    Map<Integer, List<Mounted>> eqByLocation = getProtoMek().getEquipment().stream().collect(Collectors.groupingBy(Mounted::getLocation));
    for (int location = 0; location < getProtoMek().locations(); location++) {
        int slotsUsed = 0;
        double weightUsed = 0.0;
        if (eqByLocation.containsKey(location)) {
            for (Mounted m : eqByLocation.get(location)) {
                if (TestProtomech.requiresSlot(m.getType())) {
                    slotsUsed++;
                }
                weightUsed += m.getTonnage();
            }
        }
        switch(location) {
            case Protomech.LOC_TORSO:
                torsoSpace.setText("Slots: " + slotsUsed + "/" + TestProtomech.maxSlotsByLocation(location, getProtoMek()));
                torsoWeight.setText(String.format("Weight: %3.0f/%3.0f", weightUsed * 1000, TestProtomech.maxWeightByLocation(location, getProtoMek()) * 1000));
                break;
            case Protomech.LOC_LARM:
                leftSpace.setText("Slots: " + slotsUsed + "/" + TestProtomech.maxSlotsByLocation(location, getProtoMek()));
                leftWeight.setText(String.format("Weight: %3.0f/%3.0f", weightUsed * 1000, TestProtomech.maxWeightByLocation(location, getProtoMek()) * 1000));
                break;
            case Protomech.LOC_RARM:
                rightSpace.setText("Slots: " + slotsUsed + "/" + TestProtomech.maxSlotsByLocation(location, getProtoMek()));
                rightWeight.setText(String.format("Weight: %3.0f/%3.0f", weightUsed * 1000, TestProtomech.maxWeightByLocation(location, getProtoMek()) * 1000));
                break;
            case Protomech.LOC_MAINGUN:
                mainGunSpace.setText("Slots: " + slotsUsed + "/" + TestProtomech.maxSlotsByLocation(location, getProtoMek()));
                break;
        }
    }
}
Also used : Mounted(megamek.common.Mounted) List(java.util.List) ProtomekMountList(megameklab.ui.util.ProtomekMountList)

Example 87 with Mounted

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

the class PMSummaryView method runThroughEquipment.

private void runThroughEquipment() {
    final NumberFormat format = DecimalFormat.getInstance();
    double weightJJ = 0.0f;
    double weightEnhance = 0.0f;
    for (Mounted m : getProtoMek().getMisc()) {
        MiscType mt = (MiscType) m.getType();
        if (UnitUtil.isArmorOrStructure(mt)) {
            continue;
        } else if (mt.hasFlag(MiscType.F_MASC)) {
            weightEnhance += m.getTonnage();
        } else if (mt.hasFlag(MiscType.F_JUMP_JET) || mt.hasFlag(MiscType.F_UMU)) {
            weightJJ += m.getTonnage();
        }
    }
    txtJumpKg.setText(format.format(weightJJ * 1000));
    txtEnhanceKg.setText(format.format(weightEnhance * 1000));
}
Also used : Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) NumberFormat(java.text.NumberFormat)

Example 88 with Mounted

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

the class PMStructureTab method jumpChanged.

@Override
public void jumpChanged(int jumpMP, EquipmentType jumpJet) {
    // Don't set jumpMP for UMU.
    if (null == jumpJet) {
        getProtomech().setOriginalJumpMP(0);
        jumpMP = 0;
    } else if (jumpJet.hasFlag(MiscType.F_JUMP_JET)) {
        getProtomech().setOriginalJumpMP(jumpMP);
    } else {
        getProtomech().setOriginalJumpMP(0);
    }
    List<Mounted> jjs = getProtomech().getMisc().stream().filter(m -> jumpJet.equals(m.getType())).collect(Collectors.toList());
    while (jjs.size() > jumpMP) {
        UnitUtil.removeMounted(getProtomech(), jjs.remove(jjs.size() - 1));
    }
    while (jumpMP > jjs.size()) {
        try {
            UnitUtil.addMounted(getProtomech(), new Mounted(getProtomech(), jumpJet), Protomech.LOC_BODY, false);
        } catch (LocationFullException e) {
        // Shouldn't be able to fill location
        }
        jumpMP--;
    }
    panSummary.refresh();
    refresh.refreshBuild();
    refresh.refreshStatus();
    refresh.refreshPreview();
    panMovement.setFromEntity(getProtomech());
}
Also used : IArmorState(megamek.common.IArmorState) ProtomekBuildListener(megameklab.ui.listeners.ProtomekBuildListener) RefreshListener(megameklab.ui.util.RefreshListener) SwingConstants(javax.swing.SwingConstants) ArrayList(java.util.ArrayList) TestEntity(megamek.common.verifier.TestEntity) EquipmentType(megamek.common.EquipmentType) EntitySource(megameklab.ui.EntitySource) Mounted(megamek.common.Mounted) ITab(megameklab.ui.util.ITab) BorderLayout(java.awt.BorderLayout) ITechManager(megamek.common.ITechManager) BoxLayout(javax.swing.BoxLayout) JComponent(javax.swing.JComponent) ArmorAllocationView(megameklab.ui.generalUnit.ArmorAllocationView) TechConstants(megamek.common.TechConstants) LocationFullException(megamek.common.LocationFullException) BAProtoArmorView(megameklab.ui.generalUnit.BAProtoArmorView) Engine(megamek.common.Engine) BorderFactory(javax.swing.BorderFactory) EntityMovementMode(megamek.common.EntityMovementMode) ProtomechArmor(megamek.common.verifier.TestProtomech.ProtomechArmor) GridBagConstraints(java.awt.GridBagConstraints) JOptionPane(javax.swing.JOptionPane) Collectors(java.util.stream.Collectors) BasicInfoView(megameklab.ui.generalUnit.BasicInfoView) Box(javax.swing.Box) ArmorAllocationListener(megameklab.ui.listeners.ArmorAllocationListener) UnitUtil(megameklab.util.UnitUtil) Protomech(megamek.common.Protomech) Dimension(java.awt.Dimension) List(java.util.List) TestProtomech(megamek.common.verifier.TestProtomech) JLabel(javax.swing.JLabel) SimpleTechLevel(megamek.common.SimpleTechLevel) MiscType(megamek.common.MiscType) Optional(java.util.Optional) MovementView(megameklab.ui.generalUnit.MovementView) GridBagLayout(java.awt.GridBagLayout) Entity(megamek.common.Entity) JPanel(javax.swing.JPanel) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted)

Example 89 with Mounted

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

the class BABuildTab method autoFillCrits.

private void autoFillCrits() {
    // BattleArmor doesn't track crits implicitly, so they need to be tracked explicitly
    BACriticalSuit crits = new BACriticalSuit(getBattleArmor());
    // Populate with equipment that is already installed
    for (Mounted m : getBattleArmor().getEquipment()) {
        if ((m.getLocation() == BattleArmor.LOC_SQUAD) && (m.getBaMountLoc() != BattleArmor.MOUNT_LOC_NONE)) {
            crits.addMounted(m.getBaMountLoc(), m);
        }
    }
    for (Mounted mount : buildView.getTableModel().getCrits()) {
        for (int location = BattleArmor.MOUNT_LOC_BODY; location < BattleArmor.MOUNT_NUM_LOCS; location++) {
            if (!UnitUtil.isValidLocation(getBattleArmor(), mount.getType(), location)) {
                continue;
            }
            // Don't assign change equipment that's already placed
            if (mount.getBaMountLoc() != BattleArmor.MOUNT_LOC_NONE) {
                continue;
            }
            if (crits.canAddMounted(location, mount)) {
                mount.setBaMountLoc(location);
                // Just added for record keeping
                crits.addMounted(location, mount);
                break;
            }
        }
    }
    refreshAll();
}
Also used : Mounted(megamek.common.Mounted)

Example 90 with Mounted

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

the class ASStructureTab method patchworkChanged.

@Override
public void patchworkChanged(int location, EquipmentType armor) {
    UnitUtil.resetArmor(getAero(), location);
    // TODO: move this construction data out of the ui
    int crits = 0;
    switch(EquipmentType.getArmorType(armor)) {
        case EquipmentType.T_ARMOR_STEALTH_VEHICLE:
        case EquipmentType.T_ARMOR_LIGHT_ALUM:
        case EquipmentType.T_ARMOR_ALUM:
        case EquipmentType.T_ARMOR_FERRO_ALUM_PROTO:
        case EquipmentType.T_ARMOR_FERRO_LAMELLOR:
        case EquipmentType.T_ARMOR_REFLECTIVE:
        case EquipmentType.T_ARMOR_REACTIVE:
        case EquipmentType.T_ARMOR_ANTI_PENETRATIVE_ABLATION:
        case EquipmentType.T_ARMOR_BALLISTIC_REINFORCED:
            crits = 1;
            break;
        case EquipmentType.T_ARMOR_HEAVY_ALUM:
            crits = 2;
            break;
    }
    if (getAero().getEmptyCriticals(location) < crits) {
        JOptionPane.showMessageDialog(null, String.format("%s does not fit in location %s. Resetting to Standard Armor in this location.", armor.getName(), getAero().getLocationName(location)), "Error", JOptionPane.INFORMATION_MESSAGE);
    } else {
        getAero().setArmorType(EquipmentType.getArmorType(armor), location);
        getAero().setArmorTechLevel(armor.getTechLevel(getTechManager().getGameYear(), armor.isClan()));
        for (; crits > 0; crits--) {
            try {
                getAero().addEquipment(new Mounted(getAero(), armor), location, false);
            } catch (LocationFullException ignored) {
            }
        }
    }
    panArmor.refresh();
    panArmorAllocation.setFromEntity(getAero());
    refresh.refreshBuild();
    refresh.refreshPreview();
    refresh.refreshSummary();
    refresh.refreshStatus();
}
Also used : LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted)

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