Exemplo n.º 1
0
        private Waypoint GenerateObjectiveWaypoint(MissionTemplateObjectiveRecord objectiveTemplate, Coordinates objectiveCoordinates, string objectiveName, MissionTemplateRecord template, bool scriptIgnore = false)
        {
            var AirOnGroundBehaviorLocations = new List <DBEntryObjectiveTargetBehaviorLocation> {
                DBEntryObjectiveTargetBehaviorLocation.SpawnOnAirbaseParking,
                DBEntryObjectiveTargetBehaviorLocation.SpawnOnAirbaseParkingNoHardenedShelter
            };

            var targetDB = Database.Instance.GetEntry <DBEntryObjectiveTarget>(objectiveTemplate.Target);
            var targetBehaviorLocation = Database.Instance.GetEntry <DBEntryObjectiveTargetBehavior>(objectiveTemplate.TargetBehavior).Location;

            if (targetDB == null)
            {
                throw new BriefingRoomException($"Target \"{targetDB.UIDisplayName}\" not found for objective.");
            }

            Coordinates waypointCoordinates = objectiveCoordinates;
            bool        onGround            = !targetDB.UnitCategory.IsAircraft() || AirOnGroundBehaviorLocations.Contains(targetBehaviorLocation); // Ground targets = waypoint on the ground

            var taskDB = Database.Instance.GetEntry <DBEntryObjectiveTask>(objectiveTemplate.Task);

            if (objectiveTemplate.Options.Contains(ObjectiveOption.InaccurateWaypoint) && !TRANSPORT_TASKS.Contains(taskDB.ID))
            {
                waypointCoordinates += Coordinates.CreateRandom(3.0, 6.0) * Toolbox.NM_TO_METERS;
                if (template.OptionsMission.Contains("MarkWaypoints"))
                {
                    DrawingMaker.AddDrawing($"Target Zone {objectiveName}", DrawingType.Circle, waypointCoordinates, "Radius".ToKeyValuePair(6.0 * Toolbox.NM_TO_METERS));
                }
            }
            else if (TRANSPORT_TASKS.Contains(taskDB.ID))
            {
                DrawingMaker.AddDrawing($"Target Zone {objectiveName}", DrawingType.Circle, waypointCoordinates, "Radius".ToKeyValuePair(500));
            }

            return(new Waypoint(objectiveName, waypointCoordinates, onGround, scriptIgnore));
        }
Exemplo n.º 2
0
 private static void AddSubTasks(MissionTemplateObjectiveRecord obj, List <UnitFamily> objectiveTargetUnitFamilies, ref Dictionary <string, List <string> > descriptionsMap, ref int familyCount)
 {
     foreach (var subTask in obj.SubTasks)
     {
         var descriptionDB =
             Database.Instance.GetEntry <DBEntryBriefingDescription>(
                 Database.Instance.GetEntry <DBEntryObjectiveTask>(subTask.Task).BriefingDescription);
         AppendDescription(obj.Task, descriptionDB.DescriptionText[(int)objectiveTargetUnitFamilies[familyCount]], ref descriptionsMap);
         familyCount++;
     }
 }
Exemplo n.º 3
0
        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}\".");
            }
        }
Exemplo n.º 4
0
        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));
        }