Drive: the will breaks and mends as a recurring event; reflex and flinch read Will

Resolve keeps evolving through a break. A break fires on each tick resolve
reaches zero while the will is not broken (counted in Breaks); a broken will
mends when resolve climbs back to DriveParameters.WillMendsAt (default 0.25).
WillBroken is now "broken now"; DriveQuantity.Breaks is the one-way "has
broken". Will = Resolve x Attention capped by Consciousness, the two being
slots that read 1.0 until lodur-startle-attention and lodur-physiology.
Reflex suppression and the flinch gate read Will, not a WillBroken special
case. The pain-box fixtures gate their release on Breaks >= 1. The golden
table is untouched and still byte-identical.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-20 04:11:51 +01:00
commit 74883f85e5
8 changed files with 185 additions and 17 deletions

View file

@ -7,9 +7,9 @@ namespace Lodur
public enum TickEvents
{
None = 0,
/// <summary>A reflex leaked past the suppression the will still held. After the will breaks nothing is suppressed, so there is no flinch.</summary>
/// <summary>A reflex leaked past the suppression the will still held. With no will nothing is suppressed, so there is no flinch.</summary>
Flinch = 1,
/// <summary>Resolve reached zero this tick.</summary>
/// <summary>Resolve reached zero this tick: the will broke (again, if it had mended).</summary>
WillBroke = 2,
/// <summary>The Brain's chosen goal took over, its deliberate latency after the choice.</summary>
GoalChanged = 4,
@ -43,6 +43,11 @@ 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].");
}
_dt = tickSeconds;
_driveP = drive;
_brain = brain;
@ -100,8 +105,8 @@ namespace Lodur
ReadOnlySpan<Emitter> emitters = default)
{
var events = TickEvents.None;
// A flinch is the leak of a suppressed reflex; once the will has broken nothing is suppressed, so none is reported.
var holding = !_drive.WillBroken;
// A flinch is the leak of a suppressed reflex; with no will nothing is suppressed, so none is reported.
var holding = _drive.Will > 0.0;
_perception.Sense(regionX, regionY, regionZ, sources, emitters);

View file

@ -10,8 +10,10 @@ namespace Lodur
Strain,
Arousal,
Resolve,
/// <summary>1 once the will has broken, else 0.</summary>
/// <summary>1 while the will is broken now (it mends), else 0.</summary>
WillBroken,
/// <summary>How many times the will has broken: the one-way latch, for a goal that must hold after a mend.</summary>
Breaks,
}
public enum ConditionOp
@ -31,6 +33,7 @@ namespace Lodur
DriveQuantity.Strain => drive.Strain,
DriveQuantity.Arousal => drive.Arousal,
DriveQuantity.Resolve => drive.Resolve,
DriveQuantity.Breaks => (double)drive.Breaks,
_ => drive.WillBroken ? 1.0 : 0.0,
};
return Op == ConditionOp.AtLeast ? v >= Threshold : v < Threshold;

View file

@ -27,13 +27,17 @@ namespace Lodur
/// <summary>Resolve recovers only while arousal is below this, as well as pain being low.</summary>
public double ResolveRecoversBelowArousal { get; init; } = 0.1;
/// <summary>Once the will has broken it mends when resolve climbs back to this, in (0, 1]; it can then break again.</summary>
public double WillMendsAt { get; init; } = 0.25;
}
/// <summary>
/// Layer 3: per-character state that evolves every tick. Pain rises with afferent input, strain with the
/// reflex held down, arousal with sensory load; resolve drains under all three and recovers when pain and
/// arousal are both low. Resolve reaching zero breaks
/// the will, and a broken will never mends. Only the owning <see cref="Actor"/> steps it.
/// arousal are both low. Resolve reaching zero breaks the will (counted in <see cref="Breaks"/>); the broken will
/// mends when resolve climbs back to <see cref="DriveParameters.WillMendsAt"/> and can break again. Resolve keeps
/// evolving through a break. Only the owning <see cref="Actor"/> steps it.
/// </summary>
public struct DriveState
{
@ -43,27 +47,47 @@ namespace Lodur
/// <summary>Sensory load carried over time, 0..1; it rises under load and decays when quiet.</summary>
public double Arousal { get; private set; }
public double Resolve { get; private set; }
/// <summary>True from a break until the will mends: broken now, not "has ever broken" (see <see cref="Breaks"/>).</summary>
public bool WillBroken { get; private set; }
/// <summary>How many times the will has broken.</summary>
public int Breaks { get; private set; }
/// <summary>The fraction of resolve that attention lets through, 0..1. A slot: nothing lowers it yet (lodur-startle-attention fills it).</summary>
public double Attention => 1.0;
/// <summary>The ceiling on the will that wakefulness sets, 0..1. A slot: nothing lowers it yet (lodur-physiology fills it).</summary>
public double Consciousness => 1.0;
/// <summary>The will that is available to hold reflexes down and to power voluntary behaviour: resolve through attention, capped by consciousness.</summary>
public double Will => Math.Min(Resolve * Attention, Consciousness);
internal static DriveState Fresh => new DriveState { Resolve = 1.0 };
/// <summary>Steps one tick; returns true on the tick the will breaks. <paramref name="pull"/> is the active goal's: it scales resolve drain by (1 - pull).</summary>
/// <summary>Steps one tick; returns true on the tick the will breaks (each break, not only the first). <paramref name="pull"/> is the active goal's: it scales resolve drain by (1 - pull).</summary>
internal bool Step(DriveParameters p, double dt, double afferent, double strainLoad, double load, double pull)
{
Arousal = Math.Min(Math.Max(Arousal + dt * (p.ArousalRise * load * (1.0 - Arousal) - p.ArousalDecay * Arousal), 0.0), 1.0);
Pain = Math.Min(Math.Max(Pain + dt * (p.PainRise * afferent * (1.0 - Pain) - p.PainDecay * Pain), 0.0), 1.0);
Strain = Math.Max(0.0, Strain + dt * (strainLoad - p.StrainRecover * Strain));
if (WillBroken)
{
return false;
}
var drain = (p.ResolveDrainPain * Pain + p.ResolveDrainStrain * Strain + p.ResolveDrainArousal * Arousal) * (1.0 - pull) * p.DrainTrait;
var recovery = Pain < p.ResolveRecoversBelowPain && Arousal < p.ResolveRecoversBelowArousal ? p.ResolveRecovery * (1.0 - Resolve) : 0.0;
Resolve = Math.Min(Math.Max(Resolve + dt * (recovery - drain), 0.0), 1.0);
if (WillBroken)
{
if (Resolve >= p.WillMendsAt)
{
WillBroken = false;
}
return false;
}
if (Resolve <= 0.0)
{
WillBroken = true;
Breaks++;
return true;
}

View file

@ -38,7 +38,7 @@ namespace Lodur
/// <summary>Steps once; returns true on a flinch (leak over the threshold, outside the refractory window).</summary>
public bool Step(double afferent, in DriveState drive)
{
var suppression = drive.WillBroken ? 0.0 : _p.MaxSuppression * drive.Resolve;
var suppression = _p.MaxSuppression * drive.Will;
Leak = afferent * (1.0 - suppression);
StrainLoad = afferent * suppression;
var flinch = Leak > _p.FlinchLeakThreshold && _tick - _lastFlinch >= _refractory;