public void AddPastMate(BloodLineMember pastMate) { if (!this._pastMates.Contains(pastMate)) { _pastMates.Add(pastMate); } }
public void AddChild(BloodLineMember child) { if (!this._children.Contains(child)) { _children.Add(child); } }
public void AddSibling(BloodLineMember sibling) { if (!this._siblings.Contains(sibling)) { _siblings.Add(sibling); } }
public void AddParent(BloodLineMember parent) { if (!this._parents.Contains(parent)) { _parents.Add(parent); } }
public BloodRelationInstance(BloodLineMember subject, BloodLineMember target, List <BloodRelationType> relationChain, BloodRelationDef relationDef) { this.Subject = subject; this.Target = target; this.RelationTypeChain = relationChain; this.RelationDef = relationDef; }
private static bool _findMostDirRec(BloodLineMember subject, BloodLineMember target, List <BloodRelationType> list, int depthLeft, BloodRelationType checkingFrom) { if (depthLeft == 0) { return(false); } if (subject.Parents.Contains(target)) { list.Add(BloodRelationType.Parent); return(true); } if (subject.Siblings.Contains(target)) { list.Add(BloodRelationType.Sibling); return(true); } if (subject.Children.Contains(target)) { list.Add(BloodRelationType.Child); return(true); } if (checkingFrom != BloodRelationType.Parent) { foreach (var parent in subject.Parents) { if (_findMostDirRec(parent, target, list, depthLeft - 1, BloodRelationType.Child)) { list.Add(BloodRelationType.Parent); return(true); } } } if (checkingFrom != BloodRelationType.Sibling) { foreach (var sibling in subject.Siblings) { if (_findMostDirRec(sibling, target, list, depthLeft - 1, BloodRelationType.Sibling)) { list.Add(BloodRelationType.Sibling); return(true); } } } if (checkingFrom != BloodRelationType.Child) { foreach (var child in subject.Children) { if (_findMostDirRec(child, target, list, depthLeft - 1, BloodRelationType.Parent)) { list.Add(BloodRelationType.Child); return(true); } } } return(false); }
public static BloodRelationInstance DeterminRelation(BloodLineMember subject, BloodLineMember target, int MaxDepth = 3) { var relationChain = BuildRelationChain(subject, target, MaxDepth); if (relationChain != null) { var def = TryMatchRelationChainToDef(relationChain); var relation = new BloodRelationInstance(subject, target, relationChain, def); return(relation); } return(null); }
public static List <BloodRelationType> BuildRelationChain(BloodLineMember A, BloodLineMember B, int MaxDepth) { var chain = new List <BloodRelationType>(); if (_findMostDirRec(A, B, chain, MaxDepth, BloodRelationType.UNSET)) { chain.Reverse(); return(chain); } else { return(null); } }
public static BloodLineMember NewBloodlineMember(IEnumerable <BloodLineMember> parents, IPopInstance pop) { var newMember = new BloodLineMember(pop); foreach (var parent in parents) { newMember.AddParent(parent); parent.AddChild(newMember); foreach (var otherParent in parents.Where(x => x != parent)) { parent.AddPastMate(otherParent); } foreach (var child in parent.Children.Where(x => x != newMember)) { child.AddSibling(newMember); newMember.AddSibling(child); } } return(newMember); }
//private Dictionary<string, List<BloodRelationInstance>> _knownRelations; //public List<BloodRelationInstance> GetKnownRelations(BloodLineMember member) //{ // if (_knownRelations == null) // _knownRelations = new Dictionary<string, List<BloodRelationInstance>>(); // var key = member.Villager.InstanceId.ToString(); // if (_knownRelations.ContainsKey(key)) // return _knownRelations[key]; // return null; //} //public static void TryAddNewRelation(BloodRelationInstance instance) //{ // var check = CheckForKnownRelation(instance.Subject, instance.Target); // if (check != null) // return; // var key = instance.Subject.Villager.InstanceId.ToString(); // if (_knownRelations.ContainsKey(key)) // _knownRelations[key].Add(instance); // else // _knownRelations.Add(key, new List<BloodRelationInstance> { instance }); //} //public static BloodRelationInstance CheckForKnownRelation(BloodLineMember subject, BloodLineMember target) //{ // var rel = GetKnownRelations(subject)?.Where(x => x.Target == target); // if (!(rel?.Any() ?? false)) // return null; // else // return rel.Single(); //} public static bool HasRelation(BloodLineMember A, BloodLineMember B, int MaxDepth = 3) { var instance = DeterminRelation(A, B, MaxDepth); return(instance != null); }