Exemplo n.º 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();
        }
Exemplo n.º 2
0
        private string MakeUnitsCategoryLua(DCSMission missHQ, Coalition coalition, UnitCategory categ)
        {
            string categoryUnitsLua = "";

            DCSMissionUnitGroup[] groups =
                (from g in missHQ.UnitGroups
                 where g.Coalition == coalition && g.Category == categ
                 select g).ToArray();

            int categIndex = 1;

            foreach (DCSMissionUnitGroup g in groups)
            {
                string groupLua = HQTools.ReadIncludeLuaFile($"Mission\\{g.LuaGroup}.lua");

                HQTools.ReplaceKey(ref groupLua, "Units", MakeUnitsUnitsLua(g, missHQ.SinglePlayer)); // Must be first, so full-group replacements come after unit-specific ones

                //if (g.Waypoints.Count > 0)
                //    HQTools.ReplaceKey(ref groupLua, "Waypoints", CreatePlayerWaypointsLua(g.Waypoints)); // Must be first after units

                HQTools.ReplaceKey(ref groupLua, "Name", g.Name);
                HQTools.ReplaceKey(ref groupLua, "GroupID", g.GroupID);
                HQTools.ReplaceKey(ref groupLua, "Frequency", g.RadioFrequency, "F2");
                HQTools.ReplaceKey(ref groupLua, "X", g.Coordinates.X);
                HQTools.ReplaceKey(ref groupLua, "Y", g.Coordinates.Y);
                HQTools.ReplaceKey(ref groupLua, "ObjectiveCenterX", missHQ.ObjectivesCenterPoint.X + HQTools.RandomDouble(-UNIT_RANDOM_WAYPOINT_VARIATION, UNIT_RANDOM_WAYPOINT_VARIATION));
                HQTools.ReplaceKey(ref groupLua, "ObjectiveCenterY", missHQ.ObjectivesCenterPoint.Y + HQTools.RandomDouble(-UNIT_RANDOM_WAYPOINT_VARIATION, UNIT_RANDOM_WAYPOINT_VARIATION));
                HQTools.ReplaceKey(ref groupLua, "Hidden", g.Hidden);
                foreach (DCSMissionUnitGroupCustomValueKey k in g.CustomValues.Keys)
                {
                    if (k.UnitIndex != -1)
                    {
                        continue;                    // Replacement applies only to a single unit, don't apply it to the whole group
                    }
                    HQTools.ReplaceKey(ref groupLua, k.Key, g.CustomValues[k]);
                }
                HQTools.ReplaceKey(ref groupLua, "Index", categIndex); // Must be last, used by other values

                categoryUnitsLua += groupLua + "\r\n";
                categIndex++;
            }

            return(categoryUnitsLua);
        }