Beispiel #1
0
        public clsResult Load_Game(string Path)
        {
            clsResult ReturnResult =
                new clsResult("Loading game file from " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote));
            App.sResult SubResult = new App.sResult();
            string Quote = ControlChars.Quote.ToString();

            Tileset = null;

            TileType_Reset();
            SetPainterToDefaults();

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

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

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

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

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

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

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

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

            IniFeatures INIFeatures = null;

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

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

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

            IniStructures INIStructures = null;

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

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

            IniDroids INIDroids = null;

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

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

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

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

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

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

            ZipInputStream ZipStream = new ZipInputStream(File);

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

                SplitPath = new ZipSplitPath(ZipEntry.Name);

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

            string MapLoadName = "";

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

            TileType_Reset();
            SetPainterToDefaults();

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

            ZipStreamEntry ZipSearchResult = default(ZipStreamEntry);

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

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

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

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

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

            IniFeatures INIFeatures = null;

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

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

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

            IniStructures INIStructures = null;

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

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

            IniDroids INIDroids = null;

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

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

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

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

            return ReturnResult;
        }
Beispiel #3
0
        public clsResult CreateWZObjects(sCreateWZObjectsArgs Args)
        {
            clsResult ReturnResult = new clsResult("Creating objects");
            clsUnit NewUnit = default(clsUnit);
            UInt32 AvailableID = 0;
            SimpleClassList<clsWZBJOUnit> BJOUnits = Args.BJOUnits;
            IniStructures INIStructures = Args.INIStructures;
            IniDroids INIDroids = Args.INIDroids;
            IniFeatures INIFeatures = Args.INIFeatures;
            clsUnitAdd UnitAdd = new clsUnitAdd();
            int A = 0;
            int B = 0;
            clsWZBJOUnit BJOUnit = default(clsWZBJOUnit);

            UnitAdd.Map = this;

            AvailableID = 1U;
            foreach ( clsWZBJOUnit tempLoopVar_BJOUnit in BJOUnits )
            {
                BJOUnit = tempLoopVar_BJOUnit;
                if ( BJOUnit.ID >= AvailableID )
                {
                    AvailableID = BJOUnit.ID + 1U;
                }
            }
            if ( INIStructures != null )
            {
                for ( A = 0; A <= INIStructures.StructureCount - 1; A++ )
                {
                    if ( INIStructures.Structures[A].ID >= AvailableID )
                    {
                        AvailableID = INIStructures.Structures[A].ID + 1U;
                    }
                }
            }
            if ( INIFeatures != null )
            {
                for ( A = 0; A <= INIFeatures.FeatureCount - 1; A++ )
                {
                    if ( INIFeatures.Features[A].ID >= AvailableID )
                    {
                        AvailableID = INIFeatures.Features[A].ID + 1U;
                    }
                }
            }
            if ( INIDroids != null )
            {
                for ( A = 0; A <= INIDroids.DroidCount - 1; A++ )
                {
                    if ( INIDroids.Droids[A].ID >= AvailableID )
                    {
                        AvailableID = INIDroids.Droids[A].ID + 1U;
                    }
                }
            }

            foreach ( clsWZBJOUnit tempLoopVar_BJOUnit in BJOUnits )
            {
                BJOUnit = tempLoopVar_BJOUnit;
                NewUnit = new clsUnit();
                NewUnit.ID = BJOUnit.ID;
                NewUnit.Type = App.ObjectData.FindOrCreateUnitType(BJOUnit.Code, BJOUnit.ObjectType, -1);
                if ( NewUnit.Type == null )
                {
                    ReturnResult.ProblemAdd("Unable to create object type.");
                    return ReturnResult;
                }
                if ( BJOUnit.Player >= Constants.PlayerCountMax )
                {
                    NewUnit.UnitGroup = ScavengerUnitGroup;
                }
                else
                {
                    NewUnit.UnitGroup = UnitGroups[Convert.ToInt32(BJOUnit.Player)];
                }
                NewUnit.Pos = BJOUnit.Pos;
                NewUnit.Rotation = (int)(Math.Min(BJOUnit.Rotation, 359U));
                if ( BJOUnit.ID == 0U )
                {
                    BJOUnit.ID = AvailableID;
                    App.ZeroIDWarning(NewUnit, BJOUnit.ID, ReturnResult);
                }
                UnitAdd.NewUnit = NewUnit;
                UnitAdd.ID = BJOUnit.ID;
                UnitAdd.Perform();
                App.ErrorIDChange(BJOUnit.ID, NewUnit, "CreateWZObjects");
                if ( AvailableID == BJOUnit.ID )
                {
                    AvailableID = NewUnit.ID + 1U;
                }
            }

            clsStructureType StructureType = default(clsStructureType);
            clsDroidDesign DroidType = default(clsDroidDesign);
            clsFeatureType FeatureType = default(clsFeatureType);
            clsDroidDesign.sLoadPartsArgs LoadPartsArgs = new clsDroidDesign.sLoadPartsArgs();
            clsUnitType UnitType = null;
            int ErrorCount = 0;
            int UnknownDroidComponentCount = 0;
            int UnknownDroidTypeCount = 0;
            int DroidBadPositionCount = 0;
            int StructureBadPositionCount = 0;
            int StructureBadModulesCount = 0;
            int FeatureBadPositionCount = 0;
            int ModuleLimit = 0;
            sXY_int ZeroPos = new sXY_int(0, 0);
            clsStructureType ModuleType = default(clsStructureType);
            clsUnit NewModule = default(clsUnit);

            clsStructureType FactoryModule = App.ObjectData.FindFirstStructureType(clsStructureType.enumStructureType.FactoryModule);
            clsStructureType ResearchModule = App.ObjectData.FindFirstStructureType(clsStructureType.enumStructureType.ResearchModule);
            clsStructureType PowerModule = App.ObjectData.FindFirstStructureType(clsStructureType.enumStructureType.PowerModule);

            if ( FactoryModule == null )
            {
                ReturnResult.WarningAdd("No factory module loaded.");
            }
            if ( ResearchModule == null )
            {
                ReturnResult.WarningAdd("No research module loaded.");
            }
            if ( PowerModule == null )
            {
                ReturnResult.WarningAdd("No power module loaded.");
            }

            if ( INIStructures != null )
            {
                for ( A = 0; A <= INIStructures.StructureCount - 1; A++ )
                {
                    if ( INIStructures.Structures[A].Pos == null )
                    {
                        StructureBadPositionCount++;
                    }
                    else if ( !App.PosIsWithinTileArea(INIStructures.Structures[A].Pos.WorldPos.Horizontal, ZeroPos, Terrain.TileSize) )
                    {
                        StructureBadPositionCount++;
                    }
                    else
                    {
                        UnitType = App.ObjectData.FindOrCreateUnitType(Convert.ToString(INIStructures.Structures[A].Code),
                            clsUnitType.enumType.PlayerStructure, INIStructures.Structures[A].WallType);
                        if ( UnitType.Type == clsUnitType.enumType.PlayerStructure )
                        {
                            StructureType = (clsStructureType)UnitType;
                        }
                        else
                        {
                            StructureType = null;
                        }
                        if ( StructureType == null )
                        {
                            ErrorCount++;
                        }
                        else
                        {
                            NewUnit = new clsUnit();
                            NewUnit.Type = StructureType;
                            if ( INIStructures.Structures[A].UnitGroup == null )
                            {
                                NewUnit.UnitGroup = ScavengerUnitGroup;
                            }
                            else
                            {
                                NewUnit.UnitGroup = INIStructures.Structures[A].UnitGroup;
                            }
                            NewUnit.Pos = INIStructures.Structures[A].Pos.WorldPos;
                            NewUnit.Rotation = Convert.ToInt32(INIStructures.Structures[A].Rotation.Direction * 360.0D / App.INIRotationMax);
                            if ( NewUnit.Rotation == 360 )
                            {
                                NewUnit.Rotation = 0;
                            }
                            if ( INIStructures.Structures[A].HealthPercent >= 0 )
                            {
                                NewUnit.Health = MathUtil.Clamp_dbl(INIStructures.Structures[A].HealthPercent / 100.0D, 0.01D, 1.0D);
                            }
                            if ( INIStructures.Structures[A].ID == 0U )
                            {
                                INIStructures.Structures[A].ID = AvailableID;
                                App.ZeroIDWarning(NewUnit, INIStructures.Structures[A].ID, ReturnResult);
                            }
                            UnitAdd.NewUnit = NewUnit;
                            UnitAdd.ID = INIStructures.Structures[A].ID;
                            UnitAdd.Perform();
                            App.ErrorIDChange(INIStructures.Structures[A].ID, NewUnit, "Load_WZ->INIStructures");
                            if ( AvailableID == INIStructures.Structures[A].ID )
                            {
                                AvailableID = NewUnit.ID + 1U;
                            }
                            //create modules
                            switch ( StructureType.StructureType )
                            {
                                case clsStructureType.enumStructureType.Factory:
                                    ModuleLimit = 2;
                                    ModuleType = FactoryModule;
                                    break;
                                case clsStructureType.enumStructureType.VTOLFactory:
                                    ModuleLimit = 2;
                                    ModuleType = FactoryModule;
                                    break;
                                case clsStructureType.enumStructureType.PowerGenerator:
                                    ModuleLimit = 1;
                                    ModuleType = PowerModule;
                                    break;
                                case clsStructureType.enumStructureType.Research:
                                    ModuleLimit = 1;
                                    ModuleType = ResearchModule;
                                    break;
                                default:
                                    ModuleLimit = 0;
                                    ModuleType = null;
                                    break;
                            }
                            if ( INIStructures.Structures[A].ModuleCount > ModuleLimit )
                            {
                                INIStructures.Structures[A].ModuleCount = ModuleLimit;
                                StructureBadModulesCount++;
                            }
                            else if ( INIStructures.Structures[A].ModuleCount < 0 )
                            {
                                INIStructures.Structures[A].ModuleCount = 0;
                                StructureBadModulesCount++;
                            }
                            if ( ModuleType != null )
                            {
                                for ( B = 0; B <= INIStructures.Structures[A].ModuleCount - 1; B++ )
                                {
                                    NewModule = new clsUnit();
                                    NewModule.Type = ModuleType;
                                    NewModule.UnitGroup = NewUnit.UnitGroup;
                                    NewModule.Pos = NewUnit.Pos;
                                    NewModule.Rotation = NewUnit.Rotation;
                                    UnitAdd.NewUnit = NewModule;
                                    UnitAdd.ID = AvailableID;
                                    UnitAdd.Perform();
                                    AvailableID = NewModule.ID + 1U;
                                }
                            }
                        }
                    }
                }
                if ( StructureBadPositionCount > 0 )
                {
                    ReturnResult.WarningAdd(StructureBadPositionCount + " structures had an invalid position and were removed.");
                }
                if ( StructureBadModulesCount > 0 )
                {
                    ReturnResult.WarningAdd(StructureBadModulesCount + " structures had an invalid number of modules.");
                }
            }
            if ( INIFeatures != null )
            {
                for ( A = 0; A <= INIFeatures.FeatureCount - 1; A++ )
                {
                    if ( INIFeatures.Features[A].Pos == null )
                    {
                        FeatureBadPositionCount++;
                    }
                    else if ( !App.PosIsWithinTileArea(INIFeatures.Features[A].Pos.WorldPos.Horizontal, ZeroPos, Terrain.TileSize) )
                    {
                        FeatureBadPositionCount++;
                    }
                    else
                    {
                        UnitType = App.ObjectData.FindOrCreateUnitType(Convert.ToString(INIFeatures.Features[A].Code), clsUnitType.enumType.Feature, -1);
                        if ( UnitType.Type == clsUnitType.enumType.Feature )
                        {
                            FeatureType = (clsFeatureType)UnitType;
                        }
                        else
                        {
                            FeatureType = null;
                        }
                        if ( FeatureType == null )
                        {
                            ErrorCount++;
                        }
                        else
                        {
                            NewUnit = new clsUnit();
                            NewUnit.Type = FeatureType;
                            NewUnit.UnitGroup = ScavengerUnitGroup;
                            NewUnit.Pos = INIFeatures.Features[A].Pos.WorldPos;
                            NewUnit.Rotation = Convert.ToInt32(INIFeatures.Features[A].Rotation.Direction * 360.0D / App.INIRotationMax);
                            if ( NewUnit.Rotation == 360 )
                            {
                                NewUnit.Rotation = 0;
                            }
                            if ( INIFeatures.Features[A].HealthPercent >= 0 )
                            {
                                NewUnit.Health = MathUtil.Clamp_dbl(INIFeatures.Features[A].HealthPercent / 100.0D, 0.01D, 1.0D);
                            }
                            if ( INIFeatures.Features[A].ID == 0U )
                            {
                                INIFeatures.Features[A].ID = AvailableID;
                                App.ZeroIDWarning(NewUnit, INIFeatures.Features[A].ID, ReturnResult);
                            }
                            UnitAdd.NewUnit = NewUnit;
                            UnitAdd.ID = INIFeatures.Features[A].ID;
                            UnitAdd.Perform();
                            App.ErrorIDChange(INIFeatures.Features[A].ID, NewUnit, "Load_WZ->INIFeatures");
                            if ( AvailableID == INIFeatures.Features[A].ID )
                            {
                                AvailableID = NewUnit.ID + 1U;
                            }
                        }
                    }
                }
                if ( FeatureBadPositionCount > 0 )
                {
                    ReturnResult.WarningAdd(FeatureBadPositionCount + " features had an invalid position and were removed.");
                }
            }
            if ( INIDroids != null )
            {
                for ( A = 0; A <= INIDroids.DroidCount - 1; A++ )
                {
                    if ( INIDroids.Droids[A].Pos == null )
                    {
                        DroidBadPositionCount++;
                    }
                    else if ( !App.PosIsWithinTileArea(INIDroids.Droids[A].Pos.WorldPos.Horizontal, ZeroPos, Terrain.TileSize) )
                    {
                        DroidBadPositionCount++;
                    }
                    else
                    {
                        if ( INIDroids.Droids[A].Template == null || INIDroids.Droids[A].Template == "" )
                        {
                            DroidType = new clsDroidDesign();
                            if ( !DroidType.SetDroidType((App.enumDroidType)(INIDroids.Droids[A].DroidType)) )
                            {
                                UnknownDroidTypeCount++;
                            }
                            LoadPartsArgs.Body = App.ObjectData.FindOrCreateBody(INIDroids.Droids[A].Body);
                            if ( LoadPartsArgs.Body == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Body.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Propulsion = App.ObjectData.FindOrCreatePropulsion(Convert.ToString(INIDroids.Droids[A].Propulsion));
                            if ( LoadPartsArgs.Propulsion == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Propulsion.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Construct = App.ObjectData.FindOrCreateConstruct(Convert.ToString(INIDroids.Droids[A].Construct));
                            if ( LoadPartsArgs.Construct == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Construct.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Repair = App.ObjectData.FindOrCreateRepair(INIDroids.Droids[A].Repair);
                            if ( LoadPartsArgs.Repair == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Repair.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Sensor = App.ObjectData.FindOrCreateSensor(INIDroids.Droids[A].Sensor);
                            if ( LoadPartsArgs.Sensor == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Sensor.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Brain = App.ObjectData.FindOrCreateBrain(INIDroids.Droids[A].Brain);
                            if ( LoadPartsArgs.Brain == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Brain.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.ECM = App.ObjectData.FindOrCreateECM(Convert.ToString(INIDroids.Droids[A].ECM));
                            if ( LoadPartsArgs.ECM == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.ECM.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Weapon1 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(INIDroids.Droids[A].Weapons[0]));
                            if ( LoadPartsArgs.Weapon1 == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Weapon1.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Weapon2 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(INIDroids.Droids[A].Weapons[1]));
                            if ( LoadPartsArgs.Weapon2 == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Weapon2.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            LoadPartsArgs.Weapon3 = App.ObjectData.FindOrCreateWeapon(Convert.ToString(INIDroids.Droids[A].Weapons[2]));
                            if ( LoadPartsArgs.Weapon3 == null )
                            {
                                UnknownDroidComponentCount++;
                            }
                            else
                            {
                                if ( LoadPartsArgs.Weapon3.IsUnknown )
                                {
                                    UnknownDroidComponentCount++;
                                }
                            }
                            DroidType.LoadParts(LoadPartsArgs);
                        }
                        else
                        {
                            UnitType = App.ObjectData.FindOrCreateUnitType(INIDroids.Droids[A].Template, clsUnitType.enumType.PlayerDroid, -1);
                            if ( UnitType == null )
                            {
                                DroidType = null;
                            }
                            else
                            {
                                if ( UnitType.Type == clsUnitType.enumType.PlayerDroid )
                                {
                                    DroidType = (clsDroidDesign)UnitType;
                                }
                                else
                                {
                                    DroidType = null;
                                }
                            }
                        }
                        if ( DroidType == null )
                        {
                            ErrorCount++;
                        }
                        else
                        {
                            NewUnit = new clsUnit();
                            NewUnit.Type = DroidType;
                            if ( INIDroids.Droids[A].UnitGroup == null )
                            {
                                NewUnit.UnitGroup = ScavengerUnitGroup;
                            }
                            else
                            {
                                NewUnit.UnitGroup = INIDroids.Droids[A].UnitGroup;
                            }
                            NewUnit.Pos = INIDroids.Droids[A].Pos.WorldPos;
                            NewUnit.Rotation = Convert.ToInt32(INIDroids.Droids[A].Rotation.Direction * 360.0D / App.INIRotationMax);
                            if ( NewUnit.Rotation == 360 )
                            {
                                NewUnit.Rotation = 0;
                            }
                            if ( INIDroids.Droids[A].HealthPercent >= 0 )
                            {
                                NewUnit.Health = MathUtil.Clamp_dbl(INIDroids.Droids[A].HealthPercent / 100.0D, 0.01D, 1.0D);
                            }
                            if ( INIDroids.Droids[A].ID == 0U )
                            {
                                INIDroids.Droids[A].ID = AvailableID;
                                App.ZeroIDWarning(NewUnit, INIDroids.Droids[A].ID, ReturnResult);
                            }
                            UnitAdd.NewUnit = NewUnit;
                            UnitAdd.ID = INIDroids.Droids[A].ID;
                            UnitAdd.Perform();
                            App.ErrorIDChange(INIDroids.Droids[A].ID, NewUnit, "Load_WZ->INIDroids");
                            if ( AvailableID == INIDroids.Droids[A].ID )
                            {
                                AvailableID = NewUnit.ID + 1U;
                            }
                        }
                    }
                }
                if ( DroidBadPositionCount > 0 )
                {
                    ReturnResult.WarningAdd(DroidBadPositionCount + " droids had an invalid position and were removed.");
                }
                if ( UnknownDroidTypeCount > 0 )
                {
                    ReturnResult.WarningAdd(UnknownDroidTypeCount + " droid designs had an unrecognised droidType and were removed.");
                }
                if ( UnknownDroidComponentCount > 0 )
                {
                    ReturnResult.WarningAdd(UnknownDroidComponentCount + " droid designs had components that are not loaded.");
                }
            }

            if ( ErrorCount > 0 )
            {
                ReturnResult.WarningAdd("Object Create Error.");
            }

            return ReturnResult;
        }