Search in sources :

Example 6 with Mounted

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

the class ImageHelperVehicle method printVTOLWeaponsNEquipment.

public static void printVTOLWeaponsNEquipment(Tank tank, Graphics2D g2d, float offsetY, float offsetX) {
    float qtyPoint = 26 + offsetX;
    float typePoint = 38 + offsetX;
    float locPoint = 127 + offsetX;
    float damagePoint = 150 + offsetX;
    float minPoint = 166 + offsetX;
    float shtPoint = 177 + offsetX;
    float medPoint = 195 + offsetX;
    float longPoint = 211 + offsetX;
    float maxHeight = 130.3f;
    float linePoint = 202f + offsetY;
    float lineFeed = 6.7f;
    boolean newLineNeeded = false;
    ArrayList<Hashtable<String, EquipmentInfo>> equipmentLocations = new ArrayList<Hashtable<String, EquipmentInfo>>(tank.getLocTurret() + 1);
    for (int pos = 0; pos <= tank.locations(); pos++) {
        equipmentLocations.add(pos, new Hashtable<String, EquipmentInfo>());
    }
    for (Mounted eq : tank.getEquipment()) {
        if ((eq.getType() instanceof AmmoType) || (eq.getLocation() == Entity.LOC_NONE) || !UnitUtil.isPrintableEquipment(eq.getType(), false)) {
            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(tank.getTechLevelYear()) != eqi.techLevel) {
                eqi = new EquipmentInfo(tank, eq);
            } else {
                eqi.count++;
            }
            eqHash.put(equipmentName, eqi);
        } else {
            EquipmentInfo eqi = new EquipmentInfo(tank, eq);
            eqHash.put(equipmentName, eqi);
        }
    }
    if (tank.getTroopCarryingSpace() > 0) {
        maxHeight -= lineFeed;
    }
    if (tank.hasWorkingMisc(MiscType.F_CHASSIS_MODIFICATION)) {
        maxHeight -= lineFeed;
    }
    for (@SuppressWarnings("unused") Bay bay : tank.getTransportBays()) {
        maxHeight -= lineFeed;
    }
    g2d.setFont(UnitUtil.deriveFont(false, 7.0f));
    Font font = ImageHelperVehicle.getVehicleWeaponsNEquipmentFont(g2d, false, maxHeight, equipmentLocations, 7.0f);
    g2d.setFont(font);
    float stringHeight = ImageHelper.getStringHeight(g2d, "H", font);
    lineFeed = stringHeight;
    for (int pos = Tank.LOC_BODY; pos <= tank.locations(); pos++) {
        Hashtable<String, EquipmentInfo> eqHash = equipmentLocations.get(pos);
        if (eqHash.size() < 1) {
            continue;
        }
        ArrayList<EquipmentInfo> equipmentList = new ArrayList<EquipmentInfo>();
        EquipmentInfo artemisEQ = null;
        if (eqHash.containsKey("Artemis IV FCS")) {
            artemisEQ = eqHash.get("Artemis IV FCS");
            artemisEQ.count = 1;
            eqHash.remove("Artemis IV FCS");
        }
        for (EquipmentInfo eqi : eqHash.values()) {
            equipmentList.add(eqi);
        }
        Collections.sort(equipmentList, StringUtils.equipmentInfoComparator());
        for (int eqPos = 0; eqPos < equipmentList.size(); eqPos++) {
            EquipmentInfo eqi = equipmentList.get(eqPos);
            if ((eqi.isMML || (eqi.name.indexOf("LRM") > -1) || (eqi.name.indexOf("SRM") > -1)) && (artemisEQ != null)) {
                equipmentList.add(++eqPos, artemisEQ);
            }
        }
        for (EquipmentInfo eqi : equipmentList) {
            newLineNeeded = false;
            g2d.drawString(Integer.toString(eqi.count), qtyPoint, linePoint);
            String name = eqi.name.trim();
            g2d.setFont(UnitUtil.getNewFont(g2d, name, false, 65, font.getSize2D()));
            if (eqi.c3Level == EquipmentInfo.C3I) {
                ImageHelper.printC3iName(g2d, typePoint, linePoint, font, false, tank.isMixedTech() && TechConstants.isClan(tank.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3EM) {
                ImageHelper.printC3EmName(g2d, typePoint, linePoint, font, false, tank.isMixedTech() && TechConstants.isClan(tank.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3S) {
                ImageHelper.printC3sName(g2d, typePoint, linePoint, font, false, tank.isMixedTech() && TechConstants.isClan(tank.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3M) {
                ImageHelper.printC3mName(g2d, typePoint, linePoint, font, false, tank.isMixedTech() && TechConstants.isClan(tank.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3SB) {
                ImageHelper.printC3sbName(g2d, typePoint, linePoint, font, false, tank.isMixedTech() && TechConstants.isClan(tank.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3MB) {
                ImageHelper.printC3mbName(g2d, typePoint, linePoint, font, false, tank.isMixedTech() && TechConstants.isClan(tank.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3REMOTESENSOR) {
                ImageHelper.printC3RemoteSensorName(g2d, typePoint, linePoint, font, false, tank.isMixedTech() && TechConstants.isClan(tank.getTechLevel()));
            } else if (eqi.isMashCore) {
                ImageHelper.printMashCore(g2d, typePoint, linePoint, font, false, tank);
            } else if (eqi.isDroneControl) {
                ImageHelper.printDroneControl(g2d, typePoint, linePoint, font, false, tank);
            } else {
                g2d.drawString(name, typePoint, linePoint);
            }
            g2d.setFont(font);
            String location = tank.getLocationAbbr(pos);
            g2d.drawString(location, locPoint, linePoint);
            if (eqi.isWeapon) {
                if (eqi.isMML) {
                    ImageHelper.printCenterString(g2d, "[M,S,C]", font, damagePoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("LRM", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "1/Msl", font, damagePoint, linePoint);
                    g2d.drawString("6", minPoint, linePoint);
                    g2d.drawString("7", shtPoint, linePoint);
                    g2d.drawString("14", medPoint, linePoint);
                    g2d.drawString("21", longPoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("SRM", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "2/Msl", font, damagePoint, linePoint);
                    g2d.drawString("\u2014", minPoint, linePoint);
                    // g2d.drawLine(minPoint, (int) linePoint - 2, minPoint + 6, (int) linePoint - 2);
                    g2d.drawString("3", shtPoint, linePoint);
                    g2d.drawString("6", medPoint, linePoint);
                    g2d.drawString("9", longPoint, linePoint);
                } else if (eqi.isATM) {
                    ImageHelper.printCenterString(g2d, "[M,S,C]", font, damagePoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("Standard", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "2/Msl", font, damagePoint, linePoint);
                    g2d.drawString("4", minPoint, linePoint);
                    g2d.drawString("5", shtPoint, linePoint);
                    g2d.drawString("10", medPoint, linePoint);
                    g2d.drawString("15", longPoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("Extended-Range", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "1/Msl", font, damagePoint, linePoint);
                    g2d.drawString("4", minPoint, linePoint);
                    g2d.drawString("9", shtPoint, linePoint);
                    g2d.drawString("18", medPoint, linePoint);
                    g2d.drawString("27", longPoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("High-Explosive", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "3/Msl", font, damagePoint, linePoint);
                    g2d.drawString("\u2014", minPoint, linePoint);
                    // g2d.drawLine(minPoint, (int) linePoint - 2, minPoint + 6, (int) linePoint - 2);
                    g2d.drawString("3", shtPoint, linePoint);
                    g2d.drawString("6", medPoint, linePoint);
                    g2d.drawString("9", longPoint, linePoint);
                } else {
                    if (ImageHelper.getStringWidth(g2d, eqi.damage.trim(), font) > 22) {
                        ImageHelper.printCenterString(g2d, eqi.damage.substring(0, eqi.damage.indexOf('[')), font, damagePoint, linePoint);
                        Font smallFont = UnitUtil.deriveFont(font.getSize2D() - 1.0f);
                        g2d.setFont(smallFont);
                        ImageHelper.printCenterString(g2d, eqi.damage.substring(eqi.damage.indexOf('[')), smallFont, damagePoint, (linePoint + lineFeed) - 1.0f);
                        newLineNeeded = true;
                        g2d.setFont(font);
                    } else {
                        ImageHelper.printCenterString(g2d, eqi.damage, font, damagePoint, linePoint);
                    }
                    if (eqi.minRange > 0) {
                        g2d.drawString(Integer.toString(eqi.minRange), minPoint, linePoint);
                    } else {
                        g2d.drawString("\u2014", minPoint, linePoint);
                    // g2d.drawLine(minPoint, (int) linePoint - 2, minPoint + 6, (int) linePoint - 2);
                    }
                    g2d.drawString(Integer.toString(eqi.shtRange), shtPoint, linePoint);
                    g2d.drawString(Integer.toString(eqi.medRange), medPoint, linePoint);
                    if (eqi.longRange > 0) {
                        g2d.drawString(Integer.toString(eqi.longRange), longPoint, (int) linePoint);
                    } else {
                        g2d.drawString("\u2014", longPoint, linePoint);
                    // g2d.drawLine(longPoint, (int) linePoint - 2, longPoint + 6, (int) linePoint - 2);
                    }
                }
            } else {
                ImageHelper.printCenterString(g2d, eqi.damage, font, damagePoint - 2, linePoint);
                g2d.drawString("\u2014", minPoint, linePoint);
                g2d.drawString("\u2014", shtPoint, linePoint);
                g2d.drawString("\u2014", medPoint, linePoint);
                // g2d.drawLine(medPoint, (int) linePoint - 2, medPoint + 6, (int) linePoint - 2);
                if (eqi.longRange > 0) {
                    g2d.drawString(Integer.toString(eqi.longRange), longPoint, (int) linePoint);
                } else {
                    g2d.drawString("\u2014", longPoint, linePoint);
                // g2d.drawLine(longPoint, (int) linePoint - 2, longPoint + 6, (int) linePoint - 2);
                }
            }
            linePoint += lineFeed;
            if (newLineNeeded) {
                linePoint += lineFeed;
            }
        }
    }
    double troopspace = tank.getTroopCarryingSpace();
    if (troopspace > 0) {
        linePoint += lineFeed;
        String troopString = "Infantry Compartment(";
        if ((troopspace - Math.floor(troopspace)) > 0) {
            troopString += String.valueOf(troopspace);
        } else {
            troopString += String.valueOf((int) troopspace);
        }
        if (troopspace == 1) {
            troopString += " ton)";
        } else {
            troopString += " tons)";
        }
        g2d.drawString(troopString, qtyPoint, linePoint);
    }
    for (Bay bay : tank.getTransportBays()) {
        linePoint += lineFeed;
        g2d.drawString(ImageHelperVehicle.getBayString(bay), qtyPoint, linePoint);
    }
    if (tank.hasWorkingMisc(MiscType.F_CHASSIS_MODIFICATION)) {
        linePoint += lineFeed;
        String chassisMods = "Chassis Modifications: ";
        for (Mounted misc : tank.getMisc()) {
            if (misc.getType().hasFlag(MiscType.F_CHASSIS_MODIFICATION)) {
                chassisMods += misc.getName() + ", ";
            }
        }
        chassisMods = chassisMods.substring(0, chassisMods.length() - 2);
        g2d.drawString(chassisMods, qtyPoint, linePoint);
    }
    ImageHelper.printVehicleAmmo(tank, g2d, (int) offsetY, (int) offsetX);
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Font(java.awt.Font) AmmoType(megamek.common.AmmoType) Mounted(megamek.common.Mounted) Bay(megamek.common.Bay)

Example 7 with Mounted

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

the class CriticalTransferHandler method createTransferable.

@Override
protected Transferable createTransferable(JComponent c) {
    if (c instanceof JTable) {
        JTable table = (JTable) c;
        Mounted mount = (Mounted) ((CriticalTableModel) table.getModel()).getValueAt(table.getSelectedRow(), CriticalTableModel.EQUIPMENT);
        return new StringSelection(Integer.toString(getUnit().getEquipmentNum(mount)));
    } else if (c instanceof DropTargetCriticalList) {
        DropTargetCriticalList<?> list = (DropTargetCriticalList<?>) c;
        Mounted mount = list.getMounted();
        if (mount != null) {
            return new StringSelection(Integer.toString(getUnit().getEquipmentNum(mount)));
        }
    }
    return null;
}
Also used : Mounted(megamek.common.Mounted) JTable(javax.swing.JTable) StringSelection(java.awt.datatransfer.StringSelection)

Example 8 with Mounted

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

the class DropTargetCriticalList method removeCrit.

public void removeCrit() {
    CriticalSlot crit = getCrit();
    Mounted mounted = getMounted();
    if (mounted == null) {
        return;
    }
    // mounted and be done
    if (getUnit() instanceof BattleArmor) {
        changeMountStatus(mounted, BattleArmor.MOUNT_LOC_NONE, false);
        return;
    }
    UnitUtil.removeCriticals(getUnit(), mounted);
    // Check linkings after you remove everything.
    try {
        MechFileParser.postLoadInit(getUnit());
    } catch (EntityLoadingException ele) {
    // do nothing.
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    if ((crit != null) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
        changeMountStatus(mounted, Entity.LOC_NONE, false);
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) EntityLoadingException(megamek.common.loaders.EntityLoadingException) BattleArmor(megamek.common.BattleArmor) TestBattleArmor(megamek.common.verifier.TestBattleArmor) EntityLoadingException(megamek.common.loaders.EntityLoadingException)

Example 9 with Mounted

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

the class DropTargetCriticalList method addArm.

private void addArm(int location) {
    CriticalSlot cs = getUnit().getCritical(location, 2);
    if ((cs != null) && (cs.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
        Mounted mount = cs.getMount();
        UnitUtil.removeCriticals(getUnit(), mount);
        changeMountStatus(mount, Entity.LOC_NONE, false);
    }
    getUnit().setCritical(location, 2, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_LOWER_ARM));
    if (refresh != null) {
        refresh.refreshAll();
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted)

Example 10 with Mounted

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

the class DropTargetCriticalList method addHand.

private void addHand(int location) {
    CriticalSlot cs = getUnit().getCritical(location, 3);
    if (cs != null) {
        Mounted mount = cs.getMount();
        UnitUtil.removeCriticals(getUnit(), mount);
        changeMountStatus(mount, Entity.LOC_NONE, false);
    }
    getUnit().setCritical(location, 3, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, Mech.ACTUATOR_HAND));
    addArm(location);
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted)

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