コード例 #1
0
ファイル: SimConnectInterface.cs プロジェクト: chembergj/VSPC
        /*
        void move_ai(int ai_index, Waypoint r)
        {
            AIMoveStruct ai_move_data;
            ai_move_data.latitude = r.Latitude;
            ai_move_data.longitude = r.Longitude;
            ai_move_data.altitude = r.Altitude;
            ai_move_data.pitch = r.Pitch;
            ai_move_data.bank = r.Bank;
            ai_move_data.heading = r.Heading;

            Logger.Debug(string.Format("Moving ai({0}) to {1},{2}", ai_index, r.Latitude, r.Longitude));

            // set LLAPBH
            simconnect.SetDataOnSimObject(SIMCONNECT_EVENTS.EVENTID_DEFINITION_AI_MOVE, ai_info[ai_index].id, 0, ai_move_data);

            // send slew command to stop
            simconnect.TransmitClientEvent(ai_info[ai_index].id, SIMCONNECT_EVENTS.EVENTID_AXIS_SLEW_AHEAD_SET,
                                0, // zero ahead rate => stop
                                GROUP_PRIORITIES.SIMCONNECT_GROUP_PRIORITY_HIGHEST,
                                SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
        }
        */
        /*
        void create_ai(int ai_index)
        {
            Logger.Debug(string.Format("Creating AI {0}", ai_info[ai_index].title));

            SIMCONNECT_DATA_INITPOSITION ai_init;

            ai_init.Altitude = SimMath.m2ft(replay[ai_index][0].altitude) + 10; // feet Altitude of Sea-tac is 433 feet
            ai_init.Latitude = SimMath.replay[ai_index][0].latitude;    // Degrees Convert from 47 25.90 N
            ai_init.Longitude = SimMath.replay[ai_index][0].longitude;   // Degrees Convert from 122 18.48 W
            ai_init.Pitch = SimMath.rad2deg(replay[ai_index][0].pitch);       // Degrees
            ai_init.Bank = SimMath.rad2deg(replay[ai_index][0].bank);        // Degrees
            ai_init.Heading = SimMath.rad2deg(replay[ai_index][0].heading);     // Degrees
            ai_init.OnGround = 0;                               // 1=OnGround, 0 = airborne
            ai_init.Airspeed = 0;                               // Knots

            // now create ai object
            if (!ai_info[ai_index].created) hr = SimConnect_AICreateSimulatedObject(hSimConnect,
                                                    ai_info[ai_index].title,
                                                    ai_init,
                                                    (UINT)REQUEST_AI_CREATE + ai_index);
            //if (debug) printf("create_ai %s\n", (hr==S_OK) ? "OK" : "FAIL");
        }
        */
        /// <summary>
        /// A new AI traffic position msg has been received from Vatsim
        /// Set the new waypoint and reset the timer-counter
        /// </summary>
        /// <param name="msg"></param>
        private void HandleAIPositionReport(uint AIPlaneSimConnectId, AIPositionReportStruct posreport)
        {
            var AIAircraft = CallsignToAIPlaneMap.Where(keyvalue => keyvalue.Value.SimConnectObjectId == AIPlaneSimConnectId).First().Value;
            var currentWp = CreateWaypointFromAIPositionReportStruct(ref posreport, DateTime.Now);
            var newWp = AIAircraft.TargetWaypoint;

            Logger.Debug(AIAircraft.Callsign + " pitch: " + posreport.pitch.ToString() + " on gnd: " + posreport.simOnGround.ToString() + " alt above gnd: " + posreport.altAboveGround.ToString());

            if (AIAircraft.IsTargetWaypointStale())
            {
                Logger.Debug(AIAircraft.Callsign + " has stale target waypoint");
            }
            else if (SimMath.AIAircraftIsParked(currentWp, newWp))
            {
                ResetRates(AIAircraft);
            }
            else
            {
                CalculateSlewAI(AIAircraft, currentWp, newWp);
            }
        }
コード例 #2
0
ファイル: SimConnectInterface.cs プロジェクト: chembergj/VSPC
 private static Waypoint CreateWaypointFromAIPositionReportStruct(ref AIPositionReportStruct aiposreport, DateTime timestamp)
 {
     var currentWp = new Waypoint()
     {
         Altitude = aiposreport.truealtitude,
         Longitude = aiposreport.longitude,
         Latitude = aiposreport.latitude,
         GroundSpeed = SimMath.knotsToMetersPerSecond(aiposreport.groundspeed),
         Pitch = aiposreport.pitch,
         Bank = aiposreport.bank,
         Heading = aiposreport.heading,
         Timestamp = timestamp,
         OnGround = aiposreport.simOnGround != 0
     };
     return currentWp;
 }