コード例 #1
0
        private static void CreateImageFiles(CampaignTemplate campaignTemplate, DCSCampaign campaign, string baseFileName)
        {
            string allyFlagName  = campaignTemplate.GetCoalition(campaignTemplate.ContextPlayerCoalition);
            string enemyFlagName = campaignTemplate.GetCoalition((Coalition)(1 - (int)campaignTemplate.ContextPlayerCoalition));

            ImageMaker imgMaker = new();
            string     theaterImage;

            string[] theaterImages = Directory.GetFiles($"{BRPaths.INCLUDE_JPG}Theaters\\", $"{campaignTemplate.ContextTheater}*.jpg");
            if (theaterImages.Length == 0)
            {
                theaterImage = "_default.jpg";
            }
            else
            {
                theaterImage = "Theaters\\" + Path.GetFileName(Toolbox.RandomFrom(theaterImages));
            }

            // Print the name of the campaign over the campaign "title picture"
            imgMaker.TextOverlay.Text      = campaign.Name;
            imgMaker.TextOverlay.Alignment = ContentAlignment.TopCenter;
            campaign.AddMediaFile($"{baseFileName}_Title.jpg",
                                  imgMaker.GetImageBytes(
                                      new ImageMakerLayer(theaterImage),
                                      new ImageMakerLayer($"Flags\\{enemyFlagName}.png", ContentAlignment.MiddleCenter, -32, -32),
                                      new ImageMakerLayer($"Flags\\{allyFlagName}.png", ContentAlignment.MiddleCenter, 32, 32)));

            // Reset background and text overlay
            imgMaker.BackgroundColor  = Color.Black;
            imgMaker.TextOverlay.Text = "";

            campaign.AddMediaFile($"{baseFileName}_Success.jpg", imgMaker.GetImageBytes("Sky.jpg", $"Flags\\{allyFlagName}.png"));
            campaign.AddMediaFile($"{baseFileName}_Failure.jpg", imgMaker.GetImageBytes("Fire.jpg", $"Flags\\{allyFlagName}.png", "Burning.png"));
        }
コード例 #2
0
        private static string GetCMPFile(CampaignTemplate campaignTemplate, string campaignName)
        {
            string lua = File.ReadAllText(CAMPAIGN_LUA_TEMPLATE);

            GeneratorTools.ReplaceKey(ref lua, "Name", campaignName);
            GeneratorTools.ReplaceKey(ref lua, "Description",
                                      $"This is a {campaignTemplate.ContextCoalitionBlue} vs {campaignTemplate.ContextCoalitionRed} randomly-generated campaign created by an early version of the campaign generator of BriefingRoom, a mission generator for DCS World ({BriefingRoom.WEBSITE_URL}).");
            GeneratorTools.ReplaceKey(ref lua, "Units", "");

            string stagesLua = "";

            for (int i = 0; i < campaignTemplate.MissionsCount; i++)
            {
                string nextStageLua = File.ReadAllText(CAMPAIGN_STAGE_LUA_TEMPLATE);
                GeneratorTools.ReplaceKey(ref nextStageLua, "Index", i + 1);
                GeneratorTools.ReplaceKey(ref nextStageLua, "Name", $"Stage {i + 1}");
                GeneratorTools.ReplaceKey(ref nextStageLua, "Description", $"");
                GeneratorTools.ReplaceKey(ref nextStageLua, "File", $"{campaignName}{i + 1:00}.miz");

                stagesLua += nextStageLua + "\r\n";
            }
            GeneratorTools.ReplaceKey(ref lua, "Stages", stagesLua);

            return(lua.Replace("\r\n", "\n"));
        }
コード例 #3
0
        private static MissionTemplateRecord CreateMissionTemplate(CampaignTemplate campaignTemplate, string campaignName, int missionIndex, int missionCount)
        {
            string weatherPreset = GetWeatherForMission(campaignTemplate.EnvironmentBadWeatherChance);

            MissionTemplate template = new MissionTemplate
            {
                BriefingMissionName        = $"{campaignName}, phase {missionIndex + 1}",
                BriefingMissionDescription = "",

                ContextCoalitionBlue   = campaignTemplate.ContextCoalitionBlue,
                ContextCoalitionRed    = campaignTemplate.ContextCoalitionRed,
                ContextDecade          = campaignTemplate.ContextDecade,
                ContextPlayerCoalition = campaignTemplate.ContextPlayerCoalition,
                ContextTheater         = campaignTemplate.ContextTheater,
                ContextSituation       = campaignTemplate.ContextSituation,

                EnvironmentSeason        = Season.Random,
                EnvironmentTimeOfDay     = GetTimeOfDayForMission(campaignTemplate.EnvironmentNightMissionChance),
                EnvironmentWeatherPreset = weatherPreset,
                EnvironmentWind          = GetWindForMission(campaignTemplate.EnvironmentBadWeatherChance, weatherPreset),

                FlightPlanObjectiveDistance      = GetObjectiveDistance(campaignTemplate.MissionsObjectiveDistance),
                FlightPlanTheaterStartingAirbase = campaignTemplate.PlayerStartingAirbase,

                MissionFeatures = campaignTemplate.MissionsFeatures.ToList(),

                Mods = campaignTemplate.OptionsMods.ToList(),

                Objectives = new(),

                OptionsFogOfWar = campaignTemplate.OptionsFogOfWar,
                OptionsMission  = campaignTemplate.OptionsMission.ToList(),
                OptionsRealism  = campaignTemplate.OptionsRealism.ToList(),

                PlayerFlightGroups = new List <MissionTemplateFlightGroup> {
                    campaignTemplate.Player
                },

                SituationEnemySkill      = GetPowerLevel(campaignTemplate.SituationEnemySkill, campaignTemplate.MissionsDifficultyVariation, missionIndex, missionCount),
                SituationEnemyAirDefense = GetPowerLevel(campaignTemplate.SituationEnemyAirDefense, campaignTemplate.MissionsDifficultyVariation, missionIndex, missionCount),
                SituationEnemyAirForce   = GetPowerLevel(campaignTemplate.SituationEnemyAirForce, campaignTemplate.MissionsDifficultyVariation, missionIndex, missionCount),

                SituationFriendlySkill      = GetPowerLevel(campaignTemplate.SituationFriendlySkill, campaignTemplate.MissionsDifficultyVariation, missionIndex, missionCount, true),
                SituationFriendlyAirDefense = GetPowerLevel(campaignTemplate.SituationFriendlyAirDefense, campaignTemplate.MissionsDifficultyVariation, missionIndex, missionCount, true),
                SituationFriendlyAirForce   = GetPowerLevel(campaignTemplate.SituationFriendlyAirForce, campaignTemplate.MissionsDifficultyVariation, missionIndex, missionCount, true),
            };

            int objectiveCount = GetObjectiveCountForMission(campaignTemplate.MissionsObjectiveCount);

            for (int i = 0; i < objectiveCount; i++)
            {
                template.Objectives.Add(new MissionTemplateObjective(Toolbox.RandomFrom(campaignTemplate.MissionsObjectives)));
            }

            return(new(template));
        }
コード例 #4
0
        private static DateTime GenerateCampaignDate(CampaignTemplate campaignTemplate)
        {
            int   year  = Toolbox.GetRandomYearFromDecade(campaignTemplate.ContextDecade);
            Month month = Toolbox.RandomFrom(Toolbox.GetEnumValues <Month>());
            int   day   = Toolbox.RandomMinMax(1, GeneratorTools.GetDaysPerMonth(month, year));

            DateTime date = new DateTime(year, (int)month + 1, day);

            return(date);
        }
コード例 #5
0
        internal static async Task <DCSCampaign> GenerateAsync(CampaignTemplate campaignTemplate)
        {
            DCSCampaign campaign = new();

            campaign.Name = GeneratorTools.GenerateMissionName(campaignTemplate.BriefingCampaignName);;
            string baseFileName = Toolbox.RemoveInvalidPathCharacters(campaign.Name);

            DateTime date = GenerateCampaignDate(campaignTemplate);

            campaignTemplate.Player.AIWingmen = true; //Make sure wingmen is always true for campaign

            for (int i = 0; i < campaignTemplate.MissionsCount; i++)
            {
                // Increment the date by a few days for each mission after the first
                if (i > 0)
                {
                    date = IncrementDate(date);
                }

                MissionTemplateRecord template = CreateMissionTemplate(campaignTemplate, campaign.Name, i, (int)campaignTemplate.MissionsObjectiveCount);

                DCSMission mission = await MissionGenerator.GenerateAsync(template, true);

                // TODO: mission.DateTime.Day = date.Day; mission.DateTime.Month = date.Month; mission.DateTime.Year = date.Year;
                if (mission == null)
                {
                    BriefingRoom.PrintToLog($"Failed to generate mission {i + 1} in the campaign.", LogMessageErrorLevel.Warning);
                    continue;
                }

                campaign.AddMission(mission);
            }

            if (campaign.MissionCount < 1) // No missions generated, something went very wrong.
            {
                throw new BriefingRoomException($"Campaign has no valid mission.");
            }


            CreateImageFiles(campaignTemplate, campaign, baseFileName);

            campaign.CMPFile = GetCMPFile(campaignTemplate, campaign.Name);

            return(campaign);
        }