Ejemplo n.º 1
0
        public DefinitionTheaterSpawnPoint(INIFile ini, string key) : this()
        {
            string[] vals = ini.GetValueArray <string>("SpawnPoints", key, ',');
            IsValid  = true;
            UniqueID = key;

            if (vals.Length < 4)
            {
                IsValid = false; return;
            }

            try
            {
                Coordinates = new Coordinates(HQTools.StringToDouble(vals[0]), HQTools.StringToDouble(vals[1]));
                PointType   = (TheaterLocationSpawnPointType)Enum.Parse(typeof(TheaterLocationSpawnPointType), vals[2], true);
                Country     = (DCSCountry)Enum.Parse(typeof(DCSCountry), vals[3], true);
            }
            catch (Exception)
            {
                IsValid = false;
            }
        }
Ejemplo n.º 2
0
        protected override bool OnLoad(INIFile ini)
        {
            BriefingDescription = ini.GetValue <string>("Objective", "Briefing.Description");
            BriefingRemarks     = ini.GetValueArray <string>("Objective", "Briefing.Remarks");
            BriefingTask        = ini.GetValue <string>("Objective", "Briefing.Task");

            FGTasking = ini.GetValue <DCSFlightGroupTask>("Objective", "FlightGroup.Tasking");

            IncludeLua = new string[HQTools.EnumCount <ObjectiveScriptRepetition>(), HQTools.EnumCount <ObjectiveScriptScope>()][];
            foreach (ObjectiveScriptRepetition rep in HQTools.EnumValues <ObjectiveScriptRepetition>())
            {
                foreach (ObjectiveScriptScope scope in HQTools.EnumValues <ObjectiveScriptScope>())
                {
                    IncludeLua[(int)rep, (int)scope] = ini.GetValueArray <string>("Include", $"Lua.{rep}.{scope}");
                }
            }
            IncludeOgg = ini.GetValueArray <string>("Include", "Ogg");

            SpawnPointType = ini.GetValueArray <TheaterLocationSpawnPointType>("Objective", "SpawnPoint.Type");
            if (SpawnPointType.Length == 0)
            {
                SpawnPointType = new TheaterLocationSpawnPointType[] { TheaterLocationSpawnPointType.LandMedium, TheaterLocationSpawnPointType.LandLarge }
            }
            ;

            WaypointInaccuracy = ini.GetValue <MinMaxD>("Objective", "Waypoint.Inaccuracy");
            WaypointOnGround   = ini.GetValue <bool>("Objective", "Waypoint.OnGround");

            UnitGroups = new DefinitionObjectiveUnitGroup[HQTools.EnumCount <ObjectiveUnitGroupRole>()];

            foreach (ObjectiveUnitGroupRole role in HQTools.EnumValues <ObjectiveUnitGroupRole>())
            {
                UnitGroups[(int)role] = new DefinitionObjectiveUnitGroup(ini, role.ToString());
            }

            return(true);
        }
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Add surface-to-air defense groups.
        /// </summary>
        /// <param name="mission">Mission to which generated units should be added</param>
        /// <param name="template">Mission template to use</param>
        /// <param name="airDefenseRange">Air-defense range category</param>
        /// <param name="enemyCoalitionDB">Enemy coalition database entry</param>
        /// <param name="coalition">Coalition of the spawn points air defense must be spawned at, or null to spawn them anywhere</param>
        /// <param name="unitMods">Unit mods the units can belong to</param>
        private void AddAirDefenseUnits(DCSMission mission, AirDefenseRange airDefenseRange, DBEntryCoalition enemyCoalitionDB, Coalition?coalition, string[] unitMods)
        {
            // Get the proper number of groups
            int groupCount = Database.Instance.Common.
                             EnemyAirDefense[(int)airDefense].GroupsInArea[(int)airDefenseRange].GetValue();

            if (groupCount < 1)
            {
                return;                  // No groups to add, no need to go any further
            }
            DCSMissionUnitGroupFlags flags = optionsShowEnemyUnits;

            UnitFamily[] unitFamilies;
            TheaterLocationSpawnPointType[] validSpawnPoints;
            switch (airDefenseRange)
            {
            default:     // case AirDefenseRange.ShortRange:
                unitFamilies     = new UnitFamily[] { UnitFamily.VehicleAAA, UnitFamily.VehicleAAAStatic, UnitFamily.VehicleInfantryMANPADS, UnitFamily.VehicleSAMShort, UnitFamily.VehicleSAMShort, UnitFamily.VehicleSAMShortIR, UnitFamily.VehicleSAMShortIR };
                validSpawnPoints = new TheaterLocationSpawnPointType[] { TheaterLocationSpawnPointType.LandSmall, TheaterLocationSpawnPointType.LandMedium, TheaterLocationSpawnPointType.LandLarge };
                break;

            case AirDefenseRange.MediumRange:
                unitFamilies     = new UnitFamily[] { UnitFamily.VehicleSAMMedium };
                validSpawnPoints = new TheaterLocationSpawnPointType[] { TheaterLocationSpawnPointType.LandMedium, TheaterLocationSpawnPointType.LandLarge };
                break;

            case AirDefenseRange.LongRange:
                unitFamilies     = new UnitFamily[] { UnitFamily.VehicleSAMLong };
                validSpawnPoints = new TheaterLocationSpawnPointType[] { TheaterLocationSpawnPointType.LandLarge };
                break;
            }

            for (int i = 0; i < groupCount; i++)
            {
                // Find spawn point at the proper distance from the objective(s), but not to close from starting airbase
                DBEntryTheaterSpawnPoint?spawnPoint =
                    UnitMaker.SpawnPointSelector.GetRandomSpawnPoint(
                        validSpawnPoints,
                        centerPoint,
                        distsFromCenter[(int)airDefenseRange],
                        opposingPoint,
                        new MinMaxD(minDistFromOpposingPoint[(int)airDefenseRange], 99999),
                        coalition);

                // No spawn point found, stop here.
                if (!spawnPoint.HasValue)
                {
                    DebugLog.Instance.WriteLine($"No spawn point found for {airDefenseRange} air defense unit groups", 1, DebugLogMessageErrorLevel.Warning);
                    return;
                }

                string[] units = enemyCoalitionDB.GetRandomUnits(Toolbox.RandomFrom(unitFamilies), mission.DateTime.Decade, 1, unitMods);

                DCSMissionUnitGroup group = UnitMaker.AddUnitGroup(
                    mission, units, ally? Side.Ally : Side.Enemy,
                    spawnPoint.Value.Coordinates,
                    "GroupVehicle", "UnitVehicle",
                    Toolbox.BRSkillLevelToDCSSkillLevel(skillLevel),
                    flags);

                if (group == null)
                {
                    DebugLog.Instance.WriteLine($"Failed to add {airDefenseRange} air defense unit group of type {units[0]}", 1, DebugLogMessageErrorLevel.Warning);
                }
            }
        }