public override bool MeetRequirements() { CelestialBodySubtree progress = null; foreach (var node in ProgressTracking.Instance.celestialBodyNodes) { if (node.Body == Planetarium.fetch.Home) { progress = node; } } if (progress == null) { StnSciScenario.LogError("ProgressNode for Kerbin not found, terminating"); return(false); } if (progress.orbit.IsComplete && (IsPartUnlocked("dockingPort1") || IsPartUnlocked("dockingPort2") || IsPartUnlocked("dockingPort3") || IsPartUnlocked("dockingPortLarge") || IsPartUnlocked("dockingPortLateral")) && (IsPartUnlocked("StnSciLab") || IsPartUnlocked("StnSciCyclo"))) { return(true); } return(false); }
private void OnRecovered(ProtoVessel pv, bool dummy) { CelestialBody targetBody = StnSciParameter.getTargetBody(this); AvailablePart experimentType = StnSciParameter.getExperimentType(this); if (targetBody == null || experimentType == null) { return; } foreach (ProtoPartSnapshot part in pv.protoPartSnapshots) { if (part.partName == experimentType.name) { foreach (ProtoPartModuleSnapshot module in part.modules) { if (module.moduleName == "StationExperiment") { ConfigNode cn = module.moduleValues; if (!cn.HasValue("launched") || !cn.HasValue("completed")) { continue; } float launched, completed; try { launched = float.Parse(cn.GetValue("launched")); completed = float.Parse(cn.GetValue("completed")); } catch (Exception e) { StnSciScenario.LogError(e.ToString()); continue; } if (launched >= this.Root.DateAccepted && completed >= launched) { foreach (ConfigNode datum in cn.GetNodes("ScienceData")) { if (!datum.HasValue("subjectID")) { continue; } string subjectID = datum.GetValue("subjectID"); if (subjectID.ToLower().Contains("@" + targetBody.name.ToLower() + "inspace")) { StnSciParameter parent = this.Parent as StnSciParameter; SetComplete(); if (parent != null) { parent.Complete(); } return; } } } } } } } }
private bool SetTarget(string planet) { targetBody = FlightGlobals.Bodies.FirstOrDefault(body => body.bodyName.ToLower() == planet.ToLower()); if (targetBody == null) { StnSciScenario.LogError("Couldn't find planet: " + planet); return(false); } return(true); }
private bool SetExperiment(string exp) { experimentType = PartLoader.getPartInfoByName(exp); if (experimentType == null) { StnSciScenario.LogError("Couldn't find experiment part: " + exp); return(false); } return(true); }
protected override bool Generate() { StnSciScenario.Log("Considering a StatSci contract"); if (ActiveCount() >= StnSciScenario.Instance.settings.maxContracts) { /*StnSciScenario.Log("StationScience contracts cap hit (" + * StnSciScenario.Instance.settings.maxContracts + ").");*/ return(false); } double xp = StnSciScenario.Instance.xp + Reputation.Instance.reputation * StnSciScenario.Instance.settings.reputationFactor; if (this.Prestige == ContractPrestige.Trivial) { xp *= StnSciScenario.Instance.settings.trivialMultiplier; } if (this.Prestige == ContractPrestige.Significant) { xp *= StnSciScenario.Instance.settings.significantMultiplier; } if (this.Prestige == ContractPrestige.Exceptional) { xp *= StnSciScenario.Instance.settings.exceptionalMultiplier; } if (xp <= 0.5) { xp = 0.5; } StnSciScenario.Log("checking unlocked experiements"); List <string> experiments = GetUnlockedExperiments(); StnSciScenario.Log("experiements = " + experiments + " checking unlocked bodies"); List <CelestialBody> bodies = GetBodies_Reached(true, false); StnSciScenario.Log("bodies = " + bodies); List <ContractCandidate> candidates = new List <ContractCandidate>(); double totalWeight = 0.0; //Get most difficult combination of planet and experiment that doesn't exceed random difficulty target foreach (var exp in experiments) { StnSciScenario.Log("Experiment: " + exp); double expValue; try { expValue = StnSciScenario.Instance.settings.experimentChallenge[exp]; } catch (KeyNotFoundException) { continue; } foreach (var body in bodies) { StnSciScenario.Log("Body: " + body.name); int acount = ActiveCount(exp, body); if (acount > 0) { StnSciScenario.Log("Contract already active!"); continue; } double plaValue; try { plaValue = StnSciScenario.Instance.settings.planetChallenge[body.name]; } catch (KeyNotFoundException) { continue; } ContractCandidate candidate = new ContractCandidate(); candidate.body = body; candidate.experiment = exp; candidate.value = expValue * plaValue; /* log-gaussian function; * when val equals xp, weight is 1 * when val is half of xp, weight is .5 */ candidate.weight = Math.Exp(-Math.Pow(Math.Log(candidate.value / xp, 2), 2) / (2 * Math.Pow(2 / 2.355, 2))); candidates.Add(candidate); totalWeight += candidate.weight; } } StnSciScenario.Log("Candidate List: " + candidates.Count); double rand = GetUniform() * totalWeight; ContractCandidate chosen = null; foreach (var cand in candidates) { if (rand <= cand.weight) { chosen = cand; break; } rand -= cand.weight; } if (chosen == null) { StnSciScenario.LogError("Couldn't find appropriate planet/experiment!"); return(false); } if (!SetExperiment(chosen.experiment)) { return(false); } targetBody = chosen.body; this.value = chosen.value; this.AddParameter(new Parameters.StnSciParameter(experimentType, targetBody), null); int ccount = CompletedCount(experimentType.name, targetBody); bool first_time = (ccount == 0); float v = (float)this.value; base.SetExpiry(); float sciReward = StnSciScenario.Instance.settings.contractScience.calcReward(v, first_time); StnSciScenario.Log("SciReward: " + sciReward); base.SetScience(sciReward, targetBody); base.SetDeadlineYears(StnSciScenario.Instance.settings.contractDeadline.calcReward(v, first_time), targetBody); base.SetReputation(StnSciScenario.Instance.settings.contractReputation.calcReward(v, first_time), StnSciScenario.Instance.settings.contractReputation.calcFailure(v, first_time), targetBody); base.SetFunds(StnSciScenario.Instance.settings.contractFunds.calcAdvance(v, first_time), StnSciScenario.Instance.settings.contractFunds.calcReward(v, first_time), StnSciScenario.Instance.settings.contractFunds.calcFailure(v, first_time), targetBody); return(true); }