Package megamek.common

Examples of megamek.common.Report


            return; // not on board.
        }

        int flakElevation = altitude - hex.surface();

        Report r;

        if (!flak) {
            vPhaseReport.addAll(tryClearHex(coords, damage * 2, subjectId));
        }
        Building bldg = game.getBoard().getBuildingAt(coords);
        int bldgAbsorbs = 0;
        if ((bldg != null) && !(flak && (flakElevation > hex.terrainLevel(Terrains.BLDG_ELEV)))) {
            bldgAbsorbs = bldg.getPhaseCF(coords) / 10;
            if (!((ammo != null) && (ammo.getMunitionType() == AmmoType.M_FLECHETTE))) {
                // damage the building
                Vector<Report> buildingReport = damageBuilding(bldg, damage, coords);
                for (Report report : buildingReport) {
                    report.subject = subjectId;
                }
                vPhaseReport.addAll(buildingReport);
                addNewLines();
            }
        }

        if (flak && ((flakElevation <= 0) || (flakElevation <= hex.terrainLevel(Terrains.BLDG_ELEV)) || (flakElevation == hex.terrainLevel(Terrains.BRIDGE_ELEV)))) {
            // Flak in this hex would only hit landed units
            return;
        }

        // get units in hex
        for (Enumeration<Entity> impactHexHits = game.getEntities(coords); impactHexHits.hasMoreElements();) {
            Entity entity = impactHexHits.nextElement();
            int hits = damage;
            ToHitData toHit = new ToHitData();
            int cluster = 5;

            // Check: is entity excluded?
            if (entity == exclude) {
                continue;
            }

            // Check: is entity inside building?
            if ((bldg != null) && (bldgAbsorbs > 0) && (entity.getElevation() < hex.terrainLevel(Terrains.BLDG_ELEV))) {
                cluster -= bldgAbsorbs;
                if (entity instanceof Infantry) {
                    continue; // took its damage already from building damage
                } else if (cluster <= 0) {
                    // entity takes no damage
                    r = new Report(6426);
                    r.subject = subjectId;
                    r.addDesc(entity);
                    vPhaseReport.add(r);
                    continue;
                } else {
                    r = new Report(6425);
                    r.subject = subjectId;
                    r.add(bldgAbsorbs);
                    vPhaseReport.add(r);
                }
            }

            if (flak) {
                // Check: is entity not a VTOL in flight
                if (!((entity instanceof VTOL) || (entity.getMovementMode() == IEntityMovementMode.VTOL))) {
                    continue;
                }
                // Check: is entity at correct elevation?
                if (entity.getElevation() != flakElevation) {
                    continue;
                }
            } else {
                // Check: is entity a VTOL in flight?
                if ((entity instanceof VTOL) || (entity.getMovementMode() == IEntityMovementMode.VTOL)) {
                    // VTOLs take no damage from normal artillery unless landed
                    if ((entity.getElevation() != 0) && (entity.getElevation() != hex.terrainLevel(Terrains.BLDG_ELEV)) && (entity.getElevation() != hex.terrainLevel(Terrains.BRIDGE_ELEV))) {
                        continue;
                    }
                }
            }

            // Work out hit table to use
            if (attackSource != null) {
                toHit.setSideTable(entity.sideTable(attackSource));
                if ((ammo != null) && (ammo.getMunitionType() == AmmoType.M_CLUSTER) && attackSource.equals(coords)) {
                    if (entity instanceof Mech) {
                        toHit.setHitTable(ToHitData.HIT_ABOVE);
                    } else if (entity instanceof Tank) {
                        toHit.setSideTable(ToHitData.SIDE_FRONT);
                        toHit.addModifier(2, "cluster artillery hitting a Tank");
                    }
                }
            }

            // convention infantry take x2 damage from AE weapons
            if ((entity instanceof Infantry) && !(entity instanceof BattleArmor)) {
                hits *= 2;
            }

            // Entity/ammo specific damage modifiers
            if (ammo != null) {
                if (ammo.getMunitionType() == AmmoType.M_CLUSTER) {
                    if (hex.containsTerrain(Terrains.FORTIFIED) && (entity instanceof Infantry) && !(entity instanceof BattleArmor)) {
                        hits *= 2;
                    }
                } else if (ammo.getMunitionType() == AmmoType.M_FLECHETTE) {
                    // wheeled and hover tanks take movement critical
                    if ((entity instanceof Tank) && ((entity.getMovementMode() == IEntityMovementMode.WHEELED) || (entity.getMovementMode() == IEntityMovementMode.HOVER))) {
                        r = new Report(6480);
                        r.subject = entity.getId();
                        r.addDesc(entity);
                        r.add(toHit.getTableDesc());
                        r.add(0);
                        vPhaseReport.add(r);
                        vPhaseReport.addAll(vehicleMotiveDamage((Tank) entity, 0));
                        continue;
                    }
                    // only infantry and support vees with bar < 5 are affected
                    if ((entity instanceof BattleArmor) || (entity.getBARRating() > 4)) {
                        continue;
                    }
                    if (entity instanceof Infantry) {
                        hits = Compute.d6(damage);
                        hits *= 2;
                    }
                    if (entity.getBARRating() < 5) {
                        switch (ammo.getAmmoType()) {
                        case AmmoType.T_LONG_TOM:
                            // hack: check if damage is still at 4, so we're in the
                            // center hex. otherwise, do no damage
                            if (damage == 4) {
                                damage = (5 - entity.getBARRating()) * 5;
                            } else {
                                continue;
                            }
                            break;
                        case AmmoType.T_SNIPER:
                            // hack: check if damage is still at 2, so we're in the
                            // center hex. otherwise, do no damage
                            if (damage == 2) {
                                damage = (5 - entity.getBARRating()) * 3;
                            } else {
                                continue;
                            }
                            break;
                        case AmmoType.T_THUMPER:
                            // no need to check for damage, because falloff = damage for the thumper
                            damage = 5 - entity.getBARRating();
                            break;
                        }
                    }
                }
            }

            // Do the damage
            r = new Report(6480);
            r.subject = entity.getId();
            r.addDesc(entity);
            r.add(toHit.getTableDesc());
            r.add(hits);
            vPhaseReport.add(r);
            if (entity instanceof BattleArmor) {
                // BA take full damage to each trooper, ouch!
                for (int loc = 0; loc < entity.locations(); loc++) {
                    if (entity.getInternal(loc) > 0) {
View Full Code Here


    /**
     * Resolve any Infantry units which are fortifying hexes
     */
    void resolveFortify() {
        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));
View Full Code Here

     * @param loc
     *            the <code>int</code location
     */
    private void checkBreakSpikes(Entity e, int loc) {
        int roll = Compute.d6(2);
        Report r;
        if (roll < 9) {
            r = new Report(4445);
            r.newlines = 0;
            r.add(roll);
            r.subject = e.getId();
            addReport(r);
            return;
        }
        r = new Report(4440);
        r.newlines = 0;
        r.add(roll);
        r.subject = e.getId();
        addReport(r);
        for (Mounted m : e.getMisc()) {
            if (m.getType().hasFlag(MiscType.F_SPIKES) && (m.getLocation() == loc)) {
                m.setHit(true);
View Full Code Here

     * Loops through all the attacks the game has. Checks if they care about
     * current phase, if so, runs them, and removes them if they don't want to
     * stay. TODO: Refactor the new entity annoucement out of here.
     */
    private void handleAttacks() {
        Report r;
        int lastAttackerId = -1;
        Vector<AttackHandler> currentAttacks, keptAttacks;
        currentAttacks = game.getAttacksVector();
        keptAttacks = new Vector<AttackHandler>();
        Vector<Report> handleAttackReports = new Vector<Report>();
        // first, do any TAGs, so homing arty will have TAG
        for (AttackHandler ah : currentAttacks) {
            if (!(ah instanceof TAGHandler)) {
                continue;
            }
            if (ah.cares(game.getPhase())) {
                int aId = ah.getAttackerId();
                if ((aId != lastAttackerId) && !ah.announcedEntityFiring()) {
                    // report who is firing
                    r = new Report(3100);
                    r.subject = aId;
                    Entity ae = game.getEntity(aId);
                    if (ae == null) {
                        System.err.println("ae null in handleattacks, entityId " + aId);
                    }
                    r.addDesc(game.getEntity(aId));
                    handleAttackReports.addElement(r);
                    ah.setAnnouncedEntityFiring(true);
                }
                lastAttackerId = aId;
                boolean keep = ah.handle(game.getPhase(), handleAttackReports);
                if (keep) {
                    keptAttacks.add(ah);
                }
            }
        }
        // now resolve everything but TAG
        for (AttackHandler ah : currentAttacks) {
            if (ah instanceof TAGHandler) {
                continue;
            }
            if (ah.cares(game.getPhase())) {
                int aId = ah.getAttackerId();
                if ((aId != lastAttackerId) && !ah.announcedEntityFiring()) {
                    // if this is a new attacker then resolve any
                    // standard-to-cap damage
                    // from previous
                    handleAttackReports.addAll(checkFatalThresholds(aId));
                    // report who is firing
                    r = new Report(3100);
                    r.subject = aId;
                    Entity ae = game.getEntity(aId);
                    // for arty, attacker may be dead, or fled, so check out-of-
                    // game entities
                    if (ae == null) {
                        ae = game.getOutOfGameEntity(aId);
                    }
                    if (ae == null) {
                        System.err.println("ae null in handleattacks, entityId " + aId);
                    }
                    r.addDesc(game.getEntity(aId));
                    handleAttackReports.addElement(r);
                    ah.setAnnouncedEntityFiring(true);
                }
                lastAttackerId = aId;
                boolean keep = ah.handle(game.getPhase(), handleAttackReports);
View Full Code Here

    /**
     * Check to see if blowing sand caused damage to airborne VTOL/WIGEs
     */
    private Vector<Report> resolveBlowingSandDamage() {
        Vector<Report> vFullReport = new Vector<Report>();
        vFullReport.add(new Report(5002, Report.PUBLIC));
        int damage_bonus = Math.max(0, game.getPlanetaryConditions().getWindStrength() - PlanetaryConditions.WI_MOD_GALE);
        //cycle through each team and damage 1d6 airborne VTOL/WIGE
        for (Enumeration<Team> loop = game.getTeams(); loop.hasMoreElements();) {
            Team team = loop.nextElement();
            Vector<Integer> airborne = team.getAirborneVTOL();
View Full Code Here

     * @param entity the <code>Entity</code> that should lay a mine
     * @param mineId an <code>int</code> pointing to the mine
     */
    private void layMine(Entity entity, int mineId, Coords coords) {
        Mounted mine = entity.getEquipment(mineId);
        Report r;
        if (!mine.isMissing()) {
            switch (mine.getMineType()) {
            case Mounted.MINE_CONVENTIONAL:
                deliverThunderMinefield(coords, entity.getOwnerId(), 10, entity.getId());
                mine.setMissing(true);
                r = new Report(3500, Report.PLAYER);
                r.subject = entity.getId();
                r.addDesc(entity);
                r.type = Report.PLAYER;
                r.add(coords.getBoardNum());
                addReport(r);
                break;
            case Mounted.MINE_VIBRABOMB:
                deliverThunderVibraMinefield(coords, entity.getOwnerId(), 10, mine.getVibraSetting(), entity.getId());
                mine.setMissing(true);
                r = new Report(3505, Report.PLAYER);
                r.subject = entity.getId();
                r.addDesc(entity);
                r.add(coords.getBoardNum());
                addReport(r);
                break;
            case Mounted.MINE_ACTIVE:
                deliverThunderActiveMinefield(coords, entity.getOwnerId(), 10, entity.getId());
                mine.setMissing(true);
                r = new Report(3510, Report.PLAYER);
                r.subject = entity.getId();
                r.addDesc(entity);
                r.add(coords.getBoardNum());
                addReport(r);
                break;
            case Mounted.MINE_INFERNO:
                deliverThunderInfernoMinefield(coords, entity.getOwnerId(), 10, entity.getId());
                mine.setMissing(true);
                r = new Report(3515, Report.PLAYER);
                r.subject = entity.getId();
                r.addDesc(entity);
                r.add(coords.getBoardNum());
                addReport(r);
                break;
                // TODO: command-detonated mines
                // case 2:
            }
View Full Code Here

        } // End have-entities-here

        // Collapse the building if the flag is set.
        if (collapse) {
            Report r = new Report(2375, Report.PUBLIC);
            r.add(bldg.getName());
            addReport(r);
            collapseBuilding(bldg, positionMap, coords);
        }

        // Otherwise, did any entities fall into the basement?
View Full Code Here

        if (!bldg.hasCFIn(coords)) {
            return;
        }
        // Loop through the hexes in the building, and apply
        // damage to all entities inside or on top of the building.
        Report r;
        final int phaseCF = bldg.getPhaseCF(coords);
        // Get the Vector of Entities at these coordinates.
        final Vector<Entity> vector = positionMap.get(coords);

        // Are there any Entities at these coords?
        if (vector != null) {

            // How many levels does this building have in this hex?
            final IHex curHex = game.getBoard().getHex(coords);
            final int bridgeEl = curHex.terrainLevel(Terrains.BRIDGE_ELEV);
            final int numFloors = Math.max(bridgeEl, curHex.terrainLevel(Terrains.BLDG_ELEV));

            // Now collapse the building in this hex, so entities fall to
            // the ground
            bldg.setCurrentCF(0, coords);
            bldg.setPhaseCF(0, coords);
            send(createCollapseBuildingPacket(coords));
            game.getBoard().collapseBuilding(coords);

            // Sort in elevation order
            Collections.sort(vector, new Comparator<Entity>() {
                public int compare(Entity a, Entity b) {
                    if (a.getElevation() > b.getElevation()) {
                        return -1;
                    } else if (a.getElevation() > b.getElevation()) {
                        return 1;
                    }
                    return 0;
                }
            });
            // Walk through the entities in this position.
            Enumeration<Entity> entities = vector.elements();
            while (entities.hasMoreElements()) {
                final Entity entity = entities.nextElement();
                // final int entityElev = entity.elevationOccupied( curHex
                // );
                int floor = entity.getElevation();

                // Ignore units above the building / bridge.
                if (floor > numFloors) {
                    continue;
                }

                // Treat units on the roof like
                // they were in the top floor.
                if (floor == numFloors) {
                    floor--;
                }

                // Calculate collapse damage for this entity.
                int damage = (int) Math.ceil(phaseCF * (numFloors - floor) / 10.0);

                // Infantry suffer more damage.
                if (entity instanceof Infantry) {
                    if ((entity instanceof BattleArmor) || ((Infantry)entity).isMechanized()) {
                        damage *= 2;
                    } else {
                        damage *= 3;
                    }
                }

                // Apply collapse damage the entity.
                // ASSUMPTION: use 5 point clusters.
                r = new Report(6455);
                r.indent();
                r.subject = entity.getId();
                r.add(entity.getDisplayName());
                r.add(damage);
                addReport(r);
                int remaining = damage;
                int cluster = damage;
                if ((entity instanceof BattleArmor) || (entity instanceof Mech) || (entity instanceof Tank)) {
                    cluster = 5;
                }
                while (remaining > 0) {
                    int next = Math.min(cluster, remaining);
                    // In
                    // www.classicbattletech.com/PDF/AskPMForumArchiveandFAQ.pdf,
                    // pg. 18, Randall Bills says that all damage from a
                    // collapsing building is applied to the front.

                    HitData hit = entity.rollHitLocation(ToHitData.HIT_NORMAL, ToHitData.SIDE_FRONT);
                    hit.setGeneralDamageType(HitData.DAMAGE_PHYSICAL);
                    addReport(damageEntity(entity, hit, next));
                    remaining -= next;
                }
                addReport(new Report(1210, Report.PUBLIC));
                // TODO: Why are dead entities showing up on firing phase?

                // all entities should fall
                // TODO: implement basements, then fall into it.
                floor = entity.getElevation();
View Full Code Here

            // Walk through the hexes that have collapsed.
            for (Building bldg : collapse.keySet()) {
                Vector <Coords> coordsVector = collapse.get(bldg);
                for (Coords coords : coordsVector) {
                    Report r = new Report(6460, Report.PUBLIC);
                    r.add(bldg.getName());
                    addReport(r);
                    collapseBuilding(bldg, positionMap, coords);
                }
            }
        }
View Full Code Here

     * @return a <code>Report</code> to be shown to the players.
     */
    public Vector<Report> damageBuilding(Building bldg, int damage, String why,
            Coords coords) {
        Vector<Report> vPhaseReport = new Vector<Report>();
        Report r = new Report(1210, Report.PUBLIC);
        r.newlines = 0;

        // Do nothing if no building or no damage was passed.
        if ((bldg != null) && (damage > 0)) {
            int curCF = bldg.getCurrentCF(coords);
            final int startingCF = curCF;
            curCF -= Math.min(curCF, damage);
            bldg.setCurrentCF(curCF, coords);
            r.messageId = 3435;
            r.add(bldg.getName());
            r.add(why);
            r.add(damage);
            r.newlines = 1;

            // If the CF is zero, the building should fall.
            if ((curCF == 0) && (startingCF != 0)) {
                if (bldg instanceof FuelTank) {
                    // If this is a fuel tank, we'll give it its own message.
                    r.messageId = 3441;
                    r.type = Report.PUBLIC;
                    vPhaseReport.add(r);
                    // ...But we ALSO need to blow up everything nearby.
                    // Bwahahahahaha...
                    r = new Report(3560);
                    r.type = Report.PUBLIC;
                    r.newlines = 1;
                    vPhaseReport.add(r);
                    Vector<Report> vRep = new Vector<Report>();
                    doExplosion(((FuelTank) bldg).getMagnitude(), 10, false, bldg.getCoords().nextElement(), true, vRep, null);
View Full Code Here

TOP

Related Classes of megamek.common.Report

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.