fix
This commit is contained in:
@@ -22,7 +22,7 @@ use rand::{RngExt, SeedableRng};
|
||||
pub fn task_executor_system(
|
||||
mut commands: Commands,
|
||||
tilemap: Res<TileMap>,
|
||||
time: Res<Time>,
|
||||
mut rng_q: Query<&mut WyRand, With<GlobalRng>>,
|
||||
mut query: Query<(
|
||||
Entity,
|
||||
&mut TaskQueue,
|
||||
@@ -34,21 +34,17 @@ pub fn task_executor_system(
|
||||
mut completed_writer: MessageWriter<TaskCompleted>,
|
||||
mut failed_writer: MessageWriter<TaskFailed>,
|
||||
) {
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
let mut hasher = DefaultHasher::new();
|
||||
crate::constants::SEED.hash(&mut hasher);
|
||||
time.elapsed_secs().to_bits().hash(&mut hasher);
|
||||
let seed = hasher.finish();
|
||||
let mut rng = WyRand::seed_from_u64(seed);
|
||||
let Ok(mut rng) = rng_q.single_mut() else {
|
||||
return;
|
||||
};
|
||||
|
||||
for (entity, mut queue, mut state, mut ambulatory, transform) in query.iter_mut() {
|
||||
// If queue empty, assign default Idle task
|
||||
if queue.is_empty() {
|
||||
let origin = (transform.translation / ITILE_SIZE as f32).as_ivec3();
|
||||
let origin = transform.translation.as_ivec3();
|
||||
queue.push(Task::Idle {
|
||||
target: origin,
|
||||
wander_radius: 10,
|
||||
wander_radius: 64,
|
||||
origin,
|
||||
});
|
||||
}
|
||||
@@ -134,7 +130,7 @@ pub fn task_executor_system(
|
||||
let origin = (transform.translation / ITILE_SIZE as f32).as_ivec3();
|
||||
queue.push(Task::Idle {
|
||||
target: origin,
|
||||
wander_radius: 10,
|
||||
wander_radius: 64,
|
||||
origin,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//! This module contains the logic that was previously in the wandering
|
||||
//! system. Now it's called by the task executor when Task::Idle is active.
|
||||
|
||||
use crate::constants::ITILE_SIZE;
|
||||
use crate::constants::{ITILE_SIZE, TILE_SIZE};
|
||||
use crate::entities::shared_components::Ambulatory;
|
||||
use crate::entities::tasks::components::Task;
|
||||
use crate::world::tiles::tilemap::TileMap;
|
||||
@@ -34,8 +34,13 @@ pub(super) fn execute_idle(
|
||||
// Track if target actually changed this tick
|
||||
let mut target_changed = false;
|
||||
|
||||
// Use distance threshold for arrival check - equality never triggers due to float truncation
|
||||
let dist_sq = (transform.translation.x - target.x as f32).powi(2)
|
||||
+ (transform.translation.y - target.y as f32).powi(2);
|
||||
let arrived = dist_sq < (TILE_SIZE * 1.5) * (TILE_SIZE * 1.5);
|
||||
|
||||
// If reached target or target is no longer standable, pick new target
|
||||
if entity_pos == *target || !tilemap.is_standable(*target) {
|
||||
if arrived || !tilemap.is_standable(*target) {
|
||||
if let Some(new_target) = pick_wander_target(origin, *wander_radius, tilemap, rng) {
|
||||
*target = new_target;
|
||||
target_changed = true;
|
||||
|
||||
Reference in New Issue
Block a user