private Result serialize_FMap_Gateways(IniWriter File) { var returnResult = new Result("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 WriteWZLabel(IniWriter File, int PlayerCount) { if (label != null) { var TypeNum = 0; switch (TypeBase.Type) { case UnitType.PlayerDroid: TypeNum = 0; break; case UnitType.PlayerStructure: TypeNum = 1; break; case UnitType.Feature: TypeNum = 2; break; default: return; } File.AddSection("object_" + MapLink.ArrayPosition.ToStringInvariant()); File.AddProperty("id", ID.ToStringInvariant()); if (PlayerCount >= 0) //not an FMap { File.AddProperty("type", TypeNum.ToStringInvariant()); File.AddProperty("player", UnitGroup.GetPlayerNum(PlayerCount).ToStringInvariant()); } File.AddProperty("label", label); } }
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); }
private Result Serialize_WZ_FeaturesINI(IniWriter File) { var ReturnResult = new Result("Serializing features INI", false); logger.Info("Serializing features INI"); var featureTypeBase = default(FeatureTypeBase); var Unit = default(Unit); 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 Result serialize_FMap_Objects(IniWriter file) { var returnResult = new Result("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 Result Serialize_WZ_DroidsINI(IniWriter ini, int playerCount) { var returnResult = new Result("Serializing droids INI", false); logger.Info("Serializing droids INI"); var droid = default(DroidDesign); var template = default(DroidTemplate); var text = ""; var unit = default(Unit); 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 != TurretType.Weapon) { validDroid = false; invalidPartCount++; } } else if (droid.TurretCount >= 3 && droid.Turret3 == null) { if (droid.Turret3 == null) { validDroid = false; invalidPartCount++; } else if (droid.Turret3.TurretType != TurretType.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 == TurretType.Brain) { if (((Brain)droid.Turret1).Weapon == null) { text = "0"; } else { text = "1"; } } else { if (droid.Turret1.TurretType == TurretType.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 == TurretType.Weapon) { ini.AddProperty("parts\\weapon\\1", droid.Turret1.Code); if (droid.TurretCount >= 2) { if (droid.Turret2.TurretType == TurretType.Weapon) { ini.AddProperty("parts\\weapon\\2", droid.Turret2.Code); if (droid.TurretCount >= 3) { if (droid.Turret3.TurretType == TurretType.Weapon) { ini.AddProperty("parts\\weapon\\3", droid.Turret3.Code); } } } } } else if (droid.Turret1.TurretType == TurretType.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 Result Serialize_WZ_StructuresINI(IniWriter File, int PlayerCount) { var ReturnResult = new Result("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(Unit); var moduleMin = new XYInt(); var moduleMax = new XYInt(); var footprint = new XYInt(); var A = 0; var underneathTypes = new StructureType[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 StructureType.FactoryModule: underneathTypes[0] = StructureType.Factory; underneathTypes[1] = StructureType.VTOLFactory; underneathTypeCount = 2; break; case StructureType.PowerModule: underneathTypes[0] = StructureType.PowerGenerator; underneathTypeCount = 1; break; case StructureType.ResearchModule: underneathTypes[0] = StructureType.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); Unit 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.GetGetFootprintSelected(otherUnit.Rotation); moduleMin.X = otherUnit.Pos.Horizontal.X - (footprint.X * Constants.TerrainGridSpacing / 2.0D).ToInt(); moduleMin.Y = otherUnit.Pos.Horizontal.Y - (footprint.Y * Constants.TerrainGridSpacing / 2.0D).ToInt(); moduleMax.X = otherUnit.Pos.Horizontal.X + (footprint.X * Constants.TerrainGridSpacing / 2.0D).ToInt(); moduleMax.Y = otherUnit.Pos.Horizontal.Y + (footprint.Y * Constants.TerrainGridSpacing / 2.0D).ToInt(); 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 StructureType.Factory: moduleLimit = 2; break; case StructureType.VTOLFactory: moduleLimit = 2; break; case StructureType.PowerGenerator: moduleLimit = 1; break; case StructureType.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); }
public void WriteWZ(IniWriter File) { File.AddSection("position_" + parentMapLink.ArrayPosition.ToStringInvariant()); File.AddProperty("pos", pos.X.ToStringInvariant() + ", " + pos.Y.ToStringInvariant()); File.AddProperty("label", label); }