Exemple #1
0
 public static Genetics FromString(this Genetics @this, string value)
 {
     switch (value)
     {
         ca
     }
 }
Exemple #2
0
        private void startButton_Click(object sender, EventArgs e)
        {
            try { LoadConfiguration(); }
            catch
            {
                MessageBox.Show("Algunos parametros de configuración no son válidos.");
                return;
            }
            if (!File.Exists(Database.DefaultFilePath))
            {
                MessageBox.Show("El archivo de base de datos no ha sido encontrado.");
                return;
            }
            this.startButton.Enabled    = false;
            this.configGroupBox.Enabled = false;
            //database = Database.GenerateRandom(courses, courseMaxCount);
            database = Database.LoadFromFile(DatabaseFilePath);
            genetics = new Genetics(database, maxGenerations);
            genetics.OnNewGeneration += UpdateUI;
            genetics.SleepSeconds     = delay;

            var population = database.GetRandomPopulation(populationSize);
            var task       = genetics.RunAsync(population.ToArray(), Schedule.Suitability);

            DrawWhenComplete(task);
        }
Exemple #3
0
        public static SimDescription MakeAlienBaby(SimDescription alien, SimDescription abductee, CASAgeGenderFlags gender, float averageMood, Random pregoRandom, bool interactive)
        {
            SimDescription baby = MakeAlien(CASAgeGenderFlags.Baby, gender, GameUtils.GetCurrentWorld(), 1f, interactive);

            if (baby != null)
            {
                if (interactive)
                {
                    baby.FirstName = string.Empty;
                }

                baby.LastName = alien.LastName;
                Genetics.AssignTraits(baby, alien, abductee, interactive, averageMood, pregoRandom);
                baby.TraitManager.AddHiddenElement(BuffsAndTraits.sAlienChild);

                if (Abductor.Settings.mFutureSim)
                {
                    baby.TraitManager.AddHiddenElement(TraitNames.FutureSim);
                }

                baby.CelebrityManager.SetBabyLevel(Genetics.AssignBabyCelebrityLevel(null, abductee));
                abductee.Genealogy.AddChild(baby.Genealogy);

                if (alien != null)
                {
                    alien.Genealogy.AddChild(baby.Genealogy);
                }

                /* WISHLIST-------------------------------------------------------------------------------------- */
                // Link to NRaasHybrid to allow alien children to inherit one or more occult types from abductee.
                /* ---------------------------------------------------------------------------------------------- */
            }

            return(baby);
        }
Exemple #4
0
        private void BeBorn(Genetics newGenes)
        {
            babySizeProportion = newGenes.gestationPeriod / 100f;
            navMeshAgent.speed = newGenes.maxSpeed * babySizeProportion;
            geneset            = newGenes;

            metabolicRate   = newGenes.metabolicRate + growthRate;
            comfortPoint    = newGenes.comfortPoint;
            discomfortPoint = newGenes.discomfortPoint + (babySizeProportion * 100f);
            maxSpeed        = newGenes.maxSpeed;
            isFemale        = newGenes.isFemale;
            gestationPeriod = newGenes.gestationPeriod;
            growthRate      = newGenes.growthRate;

            isAdult = false;
            transform.localScale = new Vector3(babySizeProportion, babySizeProportion, babySizeProportion);
            if (isFemale)
            {
                gameObject.name = gameObject.tag + " Female";
            }
            else
            {
                gameObject.name = gameObject.tag + " Male";
            }
        }
Exemple #5
0
        public static Sim DGSMakeRandomSimNoCheck(Vector3 point, CASAgeGenderFlags age, CASAgeGenderFlags gender, WorldName worldname)
        {
            LotLocation    lotLocation     = default(LotLocation);
            ulong          lotLocation2    = World.GetLotLocation(point, ref lotLocation);
            Lot            lot             = LotManager.GetLot(lotLocation2);
            SimDescription simDescription2 = DGSMakeSSimDescription(age, gender, worldname, uint.MaxValue);

            Genetics.AssignRandomTraits(simDescription2);
            if (lot != null)
            {
                if (lot.Household == null)
                {
                    Household household = Household.Create();
                    lot.MoveIn(household);
                }
                lot.Household.Add(simDescription2);
            }
            else
            {
                Household household2 = Household.Create();
                household2.SetName(/* "E3Lesa is Good" */ "Good Household");
                household2.Add(simDescription2);
            }
            WorldName currentWorld = worldname;

            simDescription2.FirstName = SimUtils.GetRandomGivenName(simDescription2.IsMale, currentWorld);
            simDescription2.LastName  = SimUtils.GetRandomFamilyName(currentWorld);

            return(simDescription2.Instantiate(point));
        }
Exemple #6
0
 void PassGenes(Creature mother, Creature father)
 {
     this.viewDistance = Genetics.CombineGenes(
         mother.viewDistance, father.viewDistance);
     this.baseSpeed = Genetics.CombineGenes(
         mother.baseSpeed, father.baseSpeed);
 }
Exemple #7
0
        // notas sobre geneticos:
        // - cada individuo es una posible solucion que tiene un fitnes(valor que define su nivel de bondad, mas alto es mejor)
        // - para este caso, cada invidivio es un horario con cursos y el valor de bondad que tiene cada uno es "cuantos cursos no chocan"
        // - ademas, cada gen es un curso
        private static void Test()
        {
            Console.WriteLine("[Start]");

            var database = Database.GenerateRandom(
                new string[] {
                "Mate 1", "Progra 1", "Lengua 1", "Introduccion 1",
                "Mecanica 2", "Computacion", "Religion", "Historia",
                "Quimica", "Física", "IA", "Lectura", "Biología"
            },
                50);
            //database.Save();

            var population = new List <Schedule>(4); // poblacion inicial de 4 :v

            for (int i = 0; i < population.Capacity; i++)
            {
                population.Add(database.GetRandomSchedule());
            }

            //File.WriteAllText(Environment.CurrentDirectory + "\\test.json", JsonConvert.SerializeObject(population));

            var genetics = new Genetics(database, 500);

            genetics.OnNewGeneration += UpdateUI;
            var result = genetics.RunAsync(population.ToArray(), Schedule.Suitability);

            result.ToString();

            Console.WriteLine("[Finished]");
            Console.ReadLine();
        }
    public void ToggleStatsOn()
    {
        stats.enabled = true;

        Genetics genetics = gameObject.GetComponent <Genetics>();

        stats.text = "speed: " + genetics.speed + "\n color: " + genetics.hue;  // HERE we should put ATTACK!!!
    }
Exemple #9
0
        public override void GetNewBorns()
        {
            mNewborns = new List <Sim>();
            Sims3.Gameplay.Gameflow.Singleton.DisableSave(this, "Gameplay/ActorSystems/Pregnancy:DisableSave");
            bool keepBaby = false;

            //if (Actor.Household.NumActorMembersCountingPregnancy < 0x8)
            {
                // Custom
                if (SimTypes.IsSelectable(Actor))
                {
                    keepBaby = TwoButtonDialog.Show(AlienUtils.LocalizeString("MalePregnancyConfirmationDialog", new object[] { Actor }), AlienUtils.LocalizeString("MalePregnancyConfirmationDialogAccept", new object[0x0]), AlienUtils.LocalizeString("MalePregnancyConfirmationDialogReject", new object[0x0]));
                }
                else
                {
                    keepBaby = true;
                }
            }

            /*else
             * {
             *  Actor.ShowTNSIfSelectable(AlienUtils.LocalizeString("MalePregnancyHouseholdFullTNS", new object[] { Actor }), StyledNotification.NotificationStyle.kGameMessagePositive, ObjectGuid.InvalidObjectGuid, Actor.ObjectId);
             * }*/

            CASAgeGenderFlags gender       = RandomUtil.CoinFlip() ? CASAgeGenderFlags.Male : CASAgeGenderFlags.Female;
            SimDescription    description2 = SimDescription.Find(this.AlienParentID);
            SimDescription    newSim       = Genetics.MakeAlien(CASAgeGenderFlags.Baby, gender, GameUtils.GetCurrentWorld(), 1f, false);

            newSim.LastName = Actor.LastName;
            if ((keepBaby) && (SimTypes.IsSelectable(Actor)))
            {
                newSim.FirstName = string.Empty;
            }

            Genetics.AssignTraits(newSim, null, Actor.SimDescription, (keepBaby) && (SimTypes.IsSelectable(Actor)), (float)Actor.MoodManager.MoodValue, new Random());
            Actor.Genealogy.AddChild(newSim.Genealogy);
            if (description2 != null)
            {
                description2.Genealogy.AddChild(newSim.Genealogy);
            }

            if (keepBaby)
            {
                Actor.Household.Add(newSim);
            }
            else
            {
                Household.AlienHousehold.Add(newSim);
            }

            Sim babyToHide = newSim.Instantiate(Vector3.Empty);

            babyToHide.GreetSimOnLot(Actor.LotCurrent);
            babyToHide.SetPosition(Actor.Position);
            Pregnancy.TotallyHideBaby(babyToHide);
            mNewborns.Add(babyToHide);
        }
Exemple #10
0
 public void ConsiderPurchase(Asset asset)
 {
     if (Money > asset.Price)
     {
         var value = Genetics.GetGeneExpression(GeneType.PropertyValue, asset);
         if ((value * Money) > asset.Price)
         {
             PurchaseAsset(asset);
         }
     }
 }
Exemple #11
0
            public Genetics Recombinate(Genetics otherGenes)
            {
                float newMetabolicRate   = (this.metabolicRate + otherGenes.metabolicRate) / 2;
                float newComfortPoint    = (this.comfortPoint + otherGenes.comfortPoint) / 2;
                float newDiscomfortPoint = (this.discomfortPoint + otherGenes.discomfortPoint) / 2;
                float newMaxSpeed        = (this.maxSpeed + otherGenes.maxSpeed) / 2;
                bool  newIsFemale        = (Random.value > 0.5f);
                float newGestationPeriod = (this.gestationPeriod + otherGenes.gestationPeriod) / 2;
                float newGrowthRate      = (this.growthRate + otherGenes.growthRate) / 2;

                return(new Genetics(newMetabolicRate, newComfortPoint, newDiscomfortPoint, newMaxSpeed, newIsFemale, newGestationPeriod, newGrowthRate));
            }
 static void PrintGeneticsHeader(Genetics GeneticsTrainer)
 {
     Console.ForegroundColor = ConsoleColor.White;
     Console.WriteLine($"Genetics Results: ");
     Console.ForegroundColor = ConsoleColor.Green;
     Console.Write($"Generation Count: ");
     Console.ForegroundColor = ConsoleColor.Yellow;
     Console.WriteLine(GeneticsTrainer.GenerationCount);
     Console.ForegroundColor = ConsoleColor.Green;
     Console.Write("Fitness: ");
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine($"{GeneticsTrainer.BestNetworkFitness:0.000000000}");
 }
    protected void DecodeGenotype()
    {
        float minAngle  = 120.0f;
        float maxAngle  = 360.0f;
        float minRadius = 3.0f;
        float maxRadius = 8.0f;
        var   geneDict  = Genetics.Decode(genotype);

        fov.viewAngle  = geneDict["fovAngle"] / 64.0f * (maxAngle - minAngle) + minAngle;
        fov.viewRadius = geneDict["fovRadius"] / 64.0f * (maxRadius - minRadius) + minRadius;
        agent.speed    = geneDict["speed"] / 32.0f * (maxSpeed - minSpeed) + minSpeed;
        male           = geneDict["sex"] != 0;
    }
Exemple #14
0
        public static Sim DGSMakeRandomSim(Vector3 point, CASAgeGenderFlags age, CASAgeGenderFlags gender, WorldName worldname)
        {
            LotLocation lotLocation  = default(LotLocation);
            ulong       lotLocation2 = World.GetLotLocation(point, ref lotLocation);
            Lot         lot          = LotManager.GetLot(lotLocation2);

            if ((age & (CASAgeGenderFlags.Baby | CASAgeGenderFlags.Toddler | CASAgeGenderFlags.Child)) != CASAgeGenderFlags.None)
            {
                bool flag = false;
                if (lot != null && lot.Household != null)
                {
                    foreach (SimDescription simDescription in lot.Household.SimDescriptions)
                    {
                        if (simDescription.TeenOrAbove)
                        {
                            flag = true;
                            break;
                        }
                    }
                }
                if (!flag)
                {
                    return(null);
                }
            }
            SimDescription simDescription2 = DGSMakeSSimDescription(age, gender, worldname, uint.MaxValue);

            Genetics.AssignRandomTraits(simDescription2);
            if (lot != null)
            {
                if (lot.Household == null)
                {
                    Household household = Household.Create();
                    household.Name = simDescription2.mLastName ?? "";
                    lot.MoveIn(household);
                }
                lot.Household.Add(simDescription2);
            }
            else
            {
                Household household2 = Household.Create();
                household2.SetName(/* "E3Lesa is Good" */ "Good Household");
                household2.Add(simDescription2);
            }
            WorldName currentWorld = worldname;

            simDescription2.FirstName = SimUtils.GetRandomGivenName(simDescription2.IsMale, currentWorld);
            simDescription2.LastName  = SimUtils.GetRandomFamilyName(currentWorld);

            return(simDescription2.Instantiate(point));
        }
Exemple #15
0
        public override bool InRabbitHole()
        {
            try
            {
                SimDescription oldSim = Actor.SimDescription;
                SimDescription newSim = Genetics.MakeDescendant(oldSim, oldSim, CASAgeGenderFlags.Child, oldSim.Gender, 100f, new Random(), false, true, true);
                newSim.WasCasCreated = false;

                /*
                 * if (!Household.ActiveHousehold.CanAddSpeciesToHousehold(Actor.SimDescription.Species))
                 * {
                 *  newSim.Dispose();
                 *  return false;
                 * }
                 */

                oldSim.Household.Add(newSim);
                newSim.FirstName = StringInputDialog.Show(Localization.LocalizeString("Gameplay/Objects/RabbitHoles/ScienceLab:NameCloneTitle", new object[0x0]), Localization.LocalizeString("Gameplay/Objects/RabbitHoles/ScienceLab:NameCloneDesc", new object[0x0]), string.Empty, 256, StringInputDialog.Validation.SimNameText);
                Target.SetupNewClone(oldSim, newSim, "ep4CloneTransitionChild");

                // Custom
                foreach (OccultTypes type in OccultTypeHelper.CreateList(oldSim))
                {
                    OccultTypeHelper.Add(newSim, type, false, false);
                }

                IGameObject voucher = Actor.Inventory.Find <IVoucherCloneMe>();
                if (voucher != null)
                {
                    Actor.Inventory.RemoveByForce(voucher);
                    voucher.Destroy();
                    voucher = null;
                }

                EventTracker.SendEvent(EventTypeId.kNewOffspring, Actor, newSim.CreatedSim);
                EventTracker.SendEvent(EventTypeId.kParentAdded, newSim.CreatedSim, Actor);
                EventTracker.SendEvent(EventTypeId.kChildBornOrAdopted, null, newSim.CreatedSim);
                return(true);
            }
            catch (ResetException)
            {
                throw;
            }
            catch (Exception e)
            {
                Common.Exception(Actor, Target, e);
                return(false);
            }
        }
Exemple #16
0
        private void Start()
        {
            navMeshAgent.speed = maxSpeed;
            if (comfortPoint < discomfortPoint)
            {
                Debug.LogError("Comfort Point should be set above Discomfort Point");
                comfortPoint = discomfortPoint;
            }

            if (geneset == null)
            {
                geneset            = new Genetics(metabolicRate, comfortPoint, discomfortPoint, maxSpeed, isFemale, gestationPeriod, growthRate);
                babySizeProportion = gestationPeriod / 100f;
            }
        }
        protected override void LoadContent()
        {
            font = Content.Load <SpriteFont>("fonts//Xolonium");
            font.DefaultCharacter = ' ';
            spriteBatch           = new SpriteBatch(GraphicsDevice);
            Generate();

            t.OnFinish += () =>
            {
                Genetics.Evolve(generation, () => Rand * Rand * Rand * Rand);
                //t.Reset(false);
                t.Start();
            };

            t.Start();
        }
Exemple #18
0
        public static SimDescription DGSMakeSSimDescription(CASAgeGenderFlags age, CASAgeGenderFlags gender, WorldName homeWorld, uint outfitCategoriesToBuild)
        {
            Color[] hairColors;
            if (age == CASAgeGenderFlags.Elder)
            {
                hairColors = Genetics.GetRandomElderHairColor();
            }
            else
            {
                hairColors = Genetics.GetGeneticHairColor(homeWorld);
            }
            float       skinToneIndex = 0f;
            ResourceKey skinTone      = Genetics.RandomSkin(false, homeWorld, ref skinToneIndex);

            return(DGSMakeSSimDescription(null, age, gender, skinTone, skinToneIndex, hairColors, homeWorld, outfitCategoriesToBuild, false));
        }
    protected void Init()
    {
        Time.timeScale = 1f;
        Application.targetFrameRate = 30;
        Application.runInBackground = true;
        genetics = GetComponent <Genetics>();
        agents   = new List <GameObject>();
        for (int i = 0; i < amount; i++)
        {
            GameObject spawnedCar = Instantiate(agent, spawnPoint.transform.position + GetRandVec(),
                                                spawnPoint.rotation, spawnPoint)
                                    as GameObject;
            agents.Add(spawnedCar);
        }
        log = new List <string>();

        //LoadPopulation("startPopulation.txt", false);
    }
Exemple #20
0
        public void ProduceBaby(Genetics donorGenes)
        {
            if (!isAlive)
            {
                return;
            }

            Genetics newGenes = geneset.Recombinate(donorGenes);

            StartCoroutine(GiveBirth(newGenes));

            metabolicRate      = metabolicRate + (metabolicRate * babySizeProportion);
            navMeshAgent.speed = maxSpeed * babySizeProportion;
            gestation          = gestationPeriod;
            isGestating        = true;
            isReceptive        = false;
            currentMate        = null;
            energy             = Mathf.Clamp(energy - maxSpeed, minStorage, maxStorage);
        }
Exemple #21
0
    // Use this for initialization
    void Start()
    {
        _genetics = new Genetics();
        var agents = FindObjectsOfType <Agent>();

        foreach (var agent in agents)
        {
            _genetics.AddAgent(agent);
        }
        _bestAllTimeScore = 0;
        _bestCurrentScore = 0;


        _startTime = Time.time;

        /*
         *  _prevArena = Random.Range(0, Arenas.Length);
         * Arenas[_prevArena].transform.position = new Vector3(0, 0, 0);
         */
    }
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            int n = 1;

            Circle[] circles =
            {
                new Circle {
                    X = 3.3, Y = 11.2, R = 9.7
                },
                new Circle {
                    X = 23.9, Y = 8.5, R = 14.17
                },
                new Circle {
                    X = 7.3, Y = 18.95, R = 2.58
                },
            };

            double error  = 0.22;
            int    rounds = 50;
            int    size   = 10000;

            var results = Genetics.calculate(circles, error, n, rounds, size);

            for (int i = 0; i < results.Length; ++i)
            {
                Console.WriteLine(results[i].Item1);
                Console.WriteLine(results[i].Item2);
                Console.WriteLine(results[i].Item3);
                Console.WriteLine(results[i].Item4);
            }

            sw.Stop();

            Console.WriteLine("Elapsed={0}", sw.Elapsed);

            Console.ReadLine();
        }
    void OnGUI()
    {
        {
            float x = 50;
            float y = 20;

            float width  = 200;
            float height = 15;

            if (GUI.Button(new Rect(x, y, width, 20), "Random genes test"))
            {
                Test();
            }
        }

        var genes = geneSystem.Genes;

        Genetics.DrawActiveGenomes(genes);
        Genetics.DrawGenesToApply(genes, genomesString);
        Genetics.DrawSenations(sensationsString);
        Genetics.DrawGeneInfo(genes);
    }
Exemple #24
0
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            int n = 2;

            Circle[] circles =
            {
                new Circle {
                    X = -0.85, Y = 2.45, R = 2.25
                },
                new Circle {
                    X = 2.6, Y = 4.45, R = 2.85
                },
                new Circle {
                    X = 6.15, Y = 0, R = 5.2
                },
                new Circle {
                    X = -0.85, Y = -0.5, R = 3.2
                },
            };

            double e      = 0.005;
            int    rounds = 100;
            int    size   = 500;


            var results = Genetics.calculate(circles, n, rounds, size, e, false);


            sw.Stop();

            Console.WriteLine("Elapsed={0}", sw.Elapsed);

            Console.ReadLine();
        }
Exemple #25
0
        private IEnumerator GiveBirth(Genetics newGenes)
        {
            yield return(new WaitForSeconds(gestationPeriod));

            if (!isAlive)
            {
                yield break;
            }

            if (animalPrefab != null)
            {
                Animal baby = Instantiate(animalPrefab, transform.position, Quaternion.identity);
                baby.transform.parent = transform.parent;
                baby.BeBorn(newGenes);
            }
            else
            {
                Debug.LogError("No animal prefab assigned to " + gameObject.name);
            }
            metabolicRate      = geneset.metabolicRate;
            navMeshAgent.speed = geneset.maxSpeed;
            energy             = Mathf.Clamp(energy - (babySizeProportion * 100f), minStorage, maxStorage);
        }
    private void spawnChildAnimal()
    {
        if (male)
        {
            return;
        }

        var father        = gotoTarget.GetComponent <RabbitController>();
        var childGenotype = Genetics.MultipleCrossover(father.genotype, genotype);

        childGenotype = Genetics.Mutation(childGenotype);

        var child = Instantiate(childPrefab, transform.position + new Vector3(1, 0, 1), Quaternion.identity);

        child.tag = "Bunny";
        child.transform.localScale = Vector3.zero;
        child.transform.DOScale(childPrefab.transform.localScale, 1);

        var childController = child.GetComponent <RabbitController>();

        childController.SetNewGenotype(childGenotype);
        childController.DecodeGenotype();
    }
Exemple #27
0
        public static SimDescription MakeAlien(CASAgeGenderFlags age, CASAgeGenderFlags gender, WorldName homeworld, float alienDNAPercentage, bool assignRandomTraits)
        {
            ResourceKey skinTone      = kAlienSkinTones[RandomUtil.GetInt(0, kAlienSkinTones.Length - 1)];
            float       skinToneIndex = GetSkinToneIndex(skinTone);
            SimBuilder  sb            = new SimBuilder();

            sb.Age            = age;
            sb.Gender         = gender;
            sb.Species        = CASAgeGenderFlags.Human;
            sb.SkinTone       = skinTone;
            sb.SkinToneIndex  = skinToneIndex;
            sb.TextureSize    = 1024u;
            sb.UseCompression = true;
            bool flag = (gender == CASAgeGenderFlags.Female);

            SetFacialBlends(sb);
            SimDescription alienDescription = Genetics.MakeSim(sb, age, gender, skinTone, skinToneIndex, kAlienHairColors, homeworld, 4294967295u, true);

            if (alienDescription != null)
            {
                alienDescription.FirstName = SimUtils.GetRandomAlienGivenName(alienDescription.IsMale);
                alienDescription.LastName  = SimUtils.GetRandomAlienFamilyName();
                alienDescription.SetAlienDNAPercentage(alienDNAPercentage);
                alienDescription.VoicePitchModifier = RandomUtil.GetFloat(1.2f, 1.6f);
                alienDescription.VoiceVariation     = (VoiceVariationType)RandomUtil.GetInt(2);

                if (assignRandomTraits)
                {
                    Genetics.AssignRandomTraits(alienDescription);
                }

                if (alienDescription.TeenOrAbove)
                {
                    string s = "a";

                    if (age != CASAgeGenderFlags.Teen)
                    {
                        if (age == CASAgeGenderFlags.Elder)
                        {
                            s = "e";
                        }
                    }
                    else
                    {
                        s = "t";
                    }

                    string      s2     = alienDescription.IsFemale ? "f" : "m";
                    string      name   = s + s2 + "_alienOutfit";
                    ResourceKey key33  = ResourceKey.CreateOutfitKeyFromProductVersion(name, ProductVersion.EP8);
                    SimOutfit   outfit = OutfitUtils.CreateOutfitForSim(alienDescription, key33, OutfitCategories.Everyday, OutfitCategories.Everyday, false);

                    if (outfit != null)
                    {
                        alienDescription.AddOutfit(outfit, OutfitCategories.Everyday, true);
                    }

                    outfit = OutfitUtils.CreateOutfitForSim(alienDescription, key33, OutfitCategories.Formalwear, OutfitCategories.Formalwear, false);

                    if (outfit != null)
                    {
                        alienDescription.AddOutfit(outfit, OutfitCategories.Formalwear, true);
                    }

                    outfit = OutfitUtils.CreateOutfitForSim(alienDescription, key33, OutfitCategories.Outerwear, OutfitCategories.Outerwear, false);

                    if (outfit != null)
                    {
                        alienDescription.AddOutfit(outfit, OutfitCategories.Outerwear, true);
                    }
                }
            }

            return(alienDescription);
        }
Exemple #28
0
        public void TestInitialize()
        {
            TypeFactory.stockTypes.cleanAllStacks();
            Eval.maxSteps = 1000; // don't linger

            this.config = Push.Genetic.readConfig("sampleConfig.xml");
            Code.Me.MaxCodePoints = config.maxCodePoints;
            this.population = ListModule.Initialize<Ast.Push>(config.populSize,
                FSharpFunc<int, Ast.Push>.FromConverter(i => Code.rand(config.maxCodePoints, FSharpOption<string>.Some("INTEGER"))));
            this.genetics = new Genetics(this.config, this.population);
        }
 void Awake()
 {
     genetics = GameObject.FindGameObjectWithTag("GameController").GetComponent <Genetics> ();
     movement = gameObject.GetComponent <SpecimenMovement> ();
 }
Exemple #30
0
        public static SimDescription DGSMakeSSimDescription(SimBuilder builder, CASAgeGenderFlags age, CASAgeGenderFlags gender, ResourceKey skinTone, float skinToneIndex, Color[] hairColors, WorldName homeWorld, uint outfitCategoriesToBuild, bool isAlien)
        {
            if (age == CASAgeGenderFlags.None)
            {
                return(null);
            }
            if (builder == null)
            {
                builder                = new SimBuilder();
                builder.Age            = age;
                builder.Gender         = gender;
                builder.Species        = CASAgeGenderFlags.Human;
                builder.SkinTone       = skinTone;
                builder.SkinToneIndex  = skinToneIndex;
                builder.TextureSize    = 1024u;
                builder.UseCompression = true;
            }
            if (hairColors.Length == 9)
            {
                Color[] array = new Color[10];
                hairColors.CopyTo(array, 0);
                array[9]   = hairColors[0];
                hairColors = array;
            }
            if (hairColors.Length != 10)
            {
                hairColors = Genetics.Black1;
            }
            Color[] array2 = new Color[4];
            Array.Copy(hairColors, 5, array2, 0, 4);
            Color activeEyebrowColor = hairColors[4];
            SimDescriptionCore simDescriptionCore = new SimDescriptionCore();

            simDescriptionCore.HomeWorld = homeWorld;
            bool useDyeColor = age == CASAgeGenderFlags.Elder;

            GeneticColor[] hairColors2 = simDescriptionCore.HairColors;
            for (int i = 0; i < 4; i++)
            {
                hairColors2[i].UseDyeColor = useDyeColor;
            }
            simDescriptionCore.HairColors                = hairColors2;
            simDescriptionCore.ActiveHairColors          = hairColors;
            simDescriptionCore.EyebrowColor.UseDyeColor  = useDyeColor;
            simDescriptionCore.ActiveEyebrowColor        = activeEyebrowColor;
            simDescriptionCore.BodyHairColor.UseDyeColor = useDyeColor;
            simDescriptionCore.ActiveBodyHairColor       = hairColors[9];
            GeneticColor[] facialHairColors = simDescriptionCore.FacialHairColors;
            for (int j = 0; j < 4; j++)
            {
                facialHairColors[j].UseDyeColor = useDyeColor;
            }
            simDescriptionCore.FacialHairColors       = facialHairColors;
            simDescriptionCore.ActiveFacialHairColors = array2;
            Dictionary <ResourceKey, float> dictionary = new Dictionary <ResourceKey, float>();

            if (LocaleConstraints.GetFacialShape(ref dictionary, homeWorld))
            {
                foreach (KeyValuePair <ResourceKey, float> keyValuePair in dictionary)
                {
                    builder.SetFacialBlend(keyValuePair.Key, keyValuePair.Value);
                }
            }
            OutfitUtils.AddMissingParts(builder, (OutfitCategories)2097154u, true, simDescriptionCore, isAlien);
            Genetics.SleepIfPossible();
            OutfitUtils.AddMissingParts(builder, OutfitCategories.Everyday, true, simDescriptionCore, isAlien);
            Genetics.SleepIfPossible();
            ResourceKey key = default(ResourceKey);

            if (LocaleConstraints.GetUniform(ref key, homeWorld, age, gender, OutfitCategories.Everyday))
            {
                OutfitUtils.SetOutfit(builder, new SimOutfit(key), simDescriptionCore);
            }
            OutfitUtils.SetAutomaticModifiers(builder);
            ResourceKey key2 = builder.CacheOutfit(string.Format("Genetics.MakeSim_{0}_{1}_{2}", builder.Age, Simulator.TicksElapsed(), OutfitCategories.Everyday));

            if (key2.InstanceId == 0UL)
            {
                return(null);
            }
            OutfitCategories[] array3 = new OutfitCategories[]
            {
                OutfitCategories.Naked,
                OutfitCategories.Athletic,
                OutfitCategories.Formalwear,
                OutfitCategories.Sleepwear,
                OutfitCategories.Swimwear
            };
            SimOutfit      simOutfit      = new SimOutfit(key2);
            SimDescription simDescription = new SimDescription(simOutfit);

            simDescription.HairColors       = simDescriptionCore.HairColors;
            simDescription.FacialHairColors = simDescriptionCore.FacialHairColors;
            simDescription.EyebrowColor     = simDescriptionCore.EyebrowColor;
            simDescription.BodyHairColor    = simDescriptionCore.BodyHairColor;
            simDescription.AddOutfit(simOutfit, OutfitCategories.Everyday, true);
            foreach (OutfitCategories outfitCategories in array3)
            {
                if ((outfitCategoriesToBuild & (uint)outfitCategories) != 0u)
                {
                    OutfitUtils.MakeCategoryAppropriate(builder, outfitCategories, simDescription);
                    if (LocaleConstraints.GetUniform(ref key, homeWorld, age, gender, outfitCategories))
                    {
                        OutfitUtils.SetOutfit(builder, new SimOutfit(key), simDescriptionCore);
                    }
                    ResourceKey key3 = builder.CacheOutfit(string.Format("Genetics.MakeSim_{0}_{1}_{2}", builder.Age, Simulator.TicksElapsed(), outfitCategories));
                    simDescription.AddOutfit(new SimOutfit(key3), outfitCategories);
                    Genetics.SleepIfPossible();
                }
            }
            simDescription.RandomizePreferences();
            TraitNames cultureSpecificTrait = Genetics.GetCultureSpecificTrait(homeWorld);

            if (cultureSpecificTrait == TraitNames.FutureSim)
            {
                simDescription.TraitManager.AddHiddenElement(cultureSpecificTrait);
                Skill skill = simDescription.SkillManager.AddElement(SkillNames.Future);
                if ((skill.AvailableAgeSpecies & simDescription.GetCASAGSAvailabilityFlags()) != CASAGSAvailabilityFlags.None)
                {
                    while (simDescription.SkillManager.GetSkillLevel(SkillNames.Future) < skill.MaxSkillLevel)
                    {
                        simDescription.SkillManager.ForceGainPointsForLevelUp(SkillNames.Future);
                    }
                }
            }
            else if (cultureSpecificTrait != TraitNames.Unknown)
            {
                simDescription.TraitManager.AddHiddenElement(cultureSpecificTrait);
            }
            builder.Dispose();
            builder = null;
            simDescription.HomeWorld = GameUtils.GetCurrentWorld();
            return(simDescription);
        }
Exemple #31
0
        protected List <Sim> GenerateHumanChildren(SimDescription woman, SimDescription man, int numChildren)
        {
            Random pregoRandom = new Random();

            List <Sim> babies = new List <Sim>();

            for (int i = 0; i < numChildren; i++)
            {
                try
                {
                    SimDescription newBaby = Genetics.MakeBaby(woman, man, NRaas.MasterControllerSpace.Helpers.Baby.InterpretGender(mGender), 100, pregoRandom, false);
                    woman.Household.Add(newBaby);

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

                    Sim babySim = Instantiation.Perform(newBaby, null);
                    if (babySim != null)
                    {
                        babies.Add(babySim);

                        SimOutfit currentOutfit = babySim.CurrentOutfit;
                        if (currentOutfit != null)
                        {
                            ThumbnailManager.GenerateHouseholdSimThumbnail(currentOutfit.Key, currentOutfit.Key.InstanceId, 0x0, ThumbnailSizeMask.Large | ThumbnailSizeMask.ExtraLarge | ThumbnailSizeMask.Medium | ThumbnailSizeMask.Small, ThumbnailTechnique.Default, true, false, newBaby.AgeGenderSpecies);
                        }

                        Pregnancy.MakeBabyVisible(babySim);

                        if (i == 0)
                        {
                            EventTracker.SendEvent(new SimDescriptionEvent(EventTypeId.kNewBaby, newBaby));
                        }

                        if (woman != null)
                        {
                            MidlifeCrisisManager.OnHadChild(woman);

                            if (woman.CreatedSim != null)
                            {
                                EventTracker.SendEvent(EventTypeId.kNewOffspring, woman.CreatedSim, babySim);
                                EventTracker.SendEvent(EventTypeId.kParentAdded, babySim, woman.CreatedSim);
                            }
                        }

                        if (man != null)
                        {
                            MidlifeCrisisManager.OnHadChild(man);

                            if (man.CreatedSim != null)
                            {
                                EventTracker.SendEvent(EventTypeId.kNewOffspring, man.CreatedSim, babySim);
                                EventTracker.SendEvent(EventTypeId.kParentAdded, babySim, man.CreatedSim);
                            }
                        }

                        EventTracker.SendEvent(EventTypeId.kChildBornOrAdopted, null, babySim);

                        if (newBaby.IsHuman)
                        {
                            OccultImaginaryFriend.DeliverDollToHousehold(new List <Sim> {
                                newBaby.CreatedSim
                            });
                        }
                    }
                }
                catch (Exception e)
                {
                    Common.Exception(woman, man, e);
                }
            }

            if (babies.Count > 0)
            {
                if (woman.CreatedSim != null)
                {
                    EventTracker.SendEvent(new PregnancyEvent(EventTypeId.kHadBaby, woman.CreatedSim, man.CreatedSim, null, babies));
                }

                if (man.CreatedSim != null)
                {
                    EventTracker.SendEvent(new PregnancyEvent(EventTypeId.kHadBaby, man.CreatedSim, woman.CreatedSim, null, babies));
                }
            }

            return(babies);
        }