Beispiel #1
0
        private static int CheckKeywordsFor(this ResearchProjectDef tech, List <string> keywords)
        {
            var matches = 0;

            foreach (var skill in FindSkills(x => !x.Hints.NullOrEmpty()))
            {
                foreach (var word in skill.Hints)
                {
                    if (tech.Matches(word))
                    {
                        SetSkillRelevance(skill, true);
                        matches++;
                        keywords.Add(word);
                        break;
                    }
                }
            }
            return(matches);
        }
Beispiel #2
0
 private static void CheckSpecialCases(this ResearchProjectDef tech, List <string> keywords)
 {
     if (tech.defName.StartsWith("ResearchProject_RotR"))
     {
         SetSkillRelevance(SkillDefOf.Mining, true);
         SetSkillRelevance(SkillDefOf.Construction, true);
     }
     if (tech.defName.StartsWith("BackupPower") || tech.defName.StartsWith("FluffyBreakdowns"))
     {
         SetSkillRelevance(SkillDefOf.Construction, true);
     }
     if (tech.defName.StartsWith("OG_"))
     {
         if (tech.Matches("weapon"))
         {
             SetSkillRelevance(SkillDefOf.Shooting, true);
             SetSkillRelevance(SkillDefOf.Melee, true);
             SetSkillRelevance(SkillDefOf.Crafting, true);
             keywords.Add("weapon");
         }
     }
 }
Beispiel #3
0
        public static void InferSkillBias(this ResearchProjectDef tech)
        {
            //Log.Warning("InferSkillBias Starting for "+tech.LabelCap);
            //1. check what it unlocks
            List <Pair <Def, string> > unlocks   = ResearchTree_Patches.GetUnlockDefsAndDescs(tech);
            IEnumerable <Def>          defs      = unlocks.Select(x => x.First).AsEnumerable();
            IEnumerable <ThingDef>     thingDefs = from d in defs
                                                   where d is ThingDef
                                                   select d as ThingDef;
            IEnumerable <RecipeDef> recipeDefs = from d in defs
                                                 where d is RecipeDef
                                                 select d as RecipeDef;
            IEnumerable <TerrainDef> terrainDefs = from d in defs
                                                   where d is TerrainDef
                                                   select d as TerrainDef;

            //2. look for skills based on unlocked stuff

            //a. checking by query on the research tree
            //int matches = 0;
            if (tech.Matches("scanner") > 0 | tech.Matches("terraform") > 0)
            {
                miningTag = true;                                                                /*matches++;*/
            }
            ;

            if (tech.Matches("sterile") > 0 | tech.Matches("medical") > 0 | tech.Matches("medicine") > 0 | tech.Matches("cryptosleep") > 0 | tech.Matches("prostheses") > 0 | tech.Matches("implant") > 0 | tech.Matches("organs") > 0 | tech.Matches("surgery") > 0)
            {
                medicineTag = true;                                                                                                                                                                                                                                                         /*matches++;*/
            }
            ;

            if (tech.Matches("irrigation") > 0 | tech.Matches("soil") > 0 | tech.Matches("hydroponic") > 0)
            {
                plantsTag = true;                                                                                               /*matches++;*/
            }
            ;

            if (tech.Matches("tool") > 0)
            {
                craftingTag = true;
            }

            if (tech.Matches("manage") > 0)
            {
                intellectualTag = true;
            }

            //b. checking by unlocked things
            if (thingDefs.Count() > 0)
            {
                foreach (ThingDef t in thingDefs)
                {
                    if (t != null)
                    {
                        InvestigateThingDef(t);
                    }
                }
            }

            //c. checking by unlocked recipes
            if (recipeDefs.Count() > 0)
            {
                foreach (RecipeDef r in recipeDefs)
                {
                    //Log.Message("trying recipe " + r.label);
                    foreach (ThingDef t in r.products.Select(x => x.thingDef))
                    {
                        InvestigateThingDef(t);
                    }
                    if (r.workSkill != null)
                    {
                        AccessTools.Field(typeof(Extension_Research), r.workSkill.defName.ToLower() + "Tag").SetValue(tech, true);
                    }
                }
            }

            //d. checking by unlocked terrainDefs
            if (terrainDefs.Count() > 0)
            {
                foreach (TerrainDef t in terrainDefs)
                {
                    if (!constructionTag && t.designationCategory != null && t.designationCategory.label.Contains("floor"))
                    {
                        constructionTag = true;
                    }
                    else if (!miningTag)
                    {
                        miningTag = true;
                    }
                }
            }

            //e. special cases
            if (HarmonyPatches.RunSpecialCases)
            {
                if (tech.defName.StartsWith("ResearchProject_RotR"))
                {
                    miningTag       = true;
                    constructionTag = true;
                }
                if (tech.defName.StartsWith("BackupPower") || tech.defName.StartsWith("FluffyBreakdowns"))
                {
                    constructionTag = true;
                }
            }

            //3. Figure out Bias.
            //int ThingDefCount = thingDefs.Count();
            //int RecipeDefCount = recipeDefs.Count();
            //int TerrainDefCount = terrainDefs.Count();

            List <SkillDef> relevantSkills = new List <SkillDef>();

            if (shootingTag)
            {
                relevantSkills.Add(SkillDefOf.Shooting);
                shootingTag = false;
            }
            if (meleeTag)
            {
                relevantSkills.Add(SkillDefOf.Melee);
                meleeTag = false;
            }
            if (constructionTag)
            {
                relevantSkills.Add(SkillDefOf.Construction);
                constructionTag = false;
            }
            if (miningTag)
            {
                relevantSkills.Add(SkillDefOf.Mining);
                miningTag = false;
            }
            if (cookingTag)
            {
                relevantSkills.Add(SkillDefOf.Cooking);
                cookingTag = false;
            }
            if (plantsTag)
            {
                relevantSkills.Add(SkillDefOf.Plants);
                plantsTag = false;
            }
            if (animalsTag)
            {
                relevantSkills.Add(SkillDefOf.Animals);
                animalsTag = false;
            }
            if (craftingTag)
            {
                relevantSkills.Add(SkillDefOf.Crafting);
                craftingTag = false;
            }
            if (artisticTag)
            {
                relevantSkills.Add(SkillDefOf.Artistic);
                artisticTag = false;
            }
            if (medicineTag)
            {
                relevantSkills.Add(SkillDefOf.Medicine);
                medicineTag = false;
            }
            if (socialTag)
            {
                relevantSkills.Add(SkillDefOf.Social);
                socialTag = false;
            }
            if (intellectualTag)
            {
                relevantSkills.Add(SkillDefOf.Intellectual);
                intellectualTag = false;
            }

            if (!relevantSkills.NullOrEmpty())
            {
                SkillsByTech.Add(tech, relevantSkills);
                foreach (SkillDef skill in relevantSkills)
                {
                    if (!TechsBySkill.ContainsKey(skill))
                    {
                        TechsBySkill.Add(skill, new List <ResearchProjectDef>()
                        {
                            tech
                        });
                    }
                    else
                    {
                        TechsBySkill[skill].Add(tech);
                    }
                }
            }
            else
            {
                Log.Warning("[HumanResources] No relevant skills could be calculated for " + tech + ". It won't be known by anyone.");
            }
        }