/// <summary> /// Adds a shuttle to the world or updates the position of an existing shuttle. /// </summary> /// <param name="shuttleId">The ID number of the shuttle.</param> /// <param name="location">The shuttle's current location.</param> /// <param name="name">The name of the shuttle.</param> /// <param name="bearing">The heading of the shuttle in degrees from north.</param> /// <param name="cardinalPoint">The heading of the shuttle as a cardinal direcation (e.g. Northwest).</param> /// <param name="speed">The speed of the shuttle in miles per hour.</param> /// <param name="route">The id of the shuttle route. -1 indicates that the shuttle is not on a route.</param> 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(); } }