Example #1
0
        public Review()
        {
            // Initialize coverage for Celestial Bodies (other than the Sun)

            CelestialBody[] Bodies = FlightGlobals.Bodies.ToArray();
            Coverages = new CoverageReport [Bodies.Length - 1];

            int k = 0;

            for (int i = 0; i < Bodies.Length; i++)
            {
                CelestialBody Body = Bodies [i];

                // Don't need to survey the sun
                if (Body.GetName() != "Sun")
                {
                    CoverageReport Report = new CoverageReport();
                    Report.entity = Body.GetName();

                    // Benchmark: Kerbin
                    // 10 sats till full coverage on Kerbin
                    Report.satCountForFullCoverage = (int)Math.Ceiling(Body.Radius / 60000);

                    Coverages [k] = Report;
                    k++;
                }
            }
        }
Example #2
0
            public static int BasePrestige(this CelestialBody body)
            {
                switch (body.GetName())
                {
                case "Kerbin":
                    return(1000);

                case "Mun":
                    return(1200);

                case "Minmus":
                    return(1400);

                case "Gilly":
                    return(2000);

                case "Ike":
                    return(2200);

                case "Duna":
                    return(2400);

                case "Eve":
                    return(3000);

                case "Moho":
                    return(4000);

                case "Dres":
                    return(5000);

                case "Jool":
                    return(6000);

                case "Vall":
                    return(6200);

                case "Tylo":
                    return(6400);

                case "Bop":
                    return(6600);

                case "Pol":
                    return(6800);

                case "Laythe":
                    return(7000);

                case "Eeloo":
                    return(8000);

                case "Sun":
                    return(9000);

                default:
                    Log.Warning("no base prestige for celestial body " + body.GetName());
                    return(99000);
                }
            }
Example #3
0
        public json getCelestialState(CelestialBody celestial)
        {
            Debug.Log ("Collecting: " + celestial.GetName ());
            json buffer = new json ();
            buffer.Add ("type", "celestial");

            buffer.Add ("name", celestial.GetName ());
            buffer.Add ("ref", celestial.referenceBody.GetName ());
            if (celestial.orbitDriver != null) {
                Orbit orbit = celestial.GetOrbit ();

                Vector3d r = orbit.getRelativePositionAtUT (0);
                Vector3d v = orbit.getOrbitalVelocityAtUT (0);

                List<double> RV = new List<double> ();

                // Swap coordinate system
                RV.Add (r.y);
                RV.Add (r.x);
                RV.Add (r.z);

                RV.Add (v.y);
                RV.Add (v.x);
                RV.Add (v.z);

                buffer.Add ("rv", RV);

            } else {
                List<double> RV = new List<double> ();
                RV.Add (0.0);
                RV.Add (0.0);
                RV.Add (0.0);
                RV.Add (0.0);
                RV.Add (0.0);
                RV.Add (0.0);
                buffer.Add ("rv", RV);
            }

            buffer.Add ("mu", celestial.gravParameter);
            buffer.Add ("radius", celestial.Radius);
            buffer.Add ("soi", celestial.sphereOfInfluence);

            if (celestial.atmosphere == true) {
                buffer.Add ("alt_atm", celestial.maxAtmosphereAltitude);
            } else {
                buffer.Add ("alt_atm", 0);
            }

            // Angular velocity data
            buffer.Add ("ang_v", celestial.zUpAngularVelocity.magnitude);

            buffer.Add ("initial_rotation", celestial.initialRotation);
            buffer.Add ("rotation_angle", celestial.rotationAngle);
            buffer.Add ("rotation_t0", Planetarium.GetUniversalTime ());

            return buffer;
        }
Example #4
0
 /// <summary>
 /// Call this to signal that you have found a celestial body.
 /// It will set the celestial body to discovered.
 /// </summary>
 /// <param name="scienceReward">The scienceReward additional amount that is added to the base scienceReward for finding a body</param>
 /// <param name="bodyFound">The Celestial Body found</param>
 /// <param name="withParent">Will return true if the Parent Body has also been found</param>
 /// <param name="parentBody">The parent body that was discovered as well if withParent is true</param>
 /// <returns></returns>
 public static bool FoundBody(int scienceReward, CelestialBody bodyFound, out bool withParent, out CelestialBody parentBody)
 {
     withParent = false;
     parentBody = null;
     if (HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)  //If not sandbox add the Science Points reward!
     {
         //var sciencePtsReward = scienceReward + Database.Instance.RB_SettingsParms.ScienceReward;
         var sciencePtsReward = scienceReward + Database.instance.RB_SettingsParms.ScienceReward;
         ResearchAndDevelopment.Instance.AddScience(sciencePtsReward, TransactionReasons.None);
         ScreenMessages.PostScreenMessage("Added " + sciencePtsReward + " science points !", 5f);
     }
     //Check if the referencebody is also not known. If so, we discover both the body and it's referencebody (parent).
     if (bodyFound.referenceBody != null && bodyFound != bodyFound.referenceBody && bodyFound.referenceBody.DiscoveryInfo.Level == DiscoveryLevels.Presence)
     {
         CelestialBody cbKey = Database.instance.ContainsBodiesKey(bodyFound.referenceBody.bodyName);
         if (cbKey != null)
         {
             Database.instance.CelestialBodies[cbKey].isResearched = true;
         }
         cbKey = Database.instance.ContainsBodiesKey(bodyFound.bodyName);
         if (cbKey != null)
         {
             Database.instance.CelestialBodies[cbKey].isResearched = true;
             var tempEntry = new KeyValuePair <CelestialBody, CelestialBodyInfo>(bodyFound, Database.instance.CelestialBodies[bodyFound]);
             setCBContractWeight(tempEntry, false);
         }
         withParent = true;
         parentBody = bodyFound.referenceBody;
         //check for Barycenter as well.
         if (bodyFound.referenceBody.referenceBody != null)
         {
             if ((bodyFound.referenceBody.referenceBody.DiscoveryInfo.Level == DiscoveryLevels.Appearance ||
                  bodyFound.referenceBody.referenceBody.DiscoveryInfo.Level == DiscoveryLevels.Presence) &&
                 Database.instance.CelestialBodies.ContainsKey(bodyFound.referenceBody.referenceBody))
             {
                 Database.instance.CelestialBodies[bodyFound.referenceBody.referenceBody].isResearched = true;
                 var tempEntry = new KeyValuePair <CelestialBody, CelestialBodyInfo>(bodyFound.referenceBody.referenceBody, Database.instance.CelestialBodies[bodyFound.referenceBody.referenceBody]);
                 setCBContractWeight(tempEntry, false);
             }
         }
         RSTLogWriter.Log("Found body {0} orbiting around {1} !", bodyFound.GetName(), bodyFound.referenceBody.GetName());
     }
     else //No parent or parent is already discovered. So we just found this body.
     {
         CelestialBody cbKey = Database.instance.ContainsBodiesKey(bodyFound.bodyName);
         if (cbKey != null)
         {
             Database.instance.CelestialBodies[cbKey].isResearched = true;
             var tempEntry = new KeyValuePair <CelestialBody, CelestialBodyInfo>(cbKey, Database.instance.CelestialBodies[cbKey]);
             setCBContractWeight(tempEntry, false);
         }
         withParent = false;
         RSTLogWriter.Log("Found body {0} !", bodyFound.GetName());
     }
     RSTLogWriter.Flush();
     return(true);
 }
Example #5
0
        public void doScience(CelestialBody target)
        {
            print("DOING SCIENCE, " + target.GetName());
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(experimentID);
            ScienceSubject    subject    = ResearchAndDevelopment.GetExperimentSubject(experiment, ExperimentSituations.InSpaceHigh, target, "");

            float sciTrans = Mathf.Max(subject.scientificValue - (1f - (opticsModule.isSmallOptics ? 0.10f : maxScience)), 0.0f);

            if (sciTrans == subject.scientificValue)
            {
                fullRecovery = true;
            }

            print("Current sciTrans: " + sciTrans);

            ScienceData data = new ScienceData(Mathf.Max(experiment.baseValue * subject.dataScale * sciTrans, 0.001f), 1.0f, 0.0f, subject.id, pName + " " + target.bodyName + " Observation");

            storedPath = opticsModule.GetTex(true, target.bodyName);
            storedData.Add(data);

            Events["eventReviewScience"].active = true;
            Events["eventDumpData"].active      = true;

            eventReviewScience();
        }
        public static void UpdateBody(Vessel vessel, CelestialBody body)
        {
            VesselDataClass vdc;

            if (VesselInformationDict.TryGetValue(vessel.id, out vdc))
            {
                vdc.ReferenceBody     = body;
                vdc.ReferenceBodyName = body.name;
            }
            else
            {
                Log.Info("Vessel not found: " + vessel.id);
            }

#if false
            ConfigNode Data        = VesselInformation;
            bool       Vesselfound = false;

            foreach (ConfigNode Vessel in Data.GetNodes("VESSEL"))
            {
                string id = Vessel.GetValue("id");
                if (id == vessel.id.ToString())
                {
                    Vesselfound = true;
                }

                if (Vesselfound)
                {
                    Vessel.SetValue("ReferenceBody", body.GetName());
                    break;
                }
            }
#endif
        }
Example #7
0
        private void UpdateCoverage()
        {
            for (int i = 0; i < Coverages.Length; i++)
            {
                Coverages [i].satCount = 0;
            }

            Vessel[] Satellites = VesselHelper.GetSatellites();

            for (int i = 0; i < Satellites.Length; i++)
            {
                Vessel Satellite = Satellites [i];

                CelestialBody  Body   = Satellite.GetOrbit().referenceBody;
                CoverageReport Report = GetReport(Body.GetName());
                Report.satCount++;
                Report.Update();
            }

            float totalCoverage = 0;

            for (int i = 0; i < Coverages.Length; i++)
            {
                totalCoverage += Coverages [i].coverage;
            }

            satelliteCoverage = (float)totalCoverage / (float)Coverages.Length;
        }
Example #8
0
        public override void Update()
        {
            Log.Info("Updating Coverage");

            for (int i = 0; i < variables.Coverages.Length; i++)
            {
                variables.Coverages[i].satCount = 0;
            }

            Vessel[] Satellites = VesselHelper.GetSatellites();

            for (int i = 0; i < Satellites.Length; i++)
            {
                Vessel Satellite = Satellites[i];

                CelestialBody  Body   = Satellite.GetOrbit().referenceBody;
                CoverageReport Report = GetReport(Body.GetName());
                Report.satCount++;
                Report.Update();
            }

            double totalCoverage = 0;

            for (int i = 0; i < variables.Coverages.Length; i++)
            {
                totalCoverage += variables.Coverages[i].coverage;
            }

            variables.satelliteCoverage = totalCoverage / variables.Coverages.Length;
            variables.modSCSatellite    = (int)(100 * variables.satelliteCoverage * StateFundingGlobal.fetch.GameInstance.Gov.scModifier);
        }
Example #9
0
        void playClipFor(Vessel vessel, CelestialBody body)
        {
            if (source.isPlaying)
            {
                Debug.Log("[SoundsOfSpace] " + "Audio playing already. Stopping.");
                source.Stop();
            }
            String    planetName  = body.GetName();
            AudioClip clipForBody = null;
            bool      foundClip   = planetMap.TryGetValue(planetName, out clipForBody);

            if (foundClip)
            {
                Debug.Log("[SoundsOfSpace] " + "Play clip for " + planetName + ": " + clipForBody);
                source.clip = clipForBody;
                sourceObject.SetActive(true);
                source.Play();
            }
            else
            {
                Debug.LogWarning("[SoundsOfSpace] " + "Did not find audio clip for body: " + planetName);
                if (source.isPlaying)
                {
                    source.Stop();
                }
            }
        }
        protected override void OnLoad(ConfigNode node)
        {
            Util.LoadNode(node, "FlightWaypointParameter", "targetBody", ref targetBody, Planetarium.fetch.Home);
            Util.LoadNode(node, "FlightWaypointParameter", "minAltitude", ref minAltitude, 0.0);
            Util.LoadNode(node, "FlightWaypointParameter", "maxAltitude", ref maxAltitude, 10000);
            Util.LoadNode(node, "FlightWaypointParameter", "waypointID", ref waypointID, 0);
            Util.LoadNode(node, "FlightWaypointParameter", "centerLatitude", ref centerLatitude, 0.0);
            Util.LoadNode(node, "FlightWaypointParameter", "centerLongitude", ref centerLongitude, 0.0);
            Util.LoadNode(node, "FlightWaypointParameter", "range", ref range, 10000);

            if (HighLogic.LoadedSceneIsFlight && this.Root.ContractState == Contract.State.Active && this.State == ParameterState.Incomplete)
            {
                wp.celestialName = targetBody.GetName();
                wp.seed          = Root.MissionSeed;
                wp.id            = waypointID;
                wp.RandomizeNear(centerLatitude, centerLongitude, targetBody.GetName(), range, true);
                wp.setName();
                wp.waypointType  = WaypointType.PLANE;
                wp.altitude      = calculateMidAltitude();
                wp.isOnSurface   = true;
                wp.isNavigatable = true;
                WaypointManager.AddWaypoint(wp);
                submittedWaypoint = true;
            }

            // Load all current missions in the tracking station.
            if (HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                if (this.Root.ContractState != Contract.State.Completed)
                {
                    wp.celestialName = targetBody.GetName();
                    wp.seed          = Root.MissionSeed;
                    wp.id            = waypointID;
                    wp.RandomizeNear(centerLatitude, centerLongitude, targetBody.GetName(), range, true);
                    wp.setName();
                    wp.waypointType  = WaypointType.PLANE;
                    wp.altitude      = calculateMidAltitude();
                    wp.isOnSurface   = true;
                    wp.isNavigatable = false;
                    WaypointManager.AddWaypoint(wp);
                    submittedWaypoint = true;
                }
            }
        }
Example #11
0
        protected override void OnLoad(ConfigNode node)
        {
            Util.LoadNode(node, "RoverWaypointParameter", "targetBody", ref targetBody, Planetarium.fetch.Home);
            Util.LoadNode(node, "RoverWaypointParameter", "isSecret", ref isSecret, false);
            Util.LoadNode(node, "RoverWaypointParameter", "waypointID", ref waypointID, 0);
            Util.LoadNode(node, "RoverWaypointParameter", "centerLatitude", ref centerLatitude, 0.0);
            Util.LoadNode(node, "RoverWaypointParameter", "centerLongitude", ref centerLongitude, 0.0);
            Util.LoadNode(node, "RoverWaypointParameter", "range", ref range, 10000);

            if (HighLogic.LoadedSceneIsFlight && this.Root.ContractState == Contract.State.Active && this.State == ParameterState.Incomplete)
            {
                wp.celestialName = targetBody.GetName();
                wp.seed          = Root.MissionSeed;
                wp.id            = waypointID;
                wp.RandomizeNear(centerLatitude, centerLongitude, targetBody.GetName(), range, false);
                wp.setName(false);
                wp.waypointType  = WaypointType.ROVER;
                wp.altitude      = 0.0;
                wp.isClustered   = true;
                wp.isOnSurface   = true;
                wp.isNavigatable = true;
                WaypointManager.AddWaypoint(wp);
                submittedWaypoint = true;
            }

            if (HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                if (this.Root.ContractState != Contract.State.Completed)
                {
                    wp.celestialName = targetBody.GetName();
                    wp.seed          = Root.MissionSeed;
                    wp.id            = waypointID;
                    wp.RandomizeNear(centerLatitude, centerLongitude, targetBody.GetName(), range, false);
                    wp.setName(false);
                    wp.waypointType  = WaypointType.ROVER;
                    wp.altitude      = 0.0;
                    wp.isClustered   = true;
                    wp.isOnSurface   = true;
                    wp.isNavigatable = false;
                    WaypointManager.AddWaypoint(wp);
                    submittedWaypoint = true;
                }
            }
        }
 // taken from RemoteTech's RTUtil
 public static Guid CelestialBodyGuid(CelestialBody cb)
 {
     char[] name = cb.GetName().ToCharArray();
     var s = new StringBuilder();
     for (int i = 0; i < 16; i++)
     {
         s.Append(((short)name[i % name.Length]).ToString("x"));
     }
     return new Guid(s.ToString());
 }
        public static String GetScopeForSituationAndBody(String situation, CelestialBody body)
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                return("none");
            }
            String bodyStr = body.GetName();

            return(TestFlightInterface.GetScopeForSituationAndBody(situation, bodyStr));
        }
Example #14
0
        public static Guid Guid(this CelestialBody cb)
        {
            char[] name = cb.GetName().ToCharArray();
            var    s    = new StringBuilder();

            for (int i = 0; i < 16; i++)
            {
                s.Append(((short)name[i % name.Length]).ToString("x"));
            }
            return(new Guid(s.ToString()));
        }
Example #15
0
        protected override void OnLoad(ConfigNode node)
        {
            Util.LoadNode(node, "FlightWaypointParameter", "targetBody", ref targetBody, Planetarium.fetch.Home);
            Util.LoadNode(node, "FlightWaypointParameter", "longitude", ref longitude, 0.0);

            if (HighLogic.LoadedSceneIsFlight && this.Root.ContractState == Contract.State.Active)
            {
                wp.celestialName = targetBody.GetName();
                wp.latitude      = 0.0;
                wp.longitude     = longitude;
                wp.seed          = Root.MissionSeed;
                wp.id            = 0;
                wp.setName();
                wp.waypointType  = WaypointType.DISH;
                wp.altitude      = 0;
                wp.isOnSurface   = true;
                wp.isNavigatable = true;
                WaypointManager.AddWaypoint(wp);
                submittedWaypoint = true;
            }

            // Load all current missions in the tracking station.
            if (HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                if (this.Root.ContractState != Contract.State.Completed)
                {
                    wp.celestialName = targetBody.GetName();
                    wp.latitude      = 0.0;
                    wp.longitude     = longitude;
                    wp.seed          = Root.MissionSeed;
                    wp.id            = 0;
                    wp.setName();
                    wp.waypointType  = WaypointType.DISH;
                    wp.altitude      = 0;
                    wp.isOnSurface   = true;
                    wp.isNavigatable = true;
                    WaypointManager.AddWaypoint(wp);
                    submittedWaypoint = true;
                }
            }
        }
Example #16
0
 private int orbitFactor(CelestialBody celestialBody)
 {
     if (celestialBody.isHomeWorld)
     {
         return(-1);
     }
     if (celestialBody.GetName() == "Sun")
     {
         return(0);
     }
     return(orbitFactor(celestialBody.GetOrbit().referenceBody) + 1);
 }
        public static bool ACelestialBody(string name)
        {
            CelestialBody[] Bodies = FlightGlobals.Bodies.ToArray();
            for (int i = 0; i < Bodies.Length; i++)
            {
                CelestialBody Body = Bodies[i];
                if (Body.GetName() == name)
                {
                    return(true);
                }
            }

            return(false);
        }
        public String serialized()
        {
            string header = "VERSION:" + Utilities.trackFileFormat + "\n"
                            + "[HEADER]\n"
                            + "VESSELNAME:" + VesselName + "\n"
                            + "DESCRIPTION:" + Description + "\n"
                            + "VISIBLE:" + (isVisible ? "1" : "0") + "\n"
                            + "MAINBODY:" + referenceBody.GetName() + "\n"
                            + "SAMPLING:" + SamplingFactor + "\n"
                            + "LINECOLOR:" + LineColor.r + ";" + LineColor.g + ";" + LineColor.b + ";" + LineColor.a + "\n"
                            + "LINEWIDTH:" + LineWidth + "\n"
                            + "CONERADIUSFACTOR:" + ConeRadiusToLineWidthFactor + "\n"
                            + "NUMDIRECTIONMARKERS:" + NumDirectionMarkers + "\n"
                            + "REPLAYCOLLIDERS:" + (ReplayColliders? "1":"0") + "\n"
                            + "END:" + EndAction.ToString("F") + (EndAction == EndActions.LOOP ? ":" + LoopClosureTime.ToString() : "") + "\n"; //"F" makes creates a string literal


            string points = "[WAYPOINTS]\n";

            foreach (Waypoint waypoint in waypoints)
            {
                points +=
                    waypoint.recordTime + ";"
                    + waypoint.latitude + ";"
                    + waypoint.longitude + ";"
                    + waypoint.altitude + ";"
                    + waypoint.orientation.x + ";" + waypoint.orientation.y + ";" + waypoint.orientation.z + ";" + waypoint.orientation.w + ";"
                    + waypoint.velocity.x + ";" + waypoint.velocity.y + ";" + waypoint.velocity.z + "\n";
            }

            string logs = "[LOGENTRIES]\n";

            foreach (LogEntry entry in logEntries)
            {
                logs += entry.recordTime + ";"
                        + entry.latitude + ";"
                        + entry.longitude + ";"
                        + entry.altitude + ";"
                        + entry.orientation.x + ";" + entry.orientation.y + ";" + entry.orientation.z + ";" + entry.orientation.w + ";"
                        + entry.velocity.x + ";" + entry.velocity.y + ";" + entry.velocity.z + ";"
                        + entry.label + ";"
                        + entry.description + "\n";
            }

            return(header + points + logs);
        }
Example #19
0
        protected static bool CelestialIsForbidden(CelestialBody body)
        {
            if (body == null)
            {
                return(true);
            }

            List <string> forbidList = FPConfig.ISRU.ForbiddenCelestials.Replace(" ", "").Split(',').ToList();

            foreach (string forbidden in forbidList)
            {
                if (body.GetName() == forbidden)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #20
0
        public static void UpdateBody(Vessel vessel, CelestialBody body)
        {
            ConfigNode Data        = VesselInformation;
            bool       Vesselfound = false;

            foreach (ConfigNode Vessel in Data.GetNodes("VESSEL"))
            {
                string id = Vessel.GetValue("id");
                if (id == vessel.id.ToString())
                {
                    Vesselfound = true;
                }

                if (Vesselfound == true)
                {
                    Vessel.SetValue("ReferenceBody", body.GetName());
                    break;
                }
            }
        }
Example #21
0
        public SatelliteCoverageFactor(FactorVariables factorVariables) : base(factorVariables)
        {
            variables.satelliteCoverage = 0;
            // Initialize coverage for Celestial Bodies (other than the Sun)

            CelestialBody[] Bodies = FlightGlobals.Bodies.ToArray();
            variables.Coverages = new CoverageReport[Bodies.Length - 1];
            CelestialBody home = Planetarium.fetch.Home;

            if (home == null)
            {
                home = FlightGlobals.Bodies.Find(body => body.isHomeWorld == true);
            }

            if (home != null)
            {
                StateFundingGlobal.refRadius = home.Radius / 10;
            }

            int k = 0;

            for (int i = 0; i < Bodies.Length; i++)
            {
                CelestialBody Body = Bodies[i];

                // Don't need to survey the sun
                //if (Body.GetName() != StateFundingGlobal.Sun)
                if (Body != Planetarium.fetch.Sun)
                {
                    CoverageReport Report = new CoverageReport();
                    Report.entity = Body.GetName();

                    // Benchmark: Kerbin
                    // 10 sats till full coverage on Kerbin
                    Report.satCountForFullCoverage = (int)Math.Ceiling(Body.Radius / StateFundingGlobal.refRadius);

                    variables.Coverages[k] = Report;
                    k++;
                }
            }
        }
Example #22
0
        private void UpdateMapView()
        {
            if (!show || MapView.MapCamera == null)
            {
                gameObject.renderer.enabled = false;
            }
            else
            {
                gameObject.renderer.enabled = true;
                _targetBody = MapView.MapCamera.target.GetTargetBody();

                if (_targetBody != null && (_targetBody != _body || _changed))
                {
                    this.Log("Drawing at " + _targetBody.name + " because " +
                             (_targetBody != _body ? "body changed." : "something else changed."));
                    OverlayProvider.BodyChanged(_targetBody);
                    _changed = false;
                    var dir    = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                    var radii  = System.IO.File.ReadAllLines(dir + "/Assets/Radii.cfg");
                    var radius = float.Parse(radii.First(x => x.StartsWith(_targetBody.GetName())).Split('=')[1]);
                    _body = _targetBody;
                    CreateMesh(_targetBody);
                    gameObject.renderer.material =
                        new Material(System.IO.File.ReadAllText(dir + "/Assets/MapOverlayShader.txt"));
                    gameObject.renderer.enabled     = true;
                    gameObject.renderer.castShadows = false;
                    gameObject.transform.parent     =
                        ScaledSpace.Instance.scaledSpaceTransforms.FirstOrDefault(t => t.name == _body.bodyName);
                    gameObject.layer = 10;
                    gameObject.transform.localScale    = Vector3.one * 1000f * radius;
                    gameObject.transform.localPosition = (Vector3.zero);
                    gameObject.transform.localRotation = (Quaternion.identity);
                }
                if (_targetBody != null && useScansat && _scanSat.Active())
                {
                    RecalculateColors(_targetBody);
                }
            }
        }
Example #23
0
        public void doScience(CelestialBody target)
        {
            print("DOING SCIENCE, " + target.GetName());
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(experimentID);
            ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(experiment, ExperimentSituations.InSpaceHigh, target, "");

            float sciTrans = Mathf.Max(subject.scientificValue - (1f - (opticsModule.isSmallOptics ? 0.10f : maxScience)), 0.0f);

            if (sciTrans == subject.scientificValue)
                fullRecovery = true;

            print("Current sciTrans: " + sciTrans);

            ScienceData data = new ScienceData(Mathf.Max(experiment.baseValue * subject.dataScale * sciTrans, 0.001f), 1.0f, 0.0f, subject.id, pName + " " + target.bodyName + " Observation");

            storedPath = opticsModule.GetTex(true, target.bodyName);
            storedData.Add(data);

            Events["eventReviewScience"].active = true;
            Events["eventDumpData"].active = true;

            eventReviewScience();
        }
        private void DrawWindow(int id)
        {
            GUIContent closeContent = new GUIContent(Textures.BtnRedCross, "Close Window");
            Rect       closeRect    = new Rect(windowRect.width - 21, 4, 16, 16);

            if (GUI.Button(closeRect, closeContent, Textures.ClosebtnStyle))
            {
                RBMenuAppLToolBar.onAppLaunchToggle();
                showSettings = false;
                return;
            }
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            GUILayout.BeginVertical();
            #region Wernher_Portrait Panel 1

            InstructorscrollViewVector = GUILayout.BeginScrollView(InstructorscrollViewVector, GUILayout.Width(148), GUILayout.Height(186));
            GUILayout.BeginVertical();
            if ((IsTSlevel1 && Database.allowTSlevel1) || !IsTSlevel1)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    GUILayout.Box(_portrait, GUILayout.Width(128), GUILayout.Height(128));
                }
                else
                {
                    GUILayout.Box(string.Empty, GUILayout.Width(128), GUILayout.Height(128));
                }
                GUILayout.Label("Wernher von Kerman", GUILayout.Width(128));
            }
            else
            {
                GUILayout.Label(Locales.currentLocale.Values["trackingStation_hasToBeLevel"], GUILayout.Width(128), GUILayout.Height(128));
            }
            #endregion
            GUILayout.EndVertical();
            GUILayout.EndScrollView();
            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            #region BodyList Panel 2
            scrollViewVector = GUILayout.BeginScrollView(scrollViewVector, GUILayout.Width(148), GUILayout.Height(313));
            GUILayout.BeginVertical();
            haveTrackedBodies = false;
            foreach (CelestialBody cb in BodyList)
            {
                if (TrackedBodies[cb] && !bool.Parse(BodySaveNode(cb.GetName()).GetValue("ignore")))
                {
                    if (GUILayout.Button(cb.GetName(), GUILayout.Width(110))) //new Rect(5, fromTop, 110, 32),
                    {
                        if (selectedBody == cb)
                        {
                            selectedBody = null;
                        }
                        else
                        {
                            selectedBody = cb;
                        }
                        PlayOKEmote();
                    }
                    haveTrackedBodies = true;
                }
            }
            GUILayout.EndVertical();
            GUILayout.EndScrollView();
            if (GUILayout.Button(Locales.currentLocale.Values["misc_settings"], GUILayout.Width(130), GUILayout.Height(32)))
            {
                showSettings = !showSettings;
            }
            #endregion
            GUILayout.EndVertical();
            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            #region Research Panel 3
            ResearchscrollViewVector = GUILayout.BeginScrollView(ResearchscrollViewVector, GUILayout.Width(522), GUILayout.Height(530));
            GUILayout.BeginVertical();
            if ((IsTSlevel1 && Database.allowTSlevel1) || !IsTSlevel1)
            {
                if (selectedBody == null)
                {
                    if (!haveTrackedBodies)
                    {
                        GUILayout.Label("<color=orange>" + Locales.currentLocale.Values["archives_empty"] + "</color>", GUILayout.Width(502));
                    }
                    else
                    {
                        GUILayout.Label("<color=orange>" + Locales.currentLocale.Values["archives_welcome"] + "</color>", GUILayout.Width(502)); //GUILayout
                    }
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("<b><size=35><color=orange>" + selectedBody.GetName() + "</color></size></b>", GUILayout.Width(150));
                    GUILayout.Label("<i>" + Database.DiscoveryMessage[selectedBody.GetName()] + "</i>", GUILayout.Width(300));
                    GUILayout.EndHorizontal();

                    if (selectedBody.referenceBody != Planetarium.fetch.Sun)
                    {
                        GUILayout.Label(string.Format(Locales.currentLocale.Values["research_orbiting"], selectedBody.referenceBody.GetName()), GUILayout.Width(150));
                    }
                    else
                    {
                        GUILayout.Label(Locales.currentLocale.Values["research_orbitingSun"], GUILayout.Width(150));
                    }


                    GUILayout.Label(string.Format(Locales.currentLocale.Values["research_researchState"], ResearchState[selectedBody]), GUILayout.Width(502));
                    if (ResearchState[selectedBody] == 0)
                    {
                        if (GUILayout.Button("<color=green>" + string.Format(Locales.currentLocale.Values["research_launchPlan"], selectedBody.GetName()) + " </color><size=10><i>(" + string.Format(Locales.currentLocale.Values["research_launchPlanCost"], (ResearchCost + ProgressResearchCost).ToString() /* 10 */) + ")</i></size>", GUILayout.Width(502)))
                        {
                            LaunchResearchPlan(selectedBody);
                            PlayNiceEmote();
                        }
                    }
                    else if (ResearchState[selectedBody] >= 10)
                    {
                        //GUILayout.BeginHorizontal();
                        if (GUILayout.Button("<color=red>" + string.Format(Locales.currentLocale.Values["research_stopPlan"], selectedBody.GetName()) + " </color><size=10><i>(" + string.Format(Locales.currentLocale.Values["research_stopPlanGives"], ResearchCost /* 5 */) + ")</i></size>", GUILayout.Width(502)))
                        {
                            StopResearchPlan(selectedBody);
                            PlayBadEmote();
                        }
                        if (ResearchState[selectedBody] < 40 && ResearchState[selectedBody] >= 10)
                        {
                            if (GUILayout.Button(Locales.currentLocale.Values["researchData_aspect"], GUILayout.Width(502)))
                            {
                                PlayNiceEmote();
                                Research(selectedBody, 10);
                                SetBodyDiscoveryLevels(); // Update Body Discovery Levels
                            }
                        }
                        else if (ResearchState[selectedBody] >= 40 && ResearchState[selectedBody] < 100)
                        {
                            GUILayout.Label("<i><color=green>" + Locales.currentLocale.Values["researchData_aspect"] + " ✓</color></i>", GUILayout.Width(502));
                            if (GUILayout.Button(Locales.currentLocale.Values["researchData_caracteristics"], GUILayout.Width(502)))
                            {
                                PlayNiceEmote();
                                Research(selectedBody, 10);
                                SetBodyDiscoveryLevels(); // Update Body Discovery Levels

                                //then...
                                if (ResearchState[selectedBody] == 100)
                                {
                                    ScreenMessages.PostScreenMessage(string.Format(Locales.currentLocale.Values["research_isNowFullyResearched_funds"], selectedBody.GetName(), ScienceReward));
                                    ResearchAndDevelopment.Instance.AddScience(ScienceReward, TransactionReasons.None);
                                }
                            }
                        }
                        else if (ResearchState[selectedBody] >= 100)
                        {
                            GUILayout.Label("<i><color=green>" + Locales.currentLocale.Values["researchData_aspect"] + " ✓</color></i>", GUILayout.Width(502));                                       //new Rect(188, 227, 502, 32),
                            GUILayout.Label("<i><color=green>" + Locales.currentLocale.Values["researchData_caracteristics"] + " ✓</color></i>", GUILayout.Width(502));                               //new Rect(188, 264, 502, 32),

                            GUILayout.Label("<b>" + string.Format(Locales.currentLocale.Values["research_isNowFullyResearched_sendVessels"], selectedBody.GetName()) + "</b>", GUILayout.Width(502)); //new Rect(188, 301, 502, 32),

                            // GUI.Label(new Rect(188, 301, 502, 32), "Send a exploration probe to " + selectedBody.GetName() + " : Incomplete", HighLogic.Skin.button);
                            // GUI.Label(new Rect(188, 338, 502, 32), "Run science experiments on " + selectedBody.GetName() + " : Incomplete", HighLogic.Skin.button);
                        }
                        //GUILayout.EndHorizontal();
                    }
                }
            }
            #endregion

            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            Utilities.SetTooltipText();
            GUI.DragWindow();

            /*
             * if (GUI.Button(new Rect(10, 175, 128, 35), "Play Happy"))
             *  PlayEmote(5);
             * if (GUI.Button(new Rect(10, 217, 128, 35), "Play Disappointed"))
             *  PlayEmote(10); */
        }
Example #25
0
        protected override bool Generate()
        {
            if (AreFacilitiesUnlocked() == false)
            {
                return(false);
            }

            //Facility fails generation on duplicates, so we can't have many out at once.
            int totalContracts = ContractSystem.Instance.GetCurrentContracts <FacilityContract>().Count();

            if (totalContracts >= 2)
            {
                return(false);
            }

            System.Random generator = new System.Random(this.MissionSeed);
            //I'll use this to determine how "difficult" the mission is, and adjust the pricing at the end.
            float difficultyFactor = 0.0f;
            float scienceFactor    = 1.0f;
            float repFactor        = 1.0f;

            onLand = (generator.Next(0, 2) == 1);

            if (onLand)
            {
                typeString = "land base";
            }
            else
            {
                typeString = "orbital station";
            }

            if (this.prestige == Contract.ContractPrestige.Trivial)
            {
                List <CelestialBody> bodies;

                if (onLand)
                {
                    bodies = GetBodies_Reached(false, false);
                }
                else
                {
                    bodies = GetBodies_Reached(true, true);
                }

                if (bodies.Count == 0)
                {
                    return(false);
                }

                targetBody = bodies[generator.Next(0, bodies.Count)];

                if (targetBody.GetName() == "Jool" && onLand)
                {
                    targetBody = Util.RandomJoolianMoon();

                    if (targetBody.GetName() == "Jool" || targetBody == null)
                    {
                        return(false);
                    }
                }

                if (onLand)
                {
                    this.AddParameter(new LocationAndSituationParameter(targetBody, Vessel.Situations.LANDED, "base"), null);
                }
                else
                {
                    this.AddParameter(new LocationAndSituationParameter(targetBody, Vessel.Situations.ORBITING, "station"), null);
                }

                this.AddParameter(new FacilitySystemsParameter(typeString), null);
                this.AddParameter(new CrewCapacityParameter(5), null);
                difficultyFactor = 5.0f / 4.0f;
                capacity         = 5;

                if (Util.haveTechnology("cupola"))
                {
                    if (generator.Next(0, 100) > 80)
                    {
                        this.AddParameter(new PartNameParameter("Have a viewing cupola at the facility", "cupola"), null);
                        difficultyFactor += 1.0f;
                        repFactor         = 2.0f;
                    }
                }

                if (Util.haveTechnology("Large.Crewed.Lab"))
                {
                    if (generator.Next(0, 100) > 80)
                    {
                        this.AddParameter(new FacilityLabParameter(), null);
                        difficultyFactor += 1.0f;
                        scienceFactor     = 2.0f;
                    }
                }
            }
            else if (this.prestige == Contract.ContractPrestige.Significant)
            {
                List <CelestialBody> bodies;

                if (onLand)
                {
                    bodies = GetBodies_Reached(false, false);
                }
                else
                {
                    bodies = GetBodies_Reached(false, true);
                }

                if (bodies.Count == 0)
                {
                    return(false);
                }

                targetBody = bodies[generator.Next(0, bodies.Count)];

                if (targetBody.GetName() == "Jool" && onLand)
                {
                    targetBody = Util.RandomJoolianMoon();

                    if (targetBody.GetName() == "Jool" || targetBody == null)
                    {
                        return(false);
                    }
                }

                if (onLand)
                {
                    this.AddParameter(new LocationAndSituationParameter(targetBody, Vessel.Situations.LANDED, "base"), null);
                }
                else
                {
                    this.AddParameter(new LocationAndSituationParameter(targetBody, Vessel.Situations.ORBITING, "station"), null);
                }

                this.AddParameter(new FacilitySystemsParameter(typeString), null);
                int contractCapacity = 5 + generator.Next(1, 8);
                this.AddParameter(new CrewCapacityParameter(contractCapacity), null);
                difficultyFactor = contractCapacity / 4.0f;
                capacity         = contractCapacity;

                if (Util.haveTechnology("cupola"))
                {
                    if (generator.Next(0, 100) > 60)
                    {
                        this.AddParameter(new PartNameParameter("Have a viewing cupola at the facility", "cupola"), null);
                        difficultyFactor += 1.0f;
                        repFactor         = 3.0f;
                    }
                }

                if (Util.haveTechnology("Large.Crewed.Lab"))
                {
                    if (generator.Next(0, 100) > 60)
                    {
                        this.AddParameter(new FacilityLabParameter(), null);
                        difficultyFactor += 1.0f;
                        scienceFactor     = 3.0f;
                    }
                }

                if (Util.haveTechnology("GrapplingDevice") && !onLand)
                {
                    if (generator.Next(0, 100) > 90)
                    {
                        string size;
                        if (generator.Next(0, 101) > 50)
                        {
                            size = "B";
                        }
                        else
                        {
                            size = "C";
                        }

                        this.AddParameter(new AsteroidParameter(size, true), null);
                        difficultyFactor += 2.0f;
                        repFactor        += 2.0f;
                    }
                }

                if (AreWheelsUnlocked() && onLand)
                {
                    if (generator.Next(0, 100) > 90)
                    {
                        this.AddParameter(new MobileBaseParameter(), null);
                        difficultyFactor += 2.0f;
                    }
                }
            }
            else if (this.prestige == Contract.ContractPrestige.Exceptional)
            {
                int contractCapacity = 5 + generator.Next(1, 8);

                //Prefer unreached targets for this level of difficulty.
                if (onLand)
                {
                    targetBody = GetNextUnreachedTarget(1, true, true);
                }
                else
                {
                    targetBody = GetNextUnreachedTarget(1, false, true);
                }

                // Player has reached all targets, use one we've reached, but bump up capacity to increase difficulty.
                if (targetBody == null)
                {
                    List <CelestialBody> bodies;

                    if (onLand)
                    {
                        bodies = GetBodies_Reached(false, false);
                    }
                    else
                    {
                        bodies = GetBodies_Reached(false, true);
                    }

                    if (bodies.Count == 0)
                    {
                        return(false);
                    }

                    contractCapacity = 7 + generator.Next(1, 14);
                    targetBody       = bodies[generator.Next(0, bodies.Count)];
                }

                if (targetBody.GetName() == "Jool" && onLand)
                {
                    targetBody = Util.RandomJoolianMoon();

                    if (targetBody.GetName() == "Jool" || targetBody == null)
                    {
                        return(false);
                    }
                }

                if (onLand)
                {
                    this.AddParameter(new LocationAndSituationParameter(targetBody, Vessel.Situations.LANDED, "base"), null);
                }
                else
                {
                    this.AddParameter(new LocationAndSituationParameter(targetBody, Vessel.Situations.ORBITING, "station"), null);
                }

                this.AddParameter(new FacilitySystemsParameter(typeString), null);
                this.AddParameter(new CrewCapacityParameter(contractCapacity), null);
                difficultyFactor = contractCapacity / 4.0f;
                capacity         = contractCapacity;

                if (Util.haveTechnology("cupola"))
                {
                    if (generator.Next(0, 100) > 60)
                    {
                        this.AddParameter(new PartNameParameter("Have a viewing cupola at the facility", "cupola"), null);
                        difficultyFactor += 1.0f;
                        repFactor         = 4.0f;
                    }
                }

                if (Util.haveTechnology("Large.Crewed.Lab"))
                {
                    if (generator.Next(0, 100) > 60)
                    {
                        this.AddParameter(new FacilityLabParameter(), null);
                        difficultyFactor += 1.0f;
                        scienceFactor     = 4.0f;
                    }
                }

                if (Util.haveTechnology("GrapplingDevice") && !onLand)
                {
                    if (generator.Next(0, 100) > 70)
                    {
                        string size;
                        if (generator.Next(0, 101) > 50)
                        {
                            size = "D";
                        }
                        else
                        {
                            size = "E";
                        }

                        this.AddParameter(new AsteroidParameter(size, true), null);
                        difficultyFactor += 2.0f;
                        repFactor        += 2.0f;
                    }
                }

                if (AreWheelsUnlocked() && onLand)
                {
                    if (generator.Next(0, 100) > 70)
                    {
                        this.AddParameter(new MobileBaseParameter(), null);
                        difficultyFactor += 2.0f;
                    }
                }
            }

            if (onLand)
            {
                base.AddKeywords(new string[] { "groundbase" });
            }
            else
            {
                base.AddKeywords(new string[] { "spacestation" });
            }

            base.SetExpiry();
            base.SetDeadlineYears(5.0f * difficultyFactor, targetBody);
            base.SetFunds(7500f + (7500f * difficultyFactor), 30000f + (30000f * difficultyFactor), this.targetBody);
            base.SetReputation(45f + (repFactor * 45f * difficultyFactor), 30f + (30f * difficultyFactor), this.targetBody);
            base.SetScience(5f + (scienceFactor * 5f * difficultyFactor), this.targetBody);

            //Prevent duplicate contracts shortly before finishing up.
            foreach (FacilityContract active in ContractSystem.Instance.GetCurrentContracts <FacilityContract>())
            {
                if (active.targetBody == this.targetBody && active.onLand == this.onLand)
                {
                    return(false);
                }
            }

            this.AddParameter(new KillControlsParameter(10), null);

            return(true);
        }
        private void ModifyPlanet(CelestialBody oldB, CelestialBody newB)
        {
            Debug.Log("Planitron: ModifyPlanet oldB.GetName() =  " + oldB.GetName());
            Debug.Log("Planitron: ModifyPlanet newB.GetName() =  " + newB.GetName());

            _currentPlanetName = newB.GetName();
            RoundedGeeASL = newB.GeeASL;
            RoundedGeeASL = Math.Round(RoundedGeeASL, 2);
            _currentGee = RoundedGeeASL.ToString();
            if (newB.atmosphere)
            {
                _currentatmosphereMultiplier = newB.atmosphereMultiplier.ToString();
            }
            else
            {
                _currentatmosphereMultiplier = "None";
            }
            _currentOxygen = newB.atmosphereContainsOxygen;
                oldB.atmoshpereTemperatureMultiplier = newB.atmoshpereTemperatureMultiplier;
                oldB.atmosphere = newB.atmosphere;
                oldB.atmosphereContainsOxygen = newB.atmosphereContainsOxygen;
                oldB.atmosphereMultiplier = newB.atmosphereMultiplier;
                oldB.atmosphereScaleHeight = newB.atmosphereScaleHeight;

                col_R = newB.atmosphericAmbientColor.r;
                col_G = newB.atmosphericAmbientColor.g;
                col_B = newB.atmosphericAmbientColor.b;
                col_A = newB.atmosphericAmbientColor.a;
                col_RGBA = new Color(col_R, col_G, col_B, col_A);
                oldB.atmosphericAmbientColor = col_RGBA;

                oldB.GeeASL = newB.GeeASL;
                oldB.gMagnitudeAtCenter = newB.gMagnitudeAtCenter;
                oldB.gravParameter = newB.gravParameter;
                oldB.Mass = newB.Mass;
                oldB.pressureMultiplier = newB.pressureMultiplier;
                oldB.staticPressureASL = newB.staticPressureASL;
            Debug.Log(" ");
            Debug.Log("Planitron: ModifyPlanet: New Values for vessel.mainBody ----------------------------");
            Debug.Log("Planitron: ModifyPlanet Post Name =  " + oldB.GetName());

            Debug.Log("Planitron: ModifyPlanet Post atmoshpereTemperatureMultiplier =  " + oldB.atmoshpereTemperatureMultiplier);
            Debug.Log("Planitron: ModifyPlanet Post atmosphere =  " + oldB.atmosphere);
            Debug.Log("Planitron: ModifyPlanet Post atmosphereContainsOxygen =  " + oldB.atmosphereContainsOxygen);
            Debug.Log("Planitron: ModifyPlanet Post atmosphereMultiplier =  " + oldB.atmosphereMultiplier);
            Debug.Log("Planitron: ModifyPlanet Post atmosphereScaleHeight =  " + oldB.atmosphereScaleHeight);
            Debug.Log("Planitron: ModifyPlanet Post col_RGBA.ToString =  " + col_RGBA.ToString());
            Debug.Log("Planitron: ModifyPlanet Post col_RGBA =  " + col_RGBA);
            Debug.Log("Planitron: ModifyPlanet Post atmosphericAmbientColor =  " + oldB.atmosphericAmbientColor.ToString());
            Debug.Log("Planitron: ModifyPlanet Post GeeASL =  " + oldB.GeeASL);
            Debug.Log("Planitron: ModifyPlanet Post gMagnitudeAtCenter =  " + oldB.gMagnitudeAtCenter);
            Debug.Log("Planitron: ModifyPlanet Post gravParameter =  " + oldB.gravParameter);
            Debug.Log("Planitron: ModifyPlanet Post Mass =  " + oldB.Mass);
            Debug.Log("Planitron: ModifyPlanet Post pressureMultiplier =  " + oldB.pressureMultiplier);
            Debug.Log("Planitron: ModifyPlanet Post staticPressureASL =  " + oldB.staticPressureASL);
            Debug.Log(" ");
            Debug.Log(" ");
        }
Example #27
0
 public static bool IsKerbin(this CelestialBody body)
 {
     return(body.GetName().Equals("Kerbin"));
 }
Example #28
0
        private IEnumerator<YieldInstruction> LoadCB(ConfigNode node, CelestialBody body)
        {
            bool updateMass = false;
            //OnGui();
            #region CBChanges
            print("Fixing CB " + node.name + " of radius " + body.Radius);
            guiMinor = "CelestialBody";
            //OnGui();
            double origRadius = body.Radius;
            double origAtmo = body.maxAtmosphereAltitude;

            #region CBMassRadius

            node.TryGetValue("bodyName", ref body.bodyName);
            node.TryGetValue("bodyDescription", ref body.bodyDescription);
            if (node.TryGetValue("Radius", ref body.Radius))
                updateMass = true;
            print("Radius ratio: " + body.Radius / origRadius);

            if (node.TryGetValue("Mass", ref body.Mass))
            {
                MassToOthers(body);

            }
            if (node.TryGetValue("GeeASL", ref body.GeeASL))
            {
                GeeASLToOthers(body);
                updateMass = false;
            }
            if (node.TryGetValue("gravParameter", ref body.gravParameter))
            {
                GravParamToOthers(body);
                updateMass = false;
            }
            #endregion

            #region CBAtmosphereTemperature
            node.TryGetValue("atmosphericAmbientColor", ref body.atmosphericAmbientColor);
            node.TryGetValue("atmosphere", ref body.atmosphere);
            node.TryGetValue("atmosphereScaleHeight", ref body.atmosphereScaleHeight);
            node.TryGetValue("atmosphereMultiplier", ref body.atmosphereMultiplier);
            node.TryGetValue("maxAtmosphereAltitude", ref body.maxAtmosphereAltitude);
            node.TryGetValue("staticPressureASL", ref body.staticPressureASL);
            node.TryGetValue("useLegacyAtmosphere", ref body.useLegacyAtmosphere);
            if (!body.useLegacyAtmosphere)
            {
                ConfigNode PCnode = node.GetNode("pressureCurve");
                if (PCnode != null)
                {
                    body.altitudeMultiplier = 1f;
                    body.pressureMultiplier = 1f;
                    AnimationCurve pressureCurve = Utils.LoadAnimationCurve(PCnode);
                    if (pressureCurve != null)
                        body.pressureCurve = pressureCurve;
                    else
                    {
                        body.useLegacyAtmosphere = true;
                        Debug.LogWarning("Unable to load pressureCurve data for " + body.name + ": Using legacy atmosphere");
                    }
                    print("*RSS* finished with " + body.GetName() + ".pressureCurve (" + body.pressureCurve.keys.Length.ToString() + " keys)");
                }
                else
                {
                    print("*RSS* useLegacyAtmosphere = False but pressureCurve not found!");
                }
            }
            if (node.HasNode("temperatureCurve"))
            {
                ConfigNode TCnode = node.GetNode("temperatureCurve");
                if (TCnode != null)
                {
                    AnimationCurve temperatureCurve = Utils.LoadAnimationCurve(TCnode);
                    if (temperatureCurve != null)
                    {
                        body.temperatureCurve = temperatureCurve;
                        // Following two lines corrects situations where planets without atmosphere's have these two fields zeroed out
                        // Maybe think about making these configurable in the planet's config node? yes? no? meh?
                        body.atmoshpereTemperatureMultiplier = 1f;
                        body.altitudeMultiplier = 1f;
                        print("*RSS* found and loaded temperatureCurve data for " + body.name);
                    }
                }
            }
            #endregion

            #region CBRotation
            node.TryGetValue("rotationPeriod", ref body.rotationPeriod);
            node.TryGetValue("tidallyLocked", ref body.tidallyLocked);
            node.TryGetValue("initialRotation", ref body.initialRotation);
            node.TryGetValue("inverseRotation", ref body.inverseRotation);
            #endregion

            if (updateMass)
                GeeASLToOthers(body);

            /*if (node.HasValue("axialTilt"))
            {
                if (!body.inverseRotation && double.TryParse(node.GetValue("axialTilt"), out dtmp))
                {
                    CBRotationFixer.CBRotations.Add(body.name, new CBRotation(body.name, dtmp, body.rotationPeriod, body.initialRotation));
                    body.rotationPeriod = 0;
                }
            }*/
            yield return null;

            #region CBOrbit
            ConfigNode onode = node.GetNode("Orbit");
            if (body.orbitDriver != null && body.orbit != null && onode != null)
            {
                if (loadInfo.useEpoch)
                    body.orbit.epoch = loadInfo.epoch;

                onode.TryGetValue("semiMajorAxis", ref body.orbit.semiMajorAxis);
                onode.TryGetValue("eccentricity", ref body.orbit.eccentricity);
                onode.TryGetValue("meanAnomalyAtEpoch", ref body.orbit.meanAnomalyAtEpoch);
                if (onode.TryGetValue("meanAnomalyAtEpochD", ref body.orbit.meanAnomalyAtEpoch))
                    body.orbit.meanAnomalyAtEpoch *= DEG2RAD;
                onode.TryGetValue("inclination", ref body.orbit.inclination);
                onode.TryGetValue("period", ref body.orbit.period);
                onode.TryGetValue("LAN", ref body.orbit.LAN);
                onode.TryGetValue("argumentOfPeriapsis", ref body.orbit.argumentOfPeriapsis);
                if (onode.HasValue("orbitColor"))
                {
                    try
                    {
                        Vector4 col = KSPUtil.ParseVector4(onode.GetValue("orbitColor"));
                        Color c = new Color(col.x, col.y, col.z, col.w);
                        body.GetOrbitDriver().orbitColor = c;
                    }
                    catch (Exception e)
                    {
                        print("*RSS* Error parsing as color4: original text: " + onode.GetValue("orbitColor") + " --- exception " + e.Message);
                    }
                }
                string bodyname = "";
                if (onode.TryGetValue("referenceBody", ref bodyname))
                {
                    if (body.orbit.referenceBody == null || !body.orbit.referenceBody.Equals(bodyname))
                    {
                        foreach (CelestialBody b in FlightGlobals.Bodies)
                        {
                            if (b.name.Equals(bodyname))
                            {
                                if (body.orbit.referenceBody)
                                {
                                    body.orbit.referenceBody.orbitingBodies.Remove(body);
                                }
                                b.orbitingBodies.Add(body);
                                body.orbit.referenceBody = b;
                                break;
                            }
                        }
                    }
                }
            }
            yield return null;
            // SOI and HillSphere done at end
            body.CBUpdate();
            #endregion
            #endregion

            #region SSPQSFade
            // Scaled space fader
            float SSFMult = 1.0f;
            float SSFStart = -1, SSFEnd = -1;
            node.TryGetValue("SSFStart", ref SSFStart);
            node.TryGetValue("SSFEnd", ref SSFEnd);
            node.TryGetValue("SSFMult", ref SSFMult);

            foreach (ScaledSpaceFader ssf in Resources.FindObjectsOfTypeAll(typeof(ScaledSpaceFader)))
            {
                if (ssf.celestialBody != null)
                {
                    if (ssf.celestialBody.name.Equals(node.name))
                    {
                        if (SSFStart >= 0)
                            ssf.fadeStart = SSFStart;
                        else
                            ssf.fadeStart *= SSFMult;

                        if (SSFEnd >= 0)
                            ssf.fadeEnd = SSFEnd;
                        else
                            ssf.fadeEnd *= SSFMult;
                    }
                }
            }
            // The CBT that fades out the PQS
            // Should probably do this as just another PQSMod, actually.
            foreach (PQSMod_CelestialBodyTransform c in Resources.FindObjectsOfTypeAll(typeof(PQSMod_CelestialBodyTransform)))
            {
                try
                {
                    if (c.body != null)
                    {
                        if (c.body.name.Equals(node.name))
                        {
                            print("Found CBT for " + node.name);
                            node.TryGetValue("PQSdeactivateAltitude", ref c.deactivateAltitude);
                            if (c.planetFade != null)
                            {
                                node.TryGetValue("PQSfadeStart", ref c.planetFade.fadeStart);
                                node.TryGetValue("PQSfadeEnd", ref c.planetFade.fadeEnd);
                                if (c.secondaryFades != null)
                                {
                                    foreach (PQSMod_CelestialBodyTransform.AltitudeFade af in c.secondaryFades)
                                    {
                                        node.TryGetValue("PQSSecfadeStart", ref af.fadeStart);
                                        node.TryGetValue("PQSSecfadeEnd", ref af.fadeEnd);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    print("CBT fix for " + node.name + " failed: " + e.Message);
                }
            }
            print("Did CBT for " + node.name);
            yield return null;
            #endregion

            #region Science
            // Science
            if (node.HasNode("CelestialBodyScienceParams"))
            {
                guiMinor = "Science";
                //OnGui();
                ConfigNode spNode = node.GetNode("CelestialBodyScienceParams");
                if (body.scienceValues != null)
                {
                    foreach (ConfigNode.Value val in spNode.values)
                    {
                        // meh, for now hard-code it. Saves worry of GIGO.
                        /*if(body.scienceValues.GetType().GetField(val.name) != null)
                            if(float.TryParse(val.value, out ftmp))
                                body.scienceValues.GetType().GetField(val.name).SetValue(*/
                        spNode.TryGetValue("LandedDataValue", ref body.scienceValues.LandedDataValue);
                        spNode.TryGetValue("SplashedDataValue", ref body.scienceValues.SplashedDataValue);
                        spNode.TryGetValue("FlyingLowDataValue", ref body.scienceValues.FlyingLowDataValue);
                        spNode.TryGetValue("FlyingHighDataValue", ref body.scienceValues.FlyingHighDataValue);
                        spNode.TryGetValue("InSpaceLowDataValue", ref body.scienceValues.InSpaceLowDataValue);
                        spNode.TryGetValue("InSpaceHighDataValue", ref body.scienceValues.InSpaceHighDataValue);
                        spNode.TryGetValue("RecoveryValue", ref body.scienceValues.RecoveryValue);
                        spNode.TryGetValue("flyingAltitudeThreshold", ref body.scienceValues.flyingAltitudeThreshold);
                        spNode.TryGetValue("spaceAltitudeThreshold", ref body.scienceValues.spaceAltitudeThreshold);
                    }
                }
                guiMinor = "";
                //OnGui();
            }
            yield return null;
            #endregion
        }
Example #29
0
        protected static bool CelestialIsForbidden(CelestialBody body)
        {
            if (body == null)
                return true;

            List<string> forbidList = FPConfig.ISRU.ForbiddenCelestials.Replace(" ", "").Split(',').ToList();

            foreach (string forbidden in forbidList)
            {
                if (body.GetName() == forbidden)
                    return true;
            }

            return false;
        }
Example #30
0
        protected override bool Generate()
        {
            if (AreWheelsUnlocked() == false)
                return false;

            //Allow four contracts in pocket but only two on the board at a time.
            int offeredContracts = 0;
            int activeContracts = 0;
            foreach (RoverContract contract in ContractSystem.Instance.GetCurrentContracts<RoverContract>())
            {
                if (contract.ContractState == Contract.State.Offered)
                    offeredContracts++;
                else if (contract.ContractState == Contract.State.Active)
                    activeContracts++;
            }

            if (offeredContracts >= 2 || activeContracts >= 4)
                return false;

            System.Random generator = new System.Random(this.MissionSeed);
            double range = 10000.0;
            List<CelestialBody> bodies = GetBodies_Reached(true, false);

            if (bodies.Count == 0)
                return false;

            targetBody = bodies[generator.Next(0, bodies.Count)];

            if (targetBody.GetName() == "Jool")
            {
                targetBody = Util.RandomJoolianMoon();

                if (targetBody.GetName() == "Jool" || targetBody == null)
                    return false;
            }

            int waypointCount = 0;

            if (this.prestige == Contract.ContractPrestige.Trivial)
            {
                waypointCount = 3;
                range = 1000 + 1000 * targetBody.GeeASL;
            }
            else if (this.prestige == Contract.ContractPrestige.Significant)
            {
                waypointCount = 5;
                range = 2000 + 2000 * targetBody.GeeASL;
            }
            else if (this.prestige == Contract.ContractPrestige.Exceptional)
            {
                waypointCount = 7;
                range = 3000 + 3000 * targetBody.GeeASL;
            }

            WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), false);
            int secret = UnityEngine.Random.Range(0, waypointCount);

            for (int x = 0; x < waypointCount; x++)
            {
                ContractParameter newParameter;

                if (x == secret)
                    newParameter = this.AddParameter(new RoverWaypointParameter(x, targetBody, centerLatitude, centerLongitude, range, true), null);
                else
                    newParameter = this.AddParameter(new RoverWaypointParameter(x, targetBody, centerLatitude, centerLongitude, range, false), null);

                newParameter.SetFunds(5000.0f, targetBody);
                newParameter.SetReputation(10.0f, targetBody);
                newParameter.SetScience(10.0f, targetBody);
            }

            base.AddKeywords(new string[] { "roversearch" });
            base.SetExpiry();
            base.SetDeadlineYears(5.0f, targetBody);
            base.SetFunds(4000.0f, 17500.0f, targetBody);
            base.SetReputation(50.0f, 25.0f, targetBody);
            return true;
        }
        private void AeroDataTab(GUIStyle buttonStyle, GUIStyle boxStyle)
        {
            int i = 0;

            GUILayout.BeginVertical(boxStyle);

            string tmp;

            tmp = FARAeroUtil.areaFactor.ToString();
            TextEntryField("Area Factor:", 160, ref tmp);
            tmp = Regex.Replace(tmp, @"[^\d*\.?\d*]", "");
            FARAeroUtil.areaFactor = Convert.ToDouble(tmp);

            tmp = (FARAeroUtil.attachNodeRadiusFactor * 2).ToString();
            TextEntryField("Node Diameter Factor:", 160, ref tmp);
            tmp = Regex.Replace(tmp, @"[^\d*\.?\d*]", "");
            FARAeroUtil.attachNodeRadiusFactor = Convert.ToDouble(tmp) * 0.5;

            tmp = FARAeroUtil.incompressibleRearAttachDrag.ToString();
            TextEntryField("Rear Node Drag, Incomp:", 160, ref tmp);
            tmp = Regex.Replace(tmp, @"[^\d*\.?\d*]", "");
            FARAeroUtil.incompressibleRearAttachDrag = Convert.ToDouble(tmp);

            tmp = FARAeroUtil.sonicRearAdditionalAttachDrag.ToString();
            TextEntryField("Rear Node Drag, M = 1:", 160, ref tmp);
            tmp = Regex.Replace(tmp, @"[^\d*\.?\d*]", "");
            FARAeroUtil.sonicRearAdditionalAttachDrag = Convert.ToDouble(tmp);

            tmp = FARControllableSurface.timeConstant.ToString();
            TextEntryField("Ctrl Surf Time Constant:", 160, ref tmp);
            tmp = Regex.Replace(tmp, @"[^\d*\.?\d*]", "");
            FARControllableSurface.timeConstant = Convert.ToDouble(tmp);

            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            GUILayout.Label("Celestial Body Atmosperic Properties");

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical(boxStyle);

            GUILayout.BeginHorizontal();
            int j = 0;

            for (i = 0; i < FlightGlobals.Bodies.Count; i++)
            {
                CelestialBody body = FlightGlobals.Bodies[i];

                if (!body.atmosphere)
                {
                    continue;
                }

                bool active = GUILayout.Toggle(i == atmBodyIndex, body.GetName(), buttonStyle, GUILayout.Width(150), GUILayout.Height(40));
                if (active)
                {
                    atmBodyIndex = i;
                }
                if ((j + 1) % 4 == 0)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }
                j++;
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUILayout.BeginVertical(boxStyle);

            int flightGlobalsIndex = FlightGlobals.Bodies[atmBodyIndex].flightGlobalsIndex;

            Vector3d atmProperties = FARAeroUtil.bodyAtmosphereConfiguration[flightGlobalsIndex];

            tmp = atmProperties.y.ToString();
            TextEntryField("Ratio of Specific Heats:", 80, ref tmp);
            tmp             = Regex.Replace(tmp, @"[^\d*\.?\d*]", "");
            atmProperties.y = Convert.ToDouble(tmp);


            double dTmp = 8314.5 / atmProperties.z;

            tmp = dTmp.ToString();
            TextEntryField("Gas Molecular Mass:", 80, ref tmp);
            tmp             = Regex.Replace(tmp, @"[^\d*\.?\d*]", "");
            atmProperties.z = 8314.5 / Convert.ToDouble(tmp);

            atmProperties.x = atmProperties.y * atmProperties.z;

            FARAeroUtil.bodyAtmosphereConfiguration[flightGlobalsIndex] = atmProperties;

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
Example #32
0
        protected override bool Generate()
        {
            if (AreWingsUnlocked() == false)
                return false;

            //Allow four contracts in pocket but only two on the board at a time.
            int offeredContracts = 0;
            int activeContracts = 0;
            foreach (AerialContract contract in ContractSystem.Instance.GetCurrentContracts<AerialContract>())
            {
                if (contract.ContractState == Contract.State.Offered)
                    offeredContracts++;
                else if (contract.ContractState == Contract.State.Active)
                    activeContracts++;
            }

            if (offeredContracts >= 2 || activeContracts >= 4)
                return false;

            double range = 10000.0;
            System.Random generator = new System.Random(this.MissionSeed);
            int additionalWaypoints = 0;
            List<CelestialBody> allBodies = GetBodies_Reached(true, false);
            List<CelestialBody> atmosphereBodies = new List<CelestialBody>();

            foreach (CelestialBody body in allBodies)
            {
                if (body.atmosphere)
                    atmosphereBodies.Add(body);
            }

            if (atmosphereBodies.Count == 0)
                return false;

            targetBody = atmosphereBodies[UnityEngine.Random.Range(0, atmosphereBodies.Count)];

            switch (targetBody.GetName())
            {
                case "Jool":
                    additionalWaypoints = 0;
                    minAltitude = 15000.0;
                    maxAltitude = 30000.0;
                    break;
                case "Duna":
                    additionalWaypoints = 1;
                    minAltitude = 8000.0;
                    maxAltitude = 16000.0;
                    break;
                case "Laythe":
                    additionalWaypoints = 1;
                    minAltitude = 15000.0;
                    maxAltitude = 30000.0;
                    break;
                case "Eve":
                    additionalWaypoints = 1;
                    minAltitude = 20000.0;
                    maxAltitude = 40000.0;
                    break;
                case "Kerbin":
                    additionalWaypoints = 2;
                    minAltitude = 12500.0;
                    maxAltitude = 25000.0;
                    break;
                default:
                    additionalWaypoints = 0;
                    minAltitude = 0.0;
                    maxAltitude = 10000.0;
                    break;
            }

            int waypointCount = 0;
            double altitudeHalfQuarterRange = Math.Abs(maxAltitude - minAltitude) * 0.125;
            double upperMidAltitude = ((maxAltitude + minAltitude) / 2.0) + altitudeHalfQuarterRange;
            double lowerMidAltitude = ((maxAltitude + minAltitude) / 2.0) - altitudeHalfQuarterRange;
            minAltitude = Math.Round((minAltitude + (generator.NextDouble() * (lowerMidAltitude - minAltitude))) / 100.0) * 100.0;
            maxAltitude = Math.Round((upperMidAltitude + (generator.NextDouble() * (maxAltitude - upperMidAltitude))) / 100.0) * 100.0;

            if (this.prestige == Contract.ContractPrestige.Trivial)
            {
                waypointCount = 1;
                waypointCount += additionalWaypoints;
                range = 100000.0;
            }
            else if (this.prestige == Contract.ContractPrestige.Significant)
            {
                waypointCount = 2;
                waypointCount += additionalWaypoints;
                range = 200000.0;
            }
            else if (this.prestige == Contract.ContractPrestige.Exceptional)
            {
                waypointCount = 3;
                waypointCount += additionalWaypoints;
                range = 300000.0;
            }

            WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), true);

            for (int x = 0; x < waypointCount; x++)
            {
                ContractParameter newParameter;
                newParameter = this.AddParameter(new FlightWaypointParameter(x, targetBody, minAltitude, maxAltitude, centerLatitude, centerLongitude, range), null);
                newParameter.SetFunds(3750.0f, targetBody);
                newParameter.SetReputation(7.5f, targetBody);
                newParameter.SetScience(7.5f, targetBody);
            }

            base.AddKeywords(new string[] { "surveyflight" });
            base.SetExpiry();
            base.SetDeadlineYears(5.0f, targetBody);
            base.SetFunds(4000.0f, 17500.0f, targetBody);
            base.SetReputation(50.0f, 25.0f, targetBody);
            return true;
        }
Example #33
0
        protected override bool Generate()
        {
            if (AreWingsUnlocked() == false)
            {
                return(false);
            }

            //Allow four contracts in pocket but only two on the board at a time.
            int offeredContracts = 0;
            int activeContracts  = 0;

            foreach (AerialContract contract in ContractSystem.Instance.GetCurrentContracts <AerialContract>())
            {
                if (contract.ContractState == Contract.State.Offered)
                {
                    offeredContracts++;
                }
                else if (contract.ContractState == Contract.State.Active)
                {
                    activeContracts++;
                }
            }

            if (offeredContracts >= 2 || activeContracts >= 4)
            {
                return(false);
            }

            double range = 10000.0;

            System.Random        generator           = new System.Random(this.MissionSeed);
            int                  additionalWaypoints = 0;
            List <CelestialBody> allBodies           = GetBodies_Reached(true, false);
            List <CelestialBody> atmosphereBodies    = new List <CelestialBody>();

            foreach (CelestialBody body in allBodies)
            {
                if (body.atmosphere)
                {
                    atmosphereBodies.Add(body);
                }
            }

            if (atmosphereBodies.Count == 0)
            {
                return(false);
            }

            targetBody = atmosphereBodies[UnityEngine.Random.Range(0, atmosphereBodies.Count)];

            switch (targetBody.GetName())
            {
            case "Jool":
                additionalWaypoints = 0;
                minAltitude         = 15000.0;
                maxAltitude         = 30000.0;
                break;

            case "Duna":
                additionalWaypoints = 1;
                minAltitude         = 8000.0;
                maxAltitude         = 16000.0;
                break;

            case "Laythe":
                additionalWaypoints = 1;
                minAltitude         = 15000.0;
                maxAltitude         = 30000.0;
                break;

            case "Eve":
                additionalWaypoints = 1;
                minAltitude         = 20000.0;
                maxAltitude         = 40000.0;
                break;

            case "Kerbin":
                additionalWaypoints = 2;
                minAltitude         = 12500.0;
                maxAltitude         = 25000.0;
                break;

            default:
                additionalWaypoints = 0;
                minAltitude         = 0.0;
                maxAltitude         = 10000.0;
                break;
            }

            int    waypointCount            = 0;
            double altitudeHalfQuarterRange = Math.Abs(maxAltitude - minAltitude) * 0.125;
            double upperMidAltitude         = ((maxAltitude + minAltitude) / 2.0) + altitudeHalfQuarterRange;
            double lowerMidAltitude         = ((maxAltitude + minAltitude) / 2.0) - altitudeHalfQuarterRange;

            minAltitude = Math.Round((minAltitude + (generator.NextDouble() * (lowerMidAltitude - minAltitude))) / 100.0) * 100.0;
            maxAltitude = Math.Round((upperMidAltitude + (generator.NextDouble() * (maxAltitude - upperMidAltitude))) / 100.0) * 100.0;

            if (this.prestige == Contract.ContractPrestige.Trivial)
            {
                waypointCount  = 1;
                waypointCount += additionalWaypoints;
                range          = 100000.0;
            }
            else if (this.prestige == Contract.ContractPrestige.Significant)
            {
                waypointCount  = 2;
                waypointCount += additionalWaypoints;
                range          = 200000.0;
            }
            else if (this.prestige == Contract.ContractPrestige.Exceptional)
            {
                waypointCount  = 3;
                waypointCount += additionalWaypoints;
                range          = 300000.0;
            }

            WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), true);

            for (int x = 0; x < waypointCount; x++)
            {
                ContractParameter newParameter;
                newParameter = this.AddParameter(new FlightWaypointParameter(x, targetBody, minAltitude, maxAltitude, centerLatitude, centerLongitude, range), null);
                newParameter.SetFunds(3750.0f, targetBody);
                newParameter.SetReputation(7.5f, targetBody);
                newParameter.SetScience(7.5f, targetBody);
            }

            base.AddKeywords(new string[] { "surveyflight" });
            base.SetExpiry();
            base.SetDeadlineYears(5.0f, targetBody);
            base.SetFunds(4000.0f, 17500.0f, targetBody);
            base.SetReputation(50.0f, 25.0f, targetBody);
            return(true);
        }
 public static void StopResearchPlan(CelestialBody cb)
 {
     if (Database.instance.CelestialBodies[cb].researchState >= 10)
     {
         if (Funding.Instance != null)
         {
             Funding.Instance.AddFunds(ResearchBodies.Instance.RBgameSettings.ResearchCost, TransactionReasons.None);
         }
         Database.instance.CelestialBodies[cb].researchState = 0;
         KeyValuePair <CelestialBody, CelestialBodyInfo> cbd =
             new KeyValuePair <CelestialBody, CelestialBodyInfo>(cb,
                                                                 Database.instance.CelestialBodies[cb]);
         ResearchBodiesController.instance.SetIndividualBodyDiscoveryLevel(cbd);
     }
     else
     {
         RSTLogWriter.Log(string.Format(Locales.currentLocale.Values["stopPlan_hasntBeenStarted"], cb.GetName()));
     }
 }
Example #35
0
        private void AeroDataTab(GUIStyle buttonStyle, GUIStyle boxStyle)
        {
            int i = 0;

            GUILayout.BeginVertical(boxStyle);

            FARControllableSurface.timeConstant        = GUIUtils.TextEntryForDouble("Ctrl Surf Time Constant:", 160, FARControllableSurface.timeConstant);
            FARControllableSurface.timeConstantFlap    = GUIUtils.TextEntryForDouble("Flap Time Constant:", 160, FARControllableSurface.timeConstantFlap);
            FARControllableSurface.timeConstantSpoiler = GUIUtils.TextEntryForDouble("Spoiler Time Constant:", 160, FARControllableSurface.timeConstantSpoiler);


            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            GUILayout.Label("Celestial Body Atmosperic Properties");

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical(boxStyle);

            GUILayout.BeginHorizontal();
            int j = 0;

            for (i = 0; i < FlightGlobals.Bodies.Count; i++)
            {
                CelestialBody body = FlightGlobals.Bodies[i];

                if (!body.atmosphere)
                {
                    continue;
                }

                bool active = GUILayout.Toggle(i == atmBodyIndex, body.GetName(), buttonStyle, GUILayout.Width(150), GUILayout.Height(40));
                if (active)
                {
                    atmBodyIndex = i;
                }
                if ((j + 1) % 4 == 0)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }
                j++;
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUILayout.BeginVertical(boxStyle);

            int flightGlobalsIndex = FlightGlobals.Bodies[atmBodyIndex].flightGlobalsIndex;

            double[] atmProperties = FARAeroUtil.bodyAtmosphereConfiguration[flightGlobalsIndex];

            atmProperties[0] = GUIUtils.TextEntryForDouble("Gas Viscosity:", 80, atmProperties[0]);
            atmProperties[1] = GUIUtils.TextEntryForDouble("Ref Temp for Viscosity:", 80, atmProperties[1]);

            FARAeroUtil.bodyAtmosphereConfiguration[flightGlobalsIndex] = atmProperties;

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
        private void AeroDataTab(GUIStyle buttonStyle, GUIStyle boxStyle)
        {
            int i = 0;

            GUILayout.BeginVertical(boxStyle);

            FARAeroUtil.areaFactor                     = FARGUIUtils.TextEntryForDouble("Area Factor:", 160, FARAeroUtil.areaFactor);
            FARAeroUtil.attachNodeRadiusFactor         = FARGUIUtils.TextEntryForDouble("Node Diameter Factor:", 160, FARAeroUtil.attachNodeRadiusFactor * 2) * 0.5;
            FARAeroUtil.incompressibleRearAttachDrag   = FARGUIUtils.TextEntryForDouble("Rear Node Drag, Incomp:", 160, FARAeroUtil.incompressibleRearAttachDrag);
            FARAeroUtil.sonicRearAdditionalAttachDrag  = FARGUIUtils.TextEntryForDouble("Rear Node Drag, M = 1:", 160, FARAeroUtil.sonicRearAdditionalAttachDrag);
            FARControllableSurface.timeConstant        = FARGUIUtils.TextEntryForDouble("Ctrl Surf Time Constant:", 160, FARControllableSurface.timeConstant);
            FARControllableSurface.timeConstantFlap    = FARGUIUtils.TextEntryForDouble("Flap Time Constant:", 160, FARControllableSurface.timeConstantFlap);
            FARControllableSurface.timeConstantSpoiler = FARGUIUtils.TextEntryForDouble("Spoiler Time Constant:", 160, FARControllableSurface.timeConstantSpoiler);


            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            GUILayout.Label("Celestial Body Atmosperic Properties");

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical(boxStyle);

            GUILayout.BeginHorizontal();
            int j = 0;

            for (i = 0; i < FlightGlobals.Bodies.Count; i++)
            {
                CelestialBody body = FlightGlobals.Bodies[i];

                if (!body.atmosphere)
                {
                    continue;
                }

                bool active = GUILayout.Toggle(i == atmBodyIndex, body.GetName(), buttonStyle, GUILayout.Width(150), GUILayout.Height(40));
                if (active)
                {
                    atmBodyIndex = i;
                }
                if ((j + 1) % 4 == 0)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }
                j++;
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUILayout.BeginVertical(boxStyle);

            int flightGlobalsIndex = FlightGlobals.Bodies[atmBodyIndex].flightGlobalsIndex;

            double[] atmProperties = FARAeroUtil.bodyAtmosphereConfiguration[flightGlobalsIndex];

            atmProperties[1] = FARGUIUtils.TextEntryForDouble("Ratio of Specific Heats:", 80, atmProperties[1]);


            double dTmp = 8314.5 / atmProperties[2];

            dTmp             = FARGUIUtils.TextEntryForDouble("Gas Molecular Mass:", 80, dTmp);
            atmProperties[2] = 8314.5 / dTmp;

            atmProperties[0] = atmProperties[1] * atmProperties[2];

            atmProperties[3] = FARGUIUtils.TextEntryForDouble("Gas Viscosity:", 80, atmProperties[3]);
            atmProperties[4] = FARGUIUtils.TextEntryForDouble("Ref Temp for Viscosity:", 80, atmProperties[4]);

            FARAeroUtil.bodyAtmosphereConfiguration[flightGlobalsIndex] = atmProperties;

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
Example #37
0
        protected override bool Generate()
        {
            if (AreWingsUnlocked() == false)
            {
                return(false);
            }

            int offeredContracts = 0;
            int activeContracts  = 0;

            foreach (AerialContract contract in ContractSystem.Instance.GetCurrentContracts <AerialContract>())
            {
                if (contract.ContractState == Contract.State.Offered)
                {
                    offeredContracts++;
                }
                else if (contract.ContractState == Contract.State.Active)
                {
                    activeContracts++;
                }
            }

            if (offeredContracts >= FPConfig.Aerial.MaximumAvailable || activeContracts >= FPConfig.Aerial.MaximumActive)
            {
                return(false);
            }

            double range = 10000.0;

            System.Random        generator           = new System.Random(this.MissionSeed);
            int                  additionalWaypoints = 0;
            List <CelestialBody> allBodies           = GetBodies_Reached(true, false);
            List <CelestialBody> atmosphereBodies    = new List <CelestialBody>();

            foreach (CelestialBody body in allBodies)
            {
                if (body.atmosphere)
                {
                    atmosphereBodies.Add(body);
                }
            }

            if (atmosphereBodies.Count == 0)
            {
                return(false);
            }

            targetBody = atmosphereBodies[generator.Next(0, atmosphereBodies.Count)];

            //TODO: Find some common ground to calculate these values automatically without specific names.
            switch (targetBody.GetName())
            {
            case "Jool":
                additionalWaypoints = 0;
                minAltitude         = 15000.0;
                maxAltitude         = 30000.0;
                break;

            case "Duna":
                additionalWaypoints = 1;
                minAltitude         = 8000.0;
                maxAltitude         = 16000.0;
                break;

            case "Laythe":
                additionalWaypoints = 1;
                minAltitude         = 15000.0;
                maxAltitude         = 30000.0;
                break;

            case "Eve":
                additionalWaypoints = 1;
                minAltitude         = 20000.0;
                maxAltitude         = 40000.0;
                break;

            case "Kerbin":
                additionalWaypoints = 2;
                minAltitude         = 12500.0;
                maxAltitude         = 25000.0;
                break;

            default:
                additionalWaypoints = 0;
                minAltitude         = 0.0;
                maxAltitude         = 10000.0;
                break;
            }

            int   waypointCount          = 0;
            float fundsMultiplier        = 1;
            float scienceMultiplier      = 1;
            float reputationMultiplier   = 1;
            float wpFundsMultiplier      = 1;
            float wpScienceMultiplier    = 1;
            float wpReputationMultiplier = 1;

            double altitudeHalfQuarterRange = Math.Abs(maxAltitude - minAltitude) * 0.125;
            double upperMidAltitude         = ((maxAltitude + minAltitude) / 2.0) + altitudeHalfQuarterRange;
            double lowerMidAltitude         = ((maxAltitude + minAltitude) / 2.0) - altitudeHalfQuarterRange;

            minAltitude = Math.Round((minAltitude + (generator.NextDouble() * (lowerMidAltitude - minAltitude))) / 100.0) * 100.0;
            maxAltitude = Math.Round((upperMidAltitude + (generator.NextDouble() * (maxAltitude - upperMidAltitude))) / 100.0) * 100.0;

            switch (this.prestige)
            {
            case ContractPrestige.Trivial:
                waypointCount  = FPConfig.Aerial.TrivialWaypoints;
                waypointCount += additionalWaypoints;
                range          = FPConfig.Aerial.TrivialRange;

                if (Util.IsGasGiant(targetBody))
                {
                    if (generator.Next(0, 100) < FPConfig.Aerial.ExceptionalLowAltitudeChance / 2)
                    {
                        minAltitude  *= FPConfig.Aerial.ExceptionalLowAltitudeMultiplier;
                        maxAltitude  *= FPConfig.Aerial.ExceptionalLowAltitudeMultiplier;
                        isLowAltitude = true;
                    }
                }
                else
                {
                    if (generator.Next(0, 100) < FPConfig.Aerial.TrivialLowAltitudeChance)
                    {
                        minAltitude  *= FPConfig.Aerial.TrivialLowAltitudeMultiplier;
                        maxAltitude  *= FPConfig.Aerial.TrivialLowAltitudeMultiplier;
                        isLowAltitude = true;
                    }
                }

                if (generator.Next(0, 100) < FPConfig.Aerial.TrivialHomeNearbyChance && targetBody == Planetarium.fetch.Home)
                {
                    WaypointManager.ChooseRandomPositionNear(out centerLatitude, out centerLongitude, SpaceCenter.Instance.Latitude, SpaceCenter.Instance.Longitude, targetBody.GetName(), FPConfig.Aerial.TrivialHomeNearbyRange, true);
                }
                else
                {
                    WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), true, false);
                }

                break;

            case ContractPrestige.Significant:
                waypointCount          = FPConfig.Aerial.SignificantWaypoints;
                waypointCount         += additionalWaypoints;
                range                  = FPConfig.Aerial.SignificantRange;
                fundsMultiplier        = FPConfig.Aerial.Funds.SignificantMultiplier;
                scienceMultiplier      = FPConfig.Aerial.Science.SignificantMultiplier;
                reputationMultiplier   = FPConfig.Aerial.Reputation.SignificantMultiplier;
                wpFundsMultiplier      = FPConfig.Aerial.Funds.WaypointSignificantMultiplier;
                wpScienceMultiplier    = FPConfig.Aerial.Science.WaypointSignificantMultiplier;
                wpReputationMultiplier = FPConfig.Aerial.Reputation.WaypointSignificantMultiplier;

                if (Util.IsGasGiant(targetBody))
                {
                    if (generator.Next(0, 100) < FPConfig.Aerial.SignificantLowAltitudeChance / 2)
                    {
                        minAltitude  *= FPConfig.Aerial.SignificantLowAltitudeMultiplier;
                        maxAltitude  *= FPConfig.Aerial.SignificantLowAltitudeMultiplier;
                        isLowAltitude = true;
                    }
                }
                else
                {
                    if (generator.Next(0, 100) < FPConfig.Aerial.SignificantLowAltitudeChance)
                    {
                        minAltitude  *= FPConfig.Aerial.SignificantLowAltitudeMultiplier;
                        maxAltitude  *= FPConfig.Aerial.SignificantLowAltitudeMultiplier;
                        isLowAltitude = true;
                    }
                }

                if (generator.Next(0, 100) < FPConfig.Aerial.SignificantHomeNearbyChance && targetBody == Planetarium.fetch.Home)
                {
                    WaypointManager.ChooseRandomPositionNear(out centerLatitude, out centerLongitude, SpaceCenter.Instance.Latitude, SpaceCenter.Instance.Longitude, targetBody.GetName(), FPConfig.Aerial.SignificantHomeNearbyRange, true);
                }
                else
                {
                    WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), true, false);
                }

                break;

            case ContractPrestige.Exceptional:
                waypointCount          = FPConfig.Aerial.ExceptionalWaypoints;
                waypointCount         += additionalWaypoints;
                range                  = FPConfig.Aerial.ExceptionalRange;
                fundsMultiplier        = FPConfig.Aerial.Funds.ExceptionalMultiplier;
                scienceMultiplier      = FPConfig.Aerial.Science.ExceptionalMultiplier;
                reputationMultiplier   = FPConfig.Aerial.Reputation.ExceptionalMultiplier;
                wpFundsMultiplier      = FPConfig.Aerial.Funds.WaypointExceptionalMultiplier;
                wpScienceMultiplier    = FPConfig.Aerial.Science.WaypointExceptionalMultiplier;
                wpReputationMultiplier = FPConfig.Aerial.Reputation.WaypointExceptionalMultiplier;

                if (Util.IsGasGiant(targetBody))
                {
                    if (generator.Next(0, 100) < FPConfig.Aerial.TrivialLowAltitudeChance / 2)
                    {
                        minAltitude  *= FPConfig.Aerial.TrivialLowAltitudeMultiplier;
                        maxAltitude  *= FPConfig.Aerial.TrivialLowAltitudeMultiplier;
                        isLowAltitude = true;
                    }
                }
                else
                {
                    if (generator.Next(0, 100) < FPConfig.Aerial.ExceptionalLowAltitudeChance)
                    {
                        minAltitude  *= FPConfig.Aerial.ExceptionalLowAltitudeMultiplier;
                        maxAltitude  *= FPConfig.Aerial.ExceptionalLowAltitudeMultiplier;
                        isLowAltitude = true;
                    }
                }

                if (generator.Next(0, 100) < FPConfig.Aerial.ExceptionalHomeNearbyChance && targetBody == Planetarium.fetch.Home)
                {
                    WaypointManager.ChooseRandomPositionNear(out centerLatitude, out centerLongitude, SpaceCenter.Instance.Latitude, SpaceCenter.Instance.Longitude, targetBody.GetName(), FPConfig.Aerial.ExceptionalHomeNearbyRange, true);
                }
                else
                {
                    WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), true, false);
                }

                break;
            }

            for (int x = 0; x < waypointCount; x++)
            {
                ContractParameter newParameter;
                newParameter = this.AddParameter(new FlightWaypointParameter(x, targetBody, minAltitude, maxAltitude, centerLatitude, centerLongitude, range), null);
                newParameter.SetFunds(Mathf.Round(FPConfig.Aerial.Funds.WaypointBaseReward * wpFundsMultiplier), targetBody);
                newParameter.SetReputation(Mathf.Round(FPConfig.Aerial.Reputation.WaypointBaseReward * wpReputationMultiplier), targetBody);
                newParameter.SetScience(Mathf.Round(FPConfig.Aerial.Science.WaypointBaseReward * wpScienceMultiplier), targetBody);
            }

            base.AddKeywords(new string[] { "surveyflight" });
            base.SetExpiry(FPConfig.Aerial.Expire.MinimumExpireDays, FPConfig.Aerial.Expire.MaximumExpireDays);
            base.SetDeadlineDays(FPConfig.Aerial.Expire.DeadlineDays, targetBody);
            base.SetFunds(Mathf.Round(FPConfig.Aerial.Funds.BaseAdvance * fundsMultiplier), Mathf.Round(FPConfig.Aerial.Funds.BaseReward * fundsMultiplier), Mathf.Round(FPConfig.Aerial.Funds.BaseFailure * fundsMultiplier), targetBody);
            base.SetScience(Mathf.Round(FPConfig.Aerial.Science.BaseReward * scienceMultiplier), targetBody);
            base.SetReputation(Mathf.Round(FPConfig.Aerial.Reputation.BaseReward * reputationMultiplier), Mathf.Round(FPConfig.Aerial.Reputation.BaseFailure * reputationMultiplier), targetBody);
            return(true);
        }
Example #38
0
        protected override bool Generate()
        {
            if (AreFacilitiesUnlocked() == false)
                return false;

            //Facility fails generation on duplicates, so we can't have many out at once.
            int totalContracts = ContractSystem.Instance.GetCurrentContracts<FacilityContract>().Count();
            if (totalContracts >= 2)
                return false;

            System.Random generator = new System.Random(this.MissionSeed);
            //I'll use this to determine how "difficult" the mission is, and adjust the pricing at the end.
            float difficultyFactor = 0.0f;
            float scienceFactor = 1.0f;
            float repFactor = 1.0f;
            onLand = (generator.Next(0, 2) == 1);

            if (onLand)
                typeString = "land base";
            else
                typeString = "orbital station";

            if (this.prestige == Contract.ContractPrestige.Trivial)
            {
                List<CelestialBody> bodies;

                if (onLand)
                    bodies = GetBodies_Reached(false, false);
                else
                    bodies = GetBodies_Reached(true, true);

                if (bodies.Count == 0)
                    return false;

                targetBody = bodies[generator.Next(0, bodies.Count)];

                if (targetBody.GetName() == "Jool" && onLand)
                {
                    targetBody = Util.RandomJoolianMoon();

                    if (targetBody.GetName() == "Jool" || targetBody == null)
                        return false;
                }

                if (onLand)
                    this.AddParameter(new LocationAndSituationParameter(targetBody, Vessel.Situations.LANDED, "base"), null);
                else
                    this.AddParameter(new LocationAndSituationParameter(targetBody, Vessel.Situations.ORBITING, "station"), null);

                this.AddParameter(new FacilitySystemsParameter(typeString), null);
                this.AddParameter(new CrewCapacityParameter(5), null);
                difficultyFactor = 5.0f / 4.0f;
                capacity = 5;

                if (Util.haveTechnology("cupola"))
                {
                    if (generator.Next(0, 100) > 80)
                    {
                        this.AddParameter(new PartNameParameter("Have a viewing cupola at the facility", "cupola"), null);
                        difficultyFactor += 1.0f;
                        repFactor = 2.0f;
                    }
                }

                if (Util.haveTechnology("Large.Crewed.Lab"))
                {
                    if (generator.Next(0, 100) > 80)
                    {
                        this.AddParameter(new FacilityLabParameter(), null);
                        difficultyFactor += 1.0f;
                        scienceFactor = 2.0f;
                    }
                }
            }
            else if (this.prestige == Contract.ContractPrestige.Significant)
            {
                List<CelestialBody> bodies;

                if (onLand)
                    bodies = GetBodies_Reached(false, false);
                else
                    bodies = GetBodies_Reached(false, true);

                if (bodies.Count == 0)
                    return false;

                targetBody = bodies[generator.Next(0, bodies.Count)];

                if (targetBody.GetName() == "Jool" && onLand)
                {
                    targetBody = Util.RandomJoolianMoon();

                    if (targetBody.GetName() == "Jool" || targetBody == null)
                        return false;
                }

                if (onLand)
                    this.AddParameter(new LocationAndSituationParameter(targetBody, Vessel.Situations.LANDED, "base"), null);
                else
                    this.AddParameter(new LocationAndSituationParameter(targetBody, Vessel.Situations.ORBITING, "station"), null);

                this.AddParameter(new FacilitySystemsParameter(typeString), null);
                int contractCapacity = 5 + generator.Next(1, 8);
                this.AddParameter(new CrewCapacityParameter(contractCapacity), null);
                difficultyFactor = contractCapacity / 4.0f;
                capacity = contractCapacity;

                if (Util.haveTechnology("cupola"))
                {
                    if (generator.Next(0, 100) > 60)
                    {
                        this.AddParameter(new PartNameParameter("Have a viewing cupola at the facility", "cupola"), null);
                        difficultyFactor += 1.0f;
                        repFactor = 3.0f;
                    }
                }

                if (Util.haveTechnology("Large.Crewed.Lab"))
                {
                    if (generator.Next(0, 100) > 60)
                    {
                        this.AddParameter(new FacilityLabParameter(), null);
                        difficultyFactor += 1.0f;
                        scienceFactor = 3.0f;
                    }
                }

                if (Util.haveTechnology("GrapplingDevice") && !onLand)
                {
                    if (generator.Next(0, 100) > 90)
                    {
                        string size;
                        if (generator.Next(0, 101) > 50)
                            size = "B";
                        else
                            size = "C";

                        this.AddParameter(new AsteroidParameter(size, true), null);
                        difficultyFactor += 2.0f;
                        repFactor += 2.0f;
                    }
                }

                if (AreWheelsUnlocked() && onLand)
                {
                    if (generator.Next(0, 100) > 90)
                    {
                        this.AddParameter(new MobileBaseParameter(), null);
                        difficultyFactor += 2.0f;
                    }
                }
            }
            else if (this.prestige == Contract.ContractPrestige.Exceptional)
            {
                int contractCapacity = 5 + generator.Next(1, 8);

                //Prefer unreached targets for this level of difficulty.
                if (onLand)
                    targetBody = GetNextUnreachedTarget(1, true, true);
                else
                    targetBody = GetNextUnreachedTarget(1, false, true);

                // Player has reached all targets, use one we've reached, but bump up capacity to increase difficulty.
                if (targetBody == null)
                {
                    List<CelestialBody> bodies;

                    if (onLand)
                        bodies = GetBodies_Reached(false, false);
                    else
                        bodies = GetBodies_Reached(false, true);

                    if (bodies.Count == 0)
                        return false;

                    contractCapacity = 7 + generator.Next(1, 14);
                    targetBody = bodies[generator.Next(0, bodies.Count)];
                }

                if (targetBody.GetName() == "Jool" && onLand)
                {
                    targetBody = Util.RandomJoolianMoon();

                    if (targetBody.GetName() == "Jool" || targetBody == null)
                        return false;
                }

                if (onLand)
                    this.AddParameter(new LocationAndSituationParameter(targetBody, Vessel.Situations.LANDED, "base"), null);
                else
                    this.AddParameter(new LocationAndSituationParameter(targetBody, Vessel.Situations.ORBITING, "station"), null);

                this.AddParameter(new FacilitySystemsParameter(typeString), null);
                this.AddParameter(new CrewCapacityParameter(contractCapacity), null);
                difficultyFactor = contractCapacity / 4.0f;
                capacity = contractCapacity;

                if (Util.haveTechnology("cupola"))
                {
                    if (generator.Next(0, 100) > 60)
                    {
                        this.AddParameter(new PartNameParameter("Have a viewing cupola at the facility", "cupola"), null);
                        difficultyFactor += 1.0f;
                        repFactor = 4.0f;
                    }
                }

                if (Util.haveTechnology("Large.Crewed.Lab"))
                {
                    if (generator.Next(0, 100) > 60)
                    {
                        this.AddParameter(new FacilityLabParameter(), null);
                        difficultyFactor += 1.0f;
                        scienceFactor = 4.0f;
                    }
                }

                if (Util.haveTechnology("GrapplingDevice") && !onLand)
                {
                    if (generator.Next(0, 100) > 70)
                    {
                        string size;
                        if (generator.Next(0, 101) > 50)
                            size = "D";
                        else
                            size = "E";

                        this.AddParameter(new AsteroidParameter(size, true), null);
                        difficultyFactor += 2.0f;
                        repFactor += 2.0f;
                    }
                }

                if (AreWheelsUnlocked() && onLand)
                {
                    if (generator.Next(0, 100) > 70)
                    {
                        this.AddParameter(new MobileBaseParameter(), null);
                        difficultyFactor += 2.0f;
                    }
                }
            }

            if (onLand)
                base.AddKeywords(new string[] { "groundbase" });
            else
                base.AddKeywords(new string[] { "spacestation" });

            base.SetExpiry();
            base.SetDeadlineYears(5.0f * difficultyFactor, targetBody);
            base.SetFunds(7500f + (7500f * difficultyFactor), 30000f + (30000f * difficultyFactor), this.targetBody);
            base.SetReputation(45f + (repFactor * 45f * difficultyFactor), 30f + (30f * difficultyFactor), this.targetBody);
            base.SetScience(5f + (scienceFactor * 5f * difficultyFactor), this.targetBody);

            //Prevent duplicate contracts shortly before finishing up.
            foreach (FacilityContract active in ContractSystem.Instance.GetCurrentContracts<FacilityContract>())
            {
                if (active.targetBody == this.targetBody && active.onLand == this.onLand)
                    return false;
            }

            this.AddParameter(new KillControlsParameter(10), null);

            return true;
        }
Example #39
0
		protected override bool Generate()
		{
            if (AreWingsUnlocked() == false)
                return false;

            int offeredContracts = 0;
            int activeContracts = 0;
            foreach (AerialContract contract in ContractSystem.Instance.GetCurrentContracts<AerialContract>())
            {
                if (contract.ContractState == Contract.State.Offered)
                    offeredContracts++;
                else if (contract.ContractState == Contract.State.Active)
                    activeContracts++;
            }

            if (offeredContracts >= FPConfig.Aerial.MaximumAvailable || activeContracts >= FPConfig.Aerial.MaximumActive)
                return false;

            double range = 10000.0;
			System.Random generator = new System.Random(this.MissionSeed);
			int additionalWaypoints = 0;
			List<CelestialBody> allBodies = GetBodies_Reached(true, false);
			List<CelestialBody> atmosphereBodies = new List<CelestialBody>();

			foreach (CelestialBody body in allBodies)
			{
				if (body.atmosphere)
					atmosphereBodies.Add(body);
			}

			if (atmosphereBodies.Count == 0)
				return false;

			targetBody = atmosphereBodies[generator.Next(0, atmosphereBodies.Count)];

            //TODO: Find some common ground to calculate these values automatically without specific names.
			switch (targetBody.GetName())
			{
				case "Jool":
					additionalWaypoints = 0;
					minAltitude = 15000.0;
					maxAltitude = 30000.0;
					break;
				case "Duna":
					additionalWaypoints = 1;
					minAltitude = 8000.0;
					maxAltitude = 16000.0;
					break;
				case "Laythe":
					additionalWaypoints = 1;
					minAltitude = 15000.0;
					maxAltitude = 30000.0;
					break;
				case "Eve":
					additionalWaypoints = 1;
					minAltitude = 20000.0;
					maxAltitude = 40000.0;
					break;
				case "Kerbin":
					additionalWaypoints = 2;
					minAltitude = 12500.0;
					maxAltitude = 25000.0;
					break;
				default:
					additionalWaypoints = 0;
					minAltitude = 0.0;
					maxAltitude = 10000.0;
					break;
			}

            int waypointCount = 0;
            float fundsMultiplier = 1;
            float scienceMultiplier = 1;
            float reputationMultiplier = 1;
            float wpFundsMultiplier = 1;
            float wpScienceMultiplier = 1;
            float wpReputationMultiplier = 1;
            
            double altitudeHalfQuarterRange = Math.Abs(maxAltitude - minAltitude) * 0.125;
			double upperMidAltitude = ((maxAltitude + minAltitude) / 2.0) + altitudeHalfQuarterRange;
			double lowerMidAltitude = ((maxAltitude + minAltitude) / 2.0) - altitudeHalfQuarterRange;
			minAltitude = Math.Round((minAltitude + (generator.NextDouble() * (lowerMidAltitude - minAltitude))) / 100.0) * 100.0;
			maxAltitude = Math.Round((upperMidAltitude + (generator.NextDouble() * (maxAltitude - upperMidAltitude))) / 100.0) * 100.0;

			switch(this.prestige)
            {
                case ContractPrestige.Trivial:
				    waypointCount = FPConfig.Aerial.TrivialWaypoints;
				    waypointCount += additionalWaypoints;
                    range = FPConfig.Aerial.TrivialRange;

                    if (Util.IsGasGiant(targetBody))
                    {
                        if (generator.Next(0, 100) < FPConfig.Aerial.ExceptionalLowAltitudeChance/2)
                        {
                            minAltitude *= FPConfig.Aerial.ExceptionalLowAltitudeMultiplier;
                            maxAltitude *= FPConfig.Aerial.ExceptionalLowAltitudeMultiplier;
                            isLowAltitude = true;
                        }
                    }
                    else
                    {
                        if (generator.Next(0, 100) < FPConfig.Aerial.TrivialLowAltitudeChance)
                        {
                            minAltitude *= FPConfig.Aerial.TrivialLowAltitudeMultiplier;
                            maxAltitude *= FPConfig.Aerial.TrivialLowAltitudeMultiplier;
                            isLowAltitude = true;
                        }
                    }

                    if (generator.Next(0, 100) < FPConfig.Aerial.TrivialHomeNearbyChance && targetBody == Planetarium.fetch.Home)
                        WaypointManager.ChooseRandomPositionNear(out centerLatitude, out centerLongitude, SpaceCenter.Instance.Latitude, SpaceCenter.Instance.Longitude, targetBody.GetName(), FPConfig.Aerial.TrivialHomeNearbyRange, true);
                    else
                        WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), true, false);

                    break;
                case ContractPrestige.Significant:
                    waypointCount = FPConfig.Aerial.SignificantWaypoints;
				    waypointCount += additionalWaypoints;
                    range = FPConfig.Aerial.SignificantRange;
                    fundsMultiplier = FPConfig.Aerial.Funds.SignificantMultiplier;
                    scienceMultiplier = FPConfig.Aerial.Science.SignificantMultiplier;
                    reputationMultiplier = FPConfig.Aerial.Reputation.SignificantMultiplier;
                    wpFundsMultiplier = FPConfig.Aerial.Funds.WaypointSignificantMultiplier;
                    wpScienceMultiplier = FPConfig.Aerial.Science.WaypointSignificantMultiplier;
                    wpReputationMultiplier = FPConfig.Aerial.Reputation.WaypointSignificantMultiplier;

                    if (Util.IsGasGiant(targetBody))
                    {
                        if (generator.Next(0, 100) < FPConfig.Aerial.SignificantLowAltitudeChance/2)
                        {
                            minAltitude *= FPConfig.Aerial.SignificantLowAltitudeMultiplier;
                            maxAltitude *= FPConfig.Aerial.SignificantLowAltitudeMultiplier;
                            isLowAltitude = true;
                        }
                    }
                    else
                    {
                        if (generator.Next(0, 100) < FPConfig.Aerial.SignificantLowAltitudeChance)
                        {
                            minAltitude *= FPConfig.Aerial.SignificantLowAltitudeMultiplier;
                            maxAltitude *= FPConfig.Aerial.SignificantLowAltitudeMultiplier;
                            isLowAltitude = true;
                        }
                    }

                    if (generator.Next(0, 100) < FPConfig.Aerial.SignificantHomeNearbyChance && targetBody == Planetarium.fetch.Home)
                        WaypointManager.ChooseRandomPositionNear(out centerLatitude, out centerLongitude, SpaceCenter.Instance.Latitude, SpaceCenter.Instance.Longitude, targetBody.GetName(), FPConfig.Aerial.SignificantHomeNearbyRange, true);
                    else
                        WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), true, false);

                    break;
                case ContractPrestige.Exceptional:
                    waypointCount = FPConfig.Aerial.ExceptionalWaypoints;
				    waypointCount += additionalWaypoints;
                    range = FPConfig.Aerial.ExceptionalRange;
                    fundsMultiplier = FPConfig.Aerial.Funds.ExceptionalMultiplier;
                    scienceMultiplier = FPConfig.Aerial.Science.ExceptionalMultiplier;
                    reputationMultiplier = FPConfig.Aerial.Reputation.ExceptionalMultiplier;
                    wpFundsMultiplier = FPConfig.Aerial.Funds.WaypointExceptionalMultiplier;
                    wpScienceMultiplier = FPConfig.Aerial.Science.WaypointExceptionalMultiplier;
                    wpReputationMultiplier = FPConfig.Aerial.Reputation.WaypointExceptionalMultiplier;

                    if (Util.IsGasGiant(targetBody))
                    {
                        if (generator.Next(0, 100) < FPConfig.Aerial.TrivialLowAltitudeChance/2)
                        {
                            minAltitude *= FPConfig.Aerial.TrivialLowAltitudeMultiplier;
                            maxAltitude *= FPConfig.Aerial.TrivialLowAltitudeMultiplier;
                            isLowAltitude = true;
                        }
                    }
                    else
                    {
                        if (generator.Next(0, 100) < FPConfig.Aerial.ExceptionalLowAltitudeChance)
                        {
                            minAltitude *= FPConfig.Aerial.ExceptionalLowAltitudeMultiplier;
                            maxAltitude *= FPConfig.Aerial.ExceptionalLowAltitudeMultiplier;
                            isLowAltitude = true;
                        }
                    }

                    if (generator.Next(0, 100) < FPConfig.Aerial.ExceptionalHomeNearbyChance && targetBody == Planetarium.fetch.Home)
                        WaypointManager.ChooseRandomPositionNear(out centerLatitude, out centerLongitude, SpaceCenter.Instance.Latitude, SpaceCenter.Instance.Longitude, targetBody.GetName(), FPConfig.Aerial.ExceptionalHomeNearbyRange, true);
                    else
                        WaypointManager.ChooseRandomPosition(out centerLatitude, out centerLongitude, targetBody.GetName(), true, false);

                    break;
            }

			for (int x = 0; x < waypointCount; x++)
			{
				ContractParameter newParameter;
				newParameter = this.AddParameter(new FlightWaypointParameter(x, targetBody, minAltitude, maxAltitude, centerLatitude, centerLongitude, range), null);
				newParameter.SetFunds(Mathf.Round(FPConfig.Aerial.Funds.WaypointBaseReward * wpFundsMultiplier), targetBody);
                newParameter.SetReputation(Mathf.Round(FPConfig.Aerial.Reputation.WaypointBaseReward * wpReputationMultiplier), targetBody);
                newParameter.SetScience(Mathf.Round(FPConfig.Aerial.Science.WaypointBaseReward * wpScienceMultiplier), targetBody);
			}

			base.AddKeywords(new string[] { "surveyflight" });
            base.SetExpiry(FPConfig.Aerial.Expire.MinimumExpireDays, FPConfig.Aerial.Expire.MaximumExpireDays);
            base.SetDeadlineDays(FPConfig.Aerial.Expire.DeadlineDays, targetBody);
            base.SetFunds(Mathf.Round(FPConfig.Aerial.Funds.BaseAdvance * fundsMultiplier), Mathf.Round(FPConfig.Aerial.Funds.BaseReward * fundsMultiplier), Mathf.Round(FPConfig.Aerial.Funds.BaseFailure * fundsMultiplier), targetBody);
            base.SetScience(Mathf.Round(FPConfig.Aerial.Science.BaseReward * scienceMultiplier), targetBody);
            base.SetReputation(Mathf.Round(FPConfig.Aerial.Reputation.BaseReward * reputationMultiplier), Mathf.Round(FPConfig.Aerial.Reputation.BaseFailure * reputationMultiplier), targetBody);
			return true;
		}
        public void updateMapIcons(bool isFocused)
        {
            if (beenSetup && MapView.MapIsEnabled)
            {
                if (!isFocused)
                {
                    setVisible(false);
                    return;
                }
                else
                {
                    setVisible(true);
                }

                iconTimer = (iconTimer + Time.deltaTime) % maxIconTimer;

                float offset = -(1f / numSpinners);

                for (int x = 0; x < iconWaypoints.Count; x++)
                {
                    switch (iconWaypoints[x].waypointType)
                    {
                    case WaypointType.ORBITAL:
                        offset += (1f / numSpinners);
                        iconWaypoints[x].orbitPosition = getOrbitPositionAtRatio(offset + (iconTimer / maxIconTimer));
                        break;

                    case WaypointType.ASCENDINGNODE:
                        if (HighLogic.LoadedSceneIsFlight)
                        {
                            iconWaypoints[x].visible = checkWaypointVisibility(iconWaypoints[x]);
                            double angleOfAscendingNode = Util.angleOfAscendingNode(orbitDriver.orbit, FlightGlobals.ActiveVessel.orbit);
                            iconWaypoints[x].orbitPosition = orbitDriver.orbit.getPositionFromTrueAnomaly(angleOfAscendingNode * (Math.PI / 180));
                            iconWaypoints[x].tooltip       = "Ascending Node: " + Math.Round(Util.getRelativeInclination(FlightGlobals.ActiveVessel.orbit, orbitDriver.orbit), 1) + "°";
                        }
                        break;

                    case WaypointType.DESCENDINGNODE:
                        if (HighLogic.LoadedSceneIsFlight)
                        {
                            iconWaypoints[x].visible = checkWaypointVisibility(iconWaypoints[x]);
                            double angleOfDescendingNode = Util.angleOfDescendingNode(orbitDriver.orbit, FlightGlobals.ActiveVessel.orbit);
                            iconWaypoints[x].orbitPosition = orbitDriver.orbit.getPositionFromTrueAnomaly(angleOfDescendingNode * (Math.PI / 180));
                            iconWaypoints[x].tooltip       = "Descending Node: " + Math.Round(-Util.getRelativeInclination(FlightGlobals.ActiveVessel.orbit, orbitDriver.orbit), 1) + "°";
                        }
                        break;

                    case WaypointType.APOAPSIS:
                        double ApA = (sma * (1 + eccentricity)) - targetBody.Radius;
                        iconWaypoints[x].orbitPosition = Util.positionOfApoapsis(orbitDriver.orbit);
                        iconWaypoints[x].tooltip       = targetBody.GetName() + " Apoapsis: " + Convert.ToDecimal(Math.Round(ApA)).ToString("#,###") + "m";
                        break;

                    case WaypointType.PERIAPSIS:
                        double PeA = (sma * (1 - eccentricity)) - targetBody.Radius;
                        iconWaypoints[x].orbitPosition = Util.positionOfPeriapsis(orbitDriver.orbit);
                        iconWaypoints[x].tooltip       = targetBody.GetName() + " Periapsis: " + Convert.ToDecimal(Math.Round(PeA)).ToString("#,###") + "m";
                        break;
                    }
                }
            }
        }