Cut 7 Soul Pass #2 fix: additive WhileAlive + trigger sub-spawn budget
This commit is contained in:
parent
248bb1f053
commit
97c5bab2a6
2 changed files with 63 additions and 6 deletions
|
|
@ -231,7 +231,9 @@ namespace RustToDust.Core
|
|||
visitedSet[node] = (byte)depth;
|
||||
}
|
||||
|
||||
int maxChildSubSpawns = 0;
|
||||
int whileAliveSubSpawns = 0;
|
||||
int maxTriggerSubSpawns = 0;
|
||||
const long BudgetCapSentinel = OrdnanceNodeDef.MaxShotSubSpawnBudget + 1L;
|
||||
|
||||
if (node.WhileAlive is { } wa)
|
||||
{
|
||||
|
|
@ -252,7 +254,7 @@ namespace RustToDust.Core
|
|||
if (childBudget > 0)
|
||||
{
|
||||
int pulses = Math.Clamp(wa.MaxPulses, 1, 32);
|
||||
maxChildSubSpawns = Math.Max(maxChildSubSpawns, pulses * childBudget);
|
||||
whileAliveSubSpawns = (int)Math.Min(BudgetCapSentinel, (long)pulses * childBudget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -281,7 +283,8 @@ namespace RustToDust.Core
|
|||
throw new InvalidOperationException("Split trigger requires non-null ChildNode.");
|
||||
}
|
||||
int childBudget = ValidateNode(tr.ChildNode, depth + 1, activeStack, visited, visitedSet);
|
||||
maxChildSubSpawns = Math.Max(maxChildSubSpawns, tr.SplitCount * Math.Max(1, childBudget));
|
||||
long branchBudget = (long)tr.SplitCount * Math.Max(1, childBudget);
|
||||
maxTriggerSubSpawns = Math.Max(maxTriggerSubSpawns, (int)Math.Min(BudgetCapSentinel, branchBudget));
|
||||
}
|
||||
else if (tr.Action == OrdnanceTriggerAction.Transition)
|
||||
{
|
||||
|
|
@ -290,15 +293,17 @@ namespace RustToDust.Core
|
|||
throw new InvalidOperationException("Transition trigger requires non-null ChildNode.");
|
||||
}
|
||||
int childBudget = ValidateNode(tr.ChildNode, depth + 1, activeStack, visited, visitedSet);
|
||||
maxChildSubSpawns = Math.Max(maxChildSubSpawns, Math.Max(1, childBudget));
|
||||
maxTriggerSubSpawns = Math.Max(maxTriggerSubSpawns, (int)Math.Min(BudgetCapSentinel, (long)Math.Max(1, childBudget)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int totalSubSpawns = (int)Math.Min(BudgetCapSentinel, (long)whileAliveSubSpawns + maxTriggerSubSpawns);
|
||||
|
||||
activeStack.Remove(node);
|
||||
return node.Motion == OrdnanceMotion.HitscanBeam
|
||||
? maxChildSubSpawns
|
||||
: Math.Max(1, maxChildSubSpawns);
|
||||
? totalSubSpawns
|
||||
: Math.Max(1, totalSubSpawns);
|
||||
}
|
||||
|
||||
private static void ValidateFiniteFields(OrdnanceNodeDef n)
|
||||
|
|
|
|||
|
|
@ -927,5 +927,57 @@ namespace RustToDust.Tests
|
|||
Assert.Equal(0f, scrubbedTerminal.PosZ);
|
||||
Assert.Equal(-1, scrubbedTerminal.TargetEntityId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validator_CombinesWhileAliveAndTriggerBudgetsAdditively()
|
||||
{
|
||||
var mine = new OrdnanceNodeDef
|
||||
{
|
||||
Motion = OrdnanceMotion.StationaryMine,
|
||||
MaxLifetime = 6f,
|
||||
DirectDamage = 10f
|
||||
};
|
||||
var pulseBeam = new OrdnanceNodeDef
|
||||
{
|
||||
Motion = OrdnanceMotion.HitscanBeam,
|
||||
Range = 80f,
|
||||
DirectDamage = 5f,
|
||||
Triggers = new[]
|
||||
{
|
||||
new OrdnanceTriggerRule
|
||||
{
|
||||
Kind = OrdnanceTriggerKind.Impact,
|
||||
Action = OrdnanceTriggerAction.Split,
|
||||
SplitCount = 1,
|
||||
ChildNode = mine
|
||||
}
|
||||
}
|
||||
};
|
||||
var combined = new OrdnanceNodeDef
|
||||
{
|
||||
Motion = OrdnanceMotion.LoiterOrbit,
|
||||
MaxLifetime = 5f,
|
||||
WhileAlive = new OrdnanceWhileAliveDef
|
||||
{
|
||||
Interval = 0.25f,
|
||||
MaxPulses = 10,
|
||||
ChildNode = pulseBeam
|
||||
},
|
||||
Triggers = new[]
|
||||
{
|
||||
new OrdnanceTriggerRule
|
||||
{
|
||||
Kind = OrdnanceTriggerKind.Timeout,
|
||||
Threshold = 5f,
|
||||
Action = OrdnanceTriggerAction.Split,
|
||||
SplitCount = 10,
|
||||
ChildNode = mine
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => OrdnanceGraphValidator.ValidateAndFlatten(combined));
|
||||
Assert.Contains("sub-spawn budget", ex.Message, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue