Search in sources :

Example 1 with BayWeapon

use of megamek.common.weapons.bayweapons.BayWeapon in project megameklab by MegaMek.

the class ImageHelperDropShip method printDropshipWeaponsNEquipment.

public static void printDropshipWeaponsNEquipment(Dropship dropship, Graphics2D g2d) {
    int qtyPoint = 26;
    int typePoint = 38;
    int locPoint = 111;
    int heatPoint = 135;
    int shtPoint = 151;
    int medPoint = 169;
    int longPoint = 192;
    int erPoint = 211;
    int nameSize = 65;
    float linePoint = 210f;
    float lineFeed = 6.7f;
    float maxHeight = 140f;
    float stringHeight = 0;
    float fontSize = 7.0f;
    boolean newLineNeeded = false;
    boolean hasCapital = false;
    boolean hasSubCapital = false;
    String[] locAbbr = dropship.isSpheroid() ? LOCATION_ABBRS_SPHEROID : LOCATION_ABBRS_AERODYNE;
    ArrayList<Vector<EquipmentInfo>> equipmentLocations = new ArrayList<Vector<EquipmentInfo>>(locAbbr.length);
    ArrayList<Vector<EquipmentInfo>> capitalEquipmentLocations = new ArrayList<Vector<EquipmentInfo>>(locAbbr.length);
    if (dropship.getMovementMode() == EntityMovementMode.AERODYNE) {
        linePoint = 201;
    }
    for (int pos = 0; pos < locAbbr.length; pos++) {
        equipmentLocations.add(pos, new Vector<EquipmentInfo>());
        capitalEquipmentLocations.add(pos, new Vector<EquipmentInfo>());
    }
    for (Mounted eq : dropship.getWeaponBayList()) {
        if ((eq.isWeaponGroup() || (eq.getType() instanceof AmmoType)) || (eq.getLocation() == Entity.LOC_NONE) || !UnitUtil.isPrintableEquipment(eq.getType())) {
            continue;
        }
        Vector<EquipmentInfo> eqHash = equipmentLocations.get(eq.getLocation());
        Vector<EquipmentInfo> capitalEqHash = capitalEquipmentLocations.get(eq.getLocation());
        String equipmentName = "";
        if (eq.isRearMounted()) {
            switch(eq.getLocation()) {
                case Aero.LOC_LWING:
                    eqHash = equipmentLocations.get(ImageHelperDropShip.LOC_AL);
                    capitalEqHash = capitalEquipmentLocations.get(ImageHelperDropShip.LOC_AL);
                    break;
                case Aero.LOC_RWING:
                    eqHash = equipmentLocations.get(ImageHelperDropShip.LOC_AR);
                    capitalEqHash = capitalEquipmentLocations.get(ImageHelperDropShip.LOC_AR);
                    break;
            }
        }
        if ((eq.getType() instanceof BayWeapon) && ((BayWeapon) eq.getType()).isCapital()) {
            EquipmentInfo eqi = null;
            for (int weaponIndex : eq.getBayWeapons()) {
                Mounted weapon = dropship.getEquipment(weaponIndex);
                if ((eqi == null) || (equipmentName == "") || !equipmentName.equalsIgnoreCase(UnitUtil.getCritName(dropship, weapon.getType())) || (weapon.getType().getTechLevel(dropship.getTechLevelYear()) != eqi.techLevel)) {
                    if (eqi != null) {
                        eqi = new EquipmentInfo(dropship, weapon, eq);
                        equipmentName = eqi.name;
                        eqi.shouldIndent = true;
                        capitalEqHash.add(eqi);
                    } else {
                        eqi = new EquipmentInfo(dropship, weapon, eq);
                        capitalEqHash.add(eqi);
                        equipmentName = eqi.name;
                    }
                } else {
                    eqi.count++;
                }
            }
        } else {
            EquipmentInfo eqi = null;
            for (int weaponIndex : eq.getBayWeapons()) {
                Mounted weapon = dropship.getEquipment(weaponIndex);
                if ((eqi == null) || (equipmentName == "") || !equipmentName.equalsIgnoreCase((UnitUtil.getCritName(dropship, weapon.getType()))) || (weapon.getType().getTechLevel(dropship.getTechLevelYear()) != eqi.techLevel)) {
                    if (eqi != null) {
                        eqi = new EquipmentInfo(dropship, weapon, eq);
                        eqi.shouldIndent = true;
                        eqHash.add(eqi);
                        equipmentName = eqi.name;
                    } else {
                        eqi = new EquipmentInfo(dropship, weapon, eq);
                        eqHash.add(eqi);
                        equipmentName = eqi.name;
                    }
                } else {
                    eqi.count++;
                }
            }
        }
    }
    equipmentLocations.get(ImageHelperDropShip.LOC_FL_FR).addAll(equipmentLocations.get(Aero.LOC_LWING));
    equipmentLocations.get(Aero.LOC_LWING).clear();
    equipmentLocations.get(Aero.LOC_RWING).clear();
    equipmentLocations.get(ImageHelperDropShip.LOC_AL_AR).addAll(equipmentLocations.get(ImageHelperDropShip.LOC_AL));
    equipmentLocations.get(ImageHelperDropShip.LOC_AL).clear();
    equipmentLocations.get(ImageHelperDropShip.LOC_AR).clear();
    capitalEquipmentLocations.get(ImageHelperDropShip.LOC_FL_FR).addAll(capitalEquipmentLocations.get(Aero.LOC_LWING));
    capitalEquipmentLocations.get(Aero.LOC_LWING).clear();
    capitalEquipmentLocations.get(Aero.LOC_RWING).clear();
    capitalEquipmentLocations.get(ImageHelperDropShip.LOC_AL_AR).addAll(capitalEquipmentLocations.get(ImageHelperDropShip.LOC_AL));
    capitalEquipmentLocations.get(ImageHelperDropShip.LOC_AL).clear();
    capitalEquipmentLocations.get(ImageHelperDropShip.LOC_AR).clear();
    Font font = ImageHelperDropShip.getDropShipWeaponsNEquipmentFont(g2d, true, maxHeight, equipmentLocations, capitalEquipmentLocations, fontSize);
    g2d.setFont(font);
    fontSize = font.getSize2D();
    stringHeight = ImageHelper.getStringHeight(g2d, "H", font);
    lineFeed = stringHeight;
    for (int pos = 0; pos < LOCATION_PRINT.length; pos++) {
        Vector<EquipmentInfo> eqHash = capitalEquipmentLocations.get(LOCATION_PRINT[pos]);
        if (eqHash.isEmpty()) {
            continue;
        }
        // damage has to be combined for all stuff in a bay
        for (int i = 0; i < eqHash.size(); i++) {
            EquipmentInfo eqi = eqHash.get(i);
            if (!eqi.shouldIndent) {
                // first, calculate the damage values here, so we can add
                // other
                // weapons in the same bay in the next step
                eqi.heat *= eqi.count;
                if (eqi.shtRange > 0) {
                    eqi.shtRange *= eqi.count;
                }
                if (eqi.medRange > 0) {
                    eqi.medRange *= eqi.count;
                }
                if (eqi.longRange > 0) {
                    eqi.longRange *= eqi.count;
                }
                if (eqi.erRange > 0) {
                    eqi.erRange *= eqi.count;
                }
                // shouldIndent and as such belong in the same bay
                for (int j = i + 1; j < eqHash.size(); j++) {
                    EquipmentInfo eqiBay = eqHash.get(j);
                    if (eqiBay.shouldIndent) {
                        eqi.heat += (eqiBay.heat * eqiBay.count);
                        eqiBay.heat = -1;
                        if (eqiBay.shtRange > 0) {
                            eqi.shtRange += (eqiBay.shtRange * eqiBay.count);
                        }
                        if (eqiBay.medRange > 0) {
                            eqi.medRange += (eqiBay.medRange * eqiBay.count);
                        }
                        if (eqiBay.longRange > 0) {
                            eqi.longRange += (eqiBay.longRange * eqiBay.count);
                        }
                        if (eqiBay.erRange > 0) {
                            eqi.erRange += (eqiBay.erRange * eqiBay.count);
                        }
                        eqiBay.shtRange = -1;
                        eqiBay.medRange = -1;
                        eqiBay.longRange = -1;
                        eqiBay.erRange = -1;
                        i++;
                    } else {
                        break;
                    }
                }
            }
        }
        if (!hasCapital) {
            hasCapital = true;
            g2d.drawString("Capital Scale", typePoint, linePoint);
            font = UnitUtil.getNewFont(g2d, "(1-12) (13-24) (25-40) (41-50)", true, 75, fontSize);
            g2d.setFont(font);
            g2d.drawString("(1-12) (13-24) (25-40) (41-50)", shtPoint, linePoint);
            linePoint += lineFeed;
            font = UnitUtil.getNewFont(g2d, "Bay", true, 68, fontSize);
            g2d.setFont(font);
            g2d.drawString("Bay", typePoint, linePoint);
            g2d.drawString("Loc", locPoint, linePoint);
            g2d.drawString("Ht", heatPoint, linePoint);
            g2d.drawString("SRV", shtPoint, linePoint);
            g2d.drawString("MRV", medPoint, linePoint);
            g2d.drawString("LRV", longPoint, linePoint);
            g2d.drawString("ERV", erPoint, linePoint);
            linePoint += lineFeed;
        }
        for (EquipmentInfo eqi : eqHash) {
            newLineNeeded = false;
            if (eqi.shouldIndent) {
                qtyPoint += 5;
                typePoint += 5;
                nameSize -= 10;
            }
            font = UnitUtil.deriveFont(false, fontSize);
            g2d.setFont(font);
            g2d.drawString(Integer.toString(eqi.count), qtyPoint, linePoint);
            String name = eqi.name.trim();
            if (eqi.hasArtemis) {
                name = name + " w/Artemis IV FCS";
            } else if (eqi.hasArtemisV) {
                name = name + " w/Artemis V FCS";
            } else if (eqi.hasApollo) {
                name = name + " w/Apollo FCS";
            }
            font = UnitUtil.getNewFont(g2d, name, false, nameSize, fontSize);
            g2d.setFont(font);
            if (eqi.c3Level == EquipmentInfo.C3I) {
                ImageHelper.printNavalC3Name(g2d, typePoint, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3EM) {
                ImageHelper.printC3EmName(g2d, typePoint, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3S) {
                ImageHelper.printC3sName(g2d, typePoint, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3M) {
                ImageHelper.printC3mName(g2d, typePoint, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3SB) {
                ImageHelper.printC3sbName(g2d, typePoint, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3MB) {
                ImageHelper.printC3mbName(g2d, typePoint, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3REMOTESENSOR) {
                ImageHelper.printC3RemoteSensorName(g2d, typePoint, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
            } else if (eqi.isMashCore) {
                ImageHelper.printMashCore(g2d, typePoint, linePoint, font, false, dropship);
            } else if (eqi.isDroneControl) {
                ImageHelper.printDroneControl(g2d, typePoint, linePoint, font, false, dropship);
            } else {
                g2d.drawString(name, typePoint, linePoint);
                if ((eqi.damage.trim().length() > 0) && !eqi.isAR10) {
                    g2d.drawString(eqi.damage, typePoint, linePoint + lineFeed);
                    newLineNeeded = true;
                }
            }
            if (eqi.shouldIndent) {
                qtyPoint -= 5;
                typePoint -= 5;
                nameSize += 10;
            }
            String location = locAbbr[LOCATION_PRINT[pos]];
            ImageHelper.printCenterString(g2d, location, font, locPoint + 5, linePoint);
            if ((eqi.heat != -1) && !eqi.isAR10) {
                ImageHelper.printCenterString(g2d, Integer.toString(eqi.heat), font, heatPoint + 4, linePoint);
            }
            font = UnitUtil.deriveFont(Math.min(6f, fontSize));
            g2d.setFont(font);
            if (eqi.isAR10) {
                int ammoLines = StringUtils.countOccurrences(eqi.damage, '[');
                String ammoString = eqi.damage;
                for (int i = 0; i < ammoLines; i++) {
                    String printString = ammoString.substring(0, ammoString.indexOf("]") + 1);
                    ammoString = ammoString.substring(ammoString.indexOf("]") + 1);
                    linePoint += lineFeed;
                    g2d.drawString(printString, typePoint, linePoint);
                    String damage = "";
                    if (printString.indexOf("Barracuda") != -1) {
                        ImageHelper.printCenterString(g2d, Integer.toString(10 * eqi.count), font, heatPoint + 4, linePoint);
                        int baseDam = 2 * eqi.count;
                        int baseDamNormalScale = 20 * eqi.count;
                        if (baseDamNormalScale < 100) {
                            damage = baseDam + " (" + baseDamNormalScale + ")";
                        } else {
                            damage = Integer.toString(baseDam);
                        }
                    } else if (printString.indexOf("White Shark") != -1) {
                        ImageHelper.printCenterString(g2d, Integer.toString(15 * eqi.count), font, heatPoint + 4, linePoint);
                        int baseDam = 3 * eqi.count;
                        int baseDamNormalScale = 30 * eqi.count;
                        if (baseDamNormalScale < 100) {
                            damage = baseDam + " (" + baseDamNormalScale + ")";
                        } else {
                            damage = Integer.toString(baseDam);
                        }
                    } else if (printString.indexOf("Killer Whale") != -1) {
                        ImageHelper.printCenterString(g2d, Integer.toString(20 * eqi.count), font, heatPoint + 4, linePoint);
                        int baseDam = 4 * eqi.count;
                        int baseDamNormalScale = 40 * eqi.count;
                        if (baseDamNormalScale < 100) {
                            damage = baseDam + " (" + baseDamNormalScale + ")";
                        } else {
                            damage = Integer.toString(baseDam);
                        }
                    }
                    g2d.drawString(damage, shtPoint, linePoint);
                    g2d.drawString(damage, medPoint, linePoint);
                    g2d.drawString(damage, longPoint, linePoint);
                    g2d.drawString(damage, erPoint, linePoint);
                }
            } else if (eqi.shtRange > 0) {
                if ((eqi.shtRange * 10) < 100) {
                    g2d.drawString(String.format("%1$d (%2$d)", eqi.shtRange, eqi.shtRange * 10), shtPoint, linePoint);
                } else {
                    g2d.drawString(String.format("%1$d", eqi.shtRange), shtPoint, linePoint);
                }
                if (eqi.medRange > 0) {
                    if ((eqi.medRange * 10) < 100) {
                        g2d.drawString(String.format("%1$d (%2$d)", eqi.medRange, eqi.medRange * 10), medPoint, linePoint);
                    } else {
                        g2d.drawString(String.format("%1$d", eqi.medRange), medPoint, linePoint);
                    }
                } else if (eqi.medRange != -1) {
                    g2d.drawString("\u2014", medPoint, linePoint);
                }
                if (eqi.longRange > 0) {
                    if ((eqi.longRange * 10) < 100) {
                        g2d.drawString(String.format("%1$d (%2$d)", eqi.longRange, eqi.longRange * 10), longPoint, linePoint);
                    } else {
                        g2d.drawString(String.format("%1$d", eqi.longRange), longPoint, linePoint);
                    }
                } else if (eqi.longRange != -1) {
                    g2d.drawString("\u2014", longPoint, linePoint);
                }
                if (eqi.erRange > 0) {
                    if ((eqi.erRange * 10) < 100) {
                        g2d.drawString(String.format("%1$d (%2$d)", eqi.erRange, eqi.erRange * 10), erPoint, linePoint);
                    } else {
                        g2d.drawString(String.format("%1$d", eqi.erRange), erPoint, linePoint);
                    }
                } else if (eqi.erRange != -1) {
                    g2d.drawString("\u2014", erPoint, linePoint);
                }
            } else if (eqi.shtRange != -1) {
                g2d.drawString("\u2014", shtPoint, linePoint);
            } else if (eqi.isAMS) {
                g2d.drawString("Point Defense", medPoint, linePoint);
            }
            linePoint += lineFeed;
            if (newLineNeeded) {
                linePoint += lineFeed;
            }
        }
    }
    g2d.setFont(UnitUtil.deriveFont(true, g2d.getFont().getSize2D()));
    for (int pos = 0; pos < LOCATION_PRINT.length; pos++) {
        Vector<EquipmentInfo> eqHash = equipmentLocations.get(LOCATION_PRINT[pos]);
        if (eqHash.isEmpty()) {
            continue;
        }
        // damage has to be combined for all stuff in a bay
        for (int i = 0; i < eqHash.size(); i++) {
            EquipmentInfo eqi = eqHash.get(i);
            if (!eqi.shouldIndent) {
                // first, calculate the damage values here, so we can add
                // other
                // weapons in the same bay in the next step
                eqi.heat *= eqi.count;
                if (eqi.shtRange > 0) {
                    eqi.shtRange *= eqi.count;
                }
                if (eqi.medRange > 0) {
                    eqi.medRange *= eqi.count;
                }
                if (eqi.longRange > 0) {
                    eqi.longRange *= eqi.count;
                }
                if (eqi.erRange > 0) {
                    eqi.erRange *= eqi.count;
                }
                // shouldIndent and as such belong in the same bay
                for (int j = i + 1; j < eqHash.size(); j++) {
                    EquipmentInfo eqiBay = eqHash.get(j);
                    if (eqiBay.shouldIndent) {
                        eqi.heat += eqiBay.heat * eqiBay.count;
                        eqiBay.heat = -1;
                        if (eqiBay.shtRange > 0) {
                            eqi.shtRange += eqiBay.shtRange * eqiBay.count;
                        }
                        if (eqiBay.medRange > 0) {
                            eqi.medRange += eqiBay.medRange * eqiBay.count;
                        }
                        if (eqiBay.longRange > 0) {
                            eqi.longRange += eqiBay.longRange * eqiBay.count;
                        }
                        if (eqiBay.erRange > 0) {
                            eqi.erRange += eqiBay.erRange * eqiBay.count;
                        }
                        eqiBay.shtRange = -1;
                        eqiBay.medRange = -1;
                        eqiBay.longRange = -1;
                        eqiBay.erRange = -1;
                        i++;
                    } else {
                        break;
                    }
                }
            }
        }
        if (!hasSubCapital) {
            hasSubCapital = true;
            g2d.drawString("Standard Scale", typePoint, linePoint);
            font = UnitUtil.getNewFont(g2d, "(1-6) (7-12) (13-20) (21-25)", true, 75, fontSize);
            g2d.setFont(font);
            g2d.drawString("(1-6) (7-12) (13-20) (21-25)", shtPoint, linePoint);
            linePoint += lineFeed;
            font = UnitUtil.getNewFont(g2d, "Bay", true, 68, fontSize);
            g2d.setFont(font);
            g2d.drawString("Bay", typePoint, linePoint);
            g2d.drawString("Loc", locPoint, linePoint);
            g2d.drawString("Ht", heatPoint, linePoint);
            g2d.drawString("SRV", shtPoint, linePoint);
            g2d.drawString("MRV", medPoint, linePoint);
            g2d.drawString("LRV", longPoint, linePoint);
            g2d.drawString("ERV", erPoint, linePoint);
            linePoint += lineFeed;
        }
        for (EquipmentInfo eqi : eqHash) {
            newLineNeeded = false;
            if (eqi.shouldIndent) {
                qtyPoint += 5;
                typePoint += 5;
                nameSize -= 10;
            }
            font = UnitUtil.deriveFont(false, fontSize);
            g2d.setFont(font);
            g2d.drawString(Integer.toString(eqi.count), qtyPoint, linePoint);
            String name = eqi.name.trim();
            if (eqi.hasArtemis) {
                name = name + " w/Artemis IV FCS";
            } else if (eqi.hasArtemisV) {
                name = name + " w/Artemis V FCS";
            } else if (eqi.hasApollo) {
                name = name + " w/Apollo FCS";
            }
            font = UnitUtil.getNewFont(g2d, name, false, 68, fontSize);
            g2d.setFont(font);
            if (eqi.c3Level == EquipmentInfo.C3I) {
                ImageHelper.printNavalC3Name(g2d, typePoint, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3S) {
                ImageHelper.printC3sName(g2d, typePoint, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3M) {
                ImageHelper.printC3mName(g2d, typePoint, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3SB) {
                ImageHelper.printC3sbName(g2d, typePoint, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3MB) {
                ImageHelper.printC3mbName(g2d, typePoint, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3REMOTESENSOR) {
                ImageHelper.printC3RemoteSensorName(g2d, typePoint, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
            } else {
                g2d.drawString(name, typePoint, linePoint);
                if ((eqi.damage.trim().length() > 0) && !eqi.isMML) {
                    g2d.drawString(eqi.damage, typePoint, linePoint + lineFeed);
                    newLineNeeded = true;
                }
            }
            if (eqi.shouldIndent) {
                qtyPoint -= 5;
                typePoint -= 5;
                nameSize += 10;
            }
            String location = locAbbr[LOCATION_PRINT[pos]];
            ImageHelper.printCenterString(g2d, location, font, locPoint + 5, linePoint);
            if (eqi.heat != -1) {
                ImageHelper.printCenterString(g2d, Integer.toString(eqi.heat), font, heatPoint + 4, linePoint);
            }
            if (eqi.isMML) {
                String lrmAmmoString = eqi.damage.substring(0, eqi.damage.indexOf("]") + 1);
                String srmAmmoString = eqi.damage.substring(eqi.damage.indexOf("]") + 1);
                linePoint += lineFeed;
                g2d.drawString(srmAmmoString, typePoint, linePoint);
                String damage = String.format("%1$d (%2$d)", Math.round((eqi.shtRange * 2) / 10f), eqi.shtRange * 2);
                font = UnitUtil.getNewFont(g2d, damage, false, 17, fontSize);
                g2d.setFont(font);
                g2d.drawString(damage, shtPoint, linePoint);
                font = UnitUtil.deriveFont(false, fontSize);
                g2d.setFont(font);
                g2d.drawString("\u2014", medPoint, linePoint);
                g2d.drawString("\u2014", longPoint, linePoint);
                g2d.drawString("\u2014", erPoint, linePoint);
                linePoint += lineFeed;
                g2d.drawString(lrmAmmoString, typePoint, linePoint);
                damage = String.format("%1$d (%2$d)", Math.round((eqi.shtRange) / 10f), eqi.shtRange);
                font = UnitUtil.getNewFont(g2d, damage, false, 17, fontSize);
                g2d.setFont(font);
                g2d.drawString(damage, shtPoint, linePoint);
                g2d.drawString(damage, medPoint, linePoint);
                g2d.drawString(damage, longPoint, linePoint);
                g2d.drawString("\u2014", erPoint, linePoint);
                font = UnitUtil.deriveFont(false, fontSize);
                g2d.setFont(font);
            } else if (eqi.shtRange > 0) {
                String damage = String.format("%1$d (%2$d)", Math.round((eqi.shtRange) / 10f), eqi.shtRange);
                font = UnitUtil.getNewFont(g2d, damage, false, 17, fontSize);
                g2d.setFont(font);
                g2d.drawString(damage, shtPoint, linePoint);
                font = UnitUtil.deriveFont(fontSize);
                g2d.setFont(font);
            } else if (eqi.shtRange != -1) {
                g2d.drawString("\u2014", shtPoint, linePoint);
            }
            if (eqi.isAMS) {
                g2d.drawString("Point Defense", medPoint, linePoint);
            } else {
                if ((eqi.medRange > 0) && !eqi.isMML) {
                    String damage = String.format("%1$d (%2$d)", Math.round((eqi.medRange) / 10f), eqi.medRange);
                    font = UnitUtil.getNewFont(g2d, damage, false, 17, fontSize);
                    g2d.setFont(font);
                    g2d.drawString(damage, medPoint, linePoint);
                    font = UnitUtil.deriveFont(fontSize);
                    g2d.setFont(font);
                } else if (!eqi.isMML && (eqi.medRange != -1)) {
                    g2d.drawString("\u2014", medPoint, linePoint);
                }
                if ((eqi.longRange > 0) && !eqi.isMML) {
                    String damage = String.format("%1$d (%2$d)", Math.round((eqi.longRange) / 10f), eqi.longRange);
                    font = UnitUtil.getNewFont(g2d, damage, false, 17, fontSize);
                    g2d.setFont(font);
                    g2d.drawString(damage, longPoint, linePoint);
                    font = UnitUtil.deriveFont(fontSize);
                    g2d.setFont(font);
                } else if (!eqi.isMML && (eqi.longRange != -1)) {
                    g2d.drawString("\u2014", longPoint, linePoint);
                }
                if ((eqi.erRange > 0) && !eqi.isMML) {
                    String damage = String.format("%1$d (%2$d)", Math.round((eqi.erRange) / 10f), eqi.erRange);
                    font = UnitUtil.getNewFont(g2d, damage, false, 17, fontSize);
                    g2d.setFont(font);
                    g2d.drawString(damage, erPoint, linePoint);
                    font = UnitUtil.deriveFont(fontSize);
                    g2d.setFont(font);
                } else if (!eqi.isMML && (eqi.erRange != -1)) {
                    g2d.drawString("\u2014", erPoint, linePoint);
                }
            }
            linePoint += lineFeed;
            if (newLineNeeded && !eqi.isMML) {
                linePoint += lineFeed;
            }
        }
    }
    int pointX = 22;
    boolean notesPrinted = false;
    font = UnitUtil.deriveFont(true, g2d.getFont().getSize2D());
    EquipmentInfo eq = null;
    Vector<EquipmentInfo> eqHash = new Vector<EquipmentInfo>();
    for (Mounted mount : dropship.getEquipment()) {
        if ((mount.getLocation() == Entity.LOC_NONE) && UnitUtil.isPrintableEquipment(mount.getType())) {
            eq = new EquipmentInfo(dropship, mount, null);
            eqHash.add(eq);
        }
    }
    for (EquipmentInfo eqi : eqHash) {
        if (!notesPrinted) {
            g2d.setFont(font);
            g2d.drawString("Notes: ", pointX, linePoint);
            linePoint += lineFeed;
            font = UnitUtil.deriveFont(g2d.getFont().getSize2D());
            notesPrinted = true;
            g2d.setFont(font);
        }
        if (eqi.c3Level == EquipmentInfo.C3I) {
            ImageHelper.printNavalC3Name(g2d, pointX, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
        } else if (eqi.c3Level == EquipmentInfo.C3EM) {
            ImageHelper.printC3EmName(g2d, pointX, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
        } else if (eqi.c3Level == EquipmentInfo.C3S) {
            ImageHelper.printC3sName(g2d, pointX, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
        } else if (eqi.c3Level == EquipmentInfo.C3M) {
            ImageHelper.printC3mName(g2d, pointX, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
        } else if (eqi.c3Level == EquipmentInfo.C3SB) {
            ImageHelper.printC3sbName(g2d, pointX, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
        } else if (eqi.c3Level == EquipmentInfo.C3MB) {
            ImageHelper.printC3mbName(g2d, pointX, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
        } else if (eqi.c3Level == EquipmentInfo.C3REMOTESENSOR) {
            ImageHelper.printC3RemoteSensorName(g2d, pointX, linePoint, font, false, dropship.isMixedTech() && TechConstants.isClan(dropship.getTechLevel()));
        } else if (eqi.isMashCore) {
            ImageHelper.printMashCore(g2d, pointX, linePoint, font, false, dropship);
        } else if (eqi.isDroneControl) {
            ImageHelper.printDroneControl(g2d, pointX, linePoint, font, false, dropship);
        } else {
            g2d.drawString(eqi.name, pointX, linePoint);
        }
        linePoint += lineFeed;
    }
    ImageHelperDropShip.printDropShipCargo(dropship, g2d, linePoint);
}
Also used : ArrayList(java.util.ArrayList) BayWeapon(megamek.common.weapons.bayweapons.BayWeapon) Font(java.awt.Font) AmmoType(megamek.common.AmmoType) Mounted(megamek.common.Mounted) Vector(java.util.Vector)

Example 2 with BayWeapon

use of megamek.common.weapons.bayweapons.BayWeapon in project megameklab by MegaMek.

the class AeroBayTransferHandler method importData.

@Override
public boolean importData(TransferSupport support) {
    if (!support.isDrop()) {
        return false;
    }
    // Fields are equipmentNum, node child index, bay child index
    String[] source = null;
    List<Mounted> eqList = new ArrayList<>();
    try {
        source = ((String) support.getTransferable().getTransferData(DataFlavor.stringFlavor)).split(":");
        for (String field : source[0].split(",")) {
            int eqNum = Integer.parseInt(field);
            Mounted m = eSource.getEntity().getEquipment(eqNum);
            if (null != m) {
                eqList.add(m);
            }
        }
    } catch (Exception ex) {
        MegaMekLab.getLogger().log(AeroBayTransferHandler.class, // $NON-NLS-1$
        "importData(TransferSupport)", ex);
        return false;
    }
    if (eqList.isEmpty()) {
        return false;
    }
    if ((support.getComponent() instanceof BayWeaponCriticalTree)) {
        final BayWeaponCriticalTree tree = (BayWeaponCriticalTree) support.getComponent();
        if (eSource.getEntity().usesWeaponBays() && (eqList.size() == 1)) {
            // If it's a bay we move it and its entire contents. Otherwise we find the bay that was
            // dropped on and add it there. A weapon dropped on an illegal bay will create a new one
            // and non-bay equipment will be added at the top level regardless of the drop location.
            // Non-weapon bay equipment cannot be dropped on an illegal bay.
            final Mounted mount = eqList.get(0);
            if (mount.getType() instanceof BayWeapon) {
                tree.addBay(mount);
            } else if ((mount.getType() instanceof AmmoType) && (support.getUserDropAction() == AMMO_SINGLE)) {
                // Default action for ammo is to move a single slot. Holding the ctrl key when dropping
                // will create a AMMO_ALL command, which adds all the ammo of the type.
                tree.addAmmo(mount, ((AmmoType) mount.getType()).getShots(), ((JTree.DropLocation) support.getDropLocation()).getPath());
            } else {
                tree.addToArc(mount, ((JTree.DropLocation) support.getDropLocation()).getPath());
            }
        } else {
            // Small craft don't use bays.
            tree.addToLocation(eqList);
        }
    } else {
        // Target is unallocated bay table.
        for (Mounted mount : eqList) {
            if (mount.getType() instanceof AmmoType) {
                AmmoType at = (AmmoType) mount.getType();
                // Check whether we are moving one of multiple slots.
                if ((support.getUserDropAction() == AMMO_SINGLE) && (mount.getUsableShotsLeft() > at.getShots())) {
                    mount.setShotsLeft(mount.getUsableShotsLeft() - at.getShots());
                }
                Mounted addMount = UnitUtil.findUnallocatedAmmo(eSource.getEntity(), at);
                if (null != addMount) {
                    if (support.getUserDropAction() == AMMO_SINGLE) {
                        addMount.setShotsLeft(addMount.getUsableShotsLeft() + at.getShots());
                    } else {
                        addMount.setShotsLeft(addMount.getUsableShotsLeft() + mount.getUsableShotsLeft());
                    }
                } else {
                    try {
                        Mounted m = eSource.getEntity().addEquipment(at, Entity.LOC_NONE);
                        if (support.getUserDropAction() == AMMO_ALL) {
                            m.setShotsLeft(mount.getUsableShotsLeft());
                        }
                    } catch (LocationFullException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            } else {
                List<Mounted> toRemove;
                if (mount.getType() instanceof BayWeapon) {
                    toRemove = new ArrayList<>();
                    for (Integer num : mount.getBayWeapons()) {
                        toRemove.add(eSource.getEntity().getEquipment(num));
                    }
                    for (Integer num : mount.getBayAmmo()) {
                        toRemove.add(eSource.getEntity().getEquipment(num));
                    }
                } else {
                    toRemove = Collections.singletonList(mount);
                }
                for (Mounted m : toRemove) {
                    if (m.getType() instanceof AmmoType) {
                        Mounted aMount = UnitUtil.findUnallocatedAmmo(eSource.getEntity(), m.getType());
                        if (null != aMount) {
                            aMount.setShotsLeft(aMount.getUsableShotsLeft() + m.getUsableShotsLeft());
                            m.setShotsLeft(0);
                            continue;
                        }
                    }
                    UnitUtil.removeCriticals(eSource.getEntity(), m);
                    UnitUtil.changeMountStatus(eSource.getEntity(), m, Entity.LOC_NONE, Entity.LOC_NONE, false);
                    if ((mount.getType() instanceof WeaponType) && (m.getLinkedBy() != null)) {
                        UnitUtil.removeCriticals(eSource.getEntity(), m.getLinkedBy());
                        UnitUtil.changeMountStatus(eSource.getEntity(), m.getLinkedBy(), Entity.LOC_NONE, Entity.LOC_NONE, false);
                        m.getLinkedBy().setLinked(null);
                        m.setLinkedBy(null);
                    }
                }
                UnitUtil.compactCriticals(eSource.getEntity());
            }
            if (mount.getType() instanceof BayWeapon) {
                mount.getBayWeapons().clear();
                mount.getBayAmmo().clear();
                UnitUtil.removeMounted(eSource.getEntity(), mount);
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) BayWeapon(megamek.common.weapons.bayweapons.BayWeapon) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) LocationFullException(megamek.common.LocationFullException) IOException(java.io.IOException) AmmoType(megamek.common.AmmoType) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType)

Example 3 with BayWeapon

use of megamek.common.weapons.bayweapons.BayWeapon in project megameklab by MegaMek.

the class EquipmentTab method loadEquipmentTable.

private void loadEquipmentTable() {
    // On this table we want to show individual weapons, not bays.
    for (Mounted mount : getAero().getTotalWeaponList()) {
        if ((mount.getType() instanceof BayWeapon) || mount.isWeaponGroup()) {
            continue;
        }
        equipmentList.addCrit(mount);
    }
    for (Mounted mount : getAero().getAmmo()) {
        equipmentList.addCrit(mount);
    }
    List<EquipmentType> spreadAlreadyAdded = new ArrayList<EquipmentType>();
    for (Mounted mount : getAero().getMisc()) {
        EquipmentType etype = mount.getType();
        if (UnitUtil.isHeatSink(mount) || etype.hasFlag(MiscType.F_JUMP_JET) || etype.hasFlag(MiscType.F_JUMP_BOOSTER) || etype.hasFlag(MiscType.F_TSM) || etype.hasFlag(MiscType.F_INDUSTRIAL_TSM) || (etype.hasFlag(MiscType.F_MASC) && !etype.hasSubType(MiscType.S_SUPERCHARGER)) || UnitUtil.isArmorOrStructure(etype)) {
            continue;
        }
        // if (UnitUtil.isUnitEquipment(mount.getType(), unit) || UnitUtil.isUn) {
        if (UnitUtil.isFixedLocationSpreadEquipment(etype) && !spreadAlreadyAdded.contains(etype)) {
            equipmentList.addCrit(mount);
            // keep track of spreadable equipment here, so it doesn't
            // show up multiple times in the table
            spreadAlreadyAdded.add(etype);
        } else {
            equipmentList.addCrit(mount);
        }
    // }
    }
}
Also used : Mounted(megamek.common.Mounted) ArrayList(java.util.ArrayList) BayWeapon(megamek.common.weapons.bayweapons.BayWeapon) EquipmentType(megamek.common.EquipmentType)

Aggregations

ArrayList (java.util.ArrayList)3 Mounted (megamek.common.Mounted)3 BayWeapon (megamek.common.weapons.bayweapons.BayWeapon)3 AmmoType (megamek.common.AmmoType)2 Font (java.awt.Font)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 IOException (java.io.IOException)1 Vector (java.util.Vector)1 EquipmentType (megamek.common.EquipmentType)1 LocationFullException (megamek.common.LocationFullException)1 WeaponType (megamek.common.WeaponType)1