Files
benilla-octo/crates/benilla-formats/src/environmental_damage.rs
T
Sam SungandClaude Opus 5.5 8da634afa9 Comments in benilla-formats: one line of fact each, no history, no record numbers (#130)
Part of #41: the comments of `benilla-formats` (the library, its extract tools, examples and tests) are rewritten to the rule in `docs/METHOD.md`, which is what the code does and the reference fact behind it, in a line. 19,654 comment lines become 7,264.

Fixes #105: the WMO collision comments now name walking's box-query leaf `0x6bca50` and the camera and line-of-sight segment-query leaf `0x6bc700`, in `models/collision.rs`, `examples/wmo_bsp.rs` and `tests/chain.rs`.

- **The mechanical strip.** The citations that were only a private record number go first, and each edit is shown to be a pure removal.
- **Wrong facts corrected.** The rewrite corrects the comments that stated wrong facts. Among them:
  - A placed doodad's material alpha reads file slot 0 on its spawn clock, while the reference reads bone 0's armed sequence, re-rolled every play window. The old text said doodads are armed once at load.
  - The fog end is stored ×36 and scaled once at load (`0x6d6090`). It is not raw.
  - The MCSH bit picks a map doodad's sun scale, 1.0 lit or 0.5 shadowed. 2.5 belongs to an entity's light node.
  - `SpellRec` is the row as stored, column × 4, not a translated copy.
  - A global sequence's clock is anchored at the instance's attach time (`0x714352`).
  - Particle twinkle is a gated size multiplier (`0x7b2adc`).
  - The blob shadow sizes from the Stand box.
  - Data claims are checked against the install: the weapon-trail kits' parameters and alphas, the beam rows' noise, and the maps' `field_16`.
  - Dozens more turned up on the way: renamed or deleted items, docs sitting on the wrong item, stale counts and links.
- **Deviation labels.** "Deviation:" now marks only a choice with a reason. An unbuilt behaviour says so plainly.
- **Verification.** Every file strips to identical code, and `cargo fmt --check` is clean. Four second readers compared every file old against new, restored the facts the rewrite had dropped, and checked each new citation against the reference, the code and the shipped data.

String literals are untouched; they are #92.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 19:38:53 +07:00

94 lines
3.1 KiB
Rust

//! `EnvironmentalDamage.dbc`: the `SpellVisualKit` played on the victim of
//! `SMSG_ENVIRONMENTALDAMAGELOG` (read at `0x624fcc` in `0x624f30`), by the wire's `damage_type`:
//! 0 exhausted, 1 drowning, 2 fall, 3 lava, 4 slime, 5 fire.
use crate::Chain;
use anyhow::{Context, Result};
use benilla_dbc::{FieldType, Schema, SchemaField};
use crate::dbc::{parse, u32_at};
const ENVIRONMENTAL_DAMAGE: &str = "DBFilesClient\\EnvironmentalDamage.dbc";
/// The client's 6-slot damage type → kit table (`[0xc4d8e4]`).
pub struct EnvironmentalDamageTable {
kits: [u32; 6],
}
impl EnvironmentalDamageTable {
/// The kit for a wire `damage_type`; `None` past type 5 or for an empty slot.
pub fn kit_id(&self, damage_type: u8) -> Option<u32> {
self.kits
.get(usize::from(damage_type))
.copied()
.filter(|&k| k != 0)
}
}
fn schema() -> Schema {
let mut s = Schema::new("EnvironmentalDamage");
for name in ["ID", "DamageType", "VisualKit"] {
s.add_field(SchemaField::new(name, FieldType::UInt32));
}
s
}
/// Load the table as the client's init `0x603900` fills it: zeroed, then
/// `slot[DamageType] = VisualKit` for each row whose type is below 6.
pub fn load_environmental_damage(chain: &mut Chain) -> Result<EnvironmentalDamageTable> {
let bytes = chain
.read_file(ENVIRONMENTAL_DAMAGE)
.with_context(|| format!("reading {ENVIRONMENTAL_DAMAGE}"))?;
table_from(&bytes)
}
fn table_from(bytes: &[u8]) -> Result<EnvironmentalDamageTable> {
let rs = parse(bytes, schema(), "EnvironmentalDamage")?;
let mut kits = [0u32; 6];
for r in rs.records() {
if let (Some(ty), Some(kit)) = (u32_at(r, 1), u32_at(r, 2)) {
if let Some(slot) = kits.get_mut(ty as usize) {
*slot = kit;
}
}
}
Ok(EnvironmentalDamageTable { kits })
}
#[cfg(test)]
mod tests {
use super::*;
/// The shipped rows, plus a type-9 row that the range guard must skip.
#[test]
fn table_loads_by_damage_type_with_the_range_guard() {
let rows: &[[u32; 3]] = &[
[1, 0, 871],
[2, 1, 870],
[3, 2, 1066],
[4, 3, 1064],
[5, 4, 1065],
[6, 5, 1067],
[7, 9, 999], // out of range: the client's `cmp edx,6; jae` skip
];
let mut dbc = Vec::new();
dbc.extend_from_slice(b"WDBC");
dbc.extend_from_slice(&(rows.len() as u32).to_le_bytes());
dbc.extend_from_slice(&3u32.to_le_bytes()); // fields
dbc.extend_from_slice(&12u32.to_le_bytes()); // record size
dbc.extend_from_slice(&1u32.to_le_bytes()); // string block
for row in rows {
for v in row {
dbc.extend_from_slice(&v.to_le_bytes());
}
}
dbc.push(0); // the string block
let table = table_from(&dbc).unwrap();
assert_eq!(table.kit_id(2), Some(1066), "fall → the DustCloud Land kit");
assert_eq!(table.kit_id(0), Some(871));
assert_eq!(table.kit_id(5), Some(1067));
assert_eq!(table.kit_id(9), None, "out-of-range type");
}
}