Ejemplo n.º 1
0
        public static CoordsCalculationResult CalculateNext
            (SystemLocation actual, SystemLocation dest, float speed, out SystemLocation calculated)
        {
            //Cant travel to an unreachable destination
            if (dest == null || dest.IsInHyperspace || dest.IsInPlanet)
            {
                calculated = actual;
                return(CoordsCalculationResult.None);
            }

            double distanceToDest = actual.GetInSystemDistance(dest);

            if (distanceToDest == 0)
            {
                calculated = dest;
                return(CoordsCalculationResult.End);
            }

            double diffX = actual.X - dest.X;
            double diffY = actual.Y - dest.Y;
            double diffZ = actual.Z - dest.Z;

            double speedDiffX = (speed * diffX / distanceToDest);
            double speedDiffY = (speed * diffY / distanceToDest);
            double speedDiffZ = (speed * diffZ / distanceToDest);

            int overflow = 0;

            if (Math.Abs(speedDiffX) >= Math.Abs(diffX))
            {
                speedDiffX = diffX; overflow++;
            }
            if (Math.Abs(speedDiffY) >= Math.Abs(diffY))
            {
                speedDiffY = diffY; overflow++;
            }
            if (Math.Abs(speedDiffZ) >= Math.Abs(diffZ))
            {
                speedDiffZ = diffZ; overflow++;
            }

            if (overflow == 3 || (speedDiffX == 0 && speedDiffY == 0 && speedDiffZ == 0))
            {
                calculated = dest;
                return(CoordsCalculationResult.End);
            }

            SystemLocation newLocation = new SystemLocation(
                actual.X - speedDiffX,
                actual.Y - speedDiffY,
                actual.Z - speedDiffZ
                );

            calculated = newLocation;
            return(CoordsCalculationResult.Continues);
        }
Ejemplo n.º 2
0
        public virtual TimeSpan GetInSystemETA()
        {
            if (dSystemLocation == null)
            {
                return(TimeSpan.FromSeconds(0));
            }

            SystemLocation destination = (dSystemLocation == null) ? SystemLocation : dSystemLocation;

            double distanceToDest = SystemLocation.GetInSystemDistance(destination);

            if (distanceToDest != 0 && !double.IsNaN(distanceToDest) && sysSpeed > 0)
            {
                return(TimeSpan.FromMinutes(distanceToDest / (sysSpeed * 15)));
            }
            else
            {
                return(TimeSpan.FromMinutes(0));
            }
        }
Ejemplo n.º 3
0
 public void UpdateSystemBody(SystemLocation location, bool inSpace)
 {
     if (this.StarSystem != null)
     {
         if (!inSpace)
         {
             foreach (var body in this.StarSystem.SystemBodies)
             {
                 if (location.GetInSystemDistance(
                         SystemLocation.GetUpdatedLocation(body)
                         ) <= (384403))
                 {
                     this.SystemBody = body;
                     break;
                 }
             }
         }
         else
         {
             this.SystemBody = null;
         }
     }
 }