This commit is contained in:
Dandaedre 2026-08-22 23:37:56 +02:00
parent b59805a3b5
commit e5c4098a79
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
7 changed files with 708 additions and 0 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@ _things
desktop.ini
.DS_Store
timings.json
rust_base
# Tests and benchmarks
tests/store

View File

@ -57,3 +57,32 @@ temporary plaintext PDF, protects it with `qpdf` and `MASTER_PASSWORD`, deletes
the plaintext intermediate, then archives and publishes only
`Ravenous_master_balance_report_build.pdf`. The stable deployed filename is
`Ravenous_master_balance_report.pdf`.
The advanced creature-by-creature section reproduces the combat model from
`rust_base/monsters` directly in Typst. Configure it in
`data/config/balance_report_master.yaml`:
```yaml
advanced_balance:
creature_ids: [] # Every master-visible creature
show_extra: true # Include alternate player stances
show_balanced: true # Keep rows already matching their targets
diagnostic_rows_per_page: 18
attack_rows_per_page: 60 # Portrait pagination limit
```
`creature_ids` is only a narrowing filter over the master-visible collection.
It never overrides `show_to_master`: requesting a hidden or unknown ID cannot
make that creature appear in the report.
The calculations and presentation are kept in separate modules, so later
metrics can reuse the same normalized defense and attack records without
changing the report tables.
The advanced section also includes an independent heuristic attack diagnosis.
It compares success depth and defensive thresholds within each Difficulty,
measures one- and two-success damage, estimates the chance of producing enough
defensive successes to survive, checks every player stance against an
unmitigated hit, and proposes archetypes such as Thrashing, Defense Check, Tank
Buster, or Nuke. These inferred labels are shown beside—not substituted for—the
attack type declared in the database.

View File

@ -7,6 +7,7 @@
)
#import "/setup/analysis/creature_durability_report.typ": render-durability-report
#import "/setup/analysis/creature_reward_report.typ": render-creature-reward-analysis
#import "/setup/analysis/creature_advanced_report.typ": render-advanced-creature-analysis
#let report-config = yaml("/data/config/balance_report_master.yaml")
#let enabled-chapters = report-config.chapters
@ -67,3 +68,6 @@
render-common-region-report(map-config: report-config.at("regional_map", default: none))
}
#if chapter-enabled("creatures.durability") { render-durability-report() }
#if chapter-enabled("creatures.advanced") {
render-advanced-creature-analysis(report-config.at("advanced_balance", default: (:)))
}

View File

@ -7,6 +7,16 @@ chapters:
- creatures.rewards.analysis
- creatures.common.regions
- creatures.durability
- creatures.advanced
# Creature-by-creature compatibility report matching `ravenous-tools monsters
# balance`. An empty creature_ids list analyzes every master-visible creature.
advanced_balance:
creature_ids: []
show_extra: true
show_balanced: true
diagnostic_rows_per_page: 18
attack_rows_per_page: 60
# Coordinates are percentages of the map width and height, measured from the
# top-left corner. A database region omitted here is automatically listed in

View File

@ -0,0 +1,380 @@
// Creature-by-creature combat metrics compatible with rust_base/monsters.
// Quirks from the reference implementation are intentionally isolated here so
// a future corrected model can coexist without changing report presentation.
#import "../generation/creature-data.typ": master-creatures, player-balancing-rows
#let compatibility-model = "rust_base"
#let clamp(value, minimum, maximum) = calc.min(calc.max(value, minimum), maximum)
#let number(value, fallback: 0) = if value == none or value == "" { fallback } else { int(str(value)) }
#let tagged-number(value, suffix) = if value == none or value == "" { 0 } else {
let cleaned = str(value).replace(suffix, "").trim()
if cleaned.match(regex("^-?\\d+$")) == none { 0 } else { int(cleaned) }
}
#let damage-vector(value) = if value == none or value == "" { () } else {
let cleaned = str(value).trim()
// Rust collects parsed segments through Option<Vec<_>>: one malformed
// segment invalidates the complete damage profile instead of aborting.
if cleaned.match(regex("^-?\\d+(?:/-?\\d+)*$")) == none { () } else {
cleaned.split("/").map(int)
}
}
#let category-or(value, fallback) = if value == none or value == "" { fallback } else { str(value) }
#let binomial-distribution(threshold, dice) = {
if dice <= 0 { return ((successes: 0, probability: 1.0),) }
let probability = clamp(threshold / 10, 0.0000000001, 0.9999999999)
range(dice + 1).map(successes => (
successes: successes,
probability: calc.binom(dice, successes)
* calc.pow(probability, successes)
* calc.pow(1 - probability, dice - successes),
))
}
#let damage-at-successes(profile, successes) = {
if successes <= 0 or profile.len() == 0 { 0 } else {
profile.at(clamp(successes - 1, 0, profile.len() - 1))
}
}
#let expected-damage(profile, threshold, dice) = binomial-distribution(threshold, dice).map(item => (
damage-at-successes(profile, item.successes) * item.probability
)).sum()
#let resistance-value(value) = if value == none { 0 } else {
str(value).clusters().map(char => if char == "+" { 2 } else if char == "-" { -2 } else { 0 }).sum()
}
#let worst-physical-resistance(part) = calc.min(
resistance-value(part.slash), resistance-value(part.blunt), resistance-value(part.piercing),
)
#let safe-ratio(numerator, denominator) = if denominator == 0 { none } else { numerator / denominator }
#let safe-sum(values) = if none in values { none } else { values.sum() }
#let rust-ratio(numerator, denominator) = if denominator == 0 and numerator == 0 {
(kind: "nan", value: none)
} else if denominator == 0 {
(kind: "infinite", value: none)
} else { (kind: "finite", value: numerator / denominator) }
#let rust-sum(values) = if values.any(item => item.kind == "nan") {
"NaN"
} else if values.any(item => item.kind == "infinite") {
none
} else { values.map(item => item.value).sum() }
#let damage-category(percent) = {
if percent < 0.01 { "None" }
else if percent < 0.25 { "Chip" }
else if percent < 0.5 { "Moderate" }
else if percent < 0.8 { "High" }
else if percent < 1.0 { "NearDeath" }
else if percent < 1.5 { "Kill" }
else { "Overkill" }
}
// The overlapping 0.5..0.9 and 0.8..1.2 Rust ranges resolve at 0.9 because
// match arms are evaluated in order.
#let armor-category(percent) = {
if percent < 0.01 { "None" }
else if percent < 0.3 { "Chip" }
else if percent < 0.5 { "Moderate" }
else if percent < 0.9 { "High" }
else if percent < 1.2 { "FullBreak" }
else { "Overkill" }
}
#let profile-damage-to-part(part, player, parried, phase, creature-strength) = {
let threshold = part.at("threshold_" + phase) + player.precision
let protection = part.at("protection_" + phase)
let resistance = worst-physical-resistance(part)
// Rust uses 1..max_successes_off (exclusive upper bound).
let damage-profile = range(1, player.max_successes_off).map(value => int(value * player.damage_per_s))
let dice = clamp(player.successes_off - parried, 0, player.successes_off)
let damage-a = calc.max(expected-damage(damage-profile, threshold, dice) - resistance, 0)
let damage-b1 = calc.max(expected-damage(damage-profile, threshold, calc.floor(dice / 2)) - resistance, 0)
let damage-b2 = calc.max(expected-damage(damage-profile, threshold, dice - calc.floor(dice / 2)) - resistance, 0)
let through-a = calc.max(damage-a - protection - creature-strength, 0)
let through-b1 = calc.max(damage-b1 - protection - creature-strength, 0)
let through-b2 = calc.max(damage-b2 - protection - creature-strength, 0)
let ab-a = clamp(damage-a - protection, 0, player.armor_break)
let ab-b1 = clamp(damage-b1 - protection, 0, player.armor_break)
let ab-b2 = clamp(damage-b2 - protection, 0, player.armor_break)
(
hp: calc.max(damage-a, damage-b1 + damage-b2),
armor: calc.max(ab-a, ab-b1 + ab-b2),
through: calc.max(through-a, through-b1 + through-b2),
)
}
#let scaled-damage(value, factor) = (
hp: value.hp * factor, armor: value.armor * factor, through: value.through * factor,
)
#let add-damage(left, right) = (
hp: left.hp + right.hp, armor: left.armor + right.armor, through: left.through + right.through,
)
#let player-profiles(profile-hse) = player-balancing-rows.filter(row => row.profile_hse == profile-hse)
#let player-profile(profile-hse, stance) = player-profiles(profile-hse).find(row => row.profile_stance == stance)
#let defense-row(creature, part, stance, showcase) = {
let balancing = creature.raw.balancing.first()
let player = player-profile(balancing.profile_hse, stance)
let remaining-defense = balancing.average_defensive_successes
let total-p1 = (hp: 0.0, armor: 0.0, through: 0.0)
let total-p2 = (hp: 0.0, armor: 0.0, through: 0.0)
let remaining-players = balancing.player_groupsize
while remaining-players > 0 {
let chunk = calc.min(remaining-players, 1.0)
let parried = calc.min(remaining-defense, player.successes_off)
let p1 = profile-damage-to-part(part, player, parried, "p1", creature.stats.strength)
let p2 = profile-damage-to-part(part, player, parried, "p2", creature.stats.strength)
total-p1 = add-damage(total-p1, scaled-damage(p1, chunk))
total-p2 = add-damage(total-p2, scaled-damage(p2, chunk))
remaining-defense = calc.max(remaining-defense - parried, 0)
remaining-players -= chunk
}
let time-p1 = safe-ratio(part.life_points_p1, total-p1.hp)
let time-p2 = safe-ratio(part.life_points_p2, total-p2.hp)
let through-p1 = calc.max(total-p1.through - creature.stats.strength, 0)
let through-p2 = calc.max(total-p2.through - creature.stats.strength, 0)
(
part: part.body_part_name,
stance: stance,
showcase: showcase,
armor-per-turn: total-p1.armor,
integrity-p1: part.integrity_p1,
time-armor: safe-ratio(part.integrity_p1, total-p1.armor),
target-armor: balancing.time_to_armorbreak,
damage-p1: total-p1.hp,
health-p1: part.life_points_p1,
time-p1: time-p1,
target-p1: balancing.time_to_p2,
damage-p2: total-p2.hp,
health-p2: part.life_points_p2,
time-p2: time-p2,
target-p2: balancing.time_to_kill,
through-p1: total-p1.through,
through-p2: total-p2.through,
time-through: rust-sum((
rust-ratio(part.life_points_p1, through-p1),
rust-ratio(part.life_points_p2, through-p2),
)),
)
}
#let creature-defense-report(creature, show-extra: true) = creature.raw.body-parts.map(part => {
let stances = if show-extra {
((stance: "Neutral", showcase: "Display"), (stance: "Defensive", showcase: "Balancing"), (stance: "Offensive", showcase: "Balancing"))
} else { ((stance: "Neutral", showcase: "Display"),) }
stances.map(item => defense-row(creature, part, item.stance, item.showcase))
}).flatten()
#let attack-report(attack, player, showcase) = {
// Compatibility quirk: Best and Worst both use max(parry, dodge).
let threshold = calc.max(number(attack.threshold_parry), number(attack.threshold_dodge)) + player.specialty_def
let successes = tagged-number(attack.success, "r")
let distribution = binomial-distribution(threshold, player.successes_def)
let successes-left = distribution.map(item => (successes - item.successes) * item.probability).sum()
let damage = damage-vector(attack.damage_regular)
let incoming = distribution.map(item => (
damage-at-successes(damage, successes - item.successes) * item.probability
)).sum()
let tanked = calc.max(incoming - player.protection - player.strength, 0)
let armor-loss = clamp(incoming - player.protection, 0, number(attack.armor_break))
(
attack-id: attack.attack_id,
name: attack.name,
phase: attack.phase,
stance: player.profile_stance,
showcase: showcase,
incoming: incoming,
fatigue: tagged-number(attack.damage_fatigue, "F"),
successes-left: successes-left,
threshold: threshold,
attack-successes: successes,
tanked: tanked,
health: player.health,
damage-category: damage-category(tanked / player.health),
damage-expected: {
let expected = category-or(attack.target_damage_category, "Malformed")
if expected in ("Malformed", "None", "Chip", "Moderate", "High", "NearDeath", "Kill", "Overkill") {
expected
} else { "Malformed" }
},
armor-loss: armor-loss,
integrity: player.integrity,
armor-category: armor-category(armor-loss / player.integrity),
armor-expected: {
let expected = category-or(attack.target_ab_category, "Malformed")
if expected in ("Malformed", "None", "Chip", "Moderate", "High", "FullBreak", "Overkill") {
expected
} else { "Malformed" }
},
)
}
#let creature-attack-report(creature, show-extra: true, show-balanced: true) = {
let balancing = creature.raw.balancing.first()
let profiles = player-profiles(balancing.profile_hse)
creature.raw.abilities.filter(attack => damage-vector(attack.damage_regular).len() > 0).map(attack => {
let target-stance = category-or(attack.target_stance, "Neutral")
let target = profiles.find(player => player.profile_stance == target-stance)
let balancing-row = attack-report(attack, target, "Balancing")
let rows = if show-balanced or balancing-row.damage-category != balancing-row.damage-expected or balancing-row.armor-category != balancing-row.armor-expected {
(balancing-row,)
} else { () }
if show-extra {
rows += profiles.filter(player => player.profile_stance != target-stance).map(player => attack-report(attack, player, "Display"))
}
rows
}).flatten()
}
#let category-rank(category) = (
None: 0, Chip: 1, Moderate: 2, High: 3, NearDeath: 4, Kill: 5, Overkill: 6, Malformed: -1,
).at(category, default: -1)
#let attack-type-labels = (
ATK: "Attaque", TRA: "Thrashing", TBU: "Tank buster", TBZ: "Tank buster zone",
WIP: "Raid wipe", WID: "Raid-wide", AOE: "AOE", CLV: "Cleave", CMB: "Combo",
FLR: "Flurry", GRB: "Saisie", BYP: "Bypass", TSH: "Tank shred", ASE: "Setup",
BIS: "Best action", BAD: "Bad action",
)
#let deterministic-hit(attack, player, remaining-successes) = {
let incoming = damage-at-successes(damage-vector(attack.damage_regular), remaining-successes)
let tanked = calc.max(incoming - player.protection - player.strength, 0)
(
incoming: incoming,
tanked: tanked,
ratio: tanked / player.health,
category: damage-category(tanked / player.health),
survives: tanked < player.health,
)
}
#let defense-required-to-survive(attack, player) = {
let successes = tagged-number(attack.success, "r")
let found = range(successes + 1).find(defended => (
deterministic-hit(attack, player, calc.max(successes - defended, 0)).survives
))
if found == none { successes + 1 } else { found }
}
#let survival-probability(attack, player, required) = {
let threshold = calc.max(number(attack.threshold_parry), number(attack.threshold_dodge)) + player.specialty_def
let outcomes = binomial-distribution(threshold, player.successes_def).filter(item => item.successes >= required)
if outcomes.len() == 0 { 0.0 } else { outcomes.map(item => item.probability).sum() }
}
#let attack-group-members(creature, attack) = {
let group = if attack.attack_group == none { "" } else { str(attack.attack_group).trim() }
if group == "" { (attack,) } else {
creature.raw.abilities.filter(item => (
item.phase == attack.phase
and item.attack_group != none
and str(item.attack_group).trim() == group
and damage-vector(item.damage_regular).len() > 0
))
}
}
#let diagnostic-base(creature, attack) = {
let balancing = creature.raw.balancing.first()
let profiles = player-profiles(balancing.profile_hse)
let target-stance = category-or(attack.target_stance, "Neutral")
let target = profiles.find(profile => profile.profile_stance == target-stance)
let successes = tagged-number(attack.success, "r")
let one = deterministic-hit(attack, target, 1)
let two = deterministic-hit(attack, target, calc.min(2, successes))
let maximum = deterministic-hit(attack, target, successes)
let survival = profiles.map(profile => (
stance: profile.profile_stance,
..deterministic-hit(attack, profile, successes),
))
let survivors = survival.filter(item => item.survives).len()
let required = defense-required-to-survive(attack, target)
let threshold = calc.max(number(attack.threshold_parry), number(attack.threshold_dodge)) + target.specialty_def
let group = attack-group-members(creature, attack)
let group-successes = group.map(item => tagged-number(item.success, "r")).sorted().rev()
let expected = attack-report(attack, target, "Balancing")
(
creature-id: creature.id,
creature: creature.name,
difficulty: balancing.profile_hse,
attack-id: attack.attack_id,
name: attack.name,
phase: attack.phase,
group: if attack.attack_group == none or str(attack.attack_group).trim() == "" { "—" } else { str(attack.attack_group) },
group-size: group.len(),
group-rank: group-successes.position(value => value == successes) + 1,
declared-type: category-or(attack.attack_type, "—"),
declared-label: attack-type-labels.at(category-or(attack.attack_type, ""), default: category-or(attack.attack_type, "—")),
target-stance: target-stance,
successes: successes,
threshold: threshold,
defense-required: required,
defense-dice: target.successes_def,
survival-probability: survival-probability(attack, target, required),
one: one,
two: two,
maximum: maximum,
survivors: survivors,
profile-count: profiles.len(),
survival: survival,
expected-category: expected.damage-category,
)
}
#let all-diagnostic-bases = master-creatures.map(creature => creature.raw.abilities.filter(attack => (
damage-vector(attack.damage_regular).len() > 0
)).map(attack => diagnostic-base(creature, attack))).flatten()
#let diagnostic-cohort(item) = all-diagnostic-bases.filter(other => other.difficulty == item.difficulty)
#let diagnostic-average(values) = if values.len() == 0 { none } else { values.sum() / values.len() }
#let diagnostic-deviation(values) = if values.len() < 2 { 0 } else {
let mean = diagnostic-average(values)
calc.sqrt(values.map(value => calc.pow(value - mean, 2)).sum() / values.len())
}
#let heuristic-tags(item) = {
let tags = ()
let max-rank = category-rank(item.maximum.category)
let expected-rank = category-rank(item.expected-category)
if item.survivors == 0 or item.maximum.ratio >= 2 { tags.push("Nuke") }
if (
item.survival.find(profile => profile.stance == "Defensive").survives
and item.survivors <= calc.max(2, calc.floor(item.profile-count / 2))
and max-rank >= category-rank("Kill")
) { tags.push("Tank buster") }
if max-rank >= category-rank("Kill") and expected-rank <= category-rank("Moderate") {
tags.push("Contrôle de défense")
}
if item.one.ratio < 0.25 and item.maximum.ratio < 1 and item.maximum.ratio >= 0.25 {
tags.push("Thrashing")
}
if item.one.ratio < 0.25 and item.two.ratio >= 0.25 { tags.push("Pression progressive") }
if item.one.ratio >= 1 { tags.push("Exécution immédiate") }
if item.defense-required >= 3 { tags.push("Pêche profonde") }
if item.threshold <= 5 and item.defense-required > 0 { tags.push("Pêche difficile") }
if item.maximum.ratio < 0.25 { tags.push("Faible menace directe") }
if tags.len() == 0 { tags.push("Pression standard") }
tags
}
#let attack-diagnostics = all-diagnostic-bases.map(item => {
let cohort = diagnostic-cohort(item)
let success-values = cohort.map(other => other.successes)
let threshold-values = cohort.map(other => other.threshold)
let success-deviation = diagnostic-deviation(success-values)
let threshold-deviation = diagnostic-deviation(threshold-values)
item + (
success-z: if success-deviation == 0 { 0 } else { (item.successes - diagnostic-average(success-values)) / success-deviation },
threshold-z: if threshold-deviation == 0 { 0 } else { (item.threshold - diagnostic-average(threshold-values)) / threshold-deviation },
tags: heuristic-tags(item),
)
})
#let creature-attack-diagnostics(creature-id) = attack-diagnostics.filter(item => item.creature-id == creature-id)
#let advanced-creature-analysis(creature, show-extra: true, show-balanced: true) = (
creature: creature,
model: compatibility-model,
defense: creature-defense-report(creature, show-extra: show-extra),
attacks: creature-attack-report(creature, show-extra: show-extra, show-balanced: show-balanced),
diagnostics: creature-attack-diagnostics(creature.id),
)
#let advanced-analysis(creature-ids: (), show-extra: true, show-balanced: true) = master-creatures.filter(creature => (
creature-ids.len() == 0 or creature.id in creature-ids
)).map(creature => advanced-creature-analysis(
creature, show-extra: show-extra, show-balanced: show-balanced,
))

View File

@ -0,0 +1,231 @@
// Portrait, paginated presentation of Rust-compatible creature balancing.
#import "creature_advanced_metrics.typ": advanced-analysis
#import "creature_common_report.typ": compact-profile
#import "report_style.typ": report-theme
#import "../theme/tables.typ" as tables
#let decimal(value, digits: 1) = if value == none { "⇑⇑⇑⇑T" } else if value == "NaN" {
"NaN"
} else {
let rounded = calc.round(value, digits: digits)
if digits == 1 and calc.rem(rounded, 1) == 0 {
str(int(rounded)) + ".0"
} else { str(rounded) }
}
#let ratio(value, total) = decimal(value) + "/" + str(total)
#let turns(value, target) = decimal(value) + "/" + decimal(target, digits: 0) + "t"
#let stance-label(stance) = (
Neutral: "Neutral", Defensive: "Defensive", Offensive: "Offensive", NoDefense: "NoDefense",
).at(stance, default: stance)
#let stance-short(stance) = (
Neutral: "N", Defensive: "D", Offensive: "O", NoDefense: "ND",
).at(stance, default: stance)
#let expected-label(actual, expected) = if actual == expected {
box(
inset: (x: 2.5pt, y: 0.6pt), radius: 2.5pt,
fill: rgb("#4F805A").transparentize(78%),
stroke: 0.4pt + rgb("#4F805A"),
)[#text(fill: rgb("#31573A"), weight: "bold")[#expected]]
} else {
box(
inset: (x: 2pt, y: 0.5pt), radius: 2pt,
fill: report-theme.chart-1.transparentize(82%),
stroke: 0.35pt + report-theme.chart-1,
)[#expected]
}
#let attack-row-label(row) = if row.showcase == "Balancing" {
[#row.name #text(size: 0.88em, weight: "bold", fill: report-theme.heading-accent)[(#(stance-short(row.stance)))]]
} else {
box(inset: (left: 7pt))[#text(fill: report-theme.muted-ink)[#stance-label(row.stance)]]
}
#let secondary-value(row, value) = if row.showcase == "Balancing" {
value
} else { text(fill: report-theme.muted-ink, value) }
#let defense-row-label(row) = if row.stance == "Neutral" {
[#row.part #text(size: 0.88em, weight: "bold", fill: report-theme.heading-accent)[(N)]]
} else {
box(inset: (left: 7pt))[#text(fill: report-theme.muted-ink)[#stance-label(row.stance)]]
}
#let defense-secondary-value(row, value) = if row.stance == "Neutral" {
value
} else { text(fill: report-theme.muted-ink, value) }
#let percent-number(value) = str(calc.round(value * 100)) + "%"
#let diagnostic-colors = (
"Nuke": rgb("#7A2424"),
"Tank buster": rgb("#A44632"),
"Contrôle de défense": rgb("#57486F"),
"Thrashing": rgb("#A66A32"),
"Pression progressive": rgb("#70582F"),
"Exécution immédiate": rgb("#8D263D"),
"Pêche profonde": rgb("#365F82"),
"Pêche difficile": rgb("#62517B"),
"Faible menace directe": rgb("#6B716D"),
"Pression standard": rgb("#4F805A"),
)
#let diagnostic-pill(label, count: none) = {
let color = diagnostic-colors.at(label, default: report-theme.heading-accent)
box(
inset: (x: 2.5pt, y: 0.65pt), radius: 2.5pt,
fill: color.transparentize(80%), stroke: 0.4pt + color,
)[#text(size: 4.8pt, weight: "bold", fill: color.darken(18%))[
#label#if count != none { [ · #count] }
]]
}
#let diagnostic-pills(tags) = tags.map(tag => diagnostic-pill(tag)).join(h(2pt))
#let heuristic-summary(diagnostics) = if diagnostics.len() > 0 {
let tags = diagnostics.map(item => item.tags).flatten().dedup()
let counts = tags.map(tag => (
label: tag, count: diagnostics.filter(item => tag in item.tags).len(),
)).sorted(key: item => -item.count)
let alerts = diagnostics.sorted(key: item => -item.maximum.ratio).slice(0, calc.min(3, diagnostics.len()))
block(
width: 100%, inset: 5pt, radius: 2pt,
fill: report-theme.parchment.transparentize(35%),
stroke: 0.45pt + report-theme.border,
)[
#text(size: 5.4pt)[*Archétypes observés* #h(3pt)
#counts.map(item => diagnostic-pill(item.label, count: item.count)).join(h(2pt))]
#linebreak()
#text(size: 5.2pt, fill: report-theme.muted-ink)[*Pics non mitigés* ·
#alerts.map(item => item.name + " " + decimal(item.maximum.ratio * 100, digits: 0) + "% PV").join(" · ")]
]
}
#let defense-table(rows) = {
let body = rows.map(row => (
defense-row-label(row),
defense-secondary-value(row, ratio(row.armor-per-turn, row.integrity-p1)),
defense-secondary-value(row, turns(row.time-armor, row.target-armor)),
defense-secondary-value(row, ratio(row.damage-p1, row.health-p1)),
defense-secondary-value(row, turns(row.time-p1, row.target-p1)),
defense-secondary-value(row, ratio(row.damage-p2, row.health-p2)),
defense-secondary-value(row, turns(row.time-p2, row.target-p2)),
// The reference renderer intentionally shows DPT P2 in the second slot,
// even though the time after the arrow uses damage-through.
defense-secondary-value(row,
"[" + decimal(row.through-p1, digits: 0) + " & "
+ decimal(row.damage-p2, digits: 0) + "] ⇝ " + decimal(row.time-through),
),
))
tables.set-table-style(
table(
columns: (1.15fr, 0.67fr, 0.65fr, 0.75fr, 0.65fr, 0.75fr, 0.65fr, 1.2fr),
align: (left,) + (right,) * 7,
table.header(
[Partie / profil], [AbPT P1], [TT AB], [DPT P1], [P1 → P2],
[DPT P2], [P2 → †], [P1 ⇝ P2 ⇝ †],
),
..body.flatten(),
),
table-theme: "steingrund", text-size: 5.15pt,
)
}
#let attack-table(rows) = {
let body = rows.map(row => (
attack-row-label(row),
secondary-value(row, decimal(row.incoming) + " [" + str(row.attack-successes) + "r]"),
secondary-value(row, str(row.fatigue)),
secondary-value(row, decimal(row.successes-left) + " [>" + str(row.threshold) + "]"),
secondary-value(row, ratio(row.tanked, row.health)),
secondary-value(row, row.damage-category),
expected-label(row.damage-category, row.damage-expected),
secondary-value(row, ratio(row.armor-loss, row.integrity)),
secondary-value(row, row.armor-category),
expected-label(row.armor-category, row.armor-expected),
))
tables.set-table-style(
table(
columns: (1.3fr, 0.72fr, 0.24fr, 0.67fr, 0.62fr, 0.62fr, 0.62fr, 0.58fr, 0.62fr, 0.62fr),
align: (left, right, center, right, right, left, left, right, left, left),
table.header(
[Nom / profil], [Entrants], [F], [Réussites], [Subis],
[Dég.], [Cible], [Perte arm.], [Armure], [Cible],
),
..body.flatten(),
),
table-theme: "steingrund", text-size: 4.65pt,
)
}
#let diagnostic-table(rows) = {
let body = rows.map(row => (
[#row.name #text(size: 0.86em, fill: report-theme.heading-accent)[(#row.declared-type)]],
if row.group-size == 1 { [—] } else { [#row.group-rank/#row.group-size] },
[#row.successes #text(size: 0.82em, fill: report-theme.muted-ink)[z#decimal(row.success-z)]],
[#row.defense-required/#row.defense-dice · #percent-number(row.survival-probability) · S#row.threshold],
[#decimal(row.one.tanked)/#decimal(row.two.tanked)],
[#row.survivors/#row.profile-count · #row.maximum.category],
diagnostic-pills(row.tags),
))
tables.set-table-style(
table(
columns: (1.35fr, 0.42fr, 0.58fr, 1fr, 0.72fr, 0.85fr, 1.9fr),
align: (left, center, right, right, right, left, left),
table.header(
[Attaque (type déclaré)], [Grp], [R], [Défense], [1R/2R], [Survie/max], [Lecture heuristique],
),
..body.flatten(),
),
table-theme: "steingrund", text-size: 4.8pt,
)
}
#let render-advanced-creature-analysis(config) = {
let creature-ids = config.at("creature_ids", default: ())
let show-extra = config.at("show_extra", default: true)
let show-balanced = config.at("show_balanced", default: true)
let attack-rows-per-page = config.at("attack_rows_per_page", default: 28)
let diagnostic-rows-per-page = config.at("diagnostic_rows_per_page", default: 18)
let analyses = advanced-analysis(
creature-ids: creature-ids,
show-extra: show-extra,
show-balanced: show-balanced,
)
for analysis in analyses {
let creature = analysis.creature
let balancing = creature.raw.balancing.first()
page(paper: "a4", margin: (x: 10mm, y: 10mm))[
#heading(level: 2)[Analyse avancée — #creature.name]
#text(size: 7.4pt, fill: report-theme.muted-ink)[
Modèle de compatibilité #strong(analysis.model) · Difficulté
#compact-profile(balancing.profile_hse) · #balancing.player_groupsize joueurs ·
#balancing.monster_groupsize créature(s). Les lignes Defensive et Offensive
correspondent aux profils supplémentaires demandés par `show_extra`.
]
#heading(level: 3)[Durabilité par partie et profil offensif des joueurs]
#defense-table(analysis.defense)
#heading(level: 3)[Signature offensive — synthèse]
#heuristic-summary(analysis.diagnostics)
]
let diagnostic-chunks = analysis.diagnostics.chunks(diagnostic-rows-per-page)
for (index, rows) in diagnostic-chunks.enumerate() {
page(paper: "a4", margin: (x: 10mm, y: 10mm))[
#heading(level: 3)[Diagnostic heuristique des attaques — #creature.name (#(index + 1)/#diagnostic-chunks.len())]
#text(size: 6.4pt, fill: report-theme.muted-ink)[
*R* : réussites de l’attaque et écart à sa Difficulté. *Défense* : réussites
requises pour survivre / dés disponibles, probabilité d’y parvenir, puis
seuil effectif. *1R/2R* : dégâts subis par la cible à une ou deux réussites.
*Survie/max* : profils survivants sur profils disponibles et catégorie sans
mitigation. Les archétypes sont heuristiques et indépendants du type déclaré.
]
#diagnostic-table(rows)
]
}
let chunks = analysis.attacks.chunks(attack-rows-per-page)
for (index, rows) in chunks.enumerate() {
page(paper: "a4", margin: (x: 10mm, y: 10mm))[
#heading(level: 3)[Létalité des capacités — #creature.name (#(index + 1)/#chunks.len())]
#text(size: 7.2pt, fill: report-theme.muted-ink)[
La première ligne de chaque capacité est son profil cible de balancing;
les suivantes montrent les autres postures. Une cible encadrée signale
que la catégorie calculée diffère de la catégorie attendue en base.
]
#attack-table(rows)
]
}
}
}

View File

@ -0,0 +1,53 @@
#import "/setup/analysis/creature_advanced_metrics.typ": advanced-analysis
#let close(actual, expected, tolerance: 0.06) = assert(
calc.abs(actual - expected) <= tolerance,
message: "Expected " + str(expected) + ", got " + str(actual),
)
#let analysis = advanced-analysis(creature-ids: (20,)).first()
#assert.eq(analysis.defense.len(), 21)
#assert.eq(analysis.attacks.len(), 60)
#assert.eq(analysis.diagnostics.len(), 15)
#let head = analysis.defense.find(row => row.part == "Tête" and row.stance == "Neutral")
#close(head.armor-per-turn, 20.0)
#close(head.time-armor, 3.0)
#close(head.damage-p1, 80.7)
#close(head.time-p1, 3.1)
#close(head.damage-p2, 75.4)
#close(head.time-p2, 3.3)
#let fracture = analysis.attacks.find(row => row.attack-id == 353 and row.stance == "Offensive")
#close(fracture.incoming, 40.0)
#close(fracture.successes-left, 2.0)
#close(fracture.tanked, 27.0)
#assert.eq(fracture.damage-category, "Overkill", message: repr(fracture))
#close(fracture.armor-loss, 2.0)
#assert.eq(fracture.armor-category, "Chip")
#let malformed = analysis.attacks.find(row => row.attack-id == 349 and row.showcase == "Balancing")
#assert.eq(malformed.damage-expected, "Malformed")
#let lance-defense = analysis.defense.find(row => row.part == "Lance" and row.stance == "Defensive")
#assert.eq(lance-defense.time-through, "NaN")
#let grouped-diagnostic = analysis.diagnostics.find(item => item.attack-id == 353)
#assert.eq(grouped-diagnostic.group-size, 3)
#assert.eq(grouped-diagnostic.group-rank, 1)
#assert(grouped-diagnostic.success-z > 0)
// The engine is not specialized for the reference creature.
#let second-creature = advanced-analysis(creature-ids: (1,)).first()
#assert(second-creature.defense.len() > 0)
#assert(second-creature.attacks.len() > 0)
#let arpaneris-diagnostics = advanced-analysis(creature-ids: (12,)).first().diagnostics
#let nuke = arpaneris-diagnostics.find(item => item.name == "Éventrement")
#assert("Nuke" in nuke.tags)
#assert.eq(nuke.survivors, 0)
// Configuration can narrow master visibility, never broaden it.
#let all-visible = advanced-analysis()
#assert(all-visible.all(item => item.creature.show-to-master == 1))
#assert.eq(advanced-analysis(creature-ids: (999999,)), ())
[Advanced creature balancing parity: OK]