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

📄 hmvfile.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
      fluff += "\n\rBattle History:\n\r";      buffer = new byte[readUnsignedShort(dis)];      dis.read(buffer);      fluff += new String(buffer);      fluffSize += new String(buffer).length();      fluff += "\n\rVariants:\n\r";      buffer = new byte[readUnsignedShort(dis)];      dis.read(buffer);      fluff += new String(buffer);      fluffSize += new String(buffer).length();      fluff += "\n\rFamous Vehicles and Pilots:\n\r";      buffer = new byte[readUnsignedShort(dis)];      dis.read(buffer);      fluff += new String(buffer);      fluffSize += new String(buffer).length();      fluff += "\n\rDeployment:\n\r";      buffer = new byte[readUnsignedShort(dis)];      dis.read(buffer);      fluff += new String(buffer);      fluffSize += new String(buffer).length();            dis.skipBytes(readUnsignedShort(dis)); //notes      //just a catch all for small Fluffs anything well less then 10 characters, per section, isn't worth printing.      if ( fluffSize <= 60 )          fluff = null;            int supercharger = readUnsignedShort(dis);      if(supercharger > 0) {          addEquipmentType(EquipmentType.get("Supercharger"), 1, HMVWeaponLocation.BODY);      }      dis.close();    }    catch (IOException ex)    {        ex.printStackTrace();        throw new EntityLoadingException("I/O Error reading file");    }  }  private short readUnsignedByte(DataInputStream dis)    throws IOException  {    short b = dis.readByte();    b += b < 0 ? 256 : 0;    return b;  }  private int readUnsignedShort(DataInputStream dis)    throws IOException  {    int b2 = readUnsignedByte(dis);    int b1 = readUnsignedByte(dis);    b1 <<= 8;    return b1 + b2;  }  /**   * Read a single precision float from a file in little endian format    * @param dis   * @return   * @throws IOException   */  private float readFloat(DataInputStream dis) throws IOException {      int bits = dis.readInt();      //Integer.reverseBytes is not supported in 1.4      //return Float.intBitsToFloat(Integer.reverseBytes(bits));      bits = ((bits & 0xFF000000) >> 24) |              ((bits & 0x00FF0000) >> 8) |              ((bits & 0x0000FF00) << 8) |              ((bits & 0x000000FF) << 24);      return Float.intBitsToFloat(bits);  }    /**     * Determine if the buffer contains the "is omni" flag.     *     * @param   buffer the array of <code>byte</code>s to be scanned.     * @return  <code>true</code> if the buffer contains the "is omni" flag.     */    private boolean containsOmni( byte[] buffer ) {        int index;        // Look for the 4 byte flag.        for ( index = buffer.length - 4; index >= 0; index-- ) {            if ( 0x6f == buffer[index]   &&  // 'o'                 0x6d == buffer[index+1] &&  // 'm'                 0x6e == buffer[index+2] &&  // 'n'                 0x69 == buffer[index+3] ) { // 'i'                // We found it!                return true;            }        }        // We didn't find the "is omni" flag;        return false;    }    public Entity getEntity() throws EntityLoadingException {        try  {            Tank vehicle = null;            if (movementType == HMVMovementType.TRACKED ||                    movementType == HMVMovementType.WHEELED ||                    movementType == HMVMovementType.HOVER ||                    movementType == HMVMovementType.DISPLACEMENT_HULL ||                    movementType == HMVMovementType.HYDROFOIL) {                vehicle = new Tank();            } else if (movementType == HMVMovementType.VTOL) {                vehicle = new VTOL();            } else {                throw new EntityLoadingException                    ( "Unsupported vehicle movement type:" + movementType );            }            vehicle.setChassis(name);            vehicle.setModel(model);            vehicle.setYear(year);            vehicle.setOmni(isOmni);            vehicle.setFluff(fluff);            int techLevel = TechConstants.T_IS_LEVEL_3;            if (rulesLevel == 1) {                techLevel = TechConstants.T_IS_LEVEL_1;            } else if (rulesLevel == 2) {                techLevel = techType == HMVTechType.CLAN ? TechConstants.T_CLAN_LEVEL_2 : TechConstants.T_IS_LEVEL_2;            } else if (techType == HMVTechType.CLAN) {                techLevel = TechConstants.T_CLAN_LEVEL_3;            }            vehicle.setTechLevel(techLevel);            if (vehicle instanceof VTOL) {                vehicle.setMovementMode(IEntityMovementMode.VTOL);            } else {                vehicle.setMovementMode(                                       movementType == HMVMovementType.DISPLACEMENT_HULL ? IEntityMovementMode.NAVAL :                                       movementType == HMVMovementType.HYDROFOIL ? IEntityMovementMode.HYDROFOIL :                                       movementType == HMVMovementType.HOVER ? IEntityMovementMode.HOVER :                                       movementType == HMVMovementType.WHEELED ? IEntityMovementMode.WHEELED :                                       IEntityMovementMode.TRACKED);            }            //This next line sets the weight to a rounded value            //so that the suspension factor can be retrieved.  The            //real weight is set below that.  Why is tonnage not directly            //stated in the HMV file?!            vehicle.setWeight(roundedInternalStructure * 10); //temporary            int suspensionFactor = vehicle.getSuspensionFactor();            vehicle.setWeight((engineRating + suspensionFactor) / cruiseMP);            int engineFlags = Engine.TANK_ENGINE;            if (techType == HMVTechType.CLAN || engineTechType == HMVTechType.CLAN)                engineFlags |= Engine.CLAN_ENGINE;            vehicle.setEngine(new Engine(engineRating,                                        Engine.getEngineTypeByString(engineType.toString()),                                        engineFlags));            vehicle.setOriginalJumpMP(jumpMP);            // hmmm...            vehicle.setHasNoTurret(!hasTurret);            vehicle.autoSetInternal();            vehicle.setArmorType(armorType.toString());            vehicle.initializeArmor(frontArmor, Tank.LOC_FRONT);            vehicle.initializeArmor(leftArmor, Tank.LOC_LEFT);            vehicle.initializeArmor(rightArmor, Tank.LOC_RIGHT);            vehicle.initializeArmor(rearArmor, Tank.LOC_REAR);            if (vehicle instanceof VTOL) {                vehicle.initializeArmor(turretArmor, VTOL.LOC_ROTOR);            } else if (!vehicle.hasNoTurret()) {                vehicle.initializeArmor(turretArmor, Tank.LOC_TURRET);            }            addEquipment(vehicle, HMVWeaponLocation.FRONT, Tank.LOC_FRONT);            addEquipment(vehicle, HMVWeaponLocation.LEFT, Tank.LOC_LEFT);            addEquipment(vehicle, HMVWeaponLocation.RIGHT, Tank.LOC_RIGHT);            addEquipment(vehicle, HMVWeaponLocation.REAR, Tank.LOC_REAR);            if (!vehicle.hasNoTurret()) {                addEquipment(vehicle, HMVWeaponLocation.TURRET, Tank.LOC_TURRET);            }            addEquipment(vehicle, HMVWeaponLocation.BODY, Tank.LOC_BODY);            // Do we have any infantry/cargo bays?            int capacity = (int) Math.round(Math.floor(troopSpace));            if ( capacity > 0 ) {                vehicle.addTransporter( new TroopSpace( capacity ) );            }                        addFailedEquipment(vehicle);            return vehicle;        } catch (Exception e) {                e.printStackTrace();                throw new EntityLoadingException(e.getMessage());        }    }  private void addEquipmentType(EquipmentType equipmentType, int weaponCount,                                HMVWeaponLocation weaponLocation)  {    Hashtable equipmentAtLocation = (Hashtable) equipment.get(weaponLocation);    if (equipmentAtLocation == null)    {      equipmentAtLocation = new Hashtable();      equipment.put(weaponLocation, equipmentAtLocation);    }    Integer prevCount = (Integer) equipmentAtLocation.get( equipmentType );    if ( null != prevCount ) {        weaponCount += prevCount.intValue();    }    equipmentAtLocation.put(equipmentType, new Integer(weaponCount));  }  private void addEquipment(Tank tank, HMVWeaponLocation weaponLocation,                            int location)    throws Exception  {    Hashtable equipmentAtLocation = (Hashtable) equipment.get(weaponLocation);    if (equipmentAtLocation != null)    {      for (Enumeration e = equipmentAtLocation.keys(); e.hasMoreElements();)      {        EquipmentType equipmentType = (EquipmentType) e.nextElement();        Integer count = (Integer) equipmentAtLocation.get(equipmentType);        for (int i = 0; i < count.intValue(); i++)        {          Mounted weapon = tank.addEquipment(equipmentType, location);                    //Add artemis?          //Note this is done here because SRM without artemis and LRM with artemis          //can be in the same location on a tank. (and might be mislinked)          if(artemisType != 0 && equipmentType instanceof WeaponType) {              String artemis = null;              int ammoType = ((WeaponType)equipmentType).getAmmoType();              if(ammoType == AmmoType.T_LRM) {                  if((artemisType & 2) == 2) {                      artemis="ArtemisIV";                  }                  else if((artemisType & 8) == 8) {                      artemis="ArtemisV";                  }              }              else if(ammoType == AmmoType.T_SRM) {                  if((artemisType & 1) == 1) {                      artemis="ArtemisIV";                  }                  else if((artemisType & 4) == 4) {                      artemis="ArtemisV";                  }              }              if(artemis != null) {                  EquipmentType artEq;                  if(equipmentType.getTechLevel() == TechConstants.T_CLAN_LEVEL_2                          || equipmentType.getTechLevel() == TechConstants.T_CLAN_LEVEL_3) {                      artEq = EquipmentType.get("CL"+artemis);                  } else {                      artEq = EquipmentType.get("IS"+artemis);                  }                  if(artEq != null) {                      Mounted fcs = tank.addEquipment(artEq, location);                      fcs.setLinked(weapon);                  }              }          }        }      }    }  }    private void addFailedEquipment(Tank tank) {      for(String s : failedEquipment) {          tank.addFailedEquipment(s);      }  }  private static final Hashtable EQUIPMENT = new Hashtable();  private static final Hashtable AMMO = new Hashtable();  static  {    // inner sphere equipment    // note all weapons should be matched by an ammo entry with the same index    //    Hashtable isEquipment = new Hashtable();    EQUIPMENT.put(HMVTechType.INNER_SPHERE, isEquipment);    isEquipment.put(new Long(0x0A), "ISDouble Heat Sink");    isEquipment.put(new Long(0x0B), "Jump Jet");    isEquipment.put(new Long(0x12), "ISTargeting Computer");    isEquipment.put(new Long(0x14), "Endo Steel");    isEquipment.put(new Long(0x15), "Ferro-Fibrous");    isEquipment.put(new Long(0x17), "ISMASC");    isEquipment.put(new Long(0x18), "ISArtemisIV");    isEquipment.put(new Long(0x19), "ISCASE");    isEquipment.put(new Long(0x33), "ISERLargeLaser");    isEquipment.put(new Long(0x34), "ISERPPC");    isEquipment.put(new Long(0x35), "ISFlamer");    isEquipment.put(new Long(0x36), "ISLaserAMS");    isEquipment.put(new Long(0x37), "ISLargeLaser");    isEquipment.put(new Long(0x38), "ISMediumLaser");    isEquipment.put(new Long(0x39), "ISSmallLaser");    isEquipment.put(new Long(0x3A), "ISPPC");    isEquipment.put(new Long(0x3B), "ISLargePulseLaser");    isEquipment.put(new Long(0x3C), "ISMediumPulseLaser");    isEquipment.put(new Long(0x3D), "ISSmallPulseLaser");    isEquipment.put(new Long(0x3E), "ISAC2");    isEquipment.put(new Long(0x3F), "ISAC5");    isEquipment.put(new Long(0x40), "ISAC10");    isEquipment.put(new Long(0x41), "ISAC20");    isEquipment.put(new Long(0x42), "ISAntiMissileSystem");    isEquipment.put(new Long(0x43), "Long Tom Cannon");    isEquipment.put(new Long(0x44), "Sniper Cannon");    isEquipment.put(new Long(0x45), "Thumper Cannon");    isEquipment.put(new Long(0x46), "ISLightGaussRifle");    isEquipment.put(new Long(0x47), "ISGaussRifle");    isEquipment.put(new Long(0x48), "ISLargeXPulseLaser");    isEquipment.put(new Long(0x49), "ISMediumXPulseLaser");    isEquipment.put(new Long(0x4A), "ISSmallXPulseLaser");    isEquipment.put(new Long(0x4B), "ISLBXAC2");    isEquipment.put(new Long(0x4C), "ISLBXAC5");    isEquipment.put(new Long(0x4D), "ISLBXAC10");    isEquipment.put(new Long(0x4E), "ISLBXAC20");    isEquipment.put(new Long(0x4F), "ISMachine Gun");    isEquipment.put(new Long(0x50), "ISLAC2");    isEquipment.put(new Long(0x51), "ISLAC5");    isEquipment.put(new Long(0x52), "ISHeavyFlamer");    isEquipment.put(new Long(0x54), "ISUltraAC2");    isEquipment.put(new Long(0x55), "ISUltraAC5");    isEquipment.put(new Long(0x56), "ISUltraAC10");    isEquipment.put(new Long(0x57), "ISUltraAC20");    isEquipment.put(new Long(0x59), "PPC Capacitor");    isEquipment.put(new Long(0x5A), "ISERMediumLaser");    isEquipment.put(new Long(0x5B), "ISERSmallLaser");    isEquipment.put(new Long(0x5C), "ISAntiPersonnelPod");    isEquipment.put(new Long(0x60), "ISLRM5");    isEquipment.put(new Long(0x61), "ISLRM10");    isEquipment.put(new Long(0x62), "ISLRM15");    isEquipment.put(new Long(0x63), "ISLRM20");    isEquipment.put(new Long(0x66), "ISImprovedNarc");    isEquipment.put(new Long(0x67), "ISSRM2");    isEquipment.put(new Long(0x68), "ISSRM4");    isEquipment.put(new Long(0x69), "ISSRM6");    isEquipment.put(new Long(0x6A), "ISStreakSRM2");    isEquipment.put(new Long(0x6B), "ISStreakSRM4");

⌨️ 快捷键说明

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