|
#1
|
|||
|
|||
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); } |
#2
|
|||
|
|||
Nice Idea
'SAAAAANNNNNIIIIII' With the new command menu feature, we got a very interesting feature. |
#3
|
|||
|
|||
This is insanely kewl.
What happens if one crash in enemyland and call for ambulance. |
#4
|
|||
|
|||
"... new Beta API for a 'Mission Menu' ..." ???
Where do you access/get a copy of the API? |
#5
|
|||
|
|||
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. |
#6
|
|||
|
|||
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); } 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. |
#7
|
|||
|
|||
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). |
|
|