public void AssignAverageWaypoint() { if (Waypoints.Count < 2 || Waypoints.Any(x => x.IsAverage)) { return; } var averageX = Waypoints.Sum(x => x.X) / Waypoints.Count; var averageY = Waypoints.Sum(x => x.Y) / Waypoints.Count; var averageZ = Waypoints.Sum(x => x.Z) / Waypoints.Count; var order = Waypoints.OrderBy(x => x.Index).ThenBy(x => x.Time); var waypoint = order.FirstOrDefault(x => x.O != 0f); if (waypoint == null) { waypoint = order.FirstOrDefault(); } var o = waypoint.O; var nearest = Waypoints.OrderBy(x => x.Distance(averageX, averageY, averageZ)).First(); var farthestDistance = Waypoints.Select(x => x.Distance(averageX, averageY, averageZ)).Max(); nearest.IsAverage = true; nearest.EstimatedSpawnDistance = farthestDistance; }
/// <summary> /// Registers and returns a new ID for an object of the given type. /// </summary> /// <returns>A new unique ID that can be used to identify the object.</returns> public int RegisterWaypointID() { if (Waypoints.Any() && _waypointID <= Waypoints.Max(e => e.ID)) { _waypointID = Waypoints.Max(e => e.ID) + 1; } return(_waypointID++); }
public GeoCoordinate NextStep(GeoCoordinate actualLocation) { if (!Waypoints.Any()) { return(_lastNextStep ?? (_lastNextStep = actualLocation)); } do { _lastNextStep = Waypoints.FirstOrDefault(); Waypoints.Remove(_lastNextStep); } while (actualLocation.GetDistanceTo(_lastNextStep) < 20 || Waypoints.Any()); return(_lastNextStep); }
/// <summary> /// Sanity checks the instance. /// </summary> /// <returns>All errors that were recognized.</returns> public List <Tuple <SanityError, string> > SanityCheck() { List <Tuple <SanityError, string> > errors = new List <Tuple <SanityError, string> >(); // Check dead end waypoints foreach (var waypoint in Waypoints) { if (!waypoint.Paths.Any()) { errors.Add(new Tuple <SanityError, string>(SanityError.DeadEnd, waypoint.ToString())); } } // Check dead end waypoints by blocking foreach (var waypoint in Waypoints) { if (!waypoint.Paths.Any(other => !other.PodStorageLocation)) { errors.Add(new Tuple <SanityError, string>(SanityError.DeadEnd, waypoint.ToString())); } } // Check blockable storage locations foreach (var storageLocation in Waypoints.Where(w => w.PodStorageLocation)) { if (!Waypoints.Any(otherWP => !otherWP.PodStorageLocation && otherWP.ContainsPath(storageLocation))) { errors.Add(new Tuple <SanityError, string>(SanityError.BlockableStorageLocation, storageLocation.ToString())); } } // Check resting positions int storageLocations = Waypoints.Count(w => w.PodStorageLocation); if (storageLocations - Pods.Count < Bots.Count) { errors.Add(new Tuple <SanityError, string>(SanityError.InsufficientRestingPositions, "StorageLocations-Pods<Bots:" + storageLocations + "-" + Pods.Count + "<" + Bots.Count)); } // Return the list return(errors); }
public void Move(Duration time) { var speed = MaxSpeed; if (Waypoints?.Any() == true) { var delta = Waypoints.First().Position - Position; Velocity = new Velocity(speed, delta); } else { Velocity = null; return; } var target = Waypoints.First().Position; var distanceToTarget = target.DistanceTo(Position); var distanceCovered = speed * time; if (distanceToTarget > distanceCovered) { var pct = distanceCovered / distanceToTarget; var targetDelta = target - Position; var moveDelta = targetDelta * pct; Position += moveDelta; } else { Position = target; Waypoints.RemoveAt(0); if (Waypoints.Any() == false) { Waypoints = null; } } }
protected override QueryStringParametersList GetQueryStringParameters() { if (string.IsNullOrWhiteSpace(Origin)) { throw new ArgumentException("Must specify an Origin"); } if (string.IsNullOrWhiteSpace(Destination)) { throw new ArgumentException("Must specify a Destination"); } if (!Enum.IsDefined(typeof(AvoidWay), Avoid)) { throw new ArgumentException("Invalid enumeration value for 'Avoid'"); } if (!Enum.IsDefined(typeof(TravelMode), TravelMode)) { throw new ArgumentException("Invalid enumeration value for 'TravelMode'"); } if (TravelMode == TravelMode.Transit && (DepartureTime == default(DateTime) && ArrivalTime == default(DateTime))) { throw new ArgumentException("You must set either DepatureTime or ArrivalTime when TravelMode = Transit"); } var parameters = base.GetQueryStringParameters(); parameters.Add("origin", Origin); parameters.Add("destination", Destination); parameters.Add("mode", TravelMode.ToString().ToLower()); if (Alternatives) { parameters.Add("alternatives", "true"); } if (Avoid != AvoidWay.Nothing) { parameters.Add("avoid", Avoid.ToString().ToLower()); } if (!string.IsNullOrWhiteSpace(Language)) { parameters.Add("language", Language); } if (Waypoints != null && Waypoints.Any()) { IEnumerable <string> waypoints; if (OptimizeWaypoints) { const string optimizeWaypoints = "optimize:true"; waypoints = new string[] { optimizeWaypoints }.Concat(Waypoints); } else { waypoints = Waypoints; } parameters.Add("waypoints", string.Join("|", waypoints)); } if (ArrivalTime != default(DateTime)) { parameters.Add("arrival_time", UnixTimeConverter.DateTimeToUnixTimestamp(ArrivalTime).ToString(CultureInfo.InvariantCulture)); } if (DepartureTime != default(DateTime)) { parameters.Add("departure_time", UnixTimeConverter.DateTimeToUnixTimestamp(DepartureTime).ToString(CultureInfo.InvariantCulture)); } return(parameters); }