public static void Initialize() { // Make evil people immune to thoughts listed below List<ThoughtDef> nullifiedThoughts = new List<ThoughtDef>(); nullifiedThoughts.Add(ThoughtDefOf.KnowGuestExecuted); nullifiedThoughts.Add(ThoughtDefOf.KnowPrisonerDiedInnocent); nullifiedThoughts.Add(ThoughtDefOf.KnowPrisonerSold); nullifiedThoughts.Add(ThoughtDefOf.KnowGuestOrganHarvested); nullifiedThoughts.Add(ThoughtDefOf.WitnessedDeathNonAlly); foreach (var thought in nullifiedThoughts) { thought.nullifyingTraits?.Add(BPDefOf.BadPeople_Evil); thought.ResolveReferences(); } // Ensure psychopath can't be evil person var psychopathTrait = TraitDefOf.Psychopath; if (psychopathTrait.conflictingTraits == null) psychopathTrait.conflictingTraits = new List<TraitDef>(); if (!psychopathTrait.conflictingTraits.Contains(BPDefOf.BadPeople_Evil)) psychopathTrait.conflictingTraits.Add(BPDefOf.BadPeople_Evil); psychopathTrait.ResolveReferences(); KinslayerInitialize(); // Adding Debug tab to all pawns, visibility resolved internally, later. foreach (ThingDef t in DefDatabase<ThingDef>.AllDefs.Where(def => def.race != null && def.race.intelligence == Intelligence.Humanlike)) { if (t.inspectorTabsResolved == null) { t.inspectorTabsResolved = new List<InspectTabBase>(1); } t.inspectorTabsResolved.Add(InspectTabManager.GetSharedInstance(typeof(ITab_DebugActivityLog))); } InspectPaneUtility.Reset(); }
public override void DefsLoaded() { //1. Preparing settings UpdateSettings(); //2. Adding Tech Tab to Pawns //ThingDef injection stolen from the work of notfood for Psychology var zombieThinkTree = DefDatabase <ThinkTreeDef> .GetNamedSilentFail("Zombie"); IEnumerable <ThingDef> things = (from def in DefDatabase <ThingDef> .AllDefs where def.race?.intelligence == Intelligence.Humanlike && (zombieThinkTree == null || def.race.thinkTreeMain != zombieThinkTree) select def); List <string> registered = new List <string>(); foreach (ThingDef t in things) { if (t.inspectorTabsResolved == null) { t.inspectorTabsResolved = new List <InspectTabBase>(1); } t.inspectorTabsResolved.Add(InspectTabManager.GetSharedInstance(typeof(ITab_PawnKnowledge))); if (t.comps == null) { t.comps = new List <CompProperties>(1); } t.comps.Add(new CompProperties_Knowledge()); registered.Add(t.defName); } InspectPaneUtility.Reset(); //3. Preparing knowledge support infrastructure //a. Things everyone knows UniversalWeapons.AddRange(DefDatabase <ThingDef> .AllDefs.Where(x => x.IsWeapon)); UniversalCrops.AddRange(DefDatabase <ThingDef> .AllDefs.Where(x => x.plant != null && x.plant.Sowable)); //b. Minus things unlocked on research ThingFilter lateFilter = new ThingFilter(); foreach (ResearchProjectDef tech in DefDatabase <ResearchProjectDef> .AllDefs) { tech.InferSkillBias(); tech.CreateStuff(lateFilter, unlocked); foreach (ThingDef weapon in tech.UnlockedWeapons()) { UniversalWeapons.Remove(weapon); } foreach (ThingDef plant in tech.UnlockedPlants()) { UniversalCrops.Remove(plant); } } ; //c. Also removing atipical weapons List <string> ForbiddenWeaponTags = TechDefOf.WeaponsNotBasic.weaponTags; UniversalWeapons.RemoveAll(x => SplitSimpleWeapons(x, ForbiddenWeaponTags)); List <ThingDef> garbage = new List <ThingDef>(); garbage.Add(TechDefOf.WeaponsNotBasic); //d. Classifying pawn backstories PawnBackgroundUtility.BuildCache(); //e. Telling humans what's going on ThingCategoryDef knowledgeCat = TechDefOf.Knowledge; IEnumerable <ThingDef> codifiedTech = DefDatabase <ThingDef> .AllDefs.Where(x => x.IsWithinCategory(knowledgeCat)); if (Prefs.LogVerbose || FullStartupReport) { Log.Message($"[HumanResources] Codified technologies: {codifiedTech.Select(x => x.label).ToStringSafeEnumerable()}"); Log.Message($"[HumanResources] Basic crops: {UniversalCrops.ToStringSafeEnumerable()}"); Log.Message($"[HumanResources] Basic weapons: {UniversalWeapons.ToStringSafeEnumerable()}"); Log.Message($"[HumanResources] Basic weapons that require training: {SimpleWeapons.ToStringSafeEnumerable()}"); Log.Warning($"[HumanResources] Basic weapons tags: {SimpleWeapons.Where(x => !x.weaponTags.NullOrEmpty()).SelectMany(x => x.weaponTags).Distinct().ToStringSafeEnumerable()}"); if (FullStartupReport) { Log.Warning("[HumanResources] Backstories classified by TechLevel:"); for (int i = 0; i < 8; i++) { TechLevel level = (TechLevel)i; IEnumerable <string> found = PawnBackgroundUtility.TechLevelByBackstory.Where(e => e.Value == level).Select(e => e.Key); if (!found.EnumerableNullOrEmpty()) { Log.Message($"- {level.ToString().CapitalizeFirst()} ({found.EnumerableCount()}): {found.ToStringSafeEnumerable()}"); } } Log.Warning("[HumanResources] Techs classified by associated skill:"); var skills = DefDatabase <SkillDef> .AllDefsListForReading.GetEnumerator(); while (skills.MoveNext()) { SkillDef skill = skills.Current; IEnumerable <string> found = TechTracker.FindTechs(skill).Select(x => x.Tech.label); Log.Message($"- {skill.LabelCap} ({found.EnumerableCount()}): {found.ToStringSafeEnumerable()}"); } } } else { Log.Message($"[HumanResources] This is what we know: {codifiedTech.EnumerableCount()} technologies processed, {UniversalCrops.Count()} basic crops, {UniversalWeapons.Count()} basic weapons + {SimpleWeapons.Count()} that require training."); } //4. Filling gaps on the database //a. TechBook dirty trick, but only now this is possible! TechDefOf.TechBook.stuffCategories = TechDefOf.UnfinishedTechBook.stuffCategories = TechDefOf.LowTechCategories.stuffCategories; TechDefOf.TechDrive.stuffCategories = TechDefOf.HiTechCategories.stuffCategories; garbage.Add(TechDefOf.LowTechCategories); garbage.Add(TechDefOf.HiTechCategories); //b. Filling main tech category with subcategories foreach (ThingDef t in lateFilter.AllowedThingDefs.Where(t => !t.thingCategories.NullOrEmpty())) { foreach (ThingCategoryDef c in t.thingCategories) { c.childThingDefs.Add(t); if (!knowledgeCat.childCategories.NullOrEmpty() && !knowledgeCat.childCategories.Contains(c)) { knowledgeCat.childCategories.Add(c); } } } //c. Populating knowledge recipes and book shelves foreach (RecipeDef r in DefDatabase <RecipeDef> .AllDefs.Where(x => x.ingredients.Count == 1 && x.fixedIngredientFilter.AnyAllowedDef == null)) { r.fixedIngredientFilter.ResolveReferences(); r.defaultIngredientFilter.ResolveReferences(); } foreach (ThingDef t in DefDatabase <ThingDef> .AllDefs.Where(x => x.thingClass == typeof(Building_BookStore))) { t.building.fixedStorageSettings.filter.ResolveReferences(); t.building.defaultStorageSettings.filter.ResolveReferences(); } //d. Removing temporary defs from database. foreach (ThingDef def in garbage) { AccessTools.Method(typeof(DefDatabase <ThingDef>), "Remove").Invoke(this, new object[] { def }); } }
private static void DoPlayLoad() { GraphicDatabase.Clear(); DeepProfiler.Start("Load all active mods."); try { LoadedModManager.LoadAllActiveMods(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Load language metadata."); try { LanguageDatabase.LoadAllMetadata(); } finally { DeepProfiler.End(); } LongEventHandler.SetCurrentEventText("LoadingDefs".Translate()); DeepProfiler.Start("Copy all Defs from mods to global databases."); try { foreach (Type item in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item, "AddAllInMods"); } } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between non-implied Defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent); } finally { DeepProfiler.End(); } DeepProfiler.Start("Rebind defs (early)."); try { DefOfHelper.RebindAllDefOfs(true); } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (pre-resolve)."); try { DefGenerator.GenerateImpliedDefs_PreResolve(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between Defs made by the implied defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.LogErrors); } finally { DeepProfiler.End(); } DeepProfiler.Start("Rebind DefOfs (final)."); try { DefOfHelper.RebindAllDefOfs(false); } finally { DeepProfiler.End(); } DeepProfiler.Start("Other def binding, resetting and global operations."); try { PlayerKnowledgeDatabase.ReloadAndRebind(); LessonAutoActivator.Reset(); CostListCalculator.Reset(); PawnApparelGenerator.Reset(); RestUtility.Reset(); ThoughtUtility.Reset(); PawnWeaponGenerator.Reset(); ThinkTreeKeyAssigner.Reset(); ThingCategoryNodeDatabase.FinalizeInit(); TrainableUtility.Reset(); HaulAIUtility.Reset(); GenConstruct.Reset(); WorkGiver_FillFermentingBarrel.Reset(); WorkGiver_DoBill.Reset(); Pawn.Reset(); WorkGiver_InteractAnimal.Reset(); WorkGiver_Warden_DoExecution.Reset(); WorkGiver_GrowerSow.Reset(); WorkGiver_Miner.Reset(); MedicalCareUtility.Reset(); InspectPaneUtility.Reset(); GraphicDatabaseHeadRecords.Reset(); DateReadout.Reset(); ResearchProjectDef.GenerateNonOverlappingCoordinates(); WorkGiver_FixBrokenDownBuilding.CacheTranslations(); ItemCollectionGeneratorUtility.Reset(); BaseGen.Reset(); HealthUtility.Reset(); ResourceCounter.ResetDefs(); WildSpawner.Reset(); ApparelProperties.Reset(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve references."); try { foreach (Type item2 in typeof(Def).AllSubclasses()) { if (item2 != typeof(ThingDef)) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item2, "ResolveAllReferences", true); } } DefDatabase <ThingDef> .ResolveAllReferences(true); } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (post-resolve)."); try { DefGenerator.GenerateImpliedDefs_PostResolve(); } finally { DeepProfiler.End(); } if (Prefs.DevMode) { DeepProfiler.Start("Error check all defs."); try { foreach (Type item3 in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item3, "ErrorCheckAllDefs"); } } finally { DeepProfiler.End(); } } LongEventHandler.SetCurrentEventText("Initializing".Translate()); DeepProfiler.Start("Load keyboard preferences."); try { KeyPrefs.Init(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Short hash giving."); try { ShortHashGiver.GiveAllShortHashes(); } finally { DeepProfiler.End(); } LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Load backstories."); try { BackstoryDatabase.ReloadAllBackstories(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Inject selected language data into game data."); try { LanguageDatabase.activeLanguage.InjectIntoData(); GenLabel.ClearCache(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { StaticConstructorOnStartupUtility.CallAll(); if (Prefs.DevMode) { StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes(); } }); }
private static void DoPlayLoad() { DeepProfiler.Start("GraphicDatabase.Clear()"); try { GraphicDatabase.Clear(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Load all active mods."); try { LoadedModManager.LoadAllActiveMods(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Load language metadata."); try { LanguageDatabase.InitAllMetadata(); } finally { DeepProfiler.End(); } LongEventHandler.SetCurrentEventText("LoadingDefs".Translate()); DeepProfiler.Start("Copy all Defs from mods to global databases."); try { foreach (Type item in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item, "AddAllInMods"); } } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between non-implied Defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent); } finally { DeepProfiler.End(); } DeepProfiler.Start("Rebind defs (early)."); try { DefOfHelper.RebindAllDefOfs(earlyTryMode: true); } finally { DeepProfiler.End(); } DeepProfiler.Start("TKeySystem.BuildMappings()"); try { TKeySystem.BuildMappings(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Inject selected language data into game data (early pass)."); try { LanguageDatabase.activeLanguage.InjectIntoData_BeforeImpliedDefs(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (pre-resolve)."); try { DefGenerator.GenerateImpliedDefs_PreResolve(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between Defs made by the implied defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.LogErrors); } finally { DirectXmlCrossRefLoader.Clear(); DeepProfiler.End(); } DeepProfiler.Start("Rebind DefOfs (final)."); try { DefOfHelper.RebindAllDefOfs(earlyTryMode: false); } finally { DeepProfiler.End(); } DeepProfiler.Start("Other def binding, resetting and global operations (pre-resolve)."); try { PlayerKnowledgeDatabase.ReloadAndRebind(); LessonAutoActivator.Reset(); CostListCalculator.Reset(); Pawn.ResetStaticData(); PawnApparelGenerator.Reset(); RestUtility.Reset(); ThoughtUtility.Reset(); ThinkTreeKeyAssigner.Reset(); ThingCategoryNodeDatabase.FinalizeInit(); TrainableUtility.Reset(); HaulAIUtility.Reset(); GenConstruct.Reset(); MedicalCareUtility.Reset(); InspectPaneUtility.Reset(); GraphicDatabaseHeadRecords.Reset(); DateReadout.Reset(); ResearchProjectDef.GenerateNonOverlappingCoordinates(); BaseGen.Reset(); ResourceCounter.ResetDefs(); ApparelProperties.ResetStaticData(); WildPlantSpawner.ResetStaticData(); PawnGenerator.Reset(); TunnelHiveSpawner.ResetStaticData(); Hive.ResetStaticData(); ExpectationsUtility.Reset(); WealthWatcher.ResetStaticData(); SkillUI.Reset(); QuestNode_GetThingPlayerCanProduce.ResetStaticData(); Pawn_PsychicEntropyTracker.ResetStaticData(); ColoredText.ResetStaticData(); QuestNode_GetRandomNegativeGameCondition.ResetStaticData(); RoyalTitleUtility.ResetStaticData(); RewardsGenerator.ResetStaticData(); WorkGiver_FillFermentingBarrel.ResetStaticData(); WorkGiver_DoBill.ResetStaticData(); WorkGiver_InteractAnimal.ResetStaticData(); WorkGiver_Warden_DoExecution.ResetStaticData(); WorkGiver_GrowerSow.ResetStaticData(); WorkGiver_Miner.ResetStaticData(); WorkGiver_FixBrokenDownBuilding.ResetStaticData(); WorkGiver_ConstructDeliverResources.ResetStaticData(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve references."); try { DeepProfiler.Start("ThingCategoryDef resolver"); try { DefDatabase <ThingCategoryDef> .ResolveAllReferences(); } finally { DeepProfiler.End(); } DeepProfiler.Start("RecipeDef resolver"); try { DeepProfiler.enabled = false; DefDatabase <RecipeDef> .ResolveAllReferences(onlyExactlyMyType : true, parallel : true); DeepProfiler.enabled = true; } finally { DeepProfiler.End(); } DeepProfiler.Start("Static resolver calls"); try { foreach (Type item2 in typeof(Def).AllSubclasses()) { if (!(item2 == typeof(ThingDef)) && !(item2 == typeof(ThingCategoryDef)) && !(item2 == typeof(RecipeDef))) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item2, "ResolveAllReferences", true, false); } } } finally { DeepProfiler.End(); } DeepProfiler.Start("ThingDef resolver"); try { DefDatabase <ThingDef> .ResolveAllReferences(); } finally { DeepProfiler.End(); } } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (post-resolve)."); try { DefGenerator.GenerateImpliedDefs_PostResolve(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Other def binding, resetting and global operations (post-resolve)."); try { PawnWeaponGenerator.Reset(); BuildingProperties.FinalizeInit(); ThingSetMakerUtility.Reset(); } finally { DeepProfiler.End(); } if (Prefs.DevMode) { DeepProfiler.Start("Error check all defs."); try { foreach (Type item3 in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item3, "ErrorCheckAllDefs"); } } finally { DeepProfiler.End(); } } LongEventHandler.SetCurrentEventText("Initializing".Translate()); DeepProfiler.Start("Load keyboard preferences."); try { KeyPrefs.Init(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Short hash giving."); try { ShortHashGiver.GiveAllShortHashes(); } finally { DeepProfiler.End(); } LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Load backstories."); try { BackstoryDatabase.ReloadAllBackstories(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Inject selected language data into game data."); try { LanguageDatabase.activeLanguage.InjectIntoData_AfterImpliedDefs(); GenLabel.ClearCache(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Static constructor calls"); try { StaticConstructorOnStartupUtility.CallAll(); if (Prefs.DevMode) { StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes(); } } finally { DeepProfiler.End(); } DeepProfiler.Start("Garbage Collection"); try { AbstractFilesystem.ClearAllCache(); GC.Collect(int.MaxValue, GCCollectionMode.Forced); } finally { DeepProfiler.End(); } }); }