This commit is contained in:
2026-07-09 00:18:40 -05:00
parent e545395ac6
commit 386967e936
3 changed files with 27 additions and 32 deletions
+17 -14
View File
@@ -269,21 +269,24 @@ impl Board {
let (dx, dy): (i64, i64) = dir.into();
let (mut cx, mut cy) = (x, y);
loop {
match self.solid_at(cx, cy) {
None => return None, // open space: nothing bumped
Some(s) if s.object_id().is_some() => return s.object_id(), // hit an object
Some(s) if s.player() => return None, // the player is never "bumped"
// A terrain cell: a pushable crate is walked through; a wall stops us.
Some(_) if self.is_pushable(cx, cy, dir) => {
let next = (cx as i64 + dx, cy as i64 + dy);
if !self.in_bounds(next) {
return None; // crate chain runs off the board
}
cx = next.0 as usize;
cy = next.1 as usize;
}
Some(_) => return None, // non-pushable terrain (wall): no object behind it here
// Open space ends the walk with nothing bumped.
let solid = self.solid_at(cx, cy)?;
// A solid object — directly, or at the end of a crate chain — is the target.
if let Some(id) = solid.object_id() {
return Some(id);
}
// The player is never itself "bumped"; a wall (non-pushable terrain) stops
// the chain with no object behind it. Only a pushable crate is walked
// through — reuse the already-fetched `solid` rather than re-scanning.
if solid.player() || !solid.pushable().allows(dir) {
return None;
}
let next = (cx as i64 + dx, cy as i64 + dy);
if !self.in_bounds(next) {
return None; // crate chain runs off the board
}
cx = next.0 as usize;
cy = next.1 as usize;
}
}