protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            Common.StringBuilder       msg = new Common.StringBuilder();
            List <AcademicDegreeNames> degreesThatNeedProfessors = new List <AcademicDegreeNames>();

            foreach (AcademicDegreeNames degree in Enum.GetValues(typeof(AcademicDegreeNames)))
            {
                if (degree == AcademicDegreeNames.Undefined || degree == AcademicDegreeNames.MaxDegreeNames)
                {
                    continue;
                }

                if (AcademicCareer.sProfessors != null)
                {
                    if (AcademicCareer.sProfessors.ContainsKey(degree) && SimDescription.Find(AcademicCareer.sProfessors[degree]) != null)
                    {
                        continue;
                    }
                }

                msg += "DegreesThatNeedProfessors: " + degree + Common.NewLine;
                degreesThatNeedProfessors.Add(degree);
            }

            if (degreesThatNeedProfessors.Count == 0)
            {
                Common.DebugNotify("No professors needed");
                return(false);
            }

            List <SimDescription>      possibleProfessors    = new List <SimDescription>();
            List <AcademicDegreeNames> degreesWithEnrollment = new List <AcademicDegreeNames>();

            // Sims who have completed X degree

            foreach (SimDescription sim in Sims.Humans)
            {
                msg += Common.NewLine + "Sim: " + sim.FullName;
                if (sim.CareerManager == null)
                {
                    msg += Common.NewLine + "CareerManager null";
                    continue;
                }

                if (sim.ChildOrBelow)
                {
                    msg += Common.NewLine + "ChildOrBelow";
                    continue;
                }

                if (SimTypes.IsSpecial(sim))
                {
                    msg += Common.NewLine + "IsSpecial";
                    continue;
                }

                if (sim.Occupation != null)
                {
                    msg += Common.NewLine + "Employed";
                    if (sim.CareerManager.Occupation is StoryProgressionSpace.Careers.Retired && !GetValue <AllowRetiredElder, bool>())
                    {
                        msg += Common.NewLine + "Retire skip";
                        continue;
                    }

                    if (sim.OccupationAsAcademicCareer == null && !GetValue <AllowQuitOccupation, bool>())
                    {
                        msg += Common.NewLine + "AllowQuitOccupation skip";
                        continue;
                    }

                    AcademicCareer career = sim.OccupationAsAcademicCareer;
                    if (career != null && career.Level == 2)
                    {
                        msg += Common.NewLine + "AlreadyProfessor";
                        continue;
                    }

                    if (career != null && career.DegreeInformation != null && degreesThatNeedProfessors.Contains(career.DegreeInformation.AcademicDegreeName))
                    {
                        if (!degreesWithEnrollment.Contains(career.DegreeInformation.AcademicDegreeName))
                        {
                            // note this isn't added to unless it needs a professor
                            msg += Common.NewLine + "DegreesWithEnrollment: " + career.DegreeInformation.AcademicDegreeName;
                            degreesWithEnrollment.Add(career.DegreeInformation.AcademicDegreeName);
                        }
                    }
                }
                else
                {
                    msg += Common.NewLine + "Unemployed";
                }

                if (sim.Teen || !GetValue <AllowBeProfessorOption, bool>(sim))
                {
                    msg += Common.NewLine + "Teen or !AllowBeProfessor";
                    continue;
                }

                if (!Careers.AllowFindJob(this, sim))
                {
                    msg += Common.NewLine + "!AllowFindJob";
                    continue;
                }

                if (!Careers.TestCareer(this, sim, OccupationNames.AcademicCareer))
                {
                    msg += Common.NewLine + "!TestCareer";
                    continue;
                }

                if (sim.Household != null && sim.Household != Household.ActiveHousehold)
                {
                    msg += Common.NewLine + "PossibleProfessor: " + sim.FullName;
                    possibleProfessors.Add(sim);
                }
            }

            RandomUtil.RandomizeListOfObjects <SimDescription>(possibleProfessors);

            if (degreesWithEnrollment.Count == 0)
            {
                msg += Common.NewLine + "degreesWithEnrollment = 0";
                Common.DebugWriteLog(msg);
                return(false);
            }

            if (possibleProfessors.Count == 0)
            {
                msg += Common.NewLine + "possibleProfessors = 0";
                Common.DebugWriteLog(msg);
                return(false);
            }

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

            foreach (SimDescription pSim in new List <SimDescription>(possibleProfessors))
            {
                msg += Common.NewLine + "Promote loop: " + pSim.FullName;
                foreach (AcademicDegreeNames name in new List <AcademicDegreeNames>(degreesWithEnrollment))
                {
                    // checked because it can get removed
                    if (degreesWithEnrollment.Contains(name))
                    {
                        msg += Common.NewLine + "Degree: " + name;
                        if (pSim.OccupationAsAcademicCareer != null)
                        {
                            msg += Common.NewLine + "University Student";
                            // actively enrolled but has completed the degree we need?
                            if (pSim.CareerManager.DegreeManager != null && pSim.CareerManager.DegreeManager.HasCompletedDegree(name))
                            {
                                msg += Common.NewLine + "HCD: " + name;

                                if (pSim.OccupationAsAcademicCareer.DegreeInformation != null)
                                {
                                    // quit university for professor, use existing degree
                                    if (pSim.OccupationAsAcademicCareer.DegreeInformation.AcademicDegreeName != name)
                                    {
                                        pSim.Occupation.LeaveJobNow(Career.LeaveJobReason.kQuit);

                                        if (pSim.CreatedSim != null)
                                        {
                                            pSim.CreatedSim.InteractionQueue.CancelAllInteractionsByType(WorkInRabbitHole.Singleton);
                                        }

                                        while (pSim.Occupation != null)
                                        {
                                            Common.Sleep(5);
                                        }
                                    }

                                    AcademicCareer.EnrollSimInAcademicCareer(pSim, name, AcademicCareer.ChooseRandomCoursesPerDay());
                                    degreesWithEnrollment.Remove(name);
                                    pSim.Occupation.PromoteSim();
                                    possibleProfessors.Remove(pSim);
                                    msg += Common.NewLine + "Re-enrolling";
                                    break;
                                }
                            }
                        }
                        else
                        {
                            // not active university Sim, have they completed this degree?
                            if (pSim.CareerManager.DegreeManager != null && pSim.CareerManager.DegreeManager.HasCompletedDegree(name))
                            {
                                // they have...
                                if (pSim.Occupation != null)
                                {
                                    msg += Common.NewLine + "Quit job";
                                    pSim.Occupation.LeaveJobNow(Career.LeaveJobReason.kQuit);

                                    if (pSim.CreatedSim != null)
                                    {
                                        pSim.CreatedSim.InteractionQueue.CancelAllInteractionsByType(WorkInRabbitHole.Singleton);
                                    }

                                    while (pSim.Occupation != null)
                                    {
                                        Common.Sleep(5);
                                    }
                                }

                                bool yes = AcademicCareer.EnrollSimInAcademicCareer(pSim, name, AcademicCareer.ChooseRandomCoursesPerDay());
                                Common.Notify("Success? " + yes);
                                degreesWithEnrollment.Remove(name);
                                pSim.OccupationAsAcademicCareer.PromoteSim();
                                possibleProfessors.Remove(pSim);
                                msg += Common.NewLine + "Enrolling";
                                break;
                            }
                        }
                    }
                }

                // if we got this far they aren't in uni and haven't completed any degrees...
                if (pSim.Elder && (pSim.Occupation == null || pSim.Occupation is StoryProgressionSpace.Careers.Retired))
                {
                    preferredProfessors.Add(pSim);
                }
            }

            if (degreesWithEnrollment.Count == 0)
            {
                Common.DebugWriteLog(msg);
                return(false);
            }

            if (possibleProfessors.Count == 0)
            {
                Common.DebugWriteLog(msg);
                return(false);
            }

            int loop  = 1;
            int count = degreesWithEnrollment.Count;

            msg += Common.NewLine + "Count: " + count;
            while (loop <= count)
            {
                msg += Common.NewLine + "Loop: " + loop;
                if (degreesWithEnrollment.Count == 0 || possibleProfessors.Count == 0)
                {
                    break;
                }

                SimDescription newP;
                if (preferredProfessors.Count > 0)
                {
                    newP = RandomUtil.GetRandomObjectFromList <SimDescription>(preferredProfessors);
                    preferredProfessors.Remove(newP);
                }
                else
                {
                    newP = RandomUtil.GetRandomObjectFromList <SimDescription>(possibleProfessors);
                }

                AcademicDegreeNames enroll = RandomUtil.GetRandomObjectFromList <AcademicDegreeNames>(degreesWithEnrollment);

                msg += Common.NewLine + "Professor: " + newP.FullName;
                msg += Common.NewLine + "Degree: " + enroll;

                if (newP.Occupation != null)
                {
                    msg += Common.NewLine + "Quit Job";
                    newP.Occupation.LeaveJobNow(Career.LeaveJobReason.kQuit);

                    if (newP.CreatedSim != null)
                    {
                        newP.CreatedSim.InteractionQueue.CancelAllInteractionsByType(WorkInRabbitHole.Singleton);
                    }

                    while (newP.Occupation != null)
                    {
                        Common.Sleep(5);
                    }
                }

                bool su = AcademicCareer.EnrollSimInAcademicCareer(newP, enroll, AcademicCareer.ChooseRandomCoursesPerDay());
                degreesWithEnrollment.Remove(enroll);

                newP.OccupationAsAcademicCareer.PromoteSim();
                loop++;
                possibleProfessors.Remove(newP);
                msg += Common.NewLine + "Success ? " + su;
            }

            Common.DebugWriteLog(msg);

            return(false);
        }
Пример #2
0
        protected bool AskForJob(SimDescription sim, Occupation occupation)
        {
            if ((sim.Occupation != null) && (sim.Occupation.Guid == occupation.Guid))
            {
                IncStat("Same Job");
                return(false);
            }

            Career career = occupation as Career;

            if (career != null)
            {
                if (!career.CareerAgeTest(sim))
                {
                    IncStat("Wrong Age");
                    return(false);
                }
            }

            if (!Careers.TestCareer(this, Sim, occupation.Guid))
            {
                IncStat("User Disallow " + occupation.CareerName);
                return(false);
            }

            AcquireOccupationParameters parameters;

            if (occupation is Career)
            {
                CareerLocation location = Career.FindClosestCareerLocation(sim, occupation.Guid);
                if (location == null)
                {
                    IncStat("No Location " + occupation.CareerName);
                    return(false);
                }
                else if (!AllowStandalone(location))
                {
                    IncStat("Standalone " + occupation.CareerName);
                    return(false);
                }
                else
                {
                    parameters = new AcquireOccupationParameters(location, false, false);
                }
            }
            else
            {
                parameters = new AcquireOccupationParameters(occupation.Guid, false, false);
            }

            try
            {
                if (sim.Occupation != null)
                {
                    if (sim.Occupation.Guid == occupation.Guid)
                    {
                        IncStat("Already In Job");
                        return(true);
                    }

                    if (sim.Occupation.CareerLoc != null)
                    {
                        foreach (SimDescription worker in sim.Occupation.CareerLoc.Workers)
                        {
                            if (worker.Occupation == null)
                            {
                                continue;
                            }

                            if (worker.Occupation.Coworkers == null)
                            {
                                worker.Occupation.Coworkers = new List <SimDescription>();
                            }
                        }
                    }

                    sim.Occupation.LeaveJobNow(Career.LeaveJobReason.kQuit);
                }

                Occupation retiredCareer = sim.CareerManager.mRetiredCareer;
                sim.CareerManager.mRetiredCareer = null;

                int originaHighest = 0;
                try
                {
                    if (occupation is ActiveFireFighter)
                    {
                        ActiveCareerStaticData activeCareerStaticData = ActiveCareer.GetActiveCareerStaticData(OccupationNames.Firefighter);

                        originaHighest = activeCareerStaticData.HighestLevel;

                        // Required to bypass auto promotion in SetAttributesForNewJob
                        activeCareerStaticData.HighestLevel = 1;
                    }

                    if (occupation is XpBasedCareer)
                    {
                        // Required by Stylist.GetOccupationJoiningTnsTextPrefix()
                        if (!Sims.Instantiate(sim, sim.LotHome, false))
                        {
                            IncStat("Hibernating");
                            return(false);
                        }
                    }

                    if (AcquireOccupation(sim.CareerManager, parameters))
                    {
                        IncStat(occupation.Guid.ToString());
                        return(true);
                    }
                }
                finally
                {
                    sim.CareerManager.mRetiredCareer = retiredCareer;

                    if (occupation is ActiveFireFighter)
                    {
                        ActiveCareerStaticData activeCareerStaticData = ActiveCareer.GetActiveCareerStaticData(OccupationNames.Firefighter);
                        activeCareerStaticData.HighestLevel = originaHighest;
                    }
                }
            }
            catch (Exception e)
            {
                Common.DebugException(sim, e);
            }

            IncStat("Core Failure");
            return(false);
        }
Пример #3
0
        protected List <Occupation> GetChoices(bool checkQuit)
        {
            List <Occupation> allCareers = new List <Occupation>();

            foreach (Occupation occupation in CareerManager.OccupationList)
            {
                if (occupation is School)
                {
                    continue;
                }

                if (occupation.IsAcademicCareer)
                {
                    continue;
                }

                if (!Careers.TestCareer(this, Sim, occupation.Guid))
                {
                    continue;
                }

                Career career = occupation as Career;
                if (career != null)
                {
                    if (!career.CareerAgeTest(Sim))
                    {
                        continue;
                    }

                    if (career.IsPartTime != Sim.Teen)
                    {
                        continue;
                    }

                    if (ManagerCareer.IsPlaceholderCareer(career))
                    {
                        continue;
                    }

                    if (career.Level1.PayPerHourBase <= 0)
                    {
                        continue;
                    }

                    CareerLocation location = Career.FindClosestCareerLocation(Sim, career.Guid);
                    if (location == null)
                    {
                        continue;
                    }

                    if (!AllowStandalone(location))
                    {
                        continue;
                    }
                }

                if (checkQuit)
                {
                    Occupation oldCareer;
                    if (Sim.CareerManager.QuitCareers.TryGetValue(occupation.Guid, out oldCareer))
                    {
                        if (oldCareer.CareerLevel >= 5)
                        {
                            continue;
                        }
                    }
                }

                allCareers.Add(occupation);
            }

            return(allCareers);
        }
Пример #4
0
        protected override bool PrivateUpdate(ScenarioFrame frame)
        {
            if (Sim.AssignedRole != null)
            {
                if (ManagerCareer.IsRegisterInstalled())
                {
                    if ((Sim.LotHome == null) && (Sim.Occupation == null))
                    {
                        IncStat("Registered Retiremenet");

                        GetData <CareerSimData>(Sim).Retire();
                    }
                }

                return(true);
            }
            else if (SimTypes.IsSpecial(Sim))
            {
                IncStat("Special");
                return(false);
            }

            bool enroll = false;

            if (GameUtils.IsUniversityWorld())
            {
                enroll = true;
            }
            else if (Careers.TestCareer(this, Sim, OccupationNames.AcademicCareer))
            {
                if (Careers.AllowHomeworldUniversity(Sim))
                {
                    AcademicDegreeManager degreeManager = Sim.CareerManager.DegreeManager;
                    if (degreeManager != null)
                    {
                        if (!degreeManager.HasCompletedAnyDegree())
                        {
                            enroll = true;
                        }
                    }
                }
            }

            if (!mForce)
            {
                if (GetValue <ManualCareerOption, bool>(Sim))
                {
                    IncStat("Manual");
                    return(false);
                }
            }

            List <OccupationNames> careers = new List <OccupationNames>();
            bool dream = Careers.GetPotentialCareers(this, Sim, careers, mCheckQuit);

            bool partTime = false;

            if (Sim.Teen)
            {
                bool scoreSuccess = true;
                if (mForce)
                {
                    if (AddScoring("FindJob", Sim) < 0)
                    {
                        scoreSuccess = false;
                    }
                }
                else
                {
                    if (AddScoring("ChanceFindJob", Sim) < 0)
                    {
                        scoreSuccess = false;
                    }
                }

                if ((!scoreSuccess) && (!GetValue <ForceTeensOption, bool>()))
                {
                    IncStat("Score Fail");
                    return(false);
                }
                partTime = true;
            }

            if (partTime)
            {
                List <OccupationNames> partTimeList = new List <OccupationNames>();

                AddStat(Sim.Age + ": Part-time Choices", careers.Count);

                foreach (OccupationNames career in careers)
                {
                    Career staticCareer = CareerManager.GetStaticCareer(career);
                    if (staticCareer == null)
                    {
                        continue;
                    }

                    if (staticCareer is School)
                    {
                        continue;
                    }

                    CareerLocation location = Career.FindClosestCareerLocation(Sim, staticCareer.Guid);
                    if (location == null)
                    {
                        continue;
                    }

                    if (!AllowStandalone(location))
                    {
                        continue;
                    }

                    foreach (CareerLocation loc in location.Owner.CareerLocations.Values)
                    {
                        Career possible = loc.Career;

                        if (!possible.IsPartTime)
                        {
                            continue;
                        }

                        if (ManagerCareer.IsPlaceholderCareer(possible))
                        {
                            continue;
                        }

                        partTimeList.Add(possible.Guid);
                    }
                }

                careers = partTimeList;

                AddStat(Sim.Age + ": Part-time Final", careers.Count);
            }
            else
            {
                AddStat(Sim.Age + ": Full-time Final", careers.Count);
            }

            if ((!mForce) && (!dream) && (Sim.Occupation != null) && (!(Sim.Occupation is Retired)))
            {
                IncStat("Non-Dream Employed");
                return(false);
            }

            if (enroll)
            {
                AcademicDegreeNames degreeName = AcademicDegreeNames.Undefined;

                foreach (DreamJob job in ManagerCareer.GetDreamJob(Sim))
                {
                    if (job == null)
                    {
                        continue;
                    }

                    foreach (AcademicDegreeStaticData data in AcademicDegreeManager.sDictionary.Values)
                    {
                        if (data.AssociatedOccupations.Contains(job.mCareer))
                        {
                            degreeName = data.AcademicDegreeName;
                            break;
                        }
                    }
                }

                if (degreeName == AcademicDegreeNames.Undefined)
                {
                    degreeName = AcademicDegreeManager.ChooseWeightRandomSuitableDegree(Sim);
                }

                if (!Careers.IsDegreeAllowed(Manager, Sim, degreeName))
                {
                    degreeName = Careers.GetAllowedDegree(Manager, Sim);
                }

                if (degreeName != AcademicDegreeNames.Undefined)
                {
                    if (AcademicCareer.GlobalTermLength == AcademicCareer.TermLength.kInvalid)
                    {
                        AcademicCareer.GlobalTermLength = AcademicCareer.TermLength.kOneWeek;
                    }

                    AcademicCareer.EnrollSimInAcademicCareer(Sim, degreeName, AcademicCareer.ChooseRandomCoursesPerDay());
                    return(true);
                }
            }

            bool promptForJob = GetValue <ChooseCareerOption, bool>();

            if ((promptForJob) && (!Careers.MatchesAlertLevel(Sim)))
            {
                promptForJob = false;
            }

            if (careers.Count > 0)
            {
                if ((Sim.Occupation != null) && (careers.Contains(Sim.Occupation.Guid)))
                {
                    IncStat("Already Has Choice");
                    return(false);
                }

                if (!promptForJob)
                {
                    if (AskForJob(Sim, RandomUtil.GetRandomObjectFromList(careers)))
                    {
                        return(true);
                    }
                }
            }

            if ((!mForce) && (Sim.Occupation != null))
            {
                IncStat("Already Employed");
                return(false);
            }

            List <Occupation> allCareers = null;

            if (careers.Count > 0)
            {
                allCareers = new List <Occupation>();

                foreach (Career career in CareerManager.CareerList)
                {
                    if (careers.Contains(career.Guid))
                    {
                        allCareers.Add(career);
                    }
                }
            }

            if ((allCareers == null) || (allCareers.Count == 0))
            {
                if (Sim.LifetimeWish == (uint)LifetimeWant.JackOfAllTrades)
                {
                    allCareers = GetChoices(true);
                }
            }

            if ((allCareers == null) || (allCareers.Count == 0))
            {
                allCareers = GetChoices(false);
            }

            if (allCareers.Count > 0)
            {
                AddStat("Random Choices", allCareers.Count);

                if ((promptForJob) && (AcceptCancelDialog.Show(ManagerSim.GetPersonalInfo(Sim, Common.Localize("ChooseCareer:Prompt", Sim.IsFemale)))))
                {
                    List <JobItem> jobs = new List <JobItem>();

                    foreach (Occupation career in GetChoices(false))
                    {
                        jobs.Add(new JobItem(career, allCareers.Contains(career)));
                    }

                    bool    okayed;
                    JobItem choice = new CommonSelection <JobItem>(Common.Localize("ChooseCareer:Header", Sim.IsFemale), Sim.FullName, jobs, new JobPreferenceColumn()).SelectSingle(out okayed);
                    if (!okayed)
                    {
                        return(false);
                    }

                    if (choice != null)
                    {
                        allCareers.Clear();
                        allCareers.Add(choice.Value);

                        SetValue <ManualCareerOption, bool>(Sim, true);
                    }
                }

                while (allCareers.Count > 0)
                {
                    Occupation choice = RandomUtil.GetRandomObjectFromList(allCareers);
                    allCareers.Remove(choice);

                    if (choice != null)
                    {
                        if (AskForJob(Sim, choice))
                        {
                            return(true);
                        }
                    }
                }

                IncStat("Ask Failure");
                return(false);
            }
            else
            {
                if (promptForJob)
                {
                    Common.Notify(Common.Localize("ChooseCareer:PromptFailure", Sim.IsFemale, new object[] { Sim }));
                }

                IncStat("No Applicable");
                return(false);
            }
        }
Пример #5
0
        protected bool HasProperJob(SimDescription sim)
        {
            if (sim.Occupation == null)
            {
                return(false);
            }

            if (sim.Occupation is AcademicCareer)
            {
                return(true);
            }

            if (!Careers.TestCareer(this, sim, sim.Occupation.Guid))
            {
                return(false);
            }

            if (ManagerCareer.IsPlaceholderCareer(sim.Occupation as Career))
            {
                IncStat("Proper Job: Placeholder");
                return(true);
            }

            if (sim.Teen)
            {
                IncStat("Proper Job: Teen");
                return(true);
            }

            if (!GetValue <AssignDreamJobToEmployedOption, bool>())
            {
                IncStat("Proper Job: Employed Denied");
                return(true);
            }

            bool retired = false;

            if (sim.Elder)
            {
                if (sim.Occupation is Retired)
                {
                    retired = true;
                    if (!GetValue <AllowSelfEmployedRetirementOption, bool>())
                    {
                        IncStat("Proper Job: Retired Denied");
                        return(true);
                    }
                }
                else
                {
                    IncStat("Proper Job: Elder Not Retired");
                    return(true);
                }
            }

            if (sim.HasCompletedLifetimeWish)
            {
                IncStat("Proper Job: Wish Completed");
                return(true);
            }
            else
            {
                List <DreamJob> jobs = ManagerCareer.GetDreamJob(sim, retired);
                if (jobs.Count == 0)
                {
                    if (!retired)
                    {
                        if (sim.YoungAdultOrAbove)
                        {
                            Career career = sim.Occupation as Career;
                            if ((career != null) && (career.IsPartTime))
                            {
                                IncStat("Proper Job: No Dream Part-Time");
                                return(false);
                            }
                        }

                        IncStat("Proper Job: No Dream Job");
                        return(true);
                    }
                    else
                    {
                        IncStat("Proper Job: No Dream Retired");
                        return(false);
                    }
                }

                foreach (DreamJob job in jobs)
                {
                    if (job == null)
                    {
                        continue;
                    }

                    if (job.mCareer == sim.Occupation.Guid)
                    {
                        if (job.Satisfies(Careers, sim, sim.LotHome, false))
                        {
                            IncStat("Proper Job: Already Dream");
                            return(true);
                        }
                        else
                        {
                            IncStat("Proper Job: Dream No Satisfy");
                            return(false);
                        }
                    }
                }

                AddStat("Proper Job: Default", jobs.Count);
                return(false);
            }
        }