diff --git a/src/Lodur.Core/Actor.cs b/src/Lodur.Core/Actor.cs
index 9d04ca5..5e68554 100644
--- a/src/Lodur.Core/Actor.cs
+++ b/src/Lodur.Core/Actor.cs
@@ -43,15 +43,7 @@ namespace Lodur
NerveParameters? senses = null, int senseRegion = 0)
{
brain.Validate();
- if (!(drive.WillMendsAt > 0.0 && drive.WillMendsAt <= 1.0))
- {
- throw new ArgumentException("WillMendsAt must be in (0, 1].");
- }
-
- if (!(drive.WillCurve > 0.0 && double.IsFinite(drive.WillCurve)))
- {
- throw new ArgumentException("WillCurve must be finite and above 0.");
- }
+ drive.Validate();
_dt = tickSeconds;
_driveP = drive;
diff --git a/src/Lodur.Core/DriveState.cs b/src/Lodur.Core/DriveState.cs
index 8d0c985..5b59a66 100644
--- a/src/Lodur.Core/DriveState.cs
+++ b/src/Lodur.Core/DriveState.cs
@@ -36,6 +36,36 @@ namespace Lodur
/// holds most of its strength until the will is nearly gone; above 1 it fades as soon as the will drops.
///
public double WillCurve { get; init; } = 0.25;
+
+ /// Refuses a value the drive cannot run on, at construction rather than as a NaN several ticks in: every rate, trait and threshold is finite and not negative; WillMendsAt is in (0, 1]; WillCurve is above 0.
+ internal void Validate()
+ {
+ var rates = new[]
+ {
+ (PainRise, nameof(PainRise)), (PainDecay, nameof(PainDecay)), (StrainRecover, nameof(StrainRecover)),
+ (ResolveDrainPain, nameof(ResolveDrainPain)), (ResolveDrainStrain, nameof(ResolveDrainStrain)),
+ (ResolveRecovery, nameof(ResolveRecovery)), (ResolveRecoversBelowPain, nameof(ResolveRecoversBelowPain)),
+ (DrainTrait, nameof(DrainTrait)), (ArousalRise, nameof(ArousalRise)), (ArousalDecay, nameof(ArousalDecay)),
+ (ResolveDrainArousal, nameof(ResolveDrainArousal)), (ResolveRecoversBelowArousal, nameof(ResolveRecoversBelowArousal)),
+ };
+ foreach (var (value, name) in rates)
+ {
+ if (!(value >= 0.0 && double.IsFinite(value)))
+ {
+ throw new ArgumentException($"{name} must be finite and not negative.");
+ }
+ }
+
+ if (!(WillMendsAt > 0.0 && WillMendsAt <= 1.0))
+ {
+ throw new ArgumentException("WillMendsAt must be in (0, 1].");
+ }
+
+ if (!(WillCurve > 0.0 && double.IsFinite(WillCurve)))
+ {
+ throw new ArgumentException("WillCurve must be finite and above 0.");
+ }
+ }
}
///
diff --git a/tests/Lodur.Core.Tests/WillTests.cs b/tests/Lodur.Core.Tests/WillTests.cs
index 129bb93..33be0e7 100644
--- a/tests/Lodur.Core.Tests/WillTests.cs
+++ b/tests/Lodur.Core.Tests/WillTests.cs
@@ -341,4 +341,26 @@ public sealed class WillTests
[InlineData(double.PositiveInfinity)]
public void A_WillCurve_that_is_not_finite_and_above_zero_is_refused(double curve) =>
Assert.Throws(() => new PainBoxReplay(1, drive: new DriveParameters { WillCurve = curve }));
+
+ public static IEnumerable