//----------------SUB TASK SUPPORT FUNCTIONS------------------------------- private static void GetSubTaskData(MissionTemplateSubTask objectiveTemplate, out DBEntryObjectiveTarget targetDB, out DBEntryObjectiveTargetBehavior targetBehaviorDB, out DBEntryObjectiveTask taskDB, out ObjectiveOption[] objectiveOptions) { targetDB = Database.Instance.GetEntry <DBEntryObjectiveTarget>(objectiveTemplate.Target); targetBehaviorDB = Database.Instance.GetEntry <DBEntryObjectiveTargetBehavior>(objectiveTemplate.TargetBehavior); taskDB = Database.Instance.GetEntry <DBEntryObjectiveTask>(objectiveTemplate.Task); objectiveOptions = objectiveTemplate.Options.ToArray(); if (targetDB == null) { throw new BriefingRoomException($"Target \"{targetDB.UIDisplayName}\" not found for objective."); } if (targetBehaviorDB == null) { throw new BriefingRoomException($"Target behavior \"{targetBehaviorDB.UIDisplayName}\" not found for objective."); } if (taskDB == null) { throw new BriefingRoomException($"Task \"{taskDB.UIDisplayName}\" not found for objective."); } if (!taskDB.ValidUnitCategories.Contains(targetDB.UnitCategory)) { throw new BriefingRoomException($"Task \"{taskDB.UIDisplayName}\" not valid for objective targets, which belong to category \"{targetDB.UnitCategory}\"."); } }
private static void GetObjectiveData(MissionTemplateObjectiveRecord objectiveTemplate, bool useObjectivePreset, out string[] featuresID, out DBEntryObjectiveTarget targetDB, out DBEntryObjectiveTargetBehavior targetBehaviorDB, out DBEntryObjectiveTask taskDB, out ObjectiveOption[] objectiveOptions) { featuresID = objectiveTemplate.Features.ToArray(); targetDB = Database.Instance.GetEntry <DBEntryObjectiveTarget>(objectiveTemplate.Target); targetBehaviorDB = Database.Instance.GetEntry <DBEntryObjectiveTargetBehavior>(objectiveTemplate.TargetBehavior); taskDB = Database.Instance.GetEntry <DBEntryObjectiveTask>(objectiveTemplate.Task); objectiveOptions = objectiveTemplate.Options.ToArray(); if (useObjectivePreset && objectiveTemplate.Preset != "Custom") { DBEntryObjectivePreset presetDB = Database.Instance.GetEntry <DBEntryObjectivePreset>(objectiveTemplate.Preset); if (presetDB != null) { featuresID = presetDB.Features.ToArray(); targetDB = Database.Instance.GetEntry <DBEntryObjectiveTarget>(Toolbox.RandomFrom(presetDB.Targets)); targetBehaviorDB = Database.Instance.GetEntry <DBEntryObjectiveTargetBehavior>(Toolbox.RandomFrom(presetDB.TargetsBehaviors)); taskDB = Database.Instance.GetEntry <DBEntryObjectiveTask>(Toolbox.RandomFrom(presetDB.Tasks)); objectiveOptions = presetDB.Options.ToArray(); } } if (targetDB == null) { throw new BriefingRoomException($"Target \"{targetDB.UIDisplayName}\" not found for objective."); } if (targetBehaviorDB == null) { throw new BriefingRoomException($"Target behavior \"{targetBehaviorDB.UIDisplayName}\" not found for objective."); } if (taskDB == null) { throw new BriefingRoomException($"Task \"{taskDB.UIDisplayName}\" not found for objective."); } if (!taskDB.ValidUnitCategories.Contains(targetDB.UnitCategory)) { throw new BriefingRoomException($"Task \"{taskDB.UIDisplayName}\" not valid for objective targets, which belong to category \"{targetDB.UnitCategory}\"."); } }
private void AddEmbeddedAirDefenseUnits(MissionTemplateRecord template, DBEntryObjectiveTarget targetDB, DBEntryObjectiveTargetBehavior targetBehaviorDB, DBEntryObjectiveTask taskDB, ObjectiveOption[] objectiveOptions, Coordinates objectiveCoordinates, UnitMakerGroupFlags groupFlags, List <KeyValuePair <string, object> > extraSettings) { // Static targets (aka buildings) need to have their "embedded" air defenses spawned in another group string[] airDefenseUnits = GeneratorTools.GetEmbeddedAirDefenseUnits(template, taskDB.TargetSide); if (airDefenseUnits.Length > 0) { UnitMaker.AddUnitGroup( airDefenseUnits, taskDB.TargetSide, UnitFamily.VehicleAAA, targetBehaviorDB.GroupLua[(int)targetDB.UnitCategory], targetBehaviorDB.UnitLua[(int)targetDB.UnitCategory], objectiveCoordinates + Coordinates.CreateRandom(100, 500), groupFlags, extraSettings.ToArray()); } }
private Coordinates PlaceInAirbase(MissionTemplateRecord template, DBEntrySituation situationDB, DBEntryAirbase playerAirbase, List <KeyValuePair <string, object> > extraSettings, DBEntryObjectiveTarget targetDB, DBEntryObjectiveTargetBehavior targetBehaviorDB, ref string luaUnit, Coordinates objectiveCoordinates, int unitCount, UnitFamily objectiveTargetUnitFamily) { int airbaseID = 0; var parkingSpotIDsList = new List <int>(); var parkingSpotCoordinatesList = new List <Coordinates>(); var targetAirbaseOptions = (from DBEntryAirbase airbaseDB in situationDB.GetAirbases(template.OptionsMission.Contains("InvertCountriesCoalitions")) where airbaseDB.DCSID != playerAirbase.DCSID select airbaseDB).OrderBy(x => x.Coordinates.GetDistanceFrom(objectiveCoordinates)); DBEntryAirbase targetAirbase = targetAirbaseOptions.FirstOrDefault(x => template.OptionsMission.Contains("SpawnAnywhere") ? true : x.Coalition == template.ContextPlayerCoalition.GetEnemy()); airbaseID = targetAirbase.DCSID; var parkingSpots = UnitMaker.SpawnPointSelector.GetFreeParkingSpots( targetAirbase.DCSID, unitCount, objectiveTargetUnitFamily, targetBehaviorDB.Location == DBEntryObjectiveTargetBehaviorLocation.SpawnOnAirbaseParkingNoHardenedShelter); parkingSpotIDsList = parkingSpots.Select(x => x.DCSID).ToList(); parkingSpotCoordinatesList = parkingSpots.Select(x => x.Coordinates).ToList(); luaUnit += "Parked"; extraSettings.Add("GroupAirbaseID".ToKeyValuePair(airbaseID)); extraSettings.Add("ParkingID".ToKeyValuePair(parkingSpotIDsList.ToArray())); extraSettings.Add("UnitX".ToKeyValuePair((from Coordinates coordinates in parkingSpotCoordinatesList select coordinates.X).ToArray())); extraSettings.Add("UnitY".ToKeyValuePair((from Coordinates coordinates in parkingSpotCoordinatesList select coordinates.Y).ToArray())); return(targetAirbase.Coordinates); }