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:
@@ -499,24 +499,40 @@ pub fn task_executor_system(
|
|||||||
continue;
|
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
|
// Use approach tile position for distance check, not target None
|
||||||
if let Some(approach_tile) = *approach {
|
if ambulatory.target.is_some() {
|
||||||
let dx = transform.translation.x - approach_tile.x as f32;
|
if let Some(approach_tile) = *approach {
|
||||||
let dy = transform.translation.y - approach_tile.y as f32;
|
let dx = transform.translation.x - approach_tile.x as f32;
|
||||||
let dist_sq = dx * dx + dy * dy;
|
let dy = transform.translation.y - approach_tile.y as f32;
|
||||||
let arrive_sq =
|
let dist_sq = dx * dx + dy * dy;
|
||||||
(ITILE_SIZE as f32 * 1.5) * (ITILE_SIZE as f32 * 1.5);
|
let arrive_sq =
|
||||||
info!("[HAUL] {:?} arrival check: approach={:?} dist_sq={:.1} arrive_sq={:.1} transform={:?}",
|
(ITILE_SIZE as f32 * 1.5) * (ITILE_SIZE as f32 * 1.5);
|
||||||
entity, approach_tile, dist_sq, arrive_sq, transform.translation.truncate());
|
info!("[HAUL] {:?} arrival check: approach={:?} dist_sq={:.1} arrive_sq={:.1} transform={:?}",
|
||||||
if dist_sq <= arrive_sq {
|
entity, approach_tile, dist_sq, arrive_sq, transform.translation.truncate());
|
||||||
info!(
|
if dist_sq <= arrive_sq {
|
||||||
"[HAUL] {:?} arrived at approach {:?}, picking up cargo at {:?}",
|
info!(
|
||||||
entity, approach_tile, cargo_pos
|
"[HAUL] {:?} arrived at approach {:?}, picking up cargo at {:?}",
|
||||||
);
|
entity, approach_tile, cargo_pos
|
||||||
*step = HaulStep::PickingUp;
|
);
|
||||||
|
*step = HaulStep::PickingUp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user