diff --git a/README.md b/README.md index 3a4ec17..a716da3 100644 --- a/README.md +++ b/README.md @@ -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. ``` diff --git a/client/Hud.cs b/client/Hud.cs index f7b13b3..73c6202 100644 --- a/client/Hud.cs +++ b/client/Hud.cs @@ -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"); diff --git a/client/tests/Smoke.cs b/client/tests/Smoke.cs index d4a38ff..d425085 100644 --- a/client/tests/Smoke.cs +++ b/client/tests/Smoke.cs @@ -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); diff --git a/src/BadDay.Core/StressSession.cs b/src/BadDay.Core/StressSession.cs index 71e1ef3..6f02a33 100644 --- a/src/BadDay.Core/StressSession.cs +++ b/src/BadDay.Core/StressSession.cs @@ -117,28 +117,19 @@ public sealed class StressSession } /// - /// 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 , - /// 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 , 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 + /// reaches at (in the part's frame) through the part's PartTissuesDef.Reach, + /// through , 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 , a part the body + /// lacks, or when the physiology has no room for every layer (its answer, not counted here). /// - 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 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 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); } diff --git a/src/BadDay.Core/WoundTool.cs b/src/BadDay.Core/WoundTool.cs index 654d453..e2e1d35 100644 --- a/src/BadDay.Core/WoundTool.cs +++ b/src/BadDay.Core/WoundTool.cs @@ -1,14 +1,31 @@ -using System.Collections.Generic; +using System; namespace BadDay.Core; /// -/// What a wound is made of: one Cut affliction of on each of the named tissue -/// of the part (a part without a layer skips it). Content, not a rule: 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 (m) and a . 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: +/// is the click-cut's [P] until lodur-insult-resolution turns contacts into afflictions (question bds-first-wound-tool). /// -public sealed record WoundTool(IReadOnlyList Layers, double Severity) +public sealed record WoundTool { - /// Skin, fat and muscle cut to the same depth. - public static WoundTool Knife { get; } = new(new[] { "Skin", "Fat", "Muscle" }, 60.0); + /// A tool that cuts m deep (finite and above 0) at . + 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; + } + + /// How deep the tool cuts, in m, through the part's skin outward-in (finite and above 0). + public double Depth { get; } + + /// The severity of the Cut affliction on each reached layer. + public double Severity { get; } + + /// + /// 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. + /// + public static WoundTool Knife { get; } = new(0.02, 60.0); } diff --git a/src/BadDay.Ymir/OfficeBodySession.cs b/src/BadDay.Ymir/OfficeBodySession.cs index f4655ec..21bcec5 100644 --- a/src/BadDay.Ymir/OfficeBodySession.cs +++ b/src/BadDay.Ymir/OfficeBodySession.cs @@ -155,12 +155,14 @@ public sealed class OfficeBodySession : IBodyRun /// /// Wounds the part names from the next tick, and opens the wound at the point it hit so the blood leaves from there; - /// false when refused (see ), and then nothing is opened. + /// the point goes into the part's frame () for the layers the tool's depth reaches there. + /// False when refused (a part outside the plan, or see ), and then nothing is opened. /// 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; } diff --git a/src/BadDay.Ymir/SeatedBody.cs b/src/BadDay.Ymir/SeatedBody.cs index f3bfd65..0a0d5cb 100644 --- a/src/BadDay.Ymir/SeatedBody.cs +++ b/src/BadDay.Ymir/SeatedBody.cs @@ -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)); } - /// Opens a wound at a world point and normal on : from now on it sheds its share of the part's bleed, carried by the part. - public void OpenWound(int part, BodyPoint point, BodyPoint normal) + /// + /// A world point in '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. + /// + 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]); + } + + /// 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. + 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); + } + + /// Opens a wound at a world point and normal on : from now on it sheds its share of the part's bleed, carried by the part. + 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); } diff --git a/tests/BadDay.Tests/Program.cs b/tests/BadDay.Tests/Program.cs index 6003f22..e577d77 100644 --- a/tests/BadDay.Tests/Program.cs +++ b/tests/BadDay.Tests/Program.cs @@ -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"); } + /// + /// A hit on at (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 ), on through it; the ray must meet the part first. + /// + 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; + } + /// 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. private static PartHit MouthHit(OfficeBodySession s) {