internal static DMAsteroidParameter fetchAsteroidParameter(int Size, DMScienceContainer DMScience) { ExperimentSituations targetSituation; AvailablePart aPart; string name; name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; //Determine if the science part is available if applicable if (DMScience.sciPart != "None") { DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart); aPart = PartLoader.getPartInfoByName(DMScience.sciPart); if (aPart == null) { return(null); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(null); } DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); } if (DMScience.exp == null) { return(null); } if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow) { if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded) { if (rand.Next(0, 2) == 0) { targetSituation = ExperimentSituations.SrfLanded; } else { targetSituation = ExperimentSituations.InSpaceLow; } } else { targetSituation = ExperimentSituations.InSpaceLow; } } else if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded) { targetSituation = ExperimentSituations.SrfLanded; } else { return(null); } DMUtils.DebugLog("Successfully Generated Asteroid Survey Parameter"); return(new DMAsteroidParameter(Size, targetSituation, name)); }
internal static DMAsteroidParameter fetchAsteroidParameter(DMScienceContainer DMScience) { ExperimentSituations targetSituation; string name; if (!DMUtils.availableScience.ContainsKey("All")) { return(null); } name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { if (!DMUtils.partAvailable(new List <string>(1) { DMScience.SciPart })) { return(null); } } if (DMScience.Exp == null) { return(null); } if (((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow) { if (((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded) { if (rand.Next(0, 2) == 0) { targetSituation = ExperimentSituations.SrfLanded; } else { targetSituation = ExperimentSituations.InSpaceLow; } } else { targetSituation = ExperimentSituations.InSpaceLow; } } else if (((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded) { targetSituation = ExperimentSituations.SrfLanded; } else { return(null); } return(new DMAsteroidParameter(targetSituation, name)); }
internal static DMAsteroidParameter fetchAsteroidParameter(DMScienceContainer DMScience) { ExperimentSituations targetSituation; AvailablePart aPart; string name; name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { aPart = PartLoader.getPartInfoByName(DMScience.SciPart); if (aPart == null) { return(null); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(null); } } if (DMScience.Exp == null) { return(null); } if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow) { if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded) { if (rand.Next(0, 2) == 0) { targetSituation = ExperimentSituations.SrfLanded; } else { targetSituation = ExperimentSituations.InSpaceLow; } } else { targetSituation = ExperimentSituations.InSpaceLow; } } else if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded) { targetSituation = ExperimentSituations.SrfLanded; } else { return(null); } return(new DMAsteroidParameter(targetSituation, name)); }
internal static DMCollectScience fetchBioSurveyScience(CelestialBody body, DMScienceContainer DMScience, string Biome) { ExperimentSituations targetSituation; List <ExperimentSituations> situations; AvailablePart aPart; string name; name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; DMUtils.DebugLog("Checking Contract Requirements"); //Determine if the science part is available if applicable if (DMScience.sciPart != "None") { DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart); aPart = PartLoader.getPartInfoByName(DMScience.sciPart); if (aPart == null) { return(null); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(null); } DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); } //Make sure our experiment is OK if (DMScience.exp == null) { return(null); } //Choose an acceptable experimental situation for a given science experiment if ((situations = DMUtils.availableSituations(DMScience.exp, DMScience.sitMask, body)).Count == 0) { return(null); } else { DMUtils.DebugLog("Acceptable Situations Found"); targetSituation = situations[rand.Next(0, situations.Count)]; DMUtils.DebugLog("Experimental Situation: {0}", targetSituation); } if (targetSituation != ExperimentSituations.SrfLanded) { Biome = ""; } return(new DMCollectScience(body, targetSituation, Biome, name, 1)); }
internal static DMAnomalyParameter fetchAnomalyParameter(CelestialBody Body, DMScienceContainer DMScience) { ExperimentSituations targetSituation; List <ExperimentSituations> situations; string name; if (!DMUtils.availableScience.ContainsKey("All")) { return(null); } name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; if (DMScience.Exp == null) { return(null); } //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { if (!DMUtils.partAvailable(new List <string>(1) { DMScience.SciPart })) { return(null); } } if ((situations = DMUtils.availableSituationsLimited(DMScience.Exp, (int)DMScience.Exp.situationMask, Body)).Count == 0) { return(null); } else { targetSituation = situations[rand.Next(0, situations.Count)]; } return(new DMAnomalyParameter(targetSituation, name)); }
internal static DMAnomalyParameter fetchAnomalyParameter(CelestialBody Body, DMScienceContainer DMScience) { AvailablePart aPart; ExperimentSituations targetSituation; List <ExperimentSituations> situations; string name; name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; if (DMScience.Exp == null) { return(null); } //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { aPart = PartLoader.getPartInfoByName(DMScience.SciPart); if (aPart == null) { return(null); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(null); } } if ((situations = DMUtils.availableSituationsLimited(DMScience.Exp, DMScience.SitMask, Body)).Count == 0) { return(null); } else { targetSituation = situations[rand.Next(0, situations.Count)]; } return(new DMAnomalyParameter(targetSituation, name)); }
private void configLoad() { //Load in global multipliers foreach (ConfigNode setNode in GameDatabase.Instance.GetConfigNodes("DM_CONTRACT_SETTINGS")) { if (setNode != null) { if (!float.TryParse(setNode.GetValue("Global_Science_Return"), out DMUtils.science)) DMUtils.science = 1; if (!float.TryParse(setNode.GetValue("Global_Fund_Reward"), out DMUtils.reward)) DMUtils.reward = 1; if (!float.TryParse(setNode.GetValue("Global_Fund_Forward"), out DMUtils.forward)) DMUtils.forward = 1; if (!float.TryParse(setNode.GetValue("Global_Fund_Penalty"), out DMUtils.penalty)) DMUtils.penalty = 1; if (!float.TryParse(setNode.GetValue("Global_Deadline"), out DMUtils.deadline)) DMUtils.deadline = 1; if (!int.TryParse(setNode.GetValue("Max_Survey_Offered"), out DMUtils.maxSurveyOffered)) DMUtils.maxSurveyOffered = 2; if (!int.TryParse(setNode.GetValue("Max_Survey_Active"), out DMUtils.maxSurveyActive)) DMUtils.maxSurveyActive = 4; if (!int.TryParse(setNode.GetValue("Max_Asteroid_Offered"), out DMUtils.maxAsteroidOffered)) DMUtils.maxAsteroidOffered = 1; if (!int.TryParse(setNode.GetValue("Max_Asteroid_Active"), out DMUtils.maxAsteroidActive)) DMUtils.maxAsteroidActive = 3; if (!int.TryParse(setNode.GetValue("Max_Anomaly_Offered"), out DMUtils.maxAnomalyOffered)) DMUtils.maxAnomalyOffered = 1; if (!int.TryParse(setNode.GetValue("Max_Anomaly_Active"), out DMUtils.maxAnomalyActive)) DMUtils.maxAnomalyActive = 3; if (!int.TryParse(setNode.GetValue("Max_Magnetic_Offered"), out DMUtils.maxMagneticOffered)) DMUtils.maxMagneticOffered = 2; if (!int.TryParse(setNode.GetValue("Max_Magnetic_Active"), out DMUtils.maxMagneticActive)) DMUtils.maxMagneticActive = 4; DMUtils.Logging("Contract Variables Set; Science Reward: {0} ; Completion Reward: {1} ; Forward Amount: {2} ; Penalty Amount: {3} ; Deadline Length: {4}", DMUtils.science, DMUtils.reward, DMUtils.forward, DMUtils.penalty, DMUtils.deadline); DMUtils.Logging("Max Contract Variables Set: Survey Offers: {0}; Active: {1} -- Asteroid Offers: {2}; Active: {3} -- Anomaly Offers: {4}; Active: {5} -- Magnetic Offers: {6}; Active: {7}", DMUtils.maxSurveyOffered, DMUtils.maxSurveyActive, DMUtils.maxAsteroidOffered, DMUtils.maxAsteroidActive, DMUtils.maxAnomalyOffered, DMUtils.maxAnomalyActive, DMUtils.maxMagneticOffered, DMUtils.maxMagneticActive); break; } else DMUtils.Logging("Broken Config....."); } //Load in experiment definitions foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("DM_CONTRACT_EXPERIMENT")) { if (node != null) { string name = ""; string part = ""; string agent = ""; int sitMask = 0; int bioMask = 0; int type = 0; float transmit = 0; DMScienceContainer DMscience = null; ScienceExperiment exp = null; //Some apparently not impossible errors can cause duplicate experiments to be added to the R&D science experiment dictionary try { exp = ResearchAndDevelopment.GetExperiment(node.GetValue("experimentID")); } catch (Exception e) { Debug.LogError("[DM] Whoops. Something really wrong happened here; stopping this contract experiment from loading..." + e); continue; } if (exp != null) { if (!node.HasValue("name")) continue; name = node.GetValue("name"); if (!int.TryParse(node.GetValue("sitMask"), out sitMask)) continue; if (!int.TryParse(node.GetValue("bioMask"), out bioMask)) continue; if (!int.TryParse(node.GetValue("type"), out type)) continue; if (!float.TryParse(node.GetValue("xmitDataScalar"), out transmit)) continue; if (node.HasValue("part")) part = node.GetValue("part"); else part = "None"; if (node.HasValue("agent")) agent = node.GetValue("agent"); else agent = "Any"; if (DMUtils.whiteListed) { exp.situationMask = (uint)sitMask; exp.biomeMask = (uint)bioMask; } DMscience = new DMScienceContainer(exp, sitMask, bioMask, (DMScienceType)type, part, agent, transmit); foreach (var sciType in Enum.GetValues(typeof(DMScienceType))) { string typeString = ((DMScienceType)sciType).ToString(); if (!string.IsNullOrEmpty(typeString)) { if (DMUtils.availableScience.ContainsKey(typeString)) { if ((DMScienceType)sciType == DMScienceType.All) { if (!DMUtils.availableScience[typeString].ContainsKey(name)) DMUtils.availableScience[typeString].Add(name, DMscience); } else if (((DMScienceType)type & (DMScienceType)sciType) == (DMScienceType)sciType) { if (!DMUtils.availableScience[typeString].ContainsKey(name)) DMUtils.availableScience[typeString].Add(name, DMscience); } } } } //DMUtils.DebugLog("New Experiment: [{0}] Available For Contracts", name); } } } DMUtils.Logging("Successfully Added {0} New Experiments To Contract List", DMUtils.availableScience["All"].Count); //foreach (var sciType in Enum.GetValues(typeof(DMScienceType))) //{ // string type = ((DMScienceType)sciType).ToString(); // if (!string.IsNullOrEmpty(type)) // { // if (DMUtils.availableScience.ContainsKey(type)) // { // if (type != "All") // DMUtils.DebugLog("Successfully Added {0} New {1} Experiments To Contract List", DMUtils.availableScience[type].Count, type); // } // } //} //Load in custom contract descriptions foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("DM_SCIENCE_STORY_DEF")) { if (node != null) { foreach (ConfigNode storyNode in node.GetNodes("DM_SCIENCE_BACKSTORY")) { if (storyNode != null) { if (storyNode.HasValue("survey")) { foreach (string so in storyNode.GetValues("survey")) { if (!string.IsNullOrEmpty(so)) { string story_o = so.Replace("[", "{"); story_o = story_o.Replace("]", "}"); DMUtils.backStory["survey"].Add(story_o); } } } if (storyNode.HasValue("asteroid")) { foreach (string sb in storyNode.GetValues("asteroid")) { if (!string.IsNullOrEmpty(sb)) { string story_b = sb.Replace("[", "{"); story_b = story_b.Replace("]", "}"); DMUtils.backStory["asteroid"].Add(story_b); } } } if (storyNode.HasValue("anomaly")) { foreach (string sb in storyNode.GetValues("anomaly")) { if (!string.IsNullOrEmpty(sb)) { string story_b = sb.Replace("[", "{"); story_b = story_b.Replace("]", "}"); DMUtils.backStory["anomaly"].Add(story_b); } } } if (storyNode.HasValue("magnetic")) { foreach (string sb in storyNode.GetValues("magnetic")) { if (!string.IsNullOrEmpty(sb)) { string story_b = sb.Replace("[", "{"); story_b = story_b.Replace("]", "}"); DMUtils.backStory["magnetic"].Add(story_b); } } } } } } } DMUtils.Logging("Added {0} New Survey Backstories; {1} New Asteroid Backstories; {2} New Anomaly Backstories; {3} New Magnetic Backstories To The List", DMUtils.backStory["survey"].Count, DMUtils.backStory["asteroid"].Count, DMUtils.backStory["anomaly"].Count, DMUtils.backStory["magnetic"].Count); }
//Use for recon survey internal static DMCollectScience fetchScienceContract(CelestialBody Body, ExperimentSituations Situation, string biome, DMScienceContainer DMScience) { string name; //Choose science container based on a given science experiment if (!DMUtils.availableScience.ContainsKey("All")) { return(null); } name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; if (DMScience.Exp == null) { return(null); } //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { if (!DMUtils.partAvailable(new List <string>(1) { DMScience.SciPart })) { return(null); } } return(new DMCollectScience(Body, Situation, biome, name, 1)); }
//Used for orbital survey internal static DMCollectScience fetchSurveyScience(CelestialBody Body, DMScienceContainer DMScience) { ExperimentSituations targetSituation; ScienceSubject sub; string name; if (!DMUtils.availableScience.ContainsKey("All")) { return(null); } name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { if (!DMUtils.partAvailable(new List <string>(1) { DMScience.SciPart })) { return(null); } } //Make sure our experiment is OK if (DMScience.Exp == null) { return(null); } if (!Body.atmosphere && DMScience.Exp.requireAtmosphere) { return(null); } if (((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh && ((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow) { if (rand.Next(0, 2) == 0) { targetSituation = ExperimentSituations.InSpaceHigh; } else { targetSituation = ExperimentSituations.InSpaceLow; } } else if (((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh) { targetSituation = ExperimentSituations.InSpaceHigh; } else { targetSituation = ExperimentSituations.InSpaceLow; } if (DMUtils.biomeRelevant(targetSituation, (int)DMScience.Exp.biomeMask)) { List <string> bList = DMUtils.fetchBiome(Body, DMScience.Exp, targetSituation); if (bList.Count == 0) { return(null); } } else { string subId = string.Format("{0}@{1}{2}", DMScience.Exp.id, Body.bodyName, targetSituation); if (ResearchAndDevelopment.GetSubjects().Any(s => s.id == subId)) { sub = ResearchAndDevelopment.GetSubjectByID(subId); if (sub.scientificValue < 0.5f) { return(null); } } } return(new DMCollectScience(Body, targetSituation, "", name, 0)); }
internal static DMAsteroidParameter fetchAsteroidParameter(DMScienceContainer DMScience) { ExperimentSituations targetSituation; AvailablePart aPart; string name; name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { aPart = PartLoader.getPartInfoByName(DMScience.SciPart); if (aPart == null) return null; if (!ResearchAndDevelopment.PartModelPurchased(aPart)) return null; } if (DMScience.Exp == null) return null; if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow) if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded) if (rand.Next(0, 2) == 0) targetSituation = ExperimentSituations.SrfLanded; else targetSituation = ExperimentSituations.InSpaceLow; else targetSituation = ExperimentSituations.InSpaceLow; else if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded) targetSituation = ExperimentSituations.SrfLanded; else return null; return new DMAsteroidParameter(targetSituation, name); }
//Used for initial orbital and surface survey parameter internal static DMCollectScience fetchSurveyScience(Contract.ContractPrestige c, List<CelestialBody> cR, List<CelestialBody> cUR, DMScienceContainer DMScience) { CelestialBody body; ExperimentSituations targetSituation; ScienceSubject sub; AvailablePart aPart; string name; string biome = ""; name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { aPart = PartLoader.getPartInfoByName(DMScience.SciPart); if (aPart == null) return null; if (!ResearchAndDevelopment.PartModelPurchased(aPart)) return null; } body = DMUtils.nextTargetBody(c, cR, cUR); if (body == null) return null; //Make sure our experiment is OK if (DMScience.Exp == null) return null; if (!body.atmosphere && DMScience.Exp.requireAtmosphere) return null; if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh && ((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow) { if (rand.Next(0, 2) == 0) targetSituation = ExperimentSituations.InSpaceHigh; else targetSituation = ExperimentSituations.InSpaceLow; } else if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh) targetSituation = ExperimentSituations.InSpaceHigh; else targetSituation = ExperimentSituations.InSpaceLow; if (DMUtils.biomeRelevant(targetSituation, DMScience.BioMask) && targetSituation != ExperimentSituations.SrfSplashed) { List<string> bList = DMUtils.fetchBiome(body, DMScience.Exp, targetSituation); if (bList.Count == 0) { return null; } else { biome = bList[rand.Next(0, bList.Count)]; } } //Make sure that our chosen science subject has science remaining to be gathered string subId = string.Format("{0}@{1}{2}{3}", DMScience.Exp.id, body.name, targetSituation, biome.Replace(" ", "")); if (ResearchAndDevelopment.GetSubjects().Any(s => s.id == subId)) { sub = ResearchAndDevelopment.GetSubjectByID(subId); if (sub.scientificValue < 0.5f) return null; } return new DMCollectScience(body, targetSituation, "", name, 0); }
//Used for initial orbital and surface survey parameter internal static DMCollectScience fetchSurveyScience(Contract.ContractPrestige c, List <CelestialBody> cR, List <CelestialBody> cUR, DMScienceContainer DMScience) { CelestialBody body; ExperimentSituations targetSituation; ScienceSubject sub; string name; string biome = ""; if (!DMUtils.availableScience.ContainsKey("All")) { return(null); } name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { if (!DMUtils.partAvailable(new List <string>(1) { DMScience.SciPart })) { return(null); } } List <CelestialBody> bodies = new List <CelestialBody>(); Func <CelestialBody, bool> cb = null; switch (c) { case Contract.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 Contract.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 Contract.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(null); } body = bodies[rand.Next(0, bodies.Count)]; if (body == null) { return(null); } //Make sure our experiment is OK if (DMScience.Exp == null) { return(null); } if (!body.atmosphere && DMScience.Exp.requireAtmosphere) { return(null); } if (((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh && ((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow) { if (rand.Next(0, 2) == 0) { targetSituation = ExperimentSituations.InSpaceHigh; } else { targetSituation = ExperimentSituations.InSpaceLow; } } else if (((ExperimentSituations)DMScience.Exp.situationMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh) { targetSituation = ExperimentSituations.InSpaceHigh; } else { targetSituation = ExperimentSituations.InSpaceLow; } if (DMUtils.biomeRelevant(targetSituation, (int)DMScience.Exp.biomeMask) && targetSituation != ExperimentSituations.SrfSplashed) { List <string> bList = DMUtils.fetchBiome(body, DMScience.Exp, targetSituation); if (bList.Count == 0) { return(null); } else { biome = bList[rand.Next(0, bList.Count)]; } } //Make sure that our chosen science subject has science remaining to be gathered string subId = string.Format("{0}@{1}{2}{3}", DMScience.Exp.id, body.bodyName, targetSituation, biome.Replace(" ", "")); if (ResearchAndDevelopment.GetSubjects().Any(s => s.id == subId)) { sub = ResearchAndDevelopment.GetSubjectByID(subId); if (sub.scientificValue < 0.5f) { return(null); } } return(new DMCollectScience(body, targetSituation, "", name, 0)); }
//Used for orbital survey internal static DMCollectScience fetchSurveyScience(CelestialBody Body, DMScienceContainer DMScience) { ExperimentSituations targetSituation; ScienceSubject sub; AvailablePart aPart; string name; name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; //Determine if the science part is available if applicable if (DMScience.sciPart != "None") { DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart); aPart = PartLoader.getPartInfoByName(DMScience.sciPart); if (aPart == null) { return(null); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(null); } DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); } //Make sure our experiment is OK if (DMScience.exp == null) { return(null); } if (!Body.atmosphere && DMScience.exp.requireAtmosphere) { return(null); } if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh) { if (rand.Next(0, 2) == 0) { targetSituation = ExperimentSituations.InSpaceHigh; } else { targetSituation = ExperimentSituations.InSpaceLow; } } else { targetSituation = ExperimentSituations.InSpaceLow; } if (DMUtils.biomeRelevant(targetSituation, DMScience.bioMask)) { DMUtils.DebugLog("Checking For Biome Usage"); List <string> bList = DMUtils.fetchBiome(Body, DMScience.exp, targetSituation); if (bList.Count == 0) { DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here"); return(null); } } if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}", DMScience.exp.id, Body.name, targetSituation))) != null) { if (sub.scientificValue < 0.5f) { return(null); } } return(new DMCollectScience(Body, targetSituation, "", name, 0)); }
private void configLoad() { ConfigNode DMcontractDefs = GameDatabase.Instance.GetConfigNode("DMagicOrbitalScience/Resources/DMContracts/DMContracts"); if (DMcontractDefs == null) { return; } foreach (ConfigNode node in DMcontractDefs.GetNodes("DM_CONTRACT_EXPERIMENT")) { if (node == null) { continue; } DMScienceContainer DMscience = null; ScienceExperiment exp = null; //Some apparently not impossible errors can cause duplicate experiments to be added to the R&D science experiment dictionary try { exp = ResearchAndDevelopment.GetExperiment(node.GetValue("experimentID")); } catch (Exception e) { Debug.LogError("[DM] Whoops. Something really wrong happened here, a duplicate science experiment definition may be present somewhere; stopping this contract experiment from loading..." + e); continue; } if (exp != null) { string name = node.parse("name", "null"); if (name == "null") { continue; } int type = node.parse("type", (int)1000); if (type == 1000) { continue; } float transmit = node.parse("xmitDataScalar", (float)1000); if (transmit >= 1000) { continue; } string part = node.parse("part", "None"); string agent = node.parse("agent", "Any"); DMscience = new DMScienceContainer(exp, (DMScienceType)type, part, agent, transmit); foreach (var sciType in Enum.GetValues(typeof(DMScienceType))) { string typeString = ((DMScienceType)sciType).ToString(); if (string.IsNullOrEmpty(typeString)) { continue; } if (DMUtils.availableScience.ContainsKey(typeString)) { if ((DMScienceType)sciType == DMScienceType.All) { if (!DMUtils.availableScience[typeString].ContainsKey(name)) { DMUtils.availableScience[typeString].Add(name, DMscience); } } else if (((DMScienceType)type & (DMScienceType)sciType) == (DMScienceType)sciType) { if (!DMUtils.availableScience[typeString].ContainsKey(name)) { DMUtils.availableScience[typeString].Add(name, DMscience); } } } } } } DMUtils.Logging("Successfully Added {0} New Experiments To Contract List", DMUtils.availableScience["All"].Count); ConfigNode DMAnomalyNode = DMcontractDefs.GetNode("DMAnomaly"); ConfigNode DMAsteroidNode = DMcontractDefs.GetNode("DMAsteroid"); ConfigNode DMMagNode = DMcontractDefs.GetNode("DMMag"); ConfigNode DMReconNode = DMcontractDefs.GetNode("DMRecon"); ConfigNode DMSurveyNode = DMcontractDefs.GetNode("DMSurvey"); if (DMAnomalyNode != null) { DMContractDefs.DMAnomaly.maxOffers = DMAnomalyNode.parse("maxOffers", (int)2); DMContractDefs.DMAnomaly.maxActive = DMAnomalyNode.parse("maxActive", (int)3); DMContractDefs.DMAnomaly.TrivialReconLevelRequirement = DMAnomalyNode.parse("Trivial_Recon_Level_Requirement", (int)0); DMContractDefs.DMAnomaly.SignificantReconLevelRequirement = DMAnomalyNode.parse("Significant_Recon_Level_Requirement", (int)1); DMContractDefs.DMAnomaly.ExceptionalReconLevelRequirement = DMAnomalyNode.parse("Exceptional_Recon_Level_Requirement", (int)1); DMContractDefs.DMAnomaly.TrivialAnomalyLevel = DMAnomalyNode.parse("Trivial_Anomaly_Level_Requirement", (float)0); DMContractDefs.DMAnomaly.SignificantAnomalyLevel = DMAnomalyNode.parse("Significant_Anomaly_Level_Requirement", (float)0.3f); DMContractDefs.DMAnomaly.ExceptionalAnomalyLevel = DMAnomalyNode.parse("Exceptional_Anomaly_Level_Requirement", (float)0.6f); DMContractDefs.DMAnomaly.backStory = DMAnomalyNode.parse("Backstory", '|', new List <string>(1) { "Something, Something, Something..." }); DMContractDefs.DMAnomaly.backStory = DMUtils.formatFixStringList(DMContractDefs.DMAnomaly.backStory); ConfigNode AnomalyExpireNode = DMAnomalyNode.GetNode("Expire"); ConfigNode AnomalyFundsNode = DMAnomalyNode.GetNode("Funds"); ConfigNode AnomalySciNode = DMAnomalyNode.GetNode("Science"); ConfigNode AnomalyRepNode = DMAnomalyNode.GetNode("Reputation"); if (AnomalyExpireNode != null) { DMContractDefs.DMAnomaly.Expire.MinimumExpireDays = AnomalyExpireNode.parse("MinimumExpireDays", (int)4); DMContractDefs.DMAnomaly.Expire.MaximumExpireDays = AnomalyExpireNode.parse("MaximumExpireDays", (int)10); DMContractDefs.DMAnomaly.Expire.DeadlineYears = AnomalyExpireNode.parse("DeadlineYears", (float)1.5); } if (AnomalyFundsNode != null) { DMContractDefs.DMAnomaly.Funds.BaseAdvance = AnomalyFundsNode.parse("BaseAdvance", (float)20000); DMContractDefs.DMAnomaly.Funds.BaseReward = AnomalyFundsNode.parse("BaseReward", (float)24000); DMContractDefs.DMAnomaly.Funds.BaseFailure = AnomalyFundsNode.parse("BaseFailure", (float)24000); DMContractDefs.DMAnomaly.Funds.ParamReward = AnomalyFundsNode.parse("ParamReward", (float)8000); DMContractDefs.DMAnomaly.Funds.ParamFailure = AnomalyFundsNode.parse("ParamFailure", (float)0); } if (AnomalySciNode != null) { DMContractDefs.DMAnomaly.Science.BaseReward = AnomalySciNode.parse("BaseReward", (float)0); DMContractDefs.DMAnomaly.Science.ParamReward = AnomalySciNode.parse("ParamReward", (float)5); DMContractDefs.DMAnomaly.Science.SecondaryReward = AnomalySciNode.parse("SecondaryReward", (float)0.25); } if (AnomalyRepNode != null) { DMContractDefs.DMAnomaly.Reputation.BaseReward = AnomalyRepNode.parse("BaseReward", (float)7); DMContractDefs.DMAnomaly.Reputation.BaseFailure = AnomalyRepNode.parse("BaseFailure", (float)6); DMContractDefs.DMAnomaly.Reputation.ParamReward = AnomalyRepNode.parse("ParamReward", (float)0); DMContractDefs.DMAnomaly.Reputation.ParamFailure = AnomalyRepNode.parse("ParamFailure", (float)0); } } if (DMAsteroidNode != null) { DMContractDefs.DMAsteroid.maxOffers = DMAsteroidNode.parse("maxOffers", (int)2); DMContractDefs.DMAsteroid.maxActive = DMAsteroidNode.parse("maxActive", (int)3); DMContractDefs.DMAsteroid.trivialScienceRequests = DMAsteroidNode.parse("Max_Trivial_Science_Requests", (int)3); DMContractDefs.DMAsteroid.significantScienceRequests = DMAsteroidNode.parse("Max_Significant_Science_Requests", (int)4); DMContractDefs.DMAsteroid.exceptionalScienceRequests = DMAsteroidNode.parse("Max_Exceptional_Science_Requests", (int)6); DMContractDefs.DMAsteroid.backStory = DMAsteroidNode.parse("Backstory", '|', new List <string>(1) { "Something, Something, Something..." }); DMContractDefs.DMAsteroid.backStory = DMUtils.formatFixStringList(DMContractDefs.DMAsteroid.backStory); ConfigNode AsteroidExpireNode = DMAsteroidNode.GetNode("Expire"); ConfigNode AsteroidFundsNode = DMAsteroidNode.GetNode("Funds"); ConfigNode AsteroidSciNode = DMAsteroidNode.GetNode("Science"); ConfigNode AsteroidRepNode = DMAsteroidNode.GetNode("Reputation"); if (AsteroidExpireNode != null) { DMContractDefs.DMAsteroid.Expire.MinimumExpireDays = AsteroidExpireNode.parse("MinimumExpireDays", (int)4); DMContractDefs.DMAsteroid.Expire.MaximumExpireDays = AsteroidExpireNode.parse("MaximumExpireDays", (int)10); DMContractDefs.DMAsteroid.Expire.DeadlineYears = AsteroidExpireNode.parse("DeadlineYears", (float)3.8); } if (AsteroidFundsNode != null) { DMContractDefs.DMAsteroid.Funds.BaseAdvance = AsteroidFundsNode.parse("BaseAdvance", (float)8000); DMContractDefs.DMAsteroid.Funds.BaseReward = AsteroidFundsNode.parse("BaseReward", (float)9500); DMContractDefs.DMAsteroid.Funds.BaseFailure = AsteroidFundsNode.parse("BaseFailure", (float)7000); DMContractDefs.DMAsteroid.Funds.ParamReward = AsteroidFundsNode.parse("ParamReward", (float)5000); DMContractDefs.DMAsteroid.Funds.ParamFailure = AsteroidFundsNode.parse("ParamFailure", (float)0); } if (AsteroidSciNode != null) { DMContractDefs.DMAsteroid.Science.BaseReward = AsteroidSciNode.parse("BaseReward", (float)0); DMContractDefs.DMAsteroid.Science.ParamReward = AsteroidSciNode.parse("ParamReward", (float)0.25); } if (AsteroidRepNode != null) { DMContractDefs.DMAsteroid.Reputation.BaseReward = AsteroidRepNode.parse("BaseReward", (float)8); DMContractDefs.DMAsteroid.Reputation.BaseFailure = AsteroidRepNode.parse("BaseFailure", (float)6); DMContractDefs.DMAsteroid.Reputation.ParamReward = AsteroidRepNode.parse("ParamReward", (float)0); DMContractDefs.DMAsteroid.Reputation.ParamFailure = AsteroidRepNode.parse("ParamFailure", (float)0); } } if (DMMagNode != null) { DMContractDefs.DMMagnetic.maxOffers = DMMagNode.parse("maxOffers", (int)2); DMContractDefs.DMMagnetic.maxActive = DMMagNode.parse("maxActive", (int)4); DMContractDefs.DMMagnetic.trivialTimeModifier = DMMagNode.parse("Trivial_Mission_Length", (double)100); DMContractDefs.DMMagnetic.significantTimeModifier = DMMagNode.parse("Significant_Mission_Length", (double)150); DMContractDefs.DMMagnetic.exceptionalTimeModifier = DMMagNode.parse("Exceptional_Mission_Length", (double)200); DMContractDefs.DMMagnetic.trivialEccentricityMultiplier = DMMagNode.parse("Trivial_Eccentricity_Modifier", (double)0.2); DMContractDefs.DMMagnetic.significantEccentricityMultiplier = DMMagNode.parse("Significant_Eccentricity_Modifier", (double)0.35); DMContractDefs.DMMagnetic.exceptionalEccentricityMultiplier = DMMagNode.parse("Exceptional_Eccentricity_Modifier", (double)0.5); DMContractDefs.DMMagnetic.trivialInclinationMultiplier = DMMagNode.parse("Trivial_Inclination_Modifier", (double)20); DMContractDefs.DMMagnetic.significantInclinationMultiplier = DMMagNode.parse("Significant_Inclination_Modifier", (double)40); DMContractDefs.DMMagnetic.exceptionalInclinationMultiplier = DMMagNode.parse("Exceptional_Inclination_Modifier", (double)60); DMContractDefs.DMMagnetic.magnetometerExperimentTitle = DMMagNode.parse("Magnetometer_Experiment_Title", "Magnetometer Scan"); DMContractDefs.DMMagnetic.rpwsExperimentTitle = DMMagNode.parse("RPWS_Experiment_Title", "Radio Plasma Wave Scan"); DMContractDefs.DMMagnetic.useVesselWaypoints = DMMagNode.parse("Use_Vessel_Waypoints", (bool)true); DMContractDefs.DMMagnetic.magParts = DMMagNode.parse("Magnetometer_Parts", ',', new List <string>(2) { "dmmagBoom", "dmUSMagBoom" }); DMContractDefs.DMMagnetic.rpwsParts = DMMagNode.parse("RPWS_Parts", ',', new List <string>(2) { "rpwsAnt", "USRPWS" }); DMContractDefs.DMMagnetic.backStory = DMMagNode.parse("Backstory", '|', new List <string>(1) { "Something, Something, Something..." }); DMContractDefs.DMMagnetic.backStory = DMUtils.formatFixStringList(DMContractDefs.DMMagnetic.backStory); ConfigNode MagExpireNode = DMMagNode.GetNode("Expire"); ConfigNode MagFundsNode = DMMagNode.GetNode("Funds"); ConfigNode MagSciNode = DMMagNode.GetNode("Science"); ConfigNode MagRepNode = DMMagNode.GetNode("Reputation"); if (MagExpireNode != null) { DMContractDefs.DMMagnetic.Expire.MinimumExpireDays = MagExpireNode.parse("MinimumExpireDays", (int)4); DMContractDefs.DMMagnetic.Expire.MaximumExpireDays = MagExpireNode.parse("MaximumExpireDays", (int)10); DMContractDefs.DMMagnetic.Expire.DeadlineModifier = MagExpireNode.parse("DeadlineModifier", (float)3.7); } if (MagFundsNode != null) { DMContractDefs.DMMagnetic.Funds.BaseAdvance = MagFundsNode.parse("BaseAdvance", (float)21000); DMContractDefs.DMMagnetic.Funds.BaseReward = MagFundsNode.parse("BaseReward", (float)25000); DMContractDefs.DMMagnetic.Funds.BaseFailure = MagFundsNode.parse("BaseFailure", (float)23000); DMContractDefs.DMMagnetic.Funds.ParamReward = MagFundsNode.parse("ParamReward", (float)4000); DMContractDefs.DMMagnetic.Funds.ParamFailure = MagFundsNode.parse("ParamFailure", (float)0); } if (MagSciNode != null) { DMContractDefs.DMMagnetic.Science.BaseReward = MagSciNode.parse("BaseReward", (float)24); DMContractDefs.DMMagnetic.Science.ParamReward = MagSciNode.parse("ParamReward", (float)2); } if (MagRepNode != null) { DMContractDefs.DMMagnetic.Reputation.BaseReward = MagRepNode.parse("BaseReward", (float)8); DMContractDefs.DMMagnetic.Reputation.BaseFailure = MagRepNode.parse("BaseFailure", (float)7); DMContractDefs.DMMagnetic.Reputation.ParamReward = MagRepNode.parse("ParamReward", (float)0); DMContractDefs.DMMagnetic.Reputation.ParamFailure = MagRepNode.parse("ParamFailure", (float)0); } } if (DMReconNode != null) { DMContractDefs.DMRecon.maxOffers = DMReconNode.parse("maxOffers", (int)2); DMContractDefs.DMRecon.maxActive = DMReconNode.parse("maxActive", (int)4); DMContractDefs.DMRecon.trivialTimeModifier = DMReconNode.parse("Trivial_Mission_Length", (double)50); DMContractDefs.DMRecon.significantTimeModifier = DMReconNode.parse("Significant_Mission_Length", (double)100); DMContractDefs.DMRecon.exceptionalTimeModifier = DMReconNode.parse("Exceptional_Mission_Length", (double)150); DMContractDefs.DMRecon.useVesselWaypoints = DMReconNode.parse("Use_Vessel_Waypoints", (bool)true); DMContractDefs.DMRecon.trivialExperimentTitle = DMReconNode.parse("Trivial_Experiment_Title", "Recon Scan"); DMContractDefs.DMRecon.significantExperimentTitle = DMReconNode.parse("Significant_Experiment_Title", "SIGINT Scan"); DMContractDefs.DMRecon.exceptionalExperimentTitle = DMReconNode.parse("Exceptional_Experiment_Title", "Recon Scan"); DMContractDefs.DMRecon.reconTrivialParts = DMReconNode.parse("Trivial_Parts", ',', new List <string>(1) { "dmReconSmall" }); DMContractDefs.DMRecon.reconSignificantParts = DMReconNode.parse("Significant_Parts", ',', new List <string>(3) { "dmSIGINT", "dmSIGINT.Small", "dmSIGINT.End" }); DMContractDefs.DMRecon.reconExceptionalParts = DMReconNode.parse("Exceptional_Parts", ',', new List <string>(1) { "dmReconLarge" }); DMContractDefs.DMRecon.backStory = DMReconNode.parse("Backstory", '|', new List <string>(1) { "Something, Something, Something..." }); DMContractDefs.DMRecon.backStory = DMUtils.formatFixStringList(DMContractDefs.DMRecon.backStory); ConfigNode ReconExpireNode = DMReconNode.GetNode("Expire"); ConfigNode ReconFundsNode = DMReconNode.GetNode("Funds"); ConfigNode ReconSciNode = DMReconNode.GetNode("Science"); ConfigNode ReconRepNode = DMReconNode.GetNode("Reputation"); if (ReconExpireNode != null) { DMContractDefs.DMRecon.Expire.MinimumExpireDays = ReconExpireNode.parse("MinimumExpireDays", (int)4); DMContractDefs.DMRecon.Expire.MaximumExpireDays = ReconExpireNode.parse("MaximumExpireDays", (int)10); DMContractDefs.DMRecon.Expire.DeadlineModifier = ReconExpireNode.parse("DeadlineModifier", (float)3.9); } if (ReconFundsNode != null) { DMContractDefs.DMRecon.Funds.BaseAdvance = ReconFundsNode.parse("BaseAdvance", (float)50000); DMContractDefs.DMRecon.Funds.BaseReward = ReconFundsNode.parse("BaseReward", (float)60000); DMContractDefs.DMRecon.Funds.BaseFailure = ReconFundsNode.parse("BaseFailure", (float)38000); DMContractDefs.DMRecon.Funds.ParamReward = ReconFundsNode.parse("ParamReward", (float)8000); DMContractDefs.DMRecon.Funds.ParamFailure = ReconFundsNode.parse("ParamFailure", (float)0); } if (ReconSciNode != null) { DMContractDefs.DMRecon.Science.BaseReward = ReconSciNode.parse("BaseReward", (float)10); DMContractDefs.DMRecon.Science.ParamReward = ReconSciNode.parse("ParamReward", (float)2); } if (ReconRepNode != null) { DMContractDefs.DMRecon.Reputation.BaseReward = ReconRepNode.parse("BaseReward", (float)12); DMContractDefs.DMRecon.Reputation.BaseFailure = ReconRepNode.parse("BaseFailure", (float)10); DMContractDefs.DMRecon.Reputation.ParamReward = ReconRepNode.parse("ParamReward", (float)0); DMContractDefs.DMRecon.Reputation.ParamFailure = ReconRepNode.parse("ParamFailure", (float)0); } } if (DMSurveyNode != null) { DMContractDefs.DMSurvey.maxOffers = DMSurveyNode.parse("maxOffers", (int)2); DMContractDefs.DMSurvey.maxActive = DMSurveyNode.parse("maxActive", (int)4); DMContractDefs.DMSurvey.trivialScienceRequests = DMSurveyNode.parse("Max_Trivial_Science_Requests", (int)4); DMContractDefs.DMSurvey.significantScienceRequests = DMSurveyNode.parse("Max_Significant_Science_Requests", (int)6); DMContractDefs.DMSurvey.exceptionalScienceRequests = DMSurveyNode.parse("Max_Exceptional_Science_Requests", (int)8); DMContractDefs.DMSurvey.backStory = DMSurveyNode.parse("Backstory", '|', new List <string>(1) { "Something, Something, Something..." }); DMContractDefs.DMSurvey.backStory = DMUtils.formatFixStringList(DMContractDefs.DMSurvey.backStory); ConfigNode SurveyExpireNode = DMSurveyNode.GetNode("Expire"); ConfigNode SurveyFundsNode = DMSurveyNode.GetNode("Funds"); ConfigNode SurveySciNode = DMSurveyNode.GetNode("Science"); ConfigNode SurveyRepNode = DMSurveyNode.GetNode("Reputation"); if (SurveyExpireNode != null) { DMContractDefs.DMSurvey.Expire.MinimumExpireDays = SurveyExpireNode.parse("MinimumExpireDays", (int)4); DMContractDefs.DMSurvey.Expire.MaximumExpireDays = SurveyExpireNode.parse("MaximumExpireDays", (int)10); DMContractDefs.DMSurvey.Expire.DeadlineYears = SurveyExpireNode.parse("DeadlineYears", (float)1.7); } if (SurveyFundsNode != null) { DMContractDefs.DMSurvey.Funds.BaseAdvance = SurveyFundsNode.parse("BaseAdvance", (float)8500); DMContractDefs.DMSurvey.Funds.BaseReward = SurveyFundsNode.parse("BaseReward", (float)10500); DMContractDefs.DMSurvey.Funds.BaseFailure = SurveyFundsNode.parse("BaseFailure", (float)7500); DMContractDefs.DMSurvey.Funds.ParamReward = SurveyFundsNode.parse("ParamReward", (float)3000); DMContractDefs.DMSurvey.Funds.ParamFailure = SurveyFundsNode.parse("ParamFailure", (float)0); } if (SurveySciNode != null) { DMContractDefs.DMSurvey.Science.BaseReward = SurveySciNode.parse("BaseReward", (float)0); DMContractDefs.DMSurvey.Science.ParamReward = SurveySciNode.parse("ParamReward", (float)0.25); } if (SurveyRepNode != null) { DMContractDefs.DMSurvey.Reputation.BaseReward = SurveyRepNode.parse("BaseReward", (float)12); DMContractDefs.DMSurvey.Reputation.BaseFailure = SurveyRepNode.parse("BaseFailure", (float)10); DMContractDefs.DMSurvey.Reputation.ParamReward = SurveyRepNode.parse("ParamReward", (float)0); DMContractDefs.DMSurvey.Reputation.ParamFailure = SurveyRepNode.parse("ParamFailure", (float)0); } } }
private void configLoad() { //Load in global multipliers foreach (ConfigNode setNode in GameDatabase.Instance.GetConfigNodes("DM_CONTRACT_SETTINGS")) { if (setNode != null) { if (!float.TryParse(setNode.GetValue("Global_Science_Return"), out DMUtils.science)) { DMUtils.science = 1; } if (!float.TryParse(setNode.GetValue("Global_Fund_Reward"), out DMUtils.reward)) { DMUtils.reward = 1; } if (!float.TryParse(setNode.GetValue("Global_Fund_Forward"), out DMUtils.forward)) { DMUtils.forward = 1; } if (!float.TryParse(setNode.GetValue("Global_Fund_Penalty"), out DMUtils.penalty)) { DMUtils.penalty = 1; } if (!float.TryParse(setNode.GetValue("Global_Deadline"), out DMUtils.deadline)) { DMUtils.deadline = 1; } if (!int.TryParse(setNode.GetValue("Max_Survey_Offered"), out DMUtils.maxSurveyOffered)) { DMUtils.maxSurveyOffered = 2; } if (!int.TryParse(setNode.GetValue("Max_Survey_Active"), out DMUtils.maxSurveyActive)) { DMUtils.maxSurveyActive = 4; } if (!int.TryParse(setNode.GetValue("Max_Asteroid_Offered"), out DMUtils.maxAsteroidOffered)) { DMUtils.maxAsteroidOffered = 1; } if (!int.TryParse(setNode.GetValue("Max_Asteroid_Active"), out DMUtils.maxAsteroidActive)) { DMUtils.maxAsteroidActive = 3; } if (!int.TryParse(setNode.GetValue("Max_Anomaly_Offered"), out DMUtils.maxAnomalyOffered)) { DMUtils.maxAnomalyOffered = 1; } if (!int.TryParse(setNode.GetValue("Max_Anomaly_Active"), out DMUtils.maxAnomalyActive)) { DMUtils.maxAnomalyActive = 3; } if (!int.TryParse(setNode.GetValue("Max_Magnetic_Offered"), out DMUtils.maxMagneticOffered)) { DMUtils.maxMagneticOffered = 2; } if (!int.TryParse(setNode.GetValue("Max_Magnetic_Active"), out DMUtils.maxMagneticActive)) { DMUtils.maxMagneticActive = 4; } if (!float.TryParse(setNode.GetValue("Seismic_Near_Pod_Min_Distance"), out DMSeismicHandler.nearPodMinDistance)) { DMSeismicHandler.nearPodMinDistance = 10; } if (!float.TryParse(setNode.GetValue("Seismic_Near_Pod_Max_Distance"), out DMSeismicHandler.nearPodMaxDistance)) { DMSeismicHandler.nearPodMaxDistance = 2500; } if (!float.TryParse(setNode.GetValue("Seismic_Near_Pod_Threshold"), out DMSeismicHandler.nearPodThreshold)) { DMSeismicHandler.nearPodThreshold = 500; } if (!float.TryParse(setNode.GetValue("Seismic_Far_Pod_Min_Distance"), out DMSeismicHandler.farPodMinDistance)) { DMSeismicHandler.farPodMinDistance = 2500; } if (!float.TryParse(setNode.GetValue("Seismic_Far_Pod_Max_Distance"), out DMSeismicHandler.farPodMaxDistance)) { DMSeismicHandler.farPodMaxDistance = 15000; } if (!float.TryParse(setNode.GetValue("Seismic_Far_Pod_Threshold"), out DMSeismicHandler.farPodThreshold)) { DMSeismicHandler.farPodThreshold = 4000; } if (!float.TryParse(setNode.GetValue("Seismic_Pod_Min_Angle"), out DMSeismicHandler.podMinAngle)) { DMSeismicHandler.podMinAngle = 20; } if (!float.TryParse(setNode.GetValue("Seismic_Pod_Angle_Threshold"), out DMSeismicHandler.podAngleThreshold)) { DMSeismicHandler.podAngleThreshold = 90; } DMUtils.Logging("Contract Variables Set; Science Reward: {0} ; Completion Reward: {1} ; Forward Amount: {2} ; Penalty Amount: {3} ; Deadline Length: {4}", DMUtils.science, DMUtils.reward, DMUtils.forward, DMUtils.penalty, DMUtils.deadline); DMUtils.Logging("Max Contract Variables Set: Survey Offers: {0}; Active: {1} -- Asteroid Offers: {2}; Active: {3} -- Anomaly Offers: {4}; Active: {5} -- Magnetic Offers: {6}; Active: {7}", DMUtils.maxSurveyOffered, DMUtils.maxSurveyActive, DMUtils.maxAsteroidOffered, DMUtils.maxAsteroidActive, DMUtils.maxAnomalyOffered, DMUtils.maxAnomalyActive, DMUtils.maxMagneticOffered, DMUtils.maxMagneticActive); break; } else { DMUtils.Logging("Broken Config....."); } } //Load in experiment definitions foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("DM_CONTRACT_EXPERIMENT")) { if (node != null) { string name = ""; string part = ""; string agent = ""; int sitMask = 0; int bioMask = 0; int type = 0; float transmit = 0; DMScienceContainer DMscience = null; ScienceExperiment exp = null; //Some apparently not impossible errors can cause duplicate experiments to be added to the R&D science experiment dictionary try { exp = ResearchAndDevelopment.GetExperiment(node.GetValue("experimentID")); } catch (Exception e) { Debug.LogError("[DM] Whoops. Something really wrong happened here; stopping this contract experiment from loading..." + e); continue; } if (exp != null) { if (!node.HasValue("name")) { continue; } name = node.GetValue("name"); if (!int.TryParse(node.GetValue("sitMask"), out sitMask)) { continue; } if (!int.TryParse(node.GetValue("bioMask"), out bioMask)) { continue; } if (!int.TryParse(node.GetValue("type"), out type)) { continue; } if (!float.TryParse(node.GetValue("xmitDataScalar"), out transmit)) { continue; } if (node.HasValue("part")) { part = node.GetValue("part"); } else { part = "None"; } if (node.HasValue("agent")) { agent = node.GetValue("agent"); } else { agent = "Any"; } if (DMUtils.whiteListed) { exp.situationMask = (uint)sitMask; exp.biomeMask = (uint)bioMask; } DMscience = new DMScienceContainer(exp, sitMask, bioMask, (DMScienceType)type, part, agent, transmit); foreach (var sciType in Enum.GetValues(typeof(DMScienceType))) { string typeString = ((DMScienceType)sciType).ToString(); if (!string.IsNullOrEmpty(typeString)) { if (DMUtils.availableScience.ContainsKey(typeString)) { if ((DMScienceType)sciType == DMScienceType.All) { if (!DMUtils.availableScience[typeString].ContainsKey(name)) { DMUtils.availableScience[typeString].Add(name, DMscience); } } else if (((DMScienceType)type & (DMScienceType)sciType) == (DMScienceType)sciType) { if (!DMUtils.availableScience[typeString].ContainsKey(name)) { DMUtils.availableScience[typeString].Add(name, DMscience); } } } } } //DMUtils.DebugLog("New Experiment: [{0}] Available For Contracts", name); } } } DMUtils.Logging("Successfully Added {0} New Experiments To Contract List", DMUtils.availableScience["All"].Count); //foreach (var sciType in Enum.GetValues(typeof(DMScienceType))) //{ // string type = ((DMScienceType)sciType).ToString(); // if (!string.IsNullOrEmpty(type)) // { // if (DMUtils.availableScience.ContainsKey(type)) // { // if (type != "All") // DMUtils.DebugLog("Successfully Added {0} New {1} Experiments To Contract List", DMUtils.availableScience[type].Count, type); // } // } //} //Load in custom contract descriptions foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("DM_SCIENCE_STORY_DEF")) { if (node != null) { foreach (ConfigNode storyNode in node.GetNodes("DM_SCIENCE_BACKSTORY")) { if (storyNode != null) { if (storyNode.HasValue("survey")) { foreach (string so in storyNode.GetValues("survey")) { if (!string.IsNullOrEmpty(so)) { string story_o = so.Replace("[", "{"); story_o = story_o.Replace("]", "}"); DMUtils.backStory["survey"].Add(story_o); } } } if (storyNode.HasValue("asteroid")) { foreach (string sb in storyNode.GetValues("asteroid")) { if (!string.IsNullOrEmpty(sb)) { string story_b = sb.Replace("[", "{"); story_b = story_b.Replace("]", "}"); DMUtils.backStory["asteroid"].Add(story_b); } } } if (storyNode.HasValue("anomaly")) { foreach (string sb in storyNode.GetValues("anomaly")) { if (!string.IsNullOrEmpty(sb)) { string story_b = sb.Replace("[", "{"); story_b = story_b.Replace("]", "}"); DMUtils.backStory["anomaly"].Add(story_b); } } } if (storyNode.HasValue("magnetic")) { foreach (string sb in storyNode.GetValues("magnetic")) { if (!string.IsNullOrEmpty(sb)) { string story_b = sb.Replace("[", "{"); story_b = story_b.Replace("]", "}"); DMUtils.backStory["magnetic"].Add(story_b); } } } } } } } DMUtils.Logging("Added {0} New Survey Backstories; {1} New Asteroid Backstories; {2} New Anomaly Backstories; {3} New Magnetic Backstories To The List", DMUtils.backStory["survey"].Count, DMUtils.backStory["asteroid"].Count, DMUtils.backStory["anomaly"].Count, DMUtils.backStory["magnetic"].Count); }
////Generate fully random science experiment contract parameter //internal static DMCollectScience fetchScienceContract(Contract.ContractPrestige p, List<CelestialBody> cR, List<CelestialBody> cUR) //{ // DMScienceContainer scienceContainer; // CelestialBody body; // ExperimentSituations targetSituation; // List<ExperimentSituations> situations; // ScienceExperiment exp; // ScienceSubject sub; // AvailablePart aPart; // string name; // string biome = ""; // //Choose a random science experiment from our list generated at startup // scienceContainer = DMUtils.availableScience["All"].ElementAt(rand.Next(0, DMUtils.availableScience["All"].Count)).Value; // name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key; // DMUtils.DebugLog("Checking Contract Requirements"); // //Determine if the science part is available if applicable // if (scienceContainer.sciPart != "None") // { // DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart); // aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart); // if (aPart == null) // return null; // if (!ResearchAndDevelopment.PartModelPurchased(aPart)) // return null; // DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); // } // //Select a random Celestial Body based on contract prestige levels // body = DMUtils.nextTargetBody(p, cR, cUR); // if (body == null) // return null; // //Make sure our experiment is OK // exp = scienceContainer.exp; // if (exp == null) // return null; // //Choose an acceptable experimental situation for a given science experiment // if ((situations = DMUtils.availableSituations(exp, scienceContainer.sitMask, body)).Count == 0) // return null; // else // { // DMUtils.DebugLog("Acceptable Situations Found"); // targetSituation = situations[rand.Next(0, situations.Count)]; // DMUtils.DebugLog("Experimental Situation: {0}", targetSituation); // } // //Build a list of acceptable biomes if applicable, choose one with remaining science // if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed) // { // DMUtils.DebugLog("Checking For Biome Usage"); // List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation); // if (bList.Count == 0) // { // DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here"); // return null; // } // int i = rand.Next(0, 2); // if (i == 0) // { // biome = bList[rand.Next(0, bList.Count)]; // DMUtils.DebugLog("Acceptable Biome Found: {0}", biome); // } // } // //Make sure that our chosen science subject has science remaining to be gathered // if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null) // { // if (sub.scientificValue < 0.4f) // return null; // } // return new DMCollectScience(body, targetSituation, biome, name, 0); //} ////Generate random experiment for a given celestial body //internal static DMCollectScience fetchScienceContract(CelestialBody body) //{ // DMScienceContainer scienceContainer; // ExperimentSituations targetSituation; // List<ExperimentSituations> situations; // ScienceExperiment exp; // ScienceSubject sub; // AvailablePart aPart; // string name; // string biome = ""; // //Choose a random science experiment from our list generated at startup // scienceContainer = DMUtils.availableScience["All"].ElementAt(rand.Next(0, DMUtils.availableScience.Count)).Value; // name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key; // DMUtils.DebugLog("Checking Contract Requirements"); // //Determine if the science part is available if applicable // if (scienceContainer.sciPart != "None") // { // DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart); // aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart); // if (aPart == null) // return null; // if (!ResearchAndDevelopment.PartModelPurchased(aPart)) // return null; // DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); // } // //Make sure our experiment is OK // exp = scienceContainer.exp; // if (exp == null) // return null; // //Choose an acceptable experimental situation for a given science experiment // if ((situations = DMUtils.availableSituations(exp, scienceContainer.sitMask, body)).Count == 0) // return null; // else // { // DMUtils.DebugLog("Acceptable Situations Found"); // targetSituation = situations[rand.Next(0, situations.Count)]; // DMUtils.DebugLog("Experimental Situation: {0}", targetSituation); // } // //Build a list of acceptable biomes if applicable, choose one with remaining science // if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed) // { // DMUtils.DebugLog("Checking For Biome Usage"); // List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation); // if (bList.Count == 0) // { // DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here"); // return null; // } // int i = rand.Next(0, 2); // if (i == 0) // { // biome = bList[rand.Next(0, bList.Count)]; // DMUtils.DebugLog("Acceptable Biome Found: {0}", biome); // } // } // //Make sure that our chosen science subject has science remaining to be gathered // if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null) // { // if (sub.scientificValue < 0.4f) // return null; // } // return new DMCollectScience(body, targetSituation, biome, name, 0); //} ////Generate experiment for a given Celestial Body and experimental situation //internal static DMCollectScience fetchScienceContract(CelestialBody body, ExperimentSituations targetSituation) //{ // DMScienceContainer scienceContainer; // ScienceExperiment exp; // ScienceSubject sub; // AvailablePart aPart; // string name; // string biome = ""; // //Choose a random science experiment from our list generated at startup // scienceContainer = DMUtils.availableScience["All"].ElementAt(rand.Next(0, DMUtils.availableScience.Count)).Value; // name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key; // DMUtils.DebugLog("Checking Contract Requirements"); // //Determine if the science part is available if applicable // if (scienceContainer.sciPart != "None") // { // DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart); // aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart); // if (aPart == null) // return null; // if (!ResearchAndDevelopment.PartModelPurchased(aPart)) // return null; // DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); // } // //Make sure our experiment is OK // exp = scienceContainer.exp; // if (exp == null) // return null; // //Make sure that the experiment can be conducted in this situation // if (((ExperimentSituations)exp.situationMask & targetSituation) != targetSituation) // return null; // //Build a list of acceptable biomes if applicable, choose one with remaining science // if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed) // { // DMUtils.DebugLog("Checking For Biome Usage"); // List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation); // if (bList.Count == 0) // { // DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here"); // return null; // } // int i = rand.Next(0, 2); // if (i == 0) // { // biome = bList[rand.Next(0, bList.Count)]; // DMUtils.DebugLog("Acceptable Biome Found: {0}", biome); // } // } // //Make sure that our chosen science subject has science remaining to be gathered // if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null) // { // if (sub.scientificValue < 0.4f) // return null; // } // return new DMCollectScience(body, targetSituation, biome, name, 0); //} ////Generate random experiment for a given celestial body //internal static DMCollectScience fetchScienceContract(CelestialBody body, ScienceExperiment exp) //{ // DMScienceContainer scienceContainer; // ExperimentSituations targetSituation; // List<ExperimentSituations> situations; // ScienceSubject sub; // AvailablePart aPart; // string name; // string biome = ""; // //Choose science container based on a given science experiment // scienceContainer = DMUtils.availableScience["All"].FirstOrDefault(e => e.Value.exp == exp).Value; // name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == scienceContainer).Key; // DMUtils.DebugLog("Checking Contract Requirements"); // //Determine if the science part is available if applicable // if (scienceContainer.sciPart != "None") // { // DMUtils.DebugLog("Checking For Part {0} Now", scienceContainer.sciPart); // aPart = PartLoader.getPartInfoByName(scienceContainer.sciPart); // if (aPart == null) // return null; // if (!ResearchAndDevelopment.PartModelPurchased(aPart)) // return null; // DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); // } // //Make sure our experiment is OK // exp = scienceContainer.exp; // if (exp == null) // return null; // //Choose an acceptable experimental situation for a given science experiment // if ((situations = DMUtils.availableSituations(exp, scienceContainer.sitMask, body)).Count == 0) // return null; // else // { // DMUtils.DebugLog("Acceptable Situations Found"); // targetSituation = situations[rand.Next(0, situations.Count)]; // DMUtils.DebugLog("Experimental Situation: {0}", targetSituation); // } // //Build a list of acceptable biomes if applicable, choose one with remaining science // if (DMUtils.biomeRelevant(targetSituation, scienceContainer.bioMask) && targetSituation != ExperimentSituations.SrfSplashed) // { // DMUtils.DebugLog("Checking For Biome Usage"); // List<string> bList = DMUtils.fetchBiome(body, exp, targetSituation); // if (bList.Count == 0) // { // DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here"); // return null; // } // int i = rand.Next(0, 2); // if (i == 0) // { // biome = bList[rand.Next(0, bList.Count)]; // DMUtils.DebugLog("Acceptable Biome Found: {0}", biome); // } // } // //Make sure that our chosen science subject has science remaining to be gathered // if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null) // { // if (sub.scientificValue < 0.4f) // return null; // } // return new DMCollectScience(body, targetSituation, biome, name, 0); //} //Use for magnetic field survey internal static DMCollectScience fetchScienceContract(CelestialBody Body, ExperimentSituations Situation, DMScienceContainer DMScience) { AvailablePart aPart; string name; //Choose science container based on a given science experiment name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; DMUtils.DebugLog("Checking Contract Requirements"); if (DMScience.exp == null) { return(null); } //Determine if the science part is available if applicable if (DMScience.sciPart != "None") { DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart); aPart = PartLoader.getPartInfoByName(DMScience.sciPart); if (aPart == null) { return(null); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(null); } DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); } return(new DMCollectScience(Body, Situation, "", name, 1)); }
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); }
internal static DMAnomalyParameter fetchAnomalyParameter(CelestialBody Body, DMScienceContainer DMScience) { AvailablePart aPart; ExperimentSituations targetSituation; List<ExperimentSituations> situations; string name; name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; if (DMScience.Exp == null) return null; //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { aPart = PartLoader.getPartInfoByName(DMScience.SciPart); if (aPart == null) return null; if (!ResearchAndDevelopment.PartModelPurchased(aPart)) return null; } if ((situations = DMUtils.availableSituationsLimited(DMScience.Exp, DMScience.SitMask, Body)).Count == 0) return null; else { targetSituation = situations[rand.Next(0, situations.Count)]; } return new DMAnomalyParameter(targetSituation, name); }
//Used for orbital survey internal static DMCollectScience fetchSurveyScience(CelestialBody Body, DMScienceContainer DMScience) { ExperimentSituations targetSituation; ScienceSubject sub; AvailablePart aPart; string name; name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { aPart = PartLoader.getPartInfoByName(DMScience.SciPart); if (aPart == null) return null; if (!ResearchAndDevelopment.PartModelPurchased(aPart)) return null; } //Make sure our experiment is OK if (DMScience.Exp == null) return null; if (!Body.atmosphere && DMScience.Exp.requireAtmosphere) return null; if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh && ((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow) { if (rand.Next(0, 2) == 0) targetSituation = ExperimentSituations.InSpaceHigh; else targetSituation = ExperimentSituations.InSpaceLow; } else if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh) targetSituation = ExperimentSituations.InSpaceHigh; else targetSituation = ExperimentSituations.InSpaceLow; if (DMUtils.biomeRelevant(targetSituation, DMScience.BioMask)) { List<string> bList = DMUtils.fetchBiome(Body, DMScience.Exp, targetSituation); if (bList.Count == 0) { return null; } } else { string subId = string.Format("{0}@{1}{2}", DMScience.Exp.id, Body.name, targetSituation); if (ResearchAndDevelopment.GetSubjects().Any(s => s.id == subId)) { sub = ResearchAndDevelopment.GetSubjectByID(subId); if (sub.scientificValue < 0.5f) return null; } } return new DMCollectScience(Body, targetSituation, "", name, 0); }
//Used for surface surveys internal static DMCollectScience fetchSurveyScience(CelestialBody Body, DMScienceContainer DMScience, string Biome) { AvailablePart aPart; ScienceSubject sub; string name; name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; //Determine if the science part is available if applicable if (DMScience.sciPart != "None") { DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart); aPart = PartLoader.getPartInfoByName(DMScience.sciPart); if (aPart == null) { return(null); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(null); } DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); } //Make sure our experiment is OK if (DMScience.exp == null) { return(null); } if (!DMUtils.biomeRelevant(ExperimentSituations.SrfLanded, DMScience.bioMask)) { Biome = ""; } if (Body.pqsController == null) { return(null); } if (!Body.atmosphere && DMScience.exp.requireAtmosphere) { return(null); } if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.SrfLanded) != ExperimentSituations.SrfLanded) { return(null); } if (DMScience.exp.id == "dmbiodrillscan" && !Body.atmosphere) { return(null); } if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", DMScience.exp.id, Body.name, ExperimentSituations.SrfLanded, Biome.Replace(" ", "")))) != null) { if (sub.scientificValue < 0.5f) { return(null); } } return(new DMCollectScience(Body, ExperimentSituations.SrfLanded, Biome, name, 0)); }
protected override bool Generate() { if (!GetBodies_Reached(true, true).Contains(FlightGlobals.Bodies[1])) { return(false); } int total = ContractSystem.Instance.GetCurrentContracts <DMAsteroidSurveyContract>().Count(); if (total >= DMUtils.maxAsteroid) { 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 < 4; i++) { if (sciList.Count > 0) { DMScience = sciList[rand.Next(0, sciList.Count)]; newParams[i] = DMAsteroidGenerator.fetchAsteroidParameter(size, DMScience); sciList.Remove(DMScience); } else { newParams[i] = null; } } //Add in all acceptable paramaters to the contract foreach (DMAsteroidParameter DMAP in newParams) { if (DMAP != null) { this.AddParameter(DMAP, "collectDMScience"); float modifier = ((float)rand.Next(85, 116) / 100f); DMAP.SetScience(DMAP.Container.exp.baseValue * 2f * DMUtils.science * DMUtils.asteroidSubjectVal(1f, size), null); DMAP.SetFunds(8000f * DMUtils.reward * DMUtils.asteroidSubjectVal(1f, size) * modifier, 6000f * DMUtils.penalty * (size + 1) * modifier, null); DMAP.SetReputation(15f * DMUtils.reward * (size + 1) * modifier, 10f * DMUtils.penalty * (size + 1) * modifier, null); DMUtils.DebugLog("Asteroid Survey Parameter Added"); } } if (this.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(2.8f * DMUtils.deadline * primaryModifier, null); base.SetReputation(newParams.Length * 5f * DMUtils.reward * (size + 1) * primaryModifier, newParams.Length * 3f * DMUtils.penalty * primaryModifier, null); base.SetFunds(12000 * newParams.Length * DMUtils.forward * (size + 1) * primaryModifier, 11000 * newParams.Length * DMUtils.reward * (size + 1) * primaryModifier, 9000 * newParams.Length * DMUtils.penalty * (size + 1) * primaryModifier, null); return(true); }
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); }
//Used for initial orbital and surface survey parameter internal static DMCollectScience fetchSurveyScience(Contract.ContractPrestige c, List <CelestialBody> cR, List <CelestialBody> cUR, DMScienceContainer DMScience) { CelestialBody body; ExperimentSituations targetSituation; ScienceSubject sub; AvailablePart aPart; string name; string biome = ""; name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { aPart = PartLoader.getPartInfoByName(DMScience.SciPart); if (aPart == null) { return(null); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(null); } } body = DMUtils.nextTargetBody(c, cR, cUR); if (body == null) { return(null); } //Make sure our experiment is OK if (DMScience.Exp == null) { return(null); } if (!body.atmosphere && DMScience.Exp.requireAtmosphere) { return(null); } if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh && ((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceLow) == ExperimentSituations.InSpaceLow) { if (rand.Next(0, 2) == 0) { targetSituation = ExperimentSituations.InSpaceHigh; } else { targetSituation = ExperimentSituations.InSpaceLow; } } else if (((ExperimentSituations)DMScience.SitMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh) { targetSituation = ExperimentSituations.InSpaceHigh; } else { targetSituation = ExperimentSituations.InSpaceLow; } if (DMUtils.biomeRelevant(targetSituation, DMScience.BioMask) && targetSituation != ExperimentSituations.SrfSplashed) { List <string> bList = DMUtils.fetchBiome(body, DMScience.Exp, targetSituation); if (bList.Count == 0) { return(null); } else { biome = bList[rand.Next(0, bList.Count)]; } } //Make sure that our chosen science subject has science remaining to be gathered string subId = string.Format("{0}@{1}{2}{3}", DMScience.Exp.id, body.name, targetSituation, biome.Replace(" ", "")); if (ResearchAndDevelopment.GetSubjects().Any(s => s.id == subId)) { sub = ResearchAndDevelopment.GetSubjectByID(subId); if (sub.scientificValue < 0.5f) { return(null); } } return(new DMCollectScience(body, targetSituation, "", name, 0)); }
internal static DMAnomalyParameter fetchAnomalyParameter(CelestialBody Body, DMAnomalyObject City, DMScienceContainer DMScience) { AvailablePart aPart; ExperimentSituations targetSituation; List <ExperimentSituations> situations; string name; name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; if (DMScience.exp == null) { return(null); } //Determine if the science part is available if applicable if (DMScience.sciPart != "None") { DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart); aPart = PartLoader.getPartInfoByName(DMScience.sciPart); if (aPart == null) { return(null); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(null); } DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); } if ((situations = DMUtils.availableSituationsLimited(DMScience.exp, DMScience.sitMask, Body)).Count == 0) { return(null); } else { DMUtils.DebugLog("Acceptable Situations Found"); targetSituation = situations[rand.Next(0, situations.Count)]; DMUtils.DebugLog("Experimental Situation: {0}", targetSituation); } return(new DMAnomalyParameter(Body, City, targetSituation, name)); }
//Use for magnetic field survey internal static DMCollectScience fetchScienceContract(CelestialBody Body, ExperimentSituations Situation, DMScienceContainer DMScience) { AvailablePart aPart; string name; //Choose science container based on a given science experiment name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; if (DMScience.Exp == null) return null; //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { aPart = PartLoader.getPartInfoByName(DMScience.SciPart); if (aPart == null) return null; if (!ResearchAndDevelopment.PartModelPurchased(aPart)) return null; } return new DMCollectScience(Body, Situation, "", name, 1); }
//Used for initial orbital and surface survey parameter internal static DMCollectScience fetchSurveyScience(Contract.ContractPrestige c, List <CelestialBody> cR, List <CelestialBody> cUR, DMScienceContainer DMScience, int sT) { CelestialBody body; ExperimentSituations targetSituation; ScienceSubject sub; AvailablePart aPart; string name; string biome = ""; int surveyType = sT; name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; //Determine if the science part is available if applicable if (DMScience.sciPart != "None") { DMUtils.DebugLog("Checking For Part {0} Now", DMScience.sciPart); aPart = PartLoader.getPartInfoByName(DMScience.sciPart); if (aPart == null) { return(null); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(null); } DMUtils.DebugLog("Part: [{0}] Purchased; Contract Meets Requirements", aPart.name); } body = DMUtils.nextTargetBody(c, cR, cUR); DMUtils.DebugLog("Body: {0} Selected", body.name); if (body == null) { return(null); } //Make sure our experiment is OK if (DMScience.exp == null) { return(null); } if (surveyType == 0) { if (!body.atmosphere && DMScience.exp.requireAtmosphere) { return(null); } if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.InSpaceHigh) == ExperimentSituations.InSpaceHigh) { if (rand.Next(0, 2) == 0) { targetSituation = ExperimentSituations.InSpaceHigh; } else { targetSituation = ExperimentSituations.InSpaceLow; } } else { targetSituation = ExperimentSituations.InSpaceLow; } } else if (surveyType == 1) { if (body.pqsController == null) { return(null); } if (!body.atmosphere && DMScience.exp.requireAtmosphere) { return(null); } if (((ExperimentSituations)DMScience.sitMask & ExperimentSituations.SrfLanded) == ExperimentSituations.SrfLanded) { if (DMScience.exp.id != "dmbiodrillscan") { targetSituation = ExperimentSituations.SrfLanded; } else if (body.atmosphere) { targetSituation = ExperimentSituations.SrfLanded; } else { return(null); } } else { return(null); } } else if (surveyType == 2) { if (!body.atmosphere) { return(null); } if (rand.Next(0, 2) == 0) { targetSituation = ExperimentSituations.FlyingHigh; } else { targetSituation = ExperimentSituations.FlyingLow; } } else { return(null); } DMUtils.DebugLog("Experimental Situation: {0} Selected", targetSituation.ToString()); if (DMUtils.biomeRelevant(targetSituation, DMScience.bioMask) && targetSituation != ExperimentSituations.SrfSplashed) { DMUtils.DebugLog("Checking For Biome Usage"); List <string> bList = DMUtils.fetchBiome(body, DMScience.exp, targetSituation); if (bList.Count == 0) { DMUtils.DebugLog("Planet All Tapped Out; No Remaining Science Here"); return(null); } else { biome = bList[rand.Next(0, bList.Count)]; DMUtils.DebugLog("Acceptable Biome Found: {0}", biome); } } DMUtils.DebugLog("Checking For Remaining Science"); //Make sure that our chosen science subject has science remaining to be gathered if ((sub = ResearchAndDevelopment.GetSubjectByID(string.Format("{0}@{1}{2}{3}", DMScience.exp.id, body.name, targetSituation, biome.Replace(" ", "")))) != null) { if (sub.scientificValue < 0.5f) { return(null); } } if (surveyType == 0) { return(new DMCollectScience(body, targetSituation, "", name, 0)); } else if (surveyType == 1) { return(new DMCollectScience(body, targetSituation, biome, name, 0)); } else if (surveyType == 2) { return(new DMCollectScience(body, targetSituation, biome, name, 1)); } else { return(null); } }
//Use for magnetic field survey internal static DMCollectScience fetchScienceContract(CelestialBody Body, ExperimentSituations Situation, DMScienceContainer DMScience) { AvailablePart aPart; string name; //Choose science container based on a given science experiment name = DMUtils.availableScience["All"].FirstOrDefault(n => n.Value == DMScience).Key; if (DMScience.Exp == null) { return(null); } //Determine if the science part is available if applicable if (DMScience.SciPart != "None") { aPart = PartLoader.getPartInfoByName(DMScience.SciPart); if (aPart == null) { return(null); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(null); } } return(new DMCollectScience(Body, Situation, "", name, 1)); }
private void configLoad() { //Load in global multipliers foreach (ConfigNode setNode in GameDatabase.Instance.GetConfigNodes("DM_CONTRACT_SETTINGS")) { if (setNode.GetValue("name") == "Contract Settings") { DMUtils.science = float.Parse(setNode.GetValue("Global_Science_Return")); DMUtils.reward = float.Parse(setNode.GetValue("Global_Fund_Reward")); DMUtils.forward = float.Parse(setNode.GetValue("Global_Fund_Forward")); DMUtils.penalty = float.Parse(setNode.GetValue("Global_Fund_Penalty")); DMUtils.deadline = float.Parse(setNode.GetValue("Global_Deadline")); DMUtils.maxSurvey = int.Parse(setNode.GetValue("Max_Survey")); DMUtils.maxAsteroid = int.Parse(setNode.GetValue("Max_Asteroid")); DMUtils.maxAnomaly = int.Parse(setNode.GetValue("Max_Anomaly")); DMUtils.maxMagnetic = int.Parse(setNode.GetValue("Max_Magnetic")); DMUtils.Logging("Contract Variables Set; Science Reward: {0} ; Completion Reward: {1} ; Forward Amount: {2} ; Penalty Amount: {3} ; Deadline Length: {4}", DMUtils.science, DMUtils.reward, DMUtils.forward, DMUtils.penalty, DMUtils.deadline); DMUtils.Logging("Max Contract Variables Set: Survey: {0} ; Asteroid: {1} ; Anomaly: {2} ; Magnetic: {3}", DMUtils.maxSurvey, DMUtils.maxAsteroid, DMUtils.maxAnomaly, DMUtils.maxMagnetic); break; } } //Load in experiment definitions foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("DM_CONTRACT_EXPERIMENT")) { string name, part, agent = ""; int sitMask, bioMask, type = 0; float transmit = 0; DMScienceContainer DMscience = null; ScienceExperiment exp = null; //Some apparently not impossible errors can cause deplicate experiments to be added to the R&D science experiment dictionary try { exp = ResearchAndDevelopment.GetExperiment(node.GetValue("experimentID")); } catch (Exception e) { Debug.LogError("[DM] Whoops. Something really wrong happened here; stopping this contract experiment from loading..." + e); continue; } if (exp != null) { name = node.GetValue("name"); if (!int.TryParse(node.GetValue("sitMask"), out sitMask)) { continue; } if (!int.TryParse(node.GetValue("bioMask"), out bioMask)) { continue; } if (!int.TryParse(node.GetValue("type"), out type)) { continue; } if (!float.TryParse(node.GetValue("xmitDataScalar"), out transmit)) { continue; } if (node.HasValue("part")) { part = node.GetValue("part"); } else { part = "None"; } if (node.HasValue("agent")) { agent = node.GetValue("agent"); } else { agent = "Any"; } if (DMUtils.whiteListed) { exp.situationMask = (uint)sitMask; } exp.biomeMask = (uint)bioMask; DMscience = new DMScienceContainer(exp, sitMask, bioMask, (DMScienceType)type, part, agent, transmit); if (((DMScienceType)type & DMScienceType.Surface) == DMScienceType.Surface && !DMUtils.availableScience[DMScienceType.Surface.ToString()].ContainsKey(name)) { DMUtils.availableScience[DMScienceType.Surface.ToString()].Add(name, DMscience); } if (((DMScienceType)type & DMScienceType.Aerial) == DMScienceType.Aerial && !DMUtils.availableScience[DMScienceType.Aerial.ToString()].ContainsKey(name)) { DMUtils.availableScience[DMScienceType.Aerial.ToString()].Add(name, DMscience); } if (((DMScienceType)type & DMScienceType.Space) == DMScienceType.Space && !DMUtils.availableScience[DMScienceType.Space.ToString()].ContainsKey(name)) { DMUtils.availableScience[DMScienceType.Space.ToString()].Add(name, DMscience); } if (((DMScienceType)type & DMScienceType.Biological) == DMScienceType.Biological && !DMUtils.availableScience[DMScienceType.Biological.ToString()].ContainsKey(name)) { DMUtils.availableScience[DMScienceType.Biological.ToString()].Add(name, DMscience); } if (((DMScienceType)type & DMScienceType.Asteroid) == DMScienceType.Asteroid && !DMUtils.availableScience[DMScienceType.Asteroid.ToString()].ContainsKey(name)) { DMUtils.availableScience[DMScienceType.Asteroid.ToString()].Add(name, DMscience); } if (((DMScienceType)type & DMScienceType.Anomaly) == DMScienceType.Anomaly && !DMUtils.availableScience[DMScienceType.Anomaly.ToString()].ContainsKey(name)) { DMUtils.availableScience[DMScienceType.Anomaly.ToString()].Add(name, DMscience); } if (!DMUtils.availableScience["All"].ContainsKey(name)) { DMUtils.availableScience["All"].Add(name, DMscience); } DMUtils.DebugLog("New Experiment: [{0}] Available For Contracts", name); } } DMUtils.Logging("Successfully Added {0} New Experiments To Contract List", DMUtils.availableScience["All"].Count); DMUtils.DebugLog("Successfully Added {0} New Surface Experiments To Contract List", DMUtils.availableScience[DMScienceType.Surface.ToString()].Count); DMUtils.DebugLog("Successfully Added {0} New Aerial Experiments To Contract List", DMUtils.availableScience[DMScienceType.Aerial.ToString()].Count); DMUtils.DebugLog("Successfully Added {0} New Orbital Experiments To Contract List", DMUtils.availableScience[DMScienceType.Space.ToString()].Count); DMUtils.DebugLog("Successfully Added {0} New Biological Experiments To Contract List", DMUtils.availableScience[DMScienceType.Biological.ToString()].Count); DMUtils.DebugLog("Successfully Added {0} New Asteroid Experiments To Contract List", DMUtils.availableScience[DMScienceType.Asteroid.ToString()].Count); DMUtils.DebugLog("Successfully Added {0} New Anomaly Experiments To Contract List", DMUtils.availableScience[DMScienceType.Anomaly.ToString()].Count); //Load in custom contract descriptions foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("DM_SCIENCE_STORY_DEF")) { foreach (ConfigNode storyNode in node.GetNodes("DM_SCIENCE_BACKSTORY")) { foreach (string st in storyNode.GetValues("generic")) { if (!string.IsNullOrEmpty(st)) { string story = st.Replace("[", "{"); story = story.Replace("]", "}"); DMUtils.backStory["generic"].Add(story); } } foreach (string so in storyNode.GetValues("survey")) { if (!string.IsNullOrEmpty(so)) { string story_o = so.Replace("[", "{"); story_o = story_o.Replace("]", "}"); DMUtils.backStory["survey"].Add(story_o); } } foreach (string sb in storyNode.GetValues("biological")) { if (!string.IsNullOrEmpty(sb)) { string story_b = sb.Replace("[", "{"); story_b = story_b.Replace("]", "}"); DMUtils.backStory["biological"].Add(story_b); } } foreach (string sb in storyNode.GetValues("asteroid")) { if (!string.IsNullOrEmpty(sb)) { string story_b = sb.Replace("[", "{"); story_b = story_b.Replace("]", "}"); DMUtils.backStory["asteroid"].Add(story_b); } } foreach (string sb in storyNode.GetValues("anomaly")) { if (!string.IsNullOrEmpty(sb)) { string story_b = sb.Replace("[", "{"); story_b = story_b.Replace("]", "}"); DMUtils.backStory["anomaly"].Add(story_b); } } foreach (string sb in storyNode.GetValues("magnetic")) { if (!string.IsNullOrEmpty(sb)) { string story_b = sb.Replace("[", "{"); story_b = story_b.Replace("]", "}"); DMUtils.backStory["magnetic"].Add(story_b); } } } } DMUtils.Logging("Added {0} New Generic Backstories; {1} New Survey Backstories; {2} New Biological Backstories; {3} New Asteroid Backstories; {4} New Anomaly Backstories; {5} New Magnetic Backstories To The List", DMUtils.backStory["generic"].Count, DMUtils.backStory["survey"].Count, DMUtils.backStory["biological"].Count, DMUtils.backStory["asteroid"].Count, DMUtils.backStory["anomaly"].Count, DMUtils.backStory["magnetic"].Count); }
protected override bool Generate() { int total = ContractSystem.Instance.GetCurrentContracts <DMMagneticSurveyContract>().Count(); if (total >= DMUtils.maxMagnetic) { return(false); } //Make sure that the RPWS is available AvailablePart aPart = PartLoader.getPartInfoByName("rpwsAnt"); if (aPart == null) { return(false); } if (!ResearchAndDevelopment.PartModelPurchased(aPart)) { return(false); } body = DMUtils.nextTargetBody(this.Prestige, GetBodies_Reached(false, true), GetBodies_NextUnreached(4, null)); if (body == null) { return(false); } DMScienceContainer magContainer = DMUtils.availableScience["All"].FirstOrDefault(m => m.Key == "Magnetometer Scan").Value; DMScienceContainer rpwsContainer = DMUtils.availableScience["All"].FirstOrDefault(r => r.Key == "Radio Plasma Wave Scan").Value; magParams[0] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceLow, magContainer); magParams[1] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceHigh, magContainer); magParams[2] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceLow, rpwsContainer); magParams[3] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceHigh, rpwsContainer); double time = 2160000d * (double)(this.Prestige + 1) * ((double)rand.Next(6, 21) / 10d); double eccen = 0.15d * (double)(this.Prestige + 1) * ((double)rand.Next(10, 21) / 10d); if (eccen > 0.7) { eccen = 0.7; } double inclination = 20d * (double)(this.Prestige + 1) * ((double)rand.Next(8, 15) / 10d); if (inclination > 75) { inclination = 75; } DMLongOrbitParameter longParam = new DMLongOrbitParameter(body, time); DMOrbitalParameters eccentricParam = new DMOrbitalParameters(body, eccen, 0); DMOrbitalParameters inclinedParam = new DMOrbitalParameters(body, inclination, 1); this.AddParameter(longParam); longParam.AddParameter(eccentricParam); longParam.AddParameter(inclinedParam); longParam.SetFunds(50000f * DMUtils.reward * ((float)rand.Next(85, 116) / 100f), body); longParam.SetReputation(50f * DMUtils.reward * ((float)rand.Next(85, 116) / 100f), body); longParam.SetScience(60f * DMUtils.science * ((float)rand.Next(85, 116) / 100f), body); if (eccentricParam == null || inclinedParam == null) { return(false); } foreach (DMCollectScience DMCS in magParams) { if (DMCS == null) { return(false); } else { this.AddParameter(DMCS, "collectDMScience"); DMUtils.DebugLog("Added Mag Survey Param"); DMCS.SetFunds(8000f * DMUtils.reward * ((float)rand.Next(85, 116) / 100f), body); DMCS.SetReputation(25f * DMUtils.reward * ((float)rand.Next(85, 116) / 100f), body); DMCS.SetScience(25f * DMUtils.science * DMUtils.fixSubjectVal(DMCS.Situation, 1f, body), null); } } if (this.ParameterCount == 0) { return(false); } float primaryModifier = ((float)rand.Next(80, 121) / 100f); this.agent = AgentList.Instance.GetAgent("DMagic"); base.SetExpiry(10 * DMUtils.deadline, 20f * DMUtils.deadline); base.SetDeadlineDays((float)(time / KSPUtil.KerbinDay) * 3.7f * (this.GetDestinationWeight(body) / 1.8f) * DMUtils.deadline * primaryModifier, null); base.SetReputation(50f * DMUtils.reward * primaryModifier, 10f * DMUtils.penalty * primaryModifier, body); base.SetFunds(50000 * DMUtils.forward * primaryModifier, 55000 * DMUtils.reward * primaryModifier, 20000 * DMUtils.penalty * primaryModifier, body); return(true); }