Exemple #1
0
        protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            SimDescription dad = ManagerSim.Find(Sim.Pregnancy.DadDescriptionId);

            if ((GetValue <SameSexSameGenderOption, bool>()) && (dad != null) && (dad.Gender == Sim.Gender))
            {
                IncStat("Same Sex");

                Sim.Pregnancy.mGender = Sim.Gender;
                return(true);
            }

            FirstBornGender firstBorn = GetValue <FirstBornGenderOption, FirstBornGender>();

            if (firstBorn == FirstBornGender.Male)
            {
                IncStat("First Born Male");

                Sim.Pregnancy.mGender = CASAgeGenderFlags.Male;
                return(true);
            }
            else if (firstBorn == FirstBornGender.Female)
            {
                IncStat("First Born Female");

                Sim.Pregnancy.mGender = CASAgeGenderFlags.Female;
                return(true);
            }
            else
            {
                if ((GetValue <OneOfEachGenderOption, bool>()) && (Sim.Genealogy != null))
                {
                    bool male = false, female = false;

                    foreach (SimDescription child in Relationships.GetChildren(Sim))
                    {
                        if (SimTypes.IsDead(child))
                        {
                            continue;
                        }

                        if (child.IsMale)
                        {
                            male = true;
                        }
                        else if (child.IsFemale)
                        {
                            female = true;
                        }
                    }

                    if (male)
                    {
                        if (!female)
                        {
                            Sim.Pregnancy.mGender = CASAgeGenderFlags.Female;
                            return(true);
                        }
                    }
                    else if (female)
                    {
                        Sim.Pregnancy.mGender = CASAgeGenderFlags.Male;
                        return(true);
                    }
                }

                if (firstBorn == FirstBornGender.Balanced)
                {
                    Sim.Pregnancy.mGender = CalculateGenderBalancer(Pregnancies, Sim.IsPet);
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            List <SimDescription> children = new List <SimDescription>();

            int chance = GetValue <AlimonyChanceOption, int>(Sim);

            foreach (SimDescription child in Relationships.GetChildren(Sim))
            {
                if (GetValue <ForTeensOption, bool>())
                {
                    if (child.YoungAdultOrAbove)
                    {
                        continue;
                    }
                }
                else
                {
                    if (child.TeenOrAbove)
                    {
                        continue;
                    }
                }

                if (SimTypes.IsDead(child))
                {
                    continue;
                }

                if (child.IsMarried)
                {
                    continue;
                }

                if (child.Household == Sim.Household)
                {
                    continue;
                }

                if (GetValue <NetWorthOption, int>(child.Household) >= GetValue <NetWorthOption, int>(Sim.Household))
                {
                    IncStat("Unnecessary");
                    continue;
                }

                if (!GetValue <ForAdoptedOption, bool>())
                {
                    List <SimDescription> parents = Relationships.GetParents(child);

                    bool found = false;
                    foreach (SimDescription member in CommonSpace.Helpers.Households.All(child.Household))
                    {
                        if (parents.Contains(member))
                        {
                            found = true;
                        }
                    }

                    if (!found)
                    {
                        IncStat("Child Adopted");
                        continue;
                    }
                }

                children.Add(child);
            }

            if (children.Count == 0)
            {
                return(false);
            }

            int perChildPayment = GetValue <PaymentOption, int>();

            if (GetValue <IsRichOption, bool>(Sim.Household))
            {
                perChildPayment *= GetValue <RichMultipleOption, int>();
            }

            if (AddScoring("CaresAboutChildren", chance, ScoringLookup.OptionType.Chance, Sim) <= 0)
            {
                foreach (SimDescription child in children)
                {
                    if (RandomUtil.RandomChance(GetValue <PropagationChanceOption, int>()))
                    {
                        Add(frame, new PropagateAlimonyFailScenario(child, Sim), ScenarioResult.Start);
                    }
                }

                AddValue <AlimonyLapsesOption, int>(Sim, 1);

                if ((GetValue <AlimonyJailOption, bool>()) && (RandomUtil.RandomChance(GetValue <AlimonyLapsesOption, int>(Sim) * 10)))
                {
                    Add(frame, new GoToJailScenario(Sim, "AlimonyJail", perChildPayment), ScenarioResult.Start);

                    SetValue <AlimonyLapsesOption, int>(Sim, 0);
                }

                Add(frame, new SuccessScenario(), ScenarioResult.Start);
                return(true);
            }
            else
            {
                SetValue <AlimonyLapsesOption, int>(Sim, 0);
            }

            foreach (SimDescription child in children)
            {
                if (!Money.Allow(this, child, Managers.Manager.AllowCheck.None))
                {
                    IncStat("Money Denied Child");
                    continue;
                }

                int payment = perChildPayment;
                if (Sim.FamilyFunds < payment)
                {
                    payment = Sim.FamilyFunds;
                }

                mTotalPayments += payment;

                if (payment == 0)
                {
                    IncStat("Insufficient");
                }
                else
                {
                    Money.AdjustFunds(Sim, "ChildSupport", -payment);

                    Money.AdjustFunds(child, "ChildSupport", payment);

                    AddStat("Paid", payment);
                }
            }

            return(mTotalPayments > 0);
        }
Exemple #3
0
        public static bool AttemptServiceDisposal(SimDescription sim, bool oldAge, string reason)
        {
            if (sim == null)
            {
                return(false);
            }

            bool hasChildren = (Relationships.GetChildren(sim).Count > 0);

            if (!oldAge)
            {
                if (hasChildren)
                {
                    return(false);
                }

                if ((sim.IsHuman) && (sim.TeenOrAbove))
                {
                    bool found = false;
                    foreach (SimDescription other in Households.Humans(sim.Household))
                    {
                        if (other == sim)
                        {
                            continue;
                        }

                        if (other.TeenOrAbove)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        return(false);
                    }
                }

                foreach (Household house in Household.GetHouseholdsLivingInWorld())
                {
                    if (Notifications.HasSignificantRelationship(house, sim))
                    {
                        return(false);
                    }
                }
            }

            if (hasChildren)
            {
                if (!Annihilation.Perform(sim, false))
                {
                    return(false);
                }

                if (Common.kDebugging)
                {
                    Common.DebugNotify("Disposed: " + sim.FullName + " (" + sim.Species + ")" + Common.NewLine + reason);
                }
            }
            else
            {
                if (!Annihilation.Cleanse(sim))
                {
                    return(false);
                }

                if (Common.kDebugging)
                {
                    Common.DebugNotify("Cleansed: " + sim.FullName + " (" + sim.Species + ")" + Common.NewLine + reason);
                }
            }

            return(true);
        }
Exemple #4
0
        public void HandleMarriageName(SimDescription a, SimDescription b, bool actorOnEither)
        {
            string lastName = null;

            bool wasEither = false;

            SimDescription left  = a;
            SimDescription right = b;

            if (a.Gender == b.Gender)
            {
                if (actorOnEither)
                {
                    switch (GetValue <SameSexMarriageNameOption, NameTakeType>(right))
                    {
                    case NameTakeType.User:
                    case NameTakeType.Either:
                        left  = b;
                        right = a;
                        break;
                    }
                }
                else
                {
                    if (GetValue <SameSexMarriageNameOption, NameTakeType>(right) == NameTakeType.User)
                    {
                        left  = b;
                        right = a;
                    }
                }

                lastName = GetData(left).HandleName <SameSexMarriageNameOption>(Sims, right, out wasEither);
            }
            else
            {
                if (actorOnEither)
                {
                    switch (GetValue <MarriageNameOption, NameTakeType>(right))
                    {
                    case NameTakeType.User:
                    case NameTakeType.Either:
                        left  = b;
                        right = a;
                        break;
                    }
                }
                else
                {
                    if (GetValue <MarriageNameOption, NameTakeType>(right) == NameTakeType.User)
                    {
                        left  = b;
                        right = a;
                    }
                }

                lastName = GetData(left).HandleName <MarriageNameOption>(Sims, right, out wasEither);
            }

            if ((actorOnEither) && (wasEither))
            {
                lastName = a.LastName;
            }

            if (!string.IsNullOrEmpty(lastName))
            {
                a.LastName = lastName;
                b.LastName = lastName;

                if (GetValue <MarriageScenario.RenameChildrenOption, bool>())
                {
                    bool onlyMutual = GetValue <MarriageScenario.RenameOnlyMutualOption, bool>();

                    foreach (SimDescription child in Relationships.GetChildren(a))
                    {
                        if (a.Household != child.Household)
                        {
                            continue;
                        }

                        if (Households.AllowGuardian(child))
                        {
                            continue;
                        }

                        if (onlyMutual)
                        {
                            if (!Relationships.GetParents(child).Contains(b))
                            {
                                continue;
                            }
                        }

                        child.LastName = a.LastName;
                    }

                    foreach (SimDescription child in Relationships.GetChildren(b))
                    {
                        if (b.Household != child.Household)
                        {
                            continue;
                        }

                        if (Households.AllowGuardian(child))
                        {
                            continue;
                        }

                        if (onlyMutual)
                        {
                            if (!Relationships.GetParents(child).Contains(a))
                            {
                                continue;
                            }
                        }

                        child.LastName = b.LastName;
                    }
                }
            }
        }
Exemple #5
0
        private static bool ProcessSim(FutureDescendantService ths, SimDescription simDesc)
        {
            try
            {
                if (FutureDescendantService.sPersistableData == null)
                {
                    return(false);
                }
                else if (simDesc == null)
                {
                    return(false);
                }
                else if (Household.ActiveHousehold != simDesc.Household)
                {
                    return(false);
                }
                else if ((Household.RoommateManager != null) && Household.RoommateManager.IsNPCRoommate(simDesc))
                {
                    return(false);
                }
                else if (simDesc.IsRobot)
                {
                    return(false);
                }
                else if (simDesc.Genealogy == null)
                {
                    return(false);
                }

                List <SimDescription> children = Relationships.GetChildren(simDesc);
                bool processed = false;
                if ((children != null) && (children.Count > 0x0))
                {
                    foreach (SimDescription child in children)
                    {
                        processed |= ProcessSim(ths, child);
                    }
                }

                if (!processed)
                {
                    foreach (FutureDescendantService.FutureDescendantHouseholdInfo info in FutureDescendantService.sPersistableData.ActiveDescendantHouseholdsInfo)
                    {
                        if (info.IsSimAProgenitor(simDesc.SimDescriptionId) || info.IsSimAnAncestor(simDesc.SimDescriptionId))
                        {
                            return(true);
                        }
                    }

                    Common.StringBuilder msg = new Common.StringBuilder("FutureDescendantHouseholdInfo");
                    msg += Common.NewLine + simDesc.FullName;

                    FutureDescendantService.FutureDescendantHouseholdInfo item = new FutureDescendantService.FutureDescendantHouseholdInfo();

                    List <SimDescription> tests = new List <SimDescription>();

                    try
                    {
                        tests.Add(simDesc);

                        item.AddProgenitorSim(simDesc.SimDescriptionId);

                        SimDescription mate = simDesc.Partner;
                        if (mate == null)
                        {
                            mate = GetPotentialMate(simDesc, tests, true);
                            if (mate == null)
                            {
                                mate = GetPotentialMate(simDesc, tests, false);
                                if (mate == null)
                                {
                                    msg += Common.NewLine + "Fail";
                                    return(false);
                                }
                            }
                        }

                        msg += Common.NewLine + mate.FullName;

                        tests.Add(mate);

                        item.AddProgenitorSim(mate.SimDescriptionId);

                        SimDescription inLaw = GetPotentialInLaw(simDesc, mate, tests, true);
                        if (inLaw == null)
                        {
                            inLaw = GetPotentialInLaw(simDesc, mate, tests, false);
                            if (inLaw == null)
                            {
                                msg += Common.NewLine + "Fail";
                                return(false);
                            }
                        }

                        msg += Common.NewLine + inLaw.FullName;

                        tests.Add(inLaw);

                        item.AddProgenitorSim(inLaw.SimDescriptionId);

                        mate = inLaw.Partner;
                        if (mate == null)
                        {
                            mate = GetPotentialMate(inLaw, tests, true);
                            if (mate == null)
                            {
                                mate = GetPotentialMate(inLaw, tests, false);
                                if (mate == null)
                                {
                                    msg += Common.NewLine + "Fail";
                                    return(false);
                                }
                            }
                        }

                        msg += Common.NewLine + mate.FullName;

                        item.AddProgenitorSim(mate.SimDescriptionId);

                        if (item.mProgenitorSimIds.Count != 4)
                        {
                            msg += Common.NewLine + "Fail";
                            return(false);
                        }
                    }
                    finally
                    {
                        Common.DebugWriteLog(msg);
                    }

                    FutureDescendantService.sPersistableData.ActiveDescendantHouseholdsInfo.Add(item);
                }
                return(true);
            }
            catch (Exception e)
            {
                Common.Exception(simDesc, e);
                return(false);
            }
        }
Exemple #6
0
        protected void Perform(StoryProgressionObject manager, IScoringGenerator stats, string tag, List <SimDescription> movers, ChildrenMove children, bool ignoreHead)
        {
            if (movers.Count == 0)
            {
                return;
            }

            SimDescription focus = movers[0];

            if (focus.Household == null)
            {
                stats.IncStat(tag + " Break: No Home");

                mGoing.AddRange(movers);
                return;
            }
            else if (SimTypes.IsSpecial(focus))
            {
                stats.IncStat(tag + " Break: Special");

                mGoing.AddRange(movers);
                return;
            }
            else
            {
                bool adult = false;
                foreach (SimDescription sim in movers)
                {
                    if (manager.Households.AllowGuardian(sim))
                    {
                        adult = true;
                        break;
                    }
                }

                if (!adult)
                {
                    stats.IncStat(tag + " Break: Child Transfer");

                    mStaying.AddRange(Households.All(focus.Household));

                    foreach (SimDescription sim in movers)
                    {
                        if (SimTypes.IsSelectable(sim))
                        {
                            continue;
                        }

                        mStaying.Remove(sim);

                        mGoing.Add(sim);
                    }

                    return;
                }

                List <SimDescription> going   = new List <SimDescription>();
                List <SimDescription> staying = new List <SimDescription>();
                List <SimDescription> houseChildrenPetsPlumbots = new List <SimDescription>();

                bool ancestral = manager.GetValue <IsAncestralOption, bool>(focus.Household);

                SimDescription head = null;
                if (!ignoreHead)
                {
                    head = SimTypes.HeadOfFamily(focus.Household);
                }
                else if (ancestral)
                {
                    stats.IncStat(tag + " Break: Ancestral Head Denied");

                    mStaying.AddRange(Households.All(focus.Household));
                    return;
                }

                foreach (SimDescription sim in Households.All(focus.Household))
                {
                    stats.IncStat(sim.FullName, Common.DebugLevel.Logging);

                    SimDescription partner = null;
                    if (SimTypes.IsSelectable(sim))
                    {
                        stats.IncStat(tag + " Break: Active");

                        staying.Add(sim);
                    }
                    else if (!manager.Households.Allow(stats, sim, 0))
                    {
                        stats.IncStat(tag + " Break: User Denied");

                        staying.Add(sim);
                    }
                    else if (IsPartner(sim, staying, out partner))
                    {
                        stats.IncStat(tag + " Break: Partner Stay");

                        staying.Add(sim);
                    }
                    else if ((IsPartner(sim, movers, out partner)) || (IsPartner(sim, going, out partner)))
                    {
                        if ((head == sim) && (Households.NumHumans(focus.Household) != 1))
                        {
                            stats.IncStat(tag + " Break: Partner Go Denied");

                            going.Remove(partner);

                            staying.Add(sim);

                            if (!staying.Contains(partner))
                            {
                                staying.Add(partner);
                            }
                        }
                        else
                        {
                            stats.IncStat(tag + " Break: Partner Go");

                            going.Add(sim);
                        }
                    }
                    else if (movers.Contains(sim))
                    {
                        if ((head == sim) && (Households.NumHumans(focus.Household) != 1))
                        {
                            stats.IncStat(tag + " Break: Go Denied");

                            staying.Add(sim);
                        }
                        else
                        {
                            stats.IncStat(tag + " Break: Go");

                            going.Add(sim);
                        }
                    }
                    else if (head == sim)
                    {
                        stats.IncStat(tag + " Break: Head Stay");

                        staying.Add(sim);
                    }
                    else if ((sim.YoungAdultOrAbove) && (!sim.IsPet) && (!sim.IsEP11Bot))
                    {
                        stats.IncStat(tag + " Break: Stay");

                        staying.Add(sim);
                    }
                    else
                    {
                        houseChildrenPetsPlumbots.Add(sim);
                    }
                }

                List <SimDescription> extraChildrenPets = new List <SimDescription>();
                foreach (SimDescription child in houseChildrenPetsPlumbots)
                {
                    bool bGoing = false;
                    bool bMatch = false;

                    if (child.IsPet)
                    {
                        int goingLiking = int.MinValue;
                        foreach (SimDescription foci in going)
                        {
                            if (child.LastName == foci.LastName)
                            {
                                bMatch = true;

                                int liking = ManagerSim.GetLTR(child, foci);
                                if (goingLiking < liking)
                                {
                                    goingLiking = liking;
                                }
                            }
                        }

                        int stayingLiking = int.MinValue;
                        foreach (SimDescription foci in staying)
                        {
                            if (child.LastName == foci.LastName)
                            {
                                bMatch = true;

                                int liking = ManagerSim.GetLTR(child, foci);
                                if (stayingLiking < liking)
                                {
                                    stayingLiking = liking;
                                }
                            }
                        }

                        if (goingLiking > stayingLiking)
                        {
                            bGoing = true;
                        }
                    }
                    else
                    {
                        // this will handle plumbots that are related to the family (i.e. creation)
                        if (children == ChildrenMove.RelatedStay)
                        {
                            foreach (SimDescription parent in Relationships.GetParents(child))
                            {
                                if (staying.Contains(parent))
                                {
                                    bMatch = true;
                                }
                            }
                        }
                        else if (children == ChildrenMove.RelatedGo)
                        {
                            foreach (SimDescription parent in Relationships.GetParents(child))
                            {
                                if (going.Contains(parent))
                                {
                                    bMatch = true;
                                }
                            }
                        }
                        else if (children != ChildrenMove.Stay)
                        {
                            foreach (SimDescription foci in going)
                            {
                                if (Relationships.GetChildren(foci).Contains(child))
                                {
                                    bMatch = true;
                                    if ((children != ChildrenMove.Scoring) || (ScoreChildMove(stats, tag, child, going)))
                                    {
                                        bGoing = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (child.IsEP11Bot && !bGoing)
                    {
                        // test the liking for Plumbots without the HumanEmotion chip
                        if (!manager.Households.AllowGuardian(child))
                        {
                            bMatch = true;
                            int goingLiking = int.MinValue;
                            foreach (SimDescription foci in going)
                            {
                                int liking = ManagerSim.GetLTR(child, foci);
                                if (goingLiking < liking)
                                {
                                    goingLiking = liking;
                                }
                            }

                            int stayingLiking = int.MinValue;
                            foreach (SimDescription foci in staying)
                            {
                                int liking = ManagerSim.GetLTR(child, foci);
                                if (stayingLiking < liking)
                                {
                                    stayingLiking = liking;
                                }
                            }

                            if (goingLiking > stayingLiking)
                            {
                                bGoing = true;
                            }
                        }
                    }

                    stats.IncStat(child.FullName, Common.DebugLevel.Logging);

                    if ((!bMatch) && (manager.Households.AllowSoloMove(child)))
                    {
                        stats.IncStat(tag + " Break: Teen Stay");

                        staying.Add(child);
                    }
                    else if (bGoing)
                    {
                        if (children == ChildrenMove.Go)
                        {
                            stats.IncStat(tag + " Break: Child Go");
                        }
                        else
                        {
                            stats.IncStat(tag + " Break: Child Scoring Go");
                        }

                        going.Add(child);
                    }
                    else
                    {
                        if (children == ChildrenMove.Stay)
                        {
                            stats.IncStat(tag + " Break: Child Stay");
                        }
                        else if (bMatch)
                        {
                            stats.IncStat(tag + " Break: Child Scoring Stay");
                        }

                        extraChildrenPets.Add(child);
                    }
                }

                bool foundAdult = false, foundBlood = false;
                foreach (SimDescription sim in staying)
                {
                    if (manager.Deaths.IsDying(sim))
                    {
                        continue;
                    }

                    if (!manager.Households.AllowGuardian(sim))
                    {
                        continue;
                    }

                    if (ancestral)
                    {
                        if (Relationships.IsCloselyRelated(head, sim, false))
                        {
                            foundBlood = true;
                        }
                    }

                    foundAdult = true;
                }

                if ((!foundAdult) || ((ancestral) && (!foundBlood)))
                {
                    stats.AddStat(tag + " Break: Extra", extraChildrenPets.Count);

                    going.AddRange(extraChildrenPets);

                    if (ancestral)
                    {
                        stats.IncStat(tag + " Break: Ancestral");

                        mStaying.AddRange(going);
                        return;
                    }
                }

                mStaying.AddRange(staying);

                foreach (SimDescription sim in mStaying)
                {
                    going.Remove(sim);
                }

                mGoing.AddRange(going);
            }
        }
Exemple #7
0
        protected bool HandleDoppleganger(SimDescription loadedSim, Dictionary <ulong, IMiniSimDescription> preExistingSims, Dictionary <ulong, IMiniSimDescription> allSims, List <SimDescription> dependents)
        {
            List <SimDescription> choices = FindSim(loadedSim, preExistingSims);

            if (choices.Count == 0)
            {
                return(false);
            }

            SimDescription existingSim = null;

            if ((choices.Count == 1) && (!mAskedAndAnswered))
            {
                mAskedAndAnswered = true;

                mPrompt = !AcceptCancelDialog.Show(Common.Localize("Doppleganger:Prompt"));
            }

            if ((choices.Count == 1) && (!mPrompt))
            {
                existingSim = choices[0];
            }
            else
            {
                choices.Add(loadedSim);

                existingSim = new DopplegangerSelection(loadedSim, choices).SelectSingle();
            }

            if (existingSim == null)
            {
                return(false);
            }

            if (existingSim == loadedSim)
            {
                return(false);
            }

            if (existingSim.Genealogy == null)
            {
                existingSim.Fixup();
            }

            if ((loadedSim.Genealogy != null) && (existingSim.Genealogy != null))
            {
                loadedSim.Genealogy.ClearDerivedData();

                dependents.AddRange(Relationships.GetChildren(loadedSim));

                new Relationships.RepairParents().Perform(existingSim, loadedSim.Genealogy.mNaturalParents, UnusedLog, allSims);
                new Relationships.RepairChildren().Perform(existingSim, loadedSim.Genealogy.mChildren, UnusedLog, allSims);
                new Relationships.RepairSiblings().Perform(existingSim, loadedSim.Genealogy.mSiblings, UnusedLog, allSims);

                new Relationships.RepairParents().Perform(existingSim, loadedSim.Genealogy.mNaturalParents, UnusedLog, preExistingSims);
                new Relationships.RepairChildren().Perform(existingSim, loadedSim.Genealogy.mChildren, UnusedLog, preExistingSims);
                new Relationships.RepairSiblings().Perform(existingSim, loadedSim.Genealogy.mSiblings, UnusedLog, preExistingSims);
            }

            List <Relationship> relations = new List <Relationship>(Relationship.GetRelationships(loadedSim));

            if (relations != null)
            {
                foreach (Relationship relation in relations)
                {
                    if (relation == null)
                    {
                        continue;
                    }

                    Relationship newRelation = Relationship.Get(existingSim, relation.GetOtherSimDescription(loadedSim), true);
                    if (newRelation == null)
                    {
                        continue;
                    }

                    newRelation.LTR.ForceChangeState(relation.LTR.CurrentLTR);
                    newRelation.LTR.SetLiking(relation.LTR.Liking);
                    newRelation.LTR.AddInteractionBit(relation.LTR.LTRInteractionBits);
                }
            }

            if (loadedSim.mPartner != null)
            {
                dependents.Add(loadedSim.mPartner);
            }

            if ((loadedSim.Genealogy != null) && (existingSim.Genealogy != null))
            {
                if ((existingSim.Genealogy.Spouse == null) && (loadedSim.Genealogy.Spouse != null))
                {
                    existingSim.Genealogy.mSpouse         = loadedSim.Genealogy.Spouse;
                    existingSim.Genealogy.mSpouse.mSpouse = existingSim.Genealogy;

                    existingSim.mPartner = existingSim.Genealogy.mSpouse.SimDescription;

                    if (existingSim.mPartner != null)
                    {
                        existingSim.mPartner.mPartner = existingSim;
                    }
                }
            }

            if ((existingSim.mPartner == null) && (loadedSim.mPartner != null))
            {
                existingSim.mPartner          = loadedSim.mPartner;
                existingSim.mPartner.mPartner = existingSim;
            }

            dependents.Add(existingSim);

            return(true);
        }
Exemple #8
0
        public ICollection <SimDescription> Filter(Parameters parameters, string name, SimDescription sim, ICollection <SimDescription> potentials)
        {
            if (!mEnabled)
            {
                parameters.IncStat(name + " Disabled");

                if (parameters.mDefaultAll)
                {
                    return(parameters.mManager.Sims.All);
                }
                else
                {
                    return(potentials);
                }
            }

            Collect(sim);

            if ((sim != null) && (potentials == null))
            {
                switch (mStandardFilter)
                {
                case StandardFilter.Me:
                    potentials = new List <SimDescription>();
                    potentials.Add(sim);
                    break;

                case StandardFilter.Partner:
                    potentials = new List <SimDescription>();
                    if (sim.Partner != null)
                    {
                        potentials.Add(sim.Partner);
                    }
                    break;

                case StandardFilter.AnyFlirt:
                    potentials = parameters.mManager.Flirts.FindAnyFor(parameters, sim, mAllowAffair, false);
                    break;

                case StandardFilter.ExistingFriend:
                    potentials = parameters.mManager.Friends.FindExistingFriendFor(parameters, sim, mStandardGate, mStandardIgnoreBusy);
                    break;

                case StandardFilter.Partnered:
                    potentials = parameters.mManager.Romances.FindPartneredFor(sim);
                    break;

                case StandardFilter.ExistingFlirt:
                    potentials = parameters.mManager.Flirts.FindExistingFor(parameters, sim, mStandardDisallowPartner);
                    break;

                case StandardFilter.ExistingOrAnyFlirt:
                    potentials = parameters.mManager.Flirts.FindExistingFor(parameters, sim, mStandardDisallowPartner);
                    if ((potentials == null) || (potentials.Count == 0))
                    {
                        potentials = parameters.mManager.Flirts.FindAnyFor(parameters, sim, mAllowAffair, false);
                    }
                    break;

                case StandardFilter.ExistingEnemy:
                    potentials = parameters.mManager.Friends.FindExistingEnemyFor(parameters, sim, mStandardGate, mStandardIgnoreBusy);
                    break;

                case StandardFilter.Nemesis:
                    potentials = parameters.mManager.Friends.FindNemesisFor(parameters, sim, mStandardIgnoreBusy);
                    break;
                }

                if (potentials != null)
                {
                    parameters.AddStat(name + " " + mStandardFilter.ToString(), potentials.Count);
                }
            }

            SimPersonality clan = parameters.mManager as SimPersonality;

            if (!string.IsNullOrEmpty(mClan))
            {
                clan = parameters.mManager.Personalities.GetPersonality(mClan);
                if (clan == null)
                {
                    parameters.IncStat(mClan + " Missing");
                    return(new List <SimDescription>());
                }
            }

            if (clan != null)
            {
                if (potentials == null)
                {
                    if (mClanMembers)
                    {
                        potentials = clan.GetClanMembers(mClanLeader);

                        parameters.mIsFriendly = true;
                    }
                    else if (mClanLeader)
                    {
                        potentials = clan.MeAsList;

                        parameters.mIsFriendly = true;
                    }

                    if (potentials != null)
                    {
                        parameters.AddStat(name + " Clan", potentials.Count);
                    }
                }
                else if ((mClanLeader) || (mClanMembers))
                {
                    List <SimDescription> clanPotentials = new List <SimDescription>();

                    foreach (SimDescription potential in potentials)
                    {
                        if (clan.Me == potential)
                        {
                            if (!mClanLeader)
                            {
                                parameters.IncStat(name + " Leader Denied");
                                continue;
                            }
                        }
                        else if (clan.IsMember(potential))
                        {
                            if (!mClanMembers)
                            {
                                parameters.IncStat(name + " Member Denied");
                                continue;
                            }
                        }
                        else
                        {
                            parameters.IncStat(name + " Non-clan Denied");
                            continue;
                        }

                        clanPotentials.Add(potential);
                    }

                    potentials = clanPotentials;
                }
            }

            if (potentials == null)
            {
                potentials = parameters.mManager.Sims.All;

                parameters.AddStat(name + " All", potentials.Count);
            }

            parameters.AddStat(name + " Potentials", potentials.Count);

            ScoringList <SimDescription> list = new ScoringList <SimDescription>();

            foreach (SimDescription potential in potentials)
            {
                int score = 0;
                if (!Test(parameters, name, sim, potential, true, out score))
                {
                    continue;
                }

                list.Add(potential, score);

                parameters.mManager.Main.Sleep("SimScenarioFilter:Filter");
            }

            List <SimDescription> results = list.GetBestByPercent(100);

            parameters.AddStat(name + " Results", results.Count);

            if (mThirdPartyFilter != ThirdPartyFilter.None)
            {
                Dictionary <SimDescription, bool> lookup = new Dictionary <SimDescription, bool>();

                foreach (SimDescription result in results)
                {
                    switch (mThirdPartyFilter)
                    {
                    case ThirdPartyFilter.Romantic:
                        foreach (Relationship relation in Relationship.Get(result))
                        {
                            if (!relation.AreRomantic())
                            {
                                continue;
                            }

                            SimDescription other = relation.GetOtherSimDescription(result);
                            if (other == null)
                            {
                                continue;
                            }

                            lookup[other] = true;
                        }
                        break;

                    case ThirdPartyFilter.Friend:
                        foreach (Relationship relation in Relationship.Get(result))
                        {
                            if (!relation.AreFriends())
                            {
                                continue;
                            }

                            SimDescription other = relation.GetOtherSimDescription(result);
                            if (other == null)
                            {
                                continue;
                            }

                            lookup[other] = true;
                        }
                        break;

                    case ThirdPartyFilter.Enemy:
                        foreach (Relationship relation in Relationship.Get(result))
                        {
                            if (!relation.AreEnemies())
                            {
                                continue;
                            }

                            SimDescription other = relation.GetOtherSimDescription(result);
                            if (other == null)
                            {
                                continue;
                            }

                            lookup[other] = true;
                        }
                        break;

                    case ThirdPartyFilter.Partner:
                        if (result.Partner == null)
                        {
                            continue;
                        }

                        lookup[result.Partner] = true;
                        break;

                    case ThirdPartyFilter.Parents:
                        foreach (SimDescription parent in Relationships.GetParents(result))
                        {
                            lookup[parent] = true;
                        }
                        break;

                    case ThirdPartyFilter.Siblings:
                        foreach (SimDescription sibling in Relationships.GetSiblings(result))
                        {
                            lookup[sibling] = true;
                        }
                        break;

                    case ThirdPartyFilter.Children:
                        foreach (SimDescription child in Relationships.GetChildren(result))
                        {
                            lookup[child] = true;
                        }
                        break;
                    }

                    parameters.mManager.Main.Sleep("SimScenarioFilter:Filter");
                }

                results.Clear();
                results.AddRange(lookup.Keys);

                parameters.AddStat(name + " " + mThirdPartyFilter, results.Count);
            }

            return(results);
        }