public static void AssociateAll()
        {
            allThingDic    = new Dictionary <ThingDef, ResearchProjectDef>();
            allResearchDic = new Dictionary <ResearchProjectDef, List <ThingDef> >();

            foreach (RecipeDef recipe in DefDatabase <RecipeDef> .AllDefsListForReading)
            {
                ResearchProjectDef rpd = ThingDefHelper.GetBestRPDForRecipe(recipe, true);
                if (rpd != null && recipe.ProducedThingDef != null)
                {
                    ThingDef producedThing = recipe.ProducedThingDef;
                    allThingDic.SetOrAdd(producedThing, rpd);

                    List <ThingDef> things;
                    if (allResearchDic.TryGetValue(rpd, out things))
                    {
                        things.Add(producedThing);
                    }
                    else
                    {
                        allResearchDic.Add(rpd, new List <ThingDef> {
                            producedThing
                        });
                    }
                }
            }

            if (TechprintingSettings.shardBuildings)
            {
                foreach (ThingDef building in DefDatabase <ThingDef> .AllDefs.Where(x => x.category == ThingCategory.Building || x.building != null))
                {
                    if (allThingDic.ContainsKey(building))
                    {
                        continue;
                    }
                    ResearchProjectDef rpd = ThingDefHelper.GetBestRPDForBuilding(building, true);
                    if (rpd != null)
                    {
                        allThingDic.SetOrAdd(building, rpd);

                        List <ThingDef> things;
                        if (allResearchDic.TryGetValue(rpd, out things))
                        {
                            things.Add(building);
                        }
                        else
                        {
                            allResearchDic.Add(rpd, new List <ThingDef> {
                                building
                            });
                        }
                    }
                }
            }
            GearAssigner.HardAssign(ref allThingDic, ref allResearchDic);
            GearAssigner.OverrideAssign(ref allThingDic, ref allResearchDic);
        }
        public static bool ResearchProjectIsBestPrereqForRecipe(RecipeDef recipe, ResearchProjectDef proj)
        {
            /*
             * if (recipe.ProducedThingDef == null)
             * {
             *      return false;
             * }
             * ResearchProjectDef best = ThingDefHelper.GetBestResearchProject(recipe.ProducedThingDef);
             */
            ResearchProjectDef best = ThingDefHelper.GetBestRPDForRecipe(recipe);

            return(best == proj);
        }
Esempio n. 3
0
        public static void MakeThingDictionaries()
        {
            thingDic    = new Dictionary <ThingDef, ResearchProjectDef>();
            researchDic = new Dictionary <ResearchProjectDef, List <ThingDef> >();

            foreach (RecipeDef recipe in DefDatabase <RecipeDef> .AllDefsListForReading)
            {
                ResearchProjectDef rpd = ThingDefHelper.GetBestRPDForRecipe(recipe);
                if (rpd != null && recipe.ProducedThingDef != null)
                {
                    if (ShardMaker.ShardForProject(rpd) != null && (rpd.techprintCount > 0 || TechprintingSettings.printAllItems))
                    {
                        ThingDef producedThing = recipe.ProducedThingDef;
                        if (producedThing.GetCompProperties <CompProperties_Shardable>() == null)
                        {
                            producedThing.comps.Add(new CompProperties_Shardable());
                        }

                        thingDic.SetOrAdd(producedThing, rpd);

                        List <ThingDef> things;
                        if (researchDic.TryGetValue(rpd, out things))
                        {
                            things.Add(producedThing);
                        }
                        else
                        {
                            researchDic.Add(rpd, new List <ThingDef> {
                                producedThing
                            });
                        }
                    }
                }
            }

            if (TechprintingSettings.shardBuildings)
            {
                foreach (ThingDef building in DefDatabase <ThingDef> .AllDefs.Where(x => x.category == ThingCategory.Building || x.building != null))
                {
                    if (thingDic.ContainsKey(building))
                    {
                        continue;
                    }
                    ResearchProjectDef rpd = ThingDefHelper.GetBestRPDForBuilding(building);
                    if (rpd != null)
                    {
                        if (ShardMaker.ShardForProject(rpd) != null && (rpd.techprintCount > 0 || TechprintingSettings.printAllItems))
                        {
                            if (building.GetCompProperties <CompProperties_Shardable>() == null)
                            {
                                building.comps.Add(new CompProperties_Shardable());
                            }

                            thingDic.SetOrAdd(building, rpd);

                            List <ThingDef> things;
                            if (researchDic.TryGetValue(rpd, out things))
                            {
                                things.Add(building);
                            }
                            else
                            {
                                researchDic.Add(rpd, new List <ThingDef> {
                                    building
                                });
                            }
                        }
                    }
                }
            }

            GearAssigner.HardAssign(ref thingDic, ref researchDic);
            GearAssigner.OverrideAssign(ref thingDic, ref researchDic);
        }