Beispiel #1
0
        public bool ContributeResearch(TieredResource source, string atBody, double timespentInKerbalSeconds)
        {
            if (!this.categoryToBodyToProgressMap.TryGetValue(source.ResearchCategory, out Dictionary <string, TechProgress> bodyToProgressMap))
            {
                bodyToProgressMap = new Dictionary <string, TechProgress>();
                this.categoryToBodyToProgressMap.Add(source.ResearchCategory, bodyToProgressMap);
            }

            string bodyName = source.ProductionRestriction == ProductionRestriction.Space ? "" : atBody;

            if (!bodyToProgressMap.TryGetValue(bodyName, out TechProgress progress))
            {
                progress = new TechProgress()
                {
                    ProgressInKerbalSeconds = 0, Tier = TechTier.Tier0
                };
                bodyToProgressMap.Add(bodyName, progress);
            }

            progress.ProgressInKerbalSeconds += timespentInKerbalSeconds;
            if (progress.ProgressInKerbalSeconds > KerbalTime.KerbalYearsToSeconds(source.ResearchCategory.KerbalYearsToNextTier(progress.Tier)))
            {
                progress.ProgressInKerbalSeconds = 0;
                ++progress.Tier;
                if (progress.Tier == TechTier.Tier1 && this.EligibleToSkipTier1(source.ResearchCategory))
                {
                    ++progress.Tier;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        private static ConfigNode ToNode(TechProgress progress)
        {
            ConfigNode bodyNode = new ConfigNode();

            bodyNode.AddValue("tier", progress.Tier.ToString());
            bodyNode.AddValue("progress", progress.ProgressInKerbalSeconds);
            return(bodyNode);
        }
Beispiel #3
0
        private static bool TryCreateFromNode(ConfigNode node, out TechProgress progress)
        {
            TechTier tierAtBody     = TechTier.Tier0;
            double   progressToNext = 0;

            if (!node.TryGetEnum <TechTier>("tier", ref tierAtBody, TechTier.Tier0) ||
                !node.TryGetValue("progress", ref progressToNext))
            {
                progress = null;
                return(false);
            }

            progress = new TechProgress()
            {
                ProgressInKerbalSeconds = progressToNext,
                Tier = tierAtBody
            };
            return(true);
        }