Example #1
0
        private void Make()
        {
            TransitionTable transitionTable = new TransitionTable();
            DateTime        now             = DateTime.Now;

            this.iLogger.StartTask();
            this.iLogger.LogMessage("Loading Terrain Image.");
            try
            {
                string str = string.Format("{0}\\{1}", (object)this.ProjectPath.Text, (object)this.TerrainFile.Text);
                this.iLogger.LogMessage(str);
                this.i_Terrain = new Bitmap(str);
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception exception = ex;
                this.iLogger.LogMessage("Problem with Loading Terrain Image.");
                this.iLogger.LogMessage(exception.Message);
                ProjectData.ClearProjectError();
                return;
            }
            this.iLogger.LogMessage("Loading Altitude Image.");
            try
            {
                string str = string.Format("{0}\\{1}", (object)this.ProjectPath.Text, (object)this.AltitudeFile.Text);
                this.iLogger.LogMessage(str);
                this.i_Altitude = new Bitmap(str);
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                Exception exception = ex;
                this.iLogger.LogMessage("Problem with Loading Altitude Image.");
                this.iLogger.LogMessage(exception.Message);
                ProjectData.ClearProjectError();
                return;
            }
            this.iLogger.EndTask();
            this.iLogger.LogTimeStamp();
            this.iLogger.LogMessage("Preparing Image Files.");
            this.iLogger.StartTask();
            int        width       = this.i_Terrain.Width;
            int        height      = this.i_Terrain.Height;
            Rectangle  rect        = new Rectangle(0, 0, width, height);
            BitmapData bitmapData1 = this.i_Terrain.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
            IntPtr     scan0_1     = bitmapData1.Scan0;
            int        length1     = checked (bitmapData1.Width * bitmapData1.Height);

            byte[] destination1 = new byte[checked (length1 - 1 + 1)];
            Marshal.Copy(scan0_1, destination1, 0, length1);
            BitmapData bitmapData2 = this.i_Altitude.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
            IntPtr     scan0_2     = bitmapData2.Scan0;
            int        length2     = checked (bitmapData2.Width * bitmapData2.Height);

            byte[] destination2 = new byte[checked (length2 - 1 + 1)];
            Marshal.Copy(scan0_2, destination2, 0, length2);
            this.iLogger.EndTask();
            this.iLogger.LogTimeStamp();
            this.iLogger.LogMessage("Creating Master Terrian Table.");
            this.iLogger.StartTask();
            MapCell[,] mapCellArray = new MapCell[checked (width + 1), checked (height + 1)];
            ClsAltitudeTable clsAltitudeTable = new ClsAltitudeTable();

            clsAltitudeTable.Load();
            try
            {
                int num1   = 0;
                int num2   = checked (width - 1);
                int index1 = num1;
                while (index1 <= num2)
                {
                    int num3   = 0;
                    int num4   = checked (height - 1);
                    int index2 = num3;
                    while (index2 <= num4)
                    {
                        int         index3      = checked (index2 * width + index1);
                        ClsAltitude clsAltitude = clsAltitudeTable.get_GetAltitude((int)destination2[index3]);
                        mapCellArray[index1, index2] = new MapCell(destination1[index3], clsAltitude.GetAltitude);
                        checked { ++index2; }
                    }
                    checked { ++index1; }
                }
            }
            catch (Exception ex)
            {
                ProjectData.SetProjectError(ex);
                this.iLogger.LogMessage("Altitude image needs to be rebuilt");
                ProjectData.ClearProjectError();
                return;
            }
            this.i_Terrain.Dispose();
            this.i_Altitude.Dispose();
            this.iLogger.EndTask();
            this.iLogger.LogTimeStamp();
            int num5 = checked (width - 1);
            int num6 = checked (height - 1);
            int num7 = checked ((int)Math.Round(unchecked ((double)num5 / 8.0 - 1.0)));
            int num8 = checked ((int)Math.Round(unchecked ((double)num6 / 8.0 - 1.0)));

            this.iLogger.LogMessage("Load Transition Tables.");
            this.iLogger.StartTask();
            string str1 = AppDomain.CurrentDomain.BaseDirectory + "Data\\Transitions\\";

            if (!Directory.Exists(str1))
            {
                this.iLogger.LogMessage("Unable to find Transition Data files in the following path: ");
                this.iLogger.LogMessage(str1);
            }
            else
            {
                transitionTable.MassLoad(str1);
                this.iLogger.EndTask();
                this.iLogger.LogTimeStamp();
                this.iLogger.LogMessage("Preparing Static Tables");
                Collection[,] StaticMap = new Collection[checked (num7 + 1), checked (num8 + 1)];
                int num1   = 0;
                int num2   = num7;
                int index1 = num1;
                while (index1 <= num2)
                {
                    int num3   = 0;
                    int num4   = num8;
                    int index2 = num3;
                    while (index2 <= num4)
                    {
                        StaticMap[index1, index2] = new Collection();
                        checked { ++index2; }
                    }
                    checked { ++index1; }
                }
                this.iLogger.LogMessage("Applying Transition Tables.");
                this.iLogger.StartTask();
                this.ProgressBar1.Maximum = num5;
                ClsTerrainTable clsTerrainTable = new ClsTerrainTable();
                clsTerrainTable.Load();
                MapTile    mapTile1    = new MapTile();
                Transition transition1 = new Transition();
                short[]    numArray1   = new short[16];
                int        num9        = 0;
                short      num10       = checked ((short)num5);
                for (short X = (short)num9; (int)X <= (int)num10; ++X)
                {
                    int   index2 = (int)X != 0 ? checked ((int)X - 1) : num5;
                    int   index3 = (int)X != num5 ? checked ((int)X + 1) : 0;
                    int   num3   = 0;
                    short num4   = checked ((short)num6);
                    for (short Y = (short)num3; (int)Y <= (int)num4; ++Y)
                    {
                        int    index4 = (int)Y != 0 ? checked ((int)Y - 1) : num6;
                        int    index5 = (int)Y != num6 ? checked ((int)Y + 1) : 0;
                        string iKey   = string.Format("{0:X2}{1:X2}{2:X2}{3:X2}{4:X2}{5:X2}{6:X2}{7:X2}{8:X2}", (object)mapCellArray[index2, index4].GroupID, (object)mapCellArray[(int)X, index4].GroupID, (object)mapCellArray[index3, index4].GroupID, (object)mapCellArray[index2, (int)Y].GroupID, (object)mapCellArray[(int)X, (int)Y].GroupID, (object)mapCellArray[index3, (int)Y].GroupID, (object)mapCellArray[index2, index5].GroupID, (object)mapCellArray[(int)X, index5].GroupID, (object)mapCellArray[index3, index5].GroupID);
                        short  altId;
                        try
                        {
                            Transition transition2 = transitionTable.get_Transition(iKey);
                            if (transition2 != null)
                            {
                                altId = mapCellArray[(int)X, (int)Y].AltID;
                                MapTile randomMapTile = transition2.GetRandomMapTile();
                                if (randomMapTile != null)
                                {
                                    MapTile mapTile2 = randomMapTile;
                                    mapCellArray[(int)X, (int)Y].TileID = mapTile2.TileID;
                                    mapCellArray[(int)X, (int)Y].ChangeAltID(mapTile2.AltIDMod);
                                }
                                else
                                {
                                    ClsTerrain clsTerrain = clsTerrainTable.get_TerrianGroup((int)mapCellArray[(int)X, (int)Y].GroupID);
                                    mapCellArray[(int)X, (int)Y].TileID = clsTerrain.TileID;
                                    mapCellArray[(int)X, (int)Y].ChangeAltID((short)clsTerrain.AltID);
                                }
                                transition2.GetRandomStaticTiles(X, Y, altId, StaticMap, this.i_RandomStatic);
                            }
                            else
                            {
                                ClsTerrain clsTerrain = clsTerrainTable.get_TerrianGroup((int)mapCellArray[(int)X, (int)Y].GroupID);
                                mapCellArray[(int)X, (int)Y].TileID = clsTerrain.TileID;
                                mapCellArray[(int)X, (int)Y].AltID  = altId;
                            }
                            if ((int)mapCellArray[(int)X, (int)Y].GroupID == 254)
                            {
                                mapCellArray[(int)X, (int)Y].TileID = (short)1078;
                                mapCellArray[(int)X, (int)Y].AltID  = (short)0;
                            }
                        }
                        catch (Exception ex)
                        {
                            ProjectData.SetProjectError(ex);
                            Exception exception = ex;
                            this.iLogger.LogMessage(string.Format("\r\nLocation: X:{0}, Y:{1}, Z:{2} Hkey:{3}", (object)X, (object)Y, (object)altId, (object)iKey));
                            this.iLogger.LogMessage(exception.ToString());
                            ProjectData.ClearProjectError();
                            return;
                        }
                    }
                    this.ProgressBar1.Value = (int)X;
                }
                this.iLogger.EndTask();
                this.iLogger.LogTimeStamp();
                this.iLogger.LogMessage("Second Pass.");
                this.iLogger.StartTask();
                short[]   numArray2 = new short[9];
                RoughEdge roughEdge = new RoughEdge();
                int       num11     = 0;
                short     num12     = checked ((short)num5);
                for (short index2 = (short)num11; (int)index2 <= (int)num12; ++index2)
                {
                    int   index3 = (int)index2 != 0 ? checked ((int)index2 - 1) : num5;
                    int   index4 = (int)index2 != num5 ? checked ((int)index2 + 1) : 0;
                    int   num3   = 0;
                    short num4   = checked ((short)num6);
                    for (short index5 = (short)num3; (int)index5 <= (int)num4; ++index5)
                    {
                        int index6 = (int)index5 != 0 ? checked ((int)index5 - 1) : num6;
                        int index7 = (int)index5 != num6 ? checked ((int)index5 + 1) : 0;
                        mapCellArray[(int)index2, (int)index5].ChangeAltID(roughEdge.CheckCorner(mapCellArray[index3, index6].TileID));
                        mapCellArray[(int)index2, (int)index5].ChangeAltID(roughEdge.CheckLeft(mapCellArray[index3, (int)index5].TileID));
                        mapCellArray[(int)index2, (int)index5].ChangeAltID(roughEdge.CheckTop(mapCellArray[(int)index2, index6].TileID));
                        if ((int)mapCellArray[(int)index2, (int)index5].GroupID == 20)
                        {
                            numArray2[0] = mapCellArray[index3, index6].AltID;
                            numArray2[1] = mapCellArray[(int)index2, index6].AltID;
                            numArray2[2] = mapCellArray[index4, index6].AltID;
                            numArray2[3] = mapCellArray[index3, (int)index5].AltID;
                            numArray2[4] = mapCellArray[(int)index2, (int)index5].AltID;
                            numArray2[5] = mapCellArray[index4, (int)index5].AltID;
                            numArray2[6] = mapCellArray[index3, index7].AltID;
                            numArray2[7] = mapCellArray[(int)index2, index7].AltID;
                            numArray2[8] = mapCellArray[index4, index7].AltID;
                            Array.Sort((Array)numArray2);
                            float num13 = 10f * VBMath.Rnd();
                            if ((double)num13 == 0.0)
                            {
                                mapCellArray[(int)index2, (int)index5].AltID = checked ((short)((int)numArray2[8] - 4));
                            }
                            else if ((double)num13 >= 1.0 && (double)num13 <= 2.0)
                            {
                                mapCellArray[(int)index2, (int)index5].AltID = checked ((short)((int)numArray2[8] - 2));
                            }
                            else if ((double)num13 >= 3.0 && (double)num13 <= 7.0)
                            {
                                mapCellArray[(int)index2, (int)index5].AltID = numArray2[8];
                            }
                            else if ((double)num13 >= 8.0 && (double)num13 <= 9.0)
                            {
                                mapCellArray[(int)index2, (int)index5].AltID = checked ((short)((int)numArray2[8] + 2));
                            }
                            else if ((double)num13 == 10.0)
                            {
                                mapCellArray[(int)index2, (int)index5].AltID = checked ((short)((int)numArray2[8] + 4));
                            }
                        }
                        if (clsTerrainTable.get_TerrianGroup((int)mapCellArray[(int)index2, (int)index5].GroupID).RandAlt)
                        {
                            float num13 = 10f * VBMath.Rnd();
                            if ((double)num13 == 0.0)
                            {
                                mapCellArray[(int)index2, (int)index5].ChangeAltID((short)-4);
                            }
                            else if ((double)num13 >= 1.0 && (double)num13 <= 2.0)
                            {
                                mapCellArray[(int)index2, (int)index5].ChangeAltID((short)-2);
                            }
                            else if ((double)num13 >= 8.0 && (double)num13 <= 9.0)
                            {
                                mapCellArray[(int)index2, (int)index5].ChangeAltID((short)2);
                            }
                            else if ((double)num13 == 10.0)
                            {
                                mapCellArray[(int)index2, (int)index5].ChangeAltID((short)4);
                            }
                        }
                    }
                    this.ProgressBar1.Value = (int)index2;
                }
                this.iLogger.EndTask();
                this.iLogger.LogTimeStamp();
                int  num14 = 1;
                byte num15;
                switch (num5)
                {
                case 6143:
                    num15 = (byte)0;
                    break;

                case 2303:
                    num15 = (byte)2;
                    break;

                case 2559:
                    num15 = (byte)3;
                    break;
                }
                this.iLogger.LogMessage("\r\n");
                this.iLogger.LogMessage("Load . . . . . Import Tiles.");
                this.iLogger.StartTask();
                ImportTiles importTiles = new ImportTiles(StaticMap, this.ProjectPath.Text);
                this.iLogger.EndTask();
                this.iLogger.LogTimeStamp();
                this.iLogger.LogMessage("\r\n");
                this.iLogger.LogMessage("Write Mul Files.");
                this.iLogger.StartTask();
                string str2 = string.Format("{0}/Map{1}.mul", (object)this.ProjectPath.Text, (object)num15);
                this.iLogger.LogMessage(str2);
                FileStream   fileStream1 = new FileStream(str2, FileMode.Create);
                BinaryWriter i_MapFile   = new BinaryWriter((Stream)fileStream1);
                int          num16       = 0;
                int          num17       = num5;
                int          num18       = num16;
                while (num18 <= num17)
                {
                    int num3  = 0;
                    int num4  = num6;
                    int num13 = num3;
                    while (num13 <= num4)
                    {
                        i_MapFile.Write(num14);
                        int num19 = 0;
                        do
                        {
                            int num20 = 0;
                            do
                            {
                                mapCellArray[checked (num18 + num20), checked (num13 + num19)].WriteMapMul(i_MapFile);
                                checked { ++num20; }
                            }while (num20 <= 7);
                            checked { ++num19; }
                        }while (num19 <= 7);
                        checked { num13 += 8; }
                    }
                    checked { num18 += 8; }
                }
                i_MapFile.Close();
                fileStream1.Close();
                string     str3        = string.Format("{0}/StaIdx{1}.mul", (object)this.ProjectPath.Text, (object)num15);
                FileStream fileStream2 = new FileStream(str3, FileMode.Create);
                this.iLogger.LogMessage(str3);
                string     str4        = string.Format("{0}/Statics{1}.mul", (object)this.ProjectPath.Text, (object)num15);
                FileStream fileStream3 = new FileStream(str4, FileMode.Create);
                this.iLogger.LogMessage(str4);
                BinaryWriter binaryWriter = new BinaryWriter((Stream)fileStream2);
                BinaryWriter i_StaticFile = new BinaryWriter((Stream)fileStream3);
                int          num21        = 0;
                int          num22        = num7;
                int          index8       = num21;
                while (index8 <= num22)
                {
                    int num3   = 0;
                    int num4   = num8;
                    int index2 = num3;
                    while (index2 <= num4)
                    {
                        int num13 = 0;
                        int num19 = checked ((int)i_StaticFile.BaseStream.Position);
                        try
                        {
                            foreach (StaticCell staticCell in StaticMap[index8, index2])
                            {
                                staticCell.Write(i_StaticFile);
                                checked { num13 += 7; }
                            }
                        }
                        finally
                        {
                            IEnumerator enumerator;
                            if (enumerator is IDisposable)
                            {
                                ((IDisposable)enumerator).Dispose();
                            }
                        }
                        if (num13 == 0)
                        {
                            num19 = -1;
                        }
                        binaryWriter.Write(num19);
                        binaryWriter.Write(num13);
                        binaryWriter.Write(num14);
                        checked { ++index2; }
                    }
                    checked { ++index8; }
                }
                i_StaticFile.Close();
                binaryWriter.Close();
                fileStream3.Close();
                fileStream2.Close();
                this.iLogger.EndTask();
                this.iLogger.LogTimeStamp();
                this.iLogger.LogMessage("Done.");
            }
        }