Exemplo n.º 1
0
        internal void getAnomValues()
        {
            anomCloseRange     = false;
            anomScienceInRange = false;
            closestAnom        = "";

            currentAnomalies = DMAnomalyList.getAnomalyStorage(vessel.mainBody.bodyName);

            if (currentAnomalies == null)
            {
                if (currentAnomaly == null)
                {
                    return;
                }

                checkAnomalyForScience(currentAnomaly);
            }
            else
            {
                for (int i = 0; i < currentAnomalies.AnomalyCount; i++)
                {
                    DMAnomalyObject anom = currentAnomalies.getAnomaly(i);

                    if (checkAnomalyForScience(anom))
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void inRange()
        {
            anomInRange = false;

            currentAnomalies = DMAnomalyList.getAnomalyStorage(vessel.mainBody.bodyName);

            if (currentAnomalies == null)
            {
                if (currentAnomaly != null)
                {
                    checkAnomalyDistance(currentAnomaly);
                }
            }
            else
            {
                for (int i = 0; i < currentAnomalies.AnomalyCount; i++)
                {
                    DMAnomalyObject anom = currentAnomalies.getAnomaly(i);

                    if (checkAnomalyDistance(anom))
                    {
                        break;
                    }
                }
            }

            if (!anomInRange && camDeployed)
            {
                animSecondary[foundAnimate].wrapMode = WrapMode.Default;
                cam.localRotation = Quaternion.Slerp(cam.localRotation, new Quaternion(0, 0, 0, 1), 1f);
                newSecondaryAnimator(camAnimate, -1f, 1f, WrapMode.Default);
                camDeployed = false;
            }
        }
Exemplo n.º 3
0
        public void scanPlanet(CelestialBody b)
        {
            DMAnomalyStorage anom = DMAnomalyList.getAnomalyStorage(b.bodyName);

            if (anom == null)
            {
                anom = new DMAnomalyStorage(b, false);
            }

            if (anom.Scanned)
            {
                return;
            }

            if (anom.scanBody())
            {
                DMAnomalyList.addAnomalyStorage(b.bodyName, anom);
            }
        }
Exemplo n.º 4
0
        public void Update()
        {
            if (HighLogic.LoadedSceneIsFlight && primaryModule != null)
            {
                if (!FlightGlobals.ready || DMScienceScenario.SciScenario == null)
                {
                    return;
                }

                float deltaTime = 1f;
                if (Time.deltaTime != 0)
                {
                    deltaTime = TimeWarp.deltaTime / Time.deltaTime;
                }
                if (deltaTime > 10)
                {
                    deltaTime = 10;
                }
                float dTime = Time.time * deltaTime;
                if (dTime - lastUpdate > updateInterval || dTime < updateInterval)
                {
                    lastUpdate = Time.time;
                    if (primaryModule.IsDeployed && runMagnetometer)
                    {
                        CelestialBody planetID = vessel.mainBody;
                        int           ID       = planetID.flightGlobalsIndex;

                        //double latDeg; // = (vessel.latitude + 90 + 180) % 180 - 90;
                        //double lonDeg; // = (vessel.longitude + 180 + 360) % 360 - 180;
                        double lat;
                        double lon;
                        double alt;
                        double uDay;
                        double nDay;
                        int    localDay;
                        long   date;

                        //Paramaters for mag field model
                        int      i     = 10;
                        double[] field = new double[6];
                        double   lonShift;

                        if (ID == 1 || ID == 2 || ID == 3 || ID == 5 || ID == 6 || ID == 7 || ID == 8 || ID == 9 || ID == 10 || ID == 11 || ID == 12 || ID == 13 || ID == 14)
                        {
                            if (ID == 9 || ID == 10 || ID == 11 || ID == 12 || ID == 14)
                            {
                                //For now the Joolian moons return values relative to Jool
                                Vector3 vesselPosition = vessel.transform.position;
                                alt      = FlightGlobals.fetch.bodies[8].GetAltitude(vesselPosition) / 5000;
                                lat      = ((FlightGlobals.fetch.bodies[8].GetLatitude(vesselPosition) + 90 + 180) % 180 - 90) * Mathf.Deg2Rad;
                                lon      = ((FlightGlobals.fetch.bodies[8].GetLongitude(vesselPosition) + 180 + 360) % 360 - 180) * Mathf.Deg2Rad;
                                planetID = FlightGlobals.fetch.bodies[8];
                            }
                            else if (ID == 2 || ID == 3)
                            {
                                Vector3 vesselPosition = vessel.transform.position;
                                alt      = FlightGlobals.fetch.bodies[1].GetAltitude(vesselPosition) / 1000;
                                lat      = ((FlightGlobals.fetch.bodies[1].GetLatitude(vesselPosition) + 90 + 180) % 180 - 90) * Mathf.Deg2Rad;
                                lon      = ((FlightGlobals.fetch.bodies[1].GetLongitude(vesselPosition) + 180 + 360) % 360 - 180) * Mathf.Deg2Rad;
                                planetID = FlightGlobals.fetch.bodies[1];
                            }
                            else if (ID == 7)
                            {
                                Vector3 vesselPosition = vessel.transform.position;
                                alt      = FlightGlobals.fetch.bodies[6].GetAltitude(vesselPosition) / 1000;
                                lat      = ((FlightGlobals.fetch.bodies[6].GetLatitude(vesselPosition) + 90 + 180) % 180 - 90) * Mathf.Deg2Rad;
                                lon      = ((FlightGlobals.fetch.bodies[6].GetLongitude(vesselPosition) + 180 + 360) % 360 - 180) * Mathf.Deg2Rad;
                                planetID = FlightGlobals.fetch.bodies[6];
                            }
                            else if (ID == 13)
                            {
                                Vector3 vesselPosition = vessel.transform.position;
                                alt      = FlightGlobals.fetch.bodies[5].GetAltitude(vesselPosition) / 1000;
                                lat      = ((FlightGlobals.fetch.bodies[5].GetLatitude(vesselPosition) + 90 + 180) % 180 - 90) * Mathf.Deg2Rad;
                                lon      = ((FlightGlobals.fetch.bodies[5].GetLongitude(vesselPosition) + 180 + 360) % 360 - 180) * Mathf.Deg2Rad;
                                planetID = FlightGlobals.fetch.bodies[5];
                            }
                            else
                            {
                                lat = ((vessel.latitude + 90 + 180) % 180 - 90) * Mathf.Deg2Rad;
                                lon = ((vessel.longitude + 180 + 360) % 360 - 180) * Mathf.Deg2Rad;
                                alt = vessel.altitude / 1000;
                                if (ID == 8)
                                {
                                    alt /= 5;
                                }
                            }

                            uDay = Planetarium.GetUniversalTime() / solarDay(planetID);
                            nDay = uDay % 1;

                            //Shift our current longitide to account for solar day - lonShift should equal zero when crossing solar noon, bring everything down to -Pi to Pi just to be safe
                            //For reference, at time zero the sun is directly above -90.158 Deg West on Kerbin, I'm rounding that to -90, or -Pi/2
                            lonShift = ((lon + longShift(planetID, nDay)) + Math.PI + Math.PI * 2) % (2 * Math.PI) - Math.PI;

                            //Simulate magnetosphere distortion by solar wind with stretched torus shape, determine our position on the surface of the torus
                            double radiusx = ((3.5 + (1 + 1 / Math.Cos(lonShift)) * Math.Cos(Math.PI + lonShift)) + (3.5 + (1.3 + 1 / Math.Cos(lonShift)) * Math.Cos(Math.PI + lonShift)) * Math.Cos(lat * 2)) * Math.Cos(lonShift);
                            double radiusy = (0.75 + 0.9 * Math.Cos(lat * 2)) * Math.Sin(lonShift);
                            double radiusz = (1 + 0.2 * Math.Cos(lonShift)) * Math.Sin(lat * 2);
                            double Radius  = Math.Sqrt((radiusx * radiusx) + (radiusy * radiusy) + (radiusz * radiusz));
                            if (Radius == 0)
                            {
                                Radius += 0.001;
                            }

                            //Scale our altitude by our position on the simulated torus, ignore at altitudes below one planetary radius, ramp up quickly above high scaled altitude up to a max value
                            if (alt > altScale(planetID))
                            {
                                alt *= radScale(planetID) / Radius;
                                if (alt < altScale(planetID))
                                {
                                    alt = altScale(planetID);
                                }
                            }
                            if (alt > altScale(planetID) * 2)
                            {
                                alt *= Math.Pow((alt / (altScale(planetID) * 2)), 3);
                            }
                            if (alt > altMax(planetID))
                            {
                                alt = altMax(planetID);
                            }
                        }
                        else if (ID == 0)
                        {
                            lat  = ((vessel.latitude + 90 + 180) % 180 - 90) * Mathf.Deg2Rad;
                            lon  = ((vessel.longitude + 180 + 360) % 360 - 180) * Mathf.Deg2Rad;
                            alt  = vessel.altitude / 50000;
                            uDay = Planetarium.GetUniversalTime() / solarDay(planetID);
                        }
                        else
                        {
                            //For non-magnetic planets use our position relative to the sun to calculate alt, lat, and long
                            Vector3 vesselPosition = vessel.transform.position;
                            alt      = FlightGlobals.fetch.bodies[0].GetAltitude(vesselPosition) / 50000;
                            lat      = ((FlightGlobals.fetch.bodies[0].GetLatitude(vesselPosition) + 90 + 180) % 180 - 90) * Mathf.Deg2Rad;
                            lon      = ((FlightGlobals.fetch.bodies[0].GetLongitude(vesselPosition) + 180 + 360) % 360 - 180) * Mathf.Deg2Rad;
                            planetID = FlightGlobals.fetch.bodies[0];
                            uDay     = Planetarium.GetUniversalTime() / solarDay(planetID);
                        }

                        localDay = Convert.ToInt32(uDay);
                        date     = 2455197 + (localDay % 500) + ID * 25;

                        //Send all of our modified parameters to the field model
                        double[] magComp = getMag(lat, lon, alt, date, i, field);

                        //Magnetic field components
                        //double Brad = magComp[0];
                        //double BPsi = magComp[2];
                        //double BTheta = magComp[1];
                        double Bx = magComp[3] * planetScale(planetID);
                        double By = magComp[4] * planetScale(planetID);
                        double Bz = magComp[5] * planetScale(planetID);

                        //Calculate various magenetic field components based on 3-axis field strength
                        double Bh = Math.Sqrt((Bx * Bx) + (By * By));

                        //Alter the magnetic field line vector when far away from the planet
                        if (ID > 0)
                        {
                            if (alt > altScale(planetID) * 3)
                            {
                                if (ID == 8)
                                {
                                    if (alt < (altMax(planetID) / 7))
                                    {
                                        Bh /= (alt / (altScale(planetID) * 3));
                                        Bz *= (alt / (altScale(planetID) * 3));
                                    }
                                    else
                                    {
                                        Bh /= ((altMax(planetID) / 7) / (altScale(planetID) * 3));
                                        Bz *= ((altMax(planetID) / 7) / (altScale(planetID) * 3));
                                    }
                                }
                                else
                                {
                                    if (alt < (altMax(planetID) / 2))
                                    {
                                        Bh /= (alt / (altScale(planetID) * 3));
                                        Bz *= (alt / (altScale(planetID) * 3));
                                    }
                                    else
                                    {
                                        Bh /= ((altMax(planetID) / 2) / (altScale(planetID) * 3));
                                        Bz *= ((altMax(planetID) / 2) / (altScale(planetID) * 3));
                                    }
                                }
                            }
                        }

                        //Anomaly Detection
                        Cities.Clear();
                        if (!DMAnomalyList.ScannerUpdating)
                        {
                            currentAnomalies = DMAnomalyList.getAnomalyStorage(vessel.mainBody.name);

                            if (currentAnomalies != null)
                            {
                                for (int a = 0; a < currentAnomalies.AnomalyCount; a++)
                                //foreach (DMAnomalyObject anom in DMScienceScenario.SciScenario.anomalyList.anomObjects())
                                {
                                    DMAnomalyObject anom = currentAnomalies.getAnomaly(a);

                                    if (anom == null)
                                    {
                                        continue;
                                    }

                                    //foreach (DMAnomalyObject anom in DMScienceScenario.SciScenario.anomalyList.anomObjects())
                                    //{
                                    DMAnomalyList.updateAnomaly(vessel, anom);
                                    if (anom.VDistance < 100000)
                                    {
                                        Cities.Add(anom);
                                    }
                                }
                            }
                        }
                        else
                        {
                            currentAnomalies = DMAnomalyList.getAnomalyStorage(vessel.mainBody.name);

                            if (currentAnomalies != null)
                            {
                                for (int a = 0; a < currentAnomalies.AnomalyCount; a++)
                                {
                                    //foreach (DMAnomalyObject anom in DMScienceScenario.SciScenario.anomalyList.anomObjects())
                                    //{
                                    DMAnomalyObject anom = currentAnomalies.getAnomaly(a);

                                    if (anom == null)
                                    {
                                        continue;
                                    }

                                    if (anom.VDistance < 100000)
                                    {
                                        Cities.Add(anom);
                                    }
                                }
                            }
                        }

                        if (Cities.Count > 0)
                        {
                            var sortAnom    = from entry in Cities orderby entry.VDistance ascending select entry;
                            var closestAnom = sortAnom.First();

                            double anomMult  = 1d;
                            double anomMultZ = 1d;
                            double anomMultH = 1d;

                            if (closestAnom.VDistance != 0)
                            {
                                anomMult  = 1 + ((100000 - closestAnom.VDistance) / 10000);
                                anomMultZ = 1 + (anomMult * ((closestAnom.VDistance - closestAnom.VHorizontal) / closestAnom.VDistance));
                                anomMultH = 1 + (anomMult * ((closestAnom.VDistance - closestAnom.VHeight) / closestAnom.VDistance));
                            }
                            Bz *= anomMultZ;
                            Bh *= anomMultH;
                        }

                        double Bti = Math.Sqrt((Bh * Bh) + (Bz * Bz));
                        double dip = Math.Atan2(Bz, Bh);
                        double decD;

                        //Return 0 declination at magnetic poles
                        if (Bx != 0.0 || By != 0.0)
                        {
                            decD = Math.Atan2(By, Bx);
                        }
                        else
                        {
                            decD = 0.0;
                        }

                        //Convert values for better display
                        dip  *= Mathf.Rad2Deg;
                        decD *= Mathf.Rad2Deg;
                        float Btf  = (float)Bti;
                        float incf = (float)dip;
                        float decf = (float)decD;
                        float Bzf  = (float)Bz;
                        float Bhf  = (float)Bh;

                        //float BRf = (float)Brad;
                        //float BPsif = (float)BPsi;
                        //float BThetaf = (float)BTheta;
                        //float Bxf = (float)Bx;
                        //float Byf = (float)By;

                        //Display in right-click menu
                        Bt  = Btf.ToString("F2") + " nT";
                        inc = incf.ToString("F2") + "Deg";
                        dec = decf.ToString("F2") + "Deg";
                        BhS = Bhf.ToString("F2") + " nT";
                        BzS = Bzf.ToString("F2") + " nT";

                        //Br = BRf.ToString("F2") + " nT";
                        //Bpsi = BPsif.ToString("F2") + " nT";
                        //Btheta = BThetaf.ToString("F2") + " nT";
                        //BX = Bxf.ToString("F2") + " nT";
                        //BY = Byf.ToString("F2") + " nT";
                        //BZ = Bzf.ToString("F2") + " nT";

                        Fields["Bt"].guiActive  = primaryModule.IsDeployed;
                        Fields["inc"].guiActive = alt < (altScale(planetID) / 2);
                        Fields["dec"].guiActive = alt < (altScale(planetID) / 2);
                        Fields["BhS"].guiActive = alt >= (altScale(planetID) / 2);
                        Fields["BzS"].guiActive = alt >= (altScale(planetID) / 2);

                        //Extra variables - used in development

                        //nDays = nDay.ToString();
                        //float altf = (float)alt;
                        //float nDayf = (float)nDay;
                        //Vector3 sunP = FlightGlobals.fetch.bodies[0].position;
                        //Vector3 sunD = transform.InverseTransformPoint(sunP) - part.transform.localPosition;
                        ////lons = nDayf.ToString("F5");
                        //double sunXd = sunD.x;
                        //double sunZd = sunD.z;
                        //sunX = sunXd.ToString();
                        //sunZ = sunZd.ToString();
                        //lats = altf.ToString("F4");
                        //nDays = nDayf.ToString("F4");
                        //radius = Radius.ToString();
                        //float latf = (float)latDeg;
                        //lats = (lon * Mathf.Rad2Deg).ToString();
                        //lons = (lonShift * Mathf.Rad2Deg).ToString();
                        //float lonf = (float)lonDeg;
                        //lats = latf.ToString("F3") + " Deg";
                        //altScaled = alt.ToString();
                        //lons = lonf.ToString("F3") + " Deg";
                        //lons = Btf.ToString("F2") + " nT";
                        //lons = "Shifted long: " + (((lonShift * Mathf.Rad2Deg) + 180 + 360) % 360 - 180).ToString();
                        //lons = "Scaled Bh: " + Bh.ToString();
                        //Bznew = "Scaled Bz: " + Bz.ToString();

                        //Fields["sunX"].guiActive = primaryModule.IsDeployed;
                        //Fields["sunZ"].guiActive = primaryModule.IsDeployed;
                        //Fields["lats"].guiActive = primaryModule.IsDeployed;
                        //Fields["nDays"].guiActive = primaryModule.IsDeployed;
                        //Fields["lons"].guiActive = primaryModule.IsDeployed;
                        //Fields["Bhold"].guiActive = primaryModule.IsDeployed;
                    }
                    else
                    {
                        Fields["Bt"].guiActive  = false;
                        Fields["inc"].guiActive = false;
                        Fields["dec"].guiActive = false;
                        Fields["BhS"].guiActive = false;
                        Fields["BzS"].guiActive = false;
                    }
                }
            }
        }
Exemplo n.º 5
0
        protected override bool Generate()
        {
            DMAnomalyContract[] anomContracts = ContractSystem.Instance.GetCurrentContracts <DMAnomalyContract>();
            int offers    = 0;
            int active    = 0;
            int maxOffers = DMContractDefs.DMAnomaly.maxOffers;
            int maxActive = DMContractDefs.DMAnomaly.maxActive;

            for (int i = 0; i < anomContracts.Length; i++)
            {
                DMAnomalyContract a = anomContracts[i];
                if (a.ContractState == State.Offered)
                {
                    offers++;
                }
                else if (a.ContractState == State.Active)
                {
                    active++;
                }
            }

            if (offers >= maxOffers)
            {
                return(false);
            }
            if (active >= maxActive)
            {
                return(false);
            }

            //Make sure that the anomaly scanner is available
            if (!DMUtils.partAvailable(new List <string>(1)
            {
                "dmAnomScanner"
            }))
            {
                return(false);
            }

            int   reconLevelRequirement = 0;
            float levelLow  = 0;
            float levelHigh = 1;

            switch (this.prestige)
            {
            case ContractPrestige.Trivial:
                reconLevelRequirement = DMContractDefs.DMAnomaly.TrivialReconLevelRequirement;
                levelLow  = DMContractDefs.DMAnomaly.TrivialAnomalyLevel;
                levelHigh = DMContractDefs.DMAnomaly.SignificantAnomalyLevel;
                break;

            case ContractPrestige.Significant:
                reconLevelRequirement = DMContractDefs.DMAnomaly.SignificantReconLevelRequirement;
                levelLow  = DMContractDefs.DMAnomaly.SignificantAnomalyLevel;
                levelHigh = DMContractDefs.DMAnomaly.ExceptionalAnomalyLevel;
                break;

            case ContractPrestige.Exceptional:
                reconLevelRequirement = DMContractDefs.DMAnomaly.ExceptionalReconLevelRequirement;
                levelLow  = DMContractDefs.DMAnomaly.ExceptionalAnomalyLevel;
                levelHigh = 1f;
                break;
            }

            List <CelestialBody> customReachedBodies = ContractSystem.Instance.GetCompletedContracts <DMReconContract>().Where(c => (int)c.Prestige >= reconLevelRequirement).Select(c => c.Body).ToList();

            List <DMAnomalyStorage> anomalies = new List <DMAnomalyStorage>();

            for (int i = 0; i < customReachedBodies.Count; i++)
            {
                CelestialBody b = customReachedBodies[i];

                DMAnomalyStorage stor = DMAnomalyList.getAnomalyStorage(b.bodyName);

                if (stor == null)
                {
                    continue;
                }

                if (stor.Level >= levelLow && stor.Level < levelHigh)
                {
                    anomalies.Add(stor);
                }
            }

            var allAnom = anomalies.SelectMany(a => a.getAllAnomalies);

            var reducedAnom = allAnom.Where(a => a.Name != "KSC" && a.Name != "KSC2" && a.Name != "IslandAirfield");

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

            targetAnomaly = reducedAnom.ElementAt(rand.Next(0, reducedAnom.Count()));

            if (targetAnomaly == null)
            {
                return(false);
            }

            body = targetAnomaly.Body.bodyName;

            r       = new System.Random(this.MissionSeed);
            latRand = r.Next(-5, 5);
            lonRand = r.Next(-5, 5);

            hash   = targetAnomaly.Name;
            lon    = targetAnomaly.Lon;
            lat    = targetAnomaly.Lat;
            cardNS = NSDirection(lat);
            cardEW = EWDirection(lon);

            //Assign primary anomaly contract parameter
            if ((newParam = DMAnomalyGenerator.fetchAnomalyParameter(targetAnomaly.Body, targetAnomaly)) == null)
            {
                return(false);
            }

            sciList.AddRange(DMUtils.availableScience[DMScienceType.Anomaly.ToString()].Values);

            for (i = 0; i < 3; i++)
            {
                if (sciList.Count > 0)
                {
                    DMScience     = sciList[rand.Next(0, sciList.Count)];
                    anomParams[i] = (DMAnomalyGenerator.fetchAnomalyParameter(targetAnomaly.Body, DMScience));
                    sciList.Remove(DMScience);
                }
                else
                {
                    anomParams[i] = null;
                }
            }

            this.AddParameter(newParam);

            float primaryLocationMod = GameVariables.Instance.ScoreSituation(DMUtils.convertSit(newParam.Situation), newParam.Body) * ((float)rand.Next(85, 116) / 100f);

            newParam.SetFunds(DMContractDefs.DMAnomaly.Funds.ParamReward * primaryLocationMod, DMContractDefs.DMAnomaly.Funds.ParamFailure * primaryLocationMod, targetAnomaly.Body);
            newParam.SetScience(DMContractDefs.DMAnomaly.Science.ParamReward * DMUtils.fixSubjectVal(newParam.Situation, 1f, targetAnomaly.Body), null);
            newParam.SetReputation(DMContractDefs.DMAnomaly.Reputation.ParamReward * primaryLocationMod, DMContractDefs.DMAnomaly.Reputation.ParamFailure * primaryLocationMod, null);

            //Add the science collection parent parameter
            DMCompleteParameter DMcp = new DMCompleteParameter(3, 1);

            this.AddParameter(DMcp);

            foreach (DMAnomalyParameter aP in anomParams)
            {
                if (aP != null)
                {
                    if (aP.Container == null)
                    {
                        continue;
                    }

                    DMcp.addToSubParams(aP);
                    float locationMod = GameVariables.Instance.ScoreSituation(DMUtils.convertSit(aP.Situation), targetAnomaly.Body) * ((float)rand.Next(85, 116) / 100f);
                    aP.SetFunds((DMContractDefs.DMAnomaly.Funds.ParamReward / 2) * locationMod, (DMContractDefs.DMAnomaly.Funds.ParamFailure / 2) * locationMod, targetAnomaly.Body);
                    aP.SetScience(aP.Container.Exp.baseValue * DMContractDefs.DMAnomaly.Science.SecondaryReward * DMUtils.fixSubjectVal(aP.Situation, 1f, targetAnomaly.Body), null);
                    aP.SetReputation(DMContractDefs.DMAnomaly.Reputation.ParamReward * locationMod, DMContractDefs.DMAnomaly.Reputation.ParamFailure * locationMod, null);
                }
            }

            if (DMcp.ParameterCount < 2)
            {
                return(false);
            }

            this.agent = AgentList.Instance.GetAgent("DMagic");

            if (this.agent == null)
            {
                this.agent = AgentList.Instance.GetAgentRandom();
            }

            base.SetExpiry(DMContractDefs.DMAnomaly.Expire.MinimumExpireDays, DMContractDefs.DMAnomaly.Expire.MaximumExpireDays);
            base.SetDeadlineYears(DMContractDefs.DMAnomaly.Expire.DeadlineYears * ((float)rand.Next(80, 121)) / 100f, targetAnomaly.Body);
            base.SetReputation(DMContractDefs.DMAnomaly.Reputation.BaseReward * primaryLocationMod, DMContractDefs.DMAnomaly.Reputation.BaseFailure * primaryLocationMod, null);
            base.SetScience(DMContractDefs.DMAnomaly.Science.BaseReward, null);
            base.SetFunds(DMContractDefs.DMAnomaly.Funds.BaseAdvance * primaryLocationMod, DMContractDefs.DMAnomaly.Funds.BaseReward * primaryLocationMod, DMContractDefs.DMAnomaly.Funds.BaseFailure * primaryLocationMod, targetAnomaly.Body);
            return(true);
        }
Exemplo n.º 6
0
        public override void OnSave(ConfigNode node)
        {
            ConfigNode results_node = new ConfigNode("Asteroid_Science");

            foreach (DMScienceData data in recoveredDMScience.Values)
            {
                if (data == null)
                {
                    continue;
                }

                try
                {
                    ConfigNode scienceResults_node = new ConfigNode("DM_Science");
                    scienceResults_node.AddValue("title", data.Title);
                    scienceResults_node.AddValue("bsv", data.BaseValue);
                    scienceResults_node.AddValue("scv", data.SciVal);
                    scienceResults_node.AddValue("sci", data.Science);
                    scienceResults_node.AddValue("cap", data.Cap);
                    results_node.AddNode(scienceResults_node);
                }
                catch (Exception e)
                {
                    Debug.LogWarning("[DMagic] Error Saving Asteroid Science Data: " + e);
                }
            }

            ConfigNode anomaly_node = new ConfigNode("Anomaly_Records");

            for (int i = 0; i < DMAnomalyList.AnomalyCount; i++)
            {
                DMAnomalyStorage anomStorage = DMAnomalyList.getAnomalyStorage(i);

                if (anomStorage == null)
                {
                    continue;
                }

                ConfigNode anomalyList = new ConfigNode("DM_Anomaly_List");
                anomalyList.AddValue("Body", anomStorage.Body.flightGlobalsIndex);

                for (int j = 0; j < anomStorage.AnomalyCount; j++)
                {
                    DMAnomalyObject anom = anomStorage.getAnomaly(j);

                    if (anom == null)
                    {
                        continue;
                    }

                    ConfigNode anomaly = new ConfigNode("DM_Anomaly");
                    anomaly.AddValue("Name", anom.Name);
                    anomaly.AddValue("Lat", anom.Lat.ToString("N5"));
                    anomaly.AddValue("Lon", anom.Lon.ToString("N5"));
                    anomaly.AddValue("Alt", anom.Alt.ToString("N5"));
                    anomalyList.AddNode(anomaly);
                }
                anomaly_node.AddNode(anomalyList);
            }

            node.AddNode(results_node);
            node.AddNode(anomaly_node);
        }