• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FSX SEND AI WAYPOINTS AUTOMATICALLY

I'm hoping somebody can help me and point me in the right direction.

I'm trying to edit the SDK AI Traffic or AI traffic and Waypoint sample, to automatically send a waypoint to all AI in the session.

It just needs to be one waypoint and ideally I want to send the waypoint info once the AI become in range.
 
I'm just guessing here. Look at AI Traffic sample

1. The AI created in FSX are controlled by the AI pilot/ATC.
2. You would need to trigger on the AIObjectAdd AIObjectRemove events
3. AI created event provides you with the SIMObjectID
4. Since the AI is ATC controlled you would use AIReleaseControl first
5. Then set the waypoint for the SIMObjectID
6. Once it gets to the waypoint then it disappears?? Can you even set just one waypoint - you may need minimum of two.

However you also would need to know if the AI State. If its parked then what?
 
I'm just guessing here. Look at AI Traffic sample

1. The AI created in FSX are controlled by the AI pilot/ATC.
2. You would need to trigger on the AIObjectAdd AIObjectRemove events
3. AI created event provides you with the SIMObjectID
4. Since the AI is ATC controlled you would use AIReleaseControl first
5. Then set the waypoint for the SIMObjectID
6. Once it gets to the waypoint then it disappears?? Can you even set just one waypoint - you may need minimum of two.

However you also would need to know if the AI State. If its parked then what?

Thanks for the reply ronh.

I'm asking as I use an external program that injects AI traffic.
The Traffic explorer sees the traffic but it doesn't display on my radar screen.

If I set the waypoint for each aircraft they then display on my screen in the correct postion.

All the aircraft that are created are a non ATC AI.

So my thinking was if I could edit the AI Traffic sample from the SDK to automatically give the each AI a waypoint that would save me individually clicking them and they would show automatically.

One problem I'm stuck on is how would I send a waypoint too all AI, without having to set their individual ID?
 
You don't set the AI ID. It is determined by FSX Simconnect server and the ID is given back to you in the

SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID event notification.

if you subscribe to the

// Subscribe to system events notifying the client that objects have been added or removed
hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_ADDED_AIRCRAFT, "ObjectAdded");
hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_REMOVED_AIRCRAFT, "ObjectRemoved");

see the AI traffic sample. So when your other program spawns an AI non ATC you should still get a create notification. My livingworld program does something similar.
 
Thank you I'll see what I can put together.

Just to confirm if I set something like (if Object added set waypoint) that should send to that object without specifying an id?
 
You need the ID

get it when AI created.

Notsure if this will work.

Code:
        case SIMCONNECT_RECV_ID_EVENT_OBJECT_ADDREMOVE:
        {
            SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE *evt = (SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE*)pData;
          
            switch(evt->uEventID)
            {
                    case EVENT_ADDED_AIRCRAFT:
                    printf("\nAI object added: Type=%d, ObjectID=%d", evt->eObjType, evt->dwData);

                    // Mooney aircraft should fly in circles across the North end of the runway

                    wp[0].Flags = SIMCONNECT_WAYPOINT_SPEED_REQUESTED;
                    wp[0].Altitude = 800;
                    wp[0].Latitude = 47 + (27.79/60);
                    wp[0].Longitude = -122 - (18.46/60);
                    wp[0].ktsSpeed = 100;

                    // Send the waypoint to the Mooney
                    hr = SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_WAYPOINT, evt->dwData, 0, ARRAYSIZE(wp), sizeof(wp[0]), wp);

                    break;

                case EVENT_REMOVED_AIRCRAFT:
                    printf("\nAI object removed: Type=%d, ObjectID=%d", evt->eObjType, evt->dwData);
                    break;
            }
            break;
        }
 
Thank you ronh I'm getting somehwere.

The program tells me when the aircraft are added and removed but doesn't seem to send the waypoiint info.
Or if it does the AI from the external program is ignoring it.

Code:
Connected to Flight Simulator!
Received:2
Aircraft added: Type=2, ObjectID=356
Unknown creation -1
Received:1
Aircraft removed: Type=2, ObjectID=356
Unknown creation -1

What I should have mentioned is the AI aircraft appear in the Traffic Explorer as in an init (or sleeping) state.

So what I imagine the Explorer is doing when I send them to a waypoint is setting them to a Waypoint or enroute state.

Is there a way I can set the AI STATE?
For instance does anybody know how the traffic Explorer does it?

I imagine it's an edit around here?
Code:
// Send the waypoint to the Mooney
  hr = SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_WAYPOINT, evt->dwData, 0, ARRAYSIZE(wp), sizeof(wp[0]), wp);
 
Last edited:
If you see init then it's an AI under ATC control - you need to release it.

AI TRAFFIC STATE
English string describing an AI object's state. If the object is an aircraft under ATC control the string will be one of:

"init"
"sleep"
"flt plan"
"startup"

etc.


but init is not in flight so no waypoint. Perhaps you could remove and then re-add it. Then set an INIT waypoint like the example. then set a waypoint.

Code:
    // Add a parked museum aircraft, just west of the runway

    Init.Altitude   = 433.0;                // Altitude of Sea-tac is 433 feet
    Init.Latitude   = 47 + (25.97/60);        // Convert from 47 25.97 N
    Init.Longitude  = -122 - (18.51/60);    // Convert from 122 18.51 W
    Init.Pitch      =  0.0;
    Init.Bank       =  0.0;
    Init.Heading    = 90.0;
    Init.OnGround   = 1;
    Init.Airspeed    = 0;
    hr = SimConnect_AICreateSimulatedObject(hSimConnect, "Douglas DC-3", Init, REQUEST_DOUGLAS);

set waypoint.

Code:
    // Mooney aircraft should fly in circles across the North end of the runway

    wp[0].Flags        = SIMCONNECT_WAYPOINT_SPEED_REQUESTED;
    wp[0].Altitude    = 800;
    wp[0].Latitude    = 47 + (27.79/60);   
    wp[0].Longitude = -122 - (18.46/60);
    wp[0].ktsSpeed    = 100;

    wp[1].Flags        = SIMCONNECT_WAYPOINT_SPEED_REQUESTED;
    wp[1].Altitude    = 600;
    wp[1].Latitude    = 47 + (27.79/60);   
    wp[1].Longitude = -122 - (17.37/60);
    wp[1].ktsSpeed    = 100;

    wp[2].Flags        = SIMCONNECT_WAYPOINT_WRAP_TO_FIRST | SIMCONNECT_WAYPOINT_SPEED_REQUESTED;
    wp[2].Altitude    = 800;
    wp[2].Latitude    = 47 + (27.79/60);   
    wp[2].Longitude = -122 - (19.92/60);
    wp[2].ktsSpeed    = 100;

    // Send the three waypoints to the Mooney
    hr = SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_WAYPOINT, MooneyID, 0, ARRAYSIZE(wp), sizeof(wp[0]), wp);
 
No luck so far.
I've a feeling my waypoints and init positions are not being sent.
If I send a waypoint or key event from the traffic Explorer then I have a printf that displays in the AI traffic program that I have edited.
Where as there is nothing in that program to say that the waypoint has been sent from it.
But it does show as above that an aircraft has been added or removed.

My next step is to enable the Simconnect log to see if it shows the waypoint info being sent.
 
I'm still stuck.

Does anybody know what the Traffic Explorer sends when I select a waypoint?

Or what it sends when I select a runway to takeoff from as that enables the aircraft too.

If it's of any help the aircraft are being created as NonATC AI traffic.
 
Finally cracked it.
Thanks for your help ronh.

Turned out I needed a & and that was it.

Code:
hr = SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_WAYPOINT, MooneyID, 0, ARRAYSIZE(wp), sizeof(wp[0]), &wp);

Thanks again for your help.
 
Andy,

Sorry about the mistake, I blindly copied the SDK example thinking it was correct. Adding the & is what I have in my real code. :banghead:
 
Top