Esempio n. 1
0
 public long GetInSystemDistance(SystemLocation location)
 {
     return((long)Math.Sqrt(
                Math.Pow(Math.Abs(X - location.X), 2) +
                Math.Pow(Math.Abs(Y - location.Y), 2)
                ));
 }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public virtual void SetDestSystemLocation(SystemLocation dest)
        {
            if (dest != null && (dest.IsInHyperspace || dest.IsInPlanet))
            {
                dest = null;
            }

            _dsystemLocation  = dest;
            _destinationStamp = DateTime.Now;
            _lastUpdate       = DateTime.Now;
            this.InSpace      = (dest != null) ? true : false;
        }
Esempio n. 4
0
        public SystemLocation GetLocationAtDistance(double dist)
        {
            Random rand = new Random();

            var ns = new SystemLocation(
                this.X - (dist * 2 / rand.Next(1, 5)),
                this.Y - (dist * 2 / rand.Next(1, 5)),
                this.Z
                );

            return(ns);
        }
Esempio n. 5
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));
            }
        }
Esempio n. 6
0
        public SectorObject(SerializationInfo info, StreamingContext context)
        {
            List <string> sNames = new List <string>();

            foreach (var entry in info)
            {
                sNames.Add(entry.Name);
            }

            this._coords         = (Coords)info.GetValue("coord", typeof(Coords));
            this._destination    = (Coords)info.GetValue("destination", typeof(Coords));
            this._speed          = info.GetSingle("speed");
            this._name           = info.GetString("name");
            this._sector         = _coords.GetSector();
            this._systemLocation = (SystemLocation)info.GetValue("sLoc", typeof(SystemLocation));

            if (sNames.Contains("dsLoc"))
            {
                this._dsystemLocation = (SystemLocation)info.GetValue("dsLoc", typeof(SystemLocation));
            }

            this._destinationStamp = info.GetDateTime("dStp");
            this._id         = (Guid)info.GetValue("id", typeof(Guid));
            this._lastUpdate = info.GetDateTime("stp");
            this._systemId   = (SystemId)(ulong)info.GetUInt64("sId");

            if (sNames.Contains("iHy"))
            {
                this.InHiperspace = info.GetBoolean("iHy");
            }
            if (sNames.Contains("iSp"))
            {
                this.InHiperspace = info.GetBoolean("iSp");
            }
            if (sNames.Contains("iPl"))
            {
                this.InHiperspace = info.GetBoolean("iPl");
            }
        }
Esempio n. 7
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;
         }
     }
 }
Esempio n. 8
0
        public void GenerateBody()
        {
            ulong param1 = starSystem.SystemId << 16 | starSystem.SystemId >> 12 + (_systemBodyId & 0xFF);
            ulong param2 = ((ulong)_systemBodyId << 16 | starSystem.SystemId >> 12) + (starSystem.SystemId & 0xFF);

            Utils.Rotate_SystemParams(ref param1, ref param2);

            Random rand = new Random(
                (int)(param1 + param2)
                );

            float hz      = this.StarSystem.HZone;
            float minDist = hz * 0.2F;
            float maxDist = hz * 60.0F;

            //No planets more then 5000Au away
            if (maxDist > 5000)
            {
                maxDist = 5000;
            }
            if (minDist > 600)
            {
                minDist = 600;
            }

            int totalBodies = this.StarSystem.NumberOfBodies;

            double pNum = (_systemBodyId + 1) * 0.9;
            double pMin = ((Math.Pow(2, pNum - 1)) * (maxDist - minDist) / ((Math.Pow(2, totalBodies - 1)))) + minDist;
            double pMax = ((Math.Pow(2, pNum)) * (maxDist - minDist) / ((Math.Pow(2, totalBodies - 1)))) + minDist;

            double spreadHint   = pMax - pMin;
            double baseDistance = rand.NextDouble() * (spreadHint / 2) + pMin;

            List <SystemBodyType> eTypes = new List <SystemBodyType>();

            for (int i = 0; i < PlanetBaseDistance.Length; i++)
            {
                double mind = PlanetBaseDistance[i][0] * hz;
                double maxd = PlanetBaseDistance[i][1] * hz;
                if (baseDistance >= mind && baseDistance <= maxd)
                {
                    eTypes.Add((SystemBodyType)i);
                }
            }

            if (eTypes.Count == 0)
            {
                eTypes.Add(SystemBodyType.RockyPlanetoid);
                eTypes.Add(SystemBodyType.Asteroid);
            }

            _systemBodyType = eTypes[rand.Next(0, eTypes.Count - 1)];

            if ((int)_systemBodyType > 11)
            {
                _systemBodyType = SystemBodyType.Asteroid;
            }

            int    baseTempA = PlanetBaseTemperature[(int)_systemBodyType][0];
            int    baseTempB = PlanetBaseTemperature[(int)_systemBodyType][1];
            int    baseTempR = baseTempA - baseTempB;
            double baseDistA = (double)(PlanetBaseDistance[(int)_systemBodyType][0] * hz);
            double baseDistB = (double)(PlanetBaseDistance[(int)_systemBodyType][1] * hz);
            double baseDistR = baseDistB - baseDistA;

            _temperature = (int)(
                baseTempA - (
                    (Math.Pow(baseDistance, 0.2) - Math.Pow(baseDistA, 0.2))
                    / Math.Pow(baseDistR, 0.2) * baseTempR
                    )
                );

            _distance      = (float)baseDistance;
            _orbitalPeriod = (float)Math.Round(Math.Pow(_distance, 1.5) * 1000, 5) / 1000;
            _radius        = rand.Next(20, 1000) / 100;
            _angle         = rand.Next(0, 360);

            //double rad = 0.0174532925;

            //double ssX = (long)(_distance * Math.Cos(_angle * rad) * 149598000);
            //double ssY = (long)(_distance * Math.Sin(_angle * rad) * 149598000);
            //double ssZ = 0;
            //this.SystemLocation.SetInSystemCoords(ssX, ssY, ssZ);

            SystemLocation.UpdateLocation(this);

            this._nrConcentration = new Dictionary <NaturalResource, int>();

            for (int i = 0; i < NaturalResource.Count; i++)
            {
                NaturalResource r = NaturalResource.GetNaturalResource(i);
                int             c = rand.Next(
                    r.Concentration[_systemBodyType].Minimum,
                    r.Concentration[_systemBodyType].Maximum);
                this._nrConcentration.Add(r, c);
            }
        }
Esempio n. 9
0
        public void GenerateSolBodies(int systemBodyId)
        {
            switch (systemBodyId)
            {
            case 0:
                this.Name            = "Mercury";
                this._systemBodyType = SystemBodyType.Inferno;
                this._numOfZones     = 0;
                this._distance       = 0.41F;
                this._orbitalPeriod  = 0.24F;
                this._temperature    = 396;
                break;

            case 1:
                this.Name            = "Venus";
                this._systemBodyType = SystemBodyType.Venuzian;
                this._numOfZones     = 2;
                this._distance       = 0.72F;
                this._orbitalPeriod  = 0.65F;
                this._temperature    = 480;
                break;

            case 2:
                this.Name            = "Earth";
                this._systemBodyType = SystemBodyType.Terrestrial;
                this._numOfZones     = 4;
                this._distance       = 1F;
                this._orbitalPeriod  = 1F;
                this._temperature    = 22;
                break;

            case 3:
                this.Name            = "Mars";
                this._systemBodyType = SystemBodyType.RockyWorld;
                this._numOfZones     = 3;
                this._distance       = 1.45F;
                this._orbitalPeriod  = 1.88F;
                this._temperature    = -25;
                break;

            case 4:
                this.Name            = "Jupiter";
                this._systemBodyType = SystemBodyType.GasGiant;
                this._distance       = 5.42F;
                this._orbitalPeriod  = 11.8F;
                this._temperature    = -161;
                break;

            case 5:
                this.Name            = "Saturn";
                this._systemBodyType = SystemBodyType.RingedGasGiant;
                this._distance       = 10.11F;
                this._orbitalPeriod  = 29.45F;
                this._temperature    = -190;
                break;

            case 6:
                this.Name            = "Uranus";
                this._systemBodyType = SystemBodyType.SubGasGiant;
                this._distance       = 20.08F;
                this._orbitalPeriod  = 84.32F;
                this._temperature    = -224;
                break;

            case 7:
                this.Name            = "Neptune";
                this._systemBodyType = SystemBodyType.SubGasGiant;
                this._distance       = 30.44F;
                this._orbitalPeriod  = 164.79F;
                this._temperature    = -218;
                break;

            case 8:
                this.Name            = "Pluto";
                this._systemBodyType = SystemBodyType.RockyPlanetoid;
                this._distance       = 33.45F;
                this._orbitalPeriod  = 248.09F;
                this._temperature    = -260;
                break;
            }

            SystemLocation.UpdateLocation(this);
        }