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

📄 equipmenttype.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public int getModesCount() {        if (modes != null)            return modes.size();        return 0;    }    /**     *      * @return <code>Enumeration</code> of the <code>EquipmentMode</code>      * that this type of equipment can be in     */    public Enumeration getModes() {        if (modes != null) {            return modes.elements();        }		return new Enumeration() {		    public boolean hasMoreElements() {		        return false;		    }		    public Object nextElement() {		        return null;		    }		    		};    }    /**     * Sets the modes that this type of equipment can be in. By default the EquipmentType     * doesn't have the modes, so don't try to call this method with null or empty argument.      * @param modes non null, non empty list of available mode names.     */    protected void setModes(String[] modes) {        megamek.debug.Assert.assertTrue(modes != null && modes.length >= 0,                 "List of modes must not be null or empty");        Vector newModes = new Vector(modes.length);        for (int i = 0 ,l = modes.length; i < l; i++) {            newModes.addElement(EquipmentMode.getMode(modes[i]));        }        this.modes = newModes;    }    /**     * <p>Returns the mode number <code>modeNum</code> from the list of modes available     * for this type of equipment. Modes are numbered from <code>0<code> to      * <code>getModesCount()-1</code>     * <p>Fails if this type of the equipment doesn't have modes, or given mode is out of     * the valid range.         * @param modeNum     * @return mode number <code>modeNum</code> from the list of modes available     * for this type of equipment.     * @see #hasModes()     */    public EquipmentMode getMode(int modeNum) {        megamek.debug.Assert.assertTrue(modes != null && modeNum >= 0 && modeNum < modes.size());        return (EquipmentMode)modes.elementAt(modeNum);    }        public void setInstantModeSwitch(boolean b) {        instantModeSwitch = b;    }        public boolean hasInstantModeSwitch() {        return instantModeSwitch;    }    public void setInternalName(String s) {        internalName = s;        addLookupName(s);    }    public void addLookupName(String s) {        EquipmentType.lookupHash.put(s, this); // static variable        namesVector.addElement(s); // member variable    }    public static EquipmentType get(String key) {        if (null == EquipmentType.lookupHash) {            EquipmentType.initializeTypes();        }        return (EquipmentType) EquipmentType.lookupHash.get(key);    }    public Enumeration getNames() {        return namesVector.elements();    }    public static void initializeTypes() {        EquipmentType.allTypes = new Vector();        EquipmentType.lookupHash = new Hashtable();                // will I need any others?        WeaponType.initializeTypes();        AmmoType.initializeTypes();        MiscType.initializeTypes();    }        public static Enumeration getAllTypes() {        if ( null == EquipmentType.allTypes ) {            EquipmentType.initializeTypes();        }        return EquipmentType.allTypes.elements();    }        protected static void addType(EquipmentType type) {        if ( null == EquipmentType.allTypes ) {            EquipmentType.initializeTypes();        }        EquipmentType.allTypes.addElement(type);    }    public static int getArmorType(String inType) {        EquipmentType et = EquipmentType.get(inType);        if (et != null) {            for (int x=0; x<armorNames.length; x++) {                if (armorNames[x].equals(et.getInternalName()))                    return x;            }        }        return T_ARMOR_UNKNOWN;    }    public static  String getArmorTypeName(int armorType) {        if ((armorType < 0) || (armorType >= armorNames.length))            return "UNKNOWN";        return armorNames[armorType];    }    public static int getStructureType(String inType) {        EquipmentType et = EquipmentType.get(inType);        if (et != null) {            for (int x=0; x<structureNames.length; x++) {                if (structureNames[x].equals(et.getInternalName()))                    return x;            }        }        return T_STRUCTURE_UNKNOWN;    }    public static  String getStructureTypeName(int structureType) {        if ((structureType < 0) || (structureType >= structureNames.length))            return "UNKNOWN";        return structureNames[structureType];    }    /**     * @return The C-Bill cost of the piece of equipment.     */    public double getCost() {        return cost;    }    public static double getArmorCost(int inArmor) {        if ((inArmor < 0) || (inArmor >= armorCosts.length))            return -1;        return armorCosts[inArmor];    }    public static double getStructureCost(int inStructure) {        if ((inStructure < 0) || (inStructure >= structureCosts.length))            return -1;        return structureCosts[inStructure];    }    public static double getArmorPointMultiplier(int inArmor) {        return getArmorPointMultiplier(inArmor, TechConstants.T_IS_LEVEL_2);    }    public static double getArmorPointMultiplier(int inArmor, int inTechLevel) {        return getArmorPointMultiplier(inArmor, ((inTechLevel == TechConstants.T_CLAN_LEVEL_2) || (inTechLevel == TechConstants.T_CLAN_LEVEL_3)));    }    public static double getArmorPointMultiplier(int inArmor, boolean clanArmor) {        if ((inArmor < 0) || (inArmor >= armorPointMultipliers.length))            return POINT_MULTIPLIER_UNKNOWN;        if ((inArmor == T_ARMOR_FERRO_FIBROUS) && clanArmor)            return POINT_MULTIPLIER_CLAN_FF;        return armorPointMultipliers[inArmor];    }        //stuff like hatchets, which depend on an unknown quality (usually tonnage of the unit.)    //entity is whatever has this item    public int resolveVariableCost(Entity entity) {        int cost=0;        if(this instanceof MiscType) {            if(this.hasFlag(MiscType.F_MASC)) {                if (hasSubType(MiscType.S_SUPERCHARGER)) {                    Engine e = entity.getEngine();                    if(e == null) cost = 0;                    cost = e.getRating() * 10000;                } else {                    int mascTonnage=0;                    if (this.getInternalName().equals("ISMASC")) {                        mascTonnage = Math.round(entity.getWeight() / 20.0f);                    } else if (this.getInternalName().equals("CLMASC")) {                        mascTonnage = Math.round(entity.getWeight() / 25.0f);                    }                    cost=entity.getEngine().getRating() * mascTonnage * 1000;                }            } else if(this.hasFlag(MiscType.F_TARGCOMP)) {                int tCompTons=0;                float fTons = 0.0f;                for(Mounted mo : entity.getWeaponList()) {                    WeaponType wt = (WeaponType)mo.getType();                    if (wt.hasFlag(WeaponType.F_DIRECT_FIRE))                    fTons += wt.getTonnage(entity);                }                if (this.getInternalName().equals("ISTargeting Computer")) {                    tCompTons=(int)Math.ceil(fTons / 4.0f);                } else if (this.getInternalName().equals("CLTargeting Computer")) {                    tCompTons=(int)Math.ceil(fTons / 5.0f);                }                cost=tCompTons*10000;            } else if (this.hasFlag(MiscType.F_CLUB)                    && (this.hasSubType(MiscType.S_HATCHET)                    || this.hasSubType(MiscType.S_MACE_THB))) {                int hatchetTons=(int) Math.ceil(entity.getWeight() / 15.0);                cost=hatchetTons*5000;            } else if (this.hasFlag(MiscType.F_CLUB)                    && this.hasSubType(MiscType.S_SWORD)) {                int swordTons=(int) Math.ceil(entity.getWeight() / 15.0);                cost=swordTons*10000;            }        } else {            if(cost==0) {                //if we don't know what it is...                System.out.println("I don't know how much " + this.name + " costs.");            }        }        return cost;    }    public boolean equals(EquipmentType e) {        if (e != null && this.internalName.equals(e.internalName))            return true;        return false;    }}

⌨️ 快捷键说明

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