Esempio n. 1
0
        protected override bool Allow(Household house)
        {
            if (Lots.FindLot(this, HouseholdsEx.All(house), 0, ManagerLot.FindLotFlags.Inspect, OnLotPriceCheck) == null)
            {
                IncStat("No Homes");
                return(false);
            }

            return(base.Allow(house));
        }
Esempio n. 2
0
        protected override bool Allow()
        {
            if (GetValue <ScheduledImmigrationScenario.GaugeOption, int>() <= 0)
            {
                IncStat("Gauge Fail");
                return(false);
            }
            else if (ImmigrateScenario.TestEmptyHomes(this))
            {
                if (Lots.FindLot(this, null, 0, ManagerLot.FindLotFlags.CheapestHome | ManagerLot.FindLotFlags.Inspect, null) != null)
                {
                    IncStat("Lot Found");
                    return(false);
                }
            }

            return(base.Allow());
        }
Esempio n. 3
0
        protected override bool Allow()
        {
            if (Sims.HasEnough(this, CASAgeGenderFlags.Human))
            {
                IncStat("Town Full");
                return(false);
            }
            else if (!TestEmptyHomes(this))
            {
                IncStat("Too Few Empty");
                return(false);
            }
            else if (Lots.FindLot(this, null, 0, ManagerLot.FindLotFlags.Inspect | ManagerLot.FindLotFlags.CheapestHome, OnLotPriceCheck) == null)
            {
                IncStat("No Empty");
                return(false);
            }

            return(base.Allow());
        }
Esempio n. 4
0
        protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            if (mCheckRequired)
            {
                if (!mRequirement.mRequired)
                {
                    return(false);
                }
            }

            List <CASAgeGenderFlags> ageGenderRequirements = new List <CASAgeGenderFlags>();

            if ((!mRequirement.mNeedMale) && (!mRequirement.mNeedFemale))
            {
                if (BabyGenderScenario.GetGenderByFirstBorn(Manager, GetValue <GenderOption, BabyGenderScenario.FirstBornGender>(), false) == CASAgeGenderFlags.Male)
                {
                    mRequirement.mNeedMale = true;
                }
                else
                {
                    mRequirement.mNeedFemale = true;
                }
            }

            bool teenMoveIn = false;

            if (mRequirement.mMate == null)
            {
                if (RandomUtil.RandomChance(GetValue <TeenChanceOption, int>()))
                {
                    teenMoveIn = true;
                }
            }
            else if (mRequirement.mMate.Teen)
            {
                teenMoveIn = true;
            }

            if (mRequirement.mNeedMale)
            {
                CASAgeGenderFlags age = CASAgeGenderFlags.Male | CASAgeGenderFlags.Human;
                if (teenMoveIn)
                {
                    age |= CASAgeGenderFlags.Teen;
                }
                else //if ((mRequirement.CareerLevel != null) && (mRequirement.CareerLevel.Level > 5))
                {
                    age |= CASAgeGenderFlags.YoungAdult;
                    age |= CASAgeGenderFlags.Adult;
                }

                ageGenderRequirements.Add(age);
            }

            if (mRequirement.mNeedFemale)
            {
                CASAgeGenderFlags age = CASAgeGenderFlags.Female | CASAgeGenderFlags.Human;
                if (teenMoveIn)
                {
                    age |= CASAgeGenderFlags.Teen;
                }
                else if (mRequirement.mFertile)
                {
                    age |= CASAgeGenderFlags.YoungAdult;
                }
                else //((mRequirement.CareerLevel != null) && (mRequirement.CareerLevel.Level > 5) && )
                {
                    age |= CASAgeGenderFlags.YoungAdult;
                    age |= CASAgeGenderFlags.Adult;
                }

                ageGenderRequirements.Add(age);
            }

            bool singleParent = false;

            Lot familyLot = null;

            if (((mRequirement.mMate == null) || (!mCheckRequired)) && (GetValue <WholeFamilyOption, int>() > 0) && (!RandomUtil.RandomChance(GetValue <SingleSimOption, int>())))
            {
                IncStat("WholeFamily");

                familyLot = Lots.FindLot(this, null, 0, ManagerLot.FindLotFlags.CheapestHome | ManagerLot.FindLotFlags.Inspect, OnLotPriceCheck);
                if (familyLot == null)
                {
                    return(false);
                }

                if (RandomUtil.RandomChance(GetValue <ChanceOfSingleOption, int>()))
                {
                    IncStat("Single Parent");
                    singleParent = true;
                }
                else if (familyLot.CountObjects <IBedDouble>() == 0)
                {
                    if (familyLot.CountObjects <IBedSingle>() > 1)
                    {
                        IncStat("Single Parent");
                        singleParent = true;
                    }
                    else
                    {
                        IncStat("No Double Bed");
                        familyLot = null;
                    }
                }
            }

            using (SimFromBin <ManagerLot> simBin = new SimFromBin <ManagerLot>(this, Lots))
            {
                List <SimDescription> sims = new List <SimDescription>();

                CASAgeGenderFlags genders = CASAgeGenderFlags.Male | CASAgeGenderFlags.Female;

                if (familyLot != null)
                {
                    BabyGenderScenario.FirstBornGender genderPref = GetValue <GenderOption, BabyGenderScenario.FirstBornGender>();

                    bool bothGenders = true;
                    if ((genderPref == BabyGenderScenario.FirstBornGender.Male) ||
                        (genderPref == BabyGenderScenario.FirstBornGender.Female))
                    {
                        bothGenders = false;
                    }
                    else if (RandomUtil.RandomChance(GetValue <ManagerFlirt.ChanceOfGaySim, int>()))
                    {
                        bothGenders = false;
                    }

                    if (ageGenderRequirements.Count == 1)
                    {
                        if (bothGenders)
                        {
                            if ((ageGenderRequirements[0] & CASAgeGenderFlags.Male) == CASAgeGenderFlags.Male)
                            {
                                ageGenderRequirements.Add(CASAgeGenderFlags.Female | (ageGenderRequirements[0] & CASAgeGenderFlags.AgeMask));
                            }
                            else
                            {
                                ageGenderRequirements.Add(CASAgeGenderFlags.Male | (ageGenderRequirements[0] & CASAgeGenderFlags.AgeMask));
                            }
                        }
                        else
                        {
                            genders = ageGenderRequirements[0] & CASAgeGenderFlags.GenderMask;

                            ageGenderRequirements.Add(ageGenderRequirements[0]);
                        }
                    }
                }

                foreach (CASAgeGenderFlags ageGender in ageGenderRequirements)
                {
                    SimDescription sim = simBin.CreateNewSim(ageGender & CASAgeGenderFlags.AgeMask, ageGender & CASAgeGenderFlags.GenderMask, CASAgeGenderFlags.Human);
                    if (sim == null)
                    {
                        IncStat("Creation Failure");
                    }
                    else
                    {
                        sims.Add(sim);
                    }
                }

                if (familyLot == null)
                {
                    if (sims.Count > 0)
                    {
                        Add(frame, new ImmigrantMailOrderScenario(mRequirement, sims), ScenarioResult.Start);
                    }
                }
                else
                {
                    bool createChildren = true;

                    SimDescription otherParent = null;

                    List <SimDescription> parents = new List <SimDescription>(sims);
                    if (parents.Count > 1)
                    {
                        otherParent = parents[1];

                        if (parents[1].IsMale)
                        {
                            parents[0].InternalIncreaseGenderPreferenceMale();
                        }
                        else
                        {
                            parents[0].InternalIncreaseGenderPreferenceFemale();
                        }

                        if (parents[0].IsMale)
                        {
                            parents[1].InternalIncreaseGenderPreferenceMale();
                        }
                        else
                        {
                            parents[1].InternalIncreaseGenderPreferenceFemale();
                        }

                        Relationship relation = Relationship.Get(parents[0], parents[1], true);
                        if (relation != null)
                        {
                            relation.MakeAcquaintances();
                        }

                        if (GameUtils.IsUniversityWorld())
                        {
                            createChildren = true;
                            IncStat("Immigrant Friends");
                        }
                        else if (!RandomUtil.RandomChance(GetValue <ChanceOfFriendsOption, int>()))
                        {
                            Dictionary <string, List <News.NewsTuning.ArticleTuning> > namedArticles = News.sNewsTuning.mNamedArticles;

                            try
                            {
                                // Doing so stops Marriage notices of imported sims from appearing in the newspaper
                                News.sNewsTuning.mNamedArticles = new Dictionary <string, List <News.NewsTuning.ArticleTuning> >();

                                if (RandomUtil.RandomChance(GetValue <ChanceOfPartnerOption, int>()))
                                {
                                    IncStat("Immigrant Partners");

                                    while (relation.CurrentLTR != LongTermRelationshipTypes.Partner)
                                    {
                                        if (!Romances.BumpToHigherState(this, parents[0], parents[1]))
                                        {
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    if (!Romances.BumpToHighestState(this, parents[0], parents[1]))
                                    {
                                        IncStat("Unmarriable");
                                        createChildren = false;
                                    }
                                    else
                                    {
                                        parents[1].LastName = parents[0].LastName;
                                    }
                                }
                            }
                            finally
                            {
                                News.sNewsTuning.mNamedArticles = namedArticles;
                            }
                        }
                        else
                        {
                            createChildren = false;
                            IncStat("Immigrant Friends");
                        }
                    }

                    if (createChildren)
                    {
                        Lot.LotMetrics metrics = new Lot.LotMetrics();
                        familyLot.GetLotMetrics(ref metrics);

                        int totalChildren = GetValue <WholeFamilyOption, int>();
                        if (totalChildren > Options.GetValue <MaximumSizeOption, int>())
                        {
                            totalChildren = Options.GetValue <MaximumSizeOption, int>();
                        }

                        totalChildren -= parents.Count;

                        totalChildren = RandomUtil.GetInt(totalChildren - 1) + 1;

                        AddStat("Allowed Children", totalChildren);

                        int totalBeds = metrics.BedCount - parents.Count;
                        if (totalBeds > totalChildren)
                        {
                            totalBeds = totalChildren;
                        }

                        AddStat("Available Beds", totalBeds);

                        if (!GameUtils.IsUniversityWorld())
                        {
                            int numCribs = RandomUtil.GetInt((int)familyLot.CountObjects <Sims3.Gameplay.Objects.Beds.Crib>());

                            // Create the children
                            if (numCribs > 2)
                            {
                                numCribs = 2;
                            }

                            if (numCribs > totalChildren)
                            {
                                numCribs = totalChildren;
                            }

                            AddStat("Available Cribs", numCribs);

                            for (int i = 0; i < numCribs; i++)
                            {
                                SimDescription sim = simBin.CreateNewSim(parents[0], otherParent, CASAgeGenderFlags.Toddler, genders, parents[0].Species, true);
                                if (sim == null)
                                {
                                    IncStat("Creation Failure");
                                }
                                else
                                {
                                    sims.Add(sim);

                                    totalBeds--;
                                }
                            }

                            if ((!parents[0].Teen) && ((otherParent == null) || (!otherParent.Teen)))
                            {
                                for (int i = 0; i < totalBeds; i++)
                                {
                                    SimDescription sim = simBin.CreateNewSim(parents[0], otherParent, CASAgeGenderFlags.Child | CASAgeGenderFlags.Teen, genders, parents[0].Species, true);
                                    if (sim == null)
                                    {
                                        IncStat("Creation Failure");
                                    }
                                    else
                                    {
                                        sims.Add(sim);
                                    }
                                }
                            }
                        }
                        else
                        {
                            for (int i = 0; i < totalBeds; i++)
                            {
                                SimDescription sim = simBin.CreateNewSim(CASAgeGenderFlags.YoungAdult | CASAgeGenderFlags.Adult, genders, parents[0].Species);
                                if (sim == null)
                                {
                                    IncStat("Creation Failure");
                                }
                                else
                                {
                                    sims.Add(sim);
                                }
                            }
                        }

                        if ((singleParent) && (otherParent != null))
                        {
                            sims.Remove(otherParent);

                            parents.Remove(otherParent);

                            if (otherParent.Partner != null)
                            {
                                otherParent.Partner.Partner = null;
                                otherParent.Partner         = null;
                            }

                            otherParent.Dispose(true, false, true);
                        }
                    }
                }

                if ((GameUtils.IsInstalled(ProductVersion.EP5)) &&
                    (RandomUtil.RandomChance(GetValue <PetChanceOption, int>())))
                {
                    List <CASAgeGenderFlags> choices = new List <CASAgeGenderFlags>();

                    foreach (SimDescription sim in sims)
                    {
                        PetAdoptionBaseScenario.GetPossibleSpecies(this, familyLot, sim, false, choices);
                    }

                    AddStat("Pet Choices", choices.Count);

                    if (choices.Count > 0)
                    {
                        int numberPets = RandomUtil.GetInt(1, GetValue <MaximumPetsOption, int>() - 1);

                        AddStat("Pet Immigrants", numberPets);

                        for (int i = 0; i < numberPets; i++)
                        {
                            CASAgeGenderFlags species = RandomUtil.GetRandomObjectFromList(choices);
                            if (Sims.HasEnough(this, species))
                            {
                                continue;
                            }

                            SimDescription pet = simBin.CreateNewSim(CASAgeGenderFlags.Child | CASAgeGenderFlags.Adult | CASAgeGenderFlags.Elder, CASAgeGenderFlags.Male | CASAgeGenderFlags.Female, species);
                            if (pet != null)
                            {
                                pet.LastName = sims[0].LastName;

                                sims.Add(pet);
                            }
                            else
                            {
                                IncStat("Pet Creation Fail");
                            }
                        }
                    }
                }

                Add(frame, new ImmigrantMoveInScenario(sims), ScenarioResult.Start);
                Add(frame, new NewImmigrantScenario(sims, mRequirement), ScenarioResult.Success);
            }

            return(true);
        }
Esempio n. 5
0
        protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            ManagerLot.FindLotFlags flags = Inspect;
            if (CheapestHome)
            {
                flags |= ManagerLot.FindLotFlags.CheapestHome;
            }

            Lot lot = Lots.FindLot(this, mMovers, MaximumLoan, flags, OnLotPriceCheck);

            if (lot == null)
            {
                IncStat("No Lot");
                return(false);
            }
            else if (lot.Household != null)
            {
                IncStat("Occupied");
                return(false);
            }

            int lotCost = Lots.GetLotCost(lot);

            AddStat("Lot Cost", lotCost);

            List <SimDescription> sims = new List <SimDescription>(mMovers);

            Dictionary <Household, bool> oldHouses = new Dictionary <Household, bool>();

            House = null;

            foreach (SimDescription sim in sims)
            {
                if (House == null)
                {
                    if (SimTypes.IsSpecial(sim))
                    {
                        break;
                    }
                    else if (HouseholdsEx.NumSims(sim.Household) == sims.Count)
                    {
                        House = sim.Household;
                    }
                }
                else if (House != sim.Household)
                {
                    House = null;
                    break;
                }
            }

            int newFunds = 0;

            Lot oldLot = null;

            mNewHouse = false;
            if (House == null)
            {
                House = Household.Create();
                House.ModifyFamilyFunds(-House.FamilyFunds);

                House.SetName(sims[0].LastName);

                SetValue <AcountingOption, AccountingData>(House, new AccountingData());

                mNewHouse = true;
            }
            else if (House.LotHome != null)
            {
                oldLot = House.LotHome;

                newFunds = Lots.GetLotCost(House.LotHome);

                Lots.ProcessAbandonLot(oldLot);

                House.MoveOut();
            }

            if (OnPresetLotHome != null)
            {
                OnPresetLotHome(lot, House);
            }
            lot.MoveIn(House);

            ManagerSim.ForceRecount();

            Money.AdjustFunds(House, "SellLot", newFunds);

            AddStat("New Home Funds", House.FamilyFunds);

            SetValue <InspectedOption, bool>(House, false);

            if (mNewHouse)
            {
                foreach (SimDescription sim in sims)
                {
                    if (sim.Household != null)
                    {
                        AdjustFundsMoveInLot(sim, oldHouses);
                    }

                    Households.MoveSim(sim, House);

                    if (sim.IsMale)
                    {
                        House.Name = sim.LastName;
                    }
                }
            }

            if (OnLotPriceCheck(this, lot, newFunds, newFunds) != ManagerLot.CheckResult.IgnoreCost)
            {
                PayForMoveInLot(oldHouses, lotCost);
            }

            AddStat("Remaining Funds", House.FamilyFunds);

            foreach (SimDescription sim in sims)
            {
                Sims.Instantiate(sim, lot, true);
            }

            EventTracker.SendEvent(new HouseholdUpdateEvent(EventTypeId.kFamilyMovedInToNewHouse, House));

            if ((oldLot != null) && (GetValue <NotifyOnMoveOption, bool>(House)))
            {
                if (AcceptCancelDialog.Show(Common.Localize("NotifyOnMove:Prompt", false, new object[] { oldLot.Name, oldLot.Address })))
                {
                    if (CameraController.IsMapViewModeEnabled())
                    {
                        Sims3.Gameplay.Core.Camera.ToggleMapView();
                    }

                    Camera.FocusOnLot(oldLot.LotId, 0f);
                }
            }

            SetValue <NotifyOnMoveOption, bool>(House, false);

            return(true);
        }