Fix update_wandering_targets target validation logic
- Restored original target selection logic that validates is_standable_tile - Fixed target position z-level checking (check floor tile then standable) - Re-added check for completed paths (path_index >= path.len) - This was the cause of 50,297 failed paths - entities targeting invalid positions
This commit is contained in:
@@ -200,28 +200,28 @@ pub fn update_wandering_targets(
|
||||
return;
|
||||
};
|
||||
|
||||
query.iter_mut().for_each(|(mut ambulatory, transform)| {
|
||||
if ambulatory.target.is_none() {
|
||||
let center = transform.translation;
|
||||
let center_chunk = IVec2::new(
|
||||
(center.x / (CHUNK_SIZE as f32 * TILE_SIZE)).floor() as i32,
|
||||
(center.y / (CHUNK_SIZE as f32 * TILE_SIZE)).floor() as i32,
|
||||
);
|
||||
for (mut ambulatory, _) in query.iter_mut() {
|
||||
if ambulatory.target.is_none()
|
||||
|| (ambulatory.current_path.is_some()
|
||||
&& ambulatory.path_index >= ambulatory.current_path.as_ref().unwrap().len())
|
||||
{
|
||||
let loaded_chunks: Vec<&IVec2> = chunk_map.loaded_chunks.keys().collect();
|
||||
if !loaded_chunks.is_empty() {
|
||||
let random_index = rng.random_range(0..loaded_chunks.len());
|
||||
if let Some(&chunk_pos) = loaded_chunks.get(random_index) {
|
||||
let chunk_x = chunk_pos.x * CHUNK_SIZE;
|
||||
let chunk_y = chunk_pos.y * CHUNK_SIZE;
|
||||
|
||||
if chunk_map.loaded_chunks.contains_key(¢er_chunk) {
|
||||
let loaded_chunks: Vec<&IVec2> = chunk_map.loaded_chunks.keys().collect();
|
||||
if !loaded_chunks.is_empty() {
|
||||
let random_index = rng.random_range(0..loaded_chunks.len());
|
||||
if let Some(&chunk_pos) = loaded_chunks.get(random_index) {
|
||||
let chunk_x = chunk_pos.x * CHUNK_SIZE;
|
||||
let chunk_y = chunk_pos.y * CHUNK_SIZE;
|
||||
let target_x = chunk_x + rng.random_range(0..CHUNK_SIZE);
|
||||
let target_y = chunk_y + rng.random_range(0..CHUNK_SIZE);
|
||||
|
||||
let target_x = chunk_x + rng.random_range(0..CHUNK_SIZE);
|
||||
let target_y = chunk_y + rng.random_range(0..CHUNK_SIZE);
|
||||
|
||||
for z in -3..=4 {
|
||||
let target_pos = IVec3::new(target_x, target_y, z) * ITILE_SIZE;
|
||||
if tilemap.floor_tiles.contains_key(&target_pos) {
|
||||
for z in -3..=4 {
|
||||
let mut target_pos = IVec3::new(target_x, target_y, z) * ITILE_SIZE;
|
||||
if tilemap.floor_tiles.get(&target_pos).is_some() {
|
||||
target_pos.z += ITILE_SIZE;
|
||||
if tilemap.floor_tiles.get(&target_pos).is_some()
|
||||
&& is_standable_tile(&tilemap, target_pos)
|
||||
{
|
||||
ambulatory.target = Some(Vec3::new(
|
||||
target_pos.x as f32,
|
||||
target_pos.y as f32,
|
||||
@@ -236,7 +236,7 @@ pub fn update_wandering_targets(
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn movement(mut query: Query<(&mut Ambulatory, &mut Transform)>, tilemap: Res<TileMap>) {
|
||||
|
||||
Reference in New Issue
Block a user