RJW-Sexperience/Source/RJWSexperience/Utility.cs

39 lines
874 B
C#
Raw Normal View History

2022-06-12 04:32:17 +00:00
using RimWorld;
using System;
2021-07-27 14:28:31 +00:00
namespace RJWSexperience
{
2022-06-12 04:32:17 +00:00
public static class Utility
{
private static readonly Random random = new Random(Environment.TickCount);
2021-07-27 14:28:31 +00:00
2022-06-12 04:32:17 +00:00
public static float RandGaussianLike(float min, float max, int iterations = 3)
{
double res = 0;
for (int i = 0; i < iterations; i++)
{
res += random.NextDouble();
}
res /= iterations;
2021-07-27 14:28:31 +00:00
2022-06-12 04:32:17 +00:00
return ((float)res).Denormalization(min, max);
}
2021-07-27 14:28:31 +00:00
2022-06-12 04:32:17 +00:00
public static void SetTo(this Pawn_RecordsTracker records, RecordDef record, float value)
{
float recordval = records.GetValue(record);
records.AddTo(record, value - recordval);
}
2021-07-27 14:28:31 +00:00
2022-06-12 04:32:17 +00:00
public static float Normalization(this float num, float min, float max)
{
return (num - min) / (max - min);
}
2021-08-29 13:50:11 +00:00
2022-06-12 04:32:17 +00:00
public static float Denormalization(this float num, float min, float max)
{
return (num * (max - min)) + min;
}
}
2021-07-27 14:28:31 +00:00
}