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); }
// NEXTVERSION // public Country[][] LiveriesPriority { get; private set; } = new Country[2][]; // public string[][] Liveries { get; private set; } = new string[HQTools.EnumCount<Country>()][]; /// <summary> /// Loads data required by this definition. /// </summary> /// <param name="ini">The ini file to load from.</param> /// <returns>True is successful, false if an error happened.</returns> protected override bool OnLoad(INIFile ini) { // -------------- // [Unit] section // -------------- ID = ini.GetValue <string>("Unit", "ID"); if (string.IsNullOrEmpty(ID)) { return(false); } DCSID = ini.GetValue <string>("Unit", "DCSID"); if (string.IsNullOrEmpty(DCSID)) { DCSID = ID; } DisplayName = ini.GetValue <string>("Unit", "DisplayName"); Families = ini.GetValueArray <UnitFamily>("Unit", "Families"); if (Families.Length == 0) { return(false); } Category = HQTools.GetUnitCategoryFromUnitFamily(Families[0]); // All families must belong to the same category. If that's not the case, remove all "wrong" families. Families = (from UnitFamily f in Families where f.ToString().StartsWith(Category.ToString()) select f).ToArray(); if (Families.Length == 0) { return(false); } InService = HQTools.ParseEnumString <TimePeriod>(ini.GetValue <string>("Unit", "InService"), '-', "Decade"); if (InService.Length < 2) { return(false); } InService = InService.Take(2).OrderBy(x => x).ToArray(); ExtraLua = ini.GetValue <string>("Unit", "ExtraLua"); // --------------- // [Comms] section // --------------- CommsRadioFrequency = ini.GetValue <float>("Comms", "RadioFrequency"); CommsRadioFrequency = (CommsRadioFrequency <= 0) ? DEFAULT_RADIO_FREQUENCY : CommsRadioFrequency; CommsTACANChannel = HQTools.Clamp(ini.GetValue <int>("Comms", "TACAN.Channel"), 0, 99); CommsTACANChannelMode = ini.GetValue <string>("Comms", "TACAN.ChannelMode").ToUpperInvariant(); CommsTACANChannelMode = (CommsTACANChannelMode == "Y") ? "Y" : "X"; CommsTACANCallsign = ini.GetValue <string>("Comms", "TACAN.Callsign").ToUpperInvariant(); CommsILSChannel = HQTools.Clamp(ini.GetValue <int>("Comms", "ILS.Channel"), 0, 99); // ---------------------------------------------------- // [Aircraft] section (only for planes and helicopters) // ---------------------------------------------------- if ((Category == UnitCategory.Helicopter) || (Category == UnitCategory.Plane)) { AircraftDefaultTask = ini.GetValue <DCSFlightGroupTask>("Aircraft", "DefaultTask"); AircraftAirToAirRating[0] = ini.GetValue <int>("Aircraft", "AirToAirRating.A2APayload"); AircraftAirToAirRating[1] = ini.GetValue <int>("Aircraft", "AirToAirRating.A2GPayload"); AircraftCruiseAltitude = ini.GetValue <int>("Aircraft", "CruiseAltitude") * HQTools.FEET_TO_METERS; if (AircraftCruiseAltitude <= 0) { AircraftCruiseAltitude = Category == UnitCategory.Helicopter ? 350 : 6000; } AircraftCruiseSpeed = ini.GetValue <int>("Aircraft", "CruiseSpeed") * HQTools.KNOTS_TO_METERSPERSECOND; if (AircraftCruiseSpeed <= 0) { AircraftCruiseSpeed = Category == UnitCategory.Helicopter ? 50 : 130; } AircraftPlayerControllable = ini.GetValue <bool>("Aircraft", "PlayerControllable"); AircraftCarrierShipType = ini.GetValueArray <CarrierGroupShipType>("Aircraft", "CarrierShipType"); // ----------------------------------------------------------- // [AircraftPayload] section (only for planes and helicopters) // ----------------------------------------------------------- int i, j; AircraftPayloadCommon = ini.GetValue <string>("AircraftPayload", "Common"); List <PlayerFlightGroupPayloadType> payloadsList = new List <PlayerFlightGroupPayloadType>(); for (i = 0; i < AircraftPayloadPylons.GetLength(0); i++) { for (j = 0; j < AircraftPayloadPylons.GetLength(1); j++) { AircraftPayloadPylons[i, j] = ini.GetValue <string>("AircraftPayload", $"Pylons.{((PlayerFlightGroupPayloadType)i).ToString()}.Pylon{HQTools.ValToString(j + 1, "00")}"); // Each payload with at least one pylon not empty is a valid payload if (!payloadsList.Contains((PlayerFlightGroupPayloadType)i) && !string.IsNullOrEmpty(AircraftPayloadPylons[i, j])) { payloadsList.Add((PlayerFlightGroupPayloadType)i); } } } AircraftAvailablePayloads = payloadsList.ToArray(); } // ------------------ // [Liveries] section // ------------------ // NEXT VERSION //LiveriesPriority[0] = ini.GetValueArray<Country>("Liveries", "Priority.Real"); //LiveriesPriority[1] = ini.GetValueArray<Country>("Liveries", "Priority.Fictional"); //Liveries = new string[HQTools.EnumCount<Country>()][]; //for (int i = 0; i < Liveries.Length; i++) // Liveries[i] = ini.GetValueArray<string>("Liveries", $"Country.{(Country)i}", '|'); return(true); }