コード例 #1
0
        public static void BuildingPresent_Postfix(ResearchProjectDef research, ref bool __result)
        {
            if (__result == true)
            {
                return;
            }

            bool flag = false;

            if (research.requiredResearchBuilding != null)
            {
                flag = Find.Maps.SelectMany((Map map) => map.listerBuildings.allBuildingsColonist).OfType <Building_WorkTable>().Any((Building_WorkTable b) => research.Alt_CanBeResearchedAt(b));
            }
            if (flag)
            {
                flag = research.Ancestors().All(new Func <ResearchProjectDef, bool>(BuildingPresent));
            }

            if (flag)
            {
                _buildingPresentCache.Remove(research);
                _buildingPresentCache.Add(research, flag);
            }

            __result = flag;
        }
コード例 #2
0
        public static List <ThingDef> MissingFacilities(ResearchProjectDef research)
        {
            // try get from cache
            List <ThingDef> missing;

            if (_missingFacilitiesCache.TryGetValue(research, out missing))
            {
                return(missing);
            }

            // get list of all researches required before this
            var thisAndPrerequisites = research.Ancestors().Where(rpd => !rpd.IsFinished).ToList();

            thisAndPrerequisites.Add(research);

            // get list of all available research benches
            var availableBenches = Find.Maps.SelectMany(map => map.listerBuildings.allBuildingsColonist)
                                   .OfType <Building_ResearchBench>();
            var availableBenchDefs = availableBenches.Select(b => b.def).Distinct();

            missing = new List <ThingDef>();

            // check each for prerequisites
            // TODO: We should really build this list recursively so we can re-use results for prerequisites.
            foreach (var rpd in thisAndPrerequisites)
            {
                if (rpd.requiredResearchBuilding == null)
                {
                    continue;
                }

                if (!availableBenchDefs.Contains(rpd.requiredResearchBuilding))
                {
                    missing.Add(rpd.requiredResearchBuilding);
                }

                if (rpd.requiredResearchFacilities.NullOrEmpty())
                {
                    continue;
                }

                foreach (var facility in rpd.requiredResearchFacilities)
                {
                    if (!availableBenches.Any(b => b.HasFacility(facility)))
                    {
                        missing.Add(facility);
                    }
                }
            }

            // add to cache
            missing = missing.Distinct().ToList();
            _missingFacilitiesCache.Add(research, missing);
            return(missing);
        }
コード例 #3
0
        public static void MissingFacilities_Postfix(ref ResearchProjectDef research, ref List <ThingDef> __result)
        {
            if (__result.NullOrEmpty())
            {
                return;
            }
            List <ThingDef> missing;

            // get list of all researches required before this
            var thisAndPrerequisites = research.Ancestors().Where(rpd => !rpd.IsFinished).ToList();

            thisAndPrerequisites.Add(research);

            // get list of all available research benches
            var availableBenches   = Find.Maps.SelectMany(map => map.listerBuildings.allBuildingsColonist).OfType <Building_WorkTable>();
            var availableBenchDefs = availableBenches.Select(b => b.def).Distinct();

            missing = new List <ThingDef>();

            // check each for prerequisites
            foreach (var rpd in thisAndPrerequisites)
            {
                if (rpd.requiredResearchBuilding == null)
                {
                    continue;
                }
                if (!availableBenchDefs.Contains(rpd.requiredResearchBuilding))
                {
                    missing.Add(rpd.requiredResearchBuilding);
                }
                if (rpd.requiredResearchFacilities.NullOrEmpty())
                {
                    continue;
                }
                foreach (var facility in rpd.requiredResearchFacilities)
                {
                    if (!availableBenches.Any(b => b.HasFacility(facility)))
                    {
                        missing.Add(facility);
                    }
                }
            }

            // add to cache
            missing = missing.Distinct().ToList();
            if (missing != _missingFacilitiesCache[research])
            {
                _missingFacilitiesCache.Remove(research);
                _missingFacilitiesCache.Add(research, missing);
            }

            __result = missing;
        }
コード例 #4
0
        public static bool BuildingPresent(ResearchProjectDef research)
        {
            if (DebugSettings.godMode && Prefs.DevMode)
            {
                return(true);
            }

            // try get from cache
            bool result;

            if (_buildingPresentCache.TryGetValue(research, out result))
            {
                return(result);
            }

            // do the work manually
            if (research.requiredResearchBuilding == null)
            {
                result = true;
            }
            else
            {
                result = Find.Maps.SelectMany(map => map.listerBuildings.allBuildingsColonist)
                         .OfType <Building_ResearchBench>()
                         .Any(b => research.CanBeResearchedAt(b, true));
            }

            if (result)
            {
                result = research.Ancestors().All(BuildingPresent);
            }

            // update cache
            _buildingPresentCache.Add(research, result);
            return(result);
        }