Improve belt blueprint generation
This commit is contained in:
parent
d89c8136f7
commit
24b989b9f2
3 changed files with 166 additions and 118 deletions
|
|
@ -1,137 +1,100 @@
|
|||
use super::{Blueprint, BlueprintEntity, BlueprintPosition};
|
||||
use crate::{belt_finding::common::PathField, prelude::*};
|
||||
|
||||
use super::{
|
||||
belt::{convert_to_blueprint, Beltspeed},
|
||||
Blueprint, BlueprintEntity, BlueprintPosition,
|
||||
};
|
||||
|
||||
pub fn generate_4_lane_balancer() -> Blueprint {
|
||||
let e = vec![
|
||||
let mut e = vec![
|
||||
BlueprintEntity::builder("splitter".to_owned(), 1, BlueprintPosition::new(1.0, 0.5))
|
||||
.build(),
|
||||
BlueprintEntity::builder("splitter".to_owned(), 2, BlueprintPosition::new(3.0, 0.5))
|
||||
.build(),
|
||||
BlueprintEntity::builder("splitter".to_owned(), 3, BlueprintPosition::new(2.0, 1.5))
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
4,
|
||||
BlueprintPosition::new(0.5, 1.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
5,
|
||||
BlueprintPosition::new(3.5, 1.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
6,
|
||||
BlueprintPosition::new(0.5, 2.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"underground-belt".to_owned(),
|
||||
4,
|
||||
BlueprintPosition::new(1.5, 2.5),
|
||||
)
|
||||
.underground_type("output".to_owned())
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"underground-belt".to_owned(),
|
||||
5,
|
||||
BlueprintPosition::new(2.5, 2.5),
|
||||
)
|
||||
.underground_type("output".to_owned())
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
6,
|
||||
BlueprintPosition::new(3.5, 2.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
7,
|
||||
BlueprintPosition::new(0.5, 3.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
8,
|
||||
BlueprintPosition::new(1.5, 3.5),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
9,
|
||||
BlueprintPosition::new(2.5, 3.5),
|
||||
)
|
||||
.direction(4)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
10,
|
||||
BlueprintPosition::new(3.5, 3.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder("splitter".to_owned(), 11, BlueprintPosition::new(2.0, 4.5))
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
12,
|
||||
BlueprintPosition::new(0.5, 5.5),
|
||||
)
|
||||
.direction(4)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
13,
|
||||
BlueprintPosition::new(1.5, 5.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
14,
|
||||
BlueprintPosition::new(2.5, 5.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
15,
|
||||
BlueprintPosition::new(3.5, 5.5),
|
||||
)
|
||||
.direction(12)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
16,
|
||||
BlueprintPosition::new(0.5, 6.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"underground-belt".to_owned(),
|
||||
17,
|
||||
BlueprintPosition::new(1.5, 6.5),
|
||||
)
|
||||
.underground_type("input".to_owned())
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"underground-belt".to_owned(),
|
||||
18,
|
||||
BlueprintPosition::new(2.5, 6.5),
|
||||
)
|
||||
.underground_type("input".to_owned())
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
"transport-belt".to_owned(),
|
||||
19,
|
||||
BlueprintPosition::new(3.5, 6.5),
|
||||
)
|
||||
.build(),
|
||||
BlueprintEntity::builder("splitter".to_owned(), 20, BlueprintPosition::new(1.0, 7.5))
|
||||
.build(),
|
||||
BlueprintEntity::builder("splitter".to_owned(), 21, BlueprintPosition::new(3.0, 7.5))
|
||||
.build(),
|
||||
];
|
||||
|
||||
let mut nextfree = e.len() as u32;
|
||||
e.extend(convert_to_blueprint(
|
||||
&[
|
||||
PathField::Belt {
|
||||
pos: Position::new(0, 1),
|
||||
dir: Direction::Up,
|
||||
},
|
||||
PathField::Belt {
|
||||
pos: Position::new(3, 1),
|
||||
dir: Direction::Up,
|
||||
},
|
||||
PathField::Belt {
|
||||
pos: Position::new(0, 2),
|
||||
dir: Direction::Up,
|
||||
},
|
||||
PathField::Belt {
|
||||
pos: Position::new(3, 2),
|
||||
dir: Direction::Up,
|
||||
},
|
||||
PathField::Belt {
|
||||
pos: Position::new(0, 3),
|
||||
dir: Direction::Up,
|
||||
},
|
||||
PathField::Belt {
|
||||
pos: Position::new(1, 3),
|
||||
dir: Direction::Left,
|
||||
},
|
||||
PathField::Belt {
|
||||
pos: Position::new(2, 3),
|
||||
dir: Direction::Right,
|
||||
},
|
||||
PathField::Belt {
|
||||
pos: Position::new(3, 3),
|
||||
dir: Direction::Up,
|
||||
},
|
||||
PathField::Belt {
|
||||
pos: Position::new(0, 5),
|
||||
dir: Direction::Right,
|
||||
},
|
||||
PathField::Belt {
|
||||
pos: Position::new(1, 5),
|
||||
dir: Direction::Up,
|
||||
},
|
||||
PathField::Belt {
|
||||
pos: Position::new(2, 5),
|
||||
dir: Direction::Up,
|
||||
},
|
||||
PathField::Belt {
|
||||
pos: Position::new(3, 5),
|
||||
dir: Direction::Left,
|
||||
},
|
||||
PathField::Belt {
|
||||
pos: Position::new(0, 6),
|
||||
dir: Direction::Up,
|
||||
},
|
||||
PathField::Belt {
|
||||
pos: Position::new(3, 6),
|
||||
dir: Direction::Up,
|
||||
},
|
||||
PathField::Underground {
|
||||
pos: Position::new(1, 6),
|
||||
dir: Direction::Up,
|
||||
len: 4,
|
||||
},
|
||||
PathField::Underground {
|
||||
pos: Position::new(2, 6),
|
||||
dir: Direction::Up,
|
||||
len: 4,
|
||||
},
|
||||
],
|
||||
&Beltspeed::Normal,
|
||||
&mut nextfree,
|
||||
));
|
||||
|
||||
Blueprint::builder()
|
||||
.label("balancer".to_string())
|
||||
.entities(e)
|
||||
|
|
|
|||
84
src/blueprint/belt.rs
Normal file
84
src/blueprint/belt.rs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
use crate::{belt_finding::common::PathField, prelude::PositionType};
|
||||
|
||||
use super::{Blueprint, BlueprintEntity, BlueprintPosition};
|
||||
|
||||
pub enum Beltspeed {
|
||||
Normal,
|
||||
Fast,
|
||||
Express,
|
||||
Turbo,
|
||||
}
|
||||
|
||||
impl Beltspeed {
|
||||
fn string(&self) -> String {
|
||||
match self {
|
||||
Beltspeed::Normal => "transport-belt",
|
||||
Beltspeed::Fast => "fast-transport-belt",
|
||||
Beltspeed::Express => "express-transport-belt",
|
||||
Beltspeed::Turbo => "turbo-transport-belt",
|
||||
}
|
||||
.to_owned()
|
||||
}
|
||||
|
||||
fn string_underground(&self) -> String {
|
||||
match self {
|
||||
Beltspeed::Normal => "underground-belt",
|
||||
Beltspeed::Fast => "fast-underground-belt",
|
||||
Beltspeed::Express => "express-underground-belt",
|
||||
Beltspeed::Turbo => "turbo-underground-belt",
|
||||
}
|
||||
.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn convert_belt_to_blueprint(
|
||||
belt: &PathField,
|
||||
speed: &Beltspeed,
|
||||
nextfree: &mut u32,
|
||||
) -> impl Iterator<Item = BlueprintEntity> {
|
||||
match belt {
|
||||
PathField::Belt { pos, dir } => {
|
||||
*nextfree += 1;
|
||||
vec![BlueprintEntity::builder(
|
||||
speed.string(),
|
||||
*nextfree - 1,
|
||||
BlueprintPosition::new(pos.x as f64 + 0.5, pos.y as f64 + 0.5),
|
||||
)
|
||||
.direction(dir.get_index() * 4)
|
||||
.build()]
|
||||
.into_iter()
|
||||
}
|
||||
PathField::Underground { pos, dir, len } => {
|
||||
*nextfree += 2;
|
||||
let endpos = pos.in_direction(dir, *len as PositionType);
|
||||
vec![
|
||||
BlueprintEntity::builder(
|
||||
speed.string_underground(),
|
||||
*nextfree - 2,
|
||||
BlueprintPosition::new(pos.x as f64 + 0.5, pos.y as f64 + 0.5),
|
||||
)
|
||||
.underground_type("input".to_string())
|
||||
.direction(dir.get_index() * 4)
|
||||
.build(),
|
||||
BlueprintEntity::builder(
|
||||
speed.string_underground(),
|
||||
*nextfree - 1,
|
||||
BlueprintPosition::new(endpos.x as f64 + 0.5, endpos.y as f64 + 0.5),
|
||||
)
|
||||
.underground_type("output".to_string())
|
||||
.direction(dir.get_index() * 4)
|
||||
.build(),
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn convert_to_blueprint<'p, 's, 'n>(
|
||||
path: &'p [PathField],
|
||||
speed: &'s Beltspeed,
|
||||
nextfree: &'n mut u32,
|
||||
) -> impl Iterator<Item = BlueprintEntity> + use<'p, 's, 'n> {
|
||||
path.iter()
|
||||
.flat_map(|b| convert_belt_to_blueprint(b, speed, nextfree))
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ pub mod structs;
|
|||
pub use structs::*;
|
||||
|
||||
pub mod balancer;
|
||||
pub mod belt;
|
||||
pub mod train;
|
||||
|
||||
pub fn decode(s: &str) -> String {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue