private void CheckAdvancedResearch() { //Log.Message( "Checking - " + researchComplete.Count + " - defs" ); // Quick scan to see if anything changed and early out if nothing is complete if (Game.GodMode == false) { // Reset everything if (wasGodMode) { LockEverything(); } // Not anymore wasGodMode = false; // God mode is off, do a real check bool noChange = true; for (int rcIndex = 0, rcCountTo = researchComplete.Count; rcIndex < rcCountTo; rcIndex++) { ResearchCompletePair rcPair = researchComplete[rcIndex]; //Log.Message( "Checking - " + rcPair.researchProject.LabelCap ); if ((rcPair.researchProject.IsFinished) && (rcPair.wasComplete == false)) { rcPair.wasComplete = true; noChange = false; //Log.Message( rcPair.researchProject.LabelCap + " - Is now done" ); } } // GTFO! if (noChange) { return; } } //Log.Message( "updating" ); // Prepare for some work PrepareCache(); // Start determining work for (int aIndex = 0, aCountTo = advancedResearch.Count; aIndex < aCountTo; aIndex++) { AdvancedResearchDef Advanced = advancedResearch[aIndex]; // Is it done? if ((Advanced.isEnabled == false) && (Advanced.ResearchGroupComplete())) { // If all the research is done, process the def ProcessResearch(Advanced); } } ProcessCache(); }
bool HasMatchingResearch(AdvancedResearchDef other) { if (researchDefs.Count != other.researchDefs.Count) { return(false); } SortResearch(); other.SortResearch(); for (int i = 0; i < researchDefs.Count; ++i) { if (researchDefs[i] != other.researchDefs[i]) { return(false); } } return(true); }
public static bool ResearchGroupComplete(this AdvancedResearchDef arp) { // God mode, allow it if (Game.GodMode == true) { return(true); } // No god mode, check it for (int rIndex = 0, rCountTo = arp.researchDefs.Count; rIndex < rCountTo; rIndex++) { if (!arp.researchDefs[rIndex].IsFinished) { return(false); } } // All done return(true); }
private void ProcessResearch(AdvancedResearchDef Advanced) { if (Advanced.toggleRecipes) { // Recipe toggle on buildings // Get each building associated with the advanced research for (int bIndex = 0, bCountTo = Advanced.buildingDefs.Count; bIndex < bCountTo; bIndex++) { ThingDef building = Advanced.buildingDefs[bIndex]; // Get each recipe associated with the advanced research for (int rIndex = 0, rCountTo = Advanced.recipeDefs.Count; rIndex < rCountTo; rIndex++) { RecipeDef recipe = Advanced.recipeDefs[rIndex]; // Show or hide recipes? if (!Advanced.HideDefs) { // Make sure recipe has user list if (recipe.recipeUsers == null) { recipe.recipeUsers = new List <ThingDef>(); } // Add building to recipe recipe.recipeUsers.Add(building); } else { // Remove building from recipe if ((recipe.recipeUsers != null) && (recipe.recipeUsers.IndexOf(building) >= 0)) { recipe.recipeUsers.Remove(building); } // Remove recipe from building if ((building.recipes != null) && (building.recipes.IndexOf(recipe) >= 0)) { building.recipes.Remove(recipe); } } } // Add this building to the list to recache buildingRecipeRecache.Add(building); } } if (Advanced.toggleBuildings) { // Designator toggle on buildings for (int bIndex = 0, bCountTo = Advanced.buildingDefs.Count; bIndex < bCountTo; bIndex++) { ThingDef building = Advanced.buildingDefs[bIndex]; // Show/Hide as appropriate if (!Advanced.HideDefs) { // Show building building.researchPrerequisite = Research.Unlocker; } else { building.researchPrerequisite = Research.Locker; } } } // Cache any callbacks if (Advanced.doCallbacks) { for (int mIndex = 0, mCountTo = Advanced.researchMods.Count; mIndex < mCountTo; mIndex++) { actionCache.Add(Advanced.researchMods[mIndex]); } } // Flag it as enabled to skip it in later checks Advanced.isEnabled = true; }
private void LockEverything(bool sanityChecks = false) { // Lock everything by breaking the links and do sanity checks of all the defs // Until all sanity checks are done... okToProcess = false; // Prepare (clear) the processing caches PrepareCache(); // Get each advanced research def for (int aIndex = 0, aCountTo = advancedResearch.Count; aIndex < aCountTo; aIndex++) { AdvancedResearchDef Advanced = advancedResearch[aIndex]; Advanced.toggleRecipes = IsRecipeToggle(Advanced); Advanced.toggleBuildings = IsBuildingToggle(Advanced); Advanced.doCallbacks = HasCallbacks(Advanced); // Get each building associated with the advanced research for (int bIndex = 0, bCountTo = Advanced.buildingDefs.Count; bIndex < bCountTo; bIndex++) { ThingDef building = Advanced.buildingDefs[bIndex]; if ((sanityChecks) && (building == null)) { Log.Message("Community Core Library :: Advanced Research :: buildingDefs( index = " + bIndex + " ) resolved to null in AdvancedResearchDef( " + Advanced.defName + " )"); return; } if (Advanced.toggleRecipes) { // Recipe unlock on buildings // Get each recipe associated with the advanced research for (int rIndex = 0, rCountTo = Advanced.recipeDefs.Count; rIndex < rCountTo; rIndex++) { RecipeDef recipe = Advanced.recipeDefs[rIndex]; if ((sanityChecks) && (recipe == null)) { // Sanity check Log.Message("Community Core Library :: Advanced Research :: recipeDefs( index = " + rIndex + " ) resolved to null in AdvancedResearchDef( " + Advanced.defName + " )"); return; } // Only deal with defs which unlock if (!Advanced.HideDefs) { // Remove building from recipe if ((recipe.recipeUsers != null) && (recipe.recipeUsers.IndexOf(building) >= 0)) { recipe.recipeUsers.Remove(building); } // Remove recipe from building if ((building.recipes != null) && (building.recipes.IndexOf(recipe) >= 0)) { building.recipes.Remove(recipe); } } } // Add this building to the list to recache buildingRecipeRecache.Add(building); } if (Advanced.toggleBuildings) { // Make sure to know how this building was originally set if (thingDefResearch.FindIndex(pair => (pair.thingDef == building)) < 0) { thingDefResearch.Add(new ThingResearchPair(building, building.researchPrerequisite)); } if (Advanced.HideDefs) { // Reset building to original research building.researchPrerequisite = thingDefResearch.Find(pair => (pair.thingDef == building)).researchProject; } else { // Hide the building building.researchPrerequisite = Research.Locker; } } } // Validate callbacks if ((sanityChecks) && (Advanced.doCallbacks)) { for (int mIndex = 0, mCountTo = Advanced.researchMods.Count; mIndex < mCountTo; mIndex++) { if (Advanced.researchMods[mIndex] == null) { // Sanity check Log.Message("Community Core Library :: Advanced Research :: researchMods( index = " + mIndex + " ) resolved to null in AdvancedResearchDef( " + Advanced.defName + " )"); return; } } } // Flag it as disabled to trigger research completion checks Advanced.isEnabled = false; } // Everything is ok! okToProcess = true; // Now do the work! ProcessCache(); }
private bool HasCallbacks(AdvancedResearchDef Advanced) { // Determine if this def has callbacks return((Advanced.researchMods != null) && (Advanced.researchMods.Count > 0)); }
private bool IsBuildingToggle(AdvancedResearchDef Advanced) { // Determine if this def toggles buildings return((Advanced.recipeDefs == null) || (Advanced.recipeDefs.Count == 0) && (Advanced.buildingDefs != null) && (Advanced.buildingDefs.Count > 0)); }
bool HasMatchingResearch( AdvancedResearchDef other ) { if( researchDefs.Count != other.researchDefs.Count ) { return false; } SortResearch(); other.SortResearch(); for( int i = 0; i < researchDefs.Count; ++ i ) { if( researchDefs[ i ] != other.researchDefs[ i ] ) { return false; } } return true; }
static HelpDef HelpForAdvancedResearch( AdvancedResearchDef advancedResearchDef, HelpCategoryDef category ) { var helpDef = new HelpDef(); helpDef.defName = advancedResearchDef.defName + "_AdvancedResearchDef_Help"; helpDef.keyDef = advancedResearchDef.defName; helpDef.label = advancedResearchDef.label; if( advancedResearchDef.helpCategoryDef == null ) { advancedResearchDef.helpCategoryDef = category; } if( advancedResearchDef.IsHelpEnabled ) { helpDef.category = advancedResearchDef.helpCategoryDef; } var s = new StringBuilder(); s.AppendLine( advancedResearchDef.description ); s.AppendLine(); #region Base Stats s.AppendLine( "AutoHelpTotalCost".Translate( advancedResearchDef.TotalCost.ToString() ) ); s.AppendLine(); #endregion #region Research, Buildings, Recipes and SowTags // Add research required var researchDefs = advancedResearchDef.GetResearchRequirements(); BuildDefDescription( s, "AutoHelpListResearchRequired".Translate(), researchDefs.ConvertAll<Def>( def =>(Def)def ) ); // Add buildings it unlocks var thingDefs = advancedResearchDef.GetThingsUnlocked(); BuildDefDescription( s, "AutoHelpListThingsUnlocked".Translate(), thingDefs.ConvertAll<Def>( def =>(Def)def ) ); // Add recipes it unlocks var recipeDefs = advancedResearchDef.GetRecipesUnlocked( ref thingDefs ); BuildDefWithDefDescription( s, "AutoHelpListRecipesUnlocked".Translate(), "AutoHelpListRecipesOnThings".Translate(), recipeDefs.ConvertAll<Def>( def =>(Def)def ), thingDefs.ConvertAll<Def>( def =>(Def)def ) ); // Add plants and sow tags it unlocks var sowTags = advancedResearchDef.GetSowTagsUnlocked( ref thingDefs ); BuildDefWithStringDescription( s, "AutoHelpListPlantsUnlocked".Translate(), "AutoHelpListPlantsIn".Translate(), thingDefs.ConvertAll<Def>( def =>(Def)def ), sowTags ); #endregion #region Lockouts // Add buildings it locks thingDefs = advancedResearchDef.GetThingsLocked(); BuildDefDescription( s, "AutoHelpListThingsLocked".Translate(), thingDefs.ConvertAll<Def>( def =>(Def)def ) ); // Add recipes it locks recipeDefs = advancedResearchDef.GetRecipesLocked( ref thingDefs ); BuildDefWithDefDescription( s, "Prevents recipes:", "AutoHelpListRecipesOnThings".Translate(), recipeDefs.ConvertAll<Def>( def =>(Def)def ), thingDefs.ConvertAll<Def>( def =>(Def)def ) ); // Add plants and sow tags it locks sowTags = advancedResearchDef.GetSowTagsLocked( ref thingDefs ); BuildDefWithStringDescription( s, "AutoHelpListPlantsLocked".Translate(), "AutoHelpListPlantsIn".Translate(), thingDefs.ConvertAll<Def>( def =>(Def)def ), sowTags ); #endregion helpDef.description = s.ToString(); advancedResearchDef.HelpDef = helpDef; return helpDef; }
private void ProcessResearch( AdvancedResearchDef Advanced ) { if( Advanced.toggleRecipes ){ // Recipe toggle on buildings // Get each building associated with the advanced research for( int bIndex = 0, bCountTo = Advanced.buildingDefs.Count; bIndex < bCountTo; bIndex++ ){ ThingDef building = Advanced.buildingDefs[ bIndex ]; // Get each recipe associated with the advanced research for( int rIndex = 0, rCountTo = Advanced.recipeDefs.Count; rIndex < rCountTo; rIndex++ ){ RecipeDef recipe = Advanced.recipeDefs[ rIndex ]; // Show or hide recipes? if( !Advanced.HideDefs ) { // Make sure recipe has user list if( recipe.recipeUsers == null ) recipe.recipeUsers = new List<ThingDef>(); // Add building to recipe recipe.recipeUsers.Add( building ); } else { // Remove building from recipe if( ( recipe.recipeUsers != null ) && ( recipe.recipeUsers.IndexOf( building ) >= 0 ) ){ recipe.recipeUsers.Remove( building ); } // Remove recipe from building if( ( building.recipes != null ) && ( building.recipes.IndexOf( recipe ) >= 0 ) ){ building.recipes.Remove( recipe ); } } } // Add this building to the list to recache buildingRecipeRecache.Add( building ); } } if( Advanced.toggleBuildings ) { // Designator toggle on buildings for( int bIndex = 0, bCountTo = Advanced.buildingDefs.Count; bIndex < bCountTo; bIndex++ ){ ThingDef building = Advanced.buildingDefs[ bIndex ]; // Show/Hide as appropriate if( !Advanced.HideDefs ){ // Show building building.researchPrerequisite = Research.Unlocker; } else { building.researchPrerequisite = Research.Locker; } } } // Cache any callbacks if( Advanced.doCallbacks ) for( int mIndex = 0, mCountTo = Advanced.researchMods.Count; mIndex < mCountTo; mIndex++ ) actionCache.Add( Advanced.researchMods[ mIndex ] ); // Flag it as enabled to skip it in later checks Advanced.isEnabled = true; }
private bool IsRecipeToggle( AdvancedResearchDef Advanced ) { // Determine if this def toggles recipes return ( Advanced.recipeDefs != null )&&( Advanced.recipeDefs.Count > 0 )&& ( Advanced.buildingDefs != null )&&( Advanced.buildingDefs.Count > 0 ); }
private bool HasCallbacks( AdvancedResearchDef Advanced ) { // Determine if this def has callbacks return ( Advanced.researchMods != null )&&( Advanced.researchMods.Count > 0 ); }
static HelpDef HelpForAdvancedResearch( AdvancedResearchDef advancedResearchDef, HelpCategoryDef category ) { var helpDef = new HelpDef(); helpDef.defName = advancedResearchDef.defName + "_AdvancedResearchDef_Help"; helpDef.keyDef = advancedResearchDef; helpDef.label = advancedResearchDef.label; helpDef.description = advancedResearchDef.description; if( advancedResearchDef.helpCategoryDef == null ) { advancedResearchDef.helpCategoryDef = category; } if( advancedResearchDef.IsHelpEnabled ) { helpDef.category = advancedResearchDef.helpCategoryDef; } #region Base Stats HelpDetailSection totalCost = new HelpDetailSection( null, new [] {"AutoHelpTotalCost".Translate( advancedResearchDef.TotalCost.ToString() )}); helpDef.HelpDetailSections.Add( totalCost ); #endregion #region Research, Buildings, Recipes and SowTags // Add research required var researchDefs = advancedResearchDef.GetResearchRequirements(); if( !researchDefs.NullOrEmpty() ) { HelpDetailSection researchRequired = new HelpDetailSection( "AutoHelpListResearchRequired".Translate(), researchDefs.ConvertAll<Def>( def =>(Def)def ) ); helpDef.HelpDetailSections.Add( researchRequired ); } // Add buildings it unlocks var thingDefs = advancedResearchDef.GetThingsUnlocked(); if( !thingDefs.NullOrEmpty() ) { HelpDetailSection thingsUnlocked = new HelpDetailSection( "AutoHelpListThingsUnlocked".Translate(), thingDefs.ConvertAll<Def>( def =>(Def)def ) ); helpDef.HelpDetailSections.Add( thingsUnlocked ); } // Add recipes it unlocks var recipeDefs = advancedResearchDef.GetRecipesUnlocked( ref thingDefs ); if( (!recipeDefs.NullOrEmpty()) && (!thingDefs.NullOrEmpty()) ) { HelpDetailSection recipesUnlocked = new HelpDetailSection( "AutoHelpListRecipesUnlocked".Translate(), recipeDefs.ConvertAll<Def>( def =>(Def)def ) ); helpDef.HelpDetailSections.Add( recipesUnlocked ); HelpDetailSection recipesOnThingsUnlocked = new HelpDetailSection( "AutoHelpListRecipesOnThings".Translate(), thingDefs.ConvertAll<Def>(def => (Def)def)); helpDef.HelpDetailSections.Add( recipesOnThingsUnlocked ); } // Add plants and sow tags it unlocks var sowTags = advancedResearchDef.GetSowTagsUnlocked( ref thingDefs ); if( (!sowTags.NullOrEmpty()) && (!thingDefs.NullOrEmpty()) ) { HelpDetailSection plantsUnlocked = new HelpDetailSection( "AutoHelpListPlantsUnlocked".Translate(), thingDefs.ConvertAll<Def>( def =>(Def)def ) ); helpDef.HelpDetailSections.Add( plantsUnlocked ); HelpDetailSection recipesOnThingsUnlocked = new HelpDetailSection( "AutoHelpListPlantsIn".Translate(), sowTags.ToArray() ); helpDef.HelpDetailSections.Add( recipesOnThingsUnlocked ); } #endregion #region Lockouts // Add buildings it locks thingDefs = advancedResearchDef.GetThingsLocked(); if( !thingDefs.NullOrEmpty() ) { HelpDetailSection thingsLocked = new HelpDetailSection( "AutoHelpListThingsLocked".Translate(), thingDefs.ConvertAll<Def>( def =>(Def)def ) ); helpDef.HelpDetailSections.Add( thingsLocked ); } // Add recipes it locks recipeDefs = advancedResearchDef.GetRecipesLocked( ref thingDefs ); if( (!recipeDefs.NullOrEmpty()) && (!thingDefs.NullOrEmpty()) ) { HelpDetailSection recipesLocked = new HelpDetailSection( "AutoHelpListRecipesLocked".Translate(), recipeDefs.ConvertAll<Def>( def =>(Def)def ) ); helpDef.HelpDetailSections.Add( recipesLocked ); HelpDetailSection recipesOnThings = new HelpDetailSection( "AutoHelpListRecipesOnThings".Translate(), thingDefs.ConvertAll<Def>( def =>(Def)def ) ); helpDef.HelpDetailSections.Add( recipesOnThings ); } // Add plants and sow tags it locks sowTags = advancedResearchDef.GetSowTagsLocked( ref thingDefs ); if( (!sowTags.NullOrEmpty()) && (!thingDefs.NullOrEmpty()) ) { HelpDetailSection plantsLocked = new HelpDetailSection( "AutoHelpListPlantsLocked".Translate(), thingDefs.ConvertAll<Def>( def =>(Def)def ) ); helpDef.HelpDetailSections.Add( plantsLocked ); HelpDetailSection plantsIn = new HelpDetailSection( "AutoHelpListPlantsIn".Translate(), sowTags.ToArray() ); helpDef.HelpDetailSections.Add( plantsIn ); } #endregion advancedResearchDef.HelpDef = helpDef; return helpDef; }