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

📄 tdbfile.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            // add any heat sinks not allocated            mech.addEngineSinks(expectedSinks - mech.heatSinks(), dblSinks);                        // set targeting system            if(targSysStr.startsWith("Long-Range")) {                mech.setTargSysType(MiscType.T_TARGSYS_LONGRANGE);            } else if(targSysStr.startsWith("Short-Range")) {                mech.setTargSysType(MiscType.T_TARGSYS_SHORTRANGE);            } else if(targSysStr.startsWith("Variable-Range")) {                mech.setTargSysType(MiscType.T_TARGSYS_VARIABLE_RANGE);            } else if(targSysStr.startsWith("Anti-Aircraft")) {                mech.setTargSysType(MiscType.T_TARGSYS_ANTI_AIR);            } else if(targSysStr.startsWith("Multi-Trac")) {                mech.setTargSysType(MiscType.T_TARGSYS_MULTI_TRAC);            } else if(targSysStr.startsWith("Multi-Trac II")) {                mech.setTargSysType(MiscType.T_TARGSYS_MULTI_TRAC_II);            } else if(targSysStr.startsWith("Targeting Computer")) {                mech.setTargSysType(MiscType.T_TARGSYS_TARGCOMP);            }            return mech;        } catch (NumberFormatException ex) {            throw new EntityLoadingException("NumberFormatException parsing file");        } catch (NullPointerException ex) {            throw new EntityLoadingException("NullPointerException parsing file");        } catch (StringIndexOutOfBoundsException ex) {            throw new EntityLoadingException("StringIndexOutOfBoundsException parsing file");        }    }    private void parseCrits(Mech mech, int loc) throws EntityLoadingException {        // check for removed arm actuators        if (!(mech instanceof QuadMech)) {            if (loc == Mech.LOC_LARM || loc == Mech.LOC_RARM) {                if (!critData[loc][3][0].equals("Hand Actuator")) {                    mech.setCritical(loc, 3, null);                }                if (!critData[loc][2][0].equals("Lower Arm Actuator")) {                    mech.setCritical(loc, 2, null);                }            }        }        // go thru file, add weapons        for (int i = 0; i < mech.getNumberOfCriticals(loc); i++) {            // if the slot's full already, skip it.            if (mech.getCritical(loc, i) != null) {                continue;            }            // parse out and add the critical            String critName = critData[loc][i][0];            boolean rearMounted = true;            if (critData[loc][i][1] == null || !isRearMounted[Integer.parseInt(critData[loc][i][1])]) {                rearMounted = false;            }            boolean split = true;            if (critData[loc][i][1] == null || !isSplit[Integer.parseInt(critData[loc][i][1])]) {                split = false;            }            if (critName.equalsIgnoreCase("Armored Cowl")) {                mech.setCowl(5);            }            if (critName.indexOf("Engine") != -1) {                mech.setCritical(loc,i, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_ENGINE));                continue;            }            if (critName.indexOf("Gyro") != -1) {                mech.setCritical(loc,i, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_GYRO));                continue;            }            if (critName.indexOf("Life Support") != -1) {                mech.setCritical(loc,i, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_LIFE_SUPPORT));                continue;            }            if (critName.indexOf("Sensors") != -1) {                mech.setCritical(loc,i, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_SENSORS));                continue;            }            if (critName.indexOf("Cockpit") != -1) {                mech.setCritical(loc,i, new CriticalSlot(CriticalSlot.TYPE_SYSTEM, Mech.SYSTEM_COCKPIT));                continue;            }            if (critName.endsWith("[LRM]") || critName.endsWith("[SRM]")) {                // This is a lame kludge for The Drawing Board, which                //  identifies which type of missle weapon an                //  Artemis IV system goes with.                critName = critName.substring(0,14);            }            if (critName.endsWith("- Artemis IV")) {                // Ugh, another lame kludge to allow for loading of                //  The Drawing Board's specially marked Artemis IV                //  missle ammo.  The only real game difference is                //  c-bill cost, which we don't care about anyway.                critName = critName.substring(0,critName.indexOf(" - Artemis IV"));            }            if (critName.endsWith("- Narc")) {                // Yet another lame kludge to allow for loading of                //  The Drawing Board's specially marked Narc                //  missle ammo.                critName = critName.substring(0,critName.indexOf(" - Narc"));            }            if (critName.equals("(C) Endosteel")) {                // MegaMek determines whether Endo Steel is IS or Clan                //  type by techbase of mech.                critName = critName.substring(4);            }            if (critName.equals("(C) Ferro-Fibrous Armor")) {                // MegaMek determines whether FF Armor is IS or Clan                //  type by techbase of mech.                critName = critName.substring(4);            }            try {                String hashPrefix;                if (critName.startsWith("(C)")) {                    //equipment specifically marked as clan                    hashPrefix = "Clan ";                    critName = critName.substring(4);                } else if (critName.startsWith("(IS)")) {                    //equipment specifically marked as inner sphere                    hashPrefix = "IS ";                    critName = critName.substring(5);                } else if (mech.isClan()) {                    //assume equipment is clan because mech is clan                    hashPrefix = "Clan ";                } else {                    //assume equipment is inner sphere                    hashPrefix = "IS ";                }                EquipmentType etype = EquipmentType.get(hashPrefix + critName);                if (etype == null) {                    //try without prefix                    etype = EquipmentType.get(critName);                }                if (etype != null) {                    if (etype.isSpreadable()) {                        // do we already have one of these?  Key on Type                        Mounted m = (Mounted)hSharedEquip.get(etype);                        if (m != null) {                            // use the existing one                            mech.addCritical(loc, new CriticalSlot(CriticalSlot.TYPE_EQUIPMENT,                                                                   mech.getEquipmentNum(m), etype.isHittable()));                            continue;                        }						m = mech.addEquipment(etype, loc, rearMounted);						hSharedEquip.put(etype, m);                    }                    else if (etype instanceof WeaponType &&                            etype.hasFlag(WeaponType.F_SPLITABLE)) {                        // do we already have this one in this or an outer location?                        Mounted m = null;                        boolean bFound = false;                        for (int x = 0, n = vSplitWeapons.size(); x < n; x++) {                            m = (Mounted)vSplitWeapons.elementAt(x);                            int nLoc = m.getLocation();                            if ((nLoc == loc || loc == Mech.getInnerLocation(nLoc))                                && m.getType() == etype) {                                bFound = true;                                break;                            }                        }                        if (bFound) {                            m.setFoundCrits(m.getFoundCrits() + 1);                            if (m.getFoundCrits() >= etype.getCriticals(mech)) {                                vSplitWeapons.removeElement(m);                            }                            // if we're in a new location, set the                            // weapon as split                            if (loc != m.getLocation()) {                                m.setSplit(true);                            }                            // give the most restrictive location for arcs                            int help=m.getLocation();                            m.setLocation(Mech.mostRestrictiveLoc(                                    loc, help));                            if (loc!=help) {                                m.setSecondLocation(Mech.leastRestrictiveLoc(                                    loc, help));                            }                        }                        else {                            // make a new one                            m = new Mounted(mech, etype);                            m.setFoundCrits(1);                            vSplitWeapons.addElement(m);                        }                        mech.addEquipment(m, loc, rearMounted);                    }                    else {                        mech.addEquipment(etype, loc, rearMounted);                    }                } else {                    if (!critName.equals("Empty")) {                        //Can't load this piece of equipment!                        // Add it to the list so we can show the user.                        mech.addFailedEquipment(critName);                        // Make the failed equipment an empty slot                        critData[loc][i][0] = "Empty";                        critData[loc][i][1] = null;                        // Compact criticals again                        compactCriticals(mech, loc);                        // Re-parse the same slot, since the compacting                        //  could have moved new equipment to this slot                        i--;                    }                }            } catch (LocationFullException ex) {                throw new EntityLoadingException(ex.getMessage());            }        }    }    /**     * This function moves all "empty" slots to the end of a location's     * critical list.     *     * MegaMek adds equipment to the first empty slot available in a     * location.  This means that any "holes" (empty slots not at the     * end of a location), will cause the file crits and MegaMek's crits     * to become out of sync.     */    private void compactCriticals(Mech mech) {        for (int loc = 0; loc < mech.locations(); loc++) {            compactCriticals(mech, loc);        }    }    private void compactCriticals(Mech mech, int loc) {        if (loc == Mech.LOC_HEAD) {            //This location has an empty slot inbetween systems crits            // which will mess up parsing if compacted.            return;        }        int firstEmpty = -1;        for (int slot = 0; slot < mech.getNumberOfCriticals(loc); slot++) {            if (firstEmpty == -1 && critData[loc][slot][0].equals("Empty")) {                firstEmpty = slot;            }            if (firstEmpty != -1 && !critData[loc][slot][0].equals("Empty")) {                //move this to the first empty slot                critData[loc][firstEmpty][0] = critData[loc][slot][0];                critData[loc][firstEmpty][1] = critData[loc][slot][1];                //mark the old slot empty                critData[loc][slot][0] = "Empty";                critData[loc][slot][1] = null;                //restart just after the moved slot's new location                slot = firstEmpty;                firstEmpty = -1;            }        }    }}

⌨️ 快捷键说明

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