public void SetDisabledTargets(CustomPawn source, PawnRelationDef relationDef)
        {
            disabledTargets.Clear();
            CarefullyPawnRelationDef extendedDef = DefDatabase <CarefullyPawnRelationDef> .GetNamedSilentFail(relationDef.defName);

            foreach (var pawn in PrepareCarefully.Instance.Pawns)
            {
                if (source == pawn)
                {
                    disabledTargets.Add(pawn);
                    continue;
                }
                bool bloodRelation = relationDef.familyByBloodRelation;
                foreach (CustomRelationship r in PrepareCarefully.Instance.RelationshipManager.Relationships)
                {
                    if (r.source == source && r.target == pawn)
                    {
                        if (r.inverseDef == relationDef || r.def == relationDef)
                        {
                            disabledTargets.Add(pawn);
                            break;
                        }
                        else if (extendedDef != null && extendedDef.conflicts != null && extendedDef.conflicts.Contains(r.def.defName))
                        {
                            disabledTargets.Add(pawn);
                            break;
                        }
                        else if (extendedDef != null && extendedDef.conflicts != null && extendedDef.conflicts.Contains(r.inverseDef.defName))
                        {
                            disabledTargets.Add(pawn);
                            break;
                        }
                    }
                    else if (r.source == pawn && r.target == source)
                    {
                        if (r.def == relationDef || r.inverseDef == relationDef)
                        {
                            disabledTargets.Add(pawn);
                            break;
                        }
                        else if (extendedDef != null && extendedDef.conflicts != null && extendedDef.conflicts.Contains(r.inverseDef.defName))
                        {
                            disabledTargets.Add(pawn);
                            break;
                        }
                        else if (extendedDef != null && extendedDef.conflicts != null && extendedDef.conflicts.Contains(r.def.defName))
                        {
                            disabledTargets.Add(pawn);
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void AddRelationship(Pawn source, Pawn target, PawnRelationDef def)
        {
            List <DirectPawnRelation> sourceDirectRelations = directRelationsField.GetValue(source.relations) as List <DirectPawnRelation>;
            List <DirectPawnRelation> targetDirectRelations = directRelationsField.GetValue(target.relations) as List <DirectPawnRelation>;
            HashSet <Pawn>            sourcePawnsWithDirectRelationsWithMe = pawnsWithField.GetValue(target.relations) as HashSet <Pawn>;
            HashSet <Pawn>            targetPawnsWithDirectRelationsWithMe = pawnsWithField.GetValue(target.relations) as HashSet <Pawn>;

            sourceDirectRelations.Add(new DirectPawnRelation(def, target, 0));
            targetPawnsWithDirectRelationsWithMe.Add(source);
            if (def.reflexive)
            {
                targetDirectRelations.Add(new DirectPawnRelation(def, source, 0));
                sourcePawnsWithDirectRelationsWithMe.Add(target);
            }

            // Try to find a better pawn compatibility, if it makes sense for the relationship.
            CarefullyPawnRelationDef pcDef = DefDatabase <CarefullyPawnRelationDef> .GetNamedSilentFail(def.defName);

            if (pcDef != null)
            {
                if (pcDef.needsCompatibility)
                {
                    int   originalId    = target.thingIDNumber;
                    float originalScore = source.relations.ConstantPerPawnsPairCompatibilityOffset(originalId);
                    int   bestId        = originalId;
                    float bestScore     = originalScore;
                    foreach (var id in compatibilityPool)
                    {
                        float score = source.relations.ConstantPerPawnsPairCompatibilityOffset(id);
                        if (score > bestScore)
                        {
                            bestScore = score;
                            bestId    = id;
                        }
                    }
                    if (bestId != originalId)
                    {
                        target.thingIDNumber = bestId;
                        compatibilityPool.Remove(bestId);
                        compatibilityPool.Add(originalId);
                    }
                }
            }
        }
Exemplo n.º 3
0
 protected void PopulateAllowedRelationships()
 {
     allowedRelationships.AddRange(DefDatabase <PawnRelationDef> .AllDefs.ToList().FindAll((PawnRelationDef def) => {
         CarefullyPawnRelationDef extended = DefDatabase <CarefullyPawnRelationDef> .GetNamedSilentFail(def.defName);
         if (extended != null && extended.animal)
         {
             return(false);
         }
         MethodInfo info = def.workerClass.GetMethod("CreateRelation", BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
         if (info == null)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }));
 }
Exemplo n.º 4
0
        protected void PopulateInverseRelationships()
        {
            foreach (var def in DefDatabase <PawnRelationDef> .AllDefs)
            {
                PawnRelationDef          inverse  = null;
                CarefullyPawnRelationDef extended = DefDatabase <CarefullyPawnRelationDef> .GetNamedSilentFail(def.defName);

                if (extended != null && extended.inverse != null)
                {
                    inverse = DefDatabase <PawnRelationDef> .GetNamedSilentFail(extended.inverse);
                }
                else
                {
                    inverse = ComputeInverseRelationship(def);
                }
                if (inverse != null)
                {
                    inverseRelationships[def] = inverse;
                }
            }
        }
Exemplo n.º 5
0
        public PawnRelationWorker FindPawnRelationWorker(PawnRelationDef def)
        {
            CarefullyPawnRelationDef carefullyDef = DefDatabase <CarefullyPawnRelationDef> .GetNamedSilentFail(def.defName);

            if (carefullyDef == null || carefullyDef.workerClass == null)
            {
                return(def.Worker);
            }
            else
            {
                PawnRelationWorker worker = carefullyDef.Worker;
                if (worker != null)
                {
                    return(carefullyDef.Worker);
                }
                else
                {
                    return(def.Worker);
                }
            }
        }
Exemplo n.º 6
0
        public PawnRelationWorker FindPawnRelationWorker(PawnRelationDef def)
        {
            CarefullyPawnRelationDef carefullyDef = DefDatabase <CarefullyPawnRelationDef> .GetNamedSilentFail(def.defName);

            if (carefullyDef == null || carefullyDef.workerClass == null)
            {
                return(def.Worker);
            }
            else
            {
                PawnRelationWorker worker = carefullyDef.Worker;
                if (worker != null)
                {
                    //Log.Message("Returned carefully worker for " + def.defName + ", " + worker.GetType().FullName);
                    return(carefullyDef.Worker);
                }
                else
                {
                    return(def.Worker);
                }
            }
        }
Exemplo n.º 7
0
        public void SetDisabledRelationships(CustomPawn target)
        {
            disabledRelationships.Clear();
            CustomPawn source        = PrepareCarefully.Instance.State.CurrentPawn;
            bool       bloodRelation = false;

            foreach (CustomRelationship r in PrepareCarefully.Instance.RelationshipManager.ExplicitRelationships)
            {
                if (r.def.familyByBloodRelation)
                {
                    if ((r.source == source && r.target == target) || (r.source == target && r.target == source))
                    {
                        bloodRelation = true;
                        break;
                    }
                }
            }
            if (bloodRelation)
            {
                foreach (PawnRelationDef r in PrepareCarefully.Instance.RelationshipManager.AllowedRelationships)
                {
                    if (r.familyByBloodRelation)
                    {
                        disabledRelationships.Add(r);
                    }
                }
            }
            foreach (CustomRelationship r in PrepareCarefully.Instance.RelationshipManager.ExplicitRelationships)
            {
                if ((r.source == source && r.target == target) || (r.source == target && r.target == source))
                {
                    disabledRelationships.Add(r.def);
                    CarefullyPawnRelationDef extendedDef = DefDatabase <CarefullyPawnRelationDef> .GetNamedSilentFail(r.def.defName);

                    if (extendedDef != null)
                    {
                        if (extendedDef.conflicts != null)
                        {
                            foreach (string conflictName in extendedDef.conflicts)
                            {
                                PawnRelationDef conflict = DefDatabase <PawnRelationDef> .GetNamedSilentFail(conflictName);

                                if (conflict != null)
                                {
                                    disabledRelationships.Add(conflict);
                                }
                            }
                        }
                    }
                    if (r.inverseDef != null)
                    {
                        disabledRelationships.Add(r.inverseDef);
                        extendedDef = DefDatabase <CarefullyPawnRelationDef> .GetNamedSilentFail(r.inverseDef.defName);

                        if (extendedDef != null)
                        {
                            if (extendedDef.conflicts != null)
                            {
                                foreach (string conflictName in extendedDef.conflicts)
                                {
                                    PawnRelationDef conflict = DefDatabase <PawnRelationDef> .GetNamedSilentFail(conflictName);

                                    if (conflict != null)
                                    {
                                        disabledRelationships.Add(conflict);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }