diff --git a/src/BadDay.Core/StressSession.cs b/src/BadDay.Core/StressSession.cs
index a6b80a3..5d60544 100644
--- a/src/BadDay.Core/StressSession.cs
+++ b/src/BadDay.Core/StressSession.cs
@@ -34,7 +34,6 @@ public sealed class StressSession
private Outcome _outcome = Outcome.Endured;
private long _endTick;
private long _diedTick = -1;
- private int _wounds;
/// What the Brain's goals write, one rotation per muscle; the Actor's muscle count is theirs.
/// The body's physiology, stepped by the Actor (null: a headless run, nothing can be wounded or die); it needs the it was built on and its .
@@ -122,32 +121,25 @@ public sealed class StressSession
/// 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 affliction table lacks room for every layer. The session counts its
- /// own wounds against the table (it is the only one that wounds its physiology), so a healed wound still counts: the
- /// refusal errs toward full.
+ /// none of whose layers the part has, or when the physiology has no room for every layer (its answer, not counted here).
///
public bool Wound(int part, 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;
- var layers = new List();
+ 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.Add(layer);
+ layers[n++] = layer;
break;
}
}
- if (layers.Count == 0 || _wounds + layers.Count > _physiologyPlan.AfflictionSlots) return false;
- foreach (int layer in layers)
- {
- if (!_physiology.Afflict(_cut, part, layer, tool.Severity)) throw new InvalidOperationException("the physiology's affliction table is full of wounds this session did not make.");
- _wounds++;
- }
- return true;
+ return n > 0 && _physiology.Afflict(_cut, part, layers[..n], tool.Severity);
}
///
diff --git a/tests/BadDay.Tests/Program.cs b/tests/BadDay.Tests/Program.cs
index e4fd65f..2cb7437 100644
--- a/tests/BadDay.Tests/Program.cs
+++ b/tests/BadDay.Tests/Program.cs
@@ -1295,9 +1295,21 @@ public static class Program
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");
- bool threw = false;
- try { shared.Wound(arm, skin); } catch (InvalidOperationException) { threw = true; }
- Check(threw, "a wound the table refused behind the session's count was reported as accepted or refused quietly");
+ int refused = foreign.Refused;
+ Check(!shared.Wound(arm, 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 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);
+ 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");
}),
("SeatedBody hands out no ragdoll: nothing public returns or takes a Ragdoll, so DriveAndStep is the one driver", () =>