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

📄 mech.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * 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.common;import java.io.PrintWriter;import java.io.Serializable;import java.text.NumberFormat;import java.util.Vector;import megamek.common.loaders.MtfFile;import megamek.common.preference.PreferenceManager;import megamek.common.util.StringUtil;/** * You know what mechs are, silly. */public abstract class Mech    extends Entity    implements Serializable{    public static final int      NUM_MECH_LOCATIONS = 8;    // system designators for critical hits    public static final int        SYSTEM_LIFE_SUPPORT      = 0;    public static final int        SYSTEM_SENSORS           = 1;    public static final int        SYSTEM_COCKPIT           = 2;    public static final int        SYSTEM_ENGINE            = 3;    public static final int        SYSTEM_GYRO              = 4;    // actutors are systems too, for now    public static final int        ACTUATOR_SHOULDER        = 7;    public static final int        ACTUATOR_UPPER_ARM       = 8;    public static final int        ACTUATOR_LOWER_ARM       = 9;    public static final int        ACTUATOR_HAND            = 10;    public static final int        ACTUATOR_HIP             = 11;    public static final int        ACTUATOR_UPPER_LEG       = 12;    public static final int        ACTUATOR_LOWER_LEG       = 13;    public static final int        ACTUATOR_FOOT            = 14;        public static final String systemNames[] = {"Life Support",                                                "Sensors",                                                "Cockpit",                                                "Engine",                                                "Gyro",                                                null,                                                null,                                                "Shoulder",                                                "Upper Arm",                                                "Lower Arm",                                                "Hand",                                                "Hip",                                                "Upper Leg",                                                "Lower Leg",                                                "Foot"};    // locations    public static final int        LOC_HEAD                 = 0;    public static final int        LOC_CT                   = 1;    public static final int        LOC_RT                   = 2;    public static final int        LOC_LT                   = 3;    public static final int        LOC_RARM                 = 4;    public static final int        LOC_LARM                 = 5;    public static final int        LOC_RLEG                 = 6;    public static final int        LOC_LLEG                 = 7;    // cockpit status    public static final int        COCKPIT_OFF              = 0;    public static final int        COCKPIT_ON               = 1;    public static final int        COCKPIT_AIMED_SHOT       = 2;    // gyro types    public static final int         GYRO_UNKNOWN            = -1;    public static final int         GYRO_STANDARD           = 0;    public static final int         GYRO_XL                 = 1;    public static final int         GYRO_COMPACT            = 2;    public static final int         GYRO_HEAVY_DUTY         = 3;    public static final String[]    GYRO_STRING = {"Standard Gyro",                                                   "XL Gyro",                                                   "Compact Gyro",                                                   "Heavy Duty Gyro"};    public static final String[]    GYRO_SHORT_STRING = {"Standard",                                                         "XL",                                                         "Compact",                                                        "Heavy Duty"};    // cockpit types    public static final int         COCKPIT_UNKNOWN             = -1;    public static final int         COCKPIT_STANDARD            = 0;    public static final int         COCKPIT_TORSO_MOUNTED       = 1;    public static final int         COCKPIT_SMALL               = 2;    public static final int         COCKPIT_COMMAND_CONSOLE     = 3;    public static final int         COCKPIT_DUAL                = 4;    public static final String[]    COCKPIT_STRING = {"Standard Cockpit",                                                      "Torso-Mounted Cockpit",                                                      "Small Cockpit",                                                      "Command Console",                                                      "Dual Cockpit"};    public static final String[]    COCKPIT_SHORT_STRING = {"Standard",                                                            "Torso Mounted",                                                            "Small",                                                            "Command Console",                                                            "Dual"};    /**     * The internal name for Mek Stealth systems.     */    public static final String STEALTH = "Stealth";    public static final String NULLSIG = "Mek Null Signature System";    //jump types    public static final int         JUMP_UNKNOWN = -1;    public static final int         JUMP_NONE = 0;    public static final int         JUMP_STANDARD = 1;    public static final int         JUMP_IMPROVED = 2;    public static final int         JUMP_BOOSTER = 3;    public static final int         JUMP_DISPOSABLE = 4;    //Some "has" items only need be determined once    public static final int         HAS_FALSE = -1;    public static final int         HAS_UNKNOWN = 0;    public static final int         HAS_TRUE = 1;    // rear armor    private int[] rearArmor;    private int[] orig_rearArmor;    private static int[] MASC_FAILURE = {2, 4, 6, 10, 12, 12, 12};    private int nMASCLevel = 0; // MASCLevel is the # of turns MASC has been used previously    private boolean bMASCWentUp = false;    private boolean usedMASC = false; // Has masc been used?    private int sinksOn = -1;    private int sinksOnNextRound = -1;    private boolean autoEject = true;    private int cockpitStatus = COCKPIT_ON;    private int cockpitStatusNextRound = COCKPIT_ON;    private int jumpType = JUMP_UNKNOWN;    private int gyroType = GYRO_STANDARD;    private int cockpitType = COCKPIT_STANDARD;    private boolean hasCowl = false;    private int cowlArmor = 0;    private int hasLaserHeatSinks = HAS_UNKNOWN;        // For grapple attacks    private int grappled_id = Entity.NONE;    private boolean isGrappleAttacker = false;    private static final NumberFormat commafy = NumberFormat.getInstance();    /**     * Construct a new, blank, mech.     */    public Mech() {        this(Mech.GYRO_STANDARD, Mech.COCKPIT_STANDARD);    }    public Mech(int inGyroType, int inCockpitType) {        super();        gyroType = inGyroType;        cockpitType = inCockpitType;        rearArmor = new int[locations()];        orig_rearArmor = new int[locations()];        for (int i = 0; i < locations(); i++) {            if (!hasRearArmor(i)) {              initializeRearArmor(IArmorState.ARMOR_NA, i);            }        }        // Standard leg crits        setCritical(LOC_RLEG, 0, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, ACTUATOR_HIP));        setCritical(LOC_RLEG, 1, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, ACTUATOR_UPPER_LEG));        setCritical(LOC_RLEG, 2, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, ACTUATOR_LOWER_LEG));        setCritical(LOC_RLEG, 3, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, ACTUATOR_FOOT));        setCritical(LOC_LLEG, 0, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, ACTUATOR_HIP));        setCritical(LOC_LLEG, 1, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, ACTUATOR_UPPER_LEG));        setCritical(LOC_LLEG, 2, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, ACTUATOR_LOWER_LEG));        setCritical(LOC_LLEG, 3, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, ACTUATOR_FOOT));        // Player setting specify whether their Meks' automatic        // ejection systems are disabled by default or not.        this.autoEject = !PreferenceManager.getClientPreferences().defaultAutoejectDisabled();    }    public void setCowl (int armor) {        hasCowl = true;        cowlArmor = armor;    }        public int getCowlArmor () {        if (hasCowl) return cowlArmor;        return 0;    }        public boolean hasCowl () {        return hasCowl;    }        // Damage the cowl. Returns amount of excess damage    public int damageCowl (int amount) {        if (hasCowl) {            if (amount<cowlArmor) {                cowlArmor -= amount;                return 0;            }			amount -= cowlArmor;			cowlArmor = 0;			return amount;        }		return amount; // No cowl - return full damage    }    /**     * Returns the location that transferred damage or crits will go to from a given location.     */    public static int getInnerLocation(int location) {        switch(location) {            case Mech.LOC_RT :            case Mech.LOC_LT :                return Mech.LOC_CT;            case Mech.LOC_LLEG :            case Mech.LOC_LARM :                return Mech.LOC_LT;            case Mech.LOC_RLEG :            case Mech.LOC_RARM :                return Mech.LOC_RT;            default:                return location;        }    }    /**     * Returns the location with the most restrictive firing arc for a weapon.     */    public static int mostRestrictiveLoc(int location1, int location2) {        if (location1 == location2) {            return location1;        } else if (Mech.restrictScore(location1) >= Mech.restrictScore(location2)) {            return location1;        } else {            return location2;        }    }    public static int leastRestrictiveLoc(int location1, int location2) {        if (location1==location2) {            return location2;        } else if (Mech.restrictScore(location1) >= Mech.restrictScore(location2)) {            return location2;        } else {            return location1;        }    }        /**     * Helper function designed to give relative restrictiveness of locations.     * Used for finding the most restrictive firing arc for a weapon.     */    public static int restrictScore(int location) {        switch(location) {            case Mech.LOC_RARM :            case Mech.LOC_LARM :                return 0;            case Mech.LOC_RT :            case Mech.LOC_LT :                return 1;            case Mech.LOC_CT :                return 2;            default :                return 3;        }    }    /**     * Get the number of turns MASC has been used continuously.     * <p/>     * This method should <strong>only</strong> be used during serialization.     *     * @return  the <code>int</code> number of turns MASC has been used.     */    public int getMASCTurns() {        return nMASCLevel;    }    /**     * Set the number of turns MASC has been used continuously.     * <p/>     * This method should <strong>only</strong> be used during deserialization.     *     * @param   turns The <code>int</code> number of turns MASC has been used.     */    public void setMASCTurns( int turns ) {        nMASCLevel = turns;    }    /**     * Determine if MASC has been used this turn.     * <p/>     * This method should <strong>only</strong> be used during serialization.     *     * @return  <code>true</code> if MASC has been used.     */    public boolean isMASCUsed() {        return usedMASC;    }    /**     * Set whether MASC has been used.     * <p/>     * This method should <strong>only</strong> be used during deserialization.     *     * @param   used The <code>boolean</code> whether MASC has been used.     */    public void setMASCUsed( boolean used ) {        usedMASC = used;    }    public int getMASCTarget() {        return MASC_FAILURE[nMASCLevel] + 1;    }    public boolean checkForMASCFailure(MovePath md, Vector vDesc, Vector vCriticals) {        if (md.hasActiveMASC()) {            Report r;            boolean bFailure = false;            // If usedMASC is already set, then we've already checked MASC            // this turn.  If we succeded before, return false.            // If we failed before, the MASC was destroyed, and we wouldn't            // have gotten here (hasActiveMASC would return false)            if (!usedMASC) {                Mounted equip = getMASC();                int nRoll = Compute.d6(2);

⌨️ 快捷键说明

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