Initial conflict avoidance.

This commit is contained in:
hal8174 2024-01-15 19:54:48 +01:00
parent 9751764611
commit 993fb0730c
4 changed files with 480 additions and 185 deletions

View file

@ -7,7 +7,7 @@ pub enum Direction {
}
impl Direction {
pub fn from_neghbors(pos: &Position, neighbor: &Position) -> Self {
pub fn from_neighbors(pos: &Position, neighbor: &Position) -> Self {
let x_diff = pos.x as i64 - neighbor.x as i64;
let y_diff = pos.y as i64 - neighbor.y as i64;
@ -143,4 +143,24 @@ impl PathField {
.map(|p| (p, *dir)),
}
}
pub fn offset(&self, offset: (i32, i32)) -> Self {
match self {
PathField::Belt { pos, dir } => PathField::Belt {
pos: Position::new(
(pos.x as i32 + offset.0) as usize,
(pos.y as i32 + offset.1) as usize,
),
dir: *dir,
},
PathField::Underground { pos, dir, len } => PathField::Underground {
pos: Position::new(
(pos.x as i32 + offset.0) as usize,
(pos.y as i32 + offset.1) as usize,
),
dir: *dir,
len: *len,
},
}
}
}