/// <summary> /// Initializes Traveler and calculates the time of the travel (from the distance between /// SolarSystems). Also creates the object invisible and removes it from current SolarSystem. /// </summary> /// <param name="from">The SolarSystem with the traveler</param> /// <param name="to">The target SolarSystem of the traveler</param> /// <param name="traveler">The traveling object</param> public Traveler(SolarSystem from, SolarSystem to, IMovableGameObject traveler) { this.from = from; this.to = to; this.traveler = traveler; long travelTime = (long)GetSquareOfDistance(from, to); timeToGo = new Property<TimeSpan>(new TimeSpan(travelTime*60)); // Multiply by 60 traveler.Stop(); // Removes from current SolarSystem from.RemoveIMGO(traveler); traveler.ChangeVisible(false); }
/// <summary> /// Calculates squared distance between given SolarSystems. /// </summary> /// <param name="s1">The first SolarSystem.</param> /// <param name="s2">The second SolarSystem.</param> /// <returns></returns> private static double GetSquareOfDistance(SolarSystem s1, SolarSystem s2) { double xd = s2.Position.x - s1.Position.x; double yd = s2.Position.y - s1.Position.y; double zd = s2.Position.z - s1.Position.z; double squareOfDistance = (xd * xd + yd * yd + zd * zd); return squareOfDistance; }