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

📄 mtffile.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * MegaMek - Copyright (C) 2000-2002 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. *//* * MtfFile.java * * Created on April 7, 2002, 8:47 PM */package megamek.common.loaders;import java.io.*;import java.util.Hashtable;import java.util.Vector;import megamek.common.BipedMech;import megamek.common.CriticalSlot;import megamek.common.Engine;import megamek.common.Entity;import megamek.common.EquipmentType;import megamek.common.LocationFullException;import megamek.common.Mech;import megamek.common.Mounted;import megamek.common.QuadMech;import megamek.common.TechConstants;import megamek.common.WeaponType;/** * * @author  Ben * @version */public class MtfFile implements IMechLoader {    String version;    String name;    String model;    String chassisConfig;    String techBase;    String techYear;    String rulesLevel;    String tonnage;    String engine;    String internalType;    String myomerType;    String gyroType;    String cockpitType;    String heatSinks;    String walkMP;    String jumpMP;    String armorType;    String[] armorValues = new String[11];    String weaponCount;    String[] weaponData;    String[][] critData;    Hashtable hSharedEquip = new Hashtable();    Vector vSplitWeapons = new Vector();    public static final int locationOrder[] = { Mech.LOC_LARM, Mech.LOC_RARM,                                                Mech.LOC_LT, Mech.LOC_RT,                                                Mech.LOC_CT, Mech.LOC_HEAD,                                                Mech.LOC_LLEG, Mech.LOC_RLEG };    public static final int rearLocationOrder[] = { Mech.LOC_LT, Mech.LOC_RT,                                                    Mech.LOC_CT };    public static final String EMPTY = "-Empty-";    /** Creates new MtfFile */    public MtfFile(InputStream is) throws EntityLoadingException {        try {            BufferedReader r = new BufferedReader(new InputStreamReader(is));            version = r.readLine();            //Version 1.0: Initial version.            //Version 1.1: Added level 3 cockpit and gyro options.            if (!version.trim().equalsIgnoreCase("Version:1.0")                && !version.trim().equalsIgnoreCase("Version:1.1")) {                throw new EntityLoadingException("Wrong MTF file version.");            }            name = r.readLine();            model = r.readLine();            r.readLine();            chassisConfig = r.readLine();            techBase = r.readLine();            techYear = r.readLine();            rulesLevel = r.readLine();            r.readLine();            // The next line might either be blank or a system type.            String tmp = r.readLine();            while ((tmp != null) && (tmp.length() > 0)) {                if (tmp.startsWith("Cockpit:")) {                    cockpitType = tmp;                } else if (tmp.startsWith("Gyro:")) {                    gyroType = tmp;                } else if (tmp.startsWith("Mass:")) {                    tonnage = tmp;                } else if (tmp.startsWith("Engine:")) {                    engine = tmp;                } else if (tmp.startsWith("Structure:")) {                    internalType = tmp;                } else if (tmp.startsWith("Myomer:")) {                    myomerType = tmp;                }                tmp = r.readLine();            }            heatSinks = r.readLine();            walkMP = r.readLine();            jumpMP = r.readLine();            r.readLine();            armorType = r.readLine();            for (int x = 0; x < armorValues.length; x++) {                armorValues[x] = r.readLine();            }            r.readLine();            weaponCount = r.readLine();            int weapons = Integer.parseInt(weaponCount.substring(8));            weaponData = new String[weapons];            for(int i = 0; i < weapons; i++) {                weaponData[i] = r.readLine();            }            critData = new String[8][12];            for (int x = 0; x < locationOrder.length; x++) {                readCrits(r, locationOrder[x]);            }            r.close();        } catch (IOException ex) {            ex.printStackTrace();            throw new EntityLoadingException("I/O Error reading file");        } catch (StringIndexOutOfBoundsException ex) {            ex.printStackTrace();            throw new EntityLoadingException("StringIndexOutOfBoundsException reading file (format error)");        } catch (NumberFormatException ex) {            ex.printStackTrace();            throw new EntityLoadingException("NumberFormatException reading file (format error)");        }    }    private void readCrits(BufferedReader r, int loc) throws IOException {        r.readLine(); // blank line        r.readLine(); // location name.... verify?        for (int i = 0; i < 12; i++) {            critData[loc][i] = r.readLine();        }    }    public Entity getEntity() throws EntityLoadingException {        try {            Mech mech;            int iGyroType = Mech.GYRO_STANDARD;            try {                iGyroType = Mech.getGyroTypeForString(gyroType.substring(5));                if (iGyroType == Mech.GYRO_UNKNOWN)                    iGyroType = Mech.GYRO_STANDARD;            } catch (Exception e) {                iGyroType = Mech.GYRO_STANDARD;            }            int iCockpitType = Mech.COCKPIT_STANDARD;            try {                iCockpitType = Mech.getCockpitTypeForString(cockpitType.substring(8));                if (iCockpitType == Mech.COCKPIT_UNKNOWN)                    iCockpitType = Mech.COCKPIT_STANDARD;            } catch (Exception e) {                iCockpitType = Mech.COCKPIT_STANDARD;            }            if (chassisConfig.indexOf("Quad") != -1) {                mech = new QuadMech(iGyroType, iCockpitType);            } else {                mech = new BipedMech(iGyroType, iCockpitType);            }            // aarg!  those stupid sub-names in parenthesis screw everything up            // we may do something different in the future, but for now, I'm            // going to strip them out            int pindex = name.indexOf("(");            if (pindex == -1) {                mech.setChassis(name.trim());            } else {                mech.setChassis(name.substring(0, pindex - 1).trim());            }            mech.setModel(model.trim());            mech.setYear(Integer.parseInt(this.techYear.substring(4).trim()));            if (chassisConfig.indexOf("Omni") != -1) {                mech.setOmni(true);            }            if (techBase.substring(9).trim().equals("Inner Sphere")) {                switch (Integer.parseInt(rulesLevel.substring(12).trim())) {                case 1 :                    mech.setTechLevel(TechConstants.T_IS_LEVEL_1);                    break;                case 2 :                    mech.setTechLevel(TechConstants.T_IS_LEVEL_2);                    break;                case 3 :                    mech.setTechLevel(TechConstants.T_IS_LEVEL_3);                    break;                default :                    throw new EntityLoadingException("Unsupported tech level: " + rulesLevel.substring(12).trim());                }            } else if (techBase.substring(9).trim().equals("Clan")) {                switch (Integer.parseInt(rulesLevel.substring(12).trim())) {                case 2 :                    mech.setTechLevel(TechConstants.T_CLAN_LEVEL_2);                    break;                case 3 :                    mech.setTechLevel(TechConstants.T_CLAN_LEVEL_3);                    break;                default :                    throw new EntityLoadingException("Unsupported tech level: " + rulesLevel.substring(12).trim());                }            } else if (techBase.substring(9).trim().equals("Mixed (IS Chassis)")) {                mech.setTechLevel(TechConstants.T_IS_LEVEL_3);                mech.setMixedTech(true);            } else if (techBase.substring(9).trim().equals("Mixed (Clan Chassis)")) {

⌨️ 快捷键说明

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