From 8e3e8b8b8c649be9aaa7d3c27182500410a4a08c Mon Sep 17 00:00:00 2001 From: popertots Date: Sat, 4 Apr 2026 12:16:23 +0100 Subject: [PATCH] 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. --- src/entities/tasks/executor.rs | 46 +++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/src/entities/tasks/executor.rs b/src/entities/tasks/executor.rs index b6ac09e..dcc4d42 100644 --- a/src/entities/tasks/executor.rs +++ b/src/entities/tasks/executor.rs @@ -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; + } } } }