public static IniWriter CreateFile(Stream Output) { IniWriter NewINI = new IniWriter(); NewINI.File = new StreamWriter(Output, App.UTF8Encoding); return NewINI; }
public clsResult INIWrite(IniWriter file) { clsResult returnResult = new clsResult("Writing options to INI"); foreach ( OptionInterface item in _Options.Options ) { if ( get_Changes(item) == null ) { continue; } object optionValue = get_Value(item); string valueText = null; if ( item is Option<KeyboardControl> ) { KeyboardControl control = (KeyboardControl)optionValue; valueText = ""; for ( int i = 0; i <= control.Keys.GetUpperBound(0); i++ ) { Keys key = Keys.A; valueText += IOUtil.InvariantToString((Int32)key); if ( i < control.Keys.GetUpperBound(0) ) { valueText += ","; } } if ( control.UnlessKeys.GetUpperBound(0) >= 0 ) { valueText += "unless "; for ( int i = 0; i <= control.UnlessKeys.GetUpperBound(0); i++ ) { Keys key = Keys.A; valueText += IOUtil.InvariantToString((Int32)key); if ( i < control.UnlessKeys.GetUpperBound(0) ) { valueText += ","; } } } } else if ( item is Option<SimpleList<string>> ) { SimpleList<string> list = (SimpleList<string>)optionValue; for ( int i = 0; i <= list.Count - 1; i++ ) { file.AppendProperty(item.SaveKey, list[i]); } } else if ( item is Option<clsRGB_sng> ) { valueText = ((clsRGB_sng)optionValue).GetINIOutput(); } else if ( item is Option<clsRGBA_sng> ) { valueText = ((clsRGBA_sng)optionValue).GetINIOutput(); } else if ( item is Option<FontFamily> ) { valueText = ((FontFamily)optionValue).Name; } else if ( item is Option<bool> ) { valueText = IOUtil.InvariantToString(Convert.ToBoolean(optionValue)); } else if ( item is Option<byte> ) { valueText = IOUtil.InvariantToString(Convert.ToByte(optionValue)); } else if ( item is Option<short> ) { valueText = IOUtil.InvariantToString((int)(short)optionValue); } else if ( item is Option<int> ) { valueText = IOUtil.InvariantToString(Convert.ToInt32(optionValue)); } else if ( item is Option<UInt32> ) { valueText = IOUtil.InvariantToString(Convert.ToUInt32(optionValue)); } else if ( item is Option<Single> ) { valueText = IOUtil.InvariantToString(Convert.ToSingle(Convert.ToSingle(optionValue))); } else if ( item is Option<double> ) { valueText = IOUtil.InvariantToString(Convert.ToDouble(optionValue)); } else if ( item is Option<string> ) { valueText = Convert.ToString(optionValue); } else { returnResult.ProblemAdd("Value for option " + Convert.ToString(ControlChars.Quote) + item.SaveKey + Convert.ToString(ControlChars.Quote) + " could not be written because it is of type " + optionValue.GetType().FullName); } if ( valueText != null ) { file.AppendProperty(item.SaveKey, valueText); } } return returnResult; }
public clsResult Serialize_FMap_Objects(IniWriter File) { clsResult ReturnResult = new clsResult("Serializing objects"); int A = 0; clsUnit Unit = default(clsUnit); clsDroidDesign Droid = default(clsDroidDesign); int WarningCount = 0; string Text = null; try { for ( A = 0; A <= Units.Count - 1; A++ ) { Unit = Units[A]; File.AppendSectionName(IOUtil.InvariantToString(A)); switch ( Unit.Type.Type ) { case clsUnitType.enumType.Feature: File.AppendProperty("Type", "Feature, " + ((clsFeatureType)Unit.Type).Code); break; case clsUnitType.enumType.PlayerStructure: clsStructureType StructureType = (clsStructureType)Unit.Type; File.AppendProperty("Type", "Structure, " + StructureType.Code); if ( StructureType.WallLink.IsConnected ) { File.AppendProperty("WallType", IOUtil.InvariantToString(StructureType.WallLink.ArrayPosition)); } break; case clsUnitType.enumType.PlayerDroid: Droid = (clsDroidDesign)Unit.Type; if ( Droid.IsTemplate ) { File.AppendProperty("Type", "DroidTemplate, " + ((clsDroidTemplate)Unit.Type).Code); } else { File.AppendProperty("Type", "DroidDesign"); if ( Droid.TemplateDroidType != null ) { File.AppendProperty("DroidType", Droid.TemplateDroidType.TemplateCode); } if ( Droid.Body != null ) { File.AppendProperty("Body", Droid.Body.Code); } if ( Droid.Propulsion != null ) { File.AppendProperty("Propulsion", Droid.Propulsion.Code); } File.AppendProperty("TurretCount", IOUtil.InvariantToString(Droid.TurretCount)); if ( Droid.Turret1 != null ) { if ( Droid.Turret1.GetTurretTypeName(ref Text) ) { File.AppendProperty("Turret1", Text + ", " + Droid.Turret1.Code); } } if ( Droid.Turret2 != null ) { if ( Droid.Turret2.GetTurretTypeName(ref Text) ) { File.AppendProperty("Turret2", Text + ", " + Droid.Turret2.Code); } } if ( Droid.Turret3 != null ) { if ( Droid.Turret3.GetTurretTypeName(ref Text) ) { File.AppendProperty("Turret3", Text + ", " + Droid.Turret3.Code); } } } break; default: WarningCount++; break; } File.AppendProperty("ID", IOUtil.InvariantToString(Unit.ID)); File.AppendProperty("Priority", IOUtil.InvariantToString(Unit.SavePriority)); File.AppendProperty("Pos", IOUtil.InvariantToString(Unit.Pos.Horizontal.X) + ", " + IOUtil.InvariantToString(Unit.Pos.Horizontal.Y)); File.AppendProperty("Heading", IOUtil.InvariantToString(Unit.Rotation)); File.AppendProperty("UnitGroup", Unit.UnitGroup.GetFMapINIPlayerText()); if ( Unit.Health < 1.0D ) { File.AppendProperty("Health", IOUtil.InvariantToString(Unit.Health)); } if ( Unit.Label != null ) { File.AppendProperty("ScriptLabel", Unit.Label); } File.Gap_Append(); } } catch ( Exception ex ) { ReturnResult.ProblemAdd(ex.Message); } if ( WarningCount > 0 ) { ReturnResult.WarningAdd("Error: " + Convert.ToString(WarningCount) + " units were of an unhandled type."); } return ReturnResult; }
public void WriteWZ(IniWriter File) { File.AppendSectionName("position_" + IOUtil.InvariantToString(_ParentMapLink.ArrayPosition)); File.AppendProperty("pos", IOUtil.InvariantToString(_Pos.X) + ", " + IOUtil.InvariantToString(_Pos.Y)); File.AppendProperty("label", _Label); File.Gap_Append(); }
public clsResult Serialize_FMap_Gateways(IniWriter File) { clsResult ReturnResult = new clsResult("Serializing gateways"); int A = 0; clsGateway Gateway = default(clsGateway); try { for ( A = 0; A <= Gateways.Count - 1; A++ ) { Gateway = Gateways[A]; File.AppendSectionName(IOUtil.InvariantToString(A)); File.AppendProperty("AX", IOUtil.InvariantToString(Gateway.PosA.X)); File.AppendProperty("AY", IOUtil.InvariantToString(Gateway.PosA.Y)); File.AppendProperty("BX", IOUtil.InvariantToString(Gateway.PosB.X)); File.AppendProperty("BY", IOUtil.InvariantToString(Gateway.PosB.Y)); File.Gap_Append(); } } catch ( Exception ex ) { ReturnResult.ProblemAdd(ex.Message); } return ReturnResult; }
public clsResult Serialize_FMap_Info(IniWriter File) { clsResult ReturnResult = new clsResult("Serializing general map info"); try { if ( Tileset == null ) { } else if ( Tileset == App.Tileset_Arizona ) { File.AppendProperty("Tileset", "Arizona"); } else if ( Tileset == App.Tileset_Urban ) { File.AppendProperty("Tileset", "Urban"); } else if ( Tileset == App.Tileset_Rockies ) { File.AppendProperty("Tileset", "Rockies"); } File.AppendProperty("Size", IOUtil.InvariantToString(Terrain.TileSize.X) + ", " + IOUtil.InvariantToString(Terrain.TileSize.Y)); File.AppendProperty("AutoScrollLimits", IOUtil.InvariantToString(InterfaceOptions.AutoScrollLimits)); File.AppendProperty("ScrollMinX", IOUtil.InvariantToString(InterfaceOptions.ScrollMin.X)); File.AppendProperty("ScrollMinY", IOUtil.InvariantToString(InterfaceOptions.ScrollMin.Y)); File.AppendProperty("ScrollMaxX", IOUtil.InvariantToString(InterfaceOptions.ScrollMax.X)); File.AppendProperty("ScrollMaxY", IOUtil.InvariantToString(InterfaceOptions.ScrollMax.Y)); File.AppendProperty("Name", InterfaceOptions.CompileName); File.AppendProperty("Players", InterfaceOptions.CompileMultiPlayers); File.AppendProperty("XPlayerLev", IOUtil.InvariantToString(InterfaceOptions.CompileMultiXPlayers)); File.AppendProperty("Author", InterfaceOptions.CompileMultiAuthor); File.AppendProperty("License", InterfaceOptions.CompileMultiLicense); if ( InterfaceOptions.CampaignGameType >= 0 ) { File.AppendProperty("CampType", IOUtil.InvariantToString(InterfaceOptions.CampaignGameType)); } } catch ( Exception ex ) { ReturnResult.ProblemAdd(ex.Message); } return ReturnResult; }
public clsResult Write_FMap(string Path, bool Overwrite, bool Compress) { clsResult ReturnResult = new clsResult("Writing FMap to " + Convert.ToString(ControlChars.Quote) + Path + Convert.ToString(ControlChars.Quote)); if ( !Overwrite ) { if ( File.Exists(Path) ) { ReturnResult.ProblemAdd("The file already exists"); return ReturnResult; } } FileStream FileStream = default(FileStream); try { FileStream = File.Create(Path); } catch ( Exception ) { ReturnResult.ProblemAdd("Unable to create file"); return ReturnResult; } ZipOutputStream WZStream = new ZipOutputStream(FileStream); WZStream.UseZip64 = UseZip64.Off; if ( Compress ) { WZStream.SetLevel(9); } else { WZStream.SetLevel(0); } BinaryWriter BinaryWriter = new BinaryWriter(WZStream, App.UTF8Encoding); StreamWriter StreamWriter = new StreamWriter(WZStream, App.UTF8Encoding); ZipEntry ZipEntry = default(ZipEntry); string ZipPath = ""; ZipPath = "Info.ini"; ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult); if ( ZipEntry != null ) { IniWriter INI_Info = new IniWriter(); INI_Info.File = StreamWriter; ReturnResult.Add(Serialize_FMap_Info(INI_Info)); StreamWriter.Flush(); WZStream.CloseEntry(); } ZipPath = "VertexHeight.dat"; ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult); if ( ZipEntry != null ) { ReturnResult.Add(Serialize_FMap_VertexHeight(BinaryWriter)); BinaryWriter.Flush(); WZStream.CloseEntry(); } ZipPath = "VertexTerrain.dat"; ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult); if ( ZipEntry != null ) { ReturnResult.Add(Serialize_FMap_VertexTerrain(BinaryWriter)); BinaryWriter.Flush(); WZStream.CloseEntry(); } ZipPath = "TileTexture.dat"; ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult); if ( ZipEntry != null ) { ReturnResult.Add(Serialize_FMap_TileTexture(BinaryWriter)); BinaryWriter.Flush(); WZStream.CloseEntry(); } ZipPath = "TileOrientation.dat"; ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult); if ( ZipEntry != null ) { ReturnResult.Add(Serialize_FMap_TileOrientation(BinaryWriter)); BinaryWriter.Flush(); WZStream.CloseEntry(); } ZipPath = "TileCliff.dat"; ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult); if ( ZipEntry != null ) { ReturnResult.Add(Serialize_FMap_TileCliff(BinaryWriter)); BinaryWriter.Flush(); WZStream.CloseEntry(); } ZipPath = "Roads.dat"; ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult); if ( ZipEntry != null ) { ReturnResult.Add(Serialize_FMap_Roads(BinaryWriter)); BinaryWriter.Flush(); WZStream.CloseEntry(); } ZipPath = "Objects.ini"; ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult); if ( ZipEntry != null ) { IniWriter INI_Objects = new IniWriter(); INI_Objects.File = StreamWriter; ReturnResult.Add(Serialize_FMap_Objects(INI_Objects)); StreamWriter.Flush(); WZStream.CloseEntry(); } ZipPath = "Gateways.ini"; ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult); if ( ZipEntry != null ) { IniWriter INI_Gateways = new IniWriter(); INI_Gateways.File = StreamWriter; ReturnResult.Add(Serialize_FMap_Gateways(INI_Gateways)); StreamWriter.Flush(); WZStream.CloseEntry(); } ZipPath = "TileTypes.dat"; ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult); if ( ZipEntry != null ) { ReturnResult.Add(Serialize_FMap_TileTypes(BinaryWriter)); BinaryWriter.Flush(); WZStream.CloseEntry(); } ZipPath = "ScriptLabels.ini"; ZipEntry = IOUtil.ZipMakeEntry(WZStream, ZipPath, ReturnResult); if ( ZipEntry != null ) { IniWriter INI_ScriptLabels = new IniWriter(); INI_ScriptLabels.File = StreamWriter; ReturnResult.Add(Serialize_WZ_LabelsINI(INI_ScriptLabels, -1)); StreamWriter.Flush(); WZStream.CloseEntry(); } WZStream.Finish(); WZStream.Close(); BinaryWriter.Close(); return ReturnResult; }
public clsResult Serialize_WZ_StructuresINI(IniWriter File, int PlayerCount) { clsResult ReturnResult = new clsResult("Serializing structures INI"); clsStructureType StructureType = default(clsStructureType); clsUnit Unit = default(clsUnit); bool[] UnitIsModule = new bool[Units.Count]; int[] UnitModuleCount = new int[Units.Count]; sXY_int SectorNum = new sXY_int(); clsStructureType OtherStructureType = default(clsStructureType); clsUnit OtherUnit = default(clsUnit); sXY_int ModuleMin = new sXY_int(); sXY_int ModuleMax = new sXY_int(); sXY_int Footprint = new sXY_int(); int A = 0; clsStructureType.enumStructureType[] UnderneathTypes = new clsStructureType.enumStructureType[2]; int UnderneathTypeCount = 0; int BadModuleCount = 0; clsObjectPriorityOrderList PriorityOrder = new clsObjectPriorityOrderList(); foreach ( clsUnit tempLoopVar_Unit in Units ) { Unit = tempLoopVar_Unit; if ( Unit.Type.Type == clsUnitType.enumType.PlayerStructure ) { StructureType = (clsStructureType)Unit.Type; switch ( StructureType.StructureType ) { case clsStructureType.enumStructureType.FactoryModule: UnderneathTypes[0] = clsStructureType.enumStructureType.Factory; UnderneathTypes[1] = clsStructureType.enumStructureType.VTOLFactory; UnderneathTypeCount = 2; break; case clsStructureType.enumStructureType.PowerModule: UnderneathTypes[0] = clsStructureType.enumStructureType.PowerGenerator; UnderneathTypeCount = 1; break; case clsStructureType.enumStructureType.ResearchModule: UnderneathTypes[0] = clsStructureType.enumStructureType.Research; UnderneathTypeCount = 1; break; default: UnderneathTypeCount = 0; break; } if ( UnderneathTypeCount == 0 ) { PriorityOrder.SetItem(Unit); PriorityOrder.ActionPerform(); } else { UnitIsModule[Unit.MapLink.ArrayPosition] = true; SectorNum = GetPosSectorNum(Unit.Pos.Horizontal); clsUnit Underneath = null; clsUnitSectorConnection Connection = default(clsUnitSectorConnection); foreach ( clsUnitSectorConnection tempLoopVar_Connection in Sectors[SectorNum.X, SectorNum.Y].Units ) { Connection = tempLoopVar_Connection; OtherUnit = Connection.Unit; if ( OtherUnit.Type.Type == clsUnitType.enumType.PlayerStructure ) { OtherStructureType = (clsStructureType)OtherUnit.Type; if ( OtherUnit.UnitGroup == Unit.UnitGroup ) { for ( A = 0; A <= UnderneathTypeCount - 1; A++ ) { if ( OtherStructureType.StructureType == UnderneathTypes[A] ) { break; } } if ( A < UnderneathTypeCount ) { Footprint = OtherStructureType.get_GetFootprintSelected(OtherUnit.Rotation); ModuleMin.X = OtherUnit.Pos.Horizontal.X - (int)(Footprint.X * App.TerrainGridSpacing / 2.0D); ModuleMin.Y = OtherUnit.Pos.Horizontal.Y - (int)(Footprint.Y * App.TerrainGridSpacing / 2.0D); ModuleMax.X = OtherUnit.Pos.Horizontal.X + (int)(Footprint.X * App.TerrainGridSpacing / 2.0D); ModuleMax.Y = OtherUnit.Pos.Horizontal.Y + (int)(Footprint.Y * App.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(BadModuleCount + " modules had no underlying structure."); } int TooManyModulesWarningCount = 0; int TooManyModulesWarningMaxCount = 16; int ModuleCount = 0; int ModuleLimit = 0; for ( A = 0; A <= PriorityOrder.Result.Count - 1; A++ ) { Unit = PriorityOrder.Result[A]; StructureType = (clsStructureType)Unit.Type; 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.AppendSectionName("structure_" + IOUtil.InvariantToString(Unit.ID)); File.AppendProperty("id", IOUtil.InvariantToString(Unit.ID)); if ( Unit.UnitGroup == ScavengerUnitGroup || (PlayerCount >= 0 & Unit.UnitGroup.WZ_StartPos >= PlayerCount) ) { File.AppendProperty("player", "scavenger"); } else { File.AppendProperty("startpos", IOUtil.InvariantToString(Unit.UnitGroup.WZ_StartPos)); } File.AppendProperty("name", StructureType.Code); if ( StructureType.WallLink.IsConnected ) { File.AppendProperty("wall/type", IOUtil.InvariantToString(StructureType.WallLink.ArrayPosition)); } File.AppendProperty("position", Unit.GetINIPosition()); File.AppendProperty("rotation", Unit.GetINIRotation()); if ( Unit.Health < 1.0D ) { File.AppendProperty("health", Unit.GetINIHealthPercent()); } switch ( StructureType.StructureType ) { case clsStructureType.enumStructureType.Factory: ModuleLimit = 2; break; case clsStructureType.enumStructureType.VTOLFactory: ModuleLimit = 2; break; case clsStructureType.enumStructureType.PowerGenerator: ModuleLimit = 1; break; case clsStructureType.enumStructureType.Research: ModuleLimit = 1; break; default: ModuleLimit = 0; break; } if ( UnitModuleCount[Unit.MapLink.ArrayPosition] > ModuleLimit ) { ModuleCount = ModuleLimit; if ( TooManyModulesWarningCount < TooManyModulesWarningMaxCount ) { ReturnResult.WarningAdd("Structure " + StructureType.GetDisplayTextCode() + " at " + Unit.GetPosText() + " has too many modules (" + Convert.ToString(UnitModuleCount[Unit.MapLink.ArrayPosition]) + ")."); } TooManyModulesWarningCount++; } else { ModuleCount = UnitModuleCount[Unit.MapLink.ArrayPosition]; } File.AppendProperty("modules", IOUtil.InvariantToString(ModuleCount)); File.Gap_Append(); } } if ( TooManyModulesWarningCount > TooManyModulesWarningMaxCount ) { ReturnResult.WarningAdd(TooManyModulesWarningCount + " structures had too many modules."); } return ReturnResult; }
public clsResult Serialize_WZ_LabelsINI(IniWriter File, int PlayerCount) { clsResult ReturnResult = new clsResult("Serializing labels INI"); try { clsScriptPosition ScriptPosition = default(clsScriptPosition); foreach ( clsScriptPosition tempLoopVar_ScriptPosition in ScriptPositions ) { ScriptPosition = tempLoopVar_ScriptPosition; ScriptPosition.WriteWZ(File); } clsScriptArea ScriptArea = default(clsScriptArea); foreach ( clsScriptArea tempLoopVar_ScriptArea in ScriptAreas ) { ScriptArea = tempLoopVar_ScriptArea; ScriptArea.WriteWZ(File); } if ( PlayerCount >= 0 ) //not an FMap { clsUnit Unit = default(clsUnit); foreach ( clsUnit tempLoopVar_Unit in Units ) { Unit = tempLoopVar_Unit; Unit.WriteWZLabel(File, PlayerCount); } } } catch ( Exception ex ) { ReturnResult.WarningAdd(ex.Message); } return ReturnResult; }
public clsResult Serialize_WZ_FeaturesINI(IniWriter File) { clsResult ReturnResult = new clsResult("Serializing features INI"); clsFeatureType FeatureType = default(clsFeatureType); clsUnit Unit = default(clsUnit); bool Valid = default(bool); foreach ( clsUnit tempLoopVar_Unit in Units ) { Unit = tempLoopVar_Unit; if ( Unit.Type.Type == clsUnitType.enumType.Feature ) { FeatureType = (clsFeatureType)Unit.Type; 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.AppendSectionName("feature_" + IOUtil.InvariantToString(Unit.ID)); File.AppendProperty("id", IOUtil.InvariantToString(Unit.ID)); File.AppendProperty("position", Unit.GetINIPosition()); File.AppendProperty("rotation", Unit.GetINIRotation()); File.AppendProperty("name", FeatureType.Code); if ( Unit.Health < 1.0D ) { File.AppendProperty("health", Unit.GetINIHealthPercent()); } File.Gap_Append(); } } } return ReturnResult; }
public clsResult Serialize_WZ_DroidsINI(IniWriter File, int PlayerCount) { clsResult ReturnResult = new clsResult("Serializing droids INI"); clsDroidDesign Droid = default(clsDroidDesign); clsDroidTemplate Template = default(clsDroidTemplate); string Text = ""; clsUnit Unit = default(clsUnit); bool AsPartsNotTemplate = default(bool); bool ValidDroid = default(bool); int InvalidPartCount = 0; clsBrain Brain = default(clsBrain); foreach ( clsUnit tempLoopVar_Unit in Units ) { Unit = tempLoopVar_Unit; if ( Unit.Type.Type == clsUnitType.enumType.PlayerDroid ) { Droid = (clsDroidDesign)Unit.Type; 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 = (clsDroidTemplate)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 != clsTurret.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 != clsTurret.enumTurretType.Weapon ) { ValidDroid = false; InvalidPartCount++; } } } if ( ValidDroid ) { File.AppendSectionName("droid_" + IOUtil.InvariantToString(Unit.ID)); File.AppendProperty("id", IOUtil.InvariantToString(Unit.ID)); if ( Unit.UnitGroup == ScavengerUnitGroup || (PlayerCount >= 0 & Unit.UnitGroup.WZ_StartPos >= PlayerCount) ) { File.AppendProperty("player", "scavenger"); } else { File.AppendProperty("startpos", IOUtil.InvariantToString(Unit.UnitGroup.WZ_StartPos)); } if ( AsPartsNotTemplate ) { File.AppendProperty("name", Droid.GenerateName()); } else { Template = (clsDroidTemplate)Droid; File.AppendProperty("template", Template.Code); } File.AppendProperty("position", Unit.GetINIPosition()); File.AppendProperty("rotation", Unit.GetINIRotation()); if ( Unit.Health < 1.0D ) { File.AppendProperty("health", Unit.GetINIHealthPercent()); } if ( AsPartsNotTemplate ) { File.AppendProperty("droidType", IOUtil.InvariantToString(Convert.ToInt32(Droid.GetDroidType()))); if ( Droid.TurretCount == 0 ) { Text = "0"; } else { if ( Droid.Turret1.TurretType == clsTurret.enumTurretType.Brain ) { if ( ((clsBrain)Droid.Turret1).Weapon == null ) { Text = "0"; } else { Text = "1"; } } else { if ( Droid.Turret1.TurretType == clsTurret.enumTurretType.Weapon ) { Text = IOUtil.InvariantToString(Droid.TurretCount); } else { Text = "0"; } } } File.AppendProperty("weapons", Text); File.AppendProperty("parts\\body", Droid.Body.Code); File.AppendProperty("parts\\propulsion", Droid.Propulsion.Code); File.AppendProperty("parts\\sensor", Droid.GetSensorCode()); File.AppendProperty("parts\\construct", Droid.GetConstructCode()); File.AppendProperty("parts\\repair", Droid.GetRepairCode()); File.AppendProperty("parts\\brain", Droid.GetBrainCode()); File.AppendProperty("parts\\ecm", Droid.GetECMCode()); if ( Droid.TurretCount >= 1 ) { if ( Droid.Turret1.TurretType == clsTurret.enumTurretType.Weapon ) { File.AppendProperty("parts\\weapon\\1", Droid.Turret1.Code); if ( Droid.TurretCount >= 2 ) { if ( Droid.Turret2.TurretType == clsTurret.enumTurretType.Weapon ) { File.AppendProperty("parts\\weapon\\2", Droid.Turret2.Code); if ( Droid.TurretCount >= 3 ) { if ( Droid.Turret3.TurretType == clsTurret.enumTurretType.Weapon ) { File.AppendProperty("parts\\weapon\\3", Droid.Turret3.Code); } } } } } else if ( Droid.Turret1.TurretType == clsTurret.enumTurretType.Brain ) { Brain = (clsBrain)Droid.Turret1; if ( Brain.Weapon == null ) { Text = "ZNULLWEAPON"; } else { Text = Brain.Weapon.Code; } File.AppendProperty("parts\\weapon\\1", Text); } } } File.Gap_Append(); } } } if ( InvalidPartCount > 0 ) { ReturnResult.WarningAdd("There were " + Convert.ToString(InvalidPartCount) + " droids with parts missing. They were not saved."); } return ReturnResult; }