591 lines
19 KiB
Plaintext
591 lines
19 KiB
Plaintext
// Failure-tolerant extraction of weapon-like profiles from school skill trees.
|
||
#import "weapon_metrics.typ": (
|
||
all-weapon-metrics, analyze-weapon-profile, commitment-pools,
|
||
natural-precision,
|
||
)
|
||
#import "report_config.typ": class-weapon-settings
|
||
#import "../build_config.typ": tier-is-enabled
|
||
#import "../generation/radar_graphs.typ": school-sources
|
||
#import "origin_metrics.typ": origin-sources
|
||
|
||
#let damage-profile-pattern = "(?i)(#cr\\.(?:force|psy)|F|Psy|[0-9]+)\\s*(?:@rl_(?:finale|de_base)\\s*)?/\\+([0-9]+)"
|
||
#let dice-damage-profile-pattern = "(?i)[0-9]+d[0-9]+\\s*\\+\\s*#cr\\.(?:force|psy)(?:\\s+@rl_(?:finale|de_base))?\\s+d[ée]g[âa]ts"
|
||
|
||
#let capture(text, pattern, index: 0) = {
|
||
let found = text.match(regex(pattern))
|
||
if found == none { none } else { found.captures.at(index, default: none) }
|
||
}
|
||
|
||
#let capture-first(text, patterns) = {
|
||
let result = none
|
||
for pattern in patterns {
|
||
if result == none { result = capture(text, pattern) }
|
||
}
|
||
result
|
||
}
|
||
|
||
#let configured-base(symbol) = class-weapon-settings.characteristic_values.at(
|
||
if symbol == "#cr.force" { "F" } else if symbol == "#cr.psy" { "Psy" } else {
|
||
symbol
|
||
},
|
||
default: none,
|
||
)
|
||
|
||
#let french-count(value) = if value == none { none } else {
|
||
if value == "un" or value == "une" or value == "Un" or value == "Une" {
|
||
1
|
||
} else { int(value) }
|
||
}
|
||
|
||
#let parse-school-attacks(school, display, source) = {
|
||
let rows = csv(source, delimiter: "\t")
|
||
let current-tier = none
|
||
let effect-column = none
|
||
let results = ()
|
||
let modifiers = ()
|
||
let issues = ()
|
||
for row in rows {
|
||
if row.len() == 0 { continue }
|
||
let first = row.first().trim()
|
||
if first.starts-with("Tier") {
|
||
let digits = first.replace(regex("\\D"), "")
|
||
if digits != "" { current-tier = int(digits) }
|
||
continue
|
||
}
|
||
if first == "Technique" {
|
||
effect-column = row.position(cell => cell.trim() == "Effet")
|
||
continue
|
||
}
|
||
if first == "" or effect-column == none or effect-column >= row.len() {
|
||
continue
|
||
}
|
||
if current-tier != none and not tier-is-enabled(current-tier) { continue }
|
||
let effect = row.at(effect-column)
|
||
// Attack modifiers are profiles in their own right: keep their bonuses
|
||
// data-driven instead of naming a specific technique in the report code.
|
||
let base-damage-bonus = capture(
|
||
effect,
|
||
"(?i)([0-9]+|un|une)\\s+dégâts?\\s+supplémentaires?\\s+et",
|
||
)
|
||
let p-damage-bonus = capture-first(effect, (
|
||
"(?i)\\+?([0-9]+|un|une)\\s+dégâts?\\s+supplémentaires?\\s+par\\s+réussite",
|
||
"(?i)\\+?([0-9]+|un|une)\\s+dégâts?\\s+par\\s+réussite(?:\\s+supplémentaires?)",
|
||
))
|
||
let armor-break-bonus = capture-first(effect, (
|
||
"(?i)([0-9]+|un|une)\\s+points?\\s+de\\s+brise[ -]armure(?:\\s+supplémentaires?)?",
|
||
"(?i)\\+([0-9]+)\\s+@rl_arbreak(?::short)?(?:\\s+supplémentaires?)",
|
||
"(?i)([0-9]+)\\s+@rl_arbreak(?::short)?\\s+supplémentaires?",
|
||
))
|
||
let rmax-bonus = capture-first(effect, (
|
||
"(?i)\\+([0-9]+)\\s+@rl_rmax(?::short)?(?:\\s+supplémentaires?)",
|
||
"(?i)([0-9]+)\\s+@rl_rmax(?::short)?\\s+supplémentaires?",
|
||
"(?i)([0-9]+|un|une)\\s+réussites?\\s+maxim(?:ale|ales|um)(?:\\s+supplémentaires?)",
|
||
))
|
||
let precision-bonus = capture-first(effect, (
|
||
"(?i)\\+([0-9]+)\\s+@rl_precision(?::short)?(?:\\s+supplémentaires?)",
|
||
"(?i)([0-9]+)\\s+@rl_precision(?::short)?\\s+supplémentaires?",
|
||
))
|
||
let armor-multiplier-bonus = capture-first(effect, (
|
||
"(?i)\\+([0-9]+)\\s+@rl_am(?::short)?(?:\\s+supplémentaires?)",
|
||
"(?i)([0-9]+)\\s+@rl_am(?::short)?\\s+supplémentaires?",
|
||
))
|
||
let has-weapon-bonus = (
|
||
base-damage-bonus != none
|
||
or p-damage-bonus != none
|
||
or armor-break-bonus != none
|
||
or rmax-bonus != none
|
||
or precision-bonus != none
|
||
or armor-multiplier-bonus != none
|
||
)
|
||
if has-weapon-bonus {
|
||
modifiers.push((
|
||
school: display,
|
||
technique: first,
|
||
tier: current-tier,
|
||
base-damage: if base-damage-bonus == none { 0 } else {
|
||
french-count(base-damage-bonus)
|
||
},
|
||
p-damage: if p-damage-bonus == none { 0 } else {
|
||
french-count(p-damage-bonus)
|
||
},
|
||
armor-break: if armor-break-bonus == none { 0 } else {
|
||
french-count(armor-break-bonus)
|
||
},
|
||
rmax: if rmax-bonus == none { 0 } else { french-count(rmax-bonus) },
|
||
precision: if precision-bonus == none { 0 } else {
|
||
french-count(precision-bonus)
|
||
},
|
||
armor-multiplier: if armor-multiplier-bonus == none { 0 } else {
|
||
french-count(armor-multiplier-bonus)
|
||
},
|
||
source: effect,
|
||
))
|
||
}
|
||
let structured = effect.contains("#weapon-pill(")
|
||
let structured-damage = if structured {
|
||
capture(effect, "#weapon-pill\\([^)]*damage:\\s*\\[([^]]+)\\]")
|
||
} else { none }
|
||
let damage = if structured-damage == none {
|
||
effect.match(regex(damage-profile-pattern))
|
||
} else { structured-damage.match(regex(damage-profile-pattern)) }
|
||
if damage == none { continue }
|
||
if (
|
||
effect.contains("jusqu'à 6 éclairs")
|
||
or effect.contains("jusqu'à 6 eclairs")
|
||
) {
|
||
issues.push((
|
||
school: display,
|
||
technique: first,
|
||
tier: current-tier,
|
||
reason: "Salve à réussites réparties: allocation entre éclairs non résolue",
|
||
))
|
||
continue
|
||
}
|
||
if effect.contains("cette attaque gagne +1") {
|
||
issues.push((
|
||
school: display,
|
||
technique: first,
|
||
tier: current-tier,
|
||
reason: "Profil dynamique (+0 à +10) dépendant du combat",
|
||
))
|
||
continue
|
||
}
|
||
let base-token = damage.captures.at(0)
|
||
let base = if base-token.match(regex("^[0-9]+$")) != none {
|
||
int(base-token)
|
||
} else { configured-base(base-token) }
|
||
let rmax = if structured {
|
||
capture(effect, "#weapon-pill\\([^)]*rmax:\\s*([0-9]+)")
|
||
} else { none }
|
||
if rmax == none {
|
||
rmax = capture(effect, "@rl_rmax(?::short)?\\s+([0-9]+)")
|
||
}
|
||
if base == none or rmax == none {
|
||
issues.push((
|
||
school: display,
|
||
technique: first,
|
||
tier: current-tier,
|
||
reason: if base == none {
|
||
"Caractéristique `" + base-token + "` sans valeur configurée"
|
||
} else { "R.Max absent" },
|
||
))
|
||
continue
|
||
}
|
||
let threshold = capture(effect, "(?i)seuil\\s+([0-9]+)")
|
||
let channel = capture(effect, "(?i)([0-9]+)\\s+actions")
|
||
let structured-actions = if structured {
|
||
capture(effect, "#weapon-pill\\([^)]*actions:\\s*([0-9]+)")
|
||
} else { none }
|
||
let explicit-two = effect.match(regex("(?:^|\\s)2A(?:[.,;]|\\s|$)")) != none
|
||
let actions = if structured-actions != none {
|
||
int(structured-actions)
|
||
} else if channel != none { int(channel) } else if explicit-two {
|
||
2
|
||
} else {
|
||
class-weapon-settings.default_action_cost
|
||
}
|
||
let precision = if threshold == none {
|
||
class-weapon-settings.default_precision_modifier
|
||
} else { int(threshold) - natural-precision }
|
||
let armor-break = if structured {
|
||
capture(effect, "#weapon-pill\\([^)]*arbreak:\\s*(-?[0-9]+)")
|
||
} else { none }
|
||
if armor-break == none {
|
||
armor-break = capture(effect, "@rl_arbreak\\s+([0-9]+)")
|
||
}
|
||
let armor-pierce = if structured {
|
||
capture(effect, "#weapon-pill\\([^)]*armor_pierce:\\s*(-?[0-9]+)")
|
||
} else { none }
|
||
if armor-pierce == none {
|
||
armor-pierce = capture(effect, "@rl_armor_pierce(?::short)?\\s+([0-9]+)")
|
||
}
|
||
let armor-multiplier = if structured {
|
||
capture(effect, "#weapon-pill\\([^)]*am:\\s*(-?[0-9]+)")
|
||
} else { none }
|
||
if armor-multiplier == none {
|
||
armor-multiplier = capture(effect, "@rl_am(?::short)?\\s+([0-9]+)")
|
||
}
|
||
let structured-precision = if structured {
|
||
capture(effect, "#weapon-pill\\([^)]*precision:\\s*(-?[0-9]+)")
|
||
} else { none }
|
||
if structured-precision != none {
|
||
precision += int(structured-precision)
|
||
}
|
||
let level = if row.len() > 1 and row.at(1).trim() != "" {
|
||
" · niv. " + row.at(1).trim()
|
||
} else { "" }
|
||
results.push((
|
||
school: display,
|
||
tier: current-tier,
|
||
technique: first,
|
||
base-token: base-token,
|
||
channelled: channel != none,
|
||
metric: analyze-weapon-profile(
|
||
first + level,
|
||
base,
|
||
int(damage.captures.at(1)),
|
||
int(rmax),
|
||
precision: precision,
|
||
actions: actions,
|
||
allow-chain: channel == none,
|
||
armor-break: if armor-break == none { 0 } else { int(armor-break) },
|
||
armor-pierce: if armor-pierce == none { 0 } else { int(armor-pierce) },
|
||
armor-multiplier: if armor-multiplier == none { 0 } else {
|
||
int(armor-multiplier)
|
||
},
|
||
source: effect,
|
||
),
|
||
))
|
||
}
|
||
let modified-profiles = ()
|
||
for modifier in modifiers {
|
||
for profile in results {
|
||
let item = profile.metric
|
||
modified-profiles.push(
|
||
profile
|
||
+ (
|
||
technique: profile.technique + " + " + modifier.technique,
|
||
modifier: modifier,
|
||
metric: analyze-weapon-profile(
|
||
item.name + " + " + modifier.technique,
|
||
item.base-damage + modifier.base-damage,
|
||
item.p-damage + modifier.p-damage,
|
||
item.rmax + modifier.rmax,
|
||
precision: item.precision + modifier.precision,
|
||
actions: item.actions,
|
||
allow-chain: item.allow-chain,
|
||
armor-break: item.armor-break + modifier.armor-break,
|
||
armor-pierce: item.armor-pierce,
|
||
armor-multiplier: item.armor-multiplier
|
||
+ modifier.armor-multiplier,
|
||
source: (attack: item.source, modifier: modifier.source),
|
||
),
|
||
),
|
||
)
|
||
}
|
||
}
|
||
(
|
||
profiles: results,
|
||
modified-profiles: modified-profiles,
|
||
modifiers: modifiers,
|
||
issues: issues,
|
||
)
|
||
}
|
||
|
||
// Origin abilities are YAML rather than TSV, but structured weapon pills make
|
||
// their offensive profiles deterministic enough to use the same analyzer.
|
||
#let parse-origin-attacks(entry) = {
|
||
let data = yaml(entry.source)
|
||
let display = "Origine — " + entry.family
|
||
let profiles = ()
|
||
let issues = ()
|
||
|
||
for stage in data.stades {
|
||
for ability in stage.abilities {
|
||
let effect = ability.description
|
||
if not effect.contains("#weapon-pill(") { continue }
|
||
let technique = ability.at("name", default: "Pouvoir sans nom")
|
||
let structured-damage = capture(
|
||
effect,
|
||
"#weapon-pill\\([^)]*damage:\\s*\\[([^]]+)\\]",
|
||
)
|
||
let damage = if structured-damage == none { none } else {
|
||
structured-damage.match(regex(damage-profile-pattern))
|
||
}
|
||
let rmax = capture(effect, "#weapon-pill\\([^)]*rmax:\\s*([0-9]+)")
|
||
|
||
if damage == none or rmax == none {
|
||
issues.push((
|
||
school: display,
|
||
technique: technique,
|
||
tier: stage.number,
|
||
reason: if damage == none {
|
||
"Dégâts structurés illisibles"
|
||
} else {
|
||
"R.Max vide: profil volontairement exclu de l’analyse"
|
||
},
|
||
))
|
||
continue
|
||
}
|
||
|
||
let base-token = damage.captures.at(0)
|
||
let base = if base-token.match(regex("^[0-9]+$")) != none {
|
||
int(base-token)
|
||
} else {
|
||
configured-base(base-token)
|
||
}
|
||
if base == none {
|
||
issues.push((
|
||
school: display,
|
||
technique: technique,
|
||
tier: stage.number,
|
||
reason: "Caractéristique `" + base-token + "` sans valeur configurée",
|
||
))
|
||
continue
|
||
}
|
||
|
||
let precision = capture(
|
||
effect,
|
||
"#weapon-pill\\([^)]*precision:\\s*(-?[0-9]+)",
|
||
)
|
||
let armor-break = capture(
|
||
effect,
|
||
"#weapon-pill\\([^)]*arbreak:\\s*(-?[0-9]+)",
|
||
)
|
||
let armor-pierce = capture(
|
||
effect,
|
||
"#weapon-pill\\([^)]*armor_pierce:\\s*(-?[0-9]+)",
|
||
)
|
||
let armor-multiplier = capture(
|
||
effect,
|
||
"#weapon-pill\\([^)]*am:\\s*(-?[0-9]+)",
|
||
)
|
||
let actions = capture(
|
||
effect,
|
||
"#weapon-pill\\([^)]*actions:\\s*([0-9]+)",
|
||
)
|
||
|
||
profiles.push((
|
||
school: display,
|
||
tier: stage.number,
|
||
technique: technique,
|
||
base-token: base-token,
|
||
channelled: false,
|
||
metric: analyze-weapon-profile(
|
||
technique + " · stade " + str(stage.number),
|
||
base,
|
||
int(damage.captures.at(1)),
|
||
int(rmax),
|
||
precision: if precision == none { 0 } else { int(precision) },
|
||
actions: if actions == none { 1 } else { int(actions) },
|
||
armor-break: if armor-break == none { 0 } else { int(armor-break) },
|
||
armor-pierce: if armor-pierce == none { 0 } else { int(armor-pierce) },
|
||
armor-multiplier: if armor-multiplier == none { 0 } else {
|
||
int(armor-multiplier)
|
||
},
|
||
source: effect,
|
||
),
|
||
))
|
||
}
|
||
}
|
||
(profiles: profiles, issues: issues)
|
||
}
|
||
|
||
#let untransferred-weapon-profiles = {
|
||
let issues = ()
|
||
for (school, source) in school-sources {
|
||
let rows = csv(source, delimiter: "\t")
|
||
let current-tier = none
|
||
let effect-column = none
|
||
for row in rows {
|
||
if row.len() == 0 { continue }
|
||
let first = row.first().trim()
|
||
if first.starts-with("Tier") {
|
||
let digits = first.replace(regex("\\D"), "")
|
||
if digits != "" { current-tier = int(digits) }
|
||
} else if first == "Technique" {
|
||
effect-column = row.position(cell => cell.trim() == "Effet")
|
||
} else if first != "" and effect-column != none and effect-column < row.len() {
|
||
let effect = row.at(effect-column)
|
||
let has-profile = (
|
||
effect.match(regex(damage-profile-pattern)) != none
|
||
or effect.match(regex(dice-damage-profile-pattern)) != none
|
||
)
|
||
if has-profile and not effect.contains("#weapon-pill(") {
|
||
issues.push((
|
||
school: school.replace("-", " "),
|
||
technique: first,
|
||
tier: current-tier,
|
||
source: effect,
|
||
))
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
for entry in origin-sources {
|
||
let data = yaml(entry.source)
|
||
for stage in data.stades {
|
||
for ability in stage.abilities {
|
||
let effect = ability.description
|
||
let has-profile = (
|
||
effect.match(regex(damage-profile-pattern)) != none
|
||
or effect.match(regex(dice-damage-profile-pattern)) != none
|
||
)
|
||
if has-profile and not effect.contains("#weapon-pill(") {
|
||
issues.push((
|
||
school: "Origine — " + entry.family,
|
||
technique: ability.at("name", default: "Pouvoir sans nom"),
|
||
tier: stage.number,
|
||
source: effect,
|
||
))
|
||
}
|
||
}
|
||
}
|
||
}
|
||
issues
|
||
}
|
||
|
||
// Compatibility alias for any report fragments still using the old name.
|
||
#let untransferred-school-weapons = untransferred-weapon-profiles
|
||
|
||
#let parse-artilleur() = {
|
||
let source = read("/chapters/schools/artilleur.typ")
|
||
// Artilleur already owns canonical component tables. Read their aligned
|
||
// cells directly; unlike school prose, these profiles do not use pills.
|
||
let base-pattern = regex(
|
||
"(?s)\\[([^]\\n]+)\\],\\s*\\n\\s*\\[[^]\\n]+\\],\\s*\\n\\s*\\[([0-9]+)/\\+([0-9]+)\\],\\s*\\n\\s*\\[([0-9]+)\\],\\s*\\n\\s*\\[([0-9]+)\\],\\s*\\n\\s*\\[(?:[0-9]+)\\],\\s*\\n\\s*\\[(?:[0-9]+)\\],\\s*\\n\\s*\\[([^]]*)\\],\\s*\\n\\s*\\[([0-9]+)A\\]",
|
||
)
|
||
let bases = source
|
||
.matches(base-pattern)
|
||
.filter(found => (
|
||
found.start < source.match(regex("\\[Canon\\],")).start
|
||
))
|
||
.map(found => (
|
||
name: found.captures.at(0),
|
||
damage: int(found.captures.at(1)),
|
||
p-damage: int(found.captures.at(2)),
|
||
rmax: int(found.captures.at(3)),
|
||
precision: if found.captures.at(5).contains("Précision +1") { 1 } else {
|
||
0
|
||
},
|
||
))
|
||
let loaders = source
|
||
.matches(regex("\\[Chargeur (Rotatif|Long|Unique)\\]"))
|
||
.map(found => found.captures.at(0))
|
||
let unique-damage = source.match(
|
||
regex(
|
||
"(?s)\\[Chargeur Unique\\],\\s*\\n\\s*\\[[^]]+\\],\\s*\\n\\s*\\[\\+([0-9]+)/\\+([0-9]+)\\]",
|
||
),
|
||
)
|
||
let unique-base-bonus = if unique-damage == none { 0 } else {
|
||
int(unique-damage.captures.at(0))
|
||
}
|
||
let unique-p-bonus = if unique-damage == none { 0 } else {
|
||
int(unique-damage.captures.at(1))
|
||
}
|
||
let cannons = ("Simple", "Double")
|
||
let profiles = ()
|
||
let issues = ()
|
||
for base in bases {
|
||
for cannon in cannons {
|
||
for loader in loaders {
|
||
let simple = cannon == "Simple"
|
||
let unique = loader == "Unique"
|
||
let metric = analyze-weapon-profile(
|
||
base.name + " · Canon " + cannon + " · " + loader,
|
||
base.damage + (if unique { unique-base-bonus } else { 0 }),
|
||
base.p-damage
|
||
+ (if simple { 1 } else { 0 })
|
||
+ (if unique { unique-p-bonus } else { 0 }),
|
||
base.rmax + (if simple { 1 } else { 0 }),
|
||
precision: base.precision + (if cannon == "Double" { 4 } else { 0 }),
|
||
actions: 1,
|
||
source: source,
|
||
)
|
||
profiles.push((
|
||
school: "Artilleur",
|
||
tier: none,
|
||
technique: metric.name,
|
||
base-token: str(base.damage),
|
||
channelled: false,
|
||
metric: metric,
|
||
artillery-base: base.name,
|
||
artillery-cannon: cannon,
|
||
artillery-loader: loader,
|
||
))
|
||
}
|
||
}
|
||
}
|
||
if bases.len() == 0 {
|
||
issues.push((
|
||
school: "Artilleur",
|
||
technique: "Bases",
|
||
tier: none,
|
||
reason: "Aucune base de canon reconnue",
|
||
))
|
||
}
|
||
if loaders.len() == 0 {
|
||
issues.push((
|
||
school: "Artilleur",
|
||
technique: "Chargeurs",
|
||
tier: none,
|
||
reason: "Aucun chargeur reconnu",
|
||
))
|
||
}
|
||
if unique-damage == none {
|
||
issues.push((
|
||
school: "Artilleur",
|
||
technique: "Chargeur Unique",
|
||
tier: none,
|
||
reason: "Modificateur +X/+Y illisible",
|
||
))
|
||
}
|
||
(profiles: profiles, issues: issues)
|
||
}
|
||
|
||
#let sangremage = parse-school-attacks(
|
||
"sangremage",
|
||
"Sangremage",
|
||
"/data/src/schools/sangremage.tsv",
|
||
)
|
||
#let mage-bestial = parse-school-attacks(
|
||
"mage-bestial",
|
||
"Mage bestial",
|
||
"/data/src/schools/mage_bestial.tsv",
|
||
)
|
||
#let bidouilleur = parse-school-attacks(
|
||
"bidouilleur",
|
||
"Bidouilleur",
|
||
"/data/src/schools/bidouilleur.tsv",
|
||
)
|
||
#let artilleur = parse-artilleur()
|
||
#let origins = origin-sources.map(parse-origin-attacks)
|
||
#let origin-weapon-profiles = origins.map(result => result.profiles).flatten()
|
||
#let origin-weapon-issues = origins.map(result => result.issues).flatten()
|
||
#let class-weapon-modified-profiles = (
|
||
sangremage.modified-profiles
|
||
+ mage-bestial.modified-profiles
|
||
+ bidouilleur.modified-profiles
|
||
)
|
||
#let class-weapon-profiles = (
|
||
sangremage.profiles
|
||
+ mage-bestial.profiles
|
||
+ bidouilleur.profiles
|
||
+ artilleur.profiles
|
||
+ origin-weapon-profiles
|
||
+ class-weapon-modified-profiles
|
||
)
|
||
#let class-weapon-issues = (
|
||
sangremage.issues + mage-bestial.issues + bidouilleur.issues + artilleur.issues
|
||
+ origin-weapon-issues
|
||
)
|
||
#let class-weapon-schools = (
|
||
class-weapon-profiles.map(profile => profile.school).dedup()
|
||
)
|
||
#let class-weapon-maxima = class-weapon-schools.map(school => {
|
||
let winner = class-weapon-profiles
|
||
.filter(profile => profile.school == school)
|
||
.sorted(
|
||
key: profile => -profile.metric.max-damage,
|
||
)
|
||
.first()
|
||
(school: school, profile: winner, damage: winner.metric.max-damage)
|
||
})
|
||
|
||
#let catalog-average = (
|
||
name: "Arme moyenne du catalogue",
|
||
commitments: commitment-pools
|
||
.map(scenario => (
|
||
scenario.key,
|
||
all-weapon-metrics
|
||
.map(item => item.commitments.at(scenario.key).best)
|
||
.sum()
|
||
/ all-weapon-metrics.len(),
|
||
))
|
||
.to-dict(),
|
||
)
|
||
#let catalog-best = (
|
||
all-weapon-metrics.sorted(key: item => -item.commitments.full.best).first()
|
||
)
|