protected override bool Generate() { NE_Helper.log("Generate Contract"); if (activeContracts() >= getMaxContracts()) { NE_Helper.log("Generate Contract: Max Contracts reached: " + getMaxContracts()); return(false); } targetBody = getTargetBody(); // Assert: targetBody != null NE_Helper.log("Generate Contract: Body: " + targetBody.name); if (!setTargetExperiment(getTargetExperiment())) { return(false); } NE_Helper.log("Generate Contract: Add Parameter"); AddParameter(new Parameters.ExperimentDataDoExperimentParameter(targetBody, experiment)); AddParameter(new Parameters.ExperimentDataReturnExperimentParameter(targetBody, experiment)); NE_Helper.log("Generate Contract: set Values "); base.SetExpiry(10, 100); base.SetScience(5f, targetBody); base.SetDeadlineYears(1f, targetBody); base.SetReputation(80f, 30f, targetBody); base.SetFunds(15000f, 30000f, 5000f, targetBody); agent = AgentList.Instance.GetAgent("Nehemiah Engineering"); NE_Helper.log("Generate Contract: done Exp: " + experiment.getAbbreviation() + " Body: " + targetBody.name + " funds Adv: " + this.FundsAdvance); return(true); }
public override bool protovesselHasDoneExperiement(ProtoVessel pv, AvailablePart experiment, CelestialBody targetBody, double contractAccepted) { NE_Helper.log("KEES-Experiement stategy"); foreach (ProtoPartSnapshot part in pv.protoPartSnapshots) { NE_Helper.log("KEES-Experiement stategy, Part: " + part.partName); if (part.partName == experiment.name) { if (experimentFound(part, experiment, targetBody, contractAccepted)) { return(true); } } else if (part.partName == KEES_PC) { if (payloadCarrierFound(part, experiment, targetBody, contractAccepted)) { return(true); } } else if (isKasContainerPart(part)) { if (payloadCarrierFound(part, experiment, targetBody, contractAccepted)) { return(true); } } } return(false); }
private bool payloadCarrierFound(ProtoPartSnapshot payloadCarrier, AvailablePart experiment, CelestialBody targetBody, double contractAccepted) { NE_Helper.log("ProtoVessel recovery: payload carrier found"); string experiementModuleName = experimentModulname[experiment.name]; foreach (ProtoPartModuleSnapshot module in payloadCarrier.modules) { NE_Helper.log("ProtoVessel recovery Modulename: " + module.moduleName); if (module.moduleName == KAS_CONTAINER) { NE_Helper.log("KAS container found"); ConfigNode partConf = findExperimentModulInPC(module, experiment); if (partConf != null) { NE_Helper.log("Experiment module found"); float completed = getFloatValueFromConfigNode(partConf, OMSExperiment.COMPLETED); if (completed >= contractAccepted) { return(containsDoneExperimentData(partConf, targetBody)); } } } } return(false); }
protected override void OnRegister() { NE_Helper.log("On Register"); GameEvents.onVesselRecovered.Add(OnRecovered); if (StageRecoveryWrapper.StageRecoveryAvailable) { StageRecoveryWrapper.AddRecoverySuccessEvent(StageRecoverySuccessEvent); } }
/** Removes experimental part. * TODO: Check if there is another active contract using this part in which case we have to keep it! */ private void removeExperimentalParts() { AvailablePart ap = ExperimentFactory.getPartForExperiment(ExperimentFactory.KEMINI_EXPERIMENTS, experiment); if (ap != null && ResearchAndDevelopment.IsExperimentalPart(ap)) { NE_Helper.log("Removing experimental part: " + ap.name); ResearchAndDevelopment.RemoveExperimentalPart(ap); } }
private void addExperimentalParts() { AvailablePart ap = ExperimentFactory.getPartForExperiment(ExperimentFactory.KEMINI_EXPERIMENTS, experiment); if (ap != null && !ResearchAndDevelopment.PartModelPurchased(ap)) { NE_Helper.log("Adding experimental part: " + ap.name); ResearchAndDevelopment.AddExperimentalPart(ap); } }
private void OnRecovered(ProtoVessel pv, bool quick) { NE_Helper.log("Recovery ProtoVessel"); if (targetBody != null && experiment != null) { if (protovesselHasDoneExperiment(pv, experiment, targetBody)) { SetComplete(); } } }
private bool setTargetExperiment(ExperimentData exp) { if (exp == null) { NE_Helper.log("Generate Contract: Experiment null"); return(false); } NE_Helper.log("Generate Contract: Experiment: " + exp.getAbbreviation()); this.experiment = exp; return(true); }
private bool isKasContainerPart(ProtoPartSnapshot part) { foreach (ProtoPartModuleSnapshot module in part.modules) { NE_Helper.log("ProtoVessel recovery Modulename: " + module.moduleName); if (module.moduleName == KAS_CONTAINER) { return(true); } } return(false); }
private void OnRecovered(ProtoVessel pv) { NE_Helper.log("Recovery ProtoVessel"); if (targetBody != null && experiment != null) { NE_Helper.log("Lookingup stratege for " + experiment.name); OMSExperimentRecovery strategy = new KEESExperimentRecovery(); if (strategy.protovesselHasDoneExperiement(pv, experiment, targetBody, this.Root.DateAccepted)) { SetComplete(); } } }
protected override void OnUpdate() { base.OnUpdate(); if (lastUpdate > UnityEngine.Time.realtimeSinceStartup + 1) { return; } if (targetBody == null || experiment == null) { NE_Helper.log("targetBody or experimentType is null"); return; } lastUpdate = UnityEngine.Time.realtimeSinceStartup; Vessel vessel = FlightGlobals.ActiveVessel; if (vessel != null) { foreach (Part part in vessel.Parts) { ExperimentStorage[] ess = part.GetComponents <ExperimentStorage>(); if (ess.Length > 0) { foreach (ExperimentStorage es in ess) { ScienceData[] data = es.GetData(); foreach (ScienceData datum in data) { if (datum.subjectID.ToLower().Contains(experiment.getId().ToLower() + "@" + targetBody.name.ToLower() + "inspace")) { SetComplete(); return; } } } OMSExperiment e = part.FindModuleImplementing <OMSExperiment>(); if (e != null) { if (e.completed >= this.Root.DateAccepted) { } } } } } SetIncomplete(); }
protected bool containsDoneExperimentData(ConfigNode partConf, CelestialBody targetBody) { foreach (ConfigNode scienceData in partConf.GetNodes(SCIENCE_DATA)) { if (!scienceData.HasValue(SUBJECT_ID)) { continue; } string subjectID = scienceData.GetValue(SUBJECT_ID); NE_Helper.log("Science on Board SubjectID: " + subjectID); if (subjectID.ToLower().Contains("@" + targetBody.name.ToLower() + "inspace")) { return(true); } } return(false); }
protected override void OnUpdate() { base.OnUpdate(); if (lastUpdate > UnityEngine.Time.realtimeSinceStartup + 1) { return; } if (targetBody == null || experiment == null) { NE_Helper.log("targetBody or experimentType is null"); return; } lastUpdate = UnityEngine.Time.realtimeSinceStartup; Vessel vessel = FlightGlobals.ActiveVessel; // MKW TODO: cache all the vessel parts which are KEES experiments to avoid iterating over the entire vessel every update if (vessel != null) { for (int idx = 0, count = vessel.Parts.Count; idx < count; idx++) { var part = vessel.Parts[idx]; if (part.name == experiment.name) { OMSExperiment e = part.FindModuleImplementing <OMSExperiment>(); if (e != null) { if (e.completed >= this.Root.DateAccepted) { ScienceData[] data = e.GetData(); for (int dIdx = 0, dCount = data.Length; dIdx < dCount; dIdx++) { if (data[dIdx].subjectID.ToLower().Contains("@" + targetBody.name.ToLower() + "inspace")) { SetComplete(); return; } } } } } } } SetIncomplete(); }
private bool setTargetExperiment(Experiment exp) { if (exp == null) { NE_Helper.log("Generate Contract: Experiment null"); return(false); } AvailablePart experiment = PartLoader.getPartInfoByName(exp.getPartName()); if (experiment == null) { NE_Helper.log("Generate Contract: Experiment Part null"); return(false); } NE_Helper.log("Generate Contract: Experiment: " + exp.getAbbreviation()); this.experiment = exp; return(true); }
private ConfigNode findExperimentModulInPC(ProtoPartModuleSnapshot kasModule, AvailablePart experiment) { ConfigNode partConf = kasModule.moduleValues; foreach (ConfigNode contentPart in partConf.GetNodes(CONTENT_PART)) { NE_Helper.log("ContentPart: " + contentPart.GetValue("name")); if (contentPart.GetValue("name") == experiment.name) { foreach (ConfigNode module in contentPart.GetNodes("MODULE")) { if (module.GetValue("name") == experimentModulname[experiment.name]) { return(module); } } } } return(null); }
protected bool containsDoneExperimentData(ConfigNode partConf, CelestialBody targetBody) { var nodes = partConf.GetNodes(SCIENCE_DATA); for (int idx = 0, count = nodes.Length; idx < count; idx++) { var scienceData = nodes[idx]; if (!scienceData.HasValue(SUBJECT_ID)) { continue; } string subjectID = scienceData.GetValue(SUBJECT_ID); NE_Helper.log("Science on Board SubjectID: " + subjectID); if (subjectID.ToLower().Contains("@" + targetBody.name.ToLower() + "inspace")) { return(true); } } return(false); }
protected bool experimentFound(ProtoPartSnapshot part, AvailablePart experiment, CelestialBody targetBody, double contractAccepted) { NE_Helper.log("ProtoVessel recovery: Experiment found"); string moduleName = experimentModulname[experiment.name]; foreach (ProtoPartModuleSnapshot module in part.modules) { NE_Helper.log("ProtoVessel recovery Modulename: " + module.moduleName); if (module.moduleName == moduleName) { ConfigNode partConf = module.moduleValues; float completed = getFloatValueFromConfigNode(partConf, OMSExperiment.COMPLETED); if (completed >= contractAccepted) { return(containsDoneExperimentData(partConf, targetBody)); } } } return(false); }
protected bool experimentFound(ProtoPartSnapshot part, AvailablePart experiment, CelestialBody targetBody, double contractAccepted) { NE_Helper.log("ProtoVessel recovery: Experiment found"); string moduleName = experimentModulname[experiment.name]; for (int i = 0, count = part.modules.Count; i < count; i++) { var module = part.modules[i]; NE_Helper.log("ProtoVessel recovery Modulename: " + module.moduleName); if (module.moduleName == moduleName) { ConfigNode partConf = module.moduleValues; float completed = NE_Helper.GetValueAsFloat(partConf, OMSExperiment.COMPLETED); if (completed >= contractAccepted) { return(containsDoneExperimentData(partConf, targetBody)); } } } return(false); }
public override bool protovesselHasDoneExperiment(ProtoVessel pv, AvailablePart experiment, CelestialBody targetBody, double contractAccepted) { NE_Helper.log("KEES-Experiement stategy"); for (int i = 0, count = pv.protoPartSnapshots.Count; i < count; i++) { var part = pv.protoPartSnapshots[i]; NE_Helper.log("KEES-Experiement stategy, Part: " + part.partName); if (part.partName == experiment.name) { if (experimentFound(part, experiment, targetBody, contractAccepted)) { return(true); } } else if (payloadCarrierFound(part, experiment, targetBody, contractAccepted)) { return(true); } } return(false); }
private ConfigNode findExperimentModulInPC(ProtoPartModuleSnapshot kisModule, AvailablePart experiment) { ConfigNode partConf = kisModule.moduleValues; var itemNodes = partConf.GetNodes("ITEM"); for (int itemIdx = 0, itemCount = itemNodes.Length; itemIdx < itemCount; itemIdx++) { var item = itemNodes[itemIdx]; NE_Helper.log("ConfigNode ITEM: " + item.GetValue("partName")); if (itemNodes[itemIdx].GetValue("partName") != experiment.name) { continue; } var partNodes = item.GetNodes("PART"); for (int partIdx = 0, partCount = partNodes.Length; partIdx < partCount; partIdx++) { var part = partNodes[partIdx]; NE_Helper.log("ConfigNode PART: " + part.GetValue("name")); if (part.GetValue("name") != experiment.name) { continue; } var moduleNodes = part.GetNodes("MODULE"); var experimentModuleName = getExperimentModuleName(experiment.name); for (int moduleIdx = 0, moduleCount = moduleNodes.Length; moduleIdx < moduleCount; moduleIdx++) { var module = moduleNodes[moduleIdx]; // TODO: MKW - if experiment is a custom-defined one, this line will throw an exception! // experiment.name will not be a valid index into the experimentModulname array. if (module.GetValue("name") == experimentModuleName) { return(module); } } } } return(null); }
protected override bool Generate() { NE_Helper.log("Generate Contract"); if (activeContracts() >= getMaxKEESContracts()) { NE_Helper.log("Generate Contract: Max Contracts reached: " + getMaxKEESContracts()); return(false); } targetBody = getTargetBody(); if (targetBody == null) { NE_Helper.log("Generate Contract: Body null set Kerbin as Target"); targetBody = Planetarium.fetch.Home; } else { NE_Helper.log("Generate Contract: Body: " + targetBody.name); } if (!setTargetExperiment(getTargetExperiment())) { return(false); } NE_Helper.log("Generate Contract: Add Parameter"); AddParameter(new Parameters.KEESDoExperimentParameter(targetBody, getPartForExperiment(experiment))); AddParameter(new Parameters.KEESReturnExperimentParameter(targetBody, getPartForExperiment(experiment))); NE_Helper.log("Generate Contract: set Values "); base.SetExpiry(); base.SetScience(5f, targetBody); base.SetDeadlineYears(1f, targetBody); base.SetReputation(80f, 30f, targetBody); base.SetFunds(15000f, 30000f, 5000f, targetBody); agent = AgentList.Instance.GetAgent("Nehemiah Engineering"); NE_Helper.log("Generate Contract: done Exp: " + experiment.getAbbreviation() + " Body: " + targetBody.name + " funds Adv: " + this.FundsAdvance); return(true); }
private ConfigNode findExperimentModulInPC(ProtoPartModuleSnapshot kisModule, AvailablePart experiment) { ConfigNode partConf = kisModule.moduleValues; var itemNodes = partConf.GetNodes("ITEM"); for (int itemIdx = 0, itemCount = itemNodes.Length; itemIdx < itemCount; itemIdx++) { var item = itemNodes[itemIdx]; NE_Helper.log("ConfigNode ITEM: " + item.GetValue("partName")); if (itemNodes[itemIdx].GetValue("partName") != experiment.name) { continue; } var partNodes = item.GetNodes("PART"); for (int partIdx = 0, partCount = partNodes.Length; partIdx < partCount; partIdx++) { var part = partNodes[partIdx]; NE_Helper.log("ConfigNode PART: " + part.GetValue("name")); if (part.GetValue("name") != experiment.name) { continue; } var moduleNodes = part.GetNodes("MODULE"); for (int moduleIdx = 0, moduleCount = moduleNodes.Length; moduleIdx < moduleCount; moduleIdx++) { var module = moduleNodes[moduleIdx]; if (module.GetValue("name") == experimentModulname [experiment.name]) { return(module); } } } } return(null); }
private bool payloadCarrierFound(ProtoPartSnapshot payloadCarrier, AvailablePart experiment, CelestialBody targetBody, double contractAccepted) { NE_Helper.log("ProtoVessel recovery: payload carrier found"); for (int i = 0, count = payloadCarrier.modules.Count; i < count; i++) { var module = payloadCarrier.modules[i]; NE_Helper.log("ProtoVessel recovery Modulename: " + module.moduleName); if (module.moduleName == KIS_CONTAINER) { NE_Helper.log("KIS container found"); ConfigNode partConf = findExperimentModulInPC(module, experiment); if (partConf != null) { NE_Helper.log("Experiment module found"); float completed = NE_Helper.GetValueAsFloat(partConf, OMSExperiment.COMPLETED); if (completed >= contractAccepted) { return(containsDoneExperimentData(partConf, targetBody)); } } } } return(false); }
protected override void OnUpdate() { base.OnUpdate(); if (lastUpdate > UnityEngine.Time.realtimeSinceStartup + 1) { return; } if (targetBody == null || experiment == null) { NE_Helper.log("targetBody or experimentType is null"); return; } lastUpdate = UnityEngine.Time.realtimeSinceStartup; Vessel vessel = FlightGlobals.ActiveVessel; if (vessel != null) { ExperimentStorage[] ess = getVesselExperimentStorage(vessel); if (ess.Length > 0) { for (int idx = 0, count = ess.Length; idx < count; idx++) { var es = ess[idx]; ScienceData[] data = es.GetData(); for (int dataIdx = 0, dataCount = data.Length; dataIdx < dataCount; dataIdx++) { var datum = data[dataIdx]; if (datum.subjectID.ToLower().Contains(experiment.getId().ToLower() + "@" + targetBody.name.ToLower() + "inspace")) { SetComplete(); return; } } } } } /* MKW - Commenting this out and leaving it here because there's partially unimplemented logic which may ** need to be added later; not sure what Nehemia was trying to do there (see below). ** foreach (Part part in vessel.Parts) ** { ** ExperimentStorage[] ess = part.GetComponents<ExperimentStorage>(); ** if (ess.Length > 0) ** { ** foreach (ExperimentStorage es in ess) ** { ** ScienceData[] data = es.GetData(); ** foreach (ScienceData datum in data) ** { ** if (datum.subjectID.ToLower().Contains(experiment.getId().ToLower()+"@" + targetBody.name.ToLower() + "inspace")) ** { ** SetComplete(); ** return; ** } ** } ** } ** // ** // MKW - What was the code below supposed to achieve? As it stands it does nothing.. ** // ** OMSExperiment e = part.FindModuleImplementing<OMSExperiment>(); ** if (e != null) ** { ** if (e.completed >= this.Root.DateAccepted) ** { ** ** } ** } ** } ** } */ SetIncomplete(); }
protected override void OnFailed() { base.OnFailed(); NE_Helper.log("Failed experiment " + experiment.getAbbreviation()); removeExperimentalParts(); }