demo 1
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::constants::{ITILE_SIZE, TILE_SIZE};
|
||||
use crate::entities::behaviour::IdleBehaviour;
|
||||
use crate::entities::shared_components::Ambulatory;
|
||||
use crate::entities::tasks::components::{IdleState, Task};
|
||||
use crate::entities::tasks::components::{IdleState, Task, IDLE_MAX_RETRIES};
|
||||
use crate::world::chunks::ChunkMap;
|
||||
use crate::world::chunks::CHUNK_SIZE;
|
||||
use crate::world::tiles::TileMap;
|
||||
@@ -30,7 +30,10 @@ pub(super) fn execute_idle(
|
||||
};
|
||||
|
||||
match state {
|
||||
IdleState::Picking { retry_after_tick } => {
|
||||
IdleState::Picking {
|
||||
retry_after_tick,
|
||||
retry_count,
|
||||
} => {
|
||||
if current_tick < *retry_after_tick {
|
||||
return;
|
||||
}
|
||||
@@ -47,6 +50,19 @@ pub(super) fn execute_idle(
|
||||
*state = IdleState::Moving { target };
|
||||
}
|
||||
None => {
|
||||
*retry_count += 1;
|
||||
if *retry_count >= IDLE_MAX_RETRIES {
|
||||
panic!(
|
||||
"Entity stuck: pick_gaussian_target returned None {} times \
|
||||
consecutively. origin={:?} sigma_world={:.1} \
|
||||
loaded_chunks={} \
|
||||
— no standable tile found. Check tilemap state.",
|
||||
retry_count,
|
||||
origin,
|
||||
sigma_world,
|
||||
chunk_map.loaded_chunks.len(),
|
||||
);
|
||||
}
|
||||
*retry_after_tick = current_tick.saturating_add(30);
|
||||
}
|
||||
}
|
||||
@@ -90,6 +106,7 @@ pub(super) fn execute_idle(
|
||||
} else {
|
||||
*state = IdleState::Picking {
|
||||
retry_after_tick: 0,
|
||||
retry_count: 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -114,6 +131,7 @@ pub(super) fn execute_idle(
|
||||
sprite.flip_x = false;
|
||||
*state = IdleState::Picking {
|
||||
retry_after_tick: 0,
|
||||
retry_count: 0,
|
||||
};
|
||||
} else {
|
||||
*ticks_remaining -= 1;
|
||||
|
||||
Reference in New Issue
Block a user