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; }
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; }
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; }
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; }
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; }
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); }