public void Transmit() { var data = dataContainer.GetData(); for (int i = 0; i < data.Length; i++) { // Use ExperimentResultDialogPage to compute the science value // This object creation modifies the data object new ExperimentResultDialogPage( experiment.part, data[i], data[i].baseTransmitValue, data[i].transmitBonus, false, string.Empty, false, new ScienceLabSearch(experiment.part.vessel, data[i]), null, null, null, null); } var transmitter = ScienceUtil.GetBestTransmitter(experiment.vessel); if (transmitter == null) { throw new InvalidOperationException("No transmitters available to transmit the data"); } transmitter.TransmitData(data.ToList()); for (int i = 0; i < data.Length; i++) { dataContainer.DumpData(data[i]); } if (experiment.useCooldown) { experiment.cooldownToGo = experiment.cooldownTimer; } }
public override void OnUpdate() { base.OnUpdate(); if (anim == null) { return; } //We're only interested in the act of inflating the module. if (isDeployed == false) { animationStarted = false; return; } //If we've completed the animation then we are done. if (animationStarted == false) { return; } //Animation may not be done yet. if (anim.isPlaying) { return; } //At this point we know that the animation was playing but has now stopped. //We also know that the animation was started. Now reset the flag. animationStarted = false; //Hide seismometer if (impactSeismometer != null) { IScienceDataContainer container = (IScienceDataContainer)impactSeismometer; BaseEvent reviewEvent = impactSeismometer.Events["reviewEvent"]; if (reviewEvent != null) { reviewEvent.guiActive = false; reviewEvent.guiActiveUnfocused = false; } //clear out the impact data if the current template isn't a geology lab if (CurrentTemplateName != "Geology Lab") { ScienceData[] dataItems = container.GetData(); if (dataItems != null) { foreach (ScienceData doomed in dataItems) { container.DumpData(doomed); } } } } checkAndShowToolTip(); }
public static void StoreData(this IScienceDataContainer container, IScienceDataContainer experiment, bool dumpDuplicates) { if (container == experiment as IScienceDataContainer) { ScreenMessages.PostScreenMessage("Container is the same as experiment!", 1f, ScreenMessageStyle.UPPER_LEFT); return; } var containerData = container.GetData(); var experimentData = experiment.GetData(); for (var i = 0; i < experimentData.Length; i++) { if (!container.HasData(experimentData[i])) { container.ReturnData(experimentData[i]); if (container.HasData(experimentData[i])) { experiment.DumpData(experimentData[i]); } else { ScreenMessages.PostScreenMessage("Container didnt store the experiment", 1f, ScreenMessageStyle.UPPER_LEFT); } } else if (dumpDuplicates) { experiment.DumpData(experimentData[i]); } } }
public override void TransmitData() { ThrowIfNotCPUVessel(); IScienceDataContainer container = module as IScienceDataContainer; ScienceData[] data = container.GetData(); List <IScienceDataTransmitter> tranList = module.vessel.FindPartModulesImplementing <IScienceDataTransmitter>(); if (tranList.Count() > 0 && data.Count() > 0) { tranList.OrderBy(ScienceUtil.GetTransmitterScore).First().TransmitData(new List <ScienceData>(data)); if (!container.IsRerunnable()) { module.SetInoperable(); } DumpData(); } else { ScreenMessages.PostScreenMessage("No transmitters available on this vessel or no data to transmit.", 4f, ScreenMessageStyle.UPPER_LEFT); } }
// remove one experiment at random from the vessel public static void RemoveData(Vessel v) { // stock science system if (!Features.Science) { // if vessel is loaded if (v.loaded) { // get all science containers/experiments with data List<IScienceDataContainer> modules = Lib.FindModules<IScienceDataContainer>(v).FindAll(k => k.GetData().Length > 0); // remove a data sample at random if (modules.Count > 0) { IScienceDataContainer container = modules[Lib.RandomInt(modules.Count)]; ScienceData[] data = container.GetData(); container.DumpData(data[Lib.RandomInt(data.Length)]); } } // if not loaded else { // get all science containers/experiments with data var modules = new List<ProtoPartModuleSnapshot>(); modules.AddRange(Lib.FindModules(v.protoVessel, "ModuleScienceContainer").FindAll(k => k.moduleValues.GetNodes("ScienceData").Length > 0)); modules.AddRange(Lib.FindModules(v.protoVessel, "ModuleScienceExperiment").FindAll(k => k.moduleValues.GetNodes("ScienceData").Length > 0)); // remove a data sample at random if (modules.Count > 0) { ProtoPartModuleSnapshot container = modules[Lib.RandomInt(modules.Count)]; ConfigNode[] data = container.moduleValues.GetNodes("ScienceData"); container.moduleValues.RemoveNode(data[Lib.RandomInt(data.Length)]); } } } // our own science system else { // select a file at random and remove it Drive drive = DB.Vessel(v).drive; if (drive.files.Count > 0) //< it should always be the case { string filename = string.Empty; int i = Lib.RandomInt(drive.files.Count); foreach (var pair in drive.files) { if (i-- == 0) { filename = pair.Key; break; } } drive.files.Remove(filename); } } }
bool ActiveContainerHasAllData(IScienceDataContainer container) { ScienceData[] datalist = container.GetData(); for (int i = 0; i < datalist.Length; i++) { if (!ActiveContainer().HasData(datalist[i])) { return(false); } } return(true); }
public static bool HasData(this IScienceDataContainer container, ScienceData data) { var dataStore = container.GetData();; var scienceCount = dataStore.Length; for (var i = 0; i < scienceCount; i++) { if (dataStore[i].subjectID == data.subjectID) { return(true); } } return(false); }
private static void TransferScience(IScienceDataContainer source, ModuleScienceContainer target) { if (source == null || target == null || source == target) { return; } ScienceData[] sd = source.GetData(); if (sd == null || sd.Length == 0) { Debug.Log("No data "); return; } if (source is ModuleScienceContainer) { foreach (ScienceData data in sd) { if (TargetAcceptsData(target, data)) { if (target.AddData(data)) { ((ModuleScienceContainer)source).RemoveData(data); } else { Debug.Log("Transfer fail"); } } } } else if (source is ModuleScienceExperiment) { if (TargetAcceptsData(target, sd[0])) { if (target.AddData(sd[0])) { ((ModuleScienceExperiment)source).DumpData(sd[0]); } else { Debug.Log("Transfer fail"); } } } }
protected override void setupPartModules() { base.setupPartModules(); //Setup the science container if (scienceContainer == null) { scienceContainer = this.part.FindModuleImplementing <ModuleScienceContainer>(); scienceContainer.Events["ReviewDataEvent"].guiActiveUnfocused = false; scienceContainer.Events["ReviewDataEvent"].guiActive = false; //Terrain uplink terrainUplinkView.part = this.part; terrainUplinkView.scienceContainer = scienceContainer; } //Kerbnet access kerbNetAccess = this.part.FindModuleImplementing <ModuleKerbNetAccess>(); if (kerbNetAccess != null) { } //Grab the seismometer (if any) foreach (PartModule mod in this.part.Modules) { if (mod.moduleName == "Seismometer") { impactSeismometer = mod; impactSensor = (IScienceDataContainer)impactSeismometer; ScienceData[] impactData = impactSensor.GetData(); foreach (ScienceData data in impactData) { scienceContainer.AddData(data); } foreach (ScienceData doomed in impactData) { impactSensor.DumpData(doomed); } break; } } }
/// <summary> /// Search through all science experiments and containers to determine whether /// they contain the specified subject. Returns true if any do. /// </summary> /// <param name="subject"></param> /// <returns></returns> private bool FindScience(string subjectId) { for (int containerIndex = 0; containerIndex < scienceContainers.Count; ++containerIndex) { IScienceDataContainer container = scienceContainers[containerIndex]; if (container.GetScienceCount() == 0) { continue; } ScienceData[] data = container.GetData(); for (int dataIndex = 0; dataIndex < data.Length; ++dataIndex) { if (data[dataIndex].subjectID == subjectId) { return(true); } } } return(false); }
private IEnumerable <string> GetVesselSubjects(Vessel v) { foreach (Part p in v.parts) { for (int i = 0; i < p.Modules.Count; i++) { IScienceDataContainer scienceContainer = p.Modules[i] as IScienceDataContainer; if (scienceContainer != null) { foreach (ScienceData data in scienceContainer.GetData()) { if (!string.IsNullOrEmpty(data.subjectID)) { yield return(data.subjectID); } } } } } }
private List <ScienceData> RecoverScienceContent() { List <ScienceData> result = new List <ScienceData>(); Dictionary <string, PartContent> contents = this.GetContent(); // Iterate through the contents, of which there may be multiple of each part. foreach (PartContent partContent in contents.Values) { // Iterate through all of the instances of this part. (stateless = false) foreach (ConfigNode partConfigNode in partContent.instances) { ProtoPartSnapshot partSnapshot = KAS_Shared.LoadProtoPartSnapshot(partConfigNode); foreach (ProtoPartModuleSnapshot moduleSnapshot in partSnapshot.modules) { // In order to load the state of the module, it must be added to a part. Temporarily add it to this // module's host part and then remove it after it is evaluated. int moduleIndex = this.part.Modules.Count; part.AddModule(moduleSnapshot.moduleName); PartModule module = moduleSnapshot.Load(this.part, ref moduleIndex); // ModuleScienceExperiment and ModuleScienceContainer implement IScienceDataContainer. Also, because KASModuleContainer // now implements IScienceDataContainer, it is conceivable that nested KAS containers with science data will be properly // recovered. if (module is IScienceDataContainer) { IScienceDataContainer scienceDataContainer = (IScienceDataContainer)module; // Duplicate science experiments are OK, the science awards are evaluated correctly by KSP. result.AddRange(scienceDataContainer.GetData()); } this.part.RemoveModule(module); } } } return(result); }
protected void setupPartModules() { //GPS if (gps == null) { gps = this.part.FindModuleImplementing<ModuleGPS>(); gps.Fields["bioName"].guiActive = false; gps.Fields["body"].guiActive = false; gps.Fields["lat"].guiActive = false; gps.Fields["lon"].guiActive = false; } //Biome Scanner if (biomeScanner == null) { biomeScanner = this.part.FindModuleImplementing<ModuleBiomeScanner>(); biomeScanner.Events["RunAnalysis"].guiActive = false; biomeScanner.Events["RunAnalysis"].guiActiveUnfocused = false; } //Setup the science container if (scienceContainer == null) { scienceContainer = this.part.FindModuleImplementing<ModuleScienceContainer>(); scienceContainer = this.part.FindModuleImplementing<ModuleScienceContainer>(); scienceContainer.Events["ReviewDataEvent"].guiActiveUnfocused = false; scienceContainer.Events["ReviewDataEvent"].guiActive = false; //Terrain uplink terrainUplinkView.part = this.part; terrainUplinkView.scienceContainer = scienceContainer; } //Grab the seismometer (if any) foreach (PartModule mod in this.part.Modules) if (mod.moduleName == "Seismometer") { impactSeismometer = mod; impactSensor = (IScienceDataContainer)impactSeismometer; ScienceData[] impactData = impactSensor.GetData(); foreach (ScienceData data in impactData) scienceContainer.AddData(data); foreach (ScienceData doomed in impactData) impactSensor.DumpData(doomed); break; } //Resource list if (resourceList == null) resourceList = ResourceMap.Instance.GetResourceItemList(HarvestTypes.Planetary, this.part.vessel.mainBody); else if (resourceList.Count == 0) resourceList = ResourceMap.Instance.GetResourceItemList(HarvestTypes.Planetary, this.part.vessel.mainBody); }
public void OnPMEvaCollectStore(IScienceDataContainer cont, int origDataCount) { //condition to meet before we signal controller Func<bool> pollForMove = () => //cont get captured into the delegate { //wait for module to collect or store if (cont.GetData().Length == origDataCount) { return false; } //alert models m_activeShip.FireScienceEvent(); m_externShip.FireScienceEvent(); return true; }; m_rightClickEvents.Add(pollForMove); }
private void transferToVessel(ScienceRelayData RelayData) { if (resultsDialog != null) { resultsDialog.Dismiss(); } if (RelayData._host == null || RelayData._data == null || RelayData._target == null || RelayData._source == null) { return; } List <ScienceRelayData> data = new List <ScienceRelayData>(); if (transferAll) { for (int i = resultsDialog.pages.Count - 1; i >= 0; i--) { ExperimentResultDialogPage page = resultsDialog.pages[i]; if (page == null) { continue; } if (page.pageData == null) { continue; } if (page.host == null) { continue; } ScienceRelayData relayData = new ScienceRelayData() { _data = page.pageData, _host = page.host, _boost = signalBoost(RelayData._boost + 1, RelayData._target, page.pageData, page.xmitDataScalar), _target = RelayData._target, _source = RelayData._source, }; relayData._data.baseTransmitValue = page.xmitDataScalar; data.Add(relayData); } } else { RelayData._data.baseTransmitValue = currentPage.xmitDataScalar; data.Add(RelayData); } for (int i = data.Count - 1; i >= 0; i--) { ScienceData d = data[i]._data; Part host = data[i]._host; List <IScienceDataContainer> containers = host.FindModulesImplementing <IScienceDataContainer>(); IScienceDataContainer hostContainer = null; for (int j = containers.Count - 1; j >= 0; j--) { hostContainer = null; IScienceDataContainer container = containers[j]; if (container == null) { continue; } ScienceData[] containerData = container.GetData(); for (int k = containerData.Length - 1; k >= 0; k--) { ScienceData dat = containerData[k]; if (dat.subjectID == d.subjectID) { hostContainer = container; break; } } if (hostContainer != null) { break; } } IScienceDataTransmitter bestTransmitter = ScienceUtil.GetBestTransmitter(RelayData._source.FindPartModulesImplementing <IScienceDataTransmitter>()); if (bestTransmitter == null) { if (CommNetScenario.CommNetEnabled) { ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_238505"), 3, ScreenMessageStyle.UPPER_CENTER); } else { ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_238507"), 3, ScreenMessageStyle.UPPER_CENTER); } } else { d.triggered = true; bestTransmitter.TransmitData(new List <ScienceData> { d }); queuedData.Add(data[i]); if (hostContainer != null) { hostContainer.DumpData(d); } } } }
public virtual bool HasData() { return(container.GetData().Any()); }
public static void ReviewContainer(IScienceDataContainer container) { if(vesselSettings.SelectData(container.GetData().OrderBy(d => d.title).First())) { UpdateScienceInfo(vesselSettings.selectedData); isVisable = true; } }
public override void OnStart(StartState state) { base.OnStart(state); SetGuiVisible(false); showResults = false; resourceList = ResourceMap.Instance.GetResourceItemList(HarvestTypes.Planetary, this.part.vessel.mainBody); gps = this.part.FindModuleImplementing <ModuleGPS>(); biomeScanner = this.part.FindModuleImplementing <ModuleBiomeScanner>(); hideStockGUI(); //Grab the seismometer (if any) foreach (PartModule mod in this.part.Modules) { if (mod.moduleName == "Seismometer") { impactSeismometer = mod; impactSensor = (IScienceDataContainer)impactSeismometer; break; } } //Create swizzler swizzler = new WBIResultsDialogSwizzler(); swizzler.onTransmit = transmitData; //Setup the science container scienceContainer = this.part.FindModuleImplementing <ModuleScienceContainer>(); scienceContainer.Events["ReviewDataEvent"].guiActiveUnfocused = false; scienceContainer.Events["ReviewDataEvent"].guiActive = false; if (impactSensor != null) { ScienceData[] impactData = impactSensor.GetData(); foreach (ScienceData data in impactData) { scienceContainer.AddData(data); } foreach (ScienceData doomed in impactData) { impactSensor.DumpData(doomed); } } //Terrain uplink terrainUplinkView.part = this.part; terrainUplinkView.scienceContainer = scienceContainer; //Elapsed time for current experiment if (ModuleIsActive()) { //Get the new elapsed time. int elapsedTimeIndex = (int)currentExperiment; elapsedTime = elapsedTimes[elapsedTimeIndex]; //Reset the research start time. cycleStartTime = Planetarium.GetUniversalTime() - elapsedTime; } CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel); biomeName = biome.name; if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.SPLASHED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH) { planetID = this.part.vessel.mainBody.flightGlobalsIndex; harvestType = (HarvestTypes)harvestID; } }