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);
        }
Пример #2
0
        protected override bool Generate()
        {
            DMAsteroidSurveyContract[] astContracts = ContractSystem.Instance.GetCurrentContracts <DMAsteroidSurveyContract>();
            int offers    = 0;
            int active    = 0;
            int maxOffers = DMContractDefs.DMAsteroid.maxOffers;
            int maxActive = DMContractDefs.DMAsteroid.maxActive;

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

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

            switch (prestige)
            {
            case ContractPrestige.Trivial:
                return(false);

            case ContractPrestige.Significant:
                size = rand.Next(0, 3);
                break;

            case ContractPrestige.Exceptional:
                size = rand.Next(2, 4);
                break;
            }

            hash = DMUtils.sizeHash(size);

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

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

            //Generates new asteroid science experiments
            for (i = 0; i < 6; i++)
            {
                if (sciList.Count > 0)
                {
                    DMScience    = sciList[rand.Next(0, sciList.Count)];
                    newParams[i] = DMAsteroidGenerator.fetchAsteroidParameter(DMScience);
                    sciList.Remove(DMScience);
                }
                else
                {
                    newParams[i] = null;
                }
            }

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

            this.AddParameter(DMcp);

            int limit       = 0;
            int maxRequests = 1;

            switch (prestige)
            {
            case ContractPrestige.Trivial:
                maxRequests = DMContractDefs.DMAsteroid.trivialScienceRequests;
                break;

            case ContractPrestige.Significant:
                maxRequests = DMContractDefs.DMAsteroid.significantScienceRequests;
                break;

            case ContractPrestige.Exceptional:
                maxRequests = DMContractDefs.DMAsteroid.exceptionalScienceRequests;
                break;
            }

            //Add in all acceptable paramaters to the contract
            foreach (DMAsteroidParameter DMAP in newParams)
            {
                if (limit > maxRequests)
                {
                    break;
                }
                if (DMAP != null)
                {
                    if (DMAP.Container == null)
                    {
                        continue;
                    }

                    DMcp.addToSubParams(DMAP);
                    float modifier = ((float)rand.Next(85, 116) / 100f);
                    DMAP.SetScience(DMAP.Container.Exp.baseValue * DMContractDefs.DMAsteroid.Science.ParamReward * (DMUtils.asteroidSubjectVal(size) / 2), null);
                    DMAP.SetFunds(DMContractDefs.DMAsteroid.Funds.ParamReward * modifier, DMContractDefs.DMAsteroid.Funds.ParamFailure * DMUtils.asteroidSubjectVal(size) * modifier, null);
                    DMAP.SetReputation(DMContractDefs.DMAsteroid.Reputation.ParamReward * modifier, DMContractDefs.DMAsteroid.Reputation.ParamFailure * modifier, null);
                    limit++;
                }
            }

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

            float primaryModifier = ((float)rand.Next(85, 116) / 100f);

            float Mod = primaryModifier * DMcp.ParameterCount;

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

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

            base.SetExpiry(DMContractDefs.DMAsteroid.Expire.MinimumExpireDays, DMContractDefs.DMAsteroid.Expire.MaximumExpireDays);
            base.SetDeadlineYears(DMContractDefs.DMAsteroid.Expire.DeadlineYears * primaryModifier, null);
            base.SetReputation(DMContractDefs.DMAsteroid.Reputation.BaseReward * primaryModifier, DMContractDefs.DMAsteroid.Reputation.BaseFailure * primaryModifier, null);
            base.SetFunds(DMContractDefs.DMAsteroid.Funds.BaseAdvance * Mod, DMContractDefs.DMAsteroid.Funds.BaseReward * Mod, DMContractDefs.DMAsteroid.Funds.BaseFailure * Mod, null);
            base.SetScience(DMContractDefs.DMAsteroid.Science.BaseReward * primaryModifier, null);
            return(true);
        }
        protected override bool Generate()
        {
            DMAnomalyContract[] anomContracts = ContractSystem.Instance.GetCurrentContracts <DMAnomalyContract>();
            int offers    = 0;
            int active    = 0;
            int maxOffers = DMUtils.maxAnomalyOffered;
            int maxActive = DMUtils.maxAnomalyActive;

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

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

            //Make sure that the anomaly scanner is available
            AvailablePart aPart = PartLoader.getPartInfoByName("dmAnomScanner");

            if (aPart == null)
            {
                return(false);
            }
            if (!ResearchAndDevelopment.PartModelPurchased(aPart))
            {
                return(false);
            }

            //Kerbin or Mun Anomalies for trivial contracts
            if (this.Prestige == ContractPrestige.Trivial)
            {
                if (rand.Next(0, 3) == 0)
                {
                    body = FlightGlobals.Bodies[1];
                }
                else
                {
                    body = FlightGlobals.Bodies[2];
                }
            }
            //Minmus and Duna are next
            else if (this.Prestige == ContractPrestige.Significant)
            {
                if (!ProgressTracking.Instance.NodeComplete(new string[] { "Kerbin", "Escape" }))
                {
                    return(false);
                }
                if (rand.Next(0, 2) == 0)
                {
                    body = FlightGlobals.Bodies[3];
                }
                else
                {
                    body = FlightGlobals.Bodies[6];
                }
            }
            //Vall, Tylo, and Bop are last; only if we've been to Jool first
            else if (this.Prestige == ContractPrestige.Exceptional)
            {
                if (!ProgressTracking.Instance.NodeComplete(new string[] { "Jool", "Flyby" }))
                {
                    return(false);
                }
                int i = rand.Next(0, 3);
                if (i == 0)
                {
                    body = FlightGlobals.Bodies[10];
                }
                else if (i == 1)
                {
                    body = FlightGlobals.Bodies[11];
                }
                else if (i == 2)
                {
                    body = FlightGlobals.Bodies[12];
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            PQSCity[] Cities = UnityEngine.Object.FindObjectsOfType(typeof(PQSCity)) as PQSCity[];
            foreach (PQSCity city in Cities)
            {
                if (city.transform.parent.name == body.name)
                {
                    cities.Add(city);
                }
            }

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

            //Select random anomaly
            targetAnomaly = new DMAnomalyObject(cities[rand.Next(0, cities.Count)]);
            hash          = targetAnomaly.Name;
            lon           = targetAnomaly.Lon;
            lat           = targetAnomaly.Lat;
            cardNS        = NSDirection(lat);
            cardEW        = EWDirection(lon);

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

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

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

            this.AddParameter(newParam, "AnomalyScience");

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

            newParam.SetFunds(12000f * DMUtils.reward * primaryLocationMod, body);
            newParam.SetScience(6f * DMUtils.science * DMUtils.fixSubjectVal(newParam.Situation, 1f, body), null);

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

            this.AddParameter(DMcp);

            foreach (DMAnomalyParameter aP in anomParams)
            {
                if (aP != null)
                {
                    DMcp.addToSubParams(aP, "CollectAnomalyScience");
                    float locationMod = GameVariables.Instance.ScoreSituation(DMUtils.convertSit(aP.Situation), body) * ((float)rand.Next(85, 116) / 100f);
                    aP.SetFunds(7000f * DMUtils.reward * locationMod, body);
                    aP.SetScience(aP.Container.Exp.baseValue * 0.25f * DMUtils.science * DMUtils.fixSubjectVal(aP.Situation, 1f, body), null);
                }
            }

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

            this.agent = AgentList.Instance.GetAgent("DMagic");
            base.SetExpiry(10 * DMUtils.deadline, 20 * DMUtils.deadline);
            base.SetDeadlineYears(1.5f * ((float)rand.Next(80, 121)) / 100f * DMUtils.deadline, body);
            base.SetReputation(8f * DMUtils.reward * primaryLocationMod, 9f * DMUtils.penalty * primaryLocationMod, null);
            base.SetFunds(20000f * DMUtils.forward * primaryLocationMod, 24000f * DMUtils.reward * primaryLocationMod, 20000f * DMUtils.penalty * primaryLocationMod, body);
            return(true);
        }
Пример #4
0
        protected override bool Generate()
        {
            DMAnomalyContract[] anomContracts = ContractSystem.Instance.GetCurrentContracts <DMAnomalyContract>();
            int offers    = 0;
            int active    = 0;
            int maxOffers = DMContractDefs.DMAnomaly.maxOffers;
            int maxActive = DMContractDefs.DMAnomaly.maxActive;

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

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

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

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

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

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

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

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

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

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

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

                if (stor == null)
                {
                    continue;
                }

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

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

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

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

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

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

            body = targetAnomaly.Body.bodyName;

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

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

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

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

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

            this.AddParameter(newParam);

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

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

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

            this.AddParameter(DMcp);

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

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

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

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

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

            base.SetExpiry(DMContractDefs.DMAnomaly.Expire.MinimumExpireDays, DMContractDefs.DMAnomaly.Expire.MaximumExpireDays);
            base.SetDeadlineYears(DMContractDefs.DMAnomaly.Expire.DeadlineYears * ((float)rand.Next(80, 121)) / 100f, targetAnomaly.Body);
            base.SetReputation(DMContractDefs.DMAnomaly.Reputation.BaseReward * primaryLocationMod, DMContractDefs.DMAnomaly.Reputation.BaseFailure * primaryLocationMod, null);
            base.SetScience(DMContractDefs.DMAnomaly.Science.BaseReward, null);
            base.SetFunds(DMContractDefs.DMAnomaly.Funds.BaseAdvance * primaryLocationMod, DMContractDefs.DMAnomaly.Funds.BaseReward * primaryLocationMod, DMContractDefs.DMAnomaly.Funds.BaseFailure * primaryLocationMod, targetAnomaly.Body);
            return(true);
        }
Пример #5
0
        protected override bool Generate()
        {
            DMReconContract[] reconContracts = ContractSystem.Instance.GetCurrentContracts <DMReconContract>();
            int offers    = 0;
            int active    = 0;
            int maxOffers = DMContractDefs.DMRecon.maxOffers;
            int maxActive = DMContractDefs.DMRecon.maxActive;

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

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

            List <CelestialBody> customReachedBodies = new List <CelestialBody>();

            switch (prestige)
            {
            case ContractPrestige.Trivial:
                Func <CelestialBody, bool> cb = delegate(CelestialBody b)
                {
                    if (b == Planetarium.fetch.Sun)
                    {
                        return(false);
                    }

                    if (b.pqsController == null)
                    {
                        return(false);
                    }

                    return(true);
                };
                customReachedBodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.ORBIT, true, cb));
                customReachedBodies.AddRange(ProgressUtilities.GetNextUnreached(2, cb));
                var activeBodies = ContractSystem.Instance.GetCurrentActiveContracts <DMReconContract>().Select(r => r.body).ToList();
                customReachedBodies.RemoveAll(a => activeBodies.Contains(a));
                var completedBodies = ContractSystem.Instance.GetCompletedContracts <DMReconContract>().Select(r => r.body).ToList();
                customReachedBodies.RemoveAll(a => completedBodies.Contains(a));
                break;

            case ContractPrestige.Significant:
                customReachedBodies = ContractSystem.Instance.GetCompletedContracts <DMReconContract>().Where(r => r.prestige == ContractPrestige.Trivial).Select(r => r.body).ToList();
                var activeSigBodies = ContractSystem.Instance.GetCurrentActiveContracts <DMReconContract>().Where(r => r.prestige == ContractPrestige.Significant).Select(r => r.body).ToList();
                customReachedBodies.RemoveAll(a => activeSigBodies.Contains(a));
                var completedSigBodies = ContractSystem.Instance.GetCompletedContracts <DMReconContract>().Where(r => r.prestige == ContractPrestige.Significant).Select(r => r.body).ToList();
                customReachedBodies.RemoveAll(a => completedSigBodies.Contains(a));
                break;

            case ContractPrestige.Exceptional:
                customReachedBodies = ContractSystem.Instance.GetCompletedContracts <DMReconContract>().Where(r => r.prestige == ContractPrestige.Significant).Select(r => r.body).ToList();
                var activeExcBodies = ContractSystem.Instance.GetCurrentActiveContracts <DMReconContract>().Where(r => r.prestige == ContractPrestige.Exceptional).Select(r => r.body).ToList();
                customReachedBodies.RemoveAll(a => activeExcBodies.Contains(a));
                var completedExcBodies = ContractSystem.Instance.GetCompletedContracts <DMReconContract>().Where(r => r.prestige == ContractPrestige.Exceptional).Select(r => r.body).ToList();
                customReachedBodies.RemoveAll(a => completedExcBodies.Contains(a));
                break;
            }

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

            body = customReachedBodies[rand.Next(0, customReachedBodies.Count)];

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

            double time = 0;

            OrbitType orbitType = OrbitType.POLAR;

            Dictionary <int, List <string> > parts = new Dictionary <int, List <string> >();
            Orbit o = new Orbit();

            double incMod  = (rand.NextDouble() * 10) - 5;
            double timeMod = 1080000;

            if (!DMUtils.availableScience.ContainsKey("All"))
            {
                return(false);
            }

            DMScienceContainer container = null;

            switch (prestige)
            {
            case ContractPrestige.Trivial:
                if (!DMUtils.partAvailable(DMContractDefs.DMRecon.reconTrivialParts))
                {
                    return(false);
                }

                parts.Add(0, DMContractDefs.DMRecon.reconTrivialParts);

                if (!DMUtils.availableScience["All"].ContainsKey(DMContractDefs.DMRecon.trivialExperimentTitle))
                {
                    return(false);
                }

                container = DMUtils.availableScience["All"][DMContractDefs.DMRecon.trivialExperimentTitle];

                o = CelestialUtilities.GenerateOrbit(orbitType, this.MissionSeed, body, 0.15, ContractDefs.Satellite.TrivialInclinationDifficulty);

                double st = o.semiMajorAxis - o.referenceBody.Radius;

                double mt = o.referenceBody.scienceValues.spaceAltitudeThreshold * 5 * .95;

                if (st > mt)
                {
                    o.semiMajorAxis = (mt * Math.Max(0.4, rand.NextDouble())) + o.referenceBody.Radius;
                }

                timeMod = DMContractDefs.DMRecon.trivialTimeModifier * 6 * 3600;
                break;

            case ContractPrestige.Significant:
                if (!DMUtils.partAvailable(DMContractDefs.DMRecon.reconSignificantParts))
                {
                    return(false);
                }

                parts.Add(0, DMContractDefs.DMRecon.reconSignificantParts);

                if (!DMUtils.availableScience["All"].ContainsKey(DMContractDefs.DMRecon.significantExperimentTitle))
                {
                    return(false);
                }

                container = DMUtils.availableScience["All"][DMContractDefs.DMRecon.significantExperimentTitle];

                if (SystemUtilities.CoinFlip(rand))
                {
                    if (CelestialUtilities.CanBodyBeKolniya(body))
                    {
                        orbitType = OrbitType.KOLNIYA;
                    }
                    else if (CelestialUtilities.CanBodyBeTundra(body))
                    {
                        orbitType = OrbitType.TUNDRA;
                    }
                    else
                    {
                        orbitType = OrbitType.POLAR;
                    }
                }
                else
                {
                    if (CelestialUtilities.CanBodyBeTundra(body))
                    {
                        orbitType = OrbitType.TUNDRA;
                    }
                    else if (CelestialUtilities.CanBodyBeKolniya(body))
                    {
                        orbitType = OrbitType.KOLNIYA;
                    }
                    else
                    {
                        orbitType = OrbitType.POLAR;
                    }
                }
                o       = CelestialUtilities.GenerateOrbit(orbitType, this.MissionSeed, body, 0.5, ContractDefs.Satellite.TrivialInclinationDifficulty);
                timeMod = DMContractDefs.DMRecon.significantTimeModifier * 6 * 3600;
                incMod  = 0;
                break;

            case ContractPrestige.Exceptional:
                if (!DMUtils.partAvailable(DMContractDefs.DMRecon.reconExceptionalParts))
                {
                    return(false);
                }

                parts.Add(0, DMContractDefs.DMRecon.reconExceptionalParts);

                if (!DMUtils.availableScience["All"].ContainsKey(DMContractDefs.DMRecon.exceptionalExperimentTitle))
                {
                    return(false);
                }

                container = DMUtils.availableScience["All"][DMContractDefs.DMRecon.exceptionalExperimentTitle];

                o = CelestialUtilities.GenerateOrbit(orbitType, this.MissionSeed, body, 0.15, ContractDefs.Satellite.TrivialInclinationDifficulty);

                double se = o.semiMajorAxis - o.referenceBody.Radius;

                double me = o.referenceBody.scienceValues.spaceAltitudeThreshold * 5 * .95;

                if (se > me)
                {
                    o.semiMajorAxis = (me * Math.Max(0.4, rand.NextDouble())) + o.referenceBody.Radius;
                }

                timeMod = DMContractDefs.DMRecon.exceptionalTimeModifier * 6 * 3600;
                break;
            }

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

            time           = timeMod * ((double)rand.Next(6, 17) / 10d);
            o.inclination += incMod;

            DMLongOrbitParameter     longOrbit   = new DMLongOrbitParameter(time);
            DMPartRequestParameter   partRequest = new DMPartRequestParameter(parts, DMContractDefs.DMRecon.useVesselWaypoints, body);
            DMSpecificOrbitParameter reconParam  = new DMSpecificOrbitParameter(orbitType, o.inclination, o.eccentricity, o.semiMajorAxis, o.LAN, o.argumentOfPeriapsis, o.meanAnomalyAtEpoch, o.epoch, body, ContractDefs.Satellite.SignificantDeviation, longOrbit);

            this.AddParameter(longOrbit);
            longOrbit.AddParameter(reconParam);
            longOrbit.AddParameter(partRequest);
            longOrbit.setPartRequest(partRequest);

            sciParams[0] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceLow, "SouthernHemisphere", container);
            sciParams[1] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceLow, "NorthernHemisphere", container);

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

            this.AddParameter(DMcp);

            foreach (DMCollectScience DMCS in sciParams)
            {
                if (DMCS == null)
                {
                    return(false);
                }
                else
                {
                    if (DMCS.Container == null)
                    {
                        continue;
                    }

                    float modifier = ((float)rand.Next(85, 116) / 100f);
                    DMcp.addToSubParams(DMCS);
                    DMCS.SetFunds(DMContractDefs.DMRecon.Funds.ParamReward * modifier, DMContractDefs.DMRecon.Funds.ParamFailure * modifier, body);
                    DMCS.SetScience(DMContractDefs.DMRecon.Science.ParamReward * DMUtils.fixSubjectVal(DMCS.Situation, 1f, body), null);
                    DMCS.SetReputation(DMContractDefs.DMRecon.Reputation.ParamReward * modifier, DMContractDefs.DMRecon.Reputation.ParamFailure * modifier, null);
                }
            }

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

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

            float Mod = primaryModifier * diffModifier;

            int t = rand.Next(0, 4);

            if (t == 0)
            {
                this.agent = AgentList.Instance.GetAgent("DMagic");
            }
            else
            {
                this.agent = AgentList.Instance.GetAgentRandom();
            }

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

            base.SetExpiry(DMContractDefs.DMRecon.Expire.MinimumExpireDays, DMContractDefs.DMRecon.Expire.MaximumExpireDays);
            base.SetDeadlineDays((float)(time / ((KSPUtil.DefaultDateTimeFormatter)KSPUtil.dateTimeFormatter).KerbinDay) * DMContractDefs.DMRecon.Expire.DeadlineModifier * (this.GetDestinationWeight(body) / 1.4f) * primaryModifier, null);
            base.SetReputation(DMContractDefs.DMRecon.Reputation.BaseReward * Mod, DMContractDefs.DMRecon.Reputation.BaseFailure * Mod, null);
            base.SetFunds(DMContractDefs.DMRecon.Funds.BaseAdvance * Mod, DMContractDefs.DMRecon.Funds.BaseReward * Mod, DMContractDefs.DMRecon.Funds.BaseFailure * Mod, body);
            base.SetScience(DMContractDefs.DMRecon.Science.BaseReward * Mod, body);
            return(true);
        }
Пример #6
0
        protected override bool Generate()
        {
            DMSurveyContract[] surveyContracts = ContractSystem.Instance.GetCurrentContracts <DMSurveyContract>();
            int offers    = 0;
            int active    = 0;
            int maxOffers = DMContractDefs.DMSurvey.maxOffers;
            int maxActive = DMContractDefs.DMSurvey.maxActive;

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

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

            if (!DMUtils.partAvailable(new List <string>(1)
            {
                "dmmagBoom"
            }))
            {
                return(false);
            }

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

            if (sciList.Count > 0)
            {
                DMScience = sciList[rand.Next(0, sciList.Count)];
                sciList.Remove(DMScience);
            }
            else
            {
                return(false);
            }

            //Generates the science experiment, returns null if experiment fails any check
            if ((newParams[0] = DMSurveyGenerator.fetchSurveyScience(this.Prestige, GetBodies_Reached(false, false), GetBodies_NextUnreached(4, null), DMScience)) == null)
            {
                return(false);
            }

            body = newParams[0].Body;

            //Add an orbital parameter to difficult contracts
            if (this.Prestige == ContractPrestige.Exceptional)
            {
                this.AddParameter(new EnterOrbit(body));
            }

            for (int j = 1; j < 8; j++)
            {
                if (sciList.Count > 0)
                {
                    DMScience    = sciList[rand.Next(0, sciList.Count)];
                    newParams[j] = DMSurveyGenerator.fetchSurveyScience(body, DMScience);
                    sciList.Remove(DMScience);
                }
                else
                {
                    newParams[j] = null;
                }
            }

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

            this.AddParameter(DMcp);

            int limit       = 1;
            int maxRequests = 1;

            switch (prestige)
            {
            case ContractPrestige.Trivial:
                maxRequests = DMContractDefs.DMSurvey.trivialScienceRequests;
                break;

            case ContractPrestige.Significant:
                maxRequests = DMContractDefs.DMSurvey.significantScienceRequests;
                break;

            case ContractPrestige.Exceptional:
                maxRequests = DMContractDefs.DMSurvey.exceptionalScienceRequests;
                break;
            }

            //Add in all acceptable paramaters to the contract
            foreach (DMCollectScience DMC in newParams)
            {
                if (limit > maxRequests)
                {
                    break;
                }
                if (DMC != null)
                {
                    if (DMC.Container == null)
                    {
                        continue;
                    }

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

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

            int a = rand.Next(0, 4);

            if (a == 0)
            {
                this.agent = AgentList.Instance.GetAgent("DMagic");
            }
            else if (a == 1)
            {
                this.agent = AgentList.Instance.GetAgent(newParams[0].Container.Agent);
            }
            else
            {
                this.agent = AgentList.Instance.GetAgentRandom();
            }

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

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

            float Mod = primaryLocationMod * DMcp.ParameterCount;

            base.SetExpiry(DMContractDefs.DMSurvey.Expire.MinimumExpireDays, DMContractDefs.DMSurvey.Expire.MaximumExpireDays);
            base.SetDeadlineYears(DMContractDefs.DMSurvey.Expire.DeadlineYears * ((float)rand.Next(80, 121)) / 100f, body);
            base.SetReputation(DMContractDefs.DMSurvey.Reputation.BaseReward * primaryLocationMod, DMContractDefs.DMSurvey.Reputation.BaseFailure * primaryLocationMod, null);
            base.SetFunds(DMContractDefs.DMSurvey.Funds.BaseAdvance * Mod, DMContractDefs.DMSurvey.Funds.BaseReward * Mod, DMContractDefs.DMSurvey.Funds.BaseFailure * Mod, body);
            base.SetScience(DMContractDefs.DMSurvey.Science.BaseReward * primaryLocationMod, null);
            return(true);
        }
Пример #7
0
        protected override bool Generate()
        {
            DMMagneticSurveyContract[] magContracts = ContractSystem.Instance.GetCurrentContracts <DMMagneticSurveyContract>();
            int offers    = 0;
            int active    = 0;
            int maxOffers = DMContractDefs.DMMagnetic.maxOffers;
            int maxActive = DMContractDefs.DMMagnetic.maxActive;

            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 parts are available
            if (!DMUtils.partAvailable(DMContractDefs.DMMagnetic.magParts) || !DMUtils.partAvailable(DMContractDefs.DMMagnetic.rpwsParts))
            {
                return(false);
            }

            List <CelestialBody>       bodies = new List <CelestialBody>();
            Func <CelestialBody, bool> cb     = null;

            switch (prestige)
            {
            case ContractPrestige.Trivial:
                cb = delegate(CelestialBody b)
                {
                    if (b == Planetarium.fetch.Sun)
                    {
                        return(false);
                    }

                    if (b.scienceValues.RecoveryValue > 4)
                    {
                        return(false);
                    }

                    return(true);
                };
                bodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.ORBIT, true, cb));
                break;

            case ContractPrestige.Significant:
                cb = delegate(CelestialBody b)
                {
                    if (b == Planetarium.fetch.Sun)
                    {
                        return(false);
                    }

                    if (b == Planetarium.fetch.Home)
                    {
                        return(false);
                    }

                    if (b.scienceValues.RecoveryValue > 8)
                    {
                        return(false);
                    }

                    return(true);
                };
                bodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.FLYBY, true, cb));
                bodies.AddRange(ProgressUtilities.GetNextUnreached(2, cb));
                break;

            case ContractPrestige.Exceptional:
                cb = delegate(CelestialBody b)
                {
                    if (b == Planetarium.fetch.Home)
                    {
                        return(false);
                    }

                    if (Planetarium.fetch.Home.orbitingBodies.Count > 0)
                    {
                        foreach (CelestialBody B in Planetarium.fetch.Home.orbitingBodies)
                        {
                            if (b == B)
                            {
                                return(false);
                            }
                        }
                    }

                    if (b.scienceValues.RecoveryValue < 4)
                    {
                        return(false);
                    }

                    return(true);
                };
                bodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.FLYBY, true, cb));
                bodies.AddRange(ProgressUtilities.GetNextUnreached(4, cb));
                break;
            }

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

            body = bodies[rand.Next(0, bodies.Count)];

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

            DMScienceContainer magContainer  = null;
            DMScienceContainer rpwsContainer = null;

            if (!DMUtils.availableScience.ContainsKey("All"))
            {
                return(false);
            }

            if (!DMUtils.availableScience["All"].ContainsKey(DMContractDefs.DMMagnetic.magnetometerExperimentTitle))
            {
                return(false);
            }

            magContainer = DMUtils.availableScience["All"][DMContractDefs.DMMagnetic.magnetometerExperimentTitle];

            if (!DMUtils.availableScience["All"].ContainsKey(DMContractDefs.DMMagnetic.rpwsExperimentTitle))
            {
                return(false);
            }

            rpwsContainer = DMUtils.availableScience["All"][DMContractDefs.DMMagnetic.rpwsExperimentTitle];

            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 eccMod  = 0.2;
            double incMod  = 20;
            double timeMod = 2160000;

            switch (prestige)
            {
            case ContractPrestige.Trivial:
                eccMod  = DMContractDefs.DMMagnetic.trivialEccentricityMultiplier;
                incMod  = DMContractDefs.DMMagnetic.trivialInclinationMultiplier;
                timeMod = DMContractDefs.DMMagnetic.trivialTimeModifier * 6 * 3600;
                break;

            case ContractPrestige.Significant:
                eccMod  = DMContractDefs.DMMagnetic.significantEccentricityMultiplier;
                incMod  = DMContractDefs.DMMagnetic.significantInclinationMultiplier;
                timeMod = DMContractDefs.DMMagnetic.significantTimeModifier * 6 * 3600;
                break;

            case ContractPrestige.Exceptional:
                eccMod  = DMContractDefs.DMMagnetic.exceptionalEccentricityMultiplier;
                incMod  = DMContractDefs.DMMagnetic.exceptionalInclinationMultiplier;
                timeMod = DMContractDefs.DMMagnetic.exceptionalTimeModifier * 6 * 3600;
                break;
            }

            double time  = timeMod * ((double)rand.Next(6, 17) / 10d);
            double eccen = eccMod * ((double)rand.Next(8, 13) / 10d);

            if (eccen > 0.7)
            {
                eccen = 0.7;
            }
            double inclination = incMod * ((double)rand.Next(7, 14) / 10d);

            if (inclination > 75)
            {
                inclination = 75;
            }

            DictionaryValueList <int, List <string> > parts = new DictionaryValueList <int, List <string> >();

            parts.Add(0, DMContractDefs.DMMagnetic.magParts);
            parts.Add(1, DMContractDefs.DMMagnetic.rpwsParts);

            DMLongOrbitParameter   longParam      = new DMLongOrbitParameter(time);
            DMOrbitalParameters    eccentricParam = new DMOrbitalParameters(eccen, 0, longParam);
            DMOrbitalParameters    inclinedParam  = new DMOrbitalParameters(inclination, 1, longParam);
            DMPartRequestParameter partRequest    = new DMPartRequestParameter(parts, DMContractDefs.DMMagnetic.useVesselWaypoints, body);

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

            longParam.setPartRequest(partRequest);

            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
                {
                    if (DMCS.Container == null)
                    {
                        continue;
                    }

                    float modifier = ((float)rand.Next(85, 116) / 100f);
                    DMcp.addToSubParams(DMCS);
                    DMCS.SetFunds(DMContractDefs.DMMagnetic.Funds.ParamReward * modifier, DMContractDefs.DMMagnetic.Funds.ParamFailure * modifier, body);
                    DMCS.SetScience(DMContractDefs.DMMagnetic.Science.ParamReward * DMUtils.fixSubjectVal(DMCS.Situation, 1f, body), null);
                    DMCS.SetReputation(DMContractDefs.DMMagnetic.Reputation.ParamReward * modifier, DMContractDefs.DMMagnetic.Reputation.ParamFailure * modifier, null);
                }
            }

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

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

            float Mod = primaryModifier * diffModifier;

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

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

            base.SetExpiry(DMContractDefs.DMMagnetic.Expire.MinimumExpireDays, DMContractDefs.DMMagnetic.Expire.MaximumExpireDays);
            base.SetDeadlineDays((float)(time / 3600) * DMContractDefs.DMMagnetic.Expire.DeadlineModifier * (this.GetDestinationWeight(body) / 1.8f) * primaryModifier, null);
            base.SetReputation(DMContractDefs.DMMagnetic.Reputation.BaseReward * Mod, DMContractDefs.DMMagnetic.Reputation.BaseFailure * Mod, null);
            base.SetFunds(DMContractDefs.DMMagnetic.Funds.BaseAdvance * Mod, DMContractDefs.DMMagnetic.Funds.BaseReward * Mod, DMContractDefs.DMMagnetic.Funds.BaseFailure * Mod, body);
            base.SetScience(DMContractDefs.DMMagnetic.Science.BaseReward * Mod, body);
            return(true);
        }
        protected override bool Generate()
        {
            DMAsteroidSurveyContract[] astContracts = ContractSystem.Instance.GetCurrentContracts <DMAsteroidSurveyContract>();
            int offers    = 0;
            int active    = 0;
            int maxOffers = DMUtils.maxAsteroidOffered;
            int maxActive = DMUtils.maxAsteroidActive;

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

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

            if (this.Prestige == ContractPrestige.Trivial)
            {
                return(false);
            }
            else if (this.Prestige == ContractPrestige.Significant)
            {
                size = rand.Next(0, 3);
            }
            else if (this.Prestige == ContractPrestige.Exceptional)
            {
                size = rand.Next(2, 4);
            }
            else
            {
                return(false);
            }
            hash = DMUtils.sizeHash(size);

            //Make sure that the grappling device is available
            AvailablePart aPart = PartLoader.getPartInfoByName("GrapplingDevice");

            if (aPart == null)
            {
                return(false);
            }
            if (!ResearchAndDevelopment.PartModelPurchased(aPart))
            {
                return(false);
            }

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

            //Generates new asteroid science experiments
            for (i = 0; i < 6; i++)
            {
                if (sciList.Count > 0)
                {
                    DMScience    = sciList[rand.Next(0, sciList.Count)];
                    newParams[i] = DMAsteroidGenerator.fetchAsteroidParameter(DMScience);
                    sciList.Remove(DMScience);
                }
                else
                {
                    newParams[i] = null;
                }
            }

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

            this.AddParameter(DMcp);

            int limit = 0;

            //Add in all acceptable paramaters to the contract
            foreach (DMAsteroidParameter DMAP in newParams)
            {
                if (limit > 3 + (int)this.prestige)
                {
                    break;
                }
                if (DMAP != null)
                {
                    DMcp.addToSubParams(DMAP, "CollectAsteroidScience");
                    float modifier = ((float)rand.Next(85, 116) / 100f);
                    DMAP.SetScience(DMAP.Container.Exp.baseValue * 0.3f * DMUtils.science * DMUtils.asteroidSubjectVal(1f, size), null);
                    DMAP.SetFunds(5000f * DMUtils.reward * DMUtils.asteroidSubjectVal(1f, size) * modifier, null);
                    limit++;
                }
            }

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

            float primaryModifier = ((float)rand.Next(85, 116) / 100f);

            this.agent = AgentList.Instance.GetAgent("DMagic");
            base.SetExpiry(10 * DMUtils.deadline, 20 * DMUtils.deadline);
            base.SetDeadlineYears(3.8f * DMUtils.deadline * primaryModifier, null);
            base.SetReputation(1.5f * DMcp.ParameterCount * DMUtils.reward * (size + 1) * primaryModifier, 1.2f * DMcp.ParameterCount * DMUtils.penalty * primaryModifier, null);
            base.SetFunds(8000 * DMcp.ParameterCount * DMUtils.forward * (size + 1) * primaryModifier, 9500 * DMcp.ParameterCount * DMUtils.reward * (size + 1) * primaryModifier, 7000 * DMcp.ParameterCount * DMUtils.penalty * (size + 1) * primaryModifier, null);
            return(true);
        }
        protected override bool Generate()
        {
            DMSurveyContract[] surveyContracts = ContractSystem.Instance.GetCurrentContracts <DMSurveyContract>();
            int offers    = 0;
            int active    = 0;
            int maxOffers = DMUtils.maxSurveyOffered;
            int maxActive = DMUtils.maxSurveyActive;

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

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

            AvailablePart aPart = PartLoader.getPartInfoByName("dmmagBoom");

            if (aPart == null)
            {
                return(false);
            }
            if (!ResearchAndDevelopment.PartModelPurchased(aPart))
            {
                return(false);
            }

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

            if (sciList.Count > 0)
            {
                DMScience = sciList[rand.Next(0, sciList.Count)];
                sciList.Remove(DMScience);
            }
            else
            {
                return(false);
            }

            //Generates the science experiment, returns null if experiment fails any check
            if ((newParams[0] = DMSurveyGenerator.fetchSurveyScience(this.Prestige, GetBodies_Reached(false, false), GetBodies_NextUnreached(4, null), DMScience)) == null)
            {
                return(false);
            }

            body = newParams[0].Body;

            //Add an orbital parameter to difficult contracts
            if (this.Prestige == ContractPrestige.Exceptional)
            {
                this.AddParameter(new EnterOrbit(body));
            }

            for (int j = 1; j < 8; j++)
            {
                if (sciList.Count > 0)
                {
                    DMScience    = sciList[rand.Next(0, sciList.Count)];
                    newParams[j] = DMSurveyGenerator.fetchSurveyScience(body, DMScience);
                    sciList.Remove(DMScience);
                }
                else
                {
                    newParams[j] = null;
                }
            }

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

            this.AddParameter(DMcp);

            int limit = 1;

            //Add in all acceptable paramaters to the contract
            foreach (DMCollectScience DMC in newParams)
            {
                if (limit > (3 + (int)this.Prestige))
                {
                    break;
                }
                if (DMC != null)
                {
                    DMcp.addToSubParams(DMC, "CollectScience");
                    float locationMod = GameVariables.Instance.ScoreSituation(DMUtils.convertSit(DMC.Situation), DMC.Body) * ((float)rand.Next(85, 116) / 100f);
                    DMC.SetScience(DMC.Container.Exp.baseValue * 0.2f * DMUtils.science * DMUtils.fixSubjectVal(DMC.Situation, 1f, body), null);
                    DMC.SetFunds(3500f * DMUtils.reward * locationMod, body);
                    limit++;
                }
            }

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

            int a = rand.Next(0, 4);

            if (a == 0)
            {
                this.agent = AgentList.Instance.GetAgent("DMagic");
            }
            else if (a == 1)
            {
                this.agent = AgentList.Instance.GetAgent(newParams[0].Container.Agent);
            }
            else
            {
                this.agent = AgentList.Instance.GetAgentRandom();
            }

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

            base.SetExpiry(10f * DMUtils.deadline, 20f * DMUtils.deadline);
            base.SetDeadlineYears(1.7f * ((float)rand.Next(80, 121)) / 100f * DMUtils.deadline, body);
            base.SetReputation(1.9f * DMcp.ParameterCount * DMUtils.reward * primaryLocationMod, 1.5f * DMcp.ParameterCount * DMUtils.penalty * primaryLocationMod, null);
            base.SetFunds(8500 * DMcp.ParameterCount * DMUtils.forward * primaryLocationMod, 10500 * DMcp.ParameterCount * DMUtils.reward * primaryLocationMod, 7500 * DMcp.ParameterCount * DMUtils.penalty * primaryLocationMod, body);
            return(true);
        }