public static IEnumerable <MorphDef> GetAllMorphsInClass([NotNull] this AnimalClassBase classDef)
        {
            if (classDef == null)
            {
                throw new ArgumentNullException(nameof(classDef));
            }

            if (_morphsUnderCache.TryGetValue(classDef, out List <MorphDef> morphs))
            {
                return(morphs);
            }
            morphs = new List <MorphDef>();

            if (classDef is MorphDef morph)
            {
                morphs.Add(morph);
                _morphsUnderCache[classDef] = morphs;
                return(morphs);
            }

            IEnumerable <AnimalClassBase> preorder = TreeUtilities.Preorder(classDef, c => c.Children);

            foreach (MorphDef morphDef in preorder.OfType <MorphDef>())
            {
                morphs.Add(morphDef);
            }
            _morphsUnderCache[classDef] = morphs;
            return(morphs);
        }
Beispiel #2
0
        static void PrintHumanlikeThinkTree()
        {
            ThinkTreeDef tree = DefDatabase <ThinkTreeDef> .GetNamed("Humanlike");

            if (tree == null)
            {
                return;
            }
            string outStr = TreeUtilities.PrettyPrintTree(tree.thinkRoot, GetChildren, GetNodeLabel);

            Log.Message(outStr);
        }
Beispiel #3
0
        static void PrintAnimalThinkTree()
        {
            var tTree = DefDatabase <ThinkTreeDef> .GetNamed("Animal");

            if (tTree == null)
            {
                return;
            }

            var outStr = TreeUtilities.PrettyPrintTree(tTree.thinkRoot, GetChildren, GetNodeLabel);

            Log.Message(outStr);
        }
        static AnimalClassUtilities()
        {
            foreach (AnimalClassDef animalClassDef in DefDatabase <AnimalClassDef> .AllDefs)
            {
                animalClassDef.FindChildren(); //have to do this after all other def's 'ResolveReferences' have been called
            }
            foreach (AnimalClassDef animalClassDef in DefDatabase <AnimalClassDef> .AllDefs)
            {
                if (animalClassDef.parent != null)
                {
                    continue;
                }
                if (animalClassDef != AnimalClassDefOf.Animal)
                {
                    Log.Warning($"{animalClassDef.defName} does not have a parent! only {nameof(AnimalClassDefOf.Animal)} should not have a parent!");
                }
            }


            if (CheckForCycles()) //don't precede if there are any cycles in the tree
            {
                throw
                    new InvalidDataException("detected cycles in animal class tree!"); //not sure what we should throw here, but we can't continue with
            }
            //cycles in the class tree


            //save the pre and post order traversal orders for performance reasons
            PostorderTreeInternal = TreeUtilities.Postorder <AnimalClassBase>(AnimalClassDefOf.Animal, c => c.Children);
            PreorderTreeInternal  = TreeUtilities.Preorder <AnimalClassBase>(AnimalClassDefOf.Animal, c => c.Children).ToList();


            string treeStr =
                TreeUtilities.PrettyPrintTree <AnimalClassBase>(AnimalClassDefOf.Animal, a => a.Children, a => ((Def)a).defName);

            Log.Message(treeStr); //print a pretty tree c:
        }
Beispiel #5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // First, we need to retrieve all data from the input parameters.
            // We'll start by declaring variables and assigning them starting values.

            //Plane plane = Plane.WorldXY;
            //double radius0 = 0.0;
            //double radius1 = 0.0;
            //int turns = 0;

            List <Curve> Primary      = new List <Curve>();
            List <Curve> IntPrimary   = new List <Curve>();
            List <Curve> Secondary    = new List <Curve>();
            List <Curve> IntSecondary = new List <Curve>();

            // Then we need to access the input parameters individually.
            // When data cannot be extracted from a parameter, we should abort this method.
            if (!DA.GetDataList(0, Primary))
            {
                return;
            }
            //if (!DA.GetDataList(1, IntPrimary)) return;
            if (!DA.GetDataList(2, Secondary))
            {
                return;
            }
            //if (!DA.GetDataList(3, IntSecondary)) return;

            // We should now validate the data and warn the user if invalid data is supplied.
            if (Primary == null || Secondary == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input Primary and Secondary Curves");
                return;
            }

            // We're set to create the spiral now. To keep the size of the SolveInstance() method small,
            // The actual functionality will be in a different method:
            //Curve spiral = CreateSpiral(plane, radius0, radius1, turns);

            List <List <Double> > distPrimInt = new List <List <Double> >();
            List <List <Double> > distSecInt  = new List <List <Double> >();

            List <Vector3d> primVecs = new List <Vector3d>(Grid.GridUnitVectors(Primary));
            List <Vector3d> secVecs  = new List <Vector3d>(Grid.GridUnitVectors(Secondary));

            DataTree <Point3d> gridPoints = new DataTree <Point3d>(TreeUtilities.ListToTree(Intersection.CurveCurve(Primary, Secondary, out distPrimInt, out distSecInt)));

            DataTree <Double> distPrimIntTree = new DataTree <Double>(TreeUtilities.ListToTree(distPrimInt));
            DataTree <Double> distSecIntTree  = new DataTree <Double>(TreeUtilities.ListToTree(distSecInt));

            string Information = "To be implemented";

            // Finally assign the spiral to the output parameter.

            DA.SetData(0, Information);
            DA.SetDataTree(1, gridPoints);
            DA.SetDataTree(2, gridPoints);
            DA.SetDataList(3, primVecs);
            DA.SetDataList(4, secVecs);
            DA.SetDataTree(5, distPrimIntTree);
            DA.SetDataTree(6, distSecIntTree);
        }