Esempio n. 1
0
        protected override bool Generate()
        {
            int total = ContractSystem.Instance.GetCurrentContracts <DMAnomalyContract>().Count();

            if (total >= DMUtils.maxAnomaly)
            {
                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);
                }
            }

            //Select random anomaly
            targetAnomaly = new DMAnomalyObject(cities[rand.Next(0, cities.Count)]);
            hash          = targetAnomaly.name;
            lon           = targetAnomaly.lon;
            lat           = targetAnomaly.lat;
            fudgedLat     = fudgeLat(lat);
            fudgedLon     = fudgeLon(lon);
            cardNS        = NSDirection(lat);
            cardEW        = EWDirection(lon);
            DMUtils.DebugLog("Anomaly [{0}] Selected On {1} at Latitude: {2:N1} and Longitude: {3:N1}", targetAnomaly.name, body.theName, lat, 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, targetAnomaly, DMScience));
                    sciList.Remove(DMScience);
                }
                else
                {
                    anomParams[i] = null;
                }
            }

            this.AddParameter(newParam);
            DMUtils.DebugLog("Added Primary Anomaly Parameter");
            float primaryLocationMod = GameVariables.Instance.ScoreSituation(DMUtils.convertSit(newParam.Situation), newParam.Body) * ((float)rand.Next(85, 116) / 100f);

            newParam.SetFunds(20000f * DMUtils.reward * primaryLocationMod, 10000f * DMUtils.penalty * primaryLocationMod, body);
            newParam.SetReputation(80f * DMUtils.reward * primaryLocationMod, 10f * DMUtils.penalty * primaryLocationMod, body);
            newParam.SetScience(35f * DMUtils.science * DMUtils.fixSubjectVal(newParam.Situation, 1f, body), null);

            foreach (DMAnomalyParameter aP in anomParams)
            {
                if (aP != null)
                {
                    this.AddParameter(aP, "collectDMAnomaly");
                    DMUtils.DebugLog("Added Secondary Anomaly Parameter");
                    float locationMod = GameVariables.Instance.ScoreSituation(DMUtils.convertSit(aP.Situation), aP.Body) * ((float)rand.Next(85, 116) / 100f);
                    aP.SetFunds(9000f * DMUtils.reward * locationMod, 6000f * DMUtils.penalty * locationMod, body);
                    aP.SetReputation(20f * DMUtils.reward * locationMod, 5f * DMUtils.penalty * locationMod, body);
                    aP.SetScience(aP.Container.exp.baseValue * 2f * DMUtils.science * DMUtils.fixSubjectVal(aP.Situation, 1f, body), null);
                }
            }

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

            this.agent = AgentList.Instance.GetAgent("DMagic");
            base.SetExpiry(10 * DMUtils.deadline, 20 * DMUtils.deadline);
            base.SetDeadlineYears(1.8f * ((float)rand.Next(80, 121)) / 100f * DMUtils.deadline, body);
            base.SetReputation(20f * DMUtils.reward * primaryLocationMod, 10f * DMUtils.penalty * primaryLocationMod, body);
            base.SetFunds(25000f * DMUtils.forward * primaryLocationMod, 22000f * DMUtils.reward * primaryLocationMod, 16000f * DMUtils.penalty * primaryLocationMod, body);
            return(true);
        }
Esempio n. 2
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);
        }