mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
remove unwraps in npc_ai
This commit is contained in:
parent
d1f6e6bef6
commit
2b44d534cb
@ -137,23 +137,21 @@ fn path_between_sites(
|
||||
|
||||
let neighbors = |site: &Id<civ::Site>| world.civs().neighbors(*site);
|
||||
|
||||
let track_between = |a: Id<civ::Site>, b: Id<civ::Site>| {
|
||||
world
|
||||
.civs()
|
||||
.tracks
|
||||
.get(world.civs().track_between(a, b).unwrap().0)
|
||||
let transition = |a: &Id<civ::Site>, b: &Id<civ::Site>| {
|
||||
world.civs().track_between(*a, *b).map(|(id, _)| {
|
||||
world.civs().tracks.get(id).cost
|
||||
}).unwrap_or(f32::INFINITY)
|
||||
};
|
||||
|
||||
let transition = |a: &Id<civ::Site>, b: &Id<civ::Site>| track_between(*a, *b).cost;
|
||||
|
||||
let path = astar.poll(250, heuristic, neighbors, transition, |site| *site == end);
|
||||
|
||||
path.map(|path| {
|
||||
let path = path
|
||||
.into_iter()
|
||||
.tuple_windows::<(_, _)>()
|
||||
.map(|(a, b)| world.civs().track_between(a, b).unwrap())
|
||||
.collect_vec();
|
||||
// Since we get a, b from neighbors, track_between shouldn't return None.
|
||||
.filter_map(|(a, b)| world.civs().track_between(a, b))
|
||||
.collect();
|
||||
Path { nodes: path }
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user