StressSession.Wound asks Lodur's Physiology for the all-or-none wound; the session's wound counter is deleted
Wound resolves the tool's layers against the part's stack and returns the span Afflict's answer; room is Physiology's, so a healed wound frees its slot and a table filled behind the session refuses quietly instead of throwing. Tests: foreign fill refuses without a throw (Refused +1); healed grazes free their room. Built against Lodur nibu/lodur-afflict-all b725a97 (unmerged) and Ymir bbc5628. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0f4b3a03a8
commit
c55770f048
2 changed files with 20 additions and 16 deletions
|
|
@ -34,7 +34,6 @@ public sealed class StressSession
|
|||
private Outcome _outcome = Outcome.Endured;
|
||||
private long _endTick;
|
||||
private long _diedTick = -1;
|
||||
private int _wounds;
|
||||
|
||||
/// <param name="poses">What the Brain's goals write, one rotation per muscle; the Actor's muscle count is theirs.</param>
|
||||
/// <param name="physiology">The body's physiology, stepped by the Actor (null: a headless run, nothing can be wounded or die); it needs the <paramref name="body"/> it was built on and its <paramref name="physiologyPlan"/>.</param>
|
||||
|
|
@ -122,32 +121,25 @@ public sealed class StressSession
|
|||
/// 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 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).
|
||||
/// </summary>
|
||||
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<int>();
|
||||
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.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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -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", () =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue