Пример #1
0
        private void CreateCMPFile(CampaignTemplate campaignTemplate, string campaignFilePath)
        {
            string campaignName = Path.GetFileNameWithoutExtension(campaignFilePath);

            string lua = LuaTools.ReadIncludeLuaFile("Campaign\\Campaign.lua");

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

            string stagesLua = "";

            for (int i = 0; i < campaignTemplate.MissionsCount; i++)
            {
                string nextStageLua = LuaTools.ReadIncludeLuaFile("Campaign\\CampaignStage.lua");
                LuaTools.ReplaceKey(ref nextStageLua, "Index", i + 1);
                LuaTools.ReplaceKey(ref nextStageLua, "Name", $"Stage {i + 1}");
                LuaTools.ReplaceKey(ref nextStageLua, "Description", $"");
                LuaTools.ReplaceKey(ref nextStageLua, "File", $"{campaignName}{i + 1:00}.miz");

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

            File.WriteAllText(campaignFilePath, lua.Replace("\r\n", "\n"));
        }
Пример #2
0
        public void Generate(CampaignTemplate campaignTemplate, string campaignFilePath)
        {
            string campaignName      = Path.GetFileNameWithoutExtension(campaignFilePath);
            string campaignDirectory = Path.GetDirectoryName(campaignFilePath);

            DCSMissionDateTime date = GenerateCampaignDate(campaignTemplate);

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

                    MissionTemplate template = CreateMissionTemplate(campaignTemplate, i);

                    DCSMission mission = generator.Generate(template);
                    mission.MissionName  = $"{campaignName}, phase {i + 1}";
                    mission.DateTime.Day = date.Day; mission.DateTime.Month = date.Month; mission.DateTime.Year = date.Year;

                    MizFile miz = mission.ExportToMiz();
                    miz.SaveToFile(Path.Combine(campaignDirectory, $"{campaignName}{i + 1:00}.miz"));
                }
            }

            CreateImageFiles(campaignTemplate, campaignFilePath);
            CreateCMPFile(campaignTemplate, campaignFilePath);
        }
Пример #3
0
        private MissionTemplate CreateMissionTemplate(CampaignTemplate campaignTemplate, int index, string campaignName, ref DCSMissionDateTime currentDate)
        {
            // Increment the date by a few days for each mission after the first
            if (index > 0)
            {
                currentDate = IncrementDate(currentDate);
            }

            MissionTemplate template = new MissionTemplate();

            template.BriefingDate.Enabled = true;
            template.BriefingDate.Day     = currentDate.Day;
            template.BriefingDate.Month   = currentDate.Month;
            template.BriefingDate.Year    = currentDate.Year;
            template.BriefingDescription  = "";
            template.BriefingName         = $"{campaignName}, phase {index + 1}";

            template.ContextCoalitionBlue   = campaignTemplate.ContextCoalitionsBlue;
            template.ContextCoalitionPlayer = campaignTemplate.PlayerCoalition;
            template.ContextCoalitionRed    = campaignTemplate.ContextCoalitionsRed;

            template.EnvironmentTimeOfDay = GetTimeOfDayForMission(campaignTemplate.EnvironmentNightMissionChance);
            template.EnvironmentWeather   = GetWeatherForMission(campaignTemplate.EnvironmentBadWeatherChance);
            template.EnvironmentWind      = Wind.Auto;

            template.ObjectiveCount      = GetObjectiveCountForMission(campaignTemplate.MissionsObjectiveCount);
            template.ObjectiveDistanceNM = Database.Instance.Common.DistanceFromTakeOffLocation[(int)campaignTemplate.MissionsObjectiveDistance];
            template.ObjectiveType       = Toolbox.RandomFrom(campaignTemplate.MissionsTypes);

            template.OppositionAirDefense       = GetPowerLevel(campaignTemplate.SituationEnemyAirDefense, campaignTemplate.SituationVariation, index, campaignTemplate.MissionsCount);
            template.OppositionAirForce         = GetPowerLevel(campaignTemplate.SituationEnemyAirForce, campaignTemplate.SituationVariation, index, campaignTemplate.MissionsCount);
            template.OppositionSkillLevelAir    = GetSkillLevel(campaignTemplate.SituationEnemyAirForce, campaignTemplate.SituationVariation, index, campaignTemplate.MissionsCount);
            template.OppositionSkillLevelGround = GetSkillLevel(campaignTemplate.SituationEnemyAirDefense, campaignTemplate.SituationVariation, index, campaignTemplate.MissionsCount);
            template.OppositionUnitsLocation    = SpawnPointPreferredCoalition.Any;

            template.OptionsCivilianTraffic  = campaignTemplate.OptionsCivilianTraffic;
            template.OptionsEndMode          = MissionEndMode.NoEnd;
            template.OptionsPreferences      = campaignTemplate.OptionsPreferences.ToArray();
            template.OptionsRealism          = campaignTemplate.OptionsRealism.ToArray();
            template.OptionsScriptExtensions = new string[0];
            template.OptionsUnitMods         = campaignTemplate.OptionsUnitMods;

            template.PlayerAISkillLevel   = GetSkillLevel(campaignTemplate.SituationFriendlyAirForce, CampaignDifficultyVariation.Steady, 0, 0);
            template.PlayerEscortCAP      = Toolbox.RandomFrom(2, 2, 2, 2, 3, 4, 4);
            template.PlayerEscortSEAD     = Toolbox.RandomFrom(2, 2, 2, 2, 3, 4, 4);
            template.PlayerMPFlightGroups = new MissionTemplateMPFlightGroup[0];
            template.PlayerSPAircraft     = campaignTemplate.PlayerAircraft;
            template.PlayerSPWingmen      = Toolbox.RandomFrom(1, 1, 1, 1, 2, 3, 3);
            template.PlayerStartLocation  = campaignTemplate.PlayerStartLocation;
            template.PlayerSPCarrier      = campaignTemplate.PlayerStartingCarrier;

            template.TheaterID = campaignTemplate.ContextTheaterID;
            template.TheaterRegionsCoalitions = campaignTemplate.ContextTheaterRegionsCoalitions;
            template.TheaterStartingAirbase   = campaignTemplate.PlayerStartingAirbase;

            return(template);
        }
Пример #4
0
        private DCSMissionDateTime GenerateCampaignDate(CampaignTemplate campaignTemplate)
        {
            DCSMissionDateTime date = new DCSMissionDateTime
            {
                Year  = Toolbox.GetRandomYearFromDecade(campaignTemplate.ContextDecade),
                Month = Toolbox.RandomFrom(Toolbox.GetEnumValues <Month>())
            };

            date.Day = Toolbox.RandomMinMax(1, Toolbox.GetDaysPerMonth(date.Month, date.Year));
            return(date);
        }
Пример #5
0
        private MissionTemplate CreateMissionTemplate(CampaignTemplate campaignTemplate, int index)
        {
            MissionTemplate template = new MissionTemplate
            {
                ContextCoalitionBlue   = campaignTemplate.ContextCoalitionsBlue,
                ContextCoalitionPlayer = campaignTemplate.ContextCoalitionPlayer,
                ContextCoalitionRed    = campaignTemplate.ContextCoalitionsRed,

                EnvironmentTimeOfDay = GetTimeOfDayForMission(campaignTemplate.EnvironmentNightMissionChance),
                EnvironmentWeather   = GetWeatherForMission(campaignTemplate.EnvironmentBadWeatherChance),
                EnvironmentWind      = Wind.Auto,

                ObjectiveCount    = GetObjectiveCountForMission(campaignTemplate.MissionsObjectiveCount),
                ObjectiveDistance = MissionTemplate.OBJECTIVE_DISTANCE_INCREMENT * 2 * ((int)campaignTemplate.MissionsObjectiveDistance + 1),
                ObjectiveType     = Toolbox.RandomFrom(campaignTemplate.Objectives),

                SituationEnemyAirDefense       = GetPowerLevel(campaignTemplate.SituationEnemyAirDefense, campaignTemplate.MissionsDifficultyVariation, index, campaignTemplate.MissionsCount),
                SituationEnemyAirForce         = GetPowerLevel(campaignTemplate.SituationEnemyAirForce, campaignTemplate.MissionsDifficultyVariation, index, campaignTemplate.MissionsCount),
                SituationEnemySkillLevelAir    = GetSkillLevel(campaignTemplate.SituationEnemyAirForce, campaignTemplate.MissionsDifficultyVariation, index, campaignTemplate.MissionsCount),
                SituationEnemySkillLevelGround = GetSkillLevel(campaignTemplate.SituationEnemyAirDefense, campaignTemplate.MissionsDifficultyVariation, index, campaignTemplate.MissionsCount),
                OptionsEnemyUnitsLocation      = SpawnPointPreferredCoalition.Any,

                OptionsCivilianTraffic = campaignTemplate.OptionsCivilianTraffic,
                OptionsEndMode         = MissionEndMode.Never,
                //template.OptionsPreferences = campaignTemplate.OptionsPreferences.ToArray();
                Realism          = campaignTemplate.Realism.ToArray(),
                ScriptExtensions = new string[0],
                UnitMods         = campaignTemplate.UnitMods,

                SituationFriendlyAISkillLevel = GetSkillLevel(campaignTemplate.SituationFriendlyAirForce, CampaignDifficultyVariation.Steady, 0, 0),
                SituationFriendlyEscortCAP    = Toolbox.RandomFrom(2, 2, 2, 2, 3, 4, 4),
                SituationFriendlyEscortSEAD   = Toolbox.RandomFrom(2, 2, 2, 2, 3, 4, 4),
                PlayerFlightGroups            = new MissionTemplateFlightGroup[0],
            };

            template.PlayerFlightGroups = new MissionTemplateFlightGroup[]
            { new MissionTemplateFlightGroup(
                  campaignTemplate.PlayerAircraft, Toolbox.RandomFrom(2, 2, 2, 2, 3, 4, 4),
                  MissionTemplateFlightGroupTask.Objectives, campaignTemplate.PlayerCarrier, Country.CJTFBlue, PlayerStartLocation.Runway) };   //TODO Make country selectable

            template.ContextTheater = campaignTemplate.ContextTheaterID;
            template.OptionsTheaterCountriesCoalitions = campaignTemplate.OptionsTheaterCountriesCoalitions;
            template.FlightPlanTheaterStartingAirbase  = campaignTemplate.PlayerStartingAirbase;

            return(template);
        }
Пример #6
0
        private void CreateImageFiles(CampaignTemplate campaignTemplate, string campaignFilePath)
        {
            string baseFileName  = Path.Combine(Path.GetDirectoryName(campaignFilePath), Path.GetFileNameWithoutExtension(campaignFilePath));
            string allyFlagName  = GeneratorTools.RemoveAfterComma(campaignTemplate.GetCoalition(campaignTemplate.PlayerCoalition));
            string enemyFlagName = GeneratorTools.RemoveAfterComma(campaignTemplate.GetCoalition((Coalition)(1 - (int)campaignTemplate.PlayerCoalition)));

            using (ImageMaker imgMaker = new ImageMaker())
            {
                string   theaterImage;
                string[] theaterImages = Directory.GetFiles($"{BRPaths.INCLUDE_JPG}Theaters\\", $"{campaignTemplate.ContextTheaterID}*.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      = Path.GetFileNameWithoutExtension(campaignFilePath);
                imgMaker.TextOverlay.Alignment = ContentAlignment.TopCenter;
                File.WriteAllBytes($"{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 = "";

                File.WriteAllBytes($"{baseFileName}_Success.jpg",
                                   imgMaker.GetImageBytes("Sky.jpg", $"Flags\\{allyFlagName}.png"));

                File.WriteAllBytes($"{baseFileName}_Failure.jpg",
                                   imgMaker.GetImageBytes("Fire.jpg", $"Flags\\{allyFlagName}.png", "Burning.png"));
            }
        }
Пример #7
0
        public void Generate(CampaignTemplate campaignTemplate, string campaignFilePath)
        {
            string campaignName      = Path.GetFileNameWithoutExtension(campaignFilePath);
            string campaignDirectory = Path.GetDirectoryName(campaignFilePath);

            DCSMissionDateTime date = GenerateCampaignDate(campaignTemplate);

            using (MissionGenerator generator = new MissionGenerator())
            {
                for (int i = 0; i < campaignTemplate.MissionsCount; i++)
                {
                    MissionTemplate template = CreateMissionTemplate(campaignTemplate, i, campaignName, ref date);

                    DCSMission mission = generator.Generate(template);
                    MizFile    miz     = mission.ExportToMiz();
                    miz.SaveToFile(Path.Combine(campaignDirectory, $"{campaignName}{i + 1:00}.miz"));
                }
            }

            CreateImageFiles(campaignTemplate, campaignFilePath);
            CreateCMPFile(campaignTemplate, campaignFilePath);
        }