Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions Source/Graph/ResearchNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -234,8 +242,10 @@ public static List<ThingDef> MissingFacilities( ResearchProjectDef research )
{
// try get from cache
List<ThingDef> 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();
Expand All @@ -244,30 +254,38 @@ public static List<ThingDef> MissingFacilities( ResearchProjectDef research )
// get list of all available research benches
var availableBenches = Find.Maps.SelectMany( map => map.listerBuildings.allBuildingsColonist )
.OfType<Building_ResearchBench>();

var availableBenchDefs = availableBenches.Select( b => b.def ).Distinct();
missing = new List<ThingDef>();

// check each for prerequisites
// 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;
}

Expand Down