Fulqrum Publishing Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

Go Back   Official Fulqrum Publishing forum > Fulqrum Publishing > IL-2 Sturmovik: Cliffs of Dover > FMB, Mission & Campaign builder Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 09-12-2011, 01:15 AM
fearlessfrog fearlessfrog is offline
Approved Member
 
Join Date: Jul 2010
Posts: 64
Default Mission Menu and Ambulance

I spent a short bit of time looking at the new Beta API for a 'Mission Menu' and figuring out how to direct traffic. When you crash you can call for an ambulance.

Details and test mission download here:
http://simhq.com/forum/ubbthreads.ph...ml#Post3387861

The interesting part of the script is here:

Code:
else if (menuItemIndex == 6)
      {
          GamePlay.gpHUDLogCenter("Ambulance Dispatched!");

          Player[] all = { player };

          AiActor amb = GamePlay.gpActorByName("0_Chief"); // Our ambulance, defined as 
first vehicle in mission
          if (amb != null)
          {
              AiGroup g = (AiGroup)amb; // Everything with waypoints is always in groups
              AiWayPoint[] waypoints = g.GetWay(); // Get the waypoints it had

              foreach (AiWayPoint waypoint in waypoints)
              {
                  //GamePlay.gpLogServer(all, "waypoint: x=" + waypoint.P.x.ToString() + " y=" + 
waypoint.P.y.ToString(), null);
                  x = waypoint.P.x;
                  y = waypoint.P.y;
                  z = waypoint.P.z; // Remember this for late, as we need a good height from somewhere
              }

              Player me = GamePlay.gpPlayer();
              AiActor where = me.Place();
              Point3d pos = where.Pos(); // Get our position, i.e. where to send the ambulance
              Point3d target = new Point3d(pos.x, pos.y, z); // Set our target to be us

              //GamePlay.gpLogServer(all, "me: x=" + pos.x.ToString() + " y=" + pos.y.ToString()
 + " z=" + pos.z.ToString(), null);

              // Note: Set the z height to be the last waypoint height rather than it's real height, 
Pos seems a PoS
              Point3d last_known = new Point3d(amb.Pos().x, amb.Pos().y, z);

              AiGroundWayPoint[] newWaypoints = { new AiGroundWayPoint(ref last_known, 50.0, 0.0, 10.0),                                                    
                                                    new AiGroundWayPoint(ref target, 50.0, 0.0, 10.0) };

              g.SetWay(newWaypoints); // Off we go, on new route!

              AiWayPoint[] resetWaypoints = g.GetWay(); // Just diagnostics, i.e. can be removed
 but basically to check they took
              foreach (AiWayPoint waypoint in resetWaypoints)
              {
                  //GamePlay.gpLogServer(all, "New waypoint: x=" + waypoint.P.x.ToString() + " y="
 + waypoint.P.y.ToString(), null);
              }

          }
          setMainMenu(player);
      }
Hope that helps put someone on the right spline.
Reply With Quote
  #2  
Old 09-12-2011, 05:36 AM
FG28_Kodiak FG28_Kodiak is offline
Approved Member
 
Join Date: Dec 2009
Location: Swabia->Bavaria->Germany
Posts: 884
Default

Nice Idea
'SAAAAANNNNNIIIIII'

With the new command menu feature, we got a very interesting feature.
Reply With Quote
  #3  
Old 09-12-2011, 06:22 AM
Vengeanze Vengeanze is offline
Approved Member
 
Join Date: Apr 2011
Location: Stockholm
Posts: 837
Default

This is insanely kewl.
What happens if one crash in enemyland and call for ambulance.
Reply With Quote
  #4  
Old 09-12-2011, 06:45 AM
salmo salmo is offline
Approved Member
 
Join Date: Mar 2011
Posts: 632
Default

"... new Beta API for a 'Mission Menu' ..." ???

Where do you access/get a copy of the API?
Reply With Quote
  #5  
Old 09-12-2011, 06:49 AM
fearlessfrog fearlessfrog is offline
Approved Member
 
Join Date: Jul 2010
Posts: 64
Default

The API is part of the beta patch.

As for if you called it from far away, I've not tried it - but waypoint-wise it would just keep trucking till it got to you.
Reply With Quote
  #6  
Old 09-12-2011, 07:27 AM
41Sqn_Banks 41Sqn_Banks is offline
Approved Member
 
Join Date: Oct 2007
Posts: 644
Default

You should use the "GamePlay.gpFindPath()" method to let the game engine calculate the waypoints. This way the car will not cross water and use roads and bridges.

As the calculation of the waypoints is done asynchronous (in a different thread) you have to wait until the calculation is finished:
Code:
IRecalcPathParams pathParams = GamePlay.gpFindPath(start, 10.0, end, 20.0, PathType.GROUND, groundGroup.Army);
// start is the start coordinate, end it the end coordinate, 10.0 and 20.0 how much the calculated way is allowed to differ from start and end point.

while (pathParams.State == RecalcPathState.WAIT)
{
    Game.gpLogServer(new Player[] { Game.gpPlayer() }, "Wait for path.", null);
    // This is not a good idea, I think this would stop the game thread. Better check if the path calculation is finished within the OnTick() method. 
    System.Threading.Thread.Sleep(100);
}
if (pathParams.State == RecalcPathState.SUCCESS)
{
    Game.gpLogServer(new Player[] { Game.gpPlayer() }, "Path found (" +  pathParams.Path.Length.ToString() + ").", null);
    groundGroup.setWay(pathParams.Path)
}
else if(pathParams.State == RecalcPathState.FAILED)
{
    Game.gpLogServer(new Player[] { Game.gpPlayer() }, "Path not found.", null);
}
Note that his should only show you the usage. It's not a good idea to sleep the thread while the game is running. I do it for the IL2DCE mission generation when I create the mission - but at this stage the mission is not running.

Look for navyr's tank war example how to check the result of the path calculation within the OnTick() method.

Last edited by 41Sqn_Banks; 09-12-2011 at 08:01 AM.
Reply With Quote
  #7  
Old 09-12-2011, 10:11 AM
salmo salmo is offline
Approved Member
 
Join Date: Mar 2011
Posts: 632
Default

Quote:
Originally Posted by fearlessfrog View Post
The API is part of the beta patch.
Thankyou fearlessfrog. Maybe the routine could be reworked so that instead of the pilot calling an ambulance via after-crash menu, an ambulance could arrive "automatically".

Pseudocode:
1. On player crash-landing
2. Is crash-landing within home base radius?
3. If so, cycle through vehicle objects and see if there is an ambulance (&/or fire truck)
4. If an ambulance exists, Is the ambulance within the same home base radius as the crash landing?
5. If so, then send the ambulance to the crash site (calculate waypoints).
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:15 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.