fixes traffic jams - if path is blocked, npcs will recalc path to dest
This commit is contained in:
parent
454c2aab63
commit
207f3b7671
1 changed files with 13 additions and 0 deletions
|
|
@ -110,6 +110,19 @@ impl<'a> System<'a> for DefaultAI {
|
||||||
is_telepath.dirty = true;
|
is_telepath.dirty = true;
|
||||||
}
|
}
|
||||||
path.remove(0);
|
path.remove(0);
|
||||||
|
} else {
|
||||||
|
// If the path is blocked, recalculate a new path to the same waypoint.
|
||||||
|
let path = rltk::a_star_search(
|
||||||
|
map.xy_idx(pos.x, pos.y) as i32,
|
||||||
|
map.xy_idx(
|
||||||
|
(path[path.len() - 1] as i32) % map.width,
|
||||||
|
(path[path.len() - 1] as i32) / map.width
|
||||||
|
) as i32,
|
||||||
|
&mut *map
|
||||||
|
);
|
||||||
|
if path.success && path.steps.len() > 1 {
|
||||||
|
move_mode.mode = Movement::RandomWaypoint { path: Some(path.steps) };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
move_mode.mode = Movement::RandomWaypoint { path: None };
|
move_mode.mode = Movement::RandomWaypoint { path: None };
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue