private static void GenerateFOB( UnitMaker unitMaker, ZoneMaker zoneMaker, MissionTemplateFlightGroupRecord flightGroup, Dictionary <string, UnitMakerGroupInfo> carrierDictionary, DCSMission mission, MissionTemplateRecord template, Coordinates landbaseCoordinates, Coordinates objectivesCenter) { DBEntryTheater theaterDB = Database.Instance.GetEntry <DBEntryTheater>(template.ContextTheater); if (theaterDB == null) { return; // Theater doesn't exist. Should never happen. } Coordinates?spawnPoint = unitMaker.SpawnPointSelector.GetRandomSpawnPoint( new SpawnPointType[] { SpawnPointType.LandLarge }, landbaseCoordinates, new MinMaxD(5, template.FlightPlanObjectiveDistance), objectivesCenter, new MinMaxD(10, template.FlightPlanObjectiveDistance / 2), template.ContextPlayerCoalition); if (!spawnPoint.HasValue) { BriefingRoom.PrintToLog($"No spawn point found for FOB air defense unit groups", LogMessageErrorLevel.Warning); return; } DBEntryUnit unitDB = Database.Instance.GetEntry <DBEntryUnit>(flightGroup.Carrier); if (unitDB == null) { return; // Unit doesn't exist or is not a carrier } double radioFrequency = 127.5 + carrierDictionary.Count; var FOBNames = new List <string> { "FOB_London", "FOB_Dallas", "FOB_Paris", "FOB_Moscow", "FOB_Berlin" }; UnitMakerGroupInfo?groupInfo = unitMaker.AddUnitGroup( unitDB.Families[0], 1, Side.Ally, "GroupStatic", "UnitStaticFOB", spawnPoint.Value, 0, "FOBCallSignIndex".ToKeyValuePair(FOBNames.IndexOf(flightGroup.Carrier) + 1), "RadioBand".ToKeyValuePair((int)RadioModulation.AM), "RadioFrequency".ToKeyValuePair(GeneratorTools.GetRadioFrenquency(radioFrequency))); if (!groupInfo.HasValue || (groupInfo.Value.UnitsID.Length == 0)) { return; // Couldn't generate group } zoneMaker.AddCTLDPickupZone(spawnPoint.Value, true); mission.Briefing.AddItem( DCSMissionBriefingItemType.Airbase, $"{unitDB.UIDisplayName}\t-\t{GeneratorTools.FormatRadioFrequency(radioFrequency)}\t\t"); carrierDictionary.Add(flightGroup.Carrier, groupInfo.Value); // This bit limits FOBS to one per game think about how we can fix this }
internal static Dictionary <string, UnitMakerGroupInfo> GenerateCarrierGroup( UnitMaker unitMaker, ZoneMaker zoneMaker, DCSMission mission, MissionTemplateRecord template, Coordinates landbaseCoordinates, Coordinates objectivesCenter, double windSpeedAtSeaLevel, double windDirectionAtSeaLevel) { Dictionary <string, UnitMakerGroupInfo> carrierDictionary = new Dictionary <string, UnitMakerGroupInfo>(StringComparer.InvariantCultureIgnoreCase); DBEntryTheater theaterDB = Database.Instance.GetEntry <DBEntryTheater>(template.ContextTheater); double carrierSpeed = Math.Max( Database.Instance.Common.CarrierGroup.MinimumCarrierSpeed, Database.Instance.Common.CarrierGroup.IdealWindOfDeck - windSpeedAtSeaLevel); if (windSpeedAtSeaLevel == 0) // No wind? Pick a random direction so carriers don't always go to a 0 course when wind is calm. { windDirectionAtSeaLevel = Toolbox.RandomDouble(Toolbox.TWO_PI); } var carrierPathDeg = ((windDirectionAtSeaLevel + Math.PI) % Toolbox.TWO_PI) * Toolbox.RADIANS_TO_DEGREES; var usedCoordinates = new List <Coordinates>(); foreach (MissionTemplateFlightGroupRecord flightGroup in template.PlayerFlightGroups) { if (string.IsNullOrEmpty(flightGroup.Carrier)) { continue; // No carrier for } if (carrierDictionary.ContainsKey(flightGroup.Carrier)) { continue; // Carrier type already added } if (flightGroup.Carrier.StartsWith("FOB")) { //It Carries therefore carrier not because I can't think of a name to rename this lot GenerateFOB(unitMaker, zoneMaker, flightGroup, carrierDictionary, mission, template, landbaseCoordinates, objectivesCenter); continue; } DBEntryUnit unitDB = Database.Instance.GetEntry <DBEntryUnit>(flightGroup.Carrier); if ((unitDB == null) || !unitDB.Families.Any(x => x.IsCarrier())) { continue; // Unit doesn't exist or is not a carrier } var(shipCoordinates, shipDestination) = GetSpawnAndDestination(unitMaker, template, theaterDB, usedCoordinates, landbaseCoordinates, objectivesCenter, carrierPathDeg); usedCoordinates.Add(shipCoordinates); string cvnID = carrierDictionary.Count > 0 ? (carrierDictionary.Count + 1).ToString() : ""; int ilsChannel = 11 + carrierDictionary.Count; double radioFrequency = 127.5 + carrierDictionary.Count; string tacanCallsign = $"CVN{cvnID}"; int tacanChannel = 74 + carrierDictionary.Count; UnitMakerGroupInfo?groupInfo = unitMaker.AddUnitGroup( new string[] { unitDB.ID }, Side.Ally, unitDB.Families[0], "GroupShipCarrier", "UnitShip", shipCoordinates, 0, "GroupX2".ToKeyValuePair(shipDestination.X), "GroupY2".ToKeyValuePair(shipDestination.Y), "ILS".ToKeyValuePair(ilsChannel), "RadioBand".ToKeyValuePair((int)RadioModulation.AM), "RadioFrequency".ToKeyValuePair(GeneratorTools.GetRadioFrenquency(radioFrequency)), "Speed".ToKeyValuePair(carrierSpeed), "TACANCallsign".ToKeyValuePair(tacanCallsign), "TACANChannel".ToKeyValuePair(tacanChannel), "TACANFrequency".ToKeyValuePair(GeneratorTools.GetTACANFrequency(tacanChannel, 'X', false)), "TACANMode".ToKeyValuePair("X")); if (!groupInfo.HasValue || (groupInfo.Value.UnitsID.Length == 0)) { continue; // Couldn't generate group } mission.Briefing.AddItem( DCSMissionBriefingItemType.Airbase, $"{unitDB.UIDisplayName}\t-\t{GeneratorTools.FormatRadioFrequency(radioFrequency)}\t{ilsChannel}\t{tacanCallsign}, {tacanChannel}X"); carrierDictionary.Add(flightGroup.Carrier, groupInfo.Value); } return(carrierDictionary); }