예제 #1
0
        static void HorizontalPositionsByDensity()
        {
            foreach (var node in Nodes)
            {
                List <Node> level = new List <Node>();
                level.Add(node);

                int depth = 1;
                while (level.Count > 0 && level.Any(n => n.InNodes.Count > 0))
                {
                    // has any parent, increment level.
                    depth++;

                    // set level to next batch of distinct Parents, where Parents may not be itself.
                    level = level.SelectMany(n => n.InNodes).Distinct().Where(n => n != node).ToList();

                    // stop infinite recursion with loops of size greater than 2
                    if (depth > 100)
                    {
                        ResearchLog.Error("{0} has more than 100 levels of prerequisites. Is the Research Tree defined as a loop?", false, node);
                        break;
                    }
                }
                node.SetDepth(depth);
            }
        }
예제 #2
0
        public static ResearchNode ResearchNode(this ResearchProjectDef research)
        {
            var node = Tree.Nodes.OfType <ResearchNode>().FirstOrDefault(n => n.Research == research);

            if (node == null)
            {
                ResearchLog.Error("Node for {0} not found. Was it intentionally hidden or locked?", true, research.LabelCap);
            }
            return(node);
        }