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

📄 centity.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * MegaMek - * Copyright (C) 2000,2001,2002,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.AmmoType;import megamek.common.BattleArmor;import megamek.common.Compute;import megamek.common.Coords;import megamek.common.Entity;import megamek.common.GunEmplacement;import megamek.common.Infantry;import megamek.common.Mech;import megamek.common.MiscType;import megamek.common.Mounted;import megamek.common.MovePath;import megamek.common.Protomech;import megamek.common.Tank;import megamek.common.Terrains;import megamek.common.ToHitData;import megamek.common.WeaponType;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.Iterator;import java.util.HashMap;public class CEntity {    static class Table extends HashMap {        private TestBot tb;        public Table(TestBot tb) {            this.tb = tb;        }        public void put(CEntity es) {            this.put(es.getKey(), es);        }        public CEntity get(Entity es) {            CEntity result = null;            if ((result = (CEntity) super.get(new Integer(es.getId()))) == null) {                result = new CEntity(es, tb);                this.put(result);            }            return result;        }        public CEntity get(int id) {            return (CEntity) get(new Integer(id));        }    }    // Armor values based on [ToHitData.SIDE_XXX][location static int]    // Locations are as defined in static variables in various unit type classes    // Values are the odds (out of 1.00) of rolling that location on the to-hit table        // Tank armor is either the side hit or the turret    final static double TANK_ARMOR[][] = {             { 0, 1.0, 0, 0, 0 },             { 0, 0, 0, 0, 1.0 },             { 0, 0, 0, 1.0, 0 },             { 0, 0, 1.0, 0, 0 }    };    final static double TANK_WT_ARMOR[][] = {             { 0, 31.0 / 36, 0, 0, 0, 5.0 / 36 },             { 0, 0, 0, 0, 31.0 / 36, 5.0 / 36 },             { 0, 0, 0, 31.0 / 36, 0, 5.0 / 36 },             { 0, 0, 31.0 / 36, 0, 0, 5.0 / 36 }    };        // Infantry don't have a facing.  In fact, they don't have armor...    final static double INFANTRY_ARMOR[][] = {             { 1.0 },             { 1.0 },             { 1.0 },             { 1.0 }    };        // Battle armor units have multiple suits    final static double ISBA_ARMOR[][] = {             { 0.25, 0.25, 0.25, 0.25 },             { 0.25, 0.25, 0.25, 0.25 },             { 0.25, 0.25, 0.25, 0.25 },             { 0.25, 0.25, 0.25, 0.25 }    };    final static double CLBA_ARMOR[][] = {         { 0.2, 0.2, 0.2, 0.2, 0.2 },         { 0.2, 0.2, 0.2, 0.2, 0.2 },         { 0.2, 0.2, 0.2, 0.2, 0.2 },         { 0.2, 0.2, 0.2, 0.2, 0.2 }    };    final static double PROTOMECH_ARMOR[][] = {         { 1.0 / 31, 16.0 / 31, 3.0 / 31, 3.0 / 31, 8.0 / 31 },         { 1.0 /31, 16.0 / 31, 3.0 / 31, 3.0 / 31, 8.0 / 31 },         { 1.0 /31, 16.0 / 31, 3.0 / 31, 3.0 / 31, 8.0 / 31 },         { 1.0 /31, 16.0 / 31, 3.0 / 31, 3.0 / 31, 8.0 / 31 }    };    final static double PROTOMECH_MG_ARMOR[][] = {         { 1.0 / 32, 16.0 / 32, 3.0 / 32, 3.0 / 32, 8.0 / 32, 1.0 / 32 },         { 1.0 / 31, 16.0 / 32, 3.0 / 32, 3.0 / 32, 8.0 / 32, 1.0 / 32 },         { 1.0 / 31, 16.0 / 32, 3.0 / 32, 3.0 / 32, 8.0 / 32, 1.0 / 32 },         { 1.0 / 31, 16.0 / 32, 3.0 / 32, 3.0 / 32, 8.0 / 32, 1.0 / 32 }    };    final static double MECH_ARMOR[][] = {         { 1.0 / 36, 7.0 / 36, 6.0 / 36, 6.0 / 36, 4.0 / 36, 4.0 / 36, 4.0 / 36, 4.0 / 36 },         { 1.0 / 36, 7.0 / 36, 6.0 / 36, 6.0 / 36, 4.0 / 36, 4.0 / 36, 4.0 / 36, 4.0 / 36 },         { 1.0 / 36, 6.0 / 36, 4.0 / 36, 7.0 / 36, 2.0 / 36, 6.0 / 36, 2.0 / 36, 8.0 / 36 },         { 1.0 / 36, 6.0 / 36, 7.0 / 36, 4.0 / 36, 6.0 / 36, 2.0 / 36, 8.0 / 36, 2.0 / 36 }    };    final static double GUN_EMPLACEMENT_ARMOR[][] = {         { 1.0 / 4, 0, 0, 0 },         { 1.0 / 4, 0, 0, 0 },         { 1.0 / 4, 0, 0, 0 },         { 1.0 / 4, 0, 0, 0 }    };    final static double GUN_EMPLACEMENT_TURRET_ARMOR[][] = {         { 1.0 / 3, 0, 0, 0, 5.0 / 36 },         { 1.0 / 3, 0, 0, 0, 5.0 / 36 },         { 1.0 / 3, 0, 0, 0, 5.0 / 36 },         { 1.0 / 3, 0, 0, 0, 5.0 / 36 }    };    public static final int MAX_RANGE = 36; // Updated to reflect longer ranges of level 2 equipment    public static final int MIN_BRACKET = 6;    public static final int OVERHEAT_NONE = 0;    public static final int OVERHEAT_LOW = 1;    public static final int OVERHEAT_HIGH = 2;    public static final int RANGE_SHORT = 0;    public static final int RANGE_MEDIUM = 1;    public static final int RANGE_LONG = 2;    public static final int RANGE_ALL = 3;    public static final int FIRST_ARC = 0;    public static final int LAST_PRIMARY_ARC = 3;    public static final int LAST_ARC = 4;    public static final int TT = 4;    public static final int LEFT_LEG = 0;    public static final int RIGHT_LEG = 1;    Entity entity;    MoveOption current;    MoveOption last; // set only after movement    private MoveOption.Table moves;    MoveOption.Table pass = new MoveOption.Table();    public int runMP;    public int jumpMP;    // For MASC/supercharger useage.  Set to true if failure is bad.    public boolean masc_threat = false;    boolean isPhysicalTarget = false;    // Heat characterization of this unit    int overheat = OVERHEAT_NONE;        // Ideal engagement ranges    int range = RANGE_ALL;    int long_range = 0;    double range_damages[] = new double[4];    int rd_bracket = 0;    double base_psr_odds = 1.0;    boolean hasTakenDamage = false;    public Strategy strategy = new Strategy();    // A subjective measure of the armor quality indexed by ToHitData    // location static variables (front, rear, left, right)    double[] armor_health = { 0, 0, 0, 0 };    double[] armor_percent = { 0, 0, 0, 0 };    // Armor averaged over all locations    // TODO: replace with array, one element per arc     double avg_armor = 0;    // Average internal structure    // TODO: replace with array, one element per arc    double avg_iarmor = 0;    //used to determine the utility of combining attacks    double[] expected_damage = { 0, 0, 0, 0 };    double[] possible_damage = { 0, 0, 0, 0 };    double[] leg_health = { 0, 0 };    double overall_armor_percent = 0.0;    double[][] damages = new double[6][MAX_RANGE + 1];    //the battle value of the mech    int bv;    //relative position in the enemy array    int enemy_num;    private TestBot tb;    boolean engaged = false; //am i fighting    boolean moved = false;    boolean justMoved = false;    // TSM equipped Mechs work better at 9+ heat, so flag if mounted    boolean tsm_offset = false;    int[] minRangeMods = new int[MIN_BRACKET+1];    public CEntity(Entity en, TestBot tb) {        this.entity = en;        this.tb = tb;        this.reset();    }    public Entity getEntity() {        return entity;    }    public boolean canMove() {        return (            entity.isSelectableThisTurn() && !(entity.isProne() && base_psr_odds < .2) && !entity.isImmobile());    }    public boolean justMoved() {        return (!moved && !entity.isSelectableThisTurn()) || justMoved;    }    public void reset() {        this.entity = tb.game.getEntity(this.entity.getId()); //fresh entity        for (int a = FIRST_ARC; a <= LAST_ARC; a++) {            Arrays.fill(this.damages[a], 0);        }        this.characterize();        this.resetPossibleDamage();        this.moves = null;        this.hasTakenDamage = false;        Arrays.fill(expected_damage, 0);        this.engaged = false;        this.moved = false;        this.isPhysicalTarget = false;    }    public void refresh() {        this.entity = tb.game.getEntity(this.entity.getId());        if (justMoved()) {            for (int a = FIRST_ARC; a <= LAST_ARC; a++) {                Arrays.fill(this.damages[a], 0);            }            this.characterize();            this.resetPossibleDamage();        }    }    public void resetPossibleDamage() {        Arrays.fill(possible_damage, 0);    }    public void characterize() {        this.entity = tb.game.getEntity(this.entity.getId());        this.current = new MoveOption(tb.game, this);        this.bv = entity.calculateBattleValue();        this.runMP = entity.getRunMP();        this.jumpMP = entity.getJumpMP();        this.overall_armor_percent = entity.getArmorRemainingPercent();        this.base_psr_odds = Compute.oddsAbove(entity.getBasePilotingRoll().getValue()) / 100;        // If this is a Mech equipped with TSM, push for the sweet spot at 9 heat        if (this.entity instanceof Mech){            if (((Mech)tb.game.getEntity(this.entity.getId())).hasTSM()){                this.tsm_offset = true;            }        }        //Calculate a modifer to damage based on the units current heat level        double heat_mod = .9; //these estimates are consistently too high        if (entity.heat > 7)            heat_mod = .8; //reduce effectiveness        if (entity.heat > 12)            heat_mod = .5;        if (this.tsm_offset){            if (entity.heat == 9){                heat_mod = 1.0;            }            if (entity.heat < 12 && entity.heat > 9){                heat_mod = 0.8;            }        }        if (entity.heat > 16)            heat_mod = .35;        int capacity = entity.getHeatCapacity();                int heat_total = 0;        int num_weapons = 0;

⌨️ 快捷键说明

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