Esempio n. 1
0
 public void AddPastMate(BloodLineMember pastMate)
 {
     if (!this._pastMates.Contains(pastMate))
     {
         _pastMates.Add(pastMate);
     }
 }
Esempio n. 2
0
 public void AddChild(BloodLineMember child)
 {
     if (!this._children.Contains(child))
     {
         _children.Add(child);
     }
 }
Esempio n. 3
0
 public void AddSibling(BloodLineMember sibling)
 {
     if (!this._siblings.Contains(sibling))
     {
         _siblings.Add(sibling);
     }
 }
Esempio n. 4
0
 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;
 }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        //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);
        }