Exemplo n.º 1
0
        public void btnCompileCampaign_Click(Object sender, EventArgs e)
        {
            clsResult ReturnResult = new clsResult("Compile campaign");
            int A = 0;

            SaveToMap();

            A = ValidateMap_WaterTris();
            if ( A > 0 )
            {
                ReturnResult.WarningAdd(A + " water tiles have an incorrect triangle direction. There might be in-game graphical glitches on those tiles.");
            }

            ReturnResult.Add(ValidateMap());
            ReturnResult.Add(ValidateMap_UnitPositions());

            string MapName = "";
            int TypeNum = 0;

            MapName = txtName.Text;
            if ( MapName.Length < 1 )
            {
                ReturnResult.ProblemAdd("Enter a name for the campaign files.");
            }
            TypeNum = cboCampType.SelectedIndex;
            if ( TypeNum < 0 | TypeNum > 2 )
            {
                ReturnResult.ProblemAdd("Select a campaign type.");
            }
            if ( ReturnResult.HasProblems )
            {
                App.ShowWarnings(ReturnResult);
                return;
            }
            FolderBrowserDialog CompileCampDialog = new FolderBrowserDialog();
            if ( CompileCampDialog.ShowDialog(this) != DialogResult.OK )
            {
                return;
            }
            clsMap.sWrite_WZ_Args WriteWZArgs = new clsMap.sWrite_WZ_Args();
            WriteWZArgs.MapName = MapName;
            WriteWZArgs.Path = CompileCampDialog.SelectedPath;
            WriteWZArgs.Overwrite = false;
            SetScrollLimits(WriteWZArgs.ScrollMin, WriteWZArgs.ScrollMax);
            WriteWZArgs.Campaign = new clsMap.sWrite_WZ_Args.clsCampaign();
            WriteWZArgs.Campaign.GAMType = (uint)TypeNum;
            WriteWZArgs.CompileType = clsMap.sWrite_WZ_Args.enumCompileType.Campaign;
            ReturnResult.Add(Map.Write_WZ(WriteWZArgs));
            App.ShowWarnings(ReturnResult);
            if ( !ReturnResult.HasWarnings )
            {
                Close();
            }
        }
Exemplo n.º 2
0
        public clsResult Write_FMap(string Path, bool Overwrite, bool Compress)
        {
            clsResult ReturnResult =
                new clsResult("Writing FMap to " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote));

            if ( !Overwrite )
            {
                if ( File.Exists(Path) )
                {
                    ReturnResult.ProblemAdd("The file already exists");
                    return ReturnResult;
                }
            }

            FileStream FileStream = default(FileStream);
            try
            {
                FileStream = File.Create(Path);
            }
            catch ( Exception )
            {
                ReturnResult.ProblemAdd("Unable to create file");
                return ReturnResult;
            }

            ZipOutputStream WZStream = new ZipOutputStream(FileStream);
            WZStream.UseZip64 = UseZip64.Off;
            if ( Compress )
            {
                WZStream.SetLevel(9);
            }
            else
            {
                WZStream.SetLevel(0);
            }

            BinaryWriter BinaryWriter = new BinaryWriter(WZStream, App.UTF8Encoding);
            StreamWriter StreamWriter = new StreamWriter(WZStream, App.UTF8Encoding);
            ZipEntry ZipEntry = default(ZipEntry);
            string ZipPath = "";

            ZipPath = "Info.ini";
            ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
            if ( ZipEntry != null )
            {
                IniWriter INI_Info = new IniWriter();
                INI_Info.File = StreamWriter;
                ReturnResult.Add(Serialize_FMap_Info(INI_Info));

                StreamWriter.Flush();
                WZStream.CloseEntry();
            }

            ZipPath = "VertexHeight.dat";
            ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
            if ( ZipEntry != null )
            {
                ReturnResult.Add(Serialize_FMap_VertexHeight(BinaryWriter));

                BinaryWriter.Flush();
                WZStream.CloseEntry();
            }

            ZipPath = "VertexTerrain.dat";
            ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
            if ( ZipEntry != null )
            {
                ReturnResult.Add(Serialize_FMap_VertexTerrain(BinaryWriter));

                BinaryWriter.Flush();
                WZStream.CloseEntry();
            }

            ZipPath = "TileTexture.dat";
            ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
            if ( ZipEntry != null )
            {
                ReturnResult.Add(Serialize_FMap_TileTexture(BinaryWriter));

                BinaryWriter.Flush();
                WZStream.CloseEntry();
            }

            ZipPath = "TileOrientation.dat";
            ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
            if ( ZipEntry != null )
            {
                ReturnResult.Add(Serialize_FMap_TileOrientation(BinaryWriter));

                BinaryWriter.Flush();
                WZStream.CloseEntry();
            }

            ZipPath = "TileCliff.dat";
            ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
            if ( ZipEntry != null )
            {
                ReturnResult.Add(Serialize_FMap_TileCliff(BinaryWriter));

                BinaryWriter.Flush();
                WZStream.CloseEntry();
            }

            ZipPath = "Roads.dat";
            ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
            if ( ZipEntry != null )
            {
                ReturnResult.Add(Serialize_FMap_Roads(BinaryWriter));

                BinaryWriter.Flush();
                WZStream.CloseEntry();
            }

            ZipPath = "Objects.ini";
            ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
            if ( ZipEntry != null )
            {
                IniWriter INI_Objects = new IniWriter();
                INI_Objects.File = StreamWriter;
                ReturnResult.Add(Serialize_FMap_Objects(INI_Objects));

                StreamWriter.Flush();
                WZStream.CloseEntry();
            }

            ZipPath = "Gateways.ini";
            ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
            if ( ZipEntry != null )
            {
                IniWriter INI_Gateways = new IniWriter();
                INI_Gateways.File = StreamWriter;
                ReturnResult.Add(Serialize_FMap_Gateways(INI_Gateways));

                StreamWriter.Flush();
                WZStream.CloseEntry();
            }

            ZipPath = "TileTypes.dat";
            ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
            if ( ZipEntry != null )
            {
                ReturnResult.Add(Serialize_FMap_TileTypes(BinaryWriter));

                BinaryWriter.Flush();
                WZStream.CloseEntry();
            }

            ZipPath = "ScriptLabels.ini";
            ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
            if ( ZipEntry != null )
            {
                IniWriter INI_ScriptLabels = new IniWriter();
                INI_ScriptLabels.File = StreamWriter;
                ReturnResult.Add(Serialize_WZ_LabelsINI(INI_ScriptLabels, -1));

                StreamWriter.Flush();
                WZStream.CloseEntry();
            }

            WZStream.Finish();
            WZStream.Close();
            BinaryWriter.Close();
            return ReturnResult;
        }
Exemplo n.º 3
0
        public void btnCompile_Click(Object sender, EventArgs e)
        {
            var ReturnResult = new clsResult("Compile multiplayer", false);
            logger.Info("Compile multiplayer");
            var A = 0;

            SaveToMap();

            var MapName = "";
            var License = cboLicense.Text;
            var PlayerCount = 0;
            if ( !IOUtil.InvariantParse(txtMultiPlayers.Text, ref PlayerCount) )
            {
                PlayerCount = 0;
            }
            if ( PlayerCount < 2 | PlayerCount > Constants.PlayerCountMax )
            {
                ReturnResult.ProblemAdd(string.Format("The number of players must be from 2 to {0}", Constants.PlayerCountMax));
            }

            A = ValidateMap_WaterTris();
            if ( A > 0 )
            {
                ReturnResult.WarningAdd(string.Format("{0} water tiles have an incorrect triangle direction. There might be in-game graphical glitches on those tiles.", A));
            }

            ReturnResult.Add(ValidateMap());
            ReturnResult.Add(ValidateMap_UnitPositions());
            ReturnResult.Add(ValidateMap_Multiplayer(PlayerCount));

            MapName = txtName.Text;
            var CurrentChar = (char)0;
            for ( A = 0; A <= MapName.Length - 1; A++ )
            {
                CurrentChar = MapName[A];
                if (
                    !((CurrentChar >= 'a' && CurrentChar <= 'z') || (CurrentChar >= 'A' && CurrentChar <= 'Z') ||
                      (A >= 1 && ((CurrentChar >= '0' && CurrentChar <= '9') || CurrentChar == '-' || CurrentChar == '_'))) )
                {
                    break;
                }
            }
            if ( A < MapName.Length )
            {
                ReturnResult.ProblemAdd("The map\'s name must contain only letters, numbers, underscores and hyphens, and must begin with a letter.");
            }
            if ( MapName.Length < 1 | MapName.Length > 16 )
            {
                ReturnResult.ProblemAdd("Map name must be from 1 to 16 characters.");
            }
            if ( string.IsNullOrEmpty(License) )
            {
                ReturnResult.ProblemAdd("Enter a valid license.");
            }
            if ( ReturnResult.HasProblems )
            {
                App.ShowWarnings(ReturnResult);
                return;
            }
            var CompileMultiDialog = new SaveFileDialog();
            if ( Map.PathInfo != null )
            {
                CompileMultiDialog.InitialDirectory = Map.PathInfo.Path;
            }
            CompileMultiDialog.FileName = PlayerCount + "c-" + MapName;
            CompileMultiDialog.Filter = "WZ Files (*.wz)|*.wz";
            if ( CompileMultiDialog.ShowDialog(this) != DialogResult.OK )
            {
                return;
            }
            var WriteWZArgs = new sWrite_WZ_Args();
            WriteWZArgs.MapName = MapName;
            WriteWZArgs.Path = CompileMultiDialog.FileName;
            WriteWZArgs.Overwrite = true;
            SetScrollLimits(ref WriteWZArgs.ScrollMin, ref WriteWZArgs.ScrollMax);
            WriteWZArgs.Multiplayer = new sWrite_WZ_Args.clsMultiplayer();
            WriteWZArgs.Multiplayer.AuthorName = txtAuthor.Text;
            WriteWZArgs.Multiplayer.PlayerCount = PlayerCount;
            WriteWZArgs.Multiplayer.License = License;
            WriteWZArgs.CompileType = sWrite_WZ_Args.enumCompileType.Multiplayer;

            var wzFormat = new Wz(Map);
            ReturnResult.Add(wzFormat.Save(WriteWZArgs));
            App.ShowWarnings(ReturnResult);
            if ( !ReturnResult.HasWarnings )
            {
                Close();
            }
        }
Exemplo n.º 4
0
        public clsResult LoadDirectory(string Path)
        {
            clsResult ReturnResult =
                new clsResult("Loading tileset from " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote));

            Bitmap Bitmap = null;
            App.sSplitPath SplitPath = new App.sSplitPath(Path);
            string SlashPath = App.EndWithPathSeperator(Path);
            App.sResult Result = new App.sResult();

            if ( SplitPath.FileTitle != "" )
            {
                Name = SplitPath.FileTitle;
            }
            else if ( SplitPath.PartCount >= 2 )
            {
                Name = SplitPath.Parts[SplitPath.PartCount - 2];
            }

            Result = Default_TileTypes_Load(SlashPath + Name + ".ttp");
            if ( !Result.Success )
            {
                ReturnResult.ProblemAdd("Loading tile types: " + Result.Problem);
                return ReturnResult;
            }

            int RedTotal = 0;
            int GreenTotal = 0;
            int BlueTotal = 0;
            int TileNum = 0;
            string strTile = "";
            BitmapGLTexture BitmapTextureArgs = new BitmapGLTexture();
            float[] AverageColour = new float[4];
            int X = 0;
            int Y = 0;
            Color Pixel = new Color();

            string GraphicPath = "";

            //tile count has been set by the ttp file

            for ( TileNum = 0; TileNum <= TileCount - 1; TileNum++ )
            {
                strTile = "tile-" + App.MinDigits(TileNum, 2) + ".png";

                //-------- 128 --------

                GraphicPath = SlashPath + Name + "-128" + Convert.ToString(App.PlatformPathSeparator) + strTile;

                Result = BitmapUtil.LoadBitmap(GraphicPath, ref Bitmap);
                if ( !Result.Success )
                {
                    //ignore and exit, since not all tile types have a corresponding tile graphic
                    return ReturnResult;
                }

                if ( Bitmap.Width != 128 | Bitmap.Height != 128 )
                {
                    ReturnResult.WarningAdd("Tile graphic " + GraphicPath + " from tileset " + Name + " is not 128x128.");
                    return ReturnResult;
                }

                BitmapTextureArgs.Texture = Bitmap;
                BitmapTextureArgs.MipMapLevel = 0;
                BitmapTextureArgs.MagFilter = TextureMagFilter.Nearest;
                BitmapTextureArgs.MinFilter = TextureMinFilter.Nearest;
                BitmapTextureArgs.TextureNum = 0;
                BitmapTextureArgs.Perform();
                Tiles[TileNum].TextureView_GL_Texture_Num = BitmapTextureArgs.TextureNum;

                BitmapTextureArgs.MagFilter = TextureMagFilter.Nearest;
                if ( SettingsManager.Settings.Mipmaps )
                {
                    BitmapTextureArgs.MinFilter = TextureMinFilter.LinearMipmapLinear;
                }
                else
                {
                    BitmapTextureArgs.MinFilter = TextureMinFilter.Nearest;
                }
                BitmapTextureArgs.TextureNum = 0;

                BitmapTextureArgs.Perform();
                Tiles[TileNum].MapView_GL_Texture_Num = BitmapTextureArgs.TextureNum;

                if ( SettingsManager.Settings.Mipmaps )
                {
                    if ( SettingsManager.Settings.MipmapsHardware )
                    {
                        GL.Enable(EnableCap.Texture2D);
                        GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                        GL.Disable(EnableCap.Texture2D);
                    }
                    else
                    {
                        clsResult MipmapResult = default(clsResult);
                        MipmapResult = GenerateMipMaps(SlashPath, strTile, BitmapTextureArgs, TileNum);
                        ReturnResult.Add(MipmapResult);
                        if ( MipmapResult.HasProblems )
                        {
                            return ReturnResult;
                        }
                    }
                    GL.GetTexImage<Single>(TextureTarget.Texture2D, 7, PixelFormat.Rgba, PixelType.Float, AverageColour);
                    Tiles[TileNum].AverageColour.Red = AverageColour[0];
                    Tiles[TileNum].AverageColour.Green = AverageColour[1];
                    Tiles[TileNum].AverageColour.Blue = AverageColour[2];
                }
                else
                {
                    RedTotal = 0;
                    GreenTotal = 0;
                    BlueTotal = 0;
                    for ( Y = 0; Y <= Bitmap.Height - 1; Y++ )
                    {
                        for ( X = 0; X <= Bitmap.Width - 1; X++ )
                        {
                            Pixel = Bitmap.GetPixel(X, Y);
                            RedTotal += Pixel.R;
                            GreenTotal += Pixel.G;
                            BlueTotal += Pixel.B;
                        }
                    }
                    Tiles[TileNum].AverageColour.Red = (float)(RedTotal / 4177920.0D);
                    Tiles[TileNum].AverageColour.Green = (float)(GreenTotal / 4177920.0D);
                    Tiles[TileNum].AverageColour.Blue = (float)(BlueTotal / 4177920.0D);
                }
            }

            return ReturnResult;
        }
Exemplo n.º 5
0
        public clsModel GetModelForPIE(SimpleList<clsPIE> PIE_List, string PIE_LCaseFileTitle, clsResult ResultOutput)
        {
            if ( PIE_LCaseFileTitle == "0" )
            {
                return null;
            }

            var A = 0;
            var PIEFile = default(StreamReader);
            var PIE = default(clsPIE);

            var Result = new clsResult("Loading PIE file " + PIE_LCaseFileTitle);

            for ( A = 0; A <= PIE_List.Count - 1; A++ )
            {
                PIE = PIE_List[A];
                if ( PIE.LCaseFileTitle == PIE_LCaseFileTitle )
                {
                    if ( PIE.Model == null )
                    {
                        PIE.Model = new clsModel();
                        try
                        {
                            PIEFile = new StreamReader(PIE.Path);
                            try
                            {
                                Result.Take(PIE.Model.ReadPIE(PIEFile, this));
                            }
                            catch ( Exception ex )
                            {
                                PIEFile.Close();
                                Result.WarningAdd(ex.Message);
                                ResultOutput.Add(Result);
                                return PIE.Model;
                            }
                        }
                        catch ( Exception ex )
                        {
                            Result.WarningAdd(ex.Message);
                        }
                    }
                    ResultOutput.Add(Result);
                    return PIE.Model;
                }
            }

            if ( !Result.HasWarnings )
            {
                Result.WarningAdd("file is missing");
            }
            ResultOutput.Add(Result);

            return null;
        }
Exemplo n.º 6
0
        public clsResult LoadDirectory(string path)
        {
            var returnResult = new clsResult("Loading tileset from '{0}'".Format2(path), false);
            logger.Info("Loading tileset from '{0}'".Format2(path));

            Bitmap bitmap = null;
            var SplitPath = new sSplitPath(path);
            var slashPath = PathUtil.EndWithPathSeperator(path);
            var result = new sResult();

            if ( SplitPath.FileTitle != "" )
            {
                Name = SplitPath.FileTitle;
            }
            else if ( SplitPath.PartCount >= 2 )
            {
                Name = SplitPath.Parts[SplitPath.PartCount - 2];
            }

            var ttpFileName = Path.ChangeExtension(Name, ".ttp");

            result = LoadTileType(Path.Combine(slashPath, ttpFileName));

            if ( !result.Success )
            {
                returnResult.ProblemAdd("Loading tile types: " + result.Problem);
                return returnResult;
            }

            var redTotal = 0;
            var greenTotal = 0;
            var blueTotal = 0;
            var tileNum = 0;
            var strTile = "";
            var bmpTextureArgs = new BitmapGLTexture();
            var AverageColour = new float[4];
            var x = 0;
            var y = 0;
            var Pixel = new Color();

            var graphicPath = "";

            //tile count has been set by the ttp file

            for ( tileNum = 0; tileNum <= TileCount - 1; tileNum++ )
            {
                strTile = "tile-" + App.MinDigits(tileNum, 2) + ".png";

                //-------- 128 --------

                var tileDir = Path.Combine(Name + "-128", strTile);
                graphicPath = Path.Combine(slashPath, tileDir);

                result = BitmapUtil.LoadBitmap(graphicPath, ref bitmap);
                if ( !result.Success )
                {
                    //ignore and exit, since not all tile types have a corresponding tile graphic
                    return returnResult;
                }

                if ( bitmap.Width != 128 | bitmap.Height != 128 )
                {
                    returnResult.WarningAdd("Tile graphic " + graphicPath + " from tileset " + Name + " is not 128x128.");
                    return returnResult;
                }

                bmpTextureArgs.Texture = bitmap;
                bmpTextureArgs.MipMapLevel = 0;
                bmpTextureArgs.MagFilter = TextureMagFilter.Nearest;
                bmpTextureArgs.MinFilter = TextureMinFilter.Nearest;
                bmpTextureArgs.TextureNum = 0;
                bmpTextureArgs.Perform();
                Tiles[tileNum].TextureViewGlTextureNum = bmpTextureArgs.TextureNum;

                bmpTextureArgs.MagFilter = TextureMagFilter.Nearest;
                if ( SettingsManager.Settings.Mipmaps )
                {
                    bmpTextureArgs.MinFilter = TextureMinFilter.LinearMipmapLinear;
                }
                else
                {
                    bmpTextureArgs.MinFilter = TextureMinFilter.Nearest;
                }
                bmpTextureArgs.TextureNum = 0;

                bmpTextureArgs.Perform();
                Tiles[tileNum].MapViewGlTextureNum = bmpTextureArgs.TextureNum;

                if ( SettingsManager.Settings.Mipmaps )
                {
                    if ( SettingsManager.Settings.MipmapsHardware )
                    {
                        GL.Enable(EnableCap.Texture2D);
                        GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                        GL.Disable(EnableCap.Texture2D);
                    }
                    else
                    {
                        var MipmapResult = default(clsResult);
                        MipmapResult = GenerateMipMaps(slashPath, strTile, bmpTextureArgs, tileNum);
                        returnResult.Add(MipmapResult);
                        if ( MipmapResult.HasProblems )
                        {
                            return returnResult;
                        }
                    }
                    GL.GetTexImage(TextureTarget.Texture2D, 7, PixelFormat.Rgba, PixelType.Float, AverageColour);
                    Tiles[tileNum].AverageColour.Red = AverageColour[0];
                    Tiles[tileNum].AverageColour.Green = AverageColour[1];
                    Tiles[tileNum].AverageColour.Blue = AverageColour[2];
                }
                else
                {
                    redTotal = 0;
                    greenTotal = 0;
                    blueTotal = 0;
                    for ( y = 0; y <= bitmap.Height - 1; y++ )
                    {
                        for ( x = 0; x <= bitmap.Width - 1; x++ )
                        {
                            Pixel = bitmap.GetPixel(x, y);
                            redTotal += Pixel.R;
                            greenTotal += Pixel.G;
                            blueTotal += Pixel.B;
                        }
                    }
                    Tiles[tileNum].AverageColour.Red = (float)(redTotal / 4177920.0D);
                    Tiles[tileNum].AverageColour.Green = (float)(greenTotal / 4177920.0D);
                    Tiles[tileNum].AverageColour.Blue = (float)(blueTotal / 4177920.0D);
                }
            }

            return returnResult;
        }
Exemplo n.º 7
0
        public void btnGenerateLayout_Click(Object sender, EventArgs e)
        {
            lstResult.Items.Clear();
            btnGenerateLayout.Enabled = false;
            lstResult_AddText("Generating layout.");
            Application.DoEvents();

            StopTrying = false;

            int LoopCount = 0;

            Generator.ClearLayout();

            Generator.GenerateTileset = null;
            Generator.Map = null;

            Generator.TopLeftPlayerCount = PlayerCount;

            switch ( cboSymmetry.SelectedIndex )
            {
                case 0: //none
                    Generator.SymmetryBlockCountXY.X = 1;
                    Generator.SymmetryBlockCountXY.Y = 1;
                    Generator.SymmetryBlockCount = 1;
                    Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[(Generator.SymmetryBlockCount - 1) + 1];
                    Generator.SymmetryBlocks[0].XYNum = new sXY_int(0, 0);
                    Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false);
                    Generator.SymmetryIsRotational = false;
                    break;
                case 1: //h rotation
                    Generator.SymmetryBlockCountXY.X = 2;
                    Generator.SymmetryBlockCountXY.Y = 1;
                    Generator.SymmetryBlockCount = 2;
                    Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[(Generator.SymmetryBlockCount - 1) + 1];
                    Generator.SymmetryBlocks[0].XYNum = new sXY_int(0, 0);
                    Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false);
                    Generator.SymmetryBlocks[0].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[0].ReflectToNum[0] = 1;
                    Generator.SymmetryBlocks[1].XYNum = new sXY_int(1, 0);
                    Generator.SymmetryBlocks[1].Orientation = new TileOrientation(true, true, false);
                    Generator.SymmetryBlocks[1].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[1].ReflectToNum[0] = 0;
                    Generator.SymmetryIsRotational = true;
                    break;
                case 2: //v rotation
                    Generator.SymmetryBlockCountXY.X = 1;
                    Generator.SymmetryBlockCountXY.Y = 2;
                    Generator.SymmetryBlockCount = 2;
                    Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[(Generator.SymmetryBlockCount - 1) + 1];
                    Generator.SymmetryBlocks[0].XYNum = new sXY_int(0, 0);
                    Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false);
                    Generator.SymmetryBlocks[0].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[0].ReflectToNum[0] = 1;
                    Generator.SymmetryBlocks[1].XYNum = new sXY_int(0, 1);
                    Generator.SymmetryBlocks[1].Orientation = new TileOrientation(true, true, false);
                    Generator.SymmetryBlocks[1].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[1].ReflectToNum[0] = 0;
                    Generator.SymmetryIsRotational = true;
                    break;
                case 3: //h flip
                    Generator.SymmetryBlockCountXY.X = 2;
                    Generator.SymmetryBlockCountXY.Y = 1;
                    Generator.SymmetryBlockCount = 2;
                    Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[(Generator.SymmetryBlockCount - 1) + 1];
                    Generator.SymmetryBlocks[0].XYNum = new sXY_int(0, 0);
                    Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false);
                    Generator.SymmetryBlocks[0].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[0].ReflectToNum[0] = 1;
                    Generator.SymmetryBlocks[1].XYNum = new sXY_int(1, 0);
                    Generator.SymmetryBlocks[1].Orientation = new TileOrientation(true, false, false);
                    Generator.SymmetryBlocks[1].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[1].ReflectToNum[0] = 0;
                    Generator.SymmetryIsRotational = false;
                    break;
                case 4: //v flip
                    Generator.SymmetryBlockCountXY.X = 1;
                    Generator.SymmetryBlockCountXY.Y = 2;
                    Generator.SymmetryBlockCount = 2;
                    Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[(Generator.SymmetryBlockCount - 1) + 1];
                    Generator.SymmetryBlocks[0].XYNum = new sXY_int(0, 0);
                    Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false);
                    Generator.SymmetryBlocks[0].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[0].ReflectToNum[0] = 1;
                    Generator.SymmetryBlocks[1].XYNum = new sXY_int(0, 1);
                    Generator.SymmetryBlocks[1].Orientation = new TileOrientation(false, true, false);
                    Generator.SymmetryBlocks[1].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[1].ReflectToNum[0] = 0;
                    Generator.SymmetryIsRotational = false;
                    Generator.SymmetryIsRotational = false;
                    break;
                case 5: //4x rotation
                    Generator.SymmetryBlockCountXY.X = 2;
                    Generator.SymmetryBlockCountXY.Y = 2;
                    Generator.SymmetryBlockCount = 4;
                    Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[(Generator.SymmetryBlockCount - 1) + 1];
                    Generator.SymmetryBlocks[0].XYNum = new sXY_int(0, 0);
                    Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false);
                    Generator.SymmetryBlocks[0].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[0].ReflectToNum[0] = 1;
                    Generator.SymmetryBlocks[0].ReflectToNum[1] = 2;
                    Generator.SymmetryBlocks[1].XYNum = new sXY_int(1, 0);
                    Generator.SymmetryBlocks[1].Orientation = new TileOrientation(true, false, true);
                    Generator.SymmetryBlocks[1].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[1].ReflectToNum[0] = 3;
                    Generator.SymmetryBlocks[1].ReflectToNum[1] = 0;
                    Generator.SymmetryBlocks[2].XYNum = new sXY_int(0, 1);
                    Generator.SymmetryBlocks[2].Orientation = new TileOrientation(false, true, true);
                    Generator.SymmetryBlocks[2].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[2].ReflectToNum[0] = 0;
                    Generator.SymmetryBlocks[2].ReflectToNum[1] = 3;
                    Generator.SymmetryBlocks[3].XYNum = new sXY_int(1, 1);
                    Generator.SymmetryBlocks[3].Orientation = new TileOrientation(true, true, false);
                    Generator.SymmetryBlocks[3].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[3].ReflectToNum[0] = 2;
                    Generator.SymmetryBlocks[3].ReflectToNum[1] = 1;
                    Generator.SymmetryIsRotational = true;
                    break;
                case 6: //hv flip
                    Generator.SymmetryBlockCountXY.X = 2;
                    Generator.SymmetryBlockCountXY.Y = 2;
                    Generator.SymmetryBlockCount = 4;
                    Generator.SymmetryBlocks = new clsGenerateMap.sSymmetryBlock[(Generator.SymmetryBlockCount - 1) + 1];
                    Generator.SymmetryBlocks[0].XYNum = new sXY_int(0, 0);
                    Generator.SymmetryBlocks[0].Orientation = new TileOrientation(false, false, false);
                    Generator.SymmetryBlocks[0].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[0].ReflectToNum[0] = 1;
                    Generator.SymmetryBlocks[0].ReflectToNum[1] = 2;
                    Generator.SymmetryBlocks[1].XYNum = new sXY_int(1, 0);
                    Generator.SymmetryBlocks[1].Orientation = new TileOrientation(true, false, false);
                    Generator.SymmetryBlocks[1].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[1].ReflectToNum[0] = 0;
                    Generator.SymmetryBlocks[1].ReflectToNum[1] = 3;
                    Generator.SymmetryBlocks[2].XYNum = new sXY_int(0, 1);
                    Generator.SymmetryBlocks[2].Orientation = new TileOrientation(false, true, false);
                    Generator.SymmetryBlocks[2].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[2].ReflectToNum[0] = 3;
                    Generator.SymmetryBlocks[2].ReflectToNum[1] = 0;
                    Generator.SymmetryBlocks[3].XYNum = new sXY_int(1, 1);
                    Generator.SymmetryBlocks[3].Orientation = new TileOrientation(true, true, false);
                    Generator.SymmetryBlocks[3].ReflectToNum = new int[(((int)Math.Round((double)(((double)Generator.SymmetryBlockCount) / 2.0))) - 1) + 1];
                    Generator.SymmetryBlocks[3].ReflectToNum[0] = 2;
                    Generator.SymmetryBlocks[3].ReflectToNum[1] = 1;
                    Generator.SymmetryIsRotational = false;
                    break;
                default:
                    MessageBox.Show("Select symmetry");
                    btnGenerateLayout.Enabled = true;
                    return;
            }

            if ( Generator.TopLeftPlayerCount * Generator.SymmetryBlockCount < 2 )
            {
                MessageBox.Show("That configuration only produces 1 player.");
                btnGenerateLayout.Enabled = true;
                return;
            }
            if ( Generator.TopLeftPlayerCount * Generator.SymmetryBlockCount > 10 )
            {
                MessageBox.Show("That configuration produces more than 10 players.");
                btnGenerateLayout.Enabled = true;
                return;
            }

            Generator.TileSize.X = ValidateTextbox(txtWidth, 48.0D, 250.0D, 1.0D);
            Generator.TileSize.Y = ValidateTextbox(txtHeight, 48.0D, 250.0D, 1.0D);
            if ( Generator.SymmetryBlockCount == 4 )
            {
                if ( Generator.TileSize.X != Generator.TileSize.Y && Generator.SymmetryIsRotational )
                {
                    MessageBox.Show("Width and height must be equal if map is rotated on two axes.");
                    btnGenerateLayout.Enabled = true;
                    return;
                }
            }
            Generator.PlayerBasePos = new sXY_int[Generator.TopLeftPlayerCount];
            double BaseMin = 12.0D;
            Position.XY_dbl BaseMax =
                new Position.XY_dbl(Math.Min(Generator.TileSize.X / Generator.SymmetryBlockCountXY.X, Generator.TileSize.X - 12.0D),
                    Math.Min(Generator.TileSize.Y / Generator.SymmetryBlockCountXY.Y, Generator.TileSize.Y - 12.0D));
            Generator.PlayerBasePos[0] = new sXY_int(ValidateTextbox(txt1x, BaseMin, BaseMax.X, App.TerrainGridSpacing),
                ValidateTextbox(txt1y, BaseMin, BaseMax.X, App.TerrainGridSpacing));
            if ( Generator.TopLeftPlayerCount >= 2 )
            {
                Generator.PlayerBasePos[1] = new sXY_int(ValidateTextbox(txt2x, BaseMin, BaseMax.X, App.TerrainGridSpacing),
                    ValidateTextbox(txt2y, BaseMin, BaseMax.Y, App.TerrainGridSpacing));
                if ( Generator.TopLeftPlayerCount >= 3 )
                {
                    Generator.PlayerBasePos[2] = new sXY_int(ValidateTextbox(txt3x, BaseMin, BaseMax.X, App.TerrainGridSpacing),
                        ValidateTextbox(txt3y, BaseMin, BaseMax.Y, App.TerrainGridSpacing));
                    if ( Generator.TopLeftPlayerCount >= 4 )
                    {
                        Generator.PlayerBasePos[3] = new sXY_int(ValidateTextbox(txt4x, BaseMin, BaseMax.X, App.TerrainGridSpacing),
                            ValidateTextbox(txt4y, BaseMin, BaseMax.Y, App.TerrainGridSpacing));
                        if ( Generator.TopLeftPlayerCount >= 5 )
                        {
                            Generator.PlayerBasePos[4] = new sXY_int(ValidateTextbox(txt5x, BaseMin, BaseMax.X, App.TerrainGridSpacing),
                                ValidateTextbox(txt5y, BaseMin, BaseMax.Y, App.TerrainGridSpacing));
                            if ( Generator.TopLeftPlayerCount >= 6 )
                            {
                                Generator.PlayerBasePos[5] = new sXY_int(ValidateTextbox(txt6x, BaseMin, BaseMax.X, App.TerrainGridSpacing),
                                    ValidateTextbox(txt6y, BaseMin, BaseMax.Y, App.TerrainGridSpacing));
                                if ( Generator.TopLeftPlayerCount >= 7 )
                                {
                                    Generator.PlayerBasePos[6] = new sXY_int(ValidateTextbox(txt7x, BaseMin, BaseMax.X, App.TerrainGridSpacing),
                                        ValidateTextbox(txt7y, BaseMin, BaseMax.Y, App.TerrainGridSpacing));
                                    if ( Generator.TopLeftPlayerCount >= 8 )
                                    {
                                        Generator.PlayerBasePos[7] = new sXY_int(ValidateTextbox(txt8x, BaseMin, BaseMax.X, App.TerrainGridSpacing),
                                            ValidateTextbox(txt8y, BaseMin, BaseMax.Y, App.TerrainGridSpacing));
                                        if ( Generator.TopLeftPlayerCount >= 9 )
                                        {
                                            Generator.PlayerBasePos[8] = new sXY_int(
                                                ValidateTextbox(txt9x, BaseMin, BaseMax.X, App.TerrainGridSpacing),
                                                ValidateTextbox(txt9y, BaseMin, BaseMax.Y, App.TerrainGridSpacing));
                                            if ( Generator.TopLeftPlayerCount >= 10 )
                                            {
                                                Generator.PlayerBasePos[9] =
                                                    new sXY_int(ValidateTextbox(txt10x, BaseMin, BaseMax.X, App.TerrainGridSpacing),
                                                        ValidateTextbox(txt10y, BaseMin, BaseMax.Y, App.TerrainGridSpacing));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Generator.LevelCount = ValidateTextbox(txtLevels, 3.0D, 5.0D, 1.0D);
            Generator.BaseLevel = ValidateTextbox(txtBaseLevel, -1.0D, Generator.LevelCount - 1, 1.0D);
            Generator.JitterScale = 1;
            Generator.MaxLevelTransition = 2;
            Generator.PassagesChance = ValidateTextbox(txtLevelFrequency, 0.0D, 100.0D, 1.0D);
            Generator.VariationChance = ValidateTextbox(txtVariation, 0.0D, 100.0D, 1.0D);
            Generator.FlatsChance = ValidateTextbox(txtFlatness, 0.0D, 100.0D, 1.0D);
            Generator.BaseFlatArea = ValidateTextbox(txtBaseArea, 1.0D, 16.0D, 1.0D);
            Generator.NodeScale = 4.0F;
            Generator.WaterSpawnQuantity = ValidateTextbox(txtWaterQuantity, 0.0D, 9999.0D, 1.0D);
            Generator.TotalWaterQuantity = ValidateTextbox(txtConnectedWater, 0.0D, 9999.0D, 1.0D);

            Application.DoEvents();
            LoopCount = 0;
            clsResult Result = default(clsResult);
            do
            {
                Result = new clsResult("");
                Result = Generator.GenerateLayout();
                if ( !Result.HasProblems )
                {
                    clsResult HeightsResult = FinishHeights();
                    Result.Add(HeightsResult);
                    if ( !HeightsResult.HasProblems )
                    {
                        lstResult_AddResult(Result);
                        lstResult_AddText("Done.");
                        btnGenerateLayout.Enabled = true;
                        break;
                    }
                }
                LoopCount++;
                lstResult_AddText("Attempt " + Convert.ToString(LoopCount) + " failed.");
                Application.DoEvents();
                if ( StopTrying )
                {
                    Generator.Map = null;
                    lstResult_AddResult(Result);
                    lstResult_AddText("Stopped.");
                    btnGenerateLayout.Enabled = true;
                    return;
                }
                lstResult_AddResult(Result);
                lstResult_AddText("Retrying...");
                Application.DoEvents();
                Generator.ClearLayout();
            } while ( true );
            lstResult_AddResult(Result);
        }
Exemplo n.º 8
0
        public virtual clsResult Load(string path)
        {
            var returnResult = new clsResult(string.Format("Loading WZ from '{0}'.", path), false);
            logger.Info("Loading WZ from '{0}'.", path);
            var subResult = new sResult();

            ZipSplitPath splitPath;
            var mapLoadName = "";

            using ( var zip = ZipFile.Read(path) )
            {
                foreach ( var e in zip )
                {
                    if ( e.IsDirectory )
                    {
                        continue;
                    }

                    splitPath = new ZipSplitPath(e.FileName);
                    logger.Debug("Found file \"{0}\".", e.FileName);
                    // Find the maps .lev
                    if ( splitPath.FileExtension != "lev" || splitPath.PartCount != 1 )
                    {
                        continue;
                    }

                    // Buggy file > 1MB
                    if ( e.UncompressedSize > 1 * 1024 * 1024 )
                    {
                        returnResult.ProblemAdd("lev file is too large.");
                        return returnResult;
                    }

                    using ( var s = e.OpenReader() )
                    {
                        var myresult = new clsResult(string.Format("Parsing file \"{0}\"", e.FileName), false);
                        logger.Info("Parsing file \"{0}\"", e.FileName);

                        try
                        {
                            var r = new StreamReader(s);
                            var text = r.ReadToEnd();
                            var levFile = LevGrammar.Lev.Parse(text);

                            if ( levFile.Levels.Count < 1 )
                            {
                                myresult.ProblemAdd("No maps found in file.");
                                returnResult.Add(myresult);
                                return returnResult;
                            }

                            // Group games by the Game key.
                            var groupGames = levFile.Levels.GroupBy(level => level.Game);

                            // Load default map if only one Game file is found.
                            if ( groupGames.Count() == 1 )
                            {
                                var level = groupGames.First().First(); //first group, first level

                                mapLoadName = level.Game;

                                switch ( level.Dataset.Substring(level.Dataset.Length - 1, 1) )
                                {
                                    case "1":
                                        map.Tileset = App.Tileset_Arizona;
                                        break;
                                    case "2":
                                        map.Tileset = App.Tileset_Urban;
                                        break;
                                    case "3":
                                        map.Tileset = App.Tileset_Urban;
                                        break;
                                    default:
                                        myresult.ProblemAdd("Unknown tileset.");
                                        returnResult.Add(myresult);
                                        return returnResult;
                                }
                            }
                            else
                            {
                                //prompt user for which of the entries to load
                                var selectToLoadResult = new frmWZLoad.clsOutput();

                                var names = groupGames
                                    .Select(gameGroup => gameGroup.First().Name)
                                    .ToArray();

                                var selectToLoadForm = new frmWZLoad(names, selectToLoadResult,
                                    "Select a map from " + new sSplitPath(path).FileTitle);
                                selectToLoadForm.ShowDialog();
                                if ( selectToLoadResult.Result < 0 )
                                {
                                    returnResult.ProblemAdd("No map selected.");
                                    return returnResult;
                                }

                                var level = groupGames.ElementAt(selectToLoadResult.Result).First();

                                mapLoadName = level.Game;

                                switch ( level.Dataset.Substring(level.Dataset.Length - 1, 1) )
                                {
                                    case "1":
                                        map.Tileset = App.Tileset_Arizona;
                                        break;
                                    case "2":
                                        map.Tileset = App.Tileset_Urban;
                                        break;
                                    case "3":
                                        map.Tileset = App.Tileset_Urban;
                                        break;
                                    default:
                                        myresult.ProblemAdd("Unknown tileset.");
                                        returnResult.Add(myresult);
                                        return returnResult;
                                }
                            }
                        }
                        catch ( Exception ex )
                        {
                            myresult.ProblemAdd(string.Format("Got an exception while parsing the .lev file: {0}", ex), false);
                            returnResult.Add(myresult);
                            logger.ErrorException("Got an exception while parsing the .lev file", ex);
                            Debugger.Break();
                        }
                    }
                }

                map.TileType_Reset();
                map.SetPainterToDefaults();

                // mapLoadName is now multiplay/maps/<mapname>.gam (thats "game" from the .lev file
                var gameSplitPath = new ZipSplitPath(mapLoadName);
                var gameFilesPath = gameSplitPath.FilePath + gameSplitPath.FileTitleWithoutExtension + "/";

                var gameZipEntry = zip[mapLoadName];
                if ( gameZipEntry == null )
                {
                    returnResult.ProblemAdd(string.Format("Game file \"{0}\" not found.", mapLoadName), false);
                    logger.Error("Game file \"{0}\" not found.", mapLoadName);
                    return returnResult;
                }
                using ( Stream s = gameZipEntry.OpenReader() )
                {
                    var reader = new BinaryReader(s);
                    subResult = read_WZ_gam(reader);
                    reader.Close();
                    if ( !subResult.Success )
                    {
                        returnResult.ProblemAdd(subResult.Problem);
                        return returnResult;
                    }
                }

                var gameMapZipEntry = zip[gameFilesPath + "game.map"];
                if ( gameMapZipEntry == null )
                {
                    returnResult.ProblemAdd(string.Format("{0}game.map file not found", gameFilesPath));
                    return returnResult;
                }
                using ( Stream s = gameMapZipEntry.OpenReader() )
                {
                    var reader = new BinaryReader(s);
                    subResult = read_WZ_map(reader);
                    reader.Close();
                    if ( !subResult.Success )
                    {
                        returnResult.ProblemAdd(subResult.Problem);
                        return returnResult;
                    }
                }

                var bjoUnits = new List<WZBJOUnit>();

                var iniFeatures = new List<IniFeature>();
                var featureIniZipEntry = zip[gameFilesPath + "feature.ini"];
                if ( featureIniZipEntry != null )
                {
                    using ( var reader = new StreamReader(featureIniZipEntry.OpenReader()) )
                    {
                        var text = reader.ReadToEnd();
                        returnResult.Add(read_INI_Features(text, iniFeatures));
                    }
                }

                if ( iniFeatures.Count() == 0 ) // no feature.ini
                {
                    var Result = new clsResult("feat.bjo", false);
                    logger.Info("Loading feat.bjo");

                    var featBJOZipEntry = zip[gameFilesPath + "feat.bjo"];
                    if ( featBJOZipEntry == null )
                    {
                        Result.WarningAdd(string.Format("{0}feat.bjo / feature.ini file not found", gameFilesPath));
                    }
                    else
                    {
                        using ( Stream s = featBJOZipEntry.OpenReader() )
                        {
                            var reader = new BinaryReader(s);
                            subResult = read_WZ_Features(reader, bjoUnits);
                            reader.Close();
                            if ( !subResult.Success )
                            {
                                Result.WarningAdd(subResult.Problem);
                            }
                        }
                    }
                    returnResult.Add(Result);
                }

                var result = new clsResult("ttypes.ttp", false);
                logger.Info("Loading ttypes.ttp");
                var ttypesEntry = zip[gameFilesPath + "ttypes.ttp"];
                if ( ttypesEntry == null )
                {
                    result.WarningAdd(string.Format("{0}ttypes.ttp file not found", gameFilesPath));
                }
                else
                {
                    using ( Stream s = ttypesEntry.OpenReader() )
                    {
                        var reader = new BinaryReader(s);
                        subResult = read_WZ_TileTypes(reader);
                        reader.Close();
                        if ( !subResult.Success )
                        {
                            result.WarningAdd(subResult.Problem);
                        }
                    }
                }
                returnResult.Add(result);

                var iniStructures = new List<IniStructure>();
                var structIniEntry = zip[gameFilesPath + "struct.ini"];
                if ( structIniEntry != null )
                {
                    using ( var reader = new StreamReader(structIniEntry.OpenReader()) )
                    {
                        var text = reader.ReadToEnd();
                        returnResult.Add(read_INI_Structures(text, iniStructures));
                    }
                }

                if ( iniStructures.Count() == 0 )
                {
                    var Result = new clsResult("struct.bjo", false);
                    logger.Info("Loading struct.bjo");
                    var structBjoEntry = zip[gameFilesPath + "struct.bjo"];
                    if ( structBjoEntry == null )
                    {
                        Result.WarningAdd(string.Format("{0}struct.bjo / struct.ini file not found", gameFilesPath));
                    }
                    else
                    {
                        using ( Stream s = structBjoEntry.OpenReader() )
                        {
                            var reader = new BinaryReader(s);
                            subResult = read_WZ_Structures(reader, bjoUnits);
                            reader.Close();
                            if ( !subResult.Success )
                            {
                                Result.WarningAdd(subResult.Problem);
                            }
                        }
                    }
                    returnResult.Add(Result);
                }

                var iniDroids = new List<IniDroid>();
                if ( structIniEntry != null )
                {
                    var droidIniEntry = zip[gameFilesPath + "droid.ini"];
                    if ( droidIniEntry != null )
                    {
                        using ( var reader = new StreamReader(droidIniEntry.OpenReader()) )
                        {
                            var text = reader.ReadToEnd();
                            returnResult.Add(read_INI_Droids(text, iniDroids));
                        }
                    }
                }

                if ( iniDroids.Count() == 0 ) // No droid.ini
                {
                    var Result = new clsResult("dinit.bjo", false);
                    logger.Info("Loading dinit.bjo");
                    var diniBjoEntry = zip[gameFilesPath + "dinit.bjo"];
                    if ( diniBjoEntry == null )
                    {
                        Result.WarningAdd(string.Format("{0}dinit.bjo / droid.ini file not found", gameFilesPath));
                    }
                    else
                    {
                        using ( Stream s = diniBjoEntry.OpenReader() )
                        {
                            var reader = new BinaryReader(s);
                            subResult = read_WZ_Droids(reader, bjoUnits);
                            reader.Close();
                            if ( !subResult.Success )
                            {
                                Result.WarningAdd(subResult.Problem);
                            }
                        }
                    }
                    returnResult.Add(Result);
                }

                returnResult.Add(createWZObjects(bjoUnits, iniStructures, iniDroids, iniFeatures));

                //objects are modified by this and must already exist
                var labelsIniEntry = zip[gameFilesPath + "labels.ini"];
                if ( labelsIniEntry != null )
                {
                    using ( var reader = new StreamReader(labelsIniEntry.OpenReader()) )
                    {
                        var text = reader.ReadToEnd();
                        returnResult.Add(read_INI_Labels(text));
                    }
                }
            }

            return returnResult;
        }
Exemplo n.º 9
0
        public static clsResult LoadTilesets(string TilesetsPath)
        {
            var ReturnResult = new clsResult("Loading tilesets", false);
            logger.Info("Loading tilesets");

            string[] TilesetDirs = null;
            try
            {
                TilesetDirs = Directory.GetDirectories(TilesetsPath);
            }
            catch ( Exception ex )
            {
                ReturnResult.ProblemAdd(ex.Message);
                return ReturnResult;
            }

            if ( TilesetDirs == null )
            {
                return ReturnResult;
            }

            var Result = default(clsResult);
            var Path = "";
            var Tileset = default(clsTileset);

            foreach ( var tempLoopVar_Path in TilesetDirs )
            {
                Path = tempLoopVar_Path;
                Tileset = new clsTileset();
                Result = Tileset.LoadDirectory(Path);
                ReturnResult.Add(Result);
                if ( !Result.HasProblems )
                {
                    Tilesets.Add(Tileset);
                }
            }

            foreach ( var tempLoopVar_Tileset in Tilesets )
            {
                Tileset = tempLoopVar_Tileset;
                if ( Tileset.Name == "tertilesc1hw" )
                {
                    Tileset.Name = "Arizona";
                    Tileset_Arizona = Tileset;
                    Tileset.IsOriginal = true;
                    Tileset.BGColour = new sRGB_sng(204.0f / 255.0f, 149.0f / 255.0f, 70.0f / 255.0f);
                }
                else if ( Tileset.Name == "tertilesc2hw" )
                {
                    Tileset.Name = "Urban";
                    Tileset_Urban = Tileset;
                    Tileset.IsOriginal = true;
                    Tileset.BGColour = new sRGB_sng(118.0f / 255.0f, 165.0f / 255.0f, 203.0f / 255.0f);
                }
                else if ( Tileset.Name == "tertilesc3hw" )
                {
                    Tileset.Name = "Rocky Mountains";
                    Tileset_Rockies = Tileset;
                    Tileset.IsOriginal = true;
                    Tileset.BGColour = new sRGB_sng(182.0f / 255.0f, 225.0f / 255.0f, 236.0f / 255.0f);
                }
            }

            if ( Tileset_Arizona == null )
            {
                ReturnResult.WarningAdd("Arizona tileset is missing.");
            }
            if ( Tileset_Urban == null )
            {
                ReturnResult.WarningAdd("Urban tileset is missing.");
            }
            if ( Tileset_Rockies == null )
            {
                ReturnResult.WarningAdd("Rocky Mountains tileset is missing.");
            }

            return ReturnResult;
        }
Exemplo n.º 10
0
        public clsResult Translate(SectionTranslator Translator)
        {
            clsResult ReturnResult = new clsResult("Translating INI");

            int A = 0;
            ErrorCount ErrorCount = new ErrorCount();

            ErrorCount.NameWarningCountMax = 16;
            ErrorCount.ValueWarningCountMax = 16;

            for ( A = 0; A <= Sections.Count - 1; A++ )
            {
                ReturnResult.Add(Sections[A].Translate(A, Translator, ErrorCount));
            }

            if ( ErrorCount.NameErrorCount > ErrorCount.NameWarningCountMax )
            {
                ReturnResult.WarningAdd("There were " + Convert.ToString(ErrorCount.NameErrorCount) + " unknown property names that were ignored.");
            }
            if ( ErrorCount.ValueErrorCount > ErrorCount.ValueWarningCountMax )
            {
                ReturnResult.WarningAdd("There were " + Convert.ToString(ErrorCount.ValueErrorCount) + " invalid values that were ignored.");
            }

            return ReturnResult;
        }
Exemplo n.º 11
0
        public clsResult Load(string path)
        {
            var returnResult = new clsResult(string.Format("Loading FMap from \"{0}\"", path), false);
            logger.Info(string.Format("Loading FMap from \"{0}\"", path));

            using ( var zip = ZipFile.Read(path) )
            {
                /*
                 * Info.ini loading
                 */
                var infoIniEntry = zip["info.ini"]; // Case insensetive.
                if ( infoIniEntry == null )
                {
                    returnResult.ProblemAdd("Unable to find file \"info.ini\".");
                    return returnResult;
                }

                FMapInfo resultInfo = null;
                using (var reader = new StreamReader(infoIniEntry.OpenReader()))
                {
                    var text = reader.ReadToEnd ();
                    resultInfo = new FMapInfo ();
                    returnResult.Add(read_FMap_Info(text, ref resultInfo));
                    if (returnResult.HasProblems)
                    {
                        return returnResult;
                    }

                    var newTerrainSize = resultInfo.TerrainSize;
                    map.Tileset = resultInfo.Tileset;

                    if ( newTerrainSize.X <= 0 | newTerrainSize.X > Constants.MapMaxSize )
                    {
                        returnResult.ProblemAdd(string.Format("Map width of {0} is not valid.", newTerrainSize.X));
                    }
                    if ( newTerrainSize.Y <= 0 | newTerrainSize.Y > Constants.MapMaxSize )
                    {
                        returnResult.ProblemAdd(string.Format("Map height of {0} is not valid.", newTerrainSize.Y));
                    }
                    if ( returnResult.HasProblems )
                    {
                        return returnResult;
                    }

                    map.SetPainterToDefaults(); //depends on tileset. must be called before loading the terrains.
                    map.TerrainBlank(newTerrainSize);
                    map.TileType_Reset();
                }

                // vertexheight.dat
                var vhEntry = zip["vertexheight.dat"]; // Case insensetive.
                if ( vhEntry == null )
                {
                    returnResult.ProblemAdd("Unable to find file \"vertexheight.dat\".");
                }
                else
                {
                    using ( Stream s = vhEntry.OpenReader() )
                    {
                        var reader = new BinaryReader(s);
                        returnResult.Add(read_FMap_VertexHeight(reader));
                        reader.Close();
                    }
                }

                // vertexterrain.dat
                var vtEntry = zip["vertexterrain.dat"]; // Case insensetive.
                if ( vtEntry == null )
                {
                    returnResult.ProblemAdd("Unable to find file \"vertexterrain.dat\".");
                }
                else
                {
                    using ( Stream s = vtEntry.OpenReader() )
                    {
                        var reader = new BinaryReader(s);
                        returnResult.Add(read_FMap_VertexTerrain(reader));
                        reader.Close();
                    }
                }

                // tiletexture.dat
                var ttEntry = zip["tiletexture.dat"]; // Case insensetive.
                if ( vtEntry == null )
                {
                    returnResult.ProblemAdd("Unable to find file \"tiletexture.dat\".");
                }
                else
                {
                    using ( Stream s = ttEntry.OpenReader() )
                    {
                        var reader = new BinaryReader(s);
                        returnResult.Add(read_FMap_TileTexture(reader));
                        reader.Close();
                    }
                }

                // tileorientation.dat
                var toEntry = zip["tileorientation.dat"]; // Case insensetive.
                if ( toEntry == null )
                {
                    returnResult.ProblemAdd("Unable to find file \"tileorientation.dat\".");
                }
                else
                {
                    using ( Stream s = toEntry.OpenReader() )
                    {
                        var reader = new BinaryReader(s);
                        returnResult.Add(read_FMap_TileOrientation(reader));
                        reader.Close();
                    }
                }

                // tilecliff.dat
                var tcEntry = zip["tilecliff.dat"]; // Case insensetive.
                if ( tcEntry == null )
                {
                    returnResult.ProblemAdd("Unable to find file \"tilecliff.dat\".");
                }
                else
                {
                    using ( Stream s = tcEntry.OpenReader() )
                    {
                        var reader = new BinaryReader(s);
                        returnResult.Add(read_FMap_TileCliff(reader));
                        reader.Close();
                    }
                }

                // roads.dat
                var roEntry = zip["roads.dat"]; // Case insensetive.
                if ( roEntry == null )
                {
                    returnResult.ProblemAdd("Unable to find file \"roads.dat\".");
                }
                else
                {
                    using ( Stream s = roEntry.OpenReader() )
                    {
                        var reader = new BinaryReader(s);
                        returnResult.Add(read_FMap_Roads(reader));
                        reader.Close();
                    }
                }

                // objects.ini
                var obEntry = zip["objects.ini"]; // Case insensetive.
                if ( obEntry == null )
                {
                    returnResult.ProblemAdd("Unable to find file \"objects.ini\".");
                }
                else
                {
                    using ( var reader = new StreamReader(obEntry.OpenReader()) )
                    {
                        var text = reader.ReadToEnd();
                        returnResult.Add(read_FMap_Objects(text));
                    }
                }

                // gateways.ini
                var gaEntry = zip["gateways.ini"]; // Case insensetive.
                if ( gaEntry == null )
                {
                    returnResult.ProblemAdd("Unable to find file \"gateways.ini\".");
                    return returnResult;
                }
                using ( var reader = new StreamReader(gaEntry.OpenReader()) )
                {
                    var text = reader.ReadToEnd();
                    returnResult.Add(read_FMap_Gateways(text));
                }

                // tiletypes.dat
                var tileTypesEntry = zip["tiletypes.dat"]; // Case insensetive.
                if ( tileTypesEntry == null )
                {
                    returnResult.ProblemAdd("Unable to find file \"tiletypes.dat\".");
                }
                else
                {
                    using ( Stream s = tileTypesEntry.OpenReader() )
                    {
                        var reader = new BinaryReader(s);
                        returnResult.Add(read_FMap_TileTypes(reader));
                        reader.Close();
                    }
                }

                // scriptlabels.ini
                var scriptLabelsEntry = zip["scriptlabels.ini"]; // Case insensetive.
                if ( scriptLabelsEntry == null )
                {
                    returnResult.ProblemAdd("Unable to find file \"scriptlabels.ini\".");
                    return returnResult;
                }
                if ( scriptLabelsEntry != null )
                {
                    using ( var reader = new StreamReader(scriptLabelsEntry.OpenReader()) )
                    {
                        var text = reader.ReadToEnd();
                        returnResult.Add(read_INI_Labels(text));
                    }
                }

                map.InterfaceOptions = resultInfo.InterfaceOptions;
            }

            return returnResult;
        }
Exemplo n.º 12
0
        public clsResult Save(string path, bool overwrite, bool compress)
        {
            var returnResult = new clsResult(string.Format("Writing FMap to \"{0}\"", path), false);
            logger.Info(string.Format("Writing FMap to \"{0}\"", path));

            if ( !overwrite )
            {
                if ( File.Exists(path) )
                {
                    returnResult.ProblemAdd("The file already exists");
                    return returnResult;
                }
            }
            try
            {
                using ( var zip = new ZipOutputStream(path) )
                {
                    // Set encoding
                    zip.AlternateEncoding = Encoding.GetEncoding("UTF-8");
                    zip.AlternateEncodingUsage = ZipOption.Always;

                    // Set compression
                    if ( compress )
                    {
                        zip.CompressionLevel = CompressionLevel.BestCompression;
                    }
                    else
                    {
                        zip.CompressionMethod = CompressionMethod.None;
                    }

                    var binaryWriter = new BinaryWriter(zip, App.UTF8Encoding);
                    var streamWriter = new StreamWriter(zip, App.UTF8Encoding);

                    zip.PutNextEntry("Info.ini");
                    var infoIniWriter = new IniWriter(streamWriter);
                    returnResult.Add(serialize_FMap_Info(infoIniWriter));
                    streamWriter.Flush();

                    zip.PutNextEntry("VertexHeight.dat");
                    returnResult.Add(serialize_FMap_VertexHeight(binaryWriter));
                    binaryWriter.Flush();

                    zip.PutNextEntry("VertexTerrain.dat");
                    returnResult.Add(serialize_FMap_VertexTerrain(binaryWriter));
                    binaryWriter.Flush();

                    zip.PutNextEntry("TileTexture.dat");
                    returnResult.Add(serialize_FMap_TileTexture(binaryWriter));
                    binaryWriter.Flush();

                    zip.PutNextEntry("TileOrientation.dat");
                    returnResult.Add(serialize_FMap_TileOrientation(binaryWriter));
                    binaryWriter.Flush();

                    zip.PutNextEntry("TileCliff.dat");
                    returnResult.Add(serialize_FMap_TileCliff(binaryWriter));
                    binaryWriter.Flush();

                    zip.PutNextEntry("Roads.dat");
                    returnResult.Add(serialize_FMap_Roads(binaryWriter));
                    binaryWriter.Flush();

                    zip.PutNextEntry("Objects.ini");
                    var objectsIniWriter = new IniWriter(streamWriter);
                    returnResult.Add(serialize_FMap_Objects(objectsIniWriter));
                    streamWriter.Flush();

                    zip.PutNextEntry("Gateways.ini");
                    var gatewaysIniWriter = new IniWriter(streamWriter);
                    returnResult.Add(serialize_FMap_Gateways(gatewaysIniWriter));
                    streamWriter.Flush();

                    zip.PutNextEntry("TileTypes.dat");
                    returnResult.Add(serialize_FMap_TileTypes(binaryWriter));
                    binaryWriter.Flush();

                    zip.PutNextEntry("ScriptLabels.ini");
                    var scriptLabelsIniWriter = new IniWriter(streamWriter);
                    returnResult.Add(serialize_WZ_LabelsINI(scriptLabelsIniWriter));
                    streamWriter.Flush();

                    streamWriter.Close();
                    binaryWriter.Close();
                }
            }
            catch ( Exception ex )
            {
                returnResult.ProblemAdd(ex.Message);
                return returnResult;
            }

            return returnResult;
        }
Exemplo n.º 13
0
        public clsResult AutoSavePerform()
        {
            var ReturnResult = new clsResult("Autosave", false);

            var DateNow = DateTime.Now;
            var path = string.Format("{0}autosaved-{1}-{2}-{3}-{4}-{5}-{6}-{7}.fmap",
                App.AutoSavePath, DateNow.Year, App.MinDigits(DateNow.Month, 2),
                App.MinDigits(DateNow.Day, 2), App.MinDigits(DateNow.Hour, 2),
                App.MinDigits(DateNow.Minute, 2), App.MinDigits(DateNow.Second, 2),
                App.MinDigits(DateNow.Millisecond, 3));

            logger.Info(string.Format("Autosave to: \"{0}\"", path));

            var fmap = new FMap (this);
            ReturnResult.Add(fmap.Save(path, false, SettingsManager.Settings.AutoSaveCompress));

            return ReturnResult;
        }
Exemplo n.º 14
0
        public clsResult LoadDirectory(string Path)
        {
            var ReturnResult = new clsResult(string.Format("Loading object data from \"{0}\"", Path));

            Path = PathUtil.EndWithPathSeperator(Path);

            var SubDirNames = "";
            var SubDirStructures = "";
            var SubDirBrain = "";
            var SubDirBody = "";
            var SubDirPropulsion = "";
            var SubDirBodyPropulsion = "";
            var SubDirConstruction = "";
            var SubDirSensor = "";
            var SubDirRepair = "";
            var SubDirTemplates = "";
            var SubDirWeapons = "";
            var SubDirECM = "";
            var SubDirFeatures = "";
            var SubDirTexpages = "";
            var SubDirAssignWeapons = "";
            var SubDirStructureWeapons = "";
            var SubDirPIEs = "";

            SubDirNames = "messages" + Convert.ToString(App.PlatformPathSeparator) + "strings" +
                          Convert.ToString(App.PlatformPathSeparator) + "names.txt";
            SubDirStructures = "stats" + Convert.ToString(App.PlatformPathSeparator) + "structures.txt";
            SubDirBrain = "stats" + Convert.ToString(App.PlatformPathSeparator) + "brain.txt";
            SubDirBody = "stats" + Convert.ToString(App.PlatformPathSeparator) + "body.txt";
            SubDirPropulsion = "stats" + Convert.ToString(App.PlatformPathSeparator) + "propulsion.txt";
            SubDirBodyPropulsion = "stats" + Convert.ToString(App.PlatformPathSeparator) + "bodypropulsionimd.txt";
            SubDirConstruction = "stats" + Convert.ToString(App.PlatformPathSeparator) + "construction.txt";
            SubDirSensor = "stats" + Convert.ToString(App.PlatformPathSeparator) + "sensor.txt";
            SubDirRepair = "stats" + Convert.ToString(App.PlatformPathSeparator) + "repair.txt";
            SubDirTemplates = "stats" + Convert.ToString(App.PlatformPathSeparator) + "templates.txt";
            SubDirWeapons = "stats" + Convert.ToString(App.PlatformPathSeparator) + "weapons.txt";
            SubDirECM = "stats" + Convert.ToString(App.PlatformPathSeparator) + "ecm.txt";
            SubDirFeatures = "stats" + Convert.ToString(App.PlatformPathSeparator) + "features.txt";
            SubDirPIEs = "pies" + Convert.ToString(App.PlatformPathSeparator);
            //SubDirStructurePIE = "structs" & ospathseperator
            //SubDirBodiesPIE = "components" & ospathseperator & "bodies" & ospathseperator
            //SubDirPropPIE = "components" & ospathseperator & "prop" & ospathseperator
            //SubDirWeaponsPIE = "components" & ospathseperator & "weapons" & ospathseperator
            SubDirTexpages = "texpages" + Convert.ToString(App.PlatformPathSeparator);
            SubDirAssignWeapons = "stats" + Convert.ToString(App.PlatformPathSeparator) + "assignweapons.txt";
            //SubDirFeaturePIE = "features" & ospathseperator
            SubDirStructureWeapons = "stats" + Convert.ToString(App.PlatformPathSeparator) + "structureweapons.txt";

            var CommaFiles = new SimpleList<clsTextFile>();

            var DataNames = new clsTextFile();
            DataNames.SubDirectory = SubDirNames;
            DataNames.UniqueField = 0;

            ReturnResult.Add(DataNames.LoadNamesFile(Path));
            if ( !DataNames.CalcUniqueField() )
            {
                ReturnResult.ProblemAdd("There are two entries for the same code in " + SubDirNames + ".");
            }

            var DataStructures = new clsTextFile();
            DataStructures.SubDirectory = SubDirStructures;
            DataStructures.FieldCount = 25;
            CommaFiles.Add(DataStructures);

            var DataBrain = new clsTextFile();
            DataBrain.SubDirectory = SubDirBrain;
            DataBrain.FieldCount = 9;
            CommaFiles.Add(DataBrain);

            var DataBody = new clsTextFile();
            DataBody.SubDirectory = SubDirBody;
            DataBody.FieldCount = 25;
            CommaFiles.Add(DataBody);

            var DataPropulsion = new clsTextFile();
            DataPropulsion.SubDirectory = SubDirPropulsion;
            DataPropulsion.FieldCount = 12;
            CommaFiles.Add(DataPropulsion);

            var DataBodyPropulsion = new clsTextFile();
            DataBodyPropulsion.SubDirectory = SubDirBodyPropulsion;
            DataBodyPropulsion.FieldCount = 5;
            DataBodyPropulsion.UniqueField = -1; //no unique requirement
            CommaFiles.Add(DataBodyPropulsion);

            var DataConstruction = new clsTextFile();
            DataConstruction.SubDirectory = SubDirConstruction;
            DataConstruction.FieldCount = 12;
            CommaFiles.Add(DataConstruction);

            var DataSensor = new clsTextFile();
            DataSensor.SubDirectory = SubDirSensor;
            DataSensor.FieldCount = 16;
            CommaFiles.Add(DataSensor);

            var DataRepair = new clsTextFile();
            DataRepair.SubDirectory = SubDirRepair;
            DataRepair.FieldCount = 14;
            CommaFiles.Add(DataRepair);

            var DataTemplates = new clsTextFile();
            DataTemplates.SubDirectory = SubDirTemplates;
            DataTemplates.FieldCount = 12;
            CommaFiles.Add(DataTemplates);

            var DataECM = new clsTextFile();
            DataECM.SubDirectory = SubDirECM;
            DataECM.FieldCount = 14;
            CommaFiles.Add(DataECM);

            var DataFeatures = new clsTextFile();
            DataFeatures.SubDirectory = SubDirFeatures;
            DataFeatures.FieldCount = 11;
            CommaFiles.Add(DataFeatures);

            var DataAssignWeapons = new clsTextFile();
            DataAssignWeapons.SubDirectory = SubDirAssignWeapons;
            DataAssignWeapons.FieldCount = 5;
            CommaFiles.Add(DataAssignWeapons);

            var DataWeapons = new clsTextFile();
            DataWeapons.SubDirectory = SubDirWeapons;
            DataWeapons.FieldCount = 53;
            CommaFiles.Add(DataWeapons);

            var DataStructureWeapons = new clsTextFile();
            DataStructureWeapons.SubDirectory = SubDirStructureWeapons;
            DataStructureWeapons.FieldCount = 6;
            CommaFiles.Add(DataStructureWeapons);

            var TextFile = default(clsTextFile);

            foreach ( var tempLoopVar_TextFile in CommaFiles )
            {
                TextFile = tempLoopVar_TextFile;
                var Result = TextFile.LoadCommaFile(Path);
                ReturnResult.Add(Result);
                if ( !Result.HasProblems )
                {
                    if ( TextFile.CalcIsFieldCountValid() )
                    {
                        if ( !TextFile.CalcUniqueField() )
                        {
                            ReturnResult.ProblemAdd("An entry in field " + Convert.ToString(TextFile.UniqueField) + " was not unique for file " +
                                                    TextFile.SubDirectory + ".");
                        }
                    }
                    else
                    {
                        ReturnResult.ProblemAdd("There were entries with the wrong number of fields for file " + TextFile.SubDirectory + ".");
                    }
                }
            }

            if ( ReturnResult.HasProblems )
            {
                return ReturnResult;
            }

            //load texpages

            string[] TexFiles = null;

            try
            {
                TexFiles = Directory.GetFiles(Path + SubDirTexpages);
            }
            catch ( Exception )
            {
                ReturnResult.WarningAdd("Unable to access texture pages.");
                TexFiles = new string[0];
            }

            var Text = "";
            Bitmap Bitmap = null;
            var InstrPos2 = 0;
            var BitmapTextureArgs = new BitmapGLTexture();
            var BitmapResult = new sResult();

            foreach ( var tempLoopVar_Text in TexFiles )
            {
                Text = tempLoopVar_Text;
                if ( Text.Substring(Text.Length - 4, 4).ToLower() == ".png" )
                {
                    var Result = new clsResult(string.Format("Loading texture page \"{0}\"", Text));
                    if ( File.Exists(Text) )
                    {
                        BitmapResult = BitmapUtil.LoadBitmap(Text, ref Bitmap);
                        var NewPage = new clsTexturePage();
                        if ( BitmapResult.Success )
                        {
                            Result.Take(BitmapUtil.BitmapIsGLCompatible(Bitmap));
                            BitmapTextureArgs.MagFilter = TextureMagFilter.Nearest;
                            BitmapTextureArgs.MinFilter = TextureMinFilter.Nearest;
                            BitmapTextureArgs.TextureNum = 0;
                            BitmapTextureArgs.MipMapLevel = 0;
                            BitmapTextureArgs.Texture = Bitmap;
                            BitmapTextureArgs.Perform();
                            NewPage.GLTexture_Num = BitmapTextureArgs.TextureNum;
                        }
                        else
                        {
                            Result.WarningAdd(BitmapResult.Problem);
                        }
                        InstrPos2 = Text.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
                        NewPage.FileTitle = Text.Substring(InstrPos2 + 1, Text.Length - 5 - InstrPos2);

                        TexturePages.Add(NewPage);
                    }
                    else
                    {
                        Result.WarningAdd("Texture page missing (" + Text + ").");
                    }
                    ReturnResult.Add(Result);
                }
            }

            //load PIEs

            string[] PIE_Files = null;
            var PIE_List = new SimpleList<clsPIE>();
            var NewPIE = default(clsPIE);

            try
            {
                PIE_Files = Directory.GetFiles(Path + SubDirPIEs);
            }
            catch ( Exception )
            {
                ReturnResult.WarningAdd("Unable to access PIE files.");
                PIE_Files = new string[0];
            }

            var SplitPath = new sSplitPath();

            foreach ( var tempLoopVar_Text in PIE_Files )
            {
                Text = tempLoopVar_Text;
                SplitPath = new sSplitPath(Text);
                if ( SplitPath.FileExtension.ToLower() == "pie" )
                {
                    NewPIE = new clsPIE();
                    NewPIE.Path = Text;
                    NewPIE.LCaseFileTitle = SplitPath.FileTitle.ToLower();
                    PIE_List.Add(NewPIE);
                }
            }

            //interpret stats

            var Attachment = default(clsAttachment);
            var BaseAttachment = default(clsAttachment);
            var Connector = new XYZDouble();
            var structureTypeBase = default(StructureTypeBase);
            var featureTypeBase = default(FeatureTypeBase);
            var Template = default(DroidTemplate);
            var Body = default(Body);
            var Propulsion = default(Propulsion);
            var Construct = default(Construct);
            var Weapon = default(Weapon);
            var Repair = default(Repair);
            var Sensor = default(Sensor);
            var Brain = default(Brain);
            var ECM = default(Ecm);
            string[] Fields = null;

            //interpret body

            foreach ( var tempLoopVar_Fields in DataBody.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Body = new Body();
                Body.ObjectDataLink.Connect(Bodies);
                Body.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Body, ReturnResult);
                IOUtil.InvariantParse(Fields[6], ref Body.Hitpoints);
                Body.Designable = Fields[24] != "0";
                Body.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[7].ToLower(), ReturnResult));
            }

            //interpret propulsion

            foreach ( var tempLoopVar_Fields in DataPropulsion.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Propulsion = new Propulsion(Bodies.Count);
                Propulsion.ObjectDataLink.Connect(Propulsions);
                Propulsion.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Propulsion, ReturnResult);
                IOUtil.InvariantParse(Fields[7], ref Propulsion.HitPoints);
                //.Propulsions(Propulsion_Num).PIE = LCase(DataPropulsion.Entries(Propulsion_Num).FieldValues(8))
                Propulsion.Designable = Fields[11] != "0";
            }

            //interpret body-propulsions

            var BodyPropulsionPIEs = new BodyProp[Bodies.Count, Propulsions.Count];
            for ( var A = 0; A <= Bodies.Count - 1; A++ )
            {
                for ( var B = 0; B <= Propulsions.Count - 1; B++ )
                {
                    BodyPropulsionPIEs[A, B] = new BodyProp();
                    BodyPropulsionPIEs[A, B].LeftPIE = "0";
                    BodyPropulsionPIEs[A, B].RightPIE = "0";
                }
            }

            foreach ( var tempLoopVar_Fields in DataBodyPropulsion.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Body = FindBodyCode(Fields[0]);
                Propulsion = FindPropulsionCode(Fields[1]);
                if ( Body != null && Propulsion != null )
                {
                    if ( Fields[2] != "0" )
                    {
                        BodyPropulsionPIEs[Body.ObjectDataLink.ArrayPosition, Propulsion.ObjectDataLink.ArrayPosition].LeftPIE = Fields[2].ToLower();
                    }
                    if ( Fields[3] != "0" )
                    {
                        BodyPropulsionPIEs[Body.ObjectDataLink.ArrayPosition, Propulsion.ObjectDataLink.ArrayPosition].RightPIE = Fields[3].ToLower();
                    }
                }
            }

            //set propulsion-body PIEs

            for ( var A = 0; A <= Propulsions.Count - 1; A++ )
            {
                Propulsion = Propulsions[A];
                for ( var B = 0; B <= Bodies.Count - 1; B++ )
                {
                    Body = Bodies[B];
                    Propulsion.Bodies[B].LeftAttachment = new clsAttachment();
                    Propulsion.Bodies[B].LeftAttachment.Models.Add(GetModelForPIE(PIE_List, BodyPropulsionPIEs[B, A].LeftPIE, ReturnResult));
                    Propulsion.Bodies[B].RightAttachment = new clsAttachment();
                    Propulsion.Bodies[B].RightAttachment.Models.Add(GetModelForPIE(PIE_List, BodyPropulsionPIEs[B, A].RightPIE, ReturnResult));
                }
            }

            //interpret construction

            foreach ( var tempLoopVar_Fields in DataConstruction.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Construct = new Construct();
                Construct.ObjectDataLink.Connect(Constructors);
                Construct.TurretObjectDataLink.Connect(Turrets);
                Construct.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Construct, ReturnResult);
                Construct.Designable = Fields[11] != "0";
                Construct.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[8].ToLower(), ReturnResult));
            }

            //interpret weapons

            foreach ( var tempLoopVar_Fields in DataWeapons.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Weapon = new Weapon();
                Weapon.ObjectDataLink.Connect(Weapons);
                Weapon.TurretObjectDataLink.Connect(Turrets);
                Weapon.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Weapon, ReturnResult);
                IOUtil.InvariantParse(Fields[7], ref Weapon.HitPoints);
                Weapon.Designable = Fields[51] != "0";
                Weapon.Attachment.Models.Add(GetModelForPIE(PIE_List, Convert.ToString(Fields[8].ToLower()), ReturnResult));
                Weapon.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[9].ToLower(), ReturnResult));
            }

            //interpret sensor

            foreach ( var tempLoopVar_Fields in DataSensor.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Sensor = new Sensor();
                Sensor.ObjectDataLink.Connect(Sensors);
                Sensor.TurretObjectDataLink.Connect(Turrets);
                Sensor.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Sensor, ReturnResult);
                IOUtil.InvariantParse(Fields[7], ref Sensor.HitPoints);
                Sensor.Designable = Fields[15] != "0";
                switch ( Fields[11].ToLower() )
                {
                    case "turret":
                        Sensor.Location = Sensor.enumLocation.Turret;
                        break;
                    case "default":
                        Sensor.Location = Sensor.enumLocation.Invisible;
                        break;
                    default:
                        Sensor.Location = Sensor.enumLocation.Invisible;
                        break;
                }
                Sensor.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[8].ToLower(), ReturnResult));
                Sensor.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[9].ToLower(), ReturnResult));
            }

            //interpret repair

            foreach ( var tempLoopVar_Fields in DataRepair.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Repair = new Repair();
                Repair.ObjectDataLink.Connect(Repairs);
                Repair.TurretObjectDataLink.Connect(Turrets);
                Repair.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Repair, ReturnResult);
                Repair.Designable = Fields[13] != "0";
                Repair.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[9].ToLower(), ReturnResult));
                Repair.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[10].ToLower(), ReturnResult));
            }

            //interpret brain

            foreach ( var tempLoopVar_Fields in DataBrain.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Brain = new Brain();
                Brain.ObjectDataLink.Connect(Brains);
                Brain.TurretObjectDataLink.Connect(Turrets);
                Brain.Code = Fields[0];
                SetComponentName(DataNames.ResultData, Brain, ReturnResult);
                Brain.Designable = true;
                Weapon = FindWeaponCode(Fields[7]);
                if ( Weapon != null )
                {
                    Brain.Weapon = Weapon;
                    Brain.Attachment = Weapon.Attachment;
                }
            }

            //interpret ecm

            foreach ( var tempLoopVar_Fields in DataECM.ResultData )
            {
                Fields = tempLoopVar_Fields;
                ECM = new Ecm();
                ECM.ObjectDataLink.Connect(ECMs);
                ECM.TurretObjectDataLink.Connect(Turrets);
                ECM.Code = Fields[0];
                SetComponentName(DataNames.ResultData, ECM, ReturnResult);
                IOUtil.InvariantParse(Fields[7], ref ECM.HitPoints);
                ECM.Designable = false;
                ECM.Attachment.Models.Add(GetModelForPIE(PIE_List, Fields[8].ToLower(), ReturnResult));
            }

            //interpret feature

            foreach ( var tempLoopVar_Fields in DataFeatures.ResultData )
            {
                Fields = tempLoopVar_Fields;
                featureTypeBase = new FeatureTypeBase();
                featureTypeBase.UnitType_ObjectDataLink.Connect(UnitTypes);
                featureTypeBase.FeatureType_ObjectDataLink.Connect(FeatureTypes);
                featureTypeBase.Code = Fields[0];
                if ( Fields[7] == "OIL RESOURCE" ) //type
                {
                    featureTypeBase.FeatureType = FeatureTypeBase.enumFeatureType.OilResource;
                }
                SetFeatureName(DataNames.ResultData, featureTypeBase, ReturnResult);
                if ( !IOUtil.InvariantParse(Fields[1], ref featureTypeBase.Footprint.X) )
                {
                    ReturnResult.WarningAdd("Feature footprint-x was not an integer for " + featureTypeBase.Code + ".");
                }
                if ( !IOUtil.InvariantParse(Fields[2], ref featureTypeBase.Footprint.Y) )
                {
                    ReturnResult.WarningAdd("Feature footprint-y was not an integer for " + featureTypeBase.Code + ".");
                }
                featureTypeBase.BaseAttachment = new clsAttachment();
                BaseAttachment = featureTypeBase.BaseAttachment;
                Text = Fields[6].ToLower();
                Attachment = BaseAttachment.CreateAttachment();
                Attachment.Models.Add(GetModelForPIE(PIE_List, Text, ReturnResult));
            }

            //interpret structure

            foreach ( var tempLoopVar_Fields in DataStructures.ResultData )
            {
                Fields = tempLoopVar_Fields;
                var StructureCode = Fields[0];
                var StructureTypeText = Fields[1];
                var StructurePIEs = Fields[21].ToLower().Split('@');
                var StructureFootprint = new XYInt();
                var StructureBasePIE = Fields[22].ToLower();
                if ( !IOUtil.InvariantParse(Fields[5], ref StructureFootprint.X) )
                {
                    ReturnResult.WarningAdd("Structure footprint-x was not an integer for " + StructureCode + ".");
                }
                if ( !IOUtil.InvariantParse(Fields[6], ref StructureFootprint.Y) )
                {
                    ReturnResult.WarningAdd("Structure footprint-y was not an integer for " + StructureCode + ".");
                }
                if ( StructureTypeText != "WALL" || StructurePIEs.GetLength(0) != 4 )
                {
                    //this is NOT a generic wall
                    structureTypeBase = new StructureTypeBase();
                    structureTypeBase.UnitType_ObjectDataLink.Connect(UnitTypes);
                    structureTypeBase.StructureType_ObjectDataLink.Connect(StructureTypes);
                    structureTypeBase.Code = StructureCode;
                    SetStructureName(DataNames.ResultData, structureTypeBase, ReturnResult);
                    structureTypeBase.Footprint = StructureFootprint;
                    switch ( StructureTypeText )
                    {
                        case "DEMOLISH":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Demolish;
                            break;
                        case "WALL":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Wall;
                            break;
                        case "CORNER WALL":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.CornerWall;
                            break;
                        case "FACTORY":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Factory;
                            break;
                        case "CYBORG FACTORY":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.CyborgFactory;
                            break;
                        case "VTOL FACTORY":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.VTOLFactory;
                            break;
                        case "COMMAND":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Command;
                            break;
                        case "HQ":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.HQ;
                            break;
                        case "DEFENSE":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Defense;
                            break;
                        case "POWER GENERATOR":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.PowerGenerator;
                            break;
                        case "POWER MODULE":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.PowerModule;
                            break;
                        case "RESEARCH":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Research;
                            break;
                        case "RESEARCH MODULE":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.ResearchModule;
                            break;
                        case "FACTORY MODULE":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.FactoryModule;
                            break;
                        case "DOOR":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.DOOR;
                            break;
                        case "REPAIR FACILITY":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.RepairFacility;
                            break;
                        case "SAT UPLINK":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.DOOR;
                            break;
                        case "REARM PAD":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.RearmPad;
                            break;
                        case "MISSILE SILO":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.MissileSilo;
                            break;
                        case "RESOURCE EXTRACTOR":
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.ResourceExtractor;
                            break;
                        default:
                            structureTypeBase.StructureType = StructureTypeBase.enumStructureType.Unknown;
                            break;
                    }

                    BaseAttachment = structureTypeBase.BaseAttachment;
                    if ( StructurePIEs.GetLength(0) > 0 )
                    {
                        BaseAttachment.Models.Add(GetModelForPIE(PIE_List, StructurePIEs[0], ReturnResult));
                    }
                    structureTypeBase.StructureBasePlate = GetModelForPIE(PIE_List, StructureBasePIE, ReturnResult);
                    if ( BaseAttachment.Models.Count == 1 )
                    {
                        if ( BaseAttachment.Models[0].ConnectorCount >= 1 )
                        {
                            Connector = BaseAttachment.Models[0].Connectors[0];
                            var StructureWeapons = default(SimpleList<string[]>);
                            StructureWeapons = GetRowsWithValue(DataStructureWeapons.ResultData, structureTypeBase.Code);
                            if ( StructureWeapons.Count > 0 )
                            {
                                Weapon = FindWeaponCode(Convert.ToString(StructureWeapons[0][1]));
                            }
                            else
                            {
                                Weapon = null;
                            }
                            ECM = FindECMCode(Fields[18]);
                            Sensor = FindSensorCode(Fields[19]);
                            if ( Weapon != null )
                            {
                                if ( Weapon.Code != "ZNULLWEAPON" )
                                {
                                    Attachment = BaseAttachment.CopyAttachment(Weapon.Attachment);
                                    Attachment.Pos_Offset = Connector;
                                }
                            }
                            if ( ECM != null )
                            {
                                if ( ECM.Code != "ZNULLECM" )
                                {
                                    Attachment = BaseAttachment.CopyAttachment(ECM.Attachment);
                                    Attachment.Pos_Offset = Connector;
                                }
                            }
                            if ( Sensor != null )
                            {
                                if ( Sensor.Code != "ZNULLSENSOR" )
                                {
                                    Attachment = BaseAttachment.CopyAttachment(Sensor.Attachment);
                                    Attachment.Pos_Offset = Connector;
                                }
                            }
                        }
                    }
                }
                else
                {
                    //this is a generic wall
                    var NewWall = new clsWallType();
                    NewWall.WallType_ObjectDataLink.Connect(WallTypes);
                    NewWall.Code = StructureCode;
                    SetWallName(DataNames.ResultData, NewWall, ReturnResult);
                    var WallBasePlate = GetModelForPIE(PIE_List, StructureBasePIE, ReturnResult);

                    var WallNum = 0;
                    var wallStructureTypeBase = default(StructureTypeBase);
                    for ( WallNum = 0; WallNum <= 3; WallNum++ )
                    {
                        wallStructureTypeBase = new StructureTypeBase();
                        wallStructureTypeBase.UnitType_ObjectDataLink.Connect(UnitTypes);
                        wallStructureTypeBase.StructureType_ObjectDataLink.Connect(StructureTypes);
                        wallStructureTypeBase.WallLink.Connect(NewWall.Segments);
                        wallStructureTypeBase.Code = StructureCode;
                        Text = NewWall.Name;
                        switch ( WallNum )
                        {
                            case 0:
                                Text += " - ";
                                break;
                            case 1:
                                Text += " + ";
                                break;
                            case 2:
                                Text += " T ";
                                break;
                            case 3:
                                Text += " L ";
                                break;
                        }
                        wallStructureTypeBase.Name = Text;
                        wallStructureTypeBase.Footprint = StructureFootprint;
                        wallStructureTypeBase.StructureType = StructureTypeBase.enumStructureType.Wall;

                        BaseAttachment = wallStructureTypeBase.BaseAttachment;

                        Text = StructurePIEs[WallNum];
                        BaseAttachment.Models.Add(GetModelForPIE(PIE_List, Text, ReturnResult));
                        wallStructureTypeBase.StructureBasePlate = WallBasePlate;
                    }
                }
            }

            //interpret templates

            var TurretConflictCount = 0;
            foreach ( var tempLoopVar_Fields in DataTemplates.ResultData )
            {
                Fields = tempLoopVar_Fields;
                Template = new DroidTemplate();
                Template.UnitType_ObjectDataLink.Connect(UnitTypes);
                Template.DroidTemplate_ObjectDataLink.Connect(DroidTemplates);
                Template.Code = Fields[0];
                SetTemplateName(DataNames.ResultData, Template, ReturnResult);
                switch ( Fields[9] ) //type
                {
                    case "ZNULLDROID":
                        Template.TemplateDroidType = App.TemplateDroidType_Null;
                        break;
                    case "DROID":
                        Template.TemplateDroidType = App.TemplateDroidType_Droid;
                        break;
                    case "CYBORG":
                        Template.TemplateDroidType = App.TemplateDroidType_Cyborg;
                        break;
                    case "CYBORG_CONSTRUCT":
                        Template.TemplateDroidType = App.TemplateDroidType_CyborgConstruct;
                        break;
                    case "CYBORG_REPAIR":
                        Template.TemplateDroidType = App.TemplateDroidType_CyborgRepair;
                        break;
                    case "CYBORG_SUPER":
                        Template.TemplateDroidType = App.TemplateDroidType_CyborgSuper;
                        break;
                    case "TRANSPORTER":
                        Template.TemplateDroidType = App.TemplateDroidType_Transporter;
                        break;
                    case "PERSON":
                        Template.TemplateDroidType = App.TemplateDroidType_Person;
                        break;
                    default:
                        Template.TemplateDroidType = null;
                        ReturnResult.WarningAdd("Template " + Template.GetDisplayTextCode() + " had an unrecognised type.");
                        break;
                }
                var LoadPartsArgs = new DroidDesign.sLoadPartsArgs();
                LoadPartsArgs.Body = FindBodyCode(Fields[2]);
                LoadPartsArgs.Brain = FindBrainCode(Fields[3]);
                LoadPartsArgs.Construct = FindConstructorCode(Fields[4]);
                LoadPartsArgs.ECM = FindECMCode(Fields[5]);
                LoadPartsArgs.Propulsion = FindPropulsionCode(Fields[7]);
                LoadPartsArgs.Repair = FindRepairCode(Fields[8]);
                LoadPartsArgs.Sensor = FindSensorCode(Fields[10]);
                var TemplateWeapons = GetRowsWithValue(DataAssignWeapons.ResultData, Template.Code);
                if ( TemplateWeapons.Count > 0 )
                {
                    Text = Convert.ToString(TemplateWeapons[0][1]);
                    if ( Text != "NULL" )
                    {
                        LoadPartsArgs.Weapon1 = FindWeaponCode(Text);
                    }
                    Text = Convert.ToString(TemplateWeapons[0][2]);
                    if ( Text != "NULL" )
                    {
                        LoadPartsArgs.Weapon2 = FindWeaponCode(Text);
                    }
                    Text = Convert.ToString(TemplateWeapons[0][3]);
                    if ( Text != "NULL" )
                    {
                        LoadPartsArgs.Weapon3 = FindWeaponCode(Text);
                    }
                }
                if ( !Template.LoadParts(LoadPartsArgs) )
                {
                    if ( TurretConflictCount < 16 )
                    {
                        ReturnResult.WarningAdd("Template " + Template.GetDisplayTextCode() + " had multiple conflicting turrets.");
                    }
                    TurretConflictCount++;
                }
            }
            if ( TurretConflictCount > 0 )
            {
                ReturnResult.WarningAdd(TurretConflictCount + " templates had multiple conflicting turrets.");
            }

            return ReturnResult;
        }
Exemplo n.º 15
0
        public clsResult Load_FMap(string Path)
        {
            clsResult ReturnResult =
                new clsResult("Loading FMap from " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote));

            ZipStreamEntry ZipSearchResult = default(ZipStreamEntry);
            string FindPath = "";

            FMapInfo ResultInfo = null;

            FindPath = "info.ini";
            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, FindPath);
            if ( ZipSearchResult == null )
            {
                ReturnResult.ProblemAdd("Unable to find file " + Convert.ToString(ControlChars.Quote) + FindPath + Convert.ToString(ControlChars.Quote) +
                                        ".");
                return ReturnResult;
            }
            else
            {
                StreamReader Info_StreamReader = new StreamReader(ZipSearchResult.Stream);
                ReturnResult.Add(Read_FMap_Info(Info_StreamReader, ref ResultInfo));
                Info_StreamReader.Close();
                if ( ReturnResult.HasProblems )
                {
                    return ReturnResult;
                }
            }

            sXY_int NewTerrainSize = ResultInfo.TerrainSize;
            Tileset = ResultInfo.Tileset;

            if ( NewTerrainSize.X <= 0 | NewTerrainSize.X > Constants.MapMaxSize )
            {
                ReturnResult.ProblemAdd("Map width of " + Convert.ToString(NewTerrainSize.X) + " is not valid.");
            }
            if ( NewTerrainSize.Y <= 0 | NewTerrainSize.Y > Constants.MapMaxSize )
            {
                ReturnResult.ProblemAdd("Map height of " + Convert.ToString(NewTerrainSize.Y) + " is not valid.");
            }
            if ( ReturnResult.HasProblems )
            {
                return ReturnResult;
            }

            SetPainterToDefaults(); //depends on tileset. must be called before loading the terrains.
            TerrainBlank(NewTerrainSize);
            TileType_Reset();

            FindPath = "vertexheight.dat";
            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, FindPath);
            if ( ZipSearchResult == null )
            {
                ReturnResult.WarningAdd("Unable to find file " + Convert.ToString(ControlChars.Quote) + FindPath + Convert.ToString(ControlChars.Quote) +
                                        ".");
            }
            else
            {
                BinaryReader VertexHeight_Reader = new BinaryReader(ZipSearchResult.Stream);
                ReturnResult.Add(Read_FMap_VertexHeight(VertexHeight_Reader));
                VertexHeight_Reader.Close();
            }

            FindPath = "vertexterrain.dat";
            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, FindPath);
            if ( ZipSearchResult == null )
            {
                ReturnResult.WarningAdd("Unable to find file " + Convert.ToString(ControlChars.Quote) + FindPath + Convert.ToString(ControlChars.Quote) +
                                        ".");
            }
            else
            {
                BinaryReader VertexTerrain_Reader = new BinaryReader(ZipSearchResult.Stream);
                ReturnResult.Add(Read_FMap_VertexTerrain(VertexTerrain_Reader));
                VertexTerrain_Reader.Close();
            }

            FindPath = "tiletexture.dat";
            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, FindPath);
            if ( ZipSearchResult == null )
            {
                ReturnResult.WarningAdd("Unable to find file " + Convert.ToString(ControlChars.Quote) + FindPath + Convert.ToString(ControlChars.Quote) +
                                        ".");
            }
            else
            {
                BinaryReader TileTexture_Reader = new BinaryReader(ZipSearchResult.Stream);
                ReturnResult.Add(Read_FMap_TileTexture(TileTexture_Reader));
                TileTexture_Reader.Close();
            }

            FindPath = "tileorientation.dat";
            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, FindPath);
            if ( ZipSearchResult == null )
            {
                ReturnResult.WarningAdd("Unable to find file " + Convert.ToString(ControlChars.Quote) + FindPath + Convert.ToString(ControlChars.Quote) +
                                        ".");
            }
            else
            {
                BinaryReader TileOrientation_Reader = new BinaryReader(ZipSearchResult.Stream);
                ReturnResult.Add(Read_FMap_TileOrientation(TileOrientation_Reader));
                TileOrientation_Reader.Close();
            }

            FindPath = "tilecliff.dat";
            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, FindPath);
            if ( ZipSearchResult == null )
            {
                ReturnResult.WarningAdd("Unable to find file " + Convert.ToString(ControlChars.Quote) + FindPath + Convert.ToString(ControlChars.Quote) +
                                        ".");
            }
            else
            {
                BinaryReader TileCliff_Reader = new BinaryReader(ZipSearchResult.Stream);
                ReturnResult.Add(Read_FMap_TileCliff(TileCliff_Reader));
                TileCliff_Reader.Close();
            }

            FindPath = "roads.dat";
            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, FindPath);
            if ( ZipSearchResult == null )
            {
                ReturnResult.WarningAdd("Unable to find file " + Convert.ToString(ControlChars.Quote) + FindPath + Convert.ToString(ControlChars.Quote) +
                                        ".");
            }
            else
            {
                BinaryReader Roads_Reader = new BinaryReader(ZipSearchResult.Stream);
                ReturnResult.Add(Read_FMap_Roads(Roads_Reader));
                Roads_Reader.Close();
            }

            FindPath = "objects.ini";
            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, FindPath);
            if ( ZipSearchResult == null )
            {
                ReturnResult.WarningAdd("Unable to find file " + Convert.ToString(ControlChars.Quote) + FindPath + Convert.ToString(ControlChars.Quote) +
                                        ".");
            }
            else
            {
                StreamReader Objects_Reader = new StreamReader(ZipSearchResult.Stream);
                ReturnResult.Add(Read_FMap_Objects(Objects_Reader));
                Objects_Reader.Close();
            }

            FindPath = "gateways.ini";
            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, FindPath);
            if ( ZipSearchResult == null )
            {
                ReturnResult.WarningAdd("Unable to find file " + Convert.ToString(ControlChars.Quote) + FindPath + Convert.ToString(ControlChars.Quote) +
                                        ".");
            }
            else
            {
                StreamReader Gateway_Reader = new StreamReader(ZipSearchResult.Stream);
                ReturnResult.Add(Read_FMap_Gateways(Gateway_Reader));
                Gateway_Reader.Close();
            }

            FindPath = "tiletypes.dat";
            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, FindPath);
            if ( ZipSearchResult == null )
            {
                ReturnResult.WarningAdd("Unable to find file " + Convert.ToString(ControlChars.Quote) + FindPath + Convert.ToString(ControlChars.Quote) +
                                        ".");
            }
            else
            {
                BinaryReader TileTypes_Reader = new BinaryReader(ZipSearchResult.Stream);
                ReturnResult.Add(Read_FMap_TileTypes(TileTypes_Reader));
                TileTypes_Reader.Close();
            }

            FindPath = "scriptlabels.ini";
            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, FindPath);
            if ( ZipSearchResult == null )
            {
            }
            else
            {
                clsResult Result = new clsResult("Reading labels");
                IniReader LabelsINI = new IniReader();
                StreamReader LabelsINI_Reader = new StreamReader(ZipSearchResult.Stream);
                Result.Take(LabelsINI.ReadFile(LabelsINI_Reader));
                LabelsINI_Reader.Close();
                Result.Take(Read_WZ_Labels(LabelsINI, true));
                ReturnResult.Add(Result);
            }

            InterfaceOptions = ResultInfo.InterfaceOptions;

            return ReturnResult;
        }
Exemplo n.º 16
0
        public clsResult Save(sWrite_WZ_Args Args)
        {
            var returnResult =
                new clsResult("Compiling to \"{0}\"".Format2(Args.Path), false);
            logger.Info("Compiling to \"{0}\"".Format2(Args.Path));

            try
            {
                switch ( Args.CompileType )
                {
                    case sWrite_WZ_Args.enumCompileType.Multiplayer:
                        if ( Args.Multiplayer == null )
                        {
                            returnResult.ProblemAdd("Multiplayer arguments were not passed.");
                            return returnResult;
                        }
                        if ( Args.Multiplayer.PlayerCount < 2 | Args.Multiplayer.PlayerCount > Constants.PlayerCountMax )
                        {
                            returnResult.ProblemAdd(string.Format("Number of players was below 2 or above {0}.", Constants.PlayerCountMax));
                            return returnResult;
                        }
                        break;
                    case sWrite_WZ_Args.enumCompileType.Campaign:
                        if ( Args.Campaign == null )
                        {
                            returnResult.ProblemAdd("Campaign arguments were not passed.");
                            return returnResult;
                        }
                        break;
                    default:
                        returnResult.ProblemAdd("Unknown compile method.");
                        return returnResult;
                }

                if ( !Args.Overwrite )
                {
                    if ( File.Exists(Args.Path) )
                    {
                        returnResult.ProblemAdd("The selected file already exists.");
                        return returnResult;
                    }
                }

                if ( Args.CompileType == sWrite_WZ_Args.enumCompileType.Multiplayer )
                {
                    if ( !Args.Overwrite )
                    {
                        if ( File.Exists(Args.Path) )
                        {
                            returnResult.ProblemAdd(string.Format("A file already exists at: {0}", Args.Path));
                            return returnResult;
                        }
                    }

                    try
                    {
                        using ( var zip = new ZipOutputStream(Args.Path) )
                        {
                            // Set encoding
                            zip.AlternateEncoding = Encoding.GetEncoding("UTF-8");
                            zip.AlternateEncodingUsage = ZipOption.Always;

                            // Set compression
                            zip.CompressionLevel = CompressionLevel.BestCompression;

                            // .xplayers.lev
                            var zipPath = string.Format("{0}c-{1}.xplayers.lev", Args.Multiplayer.PlayerCount, Args.MapName);
                            if ( Args.CompileType == sWrite_WZ_Args.enumCompileType.Multiplayer )
                            {
                                zip.PutNextEntry(zipPath);
                                returnResult.Add(Serialize_WZ_LEV(zip, Args.Multiplayer.PlayerCount,
                                    Args.Multiplayer.AuthorName, Args.Multiplayer.License,
                                    Args.MapName));
                            }

                            var path = string.Format("multiplay/maps/{0}c-{1}", Args.Multiplayer.PlayerCount, Args.MapName);
                            zip.PutNextEntry(string.Format("{0}.gam", path));
                            returnResult.Add(Serialize_WZ_Gam(zip, 0U,
                                Args.CompileType, Args.ScrollMin, Args.ScrollMax));

                            zip.PutNextEntry(string.Format("{0}/struct.ini", path));
                            var iniStruct = new IniWriter(zip);
                            returnResult.Add(Serialize_WZ_StructuresINI(iniStruct, Args.Multiplayer.PlayerCount));
                            iniStruct.Flush();

                            zip.PutNextEntry(string.Format("{0}/droid.ini", path));
                            var iniDroid = new IniWriter(zip);
                            returnResult.Add(Serialize_WZ_DroidsINI(iniDroid, Args.Multiplayer.PlayerCount));
                            iniDroid.Flush();

                            zip.PutNextEntry(string.Format("{0}/labels.ini", path));
                            var iniLabels = new IniWriter(zip);
                            returnResult.Add(Serialize_WZ_LabelsINI(iniLabels, Args.Multiplayer.PlayerCount));
                            iniLabels.Flush();

                            zip.PutNextEntry(string.Format("{0}/feature.ini", path));
                            var iniFeature = new IniWriter(zip);
                            returnResult.Add(Serialize_WZ_FeaturesINI(iniFeature));
                            iniFeature.Flush();

                            zip.PutNextEntry(string.Format("{0}/game.map", path));
                            returnResult.Add(Serialize_WZ_Map(zip));

                            zip.PutNextEntry(string.Format("{0}/ttypes.ttp", path));
                            var ttpSaver = new TTP.TTP(map);
                            returnResult.Add(ttpSaver.Save(zip));
                        }
                    }
                    catch ( Exception ex )
                    {
                        Debugger.Break();
                        returnResult.ProblemAdd(ex.Message);
                        logger.ErrorException("Got an exception", ex);
                        return returnResult;
                    }

                    return returnResult;
                }
                if ( Args.CompileType == sWrite_WZ_Args.enumCompileType.Campaign )
                {
                    var CampDirectory = PathUtil.EndWithPathSeperator(Args.Path);

                    if ( !Directory.Exists(CampDirectory) )
                    {
                        returnResult.ProblemAdd(string.Format("Directory {0} does not exist.", CampDirectory));
                        return returnResult;
                    }

                    var filePath = string.Format("{0}{1}.gam", CampDirectory, Args.MapName);
                    using ( var file = File.Open(filePath, FileMode.Open | FileMode.CreateNew) )
                    {
                        returnResult.Add(Serialize_WZ_Gam(file, Args.Campaign.GAMType,
                            Args.CompileType, Args.ScrollMin, Args.ScrollMax));
                    }

                    CampDirectory += Args.MapName + Convert.ToString(App.PlatformPathSeparator);
                    try
                    {
                        Directory.CreateDirectory(CampDirectory);
                    }
                    catch ( Exception ex )
                    {
                        returnResult.ProblemAdd(string.Format("Unable to create directory {0}", CampDirectory));
                        logger.ErrorException("Got an exception", ex);
                        return returnResult;
                    }

                    filePath = CampDirectory + "droid.ini";
                    using ( var file = File.Open(filePath, FileMode.Open | FileMode.CreateNew) )
                    {
                        var iniDroid = new IniWriter(file);
                        returnResult.Add(Serialize_WZ_DroidsINI(iniDroid, -1));
                        iniDroid.Flush();
                    }

                    filePath = CampDirectory + "feature.ini";
                    using ( var file = File.Open(filePath, FileMode.Open | FileMode.CreateNew) )
                    {
                        var iniFeatures = new IniWriter(file);
                        returnResult.Add(Serialize_WZ_FeaturesINI(iniFeatures));
                        iniFeatures.Flush();
                    }

                    filePath = CampDirectory + "game.map";
                    using ( var file = File.Open(filePath, FileMode.Open | FileMode.CreateNew) )
                    {
                        returnResult.Add(Serialize_WZ_Map(file));
                    }

                    filePath = CampDirectory + "struct.ini";
                    using ( var file = File.Open(filePath, FileMode.Open | FileMode.CreateNew) )
                    {
                        var iniStruct = new IniWriter(file);
                        returnResult.Add(Serialize_WZ_StructuresINI(iniStruct, -1));
                        iniStruct.Flush();
                    }

                    filePath = CampDirectory + "ttypes.ttp";
                    var ttpSaver = new TTP.TTP(map);
                    returnResult.Add(ttpSaver.Save(filePath, false));

                    filePath = CampDirectory + "labels.ini";
                    using ( var file = File.Open(filePath, FileMode.Open | FileMode.CreateNew) )
                    {
                        var iniLabels = new IniWriter(file);
                        returnResult.Add(Serialize_WZ_LabelsINI(iniLabels, 0));
                        iniLabels.Flush();
                    }
                }
            }
            catch ( Exception ex )
            {
                Debugger.Break();
                returnResult.ProblemAdd(ex.Message);
                logger.ErrorException("Got an exception", ex);
                return returnResult;
            }

            return returnResult;
        }
Exemplo n.º 17
0
        public override clsResult Load(string path)
        {
            var returnResult =
                new clsResult("Loading game file from \"{0}\"".Format2(path), false);
            logger.Info("Loading game file from \"{0}\"", path);
            var subResult = new sResult();

            map.Tileset = null;

            map.TileType_Reset();
            map.SetPainterToDefaults();

            var gameSplitPath = new sSplitPath(path);
            var gameFilesPath = gameSplitPath.FilePath + gameSplitPath.FileTitleWithoutExtension + Convert.ToString(App.PlatformPathSeparator);
            var mapDirectory = "";
            FileStream file = null;

            subResult = IOUtil.TryOpenFileStream(path, ref file);
            if ( !subResult.Success )
            {
                returnResult.ProblemAdd("Game file not found: " + subResult.Problem);
                return returnResult;
            }

            var Map_Reader = new BinaryReader(file);
            subResult = read_WZ_gam(Map_Reader);
            Map_Reader.Close();

            if ( !subResult.Success )
            {
                returnResult.ProblemAdd(subResult.Problem);
                return returnResult;
            }

            subResult = IOUtil.TryOpenFileStream(gameFilesPath + "game.map", ref file);
            if ( !subResult.Success )
            {
                if ( MessageBox.Show("game.map file not found at \"{0}\"\n" +
                                     "Do you want to select another directory to load the underlying map from?".Format2(gameFilesPath),
                    "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel )
                {
                    returnResult.ProblemAdd("Aborted.");
                    return returnResult;
                }
                var DirectorySelect = new FolderBrowserDialog();
                DirectorySelect.SelectedPath = gameFilesPath;
                if ( DirectorySelect.ShowDialog() != DialogResult.OK )
                {
                    returnResult.ProblemAdd("Aborted.");
                    return returnResult;
                }
                mapDirectory = DirectorySelect.SelectedPath + Convert.ToString(App.PlatformPathSeparator);

                subResult = IOUtil.TryOpenFileStream(mapDirectory + "game.map", ref file);
                if ( !subResult.Success )
                {
                    returnResult.ProblemAdd("game.map file not found: " + subResult.Problem);
                    return returnResult;
                }
            }
            else
            {
                mapDirectory = gameFilesPath;
            }

            var Map_ReaderB = new BinaryReader(file);
            subResult = read_WZ_map(Map_ReaderB);
            Map_ReaderB.Close();

            if ( !subResult.Success )
            {
                returnResult.ProblemAdd(subResult.Problem);
                return returnResult;
            }

            var bjoUnits = new List<WZBJOUnit>();

            var iniFeatures = new List<IniFeature>();
            subResult = IOUtil.TryOpenFileStream(gameFilesPath + "feature.ini", ref file);
            if ( subResult.Success )
            {
                using ( var reader = new StreamReader(file) )
                {
                    var text = reader.ReadToEnd();
                    returnResult.Add(read_INI_Features(text, iniFeatures));
                }
            }

            if ( iniFeatures.Count == 0 ) // no feature.ini
            {
                var Result = new clsResult("feat.bjo", false);
                logger.Info("Loading feat.bjo");
                subResult = IOUtil.TryOpenFileStream(gameFilesPath + "feat.bjo", ref file);
                if ( !subResult.Success )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    var Features_Reader = new BinaryReader(file);
                    subResult = read_WZ_Features(Features_Reader, bjoUnits);
                    Features_Reader.Close();
                    if ( !subResult.Success )
                    {
                        Result.WarningAdd(subResult.Problem);
                    }
                }
                returnResult.Add(Result);
            }

            {
                var Result = new clsResult("ttypes.ttp", false);
                logger.Info("Loading ttypes.ttp");
                subResult = IOUtil.TryOpenFileStream(mapDirectory + "ttypes.ttp", ref file);
                if ( !subResult.Success )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    var TileTypes_Reader = new BinaryReader(file);
                    subResult = read_WZ_TileTypes(TileTypes_Reader);
                    TileTypes_Reader.Close();
                    if ( !subResult.Success )
                    {
                        Result.WarningAdd(subResult.Problem);
                    }
                }
                returnResult.Add(Result);
            }

            var iniStructures = new List<IniStructure>();
            subResult = IOUtil.TryOpenFileStream(gameFilesPath + "struct.ini", ref file);
            if ( subResult.Success )
            {
                using ( var reader = new StreamReader(file) )
                {
                    var text = reader.ReadToEnd();
                    returnResult.Add(read_INI_Structures(text, iniStructures));
                }
            }

            if ( iniStructures.Count == 0 ) // no struct.ini
            {
                var Result = new clsResult("struct.bjo", false);
                logger.Info("Loading struct.bjo");
                subResult = IOUtil.TryOpenFileStream(gameFilesPath + "struct.bjo", ref file);
                if ( !subResult.Success )
                {
                    Result.WarningAdd("struct.bjo file not found.");
                }
                else
                {
                    var Structures_Reader = new BinaryReader(file);
                    subResult = read_WZ_Structures(Structures_Reader, bjoUnits);
                    Structures_Reader.Close();
                    if ( !subResult.Success )
                    {
                        Result.WarningAdd(subResult.Problem);
                    }
                }
                returnResult.Add(Result);
            }

            var iniDroids = new List<IniDroid>();
            subResult = IOUtil.TryOpenFileStream(gameFilesPath + "droid.ini", ref file);
            if ( subResult.Success )
            {
                using ( var reader = new StreamReader(file) )
                {
                    var text = reader.ReadToEnd();
                    returnResult.Add(read_INI_Droids(text, iniDroids));
                }
            }

            if ( iniDroids.Count == 0 ) // no droid.ini
            {
                var Result = new clsResult("dinit.bjo", false);
                logger.Info("Loading dinit.bjo");
                subResult = IOUtil.TryOpenFileStream(gameFilesPath + "dinit.bjo", ref file);
                if ( !subResult.Success )
                {
                    Result.WarningAdd("dinit.bjo file not found.");
                }
                else
                {
                    var Droids_Reader = new BinaryReader(file);
                    subResult = read_WZ_Droids(Droids_Reader, bjoUnits);
                    Droids_Reader.Close();
                    if ( !subResult.Success )
                    {
                        Result.WarningAdd(subResult.Problem);
                    }
                }
                returnResult.Add(Result);
            }

            returnResult.Add(createWZObjects(bjoUnits, iniStructures, iniDroids, iniFeatures));

            //map objects are modified by this and must already exist
            subResult = IOUtil.TryOpenFileStream(gameFilesPath + "labels.ini", ref file);
            if ( subResult.Success )
            {
                using ( var reader = new StreamReader(file) )
                {
                    var text = reader.ReadToEnd();
                    returnResult.Add(read_INI_Labels(text));
                }
            }

            return returnResult;
        }
Exemplo n.º 18
0
        public void btnGenerateRamps_Click(Object sender, EventArgs e)
        {
            if ( Generator.Map == null )
            {
                return;
            }

            Generator.MaxDisconnectionDist = ValidateTextbox(txtRampDistance, 0.0D, 99999.0D, App.TerrainGridSpacing);
            Generator.RampBase = ValidateTextbox(txtRampBase, 10.0D, 1000.0D, 10.0D) / 1000.0D;

            clsResult Result = new clsResult("");

            lstResult_AddText("Generating ramps.");
            Result = Generator.GenerateRamps();
            if ( !Result.HasProblems )
            {
                Result.Add(FinishHeights());
            }
            lstResult_AddResult(Result);
            if ( Result.HasProblems )
            {
                lstResult_AddText("Failed.");
                return;
            }
            else
            {
                lstResult_AddText("Done.");
            }
        }
Exemplo n.º 19
0
        public clsResult Write_WZ(sWrite_WZ_Args Args)
        {
            clsResult ReturnResult =
                new clsResult("Compiling to " + Convert.ToString(ControlChars.Quote) + Args.Path + Convert.ToString(ControlChars.Quote));

            try
            {
                switch ( Args.CompileType )
                {
                    case sWrite_WZ_Args.enumCompileType.Multiplayer:
                        if ( Args.Multiplayer == null )
                        {
                            ReturnResult.ProblemAdd("Multiplayer arguments were not passed.");
                            return ReturnResult;
                        }
                        if ( Args.Multiplayer.PlayerCount < 2 | Args.Multiplayer.PlayerCount > 10 )
                        {
                            ReturnResult.ProblemAdd("Number of players was below 2 or above 10.");
                            return ReturnResult;
                        }
                        if ( !Args.Multiplayer.IsBetaPlayerFormat )
                        {
                            if ( !(Args.Multiplayer.PlayerCount == 2 | Args.Multiplayer.PlayerCount == 4 | Args.Multiplayer.PlayerCount == 8) )
                            {
                                ReturnResult.ProblemAdd("Number of players was not 2, 4 or 8 in original format.");
                                return ReturnResult;
                            }
                        }
                        break;
                    case sWrite_WZ_Args.enumCompileType.Campaign:
                        if ( Args.Campaign == null )
                        {
                            ReturnResult.ProblemAdd("Campaign arguments were not passed.");
                            return ReturnResult;
                        }
                        break;
                    default:
                        ReturnResult.ProblemAdd("Unknown compile method.");
                        return ReturnResult;
                }

                if ( !Args.Overwrite )
                {
                    if ( File.Exists(Args.Path) )
                    {
                        ReturnResult.ProblemAdd("The selected file already exists.");
                        return ReturnResult;
                    }
                }

                char Quote = ControlChars.Quote;
                char EndChar = '\n';
                string Text = "";

                MemoryStream File_LEV_Memory = new MemoryStream();
                StreamWriter File_LEV = new StreamWriter(File_LEV_Memory, App.UTF8Encoding);
                MemoryStream File_MAP_Memory = new MemoryStream();
                BinaryWriter File_MAP = new BinaryWriter(File_MAP_Memory, App.ASCIIEncoding);
                MemoryStream File_GAM_Memory = new MemoryStream();
                BinaryWriter File_GAM = new BinaryWriter(File_GAM_Memory, App.ASCIIEncoding);
                MemoryStream File_featBJO_Memory = new MemoryStream();
                BinaryWriter File_featBJO = new BinaryWriter(File_featBJO_Memory, App.ASCIIEncoding);
                MemoryStream INI_feature_Memory = new MemoryStream();
                IniWriter INI_feature = IniWriter.CreateFile(INI_feature_Memory);
                MemoryStream File_TTP_Memory = new MemoryStream();
                BinaryWriter File_TTP = new BinaryWriter(File_TTP_Memory, App.ASCIIEncoding);
                MemoryStream File_structBJO_Memory = new MemoryStream();
                BinaryWriter File_structBJO = new BinaryWriter(File_structBJO_Memory, App.ASCIIEncoding);
                MemoryStream INI_struct_Memory = new MemoryStream();
                IniWriter INI_struct = IniWriter.CreateFile(INI_struct_Memory);
                MemoryStream File_droidBJO_Memory = new MemoryStream();
                BinaryWriter File_droidBJO = new BinaryWriter(File_droidBJO_Memory, App.ASCIIEncoding);
                MemoryStream INI_droid_Memory = new MemoryStream();
                IniWriter INI_droid = IniWriter.CreateFile(INI_droid_Memory);
                MemoryStream INI_Labels_Memory = new MemoryStream();
                IniWriter INI_Labels = IniWriter.CreateFile(INI_Labels_Memory);

                string PlayersPrefix = "";
                string PlayersText = "";

                if ( Args.CompileType == sWrite_WZ_Args.enumCompileType.Multiplayer )
                {
                    PlayersText = IOUtil.InvariantToString(Args.Multiplayer.PlayerCount);
                    PlayersPrefix = PlayersText + "c-";
                    string fog = "";
                    string TilesetNum = "";
                    if ( Tileset == null )
                    {
                        ReturnResult.ProblemAdd("Map must have a tileset.");
                        return ReturnResult;
                    }
                    else if ( Tileset == App.Tileset_Arizona )
                    {
                        fog = "fog1.wrf";
                        TilesetNum = "1";
                    }
                    else if ( Tileset == App.Tileset_Urban )
                    {
                        fog = "fog2.wrf";
                        TilesetNum = "2";
                    }
                    else if ( Tileset == App.Tileset_Rockies )
                    {
                        fog = "fog3.wrf";
                        TilesetNum = "3";
                    }
                    else
                    {
                        ReturnResult.ProblemAdd("Unknown tileset selected.");
                        return ReturnResult;
                    }

                    Text = "// Made with " + Constants.ProgramName + " " + Constants.ProgramVersionNumber + " " + Constants.ProgramPlatform +
                           Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    DateTime DateNow = DateTime.Now;
                    Text = "// Date: " + Convert.ToString(DateNow.Year) + "/" + App.MinDigits(DateNow.Month, 2) + "/" +
                           App.MinDigits(DateNow.Day, 2) + " " + App.MinDigits(DateNow.Hour, 2) + ":" + App.MinDigits(DateNow.Minute, 2) + ":" +
                           App.MinDigits(DateNow.Second, 2) + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "// Author: " + Args.Multiplayer.AuthorName + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "// License: " + Args.Multiplayer.License + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = EndChar.ToString();
                    File_LEV.Write(Text);
                    Text = "level   " + Args.MapName + "-T1" + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "players " + PlayersText + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "type    14" + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "dataset MULTI_CAM_" + TilesetNum + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "game    " + Convert.ToString(Quote) + "multiplay/maps/" + PlayersPrefix + Args.MapName + ".gam" + Convert.ToString(Quote) +
                           Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "data    " + Convert.ToString(Quote) + "wrf/multi/skirmish" + PlayersText + ".wrf" + Convert.ToString(Quote) +
                           Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "data    " + Convert.ToString(Quote) + "wrf/multi/" + fog + Convert.ToString(Quote) + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = EndChar.ToString();
                    File_LEV.Write(Text);
                    Text = "level   " + Args.MapName + "-T2" + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "players " + PlayersText + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "type    18" + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "dataset MULTI_T2_C" + TilesetNum + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "game    " + Convert.ToString(Quote) + "multiplay/maps/" + PlayersPrefix + Args.MapName + ".gam" + Convert.ToString(Quote) +
                           Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "data    " + Convert.ToString(Quote) + "wrf/multi/t2-skirmish" + PlayersText + ".wrf" + Convert.ToString(Quote) +
                           Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "data    " + Convert.ToString(Quote) + "wrf/multi/" + fog + Convert.ToString(Quote) + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = EndChar.ToString();
                    File_LEV.Write(Text);
                    Text = "level   " + Args.MapName + "-T3" + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "players " + PlayersText + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "type    19" + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "dataset MULTI_T3_C" + TilesetNum + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "game    " + Convert.ToString(Quote) + "multiplay/maps/" + PlayersPrefix + Args.MapName + ".gam" + Convert.ToString(Quote) +
                           Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "data    " + Convert.ToString(Quote) + "wrf/multi/t3-skirmish" + PlayersText + ".wrf" + Convert.ToString(Quote) +
                           Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                    Text = "data    " + Convert.ToString(Quote) + "wrf/multi/" + fog + Convert.ToString(Quote) + Convert.ToString(EndChar);
                    File_LEV.Write(Text);
                }

                byte[] GameZeroBytes = new byte[20];

                IOUtil.WriteText(File_GAM, false, "game");
                File_GAM.Write(8U);
                File_GAM.Write(0U); //Time
                if ( Args.CompileType == sWrite_WZ_Args.enumCompileType.Multiplayer )
                {
                    File_GAM.Write(0U);
                }
                else if ( Args.CompileType == sWrite_WZ_Args.enumCompileType.Campaign )
                {
                    File_GAM.Write(Args.Campaign.GAMType);
                }
                File_GAM.Write(Args.ScrollMin.X);
                File_GAM.Write(Args.ScrollMin.Y);
                File_GAM.Write(Args.ScrollMax.X);
                File_GAM.Write(Args.ScrollMax.Y);
                File_GAM.Write(GameZeroBytes);

                int A = 0;
                int X = 0;
                int Y = 0;

                IOUtil.WriteText(File_MAP, false, "map ");
                File_MAP.Write(10U);
                File_MAP.Write(Convert.ToBoolean((uint)Terrain.TileSize.X));
                File_MAP.Write(Convert.ToBoolean((uint)Terrain.TileSize.Y));
                byte Flip = 0;
                byte Rotation = 0;
                bool DoFlipX = default(bool);
                int InvalidTileCount = 0;
                int TextureNum = 0;
                for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
                {
                    for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                    {
                        TileUtil.TileOrientation_To_OldOrientation(Terrain.Tiles[X, Y].Texture.Orientation, ref Rotation, ref DoFlipX);
                        Flip = (byte)0;
                        if ( Terrain.Tiles[X, Y].Tri )
                        {
                            Flip += (byte)8;
                        }
                        Flip += (byte)(Rotation * 16);
                        if ( DoFlipX )
                        {
                            Flip += (byte)128;
                        }
                        TextureNum = Terrain.Tiles[X, Y].Texture.TextureNum;
                        if ( TextureNum < 0 | TextureNum > 255 )
                        {
                            TextureNum = 0;
                            if ( InvalidTileCount < 16 )
                            {
                                ReturnResult.WarningAdd("Tile texture number " + Convert.ToString(Terrain.Tiles[X, Y].Texture.TextureNum) +
                                                        " is invalid on tile " + Convert.ToString(X) + ", " + Convert.ToString(Y) +
                                                        " and was compiled as texture number " + Convert.ToString(TextureNum) + ".");
                            }
                            InvalidTileCount++;
                        }
                        File_MAP.Write((byte)TextureNum);
                        File_MAP.Write(Flip);
                        File_MAP.Write(Convert.ToBoolean(Terrain.Vertices[X, Y].Height));
                    }
                }
                if ( InvalidTileCount > 0 )
                {
                    ReturnResult.WarningAdd(InvalidTileCount + " tile texture numbers were invalid.");
                }
                File_MAP.Write(1U); //gateway version
                File_MAP.Write(Convert.ToBoolean((uint)Gateways.Count));
                clsGateway Gateway = default(clsGateway);
                foreach ( clsGateway tempLoopVar_Gateway in Gateways )
                {
                    Gateway = tempLoopVar_Gateway;
                    File_MAP.Write((byte)(MathUtil.Clamp_int(Gateway.PosA.X, 0, 255)));
                    File_MAP.Write((byte)(MathUtil.Clamp_int(Gateway.PosA.Y, 0, 255)));
                    File_MAP.Write((byte)(MathUtil.Clamp_int(Gateway.PosB.X, 0, 255)));
                    File_MAP.Write((byte)(MathUtil.Clamp_int(Gateway.PosB.Y, 0, 255)));
                }

                clsFeatureType FeatureType = default(clsFeatureType);
                clsStructureType StructureType = default(clsStructureType);
                clsDroidDesign DroidType = default(clsDroidDesign);
                clsDroidTemplate DroidTemplate = default(clsDroidTemplate);
                clsUnit Unit = default(clsUnit);
                clsStructureWriteWZ StructureWrite = new clsStructureWriteWZ();
                StructureWrite.File = File_structBJO;
                StructureWrite.CompileType = Args.CompileType;
                if ( Args.CompileType == sWrite_WZ_Args.enumCompileType.Multiplayer )
                {
                    StructureWrite.PlayerCount = Args.Multiplayer.PlayerCount;
                }
                else
                {
                    StructureWrite.PlayerCount = 0;
                }

                byte[] FeatZeroBytes = new byte[12];

                IOUtil.WriteText(File_featBJO, false, "feat");
                File_featBJO.Write(8U);
                clsObjectPriorityOrderList FeatureOrder = new clsObjectPriorityOrderList();
                foreach ( clsUnit tempLoopVar_Unit in Units )
                {
                    Unit = tempLoopVar_Unit;
                    if ( Unit.Type.Type == clsUnitType.enumType.Feature )
                    {
                        FeatureOrder.SetItem(Unit);
                        FeatureOrder.ActionPerform();
                    }
                }
                File_featBJO.Write(Convert.ToBoolean((uint)FeatureOrder.Result.Count));
                for ( A = 0; A <= FeatureOrder.Result.Count - 1; A++ )
                {
                    Unit = FeatureOrder.Result[A];
                    FeatureType = (clsFeatureType)Unit.Type;
                    IOUtil.WriteTextOfLength(File_featBJO, 40, FeatureType.Code);
                    File_featBJO.Write(Unit.ID);
                    File_featBJO.Write(Convert.ToBoolean((uint)Unit.Pos.Horizontal.X));
                    File_featBJO.Write(Convert.ToBoolean((uint)Unit.Pos.Horizontal.Y));
                    File_featBJO.Write(Convert.ToBoolean((uint)Unit.Pos.Altitude));
                    File_featBJO.Write(Convert.ToBoolean((uint)Unit.Rotation));
                    switch ( Args.CompileType )
                    {
                        case sWrite_WZ_Args.enumCompileType.Multiplayer:
                            File_featBJO.Write(Unit.GetBJOMultiplayerPlayerNum(Args.Multiplayer.PlayerCount));
                            break;
                        case sWrite_WZ_Args.enumCompileType.Campaign:
                            File_featBJO.Write(Unit.GetBJOCampaignPlayerNum());
                            break;
                        default:
                            Debugger.Break();
                            break;
                    }
                    File_featBJO.Write(FeatZeroBytes);
                }

                IOUtil.WriteText(File_TTP, false, "ttyp");
                File_TTP.Write(8U);
                File_TTP.Write(Convert.ToBoolean((uint)Tileset.TileCount));
                for ( A = 0; A <= Tileset.TileCount - 1; A++ )
                {
                    File_TTP.Write(Convert.ToBoolean(Tile_TypeNum[A]));
                }

                IOUtil.WriteText(File_structBJO, false, "stru");
                File_structBJO.Write(8U);
                clsObjectPriorityOrderList NonModuleStructureOrder = new clsObjectPriorityOrderList();
                //non-module structures
                foreach ( clsUnit tempLoopVar_Unit in Units )
                {
                    Unit = tempLoopVar_Unit;
                    if ( Unit.Type.Type == clsUnitType.enumType.PlayerStructure )
                    {
                        StructureType = (clsStructureType)Unit.Type;
                        if ( !StructureType.IsModule() )
                        {
                            NonModuleStructureOrder.SetItem(Unit);
                            NonModuleStructureOrder.ActionPerform();
                        }
                    }
                }
                clsObjectPriorityOrderList ModuleStructureOrder = new clsObjectPriorityOrderList();
                //module structures
                foreach ( clsUnit tempLoopVar_Unit in Units )
                {
                    Unit = tempLoopVar_Unit;
                    if ( Unit.Type.Type == clsUnitType.enumType.PlayerStructure )
                    {
                        StructureType = (clsStructureType)Unit.Type;
                        if ( StructureType.IsModule() )
                        {
                            ModuleStructureOrder.SetItem(Unit);
                            ModuleStructureOrder.ActionPerform();
                        }
                    }
                }
                File_structBJO.Write(Convert.ToBoolean((uint)(NonModuleStructureOrder.Result.Count + ModuleStructureOrder.Result.Count)));
                NonModuleStructureOrder.Result.PerformTool(StructureWrite);
                ModuleStructureOrder.Result.PerformTool(StructureWrite);

                byte[] DintZeroBytes = new byte[12];

                IOUtil.WriteText(File_droidBJO, false, "dint");
                File_droidBJO.Write(8U);
                clsObjectPriorityOrderList Droids = new clsObjectPriorityOrderList();
                foreach ( clsUnit tempLoopVar_Unit in Units )
                {
                    Unit = tempLoopVar_Unit;
                    if ( Unit.Type.Type == clsUnitType.enumType.PlayerDroid )
                    {
                        DroidType = (clsDroidDesign)Unit.Type;
                        if ( DroidType.IsTemplate )
                        {
                            Droids.SetItem(Unit);
                            Droids.ActionPerform();
                        }
                    }
                }
                File_droidBJO.Write(Convert.ToBoolean((uint)Droids.Result.Count));
                for ( A = 0; A <= Droids.Result.Count - 1; A++ )
                {
                    Unit = Droids.Result[A];
                    DroidTemplate = (clsDroidTemplate)Unit.Type;
                    IOUtil.WriteTextOfLength(File_droidBJO, 40, DroidTemplate.Code);
                    File_droidBJO.Write(Unit.ID);
                    File_droidBJO.Write(Convert.ToBoolean((uint)Unit.Pos.Horizontal.X));
                    File_droidBJO.Write(Convert.ToBoolean((uint)Unit.Pos.Horizontal.Y));
                    File_droidBJO.Write(Convert.ToBoolean((uint)Unit.Pos.Altitude));
                    File_droidBJO.Write(Convert.ToBoolean((uint)Unit.Rotation));
                    switch ( Args.CompileType )
                    {
                        case sWrite_WZ_Args.enumCompileType.Multiplayer:
                            File_droidBJO.Write(Unit.GetBJOMultiplayerPlayerNum(Args.Multiplayer.PlayerCount));
                            break;
                        case sWrite_WZ_Args.enumCompileType.Campaign:
                            File_droidBJO.Write(Unit.GetBJOCampaignPlayerNum());
                            break;
                        default:
                            Debugger.Break();
                            break;
                    }
                    File_droidBJO.Write(DintZeroBytes);
                }

                ReturnResult.Add(Serialize_WZ_FeaturesINI(INI_feature));
                if ( Args.CompileType == sWrite_WZ_Args.enumCompileType.Multiplayer )
                {
                    ReturnResult.Add(Serialize_WZ_StructuresINI(INI_struct, Args.Multiplayer.PlayerCount));
                    ReturnResult.Add(Serialize_WZ_DroidsINI(INI_droid, Args.Multiplayer.PlayerCount));
                    ReturnResult.Add(Serialize_WZ_LabelsINI(INI_Labels, Args.Multiplayer.PlayerCount));
                }
                else if ( Args.CompileType == sWrite_WZ_Args.enumCompileType.Campaign )
                {
                    ReturnResult.Add(Serialize_WZ_StructuresINI(INI_struct, -1));
                    ReturnResult.Add(Serialize_WZ_DroidsINI(INI_droid, -1));
                    ReturnResult.Add(Serialize_WZ_LabelsINI(INI_Labels, 0)); //interprets -1 players as an FMap
                }

                File_LEV.Flush();
                File_MAP.Flush();
                File_GAM.Flush();
                File_featBJO.Flush();
                INI_feature.File.Flush();
                File_TTP.Flush();
                File_structBJO.Flush();
                INI_struct.File.Flush();
                File_droidBJO.Flush();
                INI_droid.File.Flush();
                INI_Labels.File.Flush();

                if ( Args.CompileType == sWrite_WZ_Args.enumCompileType.Multiplayer )
                {
                    if ( !Args.Overwrite )
                    {
                        if ( File.Exists(Args.Path) )
                        {
                            ReturnResult.ProblemAdd("A file already exists at: " + Args.Path);
                            return ReturnResult;
                        }
                    }
                    else
                    {
                        if ( File.Exists(Args.Path) )
                        {
                            try
                            {
                                File.Delete(Args.Path);
                            }
                            catch ( Exception ex )
                            {
                                ReturnResult.ProblemAdd("Unable to delete existing file: " + ex.Message);
                                return ReturnResult;
                            }
                        }
                    }

                    ZipOutputStream WZStream = default(ZipOutputStream);

                    try
                    {
                        WZStream = new ZipOutputStream(File.Create(Args.Path));
                    }
                    catch ( Exception ex )
                    {
                        ReturnResult.ProblemAdd(ex.Message);
                        return ReturnResult;
                    }

                    WZStream.SetLevel(9);
                    WZStream.UseZip64 = UseZip64.Off; //warzone crashes without this

                    try
                    {
                        string ZipPath = "";
                        ZipEntry ZipEntry = default(ZipEntry);

                        if ( Args.Multiplayer.IsBetaPlayerFormat )
                        {
                            ZipPath = PlayersPrefix + Args.MapName + ".xplayers.lev";
                        }
                        else
                        {
                            ZipPath = PlayersPrefix + Args.MapName + ".addon.lev";
                        }
                        ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
                        if ( ZipEntry != null )
                        {
                            File_LEV_Memory.WriteTo(WZStream);
                            WZStream.Flush();
                            WZStream.CloseEntry();
                        }

                        ZipEntry = new ZipEntry("multiplay/");
                        WZStream.PutNextEntry(ZipEntry);
                        ZipEntry = new ZipEntry("multiplay/maps/");
                        WZStream.PutNextEntry(ZipEntry);
                        ZipEntry = new ZipEntry("multiplay/maps/" + PlayersPrefix + Args.MapName + "/");
                        WZStream.PutNextEntry(ZipEntry);

                        ZipPath = "multiplay/maps/" + PlayersPrefix + Args.MapName + ".gam";
                        ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
                        if ( ZipEntry != null )
                        {
                            ReturnResult.Add(IOUtil.WriteMemoryToZipEntryAndFlush(File_GAM_Memory, WZStream));
                        }
                        else
                        {
                            ReturnResult.ProblemAdd("Unable to make entry " + ZipPath);
                        }

                        ZipPath = "multiplay/maps/" + PlayersPrefix + Args.MapName + "/" + "dinit.bjo";
                        ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
                        if ( ZipEntry != null )
                        {
                            ReturnResult.Add(IOUtil.WriteMemoryToZipEntryAndFlush(File_droidBJO_Memory, WZStream));
                        }
                        else
                        {
                            ReturnResult.ProblemAdd("Unable to make entry " + ZipPath);
                        }

                        ZipPath = "multiplay/maps/" + PlayersPrefix + Args.MapName + "/" + "droid.ini";
                        ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
                        if ( ZipEntry != null )
                        {
                            ReturnResult.Add(IOUtil.WriteMemoryToZipEntryAndFlush(INI_droid_Memory, WZStream));
                        }
                        else
                        {
                            ReturnResult.ProblemAdd("Unable to make entry " + ZipPath);
                        }

                        ZipPath = "multiplay/maps/" + PlayersPrefix + Args.MapName + "/" + "feat.bjo";
                        ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
                        if ( ZipEntry != null )
                        {
                            ReturnResult.Add(IOUtil.WriteMemoryToZipEntryAndFlush(File_featBJO_Memory, WZStream));
                        }
                        else
                        {
                            ReturnResult.ProblemAdd("Unable to make entry " + ZipPath);
                        }

                        ZipPath = "multiplay/maps/" + PlayersPrefix + Args.MapName + "/" + "feature.ini";
                        ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
                        if ( ZipEntry != null )
                        {
                            ReturnResult.Add(IOUtil.WriteMemoryToZipEntryAndFlush(INI_feature_Memory, WZStream));
                        }
                        else
                        {
                            ReturnResult.ProblemAdd("Unable to make entry " + ZipPath);
                        }

                        ZipPath = "multiplay/maps/" + PlayersPrefix + Args.MapName + "/" + "game.map";
                        ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
                        if ( ZipEntry != null )
                        {
                            ReturnResult.Add(IOUtil.WriteMemoryToZipEntryAndFlush(File_MAP_Memory, WZStream));
                        }
                        else
                        {
                            ReturnResult.ProblemAdd("Unable to make entry " + ZipPath);
                        }

                        ZipPath = "multiplay/maps/" + PlayersPrefix + Args.MapName + "/" + "struct.bjo";
                        ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
                        if ( ZipEntry != null )
                        {
                            ReturnResult.Add(IOUtil.WriteMemoryToZipEntryAndFlush(File_structBJO_Memory, WZStream));
                        }
                        else
                        {
                            ReturnResult.ProblemAdd("Unable to make entry " + ZipPath);
                        }

                        ZipPath = "multiplay/maps/" + PlayersPrefix + Args.MapName + "/" + "struct.ini";
                        ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
                        if ( ZipEntry != null )
                        {
                            ReturnResult.Add(IOUtil.WriteMemoryToZipEntryAndFlush(INI_struct_Memory, WZStream));
                        }
                        else
                        {
                            ReturnResult.ProblemAdd("Unable to make entry " + ZipPath);
                        }

                        ZipPath = "multiplay/maps/" + PlayersPrefix + Args.MapName + "/" + "ttypes.ttp";
                        ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
                        if ( ZipEntry != null )
                        {
                            ReturnResult.Add(IOUtil.WriteMemoryToZipEntryAndFlush(File_TTP_Memory, WZStream));
                        }
                        else
                        {
                            ReturnResult.ProblemAdd("Unable to make entry " + ZipPath);
                        }

                        if ( INI_Labels_Memory.Length > 0 )
                        {
                            ZipPath = "multiplay/maps/" + PlayersPrefix + Args.MapName + "/" + "labels.ini";
                            ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult);
                            if ( ZipEntry != null )
                            {
                                ReturnResult.Add(IOUtil.WriteMemoryToZipEntryAndFlush(INI_Labels_Memory, WZStream));
                            }
                            else
                            {
                                ReturnResult.ProblemAdd("Unable to make entry " + ZipPath);
                            }
                        }

                        WZStream.Finish();
                        WZStream.Close();
                        return ReturnResult;
                    }
                    catch ( Exception ex )
                    {
                        WZStream.Close();
                        ReturnResult.ProblemAdd(ex.Message);
                        return ReturnResult;
                    }
                }
                else if ( Args.CompileType == sWrite_WZ_Args.enumCompileType.Campaign )
                {
                    string CampDirectory = App.EndWithPathSeperator(Args.Path);

                    if ( !Directory.Exists(CampDirectory) )
                    {
                        ReturnResult.ProblemAdd("Directory " + CampDirectory + " does not exist.");
                        return ReturnResult;
                    }

                    string FilePath = "";

                    FilePath = CampDirectory + Args.MapName + ".gam";
                    ReturnResult.Add(IOUtil.WriteMemoryToNewFile(File_GAM_Memory, CampDirectory + Args.MapName + ".gam"));

                    CampDirectory += Args.MapName + Convert.ToString(App.PlatformPathSeparator);
                    try
                    {
                        Directory.CreateDirectory(CampDirectory);
                    }
                    catch ( Exception )
                    {
                        ReturnResult.ProblemAdd("Unable to create directory " + CampDirectory);
                        return ReturnResult;
                    }

                    FilePath = CampDirectory + "dinit.bjo";
                    ReturnResult.Add(IOUtil.WriteMemoryToNewFile(File_droidBJO_Memory, FilePath));

                    FilePath = CampDirectory + "droid.ini";
                    ReturnResult.Add(IOUtil.WriteMemoryToNewFile(INI_droid_Memory, FilePath));

                    FilePath = CampDirectory + "feat.bjo";
                    ReturnResult.Add(IOUtil.WriteMemoryToNewFile(File_featBJO_Memory, FilePath));

                    FilePath = CampDirectory + "feature.ini";
                    ReturnResult.Add(IOUtil.WriteMemoryToNewFile(INI_feature_Memory, FilePath));

                    FilePath = CampDirectory + "game.map";
                    ReturnResult.Add(IOUtil.WriteMemoryToNewFile(File_MAP_Memory, FilePath));

                    FilePath = CampDirectory + "struct.bjo";
                    ReturnResult.Add(IOUtil.WriteMemoryToNewFile(File_structBJO_Memory, FilePath));

                    FilePath = CampDirectory + "struct.ini";
                    ReturnResult.Add(IOUtil.WriteMemoryToNewFile(INI_struct_Memory, FilePath));

                    FilePath = CampDirectory + "ttypes.ttp";
                    ReturnResult.Add(IOUtil.WriteMemoryToNewFile(File_TTP_Memory, FilePath));

                    FilePath = CampDirectory + "labels.ini";
                    ReturnResult.Add(IOUtil.WriteMemoryToNewFile(INI_Labels_Memory, FilePath));
                }
            }
            catch ( Exception ex )
            {
                Debugger.Break();
                ReturnResult.ProblemAdd(ex.Message);
                return ReturnResult;
            }

            return ReturnResult;
        }
Exemplo n.º 20
0
        public clsResult GenerateLayout()
        {
            clsResult ReturnResult = new clsResult("Layout");

            int X = 0;
            int Y = 0;
            int A = 0;
            int B = 0;
            int C = 0;
            int D = 0;
            int E = 0;
            int F = 0;
            int G = 0;
            int H = 0;

            TotalPlayerCount = TopLeftPlayerCount * SymmetryBlockCount;

            sXY_int SymmetrySize = new sXY_int();

            SymmetrySize.X = (int)(TileSize.X * App.TerrainGridSpacing / SymmetryBlockCountXY.X);
            SymmetrySize.Y = (int)(TileSize.Y * App.TerrainGridSpacing / SymmetryBlockCountXY.Y);

            //create passage nodes

            int PassageRadius = (int)(128.0F * NodeScale);
            int MaxLikelyPassageNodeCount = 0;
            MaxLikelyPassageNodeCount =
                (int)(Math.Ceiling(Convert.ToDecimal(2.0D * TileSize.X * 128 * TileSize.Y * 128 / (Math.PI * PassageRadius * PassageRadius))));

            PassageNodes = new clsPassageNode[SymmetryBlockCount, MaxLikelyPassageNodeCount];
            int LoopCount = 0;
            int EdgeOffset = 0 * 128;
            bool PointIsValid;
            sXY_int EdgeSections = new sXY_int();
            Position.XY_dbl EdgeSectionSize = default(Position.XY_dbl);
            sXY_int NewPointPos = new sXY_int();

            if ( SymmetryBlockCountXY.X == 1 )
            {
                EdgeSections.X =
                    Convert.ToInt32(
                        Conversion.Int((TileSize.X * App.TerrainGridSpacing - EdgeOffset * 2.0D) / (NodeScale * App.TerrainGridSpacing * 2.0F)));
                EdgeSectionSize.X = (TileSize.X * App.TerrainGridSpacing - EdgeOffset * 2.0D) / EdgeSections.X;
                EdgeSections.X--;
            }
            else
            {
                EdgeSections.X =
                    (int)
                        (Conversion.Int((TileSize.X * App.TerrainGridSpacing / SymmetryBlockCountXY.X - EdgeOffset) /
                                        (NodeScale * App.TerrainGridSpacing * 2.0F) - 0.5D));
                EdgeSectionSize.X =
                    Convert.ToDouble((TileSize.X * App.TerrainGridSpacing / SymmetryBlockCountXY.X - EdgeOffset) /
                                            (Convert.ToDouble(
                                                Conversion.Int((TileSize.X * App.TerrainGridSpacing / SymmetryBlockCountXY.X - EdgeOffset) /
                                                               (NodeScale * App.TerrainGridSpacing * 2.0F) - 0.5D)) + 0.5D));
            }
            if ( SymmetryBlockCountXY.Y == 1 )
            {
                EdgeSections.Y =
                    Convert.ToInt32(
                        Conversion.Int((TileSize.Y * App.TerrainGridSpacing - EdgeOffset * 2.0D) / (NodeScale * App.TerrainGridSpacing * 2.0F)));
                EdgeSectionSize.Y = (TileSize.Y * App.TerrainGridSpacing - EdgeOffset * 2.0D) / EdgeSections.Y;
                EdgeSections.Y--;
            }
            else
            {
                EdgeSections.Y =
                    Convert.ToInt32(
                        Conversion.Int((TileSize.Y * App.TerrainGridSpacing / SymmetryBlockCountXY.Y - EdgeOffset) /
                                       (NodeScale * App.TerrainGridSpacing * 2.0F) - 0.5D));
                EdgeSectionSize.Y =
                    Convert.ToDouble((TileSize.Y * App.TerrainGridSpacing / SymmetryBlockCountXY.Y - EdgeOffset) /
                                            (Convert.ToDouble(
                                                Conversion.Int((TileSize.Y * App.TerrainGridSpacing / SymmetryBlockCountXY.Y - EdgeOffset) /
                                                               (NodeScale * App.TerrainGridSpacing * 2.0F) - 0.5D)) + 0.5D));
            }

            PassageNodeCount = 0;
            for ( Y = 0; Y <= EdgeSections.Y; Y++ )
            {
                if ( !MakePassageNodes(new sXY_int(EdgeOffset, EdgeOffset + (int)(Y * EdgeSectionSize.Y)), true) )
                {
                    ReturnResult.ProblemAdd("Error: Bad border node.");
                    return ReturnResult;
                }
                if ( SymmetryBlockCountXY.X == 1 )
                {
                    if (
                        !MakePassageNodes(new sXY_int(TileSize.X * App.TerrainGridSpacing - EdgeOffset, EdgeOffset + (int)(Y * EdgeSectionSize.Y)), true) )
                    {
                        ReturnResult.ProblemAdd("Error: Bad border node.");
                        return ReturnResult;
                    }
                }
            }
            for ( X = 1; X <= EdgeSections.X; X++ )
            {
                if ( !MakePassageNodes(new sXY_int(EdgeOffset + (int)(X * EdgeSectionSize.X), EdgeOffset), true) )
                {
                    ReturnResult.ProblemAdd("Error: Bad border node.");
                    return ReturnResult;
                }
                if ( SymmetryBlockCountXY.Y == 1 )
                {
                    if (
                        !MakePassageNodes(new sXY_int(EdgeOffset + (int)(X * EdgeSectionSize.X), TileSize.Y * App.TerrainGridSpacing - EdgeOffset), true) )
                    {
                        ReturnResult.ProblemAdd("Error: Bad border node.");
                        return ReturnResult;
                    }
                }
            }
            do
            {
                LoopCount = 0;
                do
                {
                    PointIsValid = true;
                    if ( SymmetryBlockCountXY.X == 1 )
                    {
                        NewPointPos.X = (int)(EdgeOffset + Conversion.Int(VBMath.Rnd() * (SymmetrySize.X - EdgeOffset * 2 + 1)));
                    }
                    else
                    {
                        NewPointPos.X = EdgeOffset + (int)(Conversion.Int(VBMath.Rnd() * (SymmetrySize.X - EdgeOffset + 1)));
                    }
                    if ( SymmetryBlockCountXY.Y == 1 )
                    {
                        NewPointPos.Y = EdgeOffset + (int)(Conversion.Int(VBMath.Rnd() * (SymmetrySize.Y - EdgeOffset * 2 + 1)));
                    }
                    else
                    {
                        NewPointPos.Y = EdgeOffset + Convert.ToInt32(Conversion.Int(VBMath.Rnd() * (SymmetrySize.Y - EdgeOffset + 1)));
                    }
                    for ( A = 0; A <= PassageNodeCount - 1; A++ )
                    {
                        for ( B = 0; B <= SymmetryBlockCount - 1; B++ )
                        {
                            if ( (PassageNodes[B, A].Pos - NewPointPos).ToDoubles().GetMagnitude() < PassageRadius * 2 )
                            {
                                goto PointTooClose;
                            }
                        }
                    }
                    PointTooClose:
                    if ( A == PassageNodeCount )
                    {
                        if ( MakePassageNodes(NewPointPos, false) )
                        {
                            break;
                        }
                    }
                    LoopCount++;
                    if ( LoopCount >= (int)(64.0F * TileSize.X * TileSize.Y / (NodeScale * NodeScale)) )
                    {
                        goto PointMakingFinished;
                    }
                } while ( true );
            } while ( true );
            PointMakingFinished:
            PassageNodes =
                (clsPassageNode[,])
                    Utils.CopyArray((Array)PassageNodes, new clsPassageNode[SymmetryBlockCount, PassageNodeCount]);

            //connect until all are connected without intersecting

            MathUtil.sIntersectPos IntersectPos = new MathUtil.sIntersectPos();
            int MaxConDist2 = PassageRadius * 2 * 4;
            MaxConDist2 *= MaxConDist2;
            clsNearest NearestA = default(clsNearest);
            Nearests = new clsNearest[PassageNodeCount * 64];
            clsPassageNode tmpPassageNodeA = default(clsPassageNode);
            clsPassageNode tmpPassageNodeB = default(clsPassageNode);
            clsTestNearestArgs NearestArgs = new clsTestNearestArgs();
            int MinConDist = (int)(NodeScale * 1.25F * 128.0F);

            NearestArgs.MaxConDist2 = MaxConDist2;
            NearestArgs.MinConDist = MinConDist;

            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                NearestArgs.PassageNodeA = PassageNodes[0, A];
                for ( B = A; B <= PassageNodeCount - 1; B++ )
                {
                    for ( C = 0; C <= SymmetryBlockCount - 1; C++ )
                    {
                        NearestArgs.PassageNodeB = PassageNodes[C, B];
                        if ( NearestArgs.PassageNodeA != NearestArgs.PassageNodeB )
                        {
                            TestNearest(NearestArgs);
                        }
                    }
                }
            }

            clsNearest NearestB = default(clsNearest);
            bool Flag = default(bool);

            for ( G = 0; G <= NearestCount - 1; G++ )
            {
                NearestA = Nearests[G];
                for ( A = 0; A <= NearestA.NodeCount - 1; A++ )
                {
                    tmpPassageNodeA = NearestA.NodeA[A];
                    tmpPassageNodeB = NearestA.NodeB[A];
                    for ( H = 0; H <= NearestCount - 1; H++ )
                    {
                        NearestB = Nearests[H];
                        if ( NearestB != NearestA )
                        {
                            if ( NearestB.Dist2 < NearestA.Dist2 )
                            {
                                Flag = true;
                            }
                            else if ( NearestB.Dist2 == NearestA.Dist2 )
                            {
                                Flag = NearestA.Num > NearestB.Num;
                            }
                            else
                            {
                                Flag = false;
                            }
                            if ( Flag )
                            {
                                for ( B = 0; B <= NearestB.NodeCount - 1; B++ )
                                {
                                    if ( !(tmpPassageNodeA == NearestB.NodeA[B] || tmpPassageNodeA == NearestB.NodeB[B]
                                           || tmpPassageNodeB == NearestB.NodeA[B] || tmpPassageNodeB == NearestB.NodeB[B]) )
                                    {
                                        IntersectPos = MathUtil.GetLinesIntersectBetween(tmpPassageNodeA.Pos, tmpPassageNodeB.Pos, NearestB.NodeA[B].Pos,
                                            NearestB.NodeB[B].Pos);
                                        if ( IntersectPos.Exists )
                                        {
                                            break;
                                        }
                                    }
                                }
                                if ( B < NearestB.NodeCount )
                                {
                                    NearestA.BlockedCount++;
                                    NearestB.BlockedNearests[NearestB.BlockedNearestCount] = NearestA;
                                    NearestB.BlockedNearestCount++;
                                }
                            }
                        }
                    }
                }
            }

            int ChangeCount = 0;
            Connections = new clsConnection[PassageNodeCount * 16];

            do
            {
                //create valid connections
                ChangeCount = 0;
                G = 0;
                while ( G < NearestCount )
                {
                    NearestA = Nearests[G];
                    Flag = true;
                    if ( NearestA.BlockedCount == 0 && Flag )
                    {
                        F = ConnectionCount;
                        for ( D = 0; D <= NearestA.NodeCount - 1; D++ )
                        {
                            Connections[ConnectionCount] = new clsConnection(NearestA.NodeA[D], NearestA.NodeB[D]);
                            ConnectionCount++;
                        }
                        for ( D = 0; D <= NearestA.NodeCount - 1; D++ )
                        {
                            A = F + D;
                            Connections[A].ReflectionCount = NearestA.NodeCount - 1;
                            Connections[A].Reflections = new clsConnection[Connections[A].ReflectionCount];
                            B = 0;
                            for ( E = 0; E <= NearestA.NodeCount - 1; E++ )
                            {
                                if ( E != D )
                                {
                                    Connections[A].Reflections[B] = Connections[F + E];
                                    B++;
                                }
                            }
                        }
                        for ( C = 0; C <= NearestA.BlockedNearestCount - 1; C++ )
                        {
                            NearestA.BlockedNearests[C].Invalid = true;
                        }
                        NearestCount--;
                        H = NearestA.Num;
                        NearestA.Num = -1;
                        if ( H != NearestCount )
                        {
                            Nearests[H] = Nearests[NearestCount];
                            Nearests[H].Num = H;
                        }
                        ChangeCount++;
                    }
                    else
                    {
                        if ( !Flag )
                        {
                            NearestA.Invalid = true;
                        }
                        G++;
                    }
                }
                //remove blocked ones and their blocking effect
                G = 0;
                while ( G < NearestCount )
                {
                    NearestA = Nearests[G];
                    if ( NearestA.Invalid )
                    {
                        NearestA.Num = -1;
                        for ( D = 0; D <= NearestA.BlockedNearestCount - 1; D++ )
                        {
                            NearestA.BlockedNearests[D].BlockedCount--;
                        }
                        NearestCount--;
                        if ( G != NearestCount )
                        {
                            Nearests[G] = Nearests[NearestCount];
                            Nearests[G].Num = G;
                        }
                    }
                    else
                    {
                        G++;
                    }
                }
            } while ( ChangeCount > 0 );

            //put connections in order of angle

            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                for ( B = 0; B <= SymmetryBlockCount - 1; B++ )
                {
                    PassageNodes[B, A].ReorderConnections();
                    PassageNodes[B, A].CalcIsNearBorder();
                }
            }

            //get nodes in random order

            clsPassageNode[] PassageNodeListOrder = new clsPassageNode[PassageNodeCount];
            int PassageNodeListOrderCount = 0;
            clsPassageNode[] PassageNodeOrder = new clsPassageNode[PassageNodeCount];
            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                PassageNodeListOrder[PassageNodeListOrderCount] = PassageNodes[0, A];
                PassageNodeListOrderCount++;
            }
            B = 0;
            while ( PassageNodeListOrderCount > 0 )
            {
                A = (int)(Conversion.Int(VBMath.Rnd() * PassageNodeListOrderCount));
                PassageNodeOrder[B] = PassageNodeListOrder[A];
                B++;
                PassageNodeListOrderCount--;
                PassageNodeListOrder[A] = PassageNodeListOrder[PassageNodeListOrderCount];
            }

            //designate height levels

            LevelHeight = 255.0F / (LevelCount - 1);
            int BestNum = 0;
            double Dist = 0;
            clsPassageNodeHeightLevelArgs HeightsArgs = new clsPassageNodeHeightLevelArgs();
            HeightsArgs.PassageNodesMinLevel.Nodes = new int[PassageNodeCount];
            HeightsArgs.PassageNodesMaxLevel.Nodes = new int[PassageNodeCount];
            HeightsArgs.MapLevelCount = new int[LevelCount];
            sXY_int RotatedPos = new sXY_int();

            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                HeightsArgs.PassageNodesMinLevel.Nodes[A] = 0;
                HeightsArgs.PassageNodesMaxLevel.Nodes[A] = LevelCount - 1;
            }

            //create bases
            double[] BestDists = new double[BaseFlatArea];
            clsPassageNode[] BestNodes = new clsPassageNode[BaseFlatArea];
            int[] BestNodesReflectionNums = new int[BaseFlatArea];
            int BestDistCount = 0;
            PlayerBases = new sPlayerBase[TotalPlayerCount];
            for ( B = 0; B <= TopLeftPlayerCount - 1; B++ )
            {
                BestDistCount = 0;
                for ( A = 0; A <= PassageNodeCount - 1; A++ )
                {
                    for ( E = 0; E <= SymmetryBlockCount - 1; E++ )
                    {
                        tmpPassageNodeA = PassageNodes[E, A];
                        if ( !tmpPassageNodeA.IsOnBorder )
                        {
                            Dist = (tmpPassageNodeA.Pos - PlayerBasePos[B]).ToDoubles().GetMagnitude();
                            for ( C = BestDistCount - 1; C >= 0; C-- )
                            {
                                if ( Dist > BestDists[C] )
                                {
                                    break;
                                }
                            }
                            C++;
                            for ( D = Math.Min(BestDistCount - 1, BaseFlatArea - 2); D >= C; D-- )
                            {
                                BestDists[D + 1] = BestDists[D];
                                BestNodes[D + 1] = BestNodes[D];
                            }
                            if ( C < BaseFlatArea )
                            {
                                BestDists[C] = Dist;
                                BestNodes[C] = tmpPassageNodeA;
                                BestDistCount = Math.Max(BestDistCount, C + 1);
                            }
                        }
                    }
                }

                if ( BaseLevel < 0 )
                {
                    D = Convert.ToInt32(Conversion.Int(VBMath.Rnd() * LevelCount));
                }
                else
                {
                    D = BaseLevel;
                }

                HeightsArgs.MapLevelCount[D] += BestDistCount;

                for ( A = 0; A <= BestDistCount - 1; A++ )
                {
                    if ( BestNodes[A].MirrorNum == 0 )
                    {
                        BestNodesReflectionNums[A] = -1;
                    }
                    else
                    {
                        for ( C = 0; C <= ((int)(SymmetryBlockCount / 2.0D)) - 1; C++ )
                        {
                            if ( SymmetryBlocks[0].ReflectToNum[C] == BestNodes[A].MirrorNum )
                            {
                                break;
                            }
                        }
                        BestNodesReflectionNums[A] = C;
                    }
                }

                for ( A = 0; A <= SymmetryBlockCount - 1; A++ )
                {
                    E = A * TopLeftPlayerCount + B;
                    PlayerBases[E].NodeCount = BestDistCount;
                    PlayerBases[E].Nodes = new clsPassageNode[PlayerBases[E].NodeCount];
                    for ( C = 0; C <= BestDistCount - 1; C++ )
                    {
                        if ( BestNodesReflectionNums[C] < 0 )
                        {
                            PlayerBases[E].Nodes[C] = PassageNodes[A, BestNodes[C].Num];
                        }
                        else
                        {
                            PlayerBases[E].Nodes[C] = PassageNodes[SymmetryBlocks[A].ReflectToNum[BestNodesReflectionNums[C]], BestNodes[C].Num];
                        }
                        PlayerBases[E].Nodes[C].PlayerBaseNum = E;
                        PlayerBases[E].Nodes[C].Level = D;
                        PassageNodesMinLevelSet(PlayerBases[E].Nodes[C], HeightsArgs.PassageNodesMinLevel, D, MaxLevelTransition);
                        PassageNodesMaxLevelSet(PlayerBases[E].Nodes[C], HeightsArgs.PassageNodesMaxLevel, D, MaxLevelTransition);
                    }
                    //PlayerBases(E).CalcPos()
                    RotatedPos = TileUtil.GetRotatedPos(SymmetryBlocks[A].Orientation, PlayerBasePos[B],
                        new sXY_int(SymmetrySize.X - 1, SymmetrySize.Y - 1));
                    PlayerBases[E].Pos.X = SymmetryBlocks[A].XYNum.X * SymmetrySize.X + RotatedPos.X;
                    PlayerBases[E].Pos.Y = SymmetryBlocks[A].XYNum.Y * SymmetrySize.Y + RotatedPos.Y;
                }
            }

            int WaterCount = 0;
            bool CanDoFlatsAroundWater = default(bool);
            int TotalWater = 0;
            int WaterSpawns = 0;

            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                tmpPassageNodeA = PassageNodeOrder[A];
                if ( tmpPassageNodeA.Level < 0 && !tmpPassageNodeA.IsOnBorder )
                {
                    WaterCount = 0;
                    for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                    {
                        tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther();
                        if ( tmpPassageNodeB.IsWater )
                        {
                            WaterCount++;
                        }
                    }
                    CanDoFlatsAroundWater = true;
                    for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                    {
                        if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeA.Connections[B].GetOther().Num] > 0 )
                        {
                            CanDoFlatsAroundWater = false;
                        }
                    }
                    if ( CanDoFlatsAroundWater &&
                         ((WaterCount == 0 & WaterSpawns < WaterSpawnQuantity) || (WaterCount == 1 & TotalWaterQuantity - TotalWater > WaterSpawnQuantity - WaterSpawns)) &&
                         HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeA.Num] == 0 & TotalWater < TotalWaterQuantity )
                    {
                        if ( WaterCount == 0 )
                        {
                            WaterSpawns++;
                        }
                        TotalWater++;
                        C = tmpPassageNodeA.Num;
                        for ( D = 0; D <= SymmetryBlockCount - 1; D++ )
                        {
                            PassageNodes[D, C].IsWater = true;
                            PassageNodes[D, C].Level = 0;
                        }
                        PassageNodesMinLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMinLevel, 0, MaxLevelTransition);
                        PassageNodesMaxLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMaxLevel, 0, MaxLevelTransition);
                        HeightsArgs.MapLevelCount[0]++;
                        for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                        {
                            tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther();
                            PassageNodesMinLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMinLevel, 0, MaxLevelTransition);
                            PassageNodesMaxLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMaxLevel, 0, MaxLevelTransition);
                        }
                    }
                }
            }

            clsPassageNode tmpPassageNodeC = default(clsPassageNode);
            App.sResult Result = new App.sResult();

            HeightsArgs.FlatsCutoff = 1;
            HeightsArgs.PassagesCutoff = 1;
            HeightsArgs.VariationCutoff = 1;
            HeightsArgs.ActionTotal = 1;

            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                tmpPassageNodeA = PassageNodeOrder[A];
                if ( tmpPassageNodeA.Level < 0 && !tmpPassageNodeA.IsOnBorder && tmpPassageNodeA.IsNearBorder )
                {
                    HeightsArgs.PassageNode = tmpPassageNodeA;
                    Result = PassageNodeHeightLevel(HeightsArgs);
                    if ( !Result.Success )
                    {
                        ReturnResult.ProblemAdd(Result.Problem);
                        return ReturnResult;
                    }
                }
            }

            HeightsArgs.FlatsCutoff = FlatsChance;
            HeightsArgs.PassagesCutoff = HeightsArgs.FlatsCutoff + PassagesChance;
            HeightsArgs.VariationCutoff = HeightsArgs.PassagesCutoff + VariationChance;
            HeightsArgs.ActionTotal = HeightsArgs.VariationCutoff;
            if ( HeightsArgs.ActionTotal <= 0 )
            {
                ReturnResult.ProblemAdd("All height level behaviors are zero");
                return ReturnResult;
            }

            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                tmpPassageNodeA = PassageNodeOrder[A];
                if ( tmpPassageNodeA.Level < 0 && !tmpPassageNodeA.IsOnBorder )
                {
                    HeightsArgs.PassageNode = tmpPassageNodeA;
                    Result = PassageNodeHeightLevel(HeightsArgs);
                    if ( !Result.Success )
                    {
                        ReturnResult.ProblemAdd(Result.Problem);
                        return ReturnResult;
                    }
                }
            }

            //set edge points to the level of their neighbour
            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                tmpPassageNodeA = PassageNodes[0, A];
                if ( tmpPassageNodeA.IsOnBorder )
                {
                    if ( tmpPassageNodeA.Level >= 0 )
                    {
                        ReturnResult.ProblemAdd("Error: Border has had its height set.");
                        return ReturnResult;
                    }
                    //If tmpPassageNodeA.ConnectionCount <> 1 Then
                    //    ReturnResult.Problem = "Error: Border has incorrect connections."
                    //    Exit Function
                    //End If
                    tmpPassageNodeC = null;
                    CanDoFlatsAroundWater = true;
                    for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                    {
                        tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther();
                        if ( tmpPassageNodeB.Level >= 0 && !tmpPassageNodeB.IsOnBorder )
                        {
                            if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeA.Num] <= tmpPassageNodeB.Level &&
                                 HeightsArgs.PassageNodesMaxLevel.Nodes[tmpPassageNodeA.Num] >= tmpPassageNodeB.Level )
                            {
                                if ( tmpPassageNodeC == null )
                                {
                                    tmpPassageNodeC = tmpPassageNodeB;
                                }
                            }
                        }
                        if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeB.Num] > 0 )
                        {
                            CanDoFlatsAroundWater = false;
                        }
                    }
                    //If tmpPassageNodeC Is Nothing Then
                    //    ReturnResult.Problem_Add("Error: No connection for border node")
                    //    Return ReturnResult
                    //End If
                    if ( tmpPassageNodeC != null )
                    {
                        BestNum = tmpPassageNodeC.Level;
                        PassageNodesMinLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMinLevel, BestNum, MaxLevelTransition);
                        PassageNodesMaxLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMaxLevel, BestNum, MaxLevelTransition);
                        for ( D = 0; D <= SymmetryBlockCount - 1; D++ )
                        {
                            PassageNodes[D, A].IsWater = tmpPassageNodeC.IsWater && CanDoFlatsAroundWater;
                            PassageNodes[D, A].Level = BestNum;
                        }
                        if ( tmpPassageNodeA.IsWater )
                        {
                            for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                            {
                                tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther();
                                PassageNodesMinLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMinLevel, tmpPassageNodeA.Level, MaxLevelTransition);
                                PassageNodesMaxLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMaxLevel, tmpPassageNodeA.Level, MaxLevelTransition);
                            }
                        }
                    }
                }
                else if ( tmpPassageNodeA.Level < 0 )
                {
                    ReturnResult.ProblemAdd("Error: Node height not set");
                    return ReturnResult;
                }
            }
            //set level of edge points only connected to another border point
            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                tmpPassageNodeA = PassageNodes[0, A];
                if ( tmpPassageNodeA.IsOnBorder && tmpPassageNodeA.Level < 0 )
                {
                    tmpPassageNodeC = null;
                    CanDoFlatsAroundWater = true;
                    for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                    {
                        tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther();
                        if ( tmpPassageNodeB.Level >= 0 )
                        {
                            if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeA.Num] <= tmpPassageNodeB.Level &&
                                 HeightsArgs.PassageNodesMaxLevel.Nodes[tmpPassageNodeA.Num] >= tmpPassageNodeB.Level )
                            {
                                if ( tmpPassageNodeC == null )
                                {
                                    tmpPassageNodeC = tmpPassageNodeB;
                                }
                            }
                        }
                        if ( HeightsArgs.PassageNodesMinLevel.Nodes[tmpPassageNodeB.Num] > 0 )
                        {
                            CanDoFlatsAroundWater = false;
                        }
                    }
                    if ( tmpPassageNodeC == null )
                    {
                        ReturnResult.ProblemAdd("Error: No connection for border node");
                        return ReturnResult;
                    }
                    BestNum = tmpPassageNodeC.Level;
                    PassageNodesMinLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMinLevel, BestNum, MaxLevelTransition);
                    PassageNodesMaxLevelSet(tmpPassageNodeA, HeightsArgs.PassageNodesMaxLevel, BestNum, MaxLevelTransition);
                    for ( D = 0; D <= SymmetryBlockCount - 1; D++ )
                    {
                        PassageNodes[D, A].IsWater = tmpPassageNodeC.IsWater && CanDoFlatsAroundWater;
                        PassageNodes[D, A].Level = BestNum;
                    }
                    if ( tmpPassageNodeA.IsWater )
                    {
                        for ( B = 0; B <= tmpPassageNodeA.ConnectionCount - 1; B++ )
                        {
                            tmpPassageNodeB = tmpPassageNodeA.Connections[B].GetOther();
                            PassageNodesMinLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMinLevel, tmpPassageNodeA.Level, MaxLevelTransition);
                            PassageNodesMaxLevelSet(tmpPassageNodeB, HeightsArgs.PassageNodesMaxLevel, tmpPassageNodeA.Level, MaxLevelTransition);
                        }
                    }
                }
            }

            RampBase = 1.0D;
            MaxDisconnectionDist = 99999.0F;

            clsResult RampResult = GenerateRamps();
            ReturnResult.Add(RampResult);

            return ReturnResult;
        }
Exemplo n.º 21
0
        public clsResult Load_Game(string Path)
        {
            clsResult ReturnResult =
                new clsResult("Loading game file from " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote));
            App.sResult SubResult = new App.sResult();
            string Quote = ControlChars.Quote.ToString();

            Tileset = null;

            TileType_Reset();
            SetPainterToDefaults();

            App.sSplitPath GameSplitPath = new App.sSplitPath(Path);
            string GameFilesPath = GameSplitPath.FilePath + GameSplitPath.FileTitleWithoutExtension + Convert.ToString(App.PlatformPathSeparator);
            string MapDirectory = "";
            FileStream File = null;

            SubResult = IOUtil.TryOpenFileStream(Path, ref File);
            if ( !SubResult.Success )
            {
                ReturnResult.ProblemAdd("Game file not found: " + SubResult.Problem);
                return ReturnResult;
            }
            else
            {
                BinaryReader Map_Reader = new BinaryReader(File);
                SubResult = Read_WZ_gam(Map_Reader);
                Map_Reader.Close();

                if ( !SubResult.Success )
                {
                    ReturnResult.ProblemAdd(SubResult.Problem);
                    return ReturnResult;
                }
            }

            SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "game.map", ref File);
            if ( !SubResult.Success )
            {
                MsgBoxResult PromptResult =
                    Interaction.MsgBox(
                        "game.map file not found at " + GameFilesPath + ControlChars.NewLine + "Do you want to select another directory to load the underlying map from?",
                        (MsgBoxStyle)(MsgBoxStyle.OkCancel | MsgBoxStyle.Question), null);
                if ( PromptResult != MsgBoxResult.Ok )
                {
                    ReturnResult.ProblemAdd("Aborted.");
                    return ReturnResult;
                }
                FolderBrowserDialog DirectorySelect = new FolderBrowserDialog();
                DirectorySelect.SelectedPath = GameFilesPath;
                if ( DirectorySelect.ShowDialog() != DialogResult.OK )
                {
                    ReturnResult.ProblemAdd("Aborted.");
                    return ReturnResult;
                }
                MapDirectory = DirectorySelect.SelectedPath + Convert.ToString(App.PlatformPathSeparator);

                SubResult = IOUtil.TryOpenFileStream(MapDirectory + "game.map", ref File);
                if ( !SubResult.Success )
                {
                    ReturnResult.ProblemAdd("game.map file not found: " + SubResult.Problem);
                    return ReturnResult;
                }
            }
            else
            {
                MapDirectory = GameFilesPath;
            }

            BinaryReader Map_ReaderB = new BinaryReader(File);
            SubResult = Read_WZ_map(Map_ReaderB);
            Map_ReaderB.Close();

            if ( !SubResult.Success )
            {
                ReturnResult.ProblemAdd(SubResult.Problem);
                return ReturnResult;
            }

            SimpleClassList<clsWZBJOUnit> BJOUnits = new SimpleClassList<clsWZBJOUnit>();

            IniFeatures INIFeatures = null;

            SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "feature.ini", ref File);
            if ( !SubResult.Success )
            {
            }
            else
            {
                clsResult Result = new clsResult("feature.ini");
                IniReader FeaturesINI = new IniReader();
                StreamReader FeaturesINI_Reader = new StreamReader(File);
                Result.Take(FeaturesINI.ReadFile(FeaturesINI_Reader));
                FeaturesINI_Reader.Close();
                INIFeatures = new IniFeatures(FeaturesINI.Sections.Count);
                Result.Take(FeaturesINI.Translate(INIFeatures));
                ReturnResult.Add(Result);
            }

            if ( INIFeatures == null )
            {
                clsResult Result = new clsResult("feat.bjo");
                SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "feat.bjo", ref File);
                if ( !SubResult.Success )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    BinaryReader Features_Reader = new BinaryReader(File);
                    SubResult = Read_WZ_Features(Features_Reader, BJOUnits);
                    Features_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            if ( true )
            {
                clsResult Result = new clsResult("ttypes.ttp");
                SubResult = IOUtil.TryOpenFileStream(MapDirectory + "ttypes.ttp", ref File);
                if ( !SubResult.Success )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    BinaryReader TileTypes_Reader = new BinaryReader(File);
                    SubResult = Read_WZ_TileTypes(TileTypes_Reader);
                    TileTypes_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            IniStructures INIStructures = null;

            SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "struct.ini", ref File);
            if ( !SubResult.Success )
            {
            }
            else
            {
                clsResult Result = new clsResult("struct.ini");
                IniReader StructuresINI = new IniReader();
                StreamReader StructuresINI_Reader = new StreamReader(File);
                Result.Take(StructuresINI.ReadFile(StructuresINI_Reader));
                StructuresINI_Reader.Close();
                INIStructures = new IniStructures(StructuresINI.Sections.Count, this);
                Result.Take(StructuresINI.Translate(INIStructures));
                ReturnResult.Add(Result);
            }

            if ( INIStructures == null )
            {
                clsResult Result = new clsResult("struct.bjo");
                SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "struct.bjo", ref File);
                if ( !SubResult.Success )
                {
                    Result.WarningAdd("struct.bjo file not found.");
                }
                else
                {
                    BinaryReader Structures_Reader = new BinaryReader(File);
                    SubResult = Read_WZ_Structures(Structures_Reader, BJOUnits);
                    Structures_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            IniDroids INIDroids = null;

            SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "droid.ini", ref File);
            if ( !SubResult.Success )
            {
            }
            else
            {
                clsResult Result = new clsResult("droid.ini");
                IniReader DroidsINI = new IniReader();
                StreamReader DroidsINI_Reader = new StreamReader(File);
                Result.Take(DroidsINI.ReadFile(DroidsINI_Reader));
                DroidsINI_Reader.Close();
                INIDroids = new IniDroids(DroidsINI.Sections.Count, this);
                Result.Take(DroidsINI.Translate(INIDroids));
                ReturnResult.Add(Result);
            }

            if ( INIStructures == null )
            {
                clsResult Result = new clsResult("dinit.bjo");
                SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "dinit.bjo", ref File);
                if ( !SubResult.Success )
                {
                    Result.WarningAdd("dinit.bjo file not found.");
                }
                else
                {
                    BinaryReader Droids_Reader = new BinaryReader(File);
                    SubResult = Read_WZ_Droids(Droids_Reader, BJOUnits);
                    Droids_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            sCreateWZObjectsArgs CreateObjectsArgs = new sCreateWZObjectsArgs();
            CreateObjectsArgs.BJOUnits = BJOUnits;
            CreateObjectsArgs.INIStructures = INIStructures;
            CreateObjectsArgs.INIDroids = INIDroids;
            CreateObjectsArgs.INIFeatures = INIFeatures;
            ReturnResult.Add(CreateWZObjects(CreateObjectsArgs));

            //map objects are modified by this and must already exist
            SubResult = IOUtil.TryOpenFileStream(GameFilesPath + "labels.ini", ref File);
            if ( !SubResult.Success )
            {
            }
            else
            {
                clsResult Result = new clsResult("labels.ini");
                IniReader LabelsINI = new IniReader();
                StreamReader LabelsINI_Reader = new StreamReader(File);
                Result.Take(LabelsINI.ReadFile(LabelsINI_Reader));
                LabelsINI_Reader.Close();
                Result.Take(Read_WZ_Labels(LabelsINI, false));
                ReturnResult.Add(Result);
            }

            return ReturnResult;
        }
Exemplo n.º 22
0
        public clsResult AutoSavePerform()
        {
            clsResult ReturnResult = new clsResult("Autosave");

            if ( !Directory.Exists(App.AutoSavePath) )
            {
                try
                {
                    Directory.CreateDirectory(App.AutoSavePath);
                }
                catch ( Exception )
                {
                    ReturnResult.ProblemAdd("Unable to create directory at " + Convert.ToString(ControlChars.Quote) + App.AutoSavePath +
                                            Convert.ToString(ControlChars.Quote));
                }
            }

            DateTime DateNow = DateTime.Now;
            string Path = "";

            Path = App.AutoSavePath + "autosaved-" + IOUtil.InvariantToString(DateNow.Year) + "-" + App.MinDigits(DateNow.Month, 2) + "-" +
                   App.MinDigits(DateNow.Day, 2) + "-" + App.MinDigits(DateNow.Hour, 2) + "-" + App.MinDigits(DateNow.Minute, 2) + "-" +
                   App.MinDigits(DateNow.Second, 2) + "-" + App.MinDigits(DateNow.Millisecond, 3) + ".fmap";

            ReturnResult.Add(Write_FMap(Path, false, SettingsManager.Settings.AutoSaveCompress));

            return ReturnResult;
        }
Exemplo n.º 23
0
        public clsResult Load_WZ(string Path)
        {
            clsResult ReturnResult =
                new clsResult("Loading WZ from " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote));
            App.sResult SubResult = new App.sResult();
            string Quote = ControlChars.Quote.ToString();
            ZipEntry ZipEntry = default(ZipEntry);
            bool GameFound = default(bool);
            bool DatasetFound = default(bool);
            SimpleList<clsWZMapEntry> Maps = new SimpleList<clsWZMapEntry>();
            clsTileset GameTileset = null;
            string GameName = "";
            string strTemp = "";
            ZipSplitPath SplitPath;
            int A = 0;
            int B = 0;
            int C = 0;
            int D = 0;

            FileStream File = default(FileStream);
            try
            {
                File = System.IO.File.OpenRead(Path);
            }
            catch ( Exception ex )
            {
                ReturnResult.ProblemAdd(ex.Message);
                return ReturnResult;
            }

            ZipInputStream ZipStream = new ZipInputStream(File);

            //get all usable lev entries
            do
            {
                ZipEntry = ZipStream.GetNextEntry();
                if ( ZipEntry == null )
                {
                    break;
                }

                SplitPath = new ZipSplitPath(ZipEntry.Name);

                if ( SplitPath.FileExtension == "lev" && SplitPath.PartCount == 1 )
                {
                    if ( ZipEntry.Size > 10 * 1024 * 1024 )
                    {
                        ReturnResult.ProblemAdd("lev file is too large.");
                        ZipStream.Close();
                        return ReturnResult;
                    }
                    BinaryReader Reader = new BinaryReader(ZipStream);
                    SimpleList<string> LineData = IOUtil.BytesToLinesRemoveComments(Reader);
                    //find each level block
                    for ( A = 0; A <= LineData.Count - 1; A++ )
                    {
                        if ( Strings.LCase(Strings.Left(LineData[A], 5)) == "level" )
                        {
                            //find each levels game file
                            GameFound = false;
                            B = 1;
                            while ( A + B < LineData.Count )
                            {
                                if ( Strings.LCase(Strings.Left(Convert.ToString(LineData[A + B]), 4)) == "game" )
                                {
                                    C = Strings.InStr(Convert.ToString(LineData[A + B]), Quote, (CompareMethod)0);
                                    D = Strings.InStrRev(Convert.ToString(LineData[A + B]), Quote, -1, (CompareMethod)0);
                                    if ( C > 0 & D > 0 & D - C > 1 )
                                    {
                                        GameName = Strings.LCase(Strings.Mid(Convert.ToString(LineData[A + B]), C + 1, D - C - 1));
                                        //see if map is already counted
                                        for ( C = 0; C <= Maps.Count - 1; C++ )
                                        {
                                            if ( GameName == Maps[C].Name )
                                            {
                                                break;
                                            }
                                        }
                                        if ( C == Maps.Count )
                                        {
                                            GameFound = true;
                                        }
                                    }
                                    break;
                                }
                                else if ( Strings.LCase(Strings.Left(Convert.ToString(LineData[A + B]), 5)) == "level" )
                                {
                                    break;
                                }
                                B++;
                            }
                            if ( GameFound )
                            {
                                //find the dataset (determines tileset)
                                DatasetFound = false;
                                B = 1;
                                while ( A + B < LineData.Count )
                                {
                                    if ( Strings.LCase(Strings.Left(Convert.ToString(LineData[A + B]), 7)) == "dataset" )
                                    {
                                        strTemp = Strings.LCase(Strings.Right(Convert.ToString(LineData[A + B]), 1));
                                        if ( strTemp == "1" )
                                        {
                                            GameTileset = App.Tileset_Arizona;
                                            DatasetFound = true;
                                        }
                                        else if ( strTemp == "2" )
                                        {
                                            GameTileset = App.Tileset_Urban;
                                            DatasetFound = true;
                                        }
                                        else if ( strTemp == "3" )
                                        {
                                            GameTileset = App.Tileset_Rockies;
                                            DatasetFound = true;
                                        }
                                        break;
                                    }
                                    else if ( Strings.LCase(Strings.Left(Convert.ToString(LineData[A + B]), 5)) == "level" )
                                    {
                                        break;
                                    }
                                    B++;
                                }
                                if ( DatasetFound )
                                {
                                    clsWZMapEntry NewMap = new clsWZMapEntry();
                                    NewMap.Name = GameName;
                                    NewMap.Tileset = GameTileset;
                                    Maps.Add(NewMap);
                                }
                            }
                        }
                    }
                }
            } while ( true );
            ZipStream.Close();

            string MapLoadName = "";

            //prompt user for which of the entries to load
            if ( Maps.Count < 1 )
            {
                ReturnResult.ProblemAdd("No maps found in file.");
                return ReturnResult;
            }
            else if ( Maps.Count == 1 )
            {
                MapLoadName = Convert.ToString(Maps[0].Name);
                Tileset = Maps[0].Tileset;
            }
            else
            {
                frmWZLoad.clsOutput SelectToLoadResult = new frmWZLoad.clsOutput();
                string[] Names = new string[Maps.Count];
                for ( A = 0; A <= Maps.Count - 1; A++ )
                {
                    Names[A] = Convert.ToString(Maps[A].Name);
                }
                frmWZLoad SelectToLoadForm = new frmWZLoad(Names, SelectToLoadResult,
                    "Select a map from " + Convert.ToString(new App.sSplitPath(Path).FileTitle));
                SelectToLoadForm.ShowDialog();
                if ( SelectToLoadResult.Result < 0 )
                {
                    ReturnResult.ProblemAdd("No map selected.");
                    return ReturnResult;
                }
                MapLoadName = Convert.ToString(Maps[SelectToLoadResult.Result].Name);
                Tileset = Maps[SelectToLoadResult.Result].Tileset;
            }

            TileType_Reset();
            SetPainterToDefaults();

            ZipSplitPath GameSplitPath = new ZipSplitPath(MapLoadName);
            string GameFilesPath = GameSplitPath.FilePath + GameSplitPath.FileTitleWithoutExtension + "/";

            ZipStreamEntry ZipSearchResult = default(ZipStreamEntry);

            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, MapLoadName);
            if ( ZipSearchResult == null )
            {
                ReturnResult.ProblemAdd("Game file not found.");
                return ReturnResult;
            }
            else
            {
                BinaryReader Map_Reader = new BinaryReader(ZipSearchResult.Stream);
                SubResult = Read_WZ_gam(Map_Reader);
                Map_Reader.Close();

                if ( !SubResult.Success )
                {
                    ReturnResult.ProblemAdd(SubResult.Problem);
                    return ReturnResult;
                }
            }

            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "game.map");
            if ( ZipSearchResult == null )
            {
                ReturnResult.ProblemAdd("game.map file not found");
                return ReturnResult;
            }
            else
            {
                BinaryReader Map_Reader = new BinaryReader(ZipSearchResult.Stream);
                SubResult = Read_WZ_map(Map_Reader);
                Map_Reader.Close();

                if ( !SubResult.Success )
                {
                    ReturnResult.ProblemAdd(SubResult.Problem);
                    return ReturnResult;
                }
            }

            SimpleClassList<clsWZBJOUnit> BJOUnits = new SimpleClassList<clsWZBJOUnit>();

            IniFeatures INIFeatures = null;

            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "feature.ini");
            if ( ZipSearchResult == null )
            {
            }
            else
            {
                clsResult Result = new clsResult("feature.ini");
                IniReader FeaturesINI = new IniReader();
                StreamReader FeaturesINI_Reader = new StreamReader(ZipSearchResult.Stream);
                Result.Take(FeaturesINI.ReadFile(FeaturesINI_Reader));
                FeaturesINI_Reader.Close();
                INIFeatures = new IniFeatures(FeaturesINI.Sections.Count);
                Result.Take(FeaturesINI.Translate(INIFeatures));
                ReturnResult.Add(Result);
            }

            if ( INIFeatures == null )
            {
                clsResult Result = new clsResult("feat.bjo");
                ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "feat.bjo");
                if ( ZipSearchResult == null )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    BinaryReader Features_Reader = new BinaryReader(ZipSearchResult.Stream);
                    SubResult = Read_WZ_Features(Features_Reader, BJOUnits);
                    Features_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            if ( true )
            {
                clsResult Result = new clsResult("ttypes.ttp");
                ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "ttypes.ttp");
                if ( ZipSearchResult == null )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    BinaryReader TileTypes_Reader = new BinaryReader(ZipSearchResult.Stream);
                    SubResult = Read_WZ_TileTypes(TileTypes_Reader);
                    TileTypes_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            IniStructures INIStructures = null;

            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "struct.ini");
            if ( ZipSearchResult == null )
            {
            }
            else
            {
                clsResult Result = new clsResult("struct.ini");
                IniReader StructuresINI = new IniReader();
                StreamReader StructuresINI_Reader = new StreamReader(ZipSearchResult.Stream);
                Result.Take(StructuresINI.ReadFile(StructuresINI_Reader));
                StructuresINI_Reader.Close();
                INIStructures = new IniStructures(StructuresINI.Sections.Count, this);
                Result.Take(StructuresINI.Translate(INIStructures));
                ReturnResult.Add(Result);
            }

            if ( INIStructures == null )
            {
                clsResult Result = new clsResult("struct.bjo");
                ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "struct.bjo");
                if ( ZipSearchResult == null )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    BinaryReader Structures_Reader = new BinaryReader(ZipSearchResult.Stream);
                    SubResult = Read_WZ_Structures(Structures_Reader, BJOUnits);
                    Structures_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            IniDroids INIDroids = null;

            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "droid.ini");
            if ( ZipSearchResult == null )
            {
            }
            else
            {
                clsResult Result = new clsResult("droid.ini");
                IniReader DroidsINI = new IniReader();
                StreamReader DroidsINI_Reader = new StreamReader(ZipSearchResult.Stream);
                Result.Take(DroidsINI.ReadFile(DroidsINI_Reader));
                DroidsINI_Reader.Close();
                INIDroids = new IniDroids(DroidsINI.Sections.Count, this);
                Result.Take(DroidsINI.Translate(INIDroids));
                ReturnResult.Add(Result);
            }

            if ( INIDroids == null )
            {
                clsResult Result = new clsResult("dinit.bjo");
                ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "dinit.bjo");
                if ( ZipSearchResult == null )
                {
                    Result.WarningAdd("file not found");
                }
                else
                {
                    BinaryReader Droids_Reader = new BinaryReader(ZipSearchResult.Stream);
                    SubResult = Read_WZ_Droids(Droids_Reader, BJOUnits);
                    Droids_Reader.Close();
                    if ( !SubResult.Success )
                    {
                        Result.WarningAdd(SubResult.Problem);
                    }
                }
                ReturnResult.Add(Result);
            }

            sCreateWZObjectsArgs CreateObjectsArgs = new sCreateWZObjectsArgs();
            CreateObjectsArgs.BJOUnits = BJOUnits;
            CreateObjectsArgs.INIStructures = INIStructures;
            CreateObjectsArgs.INIDroids = INIDroids;
            CreateObjectsArgs.INIFeatures = INIFeatures;
            ReturnResult.Add(CreateWZObjects(CreateObjectsArgs));

            //objects are modified by this and must already exist
            ZipSearchResult = IOUtil.FindZipEntryFromPath(Path, GameFilesPath + "labels.ini");
            if ( ZipSearchResult == null )
            {
            }
            else
            {
                clsResult Result = new clsResult("labels.ini");
                IniReader LabelsINI = new IniReader();
                StreamReader LabelsINI_Reader = new StreamReader(ZipSearchResult.Stream);
                Result.Take(LabelsINI.ReadFile(LabelsINI_Reader));
                LabelsINI_Reader.Close();
                Result.Take(Read_WZ_Labels(LabelsINI, false));
                ReturnResult.Add(Result);
            }

            return ReturnResult;
        }