Exemplo n.º 1
0
        public void LoadTile(bool[] importance)
        {
            string path = Path.Combine(Main.ActiveWorldFileData.Path.Replace(".wld", ""), ActiveDimensionName.Split(':')[1]) + "\\Tile.data";

            Main.tile = new Tile[Main.maxTilesX, Main.maxTilesY];

            for (int i = 0; i < Main.maxTilesX; i++)
            {
                for (int j = 0; j < Main.maxTilesY; j++)
                {
                    Main.tile[i, j] = new Tile();
                }
            }

            using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open)))
            {
                for (int i = 0; i < Main.maxTilesX; i++)
                {
                    float num = (float)i / (float)Main.maxTilesX;
                    Main.statusText = string.Concat(new object[]
                    {
                        Lang.gen[51].Value,
                        " ",
                        (int)((double)num * 100.0 + 1.0),
                        "%"
                    });
                    for (int j = 0; j < Main.maxTilesY; j++)
                    {
                        int  num2 = -1;
                        byte b2;
                        byte b    = b2 = 0;
                        Tile tile = Main.tile[i, j];
                        byte b3   = reader.ReadByte();
                        if ((b3 & 1) == 1)
                        {
                            b2 = reader.ReadByte();
                            if ((b2 & 1) == 1)
                            {
                                b = reader.ReadByte();
                            }
                        }
                        byte b4;
                        if ((b3 & 2) == 2)
                        {
                            tile.active(true);
                            if ((b3 & 32) == 32)
                            {
                                b4   = reader.ReadByte();
                                num2 = (int)reader.ReadByte();
                                num2 = (num2 << 8 | (int)b4);
                            }
                            else
                            {
                                num2 = (int)reader.ReadByte();
                            }
                            tile.type = (ushort)num2;
                            if (num2 < importance.Length && importance[num2])
                            {
                                tile.frameX = reader.ReadInt16();
                                tile.frameY = reader.ReadInt16();
                                if (tile.type == 144)
                                {
                                    tile.frameY = 0;
                                }
                            }
                            else
                            {
                                tile.frameX = -1;
                                tile.frameY = -1;
                            }
                            if ((b & 8) == 8)
                            {
                                tile.color(reader.ReadByte());
                            }
                        }
                        if ((b3 & 4) == 4)
                        {
                            tile.wall = reader.ReadByte();
                            if ((b & 16) == 16)
                            {
                                tile.wallColor(reader.ReadByte());
                            }
                        }
                        b4 = (byte)((b3 & 24) >> 3);
                        if (b4 != 0)
                        {
                            tile.liquid = reader.ReadByte();
                            if (b4 > 1)
                            {
                                if (b4 == 2)
                                {
                                    tile.lava(true);
                                }
                                else
                                {
                                    tile.honey(true);
                                }
                            }
                        }
                        if (b2 > 1)
                        {
                            if ((b2 & 2) == 2)
                            {
                                tile.wire(true);
                            }
                            if ((b2 & 4) == 4)
                            {
                                tile.wire2(true);
                            }
                            if ((b2 & 8) == 8)
                            {
                                tile.wire3(true);
                            }
                            b4 = (byte)((b2 & 112) >> 4);
                            if (b4 != 0 && Main.tileSolid[(int)tile.type])
                            {
                                if (b4 == 1)
                                {
                                    tile.halfBrick(true);
                                }
                                else
                                {
                                    tile.slope((byte)(b4 - 1));
                                }
                            }
                        }
                        if (b > 0)
                        {
                            if ((b & 2) == 2)
                            {
                                tile.actuator(true);
                            }
                            if ((b & 4) == 4)
                            {
                                tile.inActive(true);
                            }
                            if ((b & 32) == 32)
                            {
                                tile.wire4(true);
                            }
                        }
                        b4 = (byte)((b3 & 192) >> 6);
                        int k;
                        if (b4 == 0)
                        {
                            k = 0;
                        }
                        else if (b4 == 1)
                        {
                            k = (int)reader.ReadByte();
                        }
                        else
                        {
                            k = (int)reader.ReadInt16();
                        }
                        if (num2 != -1)
                        {
                            if ((double)j <= Main.worldSurface)
                            {
                                if ((double)(j + k) <= Main.worldSurface)
                                {
                                    WorldGen.tileCounts[num2] += (k + 1) * 5;
                                }
                                else
                                {
                                    int num3 = (int)(Main.worldSurface - (double)j + 1.0);
                                    int num4 = k + 1 - num3;
                                    WorldGen.tileCounts[num2] += num3 * 5 + num4;
                                }
                            }
                            else
                            {
                                WorldGen.tileCounts[num2] += k + 1;
                            }
                        }
                        while (k > 0)
                        {
                            j++;
                            Main.tile[i, j].CopyFrom(tile);
                            k--;
                        }
                    }
                }
                WorldGen.AddUpAlignmentCounts(true);
                if (WorldFile.versionNumber < 105)
                {
                    WorldGen.FixHearts();
                }
            }
        }