コード例 #1
0
ファイル: Region.java プロジェクト: zuppers/mopar
  /**
   * @param plane
   * @param x
   * @param y
   * @param type
   * @param configId
   * @param orientation
   */
  public void unmarkObject(int plane, int x, int y, int type, int configId, int orientation) {
    int group = GameObjectGroup.getGroupForType(type);
    GameObjectConfig config = GameObjectConfig.forId(configId);
    TraversalMap map = traversalMaps[plane];

    if (group == GameObjectGroup.WALL) {
      if (config.isSolid()) {
        map.unmarkWall(x, y, type, orientation, config.isImpenetrable());
      }
    }

    if (group == GameObjectGroup.GROUP_2) {
      if (config.isSolid()) {
        map.unmarkOccupant(x, y, config.getWidth(), config.getHeight(), config.isImpenetrable());
      }
    }
  }
コード例 #2
0
ファイル: Region.java プロジェクト: zuppers/mopar
  /**
   * @param is
   * @throws IOException
   */
  public void parse(InputStream is) throws IOException {
    DataInputStream dis = new DataInputStream(is);

    if (dis.readInt() != 0x4d52474e) {
      throw new IOException("Invalid file magic");
    }

    int format = dis.readByte();
    if (format > 1 || format < 1) {
      throw new IOException("Unsupported format");
    }

    int locHash = dis.readUnsignedShort();
    int regionX = locHash >> 8;
    int regionY = locHash & 0xff;
    if (x != regionX || y != regionY) {
      throw new IOException("Location mismatch");
    }

    int chk;
    while ((chk = dis.readUnsignedByte()) != chk_EOF) {
      switch (chk) {
        case chk_LOCALE:
          {
            int config = dis.readUnsignedShort();

            int loc = dis.readUnsignedShort();
            int x = loc >> 6 & 0x3f;
            int y = loc & 0x3f;
            int plane = loc >> 12;

            int ori = dis.readUnsignedByte();
            int type = ori >> 2;
            int orientation = ori & 0x3;

            int group = GameObjectGroup.getGroupForType(type);

            int chunkX = x >> 3, chunkY = y >> 3;
            int localX = x & 0x7, localY = y & 0x7;

            Block block = getBlock(plane, chunkX, chunkY);
            BlockTile tile = block.getTile(localX, localY);

            GameObject gameObject = new GameObject(config, type, orientation, true);
            tile.setLocale(group, gameObject);
          }
          break;

        case chk_CLIP:
          {
            int lhash;
            while ((lhash = dis.readUnsignedShort()) != clip_EOD) {
              int x = lhash >> 8 & 0x3f;
              int y = lhash >> 2 & 0x3f;
              int p = lhash & 0x3;

              int first = dis.readUnsignedByte();
              int value = first & 0x3f;

              int length = first >> 6 & 0x3;
              if (length >= 2) {
                value |= dis.readUnsignedByte() << 6;
              }

              if (length >= 3) {
                value |= dis.readUnsignedByte() << 14;
              }

              TraversalMap traversalMap = traversalMaps[p];
              traversalMap.set(x, y, value);
            }
          }
          break;

        case chk_NPC:
          {
            int type = dis.readUnsignedShort();

            int loc = dis.readUnsignedByte();
            int x = loc >> 6 & 0x3f;
            int y = loc & 0x3f;
            int plane = loc >> 12;
          }
          break;

        default:
          throw new IOException("Bad config code");
      }
    }
  }