示例#1
0
        public static void Load(ConfigNode node)
        {
            // RnD subjects don't exists in sandbox
            if (!Science.GameHasRnD)
            {
                // load sandbox science subjects
                sandboxSubjects.Clear();
                if (node.HasNode("sandboxScienceSubjects"))
                {
                    foreach (var subjectNode in node.GetNode("sandboxScienceSubjects").GetNodes())
                    {
                        ScienceSubject subject = new ScienceSubject(subjectNode);
                        sandboxSubjects.Add(subject.id, subject);
                    }
                }
            }
            else
            {
                // Load API subjects (require RnD)
                subjectsReceivedBuffer.Clear();
                subjectsReceivedValueBuffer.Clear();
                ConfigNode APISubjects = new ConfigNode();
                if (node.TryGetNode("APISubjects", ref APISubjects))
                {
                    foreach (ConfigNode subjectNode in APISubjects.GetNodes("Subject"))
                    {
                        string         subjectId = Lib.ConfigValue(subjectNode, "subjectId", string.Empty);
                        ScienceSubject subject   = ResearchAndDevelopment.GetSubjectByID(subjectId);
                        if (subject == null)
                        {
                            Lib.Log($"Warning : API subject '{subjectId}' not found in ResearchAndDevelopment");
                            continue;
                        }
                        subjectsReceivedBuffer.Add(subject);
                        subjectsReceivedValueBuffer.Add(Lib.ConfigValue(subjectNode, "science", 0.0));
                    }
                }
            }

            // load uncredited science (transmission buffer)
            uncreditedScience = Lib.ConfigValue(node, "uncreditedScience", 0.0);

            // Rebuild the list of persisted subjects
            persistedSubjects.Clear();
            foreach (ExperimentInfo expInfo in experiments.Values)
            {
                foreach (SubjectData subjectData in subjectByExpThenSituationId[expInfo].Values)
                {
                    subjectData.CheckRnD();
                    subjectData.ClearDataCollectedInFlight();
                }
            }

            // load science subjects persisted data
            if (node.HasNode("subjectData"))
            {
                foreach (var subjectNode in node.GetNode("subjectData").GetNodes())
                {
                    string      integerSubjectId = DB.From_safe_key(subjectNode.name);
                    SubjectData subjectData      = GetSubjectData(integerSubjectId);
                    if (subjectData != null)
                    {
                        subjectData.Load(subjectNode);
                    }
                }
            }

            //if (ResearchAndDevelopment.Instance == null)
            //	Lib.Log("ERROR : ResearchAndDevelopment.Instance is null on subjects load !");

            // remove unknown subjects from the database
            foreach (SubjectData subjectData in unknownSubjectDatas.Values)
            {
                int bodyIndex;
                int scienceSituation;
                int biomeIndex;

                Situation.IdToFields(subjectData.Situation.Id, out bodyIndex, out scienceSituation, out biomeIndex);

                expBodiesSituationsBiomesSubject.RemoveSubject(subjectData.ExpInfo, bodyIndex, (ScienceSituation)scienceSituation, biomeIndex, subjectData);
            }

            // clear the list
            unknownSubjectDatas.Clear();


            // find them again
            IEnumerable <ScienceSubject> stockSubjects;

            if (Science.GameHasRnD)
            {
                stockSubjects = ResearchAndDevelopment.GetSubjects();
            }
            else
            {
                stockSubjects = sandboxSubjects.Values;
            }

            foreach (ScienceSubject stockSubject in stockSubjects)
            {
                if (!knownStockSubjectsId.Contains(stockSubject.id))
                {
                    GetSubjectDataFromStockId(stockSubject.id, stockSubject);
                }
            }
        }
示例#2
0
        public static void Load(ConfigNode node)
        {
            // RnD subjects don't exists in sandbox
            if (!Science.GameHasRnD)
            {
                return;
            }

            // load uncredited science (transmission buffer)
            uncreditedScience = Lib.ConfigValue(node, "uncreditedScience", 0.0);

            // Rebuild the list of persisted subjects
            persistedSubjects.Clear();
            foreach (ExperimentInfo expInfo in experiments.Values)
            {
                foreach (SubjectData subjectData in subjectByExpThenSituationId[expInfo].Values)
                {
                    subjectData.CheckRnD();
                    subjectData.ClearDataCollectedInFlight();
                }
            }

            // load science subjects persisted data
            if (node.HasNode("subjectData"))
            {
                foreach (var subjectNode in node.GetNode("subjectData").GetNodes())
                {
                    string      integerSubjectId = DB.From_safe_key(subjectNode.name);
                    SubjectData subjectData      = GetSubjectData(integerSubjectId);
                    if (subjectData != null)
                    {
                        subjectData.Load(subjectNode);
                    }
                }
            }

            if (ResearchAndDevelopment.Instance == null)
            {
                Lib.Log("ERROR : ResearchAndDevelopment.Instance is null on subjects load !");
            }

            // remove unknown subjects from the database
            foreach (SubjectData subjectData in unknownSubjectDatas.Values)
            {
                int bodyIndex;
                int scienceSituation;
                int biomeIndex;

                Situation.IdToFields(subjectData.Situation.Id, out bodyIndex, out scienceSituation, out biomeIndex);

                expBodiesSituationsBiomesSubject.RemoveSubject(subjectData.ExpInfo, bodyIndex, (ScienceSituation)scienceSituation, biomeIndex, subjectData);
                bodiesSituationsBiomesSubjects.RemoveSubject(bodyIndex, (ScienceSituation)scienceSituation, biomeIndex, subjectData);
            }

            // clear the list
            unknownSubjectDatas.Clear();


            // find them again
            foreach (ScienceSubject stockSubject in ResearchAndDevelopment.GetSubjects())
            {
                if (!knownStockSubjectsId.Contains(stockSubject.id))
                {
                    GetSubjectDataFromStockId(stockSubject.id, stockSubject);
                }
            }
        }