Esempio n. 1
0
        //Used for initial orbital and surface survey parameter
        internal static DMCollectScience fetchSurveyScience(Contract.ContractPrestige c, List <CelestialBody> cR, List <CelestialBody> cUR, DMScienceContainer DMScience)
        {
            CelestialBody        body;
            ExperimentSituations targetSituation;
            ScienceSubject       sub;
            AvailablePart        aPart;
            string name;
            string biome = "";

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

            //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);
                }
            }

            body = DMUtils.nextTargetBody(c, cR, cUR);
            if (body == null)
            {
                return(null);
            }

            //Make sure our experiment is OK
            if (DMScience.Exp == null)
            {
                return(null);
            }

            if (!body.atmosphere && DMScience.Exp.requireAtmosphere)
            {
                return(null);
            }
            if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh && ((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow)
            {
                if (rand.Next(0, 2) == 0)
                {
                    targetSituation = ExperimentSituations.InSpaceHigh;
                }
                else
                {
                    targetSituation = ExperimentSituations.InSpaceLow;
                }
            }
            else if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh)
            {
                targetSituation = ExperimentSituations.InSpaceHigh;
            }
            else
            {
                targetSituation = ExperimentSituations.InSpaceLow;
            }

            if (DMUtils.biomeRelevant(targetSituation, DMScience.BioMask) && targetSituation != ExperimentSituations.SrfSplashed)
            {
                List <string> bList = DMUtils.fetchBiome(body, DMScience.Exp, targetSituation);
                if (bList.Count == 0)
                {
                    return(null);
                }
                else
                {
                    biome = bList[rand.Next(0, bList.Count)];
                }
            }

            //Make sure that our chosen science subject has science remaining to be gathered
            string subId = string.Format("{0}@{1}{2}{3}", DMScience.Exp.id, body.name, targetSituation, biome.Replace(" ", ""));

            if (ResearchAndDevelopment.GetSubjects().Any(s => s.id == subId))
            {
                sub = ResearchAndDevelopment.GetSubjectByID(subId);
                if (sub.scientificValue < 0.5f)
                {
                    return(null);
                }
            }

            return(new DMCollectScience(body, targetSituation, "", name, 0));
        }
Esempio n. 2
0
        //Used for initial orbital and surface survey parameter
        internal static DMCollectScience fetchSurveyScience(Contract.ContractPrestige c, List <CelestialBody> cR, List <CelestialBody> cUR, DMScienceContainer DMScience, int sT)
        {
            CelestialBody        body;
            ExperimentSituations targetSituation;
            ScienceSubject       sub;
            AvailablePart        aPart;
            string name;
            string biome      = "";
            int    surveyType = sT;

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

            //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);
            }

            body = DMUtils.nextTargetBody(c, cR, cUR);
            DMUtils.DebugLog("Body: {0} Selected", body.name);
            if (body == null)
            {
                return(null);
            }

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

            if (surveyType == 0)
            {
                if (!body.atmosphere && DMScience.exp.requireAtmosphere)
                {
                    return(null);
                }
                if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh)
                {
                    if (rand.Next(0, 2) == 0)
                    {
                        targetSituation = ExperimentSituations.InSpaceHigh;
                    }
                    else
                    {
                        targetSituation = ExperimentSituations.InSpaceLow;
                    }
                }
                else
                {
                    targetSituation = ExperimentSituations.InSpaceLow;
                }
            }
            else if (surveyType == 1)
            {
                if (body.pqsController == null)
                {
                    return(null);
                }
                if (!body.atmosphere && DMScience.exp.requireAtmosphere)
                {
                    return(null);
                }
                if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded)
                {
                    if (DMScience.exp.id != "dmbiodrillscan")
                    {
                        targetSituation = ExperimentSituations.SrfLanded;
                    }
                    else if (body.atmosphere)
                    {
                        targetSituation = ExperimentSituations.SrfLanded;
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else if (surveyType == 2)
            {
                if (!body.atmosphere)
                {
                    return(null);
                }
                if (rand.Next(0, 2) == 0)
                {
                    targetSituation = ExperimentSituations.FlyingHigh;
                }
                else
                {
                    targetSituation = ExperimentSituations.FlyingLow;
                }
            }
            else
            {
                return(null);
            }

            DMUtils.DebugLog("Experimental Situation: {0} Selected", targetSituation.ToString());

            if (DMUtils.biomeRelevant(targetSituation, DMScience.bioMask) && targetSituation != ExperimentSituations.SrfSplashed)
            {
                DMUtils.DebugLog("Checking For Biome Usage");
                List <string> bList = DMUtils.fetchBiome(body, DMScience.exp, targetSituation);
                if (bList.Count == 0)
                {
                    DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here");
                    return(null);
                }
                else
                {
                    biome = bList[rand.Next(0, bList.Count)];
                    DMUtils.DebugLog("Acceptable Biome Found: {0}", biome);
                }
            }

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

            if (surveyType == 0)
            {
                return(new DMCollectScience(body, targetSituation, "", name, 0));
            }
            else if (surveyType == 1)
            {
                return(new DMCollectScience(body, targetSituation, biome, name, 0));
            }
            else if (surveyType == 2)
            {
                return(new DMCollectScience(body, targetSituation, biome, name, 1));
            }
            else
            {
                return(null);
            }
        }
        protected override bool Generate()
        {
            int total = ContractSystem.Instance.GetCurrentContracts <DMMagneticSurveyContract>().Count();

            if (total >= DMUtils.maxMagnetic)
            {
                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, true), 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, 21) / 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(body, time);
            DMOrbitalParameters  eccentricParam = new DMOrbitalParameters(body, eccen, 0);
            DMOrbitalParameters  inclinedParam  = new DMOrbitalParameters(body, inclination, 1);

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

            longParam.SetFunds(50000f * DMUtils.reward * ((float)rand.Next(85, 116) / 100f), body);
            longParam.SetReputation(50f * DMUtils.reward * ((float)rand.Next(85, 116) / 100f), body);
            longParam.SetScience(60f * DMUtils.science * ((float)rand.Next(85, 116) / 100f), body);

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

            foreach (DMCollectScience DMCS in magParams)
            {
                if (DMCS == null)
                {
                    return(false);
                }
                else
                {
                    this.AddParameter(DMCS, "collectDMScience");
                    DMUtils.DebugLog("Added Mag Survey Param");
                    DMCS.SetFunds(8000f * DMUtils.reward * ((float)rand.Next(85, 116) / 100f), body);
                    DMCS.SetReputation(25f * DMUtils.reward * ((float)rand.Next(85, 116) / 100f), body);
                    DMCS.SetScience(25f * DMUtils.science * DMUtils.fixSubjectVal(DMCS.Situation, 1f, body), null);
                }
            }

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

            float primaryModifier = ((float)rand.Next(80, 121) / 100f);

            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(50f * DMUtils.reward * primaryModifier, 10f * DMUtils.penalty * primaryModifier, body);
            base.SetFunds(50000 * DMUtils.forward * primaryModifier, 55000 * DMUtils.reward * primaryModifier, 20000 * DMUtils.penalty * primaryModifier, body);
            return(true);
        }