Fix bug: prevent multiple job assignments to same dorf in one frame

- Add assigned_this_frame HashSet to track dorfs receiving jobs
- Filter out already-assigned dorfs from subsequent job assignments
- Add debug logging for spawn position (z-level)
- Add debug logging for is_standable failures
- Add debug logging for falling/snapping movement behavior

This fixes the critical bug where one dorf could be assigned multiple
jobs in the same frame, causing earlier assignments to be lost due to
queue.clear(). Each dorf now receives at most one job per frame.
This commit is contained in:
2026-04-05 18:09:37 +01:00
parent c9d74ef49b
commit ec1ec6b7d4
3 changed files with 39 additions and 4 deletions
+13 -1
View File
@@ -99,12 +99,24 @@ pub fn spawn_dorfs(
let seed = hasher.finish();
let mut rng = WyRand::seed_from_u64(seed);
use crate::world::chunks::Z_ABOVE;
for _ in 0..config.spawn_counts.dorfs {
let raw_x = rng.random_range(-512.0f32..512.0f32);
let raw_y = rng.random_range(-512.0f32..512.0f32);
let grid_x = (raw_x / TILE_SIZE).round() * TILE_SIZE;
let grid_y = (raw_y / TILE_SIZE).round() * TILE_SIZE;
let grid_z = 35.0 * TILE_SIZE;
// Spawn at top of valid world range (Z_ABOVE * TILE_SIZE)
// The movement system will snap/fall them to surface level
let grid_z = Z_ABOVE * TILE_SIZE;
info!(
"[SPAWN] Dorf spawning at ({}, {}, {}) z_level={}",
grid_x,
grid_y,
grid_z,
grid_z / TILE_SIZE
);
let cit = commands
.spawn(Dorf::new(&asset_server, Vec3::new(grid_x, grid_y, grid_z)))