private string CreateGroup( string groupTypeLua, Coordinates coordinates, string groupName, params KeyValuePair <string, object>[] extraSettings ) { string lua = File.ReadAllText($"{BRPaths.INCLUDE_LUA_UNITS}{Toolbox.AddMissingFileExtension(groupTypeLua, ".lua")}"); foreach (KeyValuePair <string, object> extraSetting in extraSettings) // Replace custom values first so they override other replacements { if (!(extraSetting.Value is Array)) // Array extra settings are treated on a per-unit basis { GeneratorTools.ReplaceKey(ref lua, extraSetting.Key, extraSetting.Value); } } GeneratorTools.ReplaceKey(ref lua, "GroupID", GroupID); GeneratorTools.ReplaceKey(ref lua, "GroupX", coordinates.X); GeneratorTools.ReplaceKey(ref lua, "GroupY", coordinates.Y); GeneratorTools.ReplaceKey(ref lua, "GroupX2", coordinates.X); // GroupX2 and GroupY2 are replaced by the default coordinates only if they were not replaced earlier in extraSetting replacements. GeneratorTools.ReplaceKey(ref lua, "GroupY2", coordinates.Y); GeneratorTools.ReplaceKey(ref lua, "Name", groupName); return(lua); }
protected void AddBriefingRemarkFromFeature(T featureDB, DCSMission mission, bool useEnemyRemarkIfAvailable, UnitMakerGroupInfo?groupInfo, Dictionary <string, object> stringReplacements) { string[] remarks; if (useEnemyRemarkIfAvailable && featureDB.BriefingRemarks[(int)Side.Enemy].Length > 0) { remarks = featureDB.BriefingRemarks[(int)Side.Enemy].ToArray(); } else { remarks = featureDB.BriefingRemarks[(int)Side.Ally].ToArray(); } if (remarks.Length == 0) { return; // No briefing remarks for this feature } string remark = Toolbox.RandomFrom(remarks); foreach (KeyValuePair <string, object> stringReplacement in stringReplacements) { GeneratorTools.ReplaceKey(ref remark, stringReplacement.Key, stringReplacement.Value.ToString()); } if (groupInfo.HasValue) { GeneratorTools.ReplaceKey(ref remark, "GroupName", groupInfo.Value.Name); GeneratorTools.ReplaceKey(ref remark, "GroupFrequency", GeneratorTools.FormatRadioFrequency(groupInfo.Value.Frequency)); GeneratorTools.ReplaceKey(ref remark, "GroupUnitName", groupInfo.Value.UnitDB.UIDisplayName); } mission.Briefing.AddItem(DCSMissionBriefingItemType.Remark, remark, featureDB is DBEntryFeatureMission); }
private static void CreateLua(DCSMission mission, MissionTemplateRecord template, DBEntryObjectiveTarget targetDB, DBEntryObjectiveTask taskDB, int objectiveIndex, string objectiveName, UnitMakerGroupInfo?targetGroupInfo, string taskString) { // Add Lua table for this objective string objectiveLua = $"briefingRoom.mission.objectives[{objectiveIndex + 1}] = {{ "; objectiveLua += $"complete = false, "; objectiveLua += $"groupID = {targetGroupInfo.Value.GroupID}, "; objectiveLua += $"hideTargetCount = false, "; objectiveLua += $"name = \"{objectiveName}\", "; objectiveLua += $"targetCategory = Unit.Category.{targetDB.UnitCategory.ToLuaName()}, "; objectiveLua += $"taskType = \"{taskDB.ID}\", "; objectiveLua += $"task = \"{taskString}\", "; objectiveLua += $"unitsCount = {targetGroupInfo.Value.UnitsID.Length}, "; objectiveLua += $"unitsID = {{ {string.Join(", ", targetGroupInfo.Value.UnitsID)} }} "; objectiveLua += "}\n"; // Add F10 sub-menu for this objective objectiveLua += $"briefingRoom.f10Menu.objectives[{objectiveIndex + 1}] = missionCommands.addSubMenuForCoalition(coalition.side.{template.ContextPlayerCoalition.ToString().ToUpperInvariant()}, \"Objective {objectiveName}\", nil)\n"; mission.AppendValue("ScriptObjectives", objectiveLua); // Add objective trigger Lua for this objective string triggerLua = Toolbox.ReadAllTextIfFileExists($"{BRPaths.INCLUDE_LUA_OBJECTIVETRIGGERS}{taskDB.CompletionTriggerLua}"); GeneratorTools.ReplaceKey(ref triggerLua, "ObjectiveIndex", objectiveIndex + 1); mission.AppendValue("ScriptObjectivesTriggers", triggerLua); }
private void AddToList(string UIName, string template, Coordinates coordinates, DrawingColour colour, DrawingColour fillColour) { GeneratorTools.ReplaceKey(ref template, "UIName", UIName); GeneratorTools.ReplaceKey(ref template, "X", coordinates.X); GeneratorTools.ReplaceKey(ref template, "Y", coordinates.Y); GeneratorTools.ReplaceKey(ref template, "Colour", colour.ToValue()); GeneratorTools.ReplaceKey(ref template, "FillColour", fillColour.ToValue()); LuaDrawings.Add(template); }
private string ApplyAircraftFields(string groupLua, DBEntryUnit firstUnitDB, params KeyValuePair <string, object>[] extraSettings) { GeneratorTools.ReplaceKey(ref groupLua, "Altitude", firstUnitDB.AircraftData.CruiseAltitude); GeneratorTools.ReplaceKey(ref groupLua, "AltitudeHalf", firstUnitDB.AircraftData.CruiseAltitude / 2); GeneratorTools.ReplaceKey(ref groupLua, "EPLRS", firstUnitDB.Flags.HasFlag(DBEntryUnitFlags.EPLRS)); GeneratorTools.ReplaceKey(ref groupLua, "RadioBand", (int)firstUnitDB.AircraftData.RadioModulation); GeneratorTools.ReplaceKey(ref groupLua, "RadioFrequency", firstUnitDB.AircraftData.RadioFrequency); GeneratorTools.ReplaceKey(ref groupLua, "Speed", firstUnitDB.AircraftData.CruiseSpeed); return(groupLua); }
private void AddTextBox(string UIName, Coordinates coordinates, params KeyValuePair <string, object>[] extraSettings) { string drawingLuaTemplate = File.ReadAllText($"{BRPaths.INCLUDE_LUA_MISSION}\\Drawing\\TextBox.lua"); GeneratorTools.ReplaceKey(ref drawingLuaTemplate, "Text", extraSettings.First(x => x.Key == "Text").Value); DrawingColour colour = (DrawingColour)(extraSettings.FirstOrDefault(x => x.Key == "Colour").Value ?? DrawingColour.Red); DrawingColour fillColour = (DrawingColour)(extraSettings.FirstOrDefault(x => x.Key == "FillColour").Value ?? DrawingColour.White); AddToList(UIName, drawingLuaTemplate, coordinates, colour, fillColour); }
private void AddToList(string UIName, Coordinates coordinates, int radius) { string template = File.ReadAllText($"{BRPaths.INCLUDE_LUA_MISSION}\\Zone.lua"); GeneratorTools.ReplaceKey(ref template, "NAME", UIName); GeneratorTools.ReplaceKey(ref template, "RADIUS", radius); GeneratorTools.ReplaceKey(ref template, "X", coordinates.X); GeneratorTools.ReplaceKey(ref template, "Y", coordinates.Y); GeneratorTools.ReplaceKey(ref template, "zoneId", new Random().Next(100, 500)); LuaZones.Add(template); }
private static void CreateTaskString(DCSMission mission, int pluralIndex, ref string taskString, string objectiveName, UnitFamily objectiveTargetUnitFamily) { // Get tasking string for the briefing if (string.IsNullOrEmpty(taskString)) { taskString = "Complete objective $OBJECTIVENAME$"; } GeneratorTools.ReplaceKey(ref taskString, "ObjectiveName", objectiveName); GeneratorTools.ReplaceKey(ref taskString, "UnitFamily", Database.Instance.Common.Names.UnitFamilies[(int)objectiveTargetUnitFamily][pluralIndex]); mission.Briefing.AddItem(DCSMissionBriefingItemType.Task, taskString); }
internal string GetLuaDrawings() { string luaDrawings = ""; var index = 1; foreach (var drawing in LuaDrawings) { var drawingLua = drawing; GeneratorTools.ReplaceKey(ref drawingLua, "Index", index); luaDrawings += $"{drawingLua}\n"; index++; } return(luaDrawings); }
internal string GetLuaZones() { string luaDrawings = ""; var index = 1; foreach (var zone in LuaZones) { var zoneLua = zone; GeneratorTools.ReplaceKey(ref zoneLua, "Index", index); luaDrawings += $"{zoneLua}\n"; index++; } return(luaDrawings); }
internal static void GenerateWarehouses(DCSMission mission) { string warehousesAirportLua = ""; if (!File.Exists(AIRPORT_TEMPLATE_FILEPATH)) { throw new Exception("Airport warehouse template file (Include\\Lua\\Warehouses\\Airport.lua) not found."); } string airportLuaTemplate = File.ReadAllText(AIRPORT_TEMPLATE_FILEPATH); foreach (int airbaseID in mission.Airbases.Keys) { string airportLua = airportLuaTemplate; GeneratorTools.ReplaceKey(ref airportLua, "index", airbaseID); GeneratorTools.ReplaceKey(ref airportLua, "coalition", mission.Airbases[airbaseID].ToString().ToUpperInvariant()); warehousesAirportLua += airportLua + "\r\n"; } mission.SetValue("WarehousesAirports", warehousesAirportLua); }
private void AddFree(string UIName, Coordinates coordinates, params KeyValuePair <string, object>[] extraSettings) { string drawingLuaTemplate = File.ReadAllText($"{BRPaths.INCLUDE_LUA_MISSION}\\Drawing\\Free.lua"); string freePosLuaTemplate = File.ReadAllText($"{BRPaths.INCLUDE_LUA_MISSION}\\Drawing\\FreePos.lua"); var points = ""; var index = 1; foreach (Coordinates pos in (List <Coordinates>)extraSettings.First(x => x.Key == "Points").Value) { var templateLua = new String(freePosLuaTemplate); GeneratorTools.ReplaceKey(ref templateLua, "Index", index); GeneratorTools.ReplaceKey(ref templateLua, "X", pos.X); GeneratorTools.ReplaceKey(ref templateLua, "Y", pos.Y); points += $"{templateLua}\n"; index++; } GeneratorTools.ReplaceKey(ref drawingLuaTemplate, "POINTS", points); DrawingColour colour = (DrawingColour)(extraSettings.FirstOrDefault(x => x.Key == "Colour").Value ?? DrawingColour.Red); DrawingColour fillColour = (DrawingColour)(extraSettings.FirstOrDefault(x => x.Key == "FillColour").Value ?? DrawingColour.RedFill); AddToList(UIName, drawingLuaTemplate, coordinates, colour, fillColour); }
private static string GenerateFlightPlanLua(List <Waypoint> waypoints) { string flightPlanLua = ""; string waypointLuaTemplate = File.ReadAllText($"{BRPaths.INCLUDE_LUA_MISSION}WaypointPlayer.lua"); for (int i = 0; i < waypoints.Count; i++) { string waypointLua = waypointLuaTemplate; GeneratorTools.ReplaceKey(ref waypointLua, "Index", i + 2); GeneratorTools.ReplaceKey(ref waypointLua, "Name", waypoints[i].Name); GeneratorTools.ReplaceKey(ref waypointLua, "X", waypoints[i].Coordinates.X); GeneratorTools.ReplaceKey(ref waypointLua, "Y", waypoints[i].Coordinates.Y); if (waypoints[i].OnGround) { GeneratorTools.ReplaceKey(ref waypointLua, "Altitude", "0"); } flightPlanLua += waypointLua + "\n"; } return(flightPlanLua); }
protected UnitMakerGroupInfo?AddMissionFeature(T featureDB, DCSMission mission, Coordinates coordinates, Coordinates?coordinates2, ref Dictionary <string, object> extraSettings, Side?objectiveTargetSide = null, bool hideEnemy = false) { // Add secondary coordinates (destination point) to the extra settings if (!coordinates2.HasValue) { coordinates2 = coordinates; // No destination point? Use initial point } extraSettings.AddIfKeyUnused("GroupX2", coordinates2.Value.X); extraSettings.AddIfKeyUnused("GroupY2", coordinates2.Value.Y); var TACANStr = GetExtraSettingsFromFeature(featureDB, ref extraSettings); // Add specific settings for this feature (TACAN frequencies, etc) // Feature unit group UnitMakerGroupInfo?groupInfo = null; if (FeatureHasUnitGroup(featureDB)) { UnitMakerGroupFlags groupFlags = 0; if (featureDB.UnitGroupFlags.HasFlag(FeatureUnitGroupFlags.ImmediateAircraftActivation)) { groupFlags |= UnitMakerGroupFlags.ImmediateAircraftSpawn; } if (featureDB.UnitGroupFlags.HasFlag(FeatureUnitGroupFlags.RadioAircraftActivation)) { groupFlags |= UnitMakerGroupFlags.RadioAircraftSpawn; } Side groupSide = Side.Enemy; if (featureDB.UnitGroupFlags.HasFlag(FeatureUnitGroupFlags.Friendly)) { groupSide = Side.Ally; } else if (featureDB.UnitGroupFlags.HasFlag(FeatureUnitGroupFlags.SameSideAsTarget) && objectiveTargetSide.HasValue) { groupSide = objectiveTargetSide.Value; } if (hideEnemy && groupSide == Side.Enemy) { groupFlags |= UnitMakerGroupFlags.AlwaysHidden; } extraSettings.AddIfKeyUnused("Payload", featureDB.UnitGroupPayload); var groupLua = featureDB.UnitGroupLuaGroup; var unitCount = featureDB.UnitGroupSize.GetValue(); var unitFamily = Toolbox.RandomFrom(featureDB.UnitGroupFamilies); var luaUnit = featureDB.UnitGroupLuaUnit; SetAirbase(featureDB, unitFamily, ref groupLua, ref luaUnit, groupSide, ref coordinates, coordinates2.Value, unitCount, ref extraSettings); groupInfo = _unitMaker.AddUnitGroup( unitFamily, unitCount, groupSide, groupLua, luaUnit, coordinates, groupFlags, extraSettings.ToArray()); if ( groupSide == Side.Ally && groupInfo.HasValue && groupInfo.Value.UnitDB != null && groupInfo.Value.UnitDB.IsAircraft) { mission.Briefing.AddItem(DCSMissionBriefingItemType.FlightGroup, $"{groupInfo.Value.Name}\t" + $"{unitCount}× {groupInfo.Value.UnitDB.UIDisplayName}\t" + $"{GeneratorTools.FormatRadioFrequency(groupInfo.Value.Frequency)}{TACANStr}\t" + $"{Toolbox.FormatPayload(featureDB.UnitGroupPayload)}"); // TODO: human-readable payload name } if (featureDB.ExtraGroups.Max > 1) { SpawnExtraGroups(featureDB, mission, groupSide, groupFlags, coordinates, coordinates2.Value, extraSettings); } } // Feature Lua script string featureLua = ""; // Adds the features' group ID to the briefingRoom.mission.missionFeatures.groupsID table if (this is MissionGeneratorFeaturesMission) { featureLua += $"briefingRoom.mission.missionFeatures.groupsID.{GeneratorTools.LowercaseFirstCharacter(featureDB.ID)} = {(groupInfo.HasValue ? groupInfo.Value.GroupID : 0)}\n"; featureLua += $"briefingRoom.mission.missionFeatures.unitsID.{GeneratorTools.LowercaseFirstCharacter(featureDB.ID)} = {{{(groupInfo.HasValue ? string.Join(",", groupInfo.Value.UnitsID) : "")}}}\n"; } if (!string.IsNullOrEmpty(featureDB.IncludeLuaSettings)) { featureLua = featureDB.IncludeLuaSettings + "\n"; } foreach (string luaFile in featureDB.IncludeLua) { featureLua += Toolbox.ReadAllTextIfFileExists($"{featureDB.SourceLuaDirectory}{luaFile}") + "\n"; } foreach (KeyValuePair <string, object> extraSetting in extraSettings) { GeneratorTools.ReplaceKey(ref featureLua, extraSetting.Key, extraSetting.Value); } if (groupInfo.HasValue) { GeneratorTools.ReplaceKey(ref featureLua, "FeatureGroupID", groupInfo.Value.GroupID); } if (featureDB is DBEntryFeatureObjective) { mission.AppendValue("ScriptObjectivesFeatures", featureLua); } else { mission.AppendValue("ScriptMissionFeatures", featureLua); } // Add feature ogg files foreach (string oggFile in featureDB.IncludeOgg) { mission.AddMediaFile($"l10n/DEFAULT/{oggFile}", $"{BRPaths.INCLUDE_OGG}{oggFile}"); } return(groupInfo); }
internal Tuple <Coordinates, List <Waypoint> > GenerateObjective( DCSMission mission, MissionTemplateRecord template, DBEntrySituation situationDB, MissionTemplateObjectiveRecord objectiveTemplate, Coordinates lastCoordinates, DBEntryAirbase playerAirbase, bool useObjectivePreset, ref int objectiveIndex, ref List <Coordinates> objectiveCoordinatesList, ref List <Waypoint> waypoints, ref List <UnitFamily> objectiveTargetUnitFamilies) { var extraSettings = new List <KeyValuePair <string, object> >(); var waypointList = new List <Waypoint>(); string[] featuresID; DBEntryObjectiveTarget targetDB; DBEntryObjectiveTargetBehavior targetBehaviorDB; DBEntryObjectiveTask taskDB; ObjectiveOption[] objectiveOptions; GetObjectiveData(objectiveTemplate, useObjectivePreset, out featuresID, out targetDB, out targetBehaviorDB, out taskDB, out objectiveOptions); var luaUnit = targetBehaviorDB.UnitLua[(int)targetDB.UnitCategory]; Coordinates objectiveCoordinates = GetSpawnCoordinates(template, lastCoordinates, playerAirbase, targetDB); // Spawn target on airbase var unitCount = targetDB.UnitCount[(int)objectiveTemplate.TargetCount].GetValue(); var objectiveTargetUnitFamily = Toolbox.RandomFrom(targetDB.UnitFamilies); if (AIRBASE_LOCATIONS.Contains(targetBehaviorDB.Location) && targetDB.UnitCategory.IsAircraft()) { objectiveCoordinates = PlaceInAirbase(template, situationDB, playerAirbase, extraSettings, targetDB, targetBehaviorDB, ref luaUnit, objectiveCoordinates, unitCount, objectiveTargetUnitFamily); } UnitMakerGroupFlags groupFlags = 0; if (objectiveOptions.Contains(ObjectiveOption.ShowTarget)) { groupFlags = UnitMakerGroupFlags.NeverHidden; } else if (objectiveOptions.Contains(ObjectiveOption.HideTarget)) { groupFlags = UnitMakerGroupFlags.AlwaysHidden; } if (objectiveOptions.Contains(ObjectiveOption.EmbeddedAirDefense)) { groupFlags |= UnitMakerGroupFlags.EmbeddedAirDefense; } // Set destination point for moving unit groups Coordinates destinationPoint = objectiveCoordinates + ( (targetDB.UnitCategory == UnitCategory.Plane ? Coordinates.CreateRandom(30, 60) : Coordinates.CreateRandom(10, 20)) * Toolbox.NM_TO_METERS ); if (targetBehaviorDB.Location == DBEntryObjectiveTargetBehaviorLocation.GoToPlayerAirbase) { destinationPoint = playerAirbase.Coordinates; } var unitCoordinates = objectiveCoordinates; var objectiveName = Toolbox.RandomFrom(ObjectiveNames); if (TRANSPORT_TASKS.Contains(taskDB.ID)) { Coordinates?spawnPoint = UnitMaker.SpawnPointSelector.GetRandomSpawnPoint( targetDB.ValidSpawnPoints, playerAirbase.Coordinates, new MinMaxD(1, 5), coalition: GeneratorTools.GetSpawnPointCoalition(template, Side.Ally)); if (!spawnPoint.HasValue) // Failed to generate target group { throw new BriefingRoomException($"Failed to find Cargo SpawnPoint"); } unitCoordinates = spawnPoint.Value; var cargoWaypoint = GenerateObjectiveWaypoint(objectiveTemplate, unitCoordinates, $"{objectiveName} Pickup", template, true); waypoints.Add(cargoWaypoint); waypointList.Add(cargoWaypoint); if (taskDB.isEscort()) { extraSettings.Add("GroupX2".ToKeyValuePair(objectiveCoordinates.X)); extraSettings.Add("GroupY2".ToKeyValuePair(objectiveCoordinates.Y)); groupFlags |= UnitMakerGroupFlags.RadioAircraftSpawn; } } extraSettings.Add("GroupX2".ToKeyValuePair(destinationPoint.X)); extraSettings.Add("GroupY2".ToKeyValuePair(destinationPoint.Y)); UnitMakerGroupInfo?targetGroupInfo = UnitMaker.AddUnitGroup( objectiveTargetUnitFamily, unitCount, taskDB.TargetSide, targetBehaviorDB.GroupLua[(int)targetDB.UnitCategory], luaUnit, unitCoordinates, groupFlags, extraSettings.ToArray()); if (!targetGroupInfo.HasValue) // Failed to generate target group { throw new BriefingRoomException($"Failed to generate group for objective."); } if (objectiveOptions.Contains(ObjectiveOption.EmbeddedAirDefense) && (targetDB.UnitCategory == UnitCategory.Static)) { AddEmbeddedAirDefenseUnits(template, targetDB, targetBehaviorDB, taskDB, objectiveOptions, objectiveCoordinates, groupFlags, extraSettings); } var pluralIndex = targetGroupInfo.Value.UnitsID.Length == 1 ? 0 : 1; var taskString = GeneratorTools.ParseRandomString(taskDB.BriefingTask[pluralIndex], mission).Replace("\"", "''"); // Pick a name, then remove it from the list ObjectiveNames.Remove(objectiveName); CreateTaskString(mission, pluralIndex, ref taskString, objectiveName, objectiveTargetUnitFamily); CreateLua(mission, template, targetDB, taskDB, objectiveIndex, objectiveName, targetGroupInfo, taskString); // Add briefing remarks for this objective task if (taskDB.BriefingRemarks.Length > 0) { string remark = Toolbox.RandomFrom(taskDB.BriefingRemarks); GeneratorTools.ReplaceKey(ref remark, "ObjectiveName", objectiveName); GeneratorTools.ReplaceKey(ref remark, "UnitFamily", Database.Instance.Common.Names.UnitFamilies[(int)objectiveTargetUnitFamily][pluralIndex]); mission.Briefing.AddItem(DCSMissionBriefingItemType.Remark, remark); } // Add feature ogg files foreach (string oggFile in taskDB.IncludeOgg) { mission.AddMediaFile($"l10n/DEFAULT/{oggFile}", $"{BRPaths.INCLUDE_OGG}{oggFile}"); } // Add objective features Lua for this objective mission.AppendValue("ScriptObjectivesFeatures", ""); // Just in case there's no features foreach (string featureID in featuresID) { FeaturesGenerator.GenerateMissionFeature(mission, featureID, objectiveName, objectiveIndex, targetGroupInfo.Value.GroupID, objectiveCoordinates, taskDB.TargetSide, objectiveOptions.Contains(ObjectiveOption.HideTarget)); } objectiveCoordinatesList.Add(objectiveCoordinates); var waypoint = GenerateObjectiveWaypoint(objectiveTemplate, objectiveCoordinates, objectiveName, template); waypoints.Add(waypoint); waypointList.Add(waypoint); objectiveTargetUnitFamilies.Add(objectiveTargetUnitFamily); var preValidSpawns = targetDB.ValidSpawnPoints.ToList(); foreach (var subTasks in objectiveTemplate.SubTasks) { objectiveIndex++; GenerateSubTask(mission, template, situationDB, subTasks, objectiveCoordinates, playerAirbase, preValidSpawns, targetBehaviorDB.Location, featuresID, ref objectiveIndex, ref objectiveCoordinatesList, ref waypoints, ref waypointList, ref objectiveTargetUnitFamilies); } return(new (objectiveCoordinates, waypointList)); }
private UnitMakerGroupInfo?AddStaticGroup( Country country, Coalition coalition, DCSSkillLevel?skill, UnitFamily unitFamily, Side side, string[] unitSets, string groupName, UnitCallsign?callsign, string groupTypeLua, Coordinates coordinates, UnitMakerGroupFlags unitMakerGroupFlags, params KeyValuePair <string, object>[] extraSettings ) { List <int> unitsIDList = new List <int>(); var initalGroupId = GroupID; foreach (var unitSet in unitSets) { DBEntryUnit unitDB = Database.Instance.GetEntry <DBEntryUnit>(unitSet); if (unitDB == null) { BriefingRoom.PrintToLog($"Unit \"{unitSet}\" not found.", LogMessageErrorLevel.Warning); continue; } int unitSetIndex = 0; foreach (var DCSID in unitDB.DCSIDs) { var groupHeading = GetGroupHeading(coordinates, extraSettings); SetUnitCoordinatesAndHeading(unitDB, unitSetIndex, coordinates, groupHeading, out Coordinates unitCoordinates, out double unitHeading); var firstUnitID = UnitID; var groupLua = CreateGroup( groupTypeLua, unitCoordinates, groupName, extraSettings ); var unitLua = DCSID == "FARP" ? "UnitStaticFOB" : (unitDB.Category == UnitCategory.Cargo ? "UnitCargo" : "UnitStatic"); var unitsLuaTable = AddUnit( DCSID, groupName, callsign, 1, unitSetIndex, unitDB, unitLua, coordinates, unitMakerGroupFlags, extraSettings ); unitsIDList.Add(UnitID); unitSetIndex++; UnitID++; GeneratorTools.ReplaceKey(ref groupLua, "Units", unitsLuaTable); GeneratorTools.ReplaceKey(ref groupLua, "UnitID", firstUnitID); // Must be after units are added GeneratorTools.ReplaceKey(ref groupLua, "Skill", skill); // Must be after units are added, because skill is set as a unit level GeneratorTools.ReplaceKey(ref groupLua, "Hidden", GeneratorTools.GetHiddenStatus(Template.OptionsFogOfWar, side, unitMakerGroupFlags)); // If "hidden" was not set through custom values AddUnitGroupToTable(country, UnitCategory.Static, groupLua); BriefingRoom.PrintToLog($"Added group of {DCSID} {coalition} {unitFamily} at {coordinates}"); GroupID++; } } if (unitMakerGroupFlags.HasFlag(UnitMakerGroupFlags.EmbeddedAirDefense) && unitFamily != UnitFamily.StaticStructureOffshore) { var firstUnitID = UnitID; string[] airDefenseUnits = GeneratorTools.GetEmbeddedAirDefenseUnits(Template, side); var groupLua = CreateGroup( "GroupVehicle", coordinates, groupName, extraSettings ); var(unitsLuaTable, embeddedunitsIDList) = AddUnits( airDefenseUnits, groupName, callsign, "UnitVehicle", coordinates, unitMakerGroupFlags, extraSettings ); GeneratorTools.ReplaceKey(ref groupLua, "Units", unitsLuaTable); GeneratorTools.ReplaceKey(ref groupLua, "UnitID", firstUnitID); // Must be after units are added GeneratorTools.ReplaceKey(ref groupLua, "Skill", skill); // Must be after units are added, because skill is set as a unit level GeneratorTools.ReplaceKey(ref groupLua, "Hidden", GeneratorTools.GetHiddenStatus(Template.OptionsFogOfWar, side, unitMakerGroupFlags)); // If "hidden" was not set through custom values GroupID++; unitsIDList.AddRange(embeddedunitsIDList); AddUnitGroupToTable(country, UnitCategory.Vehicle, groupLua); BriefingRoom.PrintToLog($"Added group of Embedded Air Defense for Static {coalition} {unitFamily} at {coordinates}"); } DBEntryUnit firstUnitDB = Database.Instance.GetEntry <DBEntryUnit>(unitSets.First()); if (firstUnitDB == null) { return(new UnitMakerGroupInfo(initalGroupId, coordinates, unitsIDList, groupName)); } return(new UnitMakerGroupInfo(initalGroupId, coordinates, unitsIDList, groupName, firstUnitDB.AircraftData.RadioFrequency, firstUnitDB)); }
private string AddUnit( string DCSID, string groupName, UnitCallsign?callsign, int unitLuaIndex, int unitSetIndex, DBEntryUnit unitDB, string unitTypeLua, Coordinates coordinates, UnitMakerGroupFlags unitMakerGroupFlags, params KeyValuePair <string, object>[] extraSettings) { string unitLuaTemplate = File.ReadAllText($"{BRPaths.INCLUDE_LUA_UNITS}{Toolbox.AddMissingFileExtension(unitTypeLua, ".lua")}"); var groupHeading = GetGroupHeading(coordinates, extraSettings); SetUnitCoordinatesAndHeading(unitDB, unitSetIndex, coordinates, groupHeading, out Coordinates unitCoordinates, out double unitHeading); string singleUnitLuaTable = new string(unitLuaTemplate); if (Toolbox.IsAircraft(unitDB.Category) && (unitLuaIndex == 1) && unitMakerGroupFlags.HasFlag(UnitMakerGroupFlags.FirstUnitIsClient)) { GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "Skill", SinglePlayerMission ? "Player" : "Client"); } foreach (KeyValuePair <string, object> extraSetting in extraSettings) // Replace custom values first so they override other replacements { if (extraSetting.Value is Array) { GeneratorTools.ReplaceKey(ref singleUnitLuaTable, extraSetting.Key, extraSetting.Value, unitLuaIndex - 1); } else { GeneratorTools.ReplaceKey(ref singleUnitLuaTable, extraSetting.Key, extraSetting.Value); } } GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "ExtraLua", unitDB.ExtraLua); GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "Heading", unitHeading); GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "DCSID", DCSID); GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "UnitID", UnitID); GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "UnitX", unitCoordinates.X); GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "UnitY", unitCoordinates.Y); if (Toolbox.IsAircraft(unitDB.Category)) { GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "Callsign", callsign.Value.GetLua(unitLuaIndex)); GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "Name", callsign.Value.GetUnitName(unitLuaIndex)); GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "OnBoardNumber", Toolbox.RandomInt(1, 1000).ToString("000")); GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "PropsLua", unitDB.AircraftData.PropsLua); GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "RadioPresetsLua", string.Join("", unitDB.AircraftData.RadioPresets.Select((x, index) => $"[{index + 1}] = {x.ToLuaString()}"))); GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "Speed", unitDB.AircraftData.CruiseSpeed); GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "PayloadCommon", unitDB.AircraftData.PayloadCommon); var payload = unitDB.AircraftData.GetPayloadLua(extraSettings.Any(x => x.Key == "Payload") ? extraSettings.First(x => x.Key == "Payload").Value.ToString() : "default"); if (extraSettings.Any(x => x.Key == "Payload" && x.Value.ToString() == "EMPTY")) { payload = ""; } GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "PayloadPylons", payload); GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "Livery", extraSettings.Any(x => x.Key == "Livery") ? extraSettings.First(x => x.Key == "Livery").Value : "default"); } else if (unitDB.Category == UnitCategory.Static || unitDB.Category == UnitCategory.Cargo) { if (unitDB.Shape.Length - 1 > unitSetIndex) { GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "Shape", unitDB.Shape[unitSetIndex]); } GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "Name", $"{groupName} {unitLuaIndex}"); } else { GeneratorTools.ReplaceKey(ref singleUnitLuaTable, "Name", $"{groupName} {unitLuaIndex}"); } var unitString = $"[{unitLuaIndex}] =\n"; unitString += "{\n"; unitString += $"{singleUnitLuaTable}\n"; unitString += $"}}, -- end of [{unitLuaIndex}]\n"; return(unitString); }
internal UnitMakerGroupInfo?AddUnitGroup( string[] units, Side side, UnitFamily unitFamily, string groupTypeLua, string unitTypeLua, Coordinates coordinates, UnitMakerGroupFlags unitMakerGroupFlags = 0, params KeyValuePair <string, object>[] extraSettings) { if (units.Length == 0) { return(null); } Coalition coalition = (side == Side.Ally) ? PlayerCoalition : PlayerCoalition.GetEnemy(); Country country = (coalition == Coalition.Blue) ? Country.CJTFBlue : Country.CJTFRed; if (extraSettings.Any(x => x.Key == "Country")) { country = (Country)extraSettings.First(x => x.Key == "Country").Value; } var skill = GeneratorTools.GetDefaultSkillLevel(Template, side); if (extraSettings.Any(x => x.Key == "Skill")) { skill = (DCSSkillLevel)extraSettings.First(x => x.Key == "Skill").Value; } var isUsingSkynet = Template.MissionFeatures.Contains("SkynetIADS"); string groupName; UnitCallsign?callsign = null; if (unitFamily.GetUnitCategory().IsAircraft()) { callsign = CallsignGenerator.GetCallsign(unitFamily, coalition, side, isUsingSkynet); groupName = callsign.Value.GroupName; if (extraSettings.Any(x => x.Key == "PlayerStartingType") && extraSettings.First(x => x.Key == "PlayerStartingType").Value.ToString() == "TakeOffParking") { groupName += "(C)"; } } else { groupName = GeneratorTools.GetGroupName(GroupID, unitFamily, side, isUsingSkynet); } if (unitFamily.GetUnitCategory() == UnitCategory.Static || unitFamily.GetUnitCategory() == UnitCategory.Cargo && unitFamily != UnitFamily.FOB) { return(AddStaticGroup( country, coalition, skill, unitFamily, side, units, groupName, callsign, groupTypeLua, coordinates, unitMakerGroupFlags, extraSettings )); } var groupLua = CreateGroup( groupTypeLua, coordinates, groupName, extraSettings ); int firstUnitID = UnitID; var(unitsLuaTable, unitsIDList) = AddUnits( units, groupName, callsign, unitTypeLua, coordinates, unitMakerGroupFlags, extraSettings ); if (unitsIDList.Count == 0) { return(null); // No valid units added to this group } GeneratorTools.ReplaceKey(ref groupLua, "Units", unitsLuaTable); DBEntryUnit firstUnitDB = units.Select(x => Database.Instance.GetEntry <DBEntryUnit>(x)).First(x => x != null); var aircraftCategories = new UnitCategory[] { UnitCategory.Helicopter, UnitCategory.Plane }; var isAircraft = firstUnitDB != null && aircraftCategories.Contains(firstUnitDB.Category); if (isAircraft) { groupLua = ApplyAircraftFields(groupLua, firstUnitDB, extraSettings); if (unitMakerGroupFlags.HasFlag(UnitMakerGroupFlags.ImmediateAircraftSpawn)) { Mission.AppendValue("AircraftActivatorCurrentQueue", $"{GroupID},"); } else if (unitMakerGroupFlags.HasFlag(UnitMakerGroupFlags.RadioAircraftSpawn)) { Mission.AppendValue("AircraftRadioActivator", $"{{{GroupID}, \"{groupName}\"}},"); } else if (groupTypeLua != "GroupAircraftParkedUncontrolled") { Mission.AppendValue("AircraftActivatorReserveQueue", $"{GroupID},"); } } GeneratorTools.ReplaceKey(ref groupLua, "UnitID", firstUnitID); // Must be after units are added GeneratorTools.ReplaceKey(ref groupLua, "Skill", skill); // Must be after units are added, because skill is set as a unit level GeneratorTools.ReplaceKey(ref groupLua, "Hidden", GeneratorTools.GetHiddenStatus(Template.OptionsFogOfWar, side, unitMakerGroupFlags)); // If "hidden" was not set through custom values AddUnitGroupToTable(country, unitFamily.GetUnitCategory(), groupLua); BriefingRoom.PrintToLog($"Added group of {units.Length} {coalition} {unitFamily} at {coordinates}"); GroupID++; if (firstUnitDB == null) { return(new UnitMakerGroupInfo(GroupID - 1, coordinates, unitsIDList, groupName)); } return(new UnitMakerGroupInfo(GroupID - 1, coordinates, unitsIDList, groupName, firstUnitDB.AircraftData.RadioFrequency, firstUnitDB)); }