feat: attenuate indirect blast damage behind known cover
build / mod (push) Failing after 18s

Use a bounded read-only pre-destruction occupancy sample; preserve conservative damage for unresolved geometry and do not defer or repeat damage on replies.

Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
2026-11-02 23:55:38 +03:00
parent a7d400ea7e
commit c96676f3e5
8 changed files with 196 additions and 19 deletions
+49
View File
@@ -799,6 +799,55 @@ pub fn section_of(source: &dyn WorldSource, s: Sec) -> Fill {
}
impl WorldCache {
/// Read-only occupancy at the instant of a blast. Some(true) is known cover,
/// Some(false) a fully known open segment, None unresolved geometry. No query,
/// chunk load or later reply can change damage already committed for this blast.
/// This deliberately treats partial collision blocks as occupied cubes.
pub fn blast_cover(&self, a: DVec3, b: DVec3, now: u64) -> Option<bool> {
let d = b - a;
let mut p = [a.x.floor() as i32, a.y.floor() as i32, a.z.floor() as i32];
let av = [a.x, a.y, a.z];
let dv = [d.x, d.y, d.z];
let step = dv.map(|v| if v > 0.0 { 1 } else { -1 });
let mut next = [f64::INFINITY; 3];
let mut delta = [f64::INFINITY; 3];
for i in 0..3 {
if dv[i] != 0.0 {
let edge = f64::from(p[i]) + if dv[i] > 0.0 { 1.0 } else { 0.0 };
next[i] = (edge - av[i]) / dv[i];
delta[i] = (1.0 / dv[i]).abs();
}
}
let mut unknown = false;
for n in 0..256 {
let fill = self.secs.get(&sec_of(p[0], p[1], p[2]))
.filter(|e| !e.stale && now.saturating_sub(e.since) < RECHECK)
.map(|e| &e.fill);
let solid = match fill {
Some(Fill::Empty) => Some(false),
Some(Fill::Full) => Some(true),
Some(Fill::Mixed(bits)) => {
let i = ((p[1] & 15) << 8 | (p[2] & 15) << 4 | (p[0] & 15)) as usize;
Some(bits[i >> 3] >> (i & 7) & 1 != 0)
}
_ => None,
};
match solid {
// Ignore the struck/origin voxel, not the next wall behind it.
Some(true) if n > 0 => return Some(true),
None => unknown = true,
_ => {}
}
let axis = if next[0] < next[1] {
if next[0] < next[2] { 0 } else { 2 }
} else if next[1] < next[2] { 1 } else { 2 };
if next[axis] > 1.0 { return if unknown { None } else { Some(false) }; }
next[axis] += delta[axis];
p[axis] += step[axis];
}
None
}
/// Answers the exact rays of the last tick from a synthetic world, as the game does one tick later.
pub fn serve_rays(&mut self, source: &dyn WorldSource, rays: Vec<(u32, DVec3, DVec3)>) {
let replies: Vec<RayReply> = rays