/// <summary> /// Initializes a new instance of the <see cref="T:Snacks.AstronautData"/> class. /// </summary> public AstronautData() { keyValuePairs = new DictionaryValueList <string, string>(); processedResourceFailures = new Dictionary <string, int>(); processedResourceSuccesses = new Dictionary <string, int>(); rosterResources = new Dictionary <string, SnacksRosterResource>(); }
private void Awake() { if (HighLogic.LoadedSceneIsEditor) { Destroy(gameObject); return; } if (instance != null) { Destroy(gameObject); return; } instance = this; vessels = new DictionaryValueList <Guid, SEP_VesselSection>(); if (icon == null) { icon = GameDatabase.Instance.GetTexture("SurfaceExperimentPackage/Resources/Toolbar_Icon", false); } StartCoroutine(getVessels()); GameEvents.onGUIApplicationLauncherReady.Add(onReady); GameEvents.onGUIApplicationLauncherUnreadifying.Add(onUnreadifying); GameEvents.OnGameSettingsApplied.Add(onSettingsApplied); SEP_Utilities.onExperimentActivate.Add(onExpActivate); SEP_Utilities.onExperimentDeactivate.Add(onExpDeactivate); }
public TacGameSettings() { IsNewSave = true; knownCrew = new DictionaryValueList <string, CrewMemberInfo>(); knownVessels = new DictionaryValueList <Guid, VesselInfo>(); }
internal static DictionaryValueList <int, List <string> > stringSplit(string source) { DictionaryValueList <int, List <string> > result = new DictionaryValueList <int, List <string> >(); string[] groups = source.Split('|'); if (groups.Length == 0) { return(result); } for (int i = 0; i < groups.Length; i++) { string[] s = groups[i].Split(','); List <string> t = new List <string>(); for (int j = 0; j < s.Length; j++) { t.Add(s[j]); } result.Add(i, t); } return(result); }
internal static string stringConcat(DictionaryValueList <int, List <string> > source) { if (source.Count == 0) { return(""); } string[] result = new string[source.Count]; for (int i = 0; i < source.Count; i++) { List <string> group = source.At(i); if (group.Count == 0) { result[i] = "|"; continue; } string[] s = new string[group.Count]; for (int j = 0; j < group.Count; j++) { s[j] = group[j] + ","; } result[i] = string.Concat(s).TrimEnd(',') + "|"; } return(string.Concat(result).TrimEnd('|')); }
protected override bool VesselMeetsCondition(Vessel vessel) { List <Part> parts = vessel.Parts; double count = 0; foreach (var part in parts) { PartModuleList modules = part.Modules; foreach (var module in modules) { if (module.moduleName == "ModuleInventoryPart") { ModuleInventoryPart inv = (ModuleInventoryPart)module; DictionaryValueList <int, StoredPart> storedParts = inv.storedParts; for (int i = 0; i < storedParts.Count; i++) { if (storedParts[i].partName == partName) { count += storedParts[i].quantity; } } } } } return(count >= partCount); }
public TacGameSettings() { IsNewSave = true; compatible = false; file_full_version = ""; knownCrew = new DictionaryValueList <string, CrewMemberInfo>(); knownVessels = new DictionaryValueList <Guid, VesselInfo>(); }
public DMPartRequestParameter(DictionaryValueList <int, List <string> > parts, bool b, CelestialBody body) { requiredParts = parts; TargetBody = body; useWaypoints = b; getPartTitles(); this.disableOnStateChange = false; }
/// <summary> /// Create a CacheResource /// </summary> /// <param name="inputprotoPartResourceSnapshot"></param> /// <param name="resourcename"></param> /// <param name="inputamount"></param> /// <param name="maxamount"></param> public CacheResource(uint craftId, ProtoPartResourceSnapshot inputprotoPartResourceSnapshot, string resourcename, double inputamount, double maxamount) { protoPartResourceSnapshot = new DictionaryValueList <string, ProtoPartResourceSnapshot>(); this.protoPartResourceSnapshot.Add(GetKey(craftId, inputprotoPartResourceSnapshot), inputprotoPartResourceSnapshot); this.resourceName = resourcename; this.amount = inputamount; this.maxAmount = maxamount; this.timeWarpOverflow = new CacheTimeWarpBuffer(); }
public static CacheResource Load(ConfigNode node, ProtoVessel protoVessel) { string resName = ""; node.TryGetValue("resourceName", ref resName); double amt = 0; double maxamt = 0; node.TryGetValue("amount", ref amt); node.TryGetValue("maxAmount", ref maxamt); DictionaryValueList <string, ProtoPartResourceSnapshot> protoresSnapshots = new DictionaryValueList <string, ProtoPartResourceSnapshot>(); ConfigNode[] protoresourcesnapNodes = node.GetNodes("RESOURCE"); for (int rsI = 0; rsI < protoresourcesnapNodes.Length; rsI++) { string keyField = protoresourcesnapNodes[rsI].GetValue("craftID"); ProtoPartResourceSnapshot protoresSnap = new ProtoPartResourceSnapshot(protoresourcesnapNodes[rsI]); ProtoPartResourceSnapshot protoVesselResSnap = GetMatchingResourceSnapShot(keyField, protoresSnap, protoVessel); if (protoVesselResSnap != null) { protoresSnapshots.Add(keyField, protoVesselResSnap); } } if (protoresSnapshots.Count > 0) { Dictionary <string, ProtoPartResourceSnapshot> .Enumerator ppRSenumerator = protoresSnapshots.GetDictEnumerator(); ppRSenumerator.MoveNext(); string resourceKey = ""; uint craftID = CacheResource.RetrieveKey(ppRSenumerator.Current.Key, out resourceKey); CacheResource newCacheResource = new CacheResource(craftID, ppRSenumerator.Current.Value, resName, amt, maxamt); while (ppRSenumerator.MoveNext()) { newCacheResource.protoPartResourceSnapshot.Add(ppRSenumerator.Current.Key, ppRSenumerator.Current.Value); } ppRSenumerator.Dispose(); return(newCacheResource); } return(null); }
public override void OnAwake() { Utilities.Log("OnAwake in " + HighLogic.LoadedScene); base.OnAwake(); InterestedVessels = new DictionaryValueList <ProtoVessel, InterestedVessel>(); InterestingModules = new DictionaryValueList <string, ModuleType>(); InterestingModules.Add("ModuleDeployableSolarPanel", ModuleType.Producer); InterestingModules.Add("ModuleGenerator", ModuleType.Producer); InterestingModules.Add("KopernicusSolarPanel", ModuleType.Producer); InterestingModules.Add("FissionGenerator", ModuleType.Producer); InterestingModules.Add("TacGenericConverter", ModuleType.Both); InterestingModules.Add("ModuleResourceConverter", ModuleType.Both); InterestingModules.Add("DeepFreezer", ModuleType.Consumer); BackgroundProcessingInstalled = Utilities.IsModInstalled("BackgroundProcessing"); DeepFreezeInstalled = RSTUtils.Utilities.IsModInstalled("DeepFreeze"); GameEvents.onGamePause.Add(onGamePause); GameEvents.onGameUnpause.Add(onGameUnPause); GameEvents.OnGameSettingsApplied.Add(ApplySettings); if (BackgroundProcessingInstalled) { if (!loggedBackgroundProcessing) { Utilities.Log("BackgroundProcessing Mod installed. BackgroundResources not producing unloaded vessel resources.\nIt is recommended you remove BackgroundProcessing mod."); loggedBackgroundProcessing = true; } } if (FlightDriver.Pause) { onGamePause(); } if (DeepFreezeInstalled) { DFWrapper.InitDFWrapper(); } bgrSettings = new BGRSettings(); Utilities.Log("BackgroundProcessed Awake"); }
private void populateExperiments() { experiments = new DictionaryValueList <Vessel, List <SEP_ExperimentHandler> >(); int l = FlightGlobals.Vessels.Count; for (int i = 0; i < l; i++) { Vessel v = FlightGlobals.Vessels[i]; if (v == null) { continue; } if (v.vesselType == VesselType.Debris) { continue; } if (experiments.Contains(v)) { continue; } List <SEP_ExperimentHandler> handlers = new List <SEP_ExperimentHandler>(); if (v.loaded) { handlers = (from mod in v.FindPartModulesImplementing <ModuleSEPScienceExperiment>() where mod.Handler != null && mod.IsDeployed select mod.Handler).ToList(); } else { var snaps = v.protoVessel.protoPartSnapshots; int s = snaps.Count; for (int j = 0; j < s; j++) { ProtoPartSnapshot p = snaps[j]; if (!p.modules.Any(m => m.moduleName == "ModuleSEPScienceExperiment")) { continue; } var mods = p.modules; int d = mods.Count; for (int k = 0; k < d; k++) { ProtoPartModuleSnapshot mod = mods[k]; if (mod.moduleName != "ModuleSEPScienceExperiment") { continue; } if (!mod.moduleValues.HasValue("IsDeployed") || mod.moduleValues.GetValue("IsDeployed") != "True") { continue; } SEP_ExperimentHandler handler = new SEP_ExperimentHandler(mod, v); if (handler.loaded) { handlers.Add(handler); } } } } if (handlers.Count > 0) { if (VesselUtilities.VesselHasModuleName("ModuleSEPStation", v)) { experiments.Add(v, handlers); } } } setup = true; }
/// <summary> /// Saves persistent astronaut data to the supplied config node. /// </summary> /// <param name="crewData">A map of astronaut data, keyed by kerbal name.</param> /// <param name="node">The ConfigNode to save the data to.</param> public static void Save(DictionaryValueList <string, AstronautData> crewData, ConfigNode node) { List <AstronautData> .Enumerator dataValues = crewData.GetListEnumerator(); AstronautData astronautData; ConfigNode configNode; ConfigNode astronautNode; string[] keys; while (dataValues.MoveNext()) { astronautData = dataValues.Current; astronautNode = new ConfigNode(AstronautNode); astronautNode.AddValue(AstronautNodeName, astronautData.name); astronautNode.AddValue(AstronautNodeTrait, astronautData.experienceTrait); astronautNode.AddValue(AstronautNodeUpdated, astronautData.lastUpdated); astronautNode.AddValue(AstronautNodeExempt, astronautData.isExempt); if (!string.IsNullOrEmpty(astronautData.conditionSummary)) { astronautNode.AddValue(AstronautNodeCondition, astronautData.conditionSummary); } if (!string.IsNullOrEmpty(astronautData.disqualifiedPreconditions)) { astronautNode.AddValue(AstronautNodeDisqualifiers, astronautData.disqualifiedPreconditions); } //Save keyvalue pairs keys = astronautData.keyValuePairs.Keys.ToArray(); for (int index = 0; index < keys.Length; index++) { configNode = new ConfigNode(KeyValueNode); configNode.AddValue(KeyValuePairKey, keys[index]); configNode.AddValue(KeyValuePairValue, astronautData.keyValuePairs[keys[index]]); astronautNode.AddNode(configNode); } //Save resource process results keys = astronautData.processedResourceSuccesses.Keys.ToArray(); for (int index = 0; index < keys.Length; index++) { configNode = new ConfigNode(ResourceCounterNode); configNode.AddValue(ResourceCounterName, keys[index]); configNode.AddValue(ResourceCounterIsSuccess, true); configNode.AddValue(ResourceCounterValue, astronautData.processedResourceSuccesses[keys[index]]); astronautNode.AddNode(configNode); } keys = astronautData.processedResourceFailures.Keys.ToArray(); for (int index = 0; index < keys.Length; index++) { configNode = new ConfigNode(ResourceCounterNode); configNode.AddValue(ResourceCounterName, keys[index]); configNode.AddValue(ResourceCounterIsSuccess, false); configNode.AddValue(ResourceCounterValue, astronautData.processedResourceFailures[keys[index]]); astronautNode.AddNode(configNode); } //Save roster resources SnacksRosterResource.SaveToAstronautData(astronautData.rosterResources, astronautNode); node.AddNode(astronautNode); } }
/// <summary> /// Loads the astronaut data from the config node supplied. /// </summary> /// <returns>A map keyed kerbal name that contains astronaut data.</returns> /// <param name="node">The ConfigNode to read data from.</param> public static DictionaryValueList <string, AstronautData> Load(ConfigNode node) { DictionaryValueList <string, AstronautData> crewData = new DictionaryValueList <string, AstronautData>(); ConfigNode[] astronautNodess = node.GetNodes(AstronautNode); foreach (ConfigNode astronautNode in astronautNodess) { try { AstronautData astronautData = new AstronautData(); astronautData.name = astronautNode.GetValue(AstronautNodeName); astronautData.experienceTrait = astronautNode.GetValue(AstronautNodeTrait); astronautData.lastUpdated = double.Parse(astronautNode.GetValue(AstronautNodeUpdated)); astronautData.isExempt = bool.Parse(astronautNode.GetValue(AstronautNodeExempt)); if (astronautNode.HasValue(AstronautNodeCondition)) { astronautData.conditionSummary = astronautNode.GetValue(AstronautNodeCondition); } if (astronautNode.HasValue(AstronautNodeDisqualifiers)) { astronautData.disqualifiedPreconditions = astronautNode.GetValue(AstronautNodeDisqualifiers); } //Key value pairs astronautData.keyValuePairs = new DictionaryValueList <string, string>(); if (astronautNode.HasNode(KeyValueNode)) { ConfigNode[] keyValuePairs = astronautNode.GetNodes(KeyValueNode); foreach (ConfigNode keyValue in keyValuePairs) { astronautData.keyValuePairs.Add(keyValue.GetValue(KeyValuePairKey), keyValue.GetValue(KeyValuePairValue)); } } //Success/fail counters if (astronautNode.HasNode(ResourceCounterNode)) { ConfigNode[] resourceCounterNodes = astronautNode.GetNodes(ResourceCounterNode); ConfigNode counterNode; string resourceName = string.Empty; int count = 0; bool isSuccess = false; for (int index = 0; index < resourceCounterNodes.Length; index++) { counterNode = resourceCounterNodes[index]; resourceName = counterNode.GetValue(ResourceCounterName); int.TryParse(counterNode.GetValue(ResourceCounterValue), out count); isSuccess = false; bool.TryParse(counterNode.GetValue(ResourceCounterIsSuccess), out isSuccess); if (isSuccess) { astronautData.processedResourceSuccesses.Add(resourceName, count); } else { astronautData.processedResourceFailures.Add(resourceName, count); } } } //Roster resources if (astronautNode.HasNode(SnacksRosterResource.RosterResourceNode)) { astronautData.rosterResources = SnacksRosterResource.LoadFromAstronautData(astronautNode); } crewData.Add(astronautData.name, astronautData); } catch (Exception ex) { Log("error encountered: " + ex + " skipping kerbal."); continue; } } return(crewData); }
protected override bool Generate() { DMMagneticSurveyContract[] magContracts = ContractSystem.Instance.GetCurrentContracts <DMMagneticSurveyContract>(); int offers = 0; int active = 0; int maxOffers = DMContractDefs.DMMagnetic.maxOffers; int maxActive = DMContractDefs.DMMagnetic.maxActive; for (int i = 0; i < magContracts.Length; i++) { DMMagneticSurveyContract m = magContracts[i]; if (m.ContractState == State.Offered) { offers++; } else if (m.ContractState == State.Active) { active++; } } if (offers >= maxOffers) { return(false); } if (active >= maxActive) { return(false); } //Make sure that the parts are available if (!DMUtils.partAvailable(DMContractDefs.DMMagnetic.magParts) || !DMUtils.partAvailable(DMContractDefs.DMMagnetic.rpwsParts)) { return(false); } List <CelestialBody> bodies = new List <CelestialBody>(); Func <CelestialBody, bool> cb = null; switch (prestige) { case ContractPrestige.Trivial: cb = delegate(CelestialBody b) { if (b == Planetarium.fetch.Sun) { return(false); } if (b.scienceValues.RecoveryValue > 4) { return(false); } return(true); }; bodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.ORBIT, true, cb)); break; case ContractPrestige.Significant: cb = delegate(CelestialBody b) { if (b == Planetarium.fetch.Sun) { return(false); } if (b == Planetarium.fetch.Home) { return(false); } if (b.scienceValues.RecoveryValue > 8) { return(false); } return(true); }; bodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.FLYBY, true, cb)); bodies.AddRange(ProgressUtilities.GetNextUnreached(2, cb)); break; case ContractPrestige.Exceptional: cb = delegate(CelestialBody b) { if (b == Planetarium.fetch.Home) { return(false); } if (Planetarium.fetch.Home.orbitingBodies.Count > 0) { foreach (CelestialBody B in Planetarium.fetch.Home.orbitingBodies) { if (b == B) { return(false); } } } if (b.scienceValues.RecoveryValue < 4) { return(false); } return(true); }; bodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.FLYBY, true, cb)); bodies.AddRange(ProgressUtilities.GetNextUnreached(4, cb)); break; } if (bodies.Count <= 0) { return(false); } body = bodies[rand.Next(0, bodies.Count)]; if (body == null) { return(false); } DMScienceContainer magContainer = null; DMScienceContainer rpwsContainer = null; if (!DMUtils.availableScience.ContainsKey("All")) { return(false); } if (!DMUtils.availableScience["All"].ContainsKey(DMContractDefs.DMMagnetic.magnetometerExperimentTitle)) { return(false); } magContainer = DMUtils.availableScience["All"][DMContractDefs.DMMagnetic.magnetometerExperimentTitle]; if (!DMUtils.availableScience["All"].ContainsKey(DMContractDefs.DMMagnetic.rpwsExperimentTitle)) { return(false); } rpwsContainer = DMUtils.availableScience["All"][DMContractDefs.DMMagnetic.rpwsExperimentTitle]; magParams[0] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceLow, magContainer); magParams[1] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceHigh, magContainer); magParams[2] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceLow, rpwsContainer); magParams[3] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceHigh, rpwsContainer); double eccMod = 0.2; double incMod = 20; double timeMod = 2160000; switch (prestige) { case ContractPrestige.Trivial: eccMod = DMContractDefs.DMMagnetic.trivialEccentricityMultiplier; incMod = DMContractDefs.DMMagnetic.trivialInclinationMultiplier; timeMod = DMContractDefs.DMMagnetic.trivialTimeModifier * 6 * 3600; break; case ContractPrestige.Significant: eccMod = DMContractDefs.DMMagnetic.significantEccentricityMultiplier; incMod = DMContractDefs.DMMagnetic.significantInclinationMultiplier; timeMod = DMContractDefs.DMMagnetic.significantTimeModifier * 6 * 3600; break; case ContractPrestige.Exceptional: eccMod = DMContractDefs.DMMagnetic.exceptionalEccentricityMultiplier; incMod = DMContractDefs.DMMagnetic.exceptionalInclinationMultiplier; timeMod = DMContractDefs.DMMagnetic.exceptionalTimeModifier * 6 * 3600; break; } double time = timeMod * ((double)rand.Next(6, 17) / 10d); double eccen = eccMod * ((double)rand.Next(8, 13) / 10d); if (eccen > 0.7) { eccen = 0.7; } double inclination = incMod * ((double)rand.Next(7, 14) / 10d); if (inclination > 75) { inclination = 75; } DictionaryValueList <int, List <string> > parts = new DictionaryValueList <int, List <string> >(); parts.Add(0, DMContractDefs.DMMagnetic.magParts); parts.Add(1, DMContractDefs.DMMagnetic.rpwsParts); DMLongOrbitParameter longParam = new DMLongOrbitParameter(time); DMOrbitalParameters eccentricParam = new DMOrbitalParameters(eccen, 0, longParam); DMOrbitalParameters inclinedParam = new DMOrbitalParameters(inclination, 1, longParam); DMPartRequestParameter partRequest = new DMPartRequestParameter(parts, DMContractDefs.DMMagnetic.useVesselWaypoints, body); this.AddParameter(longParam); longParam.AddParameter(eccentricParam); longParam.AddParameter(inclinedParam); longParam.AddParameter(partRequest); longParam.setPartRequest(partRequest); if (eccentricParam == null || inclinedParam == null) { return(false); } //Add the science collection parent parameter DMCompleteParameter DMcp = new DMCompleteParameter(1, 0); this.AddParameter(DMcp); foreach (DMCollectScience DMCS in magParams) { if (DMCS == null) { return(false); } else { if (DMCS.Container == null) { continue; } float modifier = ((float)rand.Next(85, 116) / 100f); DMcp.addToSubParams(DMCS); DMCS.SetFunds(DMContractDefs.DMMagnetic.Funds.ParamReward * modifier, DMContractDefs.DMMagnetic.Funds.ParamFailure * modifier, body); DMCS.SetScience(DMContractDefs.DMMagnetic.Science.ParamReward * DMUtils.fixSubjectVal(DMCS.Situation, 1f, body), null); DMCS.SetReputation(DMContractDefs.DMMagnetic.Reputation.ParamReward * modifier, DMContractDefs.DMMagnetic.Reputation.ParamFailure * modifier, null); } } if (this.ParameterCount == 0) { return(false); } float primaryModifier = ((float)rand.Next(80, 121) / 100f); float diffModifier = 1 + ((float)this.Prestige * 0.5f); float Mod = primaryModifier * diffModifier; this.agent = AgentList.Instance.GetAgent("DMagic"); if (this.agent == null) { this.agent = AgentList.Instance.GetAgentRandom(); } base.SetExpiry(DMContractDefs.DMMagnetic.Expire.MinimumExpireDays, DMContractDefs.DMMagnetic.Expire.MaximumExpireDays); base.SetDeadlineDays((float)(time / 3600) * DMContractDefs.DMMagnetic.Expire.DeadlineModifier * (this.GetDestinationWeight(body) / 1.8f) * primaryModifier, null); base.SetReputation(DMContractDefs.DMMagnetic.Reputation.BaseReward * Mod, DMContractDefs.DMMagnetic.Reputation.BaseFailure * Mod, null); base.SetFunds(DMContractDefs.DMMagnetic.Funds.BaseAdvance * Mod, DMContractDefs.DMMagnetic.Funds.BaseReward * Mod, DMContractDefs.DMMagnetic.Funds.BaseFailure * Mod, body); base.SetScience(DMContractDefs.DMMagnetic.Science.BaseReward * Mod, body); return(true); }
protected override bool Generate() { DMReconContract[] reconContracts = ContractSystem.Instance.GetCurrentContracts <DMReconContract>(); int offers = 0; int active = 0; int maxOffers = DMContractDefs.DMRecon.maxOffers; int maxActive = DMContractDefs.DMRecon.maxActive; for (int i = 0; i < reconContracts.Length; i++) { DMReconContract r = reconContracts[i]; if (r.ContractState == State.Offered) { offers++; } else if (r.ContractState == State.Active) { active++; } } if (offers >= maxOffers) { return(false); } if (active >= maxActive) { return(false); } List <CelestialBody> customReachedBodies = new List <CelestialBody>(); switch (prestige) { case ContractPrestige.Trivial: Func <CelestialBody, bool> cb = delegate(CelestialBody b) { if (b == Planetarium.fetch.Sun) { return(false); } if (b.pqsController == null) { return(false); } return(true); }; customReachedBodies.AddRange(ProgressUtilities.GetBodiesProgress(ProgressType.ORBIT, true, cb)); customReachedBodies.AddRange(ProgressUtilities.GetNextUnreached(2, cb)); var activeBodies = ContractSystem.Instance.GetCurrentActiveContracts <DMReconContract>().Select(r => r.body).ToList(); customReachedBodies.RemoveAll(a => activeBodies.Contains(a)); var completedBodies = ContractSystem.Instance.GetCompletedContracts <DMReconContract>().Select(r => r.body).ToList(); customReachedBodies.RemoveAll(a => completedBodies.Contains(a)); break; case ContractPrestige.Significant: customReachedBodies = ContractSystem.Instance.GetCompletedContracts <DMReconContract>().Where(r => r.prestige == ContractPrestige.Trivial).Select(r => r.body).ToList(); var activeSigBodies = ContractSystem.Instance.GetCurrentActiveContracts <DMReconContract>().Where(r => r.prestige == ContractPrestige.Significant).Select(r => r.body).ToList(); customReachedBodies.RemoveAll(a => activeSigBodies.Contains(a)); var completedSigBodies = ContractSystem.Instance.GetCompletedContracts <DMReconContract>().Where(r => r.prestige == ContractPrestige.Significant).Select(r => r.body).ToList(); customReachedBodies.RemoveAll(a => completedSigBodies.Contains(a)); break; case ContractPrestige.Exceptional: customReachedBodies = ContractSystem.Instance.GetCompletedContracts <DMReconContract>().Where(r => r.prestige == ContractPrestige.Significant).Select(r => r.body).ToList(); var activeExcBodies = ContractSystem.Instance.GetCurrentActiveContracts <DMReconContract>().Where(r => r.prestige == ContractPrestige.Exceptional).Select(r => r.body).ToList(); customReachedBodies.RemoveAll(a => activeExcBodies.Contains(a)); var completedExcBodies = ContractSystem.Instance.GetCompletedContracts <DMReconContract>().Where(r => r.prestige == ContractPrestige.Exceptional).Select(r => r.body).ToList(); customReachedBodies.RemoveAll(a => completedExcBodies.Contains(a)); break; } if (customReachedBodies.Count <= 0) { return(false); } body = customReachedBodies[rand.Next(0, customReachedBodies.Count)]; if (body == null) { return(false); } double time = 0; OrbitType orbitType = OrbitType.POLAR; DictionaryValueList <int, List <string> > parts = new DictionaryValueList <int, List <string> >(); Orbit o = new Orbit(); double incMod = (rand.NextDouble() * 10) - 5; double timeMod = 1080000; if (!DMUtils.availableScience.ContainsKey("All")) { return(false); } DMScienceContainer container = null; switch (prestige) { case ContractPrestige.Trivial: if (!DMUtils.partAvailable(DMContractDefs.DMRecon.reconTrivialParts)) { return(false); } parts.Add(0, DMContractDefs.DMRecon.reconTrivialParts); if (!DMUtils.availableScience["All"].ContainsKey(DMContractDefs.DMRecon.trivialExperimentTitle)) { return(false); } container = DMUtils.availableScience["All"][DMContractDefs.DMRecon.trivialExperimentTitle]; o = OrbitUtilities.GenerateOrbit(this.MissionSeed, body, orbitType, 0.15, ContractDefs.Satellite.TrivialInclinationDifficulty); double st = o.semiMajorAxis - o.referenceBody.Radius; double mt = o.referenceBody.scienceValues.spaceAltitudeThreshold * 5 * .95; if (st > mt) { o.semiMajorAxis = (mt * Math.Max(0.4, rand.NextDouble())) + o.referenceBody.Radius; } timeMod = DMContractDefs.DMRecon.trivialTimeModifier * 6 * 3600; break; case ContractPrestige.Significant: if (!DMUtils.partAvailable(DMContractDefs.DMRecon.reconSignificantParts)) { return(false); } parts.Add(0, DMContractDefs.DMRecon.reconSignificantParts); if (!DMUtils.availableScience["All"].ContainsKey(DMContractDefs.DMRecon.significantExperimentTitle)) { return(false); } container = DMUtils.availableScience["All"][DMContractDefs.DMRecon.significantExperimentTitle]; if (SystemUtilities.CoinFlip(rand)) { if (CelestialUtilities.CanBodyBeKolniya(body)) { orbitType = OrbitType.KOLNIYA; } else if (CelestialUtilities.CanBodyBeTundra(body)) { orbitType = OrbitType.TUNDRA; } else { orbitType = OrbitType.POLAR; } } else { if (CelestialUtilities.CanBodyBeTundra(body)) { orbitType = OrbitType.TUNDRA; } else if (CelestialUtilities.CanBodyBeKolniya(body)) { orbitType = OrbitType.KOLNIYA; } else { orbitType = OrbitType.POLAR; } } o = OrbitUtilities.GenerateOrbit(this.MissionSeed, body, orbitType, 0.5, ContractDefs.Satellite.TrivialInclinationDifficulty); timeMod = DMContractDefs.DMRecon.significantTimeModifier * 6 * 3600; incMod = 0; break; case ContractPrestige.Exceptional: if (!DMUtils.partAvailable(DMContractDefs.DMRecon.reconExceptionalParts)) { return(false); } parts.Add(0, DMContractDefs.DMRecon.reconExceptionalParts); if (!DMUtils.availableScience["All"].ContainsKey(DMContractDefs.DMRecon.exceptionalExperimentTitle)) { return(false); } container = DMUtils.availableScience["All"][DMContractDefs.DMRecon.exceptionalExperimentTitle]; o = OrbitUtilities.GenerateOrbit(this.MissionSeed, body, orbitType, 0.15, ContractDefs.Satellite.TrivialInclinationDifficulty); double se = o.semiMajorAxis - o.referenceBody.Radius; double me = o.referenceBody.scienceValues.spaceAltitudeThreshold * 5 * .95; if (se > me) { o.semiMajorAxis = (me * Math.Max(0.4, rand.NextDouble())) + o.referenceBody.Radius; } timeMod = DMContractDefs.DMRecon.exceptionalTimeModifier * 6 * 3600; break; } if (container == null) { return(false); } time = timeMod * ((double)rand.Next(6, 17) / 10d); o.inclination += incMod; DMLongOrbitParameter longOrbit = new DMLongOrbitParameter(time); DMPartRequestParameter partRequest = new DMPartRequestParameter(parts, DMContractDefs.DMRecon.useVesselWaypoints, body); DMSpecificOrbitParameter reconParam = new DMSpecificOrbitParameter(orbitType, o.inclination, o.eccentricity, o.semiMajorAxis, o.LAN, o.argumentOfPeriapsis, o.meanAnomalyAtEpoch, o.epoch, body, ContractDefs.Satellite.SignificantDeviation, longOrbit); this.AddParameter(longOrbit); longOrbit.AddParameter(reconParam); longOrbit.AddParameter(partRequest); longOrbit.setPartRequest(partRequest); sciParams[0] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceLow, "SouthernHemisphere", container); sciParams[1] = DMCollectContractGenerator.fetchScienceContract(body, ExperimentSituations.InSpaceLow, "NorthernHemisphere", container); //Add the science collection parent parameter DMCompleteParameter DMcp = new DMCompleteParameter(1, 0); this.AddParameter(DMcp); foreach (DMCollectScience DMCS in sciParams) { if (DMCS == null) { return(false); } else { if (DMCS.Container == null) { continue; } float modifier = ((float)rand.Next(85, 116) / 100f); DMcp.addToSubParams(DMCS); DMCS.SetFunds(DMContractDefs.DMRecon.Funds.ParamReward * modifier, DMContractDefs.DMRecon.Funds.ParamFailure * modifier, body); DMCS.SetScience(DMContractDefs.DMRecon.Science.ParamReward * DMUtils.fixSubjectVal(DMCS.Situation, 1f, body), null); DMCS.SetReputation(DMContractDefs.DMRecon.Reputation.ParamReward * modifier, DMContractDefs.DMRecon.Reputation.ParamFailure * modifier, null); } } if (this.ParameterCount == 0) { return(false); } float primaryModifier = ((float)rand.Next(80, 121) / 100f); float diffModifier = 1 + ((float)this.Prestige * 0.5f); float Mod = primaryModifier * diffModifier; int t = rand.Next(0, 4); if (t == 0) { this.agent = AgentList.Instance.GetAgent("DMagic"); } else { this.agent = AgentList.Instance.GetAgentRandom(); } if (this.agent == null) { this.agent = AgentList.Instance.GetAgentRandom(); } base.SetExpiry(DMContractDefs.DMRecon.Expire.MinimumExpireDays, DMContractDefs.DMRecon.Expire.MaximumExpireDays); base.SetDeadlineDays((float)(time / 3600) * DMContractDefs.DMRecon.Expire.DeadlineModifier * (this.GetDestinationWeight(body) / 1.4f) * primaryModifier, null); base.SetReputation(DMContractDefs.DMRecon.Reputation.BaseReward * Mod, DMContractDefs.DMRecon.Reputation.BaseFailure * Mod, null); base.SetFunds(DMContractDefs.DMRecon.Funds.BaseAdvance * Mod, DMContractDefs.DMRecon.Funds.BaseReward * Mod, DMContractDefs.DMRecon.Funds.BaseFailure * Mod, body); base.SetScience(DMContractDefs.DMRecon.Science.BaseReward * Mod, body); return(true); }
protected override void OnLoad(ConfigNode node) { TargetBody = node.parse("Body", (CelestialBody)null); if (TargetBody == null) { DMUtils.Logging("Failed To Load Target Body; DM Part Request Parameter Removed"); this.Unregister(); this.Parent.RemoveParameter(this); return; } if (Root.GetType() == typeof(DMReconContract)) { useWaypoints = DMContractDefs.DMRecon.useVesselWaypoints; } else if (Root.GetType() == typeof(DMMagneticSurveyContract)) { useWaypoints = DMContractDefs.DMMagnetic.useVesselWaypoints; } else { useWaypoints = false; } string parts = node.parse("Requested_Parts", ""); if (string.IsNullOrEmpty(parts)) { DMUtils.Logging("Failed To Required Parts List; DM Part Request Parameter Removed"); this.Unregister(); this.Parent.RemoveParameter(this); return; } requiredParts = DMUtils.stringSplit(parts); getPartTitles(); vesselNames = node.parse("Vessels", ""); if (!string.IsNullOrEmpty(vesselNames) && !HighLogic.LoadedSceneIsEditor && this.Root.ContractState == Contract.State.Active) { List <Guid> ids = node.parse("Vessels", new List <Guid>()); if (ids.Count > 0) { foreach (Guid id in ids) { try { Vessel V = FlightGlobals.Vessels.FirstOrDefault(v => v.id == id); addVessel(V); DMUtils.DebugLog("Vessel {0} Loaded", V.vesselName); } catch { DMUtils.Logging("Failed To Load Vessel; DM Part Request Parameter Reset"); if (HighLogic.LoadedSceneIsFlight) { DMUtils.Logging("Checking If Currently Loaded Vessel Is Appropriate"); if (vesselEquipped(FlightGlobals.ActiveVessel, FlightGlobals.currentMainBody)) { addVessel(FlightGlobals.ActiveVessel); } } } } } } this.disableOnStateChange = false; }