Ejemplo n.º 1
0
        internal static string[] GetEmbeddedAirDefenseUnits(MissionTemplateRecord template, Side side, Country?country = null)
        {
            DBCommonAirDefenseLevel airDefenseInfo = (side == Side.Ally) ?
                                                     Database.Instance.Common.AirDefense.AirDefenseLevels[(int)template.SituationFriendlyAirDefense.Get()] :
                                                     Database.Instance.Common.AirDefense.AirDefenseLevels[(int)template.SituationEnemyAirDefense.Get()];

            DBEntryCoalition unitsCoalitionDB = Database.Instance.GetEntry <DBEntryCoalition>(template.GetCoalitionID(side));

            if (unitsCoalitionDB == null)
            {
                return(new string[0]);
            }

            List <string> units = new List <string>();

            if (Toolbox.RandomDouble() >= airDefenseInfo.EmbeddedChance)
            {
                return(new string[0]);
            }

            int airDefenseUnitsCount = airDefenseInfo.EmbeddedUnitCount.GetValue();

            for (int i = 0; i < airDefenseUnitsCount; i++)
            {
                var families = new List <UnitFamily> {
                    UnitFamily.VehicleAAA, UnitFamily.VehicleAAA, UnitFamily.VehicleSAMShortIR, UnitFamily.VehicleSAMShortIR, UnitFamily.VehicleSAMShort
                };
                units.AddRange(unitsCoalitionDB.GetRandomUnits(families, template.ContextDecade, 1, template.Mods, country).Item2);
            }

            return(units.ToArray());
        }
Ejemplo n.º 2
0
        private static void CreateAirDefenseGroups(
            MissionTemplateRecord template, UnitMaker unitMaker, Side side, Coalition coalition,
            AmountNR airDefenseAmount, AirDefenseRange airDefenseRange,
            Coordinates centerPoint, Coordinates opposingPoint)
        {
            var commonAirDefenseDB = Database.Instance.Common.AirDefense;
            DBCommonAirDefenseLevel airDefenseLevelDB = commonAirDefenseDB.AirDefenseLevels[(int)airDefenseAmount];

            int groupCount = airDefenseLevelDB.GroupsInArea[(int)airDefenseRange].GetValue();

            if (groupCount < 1)
            {
                return;                  // No groups to add, no need to go any further
            }
            List <UnitFamily> unitFamilies;

            SpawnPointType[] validSpawnPoints;
            switch (airDefenseRange)
            {
            case AirDefenseRange.MediumRange:
                unitFamilies = new List <UnitFamily> {
                    UnitFamily.VehicleSAMMedium
                };
                validSpawnPoints = new SpawnPointType[] { SpawnPointType.LandLarge };
                break;

            case AirDefenseRange.LongRange:
                unitFamilies = new List <UnitFamily> {
                    UnitFamily.VehicleSAMLong
                };
                validSpawnPoints = new SpawnPointType[] { SpawnPointType.LandLarge };
                break;

            default:     // case AirDefenseRange.ShortRange:
                unitFamilies = new List <UnitFamily> {
                    UnitFamily.VehicleAAA, UnitFamily.VehicleAAAStatic, UnitFamily.VehicleInfantryMANPADS, UnitFamily.VehicleSAMShort, UnitFamily.VehicleSAMShort, UnitFamily.VehicleSAMShortIR, UnitFamily.VehicleSAMShortIR
                };
                validSpawnPoints = new SpawnPointType[] { SpawnPointType.LandSmall, SpawnPointType.LandMedium, SpawnPointType.LandLarge };
                break;
            }

            for (int i = 0; i < groupCount; i++)
            {
                // Find spawn point at the proper distance
                Coordinates?spawnPoint =
                    unitMaker.SpawnPointSelector.GetRandomSpawnPoint(
                        validSpawnPoints,
                        centerPoint,
                        commonAirDefenseDB.DistanceFromCenter[(int)side, (int)airDefenseRange],
                        opposingPoint,
                        new MinMaxD(commonAirDefenseDB.MinDistanceFromOpposingPoint[(int)side, (int)airDefenseRange], 99999),
                        GeneratorTools.GetSpawnPointCoalition(template, side));

                // No spawn point found, stop here.
                if (!spawnPoint.HasValue)
                {
                    BriefingRoom.PrintToLog($"No spawn point found for {airDefenseRange} air defense unit groups", LogMessageErrorLevel.Warning);
                    return;
                }

                var groupInfo = unitMaker.AddUnitGroup(
                    unitFamilies, 1, side,
                    "GroupVehicle", "UnitVehicle",
                    spawnPoint.Value);

                if (!groupInfo.HasValue) // Failed to generate a group
                {
                    BriefingRoom.PrintToLog(
                        $"Failed to add {airDefenseRange} air defense unit group for {coalition} coalition.",
                        LogMessageErrorLevel.Warning);
                }
            }
        }