Exemplo n.º 1
0
        public Lot GetCommunityLot(Sim a, List <CommercialLotSubType> types, bool mustHaveSims)
        {
            if (a == null)
            {
                return(null);
            }

            // Stops an error in HowMuchItWantsSimToCome()
            if (a.CelebrityManager.Level > CelebrityManager.HighestLevel)
            {
                a.CelebrityManager.mLevel = CelebrityManager.HighestLevel;
            }

            ScoringList <Lot> lots = new ScoringList <Lot>();

            foreach (Lot lot in LotManager.AllLotsWithoutCommonExceptions)
            {
                if (!lot.IsCommunityLot)
                {
                    continue;
                }

                if (!AllowSim(this, a, lot))
                {
                    continue;
                }

                if (mustHaveSims)
                {
                    if (lot.GetAllActorsCount() == 0)
                    {
                        continue;
                    }
                }

                if (types != null)
                {
                    if (!types.Contains(lot.CommercialLotSubType))
                    {
                        continue;
                    }
                }

                lots.Add(lot, (int)lot.HowMuchItWantsSimToCome(a, SimClock.HoursPassedOfDay));
            }

            if (lots.Count == 0)
            {
                return(null);
            }

            return(RandomUtil.GetRandomObjectFromList(lots.GetBestByPercent(50f)));
        }
Exemplo n.º 2
0
        protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            ScoringList <SimDescription> scoring = new ScoringList <SimDescription>();

            SimDescription head = SimTypes.HeadOfFamily(House);

            foreach (SimDescription sim in HouseholdsEx.All(House))
            {
                if (!Households.AllowSoloMove(sim))
                {
                    continue;
                }

                if (head != null)
                {
                    if (head == sim)
                    {
                        continue;
                    }

                    if (head.Partner == sim)
                    {
                        continue;
                    }
                }

                scoring.Add(sim, AddScoring("FindOwnHome", sim, sim.Partner));
            }

            List <SimDescription> best = scoring.GetBestByMinScore(1);

            if ((best == null) || (best.Count == 0))
            {
                IncStat("No Choices");
                return(false);
            }
            else
            {
                foreach (SimDescription sim in best)
                {
                    HouseholdBreakdown breakdown = new HouseholdBreakdown(Manager, this, UnlocalizedName, sim, HouseholdBreakdown.ChildrenMove.Scoring, false);

                    Add(frame, new StandardMoveInLotScenario(breakdown, 0), ScenarioResult.Failure);
                    Add(frame, new PostScenario(sim, mPassedInspection), ScenarioResult.Success);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        public Lot GetCommunityLot(Sim a, Sim b)
        {
            if ((a == null) || (b == null))
            {
                return(null);
            }

            // Stops an error in HowMuchItWantsSimToCome()
            if (a.CelebrityManager.Level > CelebrityManager.HighestLevel)
            {
                a.CelebrityManager.mLevel = CelebrityManager.HighestLevel;
            }

            // Stops an error in HowMuchItWantsSimToCome()
            if (b.CelebrityManager.Level > CelebrityManager.HighestLevel)
            {
                b.CelebrityManager.mLevel = CelebrityManager.HighestLevel;
            }

            ScoringList <Lot> lots = new ScoringList <Lot> ();

            foreach (Lot lot in LotManager.AllLotsWithoutCommonExceptions)
            {
                if (!lot.IsCommunityLot)
                {
                    continue;
                }

                if (!AllowSim(this, a, lot))
                {
                    continue;
                }

                if (!AllowSim(this, b, lot))
                {
                    continue;
                }

                lots.Add(lot, (int)(lot.HowMuchItWantsSimToCome(a, SimClock.HoursPassedOfDay) + lot.HowMuchItWantsSimToCome(b, SimClock.HoursPassedOfDay)));
            }

            if (lots.Count == 0)
            {
                return(null);
            }

            return(RandomUtil.GetRandomObjectFromList(lots.GetBestByPercent(50f)));
        }
Exemplo n.º 4
0
        protected override bool Sort(List <Household> houses)
        {
            Dictionary <Household, int> candidates = new Dictionary <Household, int>();

            AddStat("Potentials", houses.Count);

            SimDescription oldestSim = Sim;

            foreach (SimDescription sim in Movers)
            {
                if ((oldestSim == null) || (SimTypes.IsOlderThan(sim, oldestSim)))
                {
                    oldestSim = sim;
                }
            }

            foreach (Household house in houses)
            {
                bool olderFound = false;

                foreach (SimDescription other in HouseholdsEx.All(house))
                {
                    if (Deaths.IsDying(other))
                    {
                        continue;
                    }

                    if (SimTypes.IsOlderThan(other, oldestSim))
                    {
                        olderFound = true;
                    }

                    int count = 0;

                    if (Flirts.IsCloselyRelated(Sim, other))
                    {
                        if (Sim.Genealogy.Parents.Contains(other.Genealogy))
                        {
                            count += 10;
                        }
                        else
                        {
                            count++;
                        }
                    }
                    else if (OnlyFamilyMoveIn)
                    {
                        continue;
                    }

                    bool checkRel = false;
                    if (other.YoungAdultOrAbove)
                    {
                        checkRel = true;
                    }
                    else if ((Households.AllowSoloMove(Sim)) && (other.TeenOrAbove))
                    {
                        checkRel = true;
                    }

                    if (checkRel)
                    {
                        int rel = 0;

                        Relationship relation = Relationship.Get(Sim, other, false);
                        if (relation != null)
                        {
                            rel = (int)(relation.LTR.Liking / 25);

                            if ((relation.AreRomantic()) && (rel > 0))
                            {
                                rel += 5;
                            }

                            count += rel;
                        }

                        if (Households.AllowSoloMove(Sim))
                        {
                            if (rel < 3)
                            {
                                continue;
                            }
                        }
                    }

                    if (Sim.Partner == other)
                    {
                        count += 10;
                    }

                    if (!candidates.ContainsKey(house))
                    {
                        candidates.Add(house, count);
                    }
                    else
                    {
                        candidates[house] += count;
                    }
                }

                if (!olderFound)
                {
                    candidates.Remove(house);
                }
            }

            houses.Clear();
            if (candidates.Count > 0)
            {
                ScoringList <Household> scoring = new ScoringList <Household>();
                foreach (KeyValuePair <Household, int> candidate in candidates)
                {
                    AddScoring("", candidate.Value);

                    scoring.Add(candidate.Key, candidate.Value);
                }

                houses.AddRange(scoring.GetBestByMinScore(1));
            }
            else
            {
                IncStat("No Candidates");
            }

            return(true);
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
        protected override bool Sort(List<Household> houses)
        {
            Dictionary<Household, int> candidates = new Dictionary<Household, int>();

            AddStat("Potentials", houses.Count);

            SimDescription oldestSim = Sim;
            foreach(SimDescription sim in Movers)
            {
                if ((oldestSim == null) || (SimTypes.IsOlderThan(sim, oldestSim)))
                {
                    oldestSim = sim;
                }
            }

            foreach (Household house in houses)
            {
                bool olderFound = false;

                foreach (SimDescription other in HouseholdsEx.All(house))
                {
                    if (Deaths.IsDying(other)) continue;

                    if (SimTypes.IsOlderThan(other, oldestSim))
                    {
                        olderFound = true;
                    }

                    int count = 0;

                    if (Flirts.IsCloselyRelated(Sim, other))
                    {
                        if (Sim.Genealogy.Parents.Contains(other.Genealogy))
                        {
                            count += 10;
                        }
                        else
                        {
                            count++;
                        }
                    }
                    else if (OnlyFamilyMoveIn)
                    {
                        continue;
                    }

                    bool checkRel = false;
                    if (other.YoungAdultOrAbove)
                    {
                        checkRel = true;
                    }
                    else if ((Households.AllowSoloMove(Sim)) && (other.TeenOrAbove))
                    {
                        checkRel = true;
                    }
                    
                    if (checkRel)
                    {
                        int rel = 0;

                        Relationship relation = Relationship.Get(Sim, other, false);
                        if (relation != null)
                        {
                            rel = (int)(relation.LTR.Liking / 25);

                            if ((relation.AreRomantic()) && (rel > 0))
                            {
                                rel += 5;
                            }

                            count += rel;
                        }

                        if (Households.AllowSoloMove(Sim))
                        {
                            if (rel < 3) continue;
                        }
                    }

                    if (Sim.Partner == other)
                    {
                        count += 10;
                    }

                    if (!candidates.ContainsKey(house))
                    {
                        candidates.Add(house, count);
                    }
                    else
                    {
                        candidates[house] += count;
                    }
                }

                if (!olderFound)
                {
                    candidates.Remove(house);
                }
            }

            houses.Clear();
            if (candidates.Count > 0)
            {
                ScoringList<Household> scoring = new ScoringList<Household>();
                foreach (KeyValuePair<Household, int> candidate in candidates)
                {
                    AddScoring("", candidate.Value);

                    scoring.Add(candidate.Key, candidate.Value);
                }

                houses.AddRange(scoring.GetBestByMinScore(1));
            }
            else
            {
                IncStat("No Candidates");
            }

            return true;
        }
Exemplo n.º 7
0
        protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            ScoringList <SimDescription> scoring = new ScoringList <SimDescription>();

            SimDescription head = SimTypes.HeadOfFamily(House);

            foreach (SimDescription sim in House.AllSimDescriptions)
            {
                if ((sim == head) || (sim.Partner == head))
                {
                    continue;
                }

                // Don't move sims that can't move out
                if (!Households.AllowSoloMove(sim))
                {
                    continue;
                }

                // Don't move sims related to the head of family
                if (Flirts.IsCloselyRelated(sim, head))
                {
                    continue;
                }

                // Don't move sims that don't have partners
                if (sim.Partner == null)
                {
                    continue;
                }

                if (!House.AllSimDescriptions.Contains(sim.Partner))
                {
                    continue;
                }

                if (Flirts.IsCloselyRelated(sim.Partner, head))
                {
                    continue;
                }

                scoring.Add(sim, AddScoring("FindOwnHome", sim.Partner, sim));
            }

            ICollection <SimDescription> best = scoring.GetBestByPercent(100);

            if ((best == null) || (best.Count == 0))
            {
                IncStat("No Choices");
                return(false);
            }
            else
            {
                foreach (SimDescription sim in best)
                {
                    HouseholdBreakdown breakdown = new HouseholdBreakdown(Manager, this, UnlocalizedName, sim, HouseholdBreakdown.ChildrenMove.Scoring, false);

                    Add(frame, new StandardMoveInLotScenario(breakdown, 0), ScenarioResult.Failure);
                    Add(frame, new PostScenario(sim), ScenarioResult.Success);
                }
            }

            return(false);
        }
Exemplo n.º 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);
        }