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