fix
This commit is contained in:
@@ -533,16 +533,11 @@ pub fn update_wandering_targets(
|
|||||||
mut query: Query<(&mut Ambulatory, &Transform), Without<crate::entities::tasks::TaskQueue>>,
|
mut query: Query<(&mut Ambulatory, &Transform), Without<crate::entities::tasks::TaskQueue>>,
|
||||||
tilemap: Res<TileMap>,
|
tilemap: Res<TileMap>,
|
||||||
chunk_map: Res<ChunkMap>,
|
chunk_map: Res<ChunkMap>,
|
||||||
time: Res<Time>,
|
mut rng_q: Query<&mut WyRand, With<GlobalRng>>,
|
||||||
) {
|
) {
|
||||||
// Use deterministic RNG - seed from SEED + time
|
let Ok(mut rng) = rng_q.single_mut() else {
|
||||||
use std::collections::hash_map::DefaultHasher;
|
return;
|
||||||
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);
|
|
||||||
|
|
||||||
for (mut ambulatory, transform) in query.iter_mut() {
|
for (mut ambulatory, transform) in query.iter_mut() {
|
||||||
if ambulatory.target.is_none() {
|
if ambulatory.target.is_none() {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use rand::{RngExt, SeedableRng};
|
|||||||
pub fn task_executor_system(
|
pub fn task_executor_system(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
tilemap: Res<TileMap>,
|
tilemap: Res<TileMap>,
|
||||||
time: Res<Time>,
|
mut rng_q: Query<&mut WyRand, With<GlobalRng>>,
|
||||||
mut query: Query<(
|
mut query: Query<(
|
||||||
Entity,
|
Entity,
|
||||||
&mut TaskQueue,
|
&mut TaskQueue,
|
||||||
@@ -34,21 +34,17 @@ pub fn task_executor_system(
|
|||||||
mut completed_writer: MessageWriter<TaskCompleted>,
|
mut completed_writer: MessageWriter<TaskCompleted>,
|
||||||
mut failed_writer: MessageWriter<TaskFailed>,
|
mut failed_writer: MessageWriter<TaskFailed>,
|
||||||
) {
|
) {
|
||||||
use std::collections::hash_map::DefaultHasher;
|
let Ok(mut rng) = rng_q.single_mut() else {
|
||||||
use std::hash::{Hash, Hasher};
|
return;
|
||||||
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);
|
|
||||||
|
|
||||||
for (entity, mut queue, mut state, mut ambulatory, transform) in query.iter_mut() {
|
for (entity, mut queue, mut state, mut ambulatory, transform) in query.iter_mut() {
|
||||||
// If queue empty, assign default Idle task
|
// If queue empty, assign default Idle task
|
||||||
if queue.is_empty() {
|
if queue.is_empty() {
|
||||||
let origin = (transform.translation / ITILE_SIZE as f32).as_ivec3();
|
let origin = transform.translation.as_ivec3();
|
||||||
queue.push(Task::Idle {
|
queue.push(Task::Idle {
|
||||||
target: origin,
|
target: origin,
|
||||||
wander_radius: 10,
|
wander_radius: 64,
|
||||||
origin,
|
origin,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -134,7 +130,7 @@ pub fn task_executor_system(
|
|||||||
let origin = (transform.translation / ITILE_SIZE as f32).as_ivec3();
|
let origin = (transform.translation / ITILE_SIZE as f32).as_ivec3();
|
||||||
queue.push(Task::Idle {
|
queue.push(Task::Idle {
|
||||||
target: origin,
|
target: origin,
|
||||||
wander_radius: 10,
|
wander_radius: 64,
|
||||||
origin,
|
origin,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
//! This module contains the logic that was previously in the wandering
|
//! 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.
|
//! 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::shared_components::Ambulatory;
|
||||||
use crate::entities::tasks::components::Task;
|
use crate::entities::tasks::components::Task;
|
||||||
use crate::world::tiles::tilemap::TileMap;
|
use crate::world::tiles::tilemap::TileMap;
|
||||||
@@ -34,8 +34,13 @@ pub(super) fn execute_idle(
|
|||||||
// Track if target actually changed this tick
|
// Track if target actually changed this tick
|
||||||
let mut target_changed = false;
|
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 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) {
|
if let Some(new_target) = pick_wander_target(origin, *wander_radius, tilemap, rng) {
|
||||||
*target = new_target;
|
*target = new_target;
|
||||||
target_changed = true;
|
target_changed = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user