private static float ExpectedAnimalCount(PawnKindDef k, BiomeDef b)
        {
            float num = b.CommonalityOfAnimal(k);
            float result;

            if (num == 0f)
            {
                result = 0f;
            }
            else
            {
                float num2 = DefDatabase <PawnKindDef> .AllDefs.Sum((PawnKindDef ki) => b.CommonalityOfAnimal(ki));

                float num3             = num / num2;
                float num4             = 10000f / b.animalDensity;
                float num5             = 62500f / num4;
                float totalCommonality = DefDatabase <PawnKindDef> .AllDefs.Sum((PawnKindDef ki) => b.CommonalityOfAnimal(ki));

                float num6 = DefDatabase <PawnKindDef> .AllDefs.Sum((PawnKindDef ki) => k.ecoSystemWeight *(b.CommonalityOfAnimal(ki) / totalCommonality));

                float num7 = num5 / num6;
                float num8 = num7 * num3;
                result = num8;
            }
            return(result);
        }
Ejemplo n.º 2
0
        private static string <BiomeAnimalsSpawnChances> m__13(PawnKindDef k, BiomeDef b)
        {
            float num = b.CommonalityOfAnimal(k);

            if (num == 0f)
            {
                return(string.Empty);
            }
            float f = num / DefDatabase <PawnKindDef> .AllDefs.Sum((PawnKindDef ki) => b.CommonalityOfAnimal(ki));

            return(f.ToStringPercent("F1"));
        }
        private static string <BiomeAnimalsSpawnChances> m__13(PawnKindDef k, BiomeDef b)
        {
            float  num = b.CommonalityOfAnimal(k);
            string result;

            if (num == 0f)
            {
                result = "";
            }
            else
            {
                float f = num / DefDatabase <PawnKindDef> .AllDefs.Sum((PawnKindDef ki) => b.CommonalityOfAnimal(ki));

                result = f.ToStringPercent("F1");
            }
            return(result);
        }
Ejemplo n.º 4
0
        private void generateSpecialities(string seed)
        {
            float chanceAnimal           = RimEconomy.SettingFloat["specialityChanceAnimal"].Value;
            float chancePlant            = RimEconomy.SettingFloat["specialityChancePlant"].Value;
            float chanceResourceRock     = RimEconomy.SettingFloat["specialityChanceResourceRock"].Value;
            bool  dontFilterSpeciality   = RimEconomy.SettingBool["dontFilterSpeciality"].Value;
            float maxCommonalityOfAnimal = RimEconomy.SettingFloat["maxCommonalityOfAnimal"].Value;
            float maxCommonalityOfPlant  = RimEconomy.SettingFloat["maxCommonalityOfPlant"].Value;

            if (seed != null)
            {
                Rand.Seed = GenText.StableStringHash(seed);
            }
            List <Tile> tiles = Find.WorldGrid.tiles;
            Dictionary <BiomeDef, IEnumerable <ThingDef> >    biomePlantCache  = new Dictionary <BiomeDef, IEnumerable <ThingDef> >();
            Dictionary <BiomeDef, IEnumerable <PawnKindDef> > biomeAnimalCache = new Dictionary <BiomeDef, IEnumerable <PawnKindDef> >();
            IEnumerable <ThingDef> resourceRocks = from d in DefDatabase <ThingDef> .AllDefs
                                                   where d.category == ThingCategory.Building && d.building != null && d.building.isResourceRock
                                                   select d;

            for (int i = 0; i <= Find.WorldGrid.TilesCount - 1; i++)
            {
                Tile tile = tiles[i];
                if (!tile.WaterCovered)
                {
                    BiomeDef    biome         = tile.biome;
                    PawnKindDef animalKindDef = null;
                    ThingDef    plantDef      = null;
                    ThingDef    resourceRock  = null;
                    if (Rand.Chance(chanceAnimal * biome.animalDensity))
                    {
                        IEnumerable <PawnKindDef> animals = null;
                        if (biomeAnimalCache.ContainsKey(biome))
                        {
                            animals = biomeAnimalCache[biome];
                        }
                        else
                        {
                            animals = biome.AllWildAnimals;
                            biomeAnimalCache[biome] = animals;
                            Log.Message("-----------deubg for animal----------------");
                            Log.Message("biome: " + biome);
                            foreach (PawnKindDef def in animals)
                            {
                                Log.Message("def: " + def.race + " commonality: " + biome.CommonalityOfAnimal(def) / def.wildSpawn_GroupSizeRange.Average);
                            }
                        }
                        animalKindDef = animals.RandomElementByWeight((PawnKindDef def) => {
                            if (def.race == DefDatabase <ThingDef> .GetNamed("Rat", true))
                            {
                                return(0);
                            }
                            if (def.wildSpawn_GroupSizeRange.Average > 0)
                            {
                                float commonality = biome.CommonalityOfAnimal(def) / def.wildSpawn_GroupSizeRange.Average;
                                if (!dontFilterSpeciality && commonality >= maxCommonalityOfAnimal)
                                {
                                    return(0);
                                }
                                return(commonality);
                            }
                            return(0);
                        });
                    }
                    if (Rand.Chance(chancePlant * biome.plantDensity))
                    {
                        IEnumerable <ThingDef> plants = null;
                        if (biomePlantCache.ContainsKey(biome))
                        {
                            plants = biomePlantCache[biome];
                        }
                        else
                        {
                            plants = from ThingDef def in biome.AllWildPlants
                                     where def.plant != null && (def.plant.harvestedThingDef != null || (def.plant.sowTags != null && def.plant.sowTags.Contains("Ground")))
                                     select def;
                            biomePlantCache[biome] = plants;
                            Log.Message("-----------deubg for plant----------------");
                            Log.Message("biome: " + biome);
                            foreach (ThingDef def in plants)
                            {
                                Log.Message("def: " + def + " commonality: " + biome.CommonalityOfPlant(def));
                            }
                        }
                        plantDef = plants.RandomElementByWeight((ThingDef def) => {
                            if (def == DefDatabase <ThingDef> .GetNamed("PlantGrass", true))
                            {
                                return(0);
                            }
                            float commonality = biome.CommonalityOfPlant(def);
                            if (!dontFilterSpeciality && commonality >= maxCommonalityOfPlant)
                            {
                                return(0);
                            }
                            return(commonality);
                        });
                    }
                    if (Rand.Chance(chanceResourceRock))
                    {
                        resourceRock = resourceRocks.RandomElementByWeight((ThingDef def) => def.building.mineableScatterCommonality);
                    }
                    if (animalKindDef != null || plantDef != null || resourceRock != null)
                    {
                        tileSpeciality[i] = new Speciality(i, animalKindDef, plantDef, resourceRock);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private ESItem[] GetLeatherApparel(BiomeDef _biome, string _ApparelDefName, bool _LogCalculation)
        {
            // Variables
            bool boolLogCalculation = _LogCalculation;

            PawnKindDef[] aAnimals = new PawnKindDef[0];
            aAnimals = aAnimals.Concat(_biome.AllWildAnimals).ToArray();
            PawnKindDef[] aAllAnimals       = (from k in DefDatabase <PawnKindDef> .AllDefs where (k.RaceProps.Animal) select k).ToArray();
            PawnKindDef[] aTameAnimals      = (from a in aAllAnimals where (a.race.race.wildness < .1f) select a).ToArray();
            PawnKindDef[] aNoLeatherAnimals = (from b in aAllAnimals where (b.race.race.leatherDef == null) select b).ToArray();

            if (aAnimals.Contains(PawnKindDef.Named("WildBoar")))
            {
                aTameAnimals = aTameAnimals.Where(x => x != PawnKindDef.Named("Pig")).ToArray();
            }

            aTameAnimals = aTameAnimals.Where(x => x != PawnKindDef.Named("YorkshireTerrier") && x != PawnKindDef.Named("Husky") &&
                                              x != PawnKindDef.Named("LabradorRetriever")).ToArray();
            aAnimals = aAnimals.Union(aTameAnimals).ToArray();
            aAnimals = aAnimals.Where(x => !aNoLeatherAnimals.Contains(x)).ToArray();
            aAnimals = aAnimals.OrderBy(pkd => pkd.defName).ToArray();
            ESItem[] aESI        = new ESItem[aAnimals.Length];
            string   strThingDef = _ApparelDefName;

            // Variables for logging
            string strAnimalCommonality       = "";
            string strAnimalLeather           = "";
            string strAnimalBodySize          = "";
            string strAnimalDanger            = "";
            string strAnimalLeatherComonality = "";
            string strAnimalLMVF     = "";
            string strCostPerLeather = "";
            string strFinal          = "";

            string[] aStrings = new string[0];

            // Start master loop for each animal in biome
            for (int i = 0; i < aAnimals.Count(); i++)
            {
                try
                {
                    // variables
                    int    intThingAmount = 1;
                    float  floBasePrice   = 0f;
                    string strStuff;
                    string strAnimalName        = aAnimals[i].defName;
                    float  floAnimalDPS         = 0f;
                    float  floAnimalCommonality = 0f;

                    // variables for tweeking
                    // Scale opens price gaps
                    float floHealthScale      = 1f;                // drives prices up
                    float floDangerScale      = 1f;                // drives prices up
                    float floCommonalityScale = 1f;                // drives prices down
                    float floBodySizeScale    = 1f;                // drives prices down
                    float floInsulationScale  = 6f;                // drives prices up

                    // Floor closes price gaps
                    float floHealthFloor      = .4f;
                    float floDangerFloor      = 20f;
                    float floCommonalityFloor = 1f;
                    float floBodySizeFloor    = 1f;
                    float floInsulationFloor  = 0f;

                    float floPredatorScale = 4f;
                    float floFarmScale     = 1.5f;
                    float floTotalScale    = .1f;

                    // Calc animal DPS
                    if (!aAnimals[i].race.Verbs.NullOrEmpty <VerbProperties>())
                    {
                        VerbProperties[] aVerbs = aAnimals[i].race.Verbs.ToArray();

                        for (int x = 0; x < aVerbs.Length; x++)
                        {
                            if ((float)aVerbs[x].meleeDamageBaseAmount > .001f)
                            {
                                floAnimalDPS += (float)aVerbs[x].meleeDamageBaseAmount / (aVerbs[x].defaultCooldownTime + aVerbs[x].warmupTime);
                            }
                        }

                        floAnimalDPS = floAnimalDPS / (float)aVerbs.Length;
                    }

                    // Calc animal danger with baseHealthScale scale and floor
                    float floAnimalDanger = floAnimalDPS * aAnimals[i].race.GetStatValueAbstract(StatDefOf.MoveSpeed) * (aAnimals[i].race.race.baseHealthScale * floHealthScale + floHealthFloor);

                    // if Boomrat or Boomalope, add more danger
                    if (aAnimals[i].defName == "Boomrat" || aAnimals[i].defName == "Boomalope")
                    {
                        floAnimalDanger += 50f;
                    }

                    // Add danger scale and floor
                    floAnimalDanger = floAnimalDanger * floDangerScale + floDangerFloor;

                    // Calc animal commonality, add animal commonality scale and floor, multiply for predators and farm types
                    if (aAnimals[i].race.race.predator == true)
                    {
                        floAnimalCommonality = _biome.CommonalityOfAnimal(aAnimals[i]) * floPredatorScale * floCommonalityScale * _biome.animalDensity;
                    }
                    else if (aAnimals[i].defName == "Chicken" || aAnimals[i].defName == "Pig" || aAnimals[i].defName == "WildBoar" || aAnimals[i].defName == "Cow" || aAnimals[i].defName == "Alpaca")
                    {
                        floAnimalCommonality = _biome.CommonalityOfAnimal(aAnimals[i]) * floFarmScale * floCommonalityScale * _biome.animalDensity;
                        //if (floAnimalCommonality < .1f)
                        //{
                        //	floAnimalCommonality = floCommonalityFloor * .5f;
                        //}
                    }
                    else
                    {
                        floAnimalCommonality = _biome.CommonalityOfAnimal(aAnimals[i]) * floCommonalityScale * _biome.animalDensity;
                    }
                    floAnimalCommonality += floCommonalityFloor;

                    // Calc animal leather commonality with baseBodySize scale and floor
                    float floAnimalLeatherCommonality = (floAnimalCommonality * (aAnimals[i].race.race.baseBodySize * floBodySizeScale + floBodySizeFloor)) / floAnimalDanger;

                    // Logging part 1
                    if (boolLogCalculation)
                    {
                        strAnimalCommonality       = string.Concat("Commonality of ", aAnimals[i].ToString(), " * Animal Density: ", floAnimalCommonality.ToString(), "\n");
                        strAnimalLeather           = string.Concat(aAnimals[i].race.race.leatherDef.ToString(), ", Insulation: ", aAnimals[i].race.race.leatherInsulation.ToString(), "\n");
                        strAnimalBodySize          = string.Concat("BodySize: ", aAnimals[i].race.race.baseBodySize.ToString(), "\n");
                        strAnimalDanger            = string.Concat("AnimalDPS * AnimalMoveSpeed * AnimalBaseHealthScale = Danger: ", floAnimalDanger.ToString(), "\n");
                        strAnimalLeatherComonality = string.Concat("Animal Commonality * BodySize / Danger = LeatherCommonality: ", floAnimalLeatherCommonality.ToString(), "\n");
                        strAnimalLMVF     = string.Concat("leatherMarketValueFactor: ", aAnimals[i].race.race.leatherMarketValueFactor.ToString(), "\n");
                        strCostPerLeather = string.Concat("leatherInsulation / LeatherCommonality * leatherMarketValueFactor = Cost per leather: ");
                    }

                    // Handle WildBoar because it uses Pig leather, add leatherInsulation scale and floor
                    if (strAnimalName == "WildBoar")
                    {
                        strAnimalName = "Pig";
                        floBasePrice  = ((aAnimals[i].race.race.leatherInsulation * floInsulationScale + floInsulationFloor) / floAnimalLeatherCommonality) * PawnKindDef.Named("Pig").race.race.leatherMarketValueFactor;
                    }
                    else
                    {
                        floBasePrice = ((aAnimals[i].race.race.leatherInsulation * floInsulationScale + floInsulationFloor) / floAnimalLeatherCommonality) * aAnimals[i].race.race.leatherMarketValueFactor;
                    }

                    // Add total scale
                    floBasePrice *= floTotalScale;

                    // Calc ThingDef string for Stuff, calc leather needed for apparel
                    strStuff = string.Concat(strAnimalName, "_Leather");
                    float floFinalCost = (float)ThingDef.Named(strThingDef).costStuffCount *floBasePrice;

                    // Populate ESItem list for return
                    aESI[i] = new ESItem(strThingDef, intThingAmount, floFinalCost, 1, strStuff);

                    // Logging part 2
                    if (boolLogCalculation)
                    {
                        strFinal = string.Concat(aAnimals[i].ToString(), " FINAL: ", floBasePrice.ToString(), "\n", strThingDef, ": ", floFinalCost.ToString());
                        aStrings = new string[] { strAnimalCommonality, strAnimalLeather, strAnimalBodySize, strAnimalDanger, strAnimalLeatherComonality, strAnimalLMVF, strCostPerLeather, strFinal };
                        Log.Message(string.Concat(aStrings));
                    }
                }
                catch
                {
                    aESI[i] = new ESItem("Apparel_Tuque", 1, 9001, 1, "Cloth");
                    Log.Message(string.Concat(aAnimals[i].defName, " FAILED ESApparel.GetLeatherApparel."));
                }
            }

            return(aESI);
        }
Ejemplo n.º 6
0
        private ESItem[] GetWoolApparel(BiomeDef _biome, string _ApparelDefName, bool _LogCalculation)
        {
            // Variables
            bool boolLogCalculation = _LogCalculation;

            PawnKindDef[] aBiomeAnimals = new PawnKindDef[0];
            aBiomeAnimals = aBiomeAnimals.Concat(_biome.AllWildAnimals).ToArray();
            string strThingDef = _ApparelDefName;

            PawnKindDef[] aAllAnimals              = (from k in DefDatabase <PawnKindDef> .AllDefs where (k.RaceProps.Animal) select k).ToArray();
            PawnKindDef[] aWoolAnimals             = (from a in aAllAnimals where a.race.HasComp(typeof(CompShearable)) select a).ToArray();
            PawnKindDef[] aTameAnimals             = (from a in aAllAnimals where (a.race.race.wildness < .1f) select a).ToArray();
            PawnKindDef[] aTameWoolAnimals         = aWoolAnimals.Intersect(aTameAnimals).ToArray();
            PawnKindDef[] aBiomeWoolAnimals        = aBiomeAnimals.Intersect(aWoolAnimals).ToArray();
            PawnKindDef[] aBiomeAndTameWoolAnimals = aTameWoolAnimals.Union(aBiomeWoolAnimals).ToArray();
            PawnKindDef[] aAnimals = aBiomeAndTameWoolAnimals;
            ESItem[]      aESI     = new ESItem[aAnimals.Length];

            // Logging for variables
            if (boolLogCalculation == true)
            {
                string[] aStr = new string[] { "All tame animals: \n" };
                foreach (PawnKindDef pkd in aTameAnimals)
                {
                    aStr = aStr.Concat(new string[] { pkd.defName, "\n" }).ToArray();
                }
                Log.Message(string.Concat(aStr));

                string[] aStr2 = new string[] { "All wool producing animals: \n" };
                foreach (PawnKindDef pkd in aWoolAnimals)
                {
                    aStr2 = aStr2.Concat(new string[] { pkd.defName, "\n" }).ToArray();
                }
                Log.Message(string.Concat(aStr2));

                string[] aStr3 = new string[] { "All tame animals that produce wool: \n" };
                foreach (PawnKindDef pkd in aTameWoolAnimals)
                {
                    aStr3 = aStr3.Concat(new string[] { pkd.defName, "\n" }).ToArray();
                }
                Log.Message(string.Concat(aStr3));

                string[] aStr4 = new string[] { "All animals that produce wool in this biome: \n" };
                foreach (PawnKindDef pkd in aBiomeWoolAnimals)
                {
                    aStr4 = aStr4.Concat(new string[] { pkd.defName, "\n" }).ToArray();
                }
                Log.Message(string.Concat(aStr4));

                string[] aStr5 = new string[] { "All Tame and Biome wool producing animals: \n" };
                foreach (PawnKindDef pkd in aAnimals)
                {
                    aStr5 = aStr5.Concat(new string[] { pkd.defName, "\n" }).ToArray();
                }
                Log.Message(string.Concat(aStr5));
            }

            // Variables for logging
            string strAnimalCommonality    = "";
            string strAnimalWool           = "";
            string strAnimalBodySize       = "";
            string strAnimalDanger         = "";
            string strAnimalwoolComonality = "";
            string strAnimalWMVF           = "";
            string strCostPerWool          = "";
            string strFinal = "";

            string[] aStrings = new string[0];

            // Start master loop for each wool producing animal in biome
            for (int i = 0; i < aAnimals.Count(); i++)
            {
                // variables
                int            intThingAmount = 1;
                float          floBasePrice   = 0f;
                string         strStuff;
                string         strAnimalName        = aAnimals[i].defName;
                float          floAnimalDPS         = 0f;
                float          floAnimalCommonality = 0f;
                string         strAnimalWoolDef     = aAnimals[i].race.GetCompProperties <CompProperties_Shearable>().woolDef.defName;
                StatModifier[] asmStatOffsets       = ThingDef.Named(strAnimalWoolDef).stuffProps.statOffsets.ToArray();
                StatModifier[] asmStatFactors       = ThingDef.Named(strAnimalWoolDef).stuffProps.statFactors.ToArray();
                (from a in aAllAnimals where a.race.HasComp(typeof(CompShearable)) select a).ToArray();

                // variables for tweeking
                // Scale opens price gaps
                float floHealthScale      = 1f;            // drives prices up
                float floDangerScale      = 1f;            // drives prices up
                float floCommonalityScale = 1f;            // drives prices down
                float floBodySizeScale    = 1f;            // drives prices down
                float floInsulationScale  = 6f;            // drives prices up

                // Floor closes price gaps
                float floHealthFloor      = .4f;
                float floDangerFloor      = 20f;
                float floCommonalityFloor = 1f;
                float floBodySizeFloor    = 1f;
                float floInsulationFloor  = 0f;

                float floPredatorScale = 4f;
                float floFarmScale     = 1.5f;
                float floTotalScale    = .05f;

                // Calc animal DPS
                if (!aAnimals[i].race.Verbs.NullOrEmpty <VerbProperties>())
                {
                    VerbProperties[] aVerbs = aAnimals[i].race.Verbs.ToArray();

                    for (int x = 0; x < aVerbs.Length; x++)
                    {
                        if ((float)aVerbs[x].meleeDamageBaseAmount > .001f)
                        {
                            floAnimalDPS += (float)aVerbs[x].meleeDamageBaseAmount / (aVerbs[x].defaultCooldownTime + aVerbs[x].warmupTime);
                        }
                    }

                    floAnimalDPS = floAnimalDPS / (float)aVerbs.Length;
                }

                // Calc animal danger with baseHealthScale scale and floor
                float floAnimalDanger = floAnimalDPS * aAnimals[i].race.GetStatValueAbstract(StatDefOf.MoveSpeed) * (aAnimals[i].race.race.baseHealthScale * floHealthScale + floHealthFloor);

                // Add danger scale and floor
                floAnimalDanger = floAnimalDanger * floDangerScale + floDangerFloor;

                // Calc animal commonality, multiply for predators and farm types
                if (aAnimals[i].race.race.predator == true)
                {
                    floAnimalCommonality = _biome.CommonalityOfAnimal(aAnimals[i]) * floPredatorScale * floCommonalityScale * _biome.animalDensity;
                }
                else if (aTameAnimals.Contains(aAnimals[i]))
                {
                    floAnimalCommonality = _biome.CommonalityOfAnimal(aAnimals[i]) * floFarmScale * floCommonalityScale * _biome.animalDensity;
                    floAnimalDanger     /= floFarmScale;
                }
                else
                {
                    floAnimalCommonality = _biome.CommonalityOfAnimal(aAnimals[i]) * floCommonalityScale * _biome.animalDensity;
                }

                // Add animal commonality scale and floor
                floAnimalCommonality += floCommonalityFloor;

                // Calc animal Wool commonality with baseBodySize scale and floor
                float floAnimalWoolCommonality = (floAnimalCommonality * ((aAnimals[i].race.race.baseBodySize * 3f) * floBodySizeScale + floBodySizeFloor)) / floAnimalDanger;

                // Calc total statOffsets
                float floStatOffsetsTotal = 0f;
                foreach (StatModifier sm in asmStatOffsets)
                {
                    floStatOffsetsTotal += sm.value;
                }

                // Calc total statFactors
                float floStatFactorsTotal = 0f;
                foreach (StatModifier sf in asmStatFactors)
                {
                    floStatFactorsTotal += (sf.value * .75f);
                }

                //Add woolInsulation scale and floor
                floBasePrice = ((floStatFactorsTotal * floInsulationScale + floInsulationFloor) + floStatOffsetsTotal) / floAnimalWoolCommonality;

                // Logging part 1
                if (boolLogCalculation)
                {
                    strAnimalCommonality    = string.Concat("Commonality of ", aAnimals[i].ToString(), " * Animal Density: ", floAnimalCommonality.ToString(), "\n");
                    strAnimalWool           = string.Concat(aAnimals[i].race.race.leatherDef.ToString(), ", statFactors: ", floStatFactorsTotal.ToString(), "\n");
                    strAnimalBodySize       = string.Concat("BodySize: ", aAnimals[i].race.race.baseBodySize.ToString(), "\n");
                    strAnimalDanger         = string.Concat("AnimalDPS * AnimalMoveSpeed * AnimalBaseHealthScale = Danger: ", floAnimalDanger.ToString(), "\n");
                    strAnimalwoolComonality = string.Concat("Animal Commonality * BodySize / Danger = woolCommonality: ", floAnimalWoolCommonality.ToString(), "\n");
                    strAnimalWMVF           = string.Concat("woolMarketValueFactor: ", aAnimals[i].race.race.leatherMarketValueFactor.ToString(), "\n");
                    strCostPerWool          = string.Concat("statFactors / woolCommonality = Cost per leather: ");
                }

                // Add total scale
                floBasePrice *= floTotalScale;

                // Calc ThingDef string for Stuff, calc wool needed for apparel
                strStuff = strAnimalWoolDef;
                float floFinalCost = (float)ThingDef.Named(strThingDef).costStuffCount *floBasePrice;

                // Populate ESItem list for return
                aESI[i] = new ESItem(strThingDef, intThingAmount, floFinalCost, 1, strStuff);

                // Logging part 2
                if (boolLogCalculation)
                {
                    strFinal = string.Concat(aAnimals[i].ToString(), " FINAL: ", floBasePrice.ToString(), "\n", strThingDef, ": ", floFinalCost.ToString());
                    aStrings = new string[] { strAnimalCommonality, strAnimalWool, strAnimalBodySize, strAnimalDanger, strAnimalwoolComonality, strAnimalWMVF, strCostPerWool, strFinal };
                    Log.Message(string.Concat(aStrings));
                }
            }

            return(aESI);
        }
Ejemplo n.º 7
0
        public void generateFresh(string seed)
        {
            float chanceAnimal;
            float chancePlant;
            float chanceResourceRock;

            chanceAnimal       = float.Parse(RimEconomy.SettingData["specialityChanceAnimal"].Value);
            chancePlant        = float.Parse(RimEconomy.SettingData["specialityChancePlant"].Value);
            chanceResourceRock = float.Parse(RimEconomy.SettingData["specialityChanceResourceRock"].Value);
            Rand.Seed          = GenText.StableStringHash(seed);
            List <Tile> tiles = Find.WorldGrid.tiles;
            Dictionary <BiomeDef, IEnumerable <ThingDef> > biomePlantCache = new Dictionary <BiomeDef, IEnumerable <ThingDef> >();
            IEnumerable <ThingDef> resourceRocks = from d in DefDatabase <ThingDef> .AllDefs
                                                   where d.category == ThingCategory.Building && d.building != null && d.building.isResourceRock
                                                   select d;

            for (int i = 0; i <= Find.WorldGrid.TilesCount - 1; i++)
            {
                Tile tile = tiles[i];
                if (!tile.WaterCovered)
                {
                    BiomeDef    biome         = tile.biome;
                    PawnKindDef animalKindDef = null;
                    ThingDef    plantDef      = null;
                    ThingDef    resourceRock  = null;
                    if (Rand.Chance(chanceAnimal * biome.animalDensity))
                    {
                        animalKindDef = biome.AllWildAnimals.RandomElementByWeight((PawnKindDef def) => biome.CommonalityOfAnimal(def) / def.wildSpawn_GroupSizeRange.Average);
                    }
                    if (Rand.Chance(chancePlant * biome.plantDensity))
                    {
                        IEnumerable <ThingDef> plants = null;
                        if (biomePlantCache.ContainsKey(biome))
                        {
                            plants = biomePlantCache[biome];
                        }
                        else
                        {
                            plants = from ThingDef def in biome.AllWildPlants
                                     where def.plant != null && (def.plant.harvestedThingDef != null || (def.plant.sowTags != null && def.plant.sowTags.Contains("Ground")))
                                     select def;
                            biomePlantCache[biome] = plants;
                        }
                        plantDef = plants.RandomElementByWeight((ThingDef def) => biome.CommonalityOfPlant(def));
                    }
                    if (Rand.Chance(chanceResourceRock))
                    {
                        resourceRock = resourceRocks.RandomElementByWeight((ThingDef def) => def.building.mineableScatterCommonality);
                    }
                    if (animalKindDef != null || plantDef != null || resourceRock != null)
                    {
                        specialities[i] = new Speciality(i, animalKindDef, plantDef, resourceRock);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public bool SpawnRandomWildAnimalAt(Map map, IntVec3 loc)
        {
            PawnKindDef pawnKindDef = (from a in biome1.AllWildAnimals
                                       where map.mapTemperature.SeasonAcceptableFor(a.race)
                                       select a).RandomElementByWeight((PawnKindDef def) => biome1.CommonalityOfAnimal(def) / def.wildGroupSize.Average);

            if (pawnKindDef == null)
            {
                Log.Error("No spawnable animals right now.");
                return(false);
            }
            int randomInRange = pawnKindDef.wildGroupSize.RandomInRange;
            int radius        = Mathf.CeilToInt(Mathf.Sqrt((float)pawnKindDef.wildGroupSize.max));

            for (int i = 0; i < randomInRange; i++)
            {
                IntVec3 loc2    = CellFinder.RandomClosewalkCellNear(loc, map, radius, null);
                Faction faction = FactionUtility.DefaultFactionFrom(pawnKindDef.defaultFactionType);

                //Pawn newThing = PawnGenerator.GeneratePawn(pawnKindDef, faction);

                Pawn newPawn = PawnGenerator.GeneratePawn(pawnKindDef, faction);
                GenSpawn.Spawn(newPawn, loc2, map);
                if (faction != null && faction != Faction.OfPlayer)
                {
                    Lord lord = null;

                    LordJob_DefendPoint lordJob = new LordJob_DefendPoint(newPawn.Position);
                    lord = LordMaker.MakeNewLord(faction, lordJob, newPawn.Map, null);

                    /* if (newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction).Any((Pawn p) => p != newPawn))
                     * {
                     *   Pawn p2 = (Pawn)GenClosest.ClosestThing_Global(newPawn.Position, newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction), 99999f, (Thing p) => p != newPawn && ((Pawn)p).GetLord() != null, null);
                     *   lord = p2.GetLord();
                     * }
                     * if (lord == null)
                     * {
                     *
                     * }*/
                    lord.AddPawn(newPawn);
                }


                //GenSpawn.Spawn(newThing, loc2, map);
            }
            return(true);
        }
Ejemplo n.º 9
0
        public bool SpawnRandomWildAnimalAt(Map map, IntVec3 loc)
        {
            PawnKindDef pawnKindDef = (from a in biome1.AllWildAnimals
                                       where map.mapTemperature.SeasonAcceptableFor(a.race)
                                       select a).RandomElementByWeight((PawnKindDef def) => biome1.CommonalityOfAnimal(def) / def.wildGroupSize.Average);

            if (pawnKindDef == null)
            {
                //Log.Error("No spawnable animals right now.");
                return(false);
            }
            int randomInRange = pawnKindDef.wildGroupSize.RandomInRange;
            int radius        = Mathf.CeilToInt(Mathf.Sqrt((float)pawnKindDef.wildGroupSize.max));

            for (int i = 0; i < randomInRange; i++)
            {
                IntVec3 loc2     = CellFinder.RandomClosewalkCellNear(loc, map, radius, null);
                Pawn    newThing = PawnGenerator.GeneratePawn(pawnKindDef, null);
                GenSpawn.Spawn(newThing, loc2, map);
            }
            return(true);
        }