Search in sources :

Example 1 with TestBattleArmor

use of megamek.common.verifier.TestBattleArmor in project megameklab by MegaMek.

the class CriticalView method refresh.

public void refresh() {
    critSuit = new CriticalSuit(getBattleArmor());
    leftPanel.removeAll();
    rightPanel.removeAll();
    bodyPanel.removeAll();
    turretPanel.removeAll();
    int[] numAPWeapons = new int[BattleArmor.MOUNT_NUM_LOCS];
    int[] numAMWeapons = new int[BattleArmor.MOUNT_NUM_LOCS];
    for (Mounted m : getBattleArmor().getEquipment()) {
        if (m.getLocation() == BattleArmor.LOC_SQUAD || m.getLocation() == trooper) {
            critSuit.addMounted(m.getBaMountLoc(), m);
            // Weapons mounted in a quad turret count against the body limits
            int useLoc = m.getBaMountLoc();
            if (useLoc == BattleArmor.MOUNT_LOC_TURRET) {
                useLoc = BattleArmor.MOUNT_LOC_BODY;
            }
            if (useLoc != BattleArmor.MOUNT_LOC_NONE) {
                if ((m.getType() instanceof WeaponType) && !(m.getType() instanceof InfantryWeapon)) {
                    numAMWeapons[useLoc]++;
                }
                if (m.getType().hasFlag(MiscType.F_AP_MOUNT)) {
                    numAPWeapons[useLoc]++;
                }
            }
        }
    }
    synchronized (getBattleArmor()) {
        for (int location = 0; location < critSuit.locations(); location++) {
            Vector<String> critNames = new Vector<String>(1, 1);
            for (int slot = 0; slot < critSuit.getNumCriticals(location); slot++) {
                CriticalSlot cs = critSuit.getCritical(location, slot);
                if (cs == null) {
                    if (showEmpty) {
                        critNames.add(MtfFile.EMPTY);
                    }
                    continue;
                } else if (cs.getType() == CriticalSlot.TYPE_SYSTEM) {
                    // BattleArmor shouldn't have system type crits
                    continue;
                } else if (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) {
                    try {
                        Mounted m = cs.getMount();
                        // Critical didn't get removed. Remove it now.
                        if (m == null) {
                            if (showEmpty) {
                                critNames.add(MtfFile.EMPTY);
                            }
                            continue;
                        }
                        StringBuffer critName = new StringBuffer(m.getName());
                        critName.append(":" + slot + ":" + getBattleArmor().getEquipmentNum(m));
                        critNames.add(critName.toString());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
            DropTargetCriticalList<String> criticalSlotList = null;
            criticalSlotList = new DropTargetCriticalList<String>(critNames, eSource, refresh, showEmpty);
            criticalSlotList.setAlignmentX(JLabel.CENTER_ALIGNMENT);
            criticalSlotList.setVisibleRowCount(critNames.size());
            criticalSlotList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            criticalSlotList.setFont(new Font("Arial", Font.PLAIN, 10));
            criticalSlotList.setName(location + ":" + trooper);
            criticalSlotList.setBorder(BorderFactory.createEtchedBorder(Color.WHITE.brighter(), Color.BLACK.darker()));
            switch(location) {
                case BattleArmor.MOUNT_LOC_LARM:
                    leftPanel.add(criticalSlotList);
                    break;
                case BattleArmor.MOUNT_LOC_RARM:
                    rightPanel.add(criticalSlotList);
                    break;
                case BattleArmor.MOUNT_LOC_BODY:
                    bodyPanel.add(criticalSlotList);
                    break;
                case BattleArmor.MOUNT_LOC_TURRET:
                    turretPanel.add(criticalSlotList);
                    break;
            }
        }
        String[] amTxt = new String[BattleArmor.MOUNT_NUM_LOCS];
        String[] apTxt = new String[BattleArmor.MOUNT_NUM_LOCS];
        for (int loc = 0; loc < BattleArmor.MOUNT_NUM_LOCS; loc++) {
            amTxt[loc] = "AM Wpn: " + numAMWeapons[loc] + "/" + getBattleArmor().getNumAllowedAntiMechWeapons(loc);
            apTxt[loc] = "AP Wpn: " + numAPWeapons[loc] + "/" + getBattleArmor().getNumAllowedAntiPersonnelWeapons(loc, trooper);
            if (numAMWeapons[loc] > getBattleArmor().getNumAllowedAntiMechWeapons(loc)) {
                amTxt[loc] = "<html><font color='C00000'>" + amTxt[loc] + "</font></html>";
            }
            if (numAPWeapons[loc] > getBattleArmor().getNumAllowedAntiMechWeapons(loc)) {
                apTxt[loc] = "<html><font color='C00000'>" + apTxt[loc] + "</font></html>";
            }
        }
        leftPanel.add(makeLabel(amTxt[BattleArmor.MOUNT_LOC_LARM], lblSz));
        leftPanel.add(makeLabel(apTxt[BattleArmor.MOUNT_LOC_LARM], lblSz));
        rightPanel.add(makeLabel(amTxt[BattleArmor.MOUNT_LOC_RARM], lblSz));
        rightPanel.add(makeLabel(apTxt[BattleArmor.MOUNT_LOC_RARM], lblSz));
        bodyPanel.add(makeLabel(amTxt[BattleArmor.MOUNT_LOC_BODY], lblSz));
        bodyPanel.add(makeLabel(apTxt[BattleArmor.MOUNT_LOC_BODY], lblSz));
        // Hide the arm panels if we are a quad
        if (getBattleArmor().getChassisType() == BattleArmor.CHASSIS_TYPE_QUAD) {
            leftPanel.setVisible(false);
            rightPanel.setVisible(false);
            turretPanel.setVisible(getBattleArmor().getTurretCapacity() > 0);
        } else {
            leftPanel.setVisible(true);
            rightPanel.setVisible(true);
            turretPanel.setVisible(false);
        }
        EntityVerifier entityVerifier = EntityVerifier.getInstance(new File("data/mechfiles/UnitVerifierOptions.xml"));
        TestBattleArmor testBA = new TestBattleArmor(getBattleArmor(), entityVerifier.baOption, null);
        String weightTxt = "Weight: " + String.format("%1$.3f", testBA.calculateWeight(trooper)) + "/" + getBattleArmor().getTrooperWeight();
        if (testBA.calculateWeight(trooper) > getBattleArmor().getTrooperWeight()) {
            weightTxt = "<html><font color='C00000'>" + weightTxt + "</font></html>";
        }
        weightLabel.setText(weightTxt);
        leftPanel.add(Box.createVerticalStrut(8));
        rightPanel.add(Box.createVerticalStrut(8));
        bodyPanel.add(Box.createVerticalStrut(8));
        turretPanel.add(Box.createVerticalStrut(8));
        leftPanel.invalidate();
        leftPanel.invalidate();
        rightPanel.invalidate();
        turretPanel.invalidate();
        bodyPanel.repaint();
        leftPanel.repaint();
        rightPanel.repaint();
        turretPanel.repaint();
    }
}
Also used : EntityVerifier(megamek.common.verifier.EntityVerifier) CriticalSlot(megamek.common.CriticalSlot) TestBattleArmor(megamek.common.verifier.TestBattleArmor) Font(java.awt.Font) Mounted(megamek.common.Mounted) CriticalSuit(megameklab.com.ui.BattleArmor.CriticalSuit) WeaponType(megamek.common.WeaponType) Vector(java.util.Vector) MtfFile(megamek.common.loaders.MtfFile) File(java.io.File) InfantryWeapon(megamek.common.weapons.infantry.InfantryWeapon)

Example 2 with TestBattleArmor

use of megamek.common.verifier.TestBattleArmor in project megameklab by MegaMek.

the class UnitUtil method getEntityVerifier.

/**
 * Returns a TestEntity instance for the supplied Entity.
 *
 * @param unit
 * @return
 */
public static TestEntity getEntityVerifier(Entity unit) {
    EntityVerifier entityVerifier = EntityVerifier.getInstance(new File("data/mechfiles/UnitVerifierOptions.xml"));
    TestEntity testEntity = null;
    if (unit.hasETypeFlag(Entity.ETYPE_MECH)) {
        testEntity = new TestMech((Mech) unit, entityVerifier.mechOption, null);
    } else if (unit.hasETypeFlag(Entity.ETYPE_SUPPORT_TANK)) {
        testEntity = new TestSupportVehicle((Tank) unit, entityVerifier.tankOption, null);
    } else if (unit.hasETypeFlag(Entity.ETYPE_TANK)) {
        testEntity = new TestTank((Tank) unit, entityVerifier.tankOption, null);
    } else if (unit.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) {
        testEntity = new TestSmallCraft((SmallCraft) unit, entityVerifier.aeroOption, null);
    } else if (unit.hasETypeFlag(Entity.ETYPE_AERO)) {
        testEntity = new TestAero((Aero) unit, entityVerifier.aeroOption, null);
    } else if (unit.hasETypeFlag(Entity.ETYPE_BATTLEARMOR)) {
        testEntity = new TestBattleArmor((BattleArmor) unit, entityVerifier.baOption, null);
    } else if (unit.hasETypeFlag(Entity.ETYPE_INFANTRY)) {
        testEntity = new TestInfantry((Infantry) unit, entityVerifier.infOption, null);
    }
    return testEntity;
}
Also used : TestEntity(megamek.common.verifier.TestEntity) EntityVerifier(megamek.common.verifier.EntityVerifier) TestTank(megamek.common.verifier.TestTank) TestAero(megamek.common.verifier.TestAero) TestBattleArmor(megamek.common.verifier.TestBattleArmor) TestTank(megamek.common.verifier.TestTank) Tank(megamek.common.Tank) Infantry(megamek.common.Infantry) TestInfantry(megamek.common.verifier.TestInfantry) TestMech(megamek.common.verifier.TestMech) TestSupportVehicle(megamek.common.verifier.TestSupportVehicle) TestSmallCraft(megamek.common.verifier.TestSmallCraft) Mech(megamek.common.Mech) TestMech(megamek.common.verifier.TestMech) TripodMech(megamek.common.TripodMech) BipedMech(megamek.common.BipedMech) LandAirMech(megamek.common.LandAirMech) QuadMech(megamek.common.QuadMech) File(java.io.File) Aero(megamek.common.Aero) TestAero(megamek.common.verifier.TestAero) TestInfantry(megamek.common.verifier.TestInfantry)

Example 3 with TestBattleArmor

use of megamek.common.verifier.TestBattleArmor in project megameklab by MegaMek.

the class StatusBar method refresh.

public void refresh() {
    int walk = getBattleArmor().getOriginalWalkMP();
    int jump = getBattleArmor().getOriginalJumpMP();
    double maxKilos = getBattleArmor().getTrooperWeight();
    double currentKilos;
    int bv = getBattleArmor().calculateBattleValue();
    long currentCost = (long) Math.round(getBattleArmor().getCost(false));
    testBA = new TestBattleArmor(getBattleArmor(), entityVerifier.baOption, null);
    currentKilos = testBA.calculateWeight(BattleArmor.LOC_SQUAD);
    currentKilos += UnitUtil.getUnallocatedAmmoTonnage(getBattleArmor());
    tons.setText("Suit Weight: " + String.format("%1$.3f", currentKilos) + "/" + maxKilos);
    tons.setToolTipText("This represents the weight of all squad-level " + "equipment, it does not count individual equipment");
    if (currentKilos > maxKilos) {
        tons.setForeground(Color.red);
    } else {
        tons.setForeground(Color.black);
    }
    bvLabel.setText("BV: " + bv);
    bvLabel.setToolTipText("BV 2.0");
    move.setText("Movement: " + walk + "/" + jump);
    move.setToolTipText("Walk/Jump MP");
    cost.setText("Squad Cost: " + formatter.format(currentCost) + " C-bills");
}
Also used : TestBattleArmor(megamek.common.verifier.TestBattleArmor)

Aggregations

TestBattleArmor (megamek.common.verifier.TestBattleArmor)3 File (java.io.File)2 EntityVerifier (megamek.common.verifier.EntityVerifier)2 Font (java.awt.Font)1 Vector (java.util.Vector)1 Aero (megamek.common.Aero)1 BipedMech (megamek.common.BipedMech)1 CriticalSlot (megamek.common.CriticalSlot)1 Infantry (megamek.common.Infantry)1 LandAirMech (megamek.common.LandAirMech)1 Mech (megamek.common.Mech)1 Mounted (megamek.common.Mounted)1 QuadMech (megamek.common.QuadMech)1 Tank (megamek.common.Tank)1 TripodMech (megamek.common.TripodMech)1 WeaponType (megamek.common.WeaponType)1 MtfFile (megamek.common.loaders.MtfFile)1 TestAero (megamek.common.verifier.TestAero)1 TestEntity (megamek.common.verifier.TestEntity)1 TestInfantry (megamek.common.verifier.TestInfantry)1