This is a script i made may be its usefull for you:
Code:
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using maddox.GP;
public class Mission : AMission
{
internal class PilotInfo
{
public Player player { get; set; }
public AiAirport StartAirport { get; set; }
public AiAirport DestinationAirport { get; set; }
public AiActor CurrActor { get; set; }
}
internal class PilotList
{
internal AiAirport[] AirportsMap;
internal List<PilotInfo> PilotsInMission = new List<PilotInfo>();
public void AddAirports(AiAirport[] airports)
{
AirportsMap = airports;
}
public void AddPilot(Player player, AiActor actor)
{
foreach (PilotInfo pi in PilotsInMission)
{
if (pi.player == player)
{
if (pi.CurrActor != actor)
{
pi.CurrActor = actor;
pi.StartAirport = getNearestAirfield(player);
if (getEndAirfield(player) != null)
pi.DestinationAirport = getEndAirfield(player);
else //if no Destinationairport (no Waypoints) set Destinationairport = Startairport
pi.DestinationAirport = getNearestAirfield(player);
}
return;
}
}
PilotInfo NewPilot = new PilotInfo();
NewPilot.player = player;
NewPilot.CurrActor = actor;
NewPilot.StartAirport = getNearestAirfield(player);
if (getEndAirfield(player) != null)
NewPilot.DestinationAirport = getEndAirfield(player);
else //if no Destinationairport (no Waypoints) set Destinationairport = Startairport
NewPilot.DestinationAirport = getNearestAirfield(player);
PilotsInMission.Add(NewPilot);
}
private AiAirport getNearestAirfield(Player player)
{
AiAirport NearestAirfield = null;
AiAirport[] airports = AirportsMap;
Point3d PlayerStartPos = player.Place().Pos();
if (airports != null)
{
foreach (AiAirport airport in airports)
{
if (NearestAirfield != null)
{
if (NearestAirfield != null)
if (NearestAirfield.Pos().distance(ref PlayerStartPos) > airport.Pos().distance(ref PlayerStartPos))
NearestAirfield = airport;
}
else NearestAirfield = airport;
}
}
return NearestAirfield;
}
internal AiAirport getNearestAirfield(AiWayPoint waypoint)
{
AiAirport NearestAirfield = null;
AiAirport[] airports = AirportsMap;
Point3d WaypointPos = waypoint.P;
if (airports != null)
{
foreach (AiAirport airport in airports)
{
if (NearestAirfield != null)
{
if (NearestAirfield != null)
if (NearestAirfield.Pos().distance(ref WaypointPos) > airport.Pos().distance(ref WaypointPos))
NearestAirfield = airport;
}
else NearestAirfield = airport;
}
}
return NearestAirfield;
}
public bool checkIsStartAirfield(Player player, double maxdistance)
{
Point3d PlayerPos = player.Place().Pos();
bool tmpIsStartAirfield = false;
foreach (PilotInfo pi in PilotsInMission)
{
if (pi.player == player)
{
if (pi.StartAirport.Pos().distance(ref PlayerPos) < maxdistance)
tmpIsStartAirfield = true;
else
tmpIsStartAirfield = false;
break;
}
}
return tmpIsStartAirfield;
}
public bool checkIsDestinationAirfield(Player player, double maxdistance)
{
Point3d PlayerPos = player.Place().Pos();
bool tmpAirfield = false;
foreach (PilotInfo pi in PilotsInMission)
{
if (pi.player == player)
{
if (pi.DestinationAirport.Pos().distance(ref PlayerPos) < maxdistance)
tmpAirfield = true;
else
tmpAirfield = false;
break;
}
}
return tmpAirfield;
}
public bool checkIsStartAirfield(AiActor actor, double maxdistance)
{
Point3d ActorPos = actor.Pos();
bool tmpIsStartAirfield = false;
foreach (PilotInfo pi in PilotsInMission)
{
if (pi.CurrActor == actor)
{
if (pi.StartAirport.Pos().distance(ref ActorPos) < maxdistance)
tmpIsStartAirfield = true;
else
tmpIsStartAirfield = false;
break;
}
}
return tmpIsStartAirfield;
}
public bool checkIsDestinationAirfield(AiActor actor, double maxdistance)
{
Point3d ActorPos = actor.Pos();
bool tmpAirfield = false;
foreach (PilotInfo pi in PilotsInMission)
{
if (pi.CurrActor == actor)
{
if (pi.DestinationAirport.Pos().distance(ref ActorPos) < maxdistance)
tmpAirfield = true;
else
tmpAirfield = false;
break;
}
}
return tmpAirfield;
}
public AiAirport getEndAirfield(Player player)
{
AiAirport tmpAirport = null;
AiWayPoint[] Wp = player.Place().Group().GetWay();
int i = Wp.Length;
if (i > 0)
{
AiWayPoint EndPoint = Wp[i - 1];
if ((EndPoint as AiAirWayPoint).Action == AiAirWayPointType.LANDING)
tmpAirport = getNearestAirfield(EndPoint);
}
return tmpAirport;
}
public AiAirport returnDestinationAirport(Player player)
{
AiAirport tmpAirport = null;
foreach (PilotInfo pi in PilotsInMission)
{
if (pi.player == player)
{
tmpAirport = pi.DestinationAirport;
}
}
return tmpAirport;
}
}
PilotList AllPilotsInMission = new PilotList();
public override void OnAircraftLanded(int missionNumber, string shortName, AiAircraft aircraft)
{
base.OnAircraftLanded(missionNumber, shortName, aircraft);
GamePlay.gpLogServer(null, "--->gelandet<---", null);
if (aircraft.Player(0) != null)
if (AllPilotsInMission.checkIsStartAirfield(aircraft.Player(0), 2000.0))
GamePlay.gpLogServer(null, "Player ist auf Ausgangsflugplatz gelandet", null);
else
GamePlay.gpLogServer(null, "Player ist NICHT auf Ausgangsflugplatz gelandet", null);
if (aircraft.Player(0) != null)
if (AllPilotsInMission.checkIsDestinationAirfield(aircraft.Player(0), 2000.0))
GamePlay.gpLogServer(null, "Player ist auf Zielflugplatz gelandet", null);
else
GamePlay.gpLogServer(null, "Player ist NICHT auf Zielflugplatz gelandet", null);
}
public override void OnPlaceLeave(Player player, AiActor actor, int placeIndex)
{
base.OnPlaceLeave(player, actor, placeIndex);
// tests
if (actor != null)
if (AllPilotsInMission.checkIsStartAirfield(actor, 2000.0))
GamePlay.gpLogServer(null, "Plane is on Destination Airfield", null);
else
GamePlay.gpLogServer(null, "Plane is NOT on Destination Airfield", null);
if (actor != null)
if (AllPilotsInMission.checkIsDestinationAirfield(actor, 2000.0))
GamePlay.gpLogServer(null, "Plane is on Destination Airfield", null);
else
GamePlay.gpLogServer(null, "Plane is NOT on Destination Airfield", null);
}
public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
{
base.OnPlaceEnter(player, actor, placeIndex);
AllPilotsInMission.AddAirports(GamePlay.gpAirports());
AllPilotsInMission.AddPilot(player, actor);
//tests
if (AllPilotsInMission.checkIsStartAirfield(player, 2000.0))
GamePlay.gpLogServer(null, "Player is on Start Airfield", null);
if (AllPilotsInMission.checkIsDestinationAirfield(player, 2000.0))
GamePlay.gpLogServer(null, "Player is on Destination Airfield", null);
}
}