public void AddOrUpdateShuttle(int shuttleId, Coordinate location, string name, int bearing, string cardinalPoint, int speed, int route = -1)
{
Shuttle s = this.shuttles[shuttleId];
Route r = this.routes[route];
if (s == null)
{
s = new Shuttle();
s.Id = shuttleId;
s.Location = location;
s.Name = name;
s.Bearing = bearing;
s.CardinalPoint = cardinalPoint;
s.Speed = speed;
s.LastUpdateTime = CurrentTimeMillis();
this.shuttles.Add(s.Id, s);
if (r != null)
{
s.CurrentRoute = r;
r.shuttles.Add(s.Id, s);
}
s.SnapToRoute();
}
else
{
s.LastUpdateTime = CurrentTimeMillis();
s.Location = location;
s.Speed = speed;
s.Bearing = bearing;
s.CardinalPoint = cardinalPoint;
s.Name = name;
if (r == null && s.CurrentRoute != null)
{
s.CurrentRoute.shuttles.Remove(s.Id);
s.CurrentRoute = null;
}
else if (r != null && s.CurrentRoute != null && s.CurrentRoute != r)
{
s.CurrentRoute.shuttles.Remove(s.Id);
s.CurrentRoute = r;
r.shuttles.Add(s.Id, s);
}
else if (r != null && s.CurrentRoute == null)
{
s.CurrentRoute = r;
r.shuttles.Add(s.Id, s);
}
s.SnapToRoute();
}
}