コード例 #1
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);
        }
コード例 #2
0
        public void can_generate_mission()
        {
            var sut    = new MissionGenerator();
            var result = sut.Generate(3, 4, 7, 5);

            Assert.Equal(5, result.Answer.Count);
            Assert.Equal(4, result.Rotors.Count);
            Assert.True(sut.CheckAnswer(result, result.Answer.ToArray()));
        }
コード例 #3
0
        public void can_generate_at_maximum()
        {
            var sut    = new MissionGenerator();
            var result = sut.Generate(12, 12, 132, 10);

            Assert.Equal(10, result.Answer.Count);
            Assert.Equal(12, result.Rotors.Count);
            Assert.True(result.Rotors.TrueForAll(x => x.CurrentState == 2));
            Assert.True(sut.CheckAnswer(result, result.Answer.ToArray()));
        }
コード例 #4
0
        public void can_generate_at_small(int sublevel)
        {
            var level       = 1;
            var difficulty  = ((level - 1) * 5 + sublevel) + 1;
            var numTick     = level + 1;
            var numRotor    = sublevel + 1;
            var numMove     = Math.Max(4, difficulty / 3);
            var numRelation = Math.Max(numRotor - 1, Convert.ToInt32(Math.Floor(numRotor * (numRotor - 1) * Math.Min(1.0, (double)difficulty / 25) * 0.6)));

            var sut    = new MissionGenerator();
            var result = sut.Generate(numTick, numRotor, numRelation, numMove);

            Assert.True(sut.CheckAnswer(result, result.Answer.ToArray()));
        }
コード例 #5
0
        private void GenerateMission()
        {
            ToggleMissionButtonsEnabled(false);

            Mission = Generator.Generate(Template);
            PrintStatusLabelOutput("Mission generation");

            if (Mission == null) // Something went wrong during the mission generation
            {
                UpdateHTMLBriefing($"<p><strong>Mission generation failed</strong></p><p>{StatusLabel.Text}</p>");
                return;
            }

            ToggleMissionButtonsEnabled(true);
            UpdateHTMLBriefing(Mission.BriefingHTML);
        }
コード例 #6
0
        /// <summary>
        /// Generates mission(s) from command line arguments.
        /// </summary>
        /// <param name="args">Command line arguments</param>
        /// <returns>True if everything when wrong, false otherwise</returns>
        public bool DoCommandLine(params string[] args)
        {
            ParseCommandLineArguments(args, out string[] templateFiles, out int missionCount);

            if (templateFiles.Length == 0)
            {
                DebugLog.Instance.WriteLine("No mission template files provided", DebugLogMessageErrorLevel.Error);
                return(false);
            }

            using (MissionGenerator generator = new MissionGenerator())
            {
                foreach (string t in templateFiles)
                {
                    using (MissionTemplate template = new MissionTemplate(t))
                    {
                        for (int i = 0; i < missionCount; i++)
                        {
                            DCSMission mission = generator.Generate(template);
                            if (mission == null)
                            {
                                DebugLog.Instance.WriteLine($"Failed to generate a mission from template {Path.GetFileName(t)}", DebugLogMessageErrorLevel.Warning);
                                continue;
                            }

                            string mizFileName = Path.Combine(Application.StartupPath, Path.GetFileNameWithoutExtension(t) + ".miz");
                            mizFileName = GetUnusedFileName(mizFileName);

                            MizFile miz = mission.ExportToMiz();
                            if ((miz == null) || !miz.SaveToFile(mizFileName))
                            {
                                DebugLog.Instance.WriteLine($"Failed to export .miz file from template {Path.GetFileName(t)}", DebugLogMessageErrorLevel.Warning);
                                continue;
                            }
                            else
                            {
                                DebugLog.Instance.WriteLine($"Mission {Path.GetFileName(mizFileName)} exported to .miz file from template {Path.GetFileName(t)}");
                            }
                        }
                    }
                }
            }

            return(true);
        }
コード例 #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);
        }
コード例 #8
0
        public RawControls(MissionGenerator mg, int yPosition)
        {
            this.yPosition   = yPosition;
            MissionGenerator = mg;

            NumOfMission = mg.NumOfMission;

            CheckBox = new CheckBox()
            {
                Location = new Point(25, yPosition),
                Checked  = false,
                Font     = new Font(new FontFamily("Arial"), 16, FontStyle.Regular, GraphicsUnit.Pixel),
                Text     = $"{mg.MissionName}",
                AutoSize = true
            };
#if DEBUG
            this.CheckBox.Text = $"{NumOfMission}. {this.CheckBox.Text}";
#endif
            Numeric = new NumericUpDown()
            {
                Location = new Point(CheckBox.Location.X + 500, CheckBox.Location.Y),
                Maximum  = mg.MaxNumInTest,
                Value    = 1,
                Width    = 50,
                Enabled  = false
            };
            OfMax = new Label()
            {
                Location = new Point(CheckBox.Location.X + 500, CheckBox.Location.Y),
                Text     = $"из {mg.MaxNumInTest}",
                Visible  = true
            };
            string timeToSolve = ((double)mg.TimeToSolveMission / 60.0).ToString("0.#") + " мин";
            TimeToSolve = new Label()
            {
                Location = new Point(CheckBox.Location.X + 600, yPosition),
                Text     = timeToSolve,
                Font     = new Font(new FontFamily("Arial"), 12, FontStyle.Regular, GraphicsUnit.Pixel),
                AutoSize = false
            };
            MissionType = new Label()
            {
                Location = new Point(CheckBox.Location.X + 700, yPosition),
                Text     = GlobalExtentions.GetStringMissionType(mg.TypeOfMission),
                Font     = new Font(new FontFamily("Arial"), 12, FontStyle.Regular, GraphicsUnit.Pixel),
                AutoSize = false
            };
            Preview = new Button()
            {
                //Text = "Предпросмотр",
                Location              = new Point(CheckBox.Location.X + 800, CheckBox.Location.Y),
                Width                 = 30,
                Height                = 15,
                BackgroundImage       = Properties.Resources.view,
                BackgroundImageLayout = ImageLayout.Stretch
            };

            Preview.Click += (s, e) =>
            {
                TabPage tab         = mg.Generate().GetTabPage(true);
                Form    previewForm = new Form()
                {
                    Width         = 900,
                    Height        = 550,
                    Icon          = Properties.Resources.icon,
                    Text          = $"Предпросмотр задания {NumOfMission} \"{mg.MissionName}\"",
                    StartPosition = FormStartPosition.CenterScreen
                };

                TabControl tc = new TabControl()
                {
                    Dock = DockStyle.Fill
                };
                tc.Controls.Add(tab);

                previewForm.Controls.Add(tc);

                StyleApply.ForForm(previewForm, changeHeader: false);

                previewForm.ShowDialog();
            };
            RegisterEventsToControls();
        }