Exemple #1
0
        public static sResult SaveBitmap(string Path, bool Overwrite, Bitmap BitmapToSave)
        {
            var ReturnResult = new sResult();
            ReturnResult.Problem = "";
            ReturnResult.Success = false;

            try
            {
                if ( File.Exists(Path) )
                {
                    if ( Overwrite )
                    {
                        File.Delete(Path);
                    }
                    else
                    {
                        ReturnResult.Problem = "File already exists.";
                        return ReturnResult;
                    }
                }
                BitmapToSave.Save(Path);
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
        public string GetDefaultScriptLabel(string Prefix)
        {
            var Number = 1;
            var Valid = new sResult();
            var Label = "";

            do
            {
                Label = Prefix + Number.ToStringInvariant();
                Valid = ScriptLabelIsValid(Label);
                if ( Valid.Success )
                {
                    return Label;
                }
                Number++;
                if ( Number >= 16384 )
                {
                    MessageBox.Show("Error: Unable to set default script label.");
                    return "";
                }
            } while ( true );
        }
Exemple #3
0
        public static sResult LoadBitmap(string Path, ref Bitmap ResultBitmap)
        {
            var ReturnResult = new sResult();
            ReturnResult.Problem = "";
            ReturnResult.Success = false;

            var Bitmap = default(Bitmap);

            try
            {
                Bitmap = new Bitmap(Path);
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                ResultBitmap = null;
                return ReturnResult;
            }

            ResultBitmap = new Bitmap(Bitmap); //copying the bitmap is needed so it doesn't lock access to the file

            ReturnResult.Success = true;
            return ReturnResult;
        }
Exemple #4
0
        public sResult SetLabel(string text)
        {
            var Result = new sResult();

            Result = _ParentMapLink.Source.ScriptLabelIsValid(text);
            if ( Result.Success )
            {
                Label = text;
            }
            return Result;
        }
Exemple #5
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;
        }
Exemple #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;
        }
Exemple #7
0
        private sResult ReadTileType(BinaryReader file)
        {
            var returnResult = new sResult();
            returnResult.Success = false;
            returnResult.Problem = "";

            UInt32 uintTemp = 0;
            var i = 0;
            UInt16 ushortTemp = 0;
            var strTemp = "";

            try
            {
                strTemp = IOUtil.ReadOldTextOfLength(file, 4);
                if ( strTemp != "ttyp" )
                {
                    returnResult.Problem = "Bad identifier.";
                    return returnResult;
                }

                uintTemp = file.ReadUInt32();
                if ( !(uintTemp == 8U) )
                {
                    returnResult.Problem = "Unknown version.";
                    return returnResult;
                }

                uintTemp = file.ReadUInt32();
                TileCount = Convert.ToInt32(uintTemp);
                Tiles = new sTile[TileCount];

                for ( i = 0; i <= Math.Min(Convert.ToInt32(uintTemp), TileCount) - 1; i++ )
                {
                    ushortTemp = file.ReadUInt16();
                    if ( ushortTemp > App.TileTypes.Count )
                    {
                        returnResult.Problem = "Unknown tile type.";
                        return returnResult;
                    }
                    Tiles[i].DefaultType = (byte)ushortTemp;
                }
            }
            catch ( Exception ex )
            {
                returnResult.Problem = ex.Message;
                return returnResult;
            }

            returnResult.Success = true;
            return returnResult;
        }
Exemple #8
0
        protected sResult read_WZ_Droids(BinaryReader File, List<WZBJOUnit> WZUnits)
        {
            var ReturnResult = new sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            string strTemp = null;
            UInt32 Version = 0;
            UInt32 uintTemp = 0;
            var A = 0;
            var WZBJOUnit = default(WZBJOUnit);

            try
            {
                strTemp = IOUtil.ReadOldTextOfLength(File, 4);
                if ( strTemp != "dint" )
                {
                    ReturnResult.Problem = "Unknown dinit.bjo identifier.";
                    return ReturnResult;
                }

                Version = File.ReadUInt32();
                if ( Version > 19U )
                {
                    if ( MessageBox.Show("dinit.bjo version is unknown. Continue?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK )
                    {
                        ReturnResult.Problem = "Aborted.";
                        return ReturnResult;
                    }
                }

                uintTemp = File.ReadUInt32();
                for ( A = 0; A <= (Convert.ToInt32(uintTemp)) - 1; A++ )
                {
                    WZBJOUnit = new WZBJOUnit();
                    WZBJOUnit.ObjectType = UnitType.PlayerDroid;
                    WZBJOUnit.Code = IOUtil.ReadOldTextOfLength(File, 40);
                    WZBJOUnit.Code = WZBJOUnit.Code.Substring(0, WZBJOUnit.Code.IndexOf('\0'));
                    WZBJOUnit.ID = File.ReadUInt32();
                    WZBJOUnit.Pos.Horizontal.X = (int)(File.ReadUInt32());
                    WZBJOUnit.Pos.Horizontal.Y = (int)(File.ReadUInt32());
                    WZBJOUnit.Pos.Altitude = (int)(File.ReadUInt32());
                    WZBJOUnit.Rotation = File.ReadUInt32();
                    WZBJOUnit.Player = File.ReadUInt32();
                    File.ReadBytes(12);
                    WZUnits.Add(WZBJOUnit);
                }
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                logger.ErrorException("Got an exception", ex);
                return ReturnResult;
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Exemple #9
0
        protected sResult read_WZ_gam(BinaryReader File)
        {
            var ReturnResult = new sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            var strTemp = "";
            UInt32 Version = 0;

            try
            {
                strTemp = IOUtil.ReadOldTextOfLength(File, 4);
                if ( strTemp != "game" )
                {
                    ReturnResult.Problem = "Unknown game identifier.";
                    return ReturnResult;
                }

                Version = File.ReadUInt32();
                if ( Version != 8U )
                {
                    if ( MessageBox.Show("Game file version is unknown. Continue?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK )
                    {
                        ReturnResult.Problem = "Aborted.";
                        return ReturnResult;
                    }
                }

                if ( map.InterfaceOptions == null )
                {
                    map.InterfaceOptions = new clsInterfaceOptions();
                }

                File.ReadInt32(); //game time
                map.InterfaceOptions.CampaignGameType = File.ReadInt32();
                map.InterfaceOptions.AutoScrollLimits = false;
                map.InterfaceOptions.ScrollMin.X = File.ReadInt32();
                map.InterfaceOptions.ScrollMin.Y = File.ReadInt32();
                map.InterfaceOptions.ScrollMax.X = File.ReadUInt32();
                map.InterfaceOptions.ScrollMax.Y = File.ReadUInt32();
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                logger.ErrorException("Got an exception", ex);
                return ReturnResult;
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Exemple #10
0
        private sResult PassageNodeHeightLevel(clsPassageNodeHeightLevelArgs Args)
        {
            var ReturnResult = new sResult();
            ReturnResult.Problem = "";
            ReturnResult.Success = false;

            var LevelCounts = new int[LevelCount];
            var WaterCount = 0;
            var ConnectedToLevel = default(bool);
            var tmpPassageNodeB = default(clsPassageNode);
            var tmpPassageNodeC = default(clsPassageNode);
            var EligableCount = 0;
            var Eligables = new int[LevelCount];
            var NewHeightLevel = 0;
            var RandomAction = 0;
            var A = 0;
            var B = 0;

            for ( B = 0; B <= Args.PassageNode.ConnectionCount - 1; B++ )
            {
                tmpPassageNodeB = Args.PassageNode.Connections[B].GetOther();
                if ( tmpPassageNodeB.Level >= 0 )
                {
                    LevelCounts[tmpPassageNodeB.Level]++;
                    ConnectedToLevel = true;
                }
                if ( tmpPassageNodeB.IsWater )
                {
                    WaterCount++;
                }
            }
            if ( WaterCount > 0 )
            {
                NewHeightLevel = 0;
            }
            else if ( Args.PassageNodesMinLevel.Nodes[Args.PassageNode.Num] > Args.PassageNodesMaxLevel.Nodes[Args.PassageNode.Num] )
            {
                ReturnResult.Problem = "Error: Min height more than max.";
                return ReturnResult;
            }
            else if ( !ConnectedToLevel )
            {
                //switch to the most uncommon level on the map
                A = int.MaxValue;
                EligableCount = 0;
                for ( B = Args.PassageNodesMinLevel.Nodes[Args.PassageNode.Num]; B <= Args.PassageNodesMaxLevel.Nodes[Args.PassageNode.Num]; B++ )
                {
                    if ( Args.MapLevelCount[B] < A )
                    {
                        A = Args.MapLevelCount[B];
                        Eligables[0] = B;
                        EligableCount = 1;
                    }
                    else if ( Args.MapLevelCount[B] == A )
                    {
                        Eligables[EligableCount] = B;
                        EligableCount++;
                    }
                }
                NewHeightLevel = Eligables[App.Random.Next() * EligableCount];
            }
            else
            {
                RandomAction = Convert.ToInt32((App.Random.Next() * Args.ActionTotal));
                if ( RandomAction < Args.FlatsCutoff )
                {
                    //extend the level that surrounds this most
                    A = 0;
                    EligableCount = 0;
                    for ( B = Args.PassageNodesMinLevel.Nodes[Args.PassageNode.Num]; B <= Args.PassageNodesMaxLevel.Nodes[Args.PassageNode.Num]; B++ )
                    {
                        if ( LevelCounts[B] > A )
                        {
                            A = LevelCounts[B];
                            Eligables[0] = B;
                            EligableCount = 1;
                        }
                        else if ( LevelCounts[B] == A )
                        {
                            Eligables[EligableCount] = B;
                            EligableCount++;
                        }
                    }
                }
                else if ( RandomAction < Args.PassagesCutoff )
                {
                    //extend any level that surrounds only once, or twice by nodes that aren't already connected
                    EligableCount = 0;
                    for ( B = Args.PassageNodesMinLevel.Nodes[Args.PassageNode.Num]; B <= Args.PassageNodesMaxLevel.Nodes[Args.PassageNode.Num]; B++ )
                    {
                        if ( LevelCounts[B] == 1 )
                        {
                            Eligables[EligableCount] = B;
                            EligableCount++;
                        }
                        else if ( LevelCounts[B] == 2 )
                        {
                            EligableCount = 0;
                            tmpPassageNodeC = null;
                            for ( A = 0; A <= Args.PassageNode.ConnectionCount - 1; A++ )
                            {
                                tmpPassageNodeB = Args.PassageNode.Connections[A].GetOther();
                                if ( tmpPassageNodeB.Level == B )
                                {
                                    if ( tmpPassageNodeC == null )
                                    {
                                        tmpPassageNodeC = tmpPassageNodeB;
                                    }
                                    else
                                    {
                                        if ( tmpPassageNodeC.FindConnection(tmpPassageNodeB) == null )
                                        {
                                            Eligables[EligableCount] = B;
                                            EligableCount++;
                                        }
                                        break;
                                    }
                                }
                            }
                            if ( A == Args.PassageNode.ConnectionCount )
                            {
                                MessageBox.Show("Error: two nodes not found");
                            }
                        }
                    }
                }
                else if ( RandomAction < Args.VariationCutoff )
                {
                    EligableCount = 0;
                }
                else
                {
                    ReturnResult.Problem = "Error: Random number out of range.";
                    return ReturnResult;
                }
                if ( EligableCount == 0 )
                {
                    //extend the most uncommon surrounding
                    A = int.MaxValue;
                    EligableCount = 0;
                    for ( B = Args.PassageNodesMinLevel.Nodes[Args.PassageNode.Num]; B <= Args.PassageNodesMaxLevel.Nodes[Args.PassageNode.Num]; B++ )
                    {
                        if ( LevelCounts[B] < A )
                        {
                            A = LevelCounts[B];
                            Eligables[0] = B;
                            EligableCount = 1;
                        }
                        else if ( LevelCounts[B] == A )
                        {
                            Eligables[EligableCount] = B;
                            EligableCount++;
                        }
                    }
                }
                NewHeightLevel = Eligables[App.Random.Next() * EligableCount];
            }
            for ( B = 0; B <= SymmetryBlockCount - 1; B++ )
            {
                PassageNodes[B, Args.PassageNode.Num].Level = NewHeightLevel;
            }
            PassageNodesMinLevelSet(Args.PassageNode, Args.PassageNodesMinLevel, NewHeightLevel, MaxLevelTransition);
            PassageNodesMaxLevelSet(Args.PassageNode, Args.PassageNodesMaxLevel, NewHeightLevel, MaxLevelTransition);
            Args.MapLevelCount[NewHeightLevel]++;

            ReturnResult.Success = true;
            return ReturnResult;
        }
Exemple #11
0
        public clsResult GenerateLayout()
        {
            var ReturnResult = new clsResult("Layout", false);
            logger.Info("Generating Layouts");

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

            TotalPlayerCount = TopLeftPlayerCount * SymmetryBlockCount;

            var SymmetrySize = new XYInt();

            SymmetrySize.X = TileSize.X * Constants.TerrainGridSpacing / SymmetryBlockCountXY.X;
            SymmetrySize.Y = TileSize.Y * Constants.TerrainGridSpacing / SymmetryBlockCountXY.Y;

            //create passage nodes

            var PassageRadius = (int)(128.0F * NodeScale);
            var 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];
            var LoopCount = 0;
            var EdgeOffset = 0 * 128;
            var EdgeSections = new XYInt();
            var EdgeSectionSize = default(XYDouble);
            var NewPointPos = new XYInt();

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

            PassageNodeCount = 0;
            for ( Y = 0; Y <= EdgeSections.Y; Y++ )
            {
                if ( !MakePassageNodes(new XYInt(EdgeOffset, EdgeOffset + (int)(Y * EdgeSectionSize.Y)), true) )
                {
                    ReturnResult.ProblemAdd("Error: Bad border node.");
                    return ReturnResult;
                }
                if ( SymmetryBlockCountXY.X == 1 )
                {
                    if (
                        !MakePassageNodes(new XYInt(TileSize.X * Constants.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 XYInt(EdgeOffset + (int)(X * EdgeSectionSize.X), EdgeOffset), true) )
                {
                    ReturnResult.ProblemAdd("Error: Bad border node.");
                    return ReturnResult;
                }
                if ( SymmetryBlockCountXY.Y == 1 )
                {
                    if (
                        !MakePassageNodes(new XYInt(EdgeOffset + (int)(X * EdgeSectionSize.X), TileSize.Y * Constants.TerrainGridSpacing - EdgeOffset), true) )
                    {
                        ReturnResult.ProblemAdd("Error: Bad border node.");
                        return ReturnResult;
                    }
                }
            }
            do
            {
                LoopCount = 0;
                do
                {
                    if ( SymmetryBlockCountXY.X == 1 )
                    {
                        NewPointPos.X = EdgeOffset + (App.Random.Next() * (SymmetrySize.X - EdgeOffset * 2 + 1));
                    }
                    else
                    {
                        NewPointPos.X = EdgeOffset + App.Random.Next() * (SymmetrySize.X - EdgeOffset + 1);
                    }
                    if ( SymmetryBlockCountXY.Y == 1 )
                    {
                        NewPointPos.Y = EdgeOffset + App.Random.Next() * (SymmetrySize.Y - EdgeOffset * 2 + 1);
                    }
                    else
                    {
                        NewPointPos.Y = EdgeOffset + Convert.ToInt32((App.Random.Next() * (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:
            var tmpPassgeNodes = new clsPassageNode[SymmetryBlockCount, PassageNodeCount];
            Array.Copy(PassageNodes, tmpPassgeNodes, PassageNodeCount);
            PassageNodes = tmpPassgeNodes;
            //connect until all are connected without intersecting

            var IntersectPos = new MathUtil.sIntersectPos();
            var MaxConDist2 = PassageRadius * 2 * 4;
            MaxConDist2 *= MaxConDist2;
            var NearestA = default(clsNearest);
            Nearests = new clsNearest[PassageNodeCount * 64];
            var tmpPassageNodeA = default(clsPassageNode);
            var tmpPassageNodeB = default(clsPassageNode);
            var NearestArgs = new clsTestNearestArgs();
            var 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);
                        }
                    }
                }
            }

            var NearestB = default(clsNearest);
            var 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++;
                                }
                            }
                        }
                    }
                }
            }

            var 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

            var PassageNodeListOrder = new clsPassageNode[PassageNodeCount];
            var PassageNodeListOrderCount = 0;
            var PassageNodeOrder = new clsPassageNode[PassageNodeCount];
            for ( A = 0; A <= PassageNodeCount - 1; A++ )
            {
                PassageNodeListOrder[PassageNodeListOrderCount] = PassageNodes[0, A];
                PassageNodeListOrderCount++;
            }
            B = 0;
            while ( PassageNodeListOrderCount > 0 )
            {
                A = App.Random.Next() * PassageNodeListOrderCount;
                PassageNodeOrder[B] = PassageNodeListOrder[A];
                B++;
                PassageNodeListOrderCount--;
                PassageNodeListOrder[A] = PassageNodeListOrder[PassageNodeListOrderCount];
            }

            //designate height levels

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

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

            //create bases
            var BestDists = new double[BaseFlatArea];
            var BestNodes = new clsPassageNode[BaseFlatArea];
            var BestNodesReflectionNums = new int[BaseFlatArea];
            var 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((App.Random.Next() * 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 XYInt(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;
                }
            }

            var WaterCount = 0;
            var CanDoFlatsAroundWater = default(bool);
            var TotalWater = 0;
            var 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);
                        }
                    }
                }
            }

            var tmpPassageNodeC = default(clsPassageNode);
            var Result = new 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;

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

            return ReturnResult;
        }
Exemple #12
0
        public sResult GenerateGateways()
        {
            var ReturnResult = new sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            //must be done before units otherwise the units will be treated as gateway obstacles

            var Terrain = Map.Terrain;

            var X = 0;
            var SpaceCount = 0;
            var Y = 0;
            var PossibleGateways = new sPossibleGateway[Terrain.TileSize.X * Terrain.TileSize.Y * 2];
            var PossibleGatewayCount = 0;

            for ( Y = 0; Y <= Terrain.TileSize.Y - 1; Y++ )
            {
                SpaceCount = 0;
                for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
                {
                    if ( GenerateTerrainTiles[X, Y].Node.GetClearance < 1 )
                    {
                    }
                    else if ( GenerateTerrainTiles[X, Y].Node.GetClearance == 1 )
                    {
                        if ( SpaceCount > 3 & SpaceCount <= 9 )
                        {
                            PossibleGateways[PossibleGatewayCount].StartPos.X = X - SpaceCount;
                            PossibleGateways[PossibleGatewayCount].StartPos.Y = Y;
                            PossibleGateways[PossibleGatewayCount].Length = SpaceCount + 1;
                            PossibleGateways[PossibleGatewayCount].IsVertical = false;
                            PossibleGateways[PossibleGatewayCount].MiddlePos.X = PossibleGateways[PossibleGatewayCount].StartPos.X * 128 +
                                                                                 PossibleGateways[PossibleGatewayCount].Length * 64;
                            PossibleGateways[PossibleGatewayCount].MiddlePos.Y = PossibleGateways[PossibleGatewayCount].StartPos.Y * 128;
                            PossibleGatewayCount++;
                        }
                        SpaceCount = 1;
                    }
                    else
                    {
                        SpaceCount++;
                    }
                }
            }
            for ( X = 0; X <= Terrain.TileSize.X - 1; X++ )
            {
                SpaceCount = 0;
                Y = 0;
                while ( Y < Terrain.TileSize.Y )
                {
                    if ( GenerateTerrainTiles[X, Y].Node.GetClearance < 1 )
                    {
                    }
                    else if ( GenerateTerrainTiles[X, Y].Node.GetClearance == 1 )
                    {
                        if ( SpaceCount >= 3 & SpaceCount <= 9 )
                        {
                            PossibleGateways[PossibleGatewayCount].StartPos.X = X;
                            PossibleGateways[PossibleGatewayCount].StartPos.Y = Y - SpaceCount;
                            PossibleGateways[PossibleGatewayCount].Length = SpaceCount + 1;
                            PossibleGateways[PossibleGatewayCount].IsVertical = true;
                            PossibleGateways[PossibleGatewayCount].MiddlePos.X = PossibleGateways[PossibleGatewayCount].StartPos.X * 128;
                            PossibleGateways[PossibleGatewayCount].MiddlePos.Y = PossibleGateways[PossibleGatewayCount].StartPos.Y * 128 +
                                                                                 PossibleGateways[PossibleGatewayCount].Length * 64;
                            PossibleGatewayCount++;
                        }
                        SpaceCount = 1;
                    }
                    else
                    {
                        SpaceCount++;
                    }
                    Y++;
                }
            }

            //add the best gateways

            var A = 0;
            float Value = 0;
            float BestValue = 0;
            var BestNum = 0;
            var TileIsGateway = new bool[Terrain.TileSize.X, Terrain.TileSize.Y];
            var Valid = default(bool);
            var InvalidPos = new XYInt();
            double InvalidDist = 0;

            while ( PossibleGatewayCount > 0 )
            {
                BestNum = -1;
                BestValue = float.MaxValue;
                for ( A = 0; A <= PossibleGatewayCount - 1; A++ )
                {
                    //Value = 0.0F
                    //For B = 0 To PossibleGatewayCount - 1
                    //    Value += GetDist(PossibleGateways(A).MiddlePos, PossibleGateways(B).MiddlePos)
                    //Next
                    Value = PossibleGateways[A].Length;
                    if ( Value < BestValue )
                    {
                        BestValue = Value;
                        BestNum = A;
                    }
                }
                if ( PossibleGateways[BestNum].IsVertical )
                {
                    Map.GatewayCreateStoreChange(PossibleGateways[BestNum].StartPos,
                        new XYInt(PossibleGateways[BestNum].StartPos.X, PossibleGateways[BestNum].StartPos.Y + PossibleGateways[BestNum].Length - 1));
                    for ( Y = PossibleGateways[BestNum].StartPos.Y; Y <= PossibleGateways[BestNum].StartPos.Y + PossibleGateways[BestNum].Length - 1; Y++ )
                    {
                        TileIsGateway[PossibleGateways[BestNum].StartPos.X, Y] = true;
                    }
                }
                else
                {
                    Map.GatewayCreateStoreChange(PossibleGateways[BestNum].StartPos,
                        new XYInt(PossibleGateways[BestNum].StartPos.X + PossibleGateways[BestNum].Length - 1, PossibleGateways[BestNum].StartPos.Y));
                    for ( X = PossibleGateways[BestNum].StartPos.X; X <= PossibleGateways[BestNum].StartPos.X + PossibleGateways[BestNum].Length - 1; X++ )
                    {
                        TileIsGateway[X, PossibleGateways[BestNum].StartPos.Y] = true;
                    }
                }
                InvalidPos = PossibleGateways[BestNum].MiddlePos;
                InvalidDist = PossibleGateways[BestNum].Length * 128;
                A = 0;
                while ( A < PossibleGatewayCount )
                {
                    Valid = true;
                    if ( PossibleGateways[A].IsVertical )
                    {
                        for ( Y = PossibleGateways[A].StartPos.Y; Y <= PossibleGateways[A].StartPos.Y + PossibleGateways[A].Length - 1; Y++ )
                        {
                            if ( TileIsGateway[PossibleGateways[A].StartPos.X, Y] )
                            {
                                Valid = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        for ( X = PossibleGateways[A].StartPos.X; X <= PossibleGateways[A].StartPos.X + PossibleGateways[A].Length - 1; X++ )
                        {
                            if ( TileIsGateway[X, PossibleGateways[A].StartPos.Y] )
                            {
                                Valid = false;
                                break;
                            }
                        }
                    }
                    if ( Valid )
                    {
                        if ( (InvalidPos - PossibleGateways[A].MiddlePos).ToDoubles().GetMagnitude() < InvalidDist )
                        {
                            Valid = false;
                        }
                    }
                    if ( !Valid )
                    {
                        PossibleGatewayCount--;
                        if ( A != PossibleGatewayCount )
                        {
                            PossibleGateways[A] = PossibleGateways[PossibleGatewayCount];
                        }
                    }
                    else
                    {
                        A++;
                    }
                }
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Exemple #13
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;
        }
Exemple #14
0
        public static sResult TryOpenFileStream(string Path, ref FileStream Output)
        {
            var ReturnResult = new sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            try
            {
                Output = new FileStream(Path, FileMode.Open);
            }
            catch ( Exception ex )
            {
                Output = null;
                ReturnResult.Problem = ex.Message;
                return ReturnResult;
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
        public sResult ScriptLabelIsValid(string Text)
        {
            var ReturnResult = new sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            if ( Text == null )
            {
                ReturnResult.Problem = "Label cannot be nothing.";
                return ReturnResult;
            }

            var LCaseText = Text.ToLower();

            if ( LCaseText.Length < 1 )
            {
                ReturnResult.Problem = "Label cannot be nothing.";
                return ReturnResult;
            }

            var CurrentChar = (char)0;
            var Invalid = default(bool);

            Invalid = false;
            foreach ( var tempLoopVar_CurrentChar in LCaseText )
            {
                CurrentChar = tempLoopVar_CurrentChar;
                if ( !((CurrentChar >= 'a' && CurrentChar <= 'z') || (CurrentChar >= '0' && CurrentChar <= '9') || CurrentChar == '_') )
                {
                    Invalid = true;
                    break;
                }
            }
            if ( Invalid )
            {
                ReturnResult.Problem = "Label contains invalid characters. Use only letters, numbers or underscores.";
                return ReturnResult;
            }

            var Unit = default(clsUnit);

            foreach ( var tempLoopVar_Unit in Units )
            {
                Unit = tempLoopVar_Unit;
                if ( Unit.Label != null )
                {
                    if ( LCaseText == Unit.Label.ToLower() )
                    {
                        ReturnResult.Problem = "Label text is already in use.";
                        return ReturnResult;
                    }
                }
            }

            var ScriptPosition = default(clsScriptPosition);

            foreach ( var tempLoopVar_ScriptPosition in ScriptPositions )
            {
                ScriptPosition = tempLoopVar_ScriptPosition;
                if ( LCaseText == ScriptPosition.Label.ToLower() )
                {
                    ReturnResult.Problem = "Label text is already in use.";
                    return ReturnResult;
                }
            }

            var ScriptArea = default(clsScriptArea);

            foreach ( var tempLoopVar_ScriptArea in ScriptAreas )
            {
                ScriptArea = tempLoopVar_ScriptArea;
                if ( LCaseText == ScriptArea.Label.ToLower() )
                {
                    ReturnResult.Problem = "Label text is already in use.";
                    return ReturnResult;
                }
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Exemple #16
0
        protected sResult read_WZ_map(BinaryReader File)
        {
            var returnResult = new sResult();
            returnResult.Success = false;
            returnResult.Problem = "";

            string strTemp = null;
            UInt32 version = 0;
            UInt32 mapWidth = 0;
            UInt32 mapHeight = 0;
            UInt32 uintTemp = 0;
            byte flip = 0;
            var flipX = default(bool);
            var flipZ = default(bool);
            byte rotate = 0;
            byte textureNum = 0;
            var a = 0;
            var x = 0;
            var y = 0;
            var posA = new XYInt();
            var posB = new XYInt();

            try
            {
                strTemp = IOUtil.ReadOldTextOfLength(File, 4);
                if ( strTemp != "map " )
                {
                    returnResult.Problem = "Unknown game.map identifier.";
                    return returnResult;
                }

                version = File.ReadUInt32();
                if ( version != 10U )
                {
                    if ( MessageBox.Show("game.map version is unknown. Continue?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK )
                    {
                        returnResult.Problem = "Aborted.";
                        return returnResult;
                    }
                }
                mapWidth = File.ReadUInt32();
                mapHeight = File.ReadUInt32();
                if ( mapWidth < 1U || mapWidth > Constants.MapMaxSize || mapHeight < 1U || mapHeight > Constants.MapMaxSize )
                {
                    returnResult.Problem = "Map size out of range.";
                    return returnResult;
                }

                map.TerrainBlank(new XYInt(Convert.ToInt32(mapWidth), Convert.ToInt32(mapHeight)));

                for ( y = 0; y <= map.Terrain.TileSize.Y - 1; y++ )
                {
                    for ( x = 0; x <= map.Terrain.TileSize.X - 1; x++ )
                    {
                        textureNum = File.ReadByte();
                        map.Terrain.Tiles[x, y].Texture.TextureNum = textureNum;
                        flip = File.ReadByte();
                        map.Terrain.Vertices[x, y].Height = File.ReadByte();
                        //get flipx
                        a = (int)((flip / 128.0D));
                        flip -= (byte)(a * 128);
                        flipX = a == 1;
                        //get flipy
                        a = (int)((flip / 64.0D));
                        flip -= (byte)(a * 64);
                        flipZ = a == 1;
                        //get rotation
                        a = (int)((flip / 16.0D));
                        flip -= (byte)(a * 16);
                        rotate = (byte)a;
                        TileUtil.OldOrientation_To_TileOrientation(rotate, flipX, flipZ, ref map.Terrain.Tiles[x, y].Texture.Orientation);
                        //get tri direction
                        a = (int)((flip / 8.0D));
                        flip -= (byte)(a * 8);
                        map.Terrain.Tiles[x, y].Tri = a == 1;
                    }
                }

                if ( version != 2U )
                {
                    uintTemp = File.ReadUInt32();
                    if ( uintTemp != 1 )
                    {
                        returnResult.Problem = "Bad gateway version number.";
                        return returnResult;
                    }

                    uintTemp = File.ReadUInt32();

                    for ( a = 0; a <= (Convert.ToInt32(uintTemp)) - 1; a++ )
                    {
                        posA.X = File.ReadByte();
                        posA.Y = File.ReadByte();
                        posB.X = File.ReadByte();
                        posB.Y = File.ReadByte();
                        if ( map.GatewayCreate(posA, posB) == null )
                        {
                            returnResult.Problem = "Gateway placement error.";
                            return returnResult;
                        }
                    }
                }
            }
            catch ( Exception ex )
            {
                returnResult.Problem = ex.Message;
                logger.ErrorException("Got an exception", ex);
                return returnResult;
            }

            returnResult.Success = true;
            return returnResult;
        }
Exemple #17
0
        public sResult Load_Image(string Path)
        {
            var ReturnResult = new sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            Bitmap HeightmapBitmap = null;
            var Result = new sResult();

            Result = BitmapUtil.LoadBitmap(Path, ref HeightmapBitmap);
            if ( !Result.Success )
            {
                ReturnResult.Problem = Result.Problem;
                return ReturnResult;
            }

            Blank(HeightmapBitmap.Height, HeightmapBitmap.Width);
            var X = 0;
            var Y = 0;
            for ( Y = 0; Y <= HeightmapBitmap.Height - 1; Y++ )
            {
                for ( X = 0; X <= HeightmapBitmap.Width - 1; X++ )
                {
                    var with_1 = HeightmapBitmap.GetPixel(X, Y);
                    HeightData.Height[Y, X] = Convert.ToInt32(((with_1.R) + with_1.G + with_1.B) / (3.0D * HeightScale));
                }
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Exemple #18
0
        protected sResult read_WZ_Structures(BinaryReader File, List<WZBJOUnit> WZUnits)
        {
            var returnResult = new sResult();
            returnResult.Success = false;
            returnResult.Problem = "";

            string strTemp = null;
            UInt32 version = 0;
            UInt32 uintTemp = 0;
            var a = 0;
            var wzBJOUnit = default(WZBJOUnit);

            try
            {
                strTemp = IOUtil.ReadOldTextOfLength(File, 4);
                if ( strTemp != "stru" )
                {
                    returnResult.Problem = "Unknown struct.bjo identifier.";
                    return returnResult;
                }

                version = File.ReadUInt32();
                if ( version != 8U )
                {
                    if ( MessageBox.Show("struct.bjo version is unknown. Continue?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK )
                    {
                        returnResult.Problem = "Aborted.";
                        return returnResult;
                    }
                }

                uintTemp = File.ReadUInt32();
                for ( a = 0; a <= (Convert.ToInt32(uintTemp)) - 1; a++ )
                {
                    wzBJOUnit = new WZBJOUnit();
                    wzBJOUnit.ObjectType = UnitType.PlayerStructure;
                    wzBJOUnit.Code = IOUtil.ReadOldTextOfLength(File, 40);
                    wzBJOUnit.Code = wzBJOUnit.Code.Substring(0, wzBJOUnit.Code.IndexOf('\0'));
                    wzBJOUnit.ID = File.ReadUInt32();
                    wzBJOUnit.Pos.Horizontal.X = (int)(File.ReadUInt32());
                    wzBJOUnit.Pos.Horizontal.Y = (int)(File.ReadUInt32());
                    wzBJOUnit.Pos.Altitude = (int)(File.ReadUInt32());
                    wzBJOUnit.Rotation = File.ReadUInt32();
                    wzBJOUnit.Player = File.ReadUInt32();
                    File.ReadBytes(56);
                    WZUnits.Add(wzBJOUnit);
                }
            }
            catch ( Exception ex )
            {
                returnResult.Problem = ex.Message;
                logger.ErrorException("Got an exception", ex);
                return returnResult;
            }

            returnResult.Success = true;
            return returnResult;
        }
Exemple #19
0
        public sResult LoadTileType(string path)
        {
            var returnResult = new sResult();
            BinaryReader file;

            try
            {
                file = new BinaryReader(new FileStream(path, FileMode.Open));
            }
            catch ( Exception ex )
            {
                returnResult.Problem = ex.Message;
                return returnResult;
            }
            returnResult = ReadTileType(file);
            file.Close();
            return returnResult;
        }
Exemple #20
0
        protected sResult read_WZ_TileTypes(BinaryReader File)
        {
            var ReturnResult = new sResult();
            ReturnResult.Success = false;
            ReturnResult.Problem = "";

            string strTemp = null;
            UInt32 Version = 0;
            UInt32 uintTemp = 0;
            UInt16 ushortTemp = 0;
            var A = 0;

            try
            {
                strTemp = IOUtil.ReadOldTextOfLength(File, 4);
                if ( strTemp != "ttyp" )
                {
                    ReturnResult.Problem = "Unknown ttypes.ttp identifier.";
                    return ReturnResult;
                }

                Version = File.ReadUInt32();
                if ( Version != 8U )
                {
                    //Load_WZ.Problem = "Unknown ttypes.ttp version."
                    //Exit Function
                    if ( MessageBox.Show("ttypes.ttp version is unknown. Continue?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK )
                    {
                        ReturnResult.Problem = "Aborted.";
                        return ReturnResult;
                    }
                }

                uintTemp = File.ReadUInt32();

                if ( map.Tileset != null )
                {
                    for ( A = 0; A <= Math.Min(Convert.ToInt32(uintTemp), map.Tileset.TileCount) - 1; A++ )
                    {
                        ushortTemp = File.ReadUInt16();
                        if ( ushortTemp > 11U )
                        {
                            ReturnResult.Problem = "Unknown tile type.";
                            return ReturnResult;
                        }
                        map.Tile_TypeNum[A] = (byte)ushortTemp;
                    }
                }
            }
            catch ( Exception ex )
            {
                ReturnResult.Problem = ex.Message;
                logger.ErrorException("Got an exception", ex);
                return ReturnResult;
            }

            ReturnResult.Success = true;
            return ReturnResult;
        }
Exemple #21
0
        public clsResult GenerateMipMaps(string SlashPath, string strTile, BitmapGLTexture BitmapTextureArgs, int TileNum)
        {
            var ReturnResult = new clsResult("Generating mipmaps", false);
            logger.Info("Generating mipmaps");
            var GraphicPath = "";
            var PixX = 0;
            var PixY = 0;
            var PixelColorA = new Color();
            var PixelColorB = new Color();
            var PixelColorC = new Color();
            var PixelColorD = new Color();
            var X1 = 0;
            var Y1 = 0;
            var X2 = 0;
            var Y2 = 0;
            var Red = 0;
            var Green = 0;
            var Blue = 0;
            var Bitmap8 = default(Bitmap);
            var Bitmap4 = default(Bitmap);
            var Bitmap2 = default(Bitmap);
            var Bitmap1 = default(Bitmap);
            Bitmap Bitmap = null;
            var Result = new sResult();

            //-------- 64 --------

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

            Result = BitmapUtil.LoadBitmap(GraphicPath, ref Bitmap);
            if ( !Result.Success )
            {
                ReturnResult.WarningAdd("Unable to load tile graphic: " + Result.Problem);
                return ReturnResult;
            }

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

            BitmapTextureArgs.Texture = Bitmap;
            BitmapTextureArgs.MipMapLevel = 1;
            BitmapTextureArgs.Perform();

            //-------- 32 --------

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

            Result = BitmapUtil.LoadBitmap(GraphicPath, ref Bitmap);
            if ( !Result.Success )
            {
                ReturnResult.WarningAdd("Unable to load tile graphic: " + Result.Problem);
                return ReturnResult;
            }

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

            BitmapTextureArgs.Texture = Bitmap;
            BitmapTextureArgs.MipMapLevel = 2;
            BitmapTextureArgs.Perform();

            //-------- 16 --------

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

            Result = BitmapUtil.LoadBitmap(GraphicPath, ref Bitmap);
            if ( !Result.Success )
            {
                ReturnResult.WarningAdd("Unable to load tile graphic: " + Result.Problem);
                return ReturnResult;
            }

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

            BitmapTextureArgs.Texture = Bitmap;
            BitmapTextureArgs.MipMapLevel = 3;
            BitmapTextureArgs.Perform();

            //-------- 8 --------

            Bitmap8 = new Bitmap(8, 8, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            for ( PixY = 0; PixY <= 7; PixY++ )
            {
                Y1 = PixY * 2;
                Y2 = Y1 + 1;
                for ( PixX = 0; PixX <= 7; PixX++ )
                {
                    X1 = PixX * 2;
                    X2 = X1 + 1;
                    PixelColorA = Bitmap.GetPixel(X1, Y1);
                    PixelColorB = Bitmap.GetPixel(X2, Y1);
                    PixelColorC = Bitmap.GetPixel(X1, Y2);
                    PixelColorD = Bitmap.GetPixel(X2, Y2);
                    Red = Convert.ToInt32(((PixelColorA.R) + PixelColorB.R + PixelColorC.R + PixelColorD.R) / 4.0F);
                    Green = Convert.ToInt32(((PixelColorA.G) + PixelColorB.G + PixelColorC.G + PixelColorD.G) / 4.0F);
                    Blue = Convert.ToInt32(((PixelColorA.B) + PixelColorB.B + PixelColorC.B + PixelColorD.B) / 4.0F);
                    Bitmap8.SetPixel(PixX, PixY, ColorTranslator.FromOle(ColorUtil.OSRGB(Red, Green, Blue)));
                }
            }

            BitmapTextureArgs.Texture = Bitmap8;
            BitmapTextureArgs.MipMapLevel = 4;
            BitmapTextureArgs.Perform();

            //-------- 4 --------

            Bitmap = Bitmap8;
            Bitmap4 = new Bitmap(4, 4, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            for ( PixY = 0; PixY <= 3; PixY++ )
            {
                Y1 = PixY * 2;
                Y2 = Y1 + 1;
                for ( PixX = 0; PixX <= 3; PixX++ )
                {
                    X1 = PixX * 2;
                    X2 = X1 + 1;
                    PixelColorA = Bitmap.GetPixel(X1, Y1);
                    PixelColorB = Bitmap.GetPixel(X2, Y1);
                    PixelColorC = Bitmap.GetPixel(X1, Y2);
                    PixelColorD = Bitmap.GetPixel(X2, Y2);
                    Red = Convert.ToInt32(((PixelColorA.R) + PixelColorB.R + PixelColorC.R + PixelColorD.R) / 4.0F);
                    Green = Convert.ToInt32(((PixelColorA.G) + PixelColorB.G + PixelColorC.G + PixelColorD.G) / 4.0F);
                    Blue = Convert.ToInt32(((PixelColorA.B) + PixelColorB.B + PixelColorC.B + PixelColorD.B) / 4.0F);
                    Bitmap4.SetPixel(PixX, PixY, ColorTranslator.FromOle(ColorUtil.OSRGB(Red, Green, Blue)));
                }
            }

            BitmapTextureArgs.Texture = Bitmap4;
            BitmapTextureArgs.MipMapLevel = 5;
            BitmapTextureArgs.Perform();

            //-------- 2 --------

            Bitmap = Bitmap4;
            Bitmap2 = new Bitmap(2, 2, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            for ( PixY = 0; PixY <= 1; PixY++ )
            {
                Y1 = PixY * 2;
                Y2 = Y1 + 1;
                for ( PixX = 0; PixX <= 1; PixX++ )
                {
                    X1 = PixX * 2;
                    X2 = X1 + 1;
                    PixelColorA = Bitmap.GetPixel(X1, Y1);
                    PixelColorB = Bitmap.GetPixel(X2, Y1);
                    PixelColorC = Bitmap.GetPixel(X1, Y2);
                    PixelColorD = Bitmap.GetPixel(X2, Y2);
                    Red = Convert.ToInt32(((PixelColorA.R) + PixelColorB.R + PixelColorC.R + PixelColorD.R) / 4.0F);
                    Green = Convert.ToInt32(((PixelColorA.G) + PixelColorB.G + PixelColorC.G + PixelColorD.G) / 4.0F);
                    Blue = Convert.ToInt32(((PixelColorA.B) + PixelColorB.B + PixelColorC.B + PixelColorD.B) / 4.0F);
                    Bitmap2.SetPixel(PixX, PixY, ColorTranslator.FromOle(ColorUtil.OSRGB(Red, Green, Blue)));
                }
            }

            BitmapTextureArgs.Texture = Bitmap2;
            BitmapTextureArgs.MipMapLevel = 6;
            BitmapTextureArgs.Perform();

            //-------- 1 --------

            Bitmap = Bitmap2;
            Bitmap1 = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            PixX = 0;
            PixY = 0;
            Y1 = PixY * 2;
            Y2 = Y1 + 1;
            X1 = PixX * 2;
            X2 = X1 + 1;
            PixelColorA = Bitmap.GetPixel(X1, Y1);
            PixelColorB = Bitmap.GetPixel(X2, Y1);
            PixelColorC = Bitmap.GetPixel(X1, Y2);
            PixelColorD = Bitmap.GetPixel(X2, Y2);
            Red = Convert.ToInt32(((PixelColorA.R) + PixelColorB.R + PixelColorC.R + PixelColorD.R) / 4.0F);
            Green = Convert.ToInt32(((PixelColorA.G) + PixelColorB.G + PixelColorC.G + PixelColorD.G) / 4.0F);
            Blue = Convert.ToInt32(((PixelColorA.B) + PixelColorB.B + PixelColorC.B + PixelColorD.B) / 4.0F);
            Bitmap1.SetPixel(PixX, PixY, ColorTranslator.FromOle(ColorUtil.OSRGB(Red, Green, Blue)));

            BitmapTextureArgs.Texture = Bitmap1;
            BitmapTextureArgs.MipMapLevel = 7;
            BitmapTextureArgs.Perform();

            return ReturnResult;
        }
Exemple #22
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;
        }