diff --git a/src/BadDay.Core/OfficeBrain.cs b/src/BadDay.Core/OfficeBrain.cs
index 412f45b..9bb19a2 100644
--- a/src/BadDay.Core/OfficeBrain.cs
+++ b/src/BadDay.Core/OfficeBrain.cs
@@ -4,18 +4,21 @@ using Lodur;
namespace BadDay.Core;
/// What the office timeline's goal column names: the goal in force, by 's index. Display only.
-public enum OfficeGoal { KeepComposure, Rage, Calm }
+public enum OfficeGoal { KeepComposure, Rage, Calm, Clutch, Thrash }
///
/// The poses Office Fella's goals write, one rotation per muscle: the composed pose he holds while he keeps his
-/// composure (and the pose a leak would pull toward), and the keys the rage walks in a loop. The body supplies them
+/// composure (and the pose a leak would pull toward), the keys the rage walks in a loop, the clutch (both hands at the
+/// throat) and the keys the thrash walks. The body supplies them
/// (OfficeBody.Poses); the headless run, which has no body, takes .
///
-public sealed record OfficePoses(Quat[] Composed, Quat[] Flinch, Quat[][] RageKeys)
+public sealed record OfficePoses(Quat[] Composed, Quat[] Flinch, Quat[][] RageKeys, Quat[] Clutch, Quat[][] ThrashKeys)
{
/// One muscle, every pose the identity: the headless run's behaviour has no body to move.
public static OfficePoses Identity { get; } = new(
new[] { Quat.Identity }, new[] { Quat.Identity },
+ new[] { new[] { Quat.Identity }, new[] { Quat.Identity }, new[] { Quat.Identity }, new[] { Quat.Identity } },
+ new[] { Quat.Identity },
new[] { new[] { Quat.Identity }, new[] { Quat.Identity }, new[] { Quat.Identity }, new[] { Quat.Identity } });
}
@@ -27,7 +30,12 @@ public sealed record OfficePoses(Quat[] Composed, Quat[] Flinch, Quat[][] RageKe
/// his composed pose at normal strength, for good (ruling lodur:ruling:fella-calm-after-rage); entering it fades his arousal and his senses' gain to nothing over
/// (rulings lodur:ruling:stress-bar-shows-arousal-calm-silences and lodur:ruling:flinch-tail-after-stimulus), so the stress bar
/// empties while the office keeps sounding. Calm is terminal as
-/// data: it gates on Breaks, which never falls, and nothing outranks it. Authored as data; the Actor commits the
+/// data among the stress goals: it gates on Breaks, which never falls, and only the two air-hunger goals outrank it, since air
+/// hunger is physiology, not a fit (ruling lodur:ruling:fella-calm-after-rage is about the rage). Air hunger, from a breath tried
+/// and not got (), makes him clutch his throat; once his will has broken while it
+/// holds he thrashes (rulings lodur:ruling:bds-air-hunger-clutch-then-thrash, lodur:ruling:bds-thrash-when-will-breaks). Both are
+/// involuntary throughout, so a will-weighted struggle never goes limp, and both sag with the Actor's motor ceiling, which
+/// carries consciousness: BDS adds no sag goal. A Fella cut while his will is still broken thrashes at once. Authored as data; the Actor commits the
/// switches, so the timeline's goal column is read back from .
///
public static class OfficeBrain
@@ -35,13 +43,21 @@ public static class OfficeBrain
public const int ComposureIndex = 0;
public const int RageIndex = 1;
public const int CalmIndex = 2;
+ public const int ClutchIndex = 3;
+ public const int ThrashIndex = 4;
public const string RageId = "rage";
/// The calm goal's id.
public const string CalmId = "calm";
- public static OfficeGoal GoalAt(int index) => index switch { RageIndex => OfficeGoal.Rage, CalmIndex => OfficeGoal.Calm, _ => OfficeGoal.KeepComposure };
+ /// The clutch goal's id.
+ public const string ClutchId = "clutch";
+
+ /// The thrash goal's id.
+ public const string ThrashId = "thrash";
+
+ public static OfficeGoal GoalAt(int index) => index switch { RageIndex => OfficeGoal.Rage, CalmIndex => OfficeGoal.Calm, ClutchIndex => OfficeGoal.Clutch, ThrashIndex => OfficeGoal.Thrash, _ => OfficeGoal.KeepComposure };
public static Brain Build(StressParameters p, OfficePoses poses) => new()
{
@@ -83,6 +99,29 @@ public static class OfficeBrain
EntrySeconds = p.CalmFadeSeconds,
Behaviour = new PoseBehaviour { Keys = new[] { poses.Composed }, FlinchPose = poses.Flinch, Hold = p.Hold },
},
+ new GoalSpec
+ {
+ Id = ClutchId,
+ Priority = 3.0,
+ When = new[] { new Condition(DriveQuantity.AirHunger, ConditionOp.AtLeast, p.ClutchAirHunger) },
+ InvoluntarySeconds = double.PositiveInfinity,
+ Pull = 0.0,
+ Behaviour = new PoseBehaviour { Keys = new[] { poses.Clutch }, FlinchPose = poses.Clutch, Hold = p.Hold with { FlinchGain = 0.0 } },
+ },
+ new GoalSpec
+ {
+ Id = ThrashId,
+ Priority = 4.0,
+ When = new[] { new Condition(DriveQuantity.WillBroken, ConditionOp.AtLeast, 1.0), new Condition(DriveQuantity.AirHunger, ConditionOp.AtLeast, p.ClutchAirHunger) },
+ InvoluntarySeconds = double.PositiveInfinity,
+ Behaviour = new PoseBehaviour
+ {
+ Keys = poses.ThrashKeys,
+ SecondsPerKey = p.ThrashKeySeconds,
+ FlinchPose = poses.ThrashKeys[0],
+ Hold = p.Hold with { HoldStrength = 1f, FlinchGain = 0.0, StrainShake = 0.0 },
+ },
+ },
},
};
}
diff --git a/src/BadDay.Core/StressParameters.cs b/src/BadDay.Core/StressParameters.cs
index 007503d..8168981 100644
--- a/src/BadDay.Core/StressParameters.cs
+++ b/src/BadDay.Core/StressParameters.cs
@@ -22,6 +22,12 @@ public sealed record StressParameters
/// Seconds from one rage key to the next [P]: wind-up left, strike left, wind-up right, strike right.
public double RageKeySeconds { get; init; } = 0.25;
+ /// The air hunger at which Fella clutches his throat, drive units [P] (ruling lodur:ruling:bds-air-hunger-clutch-then-thrash): a breath tried and not got reads 0.6.
+ public double ClutchAirHunger { get; init; } = 0.3;
+
+ /// Seconds from one thrash key to the next [P] (ruling lodur:ruling:bds-thrash-when-will-breaks): a look knob, tuned on the capture.
+ public double ThrashKeySeconds { get; init; } = 0.2;
+
public Setting Setting { get; init; } = Setting.Office;
public Character Character { get; init; } = Character.OfficeFella;
public Cause Cause { get; init; } = Cause.Office;
diff --git a/src/BadDay.Ymir/OfficeBody.cs b/src/BadDay.Ymir/OfficeBody.cs
index da31b28..dae2200 100644
--- a/src/BadDay.Ymir/OfficeBody.cs
+++ b/src/BadDay.Ymir/OfficeBody.cs
@@ -46,7 +46,9 @@ public static class OfficeBody
///
/// The office puppet's poses [P]. Composed: every muscle at the creation pose, arms down. Rage: each arm winds up (the
- /// elbow folded, the fist at the chest) and strikes (the shoulder forward, the elbow straight), left then right.
+ /// elbow folded, the fist at the chest) and strikes (the shoulder forward, the elbow straight), left then right. Clutch: both hands at the throat, the shoulders swung across and forward, the elbows folded.
+ /// Thrash: four keys, a flung and kicking one, its mirror, and two between where both arms drop back and the knees come up.
+ /// The clutch and the thrash are placeholders [P] Deru tunes on the capture.
///
public static OfficePoses Poses { get; } = BuildPoses();
@@ -97,7 +99,50 @@ public static class OfficeBody
foreach (var k in keys) { Arm(plan, k, left: true, strike: false); Arm(plan, k, left: false, strike: false); }
Arm(plan, keys[1], left: true, strike: true);
Arm(plan, keys[3], left: false, strike: true);
- return new OfficePoses(composed, Pose(), keys);
+ return new OfficePoses(composed, Pose(), keys, Clutch(plan, Pose()), Thrash(plan, Pose));
+ }
+
+ // Both hands at the throat: the shoulder swings across (z) and forward (x), the elbow folds. Left is +sx, right -sx.
+ private static Quat[] Clutch(BodyPlan plan, Quat[] pose)
+ {
+ foreach (var (side, sx) in new[] { (Side.Left, 1f), (Side.Right, -1f) })
+ {
+ pose[plan.JointIndex("Shoulder", side)] = Quat.FromAxisAngle(0f, 0f, 1f, -sx * 1.0f) * Quat.FromAxisAngle(1f, 0f, 0f, -0.8f);
+ pose[plan.JointIndex("Elbow", side)] = Quat.FromAxisAngle(0f, 0f, 1f, -2.4f);
+ }
+ return pose;
+ }
+
+ // Keys 0 and 2 mirror each other (one arm flung up and out, the other forward, the trunk twisted, the head back, one leg kicking);
+ // keys 1 and 3 throw both arms down and back, the head forward, the knees up.
+ private static Quat[][] Thrash(BodyPlan plan, Func fresh)
+ {
+ var k = new Quat[4][];
+ for (int i = 0; i < 4; i++) k[i] = fresh();
+ int Joint(string name, Side side) => plan.JointIndex(name, side);
+ Quat Q(float x, float y, float z, float a) => Quat.FromAxisAngle(x, y, z, a);
+ foreach (var (key, flip, up, fwd) in new[] { (0, 1f, Side.Left, Side.Right), (2, -1f, Side.Right, Side.Left) })
+ {
+ k[key][Joint("Shoulder", up)] = Q(0f, 0f, 1f, 1.3f * flip);
+ k[key][Joint("Elbow", up)] = Q(1f, 0f, 0f, -0.4f);
+ k[key][Joint("Shoulder", fwd)] = Q(1f, 0f, 0f, -1.2f);
+ k[key][Joint("Elbow", fwd)] = Q(1f, 0f, 0f, -1.6f);
+ k[key][Joint("Spine", Side.Center)] = Q(0f, 1f, 0f, 0.35f * flip);
+ k[key][Joint("Neck", Side.Center)] = Q(1f, 0f, 0f, -0.5f);
+ k[key][Joint("Hip", up)] = Q(1f, 0f, 0f, -0.5f);
+ k[key][Joint("Knee", up)] = Q(1f, 0f, 0f, 0.2f);
+ }
+ foreach (var key in new[] { 1, 3 })
+ {
+ foreach (var side in new[] { Side.Left, Side.Right })
+ {
+ k[key][Joint("Shoulder", side)] = Q(1f, 0f, 0f, 0.6f);
+ k[key][Joint("Elbow", side)] = Q(1f, 0f, 0f, -0.3f);
+ k[key][Joint("Knee", side)] = Q(1f, 0f, 0f, 0.6f);
+ }
+ k[key][Joint("Neck", Side.Center)] = Q(1f, 0f, 0f, 0.3f);
+ }
+ return k;
}
private static void Arm(BodyPlan plan, Quat[] pose, bool left, bool strike)
diff --git a/tests/BadDay.Tests/Program.cs b/tests/BadDay.Tests/Program.cs
index a0192af..fce6829 100644
--- a/tests/BadDay.Tests/Program.cs
+++ b/tests/BadDay.Tests/Program.cs
@@ -987,6 +987,7 @@ public static class Program
Check(r.Outcome == Outcome.WillBroke && r.EndMs == 600000, $"outcome {r.Outcome}, read at {r.EndMs} ms");
Check(r.Timeline.Count(e => e.Kind == StressEntryKind.GoalChanged) == 2 && r.Timeline.Where(e => e.Kind == StressEntryKind.Sample).Max(e => e.TimeMs) >= 599000, "the session stopped logging");
Check(r.Timeline[^1].Goal == OfficeGoal.Calm, "the office left calm after its break");
+ Check(r.Timeline.All(e => e.Goal != OfficeGoal.Clutch && e.Goal != OfficeGoal.Thrash), "the headless office, which breathes freely, clutched or thrashed");
}),
("office rage: a will that holds never switches, and the job's pull is the composure goal's alone", () =>
@@ -998,6 +999,23 @@ public static class Program
Check(brain.Goals[OfficeBrain.ComposureIndex].Pull == p.Cause.ObjectivePull && brain.Goals[OfficeBrain.RageIndex].Pull == 0.0, "the pulls are not the cause's and zero");
}),
+ ("office brain data: clutch and thrash: priorities thrash > clutch > calm > rage > composure, the two gates, both involuntary throughout", () =>
+ {
+ var p = new StressParameters();
+ var g = OfficeBrain.Build(p, OfficePoses.Identity).Goals;
+ Check(OfficeBrain.GoalAt(OfficeBrain.ClutchIndex) == OfficeGoal.Clutch && OfficeBrain.GoalAt(OfficeBrain.ThrashIndex) == OfficeGoal.Thrash, "GoalAt does not name the two goals");
+ Check(g[OfficeBrain.ClutchIndex].Id == OfficeBrain.ClutchId && g[OfficeBrain.ThrashIndex].Id == OfficeBrain.ThrashId, "the ids");
+ Check(g[OfficeBrain.ThrashIndex].Priority > g[OfficeBrain.ClutchIndex].Priority && g[OfficeBrain.ClutchIndex].Priority > g[OfficeBrain.CalmIndex].Priority
+ && g[OfficeBrain.CalmIndex].Priority > g[OfficeBrain.RageIndex].Priority && g[OfficeBrain.RageIndex].Priority > g[OfficeBrain.ComposureIndex].Priority, "the priority order");
+ var clutch = g[OfficeBrain.ClutchIndex].When;
+ Check(clutch.Count == 1 && clutch[0].Quantity == Lodur.DriveQuantity.AirHunger && clutch[0].Op == Lodur.ConditionOp.AtLeast && clutch[0].Threshold == p.ClutchAirHunger, "the clutch gate is air hunger at ClutchAirHunger");
+ var thrash = g[OfficeBrain.ThrashIndex].When;
+ Check(thrash.Count == 2 && thrash.Any(c => c.Quantity == Lodur.DriveQuantity.WillBroken && c.Op == Lodur.ConditionOp.AtLeast && c.Threshold == 1.0)
+ && thrash.Any(c => c.Quantity == Lodur.DriveQuantity.AirHunger && c.Op == Lodur.ConditionOp.AtLeast && c.Threshold == p.ClutchAirHunger), "the thrash gate is WillBroken and air hunger");
+ Check(double.IsPositiveInfinity(g[OfficeBrain.ClutchIndex].InvoluntarySeconds) && double.IsPositiveInfinity(g[OfficeBrain.ThrashIndex].InvoluntarySeconds), "a struggle goal is voluntary at some point");
+ Check(g.Where(x => x.Id != OfficeBrain.ClutchId && x.Id != OfficeBrain.ThrashId).SelectMany(x => x.When).All(c => c.Quantity == Lodur.DriveQuantity.Breaks), "rage and calm keep their Breaks gates");
+ }),
+
("office body: the rage is visible: both hands move at least 3x faster, and over 1 m/s (a limp rage gives 0.6), in the 2 s after the switch than in the 2 s before, the pelvis stays within 1 cm, and two runs agree", () =>
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
@@ -1450,21 +1468,54 @@ public static class Program
Console.WriteLine($" airway: liquid at the opening from tick {atAirway}, in the airway from tick {liquid}, peak {maxLiquid * 1e6:F2} mL, occlusion {maxOcclusion:F3}");
}),
- ("the front of the throat drowns him: HitAt(Head, the front of the throat), Wound(hit, Knife) at tick 0 puts more than 20 mL in the airway within 5 s, fills it (occlusion 0.99) within 12.9 s, and the death is Consciousness, not BloodLoss", () =>
+ ("throat clutch then thrash (the front of the throat drowns him): HitAt(Head, the front of the throat), Wound(hit, Knife) at tick 0 puts more than 20 mL in the airway within 5 s, fills it (occlusion 0.99) within 12.9 s, the goals go Clutch then Thrash, both palms stay within 0.287 m of the throat from 3 s after the cut to the thrash, the thrash starts within 0.2 s of the will's first break, both hands then move at 1.437 m/s or more, and the death is Consciousness", () =>
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
using var s = new OfficeBodySession(p, 1);
var head = SeatedPuppet.Plan.PartIndex("Head", Lodur.Side.Center);
Check(s.Wound(HitAt(s, head, (0f, -0.0778f, 0.0778f)), WoundTool.Knife), "the knife was refused at the throat");
double liquidAt5 = 0.0, maxOcclusion = 0.0, occludedAt = -1.0;
+ var goals = new List();
+ var handL = new List();
+ var handR = new List();
+ var palmFar = new List(); // per tick, the farther palm from the throat point
while (!s.Dead && s.TickIndex < 250 * Hz)
{
s.Step();
if (s.TickIndex <= 5 * Hz) liquidAt5 = Math.Max(liquidAt5, s.AirwayLiquid);
maxOcclusion = Math.Max(maxOcclusion, s.Occlusion);
if (occludedAt < 0.0 && s.Occlusion >= 0.99) occludedAt = s.TickIndex / (double)Hz;
+ goals.Add(s.Goal);
+ handL.Add(s.HandL);
+ handR.Add(s.HandR);
+ var t = HitAtPoint(s, head, (0f, -0.0778f, 0.0778f)).Point;
+ double Dist(BodyPoint h) => Math.Sqrt(Math.Pow(h.X - t.X, 2) + Math.Pow(h.Y - t.Y, 2) + Math.Pow(h.Z - t.Z, 2));
+ palmFar.Add(Math.Max(Dist(s.HandL), Dist(s.HandR)));
}
- Console.WriteLine($" throat: {liquidAt5 * 1e6:F1} mL in the airway by 5 s, full at {occludedAt:F1} s, died at {s.TickIndex / (double)Hz:F1} s");
+ var r = s.Result();
+ var changes = r.Timeline.Where(e => e.Kind == StressEntryKind.GoalChanged).ToList();
+ var broke = r.Timeline.First(e => e.Kind == StressEntryKind.WillBroke);
+ Check(changes.Count == 2 && changes[0].Goal == OfficeGoal.Clutch && changes[1].Goal == OfficeGoal.Thrash, $"the goals went {string.Join(", ", changes.Select(e => e.Goal))}");
+ int thrash = (int)Math.Round(changes[1].TimeMs * Hz / 1000.0), clutchFrom = 3 * Hz;
+ double gap = (changes[1].TimeMs - broke.TimeMs) / 1000.0;
+ Check(gap >= 0.0 && gap <= 0.2, $"the thrash came {gap:F3} s after the will broke");
+ for (int i = clutchFrom; i < thrash - 1; i++) Check(goals[i] == OfficeGoal.Clutch, $"tick {i + 1}: goal {goals[i]}, not Clutch, between the clutch and the thrash");
+ double palm = 0.0;
+ for (int i = clutchFrom; i < thrash - 1; i++) palm = Math.Max(palm, palmFar[i]);
+ // Bound by deterministic-bound-margin: shipped 0.1075 m, least mutant 0.7663 m (the composed pose in place of the clutch: arms down), separation 7.1, bound sqrt(0.1075 x 0.7663) = 0.287.
+ Check(palm <= 0.287, $"a palm was {palm:F4} m from the throat while he clutched");
+ double Rms(IReadOnlyList h, int from, int to)
+ {
+ double sum = 0.0;
+ for (int i = from + 1; i < to; i++) sum += (Math.Pow(h[i].X - h[i - 1].X, 2) + Math.Pow(h[i].Y - h[i - 1].Y, 2) + Math.Pow(h[i].Z - h[i - 1].Z, 2)) * Hz * Hz;
+ return Math.Sqrt(sum / (to - from - 1));
+ }
+ int from = thrash + Hz / 2, to = thrash + 5 * Hz / 2;
+ Check(handL.Count > to, $"he died at tick {handL.Count}, inside the thrash window");
+ double rms = Math.Sqrt(0.5 * (Math.Pow(Rms(handL, from, to), 2) + Math.Pow(Rms(handR, from, to), 2)));
+ // Bound by deterministic-bound-margin: both hands' RMS speed over [thrash+0.5, thrash+2.5] s: shipped 2.286 m/s, least mutant 0.903 (the thrash goal's InvoluntarySeconds 0: a will-weighted struggle goes limp), separation 2.53, bound sqrt(2.286 x 0.903) = 1.437.
+ Check(rms >= 1.437, $"the hands moved at {rms:F3} m/s in the thrash");
+ Console.WriteLine($" throat: {liquidAt5 * 1e6:F1} mL in the airway by 5 s, full at {occludedAt:F1} s, clutch to thrash {changes[0].TimeMs / 1000.0:F2} s to {changes[1].TimeMs / 1000.0:F2} s ({gap:F3} s after the will broke), palms within {palm:F4} m, thrash hands {rms:F3} m/s, died at {s.TickIndex / (double)Hz:F1} s");
Check(liquidAt5 > 20e-6, $"the airway held {liquidAt5 * 1e6:F2} mL by 5 s");
// Bounds are Lodur's (VesselTests, the same physiology and the same gain: shipped 1.29 s here and there): full within 12.9 s = sqrt(1.29 x 129.95), the cough-2.0 mutant at 129.95 s; separation 10.
Check(occludedAt >= 0.0 && occludedAt <= 12.9 && maxOcclusion >= 0.99, $"the airway filled at {occludedAt:F2} s, occlusion peaked at {maxOcclusion:F3}");