Beispiel #1
0
        public static SimDescription GenerateOffspring(List <SimDescription> potentialParents, out bool noParents)
        {
            SimDescription choiceMom;
            SimDescription choiceDad;

            SimUtils.SimCreationSpec.ChooseParents(potentialParents, out choiceDad, out choiceMom);

            noParents = ((choiceMom == null) || (choiceDad == null) || (choiceMom == choiceDad));

            if (noParents)
            {
                return(null);
            }

            CASAgeGenderFlags age = CASAgeGenderFlags.Teen | CASAgeGenderFlags.Child;

            if ((choiceMom.AdultOrAbove) && (choiceDad.AdultOrAbove))
            {
                age |= CASAgeGenderFlags.YoungAdult;
            }

            float weight, fitness;

            WeightAndFitness(choiceMom, choiceDad, out weight, out fitness);

            SimUtils.SimCreationSpec spec3 = new SimUtils.SimCreationSpec();
            spec3.Age = age;

            spec3.Weight  = weight;
            spec3.Fitness = fitness;

            spec3.Normalize();

            SimDescription child = spec3.Instantiate(choiceDad, choiceMom, true);

            if (child != null)
            {
                child.TraitManager.AddHiddenElement(TraitNames.DescendantHiddenTrait);
                if ((choiceMom != null) && (choiceDad != null))
                {
                    SimUtils.HouseholdCreationSpec.InitializeRomance(choiceMom, choiceDad, child, choiceMom.LastName);
                }
                else if (choiceMom != null)
                {
                    child.LastName = choiceMom.LastName;
                }
                else if (choiceDad != null)
                {
                    child.LastName = choiceDad.LastName;
                }
            }

            return(child);
        }
Beispiel #2
0
        public GenerateOffspringEx(SimDescription forcedParent, List <SimDescription> dyingSims, float daysGone)
        {
            CASAgeGenderFlags daysGoneAges = GetDaysGoneAges(daysGone);

            bool university = false;

            if (GameUtils.IsUniversityWorld())
            {
                university = true;
                if ((daysGoneAges & CASAgeGenderFlags.Teen) == CASAgeGenderFlags.None)
                {
                    return;
                }
            }

            SimDescription parent  = null;
            SimDescription partner = null;

            if (forcedParent.IsMale)
            {
                partner = forcedParent;
            }
            else
            {
                parent = forcedParent;
            }

            Household household = forcedParent.Household;

            if (household != null)
            {
                mHouseholdId = household.HouseholdId;
                mSim         = new SimUtils.SimCreationSpec();
                if ((parent == null) && (partner != null))
                {
                    if ((partner.Partner != null) && (partner.Gender != partner.Partner.Gender))
                    {
                        parent = partner.Partner;
                    }
                    else if (partner.Partner == null)
                    {
                        parent = FindPartner(partner, dyingSims);
                    }
                }
                if ((partner == null) && (parent != null))
                {
                    if ((parent.Partner != null) && (parent.Gender != parent.Partner.Gender))
                    {
                        partner = parent.Partner;
                    }
                    else if (parent.Partner == null)
                    {
                        partner = FindPartner(parent, dyingSims);
                    }
                }
                if (((parent != null) && !parent.IsMummy) && ((partner != null) && !partner.IsMummy))
                {
                    numDyingSims = 0;
                    int  numPetsRemoved = 0;
                    bool flag           = false;
                    foreach (SimDescription description3 in household.AllSimDescriptions)
                    {
                        if (dyingSims.Contains(description3))
                        {
                            if (description3.IsHuman)
                            {
                                numDyingSims++;
                            }
                            else
                            {
                                numPetsRemoved++;
                            }
                        }
                        else if (description3.TeenOrAbove)
                        {
                            flag = true;
                        }
                    }

                    if (household.CanSimBeAddedIfXSimAndYPetsRemoved(numDyingSims, numPetsRemoved))
                    {
                        if (university)
                        {
                            mSim.Age  = CASAgeGenderFlags.YoungAdult;
                            mSim.Age |= daysGoneAges;
                            mSim.Age &= ~CASAgeGenderFlags.Child;
                        }
                        else
                        {
                            if (!flag)
                            {
                                mSim.Age = CASAgeGenderFlags.Teen;
                            }
                            else
                            {
                                mSim.Age = CASAgeGenderFlags.Child;
                            }

                            mSim.Age |= daysGoneAges;
                        }

                        mSim.Normalize();

                        if (parent != null)
                        {
                            mMom = parent.SimDescriptionId;
                        }
                        if (partner != null)
                        {
                            mDad = partner.SimDescriptionId;
                        }
                    }
                }
            }
        }
Beispiel #3
0
        protected static SimDescription CreateDescendant(ulong momID, ulong dadID, Household household, CASAgeGenderFlags age, CASAgeGenderFlags gender)
        {
            bool           momUnpacked;
            SimDescription mom = CreateProgenitor(momID, out momUnpacked);

            if (mom == null)
            {
                return(null);
            }

            bool           dadUnpacked;
            SimDescription dad = CreateProgenitor(dadID, out dadUnpacked);

            if (dad == null)
            {
                return(null);
            }

            float weight, fitness;

            WeightAndFitness(mom, dad, out weight, out fitness);

            SimDescription sim = null;

            try
            {
                SimUtils.SimCreationSpec spec = new SimUtils.SimCreationSpec();
                spec.Weight  = weight;
                spec.Fitness = fitness;
                spec.Age     = age;
                spec.Gender  = gender;
                spec.Normalize();
                sim = spec.Instantiate(mom, dad, false, WorldName.FutureWorld);
            }
            catch (Exception e)
            {
                Common.Exception("CreateDescendant", e);
            }

            /*
             * if (dadUnpacked && (dad != null))
             * {
             *  dad.PackUpToMiniSimDescription();
             * }
             *
             * if (momUnpacked && (mom != null))
             * {
             *  mom.PackUpToMiniSimDescription();
             * }
             * */

            if (sim != null)
            {
                sim.TraitManager.AddHiddenElement(TraitNames.DescendantHiddenTrait);
                household.Add(sim);

                return(sim);
            }
            else
            {
                return(null);
            }
        }
Beispiel #4
0
        protected override bool Run(SimDescription me, bool singleSelection)
        {
            if (!ApplyAll)
            {
                mAdoptionParams = AdoptionDialog.Show(Common.Localize(GetTitlePrefix() + ":Prompt", me.IsFemale, new object[] { me }));
                if (mAdoptionParams.mCancelled) return false;
            }

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

            foreach (SimDescription sim in SimListing.GetResidents(true).Values)
            {
                if (!sim.IsHuman) continue;

                residents.Add(sim);
            }

            SimDescription dad = RandomUtil.GetRandomObjectFromList(residents);
            SimDescription mom = RandomUtil.GetRandomObjectFromList(residents);

            SimDescription newKid = null;

            if ((dad != null) && (mom != null))
            {
                if (dad.CelebrityManager == null)
                {
                    dad.Fixup();
                }

                if (mom.CelebrityManager == null)
                {
                    mom.Fixup();
                }

                newKid = Genetics.MakeDescendant(dad, mom, mAdoptionParams.mAge, mAdoptionParams.mIsFemale ? CASAgeGenderFlags.Female : CASAgeGenderFlags.Male, 100, new Random(), false, false, true);
            }
            else
            {
                SimUtils.SimCreationSpec spec = new SimUtils.SimCreationSpec();
                spec.Gender = mAdoptionParams.mIsFemale ? CASAgeGenderFlags.Female : CASAgeGenderFlags.Male;
                spec.Age = mAdoptionParams.mAge;
                spec.Normalize();
                newKid = spec.Instantiate();
            }

            if (newKid == null)
            {
                Common.Notify(Common.Localize(GetTitlePrefix() + ":Failure"));
                return false;
            }

            string genderName = null;
            if (newKid.IsFemale)
            {
                genderName = Common.Localize("BabyGender:Female");
            }
            else
            {
                genderName = Common.Localize("BabyGender:Male");
            }

            string name = StringInputDialog.Show(Name, Common.Localize("InstaBaby:NamePrompt", newKid.IsFemale, new object[0]), newKid.FirstName);
            if (!string.IsNullOrEmpty(name))
            {
                newKid.FirstName = name;
            }

            newKid.LastName = me.LastName;

            me.Household.Add(newKid);

            newKid.WasAdopted = true;

            Sim adoptedChild = Instantiation.Perform(newKid, null);
            if (adoptedChild != null)
            {
                ResetSimTask.UpdateInterface(adoptedChild);

                SocialWorkerAdoptionSituation.InstantiateNewKid instantiateNewKid = new SocialWorkerAdoptionSituation.InstantiateNewKid();

                instantiateNewKid.AssignTraits(adoptedChild);

                instantiateNewKid.GiveImaginaryFriendDoll(newKid);

                me.Genealogy.AddChild(newKid.Genealogy);

                if (me.CreatedSim != null)
                {
                    ActiveTopic.AddToSim(me.CreatedSim, "Recently Had Baby");

                    EventTracker.SendEvent(EventTypeId.kAdoptedChild, me.CreatedSim, adoptedChild);
                    EventTracker.SendEvent(EventTypeId.kNewOffspring, me.CreatedSim, adoptedChild);
                    EventTracker.SendEvent(EventTypeId.kParentAdded, adoptedChild, me.CreatedSim);
                }

                MidlifeCrisisManager.OnHadChild(me);

                Genealogy spouse = me.Genealogy.Spouse;
                if (spouse != null)
                {
                    spouse.AddChild(newKid.Genealogy);

                    SimDescription spouseDesc = spouse.SimDescription;
                    if (spouseDesc != null)
                    {
                        MidlifeCrisisManager.OnHadChild(spouseDesc);

                        if (spouseDesc.CreatedSim != null)
                        {
                            ActiveTopic.AddToSim(spouseDesc.CreatedSim, "Recently Had Baby");

                            EventTracker.SendEvent(EventTypeId.kAdoptedChild, spouseDesc.CreatedSim, adoptedChild);
                            EventTracker.SendEvent(EventTypeId.kNewOffspring, spouseDesc.CreatedSim, adoptedChild);
                            EventTracker.SendEvent(EventTypeId.kParentAdded, adoptedChild, spouseDesc.CreatedSim);
                        }
                    }
                }

                EventTracker.SendEvent(EventTypeId.kChildBornOrAdopted, null, adoptedChild);
            }

            return true;
        }
        public GenerateOffspringEx(SimDescription forcedParent, List<SimDescription> dyingSims, float daysGone)
        {
            CASAgeGenderFlags daysGoneAges = GetDaysGoneAges(daysGone);
            
            bool university = false;
            if (GameUtils.IsUniversityWorld())
            {
                university = true;
                if ((daysGoneAges & CASAgeGenderFlags.Teen) == CASAgeGenderFlags.None)
                {
                    return;
                }
            }

            SimDescription parent = null;
            SimDescription partner = null;
            if (forcedParent.IsMale)
            {
                partner = forcedParent;
            }
            else
            {
                parent = forcedParent;
            }

            Household household = forcedParent.Household;
            if (household != null)
            {
                mHouseholdId = household.HouseholdId;
                mSim = new SimUtils.SimCreationSpec();
                if ((parent == null) && (partner != null))
                {
                    if ((partner.Partner != null) && (partner.Gender != partner.Partner.Gender))
                    {
                        parent = partner.Partner;
                    }
                    else if (partner.Partner == null)
                    {
                        parent = FindPartner(partner, dyingSims);
                    }
                }
                if ((partner == null) && (parent != null))
                {
                    if ((parent.Partner != null) && (parent.Gender != parent.Partner.Gender))
                    {
                        partner = parent.Partner;
                    }
                    else if (parent.Partner == null)
                    {
                        partner = FindPartner(parent, dyingSims);
                    }
                }
                if (((parent != null) && !parent.IsMummy) && ((partner != null) && !partner.IsMummy))
                {
                    numDyingSims = 0;
                    int numPetsRemoved = 0;
                    bool flag = false;
                    foreach (SimDescription description3 in household.AllSimDescriptions)
                    {
                        if (dyingSims.Contains(description3))
                        {
                            if (description3.IsHuman)
                            {
                                numDyingSims++;
                            }
                            else
                            {
                                numPetsRemoved++;
                            }
                        }
                        else if (description3.TeenOrAbove)
                        {
                            flag = true;
                        }
                    }

                    if (household.CanSimBeAddedIfXSimAndYPetsRemoved(numDyingSims, numPetsRemoved))
                    {
                        if (university)
                        {
                            mSim.Age = CASAgeGenderFlags.YoungAdult;
                            mSim.Age |= daysGoneAges;
                            mSim.Age &= ~CASAgeGenderFlags.Child;
                        }
                        else
                        {
                            if (!flag)
                            {
                                mSim.Age = CASAgeGenderFlags.Teen;
                            }
                            else
                            {
                                mSim.Age = CASAgeGenderFlags.Child;
                            }

                            mSim.Age |= daysGoneAges;
                        }

                        mSim.Normalize();

                        if (parent != null)
                        {
                            mMom = parent.SimDescriptionId;
                        }
                        if (partner != null)
                        {
                            mDad = partner.SimDescriptionId;
                        }
                    }
                }
            }
        }
Beispiel #6
0
        protected override bool Run(SimDescription me, bool singleSelection)
        {
            if (!ApplyAll)
            {
                mAdoptionParams = AdoptionDialog.Show(Common.Localize(GetTitlePrefix() + ":Prompt", me.IsFemale, new object[] { me }));
                if (mAdoptionParams.mCancelled)
                {
                    return(false);
                }
            }

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

            foreach (SimDescription sim in SimListing.GetResidents(true).Values)
            {
                if (!sim.IsHuman)
                {
                    continue;
                }

                residents.Add(sim);
            }

            SimDescription dad = RandomUtil.GetRandomObjectFromList(residents);
            SimDescription mom = RandomUtil.GetRandomObjectFromList(residents);

            SimDescription newKid = null;

            if ((dad != null) && (mom != null))
            {
                if (dad.CelebrityManager == null)
                {
                    dad.Fixup();
                }

                if (mom.CelebrityManager == null)
                {
                    mom.Fixup();
                }

                newKid = Genetics.MakeDescendant(dad, mom, mAdoptionParams.mAge, mAdoptionParams.mIsFemale ? CASAgeGenderFlags.Female : CASAgeGenderFlags.Male, 100, new Random(), false, false, true);
            }
            else
            {
                SimUtils.SimCreationSpec spec = new SimUtils.SimCreationSpec();
                spec.Gender = mAdoptionParams.mIsFemale ? CASAgeGenderFlags.Female : CASAgeGenderFlags.Male;
                spec.Age    = mAdoptionParams.mAge;
                spec.Normalize();
                newKid = spec.Instantiate();
            }

            if (newKid == null)
            {
                Common.Notify(Common.Localize(GetTitlePrefix() + ":Failure"));
                return(false);
            }

            string genderName = null;

            if (newKid.IsFemale)
            {
                genderName = Common.Localize("BabyGender:Female");
            }
            else
            {
                genderName = Common.Localize("BabyGender:Male");
            }

            string name = StringInputDialog.Show(Name, Common.Localize("InstaBaby:NamePrompt", newKid.IsFemale, new object[0]), newKid.FirstName);

            if (!string.IsNullOrEmpty(name))
            {
                newKid.FirstName = name;
            }

            newKid.LastName = me.LastName;

            me.Household.Add(newKid);

            newKid.WasAdopted = true;

            Sim adoptedChild = Instantiation.Perform(newKid, null);

            if (adoptedChild != null)
            {
                ResetSimTask.UpdateInterface(adoptedChild);

                SocialWorkerAdoptionSituation.InstantiateNewKid instantiateNewKid = new SocialWorkerAdoptionSituation.InstantiateNewKid();

                instantiateNewKid.AssignTraits(adoptedChild);

                instantiateNewKid.GiveImaginaryFriendDoll(newKid);

                me.Genealogy.AddChild(newKid.Genealogy);

                if (me.CreatedSim != null)
                {
                    ActiveTopic.AddToSim(me.CreatedSim, "Recently Had Baby");

                    EventTracker.SendEvent(EventTypeId.kAdoptedChild, me.CreatedSim, adoptedChild);
                    EventTracker.SendEvent(EventTypeId.kNewOffspring, me.CreatedSim, adoptedChild);
                    EventTracker.SendEvent(EventTypeId.kParentAdded, adoptedChild, me.CreatedSim);
                }

                MidlifeCrisisManager.OnHadChild(me);

                Genealogy spouse = me.Genealogy.Spouse;
                if (spouse != null)
                {
                    spouse.AddChild(newKid.Genealogy);

                    SimDescription spouseDesc = spouse.SimDescription;
                    if (spouseDesc != null)
                    {
                        MidlifeCrisisManager.OnHadChild(spouseDesc);

                        if (spouseDesc.CreatedSim != null)
                        {
                            ActiveTopic.AddToSim(spouseDesc.CreatedSim, "Recently Had Baby");

                            EventTracker.SendEvent(EventTypeId.kAdoptedChild, spouseDesc.CreatedSim, adoptedChild);
                            EventTracker.SendEvent(EventTypeId.kNewOffspring, spouseDesc.CreatedSim, adoptedChild);
                            EventTracker.SendEvent(EventTypeId.kParentAdded, adoptedChild, spouseDesc.CreatedSim);
                        }
                    }
                }

                EventTracker.SendEvent(EventTypeId.kChildBornOrAdopted, null, adoptedChild);
            }

            return(true);
        }
        public static SimDescription GenerateOffspring(List<SimDescription> potentialParents, out bool noParents)
        {
            SimDescription choiceMom;
            SimDescription choiceDad;
            SimUtils.SimCreationSpec.ChooseParents(potentialParents, out choiceDad, out choiceMom);

            noParents = ((choiceMom == null) || (choiceDad == null) || (choiceMom == choiceDad));

            if (noParents)
            {
                return null;
            }

            CASAgeGenderFlags age = CASAgeGenderFlags.Teen | CASAgeGenderFlags.Child;
            if ((choiceMom.AdultOrAbove) && (choiceDad.AdultOrAbove))
            {
                age |= CASAgeGenderFlags.YoungAdult;
            }

            float weight, fitness;
            WeightAndFitness(choiceMom, choiceDad, out weight, out fitness);

            SimUtils.SimCreationSpec spec3 = new SimUtils.SimCreationSpec();
            spec3.Age = age;

            spec3.Weight = weight;
            spec3.Fitness = fitness;

            spec3.Normalize();

            SimDescription child = spec3.Instantiate(choiceDad, choiceMom, true);
            if (child != null)
            {
                child.TraitManager.AddHiddenElement(TraitNames.DescendantHiddenTrait);
                if ((choiceMom != null) && (choiceDad != null))
                {
                    SimUtils.HouseholdCreationSpec.InitializeRomance(choiceMom, choiceDad, child, choiceMom.LastName);
                }
                else if (choiceMom != null)
                {
                    child.LastName = choiceMom.LastName;
                }
                else if (choiceDad != null)
                {
                    child.LastName = choiceDad.LastName;
                }                
            }            

            return child;
        }
        protected static SimDescription CreateDescendant(ulong momID, ulong dadID, Household household, CASAgeGenderFlags age, CASAgeGenderFlags gender)
        {           
            bool momUnpacked;
            SimDescription mom = CreateProgenitor(momID, out momUnpacked);
            if (mom == null) return null;            

            bool dadUnpacked;
            SimDescription dad = CreateProgenitor(dadID, out dadUnpacked);
            if (dad == null) return null;            

            float weight, fitness;
            WeightAndFitness(mom, dad, out weight, out fitness);

            SimDescription sim = null;

            try
            {                
                SimUtils.SimCreationSpec spec = new SimUtils.SimCreationSpec();
                spec.Weight = weight;
                spec.Fitness = fitness;
                spec.Age = age;
                spec.Gender = gender;
                spec.Normalize();
                sim = spec.Instantiate(mom, dad, false, WorldName.FutureWorld);                
            }
            catch (Exception e)
            {
                Common.Exception("CreateDescendant", e);
            }  
          
            /*
            if (dadUnpacked && (dad != null))
            {                
                dad.PackUpToMiniSimDescription();
            }

            if (momUnpacked && (mom != null))
            {                
                mom.PackUpToMiniSimDescription();
            }
             * */

            if (sim != null)
            {
                sim.TraitManager.AddHiddenElement(TraitNames.DescendantHiddenTrait);
                household.Add(sim);

                return sim;
            }
            else
            {
                return null;
            }
        }