private static float GestationDaysEach(ThingDef d) { if (d.HasComp(typeof(CompEggLayer))) { CompProperties_EggLayer compProperties = d.GetCompProperties <CompProperties_EggLayer>(); return(compProperties.eggLayIntervalDays / compProperties.eggCountRange.Average); } return(d.race.gestationPeriodDays / ((d.race.litterSizeCurve != null) ? Rand.ByCurveAverage(d.race.litterSizeCurve) : 1f)); }
public static void RandByCurveTests() { DebugHistogram debugHistogram = new DebugHistogram(Enumerable.Range(0, 30).Select((Func <int, float>)((int x) => x)).ToArray()); SimpleCurve curve = new SimpleCurve { new CurvePoint(0f, 0f), new CurvePoint(10f, 1f), new CurvePoint(15f, 2f), new CurvePoint(20f, 2f), new CurvePoint(21f, 0.5f), new CurvePoint(30f, 0f) }; float num = 0f; for (int i = 0; i < 1000000; i++) { float num2 = Rand.ByCurve(curve); num += num2; debugHistogram.Add(num2); } debugHistogram.Display(); Log.Message($"Average {num / 1000000f}, calculated as {Rand.ByCurveAverage(curve)}"); }
public static void RandByCurveTests() { DebugHistogram debugHistogram = new DebugHistogram((from x in Enumerable.Range(0, 30) select(float) x).ToArray()); SimpleCurve simpleCurve = new SimpleCurve(); simpleCurve.Add(new CurvePoint(0f, 0f)); simpleCurve.Add(new CurvePoint(10f, 1f)); simpleCurve.Add(new CurvePoint(15f, 2f)); simpleCurve.Add(new CurvePoint(20f, 2f)); simpleCurve.Add(new CurvePoint(21f, 0.5f)); simpleCurve.Add(new CurvePoint(30f, 0f)); SimpleCurve curve = simpleCurve; float num = 0f; for (int i = 0; i < 1000000; i++) { float num2 = Rand.ByCurve(curve); num += num2; debugHistogram.Add(num2); } debugHistogram.Display(); Log.Message($"Average {num / 1000000f}, calculated as {Rand.ByCurveAverage(curve)}"); }
public static void RandByCurveTests() { DebugHistogram debugHistogram = new DebugHistogram((from x in Enumerable.Range(0, 30) select(float) x).ToArray <float>()); SimpleCurve curve = new SimpleCurve { { new CurvePoint(0f, 0f), true }, { new CurvePoint(10f, 1f), true }, { new CurvePoint(15f, 2f), true }, { new CurvePoint(20f, 2f), true }, { new CurvePoint(21f, 0.5f), true }, { new CurvePoint(30f, 0f), true } }; float num = 0f; for (int i = 0; i < 1000000; i++) { float num2 = Rand.ByCurve(curve); num += num2; debugHistogram.Add(num2); } debugHistogram.Display(); Log.Message(string.Format("Average {0}, calculated as {1}", num / 1000000f, Rand.ByCurveAverage(curve)), false); }
public static void AnimalBreeding() { DebugTables.MakeTablesDialog((from d in DefDatabase <ThingDef> .AllDefs where d.category == ThingCategory.Pawn && d.race.IsFlesh select d).OrderByDescending(GestationDaysEach), new TableDataGetter <ThingDef>(string.Empty, (ThingDef d) => d.defName), new TableDataGetter <ThingDef>("gestDaysEach", (ThingDef d) => GestationDaysEach(d).ToString("F2")), new TableDataGetter <ThingDef>("avgOffspring", (ThingDef d) => (!d.HasComp(typeof(CompEggLayer))) ? ((d.race.litterSizeCurve == null) ? 1f : Rand.ByCurveAverage(d.race.litterSizeCurve)).ToString("F2") : d.GetCompProperties <CompProperties_EggLayer>().eggCountRange.Average.ToString("F2")), new TableDataGetter <ThingDef>("gestDaysRaw", (ThingDef d) => (!d.HasComp(typeof(CompEggLayer))) ? d.race.gestationPeriodDays.ToString("F1") : d.GetCompProperties <CompProperties_EggLayer>().eggLayIntervalDays.ToString("F1")), new TableDataGetter <ThingDef>("growth per 30d", delegate(ThingDef d) { float f2 = 1f + (d.HasComp(typeof(CompEggLayer)) ? d.GetCompProperties <CompProperties_EggLayer>().eggCountRange.Average : ((d.race.litterSizeCurve == null) ? 1f : Rand.ByCurveAverage(d.race.litterSizeCurve))); float num3 = d.race.lifeStageAges[d.race.lifeStageAges.Count - 1].minAge * 60f; float num4 = num3 + ((!d.HasComp(typeof(CompEggLayer))) ? d.race.gestationPeriodDays : d.GetCompProperties <CompProperties_EggLayer>().eggLayIntervalDays); float p2 = 30f / num4; return(Mathf.Pow(f2, p2).ToString("F2")); }), new TableDataGetter <ThingDef>("growth per 60d", delegate(ThingDef d) { float f = 1f + (d.HasComp(typeof(CompEggLayer)) ? d.GetCompProperties <CompProperties_EggLayer>().eggCountRange.Average : ((d.race.litterSizeCurve == null) ? 1f : Rand.ByCurveAverage(d.race.litterSizeCurve))); float num = d.race.lifeStageAges[d.race.lifeStageAges.Count - 1].minAge * 60f; float num2 = num + ((!d.HasComp(typeof(CompEggLayer))) ? d.race.gestationPeriodDays : d.GetCompProperties <CompProperties_EggLayer>().eggLayIntervalDays); float p = 60f / num2; return(Mathf.Pow(f, p).ToString("F2")); })); }
public static void AnimalBreeding() { IEnumerable <ThingDef> arg_14B_0 = (from d in DefDatabase <ThingDef> .AllDefs where d.category == ThingCategory.Pawn && d.race.IsFlesh select d).OrderByDescending(new Func <ThingDef, float>(DebugOutputsEconomy.GestationDaysEach)); TableDataGetter <ThingDef>[] expr_4F = new TableDataGetter <ThingDef> [6]; expr_4F[0] = new TableDataGetter <ThingDef>(string.Empty, (ThingDef d) => d.defName); expr_4F[1] = new TableDataGetter <ThingDef>("gestDaysEach", (ThingDef d) => DebugOutputsEconomy.GestationDaysEach(d).ToString("F2")); expr_4F[2] = new TableDataGetter <ThingDef>("avgOffspring", (ThingDef d) => (!d.HasComp(typeof(CompEggLayer))) ? ((d.race.litterSizeCurve == null) ? 1f : Rand.ByCurveAverage(d.race.litterSizeCurve)).ToString("F2") : d.GetCompProperties <CompProperties_EggLayer>().eggCountRange.Average.ToString("F2")); expr_4F[3] = new TableDataGetter <ThingDef>("gestDaysRaw", (ThingDef d) => (!d.HasComp(typeof(CompEggLayer))) ? d.race.gestationPeriodDays.ToString("F1") : d.GetCompProperties <CompProperties_EggLayer>().eggLayIntervalDays.ToString("F1")); expr_4F[4] = new TableDataGetter <ThingDef>("growth per 30d", delegate(ThingDef d) { float f = 1f + ((!d.HasComp(typeof(CompEggLayer))) ? ((d.race.litterSizeCurve == null) ? 1f : Rand.ByCurveAverage(d.race.litterSizeCurve)) : d.GetCompProperties <CompProperties_EggLayer>().eggCountRange.Average); float num = d.race.lifeStageAges[d.race.lifeStageAges.Count - 1].minAge * 60f; float num2 = num + ((!d.HasComp(typeof(CompEggLayer))) ? d.race.gestationPeriodDays : d.GetCompProperties <CompProperties_EggLayer>().eggLayIntervalDays); float p = 30f / num2; return(Mathf.Pow(f, p).ToString("F2")); }); expr_4F[5] = new TableDataGetter <ThingDef>("growth per 60d", delegate(ThingDef d) { float f = 1f + ((!d.HasComp(typeof(CompEggLayer))) ? ((d.race.litterSizeCurve == null) ? 1f : Rand.ByCurveAverage(d.race.litterSizeCurve)) : d.GetCompProperties <CompProperties_EggLayer>().eggCountRange.Average); float num = d.race.lifeStageAges[d.race.lifeStageAges.Count - 1].minAge * 60f; float num2 = num + ((!d.HasComp(typeof(CompEggLayer))) ? d.race.gestationPeriodDays : d.GetCompProperties <CompProperties_EggLayer>().eggLayIntervalDays); float p = 60f / num2; return(Mathf.Pow(f, p).ToString("F2")); }); DebugTables.MakeTablesDialog <ThingDef>(arg_14B_0, expr_4F); }