コード例 #1
0
        internal static IEnumerable <Encounter> TowEncounter(this FlightContext context)
        {
            var nearbyAircraft = context.Options.NearbyAircraftAccessor?.Invoke(
                context.CurrentPosition.Location,
                0.5)
                                 .ToList();

            if (nearbyAircraft == null)
            {
                yield break;
            }

            foreach (var aircraft in nearbyAircraft)
            {
                var iAm = context.WhatAmI(aircraft);

                if (iAm == AircraftRelation.OnTow)
                {
                    yield return(new Encounter
                    {
                        Aircraft = aircraft.Options.AircraftId,
                        Start = aircraft.Flight.DepartureTime,
                        Type = EncounterType.Tug
                    });
                }
                else if (iAm == AircraftRelation.Towplane)
                {
                    yield return(new Encounter
                    {
                        Aircraft = aircraft.Options.AircraftId,
                        Start = aircraft.Flight.DepartureTime,
                        Type = EncounterType.Tow
                    });
                }
                else if (iAm == AircraftRelation.Indeterministic)
                {
                    yield return(null);
                }
            }
        }
コード例 #2
0
        internal static void TrackAerotow(this FlightContext context)
        {
            // ToDo: Think about the possibility of a paired landing.

            if (context.Options.AircraftAccessor == null)
            {
                throw new Exception($"Unable to track tow without {nameof(FlightContextFactory)}");
            }

            var target = context.Flight.Encounters
                         .FirstOrDefault(q => q.Type == Models.EncounterType.Tow ||
                                         q.Type == Models.EncounterType.Tug);

            if (target == null)
            {
                // Note of caution; this situation should ideally never happen. If it does it would be a design flaw in the state machine?
                context.StateMachine.Fire(FlightContext.Trigger.LaunchCompleted);
                return;
            }

            var otherContext = context.Options.AircraftAccessor(target.Aircraft);

            var iAm = context.WhatAmI(otherContext);

            if (iAm == null)
            {
                return;              // (I'm nothing. Try again next time)
            }
            if (iAm == Internal.Geo.AircraftRelation.None ||
                (target.Type == Models.EncounterType.Tow && iAm != Internal.Geo.AircraftRelation.Towplane) ||
                (target.Type == Models.EncounterType.Tug && iAm != Internal.Geo.AircraftRelation.OnTow))
            {
                target.End = context.CurrentPosition.TimeStamp;
                context.StateMachine.Fire(FlightContext.Trigger.LaunchCompleted);
                context.InvokeOnLaunchCompletedEvent();
                return;
            }
        }