Package megamek.common

Examples of megamek.common.ToHitData


                if (clubMenu.getItemCount() > 0) {
                    menu.add(clubMenu);
                }
            }

            ToHitData grap = GrappleAttackAction.toHit(client.game, myEntity.getId(), myTarget);
            ToHitData bgrap = BreakGrappleAttackAction.toHit(client.game, myEntity.getId(), myTarget);
            if (grap.getValue() != TargetRoll.IMPOSSIBLE || bgrap.getValue() != TargetRoll.IMPOSSIBLE) {

                item = createGrappleJMenuItem();

                if (item != null) {
                    menu.add(item);
                }
            }
            if (myTarget != null) {
                ToHitData vibro = BAVibroClawAttackAction.toHit(client.game, myEntity.getId(), myTarget);
                if (vibro.getValue() != TargetRoll.IMPOSSIBLE) {
                    item = createVibroClawMenuItem();
                    if (item != null) {
                        menu.add(item);
                    }
                }
View Full Code Here


            h2 = Integer.parseInt(height2.getText());
        } catch (NumberFormatException e) {
        }

        String toHit1 = "", toHit2 = ""; //$NON-NLS-1$ //$NON-NLS-2$
        ToHitData thd;
        if (flip) {
            thd = LosEffects.calculateLos(client.game,
                    buildAttackInfo(start, end, h1, h2)).losModifiers(
                    client.game);
        } else {
            thd = LosEffects.calculateLos(client.game,
                    buildAttackInfo(end, start, h2, h1)).losModifiers(
                    client.game);
        }
        if (thd.getValue() != TargetRoll.IMPOSSIBLE) {
            toHit1 = thd.getValue() + " = "; //$NON-NLS-1$
        }
        toHit1 += thd.getDesc();

        if (flip) {
            thd = LosEffects.calculateLos(client.game,
                    buildAttackInfo(end, start, h2, h1)).losModifiers(
                    client.game);
        } else {
            thd = LosEffects.calculateLos(client.game,
                    buildAttackInfo(start, end, h1, h2)).losModifiers(
                    client.game);
        }
        if (thd.getValue() != TargetRoll.IMPOSSIBLE) {
            toHit2 = thd.getValue() + " = "; //$NON-NLS-1$
        }
        toHit2 += thd.getDesc();

        tf_start.setText(start.toString());
        tf_end.setText(end.toString());
        tf_distance.setText("" + distance); //$NON-NLS-1$
        tf_los1.setText(toHit1);
View Full Code Here

                } else {
                    CEntity target = centities.get(option.getPhysicalTargetId());
                    try {
                        if (target.getEntity().getId() == enemy.getEntity().getId()) {
                            if (!target.isPhysicalTarget) {
                                ToHitData toHit = null;
                                double self_threat = 0;
                                double damage = 0;
                                if (option.isJumping() && option.getEntity().canDFA()) {
                                    self.current.setState();
                                    toHit = DfaAttackAction.toHit(game, option.getEntity().getId(),
                                            target.getEntity(), option);
                                    damage = 2 * DfaAttackAction
                                            .getDamageFor(
                                                    option.getEntity(),
                                                    target.getEntity() instanceof Infantry
                                                            && !(target.getEntity() instanceof BattleArmor));
                                    self_threat = option.getCEntity().getThreatUtility(
                                            DfaAttackAction.getDamageTakenBy(option.getEntity()),
                                            ToHitData.SIDE_REAR)
                                            * Compute.oddsAbove(toHit.getValue()) / 100;
                                    self_threat += option.getCEntity().getThreatUtility(
                                            .1 * self.getEntity().getWeight(), ToHitData.SIDE_REAR);
                                    self_threat *= 100 / option.getCEntity().getEntity()
                                            .getWeight();
                                } else if (option.getEntity().canCharge()) {
                                    self.current.setState();
                                    toHit = new ChargeAttackAction(option.getEntity(), target
                                            .getEntity()).toHit(game, option);
                                    damage = ChargeAttackAction.getDamageFor(option.getEntity(),
                                            target.getEntity(), false, option.getHexesMoved());
                                    self_threat = option.getCEntity().getThreatUtility(
                                            ChargeAttackAction.getDamageTakenBy(option.getEntity(),
                                                    target.getEntity()), ToHitData.SIDE_FRONT)
                                            * (Compute.oddsAbove(toHit.getValue()) / 100);
                                    option.setState();
                                }
                                damage = target.getThreatUtility(damage, toHit.getSideTable())
                                        * Compute.oddsAbove(toHit.getValue()) / 100;
                                // charging is a good tactic against larger
                                // mechs
                                if (!option.isJumping())
                                    damage *= Math.sqrt((double) enemy.bv / (double) self.bv);
                                // these are always risky, just don't on 11 or
                                // 12
                                if (toHit.getValue() > 10)
                                    damage = 0;
                                // 7 or less is good
                                if (toHit.getValue() < 8)
                                    damage *= 1.5;
                                // this is all you are good for
                                if (self.range_damages[CEntity.RANGE_SHORT] < 5)
                                    damage *= 2;
                                MoveOption.DamageInfo di = option.getDamageInfo(enemy, true);
View Full Code Here

        AttackOption max = new AttackOption(null, null, 0, null, 1);
        while (ents.hasMoreElements()) {
            Entity e = ents.nextElement();
            CEntity enemy = centities.get(e);
            // long entry = System.currentTimeMillis();
            ToHitData th = WeaponAttackAction.toHit(game, from, e, weaponID);
            // long exit = System.currentTimeMillis();
            // if (exit != entry)
            // System.out.println("Weapon attack toHit took "+(exit-entry));
            if (th.getValue() != TargetRoll.IMPOSSIBLE && !(th.getValue() >= 13)) {
                double expectedDmg;

                wep_test = new WeaponAttackAction(from, e.getId(), weaponID);

                // If this is an Ultra or Rotary cannon, check for spin up
View Full Code Here

        if (entity.isCharging() || entity.isMakingDfa()) {
            return null;
        }

        PhysicalOption best = null;
        ToHitData odds;
        double breach;
        double breach_a;
        double l_dmg;
        double r_dmg;
        double final_dmg;
        int best_brush = PhysicalOption.NONE;

        // If the attacker is a Mech

        if (entity instanceof Mech) {

            l_dmg = 0.0;
            r_dmg = 0.0;
            final_dmg = 0.0;
            breach_a = 0.0;

            // If the attacker is being swarmed

            if (entity.getSwarmAttackerId() != Entity.NONE) {

                // Check for left arm punch damage to self

                odds = BrushOffAttackAction.toHit(game, entity.getId(), game
                        .getEntity(entity.getSwarmAttackerId()),
                        BrushOffAttackAction.LEFT);
                if (odds.getValue() != TargetRoll.IMPOSSIBLE) {

                    l_dmg = BrushOffAttackAction.getDamageFor(entity,
                            BrushOffAttackAction.LEFT);
                    l_dmg *= 1.0 - Compute.oddsAbove(odds.getValue()) / 100.0;
                    breach = punchThroughMod(entity, ToHitData.HIT_PUNCH,
                            ToHitData.SIDE_FRONT, l_dmg, l_dmg);
                    if (breach < 1.5) {
                        best_brush = PhysicalOption.BRUSH_LEFT;
                        breach_a = breach;
                        final_dmg = BrushOffAttackAction.getDamageFor(entity,
                                BrushOffAttackAction.LEFT);
                    }
                }

                // Check for right arm punch damage to self
                odds = BrushOffAttackAction.toHit(game, entity.getId(), game
                        .getEntity(entity.getSwarmAttackerId()),
                        BrushOffAttackAction.RIGHT);
                if (odds.getValue() != TargetRoll.IMPOSSIBLE) {

                    // If chance of breaching armor is minimal set brush left

                    r_dmg = BrushOffAttackAction.getDamageFor(entity,
                            BrushOffAttackAction.RIGHT);
                    r_dmg *= 1.0 - Compute.oddsAbove(odds.getValue()) / 100.0;
                    breach = punchThroughMod(entity, ToHitData.HIT_PUNCH,
                            ToHitData.SIDE_FRONT, r_dmg, r_dmg);
                    if (breach < Math.min(breach_a, 1.5)) {
                        best_brush = PhysicalOption.BRUSH_RIGHT;
                        breach_a = breach;
                        final_dmg = BrushOffAttackAction.getDamageFor(entity,
                                BrushOffAttackAction.RIGHT);
                    }
                }

                // If both arms are capable of punching, check double punch
                // damage

                if ((l_dmg > 0) && (r_dmg > 0)) {

                    // If chance of breaching armor is minimal set double brush

                    breach = punchThroughMod(entity, ToHitData.HIT_PUNCH,
                            ToHitData.SIDE_FRONT, l_dmg + r_dmg,
                            (l_dmg + r_dmg) / 2.0);
                    if (breach < Math.min(breach_a, 1.5)) {
                        best_brush = PhysicalOption.BRUSH_BOTH;
                        breach_a = breach;
                        final_dmg = BrushOffAttackAction.getDamageFor(entity,
                                BrushOffAttackAction.LEFT);
                        final_dmg += BrushOffAttackAction.getDamageFor(entity,
                                BrushOffAttackAction.RIGHT);
                    }
                }

                // Construct and return Physical option
                if (best_brush != PhysicalOption.NONE) {
                    return new PhysicalOption(entity, game.getEntity(entity
                            .getSwarmAttackerId()), final_dmg, best_brush, null);
                }
            }

            // If the attacker has attached iNarc pods, assign
            // a competing damage value for comparison with other
            // attacks

            if (entity.hasINarcPodsAttached()) {
                double test_ranking;
                double pod_ranking;
                INarcPod test_pod;
                INarcPod best_pod;
                pod_ranking = 0.0;
                Iterator<INarcPod> pod_list = entity.getINarcPodsAttached();
                best_pod = pod_list.next();
                for (pod_list = entity.getINarcPodsAttached(); pod_list
                        .hasNext();) {
                    test_ranking = 1.0;
                    test_pod = pod_list.next();
                    // If pod is homing and attacker has no ECM
                    if ((test_pod.getType() == INarcPod.HOMING)
                            && !entity.hasActiveECM()) {
                        // Pod is +1
                        test_ranking += 1.0;
                    }
                    // If pod is ECM and attacker has C3 link
                    if ((test_pod.getType() == INarcPod.ECM)
                            && (entity.hasC3() || entity.hasC3i())) {
                        // Pod is +2
                        test_ranking += 2.0;
                    }
                    // If pod is Nemesis
                    if (test_pod.getType() == INarcPod.NEMESIS) {
                        // Pod is +variable, based on movement
                        test_ranking += (entity.getWalkMP() + entity
                                .getJumpMP()) / 2.0;
                    }
                    // If this pod is best, retain it and its ranking
                    if (test_ranking > pod_ranking) {
                        pod_ranking = test_ranking;
                        best_pod = test_pod;
                    }
                }
                if (best_pod != null) {
                    // Check for left arm punch damage to self
                    odds = BrushOffAttackAction.toHit(game, entity.getId(),
                            best_pod, BrushOffAttackAction.LEFT);
                    if (odds.getValue() != TargetRoll.IMPOSSIBLE) {

                        l_dmg = BrushOffAttackAction.getDamageFor(entity,
                                BrushOffAttackAction.LEFT);
                        l_dmg *= 1.0 - Compute.oddsAbove(odds.getValue()) / 100.0;
                        breach = punchThroughMod(entity, ToHitData.HIT_PUNCH,
                                ToHitData.SIDE_FRONT, l_dmg, l_dmg);
                        if (breach < 1.5) {
                            best_brush = PhysicalOption.BRUSH_LEFT;
                            breach_a = breach;
                            final_dmg = BrushOffAttackAction.getDamageFor(
                                    entity, BrushOffAttackAction.LEFT);
                        }
                    }

                    // Check for right arm punch damage to self
                    odds = BrushOffAttackAction.toHit(game, entity.getId(),
                            best_pod, BrushOffAttackAction.RIGHT);
                    if (odds.getValue() != TargetRoll.IMPOSSIBLE) {

                        // If chance of breaching armor is minimal set brush
                        // left

                        r_dmg = BrushOffAttackAction.getDamageFor(entity,
                                BrushOffAttackAction.RIGHT);
                        r_dmg *= 1.0 - Compute.oddsAbove(odds.getValue()) / 100.0;
                        breach = punchThroughMod(entity, ToHitData.HIT_PUNCH,
                                ToHitData.SIDE_FRONT, r_dmg, r_dmg);
                        if (breach < Math.min(breach_a, 1.5)) {
                            best_brush = PhysicalOption.BRUSH_RIGHT;
                            breach_a = breach;
View Full Code Here

            }
        } else {
            location_table = ToHitData.HIT_NORMAL;
        }

        ToHitData odds = PunchAttackAction.toHit(game, from.getId(), to,
                PunchAttackAction.LEFT);
        if (odds.getValue() != TargetRoll.IMPOSSIBLE) {
            damage = PunchAttackAction.getDamageFor(from,
                    PunchAttackAction.LEFT, targetConvInfantry);
            bestDmg = Compute.oddsAbove(odds.getValue()) / 100.0 * damage;
            // Adjust damage for targets armor
            bestType = PhysicalOption.PUNCH_LEFT;
            bestDmg *= punchThroughMod(to, location_table, target_arc, bestDmg,
                    bestDmg);
        }

        odds = PunchAttackAction.toHit(game, from.getId(), to,
                PunchAttackAction.RIGHT);
        if (odds.getValue() != TargetRoll.IMPOSSIBLE) {
            damage = PunchAttackAction.getDamageFor(from,
                    PunchAttackAction.RIGHT, targetConvInfantry);
            dmg = Compute.oddsAbove(odds.getValue()) / 100.0 * damage;
            // Adjust damage for targets armor
            dmg *= punchThroughMod(to, location_table, target_arc, dmg, dmg);
            if (dmg > bestDmg) {
                bestType = PhysicalOption.PUNCH_RIGHT;
                bestDmg = dmg;
            }
        }

        // Check for a double punch
        odds = PunchAttackAction.toHit(game, from.getId(), to,
                PunchAttackAction.LEFT);
        ToHitData odds_a = PunchAttackAction.toHit(game, from.getId(), to,
                PunchAttackAction.RIGHT);
        if ((odds.getValue() != TargetRoll.IMPOSSIBLE)
                && (odds_a.getValue() != TargetRoll.IMPOSSIBLE)) {
            damage = PunchAttackAction.getDamageFor(from,
                    PunchAttackAction.LEFT, targetConvInfantry);
            dmg = Compute.oddsAbove(odds.getValue()) / 100.0 * damage;
            double dmg_a = Compute.oddsAbove(odds_a.getValue()) / 100.0
                    * damage;
            dmg += dmg_a;
            dmg *= punchThroughMod(to, location_table, target_arc, dmg,
                    dmg / 2.0);
            if (dmg > bestDmg) {
View Full Code Here

        double self_damage;
        double dmg;
        double coll_damage = 0.0;
        int damage;
        boolean targetConvInfantry = false;
        ToHitData odds = KickAttackAction.toHit(game, from.getId(), to, action);
        if (odds.getValue() == TargetRoll.IMPOSSIBLE) {
            return 0.0;
        }

        if ((to instanceof Infantry) && !(to instanceof BattleArmor)) {
            targetConvInfantry = true;
        }

        // Calculate collateral damage, due to possible target fall
        if (to instanceof Mech) {
            coll_damage = calculateFallingDamage(Compute.oddsAbove(odds
                    .getValue()) / 100.0, to);
        }

        damage = KickAttackAction
                .getDamageFor(from, action, targetConvInfantry);
        dmg = Compute.oddsAbove(odds.getValue()) / 100.0 * damage;
        // Adjust damage for targets armor
        dmg *= punchThroughMod(to, locTable, arc, dmg, dmg);
        // Calculate self damage, due to possible fall from missing a kick
        self_damage = calculateFallingDamage(1.0 - Compute.oddsAbove(odds
                .getValue()) / 100.0, from);
        if (from.getWalkMP() > 0) {
            self_damage = self_damage
                    * Math.sqrt(1.0 / from.getWalkMP() + from.getJumpMP());
        } else {
View Full Code Here

        // and add it into the game, temporarily
        client.game.addAction(saa);
    }

    private String calculateToHit(int weaponId, Targetable target) {
        ToHitData toHit;
        String str = "No Data";
        if (target != null && weaponId != -1 && ce() != null) {
            str = "";
            toHit = WeaponAttackAction.toHit(client.game, cen, target,
                    weaponId, Entity.LOC_NONE, IAimingModes.AIM_MODE_NONE);
            // str += "Target: " + target.toString();

            str += " Range: "
                    + ce().getPosition().distance(target.getPosition());

            Mounted m = ce().getEquipment(weaponId);
            if (m.isUsedThisRound()) {
                str += " Can't shoot: "
                        + Messages.getString("FiringDisplay.alreadyFired");
            } else if (m.getType().hasFlag(WeaponType.F_AUTO_TARGET)) {
                str += " Can't shoot: "
                        + Messages.getString("FiringDisplay.autoFiringWeapon");
            } else if (toHit.getValue() == TargetRoll.IMPOSSIBLE) {
                str += " Can't shoot: " + toHit.getValueAsString();
            } else if (toHit.getValue() == TargetRoll.AUTOMATIC_FAIL) {
                str += " Automatic Failure: " + toHit.getValueAsString();
            } else {
                str += " To hit: " + toHit.getValueAsString() + " ("
                        + Compute.oddsAbove(toHit.getValue()) + "%)";
            }
            str += " To Hit modifiers: " + toHit.getDesc();
        }
        return str;
    }
View Full Code Here

     * excessive data generated
     */
    private static float getDeployDamage(IGame g, WeaponAttackAction waa) {
        Entity attacker = g.getEntity(waa.getEntityId());
        Mounted weapon = attacker.getEquipment(waa.getWeaponId());
        ToHitData hitData = waa.toHit(g);
        if (hitData.getValue() == TargetRoll.IMPOSSIBLE
                || hitData.getValue() == TargetRoll.AUTOMATIC_FAIL) {
            return 0.0f;
        }

        float fChance = 0.0f;
        if (hitData.getValue() == TargetRoll.AUTOMATIC_SUCCESS) {
            fChance = 1.0f;
        } else {
            fChance = (float) Compute.oddsAbove(hitData.getValue()) / 100.0f;
        }

        // TODO : update for BattleArmor.

        float fDamage = 0.0f;
View Full Code Here

            Entity ent = server.getGame().getEntity(id);

            if (ent != null) {
                String str = "No valid targets.";
                boolean canHit = false;
                ToHitData thd;

                Vector<Entity> entList = server.getGame().getValidTargets(ent);
                Entity target;

                for (int i = 0; i < entList.size(); i++) {
                    target = entList.get(i);
                    thd = LosEffects.calculateLos(server.getGame(), id, target)
                            .losModifiers(server.getGame());
                    if (thd.getValue() != TargetRoll.IMPOSSIBLE) {
                        thd.setSideTable(target.sideTable(ent.getPosition()));

                        if (!canHit) {
                            str = "This entity(" + id
                                    + ") can shoot the following entities: \n";
                            canHit = true;
                        }
                        str = str + entList.get(i).getId()
                                + " at a to hit penalty of ";
                        str = str
                                + thd.getValue()
                                + ", at range " + ent.getPosition().distance(entList.get(i).getPosition()) + thd.getTableDesc() + ";\n"; //$NON-NLS-1$
                    }

                }

                server.sendServerChat(connId, str);
View Full Code Here

TOP

Related Classes of megamek.common.ToHitData

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.