Package megamek.common

Examples of megamek.common.BattleArmor


                        "Can't do that!", "You can't add an invalid unit.")
                        .setVisible(true);
                return;
            }
            try {
                BattleArmor e = getEntity();
                Client c = null;
                if (m_chPlayer.getSelectedIndex() > 0) {
                    String name = m_chPlayer.getSelectedItem();
                    c = m_clientgui.getBots().get(name);
                }
                if (c == null) {
                    c = m_client;
                }
                e.setOwner(c.getLocalPlayer());
                c.sendAddEntity(e);
            } catch (Exception ex) {
                System.err.println("Error while loading custom BattleArmor!");
                ex.printStackTrace();
                return;
            }
        } else if (ae.getSource() == m_bSave) {
            FileDialog fd = new FileDialog(
                    m_clientgui.frame,
                    Messages
                            .getString("CustomBattleArmorDialog.FileSaveDialog"), FileDialog.SAVE); //$NON-NLS-1$
            fd.setDirectory("data" + File.separatorChar + "mechfiles");
            fd.setFile(m_tfBAName.getText() + ".blk");
            fd.setFilenameFilter(new FilenameFilter() {
                public boolean accept(File f, String s) {
                    return s.endsWith(".blk");
                }
            });
            fd.setModal(true);
            fd.setVisible(true);
            String filename = fd.getDirectory() + File.separator + fd.getFile();
            if (filename.indexOf('.') == -1) {
                filename = filename + ".blk";
            }
            File f = new File(filename);
            try {
                BattleArmor ba = getEntity();
                FileWriter wr = new FileWriter(f);
                wr.write(ba.getBLK());
                wr.close();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
View Full Code Here


    public int calcSquadCost() {
        return calcSuitCost() * stateMenPerSquad;
    }

    public BattleArmor getEntity() {
        BattleArmor retVal = new BattleArmor();

        // Set the name.
        retVal.setChassis(m_tfBAName.getText().trim());
        retVal.setModel("");

        retVal.setWeightClass(stateWeightClass);
        retVal.setChassisType(stateChassisType);

        // Set the weight (number of troops), and then initialize the armor.
        retVal.setWeight(stateMenPerSquad);
        retVal.refreshLocations();
        retVal.autoSetInternal();
        retVal.setArmorType(stateArmorType);
        for (int x = 1; x < retVal.locations(); x++) {
            retVal.initializeArmor(stateArmorValue, x);
        }

        // Set the tech base.
        if (stateTechBase == TECH_BASE_IS) {
            retVal.setTechLevel(TechConstants.T_IS_TW_NON_BOX);
        } else {
            retVal.setTechLevel(TechConstants.T_CLAN_TW);
        }

        // Set the ground movement.
        retVal.setOriginalWalkMP(stateGroundMP);

        // Set the jump movement.
        retVal.setOriginalJumpMP(getTotalJumpMP());

        // Set the movement mode.
        if (stateJumpType == JUMP_TYPE_VTOL) {
            retVal.setMovementMode(IEntityMovementMode.VTOL);
        } else if (stateJumpType == JUMP_TYPE_UMU) {
            retVal.setMovementMode(IEntityMovementMode.INF_UMU);
            retVal.setOriginalWalkMP(getTotalJumpMP());
            retVal.setOriginalJumpMP(0);
        } else if (getTotalJumpMP() > 0) {
            retVal.setMovementMode(IEntityMovementMode.INF_JUMP);
        } else {
            retVal.setMovementMode(IEntityMovementMode.INF_LEG);
        }

        // And set its cost.
        retVal.setCost(calcSquadCost());

        try {
            if (stateArmorType == 7) { // Fire-resistant Armor
                retVal.addEquipment(EquipmentType
                        .get("BA-Fire Resistant Armor"),
                        BattleArmor.LOC_SQUAD);
            }

            // If it's capable of anti-'Mech attacks...
            if (canDoAntiMech()) {
                retVal.addEquipment(EquipmentType.get(Infantry.LEG_ATTACK),
                        BattleArmor.LOC_SQUAD);
                retVal.addEquipment(EquipmentType.get(Infantry.SWARM_MEK),
                        BattleArmor.LOC_SQUAD);
                retVal.addEquipment(EquipmentType.get(Infantry.STOP_SWARM),
                        BattleArmor.LOC_SQUAD);

                // Don't forget magnetic claws that give a bonus, like
                // Salamanders!
                if (stateManipulatorTypeLeft == BattleArmor.MANIPULATOR_BATTLE_MAGNET) {
                    // We only check one, because they can only be added in
                    // pairs...
                    retVal.addEquipment(EquipmentType
                            .get(BattleArmor.ASSAULT_CLAW),
                            BattleArmor.LOC_SQUAD);
                }
            }

            // Lets add vibro-claws!
            if (((stateManipulatorTypeLeft == BattleArmor.MANIPULATOR_BATTLE_VIBRO) || (stateManipulatorTypeLeft == BattleArmor.MANIPULATOR_HEAVY_BATTLE_VIBRO))
                    && ((stateManipulatorTypeRight == BattleArmor.MANIPULATOR_BATTLE_VIBRO) || (stateManipulatorTypeRight == BattleArmor.MANIPULATOR_HEAVY_BATTLE_VIBRO))) {
                // BA-Vibro Claws (2)
                retVal.addEquipment(EquipmentType.get("BA-Vibro Claws (2)"),
                        BattleArmor.LOC_SQUAD);
            } else if (((stateManipulatorTypeLeft == BattleArmor.MANIPULATOR_BATTLE_VIBRO) || (stateManipulatorTypeLeft == BattleArmor.MANIPULATOR_HEAVY_BATTLE_VIBRO))
                    || ((stateManipulatorTypeRight == BattleArmor.MANIPULATOR_BATTLE_VIBRO) || (stateManipulatorTypeRight == BattleArmor.MANIPULATOR_HEAVY_BATTLE_VIBRO))) {
                // BA-Vibro Claws (1)
                retVal.addEquipment(EquipmentType.get("BA-Vibro Claws (1)"),
                        BattleArmor.LOC_SQUAD);
            }

            if (canMountMech()) {
                // Needs to be able to ride 'Mechs.
                retVal.addEquipment(EquipmentType
                        .get(BattleArmor.BOARDING_CLAW), BattleArmor.LOC_SQUAD);
            }

            // Equipment and stuff needs to be set!
            // Now all other equipment.
            if (leftArmEquipment != null) {
                Enumeration<BattleArmorEquipment> tmpE = leftArmEquipment
                        .elements();
                while (tmpE.hasMoreElements()) {
                    BattleArmorEquipment tmpBAE = (tmpE.nextElement());
                    if ((tmpBAE.internalType == EQUIPMENT_TYPE_WEAPON)
                            || (tmpBAE.internalType == EQUIPMENT_TYPE_AMMO)) {
                        retVal.addEquipment(EquipmentType
                                .get(tmpBAE.weaponTypeName),
                                BattleArmor.LOC_SQUAD);
                    } else if (tmpBAE.internalType == EQUIPMENT_TYPE_OTHER) {
                        // FIXME
                    }
                    // EQUIPMENT_TYPE_PREPROCESS, by definition, should already
                    // have been handled.
                }
            }
            if (rightArmEquipment != null) {
                Enumeration<BattleArmorEquipment> tmpE = rightArmEquipment
                        .elements();
                while (tmpE.hasMoreElements()) {
                    BattleArmorEquipment tmpBAE = (tmpE.nextElement());
                    if ((tmpBAE.internalType == EQUIPMENT_TYPE_WEAPON)
                            || (tmpBAE.internalType == EQUIPMENT_TYPE_AMMO)) {
                        retVal.addEquipment(EquipmentType
                                .get(tmpBAE.weaponTypeName),
                                BattleArmor.LOC_SQUAD);
                    } else if (tmpBAE.internalType == EQUIPMENT_TYPE_OTHER) {
                        // FIXME
                    }
                    // EQUIPMENT_TYPE_PREPROCESS, by definition, should already
                    // have been handled.
                }
            }
            if (torsoEquipment != null) {
                Enumeration<BattleArmorEquipment> tmpE = torsoEquipment
                        .elements();
                while (tmpE.hasMoreElements()) {
                    BattleArmorEquipment tmpBAE = (tmpE.nextElement());
                    if ((tmpBAE.internalType == EQUIPMENT_TYPE_WEAPON)
                            || (tmpBAE.internalType == EQUIPMENT_TYPE_AMMO)) {
                        retVal.addEquipment(EquipmentType
                                .get(tmpBAE.weaponTypeName),
                                BattleArmor.LOC_SQUAD);
                    } else if (tmpBAE.internalType == EQUIPMENT_TYPE_OTHER) {
                        // FIXME
                    }
View Full Code Here

        dataFile = bb;
    }

    public Entity getEntity() throws EntityLoadingException {

        BattleArmor t = new BattleArmor();

        if (!dataFile.exists("name")) {
            throw new EntityLoadingException("Could not find name block.");
        }
        t.setChassis(dataFile.getDataAsString("Name")[0]);

        // Model is not strictly necessary.
        if (dataFile.exists("Model") && dataFile.getDataAsString("Model")[0] != null) {
            t.setModel(dataFile.getDataAsString("Model")[0]);
        } else {
            t.setModel("");
        }

        setTechLevel(t);

        if (dataFile.exists("source")) {
            t.setSource(dataFile.getDataAsString("source")[0]);
        }

        if (!dataFile.exists("tonnage")) {
            throw new EntityLoadingException("Could not find weight block.");
        }
        t.setWeight(dataFile.getDataAsFloat("tonnage")[0]);

        if (!dataFile.exists("motion_type")) {
            throw new EntityLoadingException("Could not find movement block.");
        }
        String sMotion = dataFile.getDataAsString("motion_type")[0];
        int nMotion = -1;
        if (sMotion.equalsIgnoreCase("leg")) {
            nMotion = IEntityMovementMode.INF_LEG;
        } else if (sMotion.equalsIgnoreCase("jump")) {
            nMotion = IEntityMovementMode.INF_JUMP;
        } else if (sMotion.equalsIgnoreCase("vtol")) {
            nMotion = IEntityMovementMode.VTOL;
        } else if (sMotion.equalsIgnoreCase("submarine")) {
            nMotion = IEntityMovementMode.INF_UMU;
        }
        if (nMotion == -1) {
            throw new EntityLoadingException("Invalid movement type: " + sMotion);
        }
        t.setMovementMode(nMotion);

        if (!dataFile.exists("cruiseMP")) {
            throw new EntityLoadingException("Could not find cruiseMP block.");
        }
        t.setOriginalWalkMP(dataFile.getDataAsInt("cruiseMP")[0]);

        if (dataFile.exists("jumpingMP")) {
            t.setOriginalJumpMP(dataFile.getDataAsInt("jumpingMP")[0]);
        }

        if (!dataFile.exists("armor")) {
            throw new EntityLoadingException("Could not find armor block.");
        }

        int[] armor = dataFile.getDataAsInt("armor");

        // Each trooper has the same amount of armor
        if (armor.length != 1) {
            throw new EntityLoadingException("Incorrect armor array length");
        }

        // add the body to the armor array
        t.refreshLocations();
        for (int x = 1; x < t.locations(); x++) {
            t.initializeArmor(armor[0], x);
        }

        t.autoSetInternal();

        loadEquipment(t, "Squad", BattleArmor.LOC_SQUAD);
        String[] abbrs = t.getLocationAbbrs();
        for (int loop = 1; loop < t.locations(); loop++) {
            loadEquipment(t, abbrs[loop], loop);
        }
        return t;
    }
View Full Code Here

                10.8, 11.42, 12.1, 12.7 };

        boolean use_table = false;

        Infantry inf_attacker = new Infantry();
        BattleArmor ba_attacker = new BattleArmor();
        Mounted lnk_guide;

        if (attacker instanceof BattleArmor) {
            ba_attacker = (BattleArmor) attacker;
        }
        if ((attacker instanceof Infantry)
                && !(attacker instanceof BattleArmor)) {
            inf_attacker = (Infantry) attacker;
        }

        // Only infantry can fire into their own hex

        if (!(attacker instanceof Infantry) & (range == 0)) {
            return 0.0;
        }

        double fDamage = 0.0;
        WeaponType wt = (WeaponType) weapon.getType();

        // The "Stop Swarm Attack" really isn't one

        if (wt.getName() == "Stop Swarm Attack") {
            return 0.0;
        }

        // Get the range modifier for the weapon

        if (range <= wt.getMinimumRange()) {
            total_mod = total_mod + 1 + (wt.getMinimumRange() - range);
        } else {
            if (range > wt.getShortRange()) {
                total_mod += 2;
            }
            if (range > wt.getMediumRange()) {
                total_mod += 2;
            }
            if (range > wt.getLongRange()) {
                total_mod += 4;
            }
            if (range > wt.getExtremeRange()) {
                return 0.0;
            }
        }

        // Get the weapon to-hit mod

        total_mod += wt.getToHitModifier();

        // Some weapons use multiple hits, as determined by the missile
        // hits table. This method is used for an approximation, so
        // assume LBX cannon are using cluster rounds, Ultra-cannon
        // are firing double rate, and RACs are fired in quad mode.
        if ((wt.getDamage() == WeaponType.DAMAGE_MISSILE)
                && ((wt.getAmmoType() != AmmoType.T_TBOLT_5) ||
                    (wt.getAmmoType() != AmmoType.T_TBOLT_10) ||
                    (wt.getAmmoType() != AmmoType.T_TBOLT_15) ||
                    (wt.getAmmoType() != AmmoType.T_TBOLT_20))) {
            use_table = true;
        }
        if ((wt.getAmmoType() == AmmoType.T_AC_LBX)
                || (wt.getAmmoType() == AmmoType.T_AC_LBX_THB)) {
            use_table = true;
            total_mod -= 1;
        }

        if ((wt.getAmmoType() == AmmoType.T_AC_ULTRA)
                || (wt.getAmmoType() == AmmoType.T_AC_ULTRA_THB)
                || (wt.getAmmoType() == AmmoType.T_AC_ROTARY)) {
            use_table = true;
        }

        // Kinda cheap, but lets use the missile hits table for Battle armor
        // weapons too

        if (attacker instanceof BattleArmor) {
            if ((wt.getInternalName() != Infantry.SWARM_MEK)
                    & (wt.getInternalName() != Infantry.LEG_ATTACK)
                    & !(wt.hasFlag(WeaponType.F_INFANTRY))) {
                use_table = true;
            }
        }

        if (use_table == true) {
            double fHits = 0.0;
            if (!(attacker instanceof BattleArmor)) {
                if (weapon.getLinked() == null) {
                    return 0.0;
                }
            }
            AmmoType at = null;
            if (weapon.getLinked() != null) {
                at = (AmmoType) weapon.getLinked().getType();
                // Override damage by ammo type for some items
                // Set LRM and MRM damage at 1.0, SRM types at 2.0,
                // and ATMs at 2.4 (2.0 nominal x 1.2 for built-in
                // Artemis)

                fDamage = at.getDamagePerShot();
                if ((wt.getAmmoType() == AmmoType.T_SRM_STREAK)
                        || (wt.getAmmoType() == AmmoType.T_SRM)) {
                    fDamage = 2.0;
                }
                if (wt.getAmmoType() == AmmoType.T_ATM) {
                    fDamage = 2.4;
                }
                if ((wt.getAmmoType() == AmmoType.T_LRM_STREAK)
                        || (wt.getAmmoType() == AmmoType.T_LRM)
                        || (wt.getAmmoType() == AmmoType.T_MRM)) {
                    fDamage = 1.0;
                }
            }
            if ((wt.getRackSize() != 40) && (wt.getRackSize() != 30)) {
                fHits = expectedHitsByRackSize[wt.getRackSize()];
            } else {
                fHits = 2.0f * expectedHitsByRackSize[wt.getRackSize() / 2];
            }
            if ((wt.getAmmoType() == AmmoType.T_SRM_STREAK)
                    || (wt.getAmmoType() == AmmoType.T_LRM_STREAK)) {
                fHits = wt.getRackSize();
            }
            if ((wt.getAmmoType() == AmmoType.T_AC_ULTRA)
                    || (wt.getAmmoType() == AmmoType.T_AC_ULTRA_THB)) {
                fHits = expectedHitsByRackSize[2];
            }
            if (wt.getAmmoType() == AmmoType.T_AC_ROTARY) {
                fHits = expectedHitsByRackSize[4];
            }
            if ((wt.getAmmoType() == AmmoType.T_AC_LBX)
                    || (wt.getAmmoType() == AmmoType.T_AC_LBX_THB)) {
                fHits = expectedHitsByRackSize[wt.getDamage()];
            }
            if ((wt.getAmmoType() == AmmoType.T_LRM)
                    || (wt.getAmmoType() == AmmoType.T_SRM)) {
                lnk_guide = weapon.getLinkedBy();
                if ((lnk_guide != null)
                        && (lnk_guide.getType() instanceof MiscType)
                        && !lnk_guide.isDestroyed() && !lnk_guide.isMissing()
                        && !lnk_guide.isBreached()
                        && lnk_guide.getType().hasFlag(MiscType.F_ARTEMIS)) {
                    fHits *= 1.2f;
                }
            }

            if (wt.getAmmoType() == AmmoType.T_MRM) {
                lnk_guide = weapon.getLinkedBy();
                if ((lnk_guide != null)
                        && (lnk_guide.getType() instanceof MiscType)
                        && !lnk_guide.isDestroyed() && !lnk_guide.isMissing()
                        && !lnk_guide.isBreached()
                        && lnk_guide.getType().hasFlag(MiscType.F_APOLLO)) {
                    fHits *= .9f;
                }
            }
            // Most Battle Armor units have a weapon per trooper, plus their
            // weapons do odd things when mounting multiples
            if (attacker instanceof BattleArmor) {
                // The number of troopers hitting
                fHits = expectedHitsByRackSize[ba_attacker
                        .getShootingStrength()];
                if (wt.getDamage() == WeaponType.DAMAGE_MISSILE) {
                    fHits *= expectedHitsByRackSize[wt.getRackSize()];
                }
                if (wt.getDamage() != WeaponType.DAMAGE_MISSILE) {
                    if (wt.getDamage() != WeaponType.DAMAGE_VARIABLE) {
                        fDamage = wt.getDamage();
                    } else {
                        fDamage = wt.getRackSize();
                    }
                }
                if (wt.hasFlag(WeaponType.F_MISSILE_HITS)) {
                    fHits *= expectedHitsByRackSize[wt.getRackSize()];
                }
            }

            fDamage *= fHits;

            if ((wt.getAmmoType() == AmmoType.T_AC_ULTRA)
                    || (wt.getAmmoType() == AmmoType.T_AC_ULTRA_THB)
                    || (wt.getAmmoType() == AmmoType.T_AC_ROTARY)) {
                fDamage = fHits * wt.getDamage();
            }

        } else {

            // Direct fire weapons just do a single shot
            // so they don't use the missile hits table

            fDamage = wt.getDamage();

            // Heavy gauss and Thunderbolt LRMs do odd things with range

            if (wt.getAmmoType() == AmmoType.T_GAUSS_HEAVY) {
                fDamage = 25.0;
                if (range > 6) {
                    fDamage = 20.0;
                }
                if (range > 13) {
                    fDamage = 10.0;
                }
            }
            if ((wt.getAmmoType() == AmmoType.T_TBOLT_5) ||
                (wt.getAmmoType() == AmmoType.T_TBOLT_10) ||
                (wt.getAmmoType() == AmmoType.T_TBOLT_15) ||
                (wt.getAmmoType() == AmmoType.T_TBOLT_20)) {
                if (range <= wt.getMinimumRange()) {
                    fDamage *= 0.5;
                }
            }

            // Infantry follow some special rules, but do fixed amounts of
            // damage
            if (attacker instanceof Infantry) {

                if (wt.hasFlag(WeaponType.F_INFANTRY)) {
                    // Weapons fielded by conventional infantry and light BA
                    // Field guns should be handled under the normal weapons
                    // section
                    /*
                     * fDamage = 0.6f * inf_attacker.getDamage(inf_attacker.
                     * getShootingStrength());
                     */
                    // TODO: fix me
                    fDamage = 1;
                    if (attacker instanceof BattleArmor) {
                        /*
                         * fDamage = inf_attacker.getDamage(ba_attacker.
                         * getShootingStrength());
                         */
                        // TODO: fix me
                        fDamage = 1;
                    }
                }

                if (wt.getInternalName() == Infantry.LEG_ATTACK) {
                    // Odds change based on number of troopers. Make an
                    // estimate.
                    if (!(attacker instanceof BattleArmor)) {
                        total_mod = 4 + 2 * (inf_attacker.getOInternal(0) - inf_attacker
                                .getShootingStrength()) / 5;
                    } else {
                        total_mod = 8 - ba_attacker.getShootingStrength();
                    }
                    fDamage = 10.0; // Damage is actually 5 plus chance at crits
                }

                if (wt.getInternalName() == Infantry.SWARM_MEK) {
                    // Odds change based on number of troopers. Make an
                    // estimate.
                    // Damage is same as conventional weapons, but with chance
                    // for crits
                    if (!(attacker instanceof BattleArmor)) {
                        total_mod = 7 + 2 * (inf_attacker.getOInternal(0) - inf_attacker
                                .getShootingStrength()) / 5;
                        /*
                         * fDamage = 1.5 * inf_attacker.getDamage(inf_attacker
                         * .getShootingStrength());
                         */
                        // TODO: Fix me
                        fDamage = 5;
                    } else {
                        total_mod = 11 - ba_attacker.getShootingStrength();
                        fDamage = 5.0 * ba_attacker.getShootingStrength();
                    }
                }

            }
        }
View Full Code Here

TOP

Related Classes of megamek.common.BattleArmor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.