OddSmith #4: when a six changes the rules — sustained and lethal hits
Implementing Sustained Hits and Lethal Hits in OddSmith: how one rule challenged the domain design and forced a rethink of the Step model.
OddSmith #4: when a six changes the rules — sustained and lethal hits
In the previous post, I moved OddSmith from the domain into the UI, building the interface with React and keeping the calculation logic separate from the presentation.
This time, I wanted to take the calculator a step further.
The basic sequence was already working: hit, wound, save, damage and an optional additional save. But real Warhammer 40K attacks are not always that straightforward. Some abilities change what happens when a die rolls a natural 6.
Two of them are particularly interesting: Sustained Hits and Lethal Hits.
Implementing them turned out to be more than adding two checkboxes. One of them challenged the way I had originally designed the domain.
Sustained Hits: one roll, an extra die
Let’s start with the simpler one.
Sustained Hits means that a natural 6 when rolling to hit generates an additional hit. That extra hit moves on to the wound roll normally.
I decided to represent this with an optional property on Step:
export type Step = {
threshold: Threshold
countsAs: 'success' | 'failure'
extraOnSix?: number
}
The property represents how many additional dice a natural 6 generates.
The interesting part is that the domain doesn’t need to know anything about Warhammer terminology. It only needs to know that a successful roll can produce an additional die.
The calculation becomes:
success: (p, step) =>
p + (p > 0 ? (step.extraOnSix ?? 0) / 6 : 0)
A natural 6 has a probability of 1/6. Therefore, the expected number of additional dice is simply that probability multiplied by the configured value.
There was one important edge case: a threshold of 7 means that success is impossible. A natural 6 cannot generate an additional die if it isn’t a success in the first place.
I added tests for that case, as well as for failure steps, where the option should be ignored.
This also exposed something worth remembering: Vitest can execute TypeScript tests without checking the actual TypeScript types. I had a typo in the property name (extraOnSyx instead of extraOnSix), and the tests didn’t catch it. The typechecker did.
Another reminder that passing tests and valid types are two different things.
Lethal Hits: when the sequence itself changes
Lethal Hits are a different problem.
A natural 6 when rolling to hit automatically wounds the target. It skips the wound roll, but the resulting wound still goes through the defender’s save.
This is where my original approach started showing its limitations.
Until now, resolveSequence treated every step independently. Each step received a number of dice, applied its probability and passed the result to the next step.
But Lethal Hits introduce a dependency between two consecutive steps.
The result of the hit roll now depends on what happens during the wound roll.
Instead of simply multiplying the probabilities, I needed to separate the natural 6s from the other successful hits.
For each incoming die:
- A natural 6 contributes one automatic wound.
- Other successful hits still roll to wound.
- Additional dice generated by Sustained Hits also roll to wound.
The expected result can be expressed as:
Lethal wounds + (normal hits + extra dice) × wound probability
In the domain, I introduced a function to calculate the combined effect of the two steps:
function lethalPairFactor(step: Step, next: Step): number {
const p = successProbability(step.threshold)
const sixes = p > 0 ? 1 / 6 : 0
const extraDice = (step.extraOnSix ?? 0) * sixes
const otherHits = p - sixes
return sixes + (otherHits + extraDice) * stepProbability(next)
}
The important distinction is that the original natural 6 skips the wound roll, while the additional dice generated by Sustained Hits do not.
They are still ordinary hits.
Making the sequence aware of its next step
With the new calculation in place, resolveSequence needed a small structural change.
Instead of using a for...of loop, I introduced an index-based while loop.
Why?
Because when a step has Lethal Hits enabled, the function must process it together with the following step, then advance two positions instead of one.
Conceptually:
while (index < steps.length) {
const step = steps[index]
const next = steps[index + 1]
if (hasLethalNext(step, next)) {
count *= lethalPairFactor(step, next)
index += 2
} else {
count *= stepProbability(step)
index += 1
}
}
The rest of the sequence remains intact.
This is important because skipping the wound roll doesn’t mean skipping everything after it. The defender’s save is still calculated normally.
It also means that the domain doesn’t need to know whether a step is called Hit, Wound or Save. It only needs the information contained in the data.
Combining both abilities
The most interesting part was making both rules work together.
The natural 6 generates an automatic wound, while the additional die from Sustained Hits continues through the normal wound roll.
I deliberately tested this with values that make the difference visible.
Using 10 attacks, hitting on 4+ and wounding on 3+:
| Configuration | Expected wounds |
|---|---|
| No special rules | 3.33 |
| Sustained Hits | 4.44 |
| Lethal Hits | 3.89 |
| Both abilities | 5.00 |
One detail worth mentioning: using a 4+ wound threshold would make Sustained and Lethal Hits produce the same expected result in this particular comparison.
That’s why choosing the right test data matters. A test can pass while still failing to distinguish between two different implementations.
What I learned
This change reinforced a few things.
Not every feature is just another condition.
Sustained Hits fitted naturally into the existing probability model. Lethal Hits required the sequence itself to become aware of relationships between consecutive steps.
Trying to force both into the same simple multiplication would have made the code misleading.
The domain should model behaviour, not UI labels.
The UI can call an option Sustained Hits or Lethal Hits. The domain only needs to understand additional dice and steps that can be skipped.
Tests need to distinguish between implementations.
Choosing a threshold of 4+ for every test would have hidden an important difference between the two abilities. Good test data is just as important as good assertions.
Typechecking is not optional.
The extraOnSyx typo was a small mistake, but it reminded me why I run lint, typechecking and tests independently.
What’s next
There is still one design issue to resolve.
The interface currently displays the probability of an attack continuing after each step. That representation made sense when every step was independent.
With Lethal Hits, however, the hit and wound steps are now linked. Displaying an isolated probability for each one can be misleading.
I need to rethink how to present that information, possibly replacing the probability badge with a multiplier or a more useful breakdown of the expected results.
The goal remains the same: not just calculate the final number, but make it possible to understand where it comes from.