Fix: Set ambulatory.target for HaulCargo when approach pre-computed

When job_pathfinding pre-computes the approach tile for HaulCargo,
the executor was skipping target assignment because:
1. approach.is_none() was false (approach already set)
2. ambulatory.target.is_none() was true (no target set)
3. No else branch to set the target

Added else-if branch to set target when approach is set but target isn't.
This fixes dorfs freezing in MovingToCargo state with target=None.
This commit is contained in:
2026-04-04 12:16:23 +01:00
parent 022e21d484
commit 8e3e8b8b8c
+31 -15
View File
@@ -499,24 +499,40 @@ pub fn task_executor_system(
continue;
}
}
} else if ambulatory.target.is_none() {
// Have approach but no target — set target and start pathfinding
if let Some(approach_tile) = *approach {
info!(
"[HAUL] {:?} setting target to approach {:?}",
entity, approach_tile
);
ambulatory.target = Some(Vec3::new(
approach_tile.x as f32,
approach_tile.y as f32,
approach_tile.z as f32 + 1.0,
));
ambulatory.current_path = None;
}
}
// Check arrival at cargo tile
// Check arrival at cargo tile (only when target is set)
// Use approach tile position for distance check, not target None
if let Some(approach_tile) = *approach {
let dx = transform.translation.x - approach_tile.x as f32;
let dy = transform.translation.y - approach_tile.y as f32;
let dist_sq = dx * dx + dy * dy;
let arrive_sq =
(ITILE_SIZE as f32 * 1.5) * (ITILE_SIZE as f32 * 1.5);
info!("[HAUL] {:?} arrival check: approach={:?} dist_sq={:.1} arrive_sq={:.1} transform={:?}",
entity, approach_tile, dist_sq, arrive_sq, transform.translation.truncate());
if dist_sq <= arrive_sq {
info!(
"[HAUL] {:?} arrived at approach {:?}, picking up cargo at {:?}",
entity, approach_tile, cargo_pos
);
*step = HaulStep::PickingUp;
if ambulatory.target.is_some() {
if let Some(approach_tile) = *approach {
let dx = transform.translation.x - approach_tile.x as f32;
let dy = transform.translation.y - approach_tile.y as f32;
let dist_sq = dx * dx + dy * dy;
let arrive_sq =
(ITILE_SIZE as f32 * 1.5) * (ITILE_SIZE as f32 * 1.5);
info!("[HAUL] {:?} arrival check: approach={:?} dist_sq={:.1} arrive_sq={:.1} transform={:?}",
entity, approach_tile, dist_sq, arrive_sq, transform.translation.truncate());
if dist_sq <= arrive_sq {
info!(
"[HAUL] {:?} arrived at approach {:?}, picking up cargo at {:?}",
entity, approach_tile, cargo_pos
);
*step = HaulStep::PickingUp;
}
}
}
}