public string GetOnlineUsersInfo() { string info = ""; if (Simulator.PlayerLocomotive.Train.TrainType == Train.TRAINTYPE.REMOTE) { info = "Your locomotive is a helper\t"; } info += ("" + (OnlineTrains.Players.Count + 1) + (OnlineTrains.Players.Count <= 0 ? " player " : " players ")); info += ("" + Simulator.Trains.Count + (Simulator.Trains.Count <= 1 ? " train" : " trains")); TrainCar mine = Simulator.PlayerLocomotive; users.Clear(); try//the list of players may be changed during the following process { //foreach (var train in Simulator.Trains) info += "\t" + train.Number + " " + train.Cars.Count; //info += "\t" + MPManager.OnlineTrains.Players.Count; //foreach (var p in MPManager.OnlineTrains.Players) info += "\t" + p.Value.Train.Number + " " + p.Key; foreach (OnlinePlayer p in OnlineTrains.Players.Values) { if (p.Train == null) { continue; } if (p.Train.Cars.Count <= 0) { continue; } var d = WorldLocation.GetDistanceSquared(p.Train.RearTDBTraveller.WorldLocation, mine.Train.RearTDBTraveller.WorldLocation); users.Add(Math.Sqrt(d) + MPManager.Random.NextDouble(), p.Username); } } catch (Exception) { } if (metric == "") { metric = Simulator.TRK.Tr_RouteFile.MilepostUnitsMetric == true ? " m" : " yd"; metricbase = Simulator.TRK.Tr_RouteFile.MilepostUnitsMetric == true ? 1.0f : 1.0936133f; } int count = 0; foreach (var pair in users) { if (count >= 10) { break; } info += "\t" + pair.Value + ": distance of " + (int)(pair.Key / metricbase) + metric; count++; } if (count < OnlineTrains.Players.Count) { info += "\t ..."; } return(info); }
public void WorldLocationDistanceZeroTest() { WorldLocation location1 = new WorldLocation(); WorldLocation location2 = new WorldLocation(); Assert.IsTrue(WorldLocation.Within(location1, location2, 0)); Assert.AreEqual(0, WorldLocation.GetDistanceSquared(location1, location2)); Assert.AreEqual(Microsoft.Xna.Framework.Vector3.Zero, WorldLocation.GetDistance(location1, location2)); Assert.AreEqual(Microsoft.Xna.Framework.Vector2.Zero, WorldLocation.GetDistance2D(location1, location2)); }
private PathChartPoint CreateBrokenChartPoint(TrainpathNode thisNode, TrainpathNode nextNode) { float height = thisNode.Location.Location.Y; float distance = (float)Math.Sqrt(WorldLocation.GetDistanceSquared(thisNode.Location, nextNode.Location)); float heightOther = nextNode.Location.Location.Y; float grade = (heightOther - height) / distance; float curvature = 0; PathChartPoint brokenPoint = new PathChartPoint(height, curvature, grade, distance); return(brokenPoint); }
public void WorldLocationDistanceTest() { WorldLocation location1 = new WorldLocation(); WorldLocation location2 = new WorldLocation(1, -1, Microsoft.Xna.Framework.Vector3.Zero); Assert.AreEqual(2048 * 2048 + 2048 * 2048, WorldLocation.GetDistanceSquared(location1, location2)); Assert.IsTrue(WorldLocation.Within(location1, location2, (float)Math.Sqrt(2048 * 2048 * 2) + 1)); Assert.AreEqual(new Microsoft.Xna.Framework.Vector3(2048, 0, -2048), WorldLocation.GetDistance(location1, location2)); Assert.AreEqual(new Microsoft.Xna.Framework.Vector2(2048, -2048), WorldLocation.GetDistance2D(location1, location2)); }
public string GetOnlineUsersInfo() { StringBuilder info = new StringBuilder(); if (Simulator.Instance.PlayerLocomotive.Train.TrainType == TrainType.Remote) { info.Append("Your locomotive is a helper\t"); } info.Append($"{OnlineTrains.Players.Count + 1}{(OnlineTrains.Players.Count <= 0 ? " player " : " players ")}"); info.Append($"{Simulator.Instance.Trains.Count}{(Simulator.Instance.Trains.Count <= 1 ? " train" : " trains")}"); TrainCar mine = Simulator.Instance.PlayerLocomotive; users.Clear(); try//the list of players may be changed during the following process { //foreach (var train in Simulator.Trains) info += "\t" + train.Number + " " + train.Cars.Count; //info += "\t" + MPManager.OnlineTrains.Players.Count; //foreach (var p in MPManager.OnlineTrains.Players) info += "\t" + p.Value.Train.Number + " " + p.Key; foreach (OnlinePlayer p in OnlineTrains.Players.Values) { if (p.Train == null) { continue; } if (p.Train.Cars.Count <= 0) { continue; } double d = WorldLocation.GetDistanceSquared(p.Train.RearTDBTraveller.WorldLocation, mine.Train.RearTDBTraveller.WorldLocation); users.Add(Math.Sqrt(d) + Random.NextDouble(), p.Username); } } catch (Exception) { } if (string.IsNullOrEmpty(metric)) { metric = Simulator.Instance.Route.MilepostUnitsMetric ? " m" : " yd"; } foreach (KeyValuePair <double, string> pair in users.Take(10)) { info.Append($"\t{pair.Value}: distance of {(int)(Simulator.Instance.Route.MilepostUnitsMetric ? pair.Key : Size.Length.ToYd(pair.Key)) + metric}"); } if (OnlineTrains.Players.Count > 10) { info.Append("\t ..."); } return(info.ToString()); }