Пример #1
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);
        }
Пример #2
0
        public static ResearchProjectDef GetBestRPDForRecipe(RecipeDef recipe, bool ignoreLocked = false)
        {
            ThingDef thingDef = recipe.ProducedThingDef;

            if (thingDef == null)
            {
                return(null);
            }
            ResearchProjectDef overrideRPD;

            if (GearAssigner.GetOverrideAssignment(thingDef, out overrideRPD))
            {
                return(overrideRPD);
            }
            if ((thingDef.category == ThingCategory.Building || thingDef.building != null) && !TechprintingSettings.shardBuildings)
            {
                return(null);
            }
            if (TechprintingSettings.weaponsApparelOnly && (!thingDef.IsWeapon && !thingDef.IsApparel) && !ignoreLocked && !TechprintingSettings.printAllItems)
            {
                return(null);
            }

            if (recipe.researchPrerequisite != null)             // direct prereq for this recipe
            {
                if (recipe.researchPrerequisite.techprintCount > 0 || TechprintingSettings.printAllItems || ignoreLocked)
                {
                    return(recipe.researchPrerequisite);
                }
            }

            if (recipe.researchPrerequisites != null && recipe.researchPrerequisites.Count > 0)             // prerequisites list, never seen this but could be possible, not sure what's checked for
            {
                foreach (ResearchProjectDef prereq in recipe.researchPrerequisites)
                {
                    if (prereq.techprintCount > 0)
                    {
                        return(prereq);
                    }
                }
                if (TechprintingSettings.printAllItems || ignoreLocked)
                {
                    return(recipe.researchPrerequisites[0]);
                }
            }

            if (recipe.recipeUsers != null)             // no direct prereqs, look at benches
            {
                foreach (ThingDef user in recipe.recipeUsers)
                {
                    if (user.researchPrerequisites != null && user.researchPrerequisites.Count > 0)
                    {
                        foreach (ResearchProjectDef prereq in user.researchPrerequisites)
                        {
                            if (prereq.techprintCount > 0)
                            {
                                return(prereq);
                            }
                        }
                    }
                }
                if (TechprintingSettings.printAllItems || ignoreLocked)
                {
                    float    lowestSpeed = 99999f;
                    ThingDef bestThing   = null;
                    foreach (ThingDef user in recipe.recipeUsers)
                    {
                        if (user.researchPrerequisites != null && user.researchPrerequisites.Count > 0)
                        {
                            float workRate = user.GetStatValueAbstract(StatDefOf.WorkTableWorkSpeedFactor);
                            if (workRate < lowestSpeed)
                            {
                                bestThing   = user;
                                lowestSpeed = workRate;
                            }
                        }
                    }
                    if (bestThing != null)
                    {
                        return(bestThing.researchPrerequisites[0]);
                    }
                }
            }
            return(null);
        }