Use .downhill for waypoint generation

This commit is contained in:
Joshua Barretto 2020-01-26 13:05:28 +00:00
parent 631124f3fc
commit a4573f6fb2

View File

@ -1461,32 +1461,14 @@ impl WorldSim {
.into_par_iter() .into_par_iter()
.filter_map(|(i, j)| { .filter_map(|(i, j)| {
let mut pos = Vec2::new(i as i32, j as i32); let mut pos = Vec2::new(i as i32, j as i32);
// Slide the waypoints down hills // Slide the waypoints down hills
for _ in 0..32 { const MAX_ITERS: usize = 64;
let last_pos = pos; for _ in 0..MAX_ITERS {
let chunk = this.get(pos)?; match this.get(pos)?.downhill {
Some(downhill) => pos = downhill,
for dir in [ None => return Some(pos),
Vec2::new(1, 0),
Vec2::new(-1, 0),
Vec2::new(0, 1),
Vec2::new(0, -1),
]
.iter()
{
const MAX_HEIGHT_DIFF: f32 = 8.0;
let tgt_chunk = this.get(pos + *dir)?;
if tgt_chunk.alt + MAX_HEIGHT_DIFF < chunk.alt && !tgt_chunk.is_underwater {
pos += *dir;
}
}
if last_pos == pos {
break;
} }
} }
Some(pos) Some(pos)
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();