Esempio n. 1
0
        protected override void OnLoad(ConfigNode node)
        {
            type = node.parse("Type", (int)1000);
            if (type == 1000)
            {
                DMUtils.Logging("Failed To Load Type-Variables; Mag Orbital Parameter Removed");
                this.Unregister();
                this.Parent.RemoveParameter(this);
                return;
            }

            if (type == 0)
            {
                orbitalParameter = node.parse("Orbital_Parameter", (double)0.2);
            }
            else
            {
                orbitalParameter = node.parse("Orbital_Parameter", (double)20);
            }

            this.disableOnStateChange = false;

            try
            {
                root = (DMLongOrbitParameter)Parent;
            }
            catch (Exception e)
            {
                this.Unregister();
                this.Parent.RemoveParameter(this);
                DMUtils.Logging("Could not find root long orbit parameter; removing DMReconOrbit Parameter\n{0}", e);
                return;
            }
        }
Esempio n. 2
0
 internal DMOrbitalParameters(double Param, int Type, DMLongOrbitParameter r)
 {
     orbitalParameter          = Param;
     type                      = Type;
     root                      = r;
     this.disableOnStateChange = false;
 }
        protected override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            try
            {
                root = (DMLongOrbitParameter)Parent;
            }
            catch (Exception e)
            {
                loadFail("Could not find root long orbit parameter; removing DMSpecific Orbit Parameter\n" + e.ToString());
                return;
            }

            if (HighLogic.LoadedScene == GameScenes.SPACECENTER && this.Root.ContractState == Contract.State.Active)
            {
                body = node.parse("TargetBody", (CelestialBody)null);
                if (body == null)
                {
                    loadFail("Failed To Load Target Body; DMSpecific Orbit Parameter Removed");
                    return;
                }

                int oType = node.parse("orbitType", (int)1000);
                if (oType == 1000)
                {
                    loadFail("Failed To Load Orbit Type; DMSpecific Orbit Parameter Removed");
                    return;
                }
                type = (OrbitType)oType;

                inc       = node.parse("inclination", (double)90);
                ecc       = node.parse("eccentricity", (double)0);
                sma       = node.parse("sma", (double)0);
                aop       = node.parse("argumentOfPeriapsis", (double)0);
                mae       = node.parse("meanAnomalyAtEpoch", (double)0);
                epo       = node.parse("epoch", (double)0);
                lan       = node.parse("lan", (double)0);
                deviation = node.parse("deviationWindow", (double)10);
                setupOrbit(true);
            }

            if (this.Root.ContractState == Contract.State.Active)
            {
                orbitLoaded = testOrbit(HighLogic.LoadedScene == GameScenes.SPACECENTER);
            }

            loaded = true;
        }
Esempio n. 4
0
 public DMSpecificOrbitParameter(OrbitType orbitType, double inclination, double eccentricity, double semi, double la, double argumentOfPeriapsis, double meanAnomalyAtEpoch, double epoch, CelestialBody targetBody, double deviationWindow, DMLongOrbitParameter r) : base(orbitType, inclination, eccentricity, semi, la, argumentOfPeriapsis, meanAnomalyAtEpoch, epoch, targetBody, deviationWindow)
 {
     type                 = orbitType;
     body                 = targetBody;
     inc                  = inclination;
     ecc                  = eccentricity;
     sma                  = semi;
     lan                  = la;
     aop                  = argumentOfPeriapsis;
     mae                  = meanAnomalyAtEpoch;
     epo                  = epoch;
     deviation            = deviationWindow;
     root                 = r;
     disableOnStateChange = false;
 }
        protected override bool Generate()
        {
            DMMagneticSurveyContract[] magContracts = ContractSystem.Instance.GetCurrentContracts<DMMagneticSurveyContract>();
            int offers = 0;
            int active = 0;
            int maxOffers = DMUtils.maxMagneticOffered;
            int maxActive = DMUtils.maxMagneticActive;

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

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

            //Make sure that the RPWS is available
            AvailablePart aPart = PartLoader.getPartInfoByName("rpwsAnt");
            if (aPart == null)
                return false;
            if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                return false;

            body = DMUtils.nextTargetBody(this.Prestige, GetBodies_Reached(false, false), GetBodies_NextUnreached(4, null));
            if (body == null)
                return false;

            DMScienceContainer magContainer = DMUtils.availableScience["All"].FirstOrDefault(m => m.Key == "Magnetometer Scan").Value;
            DMScienceContainer rpwsContainer = DMUtils.availableScience["All"].FirstOrDefault(r => r.Key == "Radio Plasma Wave Scan").Value;

            magParams[0] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceLow, magContainer);
            magParams[1] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceHigh, magContainer);
            magParams[2] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceLow, rpwsContainer);
            magParams[3] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceHigh, rpwsContainer);

            double time = 2160000d *(double)(this.Prestige + 1) * ((double)rand.Next(6, 17) / 10d);
            double eccen = 0.15d * (double)(this.Prestige + 1) * ((double)rand.Next(10, 21) / 10d);
            if (eccen > 0.7) eccen = 0.7;
            double inclination = 20d * (double)(this.Prestige + 1) * ((double)rand.Next(8, 15) / 10d);
            if (inclination > 75) inclination = 75;

            DMLongOrbitParameter longParam = new DMLongOrbitParameter(time);
            DMOrbitalParameters eccentricParam = new DMOrbitalParameters(eccen, 0);
            DMOrbitalParameters inclinedParam = new DMOrbitalParameters(inclination, 1);

            this.AddParameter(longParam);
            longParam.AddParameter(eccentricParam);
            longParam.AddParameter(inclinedParam);

            if (eccentricParam == null || inclinedParam == null)
                return false;

            //Add the science collection parent parameter
            DMCompleteParameter DMcp = new DMCompleteParameter(1, 0);
            this.AddParameter(DMcp);

            foreach (DMCollectScience DMCS in magParams)
            {
                if (DMCS == null)
                    return false;
                else
                {
                    DMcp.addToSubParams(DMCS, "MagFieldScience");
                    DMCS.SetFunds(5000f * DMUtils.reward  * ((float)rand.Next(85, 116) / 100f), body);
                    DMCS.SetScience(2f * DMUtils.science * DMUtils.fixSubjectVal(DMCS.Situation, 1f, body), null);
                }
            }

            if (this.ParameterCount == 0)
                return false;

            float primaryModifier = ((float)rand.Next(80, 121) / 100f);
            float diffModifier = 1 + ((float)this.Prestige * 0.5f);

            this.agent = AgentList.Instance.GetAgent("DMagic");
            base.SetExpiry(10 * DMUtils.deadline, 20f * DMUtils.deadline);
            base.SetDeadlineDays((float)(time  / KSPUtil.KerbinDay) * 3.7f * (this.GetDestinationWeight(body) / 1.8f) * DMUtils.deadline * primaryModifier, null);
            base.SetReputation(8f * diffModifier * DMUtils.reward * primaryModifier, 7f * diffModifier * DMUtils.penalty * primaryModifier, null);
            base.SetFunds(35000 * diffModifier * DMUtils.forward * primaryModifier, 40000 * diffModifier * DMUtils.reward * primaryModifier, 28000 * diffModifier * DMUtils.penalty * primaryModifier, body);
            base.SetScience(10f * diffModifier * DMUtils.science * primaryModifier, body);
            return true;
        }