示例#1
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();
        }
示例#2
0
        public static DCSMissionUnitGroup FromCoalitionArmyAndUnitFamily(
            string luaGroup, string luaUnit,
            DefinitionCoalition army, TimePeriod timePeriod, UnitFamily family, int unitCount,
            int groupID, Coalition coalition, Coordinates coordinates)
        {
            List <string> unitList = new List <string>();

            UnitCategory category = HQTools.GetUnitCategoryFromUnitFamily(family);

            // FIXME: extendSearchToUnitsOfOtherFamilies and returnDefaultIfNoneFound should be parameters
            string[] availableUnits = army.GetUnits(timePeriod, family, false, false);

            if (availableUnits.Length == 0)
            {
                DebugLog.Instance.Log($"    WARNING: Cannot spawn unit group, no units of type {family.ToString().ToUpperInvariant()} for coalition {army.DisplayName.ToUpperInvariant()} in {timePeriod.ToString().ToUpperInvariant()}.");
                return(null);
            }

            do
            {
                unitList.AddRange((from u in HQTools.RandomFrom(availableUnits).Split('|') select u.Trim()));
            } while (unitList.Count < unitCount);

            // Some unit categories (helicopters and planes) require all units to be the same type
            if ((category == UnitCategory.Helicopter) || (category == UnitCategory.Plane))
            {
                for (int i = 1; i < unitList.Count; i++)
                {
                    unitList[i] = unitList[0];
                }
            }

            DCSMissionUnitGroup uGroup = new DCSMissionUnitGroup(
                luaGroup, luaUnit,
                category, groupID, coalition, coordinates,
                unitList.ToArray());

            return(uGroup);
        }