public static Notes_ScienceTransfer Create(Part p, IScienceDataContainer src, Callback<CrewTransfer.DismissAction> call) { if (!stringsLoaded) loadStrings(); Notes_ScienceTransfer transfer = new GameObject("Notes_ScienceTransfer").AddComponent<Notes_ScienceTransfer>(); transfer.host = p; transfer.onDismiss = call; transfer.dataCount = src.GetScienceCount(); transfer.containers = new List<IScienceDataContainer>(1) { src }; transfer.transferSetup(); return transfer; }
/// <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); }
public int GetActiveVesselDataCount() { int dataCnt = 0; if (FlightGlobals.ActiveVessel != null) { Vessel activeVessel = FlightGlobals.ActiveVessel; int pCount = activeVessel.parts.Count; while (pCount-- > 0) { Part part = activeVessel.parts[pCount]; int mCount = part.Modules.Count; while (mCount-- > 0) { IScienceDataContainer scienceDataContainer = part.Modules[mCount] as IScienceDataContainer; if (scienceDataContainer != null) { dataCnt += scienceDataContainer.GetScienceCount(); } } } } return(dataCnt); }
internal static void TransferScience(List <Part> source, List <Part> target) { // get part modules for source and target List <IScienceDataContainer> sourceContainer = ScienceDataContainers(source, true); List <IScienceDataContainer> targetContainer = ScienceDataContainers(target); if (sourceContainer.Count <= 0 || targetContainer.Count <= 0) { return; } // Pick a destination part. Preferably the Science Lab with the most science stored, If no lab, then Science Container with most science stored. IScienceDataContainer toContainer = null; bool labFound = false; List <Part> .Enumerator p = target.GetEnumerator(); while (p.MoveNext()) { if (p.Current == null) { continue; } if (!p.Current.FindModulesImplementing <ModuleScienceLab>().Any()) { continue; } labFound = true; IScienceDataContainer m = (IScienceDataContainer)p.Current.FindModulesImplementing <ModuleScienceLab>().First(); if (m.GetScienceCount() > toContainer.GetScienceCount()) { toContainer = m; } } p.Dispose(); if (!labFound) { // if none of the above, pick the first Container, then check for the container holding the largest amount of science, and move it all there. List <Part> .Enumerator p2 = target.GetEnumerator(); while (p2.MoveNext()) { if (p2.Current == null) { continue; } if (!p2.Current.FindModulesImplementing <IScienceDataContainer>().Any()) { continue; } IScienceDataContainer m = p2.Current.FindModulesImplementing <IScienceDataContainer>().First(); if (toContainer == null) { toContainer = m; } if (m.GetScienceCount() > toContainer.GetScienceCount()) { toContainer = m; } } p2.Dispose(); } // determine if science can be moved. List <IScienceDataContainer> .Enumerator scontainer = sourceContainer.GetEnumerator(); while (scontainer.MoveNext()) { if (scontainer.Current == null) { continue; } // Move science to destination. } } scontainer.Dispose(); }
bool EmptyContainer(IScienceDataContainer container) { return(container.GetScienceCount() == 0); }