Ejemplo n.º 1
0
        bool LambertSolutionExists()
        {
            // Make local copies of departure and arrival orbits.
            OrbitData earthCopy    = null;
            OrbitData asteroidCopy = null;

            foreach (Body body in Bodies)
            {
                if (body.tag == "Earth")
                {
                    earthCopy = new OrbitData(body.Orbit);
                }
                else if (body.tag == "Asteroid")
                {
                    asteroidCopy = new OrbitData(body.Orbit);
                }
            }

            // Advance orbits to epoch of impact for Lambert solver
            earthCopy.Epoch    = ImpactEpoch;
            asteroidCopy.Epoch = ImpactEpoch;

            // Get the transfer orbit and C3 from the Lambert solution
            LambertSolution lambertSolution = Lambert.GetTransferOrbit(earthCopy, asteroidCopy, TimeOfDeflection, TransferTime, -1);

            if (lambertSolution == null)
            {
                Debug.Log("No Lambert solution found\nTry different mission values.");
                ShowInfeasibleLaunchWindow();
                return(false);
            }

            if (lambertSolution.C3 <= 0.0)
            {
                Debug.Log("Lambert solution requires negative C3");
                ShowInfeasibleLaunchWindow();
                return(false);
            }

            double deliverableMass = LaunchVehicleType.ComputeDeliverableMass(lambertSolution.C3, NumLaunches * EffectMultiplier);

            if (deliverableMass <= 0.0)
            {
                Debug.LogFormat("Launch C3 = {0:F4}\nLaunch Vehicle unable to obtain required launch energy",
                                lambertSolution.C3);
                ShowInfeasibleLaunchWindow();
                return(false);
            }
            Debug.LogFormat("Launch C3 = {0:F4}Impact Mass = {1:F4}; Impact Vel. = {2:E4}",
                            lambertSolution.C3, MassKI, lambertSolution.arrDV.magnitude);
            SetMissionValuesText(deliverableMass, lambertSolution.C3, lambertSolution.arrDV.magnitude);
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Launches a spacecraft from Earth to intercept/deflect the asteroid.
        /// </summary>
        public void LaunchSpacecraft()
        {
            // Make local copies of departure and arrival orbits.
            OrbitData earth    = null;
            OrbitData asteroid = null;

            foreach (Body body in Bodies)
            {
                if (body.tag == "Earth")
                {
                    earth = new OrbitData(body.Orbit);
                }
                else if (body.tag == "Asteroid")
                {
                    asteroid = new OrbitData(body.Orbit);
                }
            }
            if (earth == null || asteroid == null)
            {
                Debug.LogError("Error finding departure/arrival orbits from bodies list by tag");
                return;
            }

            // Advance orbits to epoch of impact for Lambert solver
            earth.Epoch    = ImpactEpoch;
            asteroid.Epoch = ImpactEpoch;

            // Get the transfer orbit and C3 from the Lambert solution
            LambertSolution lambertSolution = Lambert.GetTransferOrbit(earth, asteroid, TimeOfDeflection, TransferTime, -1);

            if (lambertSolution == null || lambertSolution.C3 <= 0.0)
            {
                DisplayTextWithFadeEffect(MessageText, "No Lambert solution found");
                return;
            }

            // MassKI calculated here will be used in ProcessCollisionEnter
            MassKI = LaunchVehicleType.ComputeDeliverableMass(lambertSolution.C3, NumLaunches * EffectMultiplier);
            if (MassKI <= 0.0)
            {
                DisplayTextWithFadeEffect(MessageText, string.Format("Launch vehicle unable to achieve C3 {0:E3} (km/s)^2", lambertSolution.C3));
                return;
            }

            // TODO: Initialize spacecraft from prefab here
            //GameObject prefab = Instantiate(Resources.Load("Spacecraft.prefab", typeof(GameObject)) as GameObject);
            Body spacecraft = spacecraftObject.GetComponent <Body>();

            if (spacecraft == null)
            {
                Debug.LogError("Instantiated spacecraft prefab does not have Body component");
            }
            spacecraft.InitOrbit(lambertSolution.TransferOrbit);
            spacecraft.SetImpactEpoch(ImpactEpoch - TimeOfDeflection);
            spacecraft.gameObject.SetActive(true);

            Bodies = FindObjectsOfType <Body>(); // Update bodies list

            string message = string.Format("Launch successful!\nC3 = {0:F3} (km/s)^2\nMass = {1:F1} kg", lambertSolution.C3, MassKI);

            DisplayTextWithFadeEffect(MessageText, message);
        }