diff --git a/docs/bds-mvp-map.md b/docs/bds-mvp-map.md
index 9537064..6bacd4d 100644
--- a/docs/bds-mvp-map.md
+++ b/docs/bds-mvp-map.md
@@ -213,7 +213,7 @@ follow-up `scenario-session-unify`).
| Held object (grip) | (actor, hand side) → object stable id | grip begins on behaviour or level content → weld joint with threshold = grip strength → released by behaviour, reflex, unconsciousness or overload | Lodur grip state; Ymir weld executes | level may author "starts holding X" (content) |
| Level / arena | content id | authored with player tools, saved, loaded by replaying commands | BDS | CultCache |
| Contact / hit / overload / removal fact | (step, ordinal) | one step | Ymir | no |
-| Attention | (actor) scalar | 1.0, and nothing writes it yet but the test seam `Actor.SetWillSlots`; startle will drop it, recovering in under a second | Lodur drive | no |
+| Attention | (actor) scalar | 1.0, and nothing writes it yet but the test seam `Actor.SetAttention`; startle will drop it, recovering in under a second | Lodur drive | no |
## Questions for the operator and Deru (one batch; admitted as `question`s)
diff --git a/docs/lodur-target.md b/docs/lodur-target.md
index 24437af..f8c340c 100644
--- a/docs/lodur-target.md
+++ b/docs/lodur-target.md
@@ -90,22 +90,26 @@ Signal flows one way per tick, in this order; each layer has one owner. Layers 1
policy) behind the same interface. (`motion-pipeline:ruling:euphoria-body-layer-order`.)
`Actor` runs layers 1-4 for one character in that order once per physics step, from caller-owned inputs into
-caller-owned outputs, and reports its events (flinch, will broke, goal changed) as flags.
+caller-owned outputs, and reports its events (flinch, will broke, goal changed, died) as flags.
### Who writes what, per tick
-One order inside `Actor.Tick`: Perception senses (with the sensory gain in force) → each reflex steps on its
+One order inside `Actor.Tick`: the Physiology steps and writes Consciousness (an actor with a physiology; a dead one
+goes limp and ends the tick) → Perception senses (with the sensory gain in force) → each reflex steps on its
afferent (gain from the previous tick's drive) → the drive steps (pain, strain, arousal, resolve, the break and
the mend; the goal's effort is paid here) → the Brain decides (a decision is pending for the deliberate latency)
and a due decision commits (entry resolve is set) → the entry ramp assigns gain and arousal → the goal's
-behaviour writes strengths and targets at the will's weight. The tick that commits a goal already writes under it.
+behaviour writes strengths and targets at the will's weight, and the strengths are scaled by the motor ceiling. The tick that
+commits a goal already writes under it.
| Owner | Inputs | Outputs | Derived state | Forbidden writers |
|---|---|---|---|---|
| `Perception` | region points, the game's stimulus sources and emitters, the sensory gain passed in | per-region stimulus and afferent, per-channel stimulus and afferent, `Load`, the percept slots | sensitisation, the conduction rings, percept salience and slot occupancy; the channel afferents are gated, the stimuli are not | the drive or a goal writing an afferent; the game setting `PhantomIdBit` (`Sense` refuses it); the Brain or a session writing a percept; a gain outside [0, 1] (`Sense` refuses it, NaN and infinity included); gating a region (nociceptive) afferent |
| Reflex (`WithdrawalReflex`) | its region's afferent and the drive's `Will` (the pull acts through resolve's drain, not here) | leak, strain load, flinch | none beyond its latency ring | the Brain or the behaviour setting a reflex gain |
| Drive (`DriveState`) | afferent sum, strain load, `Load`, the goal's pull and effort | pain, strain, arousal, resolve, `Breaks`, `Will` (= min(resolve x attention, consciousness)), the break and mend events | `Will` is derived and never stored; the break recurs (it mends at `WillMendsAt`) | the Brain, a session or the body writing resolve, arousal or `Will`; the one sanctioned jumps are `Enter` (a goal's entry resolve) and the Actor's entry ramp (arousal) |
-| Attention, Consciousness slots | nothing yet: both read 1 (startle and physiology are the writers to come) | the two factors of `Will` | none | anything but the startle reflex (`lodur-startle-attention`) and physiology; the Actor's test seam `SetWillSlots` is internal |
+| Attention slot | nothing yet: reads 1 (startle is the writer to come) | a factor of `Will` | none | anything but the startle reflex (`lodur-startle-attention`); the Actor's test seam `SetAttention` is internal |
+| Consciousness slot | `Physiology.Consciousness`, written by the Actor each tick; 1 for an actor with no physiology | the cap of `Will` | derived from the physiology each tick | anything but the Actor reading its Physiology; no test seam: tests lower it through a Physiology |
+| `Physiology` | its `BodyPlan` and `PhysiologyPlan` (tissue stacks by part label and side, afflictions with data effects, blood) at construction; `Afflict` (the one entry for harm); `Step(dt)` from the Actor; the slow scale at construction | capacities (`Consciousness`, `BloodPumping`), `Bleed` per part, `BloodVolume` and `BloodLoss`, `MotorCeiling` per joint, `Integrity` per tissue, `Dead`, `Cause`, `Refused` | integrity (from Injures afflictions: part HP is never stored), capacities, bleed and the ceiling, recomputed each step; death is judged once at the end of a step (vital tissue, blood loss, consciousness: `lodur:ruling:bds-death`) and is permanent | anything else writing tissue, blood or the slot; a game writing integrity, volume or severity (harm enters through `Afflict`); an effect writing state; an affliction killing by its own severity; tissue, organ or affliction labels outside content (`PhysiologyPlans`) |
| Brain (`Brain`, `GoalSpec`) | the drive state it reads through conditions | the wanted goal; each goal's pull, priority, dwell, entry effects (`EntryResolve`, `EntryArousal`, `SensoryGain`, `EntrySeconds`), `Effort`, `InvoluntarySeconds` and behaviour | none: it is data, copied at build and read back read-only | a flip rule anywhere else (`lodur:ruling:npc-brain-authors-goals`) |
| `Actor` | all of the above, one tick | the committed goal; `DriveState.SensoryGain`; arousal during a goal's `EntrySeconds`; the events | the pending decision and its tick, the dwell, the ramp's start values, the onset in whole ticks | a consumer setting the goal or the gain from outside |
| Behaviour (`PoseBehaviour`) | the weight (the will's `Will^WillCurve` once the goal's involuntary onset is over, else 1), the leak, strain, time | strengths and targets into caller arrays: `HoldStrength x min(1, weight + leak x FlinchGain)` | none | writing a joint or a force (`body-one-interface`); any strength not under the will mix |
diff --git a/src/Lodur.Core/Actor.cs b/src/Lodur.Core/Actor.cs
index 1727a51..57ff0f9 100644
--- a/src/Lodur.Core/Actor.cs
+++ b/src/Lodur.Core/Actor.cs
@@ -13,6 +13,8 @@ namespace Lodur
WillBroke = 2,
/// The Brain's chosen goal took over, its deliberate latency after the choice.
GoalChanged = 4,
+ /// The physiology died this tick (reported once, on the tick it died).
+ Died = 8,
}
///
@@ -32,6 +34,8 @@ namespace Lodur
private readonly long[] _entryTicks;
private readonly Perception _perception;
private readonly WithdrawalReflex[] _reflexes;
+ private readonly Physiology? _physiology;
+ private bool _diedReported;
private DriveState _drive = DriveState.Fresh;
private long _tick;
private int _goal;
@@ -46,10 +50,16 @@ namespace Lodur
public Actor(
double tickSeconds, int regionCount,
NerveParameters nerve, WithdrawalParameters withdrawal, DriveParameters drive, Brain brain,
- NerveParameters? senses = null, int senseRegion = 0, PerceptParameters? percepts = null)
+ NerveParameters? senses = null, int senseRegion = 0, PerceptParameters? percepts = null, Physiology? physiology = null)
{
brain.Validate();
drive.Validate();
+ if (physiology != null && !physiology.TryBind())
+ {
+ throw new ArgumentException("this physiology is already bound to an actor; one actor steps one physiology.");
+ }
+
+ _physiology = physiology;
_dt = tickSeconds;
_driveP = drive;
@@ -97,11 +107,13 @@ namespace Lodur
/// A snapshot of the drive; nothing but writes it.
public DriveState Drive => _drive;
- /// Sets the drive's Attention and Consciousness slots; a seam for the tests until lodur-startle-attention and lodur-physiology drive them.
- internal void SetWillSlots(double attention, double consciousness)
+ /// The physiology this actor steps and reads, null for an actor with none.
+ public Physiology? Physiology => _physiology;
+
+ /// Sets the drive's Attention slot; a seam for the tests until lodur-startle-attention writes it.
+ internal void SetAttention(double attention)
{
_drive.Attention = attention;
- _drive.Consciousness = consciousness;
}
public Brain Brain => _brain;
@@ -139,6 +151,31 @@ namespace Lodur
ReadOnlySpan emitters = default)
{
var events = TickEvents.None;
+ if (_physiology != null)
+ {
+ if (strengths.Length != _physiology.JointCount)
+ {
+ throw new ArgumentException("strengths must have one entry per joint of the physiology's body.");
+ }
+
+ // The physiology steps first, on the drive as the last tick left it, and its consciousness is the slot's only writer.
+ if (!_physiology.Dead)
+ {
+ _physiology.Step(_dt);
+ _drive.Consciousness = _physiology.Consciousness;
+ }
+
+ if (_physiology.Dead)
+ {
+ // Limp and permanent: the drive, goal and perception never change again; targets are left as they were.
+ strengths.Clear();
+ _tick++;
+ if (_diedReported) return events;
+ _diedReported = true;
+ return TickEvents.Died;
+ }
+ }
+
// 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;
@@ -213,6 +250,15 @@ namespace Lodur
var secondsInGoal = (_tick - _goalSince) * _dt;
var weight = _tick - _goalSince >= _onset[_goal] ? Math.Pow(_drive.Will, _driveP.WillCurve) : 1.0;
_brain.Goals[_goal].Behaviour.Write(weight, leak, _drive.Strain, _tick * _dt, secondsInGoal, strengths, targets);
+ if (_physiology != null)
+ {
+ // The only scaling of strength: each muscle (plan joint m) is held to its ceiling.
+ for (var m = 0; m < strengths.Length; m++)
+ {
+ strengths[m] *= (float)_physiology.MotorCeiling(m);
+ }
+ }
+
_tick++;
return events;
}
diff --git a/src/Lodur.Core/DriveState.cs b/src/Lodur.Core/DriveState.cs
index 0fe8cfe..54525ef 100644
--- a/src/Lodur.Core/DriveState.cs
+++ b/src/Lodur.Core/DriveState.cs
@@ -93,7 +93,7 @@ namespace Lodur
/// The fraction of resolve that attention lets through, 0..1. A slot, 1 until lodur-startle-attention fills it.
public double Attention { get; internal set; }
- /// The ceiling on the will that wakefulness sets, 0..1. A slot, 1 until lodur-physiology fills it.
+ /// The ceiling on the will that wakefulness sets, 0..1; written each tick by the Actor from its (the only writer), 1 for an Actor with no physiology.
public double Consciousness { get; internal set; }
/// The will that is available to hold reflexes down and to power voluntary behaviour: resolve through attention, capped by consciousness.
diff --git a/src/Lodur.Core/Lodur.Core.csproj b/src/Lodur.Core/Lodur.Core.csproj
index b39e30e..14fca96 100644
--- a/src/Lodur.Core/Lodur.Core.csproj
+++ b/src/Lodur.Core/Lodur.Core.csproj
@@ -7,7 +7,7 @@
Lodur
-
+
diff --git a/tests/Lodur.Core.Tests/ActorPhysiologyTests.cs b/tests/Lodur.Core.Tests/ActorPhysiologyTests.cs
new file mode 100644
index 0000000..28fc693
--- /dev/null
+++ b/tests/Lodur.Core.Tests/ActorPhysiologyTests.cs
@@ -0,0 +1,176 @@
+using Lodur;
+using static Lodur.Core.Tests.PhysioFixtures;
+
+namespace Lodur.Core.Tests;
+
+/// The Actor steps its Physiology first, writes the Consciousness slot from it, scales strengths by the motor ceiling, and goes limp when it dies.
+public sealed class ActorPhysiologyTests
+{
+ private static readonly float[] NoPoint = { 0f };
+
+ private static Brain HoldBrain() => new()
+ {
+ Goals = new[] { new GoalSpec { Id = "g", Behaviour = new PoseBehaviour { Keys = new[] { PainBoxBrain.Hold }, FlinchPose = PainBoxBrain.Withdraw, Hold = new HoldParameters { HoldStrength = 0.7f } } } },
+ };
+
+ private static Actor Make(Physiology? physiology, DriveParameters? drive = null) =>
+ new(0.01, 1, new NerveParameters(), new WithdrawalParameters(), drive ?? new DriveParameters(), HoldBrain(), physiology: physiology);
+
+ private static TickEvents Tick(Actor a, double intensity, float[] strengths, Quat[] targets)
+ {
+ var box = new[] { new BoxStimulus(0f, 0f, 0f, 1f, 1f, 1f) { Intensity = intensity } };
+ return a.Tick(NoPoint, NoPoint, NoPoint, box, strengths, targets);
+ }
+
+ [Fact]
+ public void The_slot_is_the_physiologys_consciousness_every_tick_and_strengths_are_held_to_each_joints_ceiling()
+ {
+ var p = Make3();
+ Assert.True(p.Afflict(Af("Lesion"), 0, BrainLayer, 4)); // consciousness 0.6
+ Assert.True(p.Afflict(Af("MotorHalf"), 1, 0, 1)); // joint 0 at half
+ var a = Make(p, new DriveParameters { WillCurve = 0.5 });
+ var s = new float[2];
+ var q = new Quat[2];
+ for (var i = 0; i < 50; i++)
+ {
+ Tick(a, 0.0, s, q);
+ Assert.Equal(p.Consciousness, a.Drive.Consciousness);
+ Assert.Equal(0.6, p.Consciousness, 12);
+ var raw = 0.7f * (float)Math.Sqrt(a.Drive.Will);
+ Assert.Equal(raw * (float)p.MotorCeiling(0), s[0]);
+ Assert.Equal(raw * (float)p.MotorCeiling(1), s[1]);
+ Assert.Equal(0.3, p.MotorCeiling(0), 12);
+ Assert.Equal(0.6, p.MotorCeiling(1), 12);
+ }
+ }
+
+ private static Physiology Make3() => PhysioFixtures.Make();
+
+ [Fact]
+ public void An_actor_with_no_physiology_keeps_the_slot_at_one_and_scales_nothing()
+ {
+ var a = Make(null);
+ var s = new float[2];
+ var q = new Quat[2];
+ for (var i = 0; i < 20; i++) Tick(a, 0.0, s, q);
+ Assert.Equal(1.0, a.Drive.Consciousness);
+ Assert.Equal(0.7f, s[0]);
+ Assert.Null(a.Physiology);
+ }
+
+ [Fact]
+ public void A_physiology_bound_to_one_actor_is_refused_by_a_second_and_strengths_of_the_wrong_length_throw()
+ {
+ var p = Make3();
+ var a = Make(p);
+ Assert.Same(p, a.Physiology);
+ Assert.Throws(() => Make(p));
+
+ var q = new Quat[2];
+ Assert.Throws(() => Tick(a, 0.0, new float[1], q));
+ Assert.Throws(() => Tick(a, 0.0, new float[3], q));
+ Assert.Equal(0, a.TickCount); // a refused call changes nothing
+ }
+
+ [Fact]
+ public void Death_is_reported_once_and_is_limp_and_the_actor_never_changes_again()
+ {
+ var p = Make3();
+ var a = Make(p);
+ var s = new float[2];
+ var q = new Quat[2] { Quat.FromAxisAngle(1f, 0f, 0f, 0.5f), Quat.FromAxisAngle(0f, 1f, 0f, 0.5f) };
+ for (var i = 0; i < 100; i++) Assert.Equal(TickEvents.None, Tick(a, 0.8, s, q) & TickEvents.Died);
+ Assert.True(s[0] > 0f && a.Drive.Pain > 0.0);
+ q[0] = Quat.FromAxisAngle(0f, 0f, 1f, 0.3f); // a value no behaviour writes: a dead actor leaves targets as they are
+ q[1] = Quat.FromAxisAngle(0f, 1f, 0f, 0.4f);
+ var sentinel = q.ToArray();
+
+ Assert.True(p.Afflict(Af("Lesion"), 0, Heart, 10));
+ var died = Tick(a, 0.8, s, q);
+ Assert.Equal(TickEvents.Died, died);
+ Assert.Equal(DeathCause.VitalTissue, p.Cause);
+ Assert.Equal(new float[2], s);
+ Assert.Equal(sentinel, q); // targets are left as they were
+ var frozen = a.Drive;
+ var goal = a.GoalIndex;
+ var ticks = a.TickCount;
+ for (var i = 0; i < 200; i++)
+ {
+ s[0] = s[1] = 0.5f;
+ Assert.Equal(TickEvents.None, Tick(a, 0.8, s, q));
+ Assert.Equal(new float[2], s);
+ Assert.Equal(frozen, a.Drive);
+ Assert.Equal(goal, a.GoalIndex);
+ }
+
+ Assert.Equal(ticks + 200, a.TickCount);
+ Assert.Equal(sentinel, q);
+ Assert.Equal(0.0, frozen.Consciousness);
+ Assert.Equal(0.0, frozen.Will);
+ }
+
+ [Fact]
+ public void A_physiology_that_died_before_it_was_bound_reports_the_death_on_the_first_tick()
+ {
+ var p = Make3();
+ Assert.True(p.Afflict(Af("Lesion"), 0, Heart, 10));
+ p.Step(0.01);
+ Assert.True(p.Dead);
+ var a = Make(p);
+ var s = new float[2] { 1f, 1f };
+ Assert.Equal(TickEvents.Died, Tick(a, 0.0, s, new Quat[2]));
+ Assert.Equal(new float[2], s);
+ Assert.Equal(TickEvents.None, Tick(a, 0.0, s, new Quat[2]));
+ }
+
+ [Fact]
+ public void A_healthy_physiology_changes_nothing_bit_for_bit()
+ {
+ foreach (var seed in new ulong[] { 1, 2, 3 })
+ {
+ var plain = new PainBoxReplay(seed);
+ var with = new PainBoxReplay(seed, physiology: Make3());
+ for (var i = 0; i < 4000; i++)
+ {
+ var on = i < 2500;
+ Assert.Equal(plain.Tick(on), with.Tick(on));
+ var a = plain.Actor.Drive;
+ var b = with.Actor.Drive;
+ Assert.Equal(BitConverter.DoubleToInt64Bits(a.Pain), BitConverter.DoubleToInt64Bits(b.Pain));
+ Assert.Equal(BitConverter.DoubleToInt64Bits(a.Strain), BitConverter.DoubleToInt64Bits(b.Strain));
+ Assert.Equal(BitConverter.DoubleToInt64Bits(a.Resolve), BitConverter.DoubleToInt64Bits(b.Resolve));
+ Assert.Equal(a.Consciousness, b.Consciousness);
+ Assert.Equal(plain.Actor.GoalIndex, with.Actor.GoalIndex);
+ Assert.Equal(plain.Strengths, with.Strengths);
+ }
+
+ Assert.True(plain.Actor.Drive.Breaks > 0 && plain.Actor.GoalIndex == 1, "the replay never reached the withdraw goal");
+ }
+ }
+
+ [Fact]
+ public void A_tick_with_a_physiology_and_eight_bleeding_afflictions_allocates_nothing()
+ {
+ var p = new Physiology(Body3(), Plan3(blood: new BloodDef(1000.0, 0.5, 1e-4)), 20);
+ for (var i = 0; i < 4; i++)
+ {
+ Assert.True(p.Afflict(Af("Bleeder"), 1 + i % 2, 0, 0.5 + 0.1 * i));
+ Assert.True(p.Afflict(Af("Clot"), 0, RootMuscle, 1.0));
+ }
+
+ var a = Make(p);
+ var s = new float[2];
+ var q = new Quat[2];
+ var box = new[] { new BoxStimulus(0f, 0f, 0f, 1f, 1f, 1f) { Intensity = 0.5 } };
+ for (var i = 0; i < 2000; i++) a.Tick(NoPoint, NoPoint, NoPoint, box, s, q); // warm the JIT and the first-use paths
+
+ var before = GC.GetAllocatedBytesForCurrentThread();
+ for (var i = 0; i < 10000; i++) a.Tick(NoPoint, NoPoint, NoPoint, box, s, q);
+ var after = GC.GetAllocatedBytesForCurrentThread();
+
+ Assert.Equal(0L, after - before);
+ Assert.False(p.Dead);
+ Assert.Equal(8, Live(p));
+ Assert.True(p.Bleed(0) > 0.0 && p.Bleed(1) > 0.0);
+ }
+}
diff --git a/tests/Lodur.Core.Tests/CalmSensesTests.cs b/tests/Lodur.Core.Tests/CalmSensesTests.cs
index 9fc359b..53a01fe 100644
--- a/tests/Lodur.Core.Tests/CalmSensesTests.cs
+++ b/tests/Lodur.Core.Tests/CalmSensesTests.cs
@@ -116,7 +116,7 @@ public sealed class SensoryGainTests
{
var actor = new Actor(Dt, 1, new NerveParameters(), new WithdrawalParameters(), new DriveParameters() with { ResolveDrainPain = 0.0, ResolveDrainStrain = 0.0, ResolveDrainArousal = 0.0 },
GainGoal(gains[k]), new NerveParameters { Threshold = 0.05, SensitisationGrowth = 0.0 }, 0);
- actor.SetWillSlots(0.4, 1.0); // a will that holds only part of the reflex down, so flinches leak
+ actor.SetAttention(0.4); // a will that holds only part of the reflex down, so flinches leak
Assert.Equal(gains[k], actor.Drive.SensoryGain);
var strengths = new float[2];
var targets = new Quat[2];
diff --git a/tests/Lodur.Core.Tests/PainBoxReplay.cs b/tests/Lodur.Core.Tests/PainBoxReplay.cs
index d7a4695..91d727a 100644
--- a/tests/Lodur.Core.Tests/PainBoxReplay.cs
+++ b/tests/Lodur.Core.Tests/PainBoxReplay.cs
@@ -70,14 +70,14 @@ internal sealed class PainBoxReplay
private readonly double _intensity;
public PainBoxReplay(ulong seed, double intensity = 0.8, double pull = 0.5, WithdrawalParameters? withdrawal = null,
- DriveParameters? drive = null, double jitter = 0.2, Brain? brain = null)
+ DriveParameters? drive = null, double jitter = 0.2, Brain? brain = null, Physiology? physiology = null)
{
_rng = new SplitMix64(seed);
_intensity = intensity;
var gainTrait = 1.0 + jitter * _rng.NextSigned();
var drainTrait = 1.0 + jitter * _rng.NextSigned();
Actor = new Actor(Dt, 1, new NerveParameters { Gain = gainTrait }, withdrawal ?? new WithdrawalParameters(),
- (drive ?? new DriveParameters()) with { DrainTrait = drainTrait }, brain ?? PainBoxBrain.Make(pull));
+ (drive ?? new DriveParameters()) with { DrainTrait = drainTrait }, brain ?? PainBoxBrain.Make(pull), physiology: physiology);
}
/// One tick of the replayed stimulus; the tick index is Actor.TickCount before the call.
diff --git a/tests/Lodur.Core.Tests/PhysiologyTests.cs b/tests/Lodur.Core.Tests/PhysiologyTests.cs
index 83daf25..ef2ed55 100644
--- a/tests/Lodur.Core.Tests/PhysiologyTests.cs
+++ b/tests/Lodur.Core.Tests/PhysiologyTests.cs
@@ -406,6 +406,26 @@ public sealed class PhysiologyTests
Assert.Equal(DeathCause.VitalTissue, both.Cause); // the vital rule comes first
}
+ [Fact]
+ public void When_several_rules_hold_in_one_step_the_first_in_the_ruled_order_names_the_cause()
+ {
+ // One 3 s step: a 1 mL/s bleed loses 3 mL of a 5 mL body (past the lethal half) while the brain is wiped out.
+ var vitalBrain = new[] { new TissueDef("brain", 10, 1, Vital: true, Consciousness: 1), new TissueDef("heart", 10, 4, BloodPumping: 1), new TissueDef("muscle", 10, 1, Motor: 1) };
+ var vital = Make(root: vitalBrain);
+ Afflict(vital, "Bleeder", 1, 0, 1);
+ Afflict(vital, "Lesion", 0, 0, 10);
+ vital.Step(3.0);
+ Assert.True(vital.BloodLoss >= 1.0);
+ Assert.Equal(DeathCause.VitalTissue, vital.Cause); // vital before blood
+
+ var plain = Make();
+ Afflict(plain, "Bleeder", 1, 0, 1);
+ Afflict(plain, "Lesion", 0, BrainLayer, 10);
+ plain.Step(3.0);
+ Assert.True(plain.BloodLoss >= 1.0 && plain.Consciousness == 0.0);
+ Assert.Equal(DeathCause.BloodLoss, plain.Cause); // blood before consciousness
+ }
+
[Fact]
public void Death_is_permanent_and_limp_and_nothing_changes_after_it_but_the_table_still_takes_wounds()
{
diff --git a/tests/Lodur.Core.Tests/WillTests.cs b/tests/Lodur.Core.Tests/WillTests.cs
index 4a559f5..a493e2d 100644
--- a/tests/Lodur.Core.Tests/WillTests.cs
+++ b/tests/Lodur.Core.Tests/WillTests.cs
@@ -417,13 +417,21 @@ public sealed class WillTests
Assert.Equal(1.0, calm.Drive.Resolve);
}
- // The slots read 1 in the core today; these tests lower them through the internal seam and watch every consumer of Will move.
+ // The slots read 1 in the core today; these tests lower attention through the internal seam and consciousness through a physiology
+ // (a brain of 1 Hp lesioned by 1 - c), and watch every consumer of Will move.
private static Actor Hold(double attention, double consciousness, DriveParameters? drive = null)
{
var brain = new Brain { Goals = new[] { new GoalSpec { Id = "g", Behaviour = new PoseBehaviour { Keys = new[] { PainBoxBrain.Hold }, FlinchPose = PainBoxBrain.Withdraw, Hold = Hold07 } } } };
- var actor = new Actor(0.01, 1, new NerveParameters(), new WithdrawalParameters(), drive ?? new DriveParameters(), brain);
- actor.SetWillSlots(attention, consciousness);
+ var root = new[] { new TissueDef("brain", 1, 1, Consciousness: 1), new TissueDef("muscle", 10, 1, Motor: 1) };
+ var physiology = new Physiology(PhysioFixtures.Body3(), PhysioFixtures.Plan3(root: root), 20);
+ if (consciousness < 1.0)
+ {
+ Assert.True(physiology.Afflict(PhysioFixtures.Af("Lesion"), 0, 0, 1.0 - consciousness));
+ }
+
+ var actor = new Actor(0.01, 1, new NerveParameters(), new WithdrawalParameters(), drive ?? new DriveParameters(), brain, physiology: physiology);
+ actor.SetAttention(attention);
return actor;
}
@@ -451,7 +459,8 @@ public sealed class WillTests
{
Step(a, 0.6, s, q);
var d = a.Drive;
- Assert.Equal(Math.Min(d.Resolve * attention, consciousness), d.Will);
+ Assert.Equal(consciousness, d.Consciousness, 12); // 1 - (1 - c) is not c in doubles
+ Assert.Equal(Math.Min(d.Resolve * attention, d.Consciousness), d.Will);
}
}
@@ -464,8 +473,10 @@ public sealed class WillTests
var a = Hold(attention, consciousness);
var s = new float[2];
var q = new Quat[2];
- for (var i = 0; i < 100; i++) Step(a, 0.8, s, q);
+ var died = false;
+ for (var i = 0; i < 100; i++) died |= (Step(a, 0.8, s, q) & TickEvents.Died) != 0;
Assert.True(a.Drive.Resolve > 0.9);
+ Assert.Equal(consciousness == 0.0, died); // no consciousness is a death by the ruled rule, on the first tick
return a.Drive.Strain;
}
@@ -509,7 +520,9 @@ public sealed class WillTests
for (var i = 0; i < 20; i++)
{
Step(a, 0.0, s, q); // no stimulus, no leak
- Assert.Equal(0.7f * (float)Math.Sqrt(Math.Min(a.Drive.Resolve * attention, consciousness)), s[0]);
+ var c = a.Drive.Consciousness;
+ Assert.Equal(consciousness, c, 12);
+ Assert.Equal(0.7f * (float)Math.Sqrt(Math.Min(a.Drive.Resolve * attention, c)) * (float)c, s[0]); // the motor ceiling is the capacity times consciousness
}
}