示例#1
0
文件: Wz.cs 项目: pcdummy/SharpFlame
        private clsResult Serialize_WZ_StructuresINI(IniWriter File, int PlayerCount)
        {
            var ReturnResult = new clsResult("Serializing structures INI", false);
            logger.Info("Serializing structures INI");

            var structureTypeBase = default(StructureTypeBase);
            var unitModuleCount = new int[map.Units.Count];
            var sectorNum = new XYInt();
            var otherStructureTypeBase = default(StructureTypeBase);
            var otherUnit = default(clsUnit);
            var moduleMin = new XYInt();
            var moduleMax = new XYInt();
            var footprint = new XYInt();
            var A = 0;
            var underneathTypes = new StructureTypeBase.enumStructureType[2];
            var underneathTypeCount = 0;
            var badModuleCount = 0;
            var priorityOrder = new clsObjectPriorityOrderList();

            foreach ( var unit in map.Units.Where(d => d.TypeBase.Type == UnitType.PlayerStructure) )
            {
                structureTypeBase = (StructureTypeBase)unit.TypeBase;
                switch ( structureTypeBase.StructureType )
                {
                    case StructureTypeBase.enumStructureType.FactoryModule:
                        underneathTypes[0] = StructureTypeBase.enumStructureType.Factory;
                        underneathTypes[1] = StructureTypeBase.enumStructureType.VTOLFactory;
                        underneathTypeCount = 2;
                        break;
                    case StructureTypeBase.enumStructureType.PowerModule:
                        underneathTypes[0] = StructureTypeBase.enumStructureType.PowerGenerator;
                        underneathTypeCount = 1;
                        break;
                    case StructureTypeBase.enumStructureType.ResearchModule:
                        underneathTypes[0] = StructureTypeBase.enumStructureType.Research;
                        underneathTypeCount = 1;
                        break;
                    default:
                        underneathTypeCount = 0;
                        break;
                }

                if ( underneathTypeCount == 0 )
                {
                    priorityOrder.SetItem(unit);
                    priorityOrder.ActionPerform();
                }
                else
                {
                    // IS module.
                    sectorNum = map.GetPosSectorNum(unit.Pos.Horizontal);
                    clsUnit underneath = null;
                    var connection = default(clsUnitSectorConnection);
                    foreach ( var tempLoopVar_Connection in map.Sectors[sectorNum.X, sectorNum.Y].Units )
                    {
                        connection = tempLoopVar_Connection;
                        otherUnit = connection.Unit;
                        if ( otherUnit.TypeBase.Type == UnitType.PlayerStructure )
                        {
                            otherStructureTypeBase = (StructureTypeBase)otherUnit.TypeBase;
                            if ( otherUnit.UnitGroup == unit.UnitGroup )
                            {
                                for ( A = 0; A <= underneathTypeCount - 1; A++ )
                                {
                                    if ( otherStructureTypeBase.StructureType == underneathTypes[A] )
                                    {
                                        break;
                                    }
                                }
                                if ( A < underneathTypeCount )
                                {
                                    footprint = otherStructureTypeBase.get_GetFootprintSelected(otherUnit.Rotation);
                                    moduleMin.X = otherUnit.Pos.Horizontal.X - (int)(footprint.X * Constants.TerrainGridSpacing / 2.0D);
                                    moduleMin.Y = otherUnit.Pos.Horizontal.Y - (int)(footprint.Y * Constants.TerrainGridSpacing / 2.0D);
                                    moduleMax.X = otherUnit.Pos.Horizontal.X + (int)(footprint.X * Constants.TerrainGridSpacing / 2.0D);
                                    moduleMax.Y = otherUnit.Pos.Horizontal.Y + (int)(footprint.Y * Constants.TerrainGridSpacing / 2.0D);
                                    if ( unit.Pos.Horizontal.X >= moduleMin.X & unit.Pos.Horizontal.X < moduleMax.X &
                                         unit.Pos.Horizontal.Y >= moduleMin.Y & unit.Pos.Horizontal.Y < moduleMax.Y )
                                    {
                                        unitModuleCount[otherUnit.MapLink.ArrayPosition]++;
                                        underneath = otherUnit;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if ( underneath == null )
                    {
                        badModuleCount++;
                    }
                }
            }

            if ( badModuleCount > 0 )
            {
                ReturnResult.WarningAdd(string.Format("{0} modules had no underlying structure.", badModuleCount));
            }

            var tooManyModulesWarningCount = 0;
            var tooManyModulesWarningMaxCount = 16;
            var moduleCount = 0;
            var moduleLimit = 0;

            for ( A = 0; A <= priorityOrder.Result.Count - 1; A++ )
            {
                var unit = priorityOrder.Result[A];
                structureTypeBase = (StructureTypeBase)unit.TypeBase;
                if ( unit.ID <= 0 )
                {
                    ReturnResult.WarningAdd("Error. A structure\'s ID was zero. It was NOT saved. Delete and replace it to allow save.");
                }
                else
                {
                    File.AddSection("structure_" + unit.ID.ToStringInvariant());
                    File.AddProperty("id", unit.ID.ToStringInvariant());
                    if ( unit.UnitGroup == map.ScavengerUnitGroup || (PlayerCount >= 0 & unit.UnitGroup.WZ_StartPos >= PlayerCount) )
                    {
                        File.AddProperty("player", "scavenger");
                    }
                    else
                    {
                        File.AddProperty("startpos", unit.UnitGroup.WZ_StartPos.ToStringInvariant());
                    }
                    File.AddProperty("name", structureTypeBase.Code);
                    if ( structureTypeBase.WallLink.IsConnected )
                    {
                        File.AddProperty("wall/type", structureTypeBase.WallLink.ArrayPosition.ToStringInvariant());
                    }
                    File.AddProperty("position", unit.GetINIPosition());
                    File.AddProperty("rotation", unit.GetINIRotation());
                    if ( unit.Health < 1.0D )
                    {
                        File.AddProperty("health", unit.GetINIHealthPercent());
                    }
                    switch ( structureTypeBase.StructureType )
                    {
                        case StructureTypeBase.enumStructureType.Factory:
                            moduleLimit = 2;
                            break;
                        case StructureTypeBase.enumStructureType.VTOLFactory:
                            moduleLimit = 2;
                            break;
                        case StructureTypeBase.enumStructureType.PowerGenerator:
                            moduleLimit = 1;
                            break;
                        case StructureTypeBase.enumStructureType.Research:
                            moduleLimit = 1;
                            break;
                        default:
                            moduleLimit = 0;
                            break;
                    }
                    if ( unitModuleCount[unit.MapLink.ArrayPosition] > moduleLimit )
                    {
                        moduleCount = moduleLimit;
                        if ( tooManyModulesWarningCount < tooManyModulesWarningMaxCount )
                        {
                            ReturnResult.WarningAdd(string.Format("Structure {0} at {1} has too many modules ({2})",
                                structureTypeBase.GetDisplayTextCode(),
                                unit.GetPosText(),
                                unitModuleCount[unit.MapLink.ArrayPosition]));
                        }
                        tooManyModulesWarningCount++;
                    }
                    else
                    {
                        moduleCount = unitModuleCount[unit.MapLink.ArrayPosition];
                    }
                    File.AddProperty("modules", moduleCount.ToStringInvariant());
                }
            }

            if ( tooManyModulesWarningCount > tooManyModulesWarningMaxCount )
            {
                ReturnResult.WarningAdd(string.Format("{0} structures had too many modules.", tooManyModulesWarningCount));
            }

            return ReturnResult;
        }
示例#2
0
文件: Wz.cs 项目: pcdummy/SharpFlame
        public clsResult Save(sWrite_WZ_Args Args)
        {
            var returnResult =
                new clsResult("Compiling to \"{0}\"".Format2(Args.Path), false);
            logger.Info("Compiling to \"{0}\"".Format2(Args.Path));

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            return returnResult;
        }
示例#3
0
文件: Wz.cs 项目: pcdummy/SharpFlame
        private clsResult Serialize_WZ_FeaturesINI(IniWriter File)
        {
            var ReturnResult = new clsResult("Serializing features INI", false);
            logger.Info("Serializing features INI");
            var featureTypeBase = default(FeatureTypeBase);
            var Unit = default(clsUnit);
            var Valid = default(bool);

            foreach ( var tempLoopVar_Unit in map.Units )
            {
                Unit = tempLoopVar_Unit;
                if ( Unit.TypeBase.Type != UnitType.Feature )
                {
                    continue;
                }

                featureTypeBase = (FeatureTypeBase)Unit.TypeBase;
                Valid = true;
                if ( Unit.ID <= 0 )
                {
                    Valid = false;
                    ReturnResult.WarningAdd("Error. A features\'s ID was zero. It was NOT saved. Delete and replace it to allow save.");
                }
                if ( Valid )
                {
                    File.AddSection("feature_" + Unit.ID.ToStringInvariant());
                    File.AddProperty("id", Unit.ID.ToStringInvariant());
                    File.AddProperty("position", Unit.GetINIPosition());
                    File.AddProperty("rotation", Unit.GetINIRotation());
                    File.AddProperty("name", featureTypeBase.Code);
                    if ( Unit.Health < 1.0D )
                    {
                        File.AddProperty("health", Unit.GetINIHealthPercent());
                    }
                }
            }

            return ReturnResult;
        }
示例#4
0
文件: Wz.cs 项目: pcdummy/SharpFlame
        private clsResult Serialize_WZ_LabelsINI(IniWriter File, int PlayerCount)
        {
            var returnResult = new clsResult("Serializing labels INI", false);
            logger.Info("Serializing labels INI");

            try
            {
                var scriptPosition = default(clsScriptPosition);
                foreach ( var tempLoopVar_ScriptPosition in map.ScriptPositions )
                {
                    scriptPosition = tempLoopVar_ScriptPosition;
                    scriptPosition.WriteWZ(File);
                }
                var ScriptArea = default(clsScriptArea);
                foreach ( var tempLoopVar_ScriptArea in map.ScriptAreas )
                {
                    ScriptArea = tempLoopVar_ScriptArea;
                    ScriptArea.WriteWZ(File);
                }
                if ( PlayerCount >= 0 ) //not an FMap
                {
                    var Unit = default(clsUnit);
                    foreach ( var tempLoopVar_Unit in map.Units )
                    {
                        Unit = tempLoopVar_Unit;
                        Unit.WriteWZLabel(File, PlayerCount);
                    }
                }
            }
            catch ( Exception ex )
            {
                returnResult.WarningAdd(ex.Message);
                logger.ErrorException("Got an exception", ex);
            }

            return returnResult;
        }
示例#5
0
        public clsResult Save(string path, bool overwrite, bool compress)
        {
            var returnResult = new clsResult(string.Format("Writing FMap to \"{0}\"", path), false);
            logger.Info(string.Format("Writing FMap to \"{0}\"", path));

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            return returnResult;
        }
示例#6
0
文件: Wz.cs 项目: pcdummy/SharpFlame
        private clsResult Serialize_WZ_DroidsINI(IniWriter ini, int playerCount)
        {
            var returnResult = new clsResult("Serializing droids INI", false);
            logger.Info("Serializing droids INI");

            var droid = default(DroidDesign);
            var template = default(DroidTemplate);
            var text = "";
            var unit = default(clsUnit);
            var asPartsNotTemplate = default(bool);
            var validDroid = false;
            var invalidPartCount = 0;
            var brain = default(Brain);

            foreach ( var tempLoopVar_Unit in map.Units )
            {
                unit = tempLoopVar_Unit;
                if ( unit.TypeBase.Type == UnitType.PlayerDroid )
                {
                    droid = (DroidDesign)unit.TypeBase;
                    validDroid = true;
                    if ( unit.ID <= 0 )
                    {
                        validDroid = false;
                        returnResult.WarningAdd("Error. A droid\'s ID was zero. It was NOT saved. Delete and replace it to allow save.");
                    }
                    if ( droid.IsTemplate )
                    {
                        template = (DroidTemplate)droid;
                        asPartsNotTemplate = unit.PreferPartsOutput;
                    }
                    else
                    {
                        template = null;
                        asPartsNotTemplate = true;
                    }
                    if ( asPartsNotTemplate )
                    {
                        if ( droid.Body == null )
                        {
                            validDroid = false;
                            invalidPartCount++;
                        }
                        else if ( droid.Propulsion == null )
                        {
                            validDroid = false;
                            invalidPartCount++;
                        }
                        else if ( droid.TurretCount >= 1 )
                        {
                            if ( droid.Turret1 == null )
                            {
                                validDroid = false;
                                invalidPartCount++;
                            }
                        }
                        else if ( droid.TurretCount >= 2 )
                        {
                            if ( droid.Turret2 == null )
                            {
                                validDroid = false;
                                invalidPartCount++;
                            }
                            else if ( droid.Turret2.TurretType != enumTurretType.Weapon )
                            {
                                validDroid = false;
                                invalidPartCount++;
                            }
                        }
                        else if ( droid.TurretCount >= 3 && droid.Turret3 == null )
                        {
                            if ( droid.Turret3 == null )
                            {
                                validDroid = false;
                                invalidPartCount++;
                            }
                            else if ( droid.Turret3.TurretType != enumTurretType.Weapon )
                            {
                                validDroid = false;
                                invalidPartCount++;
                            }
                        }
                    }
                    if ( validDroid )
                    {
                        ini.AddSection("droid_" + unit.ID.ToStringInvariant());
                        ini.AddProperty("id", unit.ID.ToStringInvariant());
                        if ( unit.UnitGroup == map.ScavengerUnitGroup || (playerCount >= 0 & unit.UnitGroup.WZ_StartPos >= playerCount) )
                        {
                            ini.AddProperty("player", "scavenger");
                        }
                        else
                        {
                            ini.AddProperty("startpos", unit.UnitGroup.WZ_StartPos.ToStringInvariant());
                        }
                        if ( asPartsNotTemplate )
                        {
                            ini.AddProperty("name", droid.GenerateName());
                        }
                        else
                        {
                            template = (DroidTemplate)droid;
                            ini.AddProperty("template", template.Code);
                        }
                        ini.AddProperty("position", unit.GetINIPosition());
                        ini.AddProperty("rotation", unit.GetINIRotation());
                        if ( unit.Health < 1.0D )
                        {
                            ini.AddProperty("health", unit.GetINIHealthPercent());
                        }
                        if ( asPartsNotTemplate )
                        {
                            ini.AddProperty("droidType", Convert.ToInt32(droid.GetDroidType()).ToStringInvariant());
                            if ( droid.TurretCount == 0 )
                            {
                                text = "0";
                            }
                            else
                            {
                                if ( droid.Turret1.TurretType == enumTurretType.Brain )
                                {
                                    if ( ((Brain)droid.Turret1).Weapon == null )
                                    {
                                        text = "0";
                                    }
                                    else
                                    {
                                        text = "1";
                                    }
                                }
                                else
                                {
                                    if ( droid.Turret1.TurretType == enumTurretType.Weapon )
                                    {
                                        text = droid.TurretCount.ToStringInvariant();
                                    }
                                    else
                                    {
                                        text = "0";
                                    }
                                }
                            }
                            ini.AddProperty("weapons", text);
                            ini.AddProperty("parts\\body", droid.Body.Code);
                            ini.AddProperty("parts\\propulsion", droid.Propulsion.Code);
                            ini.AddProperty("parts\\sensor", droid.GetSensorCode());
                            ini.AddProperty("parts\\construct", droid.GetConstructCode());
                            ini.AddProperty("parts\\repair", droid.GetRepairCode());
                            ini.AddProperty("parts\\brain", droid.GetBrainCode());
                            ini.AddProperty("parts\\ecm", droid.GetECMCode());
                            if ( droid.TurretCount >= 1 )
                            {
                                if ( droid.Turret1.TurretType == enumTurretType.Weapon )
                                {
                                    ini.AddProperty("parts\\weapon\\1", droid.Turret1.Code);
                                    if ( droid.TurretCount >= 2 )
                                    {
                                        if ( droid.Turret2.TurretType == enumTurretType.Weapon )
                                        {
                                            ini.AddProperty("parts\\weapon\\2", droid.Turret2.Code);
                                            if ( droid.TurretCount >= 3 )
                                            {
                                                if ( droid.Turret3.TurretType == enumTurretType.Weapon )
                                                {
                                                    ini.AddProperty("parts\\weapon\\3", droid.Turret3.Code);
                                                }
                                            }
                                        }
                                    }
                                }
                                else if ( droid.Turret1.TurretType == enumTurretType.Brain )
                                {
                                    brain = (Brain)droid.Turret1;
                                    if ( brain.Weapon == null )
                                    {
                                        text = "ZNULLWEAPON";
                                    }
                                    else
                                    {
                                        text = brain.Weapon.Code;
                                    }
                                    ini.AddProperty("parts\\weapon\\1", text);
                                }
                            }
                        }
                    }
                }
            }

            if ( invalidPartCount > 0 )
            {
                returnResult.WarningAdd(string.Format("There were {0} droids with parts missing. They were not saved.", invalidPartCount));
            }

            return returnResult;
        }
示例#7
0
        private clsResult serialize_WZ_LabelsINI(IniWriter file)
        {
            var returnResult = new clsResult("Serializing labels INI", false);
            logger.Info("Serializing labels INI");

            try
            {
                foreach ( var scriptPosition in map.ScriptPositions )
                {
                    scriptPosition.WriteWZ(file);
                }
                foreach ( var scriptArea in map.ScriptAreas )
                {
                    scriptArea.WriteWZ(file);
                }
            }
            catch ( Exception ex )
            {
                returnResult.WarningAdd(ex.Message);
                logger.ErrorException("Got an exception", ex);
            }

            return returnResult;
        }
示例#8
0
        private clsResult serialize_FMap_Objects(IniWriter file)
        {
            var returnResult = new clsResult("Serializing objects", false);
            logger.Info("Serializing objects");

            var droid = default(DroidDesign);
            var warningCount = 0;
            string text = null;

            try
            {
                var a = 0;
                foreach (var unit in map.Units)
                {
                    file.AddSection(a.ToStringInvariant());
                    switch ( unit.TypeBase.Type )
                    {
                        case UnitType.Feature:
                            file.AddProperty("Type", "Feature, " + ((FeatureTypeBase)unit.TypeBase).Code);
                            break;
                        case UnitType.PlayerStructure:
                            var structureTypeBase = (StructureTypeBase)unit.TypeBase;
                            file.AddProperty("Type", "Structure, " + structureTypeBase.Code);
                            if ( structureTypeBase.WallLink.IsConnected )
                            {
                                file.AddProperty("WallType", structureTypeBase.WallLink.ArrayPosition.ToStringInvariant());
                            }
                            break;
                        case UnitType.PlayerDroid:
                            droid = (DroidDesign)unit.TypeBase;
                            if ( droid.IsTemplate )
                            {
                                file.AddProperty("Type", "DroidTemplate, " + ((DroidTemplate)unit.TypeBase).Code);
                            }
                            else
                            {
                                file.AddProperty("Type", "DroidDesign");
                                if ( droid.TemplateDroidType != null )
                                {
                                    file.AddProperty("DroidType", droid.TemplateDroidType.TemplateCode);
                                }
                                if ( droid.Body != null )
                                {
                                    file.AddProperty("Body", droid.Body.Code);
                                }
                                if ( droid.Propulsion != null )
                                {
                                    file.AddProperty("Propulsion", droid.Propulsion.Code);
                                }
                                file.AddProperty("TurretCount", droid.TurretCount.ToStringInvariant());
                                if ( droid.Turret1 != null )
                                {
                                    if ( droid.Turret1.GetTurretTypeName(ref text) )
                                    {
                                        file.AddProperty ("Turret1", string.Format ("{0}, {1}", text, droid.Turret1.Code));
                                    }
                                }
                                if ( droid.Turret2 != null )
                                {
                                    if ( droid.Turret2.GetTurretTypeName(ref text) )
                                    {
                                        file.AddProperty ("Turret2", string.Format ("{0}, {1}", text, droid.Turret2.Code));
                                    }
                                }
                                if ( droid.Turret3 != null )
                                {
                                    if ( droid.Turret3.GetTurretTypeName(ref text) )
                                    {
                                        file.AddProperty ("Turret3", string.Format ("{0}, {1}", text, droid.Turret3.Code));
                                    }
                                }
                            }
                            break;
                        default:
                            warningCount++;
                            break;
                    }
                    file.AddProperty("ID", unit.ID.ToStringInvariant());
                    file.AddProperty("Priority", unit.SavePriority.ToStringInvariant());
                    file.AddProperty("Pos", unit.Pos.Horizontal.X.ToStringInvariant() + ", " + unit.Pos.Horizontal.Y.ToStringInvariant());
                    file.AddProperty("Heading", unit.Rotation.ToStringInvariant());
                    file.AddProperty("UnitGroup", unit.UnitGroup.GetFMapINIPlayerText());
                    if ( unit.Health < 1.0D )
                    {
                        file.AddProperty("Health", unit.Health.ToStringInvariant());
                    }
                    if ( unit.Label != null )
                    {
                        file.AddProperty("ScriptLabel", unit.Label);
                    }

                    a++;
                }
            }
            catch ( Exception ex )
            {
                returnResult.ProblemAdd(ex.Message);
            }

            if ( warningCount > 0 )
            {
                returnResult.WarningAdd("Error: " + Convert.ToString(warningCount) + " units were of an unhandled type.");
            }

            return returnResult;
        }
示例#9
0
        private clsResult serialize_FMap_Info(IniWriter file)
        {
            var ReturnResult = new clsResult("Serializing general map info", false);
            logger.Info("Serializing general map info");

            try
            {
                if ( map.Tileset == null )
                {
                }
                else if ( map.Tileset == App.Tileset_Arizona )
                {
                    file.AddProperty("Tileset", "Arizona");
                }
                else if ( map.Tileset == App.Tileset_Urban )
                {
                    file.AddProperty("Tileset", "Urban");
                }
                else if ( map.Tileset == App.Tileset_Rockies )
                {
                    file.AddProperty("Tileset", "Rockies");
                }

                file.AddProperty("Size", map.Terrain.TileSize.X.ToStringInvariant() + ", " + map.Terrain.TileSize.Y.ToStringInvariant());

                file.AddProperty("AutoScrollLimits", map.InterfaceOptions.AutoScrollLimits.ToStringInvariant());
                file.AddProperty("ScrollMinX", map.InterfaceOptions.ScrollMin.X.ToStringInvariant());
                file.AddProperty("ScrollMinY", map.InterfaceOptions.ScrollMin.Y.ToStringInvariant());
                file.AddProperty("ScrollMaxX", map.InterfaceOptions.ScrollMax.X.ToStringInvariant());
                file.AddProperty("ScrollMaxY", map.InterfaceOptions.ScrollMax.Y.ToStringInvariant());

                file.AddProperty("Name", map.InterfaceOptions.CompileName);
                file.AddProperty("Players", map.InterfaceOptions.CompileMultiPlayers);
                file.AddProperty("Author", map.InterfaceOptions.CompileMultiAuthor);
                file.AddProperty("License", map.InterfaceOptions.CompileMultiLicense);
                if ( map.InterfaceOptions.CampaignGameType >= 0 )
                {
                    file.AddProperty("CampType", map.InterfaceOptions.CampaignGameType.ToStringInvariant());
                }
            }
            catch ( Exception ex )
            {
                ReturnResult.ProblemAdd(ex.Message);
            }

            return ReturnResult;
        }
示例#10
0
        private clsResult serialize_FMap_Gateways(IniWriter File)
        {
            var returnResult = new clsResult("Serializing gateways", false);
            logger.Info("Serializing gateways");

            try
            {
                var a = 0;
                foreach ( var gateway in map.Gateways)
                {
                    File.AddSection(a.ToStringInvariant());
                    File.AddProperty("AX", gateway.PosA.X.ToStringInvariant());
                    File.AddProperty("AY", gateway.PosA.Y.ToStringInvariant());
                    File.AddProperty("BX", gateway.PosB.X.ToStringInvariant());
                    File.AddProperty("BY", gateway.PosB.Y.ToStringInvariant());
                    a++;
                }
            }
            catch ( Exception ex )
            {
                returnResult.ProblemAdd(ex.Message);
            }

            return returnResult;
        }
示例#11
0
 public void WriteWZ(IniWriter file)
 {
     file.AddSection("area_" + _ParentMapLink.ArrayPosition.ToStringInvariant());
     file.AddProperty("pos1", _PosA.X.ToStringInvariant() + ", " + _PosA.Y.ToStringInvariant());
     file.AddProperty("pos2", _PosB.X.ToStringInvariant() + ", " + _PosB.Y.ToStringInvariant());
     file.AddProperty("label", Label);
 }