コード例 #1
0
        protected override bool Generate()
        {
            int total = ContractSystem.Instance.GetCurrentContracts <DMSurveyContract>().Count();

            if (total >= DMUtils.maxSurvey)
            {
                return(false);
            }

            surveyType = rand.Next(0, 3);
            if (surveyType == 0)
            {
                //Make sure that the magnetometer is at least available
                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, true), GetBodies_NextUnreached(4, null), DMScience, 0)) == null)
                {
                    return(false);
                }

                body = newParams[0].Body;
                //Add an orbital parameter
                this.AddParameter(new EnterOrbit(body), null);
            }
            else if (surveyType == 1)
            {
                //Make sure that the laser is at least available
                AvailablePart aPart = PartLoader.getPartInfoByName("dmsurfacelaser");
                if (aPart == null)
                {
                    return(false);
                }
                if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                {
                    return(false);
                }

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

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

                if ((newParams[0] = DMSurveyGenerator.fetchSurveyScience(this.Prestige, GetBodies_Reached(false, true), GetBodies_NextUnreached(4, null), DMScience, 1)) == null)
                {
                    return(false);
                }

                body  = newParams[0].Body;
                biome = newParams[0].Biome;

                if (biome == "")
                {
                    List <string> biomes = DMUtils.fetchBiome(body);
                    biome = biomes[rand.Next(0, biomes.Count)];
                }
                this.AddParameter(new LandOnBody(body), null);
            }
            else if (surveyType == 2)
            {
                if (this.Prestige == ContractPrestige.Trivial)
                {
                    return(false);
                }
                //Make sure that drill is at least available
                AvailablePart aPart = PartLoader.getPartInfoByName("dmbioDrill");
                if (aPart == null)
                {
                    return(false);
                }
                if (!ResearchAndDevelopment.PartModelPurchased(aPart))
                {
                    return(false);
                }

                //Duna and Eve are the easy targets
                if (this.Prestige == ContractPrestige.Significant)
                {
                    if (!ProgressTracking.Instance.NodeComplete(new string[] { "Kerbin", "Escape" }))
                    {
                        return(false);
                    }
                    if (rand.Next(0, 2) == 0)
                    {
                        body = FlightGlobals.Bodies[5];
                    }
                    else
                    {
                        body = FlightGlobals.Bodies[6];
                    }
                }
                else if (this.Prestige == ContractPrestige.Exceptional)
                {
                    //Account for mod planets and Laythe
                    if (!ProgressTracking.Instance.NodeComplete(new string[] { "Jool", "Flyby" }))
                    {
                        return(false);
                    }
                    List <CelestialBody> bList = new List <CelestialBody>();
                    foreach (CelestialBody b in FlightGlobals.Bodies)
                    {
                        if (b.flightGlobalsIndex != 1 && b.flightGlobalsIndex != 5 && b.flightGlobalsIndex != 6 && b.flightGlobalsIndex != 8)
                        {
                            if (b.atmosphere && b.pqsController != null)
                            {
                                bList.Add(b);
                            }
                        }
                    }
                    body = bList[rand.Next(0, bList.Count)];
                }
                else
                {
                    return(false);
                }

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

                if ((newParams[0] = DMSurveyGenerator.fetchBioSurveyScience(body)) == null)
                {
                    return(false);
                }

                biome = newParams[0].Biome;

                if (biome == "")
                {
                    List <string> biomes = DMUtils.fetchBiome(body);
                    biome = biomes[rand.Next(0, biomes.Count)];
                }

                this.AddParameter(new LandOnBody(body), null);
                this.AddParameter(new EnterOrbit(body), null);
            }
            else
            {
                return(false);
            }

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

            //Add in all acceptable paramaters to the contract
            foreach (DMCollectScience DMC in newParams)
            {
                if (i > (3 + (int)this.prestige))
                {
                    break;
                }
                if (DMC != null)
                {
                    this.AddParameter(DMC, "collectDMScience");
                    float locationMod = GameVariables.Instance.ScoreSituation(DMUtils.convertSit(DMC.Situation), DMC.Body) * ((float)rand.Next(85, 116) / 100f);
                    DMC.SetScience(DMC.Container.exp.baseValue * 0.7f * DMUtils.science * DMUtils.fixSubjectVal(DMC.Situation, 1f, body), null);
                    DMC.SetFunds(4000f * DMUtils.reward * locationMod, 1500f * DMUtils.penalty * locationMod, body);
                    DMC.SetReputation(15f * DMUtils.reward * locationMod, 10f * DMUtils.penalty * locationMod, body);
                    i++;
                    DMUtils.DebugLog("Survey Parameter Added");
                }
            }

            if (surveyType == 0 || surveyType == 1)
            {
                if (this.ParameterCount < 4)
                {
                    return(false);
                }
            }
            else if (surveyType == 2)
            {
                if (this.ParameterCount < 5)
                {
                    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.9f * ((float)rand.Next(80, 121)) / 100f * DMUtils.deadline, body);
            base.SetReputation(newParams.Length * 8f * DMUtils.reward * primaryLocationMod, newParams.Length * 5f * DMUtils.penalty * primaryLocationMod, body);
            base.SetFunds(3000 * newParams.Length * DMUtils.forward * primaryLocationMod, 2500 * newParams.Length * DMUtils.reward * primaryLocationMod, 2000 * newParams.Length * DMUtils.penalty * primaryLocationMod, body);
            return(true);
        }
コード例 #2
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);
        }
コード例 #3
0
        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);
        }