コード例 #1
0
        /// <summary>
        /// Returns an unique callsign in the NATO format (Callsign Number Number)
        /// </summary>
        /// <param name="csFamily">The type of aircraft (AWACS, tanker, fighter...)</param>
        /// <returns>The callsign</returns>
        private MGCallsign GetNATOCallsign(CallsignFamily csFamily)
        {
            int callsignIndex;

            do
            {
                callsignIndex = HQTools.RandomInt(NATO_CALLSIGN_NAMES[(int)csFamily].Length);
            } while (NATOCallsigns[(int)csFamily][callsignIndex] >= 9);

            NATOCallsigns[(int)csFamily][callsignIndex]++;

            string groupName =
                NATO_CALLSIGN_NAMES[(int)csFamily][callsignIndex] + " " +
                HQTools.ValToString(NATOCallsigns[(int)csFamily][callsignIndex]);

            string unitName = groupName + " $INDEX$";
            //string onboardNum = HQTools.ValToString((callsignIndex % 9) + 1) +
            //    NATOCallsigns[(int)csFamily][callsignIndex] + "$INDEX$";
            string lua =
                $"{{ [1]= {HQTools.ValToString(callsignIndex + 1)}, " +
                $"[2]={HQTools.ValToString(NATOCallsigns[(int)csFamily][callsignIndex])}, " +
                "[3]=$INDEX$, " +
                $"[\"name\"] = \"{unitName.Replace(" ", "")}\", }}";

            return(new MGCallsign(groupName, unitName /*, onboardNum*/, lua));
        }
コード例 #2
0
        // Adds "embedded" air defense to ground vehicle groups
        public void AddAirDefenseUnits(DefinitionCoalition army, TimePeriod timePeriod, LibraryCommonSettingsEnemyAirDefense airDefenseSettings)
        {
            if (Category != UnitCategory.Vehicle)
            {
                return;
            }

            List <string> unitList = new List <string>(Units);

            if (HQTools.RandomDouble() < airDefenseSettings.EmbeddedChance)
            {
                int airDefCount = airDefenseSettings.EmbeddedCount.GetValue();

                for (int i = 0; i < airDefCount; i++)
                {
                    string airDefUnit =
                        HQTools.RandomFrom(
                            army.GetUnits(timePeriod, HQTools.RandomFrom(airDefenseSettings.EmbeddedFamilies), true, false));
                    if (airDefUnit == null)
                    {
                        continue;
                    }

                    unitList.Add(airDefUnit);
                }
            }

            // Randomize list order so air defense units are not always at the end
            Units = unitList.OrderBy(x => HQTools.RandomInt()).ToList();

            CheckAbsolueMaxUnitCount();
        }
コード例 #3
0
        /// <summary>
        /// Picks a starting time for the mission.
        /// Must be called after mission date has been set because sunrise/sunset time changes every month.
        /// </summary>
        /// <param name="mission">The mission.</param>
        /// <param name="timeOfDay">The preferred time of day (noon, dawn, twilight, night, random...)</param>
        /// <param name="theater">Theater definition from which to get sunrise/sunset time.</param>
        public void GenerateMissionTime(DCSMission mission, TimeOfDay timeOfDay, DefinitionTheater theater)
        {
            DebugLog.Instance.Log("Generating mission starting time...");

            double fullTime;

            DebugLog.Instance.Log($"  Mission should start at {timeOfDay.ToString().ToUpperInvariant()}");

            switch (timeOfDay)
            {
            default:     // aka TimeOfDay.Random;
                mission.TimeHour   = HQTools.RandomInt(0, 24);
                mission.TimeMinute = HQTools.RandomInt(0, 4) * 15;
                return;

            case TimeOfDay.RandomDaytime:
                fullTime = HQTools.RandomInt(theater.DayTime[(int)mission.DateMonth].Min, theater.DayTime[(int)mission.DateMonth].Max - 60);
                break;

            case TimeOfDay.Dawn:
                fullTime = HQTools.RandomInt(theater.DayTime[(int)mission.DateMonth].Min, theater.DayTime[(int)mission.DateMonth].Min + 120);
                break;

            case TimeOfDay.Noon:
                fullTime = HQTools.RandomInt(
                    (theater.DayTime[(int)mission.DateMonth].Min + theater.DayTime[(int)mission.DateMonth].Max) / 2 - 90,
                    (theater.DayTime[(int)mission.DateMonth].Min + theater.DayTime[(int)mission.DateMonth].Max) / 2 + 90);
                break;

            case TimeOfDay.Twilight:
                fullTime = HQTools.RandomInt(theater.DayTime[(int)mission.DateMonth].Max - 120, theater.DayTime[(int)mission.DateMonth].Max + 30);
                break;

            case TimeOfDay.Night:
                fullTime = HQTools.RandomInt(0, theater.DayTime[(int)mission.DateMonth].Min - 120);
                break;
            }

            mission.TimeHour   = HQTools.Clamp((int)Math.Floor(fullTime / 60), 0, 23);
            mission.TimeMinute = HQTools.Clamp((int)Math.Floor((fullTime - mission.TimeHour * 60) / 15) * 15, 0, 45);

            DebugLog.Instance.Log($"    Starting time set to {mission.TimeHour.ToString("00")}:{mission.TimeMinute.ToString("00")}");
            DebugLog.Instance.Log();
        }
コード例 #4
0
 /// <summary>
 /// Returns the rotation (in radians) of an unit according to its formation and its index.
 /// </summary>
 /// <param name="unitIndex">The 0-based index of the unit</param>
 /// <returns>The rotation of the unit, in radians.</returns>
 public double GetUnitHeading(int unitIndex)
 {
     // TODO: return proper rotation according to formation
     return(HQTools.RandomInt(360) * HQTools.DEGREES_TO_RADIANS);
 }
コード例 #5
0
        /// <summary>
        /// Picks a date (day, month and year) for the mission.
        /// </summary>
        /// <param name="mission">The mission.</param>
        /// <param name="timePeriod">The time period (decade) during which the mission is supposed to take place.</param>
        /// <param name="season">The season during which the mission is supposed to take place.</param>
        public void GenerateMissionDate(DCSMission mission, TimePeriod timePeriod, Season season)
        {
            DebugLog.Instance.Log("Generating mission date...");

            DebugLog.Instance.Log($"  Mission should take place during the {timePeriod.ToString().Substring(6)}s");
            switch (timePeriod)
            {
            case TimePeriod.Decade1940: mission.DateYear = HQTools.RandomInt(1940, 1950); break;

            case TimePeriod.Decade1950: mission.DateYear = HQTools.RandomInt(1950, 1960); break;

            case TimePeriod.Decade1960: mission.DateYear = HQTools.RandomInt(1960, 1970); break;

            case TimePeriod.Decade1970: mission.DateYear = HQTools.RandomInt(1970, 1980); break;

            case TimePeriod.Decade1980: mission.DateYear = HQTools.RandomInt(1980, 1990); break;

            case TimePeriod.Decade1990: mission.DateYear = HQTools.RandomInt(1990, 2000); break;

            default: mission.DateYear = HQTools.RandomInt(2000, 2010); break;     // default is TimePeriod.Decade2000

            case TimePeriod.Decade2010: mission.DateYear = HQTools.RandomInt(2010, 2020); break;
            }
            DebugLog.Instance.Log($"    Year set to {mission.DateYear}.");

            DebugLog.Instance.Log($"  Mission should take place during the {season.ToString().ToUpperInvariant()} season");
            Month[] months = new Month[0];
            switch (season)
            {
            case Season.Spring: months = new Month[] { Month.March, Month.April, Month.May, Month.June }; break;

            case Season.Summer: months = new Month[] { Month.June, Month.July, Month.August, Month.September }; break;

            case Season.Fall: months = new Month[] { Month.September, Month.October, Month.November, Month.December }; break;

            case Season.Winter: months = new Month[] { Month.December, Month.January, Month.February, Month.March }; break;

            default: break;     // default is Season.Random
            }

            if (months.Length == 0) // Season.Random
            {
                mission.DateMonth = (Month)HQTools.RandomInt(12);
                mission.DateDay   = HQTools.RandomMinMax(1, GetDaysPerMonth(mission.DateMonth, mission.DateYear));
            }
            else
            {
                int mID = HQTools.RandomInt(4);
                mission.DateMonth = months[mID];
                switch (mID)
                {
                case 0: mission.DateDay = HQTools.RandomMinMax(21, GetDaysPerMonth(mission.DateMonth, mission.DateYear)); break; // First month of the season

                case 3: mission.DateDay = HQTools.RandomMinMax(1, 20); break;                                                    // Last month of the season

                default: mission.DateDay = HQTools.RandomMinMax(1, GetDaysPerMonth(mission.DateMonth, mission.DateYear)); break;
                }
            }

            DebugLog.Instance.Log($"    Month set to {mission.DateMonth}.");
            DebugLog.Instance.Log($"    Day set to {mission.DateDay}.");

            DebugLog.Instance.Log();
        }
コード例 #6
0
        /// <summary>
        /// Generates wind settings for the mission. Must be called once mission weather level has been set, as weather is used for auto wind.
        /// </summary>
        /// <param name="mission">The mission.</param>
        /// <param name="wind">The preferred wind speed.</param>
        /// <param name="theater">Theater definition from which to get wind info for this part of the world.</param>
        public void GenerateWind(DCSMission mission, Wind wind, DefinitionTheater theater)
        {
            DebugLog.Instance.Log("Generating wind...");

            DebugLog.Instance.Log($"  Wind speed should be {wind.ToString().ToUpperInvariant()}");

            // If auto, speed depends on weather, so we never end up with no wind in a storm
            mission.WindLevel = (wind == Wind.Auto) ?
                                (Wind)(HQTools.Clamp((int)mission.WeatherLevel + HQTools.RandomMinMax(-1, 1), 0, (int)Wind.StrongGale))
                : wind;

            DebugLog.Instance.Log($"    Wind speed level set to {mission.WindLevel}");

            for (int i = 0; i < 3; i++)
            {
                mission.WeatherWindSpeed[i]     = Math.Max(0, theater.Wind[(int)mission.WindLevel].Wind.GetValue());
                mission.WeatherWindDirection[i] = (mission.WeatherWindSpeed[i] > 0) ? HQTools.RandomInt(0, 360) : 0;
                DebugLog.Instance.Log($"    Wind speed at {WIND_ALTITUDE[i]} meters set to {mission.WeatherWindSpeed[i]} m/s, direction of {mission.WeatherWindDirection[i]}");
            }

            // Turbulence = max(weatherTurbulence, windTurbulence)
            mission.WeatherTurbulence = Math.Max(mission.WeatherTurbulence, theater.Wind[(int)mission.WindLevel].Turbulence.GetValue());
            DebugLog.Instance.Log($"    Turbulence updated to {mission.WeatherTurbulence} m/s");

            DebugLog.Instance.Log();
        }