diff --git a/Source/Graph/ResearchNode.cs b/Source/Graph/ResearchNode.cs index 7a7ca2d..c64e3ca 100644 --- a/Source/Graph/ResearchNode.cs +++ b/Source/Graph/ResearchNode.cs @@ -178,8 +178,10 @@ public static bool BuildingPresent( ResearchNode node ) // try get from cache bool result; - if ( _buildingPresentCache.TryGetValue( research, out result ) ) + if ( _buildingPresentCache.TryGetValue( research, out result )) + { return result; + } // do the work manually if ( research.requiredResearchBuilding == null ) { @@ -190,6 +192,12 @@ public static bool BuildingPresent( ResearchNode node ) .Any(b => research.CanBeResearchedAt(b, true)); } + //Allso check for Facilities + if (result) + { + result = MissingFacilities(research).Count == 0; + } + if ( result ) { result = node.MissingPrerequisites().All(BuildingPresent); } @@ -234,8 +242,10 @@ public static List MissingFacilities( ResearchProjectDef research ) { // try get from cache List missing; - if ( _missingFacilitiesCache.TryGetValue( research, out missing ) ) + if (_missingFacilitiesCache.TryGetValue(research, out missing)) + { return missing; + } // get list of all researches required before this var thisAndPrerequisites = research.Ancestors().Where( rpd => !rpd.IsFinished ).ToList(); @@ -244,6 +254,7 @@ public static List MissingFacilities( ResearchProjectDef research ) // get list of all available research benches var availableBenches = Find.Maps.SelectMany( map => map.listerBuildings.allBuildingsColonist ) .OfType(); + var availableBenchDefs = availableBenches.Select( b => b.def ).Distinct(); missing = new List(); @@ -251,23 +262,30 @@ public static List MissingFacilities( ResearchProjectDef research ) // TODO: We should really build this list recursively so we can re-use results for prerequisites. foreach ( var rpd in thisAndPrerequisites ) { - if ( rpd.requiredResearchBuilding == null ) - continue; - - if ( !availableBenchDefs.Contains( rpd.requiredResearchBuilding ) ) - missing.Add( rpd.requiredResearchBuilding ); - - if ( rpd.requiredResearchFacilities.NullOrEmpty() ) - continue; + if (rpd.requiredResearchBuilding != null) + { + if (!availableBenchDefs.Contains(rpd.requiredResearchBuilding)) + { + missing.Add(rpd.requiredResearchBuilding); + } + } - foreach ( var facility in rpd.requiredResearchFacilities ) - if ( !availableBenches.Any( b => b.HasFacility( facility ) ) ) - missing.Add( facility ); + if ( !rpd.requiredResearchFacilities.NullOrEmpty()) + { + foreach (var facility in rpd.requiredResearchFacilities) + { + if (!availableBenches.Any(b => b.HasFacility(facility))) + { + missing.Add(facility); + } + } + } } // add to cache missing = missing.Distinct().ToList(); _missingFacilitiesCache.Add( research, missing ); + return missing; }