Skip to content

Commit

Permalink
'Release 2.15.465 [nolog]'
Browse files Browse the repository at this point in the history
  • Loading branch information
FluffierThanThou committed Aug 17, 2018
1 parent 98e5ee9 commit dd4aee0
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Eiglsperger M., Siebenhaller M., Kaufmann M. (2005) An Efficient Implementation
Luckily, the crossing reduction and edge length reduction steps partially achieve the goals of the final step. The final graph is not as pretty as it could be, but it’s still pretty good - in most scenarios.

<size=24>Version</size>
This is version 2.14.462, for RimWorld 0.19.1996.
This is version 2.15.465, for RimWorld 0.19.1996.

</description>
</ModMetaData>
Binary file modified Assemblies/ResearchTree.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ Show your appreciation by buying me a coffee (or contribute towards a nice singl
[![Buy Me a Coffee](http://i.imgur.com/EjWiUwx.gif)](https://ko-fi.com/fluffymods)

# Version
This is version 2.14.462, for RimWorld 0.19.1996.
This is version 2.15.465, for RimWorld 0.19.1996.
10 changes: 7 additions & 3 deletions Source/Extensions/ResearchProjectDef_Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static IEnumerable<ThingDef> GetPlantsUnlocked( this ResearchProjectDef r
.Where( td => td.plant?.sowResearchPrerequisites?.Contains( research ) ?? false );
}

public static List<ResearchProjectDef> GetPrerequisitesRecursive( this ResearchProjectDef research )
public static List<ResearchProjectDef> Ancestors( this ResearchProjectDef research )
{
// keep a list of prerequites
var prerequisites = new List<ResearchProjectDef>();
Expand Down Expand Up @@ -163,9 +163,13 @@ public static List<Pair<Def, string>> GetUnlockDefsAndDescs( this ResearchProjec
return unlocks;
}

public static ResearchNode Node( this ResearchProjectDef research )
public static ResearchNode ResearchNode( this ResearchProjectDef research )
{
return Tree.Nodes.OfType<ResearchNode>().FirstOrDefault( node => node.Research == research );
var node = Tree.Nodes.OfType<ResearchNode>().FirstOrDefault( n => n.Research == research );
if (node == null){
Log.Error( "Node for {0} not found. Was it intentionally hidden or locked?", true, research.LabelCap );
}
return node;
}

#endregion Methods
Expand Down
8 changes: 4 additions & 4 deletions Source/Graph/ResearchNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static bool BuildingPresent( ResearchProjectDef research )
.Any( b => research.CanBeResearchedAt( b, true ) );

if ( result )
result = research.GetPrerequisitesRecursive().All( BuildingPresent );
result = research.Ancestors().All( BuildingPresent );

// update cache
_buildingPresentCache.Add( research, result );
Expand All @@ -107,7 +107,7 @@ public static void ClearCaches()

public static implicit operator ResearchNode( ResearchProjectDef def )
{
return Tree.Nodes.OfType<ResearchNode>().FirstOrDefault( n => n.Research == def );
return def.ResearchNode();
}

public int Matches( string query )
Expand All @@ -132,7 +132,7 @@ public static List<ThingDef> MissingFacilities( ResearchProjectDef research )
return missing;

// get list of all researches required before this
List<ResearchProjectDef> thisAndPrerequisites = research.GetPrerequisitesRecursive().Where( rpd => !rpd.IsFinished ).ToList();
List<ResearchProjectDef> thisAndPrerequisites = research.Ancestors().Where( rpd => !rpd.IsFinished ).ToList();
thisAndPrerequisites.Add( research );

// get list of all available research benches
Expand Down Expand Up @@ -332,7 +332,7 @@ public override void Draw( Rect visibleRect, bool forceDetailedMode = false )
/// <returns>List<Node> prerequisites</Node></returns>
public List<ResearchNode> GetMissingRequiredRecursive()
{
var parents = Research.prerequisites?.Where( rpd => !rpd.IsFinished ).Select( rpd => rpd.Node() );
var parents = Research.prerequisites?.Where( rpd => !rpd.IsFinished ).Select( rpd => rpd.ResearchNode() );
if (parents == null)
return new List<ResearchNode>();
var allParents = new List<ResearchNode>( parents );
Expand Down
17 changes: 14 additions & 3 deletions Source/Graph/Tree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ private static void CreateEdges()
foreach ( var prerequisite in node.Research.prerequisites )
{
ResearchNode prerequisiteNode = prerequisite;
if ( prerequisiteNode == null )
continue;
var edge = new Edge<Node, Node>( prerequisiteNode, node );
Edges.Add( edge );
node.InEdges.Add( edge );
Expand All @@ -519,7 +521,7 @@ private static void CheckPrerequisites()
if ( node.Research.prerequisites.NullOrEmpty() )
continue;

var ancestors = node.Research.prerequisites?.SelectMany(r => r.GetPrerequisitesRecursive()).ToList();
var ancestors = node.Research.prerequisites?.SelectMany(r => r.Ancestors()).ToList();
var redundant = ancestors.Intersect(node.Research.prerequisites);
if (redundant.Any())
{
Expand Down Expand Up @@ -558,10 +560,19 @@ private static void PopulateNodes()
{
Log.Debug( "Populating nodes." );
Profiler.Start();

var projects = DefDatabase<ResearchProjectDef>.AllDefsListForReading;

// find hidden nodes (nodes that have themselves as a prerequisite)
var hidden = projects.Where( p => p.prerequisites?.Contains( p ) ?? false );

// find locked nodes (nodes that have a hidden node as a prerequisite)
var locked = projects.Where( p => p.Ancestors().Intersect( hidden ).Any() );

// populate all nodes
_nodes = new List<Node>( DefDatabase<ResearchProjectDef>.AllDefsListForReading
// exclude hidden projects (prereq of itself is a common trick to hide research).
.Where( def => def.prerequisites.NullOrEmpty() || !def.prerequisites.Contains( def ) )
.Except( hidden )
.Except( locked )
.Select( def => new ResearchNode( def ) as Node ) );
Log.Debug( "\t{0} nodes", _nodes.Count );
Profiler.End();
Expand Down
10 changes: 9 additions & 1 deletion Source/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ public static void Message( string msg, params object[] args )

public static void Warning( string msg, params object[] args )
{
Verse.Log.Message( Format( msg, args ) );
Verse.Log.Warning( Format( msg, args ) );
}

private static string Format( string msg, params object[] args )
{
return "ResearchTree :: " + String.Format( msg, args );
}

public static void Error( string msg, bool once, params object[] args ){
var _msg = Format( msg, args );
if (once)
Verse.Log.ErrorOnce( _msg, _msg.GetHashCode() );
else
Verse.Log.Error( _msg );
}

[Conditional("DEBUG")]
public static void Debug( string msg, params object[] args )
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Queue/Queue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public override void ExposeData()
foreach (ResearchProjectDef research in _saveableQueue)
{
// find a node that matches the research - or null if none found
ResearchNode node = research.Node();
ResearchNode node = research.ResearchNode();

// enqueue the node
if (node != null)
Expand Down
6 changes: 3 additions & 3 deletions Source/ResearchTree.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\..\..\harmony\0Harmony.dll</HintPath>
<HintPath>..\..\..\..\harmony\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\dlls\Assembly-CSharp.dll</HintPath>
<HintPath>..\..\..\..\dlls\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -48,7 +48,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\dlls\UnityEngine.dll</HintPath>
<HintPath>..\..\..\..\dlls\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
Expand Down

0 comments on commit dd4aee0

Please sign in to comment.