예제 #1
0
        private bool PlaneIsWithin(AIPlaneInfo planeInfo, double StartBearing, double EndBearing, double?MinAltitude, double?MaxAltitude, double?WithinDistance)
        {
            bool flag = false;

            if (WithinDistance.HasValue)
            {
                double distanceNm = planeInfo.DistanceNM;
                double?nullable   = WithinDistance;
                flag = distanceNm > nullable.GetValueOrDefault() && nullable.HasValue;
            }
            if (!flag && MinAltitude.HasValue)
            {
                double altitudeFeet = planeInfo.AltitudeFeet;
                double?nullable     = MinAltitude;
                flag = altitudeFeet < nullable.GetValueOrDefault() && nullable.HasValue;
            }
            if (!flag && MaxAltitude.HasValue)
            {
                double altitudeFeet = planeInfo.AltitudeFeet;
                double?nullable     = MaxAltitude;
                flag = altitudeFeet > nullable.GetValueOrDefault() && nullable.HasValue;
            }
            if (!flag)
            {
                flag = !this.bearingBetween(planeInfo.BearingTo, StartBearing, EndBearing);
            }
            return(!flag);
        }
예제 #2
0
        internal void getATCInfo(AIPlaneInfo planeInfo, bool TailNumber, bool AirlineAndFlightNumber, bool AircraftTypeAndModel, bool AircraftTitle)
        {
            int id = planeInfo.id;

            if (TailNumber && planeInfo.tailNumber.Length == 0)
            {
                planeInfo.tailNumber = this.getATCString(id, 1);
            }
            if (AirlineAndFlightNumber)
            {
                bool flag = false;
                if (planeInfo.State == AITrafficStatus.Initialising || planeInfo.State == AITrafficStatus.Sleeping)
                {
                    planeInfo.flightNumber = "";
                }
                else if (planeInfo.flightNumber.Length == 0)
                {
                    flag = true;
                }
                if (planeInfo.airline.Length == 0)
                {
                    flag = true;
                }
                if (flag)
                {
                    string atcString = this.getATCString(id, 2);
                    int    length    = atcString.LastIndexOf(' ');
                    if (length > 0)
                    {
                        planeInfo.airline = atcString.Substring(0, length);
                    }
                    planeInfo.flightNumber = atcString.Substring(length + 1);
                    if (planeInfo.airline.Length == 0)
                    {
                        planeInfo.airline = "Private (GA)";
                    }
                }
            }
            if (AircraftTypeAndModel && planeInfo.aircraftModel.Length == 0)
            {
                string atcString = this.getATCString(id, 3);
                int    length    = atcString.IndexOf('~');
                planeInfo.aircraftType  = atcString.Substring(0, length);
                planeInfo.aircraftModel = atcString.Substring(length + 1);
                if (planeInfo.aircraftType.Length == 0)
                {
                    planeInfo.aircraftType = "n/a";
                }
                if (planeInfo.aircraftModel.Trim().Length == 0)
                {
                    planeInfo.aircraftModel = "n/a";
                }
            }
            if (!AircraftTitle || planeInfo.aircraftTitle.Trim().Length != 0)
            {
                return;
            }
            planeInfo.aircraftTitle = this.getATCString(id, 4);
        }
예제 #3
0
 private int comparePlaneDistance(AIPlaneInfo plane1, AIPlaneInfo plane2)
 {
     if (plane1.DistanceFeet == plane2.DistanceFeet)
     {
         return(0);
     }
     return(plane1.DistanceFeet < plane2.DistanceFeet ? -1 : 1);
 }
예제 #4
0
        public void ApplyFilter(bool FilterGroundTraffic, bool FilterAirbourneTraffic, double StartBearing, double EndBearing, double?MinAltitude, double?MaxAltitude, double?WithinDistance)
        {
            if (FilterGroundTraffic)
            {
                int index = 0;
                int count = this.aiGround.Count;
                while (index < count)
                {
                    AIPlaneInfo planeInfo = this.aiGround[index];
                    if (!this.PlaneIsWithin(planeInfo, StartBearing, EndBearing, MinAltitude, MaxAltitude, WithinDistance))
                    {
                        this.aiGroundIDs.Remove(planeInfo.id);
                        this.aiGround.Remove(planeInfo);
                        this.aiAllIDs.Remove(planeInfo.id);
                        this.aiAll.Remove(planeInfo);
                        --count;
                    }
                    else
                    {
                        ++index;
                    }
                }
            }
            if (!FilterAirbourneTraffic)
            {
                return;
            }
            int index1 = 0;
            int count1 = this.aiAirborne.Count;

            while (index1 < count1)
            {
                AIPlaneInfo planeInfo = this.aiAirborne[index1];
                if (!this.PlaneIsWithin(planeInfo, StartBearing, EndBearing, MinAltitude, MaxAltitude, WithinDistance))
                {
                    this.aiAirbornIDs.Remove(planeInfo.id);
                    this.aiAirborne.Remove(planeInfo);
                    this.aiAllIDs.Remove(planeInfo.id);
                    this.aiAll.Remove(planeInfo);
                    --count1;
                }
                else
                {
                    ++index1;
                }
            }
        }
예제 #5
0
        private AIPlaneInfo updatePlaneInfo(byte[] slot, byte[] slotExtra, List <AIPlaneInfo> aiPlaneList, List <int> aiPlaneIDs, List <int> processedPlaneIDs)
        {
            AIPlaneInfo planeInfo = (AIPlaneInfo)null;
            int         int32     = BitConverter.ToInt32(slot, 0);

            if (int32 != 0)
            {
                if (aiPlaneIDs.Contains(int32))
                {
                    planeInfo = aiPlaneList[aiPlaneIDs.IndexOf(int32)];
                }
                else
                {
                    planeInfo    = new AIPlaneInfo();
                    planeInfo.id = int32;
                    aiPlaneList.Add(planeInfo);
                    aiPlaneIDs.Add(int32);
                }
                planeInfo.updateFromByteArrays(slot, slotExtra, this.playerAlt.Value, this.playerLat.Value, this.playerLon.Value, this.playerMagVar.Value);
                this.getATCInfo(planeInfo, this.atcUpdateTailNumber, this.atcUpdateAirlineAndFlightNumbe, this.atcUpdateAircraftTypeAndModel, this.atcUpdateAircraftTitle);
                processedPlaneIDs.Add(int32);
            }
            return(planeInfo);
        }
예제 #6
0
        private void addToRunwaysInUse(AIPlaneInfo planeInfo)
        {
            switch (planeInfo.State)
            {
            case AITrafficStatus.Initialising:
            case AITrafficStatus.FilingFlightPlan:
            case AITrafficStatus.ObtainingClearance:
            case AITrafficStatus.PushingBack:
            case AITrafficStatus.PushingBackTurn:
            case AITrafficStatus.StartingUp:
            case AITrafficStatus.ReadyForTaxi:
            case AITrafficStatus.TaxiingOut:
            case AITrafficStatus.ReadyForTakeOff:
            case AITrafficStatus.TakingOff:
            case AITrafficStatus.Departing:
                if ((int)planeInfo.RunwayAssigned.Number <= 0)
                {
                    break;
                }
                List <FSRunway> fsRunwayList1;
                if (this.aiDepartureRunwaysInUse.ContainsKey(planeInfo.departureICAO))
                {
                    fsRunwayList1 = this.aiDepartureRunwaysInUse[planeInfo.departureICAO];
                }
                else
                {
                    fsRunwayList1 = new List <FSRunway>();
                    this.aiDepartureRunwaysInUse.Add(planeInfo.departureICAO, fsRunwayList1);
                }
                if (fsRunwayList1.Contains(planeInfo.RunwayAssigned))
                {
                    break;
                }
                fsRunwayList1.Add(planeInfo.RunwayAssigned);
                break;

            case AITrafficStatus.Enroute:
            case AITrafficStatus.InThePattern:
            case AITrafficStatus.Landing:
            case AITrafficStatus.RollingOut:
            case AITrafficStatus.GoingAround:
            case AITrafficStatus.TaxiingIn:
            case AITrafficStatus.ShuttingDown:
                if ((int)planeInfo.RunwayAssigned.Number <= 0)
                {
                    break;
                }
                List <FSRunway> fsRunwayList2;
                if (this.aiArrivalRunwaysInUse.ContainsKey(planeInfo.destinationICAO))
                {
                    fsRunwayList2 = this.aiArrivalRunwaysInUse[planeInfo.destinationICAO];
                }
                else
                {
                    fsRunwayList2 = new List <FSRunway>();
                    this.aiArrivalRunwaysInUse.Add(planeInfo.destinationICAO, fsRunwayList2);
                }
                if (fsRunwayList2.Contains(planeInfo.RunwayAssigned))
                {
                    break;
                }
                fsRunwayList2.Add(planeInfo.RunwayAssigned);
                break;
            }
        }
예제 #7
0
        public void RefreshAITrafficInformation(bool UpdateGroundTraffic, bool UpdateAirbourneTraffic)
        {
            FSUIPCConnection.Process(this.classInstance, this.AISystemGroup);
            List <int> processedPlaneIDs = new List <int>();

            this.aiArrivalRunwaysInUse.Clear();
            this.aiDepartureRunwaysInUse.Clear();
            if (UpdateGroundTraffic)
            {
                List <Offset <byte[]> > offsetList1 = new List <Offset <byte[]> >();
                List <Offset <byte[]> > offsetList2 = new List <Offset <byte[]> >();
                for (int index = 0; index < (int)this.slotsUsedGround.Value; ++index)
                {
                    Offset <byte[]> offset1 = new Offset <byte[]>(this.AISlotGroup, 57472 + 40 * index, 40);
                    Offset <byte[]> offset2 = new Offset <byte[]>(this.AISlotGroup, 53312 + 20 * index, 20);
                    offsetList1.Add(offset1);
                    offsetList2.Add(offset2);
                }
                if (offsetList1.Count > 0)
                {
                    FSUIPCConnection.Process(this.classInstance, this.AISlotGroup);
                    FSUIPCConnection.DeleteGroup(this.AISlotGroup);
                    processedPlaneIDs = new List <int>();
                    for (int index = 0; index < offsetList1.Count; ++index)
                    {
                        AIPlaneInfo planeInfo = this.updatePlaneInfo(offsetList1[index].Value, offsetList2[index].Value, this.aiGround, this.aiGroundIDs, processedPlaneIDs);
                        if (planeInfo != null)
                        {
                            this.addToRunwaysInUse(planeInfo);
                        }
                    }
                }
                List <int> intList = new List <int>();
                foreach (int aiGroundId in this.aiGroundIDs)
                {
                    if (!processedPlaneIDs.Contains(aiGroundId))
                    {
                        intList.Add(this.aiGroundIDs.IndexOf(aiGroundId));
                    }
                }
                intList.Sort();
                intList.Reverse();
                foreach (int index in intList)
                {
                    AIPlaneInfo aiPlaneInfo = this.aiGround[index];
                    aiPlaneInfo.id = 0;
                    this.aiGround.Remove(aiPlaneInfo);
                }
                this.aiGround.Sort(new Comparison <AIPlaneInfo>(this.comparePlaneDistance));
                this.aiGroundIDs.Clear();
                foreach (AIPlaneInfo aiPlaneInfo in this.aiGround)
                {
                    this.aiGroundIDs.Add(aiPlaneInfo.id);
                }
            }
            if (UpdateAirbourneTraffic)
            {
                List <Offset <byte[]> > offsetList1 = new List <Offset <byte[]> >();
                List <Offset <byte[]> > offsetList2 = new List <Offset <byte[]> >();
                for (int index = 0; index < (int)this.slotsUsedAir.Value; ++index)
                {
                    Offset <byte[]> offset1 = new Offset <byte[]>(this.AISlotGroup, 61568 + 40 * index, 40);
                    Offset <byte[]> offset2 = new Offset <byte[]>(this.AISlotGroup, 55360 + 20 * index, 20);
                    offsetList1.Add(offset1);
                    offsetList2.Add(offset2);
                }
                if (offsetList1.Count > 0)
                {
                    FSUIPCConnection.Process(this.classInstance, this.AISlotGroup);
                    FSUIPCConnection.DeleteGroup(this.AISlotGroup);
                    processedPlaneIDs = new List <int>();
                    for (int index = 0; index < offsetList1.Count; ++index)
                    {
                        AIPlaneInfo planeInfo = this.updatePlaneInfo(offsetList1[index].Value, offsetList2[index].Value, this.aiAirborne, this.aiAirbornIDs, processedPlaneIDs);
                        if (planeInfo != null)
                        {
                            this.addToRunwaysInUse(planeInfo);
                        }
                    }
                }
                List <int> intList = new List <int>();
                foreach (int aiAirbornId in this.aiAirbornIDs)
                {
                    if (!processedPlaneIDs.Contains(aiAirbornId))
                    {
                        intList.Add(this.aiAirbornIDs.IndexOf(aiAirbornId));
                    }
                }
                intList.Sort();
                intList.Reverse();
                foreach (int index in intList)
                {
                    AIPlaneInfo aiPlaneInfo = this.aiAirborne[index];
                    aiPlaneInfo.id = 0;
                    this.aiAirborne.Remove(aiPlaneInfo);
                }
                this.aiAirborne.Sort(new Comparison <AIPlaneInfo>(this.comparePlaneDistance));
                this.aiAirbornIDs.Clear();
                foreach (AIPlaneInfo aiPlaneInfo in this.aiAirborne)
                {
                    this.aiAirbornIDs.Add(aiPlaneInfo.id);
                }
            }
            this.aiAll.Clear();
            this.aiAll.AddRange((IEnumerable <AIPlaneInfo>) this.aiGround);
            this.aiAll.AddRange((IEnumerable <AIPlaneInfo>) this.aiAirborne);
            if (this.aiAll.Count <= 0)
            {
                return;
            }
            this.aiAll.Sort(new Comparison <AIPlaneInfo>(this.comparePlaneDistance));
            this.aiAllIDs.Clear();
            foreach (AIPlaneInfo aiPlaneInfo in this.aiAll)
            {
                this.aiAllIDs.Add(aiPlaneInfo.id);
            }
        }