37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using Arch.Core;
|
||
using HSchool.Content;
|
||
|
||
namespace HSchool.Simulation;
|
||
|
||
/// <summary>
|
||
/// Drains needs by <see cref="NeedDef.DecayPerHour"/> × simulated hours. Core ships decay at zero
|
||
/// so this is a no-op until something exists that can refill them.
|
||
/// </summary>
|
||
public static class NeedDecay
|
||
{
|
||
private static readonly QueryDescription PeopleWithNeeds = new QueryDescription().WithAll<PersonNeeds>();
|
||
|
||
public static void Apply(World world, DefCatalog catalog, double gameMinutes)
|
||
{
|
||
if (gameMinutes <= 0 || !catalog.AnyNeedDecays)
|
||
{
|
||
return;
|
||
}
|
||
|
||
var hours = gameMinutes / 60d;
|
||
world.Query(in PeopleWithNeeds, (ref PersonNeeds needs) =>
|
||
{
|
||
foreach (var def in catalog.Needs.Values)
|
||
{
|
||
if (def.Abstract || !needs.Values.TryGetValue(def.DefName, out var current))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
var next = current - (float)(def.DecayPerHour * hours);
|
||
needs.Values[def.DefName] = Math.Clamp(next, def.Min, def.Max);
|
||
}
|
||
});
|
||
}
|
||
}
|