protected void MakeMote(TargetInfo A, TargetInfo B)
        {
            Vector3 vector = Vector3.zero;

            switch (this.def.spawnLocType)
            {
            case MoteSpawnLocType.OnSource:
                vector = A.CenterVector3;
                break;

            case MoteSpawnLocType.BetweenPositions:
            {
                Vector3 vector2 = (!A.HasThing) ? A.Cell.ToVector3Shifted() : A.Thing.DrawPos;
                Vector3 vector3 = (!B.HasThing) ? B.Cell.ToVector3Shifted() : B.Thing.DrawPos;
                if (A.HasThing && !A.Thing.Spawned)
                {
                    vector = vector3;
                }
                else if (B.HasThing && !B.Thing.Spawned)
                {
                    vector = vector2;
                }
                else
                {
                    vector = vector2 * this.def.positionLerpFactor + vector3 * (1f - this.def.positionLerpFactor);
                }
                break;
            }

            case MoteSpawnLocType.BetweenTouchingCells:
                vector = A.Cell.ToVector3Shifted() + (B.Cell - A.Cell).ToVector3().normalized * 0.5f;
                break;

            case MoteSpawnLocType.RandomCellOnTarget:
            {
                CellRect cellRect;
                if (B.HasThing)
                {
                    cellRect = B.Thing.OccupiedRect();
                }
                else
                {
                    cellRect = CellRect.CenteredOn(B.Cell, 0);
                }
                vector = cellRect.RandomCell.ToVector3Shifted();
                break;
            }
            }
            if (this.parent != null)
            {
                Rand.PushState(this.parent.GetHashCode());
                if (A.CenterVector3 != B.CenterVector3)
                {
                    vector += (B.CenterVector3 - A.CenterVector3).normalized * this.parent.def.offsetTowardsTarget.RandomInRange;
                }
                vector += Gen.RandomHorizontalVector(this.parent.def.positionRadius);
                Rand.PopState();
            }
            Map   map = A.Map ?? B.Map;
            float num = (!this.def.absoluteAngle) ? (B.Cell - A.Cell).AngleFlat : 0f;

            if (map != null && vector.ShouldSpawnMotesAt(map))
            {
                int randomInRange = this.def.burstCount.RandomInRange;
                for (int i = 0; i < randomInRange; i++)
                {
                    Mote mote = (Mote)ThingMaker.MakeThing(this.def.moteDef, null);
                    GenSpawn.Spawn(mote, vector.ToIntVec3(), map, WipeMode.Vanish);
                    mote.Scale         = this.def.scale.RandomInRange;
                    mote.exactPosition = vector + Gen.RandomHorizontalVector(this.def.positionRadius);
                    mote.rotationRate  = this.def.rotationRate.RandomInRange;
                    mote.exactRotation = this.def.rotation.RandomInRange + num;
                    MoteThrown moteThrown = mote as MoteThrown;
                    if (moteThrown != null)
                    {
                        moteThrown.airTimeLeft = this.def.airTime.RandomInRange;
                        moteThrown.SetVelocity(this.def.angle.RandomInRange + num, this.def.speed.RandomInRange);
                    }
                }
            }
        }
Example #2
0
        public static IEnumerable <Thing> MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient)
        {
            float efficiency;

            if (recipeDef.efficiencyStat == null)
            {
                efficiency = 1f;
            }
            else
            {
                efficiency = worker.GetStatValue(recipeDef.efficiencyStat, true);
            }
            if (recipeDef.products != null)
            {
                for (int i = 0; i < recipeDef.products.Count; i++)
                {
                    ThingCountClass prod = recipeDef.products[i];
                    ThingDef        stuffDef;
                    if (prod.thingDef.MadeFromStuff)
                    {
                        stuffDef = dominantIngredient.def;
                    }
                    else
                    {
                        stuffDef = null;
                    }
                    Thing product = ThingMaker.MakeThing(prod.thingDef, stuffDef);
                    product.stackCount = Mathf.CeilToInt((float)prod.count * efficiency);
                    if (dominantIngredient != null)
                    {
                        product.SetColor(dominantIngredient.DrawColor, false);
                    }
                    CompIngredients ingredientsComp = product.TryGetComp <CompIngredients>();
                    if (ingredientsComp != null)
                    {
                        for (int l = 0; l < ingredients.Count; l++)
                        {
                            ingredientsComp.RegisterIngredient(ingredients[l].def);
                        }
                    }
                    CompFoodPoisonable foodPoisonable = product.TryGetComp <CompFoodPoisonable>();
                    if (foodPoisonable != null)
                    {
                        float num  = worker.GetStatValue(StatDefOf.FoodPoisonChance, true);
                        Room  room = worker.GetRoom(RegionType.Set_Passable);
                        if (room != null)
                        {
                            num *= room.GetStat(RoomStatDefOf.FoodPoisonChanceFactor);
                        }
                        if (Rand.Value < num)
                        {
                            foodPoisonable.PoisonPercent = 1f;
                        }
                    }
                    yield return(GenRecipe.PostProcessProduct(product, recipeDef, worker));
                }
            }
            if (recipeDef.specialProducts != null)
            {
                for (int j = 0; j < recipeDef.specialProducts.Count; j++)
                {
                    for (int k = 0; k < ingredients.Count; k++)
                    {
                        Thing ing = ingredients[k];
                        SpecialProductType specialProductType = recipeDef.specialProducts[j];
                        if (specialProductType != SpecialProductType.Butchery)
                        {
                            if (specialProductType == SpecialProductType.Smelted)
                            {
                                foreach (Thing product2 in ing.SmeltProducts(efficiency))
                                {
                                    yield return(GenRecipe.PostProcessProduct(product2, recipeDef, worker));
                                }
                            }
                        }
                        else
                        {
                            foreach (Thing product3 in ing.ButcherProducts(worker, efficiency))
                            {
                                yield return(GenRecipe.PostProcessProduct(product3, recipeDef, worker));
                            }
                        }
                    }
                }
            }
        }
        private static void SpawnShuttle()
        {
            List <DebugMenuOption> options = new List <DebugMenuOption>
            {
                new DebugMenuOption("Incoming", DebugMenuOptionMode.Tool, delegate
                {
                    GenPlace.TryPlaceThing(SkyfallerMaker.MakeSkyfaller(ThingDefOf.ShuttleIncoming, ThingMaker.MakeThing(ThingDefOf.Shuttle)), UI.MouseCell(), Find.CurrentMap, ThingPlaceMode.Near);
                }),
                new DebugMenuOption("Stationary", DebugMenuOptionMode.Tool, delegate
                {
                    GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Shuttle), UI.MouseCell(), Find.CurrentMap, ThingPlaceMode.Near);
                })
            };

            Find.WindowStack.Add(new Dialog_DebugOptionListLister(options));
        }
Example #4
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 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)
                {
                    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);
                    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.";
                    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.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.AllowPlayerStartingPawn(pawn))
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated pawn doesn't meet scenario requirements.";
                    result = null;
                }
                else if (request.Validator != null && !request.Validator(pawn))
                {
                    PawnGenerator.DiscardGeneratedPawn(pawn);
                    error  = "Generated pawn didn't pass validator check.";
                    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);
        }
Example #5
0
 public static Thing Spawn(ThingDef def, IntVec3 loc, Map map)
 {
     return(GenSpawn.Spawn(ThingMaker.MakeThing(def, null), loc, map));
 }
        protected void MakeMote(TargetInfo A, TargetInfo B)
        {
            Vector3 vector = Vector3.zero;

            switch (def.spawnLocType)
            {
            case MoteSpawnLocType.OnSource:
                vector = A.CenterVector3;
                break;

            case MoteSpawnLocType.BetweenPositions:
            {
                Vector3 vector2 = (A.HasThing ? A.Thing.DrawPos : A.Cell.ToVector3Shifted());
                Vector3 vector3 = (B.HasThing ? B.Thing.DrawPos : B.Cell.ToVector3Shifted());
                vector = ((A.HasThing && !A.Thing.Spawned) ? vector3 : ((!B.HasThing || B.Thing.Spawned) ? (vector2 * def.positionLerpFactor + vector3 * (1f - def.positionLerpFactor)) : vector2));
                break;
            }

            case MoteSpawnLocType.RandomCellOnTarget:
                vector = ((!B.HasThing) ? CellRect.CenteredOn(B.Cell, 0) : B.Thing.OccupiedRect()).RandomCell.ToVector3Shifted();
                break;

            case MoteSpawnLocType.BetweenTouchingCells:
                vector = A.Cell.ToVector3Shifted() + (B.Cell - A.Cell).ToVector3().normalized * 0.5f;
                break;
            }
            if (parent != null)
            {
                Rand.PushState(parent.GetHashCode());
                if (A.CenterVector3 != B.CenterVector3)
                {
                    vector += (B.CenterVector3 - A.CenterVector3).normalized * parent.def.offsetTowardsTarget.RandomInRange;
                }
                vector += Gen.RandomHorizontalVector(parent.def.positionRadius) + parent.offset;
                Rand.PopState();
            }
            Map   map  = A.Map ?? B.Map;
            float num  = (def.absoluteAngle ? 0f : (B.Cell - A.Cell).AngleFlat);
            float num2 = ((parent != null) ? parent.scale : 1f);

            if (map == null || !vector.ShouldSpawnMotesAt(map))
            {
                return;
            }
            int randomInRange = def.burstCount.RandomInRange;

            for (int i = 0; i < randomInRange; i++)
            {
                Mote obj = (Mote)ThingMaker.MakeThing(def.moteDef);
                GenSpawn.Spawn(obj, vector.ToIntVec3(), map);
                obj.Scale         = def.scale.RandomInRange * num2;
                obj.exactPosition = vector + def.positionOffset * num2 + Gen.RandomHorizontalVector(def.positionRadius) * num2;
                obj.rotationRate  = def.rotationRate.RandomInRange;
                obj.exactRotation = def.rotation.RandomInRange + num;
                obj.instanceColor = def.color;
                MoteThrown moteThrown = obj as MoteThrown;
                if (moteThrown != null)
                {
                    moteThrown.airTimeLeft = def.airTime.RandomInRange;
                    moteThrown.SetVelocity(def.angle.RandomInRange + num, def.speed.RandomInRange);
                }
            }
        }
        public IEnumerable <Thing> ThingsToSpawnAfterLoad()
        {
            Dictionary <ushort, ThingDef> thingDefsByShortHash = new Dictionary <ushort, ThingDef>();

            foreach (ThingDef allDef in DefDatabase <ThingDef> .AllDefs)
            {
                if (thingDefsByShortHash.ContainsKey(allDef.shortHash))
                {
                    Log.Error(string.Concat("Hash collision between ", allDef, " and  ", thingDefsByShortHash[allDef.shortHash], ": both have short hash ", allDef.shortHash));
                }
                else
                {
                    thingDefsByShortHash.Add(allDef.shortHash, allDef);
                }
            }
            int          major     = VersionControl.MajorFromVersionString(ScribeMetaHeaderUtility.loadedGameVersion);
            int          minor     = VersionControl.MinorFromVersionString(ScribeMetaHeaderUtility.loadedGameVersion);
            List <Thing> loadables = new List <Thing>();

            MapSerializeUtility.LoadUshort(compressedData, map, delegate(IntVec3 c, ushort val)
            {
                if (val != 0)
                {
                    ThingDef thingDef = BackCompatibility.BackCompatibleThingDefWithShortHash_Force(val, major, minor);
                    if (thingDef == null)
                    {
                        try
                        {
                            thingDef = thingDefsByShortHash[val];
                        }
                        catch (KeyNotFoundException)
                        {
                            ThingDef thingDef2 = BackCompatibility.BackCompatibleThingDefWithShortHash(val);
                            if (thingDef2 != null)
                            {
                                thingDef = thingDef2;
                                thingDefsByShortHash.Add(val, thingDef2);
                            }
                            else
                            {
                                Log.Error("Map compressor decompression error: No thingDef with short hash " + val + ". Adding as null to dictionary.");
                                thingDefsByShortHash.Add(val, null);
                            }
                        }
                    }
                    if (thingDef != null)
                    {
                        try
                        {
                            Thing thing = ThingMaker.MakeThing(thingDef);
                            thing.SetPositionDirect(c);
                            loadables.Add(thing);
                        }
                        catch (Exception arg)
                        {
                            Log.Error("Could not instantiate compressed thing: " + arg);
                        }
                    }
                }
            });
            return(loadables);
        }
Example #8
0
        public static IEnumerable <Thing> MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient, IBillGiver billGiver)
        {
            float efficiency = (recipeDef.efficiencyStat != null) ? worker.GetStatValue(recipeDef.efficiencyStat) : 1f;

            if (recipeDef.workTableEfficiencyStat != null)
            {
                Building_WorkTable building_WorkTable = billGiver as Building_WorkTable;
                if (building_WorkTable != null)
                {
                    efficiency *= building_WorkTable.GetStatValue(recipeDef.workTableEfficiencyStat);
                }
            }
            if (recipeDef.products != null)
            {
                for (int k = 0; k < recipeDef.products.Count; k++)
                {
                    ThingDefCountClass thingDefCountClass = recipeDef.products[k];
                    Thing thing = ThingMaker.MakeThing(stuff: (!thingDefCountClass.thingDef.MadeFromStuff) ? null : dominantIngredient.def, def: thingDefCountClass.thingDef);
                    thing.stackCount = Mathf.CeilToInt((float)thingDefCountClass.count * efficiency);
                    if (dominantIngredient != null)
                    {
                        thing.SetColor(dominantIngredient.DrawColor, reportFailure: false);
                    }
                    CompIngredients compIngredients = thing.TryGetComp <CompIngredients>();
                    if (compIngredients != null)
                    {
                        for (int l = 0; l < ingredients.Count; l++)
                        {
                            compIngredients.RegisterIngredient(ingredients[l].def);
                        }
                    }
                    CompFoodPoisonable compFoodPoisonable = thing.TryGetComp <CompFoodPoisonable>();
                    if (compFoodPoisonable != null)
                    {
                        if (Rand.Chance(worker.GetRoom()?.GetStat(RoomStatDefOf.FoodPoisonChance) ?? RoomStatDefOf.FoodPoisonChance.roomlessScore))
                        {
                            compFoodPoisonable.SetPoisoned(FoodPoisonCause.FilthyKitchen);
                        }
                        else if (Rand.Chance(worker.GetStatValue(StatDefOf.FoodPoisonChance)))
                        {
                            compFoodPoisonable.SetPoisoned(FoodPoisonCause.IncompetentCook);
                        }
                    }
                    yield return(PostProcessProduct(thing, recipeDef, worker));
                }
            }
            if (recipeDef.specialProducts == null)
            {
                yield break;
            }
            for (int k = 0; k < recipeDef.specialProducts.Count; k++)
            {
                for (int i = 0; i < ingredients.Count; i++)
                {
                    Thing thing2 = ingredients[i];
                    switch (recipeDef.specialProducts[k])
                    {
                    case SpecialProductType.Butchery:
                        foreach (Thing item in thing2.ButcherProducts(worker, efficiency))
                        {
                            yield return(PostProcessProduct(item, recipeDef, worker));
                        }
                        break;

                    case SpecialProductType.Smelted:
                        foreach (Thing item2 in thing2.SmeltProducts(efficiency))
                        {
                            yield return(PostProcessProduct(item2, recipeDef, worker));
                        }
                        break;
                    }
                }
            }
        }
        public static IEnumerable <Thing> MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient, IBillGiver billGiver)
        {
            float efficiency;

            if (recipeDef.efficiencyStat == null)
            {
                efficiency = 1f;
            }
            else
            {
                efficiency = worker.GetStatValue(recipeDef.efficiencyStat, true);
            }
            if (recipeDef.workTableEfficiencyStat != null)
            {
                Building_WorkTable building_WorkTable = billGiver as Building_WorkTable;
                if (building_WorkTable != null)
                {
                    efficiency *= building_WorkTable.GetStatValue(recipeDef.workTableEfficiencyStat, true);
                }
            }
            if (recipeDef.products != null)
            {
                for (int i = 0; i < recipeDef.products.Count; i++)
                {
                    ThingDefCountClass prod = recipeDef.products[i];
                    ThingDef           stuffDef;
                    if (prod.thingDef.MadeFromStuff)
                    {
                        stuffDef = dominantIngredient.def;
                    }
                    else
                    {
                        stuffDef = null;
                    }
                    Thing product = ThingMaker.MakeThing(prod.thingDef, stuffDef);
                    product.stackCount = Mathf.CeilToInt((float)prod.count * efficiency);
                    if (dominantIngredient != null)
                    {
                        product.SetColor(dominantIngredient.DrawColor, false);
                    }
                    CompIngredients ingredientsComp = product.TryGetComp <CompIngredients>();
                    if (ingredientsComp != null)
                    {
                        for (int l = 0; l < ingredients.Count; l++)
                        {
                            ingredientsComp.RegisterIngredient(ingredients[l].def);
                        }
                    }
                    CompFoodPoisonable foodPoisonable = product.TryGetComp <CompFoodPoisonable>();
                    if (foodPoisonable != null)
                    {
                        Room  room   = worker.GetRoom(RegionType.Set_Passable);
                        float chance = (room == null) ? RoomStatDefOf.FoodPoisonChance.roomlessScore : room.GetStat(RoomStatDefOf.FoodPoisonChance);
                        if (Rand.Chance(chance))
                        {
                            foodPoisonable.SetPoisoned(FoodPoisonCause.FilthyKitchen);
                        }
                        else
                        {
                            float statValue = worker.GetStatValue(StatDefOf.FoodPoisonChance, true);
                            if (Rand.Chance(statValue))
                            {
                                foodPoisonable.SetPoisoned(FoodPoisonCause.IncompetentCook);
                            }
                        }
                    }
                    yield return(GenRecipe.PostProcessProduct(product, recipeDef, worker));
                }
            }
            if (recipeDef.specialProducts != null)
            {
                for (int j = 0; j < recipeDef.specialProducts.Count; j++)
                {
                    for (int k = 0; k < ingredients.Count; k++)
                    {
                        Thing ing = ingredients[k];
                        SpecialProductType specialProductType = recipeDef.specialProducts[j];
                        if (specialProductType != SpecialProductType.Butchery)
                        {
                            if (specialProductType == SpecialProductType.Smelted)
                            {
                                foreach (Thing product2 in ing.SmeltProducts(efficiency))
                                {
                                    yield return(GenRecipe.PostProcessProduct(product2, recipeDef, worker));
                                }
                            }
                        }
                        else
                        {
                            foreach (Thing product3 in ing.ButcherProducts(worker, efficiency))
                            {
                                yield return(GenRecipe.PostProcessProduct(product3, recipeDef, worker));
                            }
                        }
                    }
                }
            }
            yield break;
        }
Example #10
0
 public static Thing Spawn(ThingDef def, IntVec3 loc, Map map, WipeMode wipeMode = WipeMode.Vanish)
 {
     return(Spawn(ThingMaker.MakeThing(def), loc, map, wipeMode));
 }
Example #11
0
 public override void SpawnSetup()
 {
     base.SpawnSetup();
     this.inventory.container.TryAdd(ThingMaker.MakeThing(ThingDefOf.DoorKey));
     this.food = new Pawn_FoodTracker(this);              // Workaround: HealthTracker won't work without this.food
 }
Example #12
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(out faction, tryMedievalOrBetter: false, allowDefeated: true)) ? Faction.OfAncients.def : faction.def);
                    pawn.story.melanin   = ((!request.FixedMelanin.HasValue) ? PawnSkinColors.RandomMelanin(request.Faction) : request.FixedMelanin.Value);
                    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);
                    pawn.story.hairDef = PawnHairChooser.RandomHairDefFor(pawn, factionType);
                    GenerateTraits(pawn, request);
                    GenerateBodyType(pawn);
                    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 (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.story.WorkTagIsDisabled(WorkTags.Violent)) || (pawn.RaceProps.ToolUser && !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))))
                {
                    DiscardGeneratedPawn(pawn);
                    error = "Generated pawn incapable of violence.";
                    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 i = 0; i < pawnsBeingGenerated.Count - 1; i++)
                {
                    if (pawnsBeingGenerated[i].PawnsGeneratedInTheMeantime == null)
                    {
                        pawnsBeingGenerated[i] = new PawnGenerationStatus(pawnsBeingGenerated[i].Pawn, new List <Pawn>());
                    }
                    pawnsBeingGenerated[i].PawnsGeneratedInTheMeantime.Add(pawn);
                }
                return(pawn);
            }
            finally
            {
                pawnsBeingGenerated.RemoveLast();
            }
        }
Example #13
0
        public static IEnumerable <Thing> MakeRecipeProducts(RecipeDef recipeDef, Pawn worker, List <Thing> ingredients, Thing dominantIngredient)
        {
            float efficiency = (float)((recipeDef.efficiencyStat != null) ? worker.GetStatValue(recipeDef.efficiencyStat, true) : 1.0);

            if (recipeDef.products != null)
            {
                int k = 0;
                if (k < recipeDef.products.Count)
                {
                    ThingCountClass prod     = recipeDef.products[k];
                    ThingDef        stuffDef = (!prod.thingDef.MadeFromStuff) ? null : dominantIngredient.def;
                    Thing           product3 = ThingMaker.MakeThing(prod.thingDef, stuffDef);
                    product3.stackCount = Mathf.CeilToInt((float)prod.count * efficiency);
                    if (dominantIngredient != null)
                    {
                        product3.SetColor(dominantIngredient.DrawColor, false);
                    }
                    CompIngredients ingredientsComp = product3.TryGetComp <CompIngredients>();
                    if (ingredientsComp != null)
                    {
                        for (int l = 0; l < ingredients.Count; l++)
                        {
                            ingredientsComp.RegisterIngredient(ingredients[l].def);
                        }
                    }
                    CompFoodPoisonable foodPoisonable = product3.TryGetComp <CompFoodPoisonable>();
                    if (foodPoisonable != null)
                    {
                        float num  = worker.GetStatValue(StatDefOf.FoodPoisonChance, true);
                        Room  room = worker.GetRoom(RegionType.Set_Passable);
                        if (room != null)
                        {
                            num *= room.GetStat(RoomStatDefOf.FoodPoisonChanceFactor);
                        }
                        if (Rand.Value < num)
                        {
                            foodPoisonable.PoisonPercent = 1f;
                        }
                    }
                    yield return(GenRecipe.PostProcessProduct(product3, recipeDef, worker));

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            if (recipeDef.specialProducts != null)
            {
                for (int j = 0; j < recipeDef.specialProducts.Count; j++)
                {
                    for (int i = 0; i < ingredients.Count; i++)
                    {
                        Thing ing = ingredients[i];
                        switch (recipeDef.specialProducts[j])
                        {
                        case SpecialProductType.Butchery:
                            using (IEnumerator <Thing> enumerator2 = ing.ButcherProducts(worker, efficiency).GetEnumerator())
                            {
                                if (enumerator2.MoveNext())
                                {
                                    Thing product = enumerator2.Current;
                                    yield return(GenRecipe.PostProcessProduct(product, recipeDef, worker));

                                    /*Error: Unable to find new state assignment for yield return*/;
                                }
                            }
                            break;

                        case SpecialProductType.Smelted:
                            using (IEnumerator <Thing> enumerator = ing.SmeltProducts(efficiency).GetEnumerator())
                            {
                                if (enumerator.MoveNext())
                                {
                                    Thing product2 = enumerator.Current;
                                    yield return(GenRecipe.PostProcessProduct(product2, recipeDef, worker));

                                    /*Error: Unable to find new state assignment for yield return*/;
                                }
                            }
                            break;
                        }
                    }
                }
            }
            yield break;
IL_0473:
            /*Error near IL_0474: Unexpected return in MoveNext()*/;
        }
        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();
            }
        }
Example #15
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                bool flag = false;

                switch (num)
                {
                case 0u:
                    if (Rand.Value < this.skipChance)
                    {
                        return(false);
                    }
                    if (this.thingDef != null && this.countRange.max > 0)
                    {
                        thing            = ThingMaker.MakeThing(this.thingDef, null);
                        thing.stackCount = this.countRange.RandomInRange;
                        this.$current    = thing;
                        if (!this.$disposing)
                        {
                            this.$PC = 1;
                        }
                        return(true);
                    }
                    break;

                case 1u:
                    break;

                case 2u:
Block_7:
                    try
                    {
                        switch (num)
                        {
                        case 2u:
Block_12:
                            try
                            {
                                switch (num)
                                {
                                }
                                if (enumerator2.MoveNext())
                                {
                                    subThing      = enumerator2.Current;
                                    this.$current = subThing;
                                    if (!this.$disposing)
                                    {
                                        this.$PC = 2;
                                    }
                                    flag = true;
                                    return(true);
                                }
                            }
                            finally
                            {
                                if (!flag)
                                {
                                    if (enumerator2 != null)
                                    {
                                        enumerator2.Dispose();
                                    }
                                }
                            }
                            break;
                        }
                        if (enumerator.MoveNext())
                        {
                            opt         = enumerator.Current;
                            enumerator2 = opt.GenerateThings().GetEnumerator();
                            num         = 4294967293u;
                            goto Block_12;
                        }
                    }
                    finally
                    {
                        if (!flag)
                        {
                            ((IDisposable)enumerator).Dispose();
                        }
                    }
                    goto IL_1CB;

                case 3u:
Block_10:
                    try
                    {
                        switch (num)
                        {
                        }
                        if (enumerator3.MoveNext())
                        {
                            subThing2     = enumerator3.Current;
                            this.$current = subThing2;
                            if (!this.$disposing)
                            {
                                this.$PC = 3;
                            }
                            flag = true;
                            return(true);
                        }
                    }
                    finally
                    {
                        if (!flag)
                        {
                            if (enumerator3 != null)
                            {
                                enumerator3.Dispose();
                            }
                        }
                    }
                    goto IL_2A0;

                default:
                    return(false);
                }
                if (this.subOptionsTakeAll != null)
                {
                    enumerator = this.subOptionsTakeAll.GetEnumerator();
                    num        = 4294967293u;
                    goto Block_7;
                }
IL_1CB:
                if (this.subOptionsChooseOne != null)
                {
                    chosen      = this.subOptionsChooseOne.RandomElementByWeight((PawnInventoryOption o) => o.choiceChance);
                    enumerator3 = chosen.GenerateThings().GetEnumerator();
                    num         = 4294967293u;
                    goto Block_10;
                }
IL_2A0:
                this.$PC = -1;
                return(false);
            }