コード例 #1
0
ファイル: PackUtilityWorker.cs プロジェクト: Plythios/RimVali
        public static float PackmateGeneratorChance(
            Pawn generated,
            Pawn other,
            PawnGenerationRequest request,
            bool ex)
        {
            if ((double)generated.ageTracker.AgeBiologicalYearsFloat < 5.0)
            {
                if (!(generated.RaceProps.body.defName == AvaliDefs.RimValiBody.defName))
                {
                    return(0.0f);
                }
            }
            if (!(other.RaceProps.body.defName == AvaliDefs.RimValiBody.defName))
            {
                return(0.0f);
            }
            float num1 = 2f;
            float generationChanceAgeFactor1 = PackRelationUtilityWorker.GetGenerationChanceAgeFactor(generated);
            float generationChanceAgeFactor2 = PackRelationUtilityWorker.GetGenerationChanceAgeFactor(other);
            float chanceAgeGapFactor         = PackRelationUtilityWorker.GetGenerationChanceAgeGapFactor(generated, other, ex);
            float num4 = 2f;
            float num5 = !request.FixedMelanin.HasValue ? PawnSkinColors.GetMelaninCommonalityFactor(other.story.melanin) : ChildRelationUtility.GetMelaninSimilarityFactor(request.FixedMelanin.Value, other.story.melanin);

            return(num1 * generationChanceAgeFactor1 * generationChanceAgeFactor2 * chanceAgeGapFactor * num5 * num4);
        }
コード例 #2
0
ファイル: Class1.cs プロジェクト: k2ymg/rimworld-mods
        // see PawnGenerator
        private void generate_pawn()
        {
            Gender gender;

            if (Rand.Value < 0.5f)
            {
                gender = Gender.Male;
            }
            else
            {
                gender = Gender.Female;
            }

            Faction f = Faction.OfPlayer;

            float melanin = PawnSkinColors.RandomMelanin(f);

            skinColor = PawnSkinColors.GetSkinColor(melanin);
            int age = 20;

            hairColor = PawnHairColors.RandomHairColor(skinColor, age);
            hairDef   = RandomHairDefFor(gender, f.def);

            crownType = Rand.Value >= 0.5f ? CrownType.Narrow : CrownType.Average;

            headGraphicPath = GraphicDatabaseHeadRecords.GetHeadRandom(
                gender, skinColor, crownType).GraphicPath;

            bodyType = BodyType.Male;
        }
コード例 #3
0
        /// <summary>expose data.</summary>
        public override void PostExposeData()
        {
            base.PostExposeData();
            Scribe_Values.Look(ref _customDrawSize, "customDrawSize");
            Scribe_Values.Look(ref _customPortraitDrawSize, "customPortraitDrawSize");
            Scribe_Values.Look(ref _fixedGenderPostSpawn, nameof(FixGenderPostSpawn));
            Scribe_Values.Look(ref _skinColor, "skinColor");
            Scribe_Values.Look(ref _skinColorSecond, "skinColorSecond");
            Scribe_Values.Look(ref _hairColorSecond, "hairColorSecond");
            Scribe_Values.Look(ref _crownType, "crownType");
            Scribe_Values.Look(ref _hairColor, nameof(HairColor));
            Scribe_Values.Look(ref _scanned, nameof(_scanned));
            Scribe_Defs.Look(ref _body, nameof(_body));
            Scribe_Defs.Look(ref _hairDef, nameof(_hairDef));


            if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                if (_skinColor == Color.clear)
                {
                    _skinColor = PawnSkinColors.GetSkinColor(Pawn.story.melanin);
                }
                if (_body == null)
                {
                    _body = Pawn.story.bodyType;
                }
            }
        }
コード例 #4
0
        public override float GenerationChance(Pawn generated, Pawn other, PawnGenerationRequest request)
        {
            float num  = 1f;
            float num2 = 1f;

            if (other.GetFather() != null || other.GetMother() != null)
            {
                num = ChildRelationUtility.ChanceOfBecomingChildOf(generated, other.GetFather(), other.GetMother(), new PawnGenerationRequest?(request), null, null);
            }
            else if (request.FixedMelanin.HasValue)
            {
                num2 = ChildRelationUtility.GetMelaninSimilarityFactor(request.FixedMelanin.Value, other.story.melanin);
            }
            else
            {
                num2 = PawnSkinColors.GetMelaninCommonalityFactor(other.story.melanin);
            }
            float num3 = Mathf.Abs(generated.ageTracker.AgeChronologicalYearsFloat - other.ageTracker.AgeChronologicalYearsFloat);
            float num4 = 1f;

            if (num3 > 40f)
            {
                num4 = 0.2f;
            }
            else if (num3 > 10f)
            {
                num4 = 0.65f;
            }
            return(num * num2 * num4 * base.BaseGenerationChanceFactor(generated, other, request));
        }
コード例 #5
0
        public override Color GetColor(Pawn pawn, List <string> options)
        {
            List <Pair <Color, float> > list = new List <Pair <Color, float> >();

            foreach (var option in options)
            {
                var          arg = option.Replace(" ", "");
                List <float> num = new List <float>();
                foreach (Match match in Regex.Matches(arg, @"(\d{1,}\.\d{1,}|\d{1,})"))
                {
                    num.Add(float.Parse(match.Value));
                }
                if (num.Count() != 3)
                {
                    RaceAddon.Notify("Parsing failed! => " + option, true);
                }
                Color color = PawnSkinColors.GetSkinColor(Rand.Range(num[0], num[1]));
                list.Add(new Pair <Color, float>(color, num[2]));
            }
            if (list.Count == 0)
            {
                RaceAddon.Notify("Color generation failed! => " + pawn.Name.ToStringFull, true);
                return(Color.white);
            }
            return(list.RandomElementByWeight(x => x.Second).First);
        }
コード例 #6
0
        public static void PsychologyFormula(ref float __result, Pawn generated, Pawn other, PawnGenerationRequest request, bool ex)
        {
            /* Throw away the existing result and substitute our own formula. */
            float          sexualityFactor = 1f;
            PsychologyPawn realGenerated   = generated as PsychologyPawn;
            PsychologyPawn realOther       = other as PsychologyPawn;

            if (PsychologyBase.ActivateKinsey() && realGenerated != null && realOther != null && realGenerated.sexuality != null && realOther.sexuality != null)
            {
                float kinsey  = 3 - realGenerated.sexuality.kinseyRating;
                float kinsey2 = 3 - realOther.sexuality.kinseyRating;
                float h**o    = (generated.gender == other.gender) ? 1f : -1f;
                sexualityFactor *= Mathf.InverseLerp(3f, 0f, kinsey * h**o);
                sexualityFactor *= Mathf.InverseLerp(3f, 0f, kinsey2 * h**o);
            }
            else
            {
                sexualityFactor = (generated.gender != other.gender) ? 1f : 0.01f;
            }
            float existingExLoverFactor = 1f;

            if (ex)
            {
                int exLovers = 0;
                List <DirectPawnRelation> directRelations = other.relations.DirectRelations;
                for (int i = 0; i < directRelations.Count; i++)
                {
                    if (LovePartnerRelationUtility.IsExLovePartnerRelation(directRelations[i].def))
                    {
                        exLovers++;
                    }
                }
                existingExLoverFactor = Mathf.Pow(0.2f, (float)exLovers);
            }
            else if (LovePartnerRelationUtility.HasAnyLovePartner(other))
            {
                __result = 0f;
                return;
            }
            float generationChanceAgeFactor    = Traverse.Create(typeof(LovePartnerRelationUtility)).Method("GetGenerationChanceAgeFactor", new[] { typeof(Pawn) }).GetValue <float>(new object[] { generated });
            float generationChanceAgeFactor2   = Traverse.Create(typeof(LovePartnerRelationUtility)).Method("GetGenerationChanceAgeFactor", new[] { typeof(Pawn) }).GetValue <float>(new object[] { other });
            float generationChanceAgeGapFactor = Traverse.Create(typeof(LovePartnerRelationUtility)).Method("GetGenerationChanceAgeGapFactor", new[] { typeof(Pawn), typeof(Pawn), typeof(bool) }).GetValue <float>(new object[] { generated, other, ex });
            float incestFactor = 1f;

            if (generated.GetRelations(other).Any((PawnRelationDef x) => x.familyByBloodRelation))
            {
                incestFactor = 0.01f;
            }
            float melaninFactor;

            if (request.FixedMelanin.HasValue)
            {
                melaninFactor = ChildRelationUtility.GetMelaninSimilarityFactor(request.FixedMelanin.Value, other.story.melanin);
            }
            else
            {
                melaninFactor = PawnSkinColors.GetMelaninCommonalityFactor(other.story.melanin);
            }
            __result = existingExLoverFactor * sexualityFactor * generationChanceAgeFactor * generationChanceAgeFactor2 * generationChanceAgeGapFactor * incestFactor * melaninFactor;
        }
コード例 #7
0
 // Token: 0x06000CF3 RID: 3315 RVA: 0x00040C84 File Offset: 0x0003EE84
 internal static void GenerateParentParams(float minChronologicalAge, float maxChronologicalAge, float midChronologicalAge, float minBioAgeToHaveChildren, Pawn generatedChild, Pawn existingChild, PawnGenerationRequest childRequest, out float biologicalAge, out float chronologicalAge, out float skinWhiteness, out string lastName)
 {
     chronologicalAge = Rand.GaussianAsymmetric(midChronologicalAge, (midChronologicalAge - minChronologicalAge) / 2f, (maxChronologicalAge - midChronologicalAge) / 2f);
     chronologicalAge = Mathf.Clamp(chronologicalAge, minChronologicalAge, maxChronologicalAge);
     biologicalAge    = Rand.Range(minBioAgeToHaveChildren, Mathf.Min(existingChild.RaceProps.lifeExpectancy, chronologicalAge));
     if (existingChild.GetFather() != null)
     {
         skinWhiteness = ParentRelationUtility.GetRandomSecondParentSkinColor(existingChild.GetFather().story.skinWhiteness, existingChild.story.skinWhiteness, childRequest.FixedSkinWhiteness);
     }
     else if (existingChild.GetMother() != null)
     {
         skinWhiteness = ParentRelationUtility.GetRandomSecondParentSkinColor(existingChild.GetMother().story.skinWhiteness, existingChild.story.skinWhiteness, childRequest.FixedSkinWhiteness);
     }
     else if (!childRequest.FixedSkinWhiteness.HasValue)
     {
         skinWhiteness = PawnSkinColors.GetRandomSkinColorSimilarTo(existingChild.story.skinWhiteness, 0f, 1f);
     }
     else
     {
         float num  = Mathf.Min(childRequest.FixedSkinWhiteness.Value, existingChild.story.skinWhiteness);
         float num2 = Mathf.Max(childRequest.FixedSkinWhiteness.Value, existingChild.story.skinWhiteness);
         if (Rand.Value < 0.5f)
         {
             skinWhiteness = PawnSkinColors.GetRandomSkinColorSimilarTo(num, 0f, num);
         }
         else
         {
             skinWhiteness = PawnSkinColors.GetRandomSkinColorSimilarTo(num2, num2, 1f);
         }
     }
     lastName = null;
     if (!ChildRelationUtility.DefinitelyHasNotBirthName(existingChild) && ChildRelationUtility.ChildWantsNameOfAnyParent(existingChild))
     {
         if (existingChild.GetMother() == null && existingChild.GetFather() == null)
         {
             if (Rand.Value < 0.5f)
             {
                 lastName = ((NameTriple)existingChild.Name).Last;
             }
         }
         else
         {
             string last = ((NameTriple)existingChild.Name).Last;
             string b    = null;
             if (existingChild.GetMother() != null)
             {
                 b = ((NameTriple)existingChild.GetMother().Name).Last;
             }
             else if (existingChild.GetFather() != null)
             {
                 b = ((NameTriple)existingChild.GetFather().Name).Last;
             }
             if (last != b)
             {
                 lastName = last;
             }
         }
     }
 }
コード例 #8
0
        public PawnGraphicRenderer(float melanin)
        {
            Color     skinColor = PawnSkinColors.GetSkinColor(this.melanin = melanin);
            Gender    gender    = (Rand.Value < 0.5f) ? Gender.Male : Gender.Female;
            CrownType crownType = (Rand.Value < 0.5f) ? CrownType.Average : CrownType.Narrow;
            HairDef   hairDef   = RandomHairDefFor(gender);
            Color     hairColor = PawnHairColors.RandomHairColor(skinColor, 18);

            headGraphic = GraphicDatabaseHeadRecords.GetHeadRandom(gender, skinColor, crownType, false);
            hairGraphic = GraphicDatabase.Get <Graphic_Multi>(hairDef.texPath, ShaderDatabase.Cutout, Vector2.one, hairColor);
        }
コード例 #9
0
        // Populates color arrays from PawnSkinColors.SkinColors.  Uses an indirect method of getting the color values
        // instead of just copying the color list via reflection.  This will make it work better with mods that
        // detour the color methods in that class--as long as they detour the GetSkinDataIndexOfMelanin() method.
        public static void InitializeColors()
        {
            List <float> values = new List <float>();

            // Get the private GetSkinDataLeftIndexByWhiteness() method from the PawnSkinColors class.
            MethodInfo getSkinDataIndexOfMelaninMethod = typeof(PawnSkinColors)
                                                         .GetMethod("GetSkinDataIndexOfMelanin",
                                                                    BindingFlags.NonPublic | BindingFlags.Static, null, new[] { typeof(float) }, null);

            // Iterate all values from 0.0f to 1.0f, using increments of 0.01f, to get the left index for each value.
            // Use this technique to construct a list of all of the indexes and their values.  Once we have the list
            // of indexes and their values, we can use the GetSkinColor() method to get the actual colors.
            int currentIndex = 0;

            values.Add(0.0f);
            float f       = 0.01f;
            int   counter = 1;

            while (f < 1.0f)
            {
                // ReSharper disable once PossibleNullReferenceException
                int result = (int)getSkinDataIndexOfMelaninMethod.Invoke(null, new object[] { f });
                if (result != currentIndex)
                {
                    currentIndex = result;
                    values.Add(f);
                }
                counter++;
                double d = counter / 100.0;
                f = (float)d;
            }
            values.Add(1.0f);

            // Allocate the arrays and fill them with the correct values.
            int length = values.Count;

            Colors        = new Color[length];
            ColorValues   = new float[length];
            RoundedColors = new Color[length];
            for (int i = 0; i < length; i++)
            {
                float v     = values[i];
                Color color = PawnSkinColors.GetSkinColor(v);
                Colors[i]          = color;
                RoundedColors[i]   = color;
                RoundedColors[i].r = (float)Math.Round(color.r, 3);
                RoundedColors[i].g = (float)Math.Round(color.g, 3);
                RoundedColors[i].b = (float)Math.Round(color.b, 3);
                RoundedColors[i].a = (float)Math.Round(color.a, 3);
                ColorValues[i]     = v;
                //  Log.Message("Color added: (" + color.r + ", " + color.g + ", " + color.b + ")");
            }
        }
コード例 #10
0
        // LovePartnerRelationUtility.LovePartnerRelationGenerationChance, but with the gender and sexuality code removed.
        public static float LovePartnerRelationGenerationChance(Pawn generated, Pawn other,
                                                                PawnGenerationRequest request, bool ex)
        {
            if (generated.ageTracker.AgeBiologicalYearsFloat < 14f)
            {
                return(0f);
            }

            if (other.ageTracker.AgeBiologicalYearsFloat < 14f)
            {
                return(0f);
            }

            var num = 1f;

            if (ex)
            {
                var num2            = 0;
                var directRelations = other.relations.DirectRelations;
                foreach (var directPawnRelation in directRelations)
                {
                    if (LovePartnerRelationUtility.IsExLovePartnerRelation(directPawnRelation.def))
                    {
                        num2++;
                    }
                }

                num = Mathf.Pow(0.2f, num2);
            }
            else if (LovePartnerRelationUtility.HasAnyLovePartner(other))
            {
                return(0f);
            }

            var generationChanceAgeFactor    = GetGenerationChanceAgeFactor(generated);
            var generationChanceAgeFactor2   = GetGenerationChanceAgeFactor(other);
            var generationChanceAgeGapFactor = GetGenerationChanceAgeGapFactor(generated, other, ex);
            var num3 = 1f;

            if (generated.GetRelations(other).Any(x => x.familyByBloodRelation))
            {
                num3 = 0.01f;
            }

            var num4 = request.FixedMelanin.HasValue
                ? ChildRelationUtility.GetMelaninSimilarityFactor(request.FixedMelanin.Value, other.story.melanin)
                : PawnSkinColors.GetMelaninCommonalityFactor(other.story.melanin);

            return(num * generationChanceAgeFactor * generationChanceAgeFactor2 * generationChanceAgeGapFactor * num3 *
                   num4);
        }
コード例 #11
0
 public override Color GetColor(Pawn pawn, List <string> options)
 {
     if (Rand.Value < 0.02f)
     {
         return(new Color(Rand.Value, Rand.Value, Rand.Value));
     }
     if (pawn.ageTracker.AgeBiologicalYears > (pawn.def as RaceAddonThingDef).raceAddonSettings.healthSetting.greyHairAt)
     {
         float num = GenMath.SmootherStep(40f, 75f, pawn.ageTracker.AgeBiologicalYears);
         if (Rand.Value < num)
         {
             float num2 = Rand.Range(0.65f, 0.85f);
             return(new Color(num2, num2, num2));
         }
     }
     if (PawnSkinColors.IsDarkSkin(pawn.story.SkinColor) || Rand.Value < 0.5f)
     {
         float value = Rand.Value;
         if (value < 0.25f)
         {
             return(new Color(0.2f, 0.2f, 0.2f));
         }
         if (value < 0.5f)
         {
             return(new Color(0.31f, 0.28f, 0.26f));
         }
         if (value < 0.75f)
         {
             return(new Color(0.25f, 0.2f, 0.15f));
         }
         return(new Color(0.3f, 0.2f, 0.1f));
     }
     else
     {
         float value2 = Rand.Value;
         if (value2 < 0.25f)
         {
             return(new Color(0.3529412f, 0.227450982f, 0.1254902f));
         }
         if (value2 < 0.5f)
         {
             return(new Color(0.5176471f, 0.3254902f, 0.184313729f));
         }
         if (value2 < 0.75f)
         {
             return(new Color(0.75686276f, 0.572549045f, 0.333333343f));
         }
         return(new Color(0.929411769f, 0.7921569f, 0.6117647f));
     }
 }
コード例 #12
0
 public static Color RandomHairColor(Color skinColor, int ageYears, int getsGrayAt)
 {
     if (Rand.Value < 0.02f)
     {
         return(new Color(Rand.Value, Rand.Value, Rand.Value));
     }
     if (ageYears > (getsGrayAt + Rand.Range(-0.3f * getsGrayAt, 0.1f * getsGrayAt)))
     {
         float num = GenMath.SmootherStep(40f, 75f, (float)ageYears);
         if (Rand.Value < num)
         {
             float num2 = Rand.Range(0.65f, 0.85f);
             return(new Color(num2, num2, num2));
         }
     }
     if (PawnSkinColors.IsDarkSkin(skinColor) || Rand.Value < 0.5f)
     {
         float value = Rand.Value;
         if (value < 0.25f)
         {
             return(new Color(0.2f, 0.2f, 0.2f));
         }
         if (value < 0.5f)
         {
             return(new Color(0.31f, 0.28f, 0.26f));
         }
         if (value < 0.75f)
         {
             return(new Color(0.25f, 0.2f, 0.15f));
         }
         return(new Color(0.3f, 0.2f, 0.1f));
     }
     else
     {
         float value2 = Rand.Value;
         if (value2 < 0.25f)
         {
             return(new Color(0.3529412f, 0.227450982f, 0.1254902f));
         }
         if (value2 < 0.5f)
         {
             return(new Color(0.5176471f, 0.3254902f, 0.184313729f));
         }
         if (value2 < 0.75f)
         {
             return(new Color(0.75686276f, 0.572549045f, 0.333333343f));
         }
         return(new Color(0.929411769f, 0.7921569f, 0.6117647f));
     }
 }
コード例 #13
0
        // Populates color arrays from PawnSkinColors.SkinColors.  Uses an indirect method of getting the color values
        // instead of just copying the color list via reflection.  This will make it work better with mods that
        // detour the color methods in that class--as long as they detour the GetSkinDataIndexOfMelanin() method.
        public static void InitializeColors()
        {
            List <float> values = new List <float>();

            // Iterate all values from 0.0f to 1.0f, using increments of 0.01f, to get the left index for each value.
            // Use this technique to construct a list of all of the indexes and their values.  Once we have the list
            // of indexes and their values, we can use the GetSkinColor() method to get the actual colors.
            int currentIndex = 0;

            values.Add(0.0f);
            float f       = 0.01f;
            int   counter = 1;

            while (f < 1.0f)
            {
                int result = Reflection.PawnSkinColors.GetSkinDataIndexOfMelanin(f);
                if (result != currentIndex)
                {
                    currentIndex = result;
                    values.Add(f);
                }
                counter++;
                double d = (double)counter / 100.0;
                f = (float)d;
            }
            values.Add(1.0f);

            // Allocate the arrays and fill them with the correct values.
            int length = values.Count;

            Colors        = new Color[length];
            ColorValues   = new float[length];
            RoundedColors = new Color[length];
            for (int i = 0; i < length; i++)
            {
                float v     = values[i];
                Color color = PawnSkinColors.GetSkinColor(v);
                Colors[i]          = color;
                RoundedColors[i]   = color;
                RoundedColors[i].r = (float)Math.Round(color.r, 3);
                RoundedColors[i].g = (float)Math.Round(color.g, 3);
                RoundedColors[i].b = (float)Math.Round(color.b, 3);
                RoundedColors[i].a = (float)Math.Round(color.a, 3);
                ColorValues[i]     = v;
                //Logger.Debug("Color added: (" + color.r + ", " + color.g + ", " + color.b + ")");
            }
        }
コード例 #14
0
        public override void DoEditInterface(Listing_ScenEdit listing)
        {
            phase += Time.deltaTime * step;

            float t = (Mathf.Sin(phase) + 1) / 2f;

            curCol = PawnSkinColors.GetSkinColor(melanin.LerpThroughRange(t));

            Rect rect = listing.GetScenPartRect(this, RowHeight * 4 + 31f);

            Rect[] rows = rect.SplitRows(31f, 4 * RowHeight);

            Rect[] cols = rows[0].SplitCols(rows[0].width - 31f, 31f);

            Widgets.FloatRange(cols[0], listing.CurHeight.GetHashCode(), ref melanin);
            Widgets.DrawBoxSolid(cols[1].ContractedBy(4), curCol);
            FixMelaninRange();

            DoContextEditInterface(rows[1]);
        }
コード例 #15
0
 public static Color RandomHairColor(Color skinColor)
 {
     if (UnityEngine.Random.value < 0.02f)
     {
         return(new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value));
     }
     if (PawnSkinColors.IsDarkSkin(skinColor) || UnityEngine.Random.value < 0.5f)
     {
         float value = UnityEngine.Random.value;
         if (value < 0.25f)
         {
             return(new Color(0.2f, 0.2f, 0.2f));
         }
         if (value < 0.5f)
         {
             return(new Color(0.31f, 0.28f, 0.26f));
         }
         if (value < 0.75f)
         {
             return(new Color(0.25f, 0.2f, 0.15f));
         }
         return(new Color(0.3f, 0.2f, 0.1f));
     }
     else
     {
         float value2 = UnityEngine.Random.value;
         if (value2 < 0.25f)
         {
             return(new Color(0.3529412f, 0.227450982f, 0.1254902f));
         }
         if (value2 < 0.5f)
         {
             return(new Color(0.5176471f, 0.3254902f, 0.184313729f));
         }
         if (value2 < 0.75f)
         {
             return(new Color(0.75686276f, 0.572549045f, 0.333333343f));
         }
         return(new Color(0.929411769f, 0.7921569f, 0.6117647f));
     }
 }
コード例 #16
0
        public Color SkinColor(Pawn alien, bool first = true)
        {
            AlienComp alienComp = alien.TryGetComp <AlienComp>();

            if (alienComp.skinColor == Color.clear)
            {
                alienComp.skinColor       = (this.alienskincolorgen != null ? this.alienskincolorgen.NewRandomizedColor() : PawnSkinColors.GetSkinColor(alien.story.melanin));
                alienComp.skinColorSecond = (this.alienskinsecondcolorgen != null ? this.alienskinsecondcolorgen.NewRandomizedColor() : alienComp.skinColor);
            }
            return(first ? alienComp.skinColor : alienComp.skinColorSecond);
        }
コード例 #17
0
        public static Color RandomHairColor(Color skinColor, int ageYears, int getsGrayAt)
        {
            bool  flag = Rand.Value < 0.02f;
            Color result;

            if (flag)
            {
                result = new Color(Rand.Value, Rand.Value, Rand.Value);
            }
            else
            {
                bool flag2 = (float)ageYears > (float)getsGrayAt + Rand.Range(-0.3f * (float)getsGrayAt, 0.1f * (float)getsGrayAt);
                if (flag2)
                {
                    float num   = GenMath.SmootherStep(40f, 75f, (float)ageYears);
                    bool  flag3 = Rand.Value < num;
                    if (flag3)
                    {
                        float num2 = Rand.Range(0.65f, 0.85f);
                        result = new Color(num2, num2, num2);
                        return(result);
                    }
                }
                bool flag4 = PawnSkinColors.IsDarkSkin(skinColor) || Rand.Value < 0.5f;
                if (flag4)
                {
                    float value = Rand.Value;
                    bool  flag5 = value < 0.25f;
                    if (flag5)
                    {
                        result = new Color(0.2f, 0.2f, 0.2f);
                    }
                    else
                    {
                        bool flag6 = value < 0.5f;
                        if (flag6)
                        {
                            result = new Color(0.31f, 0.28f, 0.26f);
                        }
                        else
                        {
                            bool flag7 = value < 0.75f;
                            if (flag7)
                            {
                                result = new Color(0.25f, 0.2f, 0.15f);
                            }
                            else
                            {
                                result = new Color(0.3f, 0.2f, 0.1f);
                            }
                        }
                    }
                }
                else
                {
                    float value2 = Rand.Value;
                    bool  flag8  = value2 < 0.25f;
                    if (flag8)
                    {
                        result = new Color(0.3529412f, 0.227450982f, 0.1254902f);
                    }
                    else
                    {
                        bool flag9 = value2 < 0.5f;
                        if (flag9)
                        {
                            result = new Color(0.5176471f, 0.3254902f, 0.184313729f);
                        }
                        else
                        {
                            bool flag10 = value2 < 0.75f;
                            if (flag10)
                            {
                                result = new Color(0.75686276f, 0.572549045f, 0.333333343f);
                            }
                            else
                            {
                                result = new Color(0.929411769f, 0.7921569f, 0.6117647f);
                            }
                        }
                    }
                }
            }
            return(result);
        }
コード例 #18
0
ファイル: ColorGenerators.cs プロジェクト: Plythios/RimVali
 public override Color NewRandomizedColor() =>
 PawnSkinColors.GetSkinColor(Rand.Range(this.minMelanin, this.maxMelanin));
        private static float LovePartnerRelationGenerationChance_Method(Pawn generated, Pawn other, PawnGenerationRequest request, bool ex)
        {
            if (generated.ageTracker.AgeBiologicalYearsFloat < 14f || other.ageTracker.AgeBiologicalYearsFloat < 14f)
            {
                return(0f);
            }
            float LoveChance   = 1f;
            float GenderFactor = 1f;
            var   comp         = other.TryGetComp <CompIndividuality>();

            if (generated.gender != other.gender && comp != null)
            {
                if (comp.sexuality == CompIndividuality.Sexuality.Straight)
                {
                    GenderFactor = 1.0f;
                }
                else if (comp.sexuality == CompIndividuality.Sexuality.Bisexual)
                {
                    GenderFactor = 0.75f;
                }
                else if (comp.sexuality == CompIndividuality.Sexuality.Gay)
                {
                    GenderFactor = 0.05f;
                }
            }
            if (generated.gender == other.gender && comp != null)
            {
                if (comp.sexuality == CompIndividuality.Sexuality.Gay)
                {
                    GenderFactor = 1.0f;
                }
                else if (comp.sexuality == CompIndividuality.Sexuality.Bisexual)
                {
                    GenderFactor = 0.75f;
                }
                else if (comp.sexuality == CompIndividuality.Sexuality.Straight)
                {
                    GenderFactor = 0.05f;
                }
            }
            if (ex)
            {
                int ExLovers = 0;
                List <DirectPawnRelation> directRelations = other.relations.DirectRelations;
                for (int i = 0; i < directRelations.Count; i++)
                {
                    if (LovePartnerRelationUtility.IsExLovePartnerRelation(directRelations[i].def))
                    {
                        ExLovers++;
                    }
                }
                LoveChance = Mathf.Pow(0.2f, (float)ExLovers);
            }
            else if (LovePartnerRelationUtility.HasAnyLovePartner(other))
            {
                return(0f);
            }
            float generationChanceAgeFactor    = Mathf.Clamp(GenMath.LerpDouble(14f, 27f, 0f, 1f, generated.ageTracker.AgeBiologicalYearsFloat), 0f, 1f);
            float generationChanceAgeFactor2   = Mathf.Clamp(GenMath.LerpDouble(14f, 27f, 0f, 1f, other.ageTracker.AgeBiologicalYearsFloat), 0f, 1f);
            float generationChanceAgeGapFactor = (float)GetGenerationChanceAgeGapFactor.Invoke(null, new object[] { generated, other, ex });
            float IncestFactor = 1f;

            if (generated.GetRelations(other).Any((PawnRelationDef x) => x.familyByBloodRelation))
            {
                IncestFactor = 0.01f;
            }
            float MelaninFactor;

            if (request.FixedMelanin != null)
            {
                MelaninFactor = ChildRelationUtility.GetMelaninSimilarityFactor(request.FixedMelanin.Value, other.story.melanin);
            }
            else
            {
                MelaninFactor = PawnSkinColors.GetMelaninCommonalityFactor(other.story.melanin);
            }
            return(LoveChance * generationChanceAgeFactor * generationChanceAgeFactor2 * generationChanceAgeGapFactor * GenderFactor * MelaninFactor * IncestFactor);
        }
コード例 #20
0
        public static Pawn Copy(Pawn sourcePawn, PawnKindDef kindDef, Faction faction, bool forceBodyVisual = false, bool forceApparel = false, bool forceWeapon = false)
        {
            Pawn pawn = (Pawn)ThingMaker.MakeThing(kindDef.race, null);

            pawn.kindDef = kindDef;
            pawn.SetFactionDirect(faction);
            pawn.pather     = new Pawn_PathFollower(pawn);
            pawn.ageTracker = new Pawn_AgeTracker(pawn);
            pawn.health     = new Pawn_HealthTracker(pawn);
            pawn.jobs       = new Pawn_JobTracker(pawn);
            pawn.mindState  = new Pawn_MindState(pawn);
            pawn.filth      = new Pawn_FilthTracker(pawn);
            pawn.needs      = new Pawn_NeedsTracker(pawn);
            pawn.stances    = new Pawn_StanceTracker(pawn);
            pawn.InitUnsavedUniversalComponents();

            if (pawn.RaceProps.ToolUser)
            {
                pawn.equipment = new Pawn_EquipmentTracker(pawn);
                pawn.carrier   = new Pawn_CarryTracker(pawn);
                pawn.apparel   = new Pawn_ApparelTracker(pawn);
                pawn.inventory = new Pawn_InventoryTracker(pawn);
            }
            if (pawn.RaceProps.Humanlike)
            {
                pawn.ownership    = new Pawn_Ownership(pawn);
                pawn.skills       = new Pawn_SkillTracker(pawn);
                pawn.talker       = new Pawn_TalkTracker(pawn);
                pawn.story        = new Pawn_StoryTracker(pawn);
                pawn.workSettings = new Pawn_WorkSettings(pawn);
            }
            if (pawn.RaceProps.intelligence <= Intelligence.ToolUser)
            {
                pawn.caller = new Pawn_CallTracker(pawn);
            }
            PawnUtility.AddAndRemoveComponentsAsAppropriate(pawn);
            if (pawn.RaceProps.hasGenders)
            {
                if ((sourcePawn != null) &&
                    (sourcePawn.RaceProps.hasGenders) &&
                    (sourcePawn.gender != Gender.None))
                {
                    pawn.gender = sourcePawn.gender;
                }
                else
                {
                    if (Rand.Value < 0.5f)
                    {
                        pawn.gender = Gender.Male;
                    }
                    else
                    {
                        pawn.gender = Gender.Female;
                    }
                }
            }
            else
            {
                pawn.gender = Gender.None;
            }

            AbilityEffect_Revive.GenerateRandomAge_Coping(pawn, sourcePawn);
            AbilityEffect_Revive.GenerateInitialHediffs_Coping(pawn, sourcePawn);
            if (pawn.RaceProps.Humanlike)
            {
                if ((sourcePawn != null) &&
                    (forceBodyVisual))
                {
                    pawn.story.skinColor       = sourcePawn.story.skinColor;
                    pawn.story.crownType       = sourcePawn.story.crownType;
                    pawn.story.headGraphicPath = sourcePawn.story.headGraphicPath;
                    pawn.story.hairColor       = sourcePawn.story.hairColor;

                    AbilityEffect_Revive.GiveAppropriateBioTo_Coping(pawn, sourcePawn);
                    pawn.story.hairDef = sourcePawn.story.hairDef;
                    AbilityEffect_Revive.GiveRandomTraitsTo_Coping(pawn, sourcePawn);
                    pawn.story.GenerateSkillsFromBackstory();
                }
                else
                {
                    pawn.story.skinColor       = PawnSkinColors.RandomSkinColor();
                    pawn.story.crownType       = ((Rand.Value >= 0.5f) ? CrownType.Narrow : CrownType.Average);
                    pawn.story.headGraphicPath = GraphicDatabaseHeadRecords.GetHeadRandom(pawn.gender, pawn.story.skinColor, pawn.story.crownType).GraphicPath;
                    pawn.story.hairColor       = PawnHairColors.RandomHairColor(pawn.story.skinColor, pawn.ageTracker.AgeBiologicalYears);

                    PawnBioGenerator.GiveAppropriateBioTo(pawn, faction.def);
                    pawn.story.hairDef = PawnHairChooser.RandomHairDefFor(pawn, faction.def);
                    AbilityEffect_Revive.GiveRandomTraitsTo(pawn);
                    pawn.story.GenerateSkillsFromBackstory();
                }
            }

            AbilityEffect_Revive.GenerateStartingApparelFor_Coping(pawn, sourcePawn, forceApparel);
            AbilityEffect_Revive.TryGenerateWeaponFor_Coping(pawn, sourcePawn, forceWeapon);
            AbilityEffect_Revive.GenerateInventoryFor_Coping(pawn, sourcePawn);
            PawnUtility.AddAndRemoveComponentsAsAppropriate(pawn);
            return(pawn);
        }
コード例 #21
0
        private static Pawn TryGenerateNewPawnInternal(ref PawnGenerationRequest request, out string error, bool ignoreScenarioRequirements, bool ignoreValidator)
        {
            error = null;
            Pawn pawn = (Pawn)ThingMaker.MakeThing(request.KindDef.race);

            pawnsBeingGenerated.Add(new PawnGenerationStatus(pawn, null));
            try
            {
                pawn.kindDef = request.KindDef;
                pawn.SetFactionDirect(request.Faction);
                PawnComponentsUtility.CreateInitialComponents(pawn);
                if (request.FixedGender.HasValue)
                {
                    pawn.gender = request.FixedGender.Value;
                }
                else if (pawn.RaceProps.hasGenders)
                {
                    if (Rand.Value < 0.5f)
                    {
                        pawn.gender = Gender.Male;
                    }
                    else
                    {
                        pawn.gender = Gender.Female;
                    }
                }
                else
                {
                    pawn.gender = Gender.None;
                }
                GenerateRandomAge(pawn, request);
                pawn.needs.SetInitialLevels();
                if (!request.Newborn && request.CanGeneratePawnRelations)
                {
                    GeneratePawnRelations(pawn, ref request);
                }
                if (pawn.RaceProps.Humanlike)
                {
                    Faction    faction;
                    FactionDef factionType = ((request.Faction != null) ? request.Faction.def : ((!Find.FactionManager.TryGetRandomNonColonyHumanlikeFaction_NewTemp(out faction, tryMedievalOrBetter: false, allowDefeated: true)) ? Faction.OfAncients.def : faction.def));
                    pawn.story.melanin   = (request.FixedMelanin.HasValue ? request.FixedMelanin.Value : PawnSkinColors.RandomMelanin(request.Faction));
                    pawn.story.crownType = ((Rand.Value < 0.5f) ? CrownType.Average : CrownType.Narrow);
                    pawn.story.hairColor = PawnHairColors.RandomHairColor(pawn.story.SkinColor, pawn.ageTracker.AgeBiologicalYears);
                    PawnBioAndNameGenerator.GiveAppropriateBioAndNameTo(pawn, request.FixedLastName, factionType);
                    if (pawn.story != null)
                    {
                        if (request.FixedBirthName != null)
                        {
                            pawn.story.birthLastName = request.FixedBirthName;
                        }
                        else if (pawn.Name is NameTriple)
                        {
                            pawn.story.birthLastName = ((NameTriple)pawn.Name).Last;
                        }
                    }
                    pawn.story.hairDef = PawnHairChooser.RandomHairDefFor(pawn, factionType);
                    GenerateTraits(pawn, request);
                    GenerateBodyType_NewTemp(pawn, request);
                    GenerateSkills(pawn);
                }
                if (pawn.RaceProps.Animal && request.Faction != null && request.Faction.IsPlayer)
                {
                    pawn.training.SetWantedRecursive(TrainableDefOf.Tameness, checkOn: true);
                    pawn.training.Train(TrainableDefOf.Tameness, null, complete: true);
                }
                GenerateInitialHediffs(pawn, request);
                if (!request.ForbidAnyTitle)
                {
                    RoyalTitleDef royalTitleDef = request.FixedTitle;
                    if (royalTitleDef == null)
                    {
                        if (request.KindDef.titleRequired != null)
                        {
                            royalTitleDef = request.KindDef.titleRequired;
                        }
                        else if (!request.KindDef.titleSelectOne.NullOrEmpty() && Rand.Chance(request.KindDef.royalTitleChance))
                        {
                            royalTitleDef = request.KindDef.titleSelectOne.RandomElementByWeight((RoyalTitleDef t) => t.commonality);
                        }
                    }
                    if (request.KindDef.minTitleRequired != null && (royalTitleDef == null || royalTitleDef.seniority < request.KindDef.minTitleRequired.seniority))
                    {
                        royalTitleDef = request.KindDef.minTitleRequired;
                    }
                    if (royalTitleDef != null)
                    {
                        Faction faction2 = ((request.Faction != null && request.Faction.def.HasRoyalTitles) ? request.Faction : Find.FactionManager.RandomRoyalFaction());
                        pawn.royalty.SetTitle(faction2, royalTitleDef, grantRewards: false);
                        if (request.Faction != null && !request.Faction.IsPlayer)
                        {
                            PurchasePermits(pawn, faction2);
                        }
                        int amount = 0;
                        if (royalTitleDef.GetNextTitle(faction2) != null)
                        {
                            amount = Rand.Range(0, royalTitleDef.GetNextTitle(faction2).favorCost - 1);
                        }
                        pawn.royalty.SetFavor_NewTemp(faction2, amount);
                        if (royalTitleDef.maxPsylinkLevel > 0)
                        {
                            Hediff_ImplantWithLevel hediff_ImplantWithLevel = HediffMaker.MakeHediff(HediffDefOf.PsychicAmplifier, pawn, pawn.health.hediffSet.GetBrain()) as Hediff_ImplantWithLevel;
                            pawn.health.AddHediff(hediff_ImplantWithLevel);
                            hediff_ImplantWithLevel.SetLevelTo(royalTitleDef.maxPsylinkLevel);
                        }
                    }
                }
                if (pawn.royalty != null)
                {
                    pawn.royalty.allowRoomRequirements    = request.KindDef.allowRoyalRoomRequirements;
                    pawn.royalty.allowApparelRequirements = request.KindDef.allowRoyalApparelRequirements;
                }
                if (pawn.workSettings != null && request.Faction != null && request.Faction.IsPlayer)
                {
                    pawn.workSettings.EnableAndInitialize();
                }
                if (request.Faction != null && pawn.RaceProps.Animal)
                {
                    pawn.GenerateNecessaryName();
                }
                if (Find.Scenario != null)
                {
                    Find.Scenario.Notify_NewPawnGenerating(pawn, request.Context);
                }
                if (!request.AllowDead && (pawn.Dead || pawn.Destroyed))
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated dead pawn.";
                    return(null);
                }
                if (!request.AllowDowned && pawn.Downed)
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated downed pawn.";
                    return(null);
                }
                if (request.MustBeCapableOfViolence && ((pawn.story != null && pawn.WorkTagIsDisabled(WorkTags.Violent)) || (pawn.RaceProps.ToolUser && !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))))
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated pawn incapable of violence.";
                    return(null);
                }
                if (request.KindDef != null && !request.KindDef.skills.NullOrEmpty())
                {
                    List <SkillRange> skills = request.KindDef.skills;
                    for (int i = 0; i < skills.Count; i++)
                    {
                        if (pawn.skills.GetSkill(skills[i].Skill).TotallyDisabled)
                        {
                            error = "Generated pawn incapable of required skill: " + skills[i].Skill.defName;
                            return(null);
                        }
                    }
                }
                if (request.KindDef.requiredWorkTags != 0 && (pawn.CombinedDisabledWorkTags & request.KindDef.requiredWorkTags) != 0)
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated pawn with disabled requiredWorkTags.";
                    return(null);
                }
                if (!ignoreScenarioRequirements && request.Context == PawnGenerationContext.PlayerStarter && Find.Scenario != null && !Find.Scenario.AllowPlayerStartingPawn(pawn, tryingToRedress: false, request))
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated pawn doesn't meet scenario requirements.";
                    return(null);
                }
                if (!ignoreValidator && request.ValidatorPreGear != null && !request.ValidatorPreGear(pawn))
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated pawn didn't pass validator check (pre-gear).";
                    return(null);
                }
                if (!request.Newborn)
                {
                    GenerateGearFor(pawn, request);
                }
                if (!ignoreValidator && request.ValidatorPostGear != null && !request.ValidatorPostGear(pawn))
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated pawn didn't pass validator check (post-gear).";
                    return(null);
                }
                for (int j = 0; j < pawnsBeingGenerated.Count - 1; j++)
                {
                    if (pawnsBeingGenerated[j].PawnsGeneratedInTheMeantime == null)
                    {
                        pawnsBeingGenerated[j] = new PawnGenerationStatus(pawnsBeingGenerated[j].Pawn, new List <Pawn>());
                    }
                    pawnsBeingGenerated[j].PawnsGeneratedInTheMeantime.Add(pawn);
                }
                return(pawn);
            }
            finally
            {
                pawnsBeingGenerated.RemoveLast();
            }
        }
コード例 #22
0
 static bool Prefix(ref Color __result)
 {
     __result = PawnSkinColors.GetSkinColor(WhiteOnly.settings.melaninRange.RandomInRange * 0.01f);
     return(false);
 }
コード例 #23
0
        private static Pawn DoGenerateNewNakedPawn(ref PawnGenerationRequest request, out string error, bool ignoreScenarioRequirements)
        {
            error = null;
            Pawn pawn = (Pawn)ThingMaker.MakeThing(request.KindDef.race, null);

            AlienPawnGenerator.pawnsBeingGenerated.Add(new AlienPawnGenerator.PawnGenerationStatus(pawn, null));
            Pawn result;

            try
            {
                pawn.kindDef = request.KindDef;
                pawn.SetFactionDirect(request.Faction);
                PawnComponentsUtility.CreateInitialComponents(pawn);
                if (request.FixedGender.HasValue)
                {
                    pawn.gender = request.FixedGender.Value;
                }
                else if (pawn.RaceProps.hasGenders)
                {
                    if (Rand.Value < 0.5f)
                    {
                        pawn.gender = Gender.Male;
                    }
                    else
                    {
                        pawn.gender = Gender.Female;
                    }
                }
                else
                {
                    pawn.gender = Gender.None;
                }
                AlienPawnGenerator.GenerateRandomAge(pawn, request);
                pawn.needs.SetInitialLevels();
                if (!request.Newborn && request.CanGeneratePawnRelations)
                {
                    AlienPawnGenerator.GeneratePawnRelations(pawn, ref request);
                }
                if (pawn.RaceProps.Humanlike)
                {
                    pawn.story.skinWhiteness = ((!request.FixedSkinWhiteness.HasValue) ? PawnSkinColors.RandomSkinWhiteness() : request.FixedSkinWhiteness.Value);
                    pawn.story.crownType     = ((Rand.Value >= 0.5f) ? CrownType.Narrow : CrownType.Average);
                    pawn.story.hairColor     = PawnHairColors.RandomHairColor(pawn.story.SkinColor, pawn.ageTracker.AgeBiologicalYears);
                    PawnBioGenerator.GiveAppropriateBioTo(pawn, request.FixedLastName);
                    pawn.story.hairDef = PawnHairChooser.RandomHairDefFor(pawn, request.Faction.def);
                    AlienPawnGenerator.GiveRandomTraits(pawn, request.AllowGay);
                    pawn.story.GenerateSkillsFromBackstory();
                }
                if (pawn.workSettings != null && request.Faction.IsPlayer)
                {
                    pawn.workSettings.EnableAndInitialize();
                }
                if (request.Faction != null && pawn.RaceProps.Animal)
                {
                    pawn.GenerateNecessaryName();
                }
                if (!request.AllowDead && (pawn.Dead || pawn.Destroyed))
                {
                    AlienPawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated dead pawn.";
                    result = null;
                }
                else if (!request.AllowDowned && pawn.Downed)
                {
                    AlienPawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated downed pawn.";
                    result = null;
                }
                else if (request.MustBeCapableOfViolence && pawn.story != null && pawn.story.WorkTagIsDisabled(WorkTags.Violent))
                {
                    AlienPawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated pawn incapable of violence.";
                    result = null;
                }
                else if (!ignoreScenarioRequirements && request.Context == PawnGenerationContext.PlayerStarter && !Find.Scenario.AllowPlayerStartingPawn(pawn))
                {
                    AlienPawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated pawn doesn't meet scenario requirements.";
                    result = null;
                }
                else if (request.Validator != null && !request.Validator(pawn))
                {
                    AlienPawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated pawn didn't pass validator check.";
                    result = null;
                }
                else
                {
                    for (int i = 0; i < AlienPawnGenerator.pawnsBeingGenerated.Count - 1; i++)
                    {
                        if (AlienPawnGenerator.pawnsBeingGenerated[i].PawnsGeneratedInTheMeantime == null)
                        {
                            AlienPawnGenerator.pawnsBeingGenerated[i] = new AlienPawnGenerator.PawnGenerationStatus(AlienPawnGenerator.pawnsBeingGenerated[i].Pawn, new List <Pawn>());
                        }
                        AlienPawnGenerator.pawnsBeingGenerated[i].PawnsGeneratedInTheMeantime.Add(pawn);
                    }
                    result = pawn;
                }
            }
            finally
            {
                AlienPawnGenerator.pawnsBeingGenerated.RemoveLast <AlienPawnGenerator.PawnGenerationStatus>();
            }
            return(result);
        }
コード例 #24
0
        private static Pawn TryGenerateNewPawnInternal(ref PawnGenerationRequest request, out string error, bool ignoreScenarioRequirements, bool ignoreValidator)
        {
            error = null;
            Pawn pawn = (Pawn)ThingMaker.MakeThing(request.KindDef.race, null);

            PawnGenerator.pawnsBeingGenerated.Add(new PawnGenerator.PawnGenerationStatus(pawn, null));
            Pawn result;

            try
            {
                pawn.kindDef = request.KindDef;
                pawn.SetFactionDirect(request.Faction);
                PawnComponentsUtility.CreateInitialComponents(pawn);
                if (request.FixedGender.HasValue)
                {
                    pawn.gender = request.FixedGender.Value;
                }
                else if (pawn.RaceProps.hasGenders)
                {
                    if (Rand.Value < 0.5f)
                    {
                        pawn.gender = Gender.Male;
                    }
                    else
                    {
                        pawn.gender = Gender.Female;
                    }
                }
                else
                {
                    pawn.gender = Gender.None;
                }
                PawnGenerator.GenerateRandomAge(pawn, request);
                pawn.needs.SetInitialLevels();
                if (!request.Newborn && request.CanGeneratePawnRelations)
                {
                    PawnGenerator.GeneratePawnRelations(pawn, ref request);
                }
                if (pawn.RaceProps.Humanlike)
                {
                    FactionDef def;
                    Faction    faction;
                    if (request.Faction != null)
                    {
                        def = request.Faction.def;
                    }
                    else if (Find.FactionManager.TryGetRandomNonColonyHumanlikeFaction(out faction, false, true, TechLevel.Undefined))
                    {
                        def = faction.def;
                    }
                    else
                    {
                        def = Faction.OfAncients.def;
                    }
                    pawn.story.melanin   = ((!request.FixedMelanin.HasValue) ? PawnSkinColors.RandomMelanin(request.Faction) : request.FixedMelanin.Value);
                    pawn.story.crownType = ((Rand.Value >= 0.5f) ? CrownType.Narrow : CrownType.Average);
                    pawn.story.hairColor = PawnHairColors.RandomHairColor(pawn.story.SkinColor, pawn.ageTracker.AgeBiologicalYears);
                    PawnBioAndNameGenerator.GiveAppropriateBioAndNameTo(pawn, request.FixedLastName, def);
                    pawn.story.hairDef = PawnHairChooser.RandomHairDefFor(pawn, def);
                    PawnGenerator.GenerateTraits(pawn, request);
                    PawnGenerator.GenerateBodyType(pawn);
                    PawnGenerator.GenerateSkills(pawn);
                }
                if (pawn.RaceProps.Animal && request.Faction != null && request.Faction.IsPlayer)
                {
                    pawn.training.SetWantedRecursive(TrainableDefOf.Tameness, true);
                    pawn.training.Train(TrainableDefOf.Tameness, null, true);
                }
                PawnGenerator.GenerateInitialHediffs(pawn, request);
                if (pawn.workSettings != null && request.Faction != null && request.Faction.IsPlayer)
                {
                    pawn.workSettings.EnableAndInitialize();
                }
                if (request.Faction != null && pawn.RaceProps.Animal)
                {
                    pawn.GenerateNecessaryName();
                }
                if (Find.Scenario != null)
                {
                    Find.Scenario.Notify_NewPawnGenerating(pawn, request.Context);
                }
                if (!request.AllowDead && (pawn.Dead || pawn.Destroyed))
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated dead pawn.";
                    result = null;
                }
                else if (!request.AllowDowned && pawn.Downed)
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated downed pawn.";
                    result = null;
                }
                else if (request.MustBeCapableOfViolence && ((pawn.story != null && pawn.story.WorkTagIsDisabled(WorkTags.Violent)) || (pawn.RaceProps.ToolUser && !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))))
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated pawn incapable of violence.";
                    result = null;
                }
                else if (!ignoreScenarioRequirements && request.Context == PawnGenerationContext.PlayerStarter && Find.Scenario != null && !Find.Scenario.AllowPlayerStartingPawn(pawn, false, request))
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated pawn doesn't meet scenario requirements.";
                    result = null;
                }
                else if (!ignoreValidator && request.ValidatorPreGear != null && !request.ValidatorPreGear(pawn))
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated pawn didn't pass validator check (pre-gear).";
                    result = null;
                }
                else
                {
                    if (!request.Newborn)
                    {
                        PawnGenerator.GenerateGearFor(pawn, request);
                    }
                    if (!ignoreValidator && request.ValidatorPostGear != null && !request.ValidatorPostGear(pawn))
                    {
                        PawnGenerator.DiscardGeneratedPawn(pawn);
                        error  = "Generated pawn didn't pass validator check (post-gear).";
                        result = null;
                    }
                    else
                    {
                        for (int i = 0; i < PawnGenerator.pawnsBeingGenerated.Count - 1; i++)
                        {
                            if (PawnGenerator.pawnsBeingGenerated[i].PawnsGeneratedInTheMeantime == null)
                            {
                                PawnGenerator.pawnsBeingGenerated[i] = new PawnGenerator.PawnGenerationStatus(PawnGenerator.pawnsBeingGenerated[i].Pawn, new List <Pawn>());
                            }
                            PawnGenerator.pawnsBeingGenerated[i].PawnsGeneratedInTheMeantime.Add(pawn);
                        }
                        result = pawn;
                    }
                }
            }
            finally
            {
                PawnGenerator.pawnsBeingGenerated.RemoveLast <PawnGenerator.PawnGenerationStatus>();
            }
            return(result);
        }
コード例 #25
0
        // Token: 0x06000C9A RID: 3226 RVA: 0x0003EAD8 File Offset: 0x0003CCD8
        internal static float _LovePartnerRelationGenerationChance(Pawn generated, Pawn other, PawnGenerationRequest request, bool ex)
        {
            if (generated.ageTracker.AgeBiologicalYearsFloat < 14f)
            {
                return(0f);
            }
            if (other.ageTracker.AgeBiologicalYearsFloat < 14f)
            {
                return(0f);
            }
            if (generated.gender == other.gender && (!other.story.traits.HasTrait(TraitDefOf.Gay) || !other.story.traits.HasTrait(TraitDefOfPsychology.Bisexual) || !request.AllowGay))
            {
                return(0f);
            }
            if (generated.gender != other.gender && other.story.traits.HasTrait(TraitDefOf.Gay))
            {
                return(0f);
            }
            var GetGenerationChanceAgeFactor    = typeof(LovePartnerRelationUtility).GetMethod("GetGenerationChanceAgeFactor", BindingFlags.Static | BindingFlags.NonPublic);
            var GetGenerationChanceAgeGapFactor = typeof(LovePartnerRelationUtility).GetMethod("GetGenerationChanceAgeGapFactor", BindingFlags.Static | BindingFlags.NonPublic);

            if (GetGenerationChanceAgeFactor == null)
            {
                Log.ErrorOnce("Unable to reflect LovePartnerRelationUtility.GetGenerationChanceAgeFactor!", 305432421);
                return(0f);
            }
            if (GetGenerationChanceAgeGapFactor == null)
            {
                Log.ErrorOnce("Unable to reflect LovePartnerRelationUtility.GetGenerationChanceAgeGapFactor!", 305432421);
                return(0f);
            }
            float num = 1f;

            if (ex)
            {
                int num2 = 0;
                List <DirectPawnRelation> directRelations = other.relations.DirectRelations;
                for (int i = 0; i < directRelations.Count; i++)
                {
                    if (LovePartnerRelationUtility.IsExLovePartnerRelation(directRelations[i].def))
                    {
                        num2++;
                    }
                }
                num = Mathf.Pow(0.2f, (float)num2);
            }
            else if (LovePartnerRelationUtility.HasAnyLovePartner(other))
            {
                return(0f);
            }
            float num3 = (generated.gender != other.gender) ? 1f : 0.01f;
            float generationChanceAgeFactor    = (float)GetGenerationChanceAgeFactor.Invoke(null, new object[] { generated });
            float generationChanceAgeFactor2   = (float)GetGenerationChanceAgeFactor.Invoke(null, new object[] { other });
            float generationChanceAgeGapFactor = (float)GetGenerationChanceAgeGapFactor.Invoke(null, new object[] { generated, other, ex });
            float num4 = 1f;

            if (generated.GetRelations(other).Any((PawnRelationDef x) => x.familyByBloodRelation))
            {
                num4 = 0.01f;
            }
            float num5;

            if (request.FixedSkinWhiteness.HasValue)
            {
                num5 = ChildRelationUtility.GetSkinSimilarityFactor(request.FixedSkinWhiteness.Value, other.story.skinWhiteness);
            }
            else
            {
                num5 = PawnSkinColors.GetWhitenessCommonalityFactor(other.story.skinWhiteness);
            }
            return(num * generationChanceAgeFactor * generationChanceAgeFactor2 * generationChanceAgeGapFactor * num3 * num5 * num4);
        }
コード例 #26
0
        internal static float _LovePartnerRelationGenerationChance(Pawn generated, Pawn other, PawnGenerationRequest request, bool ex)
        {
            if (generated.ageTracker.AgeBiologicalYearsFloat < 14f)
            {
                return(0f);
            }
            if (other.ageTracker.AgeBiologicalYearsFloat < 14f)
            {
                return(0f);
            }
            if (!PsychologyBase.ActivateKinsey())
            {
                if (generated.gender == other.gender && (!other.story.traits.HasTrait(TraitDefOf.Gay) || !request.AllowGay))
                {
                    return(0f);
                }
                if (generated.gender != other.gender && other.story.traits.HasTrait(TraitDefOf.Gay))
                {
                    return(0f);
                }
            }
            else if (generated.gender == other.gender && !request.AllowGay)
            {
                return(0f);
            }
            float num = 1f;

            if (ex)
            {
                int num2 = 0;
                List <DirectPawnRelation> directRelations = other.relations.DirectRelations;
                for (int i = 0; i < directRelations.Count; i++)
                {
                    if (LovePartnerRelationUtility.IsExLovePartnerRelation(directRelations[i].def))
                    {
                        num2++;
                    }
                }
                num = Mathf.Pow(0.2f, (float)num2);
            }
            else if (LovePartnerRelationUtility.HasAnyLovePartner(other))
            {
                return(0f);
            }
            float          num3          = 1f;
            PsychologyPawn realGenerated = generated as PsychologyPawn;
            PsychologyPawn realOther     = other as PsychologyPawn;

            if (PsychologyBase.ActivateKinsey() && realGenerated != null && realOther != null)
            {
                float kinsey  = 3 - realGenerated.sexuality.kinseyRating;
                float kinsey2 = 3 - realOther.sexuality.kinseyRating;
                float h**o    = (generated.gender == other.gender) ? 1f : -1f;
                num3 *= Mathf.InverseLerp(3f, 0f, kinsey * h**o);
                num3 *= Mathf.InverseLerp(3f, 0f, kinsey2 * h**o);
            }
            else
            {
                num3 = (generated.gender != other.gender) ? 1f : 0.01f;
            }
            var   GetGenerationChanceAgeFactor    = typeof(LovePartnerRelationUtility).GetMethod("GetGenerationChanceAgeFactor", BindingFlags.Static | BindingFlags.NonPublic);
            var   GetGenerationChanceAgeGapFactor = typeof(LovePartnerRelationUtility).GetMethod("GetGenerationChanceAgeGapFactor", BindingFlags.Static | BindingFlags.NonPublic);
            float generationChanceAgeFactor       = (float)GetGenerationChanceAgeFactor.Invoke(null, new object[] { generated });
            float generationChanceAgeFactor2      = (float)GetGenerationChanceAgeFactor.Invoke(null, new object[] { other });
            float generationChanceAgeGapFactor    = (float)GetGenerationChanceAgeGapFactor.Invoke(null, new object[] { generated, other, ex });
            float num4 = 1f;

            if (generated.GetRelations(other).Any((PawnRelationDef x) => x.familyByBloodRelation))
            {
                num4 = 0.01f;
            }
            float num5;

            if (request.FixedMelanin.HasValue)
            {
                num5 = ChildRelationUtility.GetMelaninSimilarityFactor(request.FixedMelanin.Value, other.story.melanin);
            }
            else
            {
                num5 = PawnSkinColors.GetMelaninCommonalityFactor(other.story.melanin);
            }
            return(num * generationChanceAgeFactor * generationChanceAgeFactor2 * generationChanceAgeGapFactor * num3 * num5 * num4);
        }
コード例 #27
0
        private static Pawn TryGenerateNewNakedPawn(ref PawnGenerationRequest request, out string error, bool ignoreScenarioRequirements)
        {
            error = null;
            Pawn pawn = (Pawn)ThingMaker.MakeThing(request.KindDef.race, null);

            PawnGenerator.pawnsBeingGenerated.Add(new PawnGenerationStatus(pawn, null));
            try
            {
                pawn.kindDef = request.KindDef;
                pawn.SetFactionDirect(request.Faction);
                PawnComponentsUtility.CreateInitialComponents(pawn);
                if (request.FixedGender.HasValue)
                {
                    pawn.gender = request.FixedGender.Value;
                }
                else if (pawn.RaceProps.hasGenders)
                {
                    if (Rand.Value < 0.5)
                    {
                        pawn.gender = Gender.Male;
                    }
                    else
                    {
                        pawn.gender = Gender.Female;
                    }
                }
                else
                {
                    pawn.gender = Gender.None;
                }
                PawnGenerator.GenerateRandomAge(pawn, request);
                pawn.needs.SetInitialLevels();
                if (!request.Newborn && request.CanGeneratePawnRelations)
                {
                    PawnGenerator.GeneratePawnRelations(pawn, ref request);
                }
                if (pawn.RaceProps.Humanlike)
                {
                    pawn.story.melanin   = ((!request.FixedMelanin.HasValue) ? PawnSkinColors.RandomMelanin(request.Faction) : request.FixedMelanin.Value);
                    pawn.story.crownType = (CrownType)((Rand.Value < 0.5) ? 1 : 2);
                    pawn.story.hairColor = PawnHairColors.RandomHairColor(pawn.story.SkinColor, pawn.ageTracker.AgeBiologicalYears);
                    PawnBioAndNameGenerator.GiveAppropriateBioAndNameTo(pawn, request.FixedLastName);
                    pawn.story.hairDef = PawnHairChooser.RandomHairDefFor(pawn, request.Faction.def);
                    PawnGenerator.GenerateTraits(pawn, request);
                    PawnGenerator.GenerateBodyType(pawn);
                    PawnGenerator.GenerateSkills(pawn);
                }
                PawnGenerator.GenerateInitialHediffs(pawn, request);
                if (pawn.workSettings != null && request.Faction.IsPlayer)
                {
                    pawn.workSettings.EnableAndInitialize();
                }
                if (request.Faction != null && pawn.RaceProps.Animal)
                {
                    pawn.GenerateNecessaryName();
                }
                if (!request.AllowDead && (pawn.Dead || pawn.Destroyed))
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error = "Generated dead pawn.";
                    return(null);
                }
                if (!request.AllowDowned && pawn.Downed)
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error = "Generated downed pawn.";
                    return(null);
                }
                if (request.MustBeCapableOfViolence)
                {
                    if (pawn.story != null && pawn.story.WorkTagIsDisabled(WorkTags.Violent))
                    {
                        goto IL_02b0;
                    }
                    if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
                    {
                        goto IL_02b0;
                    }
                }
                if (!ignoreScenarioRequirements && request.Context == PawnGenerationContext.PlayerStarter && !Find.Scenario.AllowPlayerStartingPawn(pawn))
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error = "Generated pawn doesn't meet scenario requirements.";
                    return(null);
                }
                if (request.Validator != null && !request.Validator(pawn))
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error = "Generated pawn didn't pass validator check.";
                    return(null);
                }
                for (int i = 0; i < PawnGenerator.pawnsBeingGenerated.Count - 1; i++)
                {
                    if (PawnGenerator.pawnsBeingGenerated[i].PawnsGeneratedInTheMeantime == null)
                    {
                        PawnGenerator.pawnsBeingGenerated[i] = new PawnGenerationStatus(PawnGenerator.pawnsBeingGenerated[i].Pawn, new List <Pawn>());
                    }
                    PawnGenerator.pawnsBeingGenerated[i].PawnsGeneratedInTheMeantime.Add(pawn);
                }
                return(pawn);

IL_02b0:
                PawnGenerator.DiscardGeneratedPawn(pawn);
                error = "Generated pawn incapable of violence.";
                return(null);
            }
            finally
            {
                PawnGenerator.pawnsBeingGenerated.RemoveLast();
            }
        }
コード例 #28
0
        public Color SkinColor(Pawn alien, bool first = true)
        {
            AlienComp alienComp = alien.TryGetComp <AlienComp>();

            if (alienComp.skinColor != Color.clear)
            {
                return(first ? alienComp.skinColor : alienComp.skinColorSecond);
            }

            alienComp.skinColor       = this.alienskincolorgen?.NewRandomizedColor() ?? PawnSkinColors.GetSkinColor(melanin: alien.story.melanin);
            alienComp.skinColorSecond = this.alienskinsecondcolorgen?.NewRandomizedColor() ?? alienComp.skinColor;
            return(first ? alienComp.skinColor : alienComp.skinColorSecond);
        }