Search in sources :

Example 11 with Bay

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

the class AerospaceCrewView method setFromEntity.

public void setFromEntity(SmallCraft sc) {
    int minGunners = TestSmallCraft.requiredGunners(sc);
    int minBase = TestSmallCraft.minimumBaseCrew(sc);
    int nonBay = sc.getNCrew() - sc.getBayPersonnel();
    ((SpinnerNumberModel) spnBaseCrew.getModel()).setMinimum(minBase);
    ((SpinnerNumberModel) spnGunners.getModel()).setMinimum(minGunners);
    ignoreChangeEvents = true;
    spnOfficers.setValue(sc.getNOfficers());
    spnBaseCrew.setValue(nonBay - sc.getNGunners());
    spnGunners.setValue(sc.getNGunners());
    lblTotalCrew.setText(String.valueOf(nonBay));
    lblBayPersonnel.setText(String.valueOf(sc.getBayPersonnel()));
    spnPassengers.setValue(sc.getNPassenger());
    spnMarines.setValue(sc.getNMarines());
    if (techManager.isLegal(BattleArmor.getConstructionTechAdvancement(EntityWeightClass.WEIGHT_MEDIUM))) {
        spnBAMarines.setValue(sc.getNBattleArmor());
        lblBAMarines.setVisible(true);
        spnBAMarines.setVisible(true);
    } else {
        spnBAMarines.setValue(0);
        lblBAMarines.setVisible(false);
        spnBAMarines.setVisible(false);
    }
    EnumMap<TestAero.Quarters, Integer> sizes = new EnumMap<>(TestAero.Quarters.class);
    for (Bay bay : sc.getTransportBays()) {
        Quarters q = TestAero.Quarters.getQuartersForBay(bay);
        if (null != q) {
            sizes.merge(q, (int) bay.getCapacity(), Integer::sum);
        }
    }
    spnQuartersFirstClass.setValue(sizes.getOrDefault(TestAero.Quarters.FIRST_CLASS, 0));
    spnQuartersStandard.setValue(sizes.getOrDefault(TestAero.Quarters.STANDARD, 0));
    spnQuartersSecondClass.setValue(sizes.getOrDefault(TestAero.Quarters.SECOND_CLASS, 0));
    spnQuartersSteerage.setValue(sizes.getOrDefault(TestAero.Quarters.STEERAGE, 0));
    spnLifeBoats.setValue(sc.getLifeBoats());
    spnEscapePods.setValue(sc.getEscapePods());
    ignoreChangeEvents = false;
    // If we do not meet the minimum, set the values and trigger an event that will update the vessel.
    if (sc.getNGunners() < minGunners) {
        spnGunners.setValue(minGunners);
    }
    if (nonBay - sc.getNGunners() < minBase) {
        spnBaseCrew.setValue(minBase);
    }
}
Also used : SpinnerNumberModel(javax.swing.SpinnerNumberModel) TestAero(megamek.common.verifier.TestAero) Bay(megamek.common.Bay) Quarters(megamek.common.verifier.TestAero.Quarters) EnumMap(java.util.EnumMap)

Example 12 with Bay

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

the class CVTransportView method setFromEntity.

public void setFromEntity(Tank tank) {
    double troops = tank.getTroopCarryingSpace();
    double podTroops = tank.getPodMountedTroopCarryingSpace();
    spnFixedTroop.setValue(troops - podTroops);
    spnPodTroop.setValue(podTroops);
    Map<BayData, Double> fixedCargo = new HashMap<>();
    Map<BayData, Double> podCargo = new HashMap<>();
    for (Bay b : tank.getTransportBays()) {
        BayData bayType = BayData.getBayType(b);
        if (null != bayType) {
            if (tank.isPodMountedTransport(b)) {
                podCargo.merge(bayType, b.getCapacity(), Double::sum);
            } else {
                fixedCargo.merge(bayType, b.getCapacity(), Double::sum);
            }
        }
    }
    for (Map.Entry<BayData, JSpinner> entry : fixedSpinners.entrySet()) {
        entry.getValue().setValue(fixedCargo.getOrDefault(entry.getKey(), 0.0));
    }
    for (Map.Entry<BayData, JSpinner> entry : podSpinners.entrySet()) {
        entry.getValue().setValue(podCargo.getOrDefault(entry.getKey(), 0.0));
    }
    setOmni(tank.isOmni());
}
Also used : HashMap(java.util.HashMap) JSpinner(javax.swing.JSpinner) Bay(megamek.common.Bay) HashMap(java.util.HashMap) Map(java.util.Map) BayData(megamek.common.verifier.BayData)

Example 13 with Bay

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

the class ImageHelperAero method printAeroWeaponsNEquipment.

public static void printAeroWeaponsNEquipment(Aero aero, Graphics2D g2d) {
    int pointShift = 0;
    if ((aero instanceof SmallCraft) && aero.isSpheroid()) {
        pointShift = 11;
    }
    int qtyPoint = 30;
    int typePoint = 42;
    int locPoint = 112 + pointShift;
    int heatPoint = 130 + pointShift;
    int shtPoint = 147 + pointShift;
    int medPoint = 170 + pointShift;
    int longPoint = 190 + pointShift;
    int erPoint = 210 + pointShift;
    float linePoint = 204f;
    float maxHeight = 97.0f;
    float lineFeed = 6.7f;
    boolean newLineNeeded = false;
    ArrayList<Hashtable<String, EquipmentInfo>> equipmentLocations = new ArrayList<Hashtable<String, EquipmentInfo>>(aero.locations());
    for (int pos = 0; pos <= aero.locations(); pos++) {
        equipmentLocations.add(pos, new Hashtable<String, EquipmentInfo>());
    }
    for (Mounted eq : aero.getEquipment()) {
        if ((eq.isWeaponGroup() || (eq.getType() instanceof AmmoType)) || (eq.getLocation() == Entity.LOC_NONE) || !UnitUtil.isPrintableEquipment(eq.getType())) {
            continue;
        }
        Hashtable<String, EquipmentInfo> eqHash = equipmentLocations.get(eq.getLocation());
        String equipmentName = eq.getName();
        if (eq.isRearMounted()) {
            equipmentName += "(R)";
        }
        if (eqHash.containsKey(equipmentName)) {
            EquipmentInfo eqi = eqHash.get(equipmentName);
            if (eq.getType().getTechLevel(aero.getTechLevelYear()) != eqi.techLevel) {
                eqi = new EquipmentInfo(aero, eq);
            } else {
                eqi.count++;
            }
            eqHash.put(equipmentName, eqi);
        } else {
            EquipmentInfo eqi = new EquipmentInfo(aero, eq);
            eqHash.put(equipmentName, eqi);
        }
    }
    if (aero.getTroopCarryingSpace() > 0) {
        maxHeight -= lineFeed;
    }
    if (aero.hasWorkingMisc(MiscType.F_CHASSIS_MODIFICATION)) {
        maxHeight -= lineFeed;
    }
    if (aero.getCockpitType() != Aero.COCKPIT_STANDARD) {
        maxHeight -= lineFeed;
    }
    for (@SuppressWarnings("unused") Bay bay : aero.getTransportBays()) {
        maxHeight -= lineFeed;
    }
    if (aero.getAmmo().size() > 0) {
        maxHeight -= lineFeed;
    }
    g2d.setFont(UnitUtil.deriveFont(false, 7.0f));
    Font font = ImageHelperAero.getAeroWeaponsNEquipmentFont(g2d, false, maxHeight, equipmentLocations, 7.0f);
    g2d.setFont(font);
    float stringHeight = ImageHelper.getStringHeight(g2d, "H", font);
    lineFeed = stringHeight;
    for (int pos = Aero.LOC_NOSE; pos <= aero.locations(); pos++) {
        Hashtable<String, EquipmentInfo> eqHash = equipmentLocations.get(pos);
        if (eqHash.size() < 1) {
            continue;
        }
        ArrayList<EquipmentInfo> equipmentList = new ArrayList<EquipmentInfo>();
        for (EquipmentInfo eqi : eqHash.values()) {
            equipmentList.add(eqi);
        }
        Collections.sort(equipmentList, StringUtils.equipmentInfoComparator());
        for (EquipmentInfo eqi : equipmentList) {
            newLineNeeded = false;
            g2d.setFont(font);
            g2d.drawString(Integer.toString(eqi.count), qtyPoint, linePoint);
            String name = eqi.name.trim() + " " + eqi.damage.trim();
            if (eqi.c3Level == EquipmentInfo.C3I) {
                ImageHelper.printC3iName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3EM) {
                ImageHelper.printC3EmName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3S) {
                ImageHelper.printC3sName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3M) {
                ImageHelper.printC3mName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3SB) {
                ImageHelper.printC3sbName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3MB) {
                ImageHelper.printC3mbName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3REMOTESENSOR) {
                ImageHelper.printC3RemoteSensorName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
            } else if (eqi.isMashCore) {
                ImageHelper.printMashCore(g2d, typePoint, linePoint, font, false, aero);
            } else if (eqi.isDroneControl) {
                ImageHelper.printDroneControl(g2d, typePoint, linePoint, font, false, aero);
            } else {
                if (ImageHelper.getStringWidth(g2d, name, font) > 65) {
                    // g2d.setFont(UnitUtil.getNewFont(g2d, eqi.name.trim(),
                    // false, 65, font.getSize2D()));
                    g2d.drawString(eqi.name.trim(), typePoint, linePoint);
                    linePoint += lineFeed;
                    g2d.drawString(eqi.damage.trim(), typePoint, linePoint);
                } else {
                    g2d.drawString(name, typePoint, linePoint);
                }
            }
            g2d.setFont(font);
            String location = ImageHelperAero.getLocationAbbrs(pos);
            if ((aero instanceof SmallCraft) && (aero.getMovementMode() == EntityMovementMode.SPHEROID)) {
                location = ImageHelperAero.getLocationAbbrsSmallCraft(pos);
            }
            g2d.drawString(location, locPoint, linePoint);
            ImageHelper.printCenterString(g2d, Integer.toString(eqi.heat), font, heatPoint, linePoint);
            if (eqi.isMML) {
                linePoint += lineFeed;
                g2d.drawString("SRM Ammo", typePoint, linePoint);
                g2d.drawString(Integer.toString(eqi.shtRange * 2), shtPoint, (int) linePoint);
                g2d.drawString("\u2014", medPoint, linePoint);
                g2d.drawString("\u2014", longPoint, linePoint);
                g2d.drawString("\u2014", erPoint, linePoint);
                // g2d.drawLine(medPoint, (int) linePoint - 2, medPoint + 6, (int) linePoint - 2);
                // g2d.drawLine(longPoint, (int) linePoint - 2, longPoint + 6, (int) linePoint - 2);
                // g2d.drawLine(erPoint, (int) linePoint - 2, erPoint + 6, (int) linePoint - 2);
                linePoint += lineFeed;
                g2d.drawString("LRM Ammo", typePoint, linePoint);
                g2d.drawString(Integer.toString(eqi.shtRange), shtPoint, (int) linePoint);
                g2d.drawString(Integer.toString(eqi.medRange), medPoint, (int) linePoint);
                g2d.drawString(Integer.toString(eqi.longRange), longPoint, (int) linePoint);
                g2d.drawString("\u2014", erPoint, linePoint);
            // g2d.drawLine(erPoint, (int) linePoint - 2, erPoint + 6, (int) linePoint - 2);
            } else if (eqi.shtRange > 0) {
                g2d.drawString(Integer.toString(eqi.shtRange), shtPoint, (int) linePoint);
            } else {
                g2d.drawString("\u2014", shtPoint, linePoint);
            // g2d.drawLine(shtPoint, (int) linePoint - 2, shtPoint + 6, (int) linePoint - 2);
            }
            if ((eqi.medRange > 0) && !eqi.isMML) {
                g2d.drawString(Integer.toString(eqi.medRange), medPoint, (int) linePoint);
            } else if (!eqi.isMML) {
                g2d.drawString("\u2014", medPoint, linePoint);
            // g2d.drawLine(medPoint, (int) linePoint - 2, medPoint + 6, (int) linePoint - 2);
            }
            if ((eqi.longRange > 0) && !eqi.isMML) {
                g2d.drawString(Integer.toString(eqi.longRange), longPoint, (int) linePoint);
            } else if (!eqi.isMML) {
                g2d.drawString("\u2014", longPoint, linePoint);
            // g2d.drawLine(longPoint, (int) linePoint - 2, longPoint + 6, (int) linePoint - 2);
            }
            if ((eqi.erRange > 0) && !eqi.isMML) {
                g2d.drawString(Integer.toString(eqi.erRange), erPoint, (int) linePoint);
            } else if (!eqi.isMML) {
                g2d.drawString("\u2014", erPoint, linePoint);
            // g2d.drawLine(erPoint, (int) linePoint - 2, erPoint + 6, (int) linePoint - 2);
            }
            if (eqi.hasArtemis) {
                g2d.drawString("w/Artemis IV FCS", typePoint, linePoint + lineFeed);
                newLineNeeded = true;
            } else if (eqi.hasArtemisV) {
                g2d.drawString("w/Artemis V FCS", typePoint, linePoint + lineFeed);
                newLineNeeded = true;
            } else if (eqi.hasApollo) {
                g2d.drawString("w/Apollo FCS", typePoint, linePoint + lineFeed);
                newLineNeeded = true;
            }
            linePoint += lineFeed;
            if (newLineNeeded) {
                linePoint += lineFeed;
            }
        }
    }
    if (aero.getCockpitType() != Aero.COCKPIT_STANDARD) {
        g2d.drawString(aero.getCockpitTypeString(), 22, linePoint);
        linePoint += lineFeed;
    }
    if (aero instanceof FixedWingSupport) {
        ImageHelperAero.printFixedWingSupportCargoChassisMod((FixedWingSupport) aero, g2d, (int) linePoint);
    } else {
        ImageHelperAero.printCargo(aero, g2d, (int) linePoint);
    }
    ImageHelper.printVehicleAmmo(aero, g2d, -20, 8);
    ImageHelperAero.printAeroFuel(aero, g2d, 8);
}
Also used : FixedWingSupport(megamek.common.FixedWingSupport) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Font(java.awt.Font) SmallCraft(megamek.common.SmallCraft) AmmoType(megamek.common.AmmoType) Mounted(megamek.common.Mounted) Bay(megamek.common.Bay)

Example 14 with Bay

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

the class TransportTab method rebuildBays.

/**
 * Removing bays can cause undesirable gaps in bay numbers, and it would be nice to let the
 * user order the bays. Since bay numbers are immutable we have to instantiate a new bay to
 * alter it.
 */
private void rebuildBays() {
    int bayNum = 1;
    List<Bay> newBayList = new ArrayList<>();
    for (Iterator<Bay> iter = modelInstalled.getBays(); iter.hasNext(); ) {
        final Bay bay = iter.next();
        if (bay.getBayNumber() == bayNum) {
            newBayList.add(bay);
        } else {
            BayData bayType = BayData.getBayType(bay);
            Bay newBay = bayType.newBay(bay.getCapacity(), bayNum);
            newBay.setDoors(bay.getDoors());
            newBayList.add(newBay);
        }
        bayNum++;
    }
    for (Bay bay : getAero().getTransportBays()) {
        if (bay.isQuarters()) {
            newBayList.add(bay);
        }
    }
    getAero().removeAllTransporters();
    newBayList.forEach(b -> getAero().addTransporter(b));
    modelInstalled.refreshBays();
}
Also used : ArrayList(java.util.ArrayList) Bay(megamek.common.Bay) InfantryBay(megamek.common.InfantryBay) BayData(megamek.common.verifier.BayData)

Aggregations

Bay (megamek.common.Bay)14 Font (java.awt.Font)8 ArrayList (java.util.ArrayList)8 AmmoType (megamek.common.AmmoType)5 Mounted (megamek.common.Mounted)5 Hashtable (java.util.Hashtable)4 HashMap (java.util.HashMap)3 TestAero (megamek.common.verifier.TestAero)3 EnumMap (java.util.EnumMap)2 List (java.util.List)2 Map (java.util.Map)2 BayData (megamek.common.verifier.BayData)2 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 DecimalFormat (java.text.DecimalFormat)1 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1