⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 physicalcalculator.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * MegaMek - Copyright (C) 2003,2004,2005 Ben Mazur (bmazur@sev.org) * *  This program is free software; you can redistribute it and/or modify it *  under the terms of the GNU General Public License as published by the Free *  Software Foundation; either version 2 of the License, or (at your option) *  any later version. * *  This program is distributed in the hope that it will be useful, but *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *  for more details. */package megamek.client.bot;import megamek.common.BattleArmor;import megamek.common.Compute;import megamek.common.Coords;import megamek.common.Entity;import megamek.common.IGame;import megamek.common.IHex;import megamek.common.INarcPod;import megamek.common.Infantry;import megamek.common.Mech;import megamek.common.Mounted;import megamek.common.Protomech;import megamek.common.Tank;import megamek.common.Terrains;import megamek.common.ToHitData;import megamek.common.actions.BrushOffAttackAction;import megamek.common.actions.ClubAttackAction;import megamek.common.actions.KickAttackAction;import megamek.common.actions.PunchAttackAction;import megamek.common.actions.PushAttackAction;import java.util.Enumeration;public final class PhysicalCalculator {    private PhysicalCalculator() {        super();        //should never call this    }    static PhysicalOption calculatePhysicalTurn(TestBot bot) {        int entNum = bot.game.getFirstEntityNum();        int first = entNum;        do {            // take the first entity that can do an attack            Entity en = bot.game.getEntity(entNum);            PhysicalOption bestAttack = getBestPhysical(en, bot.game);            if (bestAttack != null) {                return bestAttack;            } // End no-attack            entNum = bot.game.getNextEntityNum(entNum);        } while (entNum != -1 && entNum != first);        // Didn't find any physical attack.        return null;    }    static PhysicalOption getBestPhysical(Entity entity, IGame game) {        // Infantry can't conduct physical attacks.        if (entity instanceof Infantry) {            return null;        }        // if you're charging, it's already declared        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() != ToHitData.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() != ToHitData.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;                Enumeration pod_list = entity.getINarcPodsAttached();                best_pod = (INarcPod) pod_list.nextElement();                for (pod_list = entity.getINarcPodsAttached(); pod_list.hasMoreElements();) {                    test_ranking = 1.0;                    test_pod = (INarcPod) pod_list.nextElement();                    // 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() != ToHitData.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() != ToHitData.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,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -