Ejemplo n.º 1
0
        public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer)
        {
            var currentExperiment = baseExperiment as DMModuleScienceAnimate;

            if ((currentExperiment as IScienceDataContainer).GetScienceCount() == 0)
            {
                _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": Experiment has no data skiping transfer. Data found: ", (currentExperiment as IScienceDataContainer).GetScienceCount(), "_", currentExperiment.experimentNumber);
                return(false);
            }
            if (!currentExperiment.IsRerunnable())
            {
                if (!_AutomatedScienceSamplerInstance.craftSettings.transferAllData)
                {
                    _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": Experiment isn't rerunnable and transferAllData is turned off.");
                    return(false);
                }
            }
            if (!_AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates)
            {
                foreach (var data in (currentExperiment as IScienceDataContainer).GetData())
                {
                    if (moduleScienceContainer.HasData(data))
                    {
                        _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": Target already has experiment and dumping is disabled.");
                        return(false);
                    }
                }
            }
            _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": We can transfer the science!");
            return(true);
        }
 private void SaveScienceData()
 {
     foreach (ScienceAIData result in results)
     {
         ScienceData scienceResult = result.CreateScienceData();
         if (!container.HasData(scienceResult))
         {
             container.AddData(scienceResult);
         }
     }
     results.Clear();
 }
Ejemplo n.º 3
0
 private static bool TargetAcceptsData(ModuleScienceContainer target, ScienceData data)
 {
     if (target.allowRepeatedSubjects)
     {
         Debug.Log(string.Format("Target {0} allows repeated subjects", target.part.partInfo.title));
         return(true);
     }
     if (target.HasData(data))
     {
         Debug.Log(string.Format("Target {0} already has data {1} and does not allow repeated subjects", target.part.partInfo.title, data.title));
         return(false);
     }
     return(true);
 }
        private bool finishTransfer(Vessel v, ScienceData d, float boost)
        {
            if (v == null)
            {
                return(false);
            }

            if (d == null)
            {
                return(false);
            }

            if (v.loaded)
            {
                List <ModuleScienceContainer> containers = v.FindPartModulesImplementing <ModuleScienceContainer>();

                if (containers.Count <= 0)
                {
                    return(false);
                }

                ModuleScienceContainer currentContainer = null;

                for (int j = containers.Count - 1; j >= 0; j--)
                {
                    ModuleScienceContainer container = containers[j];

                    if (container.capacity != 0 && container.GetData().Length >= container.capacity)
                    {
                        continue;
                    }

                    if (container.allowRepeatedSubjects)
                    {
                        currentContainer = container;
                        break;
                    }

                    if (container.HasData(d))
                    {
                        continue;
                    }

                    currentContainer = container;
                }

                if (currentContainer != null)
                {
                    d.triggered         = false;
                    d.dataAmount       *= (d.baseTransmitValue * (1 + boost));
                    d.transmitBonus     = 1;
                    d.baseTransmitValue = 1;
                    return(currentContainer.AddData(d));
                }
            }
            else
            {
                List <ProtoPartSnapshot> containers = getProtoContainers(v.protoVessel);

                if (containers.Count <= 0)
                {
                    return(false);
                }

                ProtoPartModuleSnapshot currentContainer = null;

                uint host = 0;

                for (int j = containers.Count - 1; j >= 0; j--)
                {
                    ProtoPartSnapshot container = containers[j];

                    host = container.flightID;

                    ProtoPartModuleSnapshot tempContainer = null;

                    for (int k = container.modules.Count - 1; k >= 0; k--)
                    {
                        ProtoPartModuleSnapshot mod = container.modules[k];

                        if (mod.moduleName != "ModuleScienceContainer")
                        {
                            continue;
                        }

                        tempContainer = mod;

                        break;
                    }

                    if (tempContainer == null)
                    {
                        continue;
                    }

                    List <ScienceData> protoData = new List <ScienceData>();

                    ConfigNode[] science = tempContainer.moduleValues.GetNodes("ScienceData");

                    for (int l = science.Length - 1; l >= 0; l--)
                    {
                        ConfigNode node = science[l];

                        protoData.Add(new ScienceData(node));
                    }

                    Part prefab = container.partInfo.partPrefab;

                    ModuleScienceContainer prefabContainer = prefab.FindModuleImplementing <ModuleScienceContainer>();

                    if (prefabContainer != null)
                    {
                        if (prefabContainer.capacity != 0 && protoData.Count >= prefabContainer.capacity)
                        {
                            continue;
                        }

                        if (prefabContainer.allowRepeatedSubjects)
                        {
                            currentContainer = tempContainer;
                            break;
                        }

                        if (HasData(d.subjectID, protoData))
                        {
                            continue;
                        }

                        currentContainer = tempContainer;
                    }
                }

                if (currentContainer != null)
                {
                    d.triggered         = false;
                    d.dataAmount        = d.dataAmount * (d.baseTransmitValue * (boost + 1));
                    d.transmitBonus     = 1;
                    d.baseTransmitValue = 1;
                    d.container         = host;
                    d.Save(currentContainer.moduleValues.AddNode("ScienceData"));
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
        public void UpdateExternMove(int reviewIndex, ModuleScienceContainer dst, Action endFunc)
        {
            int i = reviewIndex;
            List<DataPage> selection = m_selectedLists[i];
            GUIView view = m_guiViews[i];

            view.Update();

            //lock appropriate actions for selection that [we set to/user clicked on] the view
            if (m_selectedDirty[i] || view.m_dirtySelection)
            {
                Debug.Log("GA controller active selection button locking");

                //when user has changed selection
                if (!m_selectedDirty[i])
                {
                    selection.Clear();
                    selection.AddRange(view.selectedDataPages);
                }

                //knowing dst up front, we can screen for repeats wrt container
                if (dst.allowRepeatedSubjects) { m_moveEnabled = true; }
                else { m_moveEnabled = selection.Exists(dp => !dst.HasData(dp.m_scienceData)); }
                //scientists can additionally use discard
                m_discardEnabled = m_activeShip.m_scientistAboard;
                //in collect mode, we disallow lab and transmit
                m_labEnabled = m_transEnabled = false;

                //locks as told, and clears view dirty select flag
                view.SetViewInfo(m_discardEnabled, m_moveEnabled, m_labEnabled, m_transEnabled);
                m_selectedDirty[i] = false;
            }

            //action button handling
            if (view.m_closeBtn)
            {
                CloseDialog();
            }

            //TODOJEFFGIFFEN should use reset on showReset bool
            if (view.m_discardBtn && m_discardEnabled)
            {
                m_shipModels[i].ProcessDiscardDatas(selection, ExternDiscardEnd);
                CloseDialog();
            }

            //move btn
            if (view.m_moveBtn && m_moveEnabled)
            {
                //partial selection: discard repeats wrt container
                selection = PruneDuplicates(dst, selection);

                m_shipModels[i].ProcessMoveDatas(dst, selection, endFunc);
                CloseDialog();
            }
        }
Ejemplo n.º 6
0
 public List<DataPage> PruneDuplicates(ModuleScienceContainer dst, List<DataPage> pages)
 {
     //partial selection: discard repeats wrt container
     if (!dst.allowRepeatedSubjects)
     {
         int duplicates = pages.RemoveAll(dp => dst.HasData(dp.m_scienceData));
         if (duplicates > 0) { WarnMessage("Can't move " + duplicates + " results, identical ones in destination."); }
     }
     return pages;
 }