Package megamek.common

Examples of megamek.common.Infantry


     * Damage that the specified platoon does with explosives
     */
    public static int getDamageFor(Entity entity) {
        if (!(entity instanceof Infantry))
            return 0;
        Infantry inf = (Infantry) entity;
        // maxtech page 41, damage for each turn as much as a normal shot would
        // do
        // should only be on motorized rifle platoons
        // return inf.getDamage(inf.getShootingStrength()) <<
        // (inf.turnsLayingExplosives - 1);
View Full Code Here


        // if(b == null || b.getId() != target.getTargetId())
        // return new ToHitData(TargetRoll.IMPOSSIBLE, "Target out of range");
        if (!(ae instanceof Infantry))
            return new ToHitData(TargetRoll.IMPOSSIBLE,
                    "Attacker is not infantry");
        Infantry inf = (Infantry) ae;
        if (inf.turnsLayingExplosives > 0)
            return new ToHitData(TargetRoll.AUTOMATIC_SUCCESS,
                    "STOP: Expected Damage: " + getDamageFor(ae));
        boolean ok = false;
        for (Mounted m : ae.getMisc()) {
View Full Code Here

                }
            }

            // check for dig in or fortify
            if (entity instanceof Infantry) {
                Infantry inf = (Infantry) entity;
                if (step.getType() == MovePath.STEP_DIG_IN) {
                    inf.setDugIn(Infantry.DUG_IN_WORKING);
                    continue;
                } else if (step.getType() == MovePath.STEP_FORTIFY) {
                    if (!entity.hasWorkingMisc(MiscType.F_TOOLS, MiscType.S_VIBROSHOVEL)) {
                        sendServerChat(entity.getDisplayName() + " failed to fortify because it is missing suitable equipment");
                    }
                    inf.setDugIn(Infantry.DUG_IN_FORTIFYING1);
                    continue;
                } else if ((step.getType() != MovePath.STEP_TURN_LEFT) && (step.getType() != MovePath.STEP_TURN_RIGHT)) {
                    // other movement clears dug in status
                    inf.setDugIn(Infantry.DUG_IN_NONE);
                }
            }

            // set last step parameters
            curPos = step.getPosition();
View Full Code Here

    private void resolveLayExplosivesAttack(PhysicalResult pr, int lastEntityId) {
        final LayExplosivesAttackAction laa = (LayExplosivesAttackAction) pr.aaa;
        final Entity ae = game.getEntity(laa.getEntityId());
        if (ae instanceof Infantry) {
            Infantry inf = (Infantry) ae;
            if (inf.turnsLayingExplosives < 0) {
                inf.turnsLayingExplosives = 0;
                Report r = new Report(4270);
                r.subject = inf.getId();
                r.addDesc(inf);
                addReport(r);
            } else {
                Building building = game.getBoard().getBuildingAt(ae.getPosition());
                if (building != null) {
                    building.addDemolitionCharge(ae.getOwner().getId(), pr.damage);
                    Report r = new Report(4275);
                    r.subject = inf.getId();
                    r.addDesc(inf);
                    r.add(pr.damage);
                    addReport(r);
                }
                inf.turnsLayingExplosives = -1;
View Full Code Here

        Enumeration<Entity> entities = game.getEntities();
        Report r;
        while (entities.hasMoreElements()) {
            Entity ent = entities.nextElement();
            if (ent instanceof Infantry) {
                Infantry inf = (Infantry) ent;
                int dig = inf.getDugIn();
                if (dig == Infantry.DUG_IN_WORKING) {
                    r = new Report(5300);
                    r.addDesc(inf);
                    r.subject = inf.getId();
                    addReport(r);
                } else if (dig == Infantry.DUG_IN_FORTIFYING2) {
                    Coords c = inf.getPosition();
                    r = new Report(5305);
                    r.addDesc(inf);
                    r.add(c.getBoardNum());
                    r.subject = inf.getId();
                    addReport(r);
                    // fortification complete - add to map
                    IHex hex = game.getBoard().getHex(c);
                    hex.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.FORTIFIED, 1));
                    sendChangedHex(c);
                    // Clear the dig in for any units in same hex, since they
                    // get it for free by fort
                    for (Enumeration<Entity> e = game.getEntities(c); e.hasMoreElements();) {
                        Entity ent2 = e.nextElement();
                        if (ent2 instanceof Infantry) {
                            Infantry inf2 = (Infantry) ent;
                            inf2.setDugIn(Infantry.DUG_IN_NONE);
                        }
                    }
                }
            }
        }
View Full Code Here

    public Vector<BackGroundDrawer> getBackgroundDrawers() {
        return bgDrawers;
    }

    public void setEntity(Entity e) {
        Infantry inf = (Infantry) e;
        int men = inf.getInternal(0);
        for (int i = 0; i < men; i++) {
            areas[i].setVisible(true);
        }
        for (int i = men; i < Infantry.INF_PLT_MAX_MEN; i++) {
            areas[i].setVisible(false);
View Full Code Here

    public Vector<BackGroundDrawer> getBackgroundDrawers() {
        return bgDrawers;
    }

    public void setEntity(Entity e) {
        Infantry inf = (Infantry) e;
        int men = inf.getInternal(0);
        for (int i = 0; i < men; i++) {
            areas[i].setVisible(true);
        }
        for (int i = men; i < Infantry.INF_PLT_MAX_MEN; i++) {
            areas[i].setVisible(false);
View Full Code Here

                r.subject = subjectId;
                vPhaseReport.add(r);
                return !bMissed;
            }
        }
        Infantry ba = (Infantry) ae;
        int ratedDamage = ba.getShootingStrength();
        server.artilleryDamageArea(coords, ae.getPosition(), (AmmoType) ammo
                .getType(), subjectId, ae, ratedDamage * 2, ratedDamage, false,
                0, vPhaseReport);
        return true;
    }
View Full Code Here

        dataFile = bb;
    }

    public Entity getEntity() throws EntityLoadingException {

        Infantry t = new Infantry();

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

        if (!dataFile.exists("model")) {
            throw new EntityLoadingException("Could not find model block.");
        }
        t.setModel(dataFile.getDataAsString("Model")[0]);

        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;
        for (int x = 0; x < MOVES.length; x++) {
            if (sMotion.equals(MOVES[x])) {
                nMotion = x;
                break;
            }
        }
        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]);
        }

        loadEquipment(t, "Platoon", Infantry.LOC_INFANTRY);

        if (dataFile.exists("troopers")) {
            int troopers = dataFile.getDataAsInt("troopers")[0];
            t.initializeInternal(troopers, Infantry.LOC_INFANTRY);
            if (t.hasWorkingMisc(MiscType.F_TOOLS, MiscType.S_HEAVY_ARMOR)) {
                t.initializeArmor(troopers, Infantry.LOC_INFANTRY);
            }
        } else {
            t.autoSetInternal();
        }

        return t;
    }
View Full Code Here

                4.0, 4.49, 4.98, 5.47, 6.31, 7.23, 8.14, 8.59, 9.04, 9.5, 10.1,
                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());
                         */
 
View Full Code Here

TOP

Related Classes of megamek.common.Infantry

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.