Пример #1
0
        bool StatesHaveChanged() // Track our vessel state, it is used for thread control to know when to fire off new experiments since there is no event for this
        {
            if (currentVessel() != stateVessel | currentSituation() != stateSituation | currentBody() != stateBody | currentBiome() != stateBiome)
            {
                stateVessel    = currentVessel();
                stateBody      = currentBody();
                stateSituation = currentSituation();
                stateBiome     = currentBiome();
                stopwatch.Reset();
                stopwatch.Start();
                return(true);
            }
            else
            {
                return(false);
            }

            //if (stopwatch.ElapsedMilliseconds > 100) // throttling detection to kill transient states.
            //{
            //    stopwatch.Reset();

            //    Debug.Log("[ForScience!] Vessel in new experiment state.");

            //    return true;
            //}
            //else return false;
        }
        public static string Print(this ExperimentSituations exp)
        {
            switch (exp)
            {
            case ExperimentSituations.FlyingHigh:
                return("Flying high");

            case ExperimentSituations.FlyingLow:
                return("Flying low");

            case ExperimentSituations.InSpaceHigh:
                return("High in space");

            case ExperimentSituations.InSpaceLow:
                return("Low in space");

            case ExperimentSituations.SrfLanded:
                return("Landed");

            case ExperimentSituations.SrfSplashed:
                return("Splashed down");

            default:
                throw new ArgumentException("Unexpected experiment situation: " + exp);
            }
        }
Пример #3
0
        /// <summary>
        /// Converts an ExperimentSituations to a human-readable representation.
        /// </summary>
        /// <param name="situation">The ExperimentSituations to be converted.</param>
        /// <returns>The human-readable form of the ExperimentSituations.</returns>
        private string ToString(ExperimentSituations situation)
        {
            switch (situation)
            {
            case ExperimentSituations.FlyingHigh:
                return(Localizer.Format("#autoLOC_[x]_Science!_123") /*flying high over*/);

            case ExperimentSituations.FlyingLow:
                return(Localizer.Format("#autoLOC_[x]_Science!_124") /*flying low over*/);

            case ExperimentSituations.InSpaceHigh:
                return(Localizer.Format("#autoLOC_[x]_Science!_125") /*in space high over*/);

            case ExperimentSituations.InSpaceLow:
                return(Localizer.Format("#autoLOC_[x]_Science!_126") /*in space near*/);

            case ExperimentSituations.SrfLanded:
                return(Localizer.Format("#autoLOC_[x]_Science!_127") /*landed at*/);

            case ExperimentSituations.SrfSplashed:
                return(Localizer.Format("#autoLOC_[x]_Science!_128") /*splashed down at*/);

            default:
                return(situation.ToString());
            }
        }
Пример #4
0
        /// <summary>
        /// Converts an ExperimentSituations to a human-readable representation.
        /// </summary>
        /// <param name="situation">The ExperimentSituations to be converted.</param>
        /// <returns>The human-readable form of the ExperimentSituations.</returns>
        private string ToString(ExperimentSituations situation)
        {
            switch (situation)
            {
            case ExperimentSituations.FlyingHigh:
                return("flying high over");

            case ExperimentSituations.FlyingLow:
                return("flying low over");

            case ExperimentSituations.InSpaceHigh:
                return("in space high over");

            case ExperimentSituations.InSpaceLow:
                return("in space near");

            case ExperimentSituations.SrfLanded:
                return("landed at");

            case ExperimentSituations.SrfSplashed:
                return("splashed down at");

            default:
                return(situation.ToString());
            }
        }
Пример #5
0
 public NewSituationData(Body Body, ExperimentSituations Situation, string biome, string subBiome)
 {
     _body      = Body;
     _situation = Situation;
     _biome     = biome;
     _subBiome  = subBiome;
 }
Пример #6
0
    public static double ScienceDataValue(CelestialBody body, ExperimentSituations situation)
    {
        switch (situation)
        {
        case ExperimentSituations.SrfLanded:
            return(body.scienceValues.LandedDataValue);

        case ExperimentSituations.SrfSplashed:
            return(body.scienceValues.SplashedDataValue);

        case ExperimentSituations.FlyingLow:
            return(body.scienceValues.FlyingLowDataValue);

        case ExperimentSituations.FlyingHigh:
            return(body.scienceValues.FlyingHighDataValue);

        case ExperimentSituations.InSpaceLow:
            return(body.scienceValues.InSpaceLowDataValue);

        case ExperimentSituations.InSpaceHigh:
            return(body.scienceValues.InSpaceHighDataValue);

        default:
            throw new ArgumentOutOfRangeException("situation");
        }
    }
Пример #7
0
        public static string Print(this ExperimentSituations exp)
        {
            switch (exp)
            {
            case ExperimentSituations.FlyingHigh:
                return(Localizer.Format("<<zC:1>>", Localizer.GetStringByTag("#autoLOC_6002003")));

            case ExperimentSituations.FlyingLow:
                return(Localizer.Format("<<zC:1>>", Localizer.GetStringByTag("#autoLOC_6002002")));

            case ExperimentSituations.InSpaceHigh:
                return(Localizer.GetStringByTag("#cc.science.sit.InSpaceHigh"));

            case ExperimentSituations.InSpaceLow:
                return(Localizer.GetStringByTag("#cc.science.sit.InSpaceLow"));

            case ExperimentSituations.SrfLanded:
                return(Localizer.GetStringByTag("#autoLOC_268855"));

            case ExperimentSituations.SrfSplashed:
                return(Localizer.GetStringByTag("#autoLOC_268858"));

            default:
                throw new ArgumentException("Unexpected experiment situation: " + exp);
            }
        }
Пример #8
0
        private string GetSituationString()
        {
            string result            = "";
            ExperimentSituations sit = ScienceUtil.GetExperimentSituation(ActiveVessel);

            switch (sit)
            {
            case ExperimentSituations.FlyingHigh:
                result = "High flight";
                break;

            case ExperimentSituations.FlyingLow:
                result = "Low flight";
                break;

            case ExperimentSituations.InSpaceHigh:
                result = "High above";
                break;

            case ExperimentSituations.InSpaceLow:
                result = "Just above";
                break;

            case ExperimentSituations.SrfLanded:
                result = "Landed";
                break;

            case ExperimentSituations.SrfSplashed:
                result = "Splashed";
                break;
            }

            return(result);
        }
Пример #9
0
        private static ImpactScienceData createAsteroidSpectralData(CelestialBody crashBody, Vessel asteroid, Vessel crashVessel, uint flightID)
        {
            double crashVelocity = crashVessel.srf_velocity.magnitude;

            Log("Velocity=" + crashVelocity);
            float  crashMasss  = crashVessel.GetTotalMass() * 1000;
            double crashEnergy = 0.5 * crashMasss * crashVelocity * crashVelocity; //KE of crash

            ScienceExperiment    experiment = ResearchAndDevelopment.GetExperiment("AsteroidSpectometry");
            ExperimentSituations situation  = ScienceUtil.GetExperimentSituation(asteroid);

            ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(experiment, situation, asteroid.id.ToString(), asteroid.GetName(), crashBody, "", "");
            double         science = subject.scienceCap;

            Log("Impact took place in " + situation);
            String flavourText = "Impact at <<1>> on <<2>>";


            science /= subject.subjectValue;

            ImpactScienceData data = new ImpactScienceData(0, asteroid.GetName(),
                                                           (float)(science * subject.dataScale), 1f, 0, subject.id,
                                                           Localizer.Format(flavourText, asteroid.GetName(), crashBody.GetDisplayName()), false, flightID);

            ScreenMessages.PostScreenMessage(
                Localizer.Format("#autoLOC_Screen_Asteroid", asteroid.GetName(), crashBody.GetDisplayName()),
                5.0f, ScreenMessageStyle.UPPER_RIGHT);

            return(data);
        }
Пример #10
0
        protected override void OnLoad(ConfigNode node)
        {
            int targetLocation;

            string[] scienceString = node.GetValue("Science_Subject").Split('|');
            name = scienceString[0];
            DMUtils.availableScience["All"].TryGetValue(name, out scienceContainer);
            if (scienceContainer == null)
            {
                DMUtils.Logging("Failed To Load Science Container Variables; Asteroid Parameter Set To Complete");
                this.SetComplete();
            }
            else
            {
                partName = scienceContainer.SciPart;
            }
            if (!bool.TryParse(scienceString[1], out collected))
            {
                DMUtils.Logging("Failed To Load Collected State; Asteroid Parameter Assuming Experiment Already Collected");
                collected = true;
            }
            if (int.TryParse(scienceString[2], out targetLocation))
            {
                scienceLocation = (ExperimentSituations)targetLocation;
            }
            else
            {
                DMUtils.Logging("Failed To Load Situation Variables; Asteroid Parameter Set To Complete");
                this.SetComplete();
            }

            root = (DMAsteroidSurveyContract)this.Root;
        }
Пример #11
0
        protected float GetBodyScienceValueMultipler(ExperimentSituations sit)
        {
            var b = FlightGlobals.currentMainBody;

            switch (sit)
            {
            case ExperimentSituations.FlyingHigh:
                return(b.scienceValues.FlyingHighDataValue);

            case ExperimentSituations.FlyingLow:
                return(b.scienceValues.FlyingLowDataValue);

            case ExperimentSituations.InSpaceHigh:
                return(b.scienceValues.InSpaceHighDataValue);

            case ExperimentSituations.InSpaceLow:
                return(b.scienceValues.InSpaceLowDataValue);

            case ExperimentSituations.SrfLanded:
                return(b.scienceValues.LandedDataValue);

            case ExperimentSituations.SrfSplashed:
                return(b.scienceValues.SplashedDataValue);

            default:
                return(0f);
            }
        }
        /// <summary>
        /// Get the ScienceSubject for an asteroid experiment.
        /// </summary>
        /// <param name="mse">The science experiment module must be cast as a ModuleScienceExperiment.</param>
        /// <param name="sit">The current Experiment Situation value; see the getExperimentSituation method above.</param>
        /// <returns>Returns the ScienceSubject for that specific asteroid, experiment, and ExperimentSituation; returns null if the module is not of the right type, the experiment is not suitable for astroids, if no asteroids are detected, or if the current asteroid situation is not suitable for the experiment.</returns>
        public static ScienceSubject getAsteroidSubject(ModuleScienceExperiment mse, ExperimentSituations sit)
        {
            if (mse == null)
            {
                return(null);
            }

            Type t = mse.GetType();

            if (t != typeof(DMModuleScienceAnimateGeneric_NM.DMModuleScienceAnimateGeneric))
            {
                return(null);
            }

            DMModuleScienceAnimateGeneric_NM.DMModuleScienceAnimateGeneric DMMod = (DMModuleScienceAnimateGeneric_NM.DMModuleScienceAnimateGeneric)mse;

            if (!isAsteroidExperiment(DMMod))
            {
                return(null);
            }

            if (DMMod.scienceExp == null)
            {
                return(null);
            }

            if (sit == ExperimentSituations.InSpaceLow)
            {
                if (!isAsteroidNear())
                {
                    return(null);
                }
            }
            else if (sit == ExperimentSituations.SrfLanded)
            {
                if (!isAsteroidGrappled())
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }

            if ((DMMod.scienceExp.situationMask & (int)sit) == 0)
            {
                return(null);
            }

            string oldBodyName = FlightGlobals.Bodies[16].bodyName;

            DMAsteroidScienceGen newAsteroid = new DMAsteroidScienceGen();
            ScienceSubject       sub         = new ScienceSubject(DMMod.scienceExp, sit, newAsteroid.Body, newAsteroid.AClass);

            sub.subjectValue          = newAsteroid.SciMult;
            sub.scienceCap            = DMMod.scienceExp.scienceCap * sub.subjectValue;
            newAsteroid.Body.bodyName = oldBodyName;
            return(sub);
        }
        public static float getScienceMultiplier(ExperimentSituations situation, CelestialBody body)
        {
            CelestialBodyScienceParams pars = body.scienceValues;

            switch (situation)
            {
            case ExperimentSituations.SrfLanded:
                return(pars.LandedDataValue);

            case ExperimentSituations.SrfSplashed:
                return(pars.SplashedDataValue);

            case ExperimentSituations.FlyingLow:
                return(pars.FlyingLowDataValue);

            case ExperimentSituations.FlyingHigh:
                return(pars.FlyingHighDataValue);

            case ExperimentSituations.InSpaceLow:
                return(pars.InSpaceLowDataValue);

            case ExperimentSituations.InSpaceHigh:
                return(pars.InSpaceHighDataValue);
            }
            return(1);
        }
Пример #14
0
        public static string HumanString(this ExperimentSituations situation)
        {
            switch (situation)
            {
            case ExperimentSituations.FlyingHigh:
                return("Upper Atmosphere");

            case ExperimentSituations.FlyingLow:
                return("Flying");

            case ExperimentSituations.SrfLanded:
                return("Surface");

            case ExperimentSituations.InSpaceLow:
                return("Near in Space");

            case ExperimentSituations.InSpaceHigh:
                return("High in Space");

            case ExperimentSituations.SrfSplashed:
                return("Splashed Down");

            default:
                return("Unknown");
            }
        }
Пример #15
0
        protected override List <PossibleContract> pickContracts(IEnumerable <CelestialBody> bodies)
        {
            List <PossibleContract> possible = new List <PossibleContract>();
            double probSum = 0;

            foreach (CelestialBody body in bodies)
            {
                IEnumerable <SeismicContract> contracts = ContractSystem.Instance.GetCurrentContracts <SeismicContract>()
                                                          .Where(contract => contract.pickedContract.body == body);
                if (contracts.Count() > 0)
                {
                    continue;                       //only 1 contract of a given type on a given body at once
                }
                contracts = ContractSystem.Instance.GetCurrentContracts <SeismicContract>()
                            .Where(contract => contract.prestige == prestige && contract.ContractState == State.Offered);
                if (contracts.Count() > 0)
                {
                    continue;                       //only 1 contract a given prestige offered at a time
                }
                ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment("ImpactSeismometer");

                ScienceSubject       subject;
                ExperimentSituations sit = ExperimentSituations.SrfLanded;
                subject = ResearchAndDevelopment.GetExperimentSubject(experiment, sit, body, "surface", "");
                int    stars  = starRatings[prestige];
                double energy = pickKE(stars, subject, body);
                possible.Add(new PossibleContract(++probSum, body, energy));
            }
            return(possible);
        }
 internal DMAnomalyParameter(ExperimentSituations Situation, string Name)
 {
     situation = Situation;
     name = Name;
     DMUtils.availableScience["All"].TryGetValue(name, out scienceContainer);
     partName = scienceContainer.SciPart;
 }
Пример #17
0
        //Use for magnetic field survey
        internal static DMCollectScience fetchScienceContract(CelestialBody Body, ExperimentSituations Situation, DMScienceContainer DMScience)
        {
            AvailablePart aPart;
            string        name;

            //Choose science container based on a given science experiment
            name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key;

            if (DMScience.Exp == null)
            {
                return(null);
            }

            //Determine if the science part is available if applicable
            if (DMScience.SciPart != "None")
            {
                aPart = PartLoader.getPartInfoByName(DMScience.SciPart);
                if (aPart == null)
                {
                    return(null);
                }
                if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                {
                    return(null);
                }
            }

            return(new DMCollectScience(Body, Situation, "", name, 1));
        }
Пример #18
0
        protected virtual string getBiome(ExperimentSituations s)
        {
            if ((bioMask & (int)s) == 0)
            {
                return("");
            }
            else
            {
                switch (vessel.landedAt)
                {
                case "":
                    if (vessel.mainBody.BiomeMap != null)
                    {
                        return(vessel.mainBody.BiomeMap.GetAtt(vessel.latitude * Mathf.Deg2Rad, vessel.longitude * Mathf.Deg2Rad).name);
                    }
                    else
                    {
                        return("");
                    }

                default:
                    return(Vessel.GetLandedAtString(vessel.landedAt));
                }
            }
        }
Пример #19
0
        ////Generate fully random science experiment contract parameter
        //internal static DMCollectScience fetchScienceContract(Contract.ContractPrestige p, List<CelestialBody> cR, List<CelestialBody> cUR)
        //{
        //    DMScienceContainer scienceContainer;
        //    CelestialBody body;
        //    ExperimentSituations targetSituation;
        //    List<ExperimentSituations> situations;
        //    ScienceExperiment exp;
        //    ScienceSubject sub;
        //    AvailablePart aPart;
        //    string name;
        //    string biome = "";

        //    //Choose a random science experiment from our list generated at startup
        //    scienceContainer = DMUtils.availableScience["All"].ElementAt(rand.Next(0, DMUtils.availableScience["All"].Count)).Value;
        //    name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key;
        //    DMUtils.DebugLog("Checking Contract Requirements");

        //    //Determine if the science part is available if applicable
        //    if (scienceContainer.sciPart != "None")
        //    {
        //        DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart);
        //        aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart);
        //        if (aPart == null)
        //            return null;
        //        if (!ResearchAndDevelopment.PartModelPurchased(aPart))
        //            return null;
        //        DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
        //    }

        //    //Select a random Celestial Body based on contract prestige levels
        //    body = DMUtils.nextTargetBody(p, cR, cUR);
        //    if (body == null)
        //        return null;

        //    //Make sure our experiment is OK
        //    exp = scienceContainer.exp;
        //    if (exp == null)
        //        return null;

        //    //Choose an acceptable experimental situation for a given science experiment
        //    if ((situations = DMUtils.availableSituations(exp, scienceContainer.sitMask, body)).Count == 0)
        //        return null;
        //    else
        //    {
        //        DMUtils.DebugLog("Acceptable Situations Found");
        //        targetSituation = situations[rand.Next(0, situations.Count)];
        //        DMUtils.DebugLog("Experimental Situation: {0}", targetSituation);
        //    }

        //    //Build a list of acceptable biomes if applicable, choose one with remaining science
        //    if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed)
        //    {
        //        DMUtils.DebugLog("Checking For Biome Usage");
        //        List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation);
        //        if (bList.Count == 0)
        //        {
        //            DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here");
        //            return null;
        //        }
        //        int i = rand.Next(0, 2);
        //        if (i == 0)
        //        {
        //            biome = bList[rand.Next(0, bList.Count)];
        //            DMUtils.DebugLog("Acceptable Biome Found: {0}", biome);
        //        }
        //    }

        //    //Make sure that our chosen science subject has science remaining to be gathered
        //    if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null)
        //    {
        //        if (sub.scientificValue < 0.4f)
        //            return null;
        //    }

        //    return new DMCollectScience(body, targetSituation, biome, name, 0);
        //}

        ////Generate random experiment for a given celestial body
        //internal static DMCollectScience fetchScienceContract(CelestialBody body)
        //{
        //    DMScienceContainer scienceContainer;
        //    ExperimentSituations targetSituation;
        //    List<ExperimentSituations> situations;
        //    ScienceExperiment exp;
        //    ScienceSubject sub;
        //    AvailablePart aPart;
        //    string name;
        //    string biome = "";

        //    //Choose a random science experiment from our list generated at startup
        //    scienceContainer = DMUtils.availableScience["All"].ElementAt(rand.Next(0, DMUtils.availableScience.Count)).Value;
        //    name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key;
        //    DMUtils.DebugLog("Checking Contract Requirements");

        //    //Determine if the science part is available if applicable
        //    if (scienceContainer.sciPart != "None")
        //    {
        //        DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart);
        //        aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart);
        //        if (aPart == null)
        //            return null;
        //        if (!ResearchAndDevelopment.PartModelPurchased(aPart))
        //            return null;
        //        DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
        //    }

        //    //Make sure our experiment is OK
        //    exp = scienceContainer.exp;
        //    if (exp == null)
        //        return null;

        //    //Choose an acceptable experimental situation for a given science experiment
        //    if ((situations = DMUtils.availableSituations(exp, scienceContainer.sitMask, body)).Count == 0)
        //        return null;
        //    else
        //    {
        //        DMUtils.DebugLog("Acceptable Situations Found");
        //        targetSituation = situations[rand.Next(0, situations.Count)];
        //        DMUtils.DebugLog("Experimental Situation: {0}", targetSituation);
        //    }

        //    //Build a list of acceptable biomes if applicable, choose one with remaining science
        //    if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed)
        //    {
        //        DMUtils.DebugLog("Checking For Biome Usage");
        //        List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation);
        //        if (bList.Count == 0)
        //        {
        //            DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here");
        //            return null;
        //        }
        //        int i = rand.Next(0, 2);
        //        if (i == 0)
        //        {
        //            biome = bList[rand.Next(0, bList.Count)];
        //            DMUtils.DebugLog("Acceptable Biome Found: {0}", biome);
        //        }
        //    }

        //    //Make sure that our chosen science subject has science remaining to be gathered
        //    if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null)
        //    {
        //        if (sub.scientificValue < 0.4f)
        //            return null;
        //    }

        //    return new DMCollectScience(body, targetSituation, biome, name, 0);
        //}

        ////Generate experiment for a given Celestial Body and experimental situation
        //internal static DMCollectScience fetchScienceContract(CelestialBody body, ExperimentSituations targetSituation)
        //{
        //    DMScienceContainer scienceContainer;
        //    ScienceExperiment exp;
        //    ScienceSubject sub;
        //    AvailablePart aPart;
        //    string name;
        //    string biome = "";

        //    //Choose a random science experiment from our list generated at startup
        //    scienceContainer = DMUtils.availableScience["All"].ElementAt(rand.Next(0, DMUtils.availableScience.Count)).Value;
        //    name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key;
        //    DMUtils.DebugLog("Checking Contract Requirements");

        //    //Determine if the science part is available if applicable
        //    if (scienceContainer.sciPart != "None")
        //    {
        //        DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart);
        //        aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart);
        //        if (aPart == null)
        //            return null;
        //        if (!ResearchAndDevelopment.PartModelPurchased(aPart))
        //            return null;
        //        DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
        //    }

        //    //Make sure our experiment is OK
        //    exp = scienceContainer.exp;
        //    if (exp == null)
        //        return null;

        //    //Make sure that the experiment can be conducted in this situation
        //    if (((ExperimentSituations)exp.situationMask & targetSituation) != targetSituation)
        //        return null;

        //    //Build a list of acceptable biomes if applicable, choose one with remaining science
        //    if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed)
        //    {
        //        DMUtils.DebugLog("Checking For Biome Usage");
        //        List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation);
        //        if (bList.Count == 0)
        //        {
        //            DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here");
        //            return null;
        //        }
        //        int i = rand.Next(0, 2);
        //        if (i == 0)
        //        {
        //            biome = bList[rand.Next(0, bList.Count)];
        //            DMUtils.DebugLog("Acceptable Biome Found: {0}", biome);
        //        }
        //    }

        //    //Make sure that our chosen science subject has science remaining to be gathered
        //    if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null)
        //    {
        //        if (sub.scientificValue < 0.4f)
        //            return null;
        //    }

        //    return new DMCollectScience(body, targetSituation, biome, name, 0);
        //}

        ////Generate random experiment for a given celestial body
        //internal static DMCollectScience fetchScienceContract(CelestialBody body, ScienceExperiment exp)
        //{
        //    DMScienceContainer scienceContainer;
        //    ExperimentSituations targetSituation;
        //    List<ExperimentSituations> situations;
        //    ScienceSubject sub;
        //    AvailablePart aPart;
        //    string name;
        //    string biome = "";

        //    //Choose science container based on a given science experiment
        //    scienceContainer = DMUtils.availableScience["All"].FirstOrDefault(e => e.Value.exp == exp).Value;
        //    name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key;
        //    DMUtils.DebugLog("Checking Contract Requirements");

        //    //Determine if the science part is available if applicable
        //    if (scienceContainer.sciPart != "None")
        //    {
        //        DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart);
        //        aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart);
        //        if (aPart == null)
        //            return null;
        //        if (!ResearchAndDevelopment.PartModelPurchased(aPart))
        //            return null;
        //        DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
        //    }

        //    //Make sure our experiment is OK
        //    exp = scienceContainer.exp;
        //    if (exp == null)
        //        return null;

        //    //Choose an acceptable experimental situation for a given science experiment
        //    if ((situations = DMUtils.availableSituations(exp, scienceContainer.sitMask, body)).Count == 0)
        //        return null;
        //    else
        //    {
        //        DMUtils.DebugLog("Acceptable Situations Found");
        //        targetSituation = situations[rand.Next(0, situations.Count)];
        //        DMUtils.DebugLog("Experimental Situation: {0}", targetSituation);
        //    }

        //    //Build a list of acceptable biomes if applicable, choose one with remaining science
        //    if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed)
        //    {
        //        DMUtils.DebugLog("Checking For Biome Usage");
        //        List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation);
        //        if (bList.Count == 0)
        //        {
        //            DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here");
        //            return null;
        //        }
        //        int i = rand.Next(0, 2);
        //        if (i == 0)
        //        {
        //            biome = bList[rand.Next(0, bList.Count)];
        //            DMUtils.DebugLog("Acceptable Biome Found: {0}", biome);
        //        }
        //    }

        //    //Make sure that our chosen science subject has science remaining to be gathered
        //    if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null)
        //    {
        //        if (sub.scientificValue < 0.4f)
        //            return null;
        //    }

        //    return new DMCollectScience(body, targetSituation, biome, name, 0);
        //}

        //Use for magnetic field survey
        internal static DMCollectScience fetchScienceContract(CelestialBody Body, ExperimentSituations Situation, DMScienceContainer DMScience)
        {
            AvailablePart aPart;
            string        name;

            //Choose science container based on a given science experiment
            name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key;
            DMUtils.DebugLog("Checking Contract Requirements");

            if (DMScience.exp == null)
            {
                return(null);
            }

            //Determine if the science part is available if applicable
            if (DMScience.sciPart != "None")
            {
                DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart);
                aPart = PartLoader.getPartInfoByName(DMScience.sciPart);
                if (aPart == null)
                {
                    return(null);
                }
                if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                {
                    return(null);
                }
                DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name);
            }

            return(new DMCollectScience(Body, Situation, "", name, 1));
        }
Пример #20
0
        internal static float fixSubjectVal(ExperimentSituations s, float f, CelestialBody body)
        {
            float subV = f;

            if (s == ExperimentSituations.SrfLanded)
            {
                subV = body.scienceValues.LandedDataValue;
            }
            else if (s == ExperimentSituations.SrfSplashed)
            {
                subV = body.scienceValues.SplashedDataValue;
            }
            else if (s == ExperimentSituations.FlyingLow)
            {
                subV = body.scienceValues.FlyingLowDataValue;
            }
            else if (s == ExperimentSituations.FlyingHigh)
            {
                subV = body.scienceValues.FlyingHighDataValue;
            }
            else if (s == ExperimentSituations.InSpaceLow)
            {
                subV = body.scienceValues.InSpaceLowDataValue;
            }
            else if (s == ExperimentSituations.InSpaceHigh)
            {
                subV = body.scienceValues.InSpaceHighDataValue;
            }
            return(subV);
        }
        protected override void OnLoad(ConfigNode node)
        {
            int sitID;

            string[] anomalyString = node.GetValue("Target_Anomaly").Split('|');
            if (int.TryParse(anomalyString[0], out sitID))
            {
                situation = (ExperimentSituations)sitID;
            }
            else
            {
                DMUtils.Logging("Failed To Load Anomaly Contract Situation Value; Parameter Set To Complete");
                this.SetComplete();
            }
            if (!bool.TryParse(anomalyString[1], out collected))
            {
                DMUtils.Logging("Failed To Load Anomaly Contract Collected State; Parameter Set To Complete");
                this.SetComplete();
            }
            name = anomalyString[2];
            DMUtils.availableScience["All"].TryGetValue(name, out scienceContainer);
            if (scienceContainer == null)
            {
                DMUtils.Logging("Failed To Load Anomaly Contract Science Container Variables; Parameter Set To Complete");
                this.SetComplete();
            }
            else
            {
                partName = scienceContainer.SciPart;
            }

            root = (DMAnomalyContract)this.Root;
        }
Пример #22
0
        //Use for recon survey
        internal static DMCollectScience fetchScienceContract(CelestialBody Body, ExperimentSituations Situation, string biome, DMScienceContainer DMScience)
        {
            string name;

            //Choose science container based on a given science experiment
            if (!DMUtils.availableScience.ContainsKey("All"))
            {
                return(null);
            }

            name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key;

            if (DMScience.Exp == null)
            {
                return(null);
            }

            //Determine if the science part is available if applicable
            if (DMScience.SciPart != "None")
            {
                if (!DMUtils.partAvailable(new List <string>(1)
                {
                    DMScience.SciPart
                }))
                {
                    return(null);
                }
            }

            return(new DMCollectScience(Body, Situation, biome, name, 1));
        }
 internal DMAnomalyParameter(ExperimentSituations Situation, string Name)
 {
     situation = Situation;
     name      = Name;
     DMUtils.availableScience["All"].TryGetValue(name, out scienceContainer);
     partName = scienceContainer.SciPart;
 }
        /** Updates experiments and other fields */
        private void statusUpdate()
        {
            timeSince           = 0f;
            curVessel           = FlightGlobals.ActiveVessel;
            curBiome            = currentBiome();
            expSituation        = ScienceUtil.GetExperimentSituation(curVessel);
            lastBody            = curVessel.mainBody;
            experiments         = getExperiments();
            possExperiments     = new List <ModuleScienceExperiment>();
            finishedExperiments = new List <ModuleScienceExperiment>();
            IETExperiment activator;

            if (experiments.Count() > 0)
            {
                foreach (ModuleScienceExperiment exp in experiments)
                {
                    activator = checkType(exp);
                    if (activator != null)
                    {
                        if (activator.hasData(exp))
                        {
                            finishedExperiments.Add(exp);
                        }
                        else if (activator.checkExperiment(exp, expSituation, lastBody, curBiome))
                        {
                            possExperiments.Add(exp);
                        }
                    }
                }
            }
        }
Пример #25
0
        public override string getBiome(ExperimentSituations s)
        {
            if ((bioMask & (int)s) == 0)
            {
                return("");
            }
            else
            {
                string depth = "";

                if (part.depth < depthThreshold)
                {
                    depth = "Shallow";
                }
                else
                {
                    depth = "Deep";
                }

                if (vessel.mainBody.BiomeMap != null)
                {
                    return(vessel.mainBody.BiomeMap.GetAtt(vessel.latitude * Mathf.Deg2Rad, vessel.longitude * Mathf.Deg2Rad).name + depth);
                }
                else
                {
                    return(depth);
                }
            }
        }
        public static ScienceSubject getScienceSubject(string name, Vessel vessel)
        {
            if (name == "")
            {
                return(null);
            }
            ScienceExperiment experiment = ResearchAndDevelopment.GetExperiment(name);

            if (experiment == null)
            {
                return(null);
            }
            ExperimentSituations situation = getScienceSituation(vessel);
            CelestialBody        body      = vessel.mainBody;
            string biome        = "";
            string displayBiome = "";

            if (vessel.LandedOrSplashed)
            {
                biome        = vessel.landedAt;
                displayBiome = vessel.displaylandedAt;
            }
            ScienceSubject subject = ResearchAndDevelopment.GetExperimentSubject(experiment, situation, body, biome, displayBiome);

            return(subject);
        }
Пример #27
0
 public static string FindBiome(string experimentSecondText, ExperimentSituations situation)
 {
     string situationStr = situation.ToString();
     int offset = experimentSecondText.IndexOf(situationStr) + situationStr.Length;
     if (offset == experimentSecondText.Length)
         return "";
     return experimentSecondText.Substring(offset);
 }
Пример #28
0
 public static string getBiome(ModuleScienceExperiment mse, ExperimentSituations sit)
 {
     if (_MIgetBiome == null)
     {
         return("");
     }
     return((string)_MIgetBiome.Invoke(mse, new object[] { sit }));
 }
Пример #29
0
 /// <summary>
 ///     Replace for ResearchAndDevelopment.GetExperimentSubject function. Original function inserts new ScienceSubject in
 ///     the database, but we do not want that.
 /// </summary>
 /// <param name="experiment"></param>
 /// <param name="situation"></param>
 /// <param name="sourceUId"></param>
 /// <param name="sourceTitle"></param>
 /// <param name="body"></param>
 /// <param name="biome"></param>
 /// <returns></returns>
 public static ScienceSubject GetExperimentSubject(ScienceExperiment experiment, ExperimentSituations situation, string sourceUId, string sourceTitle, CelestialBody body, string biome)
 {
     ScienceSubject scienceSubject = new ScienceSubject(experiment, situation, sourceUId, sourceTitle, body, biome);
     ScienceSubject subject = ResearchAndDevelopment.GetSubjectByID(scienceSubject.id); // this will cause error in log, but it is intended behavior.
     if (subject != null)
         return subject;
     return scienceSubject;
 }
 public MerillContractParameterCameraFooting()
     : base()
 {
     // note: default constructor is necessary or parameter will fail to load
     this.body2Shoot        = null;
     this.situationForShoot = ExperimentSituations.SrfSplashed;
     this.useKerbal         = false;
 }
 public MerillContractParameterCameraFooting(CelestialBody body2Shoot,
                                             ExperimentSituations situationForShoot, bool useKerbal)
     : base()
 {
     this.body2Shoot        = body2Shoot;
     this.situationForShoot = situationForShoot;
     this.useKerbal         = useKerbal;
 }
Пример #32
0
 internal DMAsteroidParameter(ExperimentSituations Location, string Name)
 {
     scienceLocation = Location;
     name            = Name;
     collected       = false;
     DMUtils.availableScience["All"].TryGetValue(name, out scienceContainer);
     partName = scienceContainer.SciPart;
 }
Пример #33
0
        protected override float fixSubjectValue(ExperimentSituations s, float f, float boost, CelestialBody body)
        {
            if (part.depth >= depthThreshold)
            {
                boost = 2f;
            }

            return(base.fixSubjectValue(s, f, boost, body));
        }
Пример #34
0
		/// <summary>
		/// Creates a new instance of the Situation class.
		/// </summary>
		/// <param name="body">The CelestialBody around which this situation is for.</param>
		/// <param name="situation">The ExperimentSituations flag which this situation is for.</param>
		/// <param name="biome">Optionally, the biome which this situation is for.</param>
		/// <param name="subBiome">Optionally, the KSC biome which this situation is for.</param>
		public Situation( Body body, ExperimentSituations situation, string biome = null, string subBiome = null ) {
			_body = body;
			_situation = situation;
			_biome = biome;
			_subBiome = subBiome;
			_formattedBiome = BiomeToString(_biome);
			_formattedSubBiome = BiomeToString(_subBiome);
			_description = string.Format("{0} {1}{2}",
				ToString(_situation),
				Body.CelestialBody.theName,
				string.IsNullOrEmpty(_formattedBiome)
					? string.Empty
					: string.IsNullOrEmpty(_formattedSubBiome)
						? string.Format("'s {0}", _formattedBiome)
						: string.Format("'s {0} ({1})", _formattedSubBiome, _formattedBiome));
		}
Пример #35
0
		/// <summary>
		/// Converts an ExperimentSituations to a human-readable representation.
		/// </summary>
		/// <param name="situation">The ExperimentSituations to be converted.</param>
		/// <returns>The human-readable form of the ExperimentSituations.</returns>
		private string ToString (ExperimentSituations situation) {
			switch (situation) {
				case ExperimentSituations.FlyingHigh:
					return "flying high over";
				case ExperimentSituations.FlyingLow:
					return "flying low over";
				case ExperimentSituations.InSpaceHigh:
					return "in space high over";
				case ExperimentSituations.InSpaceLow:
					return "in space near";
				case ExperimentSituations.SrfLanded:
					return "landed at";
				case ExperimentSituations.SrfSplashed:
					return "splashed down at";
				default:
					return situation.ToString();
			}
		}
 public static float getScienceMultiplier(ExperimentSituations situation, CelestialBody body)
 {
     CelestialBodyScienceParams pars = body.scienceValues;
     switch (situation)
     {
         case ExperimentSituations.SrfLanded:
           return pars.LandedDataValue;
         case ExperimentSituations.SrfSplashed:
           return pars.SplashedDataValue;
         case ExperimentSituations.FlyingLow:
           return pars.FlyingLowDataValue;
         case ExperimentSituations.FlyingHigh:
           return pars.FlyingHighDataValue;
         case ExperimentSituations.InSpaceLow:
           return pars.InSpaceLowDataValue;
         case ExperimentSituations.InSpaceHigh:
           return pars.InSpaceHighDataValue;
     }
     return 1;
 }
Пример #37
0
 public static double ScienceDataValue(CelestialBody body, ExperimentSituations situation)
 {
     switch (situation)
     {
         case ExperimentSituations.SrfLanded:
             return body.scienceValues.LandedDataValue;
         case ExperimentSituations.SrfSplashed:
             return body.scienceValues.SplashedDataValue;
         case ExperimentSituations.FlyingLow:
             return body.scienceValues.FlyingLowDataValue;
         case ExperimentSituations.FlyingHigh:
             return body.scienceValues.FlyingHighDataValue;
         case ExperimentSituations.InSpaceLow:
             return body.scienceValues.InSpaceLowDataValue;
         case ExperimentSituations.InSpaceHigh:
             return body.scienceValues.InSpaceHighDataValue;
         default:
             throw new ArgumentOutOfRangeException("situation");
     }
 }
        public static bool IsDifficult(CelestialBody body, string biome, ExperimentSituations situation)
        {
            if (body == null || !body.ocean || body.pqsController == null ||
                (situation != ExperimentSituations.SrfLanded && situation != ExperimentSituations.SrfSplashed))
            {
                return false;
            }

            if (Instance == null || !Instance.bodyInfo.ContainsKey(body))
            {
                return true;
            }

            // Handles KSC biomes
            if (!Instance.bodyInfo[body].ContainsKey(biome))
            {
                return situation == ExperimentSituations.SrfSplashed;
            }

            double landRatio = Instance.bodyInfo[body][biome].landRatio;
            return landRatio > 0.95 && situation == ExperimentSituations.SrfSplashed ||
                landRatio < 0.05 && situation == ExperimentSituations.SrfLanded;
        }
        public CollectScienceCustom(CelestialBody targetBody, string biome, ExperimentSituations? situation, BodyLocation? location,
            List<string> experiment, ScienceRecoveryMethod recoveryMethod, string title)
            : base(title)
        {
            lastUpdate = UnityEngine.Time.fixedTime + nextOffset;
            nextOffset += OFFSET_INCREMENT;
            nextOffset -= (int)nextOffset;

            this.targetBody = targetBody;
            this.biome = biome;
            this.situation = situation;
            this.location = location;
            this.experiment = experiment;
            this.recoveryMethod = recoveryMethod;

            disableOnStateChange = true;

            if (experiment.Count == 0)
            {
                experiment.Add("");
            }

            CreateDelegates();
        }
Пример #40
0
        /// <summary>
        /// Gets the science subject for the given values.
        /// </summary>
        /// <param name="experiment">The science experiment</param>
        /// <param name="situation">The experimental situation</param>
        /// <param name="body">The celestial body</param>
        /// <param name="biome">The biome</param>
        /// <returns>The ScienceSubject</returns>
        public static ScienceSubject ScienceSubject(ScienceExperiment experiment, ExperimentSituations situation, CelestialBody body, string biome)
        {
            ScienceSubject defaultIfNotResearched = new ScienceSubject(experiment, situation, body, biome);

            return ResearchAndDevelopment.GetSubjects().SingleOrDefault(researched => defaultIfNotResearched.id == researched.id) ?? defaultIfNotResearched;
        }
Пример #41
0
        private static bool ExperimentAvailable(ScienceExperiment exp, ExperimentSituations sit, CelestialBody body)
        {
            if (!ExperimentAvailable(exp, body))
            {
                return false;
            }

            if (!exp.IsAvailableWhile(sit, body))
            {
                return false;
            }

            // Get the experiment rules
            ExperimentRules rules = GetExperimentRules(exp.id);

            // Check if surface samples have been unlocked
            if (rules.requireSurfaceSample)
            {
                if (ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.ResearchAndDevelopment) < 0.3f)
                {
                    return false;
                }
            }

            // Check for EVA unlock
            if (rules.requireEVA)
            {
                if (!body.isHomeWorld || (sit != ExperimentSituations.SrfLanded && sit != ExperimentSituations.SrfSplashed))
                {
                    bool evaUnlocked = GameVariables.Instance.UnlockedEVA(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.AstronautComplex));
                    if (!evaUnlocked)
                    {
                        return false;
                    }
                }
            }

            if (rules.disallowHomeSurface)
            {
                if (body.isHomeWorld && sit == ExperimentSituations.SrfLanded || sit == ExperimentSituations.SrfSplashed)
                {
                    return false;
                }
            }

            if (rules.disallowHomeFlying)
            {
                if (body.isHomeWorld && sit == ExperimentSituations.FlyingLow || sit == ExperimentSituations.FlyingHigh)
                {
                    return false;
                }
            }

            return true;
        }
Пример #42
0
        // Track our vessel state, it is used for thread control to know when to fire off new experiments.
        private bool StatesHaveChanged()
        {
            if (currentVessel() != stateVessel | currentSituation() != stateSituation | currentBody() != stateBody | currentBiome() != stateBiome)
            {
                stateVessel = currentVessel();
                stateBody = currentBody();
                stateSituation = currentSituation();
                stateBiome = currentBiome();
                stopwatch.Reset();
                stopwatch.Start();
            }

            if (stopwatch.ElapsedMilliseconds > 100) // trottling detection to kill transient states.
            {
                stopwatch.Reset();
            #if DEBUG
                Debug.Log("[For Science] Vessel in new experiment state.");
            #endif
                return true;
            }
            else return false;
        }
        protected override void OnLoad(ConfigNode node)
        {
            int sitID;
            string[] anomalyString = node.GetValue("Target_Anomaly").Split('|');
            if (int.TryParse(anomalyString[0], out sitID))
                situation = (ExperimentSituations)sitID;
            else
            {
                DMUtils.Logging("Failed To Load Anomaly Contract Situation Value; Parameter Set To Complete");
                this.SetComplete();
            }
            if (!bool.TryParse(anomalyString[1], out collected))
            {
                DMUtils.Logging("Failed To Load Anomaly Contract Collected State; Parameter Set To Complete");
                this.SetComplete();
            }
            name = anomalyString[2];
            DMUtils.availableScience["All"].TryGetValue(name, out scienceContainer);
            if (scienceContainer == null)
            {
                DMUtils.Logging("Failed To Load Anomaly Contract Science Container Variables; Parameter Set To Complete");
                this.SetComplete();
            }
            else
                partName = scienceContainer.SciPart;

            root = (DMAnomalyContract)this.Root;
        }
Пример #44
0
 internal static bool biomeRelevant(ExperimentSituations s, int i)
 {
     if ((i & (int)s) == 0)
         return false;
     else
         return true;
 }
 public extern ScienceSubject(ScienceExperiment exp, ExperimentSituations sit, string sourceUid, string sourceTitle, CelestialBody body, string biome = "");
 protected virtual string situationCleanup(ExperimentSituations expSit, string b)
 {
     if (vessel.landedAt != "")
         return " from " + b;
     if (b == "")
     {
         switch (expSit)
         {
             case ExperimentSituations.SrfLanded:
                 return " from  " + vessel.mainBody.theName + "'s surface";
             case ExperimentSituations.SrfSplashed:
                 return " from " + vessel.mainBody.theName + "'s oceans";
             case ExperimentSituations.FlyingLow:
                 return " while flying at " + vessel.mainBody.theName;
             case ExperimentSituations.FlyingHigh:
                 return " from " + vessel.mainBody.theName + "'s upper atmosphere";
             case ExperimentSituations.InSpaceLow:
                 return " while in space near " + vessel.mainBody.theName;
             default:
                 return " while in space high over " + vessel.mainBody.theName;
         }
     }
     else
     {
         switch (expSit)
         {
             case ExperimentSituations.SrfLanded:
                 return " from " + vessel.mainBody.theName + "'s " + b;
             case ExperimentSituations.SrfSplashed:
                 return " from " + vessel.mainBody.theName + "'s " + b;
             case ExperimentSituations.FlyingLow:
                 return " while flying over " + vessel.mainBody.theName + "'s " + b;
             case ExperimentSituations.FlyingHigh:
                 return " from the upper atmosphere over " + vessel.mainBody.theName + "'s " + b;
             case ExperimentSituations.InSpaceLow:
                 return " from space just above " + vessel.mainBody.theName + "'s " + b;
             default:
                 return " while in space high over " + vessel.mainBody.theName + "'s " + b;
         }
     }
 }
 /// <summary>
 /// Checks if the biome is relevent to the experiment given the biomeMask specified in the ScienceDefs file.
 /// </summary>
 /// <param name="situation">Current Experiment Situation</param>
 /// <returns></returns>
 public extern bool BiomeIsRelevantWhile(ExperimentSituations situation);
 protected virtual string getBiome(ExperimentSituations s)
 {
     if ((bioMask & (int)s) == 0)
         return "";
     else
     {
         switch (vessel.landedAt)
         {
             case "":
                 if (vessel.mainBody.BiomeMap != null)
                     return vessel.mainBody.BiomeMap.GetAtt(vessel.latitude * Mathf.Deg2Rad, vessel.longitude * Mathf.Deg2Rad).name;
                 else
                     return "";
             default:
                 return Vessel.GetLandedAtString(vessel.landedAt);
         }
     }
 }
 protected void runExperiment(ExperimentSituations sit)
 {
     ScienceData data = makeScience(scienceBoost, sit);
     if (data == null)
         Debug.LogError("[DM] Something Went Wrong Here; Null Science Data Returned; Please Report This On The KSP Forum With Output.log Data");
     else
     {
         GameEvents.OnExperimentDeployed.Fire(data);
         if (experimentLimit <= 1)
         {
             dataIndex = 0;
             storedScienceReports.Add(data);
             Deployed = true;
             ReviewData();
         }
         else
         {
             scienceReports.Add(data);
             if (experimentNumber >= experimentLimit - 1)
                 Deployed = true;
             initialResultsPage();
         }
         if (keepDeployedMode == 1) retractEvent();
     }
 }
 internal float fixSubjectValue(ExperimentSituations s, float f, float boost, CelestialBody body)
 {
     float subV = f;
     if (s == ExperimentSituations.SrfLanded) subV = body.scienceValues.LandedDataValue;
     else if (s == ExperimentSituations.SrfSplashed) subV = body.scienceValues.SplashedDataValue;
     else if (s == ExperimentSituations.FlyingLow) subV = body.scienceValues.FlyingLowDataValue;
     else if (s == ExperimentSituations.FlyingHigh) subV = body.scienceValues.FlyingHighDataValue;
     else if (s == ExperimentSituations.InSpaceLow) subV = body.scienceValues.InSpaceLowDataValue;
     else if (s == ExperimentSituations.InSpaceHigh) subV = body.scienceValues.InSpaceHighDataValue;
     return subV * boost;
 }
 private void boardingVessel(GameEvents.FromToAction<Part, Part> parts)
 {
     Utilities.debug(modName, Utilities.LogMode.Debug, "boardingVessel");
       nextUpdate = Planetarium.GetUniversalTime() + 1;
       currentVessel = parts.to.vessel;
       resetLists();
       currentSituation = ScienceUtil.GetExperimentSituation(currentVessel);
       currentBody = currentVessel.mainBody;
       updateExperimentList();
 }
 private void updateSituation(GameEvents.HostedFromToAction<Vessel, Vessel.Situations> data)
 {
     Utilities.debug(modName, Utilities.LogMode.Debug, "updateSituation");
       resetLists();
       currentSituation = ScienceUtil.GetExperimentSituation(currentVessel);
       updateExperimentList();
 }
Пример #53
0
        internal static List<string> fetchBiome(CelestialBody b, ScienceExperiment exp, ExperimentSituations sit)
        {
            List<string> s = new List<string>();
            if (b.BiomeMap == null)
            {
                s.Add("");
                return s;
            }
            else
            {
                for (int j = 0; j < b.BiomeMap.Attributes.Length; j++)
                {
                    string bName = b.BiomeMap.Attributes[j].name;
                    string subId = string.Format("{0}@{1}{2}{3}", exp.id, b.name, sit, bName.Replace(" ", ""));

                    if (ResearchAndDevelopment.GetSubjects().Any(a => a.id == subId))
                    {
                        ScienceSubject subB = ResearchAndDevelopment.GetSubjectByID(subId);
                        if (subB.scientificValue > 0.5f)
                            s.Add(bName);
                    }
                    else
                        s.Add(bName);
                }
            }
            return s;
        }
 private string astCleanup(ExperimentSituations s, string b)
 {
     switch (s)
     {
         case ExperimentSituations.SrfLanded:
             return string.Format(" from the surface of a {0} asteroid", b);
         case ExperimentSituations.InSpaceLow:
             return string.Format(" while in space near a {0} asteroid", b);
         default:
             return "";
     }
 }
Пример #55
0
 internal static Vessel.Situations convertSit(ExperimentSituations s)
 {
     switch (s)
     {
         case ExperimentSituations.SrfLanded:
             return Vessel.Situations.LANDED;
         case ExperimentSituations.SrfSplashed:
             return Vessel.Situations.SPLASHED;
         case ExperimentSituations.FlyingLow:
             return Vessel.Situations.FLYING;
         case ExperimentSituations.FlyingHigh:
             return Vessel.Situations.SUB_ORBITAL;
         case ExperimentSituations.InSpaceLow:
             return Vessel.Situations.ORBITING;
         default:
             return Vessel.Situations.ESCAPING;
     }
 }
        private ScienceData makeScience(float boost, ExperimentSituations vesselSituation)
        {
            string biome = getBiome(vesselSituation);
            CelestialBody mainBody = vessel.mainBody;
            bool asteroids = false;
            DMAsteroidScience newAsteroid = null;

            //Check for asteroids and alter the biome and celestialbody values as necessary
            if (asteroidReports && (DMAsteroidScience.AsteroidGrappled || DMAsteroidScience.AsteroidNear))
            {
                newAsteroid = new DMAsteroidScience();
                asteroids = true;
                mainBody = newAsteroid.Body;
                biome = newAsteroid.AType + newAsteroid.ASeed.ToString();
            }

            ScienceData data = null;
            ScienceSubject sub = null;

            if (scienceExp == null)
            {
                Debug.LogError("[DM] Something Went Wrong Here; Null Experiment Returned; Please Report This On The KSP Forum With Output.log Data");
                return null;
            }

            sub = ResearchAndDevelopment.GetExperimentSubject(scienceExp, vesselSituation, mainBody, biome);
            if (sub == null)
            {
                Debug.LogError("[DM] Something Went Wrong Here; Null Subject Returned; Please Report This On The KSP Forum With Output.log Data");
                return null;
            }

            if (asteroids)
            {
                DMUtils.OnAsteroidScience.Fire(newAsteroid.AClass, experimentID);
                sub.title = scienceExp.experimentTitle + astCleanup(vesselSituation, newAsteroid.AType);
                registerDMScience(newAsteroid, sub);
                mainBody.bodyName = bodyNameFixed;
            }
            else
            {
                DMUtils.OnAnomalyScience.Fire(mainBody, experimentID, biome);
                sub.title = scienceExp.experimentTitle + situationCleanup(vesselSituation, biome);
                sub.subjectValue = fixSubjectValue(vesselSituation, sub.subjectValue, boost, mainBody);
                sub.scienceCap = scienceExp.scienceCap * sub.subjectValue;
            }

            data = new ScienceData(scienceExp.baseValue * sub.dataScale, xmitDataScalar, 1f, sub.id, sub.title, false, part.flightID);

            return data;
        }
 /// <summary>
 /// Determines if the experiment is available given the situationMask and requireAtmosphere values specified in the ScienceDefs file.
 /// </summary>
 /// <param name="situation">Current Experiment Situation</param>
 /// <param name="body">Current Celestial Body</param>
 /// <returns></returns>
 public extern bool IsAvailableWhile(ExperimentSituations situation, CelestialBody body);
Пример #58
0
        // Ethernet's Methods for ExperimentSituations (Above this point)
        // START Confirm Situation Method
        public bool ConfirmLocation(ExperimentSituations experimentlocation)
        {
            string currentSituation = "Placeholder";

            if (experimentlocation == ExperimentSituations.SrfLanded)
            {
                currentSituation = "SrfLanded";
                ScreenMessages.PostScreenMessage(String.Format("Current Situation :{0}", currentSituation), 3, ScreenMessageStyle.UPPER_CENTER);

                if (TargetSituation1 == currentSituation || TargetSituation2 == currentSituation || TargetSituation3 == currentSituation)
                {
                    return true;
                }

                if (TargetSituation1 != currentSituation && TargetSituation2 != currentSituation && TargetSituation3 != currentSituation)
                {
                    return false;
                }
            }

            if (experimentlocation == ExperimentSituations.SrfSplashed)
            {
                currentSituation = "SrfSplashed";
                ScreenMessages.PostScreenMessage(String.Format("Current Situation :{0}", currentSituation), 3, ScreenMessageStyle.UPPER_CENTER);

                if (TargetSituation1 == currentSituation || TargetSituation2 == currentSituation || TargetSituation3 == currentSituation)
                {
                    return true;
                }

                if (TargetSituation1 != currentSituation && TargetSituation2 != currentSituation && TargetSituation3 != currentSituation)
                {
                    return false;
                }
            }

            if (experimentlocation == ExperimentSituations.FlyingLow)
            {
                currentSituation = "FlyingLow";
                ScreenMessages.PostScreenMessage(String.Format("Current Situation :{0}", currentSituation), 3, ScreenMessageStyle.UPPER_CENTER);
                if (TargetSituation1 == currentSituation || TargetSituation2 == currentSituation || TargetSituation3 == currentSituation)
                {
                    return true;
                }

                if (TargetSituation1 != currentSituation && TargetSituation2 != currentSituation && TargetSituation3 != currentSituation)
                {
                    return false;
                }
            }

            if (experimentlocation == ExperimentSituations.FlyingHigh)
            {
                currentSituation = "FlyingHigh";
                ScreenMessages.PostScreenMessage(String.Format("Current Situation :{0}", currentSituation), 3, ScreenMessageStyle.UPPER_CENTER);
                if (TargetSituation1 == currentSituation || TargetSituation2 == currentSituation || TargetSituation3 == currentSituation)
                {
                    return true;
                }

                if (TargetSituation1 != currentSituation && TargetSituation2 != currentSituation && TargetSituation3 != currentSituation)
                {
                    return false;
                }
            }

            if (experimentlocation == ExperimentSituations.InSpaceLow)
            {
                currentSituation = "InSpaceLow";
                ScreenMessages.PostScreenMessage(String.Format("Current Situation :{0}", currentSituation), 3, ScreenMessageStyle.UPPER_CENTER);
                if (TargetSituation1 == currentSituation || TargetSituation2 == currentSituation || TargetSituation3 == currentSituation)
                {
                    return true;
                }

                if (TargetSituation1 != currentSituation && TargetSituation2 != currentSituation && TargetSituation3 != currentSituation)
                {
                    return false;
                }
            }

            if (experimentlocation == ExperimentSituations.InSpaceHigh)
            {
                currentSituation = "InSpaceHigh";
                ScreenMessages.PostScreenMessage(String.Format("Current Situation :{0}", currentSituation), 3, ScreenMessageStyle.UPPER_CENTER);

                if (TargetSituation1 == currentSituation || TargetSituation2 == currentSituation || TargetSituation3 == currentSituation)
                {
                    return true;
                }

                if (TargetSituation1 != currentSituation && TargetSituation2 != currentSituation && TargetSituation3 != currentSituation)
                {
                    return false;
                }
            }

            return false;
        }
Пример #59
0
        // Track our vessel state, it is used for thread control to know when to fire off new experiments since there is no event for this
        bool StatesHaveChanged()
        {
            if (currentVessel() != stateVessel | currentSituation() != stateSituation | currentBody() != stateBody | currentBiome() != stateBiome)
            {
                stateVessel = currentVessel();
                stateBody = currentBody();
                stateSituation = currentSituation();
                stateBiome = currentBiome();
                stopwatch.Reset();
                stopwatch.Start();
                return true;
            }
            else return false;

            //if (stopwatch.ElapsedMilliseconds > 100) // throttling detection to kill transient states.
            //{
            //    stopwatch.Reset();

            //    Debug.Log("[ForScience!] Vessel in new experiment state.");

            //    return true;
            //}
            //else return false;
        }
Пример #60
0
 static string ParseSituation(ExperimentSituations situation)
 {
     var rgx = new Regex("(?<!^)([A-Z])");
     return rgx.Replace(situation.ToString(), " $1");
 }