private static bool CheckForCycles() { var visitedSet = new HashSet <AnimalClassDef>(); var stk = new Stack <AnimalClassDef>(); stk.Push(AnimalClassDefOf.Animal); var anyLoops = false; while (stk.Count > 0) //simple preorder traversal while checking for loops { AnimalClassDef classification = stk.Pop(); visitedSet.Add(classification); foreach (AnimalClassDef subClass in classification.SubClasses) { if (visitedSet.Contains(subClass)) { anyLoops = true; Log.Error($"visited {subClass.defName} more then once! there must be a cycle in the classifications somewhere!"); continue; } stk.Push(subClass); } } return(anyLoops); }
/// <summary> /// Determines whether this instance contains the object. /// </summary> /// <param name="animalClass">The animal class.</param> /// <returns> /// <c>true</c> if contains the specified animal class; otherwise, <c>false</c>. /// </returns> /// <exception cref="ArgumentNullException">animalClass</exception> public bool Contains([NotNull] AnimalClassDef animalClass) { if (animalClass == null) { throw new ArgumentNullException(nameof(animalClass)); } var c = (AnimalClassBase)this; return(c.Contains(animalClass)); }
public static IEnumerable <MutationDef> GetAllMutationIn([NotNull] this AnimalClassDef animalClass) { if (animalClass == null) { throw new ArgumentNullException(nameof(animalClass)); } if (_mutationClassCache.TryGetValue(animalClass, out List <MutationDef> mutations)) { return(mutations); } mutations = animalClass.GetAllMorphsInClass() .SelectMany(m => m.AllAssociatedMutations) .Distinct() .ToList(); //cache this so we only have to calculate this once _mutationClassCache[animalClass] = mutations; return(mutations); }