1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

About AIObject

Discussion in 'SimConnect' started by guodah, 9/3/07.

  1. guodah

    guodah

    Joined:
    9/10/06
    Messages:
    8
    Country:
    us-florida
    Hello,

    I try to understand the example of AIObject. But I am confused by the following things

    1. When the AIObject connects to the simulator, it seems the client receives an event "SIMCONNECT_RECV_ID_EVENT". Then the first event must be "EVENT_SIM_START". Its handler must enable the user inputs. Is that true?

    2. When the user is setting up the objects, function SimConnect_AICreateNonATCAircraft/AICreateSimulatedObject is called. A request ID is passed into the function as an argument, such as REQUEST_BELL, REQUEST_BALLOON1, etc.

    3. The next step is the most confusing to me. When the user is sending the plans for created objects, it seems that funciton SimConnect_SetDataOnSimObject already knows the plan is given to which object. But I do not see (in the funciton call) the request ID, used in creating objects. What I do see is an Object ID, such as MooneyID or TruckID. My understanding is that after an object is created, the simulator sends another event, SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID. In the handler, I see the request IDs and the Object IDs are associated. Is that correct?

    4. The last question is whether it is possible to real-time change the position of an object. I notice that there is a function, SimConnect_RequestDataOnSimObject, requests data of objects every some time. Is that possible to use this function to generate events to let the client handle so that the client can alter the position of objects.

    Thanks,
    guodah
  2. ronh

    ronh

    Joined:
    2/11/06
    Messages:
    393
    Country:
    canada
    Guodah

    The first thing that happens is the testSimObjects() function is run. This function map client events to sim events and connects to FSX.

    // Request a simulation start event
    hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM_START, "SimStart");

    It sets up the X,Z key to set the simobjects andflight plans.

    hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT_ZX, "X", EVENT_X);
    hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT_ZX, "Z", EVENT_Z);


    It then goes into the message loop - typical windows behaviour.

    while ( 0 == quit)

    The dispatch function is called to process maessages form simconnect/FSX.

    SimConnect_CallDispatch(hSimConnect, MyDispatchProcSO, NULL);

    The MyDispatchProcSO process all the messages. In this case Z key creates AI and the X key fills in the flight plans and the AI should do what is requested via the waypoints.

    case EVENT_Z:
    if (!objectsCreated)
    {
    setUpSimObjects();
    objectsCreated = true;
    }
    break;

    case EVENT_X:
    if (!plansSent && objectsCreated)
    {
    sendFlightPlans();
    plansSent = true;
    }
    break;

    So you create the AI with the Z key and when you see the messages you can create the flight plans.

    My LivingWorld Program was basically this example file modified to work with an INI file to add moving simobjects to FSX.

    Yes you can move a sim object around - you first need to delete the AI object and give it a new position and recreate the AI.
    Last edited: 9/3/07
  3. guodah

    guodah

    Joined:
    9/10/06
    Messages:
    8
    Country:
    us-florida
    Can I have a copy of your Living World Program?

    Dear Ron,

    Thank you very much for your post.

    That would be great, if you can let me have a copy of your Living World Program.

    Thanks,
    Dahai
  4. ronh

    ronh

    Joined:
    2/11/06
    Messages:
    393
    Country:
    canada
    Dahai,

    It is available on AVSIM and FLightSIm. I'm sorry I don't want to share the source code yet. Once I finish the C# version perhaps.
  5. flight884

    flight884

    Joined:
    19/6/07
    Messages:
    2
    Country:
    unitedstates
    So lemme get this straight - once you initially assign 'waypoints' to an object, you cannot add more?

    -flight884
  6. FlapsOut

    FlapsOut

    Joined:
    29/5/07
    Messages:
    75
    Country:
    us-texas
    Technical Point on AICreateNonATCAircraft

    Technical Point,

    In fact, You do not have to delete the AI Aircraft created by AICreateNonATCAircraft, and you can quite easily cause it to move about (programmatically). And! You are indeed on the right track, but check out 'SetDataOnSimObject'. ;)

    In my case? I am interested in linking to a player (NOT IN MY GAME OR SESSION). I receive his data external to SimConnect, and then move his aircraft accordingly.

    Source-Code Fragments on Request ;)

    I need to clean it up tho...lots of experimenting :rolleyes:

    And, yes, Guodah, You are quite correct...It was confusing. >.<

    BTW, Source is entirely C# and .Net...

    Flaps
    Last edited: 21/6/07
  7. FlapsOut

    FlapsOut

    Joined:
    29/5/07
    Messages:
    75
    Country:
    us-texas
    Moving an AINonATCAircraft

    Hi flight884,

    I received your request for the code snippets.

    Ok, Here is what I have done...

    In order to facilitate conversation along this line, I have modified (yet again) my test-bed program Innergears.exe.

    I added a new Menu-Item called: "InnerGears AIObjects".
    and a Sub-Menu under it called: "Create/Move AINonATCAircraft".

    When you click on the Sub-Menu Item, a window pops up, which simply has a button to 'Create an Airbus', another to 'Move the Airbus', and another to 'Remove the Airbus'.

    For an explanation of the other menu items, please read my other posts on the various subjects we've already discussed.

    The application is as always here:
    http://www.innergears.com/innergears.zip

    The source code for the pop-up window, which contains all the code necessary is here:
    http://www.innergears.com/MoveAINonATCAircraft.zip

    Hopefully, my in-line documentation is clear enough.

    To avoid confusion, I simply included the entire source for the pop-up window, rather than just snippets. :)

    You may want to modify it to actually go down the Center-Line...I have no 'Center-Line Pride' at all. :p

    Flaps

    P.S. I suppose along these lines, you could for instance, 'record' your flight every second or so, then play it back using an AI Aircraft? Might be useful...dunno
  8. PeetyGreen

    PeetyGreen

    Joined:
    4/6/08
    Messages:
    41
    Country:
    us-virginia
    Creating Aircraft with AICreateNonATCAircraft()

    New to SimConnect. Simply trying to create a new Aircraft in my Sim.
    I'm trying to work through the sdk code sample and while it's not throwing an error when I call SimConnect_AICreateNonATCAircraft(), I don't see any new aircraft (ground or air).

    Also I'm passing it like so

    HRESULT hr;
    hr = SimConnect_AICreateNonATCAircraft(hSimConnect, "Mooney Bravo", "N1001", Init, REQUEST_MOONEY);

    I set my (SIMCONNECT_DATA_INITPOSITION Init) as well

    Am I missing a step? Do I need to install sp?

    Thanks
    Last edited: 23/6/08
  9. ronh

    ronh

    Joined:
    2/11/06
    Messages:
    393
    Country:
    canada
    PeetyGreen,

    We need a little bit more infomation.

    What version of FSX? RTM, SP1a, SP2

    Ensure you have the same version of SDK also installed.

    I assume you can get the example AI objects and WayPoints to compile and run. You press the Z key to initialize them.
  10. PeetyGreen

    PeetyGreen

    Joined:
    4/6/08
    Messages:
    41
    Country:
    us-virginia
    Hey RunH, thanks for your response.

    Currently I'm using the RTM (manufacturer release) w/o any service packs installed. I installed the sdk that comes on the Deluxe Edition disk.

    My connection is using Java (Java Native Interface). This establishes the connection and simply calls the methods setUpSimObjects() and testSimObjects().

    I've been unsuccessful in getting the example AI objects and WayPoints to to work.

    Thanks...
  11. PeetyGreen

    PeetyGreen

    Joined:
    4/6/08
    Messages:
    41
    Country:
    us-virginia
    Ok, I was finally able to get it working.. Was a number of things incl. the Sleep() function within the TestSimObject. Not sure what this should be doing, but removed it and it worked.

    Noticed when I switched between environments (FSX and Java (Eclipse)) it would cause my Simulation client to loose the connection. Not sure of any good work arounds for this?

    Thanks
  12. ronh

    ronh

    Joined:
    2/11/06
    Messages:
    393
    Country:
    canada
    I'm not sure I can help now. Java - does that mean you are using jSimConnect?

    Personally, I know that the RTM version of the example program worked. I have compiled and run it and used it as a base template for my own program. It works with Visual C++ Express 2005.

    There are some slight changes when you go to SP1a and SP2.

    EDIT ******* seems I posted just as you were posting. - Still do not know of any work around

Share This Page