コード例 #1
0
ファイル: DesignBlock.java プロジェクト: runholen/stars
 @Override
 public void decode() throws Exception {
   if ((decryptedData[0] & 3) != 3) {
     throw new Exception("Unexpected design first byte: " + this);
   }
   if ((decryptedData[0] & 0xF8) != 0) {
     throw new Exception("Unexpected design first byte: " + this);
   }
   isFullDesign = (decryptedData[0] & 0x04) == 0x04;
   if ((decryptedData[1] & 0x02) != 0) {
     throw new Exception("Unexpected design second byte: " + this);
   }
   if ((decryptedData[1] & 0x01) != 0x01) {
     throw new Exception("Unexpected design second byte: " + this);
   }
   isTransferred = (decryptedData[1] & 0x80) == 0x80;
   isStarbase = (decryptedData[1] & 0x40) == 0x40;
   designNumber = (decryptedData[1] & 0x3C) >> 2;
   hullId = decryptedData[2] & 0xFF;
   fuelCapacity = Items.ships[hullId].fuel;
   pic = decryptedData[3] & 0xFF;
   int index;
   if (isFullDesign) {
     if (isStarbase) mass = 0;
     else mass = Items.ships[hullId].mass;
     armor = Util.read16(decryptedData, 4);
     slotCount = decryptedData[6] & 0xFF;
     turnDesigned = Util.read16(decryptedData, 7);
     totalBuilt = Util.read32(decryptedData, 9);
     totalRemaining = Util.read32(decryptedData, 13);
     index = 17;
     slots.clear();
     for (int i = 0; i < slotCount; i++) {
       Slot slot = new Slot();
       slot.category = Util.read16(decryptedData, index);
       index += 2;
       slot.itemId = Util.read8(decryptedData[index++]);
       slot.count = Util.read8(decryptedData[index++]);
       slots.add(slot);
       if (slot.count > 0) {
         int key = (slot.category << 8) | (slot.itemId & 0xFF);
         mass += slot.count * Items.itemMasses.get(key);
         if (slot.category == Items.TechCategory.Mechanical.getMask()) {
           if (slot.itemId == 5) fuelCapacity += slot.count * 250;
           if (slot.itemId == 6) fuelCapacity += slot.count * 500;
         }
         if (slot.category == Items.TechCategory.Electrical.getMask()) {
           if (slot.itemId == 16) fuelCapacity += slot.count * 200;
         }
       }
     }
   } else {
     mass = Util.read16(decryptedData, 4);
     index = 6;
   }
   int nameLen = decryptedData[index];
   nameBytes = new byte[1 + nameLen];
   System.arraycopy(decryptedData, index, nameBytes, 0, 1 + nameLen);
   index += 1 + nameLen;
   if (index != size) {
     throw new Exception("Unexpected design size: " + this);
   }
 }