fix
This commit is contained in:
@@ -150,54 +150,33 @@ pub fn task_executor_system(
|
||||
|
||||
if approach.is_none() {
|
||||
// First entry: compute approach tile and set target.
|
||||
// Check 8 surrounding XY positions at the trunk's ground z.
|
||||
let offsets = [
|
||||
(-1, 0),
|
||||
(1, 0),
|
||||
(0, -1),
|
||||
(0, 1),
|
||||
(-1, -1),
|
||||
(-1, 1),
|
||||
(1, -1),
|
||||
(1, 1),
|
||||
];
|
||||
// Neighbours at the same z as the trunk base — this IS the floor level.
|
||||
let trunk_z = trunk_pos.z;
|
||||
|
||||
// Find the ground z at the trunk XY (for z reference)
|
||||
let ground_z = (-3i32..=4i32)
|
||||
.find_map(|z| {
|
||||
let floor_pos =
|
||||
IVec3::new(trunk_pos.x, trunk_pos.y, z * ITILE_SIZE);
|
||||
if tilemap_mut.floor_tiles.contains_key(&floor_pos) {
|
||||
let above = IVec3::new(
|
||||
trunk_pos.x,
|
||||
trunk_pos.y,
|
||||
floor_pos.z + ITILE_SIZE,
|
||||
// Search expanding outward from the trunk for a standable tile
|
||||
let approach_target = (1..=4).find_map(|radius: i32| {
|
||||
for dx in -radius..=radius {
|
||||
for dy in -radius..=radius {
|
||||
// Only check the outer ring of this radius
|
||||
if dx.abs() != radius && dy.abs() != radius {
|
||||
continue;
|
||||
}
|
||||
let candidate = IVec3::new(
|
||||
trunk_pos.x + dx * ITILE_SIZE,
|
||||
trunk_pos.y + dy * ITILE_SIZE,
|
||||
trunk_z,
|
||||
);
|
||||
if tilemap_mut.is_standable(above) {
|
||||
return Some(above.z);
|
||||
if tilemap_mut.is_standable(candidate) {
|
||||
*approach = Some(candidate);
|
||||
return Some(Vec3::new(
|
||||
candidate.x as f32,
|
||||
candidate.y as f32,
|
||||
candidate.z as f32 + 1.0,
|
||||
));
|
||||
}
|
||||
}
|
||||
None
|
||||
})
|
||||
.unwrap_or(trunk_pos.z);
|
||||
|
||||
// Find nearest standable neighbour
|
||||
let approach_target = offsets.iter().find_map(|(dx, dy)| {
|
||||
let candidate = IVec3::new(
|
||||
trunk_pos.x + dx * ITILE_SIZE,
|
||||
trunk_pos.y + dy * ITILE_SIZE,
|
||||
ground_z,
|
||||
);
|
||||
if tilemap_mut.is_standable(candidate) {
|
||||
*approach = Some(candidate);
|
||||
Some(Vec3::new(
|
||||
candidate.x as f32,
|
||||
candidate.y as f32,
|
||||
candidate.z as f32 + 1.0,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
None
|
||||
});
|
||||
|
||||
match approach_target {
|
||||
|
||||
Reference in New Issue
Block a user