Pin motor fold order and weights, vascularity and the bleed clamp, slot reuse age, dead Bleed, and a refused Tick leaving the physiology untouched
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7d1eae37a4
commit
aac6079369
3 changed files with 76 additions and 5 deletions
|
|
@ -66,10 +66,13 @@ public sealed class ActorPhysiologyTests
|
|||
Assert.Same(p, a.Physiology);
|
||||
Assert.Throws<ArgumentException>(() => Make(p));
|
||||
|
||||
Assert.True(p.Afflict(Af("Bleeder"), 1, 0, 1));
|
||||
var q = new Quat[2];
|
||||
Assert.Throws<ArgumentException>(() => Tick(a, 0.0, new float[1], q));
|
||||
Assert.Throws<ArgumentException>(() => Tick(a, 0.0, new float[3], q));
|
||||
Assert.Equal(0, a.TickCount); // a refused call changes nothing
|
||||
Assert.Equal(0, a.TickCount); // a refused call changes nothing, the physiology included
|
||||
Assert.Equal(0.0, p.SlotAge(0));
|
||||
Assert.Equal(0.005, p.BloodVolume);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ internal static class PhysioFixtures
|
|||
Def("Clot", 0, false, PhysiologyClock.Acute,
|
||||
Const(EffectTarget.Bleed, EffectOp.Offset, 1e-3),
|
||||
new Effect(EffectTarget.Bleed, EffectOp.Factor, EffectDriver.Age, new[] { (0.0, 1.0), (60.0, 0.5), (300.0, 0.1) })),
|
||||
Def("MotorDim", 0, false, PhysiologyClock.Acute, Const(EffectTarget.Motor, EffectOp.Offset, -0.2)),
|
||||
Def("Staunch", 0, false, PhysiologyClock.Acute, Const(EffectTarget.Bleed, EffectOp.Offset, -1e-3)),
|
||||
Def("Fading", -0.1, false, PhysiologyClock.Acute, new Effect(EffectTarget.Bleed, EffectOp.Offset, EffectDriver.Severity, new[] { (0.0, 0.0), (1.0, 1e-5) })),
|
||||
Def("SlowBleeder", 0, false, PhysiologyClock.Slow, new Effect(EffectTarget.Bleed, EffectOp.Offset, EffectDriver.Severity, new[] { (0.0, 0.0), (1.0, 1e-3) })),
|
||||
};
|
||||
|
|
@ -44,7 +46,7 @@ internal static class PhysioFixtures
|
|||
public static BloodDef DefaultBlood => new(0.005, 0.5, 0.0);
|
||||
|
||||
/// <summary>Root: brain (weight 1), heart (pumping 1, vital unless asked otherwise), a muscle; A and B: a muscle each. Every tissue has Hp 10.</summary>
|
||||
public static PhysiologyPlan Plan3(bool heartVital = true, BloodDef? blood = null, int slots = 8, IReadOnlyList<Effect>? organism = null, TissueDef[]? root = null)
|
||||
public static PhysiologyPlan Plan3(bool heartVital = true, BloodDef? blood = null, int slots = 8, IReadOnlyList<Effect>? organism = null, TissueDef[]? root = null, TissueDef[]? limbA = null)
|
||||
{
|
||||
var stack = root ?? new[]
|
||||
{
|
||||
|
|
@ -54,12 +56,12 @@ internal static class PhysioFixtures
|
|||
};
|
||||
var limb = new[] { new TissueDef("muscle", 10, 1, Motor: 1) };
|
||||
return new PhysiologyPlan(
|
||||
new[] { new PartTissuesDef("Root", Side.Center, stack), new PartTissuesDef("A", Side.Center, limb), new PartTissuesDef("B", Side.Center, limb) },
|
||||
new[] { new PartTissuesDef("Root", Side.Center, stack), new PartTissuesDef("A", Side.Center, limbA ?? limb), new PartTissuesDef("B", Side.Center, limb) },
|
||||
Defs, organism ?? Array.Empty<Effect>(), blood ?? DefaultBlood, slots);
|
||||
}
|
||||
|
||||
public static Physiology Make(double slowScale = 20.0, bool heartVital = true, BloodDef? blood = null, int slots = 8, IReadOnlyList<Effect>? organism = null, TissueDef[]? root = null) =>
|
||||
new(Body3(), Plan3(heartVital, blood, slots, organism, root), slowScale);
|
||||
public static Physiology Make(double slowScale = 20.0, bool heartVital = true, BloodDef? blood = null, int slots = 8, IReadOnlyList<Effect>? organism = null, TissueDef[]? root = null, TissueDef[]? limbA = null) =>
|
||||
new(Body3(), Plan3(heartVital, blood, slots, organism, root, limbA), slowScale);
|
||||
|
||||
public static int Live(Physiology p)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -217,6 +217,22 @@ public sealed class PhysiologyTests
|
|||
Assert.Equal(1.0, p.Consciousness);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_motor_ceiling_is_the_motor_weighted_mean_then_offsets_then_factors()
|
||||
{
|
||||
var a = new[] { new TissueDef("light", 10, 1, Motor: 1), new TissueDef("heavy", 10, 1, Motor: 3) };
|
||||
var p = Make(limbA: a);
|
||||
Afflict(p, "Lesion", 1, 0, 10); // the light layer is gone: (1 x 0 + 3 x 1) / 4
|
||||
p.Step(0.01);
|
||||
Assert.Equal(0.75, p.MotorCeiling(0), 12);
|
||||
|
||||
Afflict(p, "MotorDim", 1, 0, 1); // offset -0.2
|
||||
Afflict(p, "MotorHalf", 1, 0, 1); // factor 0.5
|
||||
p.Step(0.01);
|
||||
Assert.Equal((0.75 - 0.2) * 0.5, p.MotorCeiling(0), 12); // offsets before factors
|
||||
Assert.Equal(1.0, p.MotorCeiling(1));
|
||||
}
|
||||
|
||||
// Clocks.
|
||||
|
||||
[Fact]
|
||||
|
|
@ -311,6 +327,56 @@ public sealed class PhysiologyTests
|
|||
Assert.Equal(1e-3 * 0.25, p.Bleed(0), 15);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bleeding_goes_through_the_tissues_vascularity()
|
||||
{
|
||||
var p = Make();
|
||||
Afflict(p, "Bleeder", 0, Heart, 1); // the heart's vascularity is 4
|
||||
Afflict(p, "Bleeder", 0, RootMuscle, 1); // the muscle's is 1
|
||||
p.Step(0.01);
|
||||
Assert.Equal(1e-3 * 4 + 1e-3, p.Bleed(0), 15);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_affliction_never_bleeds_negatively_nor_cancels_another_afflictions_bleed()
|
||||
{
|
||||
var p = Make();
|
||||
Afflict(p, "Staunch", 1, 0, 1);
|
||||
p.Step(0.01);
|
||||
Assert.Equal(0.0, p.Bleed(1));
|
||||
Assert.Equal(0.005, p.BloodVolume);
|
||||
|
||||
Afflict(p, "Bleeder", 1, 0, 1);
|
||||
p.Step(0.01);
|
||||
Assert.Equal(1e-3, p.Bleed(1), 15); // the staunch slot clamps at 0 on its own; it does not subtract from the bleeder
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_dead_body_reads_no_bleed_whatever_it_was_bleeding()
|
||||
{
|
||||
var p = Make();
|
||||
Afflict(p, "Bleeder", 1, 0, 1);
|
||||
Afflict(p, "Lesion", 0, BrainLayer, 10); // consciousness 0: dead on this step, the heart still pumping
|
||||
p.Step(0.01);
|
||||
Assert.True(p.Dead);
|
||||
Assert.Equal(DeathCause.Consciousness, p.Cause);
|
||||
Assert.Equal(0.0, p.Bleed(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_reused_slot_starts_at_age_zero()
|
||||
{
|
||||
var p = Make();
|
||||
Afflict(p, "Heal", 1, 0, 0.5); // slot 0, healed away in one second
|
||||
p.Step(1.0);
|
||||
Assert.Equal(0, Live(p));
|
||||
Afflict(p, "Clot", 1, 0, 1); // reuses slot 0
|
||||
Assert.Equal(Af("Clot"), p.SlotDef(0));
|
||||
Assert.Equal(0.0, p.SlotAge(0));
|
||||
p.Step(0.01);
|
||||
Assert.Equal(0.01, p.SlotAge(0), 15);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bleeding_reads_the_pumping_so_a_stopped_non_vital_heart_bleeds_nothing()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue