The knife click cuts by depth: WoundTool carries a depth, the hit goes into the part's frame and PartTissuesDef.Reach picks the layers

WoundTool(Depth, Severity) replaces the label list; StressSession.Wound takes the
part-frame point and calls Reach; SeatedBody.ToPart is the one world-to-part
conversion (OpenWound uses it). A throat click now cuts the larynx. HUD gains an
airway line. Tests: throat in the world, reach by point, WoundTool refusals; 97/97.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-27 04:52:15 +01:00
commit ed781c0f72
8 changed files with 157 additions and 54 deletions

View file

@ -209,7 +209,7 @@ The chamber's release is declared the same way (`PainBoxParameters.ReleaseGoalId
apart from the setting and the cause. Each scenario builds its own Brain from its own parameters; one entry point keyed by character id
waits for Brains as content. Headless the rage moves nothing; `office --body` runs it on the puppet.
On the puppet the office is `OfficeBodySession`, stepped by its caller one 1/120 s step at a time like the chamber's session (`OfficeBody.Run` records one to its end). It builds a `SeatedBody`, the one owner of every BDS body world, and attaches a Lodur `Physiology` to the Actor (`StressParameters.SlowScale`, default 20 [P]: ruling `lodur:ruling:bds-physiology-clock`; Acute afflictions such as a cut do not move with it). The player's harm is `Wound(part, tool)`: a `WoundTool` names tissue layers and a severity, and `StressSession.Wound` binds one Cut affliction on each layer the part has (a palm has no fat), the only path harm takes into the body. The knife (`WoundTool.Knife`, skin, fat and muscle at 60 [P]) is the click-cut's content until contacts become afflictions. Lodur decides the rest: blood loss, consciousness, air hunger and death (`lodur:ruling:bds-death`). A cut on the left lower arm bleeds the body out in about 40 s; the Actor reports `Died` once, the body goes limp (it writes no strength from then on), the session logs a `Died` row, ends the run `ReleaseSeconds` later with `Outcome.Died`, and `StressResult` carries `DiedAtMs` and `DeathCause`. An unwounded run is unchanged: nothing in it can die.
On the puppet the office is `OfficeBodySession`, stepped by its caller one 1/120 s step at a time like the chamber's session (`OfficeBody.Run` records one to its end). It builds a `SeatedBody`, the one owner of every BDS body world, and attaches a Lodur `Physiology` to the Actor (`StressParameters.SlowScale`, default 20 [P]: ruling `lodur:ruling:bds-physiology-clock`; Acute afflictions such as a cut do not move with it). The player's harm is `Wound(part, tool)`: a `WoundTool` is a depth and a severity; the hit point in the part's frame and Lodur's `PartTissuesDef.Reach` pick the layers, and `StressSession.Wound` binds one Cut affliction on each, the only path harm takes into the body. The knife (`WoundTool.Knife`, 0.02 m at 60 [P]: skin, fat and muscle on limbs and trunk, the larynx at the front of the throat) is the click-cut's content until contacts become afflictions. Lodur decides the rest: blood loss, consciousness, air hunger and death (`lodur:ruling:bds-death`). A cut on the left lower arm bleeds the body out in about 40 s; the Actor reports `Died` once, the body goes limp (it writes no strength from then on), the session logs a `Died` row, ends the run `ReleaseSeconds` later with `Outcome.Died`, and `StressResult` carries `DiedAtMs` and `DeathCause`. An unwounded run is unchanged: nothing in it can die.
The stress bar is his arousal, how wound up he is right now, and reads **stress (arousal)** (`StressResult.StressBarLabel`; ruling `lodur:ruling:stress-bar-shows-arousal-calm-silences`).
It rises with each stressor and falls in quiet; will is not on it. Entering calm fades his arousal and his senses' gain to nothing over `CalmFadeSeconds` (3 s, the aftershock tail of
@ -222,7 +222,7 @@ keep sounding. Arousal is exactly 0 from `CalmFadeSeconds` on; the load column t
- `src/BadDay.Ymir/OfficeBody.cs`: the office on the seated puppet, recorded to its end: both hands, the pelvis and the strikes.
- `src/BadDay.Ymir/OfficeBodySession.cs`: the office's stepping session on a `SeatedBody` with a Lodur `Physiology`; `Wound`, the read-outs, death.
- `src/BadDay.Ymir/SeatedBody.cs`: the one owner of a BDS body world and its step order.
- `src/BadDay.Core/WoundTool.cs`: what a wound is made of; `Knife`.
- `src/BadDay.Core/WoundTool.cs`: what a wound is made of: a depth and a severity; `Knife`.
- `src/BadDay.Core/StressSimulation.cs`: the headless run with scheduled silences, and the seed sweep.
```

View file

@ -148,6 +148,7 @@ public partial class Hud : CanvasLayer
_text.Append($"will {o.Will:F2} stress {o.Arousal:F2} goal {o.Goal}\n");
_text.Append($"blood loss {o.BloodLoss * 100:F0} % of lethal blood spilled {o.BloodEmitted * 1000:F2} L\n");
_text.Append($"consciousness {o.Consciousness:F2} air hunger {o.AirHunger:F2}\n");
_text.Append($"airway {o.AirwayLiquid * 1e6:F0} mL ({o.Occlusion * 100:F0} % full)\n");
if (o.Dead) _text.Append($"DEAD: {o.DeathCause}\n");
else _text.Append(o.Finished ? "finished\n" : "running\n");
_text.Append(_main.Cuts.Count > 0 ? $"last cut: {_main.Cuts[^1].Part} at tick {_main.Cuts[^1].Tick}\n" : "no cuts yet\n");

View file

@ -189,6 +189,7 @@ public partial class Smoke : Node
Click(at, alt: false);
Check(_main.Cuts.Count == 1 && _main.Cuts[0].Part == "LowerArm L", $"a left press on LowerArm L's centre left cuts [{string.Join(", ", _main.Cuts)}]");
Check(office.Result().Timeline.Count > 0, "no timeline after a cut");
Check(Hud.Readout.Contains("airway "), "the readout has no airway line");
await CheckAltGuard(at);
await UntilTick(600);

View file

@ -117,28 +117,19 @@ public sealed class StressSession
}
/// <summary>
/// The player wounds a part with a tool from the current tick on: one Cut affliction of the tool's severity on each
/// of the tool's layers the part has (a layer the part lacks is skipped), through <see cref="Physiology.Afflict"/>,
/// the only way harm enters. All of the layers or none: false, and nothing wounded, for a headless session, a body
/// that is dead (death is permanent, bds-death) or a run that is <see cref="Finished"/>, a part the body lacks, a tool
/// none of whose layers the part has, or when the physiology has no room for every layer (its answer, not counted here).
/// The player wounds a part with a tool from the current tick on: one Cut affliction of the tool's severity on each layer its
/// <see cref="WoundTool.Depth"/> reaches at <paramref name="point"/> (in the part's frame) through the part's PartTissuesDef.Reach,
/// through <see cref="Physiology.Afflict"/>, the only way harm enters. All of the layers or none: false, and nothing wounded, for a
/// headless session, a body that is dead (death is permanent, bds-death) or a run that is <see cref="Finished"/>, a part the body
/// lacks, or when the physiology has no room for every layer (its answer, not counted here).
/// </summary>
public bool Wound(int part, WoundTool tool)
public bool Wound(int part, (float X, float Y, float Z) point, WoundTool tool)
{
if (_physiology is null || _physiologyPlan is null || _stackOf is null || (uint)part >= (uint)_stackOf.Length) return false;
if (Finished || _physiology.Dead) return false;
var stack = _physiologyPlan.Parts[_stackOf[part]].Tissues;
Span<int> layers = stackalloc int[tool.Layers.Count];
int n = 0;
foreach (var label in tool.Layers)
{
for (int layer = 0; layer < stack.Count; layer++)
{
if (stack[layer].Label != label) continue;
layers[n++] = layer;
break;
}
}
var stack = _physiologyPlan.Parts[_stackOf[part]];
Span<int> layers = stackalloc int[stack.Tissues.Count];
int n = stack.Reach(point, tool.Depth, layers);
return n > 0 && _physiology.Afflict(_cut, part, layers[..n], tool.Severity);
}

View file

@ -1,14 +1,31 @@
using System.Collections.Generic;
using System;
namespace BadDay.Core;
/// <summary>
/// What a wound is made of: one Cut affliction of <see cref="Severity"/> on each of the named tissue <see cref="Layers"/>
/// of the part (a part without a layer skips it). Content, not a rule: <see cref="Knife"/> is the click-cut's [P] until
/// lodur-insult-resolution turns contacts into afflictions (question bds-first-wound-tool).
/// What a wound is made of: a <see cref="Depth"/> (m) and a <see cref="Severity"/>. Which tissue layers it cuts is not content:
/// Lodur's PartTissuesDef.Reach derives it from the depth and the hit point in the part's frame. Content, not a rule:
/// <see cref="Knife"/> is the click-cut's [P] until lodur-insult-resolution turns contacts into afflictions (question bds-first-wound-tool).
/// </summary>
public sealed record WoundTool(IReadOnlyList<string> Layers, double Severity)
public sealed record WoundTool
{
/// <summary>Skin, fat and muscle cut to the same depth.</summary>
public static WoundTool Knife { get; } = new(new[] { "Skin", "Fat", "Muscle" }, 60.0);
/// <summary>A tool that cuts <paramref name="depth"/> m deep (finite and above 0) at <paramref name="severity"/>.</summary>
public WoundTool(double depth, double severity)
{
if (!(double.IsFinite(depth) && depth > 0.0)) throw new ArgumentException("depth is not finite and above 0.", nameof(depth));
Depth = depth;
Severity = severity;
}
/// <summary>How deep the tool cuts, in m, through the part's skin outward-in (finite and above 0).</summary>
public double Depth { get; }
/// <summary>The severity of the Cut affliction on each reached layer.</summary>
public double Severity { get; }
/// <summary>
/// 2 cm at severity 60. At that depth: skin, fat and muscle on the limbs and trunk (bone lies past 2.26 cm there), skin and fat on the
/// face and sides of the head, the larynx at the front of the throat, and bone as well as muscle in the hands and feet.
/// </summary>
public static WoundTool Knife { get; } = new(0.02, 60.0);
}

View file

@ -155,12 +155,14 @@ public sealed class OfficeBodySession : IBodyRun
/// <summary>
/// Wounds the part <paramref name="hit"/> names from the next tick, and opens the wound at the point it hit so the blood leaves from there;
/// false when refused (see <see cref="StressSession.Wound"/>), and then nothing is opened.
/// the point goes into the part's frame (<see cref="SeatedBody.ToPart"/>) for the layers the tool's depth reaches there.
/// False when refused (a part outside the plan, or see <see cref="StressSession.Wound"/>), and then nothing is opened.
/// </summary>
public bool Wound(in PartHit hit, WoundTool tool)
{
Live();
if (!_session.Wound(hit.Part, tool)) return false;
if ((uint)hit.Part >= (uint)_body.Plan.Parts.Count) return false;
if (!_session.Wound(hit.Part, _body.ToPart(hit.Part, hit.Point), tool)) return false;
_body.OpenWound(hit.Part, hit.Point, hit.Normal);
return true;
}

View file

@ -132,15 +132,32 @@ public sealed class SeatedBody : IDisposable
return new PartHit((int)ordinal, new BodyPoint(hit.Point.X, hit.Point.Y, hit.Point.Z), new BodyPoint(hit.Normal.X, hit.Normal.Y, hit.Normal.Z));
}
/// <summary>Opens a wound at a world point and normal on <paramref name="part"/>: from now on it sheds its share of the part's bleed, carried by the part.</summary>
public void OpenWound(int part, BodyPoint point, BodyPoint normal)
/// <summary>
/// A world point in <paramref name="part"/>'s frame: origin the part's position, axes its rotation, the frame the sites of Lodur's PartTissuesDef are
/// written in (the body's own, as the airway openings' offsets are). The inverse of the part's live pose.
/// </summary>
public (float X, float Y, float Z) ToPart(int part, BodyPoint world)
{
Live();
int lane = _ragdoll.BodyLane(part);
var v = _world.View;
var inverse = new Quat(v.RotationX[lane], v.RotationY[lane], v.RotationZ[lane], v.RotationW[lane]).Conjugate();
inverse.Rotate(point.X - v.PositionX[lane], point.Y - v.PositionY[lane], point.Z - v.PositionZ[lane], out var px, out var py, out var pz);
inverse.Rotate(normal.X, normal.Y, normal.Z, out var nx, out var ny, out var nz);
return Inverse(lane, world.X - v.PositionX[lane], world.Y - v.PositionY[lane], world.Z - v.PositionZ[lane]);
}
/// <summary>The part's inverse rotation applied to a vector: a world offset from the part's position, or a world direction, into the part's frame.</summary>
private (float X, float Y, float Z) Inverse(int lane, float x, float y, float z)
{
var v = _world.View;
new Quat(v.RotationX[lane], v.RotationY[lane], v.RotationZ[lane], v.RotationW[lane]).Conjugate().Rotate(x, y, z, out var rx, out var ry, out var rz);
return (rx, ry, rz);
}
/// <summary>Opens a wound at a world point and normal on <paramref name="part"/>: from now on it sheds its share of the part's bleed, carried by the part.</summary>
public void OpenWound(int part, BodyPoint point, BodyPoint normal)
{
Live();
var (px, py, pz) = ToPart(part, point);
var (nx, ny, nz) = Inverse(_ragdoll.BodyLane(part), normal.X, normal.Y, normal.Z);
_blood.Open(part, px, py, pz, nx, ny, nz);
}

View file

@ -1151,7 +1151,7 @@ public static class Program
var physiologyPlan = Lodur.PhysiologyPlans.Humanoid();
var physiology = new Lodur.Physiology(plan, physiologyPlan, p.SlowScale);
var session = new StressSession(p, 1, plan.SensePoints.Count, OfficeBody.Poses, plan.SenseIndex("Head"), physiology, plan, physiologyPlan);
Check(session.Wound(plan.PartIndex("LowerArm", Lodur.Side.Left), WoundTool.Knife), "the knife was refused");
Check(session.Wound(plan.PartIndex("LowerArm", Lodur.Side.Left), default, WoundTool.Knife), "the knife was refused");
var pts = new float[plan.SensePoints.Count];
var strengths = new float[plan.Joints.Count];
var targets = new Quat[plan.Joints.Count];
@ -1171,26 +1171,25 @@ public static class Program
Check(session.TickIndex - 1 == diedTick + (long)Math.Round(p.ReleaseSeconds / p.TickSeconds), $"the run ended at tick {session.TickIndex - 1}, the death was at {diedTick}");
}),
("office wound refusals: an out-of-range part and a headless session refuse, a tool with no layer the part has is refused, and a palm takes the knife on skin and muscle without fat", () =>
("office wound refusals: an out-of-range part and a headless session refuse, and a palm takes the knife on skin, muscle and metacarpals", () =>
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
using (var s = new OfficeBodySession(p, 1))
{
Check(!s.Wound(new PartHit(-1, default, default), WoundTool.Knife) && !s.Wound(new PartHit(SeatedPuppet.Plan.Parts.Count, default, default), WoundTool.Knife), "an out-of-range part was wounded");
}
Check(!NewOffice(p, 1).Wound(0, WoundTool.Knife), "a headless session was wounded");
Check(!NewOffice(p, 1).Wound(0, default, WoundTool.Knife), "a headless session was wounded");
var plan = SeatedPuppet.Plan;
var physiologyPlan = Lodur.PhysiologyPlans.Humanoid();
var physiology = new Lodur.Physiology(plan, physiologyPlan, p.SlowScale);
var session = new StressSession(p, 1, plan.SensePoints.Count, OfficeBody.Poses, plan.SenseIndex("Head"), physiology, plan, physiologyPlan);
int palm = plan.PartIndex("Palm", Lodur.Side.Left);
Check(!session.Wound(palm, new WoundTool(new[] { "Fat" }, 60.0)), "a palm took a fat-only wound");
Check(session.Wound(palm, WoundTool.Knife), "the palm refused the knife");
Check(session.Wound(palm, default, WoundTool.Knife), "the palm refused the knife");
var pts = new float[plan.SensePoints.Count];
session.Tick(pts, pts, pts, new float[plan.Joints.Count], new Quat[plan.Joints.Count]);
Check(physiology.Integrity(palm, physiology.TissueIndex(palm, "Skin")) < 1.0 && physiology.Integrity(palm, physiology.TissueIndex(palm, "Muscle")) < 1.0, "the palm's skin or muscle is unhurt");
Check(physiology.Integrity(palm, physiology.TissueIndex(palm, "Metacarpals")) == 1.0, "the palm's metacarpals were hurt");
Check(physiology.Integrity(palm, physiology.TissueIndex(palm, "Metacarpals")) < 1.0, "the palm's metacarpals were not hurt");
}),
("office slow clock: SlowScale reaches the physiology, so a skin wound's bleed ends (it heals on the acute clock) and the blood regrows sooner the larger the scale: 1 > 20 > 1000 ticks to recover", () =>
@ -1200,7 +1199,7 @@ public static class Program
long Recovered(double scale)
{
using var s = new OfficeBodySession(p with { SlowScale = scale }, 1);
Check(s.Wound(Hit(s, arm), new WoundTool(new[] { "Skin" }, 0.006)), "the skin wound was refused");
Check(s.Wound(Hit(s, arm), new WoundTool(0.001, 0.006)), "the skin wound was refused");
bool bled = false;
while (!s.Finished)
{
@ -1239,7 +1238,7 @@ public static class Program
}
using (var s = new OfficeBodySession(p, 1))
{
Check(s.Wound(Hit(s, SeatedPuppet.Plan.PartIndex("Torso", Lodur.Side.Center)), new WoundTool(new[] { "LungLeft", "LungRight" }, 15.0)), "the lungs were refused");
Check(s.Wound(HitAt(s, SeatedPuppet.Plan.PartIndex("Torso", Lodur.Side.Center), (0f, 0.07f, -0.09f), alongZ: true), new WoundTool(0.065, 15.0)), "the lungs were refused");
double maxHunger = 0.0;
while (!s.Finished)
{
@ -1293,33 +1292,33 @@ public static class Program
var physiologyPlan = Lodur.PhysiologyPlans.Humanoid();
var physiology = new Lodur.Physiology(plan, physiologyPlan, p.SlowScale);
var session = new StressSession(p, 1, plan.SensePoints.Count, OfficeBody.Poses, plan.SenseIndex("Head"), physiology, plan, physiologyPlan);
var skin = new WoundTool(new[] { "Skin" }, 1.0);
var skin = new WoundTool(0.001, 1.0);
int knives = physiologyPlan.AfflictionSlots / 3;
for (int i = 0; i < knives; i++) Check(session.Wound(arm, WoundTool.Knife), $"knife {i} was refused with room left");
for (int i = 0; i < knives; i++) Check(session.Wound(arm, default, WoundTool.Knife), $"knife {i} was refused with room left");
int free = physiologyPlan.AfflictionSlots - 3 * knives;
Check(free > 0 && free < 3, $"the table has {free} slots free; the test needs one or two");
Check(!session.Wound(arm, WoundTool.Knife), "a knife that does not fit was accepted");
for (int i = 0; i < free; i++) Check(session.Wound(arm, skin), $"the refused knife took a slot: skin wound {i} was refused");
Check(!session.Wound(arm, skin), "the table took more wounds than it has slots");
Check(!session.Wound(arm, default, WoundTool.Knife), "a knife that does not fit was accepted");
for (int i = 0; i < free; i++) Check(session.Wound(arm, default, skin), $"the refused knife took a slot: skin wound {i} was refused");
Check(!session.Wound(arm, default, skin), "the table took more wounds than it has slots");
var foreign = new Lodur.Physiology(plan, physiologyPlan, p.SlowScale);
var shared = new StressSession(p, 1, plan.SensePoints.Count, OfficeBody.Poses, plan.SenseIndex("Head"), foreign, plan, physiologyPlan);
for (int i = 0; i < physiologyPlan.AfflictionSlots; i++) Check(foreign.Afflict(physiologyPlan.AfflictionIndex("Cut"), arm, 0, 1.0), "the table filled early");
int refused = foreign.Refused;
Check(!shared.Wound(arm, skin), "a wound the physiology had no room for was accepted");
Check(!shared.Wound(arm, default, skin), "a wound the physiology had no room for was accepted");
Check(foreign.Refused == refused + 1, "the full table's refusal is the physiology's, counted once");
var healing = new Lodur.Physiology(plan, physiologyPlan, p.SlowScale);
var healer = new StressSession(p, 1, plan.SensePoints.Count, OfficeBody.Poses, plan.SenseIndex("Head"), healing, plan, physiologyPlan);
var graze = new WoundTool(new[] { "Skin" }, 1e-3);
for (int i = 0; i < physiologyPlan.AfflictionSlots; i++) Check(healer.Wound(arm, graze), $"graze {i} was refused with room left");
Check(!healer.Wound(arm, graze), "the table took more wounds than it has slots");
var graze = new WoundTool(0.001, 1e-3);
for (int i = 0; i < physiologyPlan.AfflictionSlots; i++) Check(healer.Wound(arm, default, graze), $"graze {i} was refused with room left");
Check(!healer.Wound(arm, default, graze), "the table took more wounds than it has slots");
var sensed = new float[plan.SensePoints.Count];
var strengths = new float[plan.Joints.Count];
var targets = new Lodur.Quat[plan.Joints.Count];
for (int t = 0; t < 2000 && !healer.Wound(arm, graze); t++) healer.Tick(sensed, sensed, sensed, strengths, targets);
for (int t = 0; t < 2000 && !healer.Wound(arm, default, graze); t++) healer.Tick(sensed, sensed, sensed, strengths, targets);
Check(!healer.Finished, "the run ended before the grazes healed");
Check(healer.Wound(arm, graze), "healed wounds did not free their room: the session still counts them");
Check(healer.Wound(arm, default, graze), "healed wounds did not free their room: the session still counts them");
}),
("SeatedBody hands out no ragdoll: nothing public returns or takes a Ragdoll, so DriveAndStep is the one driver", () =>
@ -1457,6 +1456,56 @@ 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}");
}),
("office throat click reaches the larynx and fills the airway: HitAt(Head, the front of the throat), Wound(hit, Knife) at tick 0 puts more than 20 mL in the airway within 5 s, occludes it fully before the death, and the death is BloodLoss", () =>
{
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;
while (!s.Dead && !s.Finished)
{
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;
}
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");
Check(liquidAt5 > 20e-6, $"the airway held {liquidAt5 * 1e6:F2} mL by 5 s");
Check(occludedAt >= 0.0 && maxOcclusion >= 0.99, $"the airway never filled: occlusion peaked at {maxOcclusion:F3}");
Check(s.Dead && s.DeathCause == Lodur.DeathCause.BloodLoss, $"cause {s.DeathCause}");
}),
("office reach by point: the throat front cuts the larynx and not the neck muscle; the chin cuts the muscle and not the larynx", () =>
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
var plan = SeatedPuppet.Plan;
var physiologyPlan = Lodur.PhysiologyPlans.Humanoid();
int head = plan.PartIndex("Head", Lodur.Side.Center);
foreach (var (point, larynx, muscle) in new[] { ((0f, -0.0778f, 0.0778f), true, false), ((0f, -0.11f, 0f), false, true) })
{
var physiology = new Lodur.Physiology(plan, physiologyPlan, p.SlowScale);
var session = new StressSession(p, 1, plan.SensePoints.Count, OfficeBody.Poses, plan.SenseIndex("Head"), physiology, plan, physiologyPlan);
Check(session.Wound(head, point, WoundTool.Knife), "the knife was refused");
var pts = new float[plan.SensePoints.Count];
session.Tick(pts, pts, pts, new float[plan.Joints.Count], new Quat[plan.Joints.Count]);
bool cutLarynx = physiology.Integrity(head, physiology.TissueIndex(head, "Larynx")) < 1.0;
bool cutMuscle = physiology.Integrity(head, physiology.TissueIndex(head, "Muscle")) < 1.0;
Check(cutLarynx == larynx && cutMuscle == muscle, $"at {point}: larynx cut {cutLarynx}, muscle cut {cutMuscle}");
}
}),
("WoundTool refuses a depth that is 0, negative, NaN or infinite, and the knife is 2 cm", () =>
{
foreach (double depth in new[] { 0.0, -0.01, double.NaN, double.PositiveInfinity, double.NegativeInfinity })
{
bool threw = false;
try { _ = new WoundTool(depth, 60.0); } catch (ArgumentException) { threw = true; }
Check(threw, $"a depth of {depth} was accepted");
}
Check(WoundTool.Knife.Depth == 0.02 && WoundTool.Knife.Severity == 60.0, "the knife changed");
}),
("office blood is conserved to death and the death tick's blood is shed: one Knife (and three on one point), run to Finished, Emitted + Backlog == Gain x the real spill within 1e-9 m^3 (the dying step bleeds, though Bleed reads 0 once dead)", () =>
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
@ -1478,7 +1527,7 @@ public static class Program
{
var p = new StressParameters { TickSeconds = OfficeBody.TickSeconds };
using var s = new OfficeBodySession(p, 1);
Check(s.Wound(Hit(s, SeatedPuppet.Plan.PartIndex("LowerArm", Lodur.Side.Left)), new WoundTool(new[] { "Skin", "Muscle" }, 3.0)), "the wound was refused");
Check(s.Wound(Hit(s, SeatedPuppet.Plan.PartIndex("LowerArm", Lodur.Side.Left)), new WoundTool(WoundTool.Knife.Depth, 3.0)), "the wound was refused");
double before = 0.0;
while (!s.Finished) { s.Step(); if (s.TickIndex == 100) before = s.BloodEmitted; }
Check(!s.Dead && s.BloodEmitted > before + 1e-3, "the wound was not bleeding at the end of the run");
@ -1708,6 +1757,31 @@ public static class Program
throw new InvalidOperationException($"no ray from outside meets part {part} first");
}
/// <summary>
/// A hit on <paramref name="part"/> at <paramref name="local"/> (the part's frame) as it now stands: a ray from 0.5 m outside that point, in along the
/// outward direction (or along +z from behind when <paramref name="alongZ"/>), on through it; the ray must meet the part first.
/// </summary>
private static PartHit HitAt(OfficeBodySession s, int part, (float X, float Y, float Z) local, bool alongZ = false)
{
var v = s.View;
ulong id = SeatedPuppet.FirstStableId + (ulong)part;
int lane = -1;
for (int i = 0; i < v.StableId.Length; i++) if (v.StableId[i] == id) { lane = i; break; }
Check(lane >= 0, $"part {part} has no lane");
var q = new Quat(v.RotationX[lane], v.RotationY[lane], v.RotationZ[lane], v.RotationW[lane]);
q.Rotate(local.X, local.Y, local.Z, out var ox, out var oy, out var oz);
float wx = v.PositionX[lane] + ox, wy = v.PositionY[lane] + oy, wz = v.PositionZ[lane] + oz;
float dx = 0f, dy = 0f, dz = 1f;
if (!alongZ)
{
float len = MathF.Sqrt(ox * ox + oy * oy + oz * oz);
dx = -ox / len; dy = -oy / len; dz = -oz / len; // travelling inward
}
var hit = s.Pick(new BodyPoint(wx - 0.5f * dx, wy - 0.5f * dy, wz - 0.5f * dz), new BodyPoint(dx, dy, dz));
Check(hit is { } h && h.Part == part, $"a ray at part {part} met something else first");
return hit!.Value;
}
/// <summary>A hit on the head at the plan's Mouth opening: a ray from 1 m in front of it, straight back and on through it.</summary>
private static PartHit MouthHit(OfficeBodySession s)
{