Files
h-school/src/HSchool.Simulation/NeedDecay.cs
T

37 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
});
}
}