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 neighbors = |site: &Id<civ::Site>| world.civs().neighbors(*site);
|
||||||
|
|
||||||
let track_between = |a: Id<civ::Site>, b: Id<civ::Site>| {
|
let transition = |a: &Id<civ::Site>, b: &Id<civ::Site>| {
|
||||||
world
|
world.civs().track_between(*a, *b).map(|(id, _)| {
|
||||||
.civs()
|
world.civs().tracks.get(id).cost
|
||||||
.tracks
|
}).unwrap_or(f32::INFINITY)
|
||||||
.get(world.civs().track_between(a, b).unwrap().0)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
let path = astar.poll(250, heuristic, neighbors, transition, |site| *site == end);
|
||||||
|
|
||||||
path.map(|path| {
|
path.map(|path| {
|
||||||
let path = path
|
let path = path
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.tuple_windows::<(_, _)>()
|
.tuple_windows::<(_, _)>()
|
||||||
.map(|(a, b)| world.civs().track_between(a, b).unwrap())
|
// Since we get a, b from neighbors, track_between shouldn't return None.
|
||||||
.collect_vec();
|
.filter_map(|(a, b)| world.civs().track_between(a, b))
|
||||||
|
.collect();
|
||||||
Path { nodes: path }
|
Path { nodes: path }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user